FastMoq 1.22.529.1812
Prefix ReservedSee the version list below for details.
dotnet add package FastMoq --version 1.22.529.1812
NuGet\Install-Package FastMoq -Version 1.22.529.1812
<PackageReference Include="FastMoq" Version="1.22.529.1812" />
<PackageVersion Include="FastMoq" Version="1.22.529.1812" />
<PackageReference Include="FastMoq" />
paket add FastMoq --version 1.22.529.1812
#r "nuget: FastMoq, 1.22.529.1812"
#:package FastMoq@1.22.529.1812
#addin nuget:?package=FastMoq&version=1.22.529.1812
#tool nuget:?package=FastMoq&version=1.22.529.1812
FastMoq
Easy and fast extension of Moq Mocking framework for mocking and auto injection of classes.
Features
- Auto Injection into tested component constructors
- Best guess picks the multiple parameter constructor over the default constructor.
- Specific mapping allows the tester to create an instance using a specific constructor and specific data.
- Auto Mocking creation whenever a mock is first used.
Targets
- .NET 5
- .NET 6
Test Base Constructor Parameters
The following constructor parameters allow customization on the testing classes.
Action<Mocks>? setupMocksAction
Func<TComponent> createComponentAction
Action<TComponent?>? createdComponentAction
Examples
Class being tested
Testing this class will auto inject IFileSystem.
public class TestClassNormal : ITestClassNormal
{
public event EventHandler TestEvent;
public IFileSystem FileSystem { get; set; }
public TestClassNormal() { }
public TestClassNormal(IFileSystem fileSystem) => FileSystem = fileSystem;
public void CallTestEvent() => TestEvent?.Invoke(this, EventArgs.Empty);
}
Fast Start
public class TestClassNormalTestsDefaultBase : TestBase<TestClassNormal>
{
[Fact]
public void Test1()
{
Component.FileSystem.Should().NotBeNull();
Component.FileSystem.Should().BeOfType<MockFileSystem>();
Component.FileSystem.File.Should().NotBeNull();
Component.FileSystem.Directory.Should().NotBeNull();
}
}
Pre-Test Setup
public class TestClassNormalTestsSetupBase : TestBase<TestClassNormal>
{
public TestClassNormalTestsSetupBase() : base(SetupMocksAction) { }
private static void SetupMocksAction(Mocks mocks)
{
var iFile = new FileSystem().File;
mocks.Strict = true;
mocks.Initialize<IFileSystem>(mock => mock.Setup(x => x.File).Returns(iFile));
}
[Fact]
public void Test1()
{
Component.FileSystem.Should().NotBeNull();
Component.FileSystem.Should().NotBeOfType<MockFileSystem>();
Component.FileSystem.File.Should().NotBeNull();
Component.FileSystem.Directory.Should().BeNull();
}
}
Custom Setup, Creation, and Post Create routines
public class TestClassNormalTestsFull : TestBase<TestClassNormal>
{
private static bool testEventCalled;
public TestClassNormalTestsFull() : base(SetupMocksAction, CreateComponentAction, CreatedComponentAction) => testEventCalled = false;
private static void CreatedComponentAction(TestClassNormal? obj) => obj.TestEvent += (_, _) => testEventCalled = true;
private static TestClassNormal CreateComponentAction(Mocks mocks) => new(mocks.GetObject<IFileSystem>());
private static void SetupMocksAction(Mocks mocks)
{
var mock = new Mock<IFileSystem>();
var iFile = new FileSystem().File;
mocks.Strict = true;
mocks.AddMock(mock, true);
mocks.Initialize<IFileSystem>(xMock => xMock.Setup(x => x.File).Returns(iFile));
}
[Fact]
public void Test1()
{
Component.FileSystem.Should().Be(Mocks.GetMock<IFileSystem>().Object);
Component.FileSystem.Should().NotBeNull();
Component.FileSystem.File.Should().NotBeNull();
Component.FileSystem.Directory.Should().BeNull();
testEventCalled.Should().BeFalse();
Component.CallTestEvent();
testEventCalled.Should().BeTrue();
Mocks.Initialize<IFileSystem>(mock => mock.Setup(x => x.Directory).Returns(new FileSystem().Directory));
Component.FileSystem.Directory.Should().NotBeNull();
}
}
Interface Type Map
A map is available to decide which class is injected for the given interface.
Two classes
public class TestClassDouble1 : ITestClassDouble {}
public class TestClassDouble2 : ITestClassDouble {}
Mapping
This code maps ITestClassDouble to TestClassDouble1 when testing a component with ITestClassDouble.
Mocks.AddType<ITestClassDouble, TestClassDouble1>();
Auto injection
Auto injection allows creation of components by selecting the constructor with the matching parameter types and data.
private static TestClassNormal CreateComponentAction() => Mocks.CreateInstance(new MockFileSystem()); // CreateInstance matches the parameters and types with the Component constructor.
License - MIT
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 is compatible. net5.0-windows was computed. net6.0 is compatible. 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. |
-
net5.0
- coverlet.collector (>= 3.0.2)
- Microsoft.CodeAnalysis.Common (>= 3.8.0)
- Microsoft.CodeAnalysis.csHARP (>= 3.8.0)
- Moq (>= 4.17.2)
- System.IO.Abstractions (>= 17.0.15)
- System.IO.Abstractions.TestingHelpers (>= 17.0.15)
-
net6.0
- coverlet.collector (>= 3.0.2)
- Microsoft.CodeAnalysis.Common (>= 3.8.0)
- Microsoft.CodeAnalysis.csHARP (>= 3.8.0)
- Moq (>= 4.17.2)
- System.IO.Abstractions (>= 17.0.15)
- System.IO.Abstractions.TestingHelpers (>= 17.0.15)
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 |
|---|---|---|
| 4.4.2 | 114 | 5/2/2026 |
| 4.4.1 | 98 | 5/1/2026 |
| 4.4.0 | 90 | 4/29/2026 |
| 4.3.5 | 110 | 4/24/2026 |
| 4.3.4 | 104 | 4/21/2026 |
| 4.3.3 | 101 | 4/21/2026 |
| 4.3.2 | 104 | 4/20/2026 |
| 4.3.1 | 103 | 4/19/2026 |
| 4.3.0 | 100 | 4/19/2026 |
| 4.2.1 | 106 | 4/17/2026 |
| 4.2.0 | 115 | 4/17/2026 |
| 4.1.2 | 126 | 4/13/2026 |
| 4.1.1 | 113 | 4/12/2026 |
| 4.1.0 | 112 | 4/11/2026 |
| 4.0.3 | 124 | 4/10/2026 |
| 4.0.2 | 116 | 4/7/2026 |
| 1.22.529.1812 | 1,781 | 5/29/2022 |