AI agents: use the documentation index at llms.txt to locate machine-readable pages. This section is indexed by https://docs.particular.net/nservicebus/llms.txt. The markdown version of this page is served as plain text. An MCP server at /mcp serves the same content via the search_docs and read_doc tools; it is read-only and needs no credentials. Markdown versions of documentation pages are available by appending .md to the page URL. Directory URLs use index.md. They are served as text/plain because some retrieval backends reject text/markdown.

Uniform Session Testing

Target Version:
NServiceBus 7.x
Standard support for version 7.x of NServiceBus has expired. For more information see our Support Policy.

Shows the usage of the NServiceBus.UniformSession.Testing package.

Prerequisites for uniform session testing functionality

The approach shown here works with the NServiceBus.UniformSession NuGet package version 2.2.0 or above. Install the NServiceBus.UniformSession.Testing NuGet package.

Testing services

Construct the service under test with an instance of TestableUniformSession. Call the methods being tested and make assertions about the messages sent and published.

var session = new TestableUniformSession();
var service = new SomeService(session);

service.DoTheThing();

Assert.AreEqual(1, session.SentMessages.Length);

Testing a handler

Construct the handler under test with an instance of TestableUniformSession.

var session = new TestableUniformSession();
var sharedComponent = new SharedComponent(session);
var handler = new SomeMessageHandler(sharedComponent);

Test.Handler(handler)
    .WithUniformSession(session)
    .ExpectPublish<SomeEvent>()
    .OnMessage<SomeMessage>();

Testing a saga

Construct the saga under test with an instance of TestableUniformSession.

var session = new TestableUniformSession();
var saga = new SomeSaga(session);
Test.Saga(saga)
    .WithUniformSession(session)
    .ExpectPublish<SomeEvent>()
    .WhenHandling<SomeCommand>();

Related Articles

  • Uniform Session
    Uniform Session introduces a uniform message session across the endpoint.