nsubstitute Questions
6
Solved
I am trying to write unit tests around my exception handling so that I can verify the my logger is properly logging the exception. I am using NSubstitute as a mocking framework and Microsoft.Extens...
Impasto asked 2/10, 2017 at 16:5
11
Solved
I tried in vain to mock a top-level (not part of any section) configuration value (.NET Core's IConfiguration). For example, neither of these will work (using NSubstitute, but it would be the same ...
Pictograph asked 11/11, 2020 at 21:13
4
Solved
We are currently in the process of moving from RhinoMocks to NSubstitute.
I have a method that takes an object of type DatabaseParams. This class has the following structure (simplified):
public ...
Excitant asked 9/7, 2015 at 11:47
3
Solved
Suppose, that I've got a following class:
public abstract class Test
{
internal abstract int Prop
{
get;
}
}
Now, I try to make a mock using NSubstitute:
var mock = Substitute.For<Test&...
Intrastate asked 14/11, 2013 at 8:12
2
Solved
I have a TestFixture marked class which is Unit testing the functionality of a class named 'HideCurrentTitleBarMessageTask'.
In this class I use a substitute to mock an interface in the [Setup] me...
Armlet asked 11/4, 2017 at 15:8
2
Solved
Is there a way to check with NSubstitute that number of received calls falls within certain range?
I would like to do something like:
myMock.Received(r => r > 1 && r <= 5).MyMeth...
Wreck asked 6/5, 2019 at 22:15
6
I'm getting the following error:
NSubstitute.Exceptions.UnexpectedArgumentMatcherException: 'Argument
matchers (Arg.Is, Arg.Any) should only be used in place of member
arguments. Do not use in...
Flyaway asked 5/4, 2018 at 10:20
8
Solved
When I run the following code:
[Test]
public async Task Can_Test_Update()
{
var response = await _controller.UpdateAsync(Guid.NewGuid());
response.Valid.Should().BeTrue();
_commands.Received()...
Tel asked 23/6, 2015 at 7:6
5
Solved
Using NSubstitute, how do you mock an exception being thrown in a method returning a Task?
Let's say our method signature looks something like this:
Task<List<object>> GetAllAsync();
...
Tompkins asked 12/7, 2016 at 21:7
7
Solved
So EntityFramework 6 is a lot better testable then previous versions. And there are some nice examples on the internet for frameworks like Moq, but the case is, I prefer using NSubstitute. I've got...
Pearlene asked 12/1, 2014 at 0:57
5
Solved
I am writing C# unit tests using NUnit and NSubstitute. I am testing a class which will attempt to retrieve objects from a config provider implementing the following interface:
public interface IC...
Seafaring asked 7/11, 2014 at 16:11
4
Solved
I use NUnit and NSubstitute for unit testing. I have the following:
public interface IDataProvider
{
void Log(int tvmId, DateTime time, int source, int level, int eventCode, string message);
}
....
Boyceboycey asked 24/3, 2016 at 14:20
2
Solved
I have a .Net Core 3 application and am trying to test calls to ILogger in my method:
public class MyClass
{
private readonly ILogger<MyClass> _logger;
public MyClass(ILogger<MyClass&g...
Drupe asked 14/3, 2020 at 15:53
1
I am trying to use NSubstitute to mock HttpClient. Here's the code:
public static HttpClient GetHttpClient(bool isSucess = true, string methodType = "GET")
{
var mockIHttpMessageHandler...
Winfredwinfrey asked 7/8, 2021 at 2:1
2
Solved
I'm trying to mock a static method in a static class. I already read that you can't do that, but I was looking a way to work around that.
I can't modify the code, and making the same function witho...
Kemeny asked 14/6, 2019 at 16:5
3
I am writing a Unit Test and need to mock Entity Framework's .FromSqlRaw method. When the method is executed in the class under test, it throws following exception:
System.InvalidOperationExceptio...
Affectionate asked 11/10, 2020 at 9:1
1
Solved
Using NSubstitute.
For some tests I want to assert that a Substitute has received no calls whatsoever. I could use DidNotReceiveWithAnyArgs() for every method in the interface, but that is tedious ...
Unboned asked 28/1, 2021 at 15:43
1
Solved
Given an async method, how can NSubstitute check a call was not received?
With NSubstitute, we can check a async method (or many) were received in order using:
Received.InOrder(async () =>
{
aw...
Trass asked 11/11, 2020 at 19:45
3
Solved
I'm writing a data access layer for my application and trying to mock out the CosmosDB SDK dependency for unit testing. I am using NUnit with NSubstitute and have come across the issue where I am t...
Grieco asked 29/9, 2019 at 13:54
2
public static void Mock(out IProgram prog, out IJson json)
{
prog = Substitute.For<IProgram>();
IJson = Substitute.For<IJson>();
prog.SaveProg(1, 1, 1, "Somthing", 1, DateTime.UtcN...
Buy asked 17/2, 2016 at 21:53
5
Solved
Most of the examples given in mocking framework website is to mock Interface. Let say NSubstitute that I'm currently using, all their mocking examples is to mock interface.
But in reality, I saw s...
Uptodate asked 29/8, 2012 at 9:3
2
I'm trying to create the unit test for a class which uses my EF Core DbContext:
public class MyContext : DbContext
{
public MyContext(DbContextOptions<MyContext> options) : base(options)
{...
Mawson asked 24/4, 2020 at 13:27
2
Solved
I use NSubstitute a lot. And I love it.
I am just looking into AutoFixture. It seems great!
I have seen AutoFixture for NSubstitute and seen a few examples in Moq on how to use this feature.
But...
Cereal asked 20/8, 2013 at 18:22
3
Solved
I'm about to take a decision about the mocking library for my next project.
and because I'm new to those libraries I made a quick search
I found that MOQ is much popular than NSubstitute and I ex...
Denationalize asked 18/1, 2016 at 9:12
2
Solved
I have a unit test where I use .Returns() to return some sample data:
[TestMethod]
public void TestRetrieveElementsInVersion()
{
IRetrieveElementSequence component = Substitute.For<IRetriev...
Prieto asked 2/12, 2016 at 0:23
1 Next >
© 2022 - 2025 — McMap. All rights reserved.