Top "Moq" questions

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

When mocking a class with Moq, how can I CallBase for just specific methods?

I really appreciate Moq's Loose mocking behaviour that returns default values when no expectations are set. It's convenient and saves …

unit-testing moq
Moq ReturnsAsync() with parameters

I'm trying to mock a repository's method like that public async Task<WhitelistItem> GetByTypeValue(WhitelistType type, string value) …

c# unit-testing moq
Moq fake one method but use real implementation of another

Given an interface IService that has Method1() and Method2(). I want to test that when Method1() throws an Exception, Method2() …

c# .net unit-testing nunit moq
Mock HttpRequest in ASP.NET Core Controller

I'm building a Web API in ASP.NET Core, and I want to unit test the controllers. I inject an …

c# unit-testing asp.net-core moq asp.net-core-webapi
Testing a Web API method that uses HttpContext.Current.Request.Files?

I am attempting to write a test for a Web API method that uses HttpContext.Current.Request.Files and after …

c# unit-testing asp.net-web-api moq httpcontext
Mocking EF core dbcontext and dbset

I am using ASP.NET Core 2.2, EF Core and MOQ. When I run the test I am getting this error: …

c# unit-testing asp.net-core entity-framework-core moq
How to MOQ an Indexed property

I am attempting to mock a call to an indexed property. I.e. I would like to moq the following: …

c# tdd mocking moq
C# WebApi Unit Testing and Mocking Controllers

I am working on this WebAPI project and I need to create unit tests for it. The base of the …

c# unit-testing asp.net-web-api moq xunit
How to add claims in a mock ClaimsPrincipal

I am trying to unit test my controller code which gets the information from the ClaimsPrincipal.Current. In the controller …

c# .net unit-testing asp.net-mvc-5 moq
How to mock Controller.User using moq

I have a couple of ActionMethods that queries the Controller.User for its role like this bool isAdmin = User.IsInRole("…

c# asp.net-mvc unit-testing mocking moq