Skip to content

Commit

Permalink
Merge pull request #7143 from Particular/nunit-and-assertion-upgrades
Browse files Browse the repository at this point in the history
Bump the minimum required NUnit version for NServiceBus.AcceptanceTesting from 3.14 to 4.1
  • Loading branch information
WilliamBZA authored Aug 19, 2024
2 parents 2eea595 + 8d5b11b commit d805eaf
Show file tree
Hide file tree
Showing 544 changed files with 3,576 additions and 2,237 deletions.
2 changes: 1 addition & 1 deletion src/NServiceBus.AcceptanceTesting/ContextAppender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ void Log(string message, LogLevel messageSeverity)
if (context == null)
{
// avoid NRE in case something logs outside of a test scenario
TestContext.WriteLine(message);
TestContext.Out.WriteLine(message);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="NUnit" Version="[3.14.0, 4.0.0)" />
<PackageReference Include="NUnit" Version="[4.1.0, 5.0.0)" />
<PackageReference Include="NUnit.Analyzers" Version="4.3.0" PrivateAssets="All" />
<PackageReference Include="Particular.Packaging" Version="4.1.0" PrivateAssets="All" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/NServiceBus.AcceptanceTesting/ScenarioWithContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public async Task<TContext> Run(RunSettings settings)

await runDescriptor.RaiseOnTestCompleted(runSummary).ConfigureAwait(false);

TestContext.WriteLine("Test {0}: Scenario completed in {1:0.0}s", TestContext.CurrentContext.Test.FullName, sw.Elapsed.TotalSeconds);
TestContext.Out.WriteLine("Test {0}: Scenario completed in {1:0.0}s", TestContext.CurrentContext.Test.FullName, sw.Elapsed.TotalSeconds);

if (runSummary.Result.Failed)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public async Task<ComponentRunner> CreateRunner(RunDescriptor run)
}
catch (Exception)
{
TestContext.WriteLine($"Endpoint {runner.Name} failed to initialize");
await TestContext.Out.WriteLineAsync($"Endpoint {runner.Name} failed to initialize").ConfigureAwait(false);
throw;
}
return runner;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public async Task Should_preserve_the_original_body()
.Done(c => c.Done)
.Run();

Assert.AreEqual(context.OriginalBodyChecksum, context.AuditChecksum, "The body of the message sent to audit should be the same as the original message coming off the queue");
Assert.That(context.AuditChecksum, Is.EqualTo(context.OriginalBodyChecksum), "The body of the message sent to audit should be the same as the original message coming off the queue");
}

public static byte Checksum(byte[] data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@ public async Task Should_audit_the_message()
.Done(c => c.MessageAudited)
.Run();

Assert.True(context.MessageProcessed);
Assert.True(context.MessageAudited);
Assert.AreEqual("SomeValue", context.HeaderValue);
Assert.Multiple(() =>
{
Assert.That(context.MessageProcessed, Is.True);
Assert.That(context.MessageAudited, Is.True);
Assert.That(context.HeaderValue, Is.EqualTo("SomeValue"));
});
}

public static byte Checksum(byte[] data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public async Task Should_audit_to_target_queue()
.Done(c => c.MessageAudited)
.Run();

Assert.True(context.MessageAudited);
Assert.That(context.MessageAudited, Is.True);
}

public class UserEndpoint : EndpointConfigurationBuilder
Expand Down
4 changes: 2 additions & 2 deletions src/NServiceBus.AcceptanceTests/Audit/When_auditing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public async Task Should_not_be_forwarded_to_auditQueue_when_auditing_is_disable
.Done(c => c.IsMessageHandlingComplete)
.Run();

Assert.IsFalse(context.IsMessageHandledByTheAuditEndpoint);
Assert.That(context.IsMessageHandledByTheAuditEndpoint, Is.False);
}

[Test]
Expand All @@ -30,7 +30,7 @@ public async Task Should_be_forwarded_to_auditQueue_when_auditing_is_enabled()
.Done(c => c.IsMessageHandlingComplete && c.IsMessageHandledByTheAuditEndpoint)
.Run();

Assert.IsTrue(context.IsMessageHandledByTheAuditEndpoint);
Assert.That(context.IsMessageHandledByTheAuditEndpoint, Is.True);
}

public class Context : ScenarioContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public async Task Should_not_honor_TimeToBeReceived_for_audit_message()
.Done(c => c.IsMessageHandlingComplete && c.TTBRHasExpiredAndMessageIsStillInAuditQueue)
.Run();

Assert.IsTrue(context.IsMessageHandlingComplete);
Assert.That(context.IsMessageHandlingComplete, Is.True);
}

class Context : ScenarioContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public async Task Should_allow_audit_action_to_be_replaced()
.Done(c => c.AuditMessageReceived)
.Run();

Assert.True(context.BodyWasEmpty);
Assert.That(context.BodyWasEmpty, Is.True);
}

public class Context : ScenarioContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ public async Task Should_not_subscribe_excluded_events()
.Done(c => c.EndpointsStarted)
.Run();

Assert.AreEqual(1, ctx.EventsSubscribedTo.Count);
Assert.AreEqual(typeof(EventToSubscribeTo), ctx.EventsSubscribedTo[0]);
Assert.That(ctx.EventsSubscribedTo, Has.Count.EqualTo(1));
Assert.That(ctx.EventsSubscribedTo[0], Is.EqualTo(typeof(EventToSubscribeTo)));

CollectionAssert.IsEmpty(ctx.Logs.Where(l => l.LoggerName == typeof(AutoSubscribe).FullName && l.Level == LogLevel.Error));
Assert.That(ctx.Logs.Where(l => l.LoggerName == typeof(AutoSubscribe).FullName && l.Level == LogLevel.Error), Is.Empty);
}

class Context : ScenarioContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public async Task Should_autoSubscribe_the_saga_messageHandler_by_default()
.Done(c => c.EventsSubscribedTo.Count >= 2)
.Run();

Assert.True(context.EventsSubscribedTo.Contains(typeof(MyEvent)), "Events only handled by sagas should be auto subscribed");
Assert.True(context.EventsSubscribedTo.Contains(typeof(MyEventBase)), "Sagas should be auto subscribed even when handling a base class event");
Assert.That(context.EventsSubscribedTo, Does.Contain(typeof(MyEvent)), "Events only handled by sagas should be auto subscribed");
Assert.That(context.EventsSubscribedTo, Does.Contain(typeof(MyEventBase)), "Sagas should be auto subscribed even when handling a base class event");
}

class Context : ScenarioContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public async Task Should_not_autoSubscribe_messages_handled_by_sagas_if_asked_to
.Done(c => c.EndpointsStarted)
.Run();

Assert.False(context.EventsSubscribedTo.Count != 0, "Events only handled by sagas should not be auto subscribed");
Assert.That(context.EventsSubscribedTo.Count, Is.EqualTo(0), "Events only handled by sagas should not be auto subscribed");
}

class Context : ScenarioContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@ public async Task Should_autosubscribe_to_relevant_messagetypes()
.Done(c => c.EndpointsStarted && c.EventsSubscribedTo.Count >= 1)
.Run();

Assert.AreEqual(1, context.EventsSubscribedTo.Count);
Assert.True(context.EventsSubscribedTo.Contains(typeof(MyEvent).AssemblyQualifiedName), "Events should be auto subscribed");
Assert.False(context.EventsSubscribedTo.Contains(typeof(MyEventWithNoRouting).AssemblyQualifiedName), "Events without routing should not be auto subscribed");
Assert.False(context.EventsSubscribedTo.Contains(typeof(MyEventWithNoHandler).AssemblyQualifiedName), "Events without handlers should not be auto subscribed");
Assert.False(context.EventsSubscribedTo.Contains(typeof(MyCommand).AssemblyQualifiedName), "Commands should not be auto subscribed");
Assert.False(context.EventsSubscribedTo.Contains(typeof(MyMessage).AssemblyQualifiedName), "Plain messages should not be auto subscribed by default");
Assert.That(context.EventsSubscribedTo, Has.Count.EqualTo(1));
Assert.That(context.EventsSubscribedTo, Does.Contain(typeof(MyEvent).AssemblyQualifiedName), "Events should be auto subscribed");
Assert.Multiple(() =>
{
Assert.That(context.EventsSubscribedTo.Contains(typeof(MyEventWithNoRouting).AssemblyQualifiedName), Is.False, "Events without routing should not be auto subscribed");
Assert.That(context.EventsSubscribedTo.Contains(typeof(MyEventWithNoHandler).AssemblyQualifiedName), Is.False, "Events without handlers should not be auto subscribed");
Assert.That(context.EventsSubscribedTo.Contains(typeof(MyCommand).AssemblyQualifiedName), Is.False, "Commands should not be auto subscribed");
Assert.That(context.EventsSubscribedTo.Contains(typeof(MyMessage).AssemblyQualifiedName), Is.False, "Plain messages should not be auto subscribed by default");
});
}

class Context : ScenarioContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public async Task Should_not_autosubscribe_any_events()
.Done(ctx => ctx.EndpointsStarted)
.Run();

Assert.IsEmpty(context.SubscribedEvents);
Assert.That(context.SubscribedEvents, Is.Empty);
}

class Context : ScenarioContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void Should_throw_on_startup()
.Done(c => c.EndpointsStarted)
.Run());

StringAssert.Contains("IMessageSession", exception.ToString());
Assert.That(exception.ToString(), Does.Contain("IMessageSession"));
}

public class StartedEndpoint : EndpointConfigurationBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public async Task Should_throw()
.Done(c => c.GotTheException)
.Run();

Assert.IsInstanceOf<Exception>(context.Exception);
Assert.That(context.Exception, Is.InstanceOf<Exception>());
}

public class Context : ScenarioContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public async Task Should_allow_publishing_commands()
.Done(c => c.EndpointsStarted)
.Run();

Assert.True(context.EndpointsStarted);
Assert.That(context.EndpointsStarted, Is.True);
}

public class Endpoint : EndpointConfigurationBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public async Task Should_allow_publishing_commands()
.Done(c => c.EndpointsStarted)
.Run();

Assert.True(context.EndpointsStarted);
Assert.That(context.EndpointsStarted, Is.True);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public async Task Should_throw()
.Done(c => c.GotTheException)
.Run();

Assert.IsInstanceOf<Exception>(context.Exception);
Assert.That(context.Exception, Is.InstanceOf<Exception>());
}

public class Context : ScenarioContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public async Task Should_allow_sending_events()
.Done(c => c.EndpointsStarted)
.Run();

Assert.True(context.EndpointsStarted);
Assert.That(context.EndpointsStarted, Is.True);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public async Task Should_throw()
.Done(c => c.GotTheException)
.Run();

Assert.IsInstanceOf<Exception>(context.Exception);
Assert.That(context.Exception, Is.InstanceOf<Exception>());
}

public class Context : ScenarioContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public async Task Should_throw()
.Done(c => c.GotTheException)
.Run();

Assert.IsInstanceOf<Exception>(context.Exception);
Assert.That(context.Exception, Is.InstanceOf<Exception>());
}

public class Context : ScenarioContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ public async Task Should_flow_causation_headers()
.Done(c => c.Done)
.Run();

Assert.AreEqual(context.FirstConversationId, context.ConversationIdReceived, "Conversation id should flow to outgoing messages");
Assert.AreEqual(context.MessageIdOfFirstMessage, context.RelatedToReceived, "RelatedToId on outgoing messages should be set to the message id of the message causing it to be sent");
Assert.Multiple(() =>
{
Assert.That(context.ConversationIdReceived, Is.EqualTo(context.FirstConversationId), "Conversation id should flow to outgoing messages");
Assert.That(context.RelatedToReceived, Is.EqualTo(context.MessageIdOfFirstMessage), "RelatedToId on outgoing messages should be set to the message id of the message causing it to be sent");
});
}

public class Context : ScenarioContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ public async Task Should_use_custom_id()
.Done(c => c.MatchingMessageReceived && c.NonMatchingMessageReceived)
.Run();

Assert.AreEqual($"{tennantId}-{myBusinessMessage.MyBusinessId}", context.MatchingConversationIdReceived);
Assert.True(Guid.TryParse(context.NonMatchingConversationIdReceived, out var _));
Assert.Multiple(() =>
{
Assert.That(context.MatchingConversationIdReceived, Is.EqualTo($"{tennantId}-{myBusinessMessage.MyBusinessId}"));
Assert.That(Guid.TryParse(context.NonMatchingConversationIdReceived, out var _), Is.True);
});
}

public class Context : ScenarioContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ public async Task With_specified_conversation_id()
.Done(ctx => ctx.MessageHandled)
.Run();

Assert.That(context.NewConversationId, Is.EqualTo(UserDefinedConverstionId), "ConversationId should be set to the user defined value.");
Assert.That(context.PreviousConversationId, Is.EqualTo(context.OriginalConversationId), "PreviousConversationId header should be set to the original conversation id.");
Assert.Multiple(() =>
{
Assert.That(context.NewConversationId, Is.EqualTo(UserDefinedConverstionId), "ConversationId should be set to the user defined value.");
Assert.That(context.PreviousConversationId, Is.EqualTo(context.OriginalConversationId), "PreviousConversationId header should be set to the original conversation id.");
});
}

[Test]
Expand All @@ -40,8 +43,11 @@ public async Task Without_specified_conversation_id()
.Run();

Assert.That(context.NewConversationId, Is.EqualTo(GeneratedConversationId), "ConversationId should be generated.");
Assert.That(context.NewConversationId, Is.Not.EqualTo(context.OriginalConversationId), "ConversationId should not be equal to the original conversation id.");
Assert.That(context.PreviousConversationId, Is.EqualTo(context.OriginalConversationId), "PreviousConversationId header should be set to the original conversation id.");
Assert.Multiple(() =>
{
Assert.That(context.NewConversationId, Is.Not.EqualTo(context.OriginalConversationId), "ConversationId should not be equal to the original conversation id.");
Assert.That(context.PreviousConversationId, Is.EqualTo(context.OriginalConversationId), "PreviousConversationId header should be set to the original conversation id.");
});
}

class NewConversationScenario : ScenarioContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ public async Task With_specified_conversation_id()
.Done(ctx => ctx.MessageHandled)
.Run();

Assert.That(context.ConversationId, Is.EqualTo(NewConversionId), "ConversationId should be set to configured user defined value.");
Assert.That(context.PreviousConversationId, Is.Null, "Previous ConversationId should not be set when handling a message outside of a message handler.");
Assert.Multiple(() =>
{
Assert.That(context.ConversationId, Is.EqualTo(NewConversionId), "ConversationId should be set to configured user defined value.");
Assert.That(context.PreviousConversationId, Is.Null, "Previous ConversationId should not be set when handling a message outside of a message handler.");
});
}

[Test]
Expand All @@ -46,8 +49,11 @@ public async Task Without_specified_conversation_id()
.Run();

Assert.That(context.ConversationId, Is.EqualTo(GeneratedConversationId), "ConversationId should be generated.");
Assert.That(context.ConversationId, Is.Not.EqualTo(context.PreviousConversationId), "ConversationId should not match the previous conversationId.");
Assert.That(context.PreviousConversationId, Is.Null, "Previous ConversationId should not be set when handling a message outside of a message handler.");
Assert.Multiple(() =>
{
Assert.That(context.ConversationId, Is.Not.EqualTo(context.PreviousConversationId), "ConversationId should not match the previous conversationId.");
Assert.That(context.PreviousConversationId, Is.Null, "Previous ConversationId should not be set when handling a message outside of a message handler.");
});
}

[Test]
Expand Down Expand Up @@ -77,8 +83,11 @@ public async Task Cannot_set_value_for_header_directly()
.Run();

var expectedExceptionMessage = $"Cannot set the NServiceBus.ConversationId header to '{overrideConversationId}' as StartNewConversation() was called.";
Assert.That(context.ExceptionThrown, Is.True, "Exception should be thrown when trying to directly set conversationId");
Assert.That(context.ExceptionMessage, Is.EqualTo(expectedExceptionMessage));
Assert.Multiple(() =>
{
Assert.That(context.ExceptionThrown, Is.True, "Exception should be thrown when trying to directly set conversationId");
Assert.That(context.ExceptionMessage, Is.EqualTo(expectedExceptionMessage));
});
}

public class AnyMessage : IMessage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public async Task Should_process_message()
.Done(c => c.GotTheMessage)
.Run();

Assert.True(context.GotTheMessage);
Assert.That(context.GotTheMessage, Is.True);
}

public class Context : ScenarioContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ public async Task Message_should_be_moved_to_error_because_handler_not_found()
.Done(c => !c.FailedMessages.IsEmpty)
.Run();

Assert.True(context.Logs.Any(l => l.Level == LogLevel.Error && l.Message.Contains($"No handlers could be found for message type: {typeof(MyCommand).FullName}")), "No handlers could be found was not logged.");
Assert.False(context.Logs.Any(l => l.Level == LogLevel.Warn && l.Message.Contains($"Message header '{typeof(MyCommand).FullName}' was mapped to type '{typeof(MyCommand).FullName}' but that type was not found in the message registry, ensure the same message registration conventions are used in all endpoints, especially if using unobtrusive mode.")), "Message type could not be mapped.");
Assert.False(context.Logs.Any(l => l.Level == LogLevel.Warn && l.Message.Contains($"Could not determine message type from message header '{typeof(MyCommand).FullName}'")), "Message type could not be mapped.");
Assert.Multiple(() =>
{
Assert.That(context.Logs.Any(l => l.Level == LogLevel.Error && l.Message.Contains($"No handlers could be found for message type: {typeof(MyCommand).FullName}")), Is.True, "No handlers could be found was not logged.");
Assert.That(context.Logs.Any(l => l.Level == LogLevel.Warn && l.Message.Contains($"Message header '{typeof(MyCommand).FullName}' was mapped to type '{typeof(MyCommand).FullName}' but that type was not found in the message registry, ensure the same message registration conventions are used in all endpoints, especially if using unobtrusive mode.")), Is.False, "Message type could not be mapped.");
Assert.That(context.Logs.Any(l => l.Level == LogLevel.Warn && l.Message.Contains($"Could not determine message type from message header '{typeof(MyCommand).FullName}'")), Is.False, "Message type could not be mapped.");
});
}

public class Context : ScenarioContext { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public async Task Should_receive_the_message()
.Done(c => c.MessageInterfaceReceived)
.Run();

Assert.True(context.MessageInterfaceReceived);
Assert.That(context.MessageInterfaceReceived, Is.True);
}

public class Context : ScenarioContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ public async Task Should_receive_the_message()
.Done(c => c.MessageClassReceived && c.MessageInterfaceReceived)
.Run();

Assert.True(context.MessageClassReceived);
Assert.True(context.MessageInterfaceReceived);
Assert.Multiple(() =>
{
Assert.That(context.MessageClassReceived, Is.True);
Assert.That(context.MessageInterfaceReceived, Is.True);
});
}

public class Context : ScenarioContext
Expand Down
Loading

0 comments on commit d805eaf

Please sign in to comment.