Skip to content

Commit

Permalink
Migrate NUnit assertions to the constraint model in preparation of th…
Browse files Browse the repository at this point in the history
…e NUnit 4 upgrade (#1543)

* Add Nunit.Analyzer to test projects

* 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 NUnit2010

* Autoformat of test projects for NUnit2011

* Autoformat of test projects for NUnit2015

* Autoformat of test projects for NUnit2017

* Autoformat of test projects for NUnit2018

* Autoformat of test projects for NUnit2019

* Autoformat of test projects for NUnit2030

* Autoformat of test projects for NUnit2031

* Autoformat of test projects for NUnit2035

* Autoformat of test projects for NUnit2036

* Autoformat of test projects for NUnit2043

* Autoformat of test projects for NUnit2045

* Autoformat of test projects for NUnit2046

* Autoformat of test projects for NUnit2048

* Autoformat of test projects for NUnit2049

* Autoformat of test projects for NUnit2050

* Fix remaining warnings and errors
  • Loading branch information
danielmarbach authored Aug 20, 2024
1 parent e38aaa5 commit e3cf475
Show file tree
Hide file tree
Showing 78 changed files with 326 additions and 240 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ await Scenario.Define<Context>()
.ConfigureAwait(false);
});

StringAssert.StartsWith("When both sagas and outbox are enabled, SQL persistence must be enabled for either both sagas and outbox, or neither.", ex.Message);
Assert.That(ex.Message, Does.StartWith("When both sagas and outbox are enabled, SQL persistence must be enabled for either both sagas and outbox, or neither."));
}

public class Context : ScenarioContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ public async Task Should_not_enable_synchronized_storage_session()
.Run()
.ConfigureAwait(false);

Assert.IsTrue(context.Done);
Assert.IsFalse(context.SessionCreated);
StringAssert.StartsWith("Cannot access the SQL synchronized storage session", context.ExceptionMessage);
Assert.Multiple(() =>
{
Assert.That(context.Done, Is.True);
Assert.That(context.SessionCreated, Is.False);
});
Assert.That(context.ExceptionMessage, Does.StartWith("Cannot access the SQL synchronized storage session"));
}

public class Context : ScenarioContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ await Scenario.Define<Context>()
.ConfigureAwait(false);
});

StringAssert.StartsWith("When both sagas and outbox are enabled, SQL persistence must be enabled for either both sagas and outbox, or neither.", ex.Message);
Assert.That(ex.Message, Does.StartWith("When both sagas and outbox are enabled, SQL persistence must be enabled for either both sagas and outbox, or neither."));
}

public class Context : ScenarioContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ public async Task Should_create_synchronized_storage_session()
.Run()
.ConfigureAwait(false);

Assert.True(context.Done);
Assert.True(context.SessionCreated);
Assert.Multiple(() =>
{
Assert.That(context.Done, Is.True);
Assert.That(context.SessionCreated, Is.True);
});
}

public 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_execute_installers()
.ConfigureAwait(false);

// If installers were run, we'd get an System.Exception: "ConnectionBuilder must be defined."
Assert.True(context.EndpointsStarted);
Assert.That(context.EndpointsStarted, Is.True);
}

public class Context : ScenarioContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ await Scenario.Define<Context>()
.ConfigureAwait(false);
});

Assert.IsTrue(ex.Message == "Saga implementations must inherit from either Saga<T> or SqlSaga<T> directly. Deep class hierarchies are not supported.");
Assert.That(ex.Message, Is.EqualTo("Saga implementations must inherit from either Saga<T> or SqlSaga<T> directly. Deep class hierarchies are not supported."));
}

public 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_be_able_to_start_the_endpoint()
.Run()
.ConfigureAwait(false);

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

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_inject_synchronized_session_into_handler()
.Run()
.ConfigureAwait(false);

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

public class Context : ScenarioContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public async Task Should_float_transaction_scope_into_handler()
.Run()
.ConfigureAwait(false);

Assert.NotNull(context.Transaction);
Assert.That(context.Transaction, Is.Not.Null);
}

public class Context : ScenarioContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@ public async Task Should_inject_synchronized_session_into_handler()
.Run()
.ConfigureAwait(false);

Assert.IsNotNull(context.ConnectionInjectedToFirstHandler);
Assert.IsNotNull(context.ConnectionInjectedToSecondHandler);
Assert.IsNotNull(context.ConnectionInjectedToThirdHandler);
Assert.AreSame(context.ConnectionInjectedToFirstHandler, context.ConnectionInjectedToSecondHandler);
Assert.AreNotSame(context.ConnectionInjectedToFirstHandler, context.ConnectionInjectedToThirdHandler);
Assert.Multiple(() =>
{
Assert.That(context.ConnectionInjectedToFirstHandler, Is.Not.Null);
Assert.That(context.ConnectionInjectedToSecondHandler, Is.Not.Null);
Assert.That(context.ConnectionInjectedToThirdHandler, Is.Not.Null);
});
Assert.That(context.ConnectionInjectedToSecondHandler, Is.SameAs(context.ConnectionInjectedToFirstHandler));
Assert.That(context.ConnectionInjectedToThirdHandler, Is.Not.SameAs(context.ConnectionInjectedToFirstHandler));
}

public class Context : ScenarioContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
<PackageReference Include="NServiceBus.AcceptanceTests.Sources" Version="9.1.1" />
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit.Analyzers" Version="4.3.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ public async Task Should_use_existing_saga()
.Run()
.ConfigureAwait(false);

Assert.True(context.StartSagaFinderUsed);
Assert.True(context.SomeOtherFinderUsed);
Assert.Multiple(() =>
{
Assert.That(context.StartSagaFinderUsed, Is.True);
Assert.That(context.SomeOtherFinderUsed, Is.True);
});
}

public class Context : ScenarioContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ await Scenario.Define<Context>()
.Done(c => c.StartSagaFinderUsed)
.Run());

Assert.AreEqual("The saga 'When_correlation_property_is_not_mapped+SagaEndpoint+TestSaga' defines a correlation property 'Property' which is not mapped to any message. Either map it or remove it from the saga definition.", exception.Message);
Assert.That(exception.Message, Is.EqualTo("The saga 'When_correlation_property_is_not_mapped+SagaEndpoint+TestSaga' defines a correlation property 'Property' which is not mapped to any message. Either map it or remove it from the saga definition."));
}

public class Context : ScenarioContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public async Task Should_use_existing_saga()
.Run()
.ConfigureAwait(false);

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

public class Context : ScenarioContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public async Task Should_correlate_the_following_message_correctly()
.Run()
.ConfigureAwait(false);

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

public class Context : ScenarioContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ public async Task Should_remove_old_property_after_phase_three()
connection.ExecuteCommand(SagaScriptBuilder.BuildCreateScript(sagaPhase3, dialect), "");
var phase3Schema = GetSchema(connection);

CollectionAssert.Contains(phase1Schema, "Correlation_OrderNumber");
CollectionAssert.DoesNotContain(phase1Schema, "Correlation_OrderId");
Assert.That(phase1Schema, Has.Member("Correlation_OrderNumber"));
Assert.That(phase1Schema, Has.No.Member("Correlation_OrderId"));

CollectionAssert.Contains(phase2Schema, "Correlation_OrderNumber");
CollectionAssert.Contains(phase2Schema, "Correlation_OrderId");
Assert.That(phase2Schema, Has.Member("Correlation_OrderNumber"));
Assert.That(phase2Schema, Has.Member("Correlation_OrderId"));

CollectionAssert.DoesNotContain(phase3Schema, "Correlation_OrderNumber");
CollectionAssert.Contains(phase3Schema, "Correlation_OrderId");
Assert.That(phase3Schema, Has.No.Member("Correlation_OrderNumber"));
Assert.That(phase3Schema, Has.Member("Correlation_OrderId"));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public async Task Should_throw_if_no_tenant_id()
var exception = failed.Exception;
var msg = exception.Message;

Assert.That(msg.Contains("unable to determine the tenant id"));
Assert.That(msg, Does.Contain("unable to determine the tenant id"));
}

[Test]
Expand Down Expand Up @@ -111,8 +111,11 @@ async Task RunTest<TEndpointType>(bool useOutbox)
.Run(TimeSpan.FromSeconds(30))
.ConfigureAwait(false);

Assert.AreEqual("nservicebus_tenanta", context.TenantADbName);
Assert.AreEqual("nservicebus_tenantb", context.TenantBDbName);
Assert.Multiple(() =>
{
Assert.That(context.TenantADbName, Is.EqualTo("nservicebus_tenanta"));
Assert.That(context.TenantBDbName, Is.EqualTo("nservicebus_tenantb"));
});
}

[Test]
Expand Down Expand Up @@ -149,8 +152,11 @@ public async Task Use_multiple_tenant_headers()
.Run(TimeSpan.FromSeconds(30))
.ConfigureAwait(false);

Assert.AreEqual("nservicebus_tenanta", context.TenantADbName);
Assert.AreEqual("nservicebus_tenantb", context.TenantBDbName);
Assert.Multiple(() =>
{
Assert.That(context.TenantADbName, Is.EqualTo("nservicebus_tenanta"));
Assert.That(context.TenantBDbName, Is.EqualTo("nservicebus_tenantb"));
});
}

static void ConfigureMultiTenant(EndpointConfiguration c, bool useOutbox = true, bool cleanOutbox = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<PackageReference Include="NServiceBus.AcceptanceTests.Sources" Version="9.1.1" GeneratePathProperty="true" />
<PackageReference Include="NServiceBus.Transport.SqlServer" Version="8.1.3" />
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit.Analyzers" Version="4.3.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@ public async Task Should_rollback_saga_data_changes_when_transport_transaction_i
.Done(c => c.ReplyReceived)
.Run();

Assert.True(context.ReplyReceived);
Assert.IsFalse(context.TransactionEscalatedToDTC);
Assert.AreEqual(2, context.SagaInvocationCount, "Saga handler should be called twice");
Assert.AreEqual(1, context.SagaCounterValue, "Saga value should be incremented only once");
Assert.Multiple(() =>
{
Assert.That(context.ReplyReceived, Is.True);
Assert.That(context.TransactionEscalatedToDTC, Is.False);
Assert.That(context.SagaInvocationCount, Is.EqualTo(2), "Saga handler should be called twice");
Assert.That(context.SagaCounterValue, Is.EqualTo(1), "Saga value should be incremented only once");
});
}

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

Assert.True(context.ReplyReceived);
Assert.IsFalse(context.TransactionEscalatedToDTC);
Assert.AreEqual(2, context.InvocationCount, "Handler should be called twice");
Assert.AreEqual(1, context.RecordCount, "There should be only once record in the database");
Assert.Multiple(() =>
{
Assert.That(context.ReplyReceived, Is.True);
Assert.That(context.TransactionEscalatedToDTC, Is.False);
Assert.That(context.InvocationCount, Is.EqualTo(2), "Handler should be called twice");
Assert.That(context.RecordCount, Is.EqualTo(1), "There should be only once record in the database");
});
}

public class Context : ScenarioContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ public async Task Should_inject_synchronized_session_into_handler(TransportTrans
.Run()
.ConfigureAwait(false);

Assert.NotNull(context.InjectedSession.Connection);
Assert.That(context.InjectedSession.Connection, Is.Not.Null);
if (transactionMode == TransportTransactionMode.TransactionScope)
{
Assert.IsNull(context.InjectedSession.Transaction);
Assert.That(context.InjectedSession.Transaction, Is.Null);
}
else
{
Assert.IsNotNull(context.InjectedSession.Transaction);
Assert.That(context.InjectedSession.Transaction, Is.Not.Null);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
<PackageReference Include="NServiceBus.AcceptanceTests.Sources" Version="9.1.1" />
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit.Analyzers" Version="4.3.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ public async Task Should_use_existing_saga()
.Run()
.ConfigureAwait(false);

Assert.True(context.StartSagaFinderUsed);
Assert.True(context.SomeOtherFinderUsed);
Assert.Multiple(() =>
{
Assert.That(context.StartSagaFinderUsed, Is.True);
Assert.That(context.SomeOtherFinderUsed, Is.True);
});
}

public class Context : ScenarioContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ await Scenario.Define<Context>()
.Done(c => c.StartSagaFinderUsed)
.Run());

Assert.AreEqual("The saga 'When_correlation_property_is_not_mapped+SagaEndpoint+TestSaga' defines a correlation property 'Property' which is not mapped to any message. Either map it or remove it from the saga definition.", exception.Message);
Assert.That(exception.Message, Is.EqualTo("The saga 'When_correlation_property_is_not_mapped+SagaEndpoint+TestSaga' defines a correlation property 'Property' which is not mapped to any message. Either map it or remove it from the saga definition."));
}

public class Context : ScenarioContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public async Task Should_use_existing_saga()
.Run()
.ConfigureAwait(false);

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

public class Context : ScenarioContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public async Task Should_correlate_the_following_message_correctly()
.Run()
.ConfigureAwait(false);

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

public class Context : ScenarioContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ public async Task Should_remove_old_property_after_phase_three()
connection.ExecuteCommand(SagaScriptBuilder.BuildCreateScript(sagaPhase3, dialect), "");
var phase3Schema = GetSchema(connection);

CollectionAssert.Contains(phase1Schema, "Correlation_OrderNumber");
CollectionAssert.DoesNotContain(phase1Schema, "Correlation_OrderId");
Assert.That(phase1Schema, Has.Member("Correlation_OrderNumber"));
Assert.That(phase1Schema, Has.No.Member("Correlation_OrderId"));

CollectionAssert.Contains(phase2Schema, "Correlation_OrderNumber");
CollectionAssert.Contains(phase2Schema, "Correlation_OrderId");
Assert.That(phase2Schema, Has.Member("Correlation_OrderNumber"));
Assert.That(phase2Schema, Has.Member("Correlation_OrderId"));

CollectionAssert.DoesNotContain(phase3Schema, "Correlation_OrderNumber");
CollectionAssert.Contains(phase3Schema, "Correlation_OrderId");
Assert.That(phase3Schema, Has.No.Member("Correlation_OrderNumber"));
Assert.That(phase3Schema, Has.Member("Correlation_OrderId"));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public async Task Should_throw_if_no_tenant_id()
var exception = failed.Exception;
var msg = exception.Message;

Assert.That(msg.Contains("unable to determine the tenant id"));
Assert.That(msg, Does.Contain("unable to determine the tenant id"));
}

[Test]
Expand Down Expand Up @@ -111,8 +111,11 @@ async Task RunTest<TEndpointType>(bool useOutbox)
.Run(TimeSpan.FromSeconds(30))
.ConfigureAwait(false);

Assert.AreEqual("nservicebus_tenanta", context.TenantADbName);
Assert.AreEqual("nservicebus_tenantb", context.TenantBDbName);
Assert.Multiple(() =>
{
Assert.That(context.TenantADbName, Is.EqualTo("nservicebus_tenanta"));
Assert.That(context.TenantBDbName, Is.EqualTo("nservicebus_tenantb"));
});
}

[Test]
Expand Down Expand Up @@ -150,8 +153,11 @@ public async Task Use_multiple_tenant_headers()
.Run(TimeSpan.FromSeconds(30))
.ConfigureAwait(false);

Assert.AreEqual("nservicebus_tenanta", context.TenantADbName);
Assert.AreEqual("nservicebus_tenantb", context.TenantBDbName);
Assert.Multiple(() =>
{
Assert.That(context.TenantADbName, Is.EqualTo("nservicebus_tenanta"));
Assert.That(context.TenantBDbName, Is.EqualTo("nservicebus_tenantb"));
});
}

static void ConfigureMultiTenant(EndpointConfiguration c, bool useOutbox = true, bool cleanOutbox = true)
Expand Down
1 change: 1 addition & 0 deletions src/MySqlAcceptanceTests/MySqlAcceptanceTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
<PackageReference Include="NServiceBus.AcceptanceTests.Sources" Version="9.1.1" GeneratePathProperty="true" />
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit.Analyzers" Version="4.3.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
</ItemGroup>

Expand Down
Loading

0 comments on commit e3cf475

Please sign in to comment.