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 (#344)

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

* Autoformat of test projects for NUnit2035

* Autoformat of test projects for NUnit2036

* Autoformat of test projects for NUnit2045

* Autoformat of test projects for NUnit2046

* Autoformat of test projects for NUnit2048
  • Loading branch information
danielmarbach authored Aug 20, 2024
1 parent 42e6013 commit 0d6a229
Show file tree
Hide file tree
Showing 10 changed files with 150 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="NServiceBus.AcceptanceTesting" 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 @@ -47,8 +47,11 @@ public async Task Should_not_send_messages_if_session_is_not_committed()
.Done(c => c.CompleteMessageReceived)
.Run();

Assert.True(result.CompleteMessageReceived);
Assert.False(result.MessageReceived);
Assert.Multiple(() =>
{
Assert.That(result.CompleteMessageReceived, Is.True);
Assert.That(result.MessageReceived, Is.False);
});
}

class Context : ScenarioContext, IInjectServiceProvider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public async Task Should_throw_exception_to_session_user()
.Done(c => c.TransactionalSessionException != null)
.Run();

Assert.IsFalse(context.MessageReceived);
Assert.That(context.MessageReceived, Is.False);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,15 @@ public async Task Should_fail_to_process_control_message()
.Done(c => c.FailedMessages.Count > 0)
.Run(TimeSpan.FromSeconds(90));

Assert.IsFalse(context.MessageReceived, "message should never be dispatched");
Assert.That(context.MessageReceived, Is.False, "message should never be dispatched");
var failedMessage = context.FailedMessages.Single().Value.Single();
// message should fail because it can't create an outbox record for the control message since the sender has already created the record and this causes a concurrency exception
// once the failed control message retries, the outbox record should be correctly found by the storage and the contained messages will be dispatched.
Assert.AreEqual($"Outbox message with id '{context.TransactionalSessionId}' is already present in storage.", failedMessage.Exception.Message);
Assert.AreEqual(context.TransactionalSessionId, failedMessage.MessageId);
Assert.Multiple(() =>
{
// message should fail because it can't create an outbox record for the control message since the sender has already created the record and this causes a concurrency exception
// once the failed control message retries, the outbox record should be correctly found by the storage and the contained messages will be dispatched.
Assert.That(failedMessage.Exception.Message, Is.EqualTo($"Outbox message with id '{context.TransactionalSessionId}' is already present in storage."));
Assert.That(failedMessage.MessageId, Is.EqualTo(context.TransactionalSessionId));
});

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@ public async Task Should_not_send_messages_if_session_is_not_committed()
.Done(c => c.CompleteMessageReceived)
.Run();

Assert.True(result.CompleteMessageReceived);
Assert.False(result.MessageReceived);
Assert.Multiple(() =>
{
Assert.That(result.CompleteMessageReceived, Is.True);
Assert.That(result.MessageReceived, Is.False);
});
}

[Test]
Expand All @@ -72,7 +75,7 @@ public async Task Should_send_immediate_dispatch_messages_even_if_session_is_not
.Run()
;

Assert.True(result.MessageReceived);
Assert.That(result.MessageReceived, Is.True);
}

[Test]
Expand All @@ -98,8 +101,11 @@ await transactionalSession.Open(new CustomTestingPersistenceOpenSessionOptions
.Done(c => c.EndpointsStarted)
.Run();

Assert.True(result.AmbientTransactionFoundBeforeAwait, "The ambient transaction was not visible before the await");
Assert.True(result.AmbientTransactionFoundAfterAwait, "The ambient transaction was not visible after the await");
Assert.Multiple(() =>
{
Assert.That(result.AmbientTransactionFoundBeforeAwait, Is.True, "The ambient transaction was not visible before the await");
Assert.That(result.AmbientTransactionFoundAfterAwait, Is.True, "The ambient transaction was not visible after the await");
});
}

class Context : ScenarioContext, IInjectServiceProvider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ await transactionalSession.Open(new CustomTestingPersistenceOpenSessionOptions
var transactionalSessionOrder = string.Join(Environment.NewLine, FilterLogs(transactionalContext, "TransactionalSession - "));
var pipelineOrder = string.Join(Environment.NewLine, FilterLogs(pipelineContext, "Pipeline - "));

Assert.AreEqual(pipelineOrder, transactionalSessionOrder, "The transactional session order of operation is different from the core order");
Assert.That(transactionalSessionOrder, Is.EqualTo(pipelineOrder), "The transactional session order of operation is different from the core order");
}

static IReadOnlyCollection<string> FilterLogs(ScenarioContext scenarioContext, string filter) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<PackageReference Include="GitHubActionsTestLogger" Version="2.4.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<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 0d6a229

Please sign in to comment.