From 017e645557a9162c216c7b6866a8eaaa72d4f9be Mon Sep 17 00:00:00 2001 From: Gustas <37534529+PunkPun@users.noreply.github.com> Date: Thu, 9 Jan 2025 16:49:56 +0200 Subject: [PATCH] Upgrade unit testing --- OpenRA.Test/OpenRA.Game/ActorInfoTest.cs | 30 ++++---- OpenRA.Test/OpenRA.Game/CPosTest.cs | 6 +- OpenRA.Test/OpenRA.Game/MediatorTest.cs | 2 +- OpenRA.Test/OpenRA.Game/MiniYamlTest.cs | 72 +++++++++---------- OpenRA.Test/OpenRA.Game/PngTest.cs | 8 +-- OpenRA.Test/OpenRA.Game/PriorityQueueTest.cs | 40 +++++------ OpenRA.Test/OpenRA.Game/Sha1Tests.cs | 4 +- .../OpenRA.Game/SpatiallyPartitionedTest.cs | 70 +++++++++--------- .../OpenRA.Game/VariableExpressionTest.cs | 8 +-- OpenRA.Test/OpenRA.Test.csproj | 8 +-- 10 files changed, 124 insertions(+), 124 deletions(-) diff --git a/OpenRA.Test/OpenRA.Game/ActorInfoTest.cs b/OpenRA.Test/OpenRA.Game/ActorInfoTest.cs index a3c409c18e..8dc8ffa094 100644 --- a/OpenRA.Test/OpenRA.Game/ActorInfoTest.cs +++ b/OpenRA.Test/OpenRA.Game/ActorInfoTest.cs @@ -45,7 +45,7 @@ namespace OpenRA.Test var actorInfo = new ActorInfo("test", unorderedTraits); var orderedTraits = actorInfo.TraitsInConstructOrder().ToArray(); - CollectionAssert.AreEquivalent(unorderedTraits, orderedTraits); + Assert.That(unorderedTraits, Is.EquivalentTo(orderedTraits)); for (var i = 0; i < orderedTraits.Length; i++) { @@ -53,7 +53,7 @@ namespace OpenRA.Test ActorInfo.PrerequisitesOf(orderedTraits[i]).Concat(ActorInfo.OptionalPrerequisitesOf(orderedTraits[i])); var traitTypesThatOccurAfterThisTrait = orderedTraits.Skip(i + 1).Select(ti => ti.GetType()); var traitTypesThatShouldOccurEarlier = traitTypesThatOccurAfterThisTrait.Intersect(traitTypesThatMustOccurBeforeThisTrait); - CollectionAssert.IsEmpty(traitTypesThatShouldOccurEarlier, "Dependency order has not been satisfied."); + Assert.That(traitTypesThatShouldOccurEarlier, Is.Empty, "Dependency order has not been satisfied."); } } @@ -64,7 +64,7 @@ namespace OpenRA.Test var actorInfo = new ActorInfo("test", unorderedTraits); var orderedTraits = actorInfo.TraitsInConstructOrder().ToArray(); - CollectionAssert.AreEquivalent(unorderedTraits, orderedTraits); + Assert.That(unorderedTraits, Is.EquivalentTo(orderedTraits)); for (var i = 0; i < orderedTraits.Length; i++) { @@ -72,7 +72,7 @@ namespace OpenRA.Test ActorInfo.PrerequisitesOf(orderedTraits[i]).Concat(ActorInfo.OptionalPrerequisitesOf(orderedTraits[i])); var traitTypesThatOccurAfterThisTrait = orderedTraits.Skip(i + 1).Select(ti => ti.GetType()); var traitTypesThatShouldOccurEarlier = traitTypesThatOccurAfterThisTrait.Intersect(traitTypesThatMustOccurBeforeThisTrait); - CollectionAssert.IsEmpty(traitTypesThatShouldOccurEarlier, "Dependency order has not been satisfied."); + Assert.That(traitTypesThatShouldOccurEarlier, Is.Empty, "Dependency order has not been satisfied."); } } @@ -82,10 +82,10 @@ namespace OpenRA.Test var actorInfo = new ActorInfo("test", new MockBInfo(), new MockCInfo()); var ex = Assert.Throws(() => actorInfo.TraitsInConstructOrder()); - StringAssert.Contains(nameof(MockBInfo), ex.Message, "Exception message did not report a missing dependency."); - StringAssert.Contains(nameof(MockCInfo), ex.Message, "Exception message did not report a missing dependency."); - StringAssert.Contains(nameof(MockInheritInfo), ex.Message, "Exception message did not report a missing dependency (from a base class)."); - StringAssert.Contains(nameof(IMock), ex.Message, "Exception message did not report a missing dependency (from an interface)."); + Assert.That(ex.Message, Does.Contain(nameof(MockBInfo)), "Exception message did not report a missing dependency."); + Assert.That(ex.Message, Does.Contain(nameof(MockCInfo)), "Exception message did not report a missing dependency."); + Assert.That(ex.Message, Does.Contain(nameof(MockInheritInfo)), "Exception message did not report a missing dependency (from a base class)."); + Assert.That(ex.Message, Does.Contain(nameof(IMock)), "Exception message did not report a missing dependency (from an interface)."); } [TestCase(TestName = "Trait ordering allows optional dependencies to be missing")] @@ -95,7 +95,7 @@ namespace OpenRA.Test var actorInfo = new ActorInfo("test", unorderedTraits); var orderedTraits = actorInfo.TraitsInConstructOrder().ToArray(); - CollectionAssert.AreEquivalent(unorderedTraits, orderedTraits); + Assert.That(unorderedTraits, Is.EquivalentTo(orderedTraits)); } [TestCase(TestName = "Trait ordering exception reports cyclic dependencies")] @@ -104,9 +104,9 @@ namespace OpenRA.Test var actorInfo = new ActorInfo("test", new MockDInfo(), new MockEInfo(), new MockFInfo()); var ex = Assert.Throws(() => actorInfo.TraitsInConstructOrder()); - StringAssert.Contains(nameof(MockDInfo), ex.Message, "Exception message should report all cyclic dependencies."); - StringAssert.Contains(nameof(MockEInfo), ex.Message, "Exception message should report all cyclic dependencies."); - StringAssert.Contains(nameof(MockFInfo), ex.Message, "Exception message should report all cyclic dependencies."); + Assert.That(ex.Message, Does.Contain(nameof(MockDInfo)), "Exception message should report all cyclic dependencies."); + Assert.That(ex.Message, Does.Contain(nameof(MockEInfo)), "Exception message should report all cyclic dependencies."); + Assert.That(ex.Message, Does.Contain(nameof(MockFInfo)), "Exception message should report all cyclic dependencies."); } [TestCase(TestName = "Trait ordering exception reports cyclic optional dependencies")] @@ -115,9 +115,9 @@ namespace OpenRA.Test var actorInfo = new ActorInfo("test", new MockJInfo(), new MockKInfo(), new MockLInfo()); var ex = Assert.Throws(() => actorInfo.TraitsInConstructOrder()); - StringAssert.Contains(nameof(MockJInfo), ex.Message, "Exception message should report all cyclic dependencies."); - StringAssert.Contains(nameof(MockKInfo), ex.Message, "Exception message should report all cyclic dependencies."); - StringAssert.Contains(nameof(MockLInfo), ex.Message, "Exception message should report all cyclic dependencies."); + Assert.That(ex.Message, Does.Contain(nameof(MockJInfo)), "Exception message should report all cyclic dependencies."); + Assert.That(ex.Message, Does.Contain(nameof(MockKInfo)), "Exception message should report all cyclic dependencies."); + Assert.That(ex.Message, Does.Contain(nameof(MockLInfo)), "Exception message should report all cyclic dependencies."); } } } diff --git a/OpenRA.Test/OpenRA.Game/CPosTest.cs b/OpenRA.Test/OpenRA.Game/CPosTest.cs index 5cbc9e3c41..d214b17d68 100644 --- a/OpenRA.Test/OpenRA.Game/CPosTest.cs +++ b/OpenRA.Test/OpenRA.Game/CPosTest.cs @@ -30,9 +30,9 @@ namespace OpenRA.Test { var cell = new CPos(x, y, layer); - Assert.AreEqual(x, cell.X); - Assert.AreEqual(y, cell.Y); - Assert.AreEqual(layer, cell.Layer); + Assert.That(x, Is.EqualTo(cell.X)); + Assert.That(y, Is.EqualTo(cell.Y)); + Assert.That(layer, Is.EqualTo(cell.Layer)); } } } diff --git a/OpenRA.Test/OpenRA.Game/MediatorTest.cs b/OpenRA.Test/OpenRA.Game/MediatorTest.cs index cc3488ec50..1e129c02b0 100644 --- a/OpenRA.Test/OpenRA.Game/MediatorTest.cs +++ b/OpenRA.Test/OpenRA.Game/MediatorTest.cs @@ -26,7 +26,7 @@ namespace OpenRA.Test mediator.Send(new TestNotificaton()); - Assert.IsTrue(testHandler.WasNotified); + Assert.That(testHandler.WasNotified, Is.True); } } diff --git a/OpenRA.Test/OpenRA.Game/MiniYamlTest.cs b/OpenRA.Test/OpenRA.Game/MiniYamlTest.cs index 91db10a101..12e8f168b7 100644 --- a/OpenRA.Test/OpenRA.Game/MiniYamlTest.cs +++ b/OpenRA.Test/OpenRA.Game/MiniYamlTest.cs @@ -173,7 +173,7 @@ Parent: var baseYaml = MiniYaml.FromString(BaseString, ""); var resultYaml = MiniYaml.Merge(new[] { baseYaml }); - Assert.AreEqual(ResultString, resultYaml.WriteToString()); + Assert.That(ResultString, Is.EqualTo(resultYaml.WriteToString())); } [TestCase(TestName = "Merged yaml files should be able to remove nodes")] @@ -196,7 +196,7 @@ Parent: var mergeYaml = MiniYaml.FromString(MergeString, ""); var resultYaml = MiniYaml.Merge(new[] { baseYaml, mergeYaml }); - Assert.AreEqual(ResultString, resultYaml.WriteToString()); + Assert.That(ResultString, Is.EqualTo(resultYaml.WriteToString())); } [TestCase(TestName = "Merged yaml files should be able to remove nodes from inherited parents")] @@ -221,7 +221,7 @@ Parent: var mergeYaml = MiniYaml.FromString(MergeString, ""); var resultYaml = MiniYaml.Merge(new[] { baseYaml, mergeYaml }); - Assert.AreEqual(ResultString, resultYaml.WriteToString()); + Assert.That(ResultString, Is.EqualTo(resultYaml.WriteToString())); } [TestCase(TestName = "Inheritance and removal can be composed")] @@ -248,9 +248,9 @@ Test: var result = MiniYaml.Merge(new[] { BaseYaml, ExtendedYaml, MapYaml }.Select(s => MiniYaml.FromString(s, ""))) .First(n => n.Key == "Test").Value.Nodes; - Assert.IsFalse(result.Any(n => n.Key == "MockA2"), "Node should not have the MockA2 child, but does."); - Assert.IsTrue(result.Any(n => n.Key == "MockB2"), "Node should have the MockB2 child, but does not."); - Assert.IsTrue(result.Any(n => n.Key == "MockC2"), "Node should have the MockC2 child, but does not."); + Assert.That(result.Any(n => n.Key == "MockA2"), Is.False, "Node should not have the MockA2 child, but does."); + Assert.That(result.Any(n => n.Key == "MockB2"), Is.True, "Node should have the MockB2 child, but does not."); + Assert.That(result.Any(n => n.Key == "MockC2"), Is.True, "Node should have the MockC2 child, but does not."); } [TestCase(TestName = "Child can be removed after multiple inheritance")] @@ -271,7 +271,7 @@ Test: var result = MiniYaml.Merge(new[] { BaseYaml, OverrideYaml }.Select(s => MiniYaml.FromString(s, ""))) .First(n => n.Key == "Test").Value.Nodes; - Assert.IsFalse(result.Any(n => n.Key == "MockA2"), "Node should not have the MockA2 child, but does."); + Assert.That(result.Any(n => n.Key == "MockA2"), Is.False, "Node should not have the MockA2 child, but does."); } [TestCase(TestName = "Child can be immediately removed")] @@ -291,7 +291,7 @@ Test: var result = MiniYaml.Merge(new[] { BaseYaml }.Select(s => MiniYaml.FromString(s, ""))) .First(n => n.Key == "Test").Value.Nodes; - Assert.IsFalse(result.Any(n => n.Key == "MockString"), "Node should not have the MockString child, but does."); + Assert.That(result.Any(n => n.Key == "MockString"), Is.False, "Node should not have the MockString child, but does."); } [TestCase(TestName = "Child can be removed and immediately overridden")] @@ -311,8 +311,8 @@ Test: var result = MiniYaml.Merge(new[] { BaseYaml }.Select(s => MiniYaml.FromString(s, ""))) .First(n => n.Key == "Test").Value.Nodes; - Assert.IsTrue(result.Any(n => n.Key == "MockString"), "Node should have the MockString child, but does not."); - Assert.IsTrue(result.First(n => n.Key == "MockString").Value.NodeWithKey("AString").Value.Value == "Override", + Assert.That(result.Any(n => n.Key == "MockString"), Is.True, "Node should have the MockString child, but does not."); + Assert.That(result.First(n => n.Key == "MockString").Value.NodeWithKey("AString").Value.Value == "Override", Is.True, "MockString value has not been set with the correct override value for AString."); } @@ -336,8 +336,8 @@ Test: var result = MiniYaml.Merge(new[] { BaseYaml, OverrideYaml }.Select(s => MiniYaml.FromString(s, ""))) .First(n => n.Key == "Test").Value.Nodes; - Assert.IsTrue(result.Any(n => n.Key == "MockString"), "Node should have the MockString child, but does not."); - Assert.IsTrue(result.First(n => n.Key == "MockString").Value.NodeWithKey("AString").Value.Value == "Override", + Assert.That(result.Any(n => n.Key == "MockString"), Is.True, "Node should have the MockString child, but does not."); + Assert.That(result.First(n => n.Key == "MockString").Value.NodeWithKey("AString").Value.Value == "Override", Is.True, "MockString value has not been set with the correct override value for AString."); } @@ -362,8 +362,8 @@ Test: var result = MiniYaml.Merge(new[] { BaseYaml, OverrideYaml }.Select(s => MiniYaml.FromString(s, ""))) .First(n => n.Key == "Test").Value.Nodes; - Assert.IsTrue(result.Any(n => n.Key == "MockString"), "Node should have the MockString child, but does not."); - Assert.IsFalse(result.First(n => n.Key == "MockString").Value.Nodes.Any(n => n.Key == "AString"), + Assert.That(result.Any(n => n.Key == "MockString"), Is.True, "Node should have the MockString child, but does not."); + Assert.That(result.First(n => n.Key == "MockString").Value.Nodes.Any(n => n.Key == "AString"), Is.False, "MockString value should have been removed, but was not."); } @@ -391,8 +391,8 @@ Test: var fieldNodes = traitNode.Value.Nodes; var fieldSubNodes = fieldNodes.Single().Value.Nodes; - Assert.IsTrue(fieldSubNodes.Length == 1, "Collection of strings should only contain the overriding subnode."); - Assert.IsTrue(fieldSubNodes.Single(n => n.Key == "StringC").Value.Value == "C", + Assert.That(fieldSubNodes.Length == 1, Is.True, "Collection of strings should only contain the overriding subnode."); + Assert.That(fieldSubNodes.Single(n => n.Key == "StringC").Value.Value == "C", Is.True, "CollectionOfStrings value has not been set with the correct override value for StringC."); } @@ -425,8 +425,8 @@ Test: var fieldNodes = traitNode.Value.Nodes; var fieldSubNodes = fieldNodes.Single().Value.Nodes; - Assert.IsTrue(fieldSubNodes.Length == 1, "Collection of strings should only contain the overriding subnode."); - Assert.IsTrue(fieldSubNodes.Single(n => n.Key == "StringC").Value.Value == "C", + Assert.That(fieldSubNodes.Length == 1, Is.True, "Collection of strings should only contain the overriding subnode."); + Assert.That(fieldSubNodes.Single(n => n.Key == "StringC").Value.Value == "C", Is.True, "CollectionOfStrings value has not been set with the correct override value for StringC."); } @@ -454,7 +454,7 @@ Parent: var mergeYaml = MiniYaml.FromString(ExtendedYaml, ""); var resultYaml = MiniYaml.Merge(new[] { baseYaml, mergeYaml }); - Assert.AreEqual(ResultString, resultYaml.WriteToString()); + Assert.That(ResultString, Is.EqualTo(resultYaml.WriteToString())); } [TestCase(TestName = "Empty lines should count toward line numbers")] @@ -469,7 +469,7 @@ TestB: "; var result = MiniYaml.FromString(Yaml, "").First(n => n.Key == "TestB"); - Assert.AreEqual(5, result.Location.Line); + Assert.That(5, Is.EqualTo(result.Location.Line)); } [TestCase(TestName = "Duplicated nodes are correctly merged")] @@ -642,29 +642,29 @@ Test: public void TestEscapedHashInValues() { var trailingWhitespace = MiniYaml.FromString("key: value # comment", "", discardCommentsAndWhitespace: false)[0]; - Assert.AreEqual("value", trailingWhitespace.Value.Value); - Assert.AreEqual(" comment", trailingWhitespace.Comment); + Assert.That("value", Is.EqualTo(trailingWhitespace.Value.Value)); + Assert.That(" comment", Is.EqualTo(trailingWhitespace.Comment)); var noWhitespace = MiniYaml.FromString("key:value# comment", "", discardCommentsAndWhitespace: false)[0]; - Assert.AreEqual("value", noWhitespace.Value.Value); - Assert.AreEqual(" comment", noWhitespace.Comment); + Assert.That("value", Is.EqualTo(noWhitespace.Value.Value)); + Assert.That(" comment", Is.EqualTo(noWhitespace.Comment)); var escapedHashInValue = MiniYaml.FromString(@"key: before \# after # comment", "", discardCommentsAndWhitespace: false)[0]; - Assert.AreEqual("before # after", escapedHashInValue.Value.Value); - Assert.AreEqual(" comment", escapedHashInValue.Comment); + Assert.That("before # after", Is.EqualTo(escapedHashInValue.Value.Value)); + Assert.That(" comment", Is.EqualTo(escapedHashInValue.Comment)); var emptyValueAndComment = MiniYaml.FromString("key:#", "", discardCommentsAndWhitespace: false)[0]; - Assert.AreEqual(null, emptyValueAndComment.Value.Value); - Assert.AreEqual("", emptyValueAndComment.Comment); + Assert.That(null, Is.EqualTo(emptyValueAndComment.Value.Value)); + Assert.That("", Is.EqualTo(emptyValueAndComment.Comment)); var noValue = MiniYaml.FromString("key:", "", discardCommentsAndWhitespace: false)[0]; - Assert.AreEqual(null, noValue.Value.Value); - Assert.AreEqual(null, noValue.Comment); + Assert.That(null, Is.EqualTo(noValue.Value.Value)); + Assert.That(null, Is.EqualTo(noValue.Comment)); var emptyKey = MiniYaml.FromString(" : value", "", discardCommentsAndWhitespace: false)[0]; - Assert.AreEqual(null, emptyKey.Key); - Assert.AreEqual("value", emptyKey.Value.Value); - Assert.AreEqual(null, emptyKey.Comment); + Assert.That(null, Is.EqualTo(emptyKey.Key)); + Assert.That("value", Is.EqualTo(emptyKey.Value.Value)); + Assert.That(null, Is.EqualTo(emptyKey.Comment)); } [TestCase(TestName = "Leading and trailing whitespace can be guarded using a backslash")] @@ -672,7 +672,7 @@ Test: { const string TestYaml = @"key: \ test value \ "; var nodes = MiniYaml.FromString(TestYaml, ""); - Assert.AreEqual(" test value ", nodes[0].Value.Value); + Assert.That(" test value ", Is.EqualTo(nodes[0].Value.Value)); } [TestCase(TestName = "Comments should count toward line numbers")] @@ -739,7 +739,7 @@ Parent: # comment without value ".Replace("\r\n", "\n"); var result = MiniYaml.FromString(yaml, "", discardCommentsAndWhitespace: false).WriteToString(); - Assert.AreEqual(canonicalYaml, result); + Assert.That(canonicalYaml, Is.EqualTo(result)); } [TestCase(TestName = "Comments should be removed when discardCommentsAndWhitespace is false")] @@ -775,7 +775,7 @@ Parent: # comment without value ".Replace("\r\n", "\n"); var result = MiniYaml.FromString(Yaml, "").WriteToString(); - Assert.AreEqual(strippedYaml, result); + Assert.That(strippedYaml, Is.EqualTo(result)); } } } diff --git a/OpenRA.Test/OpenRA.Game/PngTest.cs b/OpenRA.Test/OpenRA.Game/PngTest.cs index 373d6d51f5..a453a81def 100644 --- a/OpenRA.Test/OpenRA.Game/PngTest.cs +++ b/OpenRA.Test/OpenRA.Game/PngTest.cs @@ -32,7 +32,7 @@ namespace OpenRA.Test var result = png.Save(); // Assert - Assert.IsTrue(Png.Verify(new MemoryStream(result))); + Assert.That(Png.Verify(new MemoryStream(result)), Is.True); } [Test] @@ -90,7 +90,7 @@ namespace OpenRA.Test // Act & Assert var exception = Assert.Throws(() => new Png(new MemoryStream(invalidSignature))); - StringAssert.Contains("PNG Signature is bogus", exception.Message); + Assert.That("PNG Signature is bogus", Does.Contain(exception.Message)); } [Test] @@ -106,7 +106,7 @@ namespace OpenRA.Test // Act & Assert var exception = Assert.Throws(() => new Png(new MemoryStream(invalidPngData))); - StringAssert.Contains("Invalid PNG file - header does not appear first.", exception.Message); + Assert.That("Invalid PNG file - header does not appear first.", Does.Contain(exception.Message)); } [Test] @@ -143,7 +143,7 @@ namespace OpenRA.Test { // Act & Assert var exception = Assert.Throws(() => new Png(stream)); - Assert.AreEqual("Compression method not supported", exception.Message); + Assert.That("Compression method not supported", Is.EqualTo(exception.Message)); } } diff --git a/OpenRA.Test/OpenRA.Game/PriorityQueueTest.cs b/OpenRA.Test/OpenRA.Game/PriorityQueueTest.cs index 690d86cb13..aa700b6afe 100644 --- a/OpenRA.Test/OpenRA.Game/PriorityQueueTest.cs +++ b/OpenRA.Test/OpenRA.Game/PriorityQueueTest.cs @@ -58,24 +58,24 @@ namespace OpenRA.Test var queue = new Primitives.PriorityQueue(default); - Assert.IsTrue(queue.Empty, "New queue should start out empty."); + Assert.That(queue.Empty, Is.True, "New queue should start out empty."); Assert.Throws(() => queue.Peek(), "Peeking at an empty queue should throw."); Assert.Throws(() => queue.Pop(), "Popping an empty queue should throw."); foreach (var value in shuffledValues) { queue.Add(value); - Assert.IsFalse(queue.Empty, "Queue should not be empty - items have been added."); + Assert.That(queue.Empty, Is.False, "Queue should not be empty - items have been added."); } foreach (var value in values) { - Assert.AreEqual(value, queue.Peek(), "Peek returned the wrong item - should be in order."); - Assert.IsFalse(queue.Empty, "Queue should not be empty yet."); - Assert.AreEqual(value, queue.Pop(), "Pop returned the wrong item - should be in order."); + Assert.That(value, Is.EqualTo(queue.Peek()), "Peek returned the wrong item - should be in order."); + Assert.That(queue.Empty, Is.False, "Queue should not be empty yet."); + Assert.That(value, Is.EqualTo(queue.Pop()), "Pop returned the wrong item - should be in order."); } - Assert.IsTrue(queue.Empty, "Queue should now be empty."); + Assert.That(queue.Empty, Is.True, "Queue should now be empty."); Assert.Throws(() => queue.Peek(), "Peeking at an empty queue should throw."); Assert.Throws(() => queue.Pop(), "Popping an empty queue should throw."); } @@ -102,53 +102,53 @@ namespace OpenRA.Test var queue = new Primitives.PriorityQueue(default); - Assert.IsTrue(queue.Empty, "New queue should start out empty."); + Assert.That(queue.Empty, Is.True, "New queue should start out empty."); Assert.Throws(() => queue.Peek(), "Peeking at an empty queue should throw."); Assert.Throws(() => queue.Pop(), "Popping an empty queue should throw."); foreach (var value in shuffledValues.Take(10)) { queue.Add(value); - Assert.IsFalse(queue.Empty, "Queue should not be empty - items have been added."); + Assert.That(queue.Empty, Is.False, "Queue should not be empty - items have been added."); } foreach (var value in shuffledValues.Take(10).OrderBy(x => x).Take(5)) { - Assert.AreEqual(value, queue.Peek(), "Peek returned the wrong item - should be in order."); - Assert.IsFalse(queue.Empty, "Queue should not be empty yet."); - Assert.AreEqual(value, queue.Pop(), "Pop returned the wrong item - should be in order."); + Assert.That(value, Is.EqualTo(queue.Peek()), "Peek returned the wrong item - should be in order."); + Assert.That(queue.Empty, Is.False, "Queue should not be empty yet."); + Assert.That(value, Is.EqualTo(queue.Pop()), "Pop returned the wrong item - should be in order."); } foreach (var value in shuffledValues.Skip(10).Take(5)) { queue.Add(value); - Assert.IsFalse(queue.Empty, "Queue should not be empty - items have been added."); + Assert.That(queue.Empty, Is.False, "Queue should not be empty - items have been added."); } foreach (var value in shuffledValues.Take(10).OrderBy(x => x).Skip(5) .Concat(shuffledValues.Skip(10).Take(5)).OrderBy(x => x).Take(5)) { - Assert.AreEqual(value, queue.Peek(), "Peek returned the wrong item - should be in order."); - Assert.IsFalse(queue.Empty, "Queue should not be empty yet."); - Assert.AreEqual(value, queue.Pop(), "Pop returned the wrong item - should be in order."); + Assert.That(value, Is.EqualTo(queue.Peek()), "Peek returned the wrong item - should be in order."); + Assert.That(queue.Empty, Is.False, "Queue should not be empty yet."); + Assert.That(value, Is.EqualTo(queue.Pop()), "Pop returned the wrong item - should be in order."); } foreach (var value in shuffledValues.Skip(15)) { queue.Add(value); - Assert.IsFalse(queue.Empty, "Queue should not be empty - items have been added."); + Assert.That(queue.Empty, Is.False, "Queue should not be empty - items have been added."); } foreach (var value in shuffledValues.Take(10).OrderBy(x => x).Skip(5) .Concat(shuffledValues.Skip(10).Take(5)).OrderBy(x => x).Skip(5) .Concat(shuffledValues.Skip(15)).OrderBy(x => x)) { - Assert.AreEqual(value, queue.Peek(), "Peek returned the wrong item - should be in order."); - Assert.IsFalse(queue.Empty, "Queue should not be empty yet."); - Assert.AreEqual(value, queue.Pop(), "Pop returned the wrong item - should be in order."); + Assert.That(value, Is.EqualTo(queue.Peek()), "Peek returned the wrong item - should be in order."); + Assert.That(queue.Empty, Is.False, "Queue should not be empty yet."); + Assert.That(value, Is.EqualTo(queue.Pop()), "Pop returned the wrong item - should be in order."); } - Assert.IsTrue(queue.Empty, "Queue should now be empty."); + Assert.That(queue.Empty, Is.True, "Queue should now be empty."); Assert.Throws(() => queue.Peek(), "Peeking at an empty queue should throw."); Assert.Throws(() => queue.Pop(), "Popping an empty queue should throw."); } diff --git a/OpenRA.Test/OpenRA.Game/Sha1Tests.cs b/OpenRA.Test/OpenRA.Game/Sha1Tests.cs index bdb811336a..fcaba10449 100644 --- a/OpenRA.Test/OpenRA.Game/Sha1Tests.cs +++ b/OpenRA.Test/OpenRA.Game/Sha1Tests.cs @@ -18,7 +18,7 @@ namespace OpenRA.Test { var actual = CryptoUtil.SHA1Hash(input); - Assert.AreEqual(expected, actual); + Assert.That(expected, Is.EqualTo(actual)); } [TestCase(0xFF0000FF, "0000FF")] @@ -29,7 +29,7 @@ namespace OpenRA.Test { var color = Color.FromArgb(value); var actual = color.ToString(); - Assert.AreEqual(expected, actual); + Assert.That(expected, Is.EqualTo(actual)); } } } diff --git a/OpenRA.Test/OpenRA.Game/SpatiallyPartitionedTest.cs b/OpenRA.Test/OpenRA.Game/SpatiallyPartitionedTest.cs index 4542f3e8cf..ae3d30f34f 100644 --- a/OpenRA.Test/OpenRA.Game/SpatiallyPartitionedTest.cs +++ b/OpenRA.Test/OpenRA.Game/SpatiallyPartitionedTest.cs @@ -24,28 +24,28 @@ namespace OpenRA.Test var a = new object(); partition.Add(a, new Rectangle(0, 0, 1, 1)); - CollectionAssert.Contains(partition.At(new int2(0, 0)), a, "a is not present after add"); - CollectionAssert.DoesNotContain(partition.At(new int2(0, 1)), a, "a is present in the wrong location"); - CollectionAssert.DoesNotContain(partition.At(new int2(1, 0)), a, "a is present in the wrong location"); + Assert.That(partition.At(new int2(0, 0)), Does.Contain(a), "a is not present after add"); + Assert.That(partition.At(new int2(0, 1)), Does.Not.Contain(a), "a is present in the wrong location"); + Assert.That(partition.At(new int2(1, 0)), Does.Not.Contain(a), "a is present in the wrong location"); var b = new object(); partition.Add(b, new Rectangle(1, 1, 2, 2)); - CollectionAssert.DoesNotContain(partition.At(new int2(0, 1)), b, "b is present in the wrong location"); - CollectionAssert.DoesNotContain(partition.At(new int2(1, 0)), b, "b is present in the wrong location"); - CollectionAssert.Contains(partition.At(new int2(1, 1)), b, "b is not present after add"); - CollectionAssert.Contains(partition.At(new int2(2, 2)), b, "b is not present after add"); - CollectionAssert.DoesNotContain(partition.At(new int2(2, 3)), b, "b is present in the wrong location"); - CollectionAssert.DoesNotContain(partition.At(new int2(3, 2)), b, "b is present in the wrong location"); - CollectionAssert.DoesNotContain(partition.At(new int2(3, 3)), b, "b is present in the wrong location"); + Assert.That(partition.At(new int2(0, 1)), Does.Not.Contain(b), "b is present in the wrong location"); + Assert.That(partition.At(new int2(1, 0)), Does.Not.Contain(b), "b is present in the wrong location"); + Assert.That(partition.At(new int2(1, 1)), Does.Contain(b), "b is not present after add"); + Assert.That(partition.At(new int2(2, 2)), Does.Contain(b), "b is not present after add"); + Assert.That(partition.At(new int2(2, 3)), Does.Not.Contain(b), "b is present in the wrong location"); + Assert.That(partition.At(new int2(3, 2)), Does.Not.Contain(b), "b is present in the wrong location"); + Assert.That(partition.At(new int2(3, 3)), Does.Not.Contain(b), "b is present in the wrong location"); partition.Update(b, new Rectangle(4, 4, 1, 1)); - CollectionAssert.Contains(partition.At(new int2(0, 0)), a, "a wrongly changed location when b was updated"); - CollectionAssert.Contains(partition.At(new int2(4, 4)), b, "b is not present at the new location in the extreme corner of the partition"); - CollectionAssert.DoesNotContain(partition.At(new int2(1, 1)), b, "b is still present at the old location after update"); + Assert.That(partition.At(new int2(0, 0)), Does.Contain(a), "a wrongly changed location when b was updated"); + Assert.That(partition.At(new int2(4, 4)), Does.Contain(b), "b is not present at the new location in the extreme corner of the partition"); + Assert.That(partition.At(new int2(1, 1)), Does.Not.Contain(b), "b is still present at the old location after update"); partition.Remove(a); - CollectionAssert.DoesNotContain(partition.At(new int2(0, 0)), a, "a is still present after removal"); - CollectionAssert.Contains(partition.At(new int2(4, 4)), b, "b wrongly changed location when a was removed"); + Assert.That(partition.At(new int2(0, 0)), Does.Not.Contain(b), "a is still present after removal"); + Assert.That(partition.At(new int2(4, 4)), Does.Contain(b), "b wrongly changed location when a was removed"); } [TestCase(TestName = "SpatiallyPartitioned.InBox works")] @@ -55,38 +55,38 @@ namespace OpenRA.Test var a = new object(); partition.Add(a, new Rectangle(0, 0, 1, 1)); - CollectionAssert.DoesNotContain(partition.InBox(new Rectangle(0, 0, 0, 0)), a, "Searching an empty area should not return a"); - CollectionAssert.Contains(partition.InBox(new Rectangle(0, 0, 1, 1)), a, "a is not present after add"); - CollectionAssert.DoesNotContain(partition.InBox(new Rectangle(0, 1, 1, 1)), a, "a is present in the wrong location"); - CollectionAssert.DoesNotContain(partition.InBox(new Rectangle(1, 0, 1, 1)), a, "a is present in the wrong location"); + Assert.That(partition.InBox(new Rectangle(0, 0, 0, 0)), Does.Not.Contain(a), "Searching an empty area should not return a"); + Assert.That(partition.InBox(new Rectangle(0, 0, 1, 1)), Does.Contain(a), "a is not present after add"); + Assert.That(partition.InBox(new Rectangle(0, 1, 1, 1)), Does.Not.Contain(a), "a is present in the wrong location"); + Assert.That(partition.InBox(new Rectangle(1, 0, 1, 1)), Does.Not.Contain(a), "a is present in the wrong location"); var b = new object(); partition.Add(b, new Rectangle(1, 1, 2, 2)); - CollectionAssert.DoesNotContain(partition.InBox(new Rectangle(0, 1, 1, 1)), b, "b is present in the wrong location"); - CollectionAssert.DoesNotContain(partition.InBox(new Rectangle(1, 0, 1, 1)), b, "b is present in the wrong location"); - CollectionAssert.Contains(partition.InBox(new Rectangle(1, 1, 1, 1)), b, "b is not present after add"); - CollectionAssert.Contains(partition.InBox(new Rectangle(2, 2, 1, 1)), b, "b is not present after add"); - CollectionAssert.DoesNotContain(partition.InBox(new Rectangle(2, 3, 1, 1)), b, "b is present in the wrong location"); - CollectionAssert.DoesNotContain(partition.InBox(new Rectangle(3, 2, 1, 1)), b, "b is present in the wrong location"); - CollectionAssert.DoesNotContain(partition.InBox(new Rectangle(3, 3, 1, 1)), b, "b is present in the wrong location"); + Assert.That(partition.InBox(new Rectangle(0, 1, 1, 1)), Does.Not.Contain(b), "b is present in the wrong location"); + Assert.That(partition.InBox(new Rectangle(1, 0, 1, 1)), Does.Not.Contain(b), "b is present in the wrong location"); + Assert.That(partition.InBox(new Rectangle(1, 1, 1, 1)), Does.Contain(b), "b is not present after add"); + Assert.That(partition.InBox(new Rectangle(2, 2, 1, 1)), Does.Contain(b), "b is not present after add"); + Assert.That(partition.InBox(new Rectangle(2, 3, 1, 1)), Does.Not.Contain(b), "b is present in the wrong location"); + Assert.That(partition.InBox(new Rectangle(3, 2, 1, 1)), Does.Not.Contain(b), "b is present in the wrong location"); + Assert.That(partition.InBox(new Rectangle(3, 3, 1, 1)), Does.Not.Contain(b), "b is present in the wrong location"); - CollectionAssert.AreEquivalent(new[] { b }, partition.InBox(new Rectangle(1, 1, 1, 1)), + Assert.That(new[] { b }, Is.EquivalentTo(partition.InBox(new Rectangle(1, 1, 1, 1))), "Searching within a single partition bin did not return the correct result"); - CollectionAssert.AllItemsAreUnique(partition.InBox(new Rectangle(0, 0, 5, 5)), + Assert.That(partition.InBox(new Rectangle(0, 0, 5, 5)), Is.Unique, "Searching the whole partition returned duplicates of some items"); - CollectionAssert.AreEquivalent(new[] { a, b }, partition.InBox(new Rectangle(0, 0, 5, 5)), + Assert.That(new[] { a, b }, Is.EquivalentTo(partition.InBox(new Rectangle(0, 0, 5, 5))), "Searching the whole partition did not return all items"); - CollectionAssert.AreEquivalent(new[] { a, b }, partition.InBox(new Rectangle(-10, -10, 25, 25)), + Assert.That(new[] { a, b }, Is.EquivalentTo(partition.InBox(new Rectangle(-10, -10, 25, 25))), "Searching an area larger than the partition did not return all items"); partition.Update(b, new Rectangle(4, 4, 1, 1)); - CollectionAssert.Contains(partition.InBox(new Rectangle(0, 0, 1, 1)), a, "a wrongly changed location when b was updated"); - CollectionAssert.Contains(partition.InBox(new Rectangle(4, 4, 1, 1)), b, "b is not present at the new location in the extreme corner of the partition"); - CollectionAssert.DoesNotContain(partition.InBox(new Rectangle(1, 1, 1, 1)), b, "b is still present at the old location after update"); + Assert.That(partition.InBox(new Rectangle(0, 0, 1, 1)), Does.Contain(a), "a wrongly changed location when b was updated"); + Assert.That(partition.InBox(new Rectangle(4, 4, 1, 1)), Does.Contain(b), "b is not present at the new location in the extreme corner of the partition"); + Assert.That(partition.InBox(new Rectangle(1, 1, 1, 1)), Does.Not.Contain(b), "b is still present at the old location after update"); partition.Remove(a); - CollectionAssert.DoesNotContain(partition.InBox(new Rectangle(0, 0, 1, 1)), a, "a is still present after removal"); - CollectionAssert.Contains(partition.InBox(new Rectangle(4, 4, 1, 1)), b, "b wrongly changed location when a was removed"); + Assert.That(partition.InBox(new Rectangle(0, 0, 1, 1)), Does.Not.Contain(a), "a is still present after removal"); + Assert.That(partition.InBox(new Rectangle(4, 4, 1, 1)), Does.Contain(b), "b wrongly changed location when a was removed"); } } } diff --git a/OpenRA.Test/OpenRA.Game/VariableExpressionTest.cs b/OpenRA.Test/OpenRA.Game/VariableExpressionTest.cs index 06f778e998..54f2ff1fcf 100644 --- a/OpenRA.Test/OpenRA.Game/VariableExpressionTest.cs +++ b/OpenRA.Test/OpenRA.Game/VariableExpressionTest.cs @@ -29,17 +29,17 @@ namespace OpenRA.Test void AssertFalse(string expression) { - Assert.False(new BooleanExpression(expression).Evaluate(testValues), expression); + Assert.That(new BooleanExpression(expression).Evaluate(testValues), Is.False, expression); } void AssertTrue(string expression) { - Assert.True(new BooleanExpression(expression).Evaluate(testValues), expression); + Assert.That(new BooleanExpression(expression).Evaluate(testValues), Is.True, expression); } void AssertValue(string expression, int value) { - Assert.AreEqual(value, new IntegerExpression(expression).Evaluate(testValues), expression); + Assert.That(value, Is.EqualTo(new IntegerExpression(expression).Evaluate(testValues)), expression); } void AssertParseFailure(string expression, string errorMessage) @@ -47,7 +47,7 @@ namespace OpenRA.Test var actualErrorMessage = Assert.Throws(typeof(InvalidDataException), () => new IntegerExpression(expression).Evaluate(testValues), expression).Message; - Assert.AreEqual(errorMessage, actualErrorMessage, expression + " ===> " + actualErrorMessage); + Assert.That(errorMessage, Is.EqualTo(actualErrorMessage), expression + " ===> " + actualErrorMessage); } [TestCase(TestName = "Numbers")] diff --git a/OpenRA.Test/OpenRA.Test.csproj b/OpenRA.Test/OpenRA.Test.csproj index fe0d04aec4..f1a92a5578 100644 --- a/OpenRA.Test/OpenRA.Test.csproj +++ b/OpenRA.Test/OpenRA.Test.csproj @@ -8,9 +8,9 @@ True - - - - + + + +