NSubstitute
NSubstitute copied to clipboard
A friendly substitute for .NET mocking libraries.
**Question** How can I ensure that verifying calls does not break when adding optional arguments to an interface? Adding an optional argument to an interface is one way of adding...
**Is your feature request related to a problem? Please describe.** I have a situation with a partial mock where I want to make use of the existing implementation, but intercept...
**Is your feature request related to a problem? Please describe.** When doing a partial substitute, overriding a method with `.Returns(..)` implicitly suppresses any invocation of the base method implementation. But,...
**Describe the bug** NSubstitute behaving oddly with `StackExchange.Redis` library. Ilya Chernomordik on StackOverflow [reports a `TypeLoadException`](https://stackoverflow.com/q/60720540/906) in DynamicProxy-generated `RedisResultProxy`. This type isn't explicitly configured, I'm guessing it is from a...
The following test crashes NUnit: ```csharp [Test] public void Test1() { Received.InOrder(async () => { throw new Exception(); }); } ``` If I remove the `async` keyword, then the exception...
C# 7.0 added support for [ref returns](https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/ref-returns). I tried to mock the value of one such method via `.Returns`, but got the following: `System.InvalidProgramException : Invalid IL code in Castle.Proxies.IPlayerManagerProxy:get_PlayerInfo...
From https://github.com/nsubstitute/NSubstitute/issues/222#issuecomment-557198534, saying `protected virtual` is substitutable is misleading. While technically possible (hacky) with the current API, it's not something we encourage and people should not expect to mock these...
Partial substitute could be created in a type-safe manner: `ForPartsOf(Expression constructorExpression)` Constructor parsed to determine constructor method and arguments. Before: `Substitute.ForPartsOf(ctorArg1, ctorArg2);` After: `Substitute.ForPartsOf(() => new MyClass(ctorArg1, ctorArg2));` Benefits: static...
**Describe the bug** When there is a missing binding redirect, the mock does not throw an error when evaluating with Arg.Is(), which make it hard to debug the issue. It...
**Describe the bug** **Received.InOrder** ignores/bypasses any .Returns() configured call. All calls inside return their default result. This leads to failing Received tests, as the expected result isn't called. This bug...