Questions tagged [nsubstitute]

NSubstitute is a .NET mocking framework. It creates substitutes of types for testing that can act as both mocks (can check calls were received) and stubs (can configure results for calls).

NSubstitute is a dynamic .NET mocking library, compatible with netstandard-1.3 and .NET 4.5 and above (earlier versions support back to .NET 3.5).

Using a "fluent" syntax, it creates substitutes of types for testing that can be configured to return specific results for calls, or can be queried about the calls they did receive. As this combines the behaviour of "mocks" and "stubs", NSubstitute uses the term "substitute" to describe these test doubles.

629 questions
0
votes
3 answers

Cannot have two operations in the same contract with the same name : Auto Generated Async Method

edit Correction: My Error was that Instead of using ChatService.IChatService I was using ReflectorLike.ChatServiceReference.IchatService. In other words , AFAIU I was referencing a reference to the Interface rather than the Interface it self. (If…
Lomithrani
  • 2,033
  • 3
  • 18
  • 24
0
votes
1 answer

Unit Testing ICommand with NSubstitute

I have the following ViewModel public class MyViewModel : IMyViewModel { private readonly IMyModel myMode; private ICommand _myCommand; public MyViewModel(IMyModel model) { _model = model; } public ICommand…
James B
  • 8,975
  • 13
  • 45
  • 83
0
votes
1 answer

Nsubstitute Returns is not overriden in an other test case?

If i have Method which i want to check, and for some reason, i want to split the test case in 2 separate cases i would love to do this : [Test] public void EditCustomerShouldReturnExceptionWhenCustomerIsNotCreated() { var c =…
Timsen
  • 4,066
  • 10
  • 59
  • 117
0
votes
1 answer

NSubstitute Checking received calls don't work

Hey guys im new with the NSubstitute framework. I'm trying to test some of my classes, but when i use NSubstitute to check received calls it says received no matching calls. I'm trying to test if the method Tick() is receiving LogEvent() and…
Loc Dai Le
  • 1,661
  • 4
  • 35
  • 70
0
votes
1 answer

ReturnForAnyArgs without using NSubstitute

I am unit testing a Post method that in its implementation uses a Microsoft.AspNet.Identity.Owin.SignInManager because SignInManager inherit from a class and not an interface I cannot use NSubstitute to mock the SignInManager object. Therefore I…
Marta
  • 1,132
  • 1
  • 10
  • 26
0
votes
1 answer

NSubstitute: When....Do not working while mocking void method

I am new to NSubtitute and really confused why below test case is failing. public class IFoo { public void SayHello(string to) { Console.writeLine("Method called"); } } [Test] public void SayHello() { var…
user3640709
  • 83
  • 1
  • 9
0
votes
2 answers

How to unit test delegate was received in base class method?

I currently have a base service class that all my services extend. This is what one of the methods look like: protected internal virtual T PerformServiceOperationWithExceptionHandling(Func func) { try { …
Cool Breeze
  • 1,289
  • 11
  • 34
0
votes
2 answers

Mocked Interface with NSubstitute on F# does not allow Returns

I have the following code: open NSubstitute type MyClass()= let myObject = Substitute.For() do myObject.MyProperty.Returns(true) do myObject.MyMethod().Returns(true) On "Returns" (both) I get the error that is not defined.…
Miyamoto Akira
  • 327
  • 1
  • 7
  • 16
0
votes
1 answer

NSubstitute conditions for throwing exception other than parameters

I'm using NSubstitute to mock a class that my method under test uses. This mocked class may throw a particular exception under certain conditions. The method that I'm testing has some "retry" logic that it executes when it catches this exception. …
JoeMjr2
  • 3,804
  • 4
  • 34
  • 62
0
votes
1 answer

mocking multiple interfaces wirth machine.fakes

how can I obtain the equivalent of Substitute.For, IQueryable, IDbAsyncEnumerable>() with machine.fakes? I tried using var myFake = An>(); myFake.WhenToldTo(m =>…
0
votes
2 answers

Code coverage doesn't mark a line that uses as passed

I don't know why i'm having this behavior with my code coverage, maybe someone knows the reasson. As you may know, code coverage is blue when reached, red when not reached, yellow when partially reached a line of code. I coded a little mapper that…
Yogurtu
  • 2,656
  • 3
  • 23
  • 23
0
votes
1 answer

State design pattern modifying context class collection - How to unit test.

I am currently using nSubstitute and nUnit to do some unit testing. I a newbie when it comes to this stuff so any help would be greatly appreciated. Please have a look at this code: public class Event { private ISet hostSet; private…
Cool Breeze
  • 1,289
  • 11
  • 34
0
votes
1 answer

Unity and auto-mocking with NSubstitute (or something else)

My question derives from this question: Is this possible with Unity (Instead of Castle Windsor)? Here is the class from the answer: protected override void Initialize() { var strategy = new AutoMockingBuilderStrategy(Container); …
0
votes
1 answer

stub out a method like an interface using nsubstitute

This is my first post! I'm trying to write a unit test using nsubstitute but I'm finding the last bit difficult. I've included a snippet of code below, the test fails when calling the method on the model. Is it possible to stub this method out? …
Jamie
  • 321
  • 1
  • 6
  • 18
0
votes
1 answer

How does this MSpec/NSubstitute test pass when the Subject has no implementation?

I am trying to assert that a method was called in MSpec while using NSubstitute as the mocking framework. The Subject has an empty implementation of ExecuteAll(). It should fail, but it passes! public class…
4imble
  • 13,979
  • 15
  • 70
  • 125