![]() |
VOOZH | about |
dotnet add package FastMoq.Core --version 4.4.2
NuGet\Install-Package FastMoq.Core -Version 4.4.2
<PackageReference Include="FastMoq.Core" Version="4.4.2" />
<PackageVersion Include="FastMoq.Core" Version="4.4.2" />Directory.Packages.props
<PackageReference Include="FastMoq.Core" />Project file
paket add FastMoq.Core --version 4.4.2
#r "nuget: FastMoq.Core, 4.4.2"
#:package FastMoq.Core@4.4.2
#addin nuget:?package=FastMoq.Core&version=4.4.2Install as a Cake Addin
#tool nuget:?package=FastMoq.Core&version=4.4.2Install as a Cake Tool
FastMoq is a provider-first .NET testing framework for auto-mocking, dependency-aware construction, and test-focused object creation. In v4, it ships with a bundled reflection default and optional Moq or NSubstitute integrations when you need provider-specific arrange syntax.
FastMoq is test-framework agnostic and can be used from xUnit, NUnit, MSTest, or other .NET test frameworks.
If you are comparing FastMoq with direct mock-provider usage or deciding whether it fits your test stack, use this order:
Why FastMoq below for the high-level value proposition.3.0.0 public line.reflection provider, start with Getting Started Guide..Setup(...) syntax, read Provider Selection Guide before copying any Moq-fluent examples.GetOrCreateMock(...), Verify(...), VerifyNoOtherCalls(...), VerifyLogged(...), WhenHttpRequest(...), or AddType(...)IFastMock<T> provider extensions such as Setup(...), SetupGet(...), or AsNSubstitute() when the selected provider package exposes themAsMoq() or provider-native escape hatches only for the remaining provider-specific gapsDirect mock-provider tests often spend more effort on declaring mocks, wiring constructors, and repeating framework plumbing than on the behavior under test. FastMoq moves that harness work into a provider-first layer so tests stay focused on the behavior, not the object graph.
MockerTestBase<TComponent> maintains a mock registry, so you retrieve what you need with GetOrCreateMock<T>() instead of declaring a field for every constructor dependencynew MyService(dep1.Object, dep2.Object, ...) wiring in each testTestAllConstructorParameters(...) replaces a test-per-parameter pattern with one helper-driven null-guard assertionFastMoq ships with a bundled reflection provider, so you can start without taking a dependency on a mock library. When you want provider-native arrange syntax, add FastMoq.Provider.Moq or FastMoq.Provider.NSubstitute and keep the rest of the harness the same. The verification surface stays provider-neutral through Verify(...), VerifyNoOtherCalls(...), VerifyLogged(...), and TimesSpec, which keeps tests portable if you switch providers later.
ILogger<T>, ILoggerFactory, IFileSystem, and HttpClient do not need bespoke setup before you can use themGetMockDbContext<TContext>(), WhenHttpRequest(...), and WhenHttpRequestJson(...) cover common high-friction setup without dropping out of the FastMoq flowHttpContext helpers, Azure SDK and Functions helpers, and fluent scenario coverage through ScenarioBuilder<T>FastMoq pays off most when tests have multiple constructor dependencies, recurring framework abstractions, or a need to keep provider choices flexible over time. It targets .NET 8, 9, and 10, works with the .NET test framework your suite already uses, and includes the analyzer pack by default in FastMoq and FastMoq.Core so provider-first guidance shows up directly in the IDE.
The example below uses xUnit-style attributes and Moq arrange syntax for illustration. The point of comparison is the FastMoq harness shape, not a requirement to use xUnit or Moq for every test suite.
Using a mock provider directly:
public class OrderProcessingServiceTests
{
[Fact]
public async Task PlaceOrderAsync_ShouldPersistAndLog_WhenReservationAndPaymentSucceed()
{
var inventoryGateway = new Mock<IInventoryGateway>();
var paymentGateway = new Mock<IPaymentGateway>();
var orderRepository = new Mock<IOrderRepository>();
var logger = new Mock<ILogger<OrderProcessingService>>();
var component = new OrderProcessingService(
inventoryGateway.Object,
paymentGateway.Object,
orderRepository.Object,
logger.Object);
inventoryGateway
.Setup(x => x.ReserveAsync("SKU-RED-CHAIR", 2, CancellationToken.None))
.ReturnsAsync(true);
paymentGateway
.Setup(x => x.ChargeAsync("cust-42", 149.90m, CancellationToken.None))
.ReturnsAsync("pay_12345");
var result = await component.PlaceOrderAsync(new OrderRequest
{
CustomerId = "cust-42",
Sku = "SKU-RED-CHAIR",
Quantity = 2,
TotalAmount = 149.90m,
}, CancellationToken.None);
result.Success.Should().BeTrue();
orderRepository.Verify(x => x.SaveAsync(It.IsAny<OrderRecord>(), CancellationToken.None), Times.Once);
}
}
Using FastMoq tracked provider-first mocks with Moq-specific arrange syntax:
GetOrCreateMock<T>() is still the provider-first tracked path here. This example uses the Moq provider package only for the arrange-time Setup(...) calls, so it requires FastMoq.Provider.Moq, Moq, and explicit moq provider selection for the test assembly.
public class OrderProcessingServiceTests : MockerTestBase<OrderProcessingService>
{
[Fact]
public async Task PlaceOrderAsync_ShouldPersistAndLog_WhenReservationAndPaymentSucceed()
{
Mocks.GetOrCreateMock<IInventoryGateway>()
.Setup(x => x.ReserveAsync("SKU-RED-CHAIR", 2, CancellationToken.None))
.ReturnsAsync(true);
Mocks.GetOrCreateMock<IPaymentGateway>()
.Setup(x => x.ChargeAsync("cust-42", 149.90m, CancellationToken.None))
.ReturnsAsync("pay_12345");
var result = await Component.PlaceOrderAsync(new OrderRequest
{
CustomerId = "cust-42",
Sku = "SKU-RED-CHAIR",
Quantity = 2,
TotalAmount = 149.90m,
}, CancellationToken.None);
result.Success.Should().BeTrue();
Mocks.Verify<IOrderRepository>(x => x.SaveAsync(It.IsAny<OrderRecord>(), CancellationToken.None), TimesSpec.Once);
Mocks.VerifyLogged(LogLevel.Information, "Placed order");
}
}
FastMoq removes the need for most explicit mock declarations, subject construction, and logger-plumbing code while still allowing provider-specific setup when you need it.
If you want a copy-paste example that works under the default provider without Moq-specific setup, start with Getting Started Guide.
GetOrCreateMock<T>(), AddType(...), DbContext, IFileSystem, and known types3.0.0 to 4.3.0 transitionHttpContext, IHttpContextAccessor, and claims-principal test setupmoq, nsubstitute, and reflection support today, with recommended usage patterns3.0.0 architecture, packaging, and API changes3.0.0 public release3.0.0 to the current repo directionFastMoq.Database package, with the primary calls staying in the FastMoq namespace.In the current v4 layout, FastMoq.Core bundles the internal reflection provider and the bundled moq compatibility provider. The default provider is reflection. Additional providers such as nsubstitute can be added explicitly.
Web-helper note:
FastMoq package, the web helpers are includedFastMoq.Core directly, add FastMoq.Web before using CreateHttpContext(...), CreateControllerContext(...), SetupClaimsPrincipal(...), AddHttpContext(...), or AddHttpContextAccessor(...)Azure Functions helper note:
FastMoq package, the Azure Functions helpers are includedFastMoq.Core directly, add FastMoq.AzureFunctions and import FastMoq.AzureFunctions.Extensions before using CreateFunctionContextInstanceServices(...), AddFunctionContextInstanceServices(...), CreateHttpRequestData(...), or CreateHttpResponseData(...)CreateTypedServiceProvider(...) and AddServiceProvider(...) helpers remain in FastMoq.Core, while the request and response body readers stay in FastMoq.AzureFunctions.ExtensionsAzure SDK helper note:
FastMoq package, the shared Azure SDK helpers are includedFastMoq.Core directly, add FastMoq.Azure before using PageableBuilder, AddTokenCredential(...), CreateAzureServiceProvider(...), or the Azure client registration helpersFastMoq.Azure.Pageable, FastMoq.Azure.Credentials, FastMoq.Azure.DependencyInjection, FastMoq.Azure.Storage, and FastMoq.Azure.KeyVaultTypical split-package install:
dotnet add package FastMoq.Core
dotnet add package FastMoq.Azure
dotnet add package FastMoq.AzureFunctions
dotnet add package FastMoq.Database
dotnet add package FastMoq.Web
GetMockDbContext<TContext>() keeps the same main call shape in the FastMoq namespace. If you install FastMoq, the EF helpers are included. If you install FastMoq.Core directly, add FastMoq.Database for DbContext support.
The aggregate FastMoq package intentionally includes FastMoq.Database, which in turn brings EF Core test-helper dependencies such as Microsoft.EntityFrameworkCore.InMemory. If your suite already pins relational or provider-specific EF Core packages on a different major version, either align the EF Core major versions across the graph or consume FastMoq.Core plus only the helper packages you actually need.
PageableBuilder, AddTokenCredential(...), AddDefaultAzureCredential(...), CreateAzureConfiguration(...), CreateAzureServiceProvider(...), and the Azure client registration helpers live in the FastMoq.Azure.* namespaces.
CreateFunctionContextInstanceServices(...), AddFunctionContextInstanceServices(...), CreateHttpRequestData(...), CreateHttpResponseData(...), ReadBodyAsStringAsync(...), and ReadBodyAsJsonAsync<T>(...) live in FastMoq.AzureFunctions.Extensions, while the generic CreateTypedServiceProvider(...) and AddServiceProvider(...) helpers stay in FastMoq.Extensions.
GetMockDbContext<TContext>() remains the default mocked-sets entry point. For explicit mode selection between mocked DbSets and a real EF in-memory context, use GetDbContextHandle<TContext>(new DbContextHandleOptions<TContext> { ... }).
The mocked-sets path is still backed by the existing Moq-based DbContextMock<TContext> implementation, while the real-context path is exposed through DbContextTestMode.RealInMemory.
If you are upgrading an older suite that still uses GetMock<T>(), direct Mock<T> access, VerifyLogger(...), or older HTTP setup helpers such as SetupHttpMessage(...), select Moq explicitly for that test assembly. If you are writing new or actively refactoring tests, prefer provider-neutral APIs such as GetOrCreateMock(...), Verify(...), VerifyLogged(...), WhenHttpRequest(...), and WhenHttpRequestJson(...). When you still need provider-specific setup in v4, use the provider-package extensions on IFastMock<T> such as AsMoq(), Setup(...), or AsNSubstitute().
For the moved HTTP compatibility helpers, the migration point is package selection rather than namespace churn: the Moq compatibility methods remain in the FastMoq.Extensions namespace for low-churn source migration, but their implementation now comes from the FastMoq.Provider.Moq package instead of FastMoq.Core.
Provider selection example:
MockingProviderRegistry.Register("moq", MoqMockingProvider.Instance, setAsDefault: true);
var mocker = new Mocker();
For a temporary override in a specific async scope, use MockingProviderRegistry.Push("providerName"). For detailed setup guidance, see Provider Selection Guide.
If you want a copy-paste example that works under the default provider, use Getting Started Guide first.
The snippet below is the optional Moq-fluent path, so it assumes FastMoq.Provider.Moq is installed and moq is selected for the test assembly.
public class OrderProcessingServiceTests : MockerTestBase<OrderProcessingService>
{
[Fact]
public async Task PlaceOrderAsync_ShouldPersistAndLog_WhenReservationAndPaymentSucceed()
{
Mocks.GetOrCreateMock<IInventoryGateway>()
.Setup(x => x.ReserveAsync("SKU-RED-CHAIR", 2, CancellationToken.None))
.ReturnsAsync(true);
Mocks.GetOrCreateMock<IPaymentGateway>()
.Setup(x => x.ChargeAsync("cust-42", 149.90m, CancellationToken.None))
.ReturnsAsync("pay_12345");
var result = await Component.PlaceOrderAsync(new OrderRequest
{
CustomerId = "cust-42",
Sku = "SKU-RED-CHAIR",
Quantity = 2,
TotalAmount = 149.90m,
}, CancellationToken.None);
result.Success.Should().BeTrue();
Mocks.Verify<IOrderRepository>(x => x.SaveAsync(It.IsAny<OrderRecord>(), CancellationToken.None), TimesSpec.Once);
Mocks.VerifyLogged(LogLevel.Information, "Placed order");
}
}
MockerTestBase<TComponent>: shortest path for service and component tests with automatic construction and dependency injectionMocker: standalone entry point when you do not want a test base classGetOrCreateMock<T>(): tracked provider-first mock access for the forward v4 and v5 pathCreateStandaloneFastMock<T>(): detached provider-first mock handle for manual wiring or an additional same-type double outside the tracked graphCreateFastMock<T>(): tracked provider-first registration helper when you intentionally want the new mock added immediately; it is not a second independent unkeyed handleVerify(...), VerifyNoOtherCalls(...), VerifyLogged(...), and TimesSpec: provider-neutral verification surfaceIFileSystem, DbContext, CallMethod(...), and constructor-guard testing3.0.0| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 net8.0 is compatible. 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 is compatible. 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 is compatible. 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. |
Showing the top 5 NuGet packages that depend on FastMoq.Core:
| Package | Downloads |
|---|---|
|
FastMoq
Complete FastMoq testing framework with provider-first test doubles, automatic dependency injection, provider-neutral verification, and first-party helpers for EF Core, Azure SDK, Azure Functions, HttpClient, and ASP.NET Core. Includes Roslyn analyzers for migration guidance. |
|
|
FastMoq.Web
ASP.NET Core and Blazor testing helpers for FastMoq, including controller and HttpContext setup, claims-principal helpers, IHttpContextAccessor registration, and component-test utilities. |
|
|
FastMoq.Database
Entity Framework Core testing helpers for FastMoq, including DbContext setup, mocked DbSet support, handle-based mode selection, and real in-memory context flows. |
|
|
FastMoq.AzureFunctions
Azure Functions isolated worker testing helpers for FastMoq, including typed FunctionContext.InstanceServices setup, HttpRequestData and HttpResponseData builders, and request or response body readers. |
|
|
FastMoq.Azure
Azure SDK testing helpers for FastMoq, including credential builders, pageable builders, Key Vault helpers, Azure-oriented configuration, and service registration support. |
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.4.2 | 202 | 5/2/2026 |
| 4.4.1 | 194 | 5/1/2026 |
| 4.4.0 | 192 | 4/29/2026 |
| 4.3.5 | 199 | 4/24/2026 |
| 4.3.4 | 217 | 4/21/2026 |
| 4.3.3 | 199 | 4/21/2026 |
| 4.3.2 | 187 | 4/20/2026 |
| 4.3.1 | 202 | 4/19/2026 |
| 4.3.0 | 187 | 4/19/2026 |
| 4.2.1 | 192 | 4/17/2026 |
| 4.2.0 | 201 | 4/17/2026 |
| 4.1.2 | 211 | 4/13/2026 |
| 4.1.1 | 197 | 4/12/2026 |
| 4.1.0 | 203 | 4/11/2026 |
| 4.0.3 | 192 | 4/10/2026 |
| 4.0.2 | 169 | 4/7/2026 |
| 3.0.0 | 477 | 5/12/2025 |