1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-22 02:58:47 +00:00

fix(test): use new NUnit constraint API

This commit is contained in:
Oliver Booth 2024-11-13 18:41:45 +00:00
parent 0b978f5cdf
commit a433244799
Signed by: oliverbooth
GPG Key ID: 2A862C3F46178E8E
36 changed files with 457 additions and 312 deletions

View File

@ -117,11 +117,11 @@ internal partial class EnumerableTests
IEnumerable<DummyClass> source = oneToTen.Select(i => new DummyClass {Value = i}).ToArray(); IEnumerable<DummyClass> source = oneToTen.Select(i => new DummyClass {Value = i}).ToArray();
IEnumerable<int> values = source.Select(o => o.Value); IEnumerable<int> 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); source.For((i, o) => o.Value *= i);
values = source.Select(o => o.Value); values = source.Select(o => o.Value);
CollectionAssert.AreEqual(multipliedByIndex, values.ToArray()); Assert.That(values.ToArray(), Is.EqualTo(multipliedByIndex).AsCollection);
} }
[Test] [Test]
@ -146,11 +146,11 @@ internal partial class EnumerableTests
IEnumerable<DummyClass> source = oneToTen.Select(i => new DummyClass {Value = i}).ToArray(); IEnumerable<DummyClass> source = oneToTen.Select(i => new DummyClass {Value = i}).ToArray();
IEnumerable<int> values = source.Select(o => o.Value); IEnumerable<int> 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); source.ForEach(o => o.Value *= 2);
values = source.Select(o => o.Value); values = source.Select(o => o.Value);
CollectionAssert.AreEqual(oneToTenDoubled, values.ToArray()); Assert.That(values.ToArray(), Is.EqualTo(oneToTenDoubled).AsCollection);
} }
[Test] [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[] array = Enumerable.Range(1, 52).ToArray(); // 52! chance of being shuffled to the same order
int[] shuffled = array[..]; int[] shuffled = array[..];
CollectionAssert.AreEqual(array, shuffled); Assert.That(shuffled, Is.EqualTo(array).AsCollection);
shuffled = array.Shuffled().ToArray(); shuffled = array.Shuffled().ToArray();
CollectionAssert.AreNotEqual(array, shuffled); Assert.That(shuffled, Is.Not.EqualTo(array).AsCollection);
} }
[Test] [Test]
@ -256,7 +256,7 @@ internal partial class EnumerableTests
{ {
var enumerable = new[] {2, 4, 6, 7, 8, 9, 10}; var enumerable = new[] {2, 4, 6, 7, 8, 9, 10};
IEnumerable<int> result = enumerable.WhereNot(x => x % 2 == 0); IEnumerable<int> 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] [Test]
@ -285,7 +285,7 @@ internal partial class EnumerableTests
foreach (object o in array.WhereNotNull()) foreach (object o in array.WhereNotNull())
{ {
Assert.IsNotNull(o); Assert.That(o, Is.Not.Null);
actualCount++; actualCount++;
} }

View File

@ -6,7 +6,7 @@ namespace X10D.Tests.Collections;
[TestFixture] [TestFixture]
internal class ListTests internal class ListTests
{ {
[Test] [Test]
[TestCase(1)] [TestCase(1)]
[TestCase(1, 2, 3)] [TestCase(1, 2, 3)]
[TestCase(1, 2, 3, 4, 5)] [TestCase(1, 2, 3, 4, 5)]
@ -15,17 +15,17 @@ internal class ListTests
int[] all42 = Enumerable.Repeat(42, args.Length).ToArray(); int[] all42 = Enumerable.Repeat(42, args.Length).ToArray();
var list = new List<int>(args); var list = new List<int>(args);
CollectionAssert.AreEqual(args, list); Assert.That(list, Is.EqualTo(args).AsCollection);
args.Fill(42); args.Fill(42);
list.Fill(42); list.Fill(42);
CollectionAssert.AreEqual(args, list); Assert.That(list, Is.EqualTo(args).AsCollection);
CollectionAssert.AreEqual(all42, args); Assert.That(args, Is.EqualTo(all42).AsCollection);
CollectionAssert.AreEqual(all42, list); Assert.That(list, Is.EqualTo(all42).AsCollection);
} }
[Test] [Test]
[TestCase(1)] [TestCase(1)]
[TestCase(1, 2, 3)] [TestCase(1, 2, 3)]
[TestCase(1, 2, 3, 4, 5)] [TestCase(1, 2, 3, 4, 5)]
@ -36,7 +36,7 @@ internal class ListTests
int[] comparison = Enumerable.Repeat(1, args.Length - 1).ToArray(); int[] comparison = Enumerable.Repeat(1, args.Length - 1).ToArray();
Assert.That(args[0], Is.EqualTo(first)); Assert.That(args[0], Is.EqualTo(first));
CollectionAssert.AreEqual(comparison, args[1..]); Assert.That(args[1..], Is.EqualTo(comparison).AsCollection);
} }
[Test] [Test]
@ -80,7 +80,7 @@ internal class ListTests
[Test] [Test]
public void IndexOf_ShouldReturnCorrectValue_FromStartOfList() public void IndexOf_ShouldReturnCorrectValue_FromStartOfList()
{ {
int[] array = {0, 1, 2, 3, 4}; int[] array = { 0, 1, 2, 3, 4 };
Assert.Multiple(() => Assert.Multiple(() =>
{ {
Assert.That(array.IndexOf(2), Is.EqualTo(2)); Assert.That(array.IndexOf(2), Is.EqualTo(2));
@ -92,7 +92,7 @@ internal class ListTests
[Test] [Test]
public void IndexOf_ShouldReturnCorrectValue_GivenSubRange() public void IndexOf_ShouldReturnCorrectValue_GivenSubRange()
{ {
int[] array = {0, 1, 2, 3, 4, 0}; int[] array = { 0, 1, 2, 3, 4, 0 };
Assert.Multiple(() => Assert.Multiple(() =>
{ {
Assert.That(array.IndexOf(0), Is.Zero); Assert.That(array.IndexOf(0), Is.Zero);
@ -149,7 +149,7 @@ internal class ListTests
[Test] [Test]
public void IndexOf_ShouldThrowArgumentOutOfRangeException_GivenInvalidStartIndexCountPair() public void IndexOf_ShouldThrowArgumentOutOfRangeException_GivenInvalidStartIndexCountPair()
{ {
int[] array = {0, 1, 2}; int[] array = { 0, 1, 2 };
Assert.Throws<ArgumentOutOfRangeException>(() => array.IndexOf(0, 2, 4)); Assert.Throws<ArgumentOutOfRangeException>(() => array.IndexOf(0, 2, 4));
} }
@ -184,7 +184,7 @@ internal class ListTests
public void RemoveRange_ShouldThrowArgumentOutOfRangeException_GivenEndIndexGreaterThanOrEqualToCount() public void RemoveRange_ShouldThrowArgumentOutOfRangeException_GivenEndIndexGreaterThanOrEqualToCount()
{ {
Assert.Throws<ArgumentOutOfRangeException>(() => new List<int>().RemoveRange(..0)); Assert.Throws<ArgumentOutOfRangeException>(() => new List<int>().RemoveRange(..0));
Assert.Throws<ArgumentOutOfRangeException>(() => new List<int> {1}.RemoveRange(..2)); Assert.Throws<ArgumentOutOfRangeException>(() => new List<int> { 1 }.RemoveRange(..2));
} }
[Test] [Test]
@ -208,7 +208,7 @@ internal class ListTests
list.RemoveRange(2..5); list.RemoveRange(2..5);
Assert.That(list, Has.Count.EqualTo(6)); 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] [Test]
@ -217,11 +217,11 @@ internal class ListTests
var list = new List<int>(Enumerable.Range(1, 52)); // 52! chance of being shuffled to the same order var list = new List<int>(Enumerable.Range(1, 52)); // 52! chance of being shuffled to the same order
var shuffled = new List<int>(list); var shuffled = new List<int>(list);
CollectionAssert.AreEqual(list, shuffled); Assert.That(shuffled, Is.EqualTo(list).AsCollection);
shuffled.Shuffle(); shuffled.Shuffle();
CollectionAssert.AreNotEqual(list, shuffled); Assert.That(shuffled, Is.Not.EqualTo(list).AsCollection);
} }
[Test] [Test]
@ -233,23 +233,23 @@ internal class ListTests
[Test] [Test]
public void Slice_ShouldReturnCorrectValue_GivenStartIndex() public void Slice_ShouldReturnCorrectValue_GivenStartIndex()
{ {
int[] array = {0, 1, 2, 3, 4, 5}; int[] array = { 0, 1, 2, 3, 4, 5 };
CollectionAssert.AreEqual(new[] {2, 3, 4, 5}, array.Slice(2).ToArray()); Assert.That(array.Slice(2).ToArray(), Is.EqualTo(new[] { 2, 3, 4, 5 }).AsCollection);
} }
[Test] [Test]
public void Slice_ShouldReturnCorrectValue_GivenStartIndexAndLength() public void Slice_ShouldReturnCorrectValue_GivenStartIndexAndLength()
{ {
int[] array = {0, 1, 2, 3, 4, 5}; int[] array = { 0, 1, 2, 3, 4, 5 };
CollectionAssert.AreEqual(new[] {2, 3, 4}, array.Slice(2, 3).ToArray()); Assert.That(array.Slice(2, 3).ToArray(), Is.EqualTo(new[] { 2, 3, 4 }).AsCollection);
} }
[Test] [Test]
public void Slice_ShouldReturnEmptyList_ForEmptyList() public void Slice_ShouldReturnEmptyList_ForEmptyList()
{ {
int[] array = Array.Empty<int>(); int[] array = Array.Empty<int>();
CollectionAssert.AreEqual(Array.Empty<int>(), array.Slice(0).ToArray()); Assert.That(array.Slice(0).ToArray(), Is.EqualTo(Array.Empty<int>()).AsCollection);
CollectionAssert.AreEqual(Array.Empty<int>(), array.Slice(0, 0).ToArray()); Assert.That(array.Slice(0, 0).ToArray(), Is.EqualTo(Array.Empty<int>()).AsCollection);
} }
[Test] [Test]
@ -278,7 +278,7 @@ internal class ListTests
[Test] [Test]
public void Slice_ShouldThrowArgumentOutOfRangeException_GivenInvalidStartIndexCountPair() public void Slice_ShouldThrowArgumentOutOfRangeException_GivenInvalidStartIndexCountPair()
{ {
int[] array = {0, 1, 2}; int[] array = { 0, 1, 2 };
Assert.Throws<ArgumentOutOfRangeException>(() => array.Slice(2, 4)); Assert.Throws<ArgumentOutOfRangeException>(() => array.Slice(2, 4));
} }
@ -297,18 +297,18 @@ internal class ListTests
[Test] [Test]
public void Swap_ShouldSwapElements_GivenMatchingElementCount() public void Swap_ShouldSwapElements_GivenMatchingElementCount()
{ {
var first = new List<int> {1, 2, 3}; var first = new List<int> { 1, 2, 3 };
var second = new List<int> {4, 5, 6}; var second = new List<int> { 4, 5, 6 };
first.Swap(second); first.Swap(second);
CollectionAssert.AreEqual(new[] {4, 5, 6}, first, string.Join(' ', first)); Assert.That(first, Is.EqualTo(new[] { 4, 5, 6 }).AsCollection, string.Join(' ', first));
CollectionAssert.AreEqual(new[] {1, 2, 3}, second, string.Join(' ', second)); Assert.That(second, Is.EqualTo(new[] { 1, 2, 3 }).AsCollection, string.Join(' ', second));
first.Swap(second); first.Swap(second);
CollectionAssert.AreEqual(new[] {1, 2, 3}, first, string.Join(' ', first)); Assert.That(first, Is.EqualTo(new[] { 1, 2, 3 }).AsCollection, string.Join(' ', first));
CollectionAssert.AreEqual(new[] {4, 5, 6}, second, string.Join(' ', second)); Assert.That(second, Is.EqualTo(new[] { 4, 5, 6 }).AsCollection, string.Join(' ', second));
} }
[Test] [Test]
@ -322,16 +322,16 @@ internal class ListTests
4, 4,
5 5
}; };
var second = new List<int> {6, 7}; var second = new List<int> { 6, 7 };
first.Swap(second); first.Swap(second);
CollectionAssert.AreEqual(new[] {6, 7}, first, string.Join(' ', first)); Assert.That(first, Is.EqualTo(new[] { 6, 7 }).AsCollection, string.Join(' ', first));
CollectionAssert.AreEqual(new[] {1, 2, 3, 4, 5}, second, string.Join(' ', second)); Assert.That(second, Is.EqualTo(new[] { 1, 2, 3, 4, 5 }).AsCollection, string.Join(' ', second));
first.Swap(second); first.Swap(second);
CollectionAssert.AreEqual(new[] {1, 2, 3, 4, 5}, first, string.Join(' ', first)); Assert.That(first, Is.EqualTo(new[] { 1, 2, 3, 4, 5 }).AsCollection, string.Join(' ', first));
CollectionAssert.AreEqual(new[] {6, 7}, second, string.Join(' ', second)); Assert.That(second, Is.EqualTo(new[] { 6, 7 }).AsCollection, string.Join(' ', second));
} }
} }

View File

@ -31,7 +31,7 @@ internal class SpanTest
[Test] [Test]
public void Count_ShouldReturn8_GivenSpanWith8MatchingElements() public void Count_ShouldReturn8_GivenSpanWith8MatchingElements()
{ {
Span<int> span = stackalloc int[16] {1, 2, 3, 2, 5, 2, 7, 2, 9, 2, 11, 2, 13, 2, 15, 2}; Span<int> 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); int count = span.Count(2);
@ -41,7 +41,7 @@ internal class SpanTest
[Test] [Test]
public void Count_ShouldReturn8_GivenReadOnlySpanWith8MatchingElements() public void Count_ShouldReturn8_GivenReadOnlySpanWith8MatchingElements()
{ {
ReadOnlySpan<int> span = stackalloc int[16] {1, 2, 3, 2, 5, 2, 7, 2, 9, 2, 11, 2, 13, 2, 15, 2}; ReadOnlySpan<int> 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); int count = span.Count(2);
@ -51,25 +51,25 @@ internal class SpanTest
[Test] [Test]
public void Replace_ShouldReplaceAllElements_GivenSpanOfInt32() public void Replace_ShouldReplaceAllElements_GivenSpanOfInt32()
{ {
Span<int> span = stackalloc int[16] {1, 2, 3, 2, 5, 2, 7, 2, 9, 2, 11, 2, 13, 2, 15, 2}; Span<int> span = stackalloc int[16] { 1, 2, 3, 2, 5, 2, 7, 2, 9, 2, 11, 2, 13, 2, 15, 2 };
span.Replace(2, 4); 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] [Test]
public void Replace_ShouldReplaceAllElements_GivenSpanOfChar() public void Replace_ShouldReplaceAllElements_GivenSpanOfChar()
{ {
Span<char> chars = stackalloc char[12] {'H', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!'}; Span<char> chars = stackalloc char[12] { 'H', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!' };
chars.Replace('l', 'w'); chars.Replace('l', 'w');
CollectionAssert.AreEqual(chars.ToArray(), "Hewwo worwd!".ToCharArray()); Assert.That("Hewwo worwd!".ToCharArray(), Is.EqualTo(chars.ToArray()).AsCollection);
} }
[Test] [Test]
public void Replace_ShouldDoNothing_GivenSpanWithNoMatchingElements() public void Replace_ShouldDoNothing_GivenSpanWithNoMatchingElements()
{ {
Span<int> span = stackalloc int[16] {1, 2, 3, 2, 5, 2, 7, 2, 9, 2, 11, 2, 13, 2, 15, 2}; Span<int> span = stackalloc int[16] { 1, 2, 3, 2, 5, 2, 7, 2, 9, 2, 11, 2, 13, 2, 15, 2 };
span.Replace(4, 8); 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 #if !NET9_0_OR_GREATER

View File

@ -63,7 +63,7 @@ internal class CoreTests
// ReSharper disable once PossibleMultipleEnumeration // ReSharper disable once PossibleMultipleEnumeration
object[] array = enumerable.ToArray(); object[] array = enumerable.ToArray();
Assert.That(array, Has.Length.EqualTo(10)); 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] [Test]

View File

@ -1,4 +1,3 @@
using System.Runtime.Intrinsics.Arm;
using System.Runtime.Intrinsics.X86; using System.Runtime.Intrinsics.X86;
using NUnit.Framework; using NUnit.Framework;
using X10D.Core; using X10D.Core;

View File

@ -85,7 +85,7 @@ internal class PolygonFTests
// we cannot use CollectionAssert here for reasons I am not entirely sure of. // we cannot use CollectionAssert here for reasons I am not entirely sure of.
// it seems to dislike casting from IReadOnlyList<Point> to ICollection. but okay. // it seems to dislike casting from IReadOnlyList<Point> 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 the empty polygon was not modified
Assert.That(PolygonF.Empty.VertexCount, Is.Zero); Assert.That(PolygonF.Empty.VertexCount, Is.Zero);
@ -178,7 +178,7 @@ internal class PolygonFTests
Assert.That(converted, Is.EqualTo((Polygon)polygon)); Assert.That(converted, Is.EqualTo((Polygon)polygon));
Assert.That(converted.IsConvex, Is.EqualTo(polygon.IsConvex)); Assert.That(converted.IsConvex, Is.EqualTo(polygon.IsConvex));
Assert.That(converted.VertexCount, Is.EqualTo(polygon.VertexCount)); 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 == polygon);
Assert.That(converted.IsConvex, Is.EqualTo(polygon.IsConvex)); Assert.That(converted.IsConvex, Is.EqualTo(polygon.IsConvex));
Assert.That(converted.VertexCount, Is.EqualTo(polygon.VertexCount)); 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);
}); });
} }

View File

@ -75,7 +75,7 @@ internal class PolyhedronTests
// we cannot use CollectionAssert here for reasons I am not entirely sure of. // we cannot use CollectionAssert here for reasons I am not entirely sure of.
// it seems to dislike casting from IReadOnlyList<Point> to ICollection. but okay. // it seems to dislike casting from IReadOnlyList<Point> 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 the empty polyhedron was not modified
Assert.That(Polyhedron.Empty.VertexCount, Is.Zero); Assert.That(Polyhedron.Empty.VertexCount, Is.Zero);
@ -148,11 +148,11 @@ internal class PolyhedronTests
Assert.That(converted, Is.EqualTo((Polyhedron)polygon)); Assert.That(converted, Is.EqualTo((Polyhedron)polygon));
Assert.That(converted.VertexCount, Is.EqualTo(polygon.VertexCount)); 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(); var point = p.ToVector2();
return new Vector3(point.X, point.Y, 0); 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, Is.EqualTo((Polyhedron)polygon));
Assert.That(converted.VertexCount, Is.EqualTo(polygon.VertexCount)); 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(); var point = p.ToVector2();
return new Vector3(point.X, point.Y, 0); return new Vector3(point.X, point.Y, 0);
})); })).AsCollection);
}); });
} }

View File

@ -23,8 +23,8 @@ internal class ServiceCollectionTests
{ {
Assert.That(service, Is.Not.Null); Assert.That(service, Is.Not.Null);
Assert.That(hostedService, Is.Not.Null); Assert.That(hostedService, Is.Not.Null);
Assert.IsAssignableFrom<TestService>(service); Assert.That(service, Is.AssignableFrom<TestService>());
Assert.IsAssignableFrom<TestService>(hostedService); Assert.That(hostedService, Is.AssignableFrom<TestService>());
Assert.That(hostedService, Is.SameAs(service)); Assert.That(hostedService, Is.SameAs(service));
}); });
} }
@ -44,8 +44,8 @@ internal class ServiceCollectionTests
{ {
Assert.That(service, Is.Not.Null); Assert.That(service, Is.Not.Null);
Assert.That(hostedService, Is.Not.Null); Assert.That(hostedService, Is.Not.Null);
Assert.IsAssignableFrom<TestService>(service); Assert.That(service, Is.AssignableFrom<TestService>());
Assert.IsAssignableFrom<TestService>(hostedService); Assert.That(hostedService, Is.AssignableFrom<TestService>());
Assert.That(hostedService, Is.SameAs(service)); Assert.That(hostedService, Is.SameAs(service));
}); });
} }
@ -65,8 +65,8 @@ internal class ServiceCollectionTests
{ {
Assert.That(service, Is.Not.Null); Assert.That(service, Is.Not.Null);
Assert.That(hostedService, Is.Not.Null); Assert.That(hostedService, Is.Not.Null);
Assert.IsAssignableFrom<TestService>(service); Assert.That(service, Is.AssignableFrom<TestService>());
Assert.IsAssignableFrom<TestService>(hostedService); Assert.That(hostedService, Is.AssignableFrom<TestService>());
Assert.That(hostedService, Is.SameAs(service)); Assert.That(hostedService, Is.SameAs(service));
}); });
} }
@ -86,8 +86,8 @@ internal class ServiceCollectionTests
{ {
Assert.That(service, Is.Not.Null); Assert.That(service, Is.Not.Null);
Assert.That(hostedService, Is.Not.Null); Assert.That(hostedService, Is.Not.Null);
Assert.IsAssignableFrom<TestService>(service); Assert.That(service, Is.AssignableFrom<TestService>());
Assert.IsAssignableFrom<TestService>(hostedService); Assert.That(hostedService, Is.AssignableFrom<TestService>());
Assert.That(hostedService, Is.SameAs(service)); Assert.That(hostedService, Is.SameAs(service));
}); });
} }

View File

@ -10,7 +10,7 @@ internal class BooleanTests
public void GetBytes_ReturnsArrayContaining1() public void GetBytes_ReturnsArrayContaining1()
{ {
const bool value = true; const bool value = true;
CollectionAssert.AreEqual(new byte[] {1}, value.GetBytes()); Assert.That(value.GetBytes(), Is.EqualTo(new byte[] { 1 }).AsCollection);
} }
[Test] [Test]
@ -19,7 +19,7 @@ internal class BooleanTests
const bool value = true; const bool value = true;
Span<byte> buffer = stackalloc byte[1]; Span<byte> buffer = stackalloc byte[1];
Assert.That(value.TryWriteBytes(buffer)); Assert.That(value.TryWriteBytes(buffer));
CollectionAssert.AreEqual(new byte[] {1}, buffer.ToArray()); Assert.That(buffer.ToArray(), Is.EqualTo(new byte[] { 1 }).AsCollection);
} }
[Test] [Test]

View File

@ -10,16 +10,19 @@ internal class ByteTests
public void GetBytes_ReturnsArrayContainingItself() public void GetBytes_ReturnsArrayContainingItself()
{ {
const byte value = 0xFF; const byte value = 0xFF;
CollectionAssert.AreEqual(new[] {value}, value.GetBytes()); Assert.That(value.GetBytes(), Is.EqualTo(new[] { value }).AsCollection);
} }
[Test] [Test]
public void TryWriteBytes_ReturnsTrue_FillsSpanContainingItself_GivenLargeEnoughSpan() public void TryWriteBytes_ReturnsTrue_FillsSpanContainingItself_GivenLargeEnoughSpan()
{ {
const byte value = 0xFF; const byte value = 0xFF;
Span<byte> buffer = stackalloc byte[1]; Assert.Multiple(() =>
Assert.That(value.TryWriteBytes(buffer)); {
CollectionAssert.AreEqual(new[] {value}, buffer.ToArray()); Span<byte> buffer = stackalloc byte[1];
Assert.That(value.TryWriteBytes(buffer));
Assert.That(buffer.ToArray(), Is.EqualTo(new[] { value }).AsCollection);
});
} }
[Test] [Test]

View File

@ -14,7 +14,7 @@ internal class DecimalTests
byte[] bytes = value.GetBigEndianBytes(); byte[] bytes = value.GetBigEndianBytes();
CollectionAssert.AreEqual(expected, bytes); Assert.That(bytes, Is.EqualTo(expected).AsCollection);
} }
[Test] [Test]
@ -25,7 +25,7 @@ internal class DecimalTests
byte[] bytes = value.GetLittleEndianBytes(); byte[] bytes = value.GetLittleEndianBytes();
CollectionAssert.AreEqual(expected, bytes); Assert.That(bytes, Is.EqualTo(expected).AsCollection);
} }
[Test] [Test]
@ -34,10 +34,12 @@ internal class DecimalTests
const decimal value = 1234m; const decimal value = 1234m;
byte[] expected = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 210]; byte[] expected = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 210];
Span<byte> bytes = stackalloc byte[16]; Assert.Multiple(() =>
Assert.That(value.TryWriteBigEndianBytes(bytes)); {
Span<byte> bytes = stackalloc byte[16];
CollectionAssert.AreEqual(expected, bytes.ToArray()); Assert.That(value.TryWriteBigEndianBytes(bytes));
Assert.That(bytes.ToArray(), Is.EqualTo(expected).AsCollection);
});
} }
[Test] [Test]
@ -46,10 +48,12 @@ internal class DecimalTests
const decimal value = 1234m; const decimal value = 1234m;
byte[] expected = [210, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; byte[] expected = [210, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
Span<byte> bytes = stackalloc byte[16]; Assert.Multiple(() =>
Assert.That(value.TryWriteLittleEndianBytes(bytes)); {
Span<byte> bytes = stackalloc byte[16];
CollectionAssert.AreEqual(expected, bytes.ToArray()); Assert.That(value.TryWriteLittleEndianBytes(bytes));
Assert.That(bytes.ToArray(), Is.EqualTo(expected).AsCollection);
});
} }
[Test] [Test]

View File

@ -13,7 +13,7 @@ internal class DoubleTests
var expected = new byte[] { 0x40, 0x45, 0x40, 0, 0, 0, 0, 0 }; var expected = new byte[] { 0x40, 0x45, 0x40, 0, 0, 0, 0, 0 };
byte[] actual = value.GetBigEndianBytes(); byte[] actual = value.GetBigEndianBytes();
CollectionAssert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected).AsCollection);
} }
[Test] [Test]
@ -23,7 +23,7 @@ internal class DoubleTests
var expected = new byte[] { 0, 0, 0, 0, 0, 0x40, 0x45, 0x40 }; var expected = new byte[] { 0, 0, 0, 0, 0, 0x40, 0x45, 0x40 };
byte[] actual = value.GetLittleEndianBytes(); byte[] actual = value.GetLittleEndianBytes();
CollectionAssert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected).AsCollection);
} }
[Test] [Test]
@ -32,9 +32,12 @@ internal class DoubleTests
const double value = 42.5; const double value = 42.5;
var expected = new byte[] { 0x40, 0x45, 0x40, 0, 0, 0, 0, 0 }; var expected = new byte[] { 0x40, 0x45, 0x40, 0, 0, 0, 0, 0 };
Span<byte> actual = stackalloc byte[8]; Assert.Multiple(() =>
Assert.That(value.TryWriteBigEndianBytes(actual)); {
CollectionAssert.AreEqual(expected, actual.ToArray()); Span<byte> actual = stackalloc byte[8];
Assert.That(value.TryWriteBigEndianBytes(actual));
Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection);
});
} }
[Test] [Test]
@ -43,9 +46,12 @@ internal class DoubleTests
const double value = 42.5; const double value = 42.5;
var expected = new byte[] { 0, 0, 0, 0, 0, 0x40, 0x45, 0x40 }; var expected = new byte[] { 0, 0, 0, 0, 0, 0x40, 0x45, 0x40 };
Span<byte> actual = stackalloc byte[8]; Assert.Multiple(() =>
Assert.That(value.TryWriteLittleEndianBytes(actual)); {
CollectionAssert.AreEqual(expected, actual.ToArray()); Span<byte> actual = stackalloc byte[8];
Assert.That(value.TryWriteLittleEndianBytes(actual));
Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection);
});
} }
[Test] [Test]

View File

@ -29,7 +29,7 @@ internal class FileInfoTests
try try
{ {
byte[] hash = new FileInfo(fileName).GetHash<SHA1>(); byte[] hash = new FileInfo(fileName).GetHash<SHA1>();
CollectionAssert.AreEqual(expectedHash, hash); Assert.That(hash, Is.EqualTo(expectedHash).AsCollection);
} }
finally finally
{ {
@ -58,10 +58,14 @@ internal class FileInfoTests
try try
{ {
Span<byte> hash = stackalloc byte[20]; Assert.Multiple(() =>
new FileInfo(fileName).TryWriteHash<SHA1>(hash, out int bytesWritten); {
Assert.That(bytesWritten, Is.EqualTo(expectedHash.Length)); Span<byte> hash = stackalloc byte[20];
CollectionAssert.AreEqual(expectedHash, hash.ToArray()); new FileInfo(fileName).TryWriteHash<SHA1>(hash, out int bytesWritten);
Assert.That(bytesWritten, Is.EqualTo(expectedHash.Length));
Assert.That(hash.ToArray(), Is.EqualTo(expectedHash).AsCollection);
});
} }
finally finally
{ {

View File

@ -13,7 +13,7 @@ internal class Int16Tests
byte[] expected = { 0x0F, 0 }; byte[] expected = { 0x0F, 0 };
byte[] actual = value.GetLittleEndianBytes(); byte[] actual = value.GetLittleEndianBytes();
CollectionAssert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected).AsCollection);
} }
[Test] [Test]
@ -23,7 +23,7 @@ internal class Int16Tests
byte[] expected = { 0, 0x0F }; byte[] expected = { 0, 0x0F };
byte[] actual = value.GetBigEndianBytes(); byte[] actual = value.GetBigEndianBytes();
CollectionAssert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected).AsCollection);
} }
[Test] [Test]
@ -32,9 +32,12 @@ internal class Int16Tests
const short value = 0x0F; const short value = 0x0F;
byte[] expected = { 0x0F, 0 }; byte[] expected = { 0x0F, 0 };
Span<byte> actual = stackalloc byte[2]; Assert.Multiple(() =>
Assert.That(value.TryWriteLittleEndianBytes(actual)); {
CollectionAssert.AreEqual(expected, actual.ToArray()); Span<byte> actual = stackalloc byte[2];
Assert.That(value.TryWriteLittleEndianBytes(actual));
Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection);
});
} }
[Test] [Test]
@ -43,9 +46,12 @@ internal class Int16Tests
const short value = 0x0F; const short value = 0x0F;
byte[] expected = { 0, 0x0F }; byte[] expected = { 0, 0x0F };
Span<byte> actual = stackalloc byte[2]; Assert.Multiple(() =>
Assert.That(value.TryWriteBigEndianBytes(actual)); {
CollectionAssert.AreEqual(expected, actual.ToArray()); Span<byte> actual = stackalloc byte[2];
Assert.That(value.TryWriteBigEndianBytes(actual));
Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection);
});
} }
[Test] [Test]

View File

@ -13,7 +13,7 @@ internal class Int32Tests
var expected = new byte[] { 0, 0, 0, 0x0F }; var expected = new byte[] { 0, 0, 0, 0x0F };
byte[] actual = value.GetBigEndianBytes(); byte[] actual = value.GetBigEndianBytes();
CollectionAssert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected).AsCollection);
} }
[Test] [Test]
@ -23,7 +23,7 @@ internal class Int32Tests
var expected = new byte[] { 0x0F, 0, 0, 0 }; var expected = new byte[] { 0x0F, 0, 0, 0 };
byte[] actual = value.GetLittleEndianBytes(); byte[] actual = value.GetLittleEndianBytes();
CollectionAssert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected).AsCollection);
} }
[Test] [Test]
@ -32,9 +32,12 @@ internal class Int32Tests
const int value = 0x0F; const int value = 0x0F;
var expected = new byte[] { 0, 0, 0, 0x0F }; var expected = new byte[] { 0, 0, 0, 0x0F };
Span<byte> actual = stackalloc byte[4]; Assert.Multiple(() =>
Assert.That(value.TryWriteBigEndianBytes(actual)); {
CollectionAssert.AreEqual(expected, actual.ToArray()); Span<byte> actual = stackalloc byte[4];
Assert.That(value.TryWriteBigEndianBytes(actual));
Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection);
});
} }
[Test] [Test]
@ -43,9 +46,12 @@ internal class Int32Tests
const int value = 0x0F; const int value = 0x0F;
var expected = new byte[] { 0x0F, 0, 0, 0 }; var expected = new byte[] { 0x0F, 0, 0, 0 };
Span<byte> actual = stackalloc byte[4]; Assert.Multiple(() =>
Assert.That(value.TryWriteLittleEndianBytes(actual)); {
CollectionAssert.AreEqual(expected, actual.ToArray()); Span<byte> actual = stackalloc byte[4];
Assert.That(value.TryWriteLittleEndianBytes(actual));
Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection);
});
} }
[Test] [Test]

View File

@ -13,7 +13,7 @@ internal class Int64Tests
byte[] expected = { 0x0F, 0, 0, 0, 0, 0, 0, 0 }; byte[] expected = { 0x0F, 0, 0, 0, 0, 0, 0, 0 };
byte[] actual = value.GetLittleEndianBytes(); byte[] actual = value.GetLittleEndianBytes();
CollectionAssert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected).AsCollection);
} }
[Test] [Test]
@ -23,7 +23,7 @@ internal class Int64Tests
byte[] expected = { 0, 0, 0, 0, 0, 0, 0, 0x0F }; byte[] expected = { 0, 0, 0, 0, 0, 0, 0, 0x0F };
byte[] actual = value.GetBigEndianBytes(); byte[] actual = value.GetBigEndianBytes();
CollectionAssert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected).AsCollection);
} }
[Test] [Test]
@ -32,9 +32,12 @@ internal class Int64Tests
const long value = 0x0F; const long value = 0x0F;
byte[] expected = { 0x0F, 0, 0, 0, 0, 0, 0, 0 }; byte[] expected = { 0x0F, 0, 0, 0, 0, 0, 0, 0 };
Span<byte> actual = stackalloc byte[8]; Assert.Multiple(() =>
Assert.That(value.TryWriteLittleEndianBytes(actual)); {
CollectionAssert.AreEqual(expected, actual.ToArray()); Span<byte> actual = stackalloc byte[8];
Assert.That(value.TryWriteLittleEndianBytes(actual));
Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection);
});
} }
[Test] [Test]
@ -43,9 +46,12 @@ internal class Int64Tests
const long value = 0x0F; const long value = 0x0F;
byte[] expected = { 0, 0, 0, 0, 0, 0, 0, 0x0F }; byte[] expected = { 0, 0, 0, 0, 0, 0, 0, 0x0F };
Span<byte> actual = stackalloc byte[8]; Assert.Multiple(() =>
Assert.That(value.TryWriteBigEndianBytes(actual)); {
CollectionAssert.AreEqual(expected, actual.ToArray()); Span<byte> actual = stackalloc byte[8];
Assert.That(value.TryWriteBigEndianBytes(actual));
Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection);
});
} }
[Test] [Test]

View File

@ -10,16 +10,19 @@ internal class SByteTests
public void GetBytes_ReturnsArrayContainingItself() public void GetBytes_ReturnsArrayContainingItself()
{ {
const sbyte value = 0x0F; const sbyte value = 0x0F;
CollectionAssert.AreEqual(new[] {(byte)value}, value.GetBytes()); Assert.That(value.GetBytes(), Is.EqualTo(new[] { (byte)value }).AsCollection);
} }
[Test] [Test]
public void TryWriteBytes_ReturnsTrue_FillsSpanContainingItself_GivenLargeEnoughSpan() public void TryWriteBytes_ReturnsTrue_FillsSpanContainingItself_GivenLargeEnoughSpan()
{ {
const sbyte value = 0x0F; const sbyte value = 0x0F;
Span<byte> buffer = stackalloc byte[1]; Assert.Multiple(() =>
Assert.That(value.TryWriteBytes(buffer)); {
CollectionAssert.AreEqual(new[] {(byte)value}, buffer.ToArray()); Span<byte> buffer = stackalloc byte[1];
Assert.That(value.TryWriteBytes(buffer));
Assert.That(buffer.ToArray(), Is.EqualTo(new[] { (byte)value }).AsCollection);
});
} }
[Test] [Test]

View File

@ -13,7 +13,7 @@ internal class SingleTests
var expected = new byte[] { 0x42, 0x2A, 0, 0 }; var expected = new byte[] { 0x42, 0x2A, 0, 0 };
byte[] actual = value.GetBigEndianBytes(); byte[] actual = value.GetBigEndianBytes();
CollectionAssert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected).AsCollection);
} }
[Test] [Test]
@ -23,7 +23,7 @@ internal class SingleTests
var expected = new byte[] { 0, 0, 0x2A, 0x42 }; var expected = new byte[] { 0, 0, 0x2A, 0x42 };
byte[] actual = value.GetLittleEndianBytes(); byte[] actual = value.GetLittleEndianBytes();
CollectionAssert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected).AsCollection);
} }
[Test] [Test]
@ -32,9 +32,12 @@ internal class SingleTests
const float value = 42.5f; const float value = 42.5f;
var expected = new byte[] { 0x42, 0x2A, 0, 0 }; var expected = new byte[] { 0x42, 0x2A, 0, 0 };
Span<byte> actual = stackalloc byte[4]; Assert.Multiple(() =>
Assert.That(value.TryWriteBigEndianBytes(actual)); {
CollectionAssert.AreEqual(expected, actual.ToArray()); Span<byte> actual = stackalloc byte[4];
Assert.That(value.TryWriteBigEndianBytes(actual));
Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection);
});
} }
[Test] [Test]
@ -43,9 +46,12 @@ internal class SingleTests
const float value = 42.5f; const float value = 42.5f;
var expected = new byte[] { 0, 0, 0x2A, 0x42 }; var expected = new byte[] { 0, 0, 0x2A, 0x42 };
Span<byte> actual = stackalloc byte[4]; Assert.Multiple(() =>
Assert.That(value.TryWriteLittleEndianBytes(actual)); {
CollectionAssert.AreEqual(expected, actual.ToArray()); Span<byte> actual = stackalloc byte[4];
Assert.That(value.TryWriteLittleEndianBytes(actual));
Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection);
});
} }
[Test] [Test]

View File

@ -45,16 +45,19 @@ internal partial class StreamTests
Assert.That(stream.Position, Is.EqualTo(16)); Assert.That(stream.Position, Is.EqualTo(16));
stream.Position = 0; stream.Position = 0;
Span<byte> actual = stackalloc byte[16]; Assert.Multiple(() =>
ReadOnlySpan<byte> expected = stackalloc byte[]
{ {
0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x68 Span<byte> actual = stackalloc byte[16];
}; ReadOnlySpan<byte> expected = stackalloc byte[]
int read = stream.Read(actual); {
Trace.WriteLine(string.Join(' ', actual.ToArray())); 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)); Assert.That(read, Is.EqualTo(16));
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray()); Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection);
});
} }
[Test] [Test]
@ -65,16 +68,19 @@ internal partial class StreamTests
Assert.That(stream.Position, Is.EqualTo(16)); Assert.That(stream.Position, Is.EqualTo(16));
stream.Position = 0; stream.Position = 0;
Span<byte> actual = stackalloc byte[16]; Assert.Multiple(() =>
ReadOnlySpan<byte> expected = stackalloc byte[]
{ {
0x68, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00 Span<byte> actual = stackalloc byte[16];
}; ReadOnlySpan<byte> expected = stackalloc byte[]
int read = stream.Read(actual); {
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)); Assert.That(read, Is.EqualTo(16));
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray()); Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection);
});
} }
} }

View File

@ -44,12 +44,15 @@ internal partial class StreamTests
Assert.That(stream.Position, Is.EqualTo(8)); Assert.That(stream.Position, Is.EqualTo(8));
stream.Position = 0; stream.Position = 0;
Span<byte> actual = stackalloc byte[8]; Assert.Multiple(() =>
ReadOnlySpan<byte> expected = stackalloc byte[] { 0x40, 0x7A, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00 }; {
int read = stream.Read(actual); Span<byte> actual = stackalloc byte[8];
ReadOnlySpan<byte> expected = stackalloc byte[] { 0x40, 0x7A, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00 };
int read = stream.Read(actual);
Assert.That(read, Is.EqualTo(8)); Assert.That(read, Is.EqualTo(8));
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray()); Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection);
});
} }
[Test] [Test]
@ -60,11 +63,14 @@ internal partial class StreamTests
Assert.That(stream.Position, Is.EqualTo(8)); Assert.That(stream.Position, Is.EqualTo(8));
stream.Position = 0; stream.Position = 0;
Span<byte> actual = stackalloc byte[8]; Assert.Multiple(() =>
ReadOnlySpan<byte> expected = stackalloc byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x7A, 0x40 }; {
int read = stream.Read(actual); Span<byte> actual = stackalloc byte[8];
ReadOnlySpan<byte> expected = stackalloc byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x7A, 0x40 };
int read = stream.Read(actual);
Assert.That(read, Is.EqualTo(8)); Assert.That(read, Is.EqualTo(8));
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray()); Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection);
});
} }
} }

View File

@ -44,12 +44,15 @@ internal partial class StreamTests
Assert.That(stream.Position, Is.EqualTo(2)); Assert.That(stream.Position, Is.EqualTo(2));
stream.Position = 0; stream.Position = 0;
Span<byte> actual = stackalloc byte[2]; Assert.Multiple(() =>
ReadOnlySpan<byte> expected = stackalloc byte[] { 0x01, 0xA4 }; {
int read = stream.Read(actual); Span<byte> actual = stackalloc byte[2];
ReadOnlySpan<byte> expected = stackalloc byte[] { 0x01, 0xA4 };
int read = stream.Read(actual);
Assert.That(read, Is.EqualTo(2)); Assert.That(read, Is.EqualTo(2));
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray()); Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection);
});
} }
[Test] [Test]
@ -60,11 +63,14 @@ internal partial class StreamTests
Assert.That(stream.Position, Is.EqualTo(2)); Assert.That(stream.Position, Is.EqualTo(2));
stream.Position = 0; stream.Position = 0;
Span<byte> actual = stackalloc byte[2]; Assert.Multiple(() =>
ReadOnlySpan<byte> expected = stackalloc byte[] { 0xA4, 0x01 }; {
int read = stream.Read(actual); Span<byte> actual = stackalloc byte[2];
ReadOnlySpan<byte> expected = stackalloc byte[] { 0xA4, 0x01 };
int read = stream.Read(actual);
Assert.That(read, Is.EqualTo(2)); Assert.That(read, Is.EqualTo(2));
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray()); Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection);
});
} }
} }

View File

@ -44,12 +44,15 @@ internal partial class StreamTests
Assert.That(stream.Position, Is.EqualTo(4)); Assert.That(stream.Position, Is.EqualTo(4));
stream.Position = 0; stream.Position = 0;
Span<byte> actual = stackalloc byte[4]; Assert.Multiple(() =>
ReadOnlySpan<byte> expected = stackalloc byte[] { 0x00, 0x00, 0x01, 0xA4 }; {
int read = stream.Read(actual); Span<byte> actual = stackalloc byte[4];
ReadOnlySpan<byte> expected = stackalloc byte[] { 0x00, 0x00, 0x01, 0xA4 };
int read = stream.Read(actual);
Assert.That(read, Is.EqualTo(4)); Assert.That(read, Is.EqualTo(4));
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray()); Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection);
});
} }
[Test] [Test]
@ -60,11 +63,14 @@ internal partial class StreamTests
Assert.That(stream.Position, Is.EqualTo(4)); Assert.That(stream.Position, Is.EqualTo(4));
stream.Position = 0; stream.Position = 0;
Span<byte> actual = stackalloc byte[4]; Assert.Multiple(() =>
ReadOnlySpan<byte> expected = stackalloc byte[] { 0xA4, 0x01, 0x00, 0x00 }; {
int read = stream.Read(actual); Span<byte> actual = stackalloc byte[4];
ReadOnlySpan<byte> expected = stackalloc byte[] { 0xA4, 0x01, 0x00, 0x00 };
int read = stream.Read(actual);
Assert.That(read, Is.EqualTo(4)); Assert.That(read, Is.EqualTo(4));
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray()); Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection);
});
} }
} }

View File

@ -44,12 +44,15 @@ internal partial class StreamTests
Assert.That(stream.Position, Is.EqualTo(8)); Assert.That(stream.Position, Is.EqualTo(8));
stream.Position = 0; stream.Position = 0;
Span<byte> actual = stackalloc byte[8]; Assert.Multiple(() =>
ReadOnlySpan<byte> expected = stackalloc byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xA4 }; {
int read = stream.Read(actual); Span<byte> actual = stackalloc byte[8];
ReadOnlySpan<byte> expected = stackalloc byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xA4 };
int read = stream.Read(actual);
Assert.That(read, Is.EqualTo(8)); Assert.That(read, Is.EqualTo(8));
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray()); Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection);
});
} }
[Test] [Test]
@ -60,11 +63,14 @@ internal partial class StreamTests
Assert.That(stream.Position, Is.EqualTo(8)); Assert.That(stream.Position, Is.EqualTo(8));
stream.Position = 0; stream.Position = 0;
Span<byte> actual = stackalloc byte[8]; Assert.Multiple(() =>
ReadOnlySpan<byte> expected = stackalloc byte[] { 0xA4, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; {
int read = stream.Read(actual); Span<byte> actual = stackalloc byte[8];
ReadOnlySpan<byte> expected = stackalloc byte[] { 0xA4, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
int read = stream.Read(actual);
Assert.That(read, Is.EqualTo(8)); Assert.That(read, Is.EqualTo(8));
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray()); Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection);
});
} }
} }

View File

@ -44,12 +44,15 @@ internal partial class StreamTests
Assert.That(stream.Position, Is.EqualTo(4)); Assert.That(stream.Position, Is.EqualTo(4));
stream.Position = 0; stream.Position = 0;
Span<byte> actual = stackalloc byte[4]; Assert.Multiple(() =>
ReadOnlySpan<byte> expected = stackalloc byte[] { 0x43, 0xD2, 0x00, 0x00 }; {
int read = stream.Read(actual); Span<byte> actual = stackalloc byte[4];
ReadOnlySpan<byte> expected = stackalloc byte[] { 0x43, 0xD2, 0x00, 0x00 };
int read = stream.Read(actual);
Assert.That(read, Is.EqualTo(4)); Assert.That(read, Is.EqualTo(4));
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray()); Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection);
});
} }
[Test] [Test]
@ -60,11 +63,14 @@ internal partial class StreamTests
Assert.That(stream.Position, Is.EqualTo(4)); Assert.That(stream.Position, Is.EqualTo(4));
stream.Position = 0; stream.Position = 0;
Span<byte> actual = stackalloc byte[4]; Assert.Multiple(() =>
ReadOnlySpan<byte> expected = stackalloc byte[] { 0x00, 0x00, 0xD2, 0x43 }; {
int read = stream.Read(actual); Span<byte> actual = stackalloc byte[4];
ReadOnlySpan<byte> expected = stackalloc byte[] { 0x00, 0x00, 0xD2, 0x43 };
int read = stream.Read(actual);
Assert.That(read, Is.EqualTo(4)); Assert.That(read, Is.EqualTo(4));
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray()); Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection);
});
} }
} }

View File

@ -44,12 +44,15 @@ internal partial class StreamTests
Assert.That(stream.Position, Is.EqualTo(2)); Assert.That(stream.Position, Is.EqualTo(2));
stream.Position = 0; stream.Position = 0;
Span<byte> actual = stackalloc byte[2]; Assert.Multiple(() =>
ReadOnlySpan<byte> expected = stackalloc byte[] { 0x01, 0xA4 }; {
int read = stream.Read(actual); Span<byte> actual = stackalloc byte[2];
ReadOnlySpan<byte> expected = stackalloc byte[] { 0x01, 0xA4 };
int read = stream.Read(actual);
Assert.That(read, Is.EqualTo(2)); Assert.That(read, Is.EqualTo(2));
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray()); Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection);
});
} }
[Test] [Test]
@ -60,11 +63,14 @@ internal partial class StreamTests
Assert.That(stream.Position, Is.EqualTo(2)); Assert.That(stream.Position, Is.EqualTo(2));
stream.Position = 0; stream.Position = 0;
Span<byte> actual = stackalloc byte[2]; Assert.Multiple(() =>
ReadOnlySpan<byte> expected = stackalloc byte[] { 0xA4, 0x01 }; {
int read = stream.Read(actual); Span<byte> actual = stackalloc byte[2];
ReadOnlySpan<byte> expected = stackalloc byte[] { 0xA4, 0x01 };
int read = stream.Read(actual);
Assert.That(read, Is.EqualTo(2)); Assert.That(read, Is.EqualTo(2));
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray()); Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection);
});
} }
} }

View File

@ -44,12 +44,15 @@ internal partial class StreamTests
Assert.That(stream.Position, Is.EqualTo(4)); Assert.That(stream.Position, Is.EqualTo(4));
stream.Position = 0; stream.Position = 0;
Span<byte> actual = stackalloc byte[4]; Assert.Multiple(() =>
ReadOnlySpan<byte> expected = stackalloc byte[] { 0x00, 0x00, 0x01, 0xA4 }; {
int read = stream.Read(actual); Span<byte> actual = stackalloc byte[4];
ReadOnlySpan<byte> expected = stackalloc byte[] { 0x00, 0x00, 0x01, 0xA4 };
int read = stream.Read(actual);
Assert.That(read, Is.EqualTo(4)); Assert.That(read, Is.EqualTo(4));
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray()); Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection);
});
} }
[Test] [Test]
@ -60,11 +63,14 @@ internal partial class StreamTests
Assert.That(stream.Position, Is.EqualTo(4)); Assert.That(stream.Position, Is.EqualTo(4));
stream.Position = 0; stream.Position = 0;
Span<byte> actual = stackalloc byte[4]; Assert.Multiple(() =>
ReadOnlySpan<byte> expected = stackalloc byte[] { 0xA4, 0x01, 0x00, 0x00 }; {
int read = stream.Read(actual); Span<byte> actual = stackalloc byte[4];
ReadOnlySpan<byte> expected = stackalloc byte[] { 0xA4, 0x01, 0x00, 0x00 };
int read = stream.Read(actual);
Assert.That(read, Is.EqualTo(4)); Assert.That(read, Is.EqualTo(4));
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray()); Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection);
});
} }
} }

View File

@ -44,12 +44,15 @@ internal partial class StreamTests
Assert.That(stream.Position, Is.EqualTo(8)); Assert.That(stream.Position, Is.EqualTo(8));
stream.Position = 0; stream.Position = 0;
Span<byte> actual = stackalloc byte[8]; Assert.Multiple(() =>
ReadOnlySpan<byte> expected = stackalloc byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xA4 }; {
int read = stream.Read(actual); Span<byte> actual = stackalloc byte[8];
ReadOnlySpan<byte> expected = stackalloc byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xA4 };
int read = stream.Read(actual);
Assert.That(read, Is.EqualTo(8)); Assert.That(read, Is.EqualTo(8));
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray()); Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection);
});
} }
[Test] [Test]
@ -60,11 +63,14 @@ internal partial class StreamTests
Assert.That(stream.Position, Is.EqualTo(8)); Assert.That(stream.Position, Is.EqualTo(8));
stream.Position = 0; stream.Position = 0;
Span<byte> actual = stackalloc byte[8]; Assert.Multiple(() =>
ReadOnlySpan<byte> expected = stackalloc byte[] { 0xA4, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; {
int read = stream.Read(actual); Span<byte> actual = stackalloc byte[8];
ReadOnlySpan<byte> expected = stackalloc byte[] { 0xA4, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
int read = stream.Read(actual);
Assert.That(read, Is.EqualTo(8)); Assert.That(read, Is.EqualTo(8));
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray()); Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection);
});
} }
} }

View File

@ -26,7 +26,7 @@ internal partial class StreamTests
byte[] hash = stream.GetHash<SHA1>(); byte[] hash = stream.GetHash<SHA1>();
Trace.WriteLine($"Hash: {BitConverter.ToString(hash)}"); Trace.WriteLine($"Hash: {BitConverter.ToString(hash)}");
Trace.WriteLine($"Expected: {BitConverter.ToString(expectedHash)}"); Trace.WriteLine($"Expected: {BitConverter.ToString(expectedHash)}");
CollectionAssert.AreEqual(expectedHash, hash); Assert.That(hash, Is.EqualTo(expectedHash).AsCollection);
} }
[Test] [Test]
@ -54,7 +54,7 @@ internal partial class StreamTests
Span<byte> hash = stackalloc byte[20]; Span<byte> hash = stackalloc byte[20];
stream.TryWriteHash<SHA1>(hash, out int bytesWritten); stream.TryWriteHash<SHA1>(hash, out int bytesWritten);
Assert.That(bytesWritten, Is.EqualTo(expectedHash.Length)); Assert.That(bytesWritten, Is.EqualTo(expectedHash.Length));
CollectionAssert.AreEqual(expectedHash, hash.ToArray()); Assert.That(hash.ToArray(), Is.EqualTo(expectedHash).AsCollection);
} }
[Test] [Test]

View File

@ -13,7 +13,7 @@ internal class UInt16Tests
byte[] expected = { 0x0F, 0 }; byte[] expected = { 0x0F, 0 };
byte[] actual = value.GetLittleEndianBytes(); byte[] actual = value.GetLittleEndianBytes();
CollectionAssert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected).AsCollection);
} }
[Test] [Test]
@ -23,7 +23,7 @@ internal class UInt16Tests
byte[] expected = { 0, 0x0F }; byte[] expected = { 0, 0x0F };
byte[] actual = value.GetBigEndianBytes(); byte[] actual = value.GetBigEndianBytes();
CollectionAssert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected).AsCollection);
} }
[Test] [Test]
@ -32,10 +32,12 @@ internal class UInt16Tests
const ushort value = 0x0F; const ushort value = 0x0F;
byte[] expected = { 0x0F, 0 }; byte[] expected = { 0x0F, 0 };
Span<byte> actual = stackalloc byte[2]; Assert.Multiple(() =>
Assert.That(value.TryWriteLittleEndianBytes(actual)); {
Span<byte> actual = stackalloc byte[2];
CollectionAssert.AreEqual(expected, actual.ToArray()); Assert.That(value.TryWriteLittleEndianBytes(actual));
Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection);
});
} }
[Test] [Test]
@ -44,10 +46,12 @@ internal class UInt16Tests
const ushort value = 0x0F; const ushort value = 0x0F;
byte[] expected = { 0, 0x0F }; byte[] expected = { 0, 0x0F };
Span<byte> actual = stackalloc byte[2]; Assert.Multiple(() =>
Assert.That(value.TryWriteBigEndianBytes(actual)); {
Span<byte> actual = stackalloc byte[2];
CollectionAssert.AreEqual(expected, actual.ToArray()); Assert.That(value.TryWriteBigEndianBytes(actual));
Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection);
});
} }
[Test] [Test]

View File

@ -13,7 +13,7 @@ internal class UInt32Tests
byte[] expected = { 0x0F, 0, 0, 0 }; byte[] expected = { 0x0F, 0, 0, 0 };
byte[] actual = value.GetLittleEndianBytes(); byte[] actual = value.GetLittleEndianBytes();
CollectionAssert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected).AsCollection);
} }
[Test] [Test]
@ -23,7 +23,7 @@ internal class UInt32Tests
byte[] expected = { 0, 0, 0, 0x0F }; byte[] expected = { 0, 0, 0, 0x0F };
byte[] actual = value.GetBigEndianBytes(); byte[] actual = value.GetBigEndianBytes();
CollectionAssert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected).AsCollection);
} }
[Test] [Test]
@ -32,10 +32,12 @@ internal class UInt32Tests
const uint value = 0x0F; const uint value = 0x0F;
byte[] expected = { 0x0F, 0, 0, 0 }; byte[] expected = { 0x0F, 0, 0, 0 };
Span<byte> actual = stackalloc byte[4]; Assert.Multiple(() =>
Assert.That(value.TryWriteLittleEndianBytes(actual)); {
Span<byte> actual = stackalloc byte[4];
CollectionAssert.AreEqual(expected, actual.ToArray()); Assert.That(value.TryWriteLittleEndianBytes(actual));
Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection);
});
} }
[Test] [Test]
@ -44,10 +46,12 @@ internal class UInt32Tests
const uint value = 0x0F; const uint value = 0x0F;
byte[] expected = { 0, 0, 0, 0x0F }; byte[] expected = { 0, 0, 0, 0x0F };
Span<byte> actual = stackalloc byte[4]; Assert.Multiple(() =>
Assert.That(value.TryWriteBigEndianBytes(actual)); {
Span<byte> actual = stackalloc byte[4];
CollectionAssert.AreEqual(expected, actual.ToArray()); Assert.That(value.TryWriteBigEndianBytes(actual));
Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection);
});
} }
[Test] [Test]

View File

@ -13,7 +13,7 @@ internal class UInt64Tests
byte[] expected = { 0x0F, 0, 0, 0, 0, 0, 0, 0 }; byte[] expected = { 0x0F, 0, 0, 0, 0, 0, 0, 0 };
byte[] actual = value.GetLittleEndianBytes(); byte[] actual = value.GetLittleEndianBytes();
CollectionAssert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected).AsCollection);
} }
[Test] [Test]
@ -23,7 +23,7 @@ internal class UInt64Tests
byte[] expected = { 0, 0, 0, 0, 0, 0, 0, 0x0F }; byte[] expected = { 0, 0, 0, 0, 0, 0, 0, 0x0F };
byte[] actual = value.GetBigEndianBytes(); byte[] actual = value.GetBigEndianBytes();
CollectionAssert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected).AsCollection);
} }
[Test] [Test]
@ -32,10 +32,12 @@ internal class UInt64Tests
const ulong value = 0x0F; const ulong value = 0x0F;
byte[] expected = { 0x0F, 0, 0, 0, 0, 0, 0, 0 }; byte[] expected = { 0x0F, 0, 0, 0, 0, 0, 0, 0 };
Span<byte> actual = stackalloc byte[8]; Assert.Multiple(() =>
Assert.That(value.TryWriteLittleEndianBytes(actual)); {
Span<byte> actual = stackalloc byte[8];
CollectionAssert.AreEqual(expected, actual.ToArray()); Assert.That(value.TryWriteLittleEndianBytes(actual));
Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection);
});
} }
[Test] [Test]
@ -44,10 +46,12 @@ internal class UInt64Tests
const ulong value = 0x0F; const ulong value = 0x0F;
byte[] expected = { 0, 0, 0, 0, 0, 0, 0, 0x0F }; byte[] expected = { 0, 0, 0, 0, 0, 0, 0, 0x0F };
Span<byte> actual = stackalloc byte[8]; Assert.Multiple(() =>
Assert.That(value.TryWriteBigEndianBytes(actual)); {
Span<byte> actual = stackalloc byte[8];
CollectionAssert.AreEqual(expected, actual.ToArray()); Assert.That(value.TryWriteBigEndianBytes(actual));
Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection);
});
} }
[Test] [Test]

View File

@ -142,7 +142,7 @@ internal class IsPrimeTests
private static IReadOnlyList<int> LoadPrimes() private static IReadOnlyList<int> LoadPrimes()
{ {
using var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("X10D.Tests.1000primes.txt"); 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); using var reader = new StreamReader(stream, Encoding.UTF8);
var primes = new List<int>(); var primes = new List<int>();

View File

@ -20,7 +20,11 @@ internal class CoreTests
int[] source = Enumerable.Range(1, 100).ToArray(); int[] source = Enumerable.Range(1, 100).ToArray();
string json = source.ToJson(); string json = source.ToJson();
int[]? target = json.FromJson<int[]>(); int[]? target = json.FromJson<int[]>();
CollectionAssert.AreEqual(source, target);
CollectionAssert.AreEquivalent(source, target); Assert.Multiple(() =>
{
Assert.That(target, Is.EqualTo(source).AsCollection);
Assert.That(target, Is.EquivalentTo(source));
});
} }
} }

View File

@ -10,13 +10,13 @@ internal class EnumerableTests
public void Grep_ShouldFilterCorrectly_GivenPattern() public void Grep_ShouldFilterCorrectly_GivenPattern()
{ {
int year = DateTime.Now.Year; 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}" };
var expectedResult = new[] {"String 123", $"The year is {year}"}; var expectedResult = new[] { "String 123", $"The year is {year}" };
const string pattern = /*lang=regex*/@"[0-9]+"; const string pattern = /*lang=regex*/@"[0-9]+";
string[] actualResult = source.Grep(pattern).ToArray(); string[] actualResult = source.Grep(pattern).ToArray();
CollectionAssert.AreEqual(expectedResult, actualResult); Assert.That(actualResult, Is.EqualTo(expectedResult).AsCollection);
} }
[Test] [Test]
@ -28,27 +28,27 @@ internal class EnumerableTests
const string pattern = /*lang=regex*/@"[0-9]+"; const string pattern = /*lang=regex*/@"[0-9]+";
string[] actualResult = source.Grep(pattern).ToArray(); string[] actualResult = source.Grep(pattern).ToArray();
CollectionAssert.AreEqual(expectedResult, actualResult); Assert.That(actualResult, Is.EqualTo(expectedResult).AsCollection);
} }
[Test] [Test]
public void Grep_ShouldMatchUpperCase_GivenIgnoreCaseTrue() public void Grep_ShouldMatchUpperCase_GivenIgnoreCaseTrue()
{ {
int year = DateTime.Now.Year; 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}" };
var expectedResult = new[] {"WORLD"}; var expectedResult = new[] { "WORLD" };
const string pattern = /*lang=regex*/@"world"; const string pattern = /*lang=regex*/@"world";
string[] actualResult = source.Grep(pattern, true).ToArray(); string[] actualResult = source.Grep(pattern, true).ToArray();
CollectionAssert.AreEqual(expectedResult, actualResult); Assert.That(actualResult, Is.EqualTo(expectedResult).AsCollection);
} }
[Test] [Test]
public void Grep_ShouldNotMatchUpperCase_GivenIgnoreCaseFalse() public void Grep_ShouldNotMatchUpperCase_GivenIgnoreCaseFalse()
{ {
int year = DateTime.Now.Year; 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"; const string pattern = /*lang=regex*/@"world";
string[] actualResult = source.Grep(pattern, false).ToArray(); string[] actualResult = source.Grep(pattern, false).ToArray();
@ -60,22 +60,28 @@ internal class EnumerableTests
public void Grep_ShouldThrowArgumentNullException_GivenNullPattern() public void Grep_ShouldThrowArgumentNullException_GivenNullPattern()
{ {
IEnumerable<string> source = Enumerable.Empty<string>(); IEnumerable<string> source = Enumerable.Empty<string>();
Assert.Throws<ArgumentNullException>(() => source.Grep(null!).ToArray()); Assert.Multiple(() =>
Assert.Throws<ArgumentNullException>(() => source.Grep(null!, false).ToArray()); {
Assert.Throws<ArgumentNullException>(() => source.Grep(null!).ToArray());
Assert.Throws<ArgumentNullException>(() => source.Grep(null!, false).ToArray());
});
} }
[Test] [Test]
public void Grep_ShouldThrowArgumentNullException_GivenNullSource() public void Grep_ShouldThrowArgumentNullException_GivenNullSource()
{ {
IEnumerable<string> source = null!; IEnumerable<string> source = null!;
Assert.Throws<ArgumentNullException>(() => source.Grep("foo").ToArray()); Assert.Multiple(() =>
Assert.Throws<ArgumentNullException>(() => source.Grep("foo", false).ToArray()); {
Assert.Throws<ArgumentNullException>(() => source.Grep("foo").ToArray());
Assert.Throws<ArgumentNullException>(() => source.Grep("foo", false).ToArray());
});
} }
[Test] [Test]
public void Grep_ShouldYieldNoElements_GivenNoMatchingStrings() public void Grep_ShouldYieldNoElements_GivenNoMatchingStrings()
{ {
var source = new[] {"Hello", "World", "String"}; var source = new[] { "Hello", "World", "String" };
const string pattern = /*lang=regex*/@"[0-9]+"; const string pattern = /*lang=regex*/@"[0-9]+";
string[] actualResult = source.Grep(pattern).ToArray(); string[] actualResult = source.Grep(pattern).ToArray();

View File

@ -22,18 +22,21 @@ internal class StringBuilderReaderTests
{ {
using var reader = new StringBuilderReader(new StringBuilder("Hello\nWorld")); using var reader = new StringBuilderReader(new StringBuilder("Hello\nWorld"));
Assert.That(reader.Read(), Is.EqualTo('H')); Assert.Multiple(() =>
Assert.That(reader.Read(), Is.EqualTo('e')); {
Assert.That(reader.Read(), Is.EqualTo('l')); Assert.That(reader.Read(), Is.EqualTo('H'));
Assert.That(reader.Read(), Is.EqualTo('l')); Assert.That(reader.Read(), Is.EqualTo('e'));
Assert.That(reader.Read(), Is.EqualTo('o')); Assert.That(reader.Read(), Is.EqualTo('l'));
Assert.That(reader.Read(), Is.EqualTo('\n')); Assert.That(reader.Read(), Is.EqualTo('l'));
Assert.That(reader.Read(), Is.EqualTo('W')); Assert.That(reader.Read(), Is.EqualTo('o'));
Assert.That(reader.Read(), Is.EqualTo('o')); Assert.That(reader.Read(), Is.EqualTo('\n'));
Assert.That(reader.Read(), Is.EqualTo('r')); Assert.That(reader.Read(), Is.EqualTo('W'));
Assert.That(reader.Read(), Is.EqualTo('l')); Assert.That(reader.Read(), Is.EqualTo('o'));
Assert.That(reader.Read(), Is.EqualTo('d')); Assert.That(reader.Read(), Is.EqualTo('r'));
Assert.That(reader.Read(), Is.EqualTo(-1)); Assert.That(reader.Read(), Is.EqualTo('l'));
Assert.That(reader.Read(), Is.EqualTo('d'));
Assert.That(reader.Read(), Is.EqualTo(-1));
});
reader.Close(); reader.Close();
} }
@ -45,9 +48,12 @@ internal class StringBuilderReaderTests
var array = new char[5]; var array = new char[5];
int read = reader.Read(array, 0, 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(); reader.Close();
} }
@ -114,11 +120,14 @@ internal class StringBuilderReaderTests
{ {
using var reader = new StringBuilderReader(new StringBuilder("Hello\nWorld")); using var reader = new StringBuilderReader(new StringBuilder("Hello\nWorld"));
Span<char> span = stackalloc char[5]; Assert.Multiple(() =>
int read = reader.Read(span); {
Assert.That(read, Is.EqualTo(5)); Span<char> 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(); reader.Close();
} }
@ -130,9 +139,12 @@ internal class StringBuilderReaderTests
var array = new char[5]; var array = new char[5];
int read = reader.ReadAsync(array, 0, 5).GetAwaiter().GetResult(); 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(); reader.Close();
} }
@ -144,9 +156,12 @@ internal class StringBuilderReaderTests
Memory<char> memory = new char[5]; Memory<char> memory = new char[5];
int read = reader.ReadAsync(memory).GetAwaiter().GetResult(); 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(); reader.Close();
} }
@ -158,9 +173,12 @@ internal class StringBuilderReaderTests
var array = new char[5]; var array = new char[5];
int read = reader.ReadBlock(array, 0, 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(); reader.Close();
} }
@ -170,11 +188,14 @@ internal class StringBuilderReaderTests
{ {
using var reader = new StringBuilderReader(new StringBuilder("Hello\nWorld")); using var reader = new StringBuilderReader(new StringBuilder("Hello\nWorld"));
Span<char> span = stackalloc char[5]; Assert.Multiple(() =>
int read = reader.ReadBlock(span); {
Assert.That(read, Is.EqualTo(5)); Span<char> 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(); reader.Close();
} }
@ -200,9 +221,12 @@ internal class StringBuilderReaderTests
var array = new char[5]; var array = new char[5];
int read = reader.ReadBlockAsync(array, 0, 5).GetAwaiter().GetResult(); 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(); reader.Close();
} }
@ -214,9 +238,12 @@ internal class StringBuilderReaderTests
Memory<char> memory = new char[5]; Memory<char> memory = new char[5];
int read = reader.ReadBlockAsync(memory).GetAwaiter().GetResult(); 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(); reader.Close();
} }

View File

@ -423,7 +423,7 @@ internal class StringTests
var target = json.FromJson<SampleStructure>(); var target = json.FromJson<SampleStructure>();
Assert.Multiple(() => Assert.Multiple(() =>
{ {
Assert.IsInstanceOf<SampleStructure>(target); Assert.That(target, Is.InstanceOf<SampleStructure>());
Assert.That(target.Values, Is.Not.Null); Assert.That(target.Values, Is.Not.Null);
Assert.That(target.Values.Length, Is.EqualTo(3)); Assert.That(target.Values.Length, Is.EqualTo(3));
Assert.That(target.Values[0], Is.EqualTo(1)); 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 }; var expected = new byte[] { 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64 };
byte[] actual = "Hello World".GetBytes(); byte[] actual = "Hello World".GetBytes();
CollectionAssert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected).AsCollection);
} }
[Test] [Test]
@ -447,7 +447,7 @@ internal class StringTests
var expected = new byte[] { 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64 }; var expected = new byte[] { 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64 };
byte[] actual = "Hello World".GetBytes(Encoding.ASCII); byte[] actual = "Hello World".GetBytes(Encoding.ASCII);
CollectionAssert.AreEqual(expected, actual); Assert.That(actual, Is.EqualTo(expected).AsCollection);
} }
[Test] [Test]
@ -1004,7 +1004,6 @@ internal class StringTests
private struct SampleStructure private struct SampleStructure
{ {
[JsonPropertyName("values")] [JsonPropertyName("values")] public int[] Values { get; set; }
public int[] Values { get; set; }
} }
} }