Moq.AutoMock
4.0.2
See the version list below for details.
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" />
<PackageReference Include="Moq.AutoMock" />
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.2
#tool nuget:?package=Moq.AutoMock&version=4.0.2
Moq.AutoMock

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.
Usage
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>();
Extracting Mocks
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();
HttpClient Support
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.
Documentation
For more detailed documentation, including information about the built-in source generators that can automatically generate test boilerplate code, see the docs folder.
- AutoMocker API Reference
- HttpClient Support - Mock HTTP dependencies with fluent setup and verification
- Source Generators - Learn about automatic code generation for constructor tests, options configuration, logging, and more
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Moq (>= 4.20.72)
- NonBlocking (>= 2.1.2)
NuGet packages (35)
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 |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.3-ci0882 | 744 | 4/21/2026 |
| 4.0.3-ci0880 | 77 | 4/21/2026 |
| 4.0.3-ci0864 | 1,103 | 4/3/2026 |
| 4.0.2 | 48,062 | 4/3/2026 |
| 4.0.1 | 50,558 | 3/16/2026 |
| 4.0.1-ci0862 | 92 | 4/3/2026 |
| 4.0.1-ci0855 | 101 | 3/25/2026 |
| 4.0.1-ci0854 | 95 | 3/25/2026 |
| 4.0.1-ci0852 | 93 | 3/25/2026 |
| 4.0.1-ci0846 | 104 | 3/16/2026 |
| 4.0.1-ci0841 | 148 | 3/15/2026 |
| 4.0.0 | 4,105 | 3/15/2026 |
| 4.0.0-ci0833 | 807 | 3/4/2026 |
| 4.0.0-ci0828 | 855 | 2/24/2026 |
| 4.0.0-ci0823 | 313 | 2/20/2026 |
| 4.0.0-ci0820 | 186 | 2/18/2026 |
| 3.6.2-ci0814 | 6,826 | 2/16/2026 |
| 3.6.2-ci0808 | 207 | 2/13/2026 |
| 3.6.2-ci0796 | 412 | 2/6/2026 |
| 3.6.2-ci0793 | 103 | 2/6/2026 |