TiMoch.Orleans.TestUtilities 2.0.2

dotnet add package TiMoch.Orleans.TestUtilities --version 2.0.2
                    
NuGet\Install-Package TiMoch.Orleans.TestUtilities -Version 2.0.2
                    
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="TiMoch.Orleans.TestUtilities" Version="2.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TiMoch.Orleans.TestUtilities" Version="2.0.2" />
                    
Directory.Packages.props
<PackageReference Include="TiMoch.Orleans.TestUtilities" />
                    
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 TiMoch.Orleans.TestUtilities --version 2.0.2
                    
#r "nuget: TiMoch.Orleans.TestUtilities, 2.0.2"
                    
#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.
#:package TiMoch.Orleans.TestUtilities@2.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=TiMoch.Orleans.TestUtilities&version=2.0.2
                    
Install as a Cake Addin
#tool nuget:?package=TiMoch.Orleans.TestUtilities&version=2.0.2
                    
Install as a Cake Tool

TiMoch.Orleans.TestUtilities

Testing utilities for Microsoft Orleans applications with NUnit integration. Provides base classes, cluster fixtures, and polling utilities for comprehensive Orleans grain testing.

Features

  • OrleansTestClusterFixture: Abstract base class for test cluster management with DI support
  • OrleansTestBase: Base test class with polling utilities and timeout management
  • FluentTestSiloConfigurator: Easy setup of named memory storage and stream providers
  • NUnitTestContextLoggerProvider: Integrated logging to NUnit test output (automatically configured)
  • Automatic Configuration: IConfiguration and logging automatically set up from appsettings.json

Quick Start

1. Create a Test Cluster Fixture

[SetUpFixture]
public class MyProjectTestClusterFixture : OrleansTestClusterFixture
{
    protected override ISiloConfigurator CreateSiloConfigurator()
    {
        return new FluentTestSiloConfigurator()
            .WithNamedMemoryStorage("UserStorage")
            .WithNamedMemoryStorage("OrderStorage")
            .WithNamedMemoryStreams("NotificationStream");
    }

    protected override void ConfigureServices(IServiceCollection services)
    {
        // IConfiguration is automatically registered and available
        // NUnit logging is automatically configured
        
        // Register real services
        services.AddSingleton<IMyService, MyService>();
        
        // Override with test doubles
        services.AddSingleton<IExternalApi, MockExternalApi>();
    }
}

2. Create Test Classes

public class UserGrainTests : OrleansTestBase
{
    [Test]
    public async Task UserGrain_Should_UpdateStatus()
    {
        // Arrange
        var userId = Guid.NewGuid();
        var userGrain = GrainFactory.GetGrain<IUserGrain>(userId);

        // Act
        await userGrain.SetStatus("Active");

        // Assert - using polling to wait for eventual consistency
        var finalStatus = await PollForConditionAsync(
            async () => await userGrain.GetStatus(),
            status => status == "Active",
            timeout: TimeSpan.FromSeconds(5));

        Assert.That(finalStatus, Is.EqualTo("Active"));
    }

    [Test]
    public async Task UserGrain_Should_ProcessAsync()
    {
        // Arrange
        var userGrain = GrainFactory.GetGrain<IUserGrain>(Guid.NewGuid());

        // Act
        await userGrain.StartProcessing();

        // Assert - simple boolean condition polling
        await PollForConditionAsync(
            async () => await userGrain.IsProcessingComplete(),
            timeout: TimeSpan.FromSeconds(10));
    }
}

Polling Utilities

The OrleansTestBase provides powerful polling utilities for testing eventually consistent Orleans systems:

PollForConditionAsync<T>

Polls for a condition on a returned value:

var result = await PollForConditionAsync(
    async () => await grain.GetCount(),
    count => count >= 5,
    timeout: TimeSpan.FromSeconds(10),
    pollInterval: TimeSpan.FromMilliseconds(100));

PollForConditionAsync (Boolean)

Polls for a simple boolean condition:

await PollForConditionAsync(
    async () => await grain.IsReady(),
    timeout: TimeSpan.FromSeconds(5));

Automatic Features

Configuration Support

  • IConfiguration automatically loaded from appsettings.json in base directory
  • Available for injection in all Orleans grains and services
  • Override CreateConfiguration() method to customize configuration sources

NUnit Logging Integration

  • Orleans logs automatically appear in NUnit test output
  • Configurable via Logging section in appsettings.json
  • Override ConfigureLogging() method to customize logging setup

Debug Support

Tests automatically detect when running under debugger:

  • Timeouts extend to 1 hour when debugger attached
  • Force debug mode with DEBUG_TESTS=true environment variable
  • Debug status shown in test output

Example appsettings.json

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.Orleans": "Warning",
      "MyApp": "Debug"
    },
    "NUnitTestContext": {
      "LogLevel": {
        "Default": "Information"
      }
    }
  }
}

Requirements

  • .NET 8.0
  • Microsoft Orleans 9.1.2+
  • NUnit 3.14.0+

License

MIT License - see GitHub repository for details.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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. 
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.0.2 128 9/22/2025
2.0.1 123 9/22/2025
2.0.0 128 9/22/2025
1.2.1 235 9/19/2025
1.2.0 247 9/19/2025
1.1.0 152 9/4/2025
1.0.1 146 9/3/2025
1.0.0 153 9/3/2025

Initial release with Orleans test cluster fixtures, base test classes, and polling utilities.