![]() |
VOOZH | about |
dotnet add package Moq.AutoMock --version 4.0.2
NuGet\Install-Package Moq.AutoMock -Version 4.0.2
<PackageReference Include="Moq.AutoMock" Version="4.0.2" />
<PackageVersion Include="Moq.AutoMock" Version="4.0.2" />Directory.Packages.props
<PackageReference Include="Moq.AutoMock" />Project file
paket add Moq.AutoMock --version 4.0.2
#r "nuget: Moq.AutoMock, 4.0.2"
#:package Moq.AutoMock@4.0.2
#addin nuget:?package=Moq.AutoMock&version=4.0.2Install as a Cake Addin
#tool nuget:?package=Moq.AutoMock&version=4.0.2Install as a Cake Tool
An automocking container for Moq. Use this if you're invested in your IoC container and want to decouple your unit tests from changes to their constructor arguments.
Simplest usage is to build an instance that you can unit test.
var mocker = new AutoMocker();
var car = mocker.CreateInstance<Car>();
car.DriveTrain.ShouldNotBeNull();
car.DriveTrain.ShouldImplement<IDriveTrain>();
Mock<IDriveTrain> mock = Mock.Get(car.DriveTrain);
If you have a special instance that you need to use, you can register it
with .Use(...). This is very similar to registrations in a regular IoC
container (i.e. For<IService>().Use(x) in StructureMap).
var mocker = new AutoMocker();
mocker.Use<IDriveTrain>(new DriveTrain());
// OR, setup a Mock
mocker.Use<IDriveTrain>(x => x.Shaft.Length == 5);
var car = mocker.CreateInstance<Car>();
At some point you might need to get to a mock that was auto-generated. For
this, use the .Get<>() or .GetMock<>() methods.
var mocker = new AutoMocker();
// Let's say you have a setup that needs verifying
mocker.Use<IDriveTrain>(x => x.Accelerate(42) == true);
var car = mocker.CreateInstance<Car>();
car.Accelerate(42);
// Then extract & verify
var driveTrainMock = mocker.GetMock<IDriveTrain>();
driveTrainMock.VerifyAll();
Alternately, there's an even faster way to verify all mocks in the container:
var mocker = new AutoMocker();
mocker.Use<IDriveTrain>(x => x.Accelerate(42) == true);
var car = mocker.CreateInstance<Car>();
car.Accelerate(42);
// This method verifies all mocks in the container
mocker.VerifyAll();
AutoMocker automatically resolves HttpClient dependencies with a mocked
HttpMessageHandler. Use the built-in extension methods to set up responses
and verify requests with minimal boilerplate.
var mocker = new AutoMocker();
mocker.SetupHttpGet("/users")
.ReturnsHttpResponse(HttpStatusCode.OK, """{"users": ["Alice", "Bob"]}""");
var service = mocker.CreateInstance<UserService>();
var response = await service.GetUsersAsync();
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
mocker.VerifyHttpGet("https://example.com/api/users", Times.Once());
Setup methods are available for all common HTTP verbs (SetupHttpGet,
SetupHttpPost, SetupHttpPut, SetupHttpDelete, SetupHttpHead) with
matching by URL substring or expression predicate. Sequential responses are
supported for testing retry logic.
For more detailed documentation, including information about the built-in source generators that can automatically generate test boilerplate code, see the .
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 was computed. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 5 NuGet packages that depend on Moq.AutoMock:
| Package | Downloads |
|---|---|
|
Reo.Core.Testing
Package Description |
|
|
Reo.Core.IntegrationTesting
Package Description |
|
|
Reo.Core.CodeGeneratorTesting
Package Description |
|
|
Relay.Core.Plugins.NUnit
Plugins available for the Core framework |
|
|
Relay.Web.Testing
A web testing framework built for .NET Core |
Showing the top 20 popular GitHub repositories that depend on Moq.AutoMock:
| Repository | Stars |
|---|---|
|
Ombi-app/Ombi
Want a Movie or TV Show on Plex/Emby/Jellyfin? Use Ombi!
|
|
|
dotnet/extensions
This repository contains a suite of libraries that provide facilities commonly needed when creating production-ready applications.
|
|
|
matthewrenze/clean-architecture-demo
A sample app for my online course "Clean Architecture: Patterns, Practices, and Principles"
|
|
|
colinin/abp-next-admin
这是基于vue-vben-admin 模板适用于abp vNext的前端管理项目
|
|
|
vknet/vk
Vkontakte API for .NET
|
|
|
lkurzyniec/netcore-boilerplate
Boilerplate of API in .NET 10
|
|
|
vchelaru/Gum
Flexible layout tool for creating UI on any platform
|
|
|
IngvarX/Camelot
Camelot is a cross-platform file manager written in C#
|
|
|
planetarium/libplanet
Blockchain in C#/.NET for on-chain, decentralized gaming
|
|
|
sandreas/tone
tone is a cross platform audio tagger and metadata editor to dump and modify metadata for a wide variety of formats, including mp3, m4b, flac and more. It has no dependencies and can be downloaded as single binary for Windows, macOS, Linux and other common platforms.
|
|
|
karpach/remote-shutdown-pc
Remote Shutdown Manager is a windows application, which gives an ability to shutdown, suspend, hibernate PC or turn screen off using HTTP GET request.
|
|
|
appget/appget
Free and open package manager for Windows.
|
|
|
philosowaffle/peloton-to-garmin
Convert workout data from Peloton into JSON/TCX/FIT files and automatically upload to Garmin Connect
|
|
|
IEvangelist/azure-cosmos-dotnet-repository
Wraps the .NET SDK for Azure Cosmos DB abstracting away the complexity, exposing a simple CRUD-based repository pattern
|
|
| Eremex/controls-demo | |
|
neo4j/neo4j-dotnet-driver
Neo4j Bolt driver for .NET
|
|
|
notion-dotnet/notion-sdk-net
A Notion SDK for .Net
|
|
|
whuanle/maomi
Maomi 框架是一个简单的、简洁的开发框架,除了框架本身提供的功能之外,Maomi 还作为一个易于阅读的开源项目,能够给开发者提供设计框架的思路和代码。
|
|
|
Lombiq/Orchard-Training-Demo-Module
Demo Orchard Core CMS and Orchard 1.x module for for you to become an Orchard developer. This module completes the training materials under https://orcharddojo.net.
|
|
|
aykutalparslan/Ferrite
Experimental Telegram Server
|
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.3-ci0905 | 205 | 6/15/2026 |
| 4.0.3-ci0895 | 450 | 5/31/2026 |
| 4.0.3-ci0893 | 131 | 5/28/2026 |
| 4.0.3-ci0890 | 113 | 5/28/2026 |
| 4.0.3-ci0882 | 1,469 | 4/21/2026 |
| 4.0.3-ci0880 | 110 | 4/21/2026 |
| 4.0.3-ci0864 | 1,134 | 4/3/2026 |
| 4.0.2 | 234,495 | 4/3/2026 |
| 4.0.1 | 70,982 | 3/16/2026 |
| 4.0.1-ci0862 | 117 | 4/3/2026 |
| 4.0.1-ci0855 | 121 | 3/25/2026 |
| 4.0.1-ci0854 | 120 | 3/25/2026 |
| 4.0.1-ci0852 | 118 | 3/25/2026 |
| 4.0.1-ci0846 | 126 | 3/16/2026 |
| 4.0.1-ci0841 | 182 | 3/15/2026 |
| 4.0.0 | 5,801 | 3/15/2026 |
| 4.0.0-ci0833 | 1,120 | 3/4/2026 |
| 4.0.0-ci0828 | 883 | 2/24/2026 |
| 4.0.0-ci0823 | 335 | 2/20/2026 |
| 4.0.0-ci0820 | 205 | 2/18/2026 |