NSubstitute
NSubstitute copied to clipboard
A friendly substitute for .NET mocking libraries.
Hello, thank you for your help. In my code I encounter the following scenario extremely often: ``` obj.Received(1).SampleMethod("sample"); obj.Received(1).SampleMethod(Arg.Any()); ``` It is testing whether I received a single call to...
For the following interface: ``` public interface IInterfaceUnderTest { bool PublicProperty { get; set; } } ``` The following test code works. ``` interfaceUnderTest.PublicProperty = Arg.Do(x => propertyValue = x);...
**Describe the bug** If you use `Arg.Is` when setting the return value and do something elaborate as accessing an outer saved `Substitute`, you get the `CouldNotSetReturnDueToTypeMismatchException` when (and only when!)...
**Question** Is it possible to mock methods that take `Span` and capture the arguments? Using `Arg.Do`, I'm getting an error that: > The type 'Span' may not be used as...
**Is your feature request related to a problem? Please describe.** I would like to be able to assert that no methods were called in a substitute rather than any specific...
**Describe the bug** `Received` passes even if the predicate isn't true when calling the method being asserted, if the property that the predicate is checking is changed after the method...
I am using NSubstitute for unit testing. I am getting below exception for ReturnsForAnyArgs Exception thrown: 'NSubstitute.Exceptions.CouldNotSetReturnDueToTypeMismatchException' in NSubstitute.dll this.exchangeService = Substitute.For(); HttpClient httpClient = new HttpClient(); this.exchangeService.Client.Returns(httpClient); HttpResponseMessage httpResponseMessage...
My question seems similar to https://github.com/nsubstitute/NSubstitute/issues/629, but the issue there seems to discard `ReceivedWithAnyArgs`, but my issue is about the fact that `ReceivedWithAnyArgs` does not ignore the number of arguments....
Not sure if this is a terrible idea, but was reading [this SO question](https://stackoverflow.com/q/67423477/906) and started thinking about an `Arg.MustMatch` or similar matcher that throws on non-matches and is not...
**Describe the bug** `bool` argument type when combined with argument matcher `Arg.Any` yields wrong call specifications. In particular, `false` with `Arg.any()` end up out of order call specification. For example,...