MeshWeaver.Fixture 2.1.0

dotnet add package MeshWeaver.Fixture --version 2.1.0
                    
NuGet\Install-Package MeshWeaver.Fixture -Version 2.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MeshWeaver.Fixture" Version="2.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MeshWeaver.Fixture" Version="2.1.0" />
                    
Directory.Packages.props
<PackageReference Include="MeshWeaver.Fixture" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MeshWeaver.Fixture --version 2.1.0
                    
#r "nuget: MeshWeaver.Fixture, 2.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=MeshWeaver.Fixture&version=2.1.0
                    
Install MeshWeaver.Fixture as a Cake Addin
#tool nuget:?package=MeshWeaver.Fixture&version=2.1.0
                    
Install MeshWeaver.Fixture as a Cake Tool

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

  1. Test Base Classes

    • TestBase - Root test class with lifecycle management
    • HubTestBase - For message hub testing
    • Custom base classes for specific scenarios
  2. Message Hub Testing

    • Request-response testing
    • Message routing
    • Hub configuration
    • Client creation
  3. Test Utilities

    • Output helpers
    • Async support
    • Common assertions
    • Test data generation
  4. Configuration

    • Hub configuration helpers
    • Route configuration
    • Handler registration
    • Service configuration

Best Practices

  1. 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();
        }
    }
    
  2. Async Testing

    [Fact]
    public async Task AsyncTest()
    {
        await using var client = GetClient();
        var result = await client
            .AwaitResponse(request)
            .Timeout(5.Seconds());
    
        result.Should().NotBeNull();
    }
    
  3. 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
}
  • MeshWeaver.Messaging.Hub - Core messaging functionality
  • MeshWeaver.TestDomain - Test domain models
  • MeshWeaver.Data.Test - Data module tests
Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
2.1.0 44 4/6/2025
2.0.3 473 3/24/2025
2.0.2 442 3/24/2025
2.0.1 94 3/21/2025
2.0.0 143 3/20/2025
2.0.0-preview3 84 2/28/2025
2.0.0-Preview2 90 2/10/2025
2.0.0-preview1 90 1/6/2025
1.0.1 118 10/8/2024