Many.Mocks 2.1.0

.NET Standard 2.1
There is a newer prerelease version of this package available.
See the version list below for details.
Install-Package Many.Mocks -Version 2.1.0
dotnet add package Many.Mocks --version 2.1.0
<PackageReference Include="Many.Mocks" Version="2.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Many.Mocks --version 2.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Many.Mocks, 2.1.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Many.Mocks as a Cake Addin
#addin nuget:?package=Many.Mocks&version=2.1.0

// Install Many.Mocks as a Cake Tool
#tool nuget:?package=Many.Mocks&version=2.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.


Time-saving extensions to create and setup large number of mocks using Moq framework.

👉Download releases at

How to use

You have a class with lots of mocks...

public class UserManager : UserManager<User>
        /// <summary>
        /// Ctor. 1
        /// </summary>
        public UserManager(IUserStore<User> store, 
                            IOptions<IdentityOptions> optionsAccessor)
        /// <summary>
        /// Ctor. 2
        /// </summary>
        public UserManager(IUserStore<User> store, 
                            IOptions<IdentityOptions> optionsAccessor,
                            IPasswordHasher<User> passwordHasher, 
                            IEnumerable<IUserValidator<User>> userValidators, 
                            IEnumerable<IPasswordValidator<User>> passwordValidators, 
                            ILookupNormalizer keyNormalizer, 
                            IdentityErrorDescriber errors, 
                            IServiceProvider services,
                            ILogger<UserManager<User>> logger)
            : base(store, optionsAccessor, passwordHasher, userValidators, passwordValidators, keyNormalizer, errors, services, logger)

        public void Method(IUserPasswordStore<User> store) { ... }
        public void Method(IUserStore<TUser> store) { ... }

How to generate a bag of mocks from any method or constructor?

  1. You can get a bag of nedeed mocks just typing:
var mocks = typeof(UserManager).GetMocksFromConstructors(); //11 mocks: 2 from ctor. 1 and 9 from ctor. 2
  1. And also you can get only mocks from one specific constructor:
var mocks = typeof(UserManager).GetMocksFromConstructors(new List<Type>{ typeof(IUserStore<User>), typeof(IOptions<IdentityOptions>) }); //2 mocks from ctor. 1
  1. Same works for any method:
var mocks = typeof(UserManager).GetMocksFrom("method", new List<Type>{ typeof(IUserPasswordStore<User>) }); //1 mock

If a class is not proxiable and no mock can be created you can check it in the details:

var noMockCouldBeGeneratedForTheseClasses = mocks.Mocks.Where(p => !p.Generated); //Get the errors
var ex = noMockCouldBeGeneratedForTheseClasses.Error; //The thrown exception during mock generation

How to generate a mock for every property type of a class/interface?

Just ask for them 😃

var mocks = typeof(UserManager).GetMocksFromProperties();

How to instantiate a class injecting a bag of mocks?

var mocks = typeof(UserManager)
                .Mocks.Select(p => p.Details); //Get mocks from constructor

var result = mocks.UseToTryInstantiate(out UserManager result); //Get the instance

How to instantiate a class injecting a bag of mocks and custom ones?

var mocks = typeof(UserManager)
                .Mocks.Select(p => p.Details); //Get mocks from constructor

var customMockToReplace = new Mock<IServiceProvider>();
var result = mocks.UseToTryInstantiate(new List<Mock>() {customMockToReplace}, out UserManager result); //Get the instance replacing your custom mock
Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
.NET Core netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.1
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.1

    • Moq (>= 4.13.1)

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.0.0-beta1 72 4/7/2022
2.1.0 85 3/31/2022
2.0.0 139 12/6/2021
1.1.0 262 11/29/2020
1.0.0 1,189 6/12/2020
0.5.0 302 6/11/2020
0.3.7 545 11/25/2019
0.3.6 454 11/22/2019
0.3.5 470 11/22/2019
0.3.4 446 11/20/2019
0.3.3 443 11/19/2019
0.3.2 438 11/19/2019
0.3.1 457 11/19/2019
0.3.0-beta1 416 11/19/2019
0.2.0-beta1 397 11/18/2019

- Performance improvements when getting mocks
- MockItem is at Many.Mocks namespace now
- Minor issues and documentation errors fixed
- Support for NETFramework removed. Only Netstandard 2.1 now
- Documentation Xml file available