This directory contains complete sample applications demonstrating FastMoq's capabilities in real-world scenarios, particularly focusing on modern .NET and Azure integration patterns.
- E-Commerce Order Processing - Complete order processing system with Azure integration
- Microservices Communication - Service-to-service communication patterns
- Background Processing - Queue processing and background jobs
- Blazor Web Application - Full-stack Blazor application with testing
- Azure Service Bus integration and testing
- Azure Blob Storage operations
- Azure Key Vault configuration
- Entity Framework Core with Azure SQL
- HttpClient and external API integration
- Background Services and hosted services
- Blazor Components testing
- API Controllers with complex dependencies
- Configuration and Options patterns
- Logging and Monitoring integration
The sample test projects intentionally showcase FastMoq extension helpers so you can apply them directly:
CreateHttpClient()to quickly register anHttpClientand (if needed) anIHttpClientFactorywith a default response.SetupHttpMessage(...)for per‑test customization (status codes, payloads, sequences).- Content helpers:
GetStringContent,GetContentBytesAsync(),GetContentStreamAsync()for asserting raw payloads.
GetMockDbContext<TContext>()to obtain a mock context with DbSets auto‑prepared.- Add the real in‑memory variant via
AddTypeif you want a lightweight functional test using SQLite in memory.
- Use
Mocks.GetMock<ILogger<T>>() .VerifyLogger(LogLevel.Information, "Message")instead of direct invocation inspection.
CreateInstance<T>()/ typed overloads pick the correct constructor and auto‑inject mocks.AddType<TAbstraction>(factory)to pin specific concrete/instance values (e.g., seededDbConnection,Uri, or options).
Even when not running in Azure, the samples demonstrate how you would substitute Azure types:
- Wrap Azure SDK clients with interfaces in your application layer and mock those interfaces in tests.
- Use consistent naming for senders/processors so verification (e.g., Service Bus send) is easy.
If you adapt these samples for Azure Functions HTTP triggers, use patterns similar to (conceptually) MockedHttpRequestData and MockedHttpResponseData helpers (as seen in other internal solution test utilities):
- Build the request: supply method, route values, headers, and JSON body.
- Provide dependency injection values using
AddType(e.g., configuration, services). - Use
SetupHttpMessagefor outboundHttpClientcalls triggered inside the function. - Assert:
- Outbound calls (verify
SendAsync) - Response status & body (deserialize or use content helpers)
- Logs via
VerifyLogger
- Outbound calls (verify
Recommended layering:
var request = TestUtils.CreateHttpRequest(jsonBody, queryParams);
var result = await Component.RunAsync(request, CancellationToken.None);
Mocks.GetMock<ILogger<MyFunction>>()
.VerifyLogger(LogLevel.Information, "Processed event");While FastMoq does not ship Azure Functions request/response shims directly, it complements such utilities by supplying:
- Automatic logger mocks with capture/verification.
- Consistent
HttpClientmocking for downstream REST calls. - Simplified DI graph creation so only function inputs need explicit arrangement.
The current samples are intentionally minimal. Consider extending locally with:
- Adding a payment gateway client abstraction and testing retry/backoff logic via
SetupHttpMessagesequences. - Adding blob metadata assertions using a mocked
BlobClient. - Introducing an options reload test using
IOptionsMonitor<T>+ updated values viaAddType.
| Goal | Helper | Notes |
|---|---|---|
| Fast default HttpClient | CreateHttpClient() |
Registers handler + factory if missing |
| Custom per‑test response | SetupHttpMessage() |
Use multiple calls for sequential responses |
| Mock EF Core context | GetMockDbContext<T>() |
Auto sets up DbSets; seed data before use |
| Replace concrete dependency | AddType<T>() |
Pin deterministic instances (e.g., clock) |
| Verify log message | VerifyLogger(...) |
Works on ILogger or ILogger<T> mocks |
| Extract HTTP content | GetStringContent |
Use for string assertions |
Tip: Prefer the extension helpers first; drop down to raw Moq setup only for edge cases.
Each sample application includes:
- Complete source code
- Comprehensive test suite using FastMoq
- Docker configuration for local development
- README with setup instructions
- Azure deployment templates
Choose a sample based on your use case and follow the individual README files for setup instructions.
- .NET 8.0 or later
- Azure subscription (for cloud features)
- Docker Desktop (optional, for containerized development)
- Visual Studio 2022 or VS Code
- Clone the repository
- Navigate to a sample directory
- Follow the sample-specific README
- Run the tests to see FastMoq in action
cd docs/samples/ecommerce-orders
dotnet restore
dotnet testAfter exploring these samples, you'll understand how to:
- Structure tests for complex, real-world applications
- Mock Azure services and external dependencies
- Test asynchronous and background operations
- Verify logging and monitoring behavior
- Handle configuration and secrets in tests
- Test web applications and APIs comprehensively
- Implement integration testing strategies
If you have questions about the samples or need help adapting them to your specific use case, please:
- Check the individual sample README files
- Review the main documentation
- Open an issue on the FastMoq repository