moq Questions

3

Solved

I am unit testing a wrapper to the MongoDB C# driver. I have this line of code: Collection.Find(predicate).ToListAsync(); Where Collection is of type IMongoCollection<T> and Find(predicate...
Pierian asked 28/7, 2015 at 1:30

3

Solved

I want to Unit Test my Controller, but I'm having issues reading values from HttpContext.Session. I want to mock this piece from my Controller: HttpContext.Session.Get<int>(Foo) With Mock Ht...
Rocket asked 16/1, 2019 at 12:37

4

Solved

I am using the latest Moq (4.2.1502.911) in Visual Studio 2013 to mock an internal interface contained in another project. Both projects are signed with the same key. After searching here and elsew...
Nevins asked 6/5, 2015 at 22:52

8

I have a list like following in config.json file ` { "foo": { "bar": [ "1", "2", "3" ] } }` I am able to get the list at run-time using Configuration.GetSection("foo:bar").Get<List&l...
Unbuild asked 6/5, 2018 at 15:46

5

Solved

I'm writing unit test. For testing the method below, public async Task<Guid> CreateWebJobStatus(string blobId, Guid loggedInUserId, string loggedInUserEmail) { Guid webJobStatusId = Guid....
Selfsufficient asked 7/3, 2018 at 1:6

2

Solved

Is there a way to Mock ProtectedSessionStorage in a Blazor Server Side project? I tried below code but I am getting error : "Type to mock (ProtectedSessionStorage) must be an interface, a dele...
Owsley asked 6/4, 2022 at 14:57

4

Solved

I have a base class: public abstract class MyBaseClass { protected virtual void Method1() { } } and a derived class: public class MyDerivedClass : MyBaseClass { public void Method2() { ...
Resurrect asked 19/4, 2016 at 18:35

7

Solved

I'm trying to create a unit test for my service with a mocked DbContext. I created an interface IDbContext with the following functions: public interface IDbContext : IDisposable { IDbSet<T&gt...
Cristionna asked 21/9, 2014 at 14:24

2

My project requires unit testing. I am using constructor dependency injection in my controller. When I mock the injected dependency object in my unit testing project and call it in a test method. R...
Ruffi asked 6/7, 2021 at 18:7

2

We are using Azure cosmos client V3. For fetching data we are using GetItemLinqQueryable and ToFeedIterator for making it Async. It works well however while mocking/unit testing we are getting erro...
Moral asked 3/10, 2019 at 5:15

11

Solved

I need to test the following method: CreateOutput(IWriter writer) { writer.Write(type); writer.Write(id); writer.Write(sender); // many more Write()s... } I've created a Moq'd IWriter and I...
Kropp asked 15/5, 2012 at 13:53

2

Solved

I want to create a factory that will create commonly mocked objects for my unit tests. I've already managed to set up my tests so I can mock up a Linq2Sql DataContext and return an in memory table ...
Curl asked 23/6, 2011 at 19:3

11

Solved

I am trying to create a Mock (using Moq) for an IServiceProvider so that I can test my repository class: public class ApiResourceRepository : IApiResourceRepository { private readonly IServicePro...
Charron asked 2/6, 2017 at 19:53

4

I want to write unit test for try catch block(C#). Public ActionResult Index() { try { ------------- } catch(Exception ex) { throw; } } As you can see that i am using try-catch block in...
Amphibolite asked 14/4, 2014 at 7:1

7

Solved

I have a pair of tables with a parent/child relationship - incident and incidentDetails. I have a viewmodel that contains information from both of these tables. And I have a business layer method t...
Recondition asked 27/12, 2013 at 20:51

5

Solved

I am trying to fire the event handler assigned to my timer mock. How can I test this private method here? public interface ITimer { void Start(); double Interval { get; set; } event ElapsedEven...
Overword asked 20/1, 2012 at 11:49

3

I have used Microsoft Graph SDK in my project to call graph API, for this I need to use GraphServiceClient. To use GraphServiceClient, i have to add some helper classes, in which SDKHelper is a sta...
Instant asked 11/1, 2018 at 13:16

2

Some of my unit tests are failing after updating Microsoft.Extensions.Logging.Abstractions from Version=2.0.0.0 to Version=3.1.1.0. I have an ILogger mocked as so: var loggerMock = new Mock<IL...
Trader asked 11/5, 2020 at 20:37

0

I have an authorization handler in my web API project which needs to read route data (not query string). The code works perfectly fine, but I have hit a dead end trying to unit test it. Tried a lot...
Backset asked 22/12, 2023 at 14:20

1

Solved

I cannot run a unit test from the BLL/Service layer. The test mocks the Unit of Work because its a unit test for a service method. Thus, the uow mock has a null repository property which fails the ...
Rooftree asked 21/11, 2023 at 15:43

2

Solved

I am using Entity Framework core 1.0 rc2. Here is the class. public class ApplicationDbContext : DbContext { public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : bas...
Feint asked 4/6, 2016 at 13:3

7

Solved

I'm new to Moq. I'm mocking a PagingOptions class. Here is how the class looks like: public class PagingOptions { [Range(1, 99999, ErrorMessage = "Offset must be greater than 0.")] public int? ...
Calx asked 5/7, 2019 at 15:9

11

Solved

I'm trying to create a unit test for a class that calls into an async repository. I'm using ASP.NET Core and Entity Framework Core. My generic repository looks like this. public class EntityReposi...
Calliper asked 7/11, 2016 at 23:1

6

I'm trying to unit test a function that makes a call to an API. I have successfully done this using a mock HttpMessageHandler as below which allows me to fake a response from the API: private stat...
Marlowe asked 21/4, 2018 at 13:48

18

Solved

This is my controller: public class BlogController : Controller { private IDAO<Blog> _blogDAO; private readonly ILogger<BlogController> _logger; public BlogController(ILogger<Bl...
Sardanapalus asked 15/4, 2017 at 8:51

© 2022 - 2024 — McMap. All rights reserved.