Skip to main content

Questions tagged [moq]

Moq is a strongly typed and minimalistic mocking framework for .NET.

0 votes
0 answers
25 views

How to create a test double for DataLakeDirectoryClient object of Azure.Storage.Files.DataLake c# library?

My code is accessing or precisely downloading the file from Azure's DataLake Storage Gen2. That file is placed by an upstream system of our application. The files are organized hierarchy of ...
Siva Sankaran's user avatar
0 votes
0 answers
17 views

Refernce to RouteValueDictionary claims it is defined in System.Web but could not be found

I am currently learning to unit test in ASP.NET MVC, and I have encountered an issue while working on my Controller Test class. The error message states, "Reference to RouteValueDictionary claims ...
Stutee Rath's user avatar
-1 votes
0 answers
33 views

How to Moq and test a class that gets IOptions injected and has method that calls a SQL Server stored procedure

Say I have a basic "service" class that looks something like this. One of the methods uses SqlClient to make a connection to a SQL Server database and make a stored procedure call and ...
bitshift's user avatar
  • 6,550
1 vote
2 answers
70 views

Mock constructor arguments of inherited classes which differ from parent class costructor arguments

I'm writing tests for controllers actions of ASP.Net Core application. All controllers of my app inherited from base controller, let's call it MyBaseController. Constructor of this class looks like ...
Ivan Kozlov's user avatar
-4 votes
0 answers
43 views

Creating a mock of the async method in the repository

My problem is I have handler. Handler has got BussinessRules which is void method. BussinessRules (async void method) has got an getasync method. I want to unit test of handler with mock. BUSINESSRULE ...
gandalfthegray's user avatar
0 votes
1 answer
37 views

Mocking created object which then added to dictionary

How can I mock object which is created with the action in the runtime? In the following code I want to mock the Connection class for the unit test. private readonly Dictionary<IPEndPoint, ...
Hamza's user avatar
  • 5
0 votes
0 answers
68 views

Create a function that takes method name and verify if that method was called

I would like to create a method that can take a method name and verify if method was called. I have implemented the following code block and wanted to investigate if there is a better way to do it ...
Hamza's user avatar
  • 5
0 votes
0 answers
40 views

Mocked DbContext throws exception when execute async operations

I have the following problem, maybe one of you had something similar. I want to mock DbContext to test my repository class. This is a code which i want to test: public async Task<bool> ...
Mauty404's user avatar
1 vote
1 answer
64 views

xUnit test throws TypeInitializationException

I have an xUnit test project within a net8.0 Maui solution. All projects in the solution are targeting the same Windows versions (Mac and Android excluded) I have set up the following test to check ...
Darren Rockett's user avatar
0 votes
0 answers
18 views

Using Moq how can I setup a method that has an out parameter with that out parameter returing a mock of another interface? [duplicate]

I have an interface that has a method which has an out parameter which is another interface. Something like this: bool GetA(string name, out IA a); I can find plenty of examples of doing this with ...
JonB's user avatar
  • 1
1 vote
1 answer
61 views

Mock EncryptAsync method and return EncryptResult from Azure.Security.KeyVault.Keys.Cryptography

I am trying to mock the functionality of the EncryptAsync method in Azure.Security.KeyVault.Keys.Cryptography.CryptographyClient. This is the method I am trying to cover in my unit test. public ...
mohanraj's user avatar
0 votes
0 answers
31 views

Mocking IDbContextFactory with NSubstitute, disposes context

I am using IDbContextFactory in a Blazor server application. I want to mock the services. I can do this using Moq, but when switching to NSubstitute, I run into a problem: only the Save method in the ...
Sulieman Mansouri's user avatar
0 votes
1 answer
40 views

Unit testing a class that contains multiple continuous tasks at the background

I would like to unit test the WpaConnection class which contains multiple continuous tasks. Starting of these task is dependent on TCP connection. I would like to gather some information on what would ...
Hamza's user avatar
  • 5
0 votes
0 answers
62 views

Having trouble mocking response from Microsoft Graph Api 5.54.0

I have a service that is a wrapper around Microsoft Graph that I am trying to unit test. I have my mocking working, but my mocked response always returns as null. Here is the setup for my mocks: ...
Josh's user avatar
  • 16.5k
1 vote
1 answer
105 views

How to mock TaskOrchestrationContext.CallHttpAsync to test an Azure Function .net isolated method

I have this Azure Function orchestrator using Microsoft.Azure.Functions.Worker; using Microsoft.DurableTask; using System; using System.Collections.Generic; using System.Linq; using System.Net.Http; ...
Chris Rockwell's user avatar

15 30 50 per page
1
2 3 4 5
387