Skip to content

Commit 4b374a8

Browse files
Migrate NUnit assertions to the constraint model in preparation of the NUnit 4 upgrade (#1434)
* Add Nunit.Analyzer to test projects * Autoformat of test projects for NUnit2001 * Autoformat of test projects for NUnit2002 * Autoformat of test projects for NUnit2003 * Autoformat of test projects for NUnit2004 * Autoformat of test projects for NUnit2005 * Autoformat of test projects for NUnit2007 * Autoformat of test projects for NUnit2018 * Autoformat of test projects for NUnit2019 * Autoformat of test projects for NUnit2045 * Autoformat of test projects for NUnit2046 * Autoformat of test projects for NUnit2048 * Fix remaining warnings and errors --------- Co-authored-by: danielmarbach <danielmarbach@users.noreply.github.com>
1 parent f13a4c5 commit 4b374a8

File tree

35 files changed

+273
-164
lines changed

35 files changed

+273
-164
lines changed

src/NServiceBus.Transport.RabbitMQ.AcceptanceTests/DelayedDelivery/When_deferring_a_message_longer_than_allowed_maximum.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public void Should_throw()
2828
.Run());
2929

3030
Assert.That(exception, Is.Not.Null);
31-
StringAssert.StartsWith("Message cannot be delayed by", exception.Message);
31+
Assert.That(exception.Message, Does.StartWith("Message cannot be delayed by"));
3232
}
3333

3434
public class Endpoint : EndpointConfigurationBuilder

src/NServiceBus.Transport.RabbitMQ.AcceptanceTests/NServiceBus.Transport.RabbitMQ.AcceptanceTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<PackageReference Include="GitHubActionsTestLogger" Version="2.4.1" />
1515
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
1616
<PackageReference Include="NUnit" Version="3.14.0" />
17+
<PackageReference Include="NUnit.Analyzers" Version="4.3.0" />
1718
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
1819
</ItemGroup>
1920

src/NServiceBus.Transport.RabbitMQ.AcceptanceTests/QuorumQueues/When_classic_endpoint_uses_quorum_error_queue.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ public void Should_fail_to_start()
2222
.Done(c => c.EndpointsStarted)
2323
.Run());
2424

25-
StringAssert.Contains("PRECONDITION_FAILED - inequivalent arg 'x-queue-type' for queue 'rabbitmq.transport.tests.quorum-error'", exception.Message);
26-
StringAssert.Contains("received none but current is the value 'quorum'", exception.Message);
25+
Assert.That(exception.Message, Does.Contain("PRECONDITION_FAILED - inequivalent arg 'x-queue-type' for queue 'rabbitmq.transport.tests.quorum-error'"));
26+
Assert.That(exception.Message, Does.Contain("received none but current is the value 'quorum'"));
2727
}
2828

2929
class ClassicQueueEndpoint : EndpointConfigurationBuilder

src/NServiceBus.Transport.RabbitMQ.AcceptanceTests/QuorumQueues/When_classic_endpoint_uses_quorum_queue.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ public void Should_fail_to_start()
2323
.Done(c => c.EndpointsStarted)
2424
.Run());
2525

26-
StringAssert.Contains("PRECONDITION_FAILED - inequivalent arg 'x-queue-type' for queue 'ClassicEndpointUsesQuorumQueue.ClassicQueueEndpoint'", exception.Message);
27-
StringAssert.Contains("received none but current is the value 'quorum'", exception.Message);
26+
Assert.That(exception.Message, Does.Contain("PRECONDITION_FAILED - inequivalent arg 'x-queue-type' for queue 'ClassicEndpointUsesQuorumQueue.ClassicQueueEndpoint'"));
27+
Assert.That(exception.Message, Does.Contain("received none but current is the value 'quorum'"));
2828
}
2929

3030
class ClassicQueueEndpoint : EndpointConfigurationBuilder

src/NServiceBus.Transport.RabbitMQ.AcceptanceTests/QuorumQueues/When_immediate_retries_with_quorum_queues.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@ public async Task Should_do_the_configured_number_of_retries()
1919
.Done(c => c.ForwardedToErrorQueue)
2020
.Run();
2121

22-
Assert.True(context.ForwardedToErrorQueue);
23-
Assert.AreEqual(numberOfRetries + 1, context.NumberOfTimesInvoked, "Message should be retried 5 times immediately");
24-
Assert.AreEqual(numberOfRetries, context.Logs.Count(l => l.Message
25-
.StartsWith($"Immediate Retry is going to retry message '{context.MessageId}' because of an exception:")));
22+
Assert.Multiple(() =>
23+
{
24+
Assert.That(context.ForwardedToErrorQueue, Is.True);
25+
Assert.That(context.NumberOfTimesInvoked, Is.EqualTo(numberOfRetries + 1), "Message should be retried 5 times immediately");
26+
Assert.That(context.Logs.Count(l => l.Message
27+
.StartsWith($"Immediate Retry is going to retry message '{context.MessageId}' because of an exception:")), Is.EqualTo(numberOfRetries));
28+
});
2629
}
2730

2831
const int numberOfRetries = 5;

src/NServiceBus.Transport.RabbitMQ.AcceptanceTests/QuorumQueues/When_quorum_endpoint_uses_classic_error_queue.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ public void Should_fail_to_start()
2222
.Done(c => c.EndpointsStarted)
2323
.Run());
2424

25-
StringAssert.Contains("PRECONDITION_FAILED - inequivalent arg 'x-queue-type' for queue 'rabbitmq.transport.tests.classic-error'", exception.Message);
26-
StringAssert.Contains("received the value 'quorum' of type 'longstr' but current is none'", exception.Message);
25+
Assert.That(exception.Message, Does.Contain("PRECONDITION_FAILED - inequivalent arg 'x-queue-type' for queue 'rabbitmq.transport.tests.classic-error'"));
26+
Assert.That(exception.Message, Does.Contain("received the value 'quorum' of type 'longstr' but current is none'"));
2727
}
2828

2929
class QuorumQueueEndpoint : EndpointConfigurationBuilder

src/NServiceBus.Transport.RabbitMQ.AcceptanceTests/QuorumQueues/When_quorum_endpoint_uses_classic_queue.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ public void Should_fail_to_start()
2222
.Done(c => c.EndpointsStarted)
2323
.Run());
2424

25-
StringAssert.Contains("PRECONDITION_FAILED - inequivalent arg 'x-queue-type' for queue 'QuorumEndpointUsesClassicQueue.QuorumQueueEndpoint'", exception.Message);
26-
StringAssert.Contains("received the value 'quorum' of type 'longstr' but current is none", exception.Message);
25+
Assert.That(exception.Message, Does.Contain("PRECONDITION_FAILED - inequivalent arg 'x-queue-type' for queue 'QuorumEndpointUsesClassicQueue.QuorumQueueEndpoint'"));
26+
Assert.That(exception.Message, Does.Contain("received the value 'quorum' of type 'longstr' but current is none"));
2727
}
2828

2929
class QuorumQueueEndpoint : EndpointConfigurationBuilder

src/NServiceBus.Transport.RabbitMQ.AcceptanceTests/QuorumQueues/When_starting_endpoint_using_quorum_queues.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,19 @@ await Scenario.Define<ScenarioContext>()
3434
using (var channel = connection.CreateModel())
3535
{
3636
var mainQueueException = Assert.Catch<RabbitMQClientException>(() => channel.DeclareClassicQueue(endpointInputQueue));
37-
StringAssert.Contains("PRECONDITION_FAILED - inequivalent arg 'x-queue-type'", mainQueueException.Message);
37+
Assert.That(mainQueueException.Message, Does.Contain("PRECONDITION_FAILED - inequivalent arg 'x-queue-type'"));
3838
}
3939

4040
using (var channel = connection.CreateModel())
4141
{
4242
var instanceSpecificQueueException = Assert.Catch<RabbitMQClientException>(() => channel.DeclareClassicQueue(endpointInputQueue + "-disc"));
43-
StringAssert.Contains("PRECONDITION_FAILED - inequivalent arg 'x-queue-type'", instanceSpecificQueueException.Message);
43+
Assert.That(instanceSpecificQueueException.Message, Does.Contain("PRECONDITION_FAILED - inequivalent arg 'x-queue-type'"));
4444
}
4545

4646
using (var channel = connection.CreateModel())
4747
{
4848
var satelliteReceiver = Assert.Catch<RabbitMQClientException>(() => channel.DeclareClassicQueue("QuorumQueueSatelliteReceiver"));
49-
StringAssert.Contains("PRECONDITION_FAILED - inequivalent arg 'x-queue-type'", satelliteReceiver.Message);
49+
Assert.That(satelliteReceiver.Message, Does.Contain("PRECONDITION_FAILED - inequivalent arg 'x-queue-type'"));
5050
}
5151
}
5252
}

src/NServiceBus.Transport.RabbitMQ.AcceptanceTests/When_publishing_message_implementing_interface_in_direct_topology.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public async Task Should_log_a_warning()
2929
.Done(c => c.GotTheMessage)
3030
.Run();
3131

32-
Assert.True(context.Logs.Any(l => l.Level == LogLevel.Warn && l.Message.Contains("The direct routing topology cannot properly publish a message type that implements")));
32+
Assert.That(context.Logs.Any(l => l.Level == LogLevel.Warn && l.Message.Contains("The direct routing topology cannot properly publish a message type that implements")), Is.True);
3333
}
3434

3535
public class Publisher : EndpointConfigurationBuilder

src/NServiceBus.Transport.RabbitMQ.AcceptanceTests/When_receiving_a_message.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public async Task Should_have_access_to_BasicDeliverEventArgs()
1717
.Done(c => c.MessageReceived)
1818
.Run();
1919

20-
Assert.True(scenario.HandlerHasAccessToBasicDeliverEventArgs, "The handler should have access to BasicDeliverEventArgs");
20+
Assert.That(scenario.HandlerHasAccessToBasicDeliverEventArgs, Is.True, "The handler should have access to BasicDeliverEventArgs");
2121
}
2222

2323
public class Receiver : EndpointConfigurationBuilder

0 commit comments

Comments
 (0)