Moq.AutoMock 3.6.1

There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Moq.AutoMock --version 3.6.1
                    
NuGet\Install-Package Moq.AutoMock -Version 3.6.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Moq.AutoMock" Version="3.6.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Moq.AutoMock" Version="3.6.1" />
                    
Directory.Packages.props
<PackageReference Include="Moq.AutoMock" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Moq.AutoMock --version 3.6.1
                    
#r "nuget: Moq.AutoMock, 3.6.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Moq.AutoMock@3.6.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Moq.AutoMock&version=3.6.1
                    
Install as a Cake Addin
#tool nuget:?package=Moq.AutoMock&version=3.6.1
                    
Install as a Cake Tool

Moq.AutoMock Continuous NuGet Status

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();
Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (33)

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 (29)

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
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.
vchelaru/Gum
Flexible layout tool for creating UI on any platform
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
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
matthewrenze/clean-architecture-core
A sample app for my online course "Clean Architecture: Patterns, Practices, and Principles" in .NET Core
Version Downloads Last Updated
3.6.2-ci0796 95 2/6/2026
3.6.2-ci0793 36 2/6/2026
3.6.2-ci0790 423 1/29/2026
3.6.2-ci0779 5,284 12/24/2025
3.6.2-ci0768 776 12/5/2025
3.6.1 151,534 12/4/2025
3.6.1-ci0761 1,036 12/2/2025
3.6.0 13,317 12/1/2025
3.6.0-ci0759 670 12/2/2025
3.6.0-ci0756 664 12/2/2025
3.6.0-ci0745 499 11/24/2025
3.6.0-ci0737 212 11/23/2025
3.6.0-ci0734 151 11/23/2025
3.6.0-ci0731 508 11/20/2025
3.6.0-ci0729 454 11/19/2025
3.6.0-ci0726 1,431 11/18/2025
3.6.0-ci0724 396 11/18/2025
3.6.0-ci0722 465 11/17/2025
3.6.0-ci0720 609 11/10/2025
3.6.0-ci0717 259 11/10/2025
3.6.0-ci0713 252 11/10/2025
3.6.0-ci0596 95,141 5/24/2024
3.6.0-ci0594 250 5/24/2024
3.6.0-ci0592 3,992 5/14/2024
3.6.0-ci0590 2,199 5/13/2024
3.6.0-ci0546 13,605 2/8/2024
3.6.0-ci0544 325 2/8/2024
3.6.0-ci0539 8,061 2/3/2024
3.6.0-ci0532 666 2/2/2024
3.5.0 10,688,135 1/4/2023
3.5.0-ci0332 778 1/4/2023
3.5.0-ci0331 809 1/4/2023
3.5.0-ci0287 22,435 10/10/2022
3.5.0-ci0285 2,129 10/3/2022
3.4.0 2,949,385 6/1/2022
3.4.0-ci0283 790 10/3/2022
3.4.0-ci0280 800 10/3/2022
3.4.0-ci0278 749 10/3/2022
3.4.0-ci0274 795 10/3/2022
3.4.0-ci0270 802 10/3/2022
3.4.0-ci0265 794 10/3/2022
3.4.0-ci0259 732 10/3/2022
3.4.0-ci0252 1,143 5/31/2022
3.3.1-ci0247 3,534 5/3/2022
3.3.1-ci0245 795 5/3/2022
3.3.1-ci0242 3,227 4/25/2022
3.3.0 1,061,378 2/23/2022
3.3.0-ci0240 956 4/25/2022
3.3.0-ci0221 1,416 2/21/2022
3.2.0 379,986 2/4/2022
3.2.0-ci0219 839 2/21/2022
3.2.0-ci0217 780 2/21/2022
3.2.0-ci0214 863 2/21/2022
3.2.0-ci0207 15,152 12/14/2021
3.2.0-ci0205 3,903 12/14/2021
3.1.0 895,299 10/29/2021
3.0.0 1,167,467 6/28/2021
3.0.0-ci0203 912 12/6/2021
3.0.0-ci0198 949 10/25/2021
3.0.0-ci0195 941 10/25/2021
3.0.0-ci0192 890 9/18/2021
3.0.0-ci0183 862 9/1/2021
3.0.0-ci0177 983 6/25/2021
3.0.0-ci0170 3,725 5/12/2021
3.0.0-ci0168 3,948 4/22/2021
3.0.0-ci0164 908 4/20/2021
3.0.0-ci0155 2,778 4/13/2021
3.0.0-ci0146 57,528 1/22/2021
3.0.0-ci0145 1,844 1/16/2021
2.3.0 1,648,168 12/15/2020
2.3.0-ci0136 1,059 12/15/2020
2.2.0.124 157,596 12/8/2020
2.2.0.123-ci 1,092 12/8/2020
2.2.0.120-ci 38,613 11/24/2020
2.2.0.115-ci 1,068 11/23/2020
2.2.0.113-ci 1,028 11/23/2020
2.1.0.104-ci 1,107 11/23/2020
2.1.0.99-ci 1,091 11/23/2020
2.1.0 762,856 9/9/2020
2.1.0-ci0019 1,124 9/9/2020
2.0.1 674,706 5/24/2020
2.0.1-ci0017 1,222 5/24/2020
2.0.0 212,599 4/6/2020
2.0.0-ci0015 1,197 5/5/2020
2.0.0-ci0014 1,143 5/5/2020
2.0.0-ci0012 1,206 4/6/2020
2.0.0-ci0011 1,189 4/6/2020
1.2.0.131-pre 397,475 2/5/2020
1.2.0.128-pre 1,187 2/5/2020
1.2.0.127-pre 1,237 2/5/2020
1.2.0.122-pre 117,654 5/17/2019
1.2.0.120 2,411,911 12/6/2018
1.2.0.118-pre 1,447 12/6/2018
1.2.0.116-pre 1,446 12/6/2018
1.2.0.113-pre 5,612 8/1/2018
1.2.0.111 186,701 7/25/2018
1.2.0.109-pre 1,716 7/25/2018
1.1.0.107-pre 1,688 7/25/2018
1.1.0.105-pre 1,785 7/25/2018
1.1.0.104-pre 1,903 7/25/2018
1.1.0.96 24,402 6/8/2018
1.1.0.94-pre 2,078 6/8/2018
1.1.0.92-pre 2,042 6/8/2018
1.1.0.85-pre 2,177 6/7/2018
1.1.0.68-pre 2,005 6/4/2018
1.0.60 139,479 5/31/2018
1.0.56-pre 2,025 5/31/2018
1.0.52-pre 2,014 5/31/2018
1.0.48-pre 2,072 5/31/2018
1.0.44-pre 2,035 5/31/2018
1.0.41-pre 2,078 5/30/2018
1.0.38-pre 2,077 5/30/2018
1.0.35-pre 2,040 5/30/2018
1.0.32-pre 2,057 5/30/2018
0.4.0 767,431 9/7/2015
0.3.2.1 132,381 12/27/2012
0.3.2 2,888 8/23/2012
0.3.1 2,449 8/23/2012
0.3.0 4,516 8/23/2012
0.2.2 3,678 7/18/2012
0.2.1 2,509 7/18/2012
0.2.0 2,466 7/18/2012
0.1.0 27,769 7/18/2012