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.

NServiceBus Testing Upgrade Version 6 to 7

Component: Testing

Upgrade to NServiceBus Version 7

NServiceBus.Testing requires NServiceBus Version 7.

When upgrading to NServiceBus.Testing Version 7, projects will also require an upgrade to NServiceBus Version 7.

AssertSagaCompletionIs

The AssertSagaCompletionIs method has been obsoleted and replaced by ExpectSagaCompleted and ExpectSagaNotCompleted.

// For Testing version 7.x
Test.Saga<MySaga>()
    .ExpectSagaCompleted()
    .WhenHandling<CompleteSagaMessage>();

// For Testing version 6.x
Test.Saga<MySaga>()
    .WhenHandling<CompleteSagaMessage>()
    .AssertSagaCompletionIs(true);

Note the ExpectSagaCompleted and ExpectSagaNotCompleted expectations must be placed before a When method, similar to other expectation methods.

ExpectHandleCurrentMessageLater

The ExpectHandleCurrentMessageLater method has been obsoleted as IMessageHandlerContext.HandleCurrentMessageLater() has been deprecated in NServiceBus Version 7.

WhenHandling

An overload of the WhenHandling method has been added, which accepts a preconstructed message.

// For Testing version 7.x
var message = new CompleteSagaMessage();

Test.Saga<MySaga>()
    .ExpectSagaCompleted()
    .WhenHandling(message);

// For Testing version 6.x
var message = new CompleteSagaMessage();

Test.Saga<MySaga>()
    .WhenHandling<CompleteSagaMessage>(msg => { /* msg has already been created */ })
    .AssertSagaCompletionIs(true);

Fluent-style tests deprecated

The fluent-style testing API has been deprecated. See the upgrade guide for help on migrating to the Arrange-Act-Assert (AAA) test API.

Related Articles