From a433244799efaf9e08f430a3d86da60c3d6052c4 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Wed, 13 Nov 2024 18:41:45 +0000 Subject: [PATCH] fix(test): use new NUnit constraint API --- X10D.Tests/src/Collections/EnumerableTests.cs | 16 ++-- X10D.Tests/src/Collections/ListTests.cs | 64 ++++++------- X10D.Tests/src/Collections/SpanTest.cs | 16 ++-- X10D.Tests/src/Core/CoreTests.cs | 2 +- X10D.Tests/src/Core/SpanTest.cs | 1 - X10D.Tests/src/Drawing/PolygonFTests.cs | 6 +- X10D.Tests/src/Drawing/PolyhedronTests.cs | 10 +- .../src/Hosting/ServiceCollectionTests.cs | 16 ++-- X10D.Tests/src/IO/BooleanTests.cs | 4 +- X10D.Tests/src/IO/ByteTests.cs | 11 ++- X10D.Tests/src/IO/DecimalTests.cs | 24 +++-- X10D.Tests/src/IO/DoubleTests.cs | 22 +++-- X10D.Tests/src/IO/FileInfoTests.cs | 14 ++- X10D.Tests/src/IO/Int16Tests.cs | 22 +++-- X10D.Tests/src/IO/Int32Tests.cs | 22 +++-- X10D.Tests/src/IO/Int64Tests.cs | 22 +++-- X10D.Tests/src/IO/SByteTests.cs | 11 ++- X10D.Tests/src/IO/SingleTests.cs | 22 +++-- X10D.Tests/src/IO/StreamTests.WriteDecimal.cs | 38 ++++---- X10D.Tests/src/IO/StreamTests.WriteDouble.cs | 26 ++++-- X10D.Tests/src/IO/StreamTests.WriteInt16.cs | 26 ++++-- X10D.Tests/src/IO/StreamTests.WriteInt32.cs | 26 ++++-- X10D.Tests/src/IO/StreamTests.WriteInt64.cs | 26 ++++-- X10D.Tests/src/IO/StreamTests.WriteSingle.cs | 26 ++++-- X10D.Tests/src/IO/StreamTests.WriteUInt16.cs | 26 ++++-- X10D.Tests/src/IO/StreamTests.WriteUInt32.cs | 26 ++++-- X10D.Tests/src/IO/StreamTests.WriteUInt64.cs | 26 ++++-- X10D.Tests/src/IO/StreamTests.cs | 4 +- X10D.Tests/src/IO/UInt16Tests.cs | 24 +++-- X10D.Tests/src/IO/UInt32Tests.cs | 24 +++-- X10D.Tests/src/IO/UInt64Tests.cs | 24 +++-- X10D.Tests/src/Math/IsPrimeTests.cs | 2 +- X10D.Tests/src/Text/CoreTests.cs | 8 +- X10D.Tests/src/Text/EnumerableTests.cs | 32 ++++--- .../src/Text/StringBuilderReaderTests.cs | 91 ++++++++++++------- X10D.Tests/src/Text/StringTests.cs | 9 +- 36 files changed, 457 insertions(+), 312 deletions(-) diff --git a/X10D.Tests/src/Collections/EnumerableTests.cs b/X10D.Tests/src/Collections/EnumerableTests.cs index a08c05f..37e19f8 100644 --- a/X10D.Tests/src/Collections/EnumerableTests.cs +++ b/X10D.Tests/src/Collections/EnumerableTests.cs @@ -117,11 +117,11 @@ internal partial class EnumerableTests IEnumerable source = oneToTen.Select(i => new DummyClass {Value = i}).ToArray(); IEnumerable values = source.Select(o => o.Value); - CollectionAssert.AreEqual(oneToTen, values.ToArray()); + Assert.That(values.ToArray(), Is.EqualTo(oneToTen).AsCollection); source.For((i, o) => o.Value *= i); values = source.Select(o => o.Value); - CollectionAssert.AreEqual(multipliedByIndex, values.ToArray()); + Assert.That(values.ToArray(), Is.EqualTo(multipliedByIndex).AsCollection); } [Test] @@ -146,11 +146,11 @@ internal partial class EnumerableTests IEnumerable source = oneToTen.Select(i => new DummyClass {Value = i}).ToArray(); IEnumerable values = source.Select(o => o.Value); - CollectionAssert.AreEqual(oneToTen, values.ToArray()); + Assert.That(values.ToArray(), Is.EqualTo(oneToTen).AsCollection); source.ForEach(o => o.Value *= 2); values = source.Select(o => o.Value); - CollectionAssert.AreEqual(oneToTenDoubled, values.ToArray()); + Assert.That(values.ToArray(), Is.EqualTo(oneToTenDoubled).AsCollection); } [Test] @@ -245,10 +245,10 @@ internal partial class EnumerableTests int[] array = Enumerable.Range(1, 52).ToArray(); // 52! chance of being shuffled to the same order int[] shuffled = array[..]; - CollectionAssert.AreEqual(array, shuffled); + Assert.That(shuffled, Is.EqualTo(array).AsCollection); shuffled = array.Shuffled().ToArray(); - CollectionAssert.AreNotEqual(array, shuffled); + Assert.That(shuffled, Is.Not.EqualTo(array).AsCollection); } [Test] @@ -256,7 +256,7 @@ internal partial class EnumerableTests { var enumerable = new[] {2, 4, 6, 7, 8, 9, 10}; IEnumerable result = enumerable.WhereNot(x => x % 2 == 0); - CollectionAssert.AreEqual(new[] {7, 9}, result.ToArray()); + Assert.That(result.ToArray(), Is.EqualTo(new[] { 7, 9 }).AsCollection); } [Test] @@ -285,7 +285,7 @@ internal partial class EnumerableTests foreach (object o in array.WhereNotNull()) { - Assert.IsNotNull(o); + Assert.That(o, Is.Not.Null); actualCount++; } diff --git a/X10D.Tests/src/Collections/ListTests.cs b/X10D.Tests/src/Collections/ListTests.cs index a2f7f28..469d097 100644 --- a/X10D.Tests/src/Collections/ListTests.cs +++ b/X10D.Tests/src/Collections/ListTests.cs @@ -6,7 +6,7 @@ namespace X10D.Tests.Collections; [TestFixture] internal class ListTests { - [Test] + [Test] [TestCase(1)] [TestCase(1, 2, 3)] [TestCase(1, 2, 3, 4, 5)] @@ -15,17 +15,17 @@ internal class ListTests int[] all42 = Enumerable.Repeat(42, args.Length).ToArray(); var list = new List(args); - CollectionAssert.AreEqual(args, list); + Assert.That(list, Is.EqualTo(args).AsCollection); args.Fill(42); list.Fill(42); - CollectionAssert.AreEqual(args, list); - CollectionAssert.AreEqual(all42, args); - CollectionAssert.AreEqual(all42, list); + Assert.That(list, Is.EqualTo(args).AsCollection); + Assert.That(args, Is.EqualTo(all42).AsCollection); + Assert.That(list, Is.EqualTo(all42).AsCollection); } - [Test] + [Test] [TestCase(1)] [TestCase(1, 2, 3)] [TestCase(1, 2, 3, 4, 5)] @@ -36,7 +36,7 @@ internal class ListTests int[] comparison = Enumerable.Repeat(1, args.Length - 1).ToArray(); Assert.That(args[0], Is.EqualTo(first)); - CollectionAssert.AreEqual(comparison, args[1..]); + Assert.That(args[1..], Is.EqualTo(comparison).AsCollection); } [Test] @@ -80,7 +80,7 @@ internal class ListTests [Test] public void IndexOf_ShouldReturnCorrectValue_FromStartOfList() { - int[] array = {0, 1, 2, 3, 4}; + int[] array = { 0, 1, 2, 3, 4 }; Assert.Multiple(() => { Assert.That(array.IndexOf(2), Is.EqualTo(2)); @@ -92,7 +92,7 @@ internal class ListTests [Test] public void IndexOf_ShouldReturnCorrectValue_GivenSubRange() { - int[] array = {0, 1, 2, 3, 4, 0}; + int[] array = { 0, 1, 2, 3, 4, 0 }; Assert.Multiple(() => { Assert.That(array.IndexOf(0), Is.Zero); @@ -149,7 +149,7 @@ internal class ListTests [Test] public void IndexOf_ShouldThrowArgumentOutOfRangeException_GivenInvalidStartIndexCountPair() { - int[] array = {0, 1, 2}; + int[] array = { 0, 1, 2 }; Assert.Throws(() => array.IndexOf(0, 2, 4)); } @@ -184,7 +184,7 @@ internal class ListTests public void RemoveRange_ShouldThrowArgumentOutOfRangeException_GivenEndIndexGreaterThanOrEqualToCount() { Assert.Throws(() => new List().RemoveRange(..0)); - Assert.Throws(() => new List {1}.RemoveRange(..2)); + Assert.Throws(() => new List { 1 }.RemoveRange(..2)); } [Test] @@ -208,7 +208,7 @@ internal class ListTests list.RemoveRange(2..5); Assert.That(list, Has.Count.EqualTo(6)); - CollectionAssert.AreEqual(new[] {1, 2, 7, 8, 9, 10}, list); + Assert.That(list, Is.EqualTo(new[] { 1, 2, 7, 8, 9, 10 }).AsCollection); } [Test] @@ -217,11 +217,11 @@ internal class ListTests var list = new List(Enumerable.Range(1, 52)); // 52! chance of being shuffled to the same order var shuffled = new List(list); - CollectionAssert.AreEqual(list, shuffled); + Assert.That(shuffled, Is.EqualTo(list).AsCollection); shuffled.Shuffle(); - CollectionAssert.AreNotEqual(list, shuffled); + Assert.That(shuffled, Is.Not.EqualTo(list).AsCollection); } [Test] @@ -233,23 +233,23 @@ internal class ListTests [Test] public void Slice_ShouldReturnCorrectValue_GivenStartIndex() { - int[] array = {0, 1, 2, 3, 4, 5}; - CollectionAssert.AreEqual(new[] {2, 3, 4, 5}, array.Slice(2).ToArray()); + int[] array = { 0, 1, 2, 3, 4, 5 }; + Assert.That(array.Slice(2).ToArray(), Is.EqualTo(new[] { 2, 3, 4, 5 }).AsCollection); } [Test] public void Slice_ShouldReturnCorrectValue_GivenStartIndexAndLength() { - int[] array = {0, 1, 2, 3, 4, 5}; - CollectionAssert.AreEqual(new[] {2, 3, 4}, array.Slice(2, 3).ToArray()); + int[] array = { 0, 1, 2, 3, 4, 5 }; + Assert.That(array.Slice(2, 3).ToArray(), Is.EqualTo(new[] { 2, 3, 4 }).AsCollection); } [Test] public void Slice_ShouldReturnEmptyList_ForEmptyList() { int[] array = Array.Empty(); - CollectionAssert.AreEqual(Array.Empty(), array.Slice(0).ToArray()); - CollectionAssert.AreEqual(Array.Empty(), array.Slice(0, 0).ToArray()); + Assert.That(array.Slice(0).ToArray(), Is.EqualTo(Array.Empty()).AsCollection); + Assert.That(array.Slice(0, 0).ToArray(), Is.EqualTo(Array.Empty()).AsCollection); } [Test] @@ -278,7 +278,7 @@ internal class ListTests [Test] public void Slice_ShouldThrowArgumentOutOfRangeException_GivenInvalidStartIndexCountPair() { - int[] array = {0, 1, 2}; + int[] array = { 0, 1, 2 }; Assert.Throws(() => array.Slice(2, 4)); } @@ -297,18 +297,18 @@ internal class ListTests [Test] public void Swap_ShouldSwapElements_GivenMatchingElementCount() { - var first = new List {1, 2, 3}; - var second = new List {4, 5, 6}; + var first = new List { 1, 2, 3 }; + var second = new List { 4, 5, 6 }; first.Swap(second); - CollectionAssert.AreEqual(new[] {4, 5, 6}, first, string.Join(' ', first)); - CollectionAssert.AreEqual(new[] {1, 2, 3}, second, string.Join(' ', second)); + Assert.That(first, Is.EqualTo(new[] { 4, 5, 6 }).AsCollection, string.Join(' ', first)); + Assert.That(second, Is.EqualTo(new[] { 1, 2, 3 }).AsCollection, string.Join(' ', second)); first.Swap(second); - CollectionAssert.AreEqual(new[] {1, 2, 3}, first, string.Join(' ', first)); - CollectionAssert.AreEqual(new[] {4, 5, 6}, second, string.Join(' ', second)); + Assert.That(first, Is.EqualTo(new[] { 1, 2, 3 }).AsCollection, string.Join(' ', first)); + Assert.That(second, Is.EqualTo(new[] { 4, 5, 6 }).AsCollection, string.Join(' ', second)); } [Test] @@ -322,16 +322,16 @@ internal class ListTests 4, 5 }; - var second = new List {6, 7}; + var second = new List { 6, 7 }; first.Swap(second); - CollectionAssert.AreEqual(new[] {6, 7}, first, string.Join(' ', first)); - CollectionAssert.AreEqual(new[] {1, 2, 3, 4, 5}, second, string.Join(' ', second)); + Assert.That(first, Is.EqualTo(new[] { 6, 7 }).AsCollection, string.Join(' ', first)); + Assert.That(second, Is.EqualTo(new[] { 1, 2, 3, 4, 5 }).AsCollection, string.Join(' ', second)); first.Swap(second); - CollectionAssert.AreEqual(new[] {1, 2, 3, 4, 5}, first, string.Join(' ', first)); - CollectionAssert.AreEqual(new[] {6, 7}, second, string.Join(' ', second)); + Assert.That(first, Is.EqualTo(new[] { 1, 2, 3, 4, 5 }).AsCollection, string.Join(' ', first)); + Assert.That(second, Is.EqualTo(new[] { 6, 7 }).AsCollection, string.Join(' ', second)); } } diff --git a/X10D.Tests/src/Collections/SpanTest.cs b/X10D.Tests/src/Collections/SpanTest.cs index 114336e..47175f0 100644 --- a/X10D.Tests/src/Collections/SpanTest.cs +++ b/X10D.Tests/src/Collections/SpanTest.cs @@ -31,7 +31,7 @@ internal class SpanTest [Test] public void Count_ShouldReturn8_GivenSpanWith8MatchingElements() { - Span span = stackalloc int[16] {1, 2, 3, 2, 5, 2, 7, 2, 9, 2, 11, 2, 13, 2, 15, 2}; + Span span = stackalloc int[16] { 1, 2, 3, 2, 5, 2, 7, 2, 9, 2, 11, 2, 13, 2, 15, 2 }; int count = span.Count(2); @@ -41,7 +41,7 @@ internal class SpanTest [Test] public void Count_ShouldReturn8_GivenReadOnlySpanWith8MatchingElements() { - ReadOnlySpan span = stackalloc int[16] {1, 2, 3, 2, 5, 2, 7, 2, 9, 2, 11, 2, 13, 2, 15, 2}; + ReadOnlySpan span = stackalloc int[16] { 1, 2, 3, 2, 5, 2, 7, 2, 9, 2, 11, 2, 13, 2, 15, 2 }; int count = span.Count(2); @@ -51,25 +51,25 @@ internal class SpanTest [Test] public void Replace_ShouldReplaceAllElements_GivenSpanOfInt32() { - Span span = stackalloc int[16] {1, 2, 3, 2, 5, 2, 7, 2, 9, 2, 11, 2, 13, 2, 15, 2}; + Span span = stackalloc int[16] { 1, 2, 3, 2, 5, 2, 7, 2, 9, 2, 11, 2, 13, 2, 15, 2 }; span.Replace(2, 4); - Assert.That(span.ToArray(), Is.EqualTo(new[] {1, 4, 3, 4, 5, 4, 7, 4, 9, 4, 11, 4, 13, 4, 15, 4})); + Assert.That(span.ToArray(), Is.EqualTo(new[] { 1, 4, 3, 4, 5, 4, 7, 4, 9, 4, 11, 4, 13, 4, 15, 4 })); } [Test] public void Replace_ShouldReplaceAllElements_GivenSpanOfChar() { - Span chars = stackalloc char[12] {'H', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!'}; + Span chars = stackalloc char[12] { 'H', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!' }; chars.Replace('l', 'w'); - CollectionAssert.AreEqual(chars.ToArray(), "Hewwo worwd!".ToCharArray()); + Assert.That("Hewwo worwd!".ToCharArray(), Is.EqualTo(chars.ToArray()).AsCollection); } [Test] public void Replace_ShouldDoNothing_GivenSpanWithNoMatchingElements() { - Span span = stackalloc int[16] {1, 2, 3, 2, 5, 2, 7, 2, 9, 2, 11, 2, 13, 2, 15, 2}; + Span span = stackalloc int[16] { 1, 2, 3, 2, 5, 2, 7, 2, 9, 2, 11, 2, 13, 2, 15, 2 }; span.Replace(4, 8); - Assert.That(span.ToArray(), Is.EqualTo(new[] {1, 2, 3, 2, 5, 2, 7, 2, 9, 2, 11, 2, 13, 2, 15, 2})); + Assert.That(span.ToArray(), Is.EqualTo(new[] { 1, 2, 3, 2, 5, 2, 7, 2, 9, 2, 11, 2, 13, 2, 15, 2 })); } #if !NET9_0_OR_GREATER diff --git a/X10D.Tests/src/Core/CoreTests.cs b/X10D.Tests/src/Core/CoreTests.cs index a5df6ac..6e46d93 100644 --- a/X10D.Tests/src/Core/CoreTests.cs +++ b/X10D.Tests/src/Core/CoreTests.cs @@ -63,7 +63,7 @@ internal class CoreTests // ReSharper disable once PossibleMultipleEnumeration object[] array = enumerable.ToArray(); Assert.That(array, Has.Length.EqualTo(10)); - CollectionAssert.AreEqual(new[] {o, o, o, o, o, o, o, o, o, o}, array); + Assert.That(array, Is.EqualTo(new[] { o, o, o, o, o, o, o, o, o, o }).AsCollection); } [Test] diff --git a/X10D.Tests/src/Core/SpanTest.cs b/X10D.Tests/src/Core/SpanTest.cs index 743a55e..9b3673b 100644 --- a/X10D.Tests/src/Core/SpanTest.cs +++ b/X10D.Tests/src/Core/SpanTest.cs @@ -1,4 +1,3 @@ -using System.Runtime.Intrinsics.Arm; using System.Runtime.Intrinsics.X86; using NUnit.Framework; using X10D.Core; diff --git a/X10D.Tests/src/Drawing/PolygonFTests.cs b/X10D.Tests/src/Drawing/PolygonFTests.cs index 9052c98..a5c54fe 100644 --- a/X10D.Tests/src/Drawing/PolygonFTests.cs +++ b/X10D.Tests/src/Drawing/PolygonFTests.cs @@ -85,7 +85,7 @@ internal class PolygonFTests // we cannot use CollectionAssert here for reasons I am not entirely sure of. // it seems to dislike casting from IReadOnlyList to ICollection. but okay. - CollectionAssert.AreEqual(first.Vertices, second.Vertices); + Assert.That(second.Vertices, Is.EqualTo(first.Vertices).AsCollection); // assert that the empty polygon was not modified Assert.That(PolygonF.Empty.VertexCount, Is.Zero); @@ -178,7 +178,7 @@ internal class PolygonFTests Assert.That(converted, Is.EqualTo((Polygon)polygon)); Assert.That(converted.IsConvex, Is.EqualTo(polygon.IsConvex)); Assert.That(converted.VertexCount, Is.EqualTo(polygon.VertexCount)); - CollectionAssert.AreEqual(polygon.Vertices, converted.Vertices.Select(p => (PointF)p)); + Assert.That(converted.Vertices.Select(p => (PointF)p), Is.EqualTo(polygon.Vertices).AsCollection); }); } @@ -194,7 +194,7 @@ internal class PolygonFTests Assert.That(converted == polygon); Assert.That(converted.IsConvex, Is.EqualTo(polygon.IsConvex)); Assert.That(converted.VertexCount, Is.EqualTo(polygon.VertexCount)); - CollectionAssert.AreEqual(converted.Vertices, polygon.Vertices.Select(p => (PointF)p)); + Assert.That(polygon.Vertices.Select(p => (PointF)p), Is.EqualTo(converted.Vertices).AsCollection); }); } diff --git a/X10D.Tests/src/Drawing/PolyhedronTests.cs b/X10D.Tests/src/Drawing/PolyhedronTests.cs index 30545e7..4a81ec7 100644 --- a/X10D.Tests/src/Drawing/PolyhedronTests.cs +++ b/X10D.Tests/src/Drawing/PolyhedronTests.cs @@ -75,7 +75,7 @@ internal class PolyhedronTests // we cannot use CollectionAssert here for reasons I am not entirely sure of. // it seems to dislike casting from IReadOnlyList to ICollection. but okay. - CollectionAssert.AreEqual(first.Vertices, second.Vertices); + Assert.That(second.Vertices, Is.EqualTo(first.Vertices).AsCollection); // assert that the empty polyhedron was not modified Assert.That(Polyhedron.Empty.VertexCount, Is.Zero); @@ -148,11 +148,11 @@ internal class PolyhedronTests Assert.That(converted, Is.EqualTo((Polyhedron)polygon)); Assert.That(converted.VertexCount, Is.EqualTo(polygon.VertexCount)); - CollectionAssert.AreEqual(converted.Vertices, polygon.Vertices.Select(p => + Assert.That(polygon.Vertices.Select(p => { var point = p.ToVector2(); return new Vector3(point.X, point.Y, 0); - })); + }), Is.EqualTo(converted.Vertices).AsCollection); }); } @@ -166,11 +166,11 @@ internal class PolyhedronTests { Assert.That(converted, Is.EqualTo((Polyhedron)polygon)); Assert.That(converted.VertexCount, Is.EqualTo(polygon.VertexCount)); - CollectionAssert.AreEqual(converted.Vertices, polygon.Vertices.Select(p => + Assert.That(converted.Vertices, Is.EqualTo(polygon.Vertices.Select(p => { var point = p.ToVector2(); return new Vector3(point.X, point.Y, 0); - })); + })).AsCollection); }); } diff --git a/X10D.Tests/src/Hosting/ServiceCollectionTests.cs b/X10D.Tests/src/Hosting/ServiceCollectionTests.cs index d9a8351..7bc78d1 100644 --- a/X10D.Tests/src/Hosting/ServiceCollectionTests.cs +++ b/X10D.Tests/src/Hosting/ServiceCollectionTests.cs @@ -23,8 +23,8 @@ internal class ServiceCollectionTests { Assert.That(service, Is.Not.Null); Assert.That(hostedService, Is.Not.Null); - Assert.IsAssignableFrom(service); - Assert.IsAssignableFrom(hostedService); + Assert.That(service, Is.AssignableFrom()); + Assert.That(hostedService, Is.AssignableFrom()); Assert.That(hostedService, Is.SameAs(service)); }); } @@ -44,8 +44,8 @@ internal class ServiceCollectionTests { Assert.That(service, Is.Not.Null); Assert.That(hostedService, Is.Not.Null); - Assert.IsAssignableFrom(service); - Assert.IsAssignableFrom(hostedService); + Assert.That(service, Is.AssignableFrom()); + Assert.That(hostedService, Is.AssignableFrom()); Assert.That(hostedService, Is.SameAs(service)); }); } @@ -65,8 +65,8 @@ internal class ServiceCollectionTests { Assert.That(service, Is.Not.Null); Assert.That(hostedService, Is.Not.Null); - Assert.IsAssignableFrom(service); - Assert.IsAssignableFrom(hostedService); + Assert.That(service, Is.AssignableFrom()); + Assert.That(hostedService, Is.AssignableFrom()); Assert.That(hostedService, Is.SameAs(service)); }); } @@ -86,8 +86,8 @@ internal class ServiceCollectionTests { Assert.That(service, Is.Not.Null); Assert.That(hostedService, Is.Not.Null); - Assert.IsAssignableFrom(service); - Assert.IsAssignableFrom(hostedService); + Assert.That(service, Is.AssignableFrom()); + Assert.That(hostedService, Is.AssignableFrom()); Assert.That(hostedService, Is.SameAs(service)); }); } diff --git a/X10D.Tests/src/IO/BooleanTests.cs b/X10D.Tests/src/IO/BooleanTests.cs index 87e2075..99bd606 100644 --- a/X10D.Tests/src/IO/BooleanTests.cs +++ b/X10D.Tests/src/IO/BooleanTests.cs @@ -10,7 +10,7 @@ internal class BooleanTests public void GetBytes_ReturnsArrayContaining1() { const bool value = true; - CollectionAssert.AreEqual(new byte[] {1}, value.GetBytes()); + Assert.That(value.GetBytes(), Is.EqualTo(new byte[] { 1 }).AsCollection); } [Test] @@ -19,7 +19,7 @@ internal class BooleanTests const bool value = true; Span buffer = stackalloc byte[1]; Assert.That(value.TryWriteBytes(buffer)); - CollectionAssert.AreEqual(new byte[] {1}, buffer.ToArray()); + Assert.That(buffer.ToArray(), Is.EqualTo(new byte[] { 1 }).AsCollection); } [Test] diff --git a/X10D.Tests/src/IO/ByteTests.cs b/X10D.Tests/src/IO/ByteTests.cs index 433cc09..1c9d1c9 100644 --- a/X10D.Tests/src/IO/ByteTests.cs +++ b/X10D.Tests/src/IO/ByteTests.cs @@ -10,16 +10,19 @@ internal class ByteTests public void GetBytes_ReturnsArrayContainingItself() { const byte value = 0xFF; - CollectionAssert.AreEqual(new[] {value}, value.GetBytes()); + Assert.That(value.GetBytes(), Is.EqualTo(new[] { value }).AsCollection); } [Test] public void TryWriteBytes_ReturnsTrue_FillsSpanContainingItself_GivenLargeEnoughSpan() { const byte value = 0xFF; - Span buffer = stackalloc byte[1]; - Assert.That(value.TryWriteBytes(buffer)); - CollectionAssert.AreEqual(new[] {value}, buffer.ToArray()); + Assert.Multiple(() => + { + Span buffer = stackalloc byte[1]; + Assert.That(value.TryWriteBytes(buffer)); + Assert.That(buffer.ToArray(), Is.EqualTo(new[] { value }).AsCollection); + }); } [Test] diff --git a/X10D.Tests/src/IO/DecimalTests.cs b/X10D.Tests/src/IO/DecimalTests.cs index 46e7077..8a64198 100644 --- a/X10D.Tests/src/IO/DecimalTests.cs +++ b/X10D.Tests/src/IO/DecimalTests.cs @@ -14,7 +14,7 @@ internal class DecimalTests byte[] bytes = value.GetBigEndianBytes(); - CollectionAssert.AreEqual(expected, bytes); + Assert.That(bytes, Is.EqualTo(expected).AsCollection); } [Test] @@ -25,7 +25,7 @@ internal class DecimalTests byte[] bytes = value.GetLittleEndianBytes(); - CollectionAssert.AreEqual(expected, bytes); + Assert.That(bytes, Is.EqualTo(expected).AsCollection); } [Test] @@ -34,10 +34,12 @@ internal class DecimalTests const decimal value = 1234m; byte[] expected = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 210]; - Span bytes = stackalloc byte[16]; - Assert.That(value.TryWriteBigEndianBytes(bytes)); - - CollectionAssert.AreEqual(expected, bytes.ToArray()); + Assert.Multiple(() => + { + Span bytes = stackalloc byte[16]; + Assert.That(value.TryWriteBigEndianBytes(bytes)); + Assert.That(bytes.ToArray(), Is.EqualTo(expected).AsCollection); + }); } [Test] @@ -46,10 +48,12 @@ internal class DecimalTests const decimal value = 1234m; byte[] expected = [210, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; - Span bytes = stackalloc byte[16]; - Assert.That(value.TryWriteLittleEndianBytes(bytes)); - - CollectionAssert.AreEqual(expected, bytes.ToArray()); + Assert.Multiple(() => + { + Span bytes = stackalloc byte[16]; + Assert.That(value.TryWriteLittleEndianBytes(bytes)); + Assert.That(bytes.ToArray(), Is.EqualTo(expected).AsCollection); + }); } [Test] diff --git a/X10D.Tests/src/IO/DoubleTests.cs b/X10D.Tests/src/IO/DoubleTests.cs index 66f15fe..99ae227 100644 --- a/X10D.Tests/src/IO/DoubleTests.cs +++ b/X10D.Tests/src/IO/DoubleTests.cs @@ -13,7 +13,7 @@ internal class DoubleTests var expected = new byte[] { 0x40, 0x45, 0x40, 0, 0, 0, 0, 0 }; byte[] actual = value.GetBigEndianBytes(); - CollectionAssert.AreEqual(expected, actual); + Assert.That(actual, Is.EqualTo(expected).AsCollection); } [Test] @@ -23,7 +23,7 @@ internal class DoubleTests var expected = new byte[] { 0, 0, 0, 0, 0, 0x40, 0x45, 0x40 }; byte[] actual = value.GetLittleEndianBytes(); - CollectionAssert.AreEqual(expected, actual); + Assert.That(actual, Is.EqualTo(expected).AsCollection); } [Test] @@ -32,9 +32,12 @@ internal class DoubleTests const double value = 42.5; var expected = new byte[] { 0x40, 0x45, 0x40, 0, 0, 0, 0, 0 }; - Span actual = stackalloc byte[8]; - Assert.That(value.TryWriteBigEndianBytes(actual)); - CollectionAssert.AreEqual(expected, actual.ToArray()); + Assert.Multiple(() => + { + Span actual = stackalloc byte[8]; + Assert.That(value.TryWriteBigEndianBytes(actual)); + Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection); + }); } [Test] @@ -43,9 +46,12 @@ internal class DoubleTests const double value = 42.5; var expected = new byte[] { 0, 0, 0, 0, 0, 0x40, 0x45, 0x40 }; - Span actual = stackalloc byte[8]; - Assert.That(value.TryWriteLittleEndianBytes(actual)); - CollectionAssert.AreEqual(expected, actual.ToArray()); + Assert.Multiple(() => + { + Span actual = stackalloc byte[8]; + Assert.That(value.TryWriteLittleEndianBytes(actual)); + Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection); + }); } [Test] diff --git a/X10D.Tests/src/IO/FileInfoTests.cs b/X10D.Tests/src/IO/FileInfoTests.cs index 319e864..aff685e 100644 --- a/X10D.Tests/src/IO/FileInfoTests.cs +++ b/X10D.Tests/src/IO/FileInfoTests.cs @@ -29,7 +29,7 @@ internal class FileInfoTests try { byte[] hash = new FileInfo(fileName).GetHash(); - CollectionAssert.AreEqual(expectedHash, hash); + Assert.That(hash, Is.EqualTo(expectedHash).AsCollection); } finally { @@ -58,10 +58,14 @@ internal class FileInfoTests try { - Span hash = stackalloc byte[20]; - new FileInfo(fileName).TryWriteHash(hash, out int bytesWritten); - Assert.That(bytesWritten, Is.EqualTo(expectedHash.Length)); - CollectionAssert.AreEqual(expectedHash, hash.ToArray()); + Assert.Multiple(() => + { + Span hash = stackalloc byte[20]; + new FileInfo(fileName).TryWriteHash(hash, out int bytesWritten); + + Assert.That(bytesWritten, Is.EqualTo(expectedHash.Length)); + Assert.That(hash.ToArray(), Is.EqualTo(expectedHash).AsCollection); + }); } finally { diff --git a/X10D.Tests/src/IO/Int16Tests.cs b/X10D.Tests/src/IO/Int16Tests.cs index 6b03d4a..ad6a146 100644 --- a/X10D.Tests/src/IO/Int16Tests.cs +++ b/X10D.Tests/src/IO/Int16Tests.cs @@ -13,7 +13,7 @@ internal class Int16Tests byte[] expected = { 0x0F, 0 }; byte[] actual = value.GetLittleEndianBytes(); - CollectionAssert.AreEqual(expected, actual); + Assert.That(actual, Is.EqualTo(expected).AsCollection); } [Test] @@ -23,7 +23,7 @@ internal class Int16Tests byte[] expected = { 0, 0x0F }; byte[] actual = value.GetBigEndianBytes(); - CollectionAssert.AreEqual(expected, actual); + Assert.That(actual, Is.EqualTo(expected).AsCollection); } [Test] @@ -32,9 +32,12 @@ internal class Int16Tests const short value = 0x0F; byte[] expected = { 0x0F, 0 }; - Span actual = stackalloc byte[2]; - Assert.That(value.TryWriteLittleEndianBytes(actual)); - CollectionAssert.AreEqual(expected, actual.ToArray()); + Assert.Multiple(() => + { + Span actual = stackalloc byte[2]; + Assert.That(value.TryWriteLittleEndianBytes(actual)); + Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection); + }); } [Test] @@ -43,9 +46,12 @@ internal class Int16Tests const short value = 0x0F; byte[] expected = { 0, 0x0F }; - Span actual = stackalloc byte[2]; - Assert.That(value.TryWriteBigEndianBytes(actual)); - CollectionAssert.AreEqual(expected, actual.ToArray()); + Assert.Multiple(() => + { + Span actual = stackalloc byte[2]; + Assert.That(value.TryWriteBigEndianBytes(actual)); + Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection); + }); } [Test] diff --git a/X10D.Tests/src/IO/Int32Tests.cs b/X10D.Tests/src/IO/Int32Tests.cs index 01c7990..634426f 100644 --- a/X10D.Tests/src/IO/Int32Tests.cs +++ b/X10D.Tests/src/IO/Int32Tests.cs @@ -13,7 +13,7 @@ internal class Int32Tests var expected = new byte[] { 0, 0, 0, 0x0F }; byte[] actual = value.GetBigEndianBytes(); - CollectionAssert.AreEqual(expected, actual); + Assert.That(actual, Is.EqualTo(expected).AsCollection); } [Test] @@ -23,7 +23,7 @@ internal class Int32Tests var expected = new byte[] { 0x0F, 0, 0, 0 }; byte[] actual = value.GetLittleEndianBytes(); - CollectionAssert.AreEqual(expected, actual); + Assert.That(actual, Is.EqualTo(expected).AsCollection); } [Test] @@ -32,9 +32,12 @@ internal class Int32Tests const int value = 0x0F; var expected = new byte[] { 0, 0, 0, 0x0F }; - Span actual = stackalloc byte[4]; - Assert.That(value.TryWriteBigEndianBytes(actual)); - CollectionAssert.AreEqual(expected, actual.ToArray()); + Assert.Multiple(() => + { + Span actual = stackalloc byte[4]; + Assert.That(value.TryWriteBigEndianBytes(actual)); + Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection); + }); } [Test] @@ -43,9 +46,12 @@ internal class Int32Tests const int value = 0x0F; var expected = new byte[] { 0x0F, 0, 0, 0 }; - Span actual = stackalloc byte[4]; - Assert.That(value.TryWriteLittleEndianBytes(actual)); - CollectionAssert.AreEqual(expected, actual.ToArray()); + Assert.Multiple(() => + { + Span actual = stackalloc byte[4]; + Assert.That(value.TryWriteLittleEndianBytes(actual)); + Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection); + }); } [Test] diff --git a/X10D.Tests/src/IO/Int64Tests.cs b/X10D.Tests/src/IO/Int64Tests.cs index c331369..d4751be 100644 --- a/X10D.Tests/src/IO/Int64Tests.cs +++ b/X10D.Tests/src/IO/Int64Tests.cs @@ -13,7 +13,7 @@ internal class Int64Tests byte[] expected = { 0x0F, 0, 0, 0, 0, 0, 0, 0 }; byte[] actual = value.GetLittleEndianBytes(); - CollectionAssert.AreEqual(expected, actual); + Assert.That(actual, Is.EqualTo(expected).AsCollection); } [Test] @@ -23,7 +23,7 @@ internal class Int64Tests byte[] expected = { 0, 0, 0, 0, 0, 0, 0, 0x0F }; byte[] actual = value.GetBigEndianBytes(); - CollectionAssert.AreEqual(expected, actual); + Assert.That(actual, Is.EqualTo(expected).AsCollection); } [Test] @@ -32,9 +32,12 @@ internal class Int64Tests const long value = 0x0F; byte[] expected = { 0x0F, 0, 0, 0, 0, 0, 0, 0 }; - Span actual = stackalloc byte[8]; - Assert.That(value.TryWriteLittleEndianBytes(actual)); - CollectionAssert.AreEqual(expected, actual.ToArray()); + Assert.Multiple(() => + { + Span actual = stackalloc byte[8]; + Assert.That(value.TryWriteLittleEndianBytes(actual)); + Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection); + }); } [Test] @@ -43,9 +46,12 @@ internal class Int64Tests const long value = 0x0F; byte[] expected = { 0, 0, 0, 0, 0, 0, 0, 0x0F }; - Span actual = stackalloc byte[8]; - Assert.That(value.TryWriteBigEndianBytes(actual)); - CollectionAssert.AreEqual(expected, actual.ToArray()); + Assert.Multiple(() => + { + Span actual = stackalloc byte[8]; + Assert.That(value.TryWriteBigEndianBytes(actual)); + Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection); + }); } [Test] diff --git a/X10D.Tests/src/IO/SByteTests.cs b/X10D.Tests/src/IO/SByteTests.cs index c9486e2..e7d3d6e 100644 --- a/X10D.Tests/src/IO/SByteTests.cs +++ b/X10D.Tests/src/IO/SByteTests.cs @@ -10,16 +10,19 @@ internal class SByteTests public void GetBytes_ReturnsArrayContainingItself() { const sbyte value = 0x0F; - CollectionAssert.AreEqual(new[] {(byte)value}, value.GetBytes()); + Assert.That(value.GetBytes(), Is.EqualTo(new[] { (byte)value }).AsCollection); } [Test] public void TryWriteBytes_ReturnsTrue_FillsSpanContainingItself_GivenLargeEnoughSpan() { const sbyte value = 0x0F; - Span buffer = stackalloc byte[1]; - Assert.That(value.TryWriteBytes(buffer)); - CollectionAssert.AreEqual(new[] {(byte)value}, buffer.ToArray()); + Assert.Multiple(() => + { + Span buffer = stackalloc byte[1]; + Assert.That(value.TryWriteBytes(buffer)); + Assert.That(buffer.ToArray(), Is.EqualTo(new[] { (byte)value }).AsCollection); + }); } [Test] diff --git a/X10D.Tests/src/IO/SingleTests.cs b/X10D.Tests/src/IO/SingleTests.cs index 984f8a4..1dd325a 100644 --- a/X10D.Tests/src/IO/SingleTests.cs +++ b/X10D.Tests/src/IO/SingleTests.cs @@ -13,7 +13,7 @@ internal class SingleTests var expected = new byte[] { 0x42, 0x2A, 0, 0 }; byte[] actual = value.GetBigEndianBytes(); - CollectionAssert.AreEqual(expected, actual); + Assert.That(actual, Is.EqualTo(expected).AsCollection); } [Test] @@ -23,7 +23,7 @@ internal class SingleTests var expected = new byte[] { 0, 0, 0x2A, 0x42 }; byte[] actual = value.GetLittleEndianBytes(); - CollectionAssert.AreEqual(expected, actual); + Assert.That(actual, Is.EqualTo(expected).AsCollection); } [Test] @@ -32,9 +32,12 @@ internal class SingleTests const float value = 42.5f; var expected = new byte[] { 0x42, 0x2A, 0, 0 }; - Span actual = stackalloc byte[4]; - Assert.That(value.TryWriteBigEndianBytes(actual)); - CollectionAssert.AreEqual(expected, actual.ToArray()); + Assert.Multiple(() => + { + Span actual = stackalloc byte[4]; + Assert.That(value.TryWriteBigEndianBytes(actual)); + Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection); + }); } [Test] @@ -43,9 +46,12 @@ internal class SingleTests const float value = 42.5f; var expected = new byte[] { 0, 0, 0x2A, 0x42 }; - Span actual = stackalloc byte[4]; - Assert.That(value.TryWriteLittleEndianBytes(actual)); - CollectionAssert.AreEqual(expected, actual.ToArray()); + Assert.Multiple(() => + { + Span actual = stackalloc byte[4]; + Assert.That(value.TryWriteLittleEndianBytes(actual)); + Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection); + }); } [Test] diff --git a/X10D.Tests/src/IO/StreamTests.WriteDecimal.cs b/X10D.Tests/src/IO/StreamTests.WriteDecimal.cs index 15e7538..91aed0d 100644 --- a/X10D.Tests/src/IO/StreamTests.WriteDecimal.cs +++ b/X10D.Tests/src/IO/StreamTests.WriteDecimal.cs @@ -45,16 +45,19 @@ internal partial class StreamTests Assert.That(stream.Position, Is.EqualTo(16)); stream.Position = 0; - Span actual = stackalloc byte[16]; - ReadOnlySpan expected = stackalloc byte[] + Assert.Multiple(() => { - 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x68 - }; - int read = stream.Read(actual); - Trace.WriteLine(string.Join(' ', actual.ToArray())); + Span actual = stackalloc byte[16]; + ReadOnlySpan expected = stackalloc byte[] + { + 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x68 + }; + int read = stream.Read(actual); + Trace.WriteLine(string.Join(' ', actual.ToArray())); - Assert.That(read, Is.EqualTo(16)); - CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray()); + Assert.That(read, Is.EqualTo(16)); + Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection); + }); } [Test] @@ -65,16 +68,19 @@ internal partial class StreamTests Assert.That(stream.Position, Is.EqualTo(16)); stream.Position = 0; - Span actual = stackalloc byte[16]; - ReadOnlySpan expected = stackalloc byte[] + Assert.Multiple(() => { - 0x68, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00 - }; - int read = stream.Read(actual); + Span actual = stackalloc byte[16]; + ReadOnlySpan expected = stackalloc byte[] + { + 0x68, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00 + }; + int read = stream.Read(actual); - Trace.WriteLine(string.Join(", ", actual.ToArray().Select(b => $"0x{b:X2}"))); + Trace.WriteLine(string.Join(", ", actual.ToArray().Select(b => $"0x{b:X2}"))); - Assert.That(read, Is.EqualTo(16)); - CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray()); + Assert.That(read, Is.EqualTo(16)); + Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection); + }); } } diff --git a/X10D.Tests/src/IO/StreamTests.WriteDouble.cs b/X10D.Tests/src/IO/StreamTests.WriteDouble.cs index 8828325..ba82011 100644 --- a/X10D.Tests/src/IO/StreamTests.WriteDouble.cs +++ b/X10D.Tests/src/IO/StreamTests.WriteDouble.cs @@ -44,12 +44,15 @@ internal partial class StreamTests Assert.That(stream.Position, Is.EqualTo(8)); stream.Position = 0; - Span actual = stackalloc byte[8]; - ReadOnlySpan expected = stackalloc byte[] { 0x40, 0x7A, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00 }; - int read = stream.Read(actual); + Assert.Multiple(() => + { + Span actual = stackalloc byte[8]; + ReadOnlySpan expected = stackalloc byte[] { 0x40, 0x7A, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00 }; + int read = stream.Read(actual); - Assert.That(read, Is.EqualTo(8)); - CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray()); + Assert.That(read, Is.EqualTo(8)); + Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection); + }); } [Test] @@ -60,11 +63,14 @@ internal partial class StreamTests Assert.That(stream.Position, Is.EqualTo(8)); stream.Position = 0; - Span actual = stackalloc byte[8]; - ReadOnlySpan expected = stackalloc byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x7A, 0x40 }; - int read = stream.Read(actual); + Assert.Multiple(() => + { + Span actual = stackalloc byte[8]; + ReadOnlySpan expected = stackalloc byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x7A, 0x40 }; + int read = stream.Read(actual); - Assert.That(read, Is.EqualTo(8)); - CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray()); + Assert.That(read, Is.EqualTo(8)); + Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection); + }); } } diff --git a/X10D.Tests/src/IO/StreamTests.WriteInt16.cs b/X10D.Tests/src/IO/StreamTests.WriteInt16.cs index bc38dd8..a49513b 100644 --- a/X10D.Tests/src/IO/StreamTests.WriteInt16.cs +++ b/X10D.Tests/src/IO/StreamTests.WriteInt16.cs @@ -44,12 +44,15 @@ internal partial class StreamTests Assert.That(stream.Position, Is.EqualTo(2)); stream.Position = 0; - Span actual = stackalloc byte[2]; - ReadOnlySpan expected = stackalloc byte[] { 0x01, 0xA4 }; - int read = stream.Read(actual); + Assert.Multiple(() => + { + Span actual = stackalloc byte[2]; + ReadOnlySpan expected = stackalloc byte[] { 0x01, 0xA4 }; + int read = stream.Read(actual); - Assert.That(read, Is.EqualTo(2)); - CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray()); + Assert.That(read, Is.EqualTo(2)); + Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection); + }); } [Test] @@ -60,11 +63,14 @@ internal partial class StreamTests Assert.That(stream.Position, Is.EqualTo(2)); stream.Position = 0; - Span actual = stackalloc byte[2]; - ReadOnlySpan expected = stackalloc byte[] { 0xA4, 0x01 }; - int read = stream.Read(actual); + Assert.Multiple(() => + { + Span actual = stackalloc byte[2]; + ReadOnlySpan expected = stackalloc byte[] { 0xA4, 0x01 }; + int read = stream.Read(actual); - Assert.That(read, Is.EqualTo(2)); - CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray()); + Assert.That(read, Is.EqualTo(2)); + Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection); + }); } } diff --git a/X10D.Tests/src/IO/StreamTests.WriteInt32.cs b/X10D.Tests/src/IO/StreamTests.WriteInt32.cs index 75688f9..7534e2e 100644 --- a/X10D.Tests/src/IO/StreamTests.WriteInt32.cs +++ b/X10D.Tests/src/IO/StreamTests.WriteInt32.cs @@ -44,12 +44,15 @@ internal partial class StreamTests Assert.That(stream.Position, Is.EqualTo(4)); stream.Position = 0; - Span actual = stackalloc byte[4]; - ReadOnlySpan expected = stackalloc byte[] { 0x00, 0x00, 0x01, 0xA4 }; - int read = stream.Read(actual); + Assert.Multiple(() => + { + Span actual = stackalloc byte[4]; + ReadOnlySpan expected = stackalloc byte[] { 0x00, 0x00, 0x01, 0xA4 }; + int read = stream.Read(actual); - Assert.That(read, Is.EqualTo(4)); - CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray()); + Assert.That(read, Is.EqualTo(4)); + Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection); + }); } [Test] @@ -60,11 +63,14 @@ internal partial class StreamTests Assert.That(stream.Position, Is.EqualTo(4)); stream.Position = 0; - Span actual = stackalloc byte[4]; - ReadOnlySpan expected = stackalloc byte[] { 0xA4, 0x01, 0x00, 0x00 }; - int read = stream.Read(actual); + Assert.Multiple(() => + { + Span actual = stackalloc byte[4]; + ReadOnlySpan expected = stackalloc byte[] { 0xA4, 0x01, 0x00, 0x00 }; + int read = stream.Read(actual); - Assert.That(read, Is.EqualTo(4)); - CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray()); + Assert.That(read, Is.EqualTo(4)); + Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection); + }); } } diff --git a/X10D.Tests/src/IO/StreamTests.WriteInt64.cs b/X10D.Tests/src/IO/StreamTests.WriteInt64.cs index feeb677..3a3fea5 100644 --- a/X10D.Tests/src/IO/StreamTests.WriteInt64.cs +++ b/X10D.Tests/src/IO/StreamTests.WriteInt64.cs @@ -44,12 +44,15 @@ internal partial class StreamTests Assert.That(stream.Position, Is.EqualTo(8)); stream.Position = 0; - Span actual = stackalloc byte[8]; - ReadOnlySpan expected = stackalloc byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xA4 }; - int read = stream.Read(actual); + Assert.Multiple(() => + { + Span actual = stackalloc byte[8]; + ReadOnlySpan expected = stackalloc byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xA4 }; + int read = stream.Read(actual); - Assert.That(read, Is.EqualTo(8)); - CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray()); + Assert.That(read, Is.EqualTo(8)); + Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection); + }); } [Test] @@ -60,11 +63,14 @@ internal partial class StreamTests Assert.That(stream.Position, Is.EqualTo(8)); stream.Position = 0; - Span actual = stackalloc byte[8]; - ReadOnlySpan expected = stackalloc byte[] { 0xA4, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - int read = stream.Read(actual); + Assert.Multiple(() => + { + Span actual = stackalloc byte[8]; + ReadOnlySpan expected = stackalloc byte[] { 0xA4, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + int read = stream.Read(actual); - Assert.That(read, Is.EqualTo(8)); - CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray()); + Assert.That(read, Is.EqualTo(8)); + Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection); + }); } } diff --git a/X10D.Tests/src/IO/StreamTests.WriteSingle.cs b/X10D.Tests/src/IO/StreamTests.WriteSingle.cs index 7df8eb8..b9a6db0 100644 --- a/X10D.Tests/src/IO/StreamTests.WriteSingle.cs +++ b/X10D.Tests/src/IO/StreamTests.WriteSingle.cs @@ -44,12 +44,15 @@ internal partial class StreamTests Assert.That(stream.Position, Is.EqualTo(4)); stream.Position = 0; - Span actual = stackalloc byte[4]; - ReadOnlySpan expected = stackalloc byte[] { 0x43, 0xD2, 0x00, 0x00 }; - int read = stream.Read(actual); + Assert.Multiple(() => + { + Span actual = stackalloc byte[4]; + ReadOnlySpan expected = stackalloc byte[] { 0x43, 0xD2, 0x00, 0x00 }; + int read = stream.Read(actual); - Assert.That(read, Is.EqualTo(4)); - CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray()); + Assert.That(read, Is.EqualTo(4)); + Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection); + }); } [Test] @@ -60,11 +63,14 @@ internal partial class StreamTests Assert.That(stream.Position, Is.EqualTo(4)); stream.Position = 0; - Span actual = stackalloc byte[4]; - ReadOnlySpan expected = stackalloc byte[] { 0x00, 0x00, 0xD2, 0x43 }; - int read = stream.Read(actual); + Assert.Multiple(() => + { + Span actual = stackalloc byte[4]; + ReadOnlySpan expected = stackalloc byte[] { 0x00, 0x00, 0xD2, 0x43 }; + int read = stream.Read(actual); - Assert.That(read, Is.EqualTo(4)); - CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray()); + Assert.That(read, Is.EqualTo(4)); + Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection); + }); } } diff --git a/X10D.Tests/src/IO/StreamTests.WriteUInt16.cs b/X10D.Tests/src/IO/StreamTests.WriteUInt16.cs index 7fde9f2..4f0be3d 100644 --- a/X10D.Tests/src/IO/StreamTests.WriteUInt16.cs +++ b/X10D.Tests/src/IO/StreamTests.WriteUInt16.cs @@ -44,12 +44,15 @@ internal partial class StreamTests Assert.That(stream.Position, Is.EqualTo(2)); stream.Position = 0; - Span actual = stackalloc byte[2]; - ReadOnlySpan expected = stackalloc byte[] { 0x01, 0xA4 }; - int read = stream.Read(actual); + Assert.Multiple(() => + { + Span actual = stackalloc byte[2]; + ReadOnlySpan expected = stackalloc byte[] { 0x01, 0xA4 }; + int read = stream.Read(actual); - Assert.That(read, Is.EqualTo(2)); - CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray()); + Assert.That(read, Is.EqualTo(2)); + Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection); + }); } [Test] @@ -60,11 +63,14 @@ internal partial class StreamTests Assert.That(stream.Position, Is.EqualTo(2)); stream.Position = 0; - Span actual = stackalloc byte[2]; - ReadOnlySpan expected = stackalloc byte[] { 0xA4, 0x01 }; - int read = stream.Read(actual); + Assert.Multiple(() => + { + Span actual = stackalloc byte[2]; + ReadOnlySpan expected = stackalloc byte[] { 0xA4, 0x01 }; + int read = stream.Read(actual); - Assert.That(read, Is.EqualTo(2)); - CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray()); + Assert.That(read, Is.EqualTo(2)); + Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection); + }); } } diff --git a/X10D.Tests/src/IO/StreamTests.WriteUInt32.cs b/X10D.Tests/src/IO/StreamTests.WriteUInt32.cs index e5eafb7..2c58155 100644 --- a/X10D.Tests/src/IO/StreamTests.WriteUInt32.cs +++ b/X10D.Tests/src/IO/StreamTests.WriteUInt32.cs @@ -44,12 +44,15 @@ internal partial class StreamTests Assert.That(stream.Position, Is.EqualTo(4)); stream.Position = 0; - Span actual = stackalloc byte[4]; - ReadOnlySpan expected = stackalloc byte[] { 0x00, 0x00, 0x01, 0xA4 }; - int read = stream.Read(actual); + Assert.Multiple(() => + { + Span actual = stackalloc byte[4]; + ReadOnlySpan expected = stackalloc byte[] { 0x00, 0x00, 0x01, 0xA4 }; + int read = stream.Read(actual); - Assert.That(read, Is.EqualTo(4)); - CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray()); + Assert.That(read, Is.EqualTo(4)); + Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection); + }); } [Test] @@ -60,11 +63,14 @@ internal partial class StreamTests Assert.That(stream.Position, Is.EqualTo(4)); stream.Position = 0; - Span actual = stackalloc byte[4]; - ReadOnlySpan expected = stackalloc byte[] { 0xA4, 0x01, 0x00, 0x00 }; - int read = stream.Read(actual); + Assert.Multiple(() => + { + Span actual = stackalloc byte[4]; + ReadOnlySpan expected = stackalloc byte[] { 0xA4, 0x01, 0x00, 0x00 }; + int read = stream.Read(actual); - Assert.That(read, Is.EqualTo(4)); - CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray()); + Assert.That(read, Is.EqualTo(4)); + Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection); + }); } } diff --git a/X10D.Tests/src/IO/StreamTests.WriteUInt64.cs b/X10D.Tests/src/IO/StreamTests.WriteUInt64.cs index 5d8edcf..349f489 100644 --- a/X10D.Tests/src/IO/StreamTests.WriteUInt64.cs +++ b/X10D.Tests/src/IO/StreamTests.WriteUInt64.cs @@ -44,12 +44,15 @@ internal partial class StreamTests Assert.That(stream.Position, Is.EqualTo(8)); stream.Position = 0; - Span actual = stackalloc byte[8]; - ReadOnlySpan expected = stackalloc byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xA4 }; - int read = stream.Read(actual); + Assert.Multiple(() => + { + Span actual = stackalloc byte[8]; + ReadOnlySpan expected = stackalloc byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xA4 }; + int read = stream.Read(actual); - Assert.That(read, Is.EqualTo(8)); - CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray()); + Assert.That(read, Is.EqualTo(8)); + Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection); + }); } [Test] @@ -60,11 +63,14 @@ internal partial class StreamTests Assert.That(stream.Position, Is.EqualTo(8)); stream.Position = 0; - Span actual = stackalloc byte[8]; - ReadOnlySpan expected = stackalloc byte[] { 0xA4, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - int read = stream.Read(actual); + Assert.Multiple(() => + { + Span actual = stackalloc byte[8]; + ReadOnlySpan expected = stackalloc byte[] { 0xA4, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + int read = stream.Read(actual); - Assert.That(read, Is.EqualTo(8)); - CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray()); + Assert.That(read, Is.EqualTo(8)); + Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection); + }); } } diff --git a/X10D.Tests/src/IO/StreamTests.cs b/X10D.Tests/src/IO/StreamTests.cs index b522265..2857c16 100644 --- a/X10D.Tests/src/IO/StreamTests.cs +++ b/X10D.Tests/src/IO/StreamTests.cs @@ -26,7 +26,7 @@ internal partial class StreamTests byte[] hash = stream.GetHash(); Trace.WriteLine($"Hash: {BitConverter.ToString(hash)}"); Trace.WriteLine($"Expected: {BitConverter.ToString(expectedHash)}"); - CollectionAssert.AreEqual(expectedHash, hash); + Assert.That(hash, Is.EqualTo(expectedHash).AsCollection); } [Test] @@ -54,7 +54,7 @@ internal partial class StreamTests Span hash = stackalloc byte[20]; stream.TryWriteHash(hash, out int bytesWritten); Assert.That(bytesWritten, Is.EqualTo(expectedHash.Length)); - CollectionAssert.AreEqual(expectedHash, hash.ToArray()); + Assert.That(hash.ToArray(), Is.EqualTo(expectedHash).AsCollection); } [Test] diff --git a/X10D.Tests/src/IO/UInt16Tests.cs b/X10D.Tests/src/IO/UInt16Tests.cs index be9360e..e646553 100644 --- a/X10D.Tests/src/IO/UInt16Tests.cs +++ b/X10D.Tests/src/IO/UInt16Tests.cs @@ -13,7 +13,7 @@ internal class UInt16Tests byte[] expected = { 0x0F, 0 }; byte[] actual = value.GetLittleEndianBytes(); - CollectionAssert.AreEqual(expected, actual); + Assert.That(actual, Is.EqualTo(expected).AsCollection); } [Test] @@ -23,7 +23,7 @@ internal class UInt16Tests byte[] expected = { 0, 0x0F }; byte[] actual = value.GetBigEndianBytes(); - CollectionAssert.AreEqual(expected, actual); + Assert.That(actual, Is.EqualTo(expected).AsCollection); } [Test] @@ -32,10 +32,12 @@ internal class UInt16Tests const ushort value = 0x0F; byte[] expected = { 0x0F, 0 }; - Span actual = stackalloc byte[2]; - Assert.That(value.TryWriteLittleEndianBytes(actual)); - - CollectionAssert.AreEqual(expected, actual.ToArray()); + Assert.Multiple(() => + { + Span actual = stackalloc byte[2]; + Assert.That(value.TryWriteLittleEndianBytes(actual)); + Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection); + }); } [Test] @@ -44,10 +46,12 @@ internal class UInt16Tests const ushort value = 0x0F; byte[] expected = { 0, 0x0F }; - Span actual = stackalloc byte[2]; - Assert.That(value.TryWriteBigEndianBytes(actual)); - - CollectionAssert.AreEqual(expected, actual.ToArray()); + Assert.Multiple(() => + { + Span actual = stackalloc byte[2]; + Assert.That(value.TryWriteBigEndianBytes(actual)); + Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection); + }); } [Test] diff --git a/X10D.Tests/src/IO/UInt32Tests.cs b/X10D.Tests/src/IO/UInt32Tests.cs index 7847759..588f2fb 100644 --- a/X10D.Tests/src/IO/UInt32Tests.cs +++ b/X10D.Tests/src/IO/UInt32Tests.cs @@ -13,7 +13,7 @@ internal class UInt32Tests byte[] expected = { 0x0F, 0, 0, 0 }; byte[] actual = value.GetLittleEndianBytes(); - CollectionAssert.AreEqual(expected, actual); + Assert.That(actual, Is.EqualTo(expected).AsCollection); } [Test] @@ -23,7 +23,7 @@ internal class UInt32Tests byte[] expected = { 0, 0, 0, 0x0F }; byte[] actual = value.GetBigEndianBytes(); - CollectionAssert.AreEqual(expected, actual); + Assert.That(actual, Is.EqualTo(expected).AsCollection); } [Test] @@ -32,10 +32,12 @@ internal class UInt32Tests const uint value = 0x0F; byte[] expected = { 0x0F, 0, 0, 0 }; - Span actual = stackalloc byte[4]; - Assert.That(value.TryWriteLittleEndianBytes(actual)); - - CollectionAssert.AreEqual(expected, actual.ToArray()); + Assert.Multiple(() => + { + Span actual = stackalloc byte[4]; + Assert.That(value.TryWriteLittleEndianBytes(actual)); + Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection); + }); } [Test] @@ -44,10 +46,12 @@ internal class UInt32Tests const uint value = 0x0F; byte[] expected = { 0, 0, 0, 0x0F }; - Span actual = stackalloc byte[4]; - Assert.That(value.TryWriteBigEndianBytes(actual)); - - CollectionAssert.AreEqual(expected, actual.ToArray()); + Assert.Multiple(() => + { + Span actual = stackalloc byte[4]; + Assert.That(value.TryWriteBigEndianBytes(actual)); + Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection); + }); } [Test] diff --git a/X10D.Tests/src/IO/UInt64Tests.cs b/X10D.Tests/src/IO/UInt64Tests.cs index e783e2a..07e38f4 100644 --- a/X10D.Tests/src/IO/UInt64Tests.cs +++ b/X10D.Tests/src/IO/UInt64Tests.cs @@ -13,7 +13,7 @@ internal class UInt64Tests byte[] expected = { 0x0F, 0, 0, 0, 0, 0, 0, 0 }; byte[] actual = value.GetLittleEndianBytes(); - CollectionAssert.AreEqual(expected, actual); + Assert.That(actual, Is.EqualTo(expected).AsCollection); } [Test] @@ -23,7 +23,7 @@ internal class UInt64Tests byte[] expected = { 0, 0, 0, 0, 0, 0, 0, 0x0F }; byte[] actual = value.GetBigEndianBytes(); - CollectionAssert.AreEqual(expected, actual); + Assert.That(actual, Is.EqualTo(expected).AsCollection); } [Test] @@ -32,10 +32,12 @@ internal class UInt64Tests const ulong value = 0x0F; byte[] expected = { 0x0F, 0, 0, 0, 0, 0, 0, 0 }; - Span actual = stackalloc byte[8]; - Assert.That(value.TryWriteLittleEndianBytes(actual)); - - CollectionAssert.AreEqual(expected, actual.ToArray()); + Assert.Multiple(() => + { + Span actual = stackalloc byte[8]; + Assert.That(value.TryWriteLittleEndianBytes(actual)); + Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection); + }); } [Test] @@ -44,10 +46,12 @@ internal class UInt64Tests const ulong value = 0x0F; byte[] expected = { 0, 0, 0, 0, 0, 0, 0, 0x0F }; - Span actual = stackalloc byte[8]; - Assert.That(value.TryWriteBigEndianBytes(actual)); - - CollectionAssert.AreEqual(expected, actual.ToArray()); + Assert.Multiple(() => + { + Span actual = stackalloc byte[8]; + Assert.That(value.TryWriteBigEndianBytes(actual)); + Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection); + }); } [Test] diff --git a/X10D.Tests/src/Math/IsPrimeTests.cs b/X10D.Tests/src/Math/IsPrimeTests.cs index 452a286..314bad0 100644 --- a/X10D.Tests/src/Math/IsPrimeTests.cs +++ b/X10D.Tests/src/Math/IsPrimeTests.cs @@ -142,7 +142,7 @@ internal class IsPrimeTests private static IReadOnlyList LoadPrimes() { using var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("X10D.Tests.1000primes.txt"); - Assert.IsNotNull(stream); + Assert.That(stream, Is.Not.Null); using var reader = new StreamReader(stream, Encoding.UTF8); var primes = new List(); diff --git a/X10D.Tests/src/Text/CoreTests.cs b/X10D.Tests/src/Text/CoreTests.cs index 684fa26..679164a 100644 --- a/X10D.Tests/src/Text/CoreTests.cs +++ b/X10D.Tests/src/Text/CoreTests.cs @@ -20,7 +20,11 @@ internal class CoreTests int[] source = Enumerable.Range(1, 100).ToArray(); string json = source.ToJson(); int[]? target = json.FromJson(); - CollectionAssert.AreEqual(source, target); - CollectionAssert.AreEquivalent(source, target); + + Assert.Multiple(() => + { + Assert.That(target, Is.EqualTo(source).AsCollection); + Assert.That(target, Is.EquivalentTo(source)); + }); } } diff --git a/X10D.Tests/src/Text/EnumerableTests.cs b/X10D.Tests/src/Text/EnumerableTests.cs index ab6bfd0..8fbcec2 100644 --- a/X10D.Tests/src/Text/EnumerableTests.cs +++ b/X10D.Tests/src/Text/EnumerableTests.cs @@ -10,13 +10,13 @@ internal class EnumerableTests public void Grep_ShouldFilterCorrectly_GivenPattern() { int year = DateTime.Now.Year; - var source = new[] {"Hello", "World", "String 123", $"The year is {year}"}; - var expectedResult = new[] {"String 123", $"The year is {year}"}; + var source = new[] { "Hello", "World", "String 123", $"The year is {year}" }; + var expectedResult = new[] { "String 123", $"The year is {year}" }; const string pattern = /*lang=regex*/@"[0-9]+"; string[] actualResult = source.Grep(pattern).ToArray(); - CollectionAssert.AreEqual(expectedResult, actualResult); + Assert.That(actualResult, Is.EqualTo(expectedResult).AsCollection); } [Test] @@ -28,27 +28,27 @@ internal class EnumerableTests const string pattern = /*lang=regex*/@"[0-9]+"; string[] actualResult = source.Grep(pattern).ToArray(); - CollectionAssert.AreEqual(expectedResult, actualResult); + Assert.That(actualResult, Is.EqualTo(expectedResult).AsCollection); } [Test] public void Grep_ShouldMatchUpperCase_GivenIgnoreCaseTrue() { int year = DateTime.Now.Year; - var source = new[] {"Hello", "WORLD", "String 123", $"The year is {year}"}; - var expectedResult = new[] {"WORLD"}; + var source = new[] { "Hello", "WORLD", "String 123", $"The year is {year}" }; + var expectedResult = new[] { "WORLD" }; const string pattern = /*lang=regex*/@"world"; string[] actualResult = source.Grep(pattern, true).ToArray(); - CollectionAssert.AreEqual(expectedResult, actualResult); + Assert.That(actualResult, Is.EqualTo(expectedResult).AsCollection); } [Test] public void Grep_ShouldNotMatchUpperCase_GivenIgnoreCaseFalse() { int year = DateTime.Now.Year; - var source = new[] {"Hello", "WORLD", "String 123", $"The year is {year}"}; + var source = new[] { "Hello", "WORLD", "String 123", $"The year is {year}" }; const string pattern = /*lang=regex*/@"world"; string[] actualResult = source.Grep(pattern, false).ToArray(); @@ -60,22 +60,28 @@ internal class EnumerableTests public void Grep_ShouldThrowArgumentNullException_GivenNullPattern() { IEnumerable source = Enumerable.Empty(); - Assert.Throws(() => source.Grep(null!).ToArray()); - Assert.Throws(() => source.Grep(null!, false).ToArray()); + Assert.Multiple(() => + { + Assert.Throws(() => source.Grep(null!).ToArray()); + Assert.Throws(() => source.Grep(null!, false).ToArray()); + }); } [Test] public void Grep_ShouldThrowArgumentNullException_GivenNullSource() { IEnumerable source = null!; - Assert.Throws(() => source.Grep("foo").ToArray()); - Assert.Throws(() => source.Grep("foo", false).ToArray()); + Assert.Multiple(() => + { + Assert.Throws(() => source.Grep("foo").ToArray()); + Assert.Throws(() => source.Grep("foo", false).ToArray()); + }); } [Test] public void Grep_ShouldYieldNoElements_GivenNoMatchingStrings() { - var source = new[] {"Hello", "World", "String"}; + var source = new[] { "Hello", "World", "String" }; const string pattern = /*lang=regex*/@"[0-9]+"; string[] actualResult = source.Grep(pattern).ToArray(); diff --git a/X10D.Tests/src/Text/StringBuilderReaderTests.cs b/X10D.Tests/src/Text/StringBuilderReaderTests.cs index 8575511..fc2f60f 100644 --- a/X10D.Tests/src/Text/StringBuilderReaderTests.cs +++ b/X10D.Tests/src/Text/StringBuilderReaderTests.cs @@ -22,18 +22,21 @@ internal class StringBuilderReaderTests { using var reader = new StringBuilderReader(new StringBuilder("Hello\nWorld")); - Assert.That(reader.Read(), Is.EqualTo('H')); - Assert.That(reader.Read(), Is.EqualTo('e')); - Assert.That(reader.Read(), Is.EqualTo('l')); - Assert.That(reader.Read(), Is.EqualTo('l')); - Assert.That(reader.Read(), Is.EqualTo('o')); - Assert.That(reader.Read(), Is.EqualTo('\n')); - Assert.That(reader.Read(), Is.EqualTo('W')); - Assert.That(reader.Read(), Is.EqualTo('o')); - Assert.That(reader.Read(), Is.EqualTo('r')); - Assert.That(reader.Read(), Is.EqualTo('l')); - Assert.That(reader.Read(), Is.EqualTo('d')); - Assert.That(reader.Read(), Is.EqualTo(-1)); + Assert.Multiple(() => + { + Assert.That(reader.Read(), Is.EqualTo('H')); + Assert.That(reader.Read(), Is.EqualTo('e')); + Assert.That(reader.Read(), Is.EqualTo('l')); + Assert.That(reader.Read(), Is.EqualTo('l')); + Assert.That(reader.Read(), Is.EqualTo('o')); + Assert.That(reader.Read(), Is.EqualTo('\n')); + Assert.That(reader.Read(), Is.EqualTo('W')); + Assert.That(reader.Read(), Is.EqualTo('o')); + Assert.That(reader.Read(), Is.EqualTo('r')); + Assert.That(reader.Read(), Is.EqualTo('l')); + Assert.That(reader.Read(), Is.EqualTo('d')); + Assert.That(reader.Read(), Is.EqualTo(-1)); + }); reader.Close(); } @@ -45,9 +48,12 @@ internal class StringBuilderReaderTests var array = new char[5]; int read = reader.Read(array, 0, 5); - Assert.That(read, Is.EqualTo(5)); - CollectionAssert.AreEqual("Hello".ToCharArray(), array); + Assert.Multiple(() => + { + Assert.That(read, Is.EqualTo(5)); + Assert.That(array, Is.EqualTo("Hello".ToCharArray()).AsCollection); + }); reader.Close(); } @@ -114,11 +120,14 @@ internal class StringBuilderReaderTests { using var reader = new StringBuilderReader(new StringBuilder("Hello\nWorld")); - Span span = stackalloc char[5]; - int read = reader.Read(span); - Assert.That(read, Is.EqualTo(5)); + Assert.Multiple(() => + { + Span span = stackalloc char[5]; + int read = reader.Read(span); - CollectionAssert.AreEqual("Hello".ToCharArray(), span.ToArray()); + Assert.That(read, Is.EqualTo(5)); + Assert.That(span.ToArray(), Is.EqualTo("Hello".ToCharArray()).AsCollection); + }); reader.Close(); } @@ -130,9 +139,12 @@ internal class StringBuilderReaderTests var array = new char[5]; int read = reader.ReadAsync(array, 0, 5).GetAwaiter().GetResult(); - Assert.That(read, Is.EqualTo(5)); - CollectionAssert.AreEqual("Hello".ToCharArray(), array); + Assert.Multiple(() => + { + Assert.That(read, Is.EqualTo(5)); + Assert.That(array, Is.EqualTo("Hello".ToCharArray()).AsCollection); + }); reader.Close(); } @@ -144,9 +156,12 @@ internal class StringBuilderReaderTests Memory memory = new char[5]; int read = reader.ReadAsync(memory).GetAwaiter().GetResult(); - Assert.That(read, Is.EqualTo(5)); - CollectionAssert.AreEqual("Hello".ToCharArray(), memory.ToArray()); + Assert.Multiple(() => + { + Assert.That(read, Is.EqualTo(5)); + Assert.That(memory.ToArray(), Is.EqualTo("Hello".ToCharArray()).AsCollection); + }); reader.Close(); } @@ -158,9 +173,12 @@ internal class StringBuilderReaderTests var array = new char[5]; int read = reader.ReadBlock(array, 0, 5); - Assert.That(read, Is.EqualTo(5)); - CollectionAssert.AreEqual("Hello".ToCharArray(), array); + Assert.Multiple(() => + { + Assert.That(read, Is.EqualTo(5)); + Assert.That(array, Is.EqualTo("Hello".ToCharArray()).AsCollection); + }); reader.Close(); } @@ -170,11 +188,14 @@ internal class StringBuilderReaderTests { using var reader = new StringBuilderReader(new StringBuilder("Hello\nWorld")); - Span span = stackalloc char[5]; - int read = reader.ReadBlock(span); - Assert.That(read, Is.EqualTo(5)); + Assert.Multiple(() => + { + Span span = stackalloc char[5]; + int read = reader.ReadBlock(span); - CollectionAssert.AreEqual("Hello".ToCharArray(), span.ToArray()); + Assert.That(read, Is.EqualTo(5)); + Assert.That(span.ToArray(), Is.EqualTo("Hello".ToCharArray()).AsCollection); + }); reader.Close(); } @@ -200,9 +221,12 @@ internal class StringBuilderReaderTests var array = new char[5]; int read = reader.ReadBlockAsync(array, 0, 5).GetAwaiter().GetResult(); - Assert.That(read, Is.EqualTo(5)); - CollectionAssert.AreEqual("Hello".ToCharArray(), array); + Assert.Multiple(() => + { + Assert.That(read, Is.EqualTo(5)); + Assert.That(array, Is.EqualTo("Hello".ToCharArray()).AsCollection); + }); reader.Close(); } @@ -214,9 +238,12 @@ internal class StringBuilderReaderTests Memory memory = new char[5]; int read = reader.ReadBlockAsync(memory).GetAwaiter().GetResult(); - Assert.That(read, Is.EqualTo(5)); - CollectionAssert.AreEqual("Hello".ToCharArray(), memory.ToArray()); + Assert.Multiple(() => + { + Assert.That(read, Is.EqualTo(5)); + Assert.That(memory.ToArray(), Is.EqualTo("Hello".ToCharArray()).AsCollection); + }); reader.Close(); } diff --git a/X10D.Tests/src/Text/StringTests.cs b/X10D.Tests/src/Text/StringTests.cs index d658b72..5c0afe1 100644 --- a/X10D.Tests/src/Text/StringTests.cs +++ b/X10D.Tests/src/Text/StringTests.cs @@ -423,7 +423,7 @@ internal class StringTests var target = json.FromJson(); Assert.Multiple(() => { - Assert.IsInstanceOf(target); + Assert.That(target, Is.InstanceOf()); Assert.That(target.Values, Is.Not.Null); Assert.That(target.Values.Length, Is.EqualTo(3)); Assert.That(target.Values[0], Is.EqualTo(1)); @@ -438,7 +438,7 @@ internal class StringTests var expected = new byte[] { 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64 }; byte[] actual = "Hello World".GetBytes(); - CollectionAssert.AreEqual(expected, actual); + Assert.That(actual, Is.EqualTo(expected).AsCollection); } [Test] @@ -447,7 +447,7 @@ internal class StringTests var expected = new byte[] { 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64 }; byte[] actual = "Hello World".GetBytes(Encoding.ASCII); - CollectionAssert.AreEqual(expected, actual); + Assert.That(actual, Is.EqualTo(expected).AsCollection); } [Test] @@ -1004,7 +1004,6 @@ internal class StringTests private struct SampleStructure { - [JsonPropertyName("values")] - public int[] Values { get; set; } + [JsonPropertyName("values")] public int[] Values { get; set; } } }