MeshWeaver.Fixture
2.3.0
dotnet add package MeshWeaver.Fixture --version 2.3.0
NuGet\Install-Package MeshWeaver.Fixture -Version 2.3.0
<PackageReference Include="MeshWeaver.Fixture" Version="2.3.0" />
<PackageVersion Include="MeshWeaver.Fixture" Version="2.3.0" />
<PackageReference Include="MeshWeaver.Fixture" />
paket add MeshWeaver.Fixture --version 2.3.0
#r "nuget: MeshWeaver.Fixture, 2.3.0"
#:package MeshWeaver.Fixture@2.3.0
#addin nuget:?package=MeshWeaver.Fixture&version=2.3.0
#tool nuget:?package=MeshWeaver.Fixture&version=2.3.0
MeshWeaver.Fixture
MeshWeaver.Fixture provides the foundational testing infrastructure for the MeshWeaver ecosystem. It includes base classes and utilities that make it easier to write consistent, reliable tests, particularly for components that use message hubs.
Overview
The library provides:
- Base test classes for different testing scenarios
- Message hub testing infrastructure
- Test utilities and helpers
- Common test configurations
Core Components
TestBase
The root base class for all MeshWeaver tests:
public abstract class TestBase : IAsyncLifetime
{
protected readonly ITestOutputHelper Output;
protected TestBase(ITestOutputHelper output)
{
Output = output;
}
// Lifecycle methods
public virtual Task InitializeAsync() => Task.CompletedTask;
public virtual Task DisposeAsync() => Task.CompletedTask;
}
HubTestBase
Base class for testing components that use message hubs:
public class HubTestBase : TestBase
{
protected IMessageHub Router { get; }
protected IMessageHub Host { get; }
protected virtual MessageHubConfiguration ConfigureRouter(MessageHubConfiguration configuration)
{
return configuration.WithTypes(typeof(PingRequest), typeof(PingResponse));
}
protected virtual MessageHubConfiguration ConfigureHost(MessageHubConfiguration configuration)
{
return configuration.WithHandler<PingRequest>((hub, request) =>
{
hub.Post(new PingResponse(), options => options.ResponseFor(request));
return request.Processed();
});
}
// Helper methods for tests
protected IMessageHub GetClient() =>
Router.ServiceProvider.CreateMessageHub(new ClientAddress());
}
Usage Examples
Basic Test
public class MyTest : TestBase
{
public MyTest(ITestOutputHelper output) : base(output) { }
[Fact]
public async Task BasicTest()
{
// Test implementation
await Task.CompletedTask;
}
}
Message Hub Test
public class MyHubTest : HubTestBase
{
public MyHubTest(ITestOutputHelper output) : base(output) { }
protected override MessageHubConfiguration ConfigureHost(
MessageHubConfiguration configuration)
{
return base.ConfigureHost(configuration)
.WithHandler<CustomRequest>((hub, request) =>
{
hub.Post(new CustomResponse(), o => o.ResponseFor(request));
return request.Processed();
});
}
[Fact]
public async Task RequestResponse()
{
var client = GetClient();
var response = await client.AwaitResponse(
new CustomRequest(),
o => o.WithTarget(new HostAddress())
);
response.Should().BeOfType<CustomResponse>();
}
}
Testing with Multiple Hubs
public class DistributedTest : HubTestBase
{
protected override MessageHubConfiguration ConfigureRouter(
MessageHubConfiguration configuration)
{
return base.ConfigureRouter(configuration)
.WithRoutes(forward =>
forward
.RouteAddressToHostedHub<DataAddress>(c =>
c.ConfigureDataHub())
.RouteAddressToHostedHub<ComputeAddress>(c =>
c.ConfigureComputeHub())
);
}
[Fact]
public async Task DistributedProcessing()
{
var client = GetClient();
// Test distributed message processing
}
}
Features
Test Base Classes
TestBase
- Root test class with lifecycle managementHubTestBase
- For message hub testing- Custom base classes for specific scenarios
Message Hub Testing
- Request-response testing
- Message routing
- Hub configuration
- Client creation
Test Utilities
- Output helpers
- Async support
- Common assertions
- Test data generation
Configuration
- Hub configuration helpers
- Route configuration
- Handler registration
- Service configuration
Best Practices
Test Class Organization
public class MyTests : HubTestBase { // Configuration overrides protected override MessageHubConfiguration ConfigureHost( MessageHubConfiguration configuration) { return base.ConfigureHost(configuration) .WithCustomConfiguration(); } // Test methods [Fact] public async Task TestScenario() { // Arrange var client = GetClient(); // Act var result = await ExecuteTest(); // Assert result.Should().BeSuccessful(); } }
Async Testing
[Fact] public async Task AsyncTest() { await using var client = GetClient(); var result = await client .AwaitResponse(request) .Timeout(5.Seconds()); result.Should().NotBeNull(); }
Hub Configuration
protected override MessageHubConfiguration ConfigureHost( MessageHubConfiguration configuration) { return configuration .WithTypes(messageTypes) .WithHandlers(handlers) .WithServices(services); }
Integration
With xUnit
// Fact attribute for hub tests
public class HubFactAttribute : FactAttribute
{
public HubFactAttribute()
{
// Configure timeout and other test parameters
}
}
// Using in tests
[HubFact]
public async Task MyHubTest()
{
// Test implementation
}
Related Projects
- MeshWeaver.Messaging.Hub - Core messaging functionality
- MeshWeaver.TestDomain - Test domain models
- MeshWeaver.Data.Test - Data module tests
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. 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. |
-
net9.0
- MeshWeaver.Mesh.Contract (>= 2.3.0)
- MeshWeaver.Messaging.Hub (>= 2.3.0)
- Microsoft.Extensions.Configuration.Json (>= 9.0.6)
- Microsoft.Extensions.Logging (>= 9.0.6)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.6)
- Microsoft.Extensions.Logging.Configuration (>= 9.0.6)
- xunit.v3.extensibility.core (>= 3.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on MeshWeaver.Fixture:
Package | Downloads |
---|---|
MeshWeaver.Hosting.Monolith.TestBase
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
2.3.0 | 205 | 8/4/2025 |
2.2.0 | 489 | 7/21/2025 |
2.1.0 | 177 | 4/6/2025 |
2.0.3 | 508 | 3/24/2025 |
2.0.2 | 474 | 3/24/2025 |
2.0.1 | 123 | 3/21/2025 |
2.0.0 | 166 | 3/20/2025 |
2.0.0-preview3 | 105 | 2/28/2025 |
2.0.0-Preview2 | 109 | 2/10/2025 |
2.0.0-preview1 | 110 | 1/6/2025 |
1.0.1 | 137 | 10/8/2024 |