Skip to main content
Filter by
Sorted by
Tagged with
-1 votes
2 answers
73 views

I need to have every invocation from the ILogger interface of a test, but I mock the ILogger interface in the class that is going to be tested, so it won't write to console and therefore the ILogger ...
FlorianD's user avatar
  • 113
3 votes
2 answers
155 views

I am creating a test to verify an object is passed to a method then verifying that the params match to the method in the call I am testing. The problem I am having that the object I am verifying ...
James Andrew Smith's user avatar
1 vote
1 answer
54 views

I provide a generic provider for Json serialization: public interface IJsonSerializerProvider { T? Deserialize<T>(string value); string Serialize(object? obj); object? ...
user2843511's user avatar
1 vote
1 answer
95 views

I am working with ASP.NET/.NET 4.8 application. My action method is as follows: public class TestController: System.Web.Http.ApiController { // pseudo code public async Task<...
Nitin S's user avatar
  • 7,713
4 votes
2 answers
195 views

I'm mocking a DbContext to auto-test classes that update the database. I'm using Entity Framework Core and .NET 5. Mock<MyDbContext> fakeDbContext = new Mock<MyDbContext>(); List<Book&...
Jean-David Lanz's user avatar
1 vote
1 answer
268 views

I have a factory class that let's say for arguments sake returns a car: public class CarFactory : ICarFactory { private const string carKey = "MyCarKey"; private readonly ...
sr28's user avatar
  • 5,258
0 votes
0 answers
359 views

I created a wrapper for FusionCache and am attempting to create a unit test. This is the method: public class FusionCacheService<TEntity> : IFusionCacheService<TEntity> where TEntity : ...
Cef's user avatar
  • 949
1 vote
4 answers
180 views

One unit test keeps failing when I run all unit tests, but doesn't fail when running it as a single test. I've marked it with a comment below. When firing the RulesEngine via Session.Fire() there is ...
Chris's user avatar
  • 855
1 vote
1 answer
105 views

I have a C# method with an out parameter: public bool TryGetNext(out Bestellung? bestellung); When setting up a mock for this method using Moq, how do I: Correctly handle the out parameter in the ...
FlorianD's user avatar
  • 113
-1 votes
1 answer
75 views

_mockScreener .Setup( x => x.CaptureTargetScreen( It.IsAny<string>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<Action<Bitmap>>() ...
Zach's user avatar
  • 5,941
0 votes
1 answer
32 views

I'm working on a unit test for a controller that calls a handler to retrieve a list of consumers multiple times. The handler calls GetItemsAsync() and returns either a null value or a list of ...
ChrisP's user avatar
  • 47
2 votes
3 answers
209 views

I have an ASP.NET Core Web API and services. To abstract EF Core's DbContext from service layer, I decided to use the repository pattern. However, the repository contains logic that cannot be unit ...
Quikler's user avatar
  • 190
1 vote
1 answer
190 views

I'm learning on how to write unit tests. From what I gathered, if I want to unit test a controller in a C# API, I need to mock/fake the inputs, the outputs and all dependencies of it. Next, I want to ...
Sonny's user avatar
  • 324
0 votes
1 answer
225 views

We have a class below that finds records in the list of tables provided in the parameters, and then deletes them within a transaction. public async Task<IEnumerable<DataTableRecordsResponse>&...
Mahyar Mottaghi Zadeh's user avatar
0 votes
0 answers
54 views

I have created the following extension method for an IQueryable to use it in Entity Framework DbContext moqs in unit tests public static DbSet<T> BuildMockDbSet<T>(this IQueryable<T>...
Wouter Vandenputte's user avatar
2 votes
3 answers
111 views

I have a CancelScheduledJob method, taking in the Id of a backgroundjob and using the JobStorage to retrieve this Id and cancelling the matching hangfire job: var mon = JobStorage.Current....
B.Quaink's user avatar
  • 586
0 votes
1 answer
79 views

PROBLEM TO SOLVE I'm trying to create a mock of interface ISomeService using Moq library which will wrap its real implementation SomeService. Right now I'm doing this manually like this: var instance =...
Arthur's user avatar
  • 201
1 vote
1 answer
84 views

How do i verify an init-call with Moq? I have the following property defined in an interface: public string Text { init; } I want to verify that init was called with a specific parameter. Is that ...
Stevie's user avatar
  • 491
1 vote
0 answers
72 views

In the following example, I'm getting some behavior I wouldn't expect: [Test] public void Test() { var mockGetter = new Mock<IHostedServiceGetter>(); var mockService = new Mock<...
ewok's user avatar
  • 21.7k
2 votes
1 answer
51 views

I am writing test code with xUnit and mock(moq) on C#. However, the program through the interface cannot be executed. The test code is as follows. // test code public void test1(string id, EntityA ...
Tatsuya's user avatar
  • 31
1 vote
1 answer
192 views

I'm new to unit testing, so I'm not sure what I'm looking for. I'm trying to convert a project using Moq to NSubstitute. Question: How do you convert this line from Moq to NSubstitute services....
RoLYroLLs's user avatar
  • 3,225
0 votes
0 answers
27 views

I am writing some unit tests for a backend that uses MS Graph to communicate with Azure, specifically the endpoints to add and remove users in Entra groups. But when writing the test for removing ...
Hotbullets95's user avatar
0 votes
1 answer
80 views

The following method works perfectly with SQL Server, no issues. public async Task<IEnumerable<HashRecord>> GetLatestHashes(long jobId, CancellationToken token) { var context = ...
JaimeCamargo's user avatar
1 vote
1 answer
218 views

I am trying to Moq a Rabbit MQ method. ValueTask BasicPublishAsync<TProperties>(string exchange, string routingKey, bool mandatory, TProperties basicProperties, ReadOnlyMemory<byte> ...
MCFH's user avatar
  • 147
2 votes
1 answer
36 views

I'm unit testing a code similar to the one below. There is one use case where I want the GetAsync to throw an exception to be caught in the catch block. try { var response = await client.GetAsync(...
Richard77's user avatar
  • 21.9k

1
2 3 4 5
118