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
-1
votes
1 answer

AutoFixture.AutoNSubstitute not autogenerating data for properties in interfaces

I'm wanting to use AutoFixture to automatically generate test data, and am currently using the mocking framework NSubstitute. However, I'm unable to generate random data for properties on interfaces. I have the following test case setup: public…
Hayden
  • 2,902
  • 2
  • 15
  • 29
-1
votes
2 answers

Refit with TestServer and NSubstitute

I am trying to use Refit to test a Rest interface on TestServer, while replacing the DateTime.Now to return custom time. My refit interface looks something like this: public interface IMyApi { DateTime CurentTime(); …
Will I Am
  • 2,614
  • 3
  • 35
  • 61
-1
votes
2 answers

Writing unit test without mocking framework

I am doing some unit tests with NUnit and NSubstiture. I have this class: public class Presenter { public Presenter() { } private readonly IView _view; public Presenter(IView view) { _view = view; …
SavantKing
  • 27
  • 1
  • 6
-1
votes
2 answers

Abstracted Dispose Method not called when using nSubstitute

i have this base (abstract) class: public abstract class StreamWriterBuilderService : IStreamWriterService { private Stream fs; private StreamWriter stream; public void WriteLine( string stringToWrite ) { if ( stream…
Andrew Simpson
  • 6,883
  • 11
  • 79
  • 179
-1
votes
1 answer

Setup a mocked injected object

I've configured a MockingKernel in order to mock a dependency: [TestFixture] public class TestsFixture { private NSubstituteMockingKernel IoCKernel; public UsersTests() { this.IoCKernel = new NSubstituteMockingKernel(); } …
Jordi
  • 20,868
  • 39
  • 149
  • 333
-1
votes
1 answer

NSubstitute: Received Calls asserts wrongly

I've created this test: [TestFixture] public class UsersTests { private Core.Kernel coreKernel; private Core.Configuration.ICoreConfiguration coreConfiguration; [SetUp] public void SetUp() { this.coreConfiguration =…
Jordi
  • 20,868
  • 39
  • 149
  • 333
-1
votes
1 answer

Why NSubstitute returns only last value when multiples are specified

I am trying to mock IDbConnection in my DAO class, but I am receiving following error: String lengths are both 5. Strings differ at index 0. Expected: "11111" But was: "22222" Here is my code: Classes under test internal class…
ceezy
  • 25
  • 1
  • 4
-1
votes
1 answer

unit test strange things

i have a class extend from a base class,the base class in another dll. public class MyMicroBlogCache : RelatedBase and in constructor,inject a ICache public MyMicroBlogCache(ICache cache,.... in base class ,i…
chenZ
  • 920
  • 4
  • 16
-1
votes
1 answer

Unit test Nsubstitute

I am learning unittesting and I am using Nsubstitute as a choice of mocking framework. so I have this small imaginary app I am writing for a guest inn. I am trying to write a test to ensure that once a reservation is made on a friday, room prices…
Joseph Izang
  • 766
  • 1
  • 13
  • 43
-1
votes
2 answers

Testing behavior of a derived class in isolation

I'm attempting to isolate and test a particular class in an existing code base which is derived from some base and has a private class member that I want to mock: public class Derived : Base { protected Something _otherSomething = new…
itsmatt
  • 31,265
  • 10
  • 100
  • 164
-1
votes
1 answer

Unit Tests: How to Assert? Asserting results returned or that a method was called on a mock?

I am trying to find out the best way to Assert, should I be creating an object with what i should return and check that it has equal to the expected result ? Or should I be running a method against a mock to ensure that the method was actually…
Martin
  • 23,844
  • 55
  • 201
  • 327
-2
votes
1 answer

Due to AutoFixture and NSubstitude object reference not set to an instance of an object error from unit test

I am writing unit test in mvc project with AutoFixture and NSubstitude. But I am getting object reference error in my update and delete methods. Probably because I'm new, I may be missing the settings for these packages. This is my main code public…
sedya
  • 13
  • 4
-2
votes
1 answer

c# vs 2017 mocking var property with return inside

i'm trying to mock a custom variable inside a class that's readonly and has a return inside the get. public class BaseController { public string Local { return GlobalVariable.Local } } [TestMethod] public void TestMethod() { …
1 2 3
41
42