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

* Add NUnit as a direct reference to test projects

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

* Autoformat of test projects for NUnit2035

* Autoformat of test projects for NUnit2045

* Fixing errors

* Fixing NUnit1030

* Small cleanup of package refs

---------

Co-authored-by: Christian <christian.quiros+github@gmamil.com>
Co-authored-by: Daniel Marbach <danielmarbach@users.noreply.github.com>
  • Loading branch information
3 people authored Aug 22, 2024
1 parent ba21a31 commit 7756410
Show file tree
Hide file tree
Showing 15 changed files with 59 additions and 29 deletions.
2 changes: 2 additions & 0 deletions src/AcceptanceTests/AcceptanceTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
<ItemGroup>
<PackageReference Include="NServiceBus.AcceptanceTests.Sources" Version="8.1.1" GeneratePathProperty="true" />
<PackageReference Include="GitHubActionsTestLogger" Version="2.4.1" />
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit.Analyzers" Version="4.3.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ public async Task Should_share_it()
.Done(c => c.OrderAckReceived == 1)
.Run(TimeSpan.FromSeconds(20));

Assert.AreEqual(1, context.OrderAckReceived, "Order ack should have been received");
Assert.AreEqual(context.TestRunId.ToString(), context.Value, "TestRunId should have been stored in dictionary");
Assert.Multiple(() =>
{
Assert.That(context.OrderAckReceived, Is.EqualTo(1), "Order ack should have been received");
Assert.That(context.Value, Is.EqualTo(context.TestRunId.ToString()), "TestRunId should have been stored in dictionary");
});
}

class Context : ScenarioContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public async Task Should_use_custom_collection_name()
{
var conditionalValue = await collection.TryGetValueAsync(tx, context.SagaId.Value);

Assert.True(conditionalValue.HasValue);
Assert.That(conditionalValue.HasValue, Is.True);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public async Task Should_use_saga_data_type_name()
{
var conditionalValue = await collection.TryGetValueAsync(tx, context.SagaId.Value);

Assert.True(conditionalValue.HasValue);
Assert.That(conditionalValue.HasValue, Is.True);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@ public async Task Should_succeed_without_retries()
.Done(c => c.Done)
.Run();

Assert.AreEqual(0, context.NumberOfRetries);
Assert.IsTrue(context.MessagesSent);
Assert.IsTrue(context.SagaStarted);
Assert.Multiple(() =>
{
Assert.That(context.NumberOfRetries, Is.EqualTo(0));
Assert.That(context.MessagesSent, Is.True);
Assert.That(context.SagaStarted, Is.True);
});
}

public class Context : ScenarioContext
Expand Down
24 changes: 15 additions & 9 deletions src/ApiTests/ApiStandardTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@ public void VerifyFeatureNaming()
{
foreach (var featureType in GetFeatures())
{
Assert.AreEqual("NServiceBus.Features", featureType.Namespace, "Features should be in the NServiceBus.Features namespace. " + featureType.FullName);
Assert.IsFalse(featureType.Name.EndsWith("Feature"), "Features should not be suffixed with 'Feature'. " + featureType.FullName);
Assert.Multiple(() =>
{
Assert.That(featureType.Namespace, Is.EqualTo("NServiceBus.Features"), "Features should be in the NServiceBus.Features namespace. " + featureType.FullName);
Assert.That(featureType.Name, Does.Not.EndWith("Feature"), "Features should not be suffixed with 'Feature'. " + featureType.FullName);
});
if (featureType.IsPublic)
{
var constructorInfo = featureType.GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public, null, new Type[]
{
}, null);
Assert.IsFalse(constructorInfo.IsPublic, "Features should have an internal constructor. " + featureType.FullName);
Assert.That(constructorInfo.IsPublic, Is.False, "Features should have an internal constructor. " + featureType.FullName);
}
}
}
Expand All @@ -51,7 +54,7 @@ public void NonPublicShouldHaveSimpleNamespace()
x.Namespace != "NServiceBus.Persistence.ServiceFabric").ToList();
if (types.Count > 0)
{
Assert.IsEmpty(types, "Non public types should have 'NServiceBus.Persistence.ServiceFabric' namespace\r\n" + string.Join(Environment.NewLine, types.Select(x => x.FullName)));
Assert.That(types, Is.Empty, "Non public types should have 'NServiceBus.Persistence.ServiceFabric' namespace\r\n" + string.Join(Environment.NewLine, types.Select(x => x.FullName)));
}
}

Expand All @@ -71,7 +74,7 @@ public void LoggersShouldBeStaticField()
{
if (field.FieldType == typeof(ILog))
{
Assert.IsTrue(field.IsStatic, "Logger fields should be static " + type.FullName);
Assert.That(field.IsStatic, Is.True, "Logger fields should be static " + type.FullName);
}
}
}
Expand All @@ -82,9 +85,12 @@ public void VerifyBehaviorNaming()
{
foreach (var featureType in GetBehaviors())
{
Assert.IsFalse(featureType.IsPublic, "Behaviors should internal " + featureType.FullName);
Assert.AreEqual("NServiceBus", featureType.Namespace, "Behaviors should be in the NServiceBus namespace since it reduces the 'wall of text' problem when looking at pipeline stack traces. " + featureType.FullName);
Assert.IsTrue(featureType.Name.EndsWith("Terminator") || featureType.Name.EndsWith("Behavior") || featureType.Name.EndsWith("Connector"), "Behaviors should be suffixed with 'Behavior' or 'Connector'. " + featureType.FullName);
Assert.Multiple(() =>
{
Assert.That(featureType.IsPublic, Is.False, "Behaviors should internal " + featureType.FullName);
Assert.That(featureType.Namespace, Is.EqualTo("NServiceBus"), "Behaviors should be in the NServiceBus namespace since it reduces the 'wall of text' problem when looking at pipeline stack traces. " + featureType.FullName);
Assert.That(featureType.Name.EndsWith("Terminator") || featureType.Name.EndsWith("Behavior") || featureType.Name.EndsWith("Connector"), Is.True, "Behaviors should be suffixed with 'Behavior' or 'Connector'. " + featureType.FullName);
});
}
}

Expand All @@ -93,7 +99,7 @@ public void VerifyAttributesAreSealed()
{
foreach (var attributeType in GetAttributeTypes())
{
Assert.IsTrue(attributeType.IsSealed, attributeType.FullName + " should be sealed.");
Assert.That(attributeType.IsSealed, Is.True, attributeType.FullName + " should be sealed.");
}
}

Expand Down
1 change: 1 addition & 0 deletions src/ApiTests/ApiTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<PackageReference Include="GitHubActionsTestLogger" Version="2.4.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit.Analyzers" Version="4.3.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageReference Include="Particular.Approvals" Version="0.6.0" />
<PackageReference Include="PublicApiGenerator" Version="11.1.0" />
Expand Down
9 changes: 6 additions & 3 deletions src/PersistenceTests/PersistenceTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@
<ProjectReference Include="..\TestRunner\TestRunner.csproj" />
</ItemGroup>

<ItemGroup>
<!-- DO NOT REMOVE Microsoft.Azure.ServiceFabric.Data, it is added so that dependabot knows about version changes-->
<ItemGroup Label="Pinned packages to prevent transitive dependencies issues">
<PackageReference Include="Microsoft.ServiceFabric.Data" Version="6.1.1390" />
<!-- DO NOT REMOVE Newtonsoft.Json, it is added so that dependabot knows about version changes-->
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="NServiceBus.PersistenceTests.Sources" Version="8.1.6" />
<PackageReference Include="GitHubActionsTestLogger" Version="2.4.1" />
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit.Analyzers" Version="4.3.0" />
</ItemGroup>

</Project>
3 changes: 2 additions & 1 deletion src/TestHarness/R.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace TestHarness
{
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Fabric;
Expand Down Expand Up @@ -155,7 +156,7 @@ static async Task TearDown(CancellationToken cancellationToken = default)
}
}

public static IEnumerable<ITestCaseData> GetTestCases()
public static IEnumerable GetTestCases()
{
string[] enumerable;
try
Expand Down
4 changes: 3 additions & 1 deletion src/TestHarness/TestHarness.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
<ItemGroup>
<PackageReference Include="GitHubActionsTestLogger" Version="2.4.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit.Analyzers" Version="4.3.0" />
</ItemGroup>

</Project>
1 change: 1 addition & 0 deletions src/TestRunner/TestRunner.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.ServiceFabric.Services.Remoting" Version="6.1.1390" />
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit.Analyzers" Version="4.3.0" />
</ItemGroup>

</Project>
9 changes: 6 additions & 3 deletions src/Tests/Outbox/ServiceFabricOutboxTransactionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ public async Task Commit_completes_transaction()
{
var value = await dictionary.TryGetValueAsync(tx, "Key");

Assert.True(value.HasValue);
Assert.AreEqual("Value", value.Value);
Assert.Multiple(() =>
{
Assert.That(value.HasValue, Is.True);
Assert.That(value.Value, Is.EqualTo("Value"));
});
}
}

Expand All @@ -43,7 +46,7 @@ public async Task Dispose_transaction_owned_without_complete_rolls_back()
{
var value = await dictionary.TryGetValueAsync(tx, "Key");

Assert.False(value.HasValue);
Assert.That(value.HasValue, Is.False);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public async Task CompleteAsync_transaction_owned_completes_transaction()
var value = await dictionary.TryGetValueAsync(tx, "Key");

Assert.True(value.HasValue);
Assert.AreEqual("Value", value.Value);
Assert.That(value.Value, Is.EqualTo("Value"));
}
}

Expand Down Expand Up @@ -112,7 +112,7 @@ public async Task Dispose_transaction_not_owned_does_not_rollback_transaction()
var value = await dictionary.TryGetValueAsync(tx, "Key");

Assert.True(value.HasValue);
Assert.AreEqual("Value", value.Value);
Assert.That(value.Value, Is.EqualTo("Value"));
}
}

Expand Down
7 changes: 5 additions & 2 deletions src/Tests/Testing/TestableStorageSessionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ public async Task CanBeUsed()
{
var value = await dictionary.TryGetValueAsync(tx, "Key");

Assert.True(value.HasValue);
Assert.AreEqual("Value", value.Value);
Assert.Multiple(() =>
{
Assert.That(value.HasValue, Is.True);
Assert.That(value.Value, Is.EqualTo("Value"));
});
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/Tests/Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="NServiceBus.Testing" Version="8.1.0" />
<PackageReference Include="NServiceBus.Testing" Version="8.1.0" />
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit.Analyzers" Version="4.3.0" />
</ItemGroup>

</Project>

0 comments on commit 7756410

Please sign in to comment.