diff --git a/tests/CommunityToolkit.Common.UnitTests/Extensions/Test_TaskExtensions.cs b/tests/CommunityToolkit.Common.UnitTests/Extensions/Test_TaskExtensions.cs index 86d6ec2aa..1bebbf5d8 100644 --- a/tests/CommunityToolkit.Common.UnitTests/Extensions/Test_TaskExtensions.cs +++ b/tests/CommunityToolkit.Common.UnitTests/Extensions/Test_TaskExtensions.cs @@ -85,8 +85,8 @@ public async Task Test_TaskExtensions_ResultOrDefault_FromAsyncTaskMethodBuilder _ = await taskFromBuilder; - Assert.AreEqual(((Task)taskFromBuilder).GetResultOrDefault(), "Test"); - Assert.AreEqual(taskFromBuilder.GetResultOrDefault(), "Test"); + Assert.AreEqual("Test", ((Task)taskFromBuilder).GetResultOrDefault()); + Assert.AreEqual("Test", taskFromBuilder.GetResultOrDefault()); } [TestMethod] diff --git a/tests/CommunityToolkit.Diagnostics.UnitTests/Extensions/Test_ValueTypeExtensions.cs b/tests/CommunityToolkit.Diagnostics.UnitTests/Extensions/Test_ValueTypeExtensions.cs index 972dfff33..d9c6855e0 100644 --- a/tests/CommunityToolkit.Diagnostics.UnitTests/Extensions/Test_ValueTypeExtensions.cs +++ b/tests/CommunityToolkit.Diagnostics.UnitTests/Extensions/Test_ValueTypeExtensions.cs @@ -12,12 +12,12 @@ public class Test_ValueTypeExtensions [TestMethod] public void Test_ValueTypeExtensions_ToHexString() { - Assert.AreEqual(((byte)0).ToHexString(), "0x00"); - Assert.AreEqual(((byte)127).ToHexString(), "0x7F"); - Assert.AreEqual(((byte)255).ToHexString(), "0xFF"); - Assert.AreEqual(((ushort)6458).ToHexString(), "0x193A"); - Assert.AreEqual(6458.ToHexString(), "0x0000193A"); - Assert.AreEqual((-1).ToHexString(), "0xFFFFFFFF"); - Assert.AreEqual(true.ToHexString(), "0x01"); + Assert.AreEqual("0x00", ((byte)0).ToHexString()); + Assert.AreEqual("0x7F", ((byte)127).ToHexString()); + Assert.AreEqual("0xFF", ((byte)255).ToHexString()); + Assert.AreEqual("0x193A", ((ushort)6458).ToHexString()); + Assert.AreEqual("0x0000193A", 6458.ToHexString()); + Assert.AreEqual("0xFFFFFFFF", (-1).ToHexString()); + Assert.AreEqual("0x01", true.ToHexString()); } } diff --git a/tests/CommunityToolkit.Diagnostics.UnitTests/Test_Guard.cs b/tests/CommunityToolkit.Diagnostics.UnitTests/Test_Guard.cs index 482df6fe8..f80bef29b 100644 --- a/tests/CommunityToolkit.Diagnostics.UnitTests/Test_Guard.cs +++ b/tests/CommunityToolkit.Diagnostics.UnitTests/Test_Guard.cs @@ -755,7 +755,7 @@ public void Test_Guard_CallerArgumentExpression_1() } catch (ArgumentNullException e) { - Assert.AreEqual(e.ParamName, nameof(thisStringShouldNotBeNull)); + Assert.AreEqual(nameof(thisStringShouldNotBeNull), e.ParamName); return; } @@ -775,7 +775,7 @@ public void Test_Guard_CallerArgumentExpression_2() } catch (ArgumentOutOfRangeException e) { - Assert.AreEqual(e.ParamName, nameof(thisIndexIsOutOfRange)); + Assert.AreEqual(nameof(thisIndexIsOutOfRange), e.ParamName); return; } @@ -795,7 +795,7 @@ public void Test_Guard_CallerArgumentExpression_3() } catch (ArgumentException e) { - Assert.AreEqual(e.ParamName, nameof(thisArrayShouldNotBeShorterThan10)); + Assert.AreEqual(nameof(thisArrayShouldNotBeShorterThan10), e.ParamName); return; } diff --git a/tests/CommunityToolkit.HighPerformance.UnitTests/Buffers/Test_ArrayPoolBufferWriter{T}.cs b/tests/CommunityToolkit.HighPerformance.UnitTests/Buffers/Test_ArrayPoolBufferWriter{T}.cs index 47f977b17..afdfce6f0 100644 --- a/tests/CommunityToolkit.HighPerformance.UnitTests/Buffers/Test_ArrayPoolBufferWriter{T}.cs +++ b/tests/CommunityToolkit.HighPerformance.UnitTests/Buffers/Test_ArrayPoolBufferWriter{T}.cs @@ -52,7 +52,7 @@ public void Test_ArrayPoolBufferWriterOfT_BufferSize(int request, int expected) byte[] array = (byte[])arrayFieldInfo!.GetValue(writer)!; - Assert.AreEqual(array.Length, expected); + Assert.AreEqual(expected, array.Length); } [TestMethod] @@ -60,9 +60,9 @@ public void Test_ArrayPoolBufferWriterOfT_AllocateAndGetMemoryAndSpan() { ArrayPoolBufferWriter? writer = new(); - Assert.AreEqual(writer.Capacity, 256); - Assert.AreEqual(writer.FreeCapacity, 256); - Assert.AreEqual(writer.WrittenCount, 0); + Assert.AreEqual(256, writer.Capacity); + Assert.AreEqual(256, writer.FreeCapacity); + Assert.AreEqual(0, writer.WrittenCount); Assert.IsTrue(writer.WrittenMemory.IsEmpty); Assert.IsTrue(writer.WrittenSpan.IsEmpty); @@ -72,11 +72,11 @@ public void Test_ArrayPoolBufferWriterOfT_AllocateAndGetMemoryAndSpan() writer.Advance(43); - Assert.AreEqual(writer.Capacity, 256); - Assert.AreEqual(writer.FreeCapacity, 256 - 43); - Assert.AreEqual(writer.WrittenCount, 43); - Assert.AreEqual(writer.WrittenMemory.Length, 43); - Assert.AreEqual(writer.WrittenSpan.Length, 43); + Assert.AreEqual(256, writer.Capacity); + Assert.AreEqual(256 - 43, writer.FreeCapacity); + Assert.AreEqual(43, writer.WrittenCount); + Assert.AreEqual(43, writer.WrittenMemory.Length); + Assert.AreEqual(43, writer.WrittenSpan.Length); _ = Assert.ThrowsException(() => writer.Advance(-1)); _ = Assert.ThrowsException(() => writer.GetMemory(-1)); @@ -99,11 +99,11 @@ public void Test_ArrayPoolBufferWriterOfT_AllocateFromCustomPoolAndGetMemoryAndS using (ArrayPoolBufferWriter? writer = new(pool)) { - Assert.AreEqual(pool.RentedArrays.Count, 1); + Assert.AreEqual(1, pool.RentedArrays.Count); - Assert.AreEqual(writer.Capacity, 256); - Assert.AreEqual(writer.FreeCapacity, 256); - Assert.AreEqual(writer.WrittenCount, 0); + Assert.AreEqual(256, writer.Capacity); + Assert.AreEqual(256, writer.FreeCapacity); + Assert.AreEqual(0, writer.WrittenCount); Assert.IsTrue(writer.WrittenMemory.IsEmpty); Assert.IsTrue(writer.WrittenSpan.IsEmpty); @@ -113,11 +113,11 @@ public void Test_ArrayPoolBufferWriterOfT_AllocateFromCustomPoolAndGetMemoryAndS writer.Advance(43); - Assert.AreEqual(writer.Capacity, 256); - Assert.AreEqual(writer.FreeCapacity, 256 - 43); - Assert.AreEqual(writer.WrittenCount, 43); - Assert.AreEqual(writer.WrittenMemory.Length, 43); - Assert.AreEqual(writer.WrittenSpan.Length, 43); + Assert.AreEqual(256, writer.Capacity); + Assert.AreEqual(256 - 43, writer.FreeCapacity); + Assert.AreEqual(43, writer.WrittenCount); + Assert.AreEqual(43, writer.WrittenMemory.Length); + Assert.AreEqual(43, writer.WrittenSpan.Length); _ = Assert.ThrowsException(() => writer.Advance(-1)); _ = Assert.ThrowsException(() => writer.GetMemory(-1)); @@ -133,7 +133,7 @@ public void Test_ArrayPoolBufferWriterOfT_AllocateFromCustomPoolAndGetMemoryAndS _ = Assert.ThrowsException(() => writer.Advance(1)); } - Assert.AreEqual(pool.RentedArrays.Count, 0); + Assert.AreEqual(0, pool.RentedArrays.Count); } [TestMethod] @@ -158,12 +158,12 @@ public void Test_ArrayPoolBufferWriterOfT_Clear() writer.Advance(4); - Assert.AreEqual(writer.WrittenCount, 4); + Assert.AreEqual(4, writer.WrittenCount); Assert.IsTrue(span.SequenceEqual(data)); writer.Clear(); - Assert.AreEqual(writer.WrittenCount, 0); + Assert.AreEqual(0, writer.WrittenCount); Assert.IsTrue(span.ToArray().All(b => b == 0)); } @@ -194,13 +194,13 @@ public void Test_ArrayPoolBufferWriterOfT_AsStream() writeStream.Write(guid); } - Assert.AreEqual(writer.WrittenCount, GuidSize); + Assert.AreEqual(GuidSize, writer.WrittenCount); // Here we get a readable stream instead, and read from it to ensure // the previous data was written correctly from the writeable stream. using (Stream stream = writer.WrittenMemory.AsStream()) { - Assert.AreEqual(stream.Length, GuidSize); + Assert.AreEqual(GuidSize, stream.Length); byte[] result = new byte[GuidSize]; @@ -234,13 +234,13 @@ public void Test_ArrayPoolBufferWriterOfT_AllocateAndGetArray() Assert.IsNotNull(segment.Array); Assert.IsTrue(segment.Array.Length >= bufferWriter.WrittenSpan.Length); - Assert.AreEqual(segment.Offset, 0); - Assert.AreEqual(segment.Count, bufferWriter.WrittenSpan.Length); + Assert.AreEqual(0, segment.Offset); + Assert.AreEqual(bufferWriter.WrittenSpan.Length, segment.Count); _ = MemoryMarshal.TryGetArray(bufferWriter.WrittenMemory, out ArraySegment writtenSegment); // The array is the same one as the one from the written span - Assert.AreSame(segment.Array, writtenSegment.Array); + Assert.AreSame(writtenSegment.Array, segment.Array); bufferWriter.Dispose(); diff --git a/tests/CommunityToolkit.HighPerformance.UnitTests/Buffers/Test_MemoryBufferWriter{T}.cs b/tests/CommunityToolkit.HighPerformance.UnitTests/Buffers/Test_MemoryBufferWriter{T}.cs index 6a6bf4ee8..dade4eea1 100644 --- a/tests/CommunityToolkit.HighPerformance.UnitTests/Buffers/Test_MemoryBufferWriter{T}.cs +++ b/tests/CommunityToolkit.HighPerformance.UnitTests/Buffers/Test_MemoryBufferWriter{T}.cs @@ -19,23 +19,23 @@ public void Test_MemoryBufferWriterOfT_AllocateAndGetMemoryAndSpan() MemoryBufferWriter? writer = new(memory); - Assert.AreEqual(writer.Capacity, 256); - Assert.AreEqual(writer.FreeCapacity, 256); - Assert.AreEqual(writer.WrittenCount, 0); + Assert.AreEqual(256, writer.Capacity); + Assert.AreEqual(256, writer.FreeCapacity); + Assert.AreEqual(0, writer.WrittenCount); Assert.IsTrue(writer.WrittenMemory.IsEmpty); Assert.IsTrue(writer.WrittenSpan.IsEmpty); Span span = writer.GetSpan(43); - Assert.AreEqual(span.Length, memory.Length); + Assert.AreEqual(memory.Length, span.Length); writer.Advance(43); - Assert.AreEqual(writer.Capacity, 256); - Assert.AreEqual(writer.FreeCapacity, 256 - 43); - Assert.AreEqual(writer.WrittenCount, 43); - Assert.AreEqual(writer.WrittenMemory.Length, 43); - Assert.AreEqual(writer.WrittenSpan.Length, 43); + Assert.AreEqual(256, writer.Capacity); + Assert.AreEqual(256 - 43, writer.FreeCapacity); + Assert.AreEqual(43, writer.WrittenCount); + Assert.AreEqual(43, writer.WrittenMemory.Length); + Assert.AreEqual(43, writer.WrittenSpan.Length); Assert.AreEqual(memory.Length - 43, writer.GetSpan().Length); Assert.AreEqual(memory.Length - 43, writer.GetMemory().Length); @@ -64,12 +64,12 @@ public void Test_MemoryBufferWriterOfT_Clear() writer.Advance(4); - Assert.AreEqual(writer.WrittenCount, 4); + Assert.AreEqual(4, writer.WrittenCount); Assert.IsTrue(span.SequenceEqual(data)); writer.Clear(); - Assert.AreEqual(writer.WrittenCount, 0); + Assert.AreEqual(0, writer.WrittenCount); Assert.IsTrue(span.ToArray().All(b => b == 0)); } } diff --git a/tests/CommunityToolkit.HighPerformance.UnitTests/Buffers/Test_MemoryOwner{T}.cs b/tests/CommunityToolkit.HighPerformance.UnitTests/Buffers/Test_MemoryOwner{T}.cs index 80030bc1a..bd34226fd 100644 --- a/tests/CommunityToolkit.HighPerformance.UnitTests/Buffers/Test_MemoryOwner{T}.cs +++ b/tests/CommunityToolkit.HighPerformance.UnitTests/Buffers/Test_MemoryOwner{T}.cs @@ -35,7 +35,7 @@ public void Test_MemoryOwnerOfT_AllocateFromCustomPoolAndGetMemoryAndSpan() using (MemoryOwner? buffer = MemoryOwner.Allocate(127, pool)) { - Assert.AreEqual(pool.RentedArrays.Count, 1); + Assert.AreEqual(1, pool.RentedArrays.Count); Assert.IsTrue(buffer.Length == 127); Assert.IsTrue(buffer.Memory.Length == 127); @@ -47,7 +47,7 @@ public void Test_MemoryOwnerOfT_AllocateFromCustomPoolAndGetMemoryAndSpan() Assert.IsTrue(buffer.Span.ToArray().All(i => i == 42)); } - Assert.AreEqual(pool.RentedArrays.Count, 0); + Assert.AreEqual(0, pool.RentedArrays.Count); } [TestMethod] @@ -130,8 +130,8 @@ public void Test_MemoryOwnerOfT_AllocateAndGetArray() Assert.IsNotNull(segment.Array); Assert.IsTrue(segment.Array.Length >= buffer.Length); - Assert.AreEqual(segment.Offset, 0); - Assert.AreEqual(segment.Count, buffer.Length); + Assert.AreEqual(0, segment.Offset); + Assert.AreEqual(buffer.Length, segment.Count); MemoryOwner? second = buffer.Slice(10, 80); @@ -145,8 +145,8 @@ public void Test_MemoryOwnerOfT_AllocateAndGetArray() // Same as before, but we now also verify the initial offset != 0, as we used Slice Assert.IsNotNull(segment.Array); Assert.IsTrue(segment.Array.Length >= second.Length); - Assert.AreEqual(segment.Offset, 10); - Assert.AreEqual(segment.Count, second.Length); + Assert.AreEqual(10, segment.Offset); + Assert.AreEqual(second.Length, segment.Count); second.Dispose(); diff --git a/tests/CommunityToolkit.HighPerformance.UnitTests/Buffers/Test_SpanOwner{T}.cs b/tests/CommunityToolkit.HighPerformance.UnitTests/Buffers/Test_SpanOwner{T}.cs index 8fcaedd4e..99b33cd81 100644 --- a/tests/CommunityToolkit.HighPerformance.UnitTests/Buffers/Test_SpanOwner{T}.cs +++ b/tests/CommunityToolkit.HighPerformance.UnitTests/Buffers/Test_SpanOwner{T}.cs @@ -33,7 +33,7 @@ public void Test_SpanOwnerOfT_AllocateFromCustomPoolAndGetMemoryAndSpan() using (SpanOwner buffer = SpanOwner.Allocate(127, pool)) { - Assert.AreEqual(pool.RentedArrays.Count, 1); + Assert.AreEqual(1, pool.RentedArrays.Count); Assert.IsTrue(buffer.Length == 127); Assert.IsTrue(buffer.Span.Length == 127); @@ -43,7 +43,7 @@ public void Test_SpanOwnerOfT_AllocateFromCustomPoolAndGetMemoryAndSpan() Assert.IsTrue(buffer.Span.ToArray().All(i => i == 42)); } - Assert.AreEqual(pool.RentedArrays.Count, 0); + Assert.AreEqual(0, pool.RentedArrays.Count); } [TestMethod] @@ -87,7 +87,7 @@ public void Test_SpanOwnerOfT_AllocateAndGetArray() // is all documented in the XML docs for the SpanOwner type. Assert.IsNotNull(segment.Array); Assert.IsTrue(segment.Array.Length >= buffer.Length); - Assert.AreEqual(segment.Offset, 0); - Assert.AreEqual(segment.Count, buffer.Length); + Assert.AreEqual(0, segment.Offset); + Assert.AreEqual(buffer.Length, segment.Count); } } diff --git a/tests/CommunityToolkit.HighPerformance.UnitTests/Enumerables/Test_ReadOnlyRefEnumerable{T}.cs b/tests/CommunityToolkit.HighPerformance.UnitTests/Enumerables/Test_ReadOnlyRefEnumerable{T}.cs index 964914d6a..389a2c23b 100644 --- a/tests/CommunityToolkit.HighPerformance.UnitTests/Enumerables/Test_ReadOnlyRefEnumerable{T}.cs +++ b/tests/CommunityToolkit.HighPerformance.UnitTests/Enumerables/Test_ReadOnlyRefEnumerable{T}.cs @@ -32,7 +32,7 @@ public void Test_ReadOnlyRefEnumerable_DangerousCreate_Ok(int length, int step, int[] result = enumerable.ToArray(); - CollectionAssert.AreEqual(result, values); + CollectionAssert.AreEqual(values, result); } [TestMethod] @@ -64,7 +64,7 @@ public void Test_ReadOnlyRefEnumerable_Indexer(int step, int[] values) for (int i = 0; i < enumerable.Length; i++) { - Assert.AreEqual(enumerable[i], values[i]); + Assert.AreEqual(values[i], enumerable[i]); } } diff --git a/tests/CommunityToolkit.HighPerformance.UnitTests/Enumerables/Test_RefEnumerable{T}.cs b/tests/CommunityToolkit.HighPerformance.UnitTests/Enumerables/Test_RefEnumerable{T}.cs index 589e7d650..013b1c11c 100644 --- a/tests/CommunityToolkit.HighPerformance.UnitTests/Enumerables/Test_RefEnumerable{T}.cs +++ b/tests/CommunityToolkit.HighPerformance.UnitTests/Enumerables/Test_RefEnumerable{T}.cs @@ -32,7 +32,7 @@ public void Test_RefEnumerable_DangerousCreate_Ok(int length, int step, int[] va int[] result = enumerable.ToArray(); - CollectionAssert.AreEqual(result, values); + CollectionAssert.AreEqual(values, result); } [TestMethod] @@ -64,7 +64,7 @@ public void Test_RefEnumerable_Indexer(int step, int[] values) for (int i = 0; i < enumerable.Length; i++) { - Assert.AreEqual(enumerable[i], values[i]); + Assert.AreEqual(values[i], enumerable[i]); } } diff --git a/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_ArrayExtensions.2D.cs b/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_ArrayExtensions.2D.cs index 5d41cf9b0..1bf1f60f5 100644 --- a/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_ArrayExtensions.2D.cs +++ b/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_ArrayExtensions.2D.cs @@ -174,10 +174,10 @@ public void Test_ArrayExtensions_2D_GetRow_Rectangle() } // Check that RefEnumerable.ToArray() works correctly - CollectionAssert.AreEqual(array.GetRow(1).ToArray(), new[] { 5, 6, 7, 8 }); + CollectionAssert.AreEqual(new[] { 5, 6, 7, 8 }, array.GetRow(1).ToArray()); // Test an empty array - Assert.AreSame(new int[1, 0].GetRow(0).ToArray(), Array.Empty()); + Assert.AreSame(Array.Empty(), new int[1, 0].GetRow(0).ToArray()); _ = Assert.ThrowsException(() => array.GetRow(-1)); _ = Assert.ThrowsException(() => array.GetRow(3)); @@ -202,7 +202,7 @@ public void Test_ArrayExtensions_2D_GetColumn_Rectangle() Assert.IsTrue(Unsafe.AreSame(ref value, ref array[i++, 1])); } - CollectionAssert.AreEqual(array.GetColumn(1).ToArray(), new[] { 2, 6, 10 }); + CollectionAssert.AreEqual(new[] { 2, 6, 10 }, array.GetColumn(1).ToArray()); _ = Assert.ThrowsException(() => array.GetColumn(-1)); _ = Assert.ThrowsException(() => array.GetColumn(4)); @@ -242,7 +242,7 @@ public void Test_ArrayExtensions_2D_GetRowOrColumn_Helpers() { 13, 14, 15, 16 } }; - CollectionAssert.AreEqual(array, expected); + CollectionAssert.AreEqual(expected, array); // Same as before, but this time we fill a column with a value array.GetColumn(2).Fill(42); @@ -255,7 +255,7 @@ public void Test_ArrayExtensions_2D_GetRowOrColumn_Helpers() { 13, 14, 42, 16 } }; - CollectionAssert.AreEqual(array, expected); + CollectionAssert.AreEqual(expected, array); int[] copy = new int[4]; @@ -264,14 +264,14 @@ public void Test_ArrayExtensions_2D_GetRowOrColumn_Helpers() int[] result = { 9, 10, 42, 12 }; - CollectionAssert.AreEqual(copy, result); + CollectionAssert.AreEqual(result, copy); // Same as above, but copying from a column (so we test non contiguous sequences too) array.GetColumn(1).CopyTo(copy); result = new[] { 2, 0, 10, 14 }; - CollectionAssert.AreEqual(copy, result); + CollectionAssert.AreEqual(result, copy); // Some invalid attempts to copy to an empty span or sequence _ = Assert.ThrowsException(() => array.GetRow(0).CopyTo(default(RefEnumerable))); @@ -286,7 +286,7 @@ public void Test_ArrayExtensions_2D_GetRowOrColumn_Helpers() result = new[] { 9, 10, 42, 12 }; - CollectionAssert.AreEqual(copy, result); + CollectionAssert.AreEqual(result, copy); // Also fill a row and then further down clear a column (trying out all possible combinations) array.GetRow(2).Fill(99); @@ -299,7 +299,7 @@ public void Test_ArrayExtensions_2D_GetRowOrColumn_Helpers() { 13, 14, 42, 16 } }; - CollectionAssert.AreEqual(array, expected); + CollectionAssert.AreEqual(expected, array); array.GetColumn(2).Clear(); @@ -311,7 +311,7 @@ public void Test_ArrayExtensions_2D_GetRowOrColumn_Helpers() { 13, 14, 0, 16 } }; - CollectionAssert.AreEqual(array, expected); + CollectionAssert.AreEqual(expected, array); } [TestMethod] @@ -336,13 +336,13 @@ public void Test_ArrayExtensions_2D_ReadOnlyGetRowOrColumn_Helpers() int[] result = { 9, 10, 11, 12 }; - CollectionAssert.AreEqual(copy, result); + CollectionAssert.AreEqual(result, copy); span2D.GetColumn(1).CopyTo(copy); result = new[] { 2, 6, 10, 14 }; - CollectionAssert.AreEqual(copy, result); + CollectionAssert.AreEqual(result, copy); _ = Assert.ThrowsException(() => ((ReadOnlySpan2D)array).GetRow(0).CopyTo(default(RefEnumerable))); _ = Assert.ThrowsException(() => ((ReadOnlySpan2D)array).GetRow(0).CopyTo(default(Span))); @@ -355,7 +355,7 @@ public void Test_ArrayExtensions_2D_ReadOnlyGetRowOrColumn_Helpers() result = new[] { 9, 10, 11, 12 }; - CollectionAssert.AreEqual(copy, result); + CollectionAssert.AreEqual(result, copy); } [TestMethod] @@ -391,7 +391,7 @@ public void Test_ArrayExtensions_2D_RefEnumerable_Misc() { 0, 8, 0, 16 } }; - CollectionAssert.AreEqual(array2, result); + CollectionAssert.AreEqual(result, array2); // Test a valid and an invalid TryCopyTo call with the RefEnumerable overload bool shouldBeTrue = array1.GetRow(0).TryCopyTo(array2.GetColumn(0)); @@ -405,7 +405,7 @@ public void Test_ArrayExtensions_2D_RefEnumerable_Misc() { 4, 8, 0, 16 } }; - CollectionAssert.AreEqual(array2, result); + CollectionAssert.AreEqual(result, array2); Assert.IsTrue(shouldBeTrue); Assert.IsFalse(shouldBeFalse); @@ -428,7 +428,7 @@ public void Test_ArrayExtensions_2D_AsSpan_Empty() Span span = array.AsSpan(); // Check that the empty array was loaded properly - Assert.AreEqual(span.Length, array.Length); + Assert.AreEqual(array.Length, span.Length); Assert.IsTrue(span.IsEmpty); } @@ -445,7 +445,7 @@ public void Test_ArrayExtensions_2D_AsSpan_Populated() Span span = array.AsSpan(); // Test the total length of the span - Assert.AreEqual(span.Length, array.Length); + Assert.AreEqual(array.Length, span.Length); ref int r0 = ref array[0, 0]; ref int r1 = ref span[0]; diff --git a/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_ArrayPoolExtensions.cs b/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_ArrayPoolExtensions.cs index a215c082e..46e951ad3 100644 --- a/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_ArrayPoolExtensions.cs +++ b/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_ArrayPoolExtensions.cs @@ -41,7 +41,7 @@ public void Test_ArrayPoolExtensions_Resize_SameSize() ArrayPool.Shared.Resize(ref array, array.Length); - Assert.AreSame(array, backup); + Assert.AreSame(backup, array); } [TestMethod] @@ -54,7 +54,7 @@ public void Test_ArrayPoolExtensions_Resize_Expand() ArrayPool.Shared.Resize(ref array, 32); - Assert.AreNotSame(array, backup); + Assert.AreNotSame(backup, array); Assert.IsTrue(array.Length >= 32); Assert.IsTrue(array.AsSpan(0, 16).ToArray().All(i => i == 7)); } @@ -69,7 +69,7 @@ public void Test_ArrayPoolExtensions_Resize_Shrink() ArrayPool.Shared.Resize(ref array, 16); - Assert.AreNotSame(array, backup); + Assert.AreNotSame(backup, array); Assert.IsTrue(array.Length >= 16); Assert.IsTrue(array.AsSpan(0, 16).ToArray().All(i => i == 7)); } @@ -84,7 +84,7 @@ public void Test_ArrayPoolExtensions_Resize_Clear() ArrayPool.Shared.Resize(ref array, 0, true); - Assert.AreNotSame(array, backup); + Assert.AreNotSame(backup, array); Assert.IsTrue(backup.AsSpan(0, 16).ToArray().All(i => i == 0)); } diff --git a/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_BoolExtensions.cs b/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_BoolExtensions.cs index acb0efd61..15b8df9a0 100644 --- a/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_BoolExtensions.cs +++ b/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_BoolExtensions.cs @@ -31,7 +31,7 @@ public void Test_BoolExtensions_False() [DataRow(false, 0)] public void Test_BoolExtensions_ToBitwiseMask32(bool value, int result) { - Assert.AreEqual(value.ToBitwiseMask32(), result); + Assert.AreEqual(result, value.ToBitwiseMask32()); } [TestMethod] @@ -39,6 +39,6 @@ public void Test_BoolExtensions_ToBitwiseMask32(bool value, int result) [DataRow(false, 0)] public void Test_BoolExtensions_ToBitwiseMask64(bool value, long result) { - Assert.AreEqual(value.ToBitwiseMask64(), result); + Assert.AreEqual(result, value.ToBitwiseMask64()); } } diff --git a/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_IMemoryOwnerExtensions.cs b/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_IMemoryOwnerExtensions.cs index 42db952ca..987f49b11 100644 --- a/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_IMemoryOwnerExtensions.cs +++ b/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_IMemoryOwnerExtensions.cs @@ -19,8 +19,8 @@ public void Test_IMemoryOwnerExtensions_EmptyIMemoryOwnerStream() Stream stream = buffer.AsStream(); Assert.IsNotNull(stream); - Assert.AreEqual(buffer.Length, 0); - Assert.AreEqual(stream.Length, 0); + Assert.AreEqual(0, buffer.Length); + Assert.AreEqual(0, stream.Length); Assert.IsTrue(stream.CanWrite); } @@ -32,7 +32,7 @@ public void Test_MemoryExtensions_IMemoryOwnerStream() Stream stream = buffer.AsStream(); Assert.IsNotNull(stream); - Assert.AreEqual(stream.Length, buffer.Length); + Assert.AreEqual(buffer.Length, stream.Length); Assert.IsTrue(stream.CanWrite); } @@ -50,13 +50,13 @@ public void Test_MemoryExtensions_IMemoryOwnerStream_DoesNotAlterExistingData() Stream stream = buffer.AsStream(); Assert.IsNotNull(stream); - Assert.AreEqual(stream.Length, buffer.Length); + Assert.AreEqual(buffer.Length, stream.Length); Assert.IsTrue(stream.CanWrite); // Validate that creating the stream doesn't alter the underlying buffer for (int i = 0; i < buffer.Length; i++) { - Assert.AreEqual(buffer.Span[i], unchecked((byte)(i & byte.MaxValue))); + Assert.AreEqual(unchecked((byte)(i & byte.MaxValue)), buffer.Span[i]); } } } diff --git a/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_MemoryExtensions.cs b/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_MemoryExtensions.cs index 3c33ee981..6bf852445 100644 --- a/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_MemoryExtensions.cs +++ b/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_MemoryExtensions.cs @@ -61,13 +61,13 @@ public void Test_MemoryExtensions_Cast_TooShort() Memory m2 = new byte[13]; Memory mc2 = m2.Cast(); - Assert.AreEqual(mc2.Length, 3); + Assert.AreEqual(3, mc2.Length); // 16 - 5 = 11 ---> 11 / sizeof(int) = 2 Memory m3 = new byte[16].AsMemory(5); Memory mc3 = m3.Cast(); - Assert.AreEqual(mc3.Length, 2); + Assert.AreEqual(2, mc3.Length); } [TestMethod] @@ -77,7 +77,7 @@ public void Test_MemoryExtensions_FromArray_CastFromByte() Memory memoryOfBytes = new byte[128]; Memory memoryOfFloats = memoryOfBytes.Cast(); - Assert.AreEqual(memoryOfFloats.Length, 128 / sizeof(float)); + Assert.AreEqual(128 / sizeof(float), memoryOfFloats.Length); Span spanOfBytes = memoryOfBytes.Span; Span spanOfFloats = memoryOfFloats.Span; @@ -99,7 +99,7 @@ public void Test_MemoryExtensions_FromArray_CastToByte() Memory memoryOfFloats = new float[128]; Memory memoryOfBytes = memoryOfFloats.Cast(); - Assert.AreEqual(memoryOfBytes.Length, 128 * sizeof(float)); + Assert.AreEqual(128 * sizeof(float), memoryOfBytes.Length); Span spanOfFloats = memoryOfFloats.Span; Span spanOfBytes = memoryOfBytes.Span; @@ -119,7 +119,7 @@ public void Test_MemoryExtensions_FromArray_CastToShort() Memory memoryOfFloats = new float[128]; Memory memoryOfShorts = memoryOfFloats.Cast(); - Assert.AreEqual(memoryOfShorts.Length, 128 * sizeof(float) / sizeof(short)); + Assert.AreEqual(128 * sizeof(float) / sizeof(short), memoryOfShorts.Length); Span spanOfFloats = memoryOfFloats.Span; Span spanOfShorts = memoryOfShorts.Span; @@ -148,9 +148,9 @@ public void Test_MemoryExtensions_FromArray_CastFromByteAndBack() // Here we get the array from the final memory and check that it does exist and // the associated parameters match the ones we'd expect here (same length, offset of 0). Assert.IsTrue(MemoryMarshal.TryGetArray(memoryBack, out ArraySegment segment)); - Assert.AreSame(segment.Array!, data); - Assert.AreEqual(segment.Offset, 0); - Assert.AreEqual(segment.Count, data.Length); + Assert.AreSame(data, segment.Array!); + Assert.AreEqual(0, segment.Offset); + Assert.AreEqual(data.Length, segment.Count); Assert.IsTrue(memoryOfBytes.Equals(memoryBack)); @@ -174,12 +174,12 @@ public void Test_MemoryExtensions_Cast_TooShort_WithSlice() Memory m2 = new byte[20].AsMemory().Slice(4, 13); Memory mc2 = m2.Cast(); - Assert.AreEqual(mc2.Length, 3); + Assert.AreEqual(3, mc2.Length); Memory m3 = new byte[16].AsMemory().Slice(5); Memory mc3 = m3.Cast(); - Assert.AreEqual(mc3.Length, 2); + Assert.AreEqual(2, mc3.Length); } [TestMethod] @@ -190,7 +190,7 @@ public void Test_MemoryExtensions_FromArray_CastFromByte_WithSlice() Memory memoryOfBytes = new byte[512].AsMemory().Slice(128, 128); Memory memoryOfFloats = memoryOfBytes.Cast(); - Assert.AreEqual(memoryOfFloats.Length, 128 / sizeof(float)); + Assert.AreEqual(128 / sizeof(float), memoryOfFloats.Length); Span spanOfBytes = memoryOfBytes.Span; Span spanOfFloats = memoryOfFloats.Span; @@ -208,7 +208,7 @@ public void Test_MemoryExtensions_FromArray_CastToByte_WithSlice() Memory memoryOfFloats = new float[512].AsMemory().Slice(128, 128); Memory memoryOfBytes = memoryOfFloats.Cast(); - Assert.AreEqual(memoryOfBytes.Length, 128 * sizeof(float)); + Assert.AreEqual(128 * sizeof(float), memoryOfBytes.Length); Span spanOfFloats = memoryOfFloats.Span; Span spanOfBytes = memoryOfBytes.Span; @@ -227,7 +227,7 @@ public void Test_MemoryExtensions_FromArray_CastToShort_WithSlice() Memory memoryOfFloats = new float[512].AsMemory().Slice(128, 128); Memory memoryOfShorts = memoryOfFloats.Cast(); - Assert.AreEqual(memoryOfShorts.Length, 128 * sizeof(float) / sizeof(short)); + Assert.AreEqual(128 * sizeof(float) / sizeof(short), memoryOfShorts.Length); Span spanOfFloats = memoryOfFloats.Span; Span spanOfShorts = memoryOfShorts.Span; @@ -251,9 +251,9 @@ public void Test_MemoryExtensions_FromArray_CastFromByteAndBack_WithSlice() // Here we now also have to validate the starting offset from the extracted array Assert.IsTrue(MemoryMarshal.TryGetArray(memoryBack, out ArraySegment segment)); - Assert.AreSame(segment.Array!, data); - Assert.AreEqual(segment.Offset, 128); - Assert.AreEqual(segment.Count, 128); + Assert.AreSame(data, segment.Array!); + Assert.AreEqual(128, segment.Offset); + Assert.AreEqual(128, segment.Count); Assert.IsTrue(memoryOfBytes.Equals(memoryBack)); @@ -273,7 +273,7 @@ public void Test_MemoryExtensions_FromMemoryManager_CastFromByte() Memory memoryOfBytes = new ArrayMemoryManager(128); Memory memoryOfFloats = memoryOfBytes.Cast(); - Assert.AreEqual(memoryOfFloats.Length, 128 / sizeof(float)); + Assert.AreEqual(128 / sizeof(float), memoryOfFloats.Length); Span spanOfBytes = memoryOfBytes.Span; Span spanOfFloats = memoryOfFloats.Span; @@ -291,7 +291,7 @@ public void Test_MemoryExtensions_FromMemoryManager_CastToByte() Memory memoryOfFloats = new ArrayMemoryManager(128); Memory memoryOfBytes = memoryOfFloats.Cast(); - Assert.AreEqual(memoryOfBytes.Length, 128 * sizeof(float)); + Assert.AreEqual(128 * sizeof(float), memoryOfBytes.Length); Span spanOfFloats = memoryOfFloats.Span; Span spanOfBytes = memoryOfBytes.Span; @@ -309,7 +309,7 @@ public void Test_MemoryExtensions_FromMemoryManager_CastToShort() Memory memoryOfFloats = new ArrayMemoryManager(128); Memory memoryOfShorts = memoryOfFloats.Cast(); - Assert.AreEqual(memoryOfShorts.Length, 128 * sizeof(float) / sizeof(short)); + Assert.AreEqual(128 * sizeof(float) / sizeof(short), memoryOfShorts.Length); Span spanOfFloats = memoryOfFloats.Span; Span spanOfShorts = memoryOfShorts.Span; @@ -334,9 +334,9 @@ public void Test_MemoryExtensions_FromMemoryManager_CastFromByteAndBack() // Here we expect to get back the original memory manager, due to the same optimization we // checked for when using an array. We need to check they're the same, and the other parameters. Assert.IsTrue(MemoryMarshal.TryGetMemoryManager>(memoryBack, out ArrayMemoryManager? manager, out int start, out int length)); - Assert.AreSame(manager!, data); - Assert.AreEqual(start, 0); - Assert.AreEqual(length, 128); + Assert.AreSame(data, manager!); + Assert.AreEqual(0, start); + Assert.AreEqual(128, length); Assert.IsTrue(memoryOfBytes.Equals(memoryBack)); @@ -353,7 +353,7 @@ public void Test_MemoryExtensions_FromMemoryManager_CastFromByte_WithSlice() Memory memoryOfBytes = new ArrayMemoryManager(512).Memory.Slice(128, 128); Memory memoryOfFloats = memoryOfBytes.Cast(); - Assert.AreEqual(memoryOfFloats.Length, 128 / sizeof(float)); + Assert.AreEqual(128 / sizeof(float), memoryOfFloats.Length); Span spanOfBytes = memoryOfBytes.Span; Span spanOfFloats = memoryOfFloats.Span; @@ -371,7 +371,7 @@ public void Test_MemoryExtensions_FromMemoryManager_CastToByte_WithSlice() Memory memoryOfFloats = new ArrayMemoryManager(512).Memory.Slice(128, 128); Memory memoryOfBytes = memoryOfFloats.Cast(); - Assert.AreEqual(memoryOfBytes.Length, 128 * sizeof(float)); + Assert.AreEqual(128 * sizeof(float), memoryOfBytes.Length); Span spanOfFloats = memoryOfFloats.Span; Span spanOfBytes = memoryOfBytes.Span; @@ -389,7 +389,7 @@ public void Test_MemoryExtensions_FromMemoryManager_CastToShort_WithSlice() Memory memoryOfFloats = new ArrayMemoryManager(512).Memory.Slice(128, 128); Memory memoryOfShorts = memoryOfFloats.Cast(); - Assert.AreEqual(memoryOfShorts.Length, 128 * sizeof(float) / sizeof(short)); + Assert.AreEqual(128 * sizeof(float) / sizeof(short), memoryOfShorts.Length); Span spanOfFloats = memoryOfFloats.Span; Span spanOfShorts = memoryOfShorts.Span; @@ -413,9 +413,9 @@ public void Test_MemoryExtensions_FromMemoryManager_CastFromByteAndBack_WithSlic // Here we also need to validate that the offset was maintained Assert.IsTrue(MemoryMarshal.TryGetMemoryManager>(memoryBack, out ArrayMemoryManager? manager, out int start, out int length)); - Assert.AreSame(manager!, data); - Assert.AreEqual(start, 128); - Assert.AreEqual(length, 128); + Assert.AreSame(data, manager!); + Assert.AreEqual(128, start); + Assert.AreEqual(128, length); Assert.IsTrue(memoryOfBytes.Equals(memoryBack)); @@ -494,9 +494,9 @@ public void Test_MemoryExtensions_FromString_CastFromByteAndBack() // Get the original string back (to validate the optimization too) and check the params Assert.IsTrue(MemoryMarshal.TryGetString(memoryOfChars, out string? text, out int start, out int length)); - Assert.AreSame(text!, data); - Assert.AreEqual(start, 0); - Assert.AreEqual(length, data.Length); + Assert.AreSame(data, text!); + Assert.AreEqual(0, start); + Assert.AreEqual(data.Length, length); Assert.IsTrue(memoryOfChars.Equals(memoryBack)); @@ -553,7 +553,7 @@ public void Test_MemoryExtensions_EmptyMemoryStream() Stream stream = memory.AsStream(); Assert.IsNotNull(stream); - Assert.AreEqual(stream.Length, memory.Length); + Assert.AreEqual(memory.Length, stream.Length); Assert.IsTrue(stream.CanWrite); } @@ -565,7 +565,7 @@ public void Test_MemoryExtensions_MemoryStream() Stream stream = memory.AsStream(); Assert.IsNotNull(stream); - Assert.AreEqual(stream.Length, memory.Length); + Assert.AreEqual(memory.Length, stream.Length); Assert.IsTrue(stream.CanWrite); } diff --git a/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_NullableExtensions.cs b/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_NullableExtensions.cs index e66d03ea4..5e050c8fa 100644 --- a/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_NullableExtensions.cs +++ b/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_NullableExtensions.cs @@ -23,11 +23,11 @@ static void Test(T before, T after) T? nullable = before; ref T reference = ref nullable.DangerousGetValueOrDefaultReference(); - Assert.AreEqual(nullable!.Value, before); + Assert.AreEqual(before, nullable!.Value); reference = after; - Assert.AreEqual(nullable.Value, after); + Assert.AreEqual(after, nullable.Value); } Test(0, 42); @@ -49,11 +49,11 @@ static void Test(T before, T after) ref T reference = ref nullable.DangerousGetValueOrNullReference(); Assert.IsFalse(Unsafe.IsNullRef(ref reference)); - Assert.AreEqual(nullable!.Value, before); + Assert.AreEqual(before, nullable!.Value); reference = after; - Assert.AreEqual(nullable.Value, after); + Assert.AreEqual(after, nullable.Value); } Test(0, 42); diff --git a/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_ReadOnlyMemoryExtensions.cs b/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_ReadOnlyMemoryExtensions.cs index 119d8a83f..d031428d1 100644 --- a/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_ReadOnlyMemoryExtensions.cs +++ b/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_ReadOnlyMemoryExtensions.cs @@ -19,7 +19,7 @@ public void Test_ReadOnlyMemoryExtensions_EmptyMemoryStream() Stream stream = memory.AsStream(); Assert.IsNotNull(stream); - Assert.AreEqual(stream.Length, memory.Length); + Assert.AreEqual(memory.Length, stream.Length); Assert.IsFalse(stream.CanWrite); } @@ -31,7 +31,7 @@ public void Test_ReadOnlyMemoryExtensions_MemoryStream() Stream stream = memory.AsStream(); Assert.IsNotNull(stream); - Assert.AreEqual(stream.Length, memory.Length); + Assert.AreEqual(memory.Length, stream.Length); Assert.IsFalse(stream.CanWrite); } } diff --git a/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_ReadOnlySpanExtensions.Count.cs b/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_ReadOnlySpanExtensions.Count.cs index 346e801f9..e43417745 100644 --- a/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_ReadOnlySpanExtensions.Count.cs +++ b/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_ReadOnlySpanExtensions.Count.cs @@ -89,7 +89,7 @@ public void Test_ReadOnlySpanExtensions_RandomCountManaged() int result = data.Count(value); int expected = CountWithForeach(data, value); - Assert.AreEqual(result, expected, $"Failed {typeof(Int)} test with count {count}: got {result} instead of {expected}"); + Assert.AreEqual(expected, result, $"Failed {typeof(Int)} test with count {count}: got {result} instead of {expected}"); } } @@ -181,7 +181,7 @@ private static void TestForType(T value, Func> int result = data.GetSpan().Count(value); int expected = CountWithForeach(data.GetSpan(), value); - Assert.AreEqual(result, expected, $"Failed {typeof(T)} test with count {count}: got {result} instead of {expected}"); + Assert.AreEqual(expected, result, $"Failed {typeof(T)} test with count {count}: got {result} instead of {expected}"); } } diff --git a/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_ReadOnlySpanExtensions.cs b/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_ReadOnlySpanExtensions.cs index 2ee9962b8..2be3c7840 100644 --- a/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_ReadOnlySpanExtensions.cs +++ b/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_ReadOnlySpanExtensions.cs @@ -218,7 +218,7 @@ public void Test_ReadOnlySpanExtensions_Tokenize_Empty() string[]? tokens = text.Split(','); - CollectionAssert.AreEqual(result, tokens); + CollectionAssert.AreEqual(tokens, result); } [TestMethod] @@ -235,7 +235,7 @@ public void Test_ReadOnlySpanExtensions_Tokenize_Comma() string[]? tokens = text.Split(','); - CollectionAssert.AreEqual(result, tokens); + CollectionAssert.AreEqual(tokens, result); } [TestMethod] @@ -252,7 +252,7 @@ public void Test_ReadOnlySpanExtensions_Tokenize_CommaWithMissingValues() string[]? tokens = text.Split(','); - CollectionAssert.AreEqual(result, tokens); + CollectionAssert.AreEqual(tokens, result); } [TestMethod] @@ -275,7 +275,7 @@ public void Test_ReadOnlySpanExtensions_CopyTo_RefEnumerable() { 0, 44, 0, 0, 0 } }; - CollectionAssert.AreEqual(array, result); + CollectionAssert.AreEqual(result, array); // Try to copy to a valid row and an invalid column (too short for the source span) bool shouldBeTrue = values1.TryCopyTo(array.GetRow(2)); @@ -292,6 +292,6 @@ public void Test_ReadOnlySpanExtensions_CopyTo_RefEnumerable() { 0, 44, 0, 0, 0 } }; - CollectionAssert.AreEqual(array, result); + CollectionAssert.AreEqual(result, array); } } diff --git a/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_SpanExtensions.cs b/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_SpanExtensions.cs index 8baa1f295..4d25fa0e8 100644 --- a/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_SpanExtensions.cs +++ b/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_SpanExtensions.cs @@ -177,7 +177,7 @@ public void Test_SpanExtensions_CopyTo_RefEnumerable() { 0, 44, 0, 0, 0 } }; - CollectionAssert.AreEqual(array, result); + CollectionAssert.AreEqual(result, array); // Try to copy to a valid row and an invalid column (too short for the source span) bool shouldBeTrue = values1.AsSpan().TryCopyTo(array.GetRow(2)); @@ -194,6 +194,6 @@ public void Test_SpanExtensions_CopyTo_RefEnumerable() { 0, 44, 0, 0, 0 } }; - CollectionAssert.AreEqual(array, result); + CollectionAssert.AreEqual(result, array); } } diff --git a/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_SpinLockExtensions.cs b/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_SpinLockExtensions.cs index 6857393fe..f9cddcddf 100644 --- a/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_SpinLockExtensions.cs +++ b/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_SpinLockExtensions.cs @@ -32,7 +32,7 @@ public unsafe void Test_ArrayExtensions_Pointer() } }); - Assert.AreEqual(sum, 1000 * 10); + Assert.AreEqual(1000 * 10, sum); } #if NET7_0_OR_GREATER @@ -54,7 +54,7 @@ public void Test_ArrayExtensions_Ref() } }); - Assert.AreEqual(sum, 1000 * 10); + Assert.AreEqual(1000 * 10, sum); } /// diff --git a/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_StreamExtensions.cs b/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_StreamExtensions.cs index 4977176ef..0aca50cd1 100644 --- a/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_StreamExtensions.cs +++ b/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_StreamExtensions.cs @@ -23,7 +23,7 @@ public void Test_StreamExtensions_ReadWrite() stream.Write(3.14f); stream.Write(unchecked(uint.MaxValue * 324823489204ul)); - Assert.AreEqual(stream.Position, 17); + Assert.AreEqual(17, stream.Position); _ = Assert.ThrowsException(() => stream.Write(long.MaxValue)); diff --git a/tests/CommunityToolkit.HighPerformance.UnitTests/Helpers/Test_BitHelper.cs b/tests/CommunityToolkit.HighPerformance.UnitTests/Helpers/Test_BitHelper.cs index 3df976c4e..262956407 100644 --- a/tests/CommunityToolkit.HighPerformance.UnitTests/Helpers/Test_BitHelper.cs +++ b/tests/CommunityToolkit.HighPerformance.UnitTests/Helpers/Test_BitHelper.cs @@ -193,8 +193,8 @@ public void Test_BitHelper_SetRange_UInt32(byte start, byte length, uint flags) uint extracted = BitHelper.ExtractRange(result, start, length); uint restored = BitHelper.SetRange(result, start, length, backup); - Assert.AreEqual(extracted, flags); - Assert.AreEqual(restored, value); + Assert.AreEqual(flags, extracted); + Assert.AreEqual(value, restored); } [TestMethod] @@ -301,7 +301,7 @@ public void Test_BitHelper_SetRange_UInt64(byte start, byte length, ulong flags) ulong extracted = BitHelper.ExtractRange(result, start, length); ulong restored = BitHelper.SetRange(result, start, length, backup); - Assert.AreEqual(extracted, flags); - Assert.AreEqual(restored, value); + Assert.AreEqual(flags, extracted); + Assert.AreEqual(value, restored); } } diff --git a/tests/CommunityToolkit.HighPerformance.UnitTests/Helpers/Test_ObjectMarshal.cs b/tests/CommunityToolkit.HighPerformance.UnitTests/Helpers/Test_ObjectMarshal.cs index 924bdc6bb..89e344406 100644 --- a/tests/CommunityToolkit.HighPerformance.UnitTests/Helpers/Test_ObjectMarshal.cs +++ b/tests/CommunityToolkit.HighPerformance.UnitTests/Helpers/Test_ObjectMarshal.cs @@ -107,7 +107,7 @@ private static void Test(T value) success = obj.TryUnbox(out decimal test); Assert.IsFalse(success); - Assert.AreEqual(test, default); + Assert.AreEqual(default, test); result = ObjectMarshal.DangerousUnbox(obj); diff --git a/tests/CommunityToolkit.HighPerformance.UnitTests/Helpers/Test_ParallelHelper.ForEach.In.cs b/tests/CommunityToolkit.HighPerformance.UnitTests/Helpers/Test_ParallelHelper.ForEach.In.cs index 4c393c210..f9755a8a8 100644 --- a/tests/CommunityToolkit.HighPerformance.UnitTests/Helpers/Test_ParallelHelper.ForEach.In.cs +++ b/tests/CommunityToolkit.HighPerformance.UnitTests/Helpers/Test_ParallelHelper.ForEach.In.cs @@ -31,7 +31,7 @@ public unsafe void Test_ParallelHelper_ForEach_In() expected += n; } - Assert.AreEqual(sum, expected, $"The sum doesn't match, was {sum} instead of {expected}"); + Assert.AreEqual(expected, sum, $"The sum doesn't match, was {sum} instead of {expected}"); } } diff --git a/tests/CommunityToolkit.HighPerformance.UnitTests/Helpers/Test_ParallelHelper.ForEach.In2D.cs b/tests/CommunityToolkit.HighPerformance.UnitTests/Helpers/Test_ParallelHelper.ForEach.In2D.cs index 734377225..e43e41416 100644 --- a/tests/CommunityToolkit.HighPerformance.UnitTests/Helpers/Test_ParallelHelper.ForEach.In2D.cs +++ b/tests/CommunityToolkit.HighPerformance.UnitTests/Helpers/Test_ParallelHelper.ForEach.In2D.cs @@ -32,9 +32,9 @@ public unsafe void Test_ParallelHelper_ForEach_In2D( // Create a memory wrapping the random array with the given parameters ReadOnlyMemory2D memory = data.AsMemory2D(row, column, height, width); - Assert.AreEqual(memory.Length, height * width); - Assert.AreEqual(memory.Height, height); - Assert.AreEqual(memory.Width, width); + Assert.AreEqual(height * width, memory.Length); + Assert.AreEqual(height, memory.Height); + Assert.AreEqual(width, memory.Width); int sum = 0; @@ -50,7 +50,7 @@ public unsafe void Test_ParallelHelper_ForEach_In2D( expected += n; } - Assert.AreEqual(sum, expected, $"The sum doesn't match, was {sum} instead of {expected}"); + Assert.AreEqual(expected, sum, $"The sum doesn't match, was {sum} instead of {expected}"); } /// diff --git a/tests/CommunityToolkit.HighPerformance.UnitTests/Helpers/Test_ParallelHelper.ForEach.Ref2D.cs b/tests/CommunityToolkit.HighPerformance.UnitTests/Helpers/Test_ParallelHelper.ForEach.Ref2D.cs index c8c847487..9dab39d56 100644 --- a/tests/CommunityToolkit.HighPerformance.UnitTests/Helpers/Test_ParallelHelper.ForEach.Ref2D.cs +++ b/tests/CommunityToolkit.HighPerformance.UnitTests/Helpers/Test_ParallelHelper.ForEach.Ref2D.cs @@ -37,13 +37,13 @@ public void Test_ParallelHelper_ForEach_Ref2D( Memory2D memory = data.AsMemory2D(row, column, height, width); - Assert.AreEqual(memory.Length, height * width); - Assert.AreEqual(memory.Height, height); - Assert.AreEqual(memory.Width, width); + Assert.AreEqual(height * width, memory.Length); + Assert.AreEqual(height, memory.Height); + Assert.AreEqual(width, memory.Width); // Do the same computation in parallel, then compare the two arrays ParallelHelper.ForEach(memory, new Multiplier(397)); - CollectionAssert.AreEqual(data, copy); + CollectionAssert.AreEqual(copy, data); } } diff --git a/tests/CommunityToolkit.HighPerformance.UnitTests/Helpers/Test_ParallelHelper.ThrowExceptions.cs b/tests/CommunityToolkit.HighPerformance.UnitTests/Helpers/Test_ParallelHelper.ThrowExceptions.cs index 1b78a9fe4..734f1e381 100644 --- a/tests/CommunityToolkit.HighPerformance.UnitTests/Helpers/Test_ParallelHelper.ThrowExceptions.cs +++ b/tests/CommunityToolkit.HighPerformance.UnitTests/Helpers/Test_ParallelHelper.ThrowExceptions.cs @@ -33,7 +33,7 @@ from method in typeof(ParallelHelper).GetMethods() normalParams.All(p => p.ParameterType == typeof(int)) select normalParams[2].Name).Single(); - Assert.AreEqual(e.ParamName, name); + Assert.AreEqual(name, e.ParamName); return; } @@ -63,7 +63,7 @@ from method in typeof(ParallelHelper).GetMethods() normalParams.All(p => p.ParameterType == typeof(int)) select normalParams[0].Name).Single(); - Assert.AreEqual(e.ParamName, name); + Assert.AreEqual(name, e.ParamName); return; } @@ -93,7 +93,7 @@ from method in typeof(ParallelHelper).GetMethods() normalParams.All(p => p.ParameterType == typeof(int)) select normalParams[0].Name).Single(); - Assert.AreEqual(e.ParamName, name); + Assert.AreEqual(name, e.ParamName); return; } @@ -123,7 +123,7 @@ from method in typeof(ParallelHelper).GetMethods() normalParams.All(p => p.ParameterType == typeof(int)) select normalParams[2].Name).Single(); - Assert.AreEqual(e.ParamName, name); + Assert.AreEqual(name, e.ParamName); return; } diff --git a/tests/CommunityToolkit.HighPerformance.UnitTests/Memory/Test_Memory2D{T}.cs b/tests/CommunityToolkit.HighPerformance.UnitTests/Memory/Test_Memory2D{T}.cs index d1e365876..b51e56549 100644 --- a/tests/CommunityToolkit.HighPerformance.UnitTests/Memory/Test_Memory2D{T}.cs +++ b/tests/CommunityToolkit.HighPerformance.UnitTests/Memory/Test_Memory2D{T}.cs @@ -19,30 +19,30 @@ public void Test_Memory2DT_Empty() Memory2D empty1 = default; Assert.IsTrue(empty1.IsEmpty); - Assert.AreEqual(empty1.Length, 0); - Assert.AreEqual(empty1.Width, 0); - Assert.AreEqual(empty1.Height, 0); + Assert.AreEqual(0, empty1.Length); + Assert.AreEqual(0, empty1.Width); + Assert.AreEqual(0, empty1.Height); Memory2D empty2 = Memory2D.Empty; Assert.IsTrue(empty2.IsEmpty); - Assert.AreEqual(empty2.Length, 0); - Assert.AreEqual(empty2.Width, 0); - Assert.AreEqual(empty2.Height, 0); + Assert.AreEqual(0, empty2.Length); + Assert.AreEqual(0, empty2.Width); + Assert.AreEqual(0, empty2.Height); Memory2D empty3 = new int[4, 0]; Assert.IsTrue(empty3.IsEmpty); - Assert.AreEqual(empty3.Length, 0); - Assert.AreEqual(empty3.Width, 0); - Assert.AreEqual(empty3.Height, 4); + Assert.AreEqual(0, empty3.Length); + Assert.AreEqual(0, empty3.Width); + Assert.AreEqual(4, empty3.Height); Memory2D empty4 = new int[0, 7]; Assert.IsTrue(empty4.IsEmpty); - Assert.AreEqual(empty4.Length, 0); - Assert.AreEqual(empty4.Width, 7); - Assert.AreEqual(empty4.Height, 0); + Assert.AreEqual(0, empty4.Length); + Assert.AreEqual(7, empty4.Width); + Assert.AreEqual(0, empty4.Height); } [TestMethod] @@ -58,11 +58,11 @@ public void Test_Memory2DT_Array1DConstructor() Memory2D memory2d = new(array, 1, 2, 2, 1); Assert.IsFalse(memory2d.IsEmpty); - Assert.AreEqual(memory2d.Length, 4); - Assert.AreEqual(memory2d.Width, 2); - Assert.AreEqual(memory2d.Height, 2); - Assert.AreEqual(memory2d.Span[0, 0], 2); - Assert.AreEqual(memory2d.Span[1, 1], 6); + Assert.AreEqual(4, memory2d.Length); + Assert.AreEqual(2, memory2d.Width); + Assert.AreEqual(2, memory2d.Height); + Assert.AreEqual(2, memory2d.Span[0, 0]); + Assert.AreEqual(6, memory2d.Span[1, 1]); // Also ensure the right exceptions are thrown with invalid parameters, such as // negative indices, indices out of range, values that are too big, etc. @@ -90,11 +90,11 @@ public void Test_Memory2DT_Array2DConstructor_1() Memory2D memory2d = new(array); Assert.IsFalse(memory2d.IsEmpty); - Assert.AreEqual(memory2d.Length, 6); - Assert.AreEqual(memory2d.Width, 3); - Assert.AreEqual(memory2d.Height, 2); - Assert.AreEqual(memory2d.Span[0, 1], 2); - Assert.AreEqual(memory2d.Span[1, 2], 6); + Assert.AreEqual(6, memory2d.Length); + Assert.AreEqual(3, memory2d.Width); + Assert.AreEqual(2, memory2d.Height); + Assert.AreEqual(2, memory2d.Span[0, 1]); + Assert.AreEqual(6, memory2d.Span[1, 2]); // Here we test the check for covariance: we can't create a Memory2D from a U[,] array // where U is assignable to T (as in, U : T). This would cause a type safety violation on write. @@ -114,11 +114,11 @@ public void Test_Memory2DT_Array2DConstructor_2() Memory2D memory2d = new(array, 0, 1, 2, 2); Assert.IsFalse(memory2d.IsEmpty); - Assert.AreEqual(memory2d.Length, 4); - Assert.AreEqual(memory2d.Width, 2); - Assert.AreEqual(memory2d.Height, 2); - Assert.AreEqual(memory2d.Span[0, 0], 2); - Assert.AreEqual(memory2d.Span[1, 1], 6); + Assert.AreEqual(4, memory2d.Length); + Assert.AreEqual(2, memory2d.Width); + Assert.AreEqual(2, memory2d.Height); + Assert.AreEqual(2, memory2d.Span[0, 0]); + Assert.AreEqual(6, memory2d.Span[1, 1]); _ = Assert.ThrowsException(() => new Memory2D(new string[1, 2], 0, 0, 2, 2)); } @@ -142,11 +142,11 @@ public void Test_Memory2DT_Array3DConstructor_1() Memory2D memory2d = new(array, 1); Assert.IsFalse(memory2d.IsEmpty); - Assert.AreEqual(memory2d.Length, 6); - Assert.AreEqual(memory2d.Width, 3); - Assert.AreEqual(memory2d.Height, 2); - Assert.AreEqual(memory2d.Span[0, 1], 20); - Assert.AreEqual(memory2d.Span[1, 2], 60); + Assert.AreEqual(6, memory2d.Length); + Assert.AreEqual(3, memory2d.Width); + Assert.AreEqual(2, memory2d.Height); + Assert.AreEqual(20, memory2d.Span[0, 1]); + Assert.AreEqual(60, memory2d.Span[1, 2]); // A couple of tests for invalid parameters, ie. layers out of range _ = Assert.ThrowsException(() => new Memory2D(array, -1)); @@ -176,11 +176,11 @@ public void Test_Memory2DT_Array3DConstructor_2() Memory2D memory2d = new(array, 1, 0, 1, 2, 2); Assert.IsFalse(memory2d.IsEmpty); - Assert.AreEqual(memory2d.Length, 4); - Assert.AreEqual(memory2d.Width, 2); - Assert.AreEqual(memory2d.Height, 2); - Assert.AreEqual(memory2d.Span[0, 0], 20); - Assert.AreEqual(memory2d.Span[1, 1], 60); + Assert.AreEqual(4, memory2d.Length); + Assert.AreEqual(2, memory2d.Width); + Assert.AreEqual(2, memory2d.Height); + Assert.AreEqual(20, memory2d.Span[0, 0]); + Assert.AreEqual(60, memory2d.Span[1, 1]); // Same as above, testing a few cases with invalid parameters _ = Assert.ThrowsException(() => new Memory2D(array, -1, 1, 1, 1, 1)); @@ -210,11 +210,11 @@ public void Test_Memory2DT_MemoryConstructor() Memory2D memory2d = memory.AsMemory2D(1, 2, 2, 1); Assert.IsFalse(memory2d.IsEmpty); - Assert.AreEqual(memory2d.Length, 4); - Assert.AreEqual(memory2d.Width, 2); - Assert.AreEqual(memory2d.Height, 2); - Assert.AreEqual(memory2d.Span[0, 0], 2); - Assert.AreEqual(memory2d.Span[1, 1], 6); + Assert.AreEqual(4, memory2d.Length); + Assert.AreEqual(2, memory2d.Width); + Assert.AreEqual(2, memory2d.Height); + Assert.AreEqual(2, memory2d.Span[0, 0]); + Assert.AreEqual(6, memory2d.Span[1, 1]); _ = Assert.ThrowsException(() => memory.AsMemory2D(-99, 1, 1, 1)); _ = Assert.ThrowsException(() => memory.AsMemory2D(0, -10, 1, 1)); @@ -241,23 +241,23 @@ public void Test_Memory2DT_Slice_1() // Test a slice from a Memory2D with valid parameters Memory2D slice1 = memory2d.Slice(1, 1, 1, 2); - Assert.AreEqual(slice1.Length, 2); - Assert.AreEqual(slice1.Height, 1); - Assert.AreEqual(slice1.Width, 2); - Assert.AreEqual(slice1.Span[0, 0], 5); - Assert.AreEqual(slice1.Span[0, 1], 6); + Assert.AreEqual(2, slice1.Length); + Assert.AreEqual(1, slice1.Height); + Assert.AreEqual(2, slice1.Width); + Assert.AreEqual(5, slice1.Span[0, 0]); + Assert.AreEqual(6, slice1.Span[0, 1]); // Same above, but we test slicing a pre-sliced instance as well. This // is done to verify that the internal offsets are properly tracked // across multiple slicing operations, instead of just in the first. Memory2D slice2 = memory2d.Slice(0, 1, 2, 2); - Assert.AreEqual(slice2.Length, 4); - Assert.AreEqual(slice2.Height, 2); - Assert.AreEqual(slice2.Width, 2); - Assert.AreEqual(slice2.Span[0, 0], 2); - Assert.AreEqual(slice2.Span[1, 0], 5); - Assert.AreEqual(slice2.Span[1, 1], 6); + Assert.AreEqual(4, slice2.Length); + Assert.AreEqual(2, slice2.Height); + Assert.AreEqual(2, slice2.Width); + Assert.AreEqual(2, slice2.Span[0, 0]); + Assert.AreEqual(5, slice2.Span[1, 0]); + Assert.AreEqual(6, slice2.Span[1, 1]); // A few invalid slicing operations, with out of range parameters _ = Assert.ThrowsException(() => new Memory2D(array).Slice(-1, 1, 1, 1)); @@ -287,26 +287,26 @@ public void Test_Memory2DT_Slice_2() // Mostly the same test as above, just with different parameters Memory2D slice1 = memory2d.Slice(0, 0, 2, 2); - Assert.AreEqual(slice1.Length, 4); - Assert.AreEqual(slice1.Height, 2); - Assert.AreEqual(slice1.Width, 2); - Assert.AreEqual(slice1.Span[0, 0], 1); - Assert.AreEqual(slice1.Span[1, 1], 5); + Assert.AreEqual(4, slice1.Length); + Assert.AreEqual(2, slice1.Height); + Assert.AreEqual(2, slice1.Width); + Assert.AreEqual(1, slice1.Span[0, 0]); + Assert.AreEqual(5, slice1.Span[1, 1]); Memory2D slice2 = slice1.Slice(1, 0, 1, 2); - Assert.AreEqual(slice2.Length, 2); - Assert.AreEqual(slice2.Height, 1); - Assert.AreEqual(slice2.Width, 2); - Assert.AreEqual(slice2.Span[0, 0], 4); - Assert.AreEqual(slice2.Span[0, 1], 5); + Assert.AreEqual(2, slice2.Length); + Assert.AreEqual(1, slice2.Height); + Assert.AreEqual(2, slice2.Width); + Assert.AreEqual(4, slice2.Span[0, 0]); + Assert.AreEqual(5, slice2.Span[0, 1]); Memory2D slice3 = slice2.Slice(0, 1, 1, 1); - Assert.AreEqual(slice3.Length, 1); - Assert.AreEqual(slice3.Height, 1); - Assert.AreEqual(slice3.Width, 1); - Assert.AreEqual(slice3.Span[0, 0], 5); + Assert.AreEqual(1, slice3.Length); + Assert.AreEqual(1, slice3.Height); + Assert.AreEqual(1, slice3.Width); + Assert.AreEqual(5, slice3.Span[0, 0]); } [TestMethod] @@ -331,7 +331,7 @@ public void Test_Memory2DT_TryGetMemory_1() Assert.IsTrue(memory.IsEmpty); #else Assert.IsTrue(success); - Assert.AreEqual(memory.Length, array.Length); + Assert.AreEqual(array.Length, memory.Length); Assert.IsTrue(Unsafe.AreSame(ref array[0, 0], ref memory.Span[0])); #endif } @@ -348,8 +348,8 @@ public void Test_Memory2DT_TryGetMemory_2() bool success = memory2d.TryGetMemory(out Memory memory); Assert.IsTrue(success); - Assert.AreEqual(memory.Length, array.Length); - Assert.AreEqual(memory.Span[2], 3); + Assert.AreEqual(array.Length, memory.Length); + Assert.AreEqual(3, memory.Span[2]); } #if NET6_0_OR_GREATER @@ -366,8 +366,8 @@ public void Test_Memory2DT_TryGetMemory_3() bool success = memory2d.TryGetMemory(out Memory memory); Assert.IsTrue(success); - Assert.AreEqual(memory.Length, data.Length); - Assert.AreEqual(memory.Span[2], 3); + Assert.AreEqual(data.Length, memory.Length); + Assert.AreEqual(3, memory.Span[2]); } #endif @@ -382,8 +382,8 @@ public unsafe void Test_Memory2DT_Pin_1() using System.Buffers.MemoryHandle pin = memory2d.Pin(); - Assert.AreEqual(((int*)pin.Pointer)[0], 1); - Assert.AreEqual(((int*)pin.Pointer)[3], 4); + Assert.AreEqual(1, ((int*)pin.Pointer)[0]); + Assert.AreEqual(4, ((int*)pin.Pointer)[3]); } [TestMethod] @@ -396,8 +396,8 @@ public unsafe void Test_Memory2DT_Pin_2() using System.Buffers.MemoryHandle pin = memory2d.Pin(); - Assert.AreEqual(((int*)pin.Pointer)[0], 1); - Assert.AreEqual(((int*)pin.Pointer)[3], 4); + Assert.AreEqual(1, ((int*)pin.Pointer)[0]); + Assert.AreEqual(4, ((int*)pin.Pointer)[3]); } [TestMethod] @@ -415,8 +415,8 @@ public void Test_Memory2DT_ToArray_1() int[,] copy = memory2d.ToArray(); - Assert.AreEqual(copy.GetLength(0), array.GetLength(0)); - Assert.AreEqual(copy.GetLength(1), array.GetLength(1)); + Assert.AreEqual(array.GetLength(0), copy.GetLength(0)); + Assert.AreEqual(array.GetLength(1), copy.GetLength(1)); CollectionAssert.AreEqual(array, copy); } @@ -435,8 +435,8 @@ public void Test_Memory2DT_ToArray_2() int[,] copy = memory2d.ToArray(); - Assert.AreEqual(copy.GetLength(0), 2); - Assert.AreEqual(copy.GetLength(1), 2); + Assert.AreEqual(2, copy.GetLength(0)); + Assert.AreEqual(2, copy.GetLength(1)); int[,] expected = { @@ -476,7 +476,7 @@ public void Test_Memory2DT_Equals() public void Test_Memory2DT_GetHashCode() { // An empty Memory2D has just 0 as the hashcode - Assert.AreEqual(Memory2D.Empty.GetHashCode(), 0); + Assert.AreEqual(0, Memory2D.Empty.GetHashCode()); int[,] array = { @@ -514,6 +514,6 @@ public void Test_Memory2DT_ToString() const string expected = "CommunityToolkit.HighPerformance.Memory2D[2, 3]"; - Assert.AreEqual(text, expected); + Assert.AreEqual(expected, text); } } diff --git a/tests/CommunityToolkit.HighPerformance.UnitTests/Memory/Test_ReadOnlyMemory2D{T}.cs b/tests/CommunityToolkit.HighPerformance.UnitTests/Memory/Test_ReadOnlyMemory2D{T}.cs index 55cafefcb..5db6aff1b 100644 --- a/tests/CommunityToolkit.HighPerformance.UnitTests/Memory/Test_ReadOnlyMemory2D{T}.cs +++ b/tests/CommunityToolkit.HighPerformance.UnitTests/Memory/Test_ReadOnlyMemory2D{T}.cs @@ -24,16 +24,16 @@ public void Test_ReadOnlyMemory2DT_Empty() ReadOnlyMemory2D empty1 = default; Assert.IsTrue(empty1.IsEmpty); - Assert.AreEqual(empty1.Length, 0); - Assert.AreEqual(empty1.Width, 0); - Assert.AreEqual(empty1.Height, 0); + Assert.AreEqual(0, empty1.Length); + Assert.AreEqual(0, empty1.Width); + Assert.AreEqual(0, empty1.Height); ReadOnlyMemory2D empty2 = ReadOnlyMemory2D.Empty; Assert.IsTrue(empty2.IsEmpty); - Assert.AreEqual(empty2.Length, 0); - Assert.AreEqual(empty2.Width, 0); - Assert.AreEqual(empty2.Height, 0); + Assert.AreEqual(0, empty2.Length); + Assert.AreEqual(0, empty2.Width); + Assert.AreEqual(0, empty2.Height); } [TestMethod] @@ -47,11 +47,11 @@ public void Test_ReadOnlyMemory2DT_Array1DConstructor() ReadOnlyMemory2D memory2d = new(array, 1, 2, 2, 1); Assert.IsFalse(memory2d.IsEmpty); - Assert.AreEqual(memory2d.Length, 4); - Assert.AreEqual(memory2d.Width, 2); - Assert.AreEqual(memory2d.Height, 2); - Assert.AreEqual(memory2d.Span[0, 0], 2); - Assert.AreEqual(memory2d.Span[1, 1], 6); + Assert.AreEqual(4, memory2d.Length); + Assert.AreEqual(2, memory2d.Width); + Assert.AreEqual(2, memory2d.Height); + Assert.AreEqual(2, memory2d.Span[0, 0]); + Assert.AreEqual(6, memory2d.Span[1, 1]); // Here we check to ensure a covariant array conversion is allowed for ReadOnlyMemory2D _ = new ReadOnlyMemory2D(new string[1], 1, 1); @@ -78,11 +78,11 @@ public void Test_ReadOnlyMemory2DT_Array2DConstructor_1() ReadOnlyMemory2D memory2d = new(array); Assert.IsFalse(memory2d.IsEmpty); - Assert.AreEqual(memory2d.Length, 6); - Assert.AreEqual(memory2d.Width, 3); - Assert.AreEqual(memory2d.Height, 2); - Assert.AreEqual(memory2d.Span[0, 1], 2); - Assert.AreEqual(memory2d.Span[1, 2], 6); + Assert.AreEqual(6, memory2d.Length); + Assert.AreEqual(3, memory2d.Width); + Assert.AreEqual(2, memory2d.Height); + Assert.AreEqual(2, memory2d.Span[0, 1]); + Assert.AreEqual(6, memory2d.Span[1, 2]); _ = new ReadOnlyMemory2D(new string[1, 2]); } @@ -99,11 +99,11 @@ public void Test_ReadOnlyMemory2DT_Array2DConstructor_2() ReadOnlyMemory2D memory2d = new(array, 0, 1, 2, 2); Assert.IsFalse(memory2d.IsEmpty); - Assert.AreEqual(memory2d.Length, 4); - Assert.AreEqual(memory2d.Width, 2); - Assert.AreEqual(memory2d.Height, 2); - Assert.AreEqual(memory2d.Span[0, 0], 2); - Assert.AreEqual(memory2d.Span[1, 1], 6); + Assert.AreEqual(4, memory2d.Length); + Assert.AreEqual(2, memory2d.Width); + Assert.AreEqual(2, memory2d.Height); + Assert.AreEqual(2, memory2d.Span[0, 0]); + Assert.AreEqual(6, memory2d.Span[1, 1]); _ = new ReadOnlyMemory2D(new string[1, 2]); @@ -128,11 +128,11 @@ public void Test_ReadOnlyMemory2DT_Array3DConstructor_1() ReadOnlyMemory2D memory2d = new(array, 1); Assert.IsFalse(memory2d.IsEmpty); - Assert.AreEqual(memory2d.Length, 6); - Assert.AreEqual(memory2d.Width, 3); - Assert.AreEqual(memory2d.Height, 2); - Assert.AreEqual(memory2d.Span[0, 1], 20); - Assert.AreEqual(memory2d.Span[1, 2], 60); + Assert.AreEqual(6, memory2d.Length); + Assert.AreEqual(3, memory2d.Width); + Assert.AreEqual(2, memory2d.Height); + Assert.AreEqual(20, memory2d.Span[0, 1]); + Assert.AreEqual(60, memory2d.Span[1, 2]); _ = Assert.ThrowsException(() => new ReadOnlyMemory2D(array, -1)); _ = Assert.ThrowsException(() => new ReadOnlyMemory2D(array, 20)); @@ -157,11 +157,11 @@ public void Test_ReadOnlyMemory2DT_Array3DConstructor_2() ReadOnlyMemory2D memory2d = new(array, 1, 0, 1, 2, 2); Assert.IsFalse(memory2d.IsEmpty); - Assert.AreEqual(memory2d.Length, 4); - Assert.AreEqual(memory2d.Width, 2); - Assert.AreEqual(memory2d.Height, 2); - Assert.AreEqual(memory2d.Span[0, 0], 20); - Assert.AreEqual(memory2d.Span[1, 1], 60); + Assert.AreEqual(4, memory2d.Length); + Assert.AreEqual(2, memory2d.Width); + Assert.AreEqual(2, memory2d.Height); + Assert.AreEqual(20, memory2d.Span[0, 0]); + Assert.AreEqual(60, memory2d.Span[1, 1]); _ = Assert.ThrowsException(() => new ReadOnlyMemory2D(array, -1, 1, 1, 1, 1)); _ = Assert.ThrowsException(() => new ReadOnlyMemory2D(array, 1, -1, 1, 1, 1)); @@ -186,11 +186,11 @@ public void Test_ReadOnlyMemory2DT_ReadOnlyMemoryConstructor() ReadOnlyMemory2D memory2d = memory.AsMemory2D(1, 2, 2, 1); Assert.IsFalse(memory2d.IsEmpty); - Assert.AreEqual(memory2d.Length, 4); - Assert.AreEqual(memory2d.Width, 2); - Assert.AreEqual(memory2d.Height, 2); - Assert.AreEqual(memory2d.Span[0, 0], 2); - Assert.AreEqual(memory2d.Span[1, 1], 6); + Assert.AreEqual(4, memory2d.Length); + Assert.AreEqual(2, memory2d.Width); + Assert.AreEqual(2, memory2d.Height); + Assert.AreEqual(2, memory2d.Span[0, 0]); + Assert.AreEqual(6, memory2d.Span[1, 1]); _ = Assert.ThrowsException(() => memory.AsMemory2D(-99, 1, 1, 1)); _ = Assert.ThrowsException(() => memory.AsMemory2D(0, -10, 1, 1)); @@ -216,20 +216,20 @@ public void Test_ReadOnlyMemory2DT_Slice_1() ReadOnlyMemory2D slice1 = memory2d.Slice(1, 1, 1, 2); - Assert.AreEqual(slice1.Length, 2); - Assert.AreEqual(slice1.Height, 1); - Assert.AreEqual(slice1.Width, 2); - Assert.AreEqual(slice1.Span[0, 0], 5); - Assert.AreEqual(slice1.Span[0, 1], 6); + Assert.AreEqual(2, slice1.Length); + Assert.AreEqual(1, slice1.Height); + Assert.AreEqual(2, slice1.Width); + Assert.AreEqual(5, slice1.Span[0, 0]); + Assert.AreEqual(6, slice1.Span[0, 1]); ReadOnlyMemory2D slice2 = memory2d.Slice(0, 1, 2, 2); - Assert.AreEqual(slice2.Length, 4); - Assert.AreEqual(slice2.Height, 2); - Assert.AreEqual(slice2.Width, 2); - Assert.AreEqual(slice2.Span[0, 0], 2); - Assert.AreEqual(slice2.Span[1, 0], 5); - Assert.AreEqual(slice2.Span[1, 1], 6); + Assert.AreEqual(4, slice2.Length); + Assert.AreEqual(2, slice2.Height); + Assert.AreEqual(2, slice2.Width); + Assert.AreEqual(2, slice2.Span[0, 0]); + Assert.AreEqual(5, slice2.Span[1, 0]); + Assert.AreEqual(6, slice2.Span[1, 1]); _ = Assert.ThrowsException(() => new ReadOnlyMemory2D(array).Slice(-1, 1, 1, 1)); _ = Assert.ThrowsException(() => new ReadOnlyMemory2D(array).Slice(1, -1, 1, 1)); @@ -257,26 +257,26 @@ public void Test_ReadOnlyMemory2DT_Slice_2() ReadOnlyMemory2D slice1 = memory2d.Slice(0, 0, 2, 2); - Assert.AreEqual(slice1.Length, 4); - Assert.AreEqual(slice1.Height, 2); - Assert.AreEqual(slice1.Width, 2); - Assert.AreEqual(slice1.Span[0, 0], 1); - Assert.AreEqual(slice1.Span[1, 1], 5); + Assert.AreEqual(4, slice1.Length); + Assert.AreEqual(2, slice1.Height); + Assert.AreEqual(2, slice1.Width); + Assert.AreEqual(1, slice1.Span[0, 0]); + Assert.AreEqual(5, slice1.Span[1, 1]); ReadOnlyMemory2D slice2 = slice1.Slice(1, 0, 1, 2); - Assert.AreEqual(slice2.Length, 2); - Assert.AreEqual(slice2.Height, 1); - Assert.AreEqual(slice2.Width, 2); - Assert.AreEqual(slice2.Span[0, 0], 4); - Assert.AreEqual(slice2.Span[0, 1], 5); + Assert.AreEqual(2, slice2.Length); + Assert.AreEqual(1, slice2.Height); + Assert.AreEqual(2, slice2.Width); + Assert.AreEqual(4, slice2.Span[0, 0]); + Assert.AreEqual(5, slice2.Span[0, 1]); ReadOnlyMemory2D slice3 = slice2.Slice(0, 1, 1, 1); - Assert.AreEqual(slice3.Length, 1); - Assert.AreEqual(slice3.Height, 1); - Assert.AreEqual(slice3.Width, 1); - Assert.AreEqual(slice3.Span[0, 0], 5); + Assert.AreEqual(1, slice3.Length); + Assert.AreEqual(1, slice3.Height); + Assert.AreEqual(1, slice3.Width); + Assert.AreEqual(5, slice3.Span[0, 0]); } [TestMethod] @@ -297,7 +297,7 @@ public void Test_ReadOnlyMemory2DT_TryGetReadOnlyMemory_1() Assert.IsTrue(memory.IsEmpty); #else Assert.IsTrue(success); - Assert.AreEqual(memory.Length, array.Length); + Assert.AreEqual(array.Length, memory.Length); Assert.IsTrue(Unsafe.AreSame(ref array[0, 0], ref Unsafe.AsRef(memory.Span[0]))); #endif } @@ -312,8 +312,8 @@ public void Test_ReadOnlyMemory2DT_TryGetReadOnlyMemory_2() bool success = memory2d.TryGetMemory(out ReadOnlyMemory memory); Assert.IsTrue(success); - Assert.AreEqual(memory.Length, array.Length); - Assert.AreEqual(memory.Span[2], 3); + Assert.AreEqual(array.Length, memory.Length); + Assert.AreEqual(3, memory.Span[2]); } #if NET6_0_OR_GREATER @@ -327,8 +327,8 @@ public void Test_ReadOnlyMemory2DT_TryGetReadOnlyMemory_3() bool success = memory2d.TryGetMemory(out ReadOnlyMemory memory); Assert.IsTrue(success); - Assert.AreEqual(memory.Length, data.Length); - Assert.AreEqual(memory.Span[2], 3); + Assert.AreEqual(data.Length, memory.Length); + Assert.AreEqual(3, memory.Span[2]); } #endif @@ -341,8 +341,8 @@ public unsafe void Test_ReadOnlyMemory2DT_Pin_1() using System.Buffers.MemoryHandle pin = memory2d.Pin(); - Assert.AreEqual(((int*)pin.Pointer)[0], 1); - Assert.AreEqual(((int*)pin.Pointer)[3], 4); + Assert.AreEqual(1, ((int*)pin.Pointer)[0]); + Assert.AreEqual(4, ((int*)pin.Pointer)[3]); } [TestMethod] @@ -354,8 +354,8 @@ public unsafe void Test_ReadOnlyMemory2DT_Pin_2() using System.Buffers.MemoryHandle pin = memory2d.Pin(); - Assert.AreEqual(((int*)pin.Pointer)[0], 1); - Assert.AreEqual(((int*)pin.Pointer)[3], 4); + Assert.AreEqual(1, ((int*)pin.Pointer)[0]); + Assert.AreEqual(4, ((int*)pin.Pointer)[3]); } [TestMethod] @@ -371,8 +371,8 @@ public void Test_ReadOnlyMemory2DT_ToArray_1() int[,] copy = memory2d.ToArray(); - Assert.AreEqual(copy.GetLength(0), array.GetLength(0)); - Assert.AreEqual(copy.GetLength(1), array.GetLength(1)); + Assert.AreEqual(array.GetLength(0), copy.GetLength(0)); + Assert.AreEqual(array.GetLength(1), copy.GetLength(1)); CollectionAssert.AreEqual(array, copy); } @@ -390,8 +390,8 @@ public void Test_ReadOnlyMemory2DT_ToArray_2() int[,] copy = memory2d.ToArray(); - Assert.AreEqual(copy.GetLength(0), 2); - Assert.AreEqual(copy.GetLength(1), 2); + Assert.AreEqual(2, copy.GetLength(0)); + Assert.AreEqual(2, copy.GetLength(1)); int[,] expected = { @@ -427,7 +427,7 @@ public void Test_ReadOnlyMemory2DT_Equals() [TestMethod] public void Test_ReadOnlyMemory2DT_GetHashCode() { - Assert.AreEqual(ReadOnlyMemory2D.Empty.GetHashCode(), 0); + Assert.AreEqual(0, ReadOnlyMemory2D.Empty.GetHashCode()); int[,] array = { @@ -462,6 +462,6 @@ public void Test_ReadOnlyMemory2DT_ToString() const string expected = "CommunityToolkit.HighPerformance.ReadOnlyMemory2D[2, 3]"; - Assert.AreEqual(text, expected); + Assert.AreEqual(expected, text); } } diff --git a/tests/CommunityToolkit.HighPerformance.UnitTests/Memory/Test_ReadOnlySpan2D{T}.cs b/tests/CommunityToolkit.HighPerformance.UnitTests/Memory/Test_ReadOnlySpan2D{T}.cs index 4089b74f5..75a2ba3b5 100644 --- a/tests/CommunityToolkit.HighPerformance.UnitTests/Memory/Test_ReadOnlySpan2D{T}.cs +++ b/tests/CommunityToolkit.HighPerformance.UnitTests/Memory/Test_ReadOnlySpan2D{T}.cs @@ -23,16 +23,16 @@ public void Test_ReadOnlySpan2DT_Empty() ReadOnlySpan2D empty1 = default; Assert.IsTrue(empty1.IsEmpty); - Assert.AreEqual(empty1.Length, 0); - Assert.AreEqual(empty1.Width, 0); - Assert.AreEqual(empty1.Height, 0); + Assert.AreEqual(0, empty1.Length); + Assert.AreEqual(0, empty1.Width); + Assert.AreEqual(0, empty1.Height); ReadOnlySpan2D empty2 = ReadOnlySpan2D.Empty; Assert.IsTrue(empty2.IsEmpty); - Assert.AreEqual(empty2.Length, 0); - Assert.AreEqual(empty2.Width, 0); - Assert.AreEqual(empty2.Height, 0); + Assert.AreEqual(0, empty2.Length); + Assert.AreEqual(0, empty2.Width); + Assert.AreEqual(0, empty2.Height); } #if NET6_0_OR_GREATER @@ -52,11 +52,11 @@ public unsafe void Test_ReadOnlySpan2DT_RefConstructor() ReadOnlySpan2D span2d = ReadOnlySpan2D.DangerousCreate(span[0], 2, 3, 0); Assert.IsFalse(span2d.IsEmpty); - Assert.AreEqual(span2d.Length, 6); - Assert.AreEqual(span2d.Width, 3); - Assert.AreEqual(span2d.Height, 2); - Assert.AreEqual(span2d[0, 0], 1); - Assert.AreEqual(span2d[1, 2], 6); + Assert.AreEqual(6, span2d.Length); + Assert.AreEqual(3, span2d.Width); + Assert.AreEqual(2, span2d.Height); + Assert.AreEqual(1, span2d[0, 0]); + Assert.AreEqual(6, span2d[1, 2]); _ = Assert.ThrowsException(() => ReadOnlySpan2D.DangerousCreate(Unsafe.AsRef(null), -1, 0, 0)); _ = Assert.ThrowsException(() => ReadOnlySpan2D.DangerousCreate(Unsafe.AsRef(null), 1, -2, 0)); @@ -80,11 +80,11 @@ public unsafe void Test_ReadOnlySpan2DT_PtrConstructor() ReadOnlySpan2D span2d = new(ptr, 2, 3, 0); Assert.IsFalse(span2d.IsEmpty); - Assert.AreEqual(span2d.Length, 6); - Assert.AreEqual(span2d.Width, 3); - Assert.AreEqual(span2d.Height, 2); - Assert.AreEqual(span2d[0, 0], 1); - Assert.AreEqual(span2d[1, 2], 6); + Assert.AreEqual(6, span2d.Length); + Assert.AreEqual(3, span2d.Width); + Assert.AreEqual(2, span2d.Height); + Assert.AreEqual(1, span2d[0, 0]); + Assert.AreEqual(6, span2d[1, 2]); _ = Assert.ThrowsException(() => new ReadOnlySpan2D((void*)0, -1, 0, 0)); _ = Assert.ThrowsException(() => new ReadOnlySpan2D((void*)0, 1, -2, 0)); @@ -103,11 +103,11 @@ public void Test_ReadOnlySpan2DT_Array1DConstructor() ReadOnlySpan2D span2d = new(array, 1, 2, 2, 1); Assert.IsFalse(span2d.IsEmpty); - Assert.AreEqual(span2d.Length, 4); - Assert.AreEqual(span2d.Width, 2); - Assert.AreEqual(span2d.Height, 2); - Assert.AreEqual(span2d[0, 0], 2); - Assert.AreEqual(span2d[1, 1], 6); + Assert.AreEqual(4, span2d.Length); + Assert.AreEqual(2, span2d.Width); + Assert.AreEqual(2, span2d.Height); + Assert.AreEqual(2, span2d[0, 0]); + Assert.AreEqual(6, span2d[1, 1]); // Same for ReadOnlyMemory2D, we need to check that covariant array conversions are allowed _ = new ReadOnlySpan2D(new string[1], 1, 1); @@ -131,11 +131,11 @@ public void Test_ReadOnlySpan2DT_Array2DConstructor_1() ReadOnlySpan2D span2d = new(array); Assert.IsFalse(span2d.IsEmpty); - Assert.AreEqual(span2d.Length, 6); - Assert.AreEqual(span2d.Width, 3); - Assert.AreEqual(span2d.Height, 2); - Assert.AreEqual(span2d[0, 1], 2); - Assert.AreEqual(span2d[1, 2], 6); + Assert.AreEqual(6, span2d.Length); + Assert.AreEqual(3, span2d.Width); + Assert.AreEqual(2, span2d.Height); + Assert.AreEqual(2, span2d[0, 1]); + Assert.AreEqual(6, span2d[1, 2]); _ = new ReadOnlySpan2D(new string[1, 2]); } @@ -152,11 +152,11 @@ public void Test_ReadOnlySpan2DT_Array2DConstructor_2() ReadOnlySpan2D span2d = new(array, 0, 1, 2, 2); Assert.IsFalse(span2d.IsEmpty); - Assert.AreEqual(span2d.Length, 4); - Assert.AreEqual(span2d.Width, 2); - Assert.AreEqual(span2d.Height, 2); - Assert.AreEqual(span2d[0, 0], 2); - Assert.AreEqual(span2d[1, 1], 6); + Assert.AreEqual(4, span2d.Length); + Assert.AreEqual(2, span2d.Width); + Assert.AreEqual(2, span2d.Height); + Assert.AreEqual(2, span2d[0, 0]); + Assert.AreEqual(6, span2d[1, 1]); _ = new ReadOnlySpan2D(new string[1, 2]); @@ -181,12 +181,12 @@ public void Test_ReadOnlySpan2DT_Array3DConstructor_1() ReadOnlySpan2D span2d = new(array, 1); Assert.IsFalse(span2d.IsEmpty); - Assert.AreEqual(span2d.Length, 6); - Assert.AreEqual(span2d.Width, 3); - Assert.AreEqual(span2d.Height, 2); - Assert.AreEqual(span2d[0, 0], 10); - Assert.AreEqual(span2d[0, 1], 20); - Assert.AreEqual(span2d[1, 2], 60); + Assert.AreEqual(6, span2d.Length); + Assert.AreEqual(3, span2d.Width); + Assert.AreEqual(2, span2d.Height); + Assert.AreEqual(10, span2d[0, 0]); + Assert.AreEqual(20, span2d[0, 1]); + Assert.AreEqual(60, span2d[1, 2]); _ = Assert.ThrowsException(() => new ReadOnlySpan2D(array, -1)); _ = Assert.ThrowsException(() => new ReadOnlySpan2D(array, 20)); @@ -210,12 +210,12 @@ public void Test_ReadOnlySpan2DT_Array3DConstructor_2() ReadOnlySpan2D span2d = new(array, 1, 0, 1, 2, 2); Assert.IsFalse(span2d.IsEmpty); - Assert.AreEqual(span2d.Length, 4); - Assert.AreEqual(span2d.Width, 2); - Assert.AreEqual(span2d.Height, 2); - Assert.AreEqual(span2d[0, 0], 20); - Assert.AreEqual(span2d[0, 1], 30); - Assert.AreEqual(span2d[1, 1], 60); + Assert.AreEqual(4, span2d.Length); + Assert.AreEqual(2, span2d.Width); + Assert.AreEqual(2, span2d.Height); + Assert.AreEqual(20, span2d[0, 0]); + Assert.AreEqual(30, span2d[0, 1]); + Assert.AreEqual(60, span2d[1, 1]); _ = Assert.ThrowsException(() => new ReadOnlySpan2D(array, -1, 1, 1, 1, 1)); _ = Assert.ThrowsException(() => new ReadOnlySpan2D(array, 1, -1, 1, 1, 1)); @@ -261,7 +261,7 @@ public void Test_ReadOnlySpan2DT_CopyTo_2() int[] expected = { 2, 3, 5, 6 }; - CollectionAssert.AreEqual(target, expected); + CollectionAssert.AreEqual(expected, target); _ = Assert.ThrowsException(() => new ReadOnlySpan2D(array).CopyTo(Span.Empty)); } @@ -307,7 +307,7 @@ public void Test_ReadOnlySpan2DT_CopyTo2D_2() { 5, 6 } }; - CollectionAssert.AreEqual(target, expected); + CollectionAssert.AreEqual(expected, target); _ = Assert.ThrowsException(() => new ReadOnlySpan2D(array).CopyTo(new Span2D(target))); } @@ -432,7 +432,7 @@ public unsafe void Test_ReadOnlySpan2DT_Range_Indexer_1() ReadOnlySpan2D span2d = new(array); ReadOnlySpan2D slice = span2d[1.., 1..]; - Assert.AreEqual(slice.Length, 9); + Assert.AreEqual(9, slice.Length); Assert.IsTrue(Unsafe.AreSame(ref array[1, 1], ref Unsafe.AsRef(in slice[0, 0]))); Assert.IsTrue(Unsafe.AreSame(ref array[3, 3], ref Unsafe.AsRef(in slice[2, 2]))); } @@ -445,7 +445,7 @@ public unsafe void Test_ReadOnlySpan2DT_Range_Indexer_2() ReadOnlySpan2D span2d = new(array); ReadOnlySpan2D slice = span2d[0..^2, 1..^1]; - Assert.AreEqual(slice.Length, 4); + Assert.AreEqual(4, slice.Length); Assert.IsTrue(Unsafe.AreSame(ref array[0, 1], ref Unsafe.AsRef(in slice[0, 0]))); Assert.IsTrue(Unsafe.AreSame(ref array[1, 2], ref Unsafe.AsRef(in slice[1, 1]))); } @@ -476,20 +476,20 @@ public void Test_ReadOnlySpan2DT_Slice_1() ReadOnlySpan2D slice1 = span2d.Slice(1, 1, 1, 2); - Assert.AreEqual(slice1.Length, 2); - Assert.AreEqual(slice1.Height, 1); - Assert.AreEqual(slice1.Width, 2); - Assert.AreEqual(slice1[0, 0], 5); - Assert.AreEqual(slice1[0, 1], 6); + Assert.AreEqual(2, slice1.Length); + Assert.AreEqual(1, slice1.Height); + Assert.AreEqual(2, slice1.Width); + Assert.AreEqual(5, slice1[0, 0]); + Assert.AreEqual(6, slice1[0, 1]); ReadOnlySpan2D slice2 = span2d.Slice(0, 1, 2, 2); - Assert.AreEqual(slice2.Length, 4); - Assert.AreEqual(slice2.Height, 2); - Assert.AreEqual(slice2.Width, 2); - Assert.AreEqual(slice2[0, 0], 2); - Assert.AreEqual(slice2[1, 0], 5); - Assert.AreEqual(slice2[1, 1], 6); + Assert.AreEqual(4, slice2.Length); + Assert.AreEqual(2, slice2.Height); + Assert.AreEqual(2, slice2.Width); + Assert.AreEqual(2, slice2[0, 0]); + Assert.AreEqual(5, slice2[1, 0]); + Assert.AreEqual(6, slice2[1, 1]); _ = Assert.ThrowsException(() => new ReadOnlySpan2D(array).Slice(-1, 1, 1, 1)); _ = Assert.ThrowsException(() => new ReadOnlySpan2D(array).Slice(1, -1, 1, 1)); @@ -513,26 +513,26 @@ public void Test_ReadOnlySpan2DT_Slice_2() ReadOnlySpan2D slice1 = span2d.Slice(0, 0, 2, 2); - Assert.AreEqual(slice1.Length, 4); - Assert.AreEqual(slice1.Height, 2); - Assert.AreEqual(slice1.Width, 2); - Assert.AreEqual(slice1[0, 0], 1); - Assert.AreEqual(slice1[1, 1], 5); + Assert.AreEqual(4, slice1.Length); + Assert.AreEqual(2, slice1.Height); + Assert.AreEqual(2, slice1.Width); + Assert.AreEqual(1, slice1[0, 0]); + Assert.AreEqual(5, slice1[1, 1]); ReadOnlySpan2D slice2 = slice1.Slice(1, 0, 1, 2); - Assert.AreEqual(slice2.Length, 2); - Assert.AreEqual(slice2.Height, 1); - Assert.AreEqual(slice2.Width, 2); - Assert.AreEqual(slice2[0, 0], 4); - Assert.AreEqual(slice2[0, 1], 5); + Assert.AreEqual(2, slice2.Length); + Assert.AreEqual(1, slice2.Height); + Assert.AreEqual(2, slice2.Width); + Assert.AreEqual(4, slice2[0, 0]); + Assert.AreEqual(5, slice2[0, 1]); ReadOnlySpan2D slice3 = slice2.Slice(0, 1, 1, 1); - Assert.AreEqual(slice3.Length, 1); - Assert.AreEqual(slice3.Height, 1); - Assert.AreEqual(slice3.Width, 1); - Assert.AreEqual(slice3[0, 0], 5); + Assert.AreEqual(1, slice3.Length); + Assert.AreEqual(1, slice3.Height); + Assert.AreEqual(1, slice3.Width); + Assert.AreEqual(5, slice3[0, 0]); } #if NET6_0_OR_GREATER @@ -571,7 +571,7 @@ public void Test_ReadOnlySpan2DT_TryGetSpan_From1DArray_1() bool success = span2d.TryGetSpan(out ReadOnlySpan span); Assert.IsTrue(success); - Assert.AreEqual(span.Length, span2d.Length); + Assert.AreEqual(span2d.Length, span.Length); Assert.IsTrue(Unsafe.AreSame(ref array[0], ref Unsafe.AsRef(in span[0]))); } @@ -585,7 +585,7 @@ public void Test_ReadOnlySpan2DT_TryGetSpan_From1DArray_2() bool success = span2d.TryGetSpan(out ReadOnlySpan span); Assert.IsTrue(success); - Assert.AreEqual(span.Length, span2d.Length); + Assert.AreEqual(span2d.Length, span.Length); Assert.IsTrue(Unsafe.AreSame(ref array[3], ref Unsafe.AsRef(in span[0]))); } @@ -599,7 +599,7 @@ public void Test_ReadOnlySpan2DT_TryGetSpan_From1DArray_3() bool success = span2d.TryGetSpan(out ReadOnlySpan span); Assert.IsFalse(success); - Assert.AreEqual(span.Length, 0); + Assert.AreEqual(0, span.Length); } [TestMethod] @@ -618,10 +618,10 @@ public void Test_ReadOnlySpan2DT_TryGetReadOnlySpan_From2DArray_1() #if NETFRAMEWORK // Can't get a ReadOnlySpan over a T[,] array on .NET Standard 2.0 Assert.IsFalse(success); - Assert.AreEqual(span.Length, 0); + Assert.AreEqual(0, span.Length); #else Assert.IsTrue(success); - Assert.AreEqual(span.Length, span2d.Length); + Assert.AreEqual(span2d.Length, span.Length); #endif } @@ -655,8 +655,8 @@ public void Test_ReadOnlySpan2DT_ToArray_1() int[,] copy = span2d.ToArray(); - Assert.AreEqual(copy.GetLength(0), array.GetLength(0)); - Assert.AreEqual(copy.GetLength(1), array.GetLength(1)); + Assert.AreEqual(array.GetLength(0), copy.GetLength(0)); + Assert.AreEqual(array.GetLength(1), copy.GetLength(1)); CollectionAssert.AreEqual(array, copy); } @@ -674,8 +674,8 @@ public void Test_ReadOnlySpan2DT_ToArray_2() int[,] copy = span2d.ToArray(); - Assert.AreEqual(copy.GetLength(0), 2); - Assert.AreEqual(copy.GetLength(1), 2); + Assert.AreEqual(2, copy.GetLength(0)); + Assert.AreEqual(2, copy.GetLength(1)); int[,] expected = { @@ -731,7 +731,7 @@ public void Test_ReadOnlySpan2DT_ToString() const string expected = "CommunityToolkit.HighPerformance.ReadOnlySpan2D[2, 3]"; - Assert.AreEqual(text, expected); + Assert.AreEqual(expected, text); } [TestMethod] @@ -790,9 +790,9 @@ public void Test_ReadOnlySpan2DT_GetRow() int[] expected = { 4, 5, 6 }; - CollectionAssert.AreEqual(enumerable.ToArray(), expected); + CollectionAssert.AreEqual(expected, enumerable.ToArray()); - Assert.AreSame(default(ReadOnlyRefEnumerable).ToArray(), Array.Empty()); + Assert.AreSame(Array.Empty(), default(ReadOnlyRefEnumerable).ToArray()); _ = Assert.ThrowsException(() => new ReadOnlySpan2D(array).GetRow(-1)); _ = Assert.ThrowsException(() => new ReadOnlySpan2D(array).GetRow(2)); @@ -822,7 +822,7 @@ public unsafe void Test_ReadOnlySpan2DT_Pointer_GetRow() int[] expected = { 4, 5, 6 }; - CollectionAssert.AreEqual(enumerable.ToArray(), expected); + CollectionAssert.AreEqual(expected, enumerable.ToArray()); _ = Assert.ThrowsException(() => new ReadOnlySpan2D(array, 2, 3, 0).GetRow(-1)); _ = Assert.ThrowsException(() => new ReadOnlySpan2D(array, 2, 3, 0).GetRow(2)); @@ -848,7 +848,7 @@ public void Test_ReadOnlySpan2DT_GetColumn() int[] expected = { 3, 6 }; - CollectionAssert.AreEqual(enumerable.ToArray(), expected); + CollectionAssert.AreEqual(expected, enumerable.ToArray()); _ = Assert.ThrowsException(() => new ReadOnlySpan2D(array).GetColumn(-1)); _ = Assert.ThrowsException(() => new ReadOnlySpan2D(array).GetColumn(3)); @@ -878,7 +878,7 @@ public unsafe void Test_ReadOnlySpan2DT_Pointer_GetColumn() int[] expected = { 3, 6 }; - CollectionAssert.AreEqual(enumerable.ToArray(), expected); + CollectionAssert.AreEqual(expected, enumerable.ToArray()); _ = Assert.ThrowsException(() => new ReadOnlySpan2D(array, 2, 3, 0).GetColumn(-1)); _ = Assert.ThrowsException(() => new ReadOnlySpan2D(array, 2, 3, 0).GetColumn(3)); @@ -904,7 +904,7 @@ public void Test_ReadOnlySpan2DT_GetEnumerator() int[] expected = { 2, 3, 5, 6 }; - CollectionAssert.AreEqual(result, expected); + CollectionAssert.AreEqual(expected, result); } [TestMethod] @@ -930,7 +930,7 @@ public unsafe void Test_ReadOnlySpan2DT_Pointer_GetEnumerator() int[] expected = { 2, 3, 5, 6 }; - CollectionAssert.AreEqual(result, expected); + CollectionAssert.AreEqual(expected, result); } [TestMethod] @@ -976,7 +976,7 @@ public void Test_ReadOnlySpan2DT_ReadOnlyRefEnumerable_Misc() { 0, 8, 0, 16 } }; - CollectionAssert.AreEqual(array2, result); + CollectionAssert.AreEqual(result, array2); // Test a valid and an invalid TryCopyTo call with the RefEnumerable overload bool shouldBeTrue = span1.GetRow(0).TryCopyTo(array2.GetColumn(0)); @@ -990,7 +990,7 @@ public void Test_ReadOnlySpan2DT_ReadOnlyRefEnumerable_Misc() { 4, 8, 0, 16 } }; - CollectionAssert.AreEqual(array2, result); + CollectionAssert.AreEqual(result, array2); Assert.IsTrue(shouldBeTrue); Assert.IsFalse(shouldBeFalse); diff --git a/tests/CommunityToolkit.HighPerformance.UnitTests/Memory/Test_Span2D{T}.cs b/tests/CommunityToolkit.HighPerformance.UnitTests/Memory/Test_Span2D{T}.cs index 15be6300c..5a23cf514 100644 --- a/tests/CommunityToolkit.HighPerformance.UnitTests/Memory/Test_Span2D{T}.cs +++ b/tests/CommunityToolkit.HighPerformance.UnitTests/Memory/Test_Span2D{T}.cs @@ -20,30 +20,30 @@ public void Test_Span2DT_Empty() Span2D empty1 = default; Assert.IsTrue(empty1.IsEmpty); - Assert.AreEqual(empty1.Length, 0); - Assert.AreEqual(empty1.Width, 0); - Assert.AreEqual(empty1.Height, 0); + Assert.AreEqual(0, empty1.Length); + Assert.AreEqual(0, empty1.Width); + Assert.AreEqual(0, empty1.Height); Span2D empty2 = Span2D.Empty; Assert.IsTrue(empty2.IsEmpty); - Assert.AreEqual(empty2.Length, 0); - Assert.AreEqual(empty2.Width, 0); - Assert.AreEqual(empty2.Height, 0); + Assert.AreEqual(0, empty2.Length); + Assert.AreEqual(0, empty2.Width); + Assert.AreEqual(0, empty2.Height); Span2D empty3 = new int[4, 0]; Assert.IsTrue(empty3.IsEmpty); - Assert.AreEqual(empty3.Length, 0); - Assert.AreEqual(empty3.Width, 0); - Assert.AreEqual(empty3.Height, 4); + Assert.AreEqual(0, empty3.Length); + Assert.AreEqual(0, empty3.Width); + Assert.AreEqual(4, empty3.Height); Span2D empty4 = new int[0, 7]; Assert.IsTrue(empty4.IsEmpty); - Assert.AreEqual(empty4.Length, 0); - Assert.AreEqual(empty4.Width, 7); - Assert.AreEqual(empty4.Height, 0); + Assert.AreEqual(0, empty4.Length); + Assert.AreEqual(7, empty4.Width); + Assert.AreEqual(0, empty4.Height); } #if NET6_0_OR_GREATER @@ -65,16 +65,16 @@ public unsafe void Test_Span2DT_RefConstructor() Span2D span2d = Span2D.DangerousCreate(ref span[0], 2, 3, 0); Assert.IsFalse(span2d.IsEmpty); - Assert.AreEqual(span2d.Length, 6); - Assert.AreEqual(span2d.Width, 3); - Assert.AreEqual(span2d.Height, 2); + Assert.AreEqual(6, span2d.Length); + Assert.AreEqual(3, span2d.Width); + Assert.AreEqual(2, span2d.Height); span2d[0, 0] = 99; span2d[1, 2] = 101; // Validate that those values were mapped to the right spot in the target span - Assert.AreEqual(span[0], 99); - Assert.AreEqual(span[5], 101); + Assert.AreEqual(99, span[0]); + Assert.AreEqual(101, span[5]); // A few cases with invalid indices _ = Assert.ThrowsException(() => Span2D.DangerousCreate(ref Unsafe.AsRef(null), -1, 0, 0)); @@ -100,15 +100,15 @@ public unsafe void Test_Span2DT_PtrConstructor() Span2D span2d = new(ptr, 2, 3, 0); Assert.IsFalse(span2d.IsEmpty); - Assert.AreEqual(span2d.Length, 6); - Assert.AreEqual(span2d.Width, 3); - Assert.AreEqual(span2d.Height, 2); + Assert.AreEqual(6, span2d.Length); + Assert.AreEqual(3, span2d.Width); + Assert.AreEqual(2, span2d.Height); span2d[0, 0] = 99; span2d[1, 2] = 101; - Assert.AreEqual(ptr[0], 99); - Assert.AreEqual(ptr[5], 101); + Assert.AreEqual(99, ptr[0]); + Assert.AreEqual(101, ptr[5]); _ = Assert.ThrowsException(() => new Span2D((void*)0, -1, 0, 0)); _ = Assert.ThrowsException(() => new Span2D((void*)0, 1, -2, 0)); @@ -128,15 +128,15 @@ public void Test_Span2DT_Array1DConstructor() Span2D span2d = new(array, 1, 2, 2, 1); Assert.IsFalse(span2d.IsEmpty); - Assert.AreEqual(span2d.Length, 4); - Assert.AreEqual(span2d.Width, 2); - Assert.AreEqual(span2d.Height, 2); + Assert.AreEqual(4, span2d.Length); + Assert.AreEqual(2, span2d.Width); + Assert.AreEqual(2, span2d.Height); span2d[0, 0] = 99; span2d[1, 1] = 101; - Assert.AreEqual(array[1], 99); - Assert.AreEqual(array[5], 101); + Assert.AreEqual(99, array[1]); + Assert.AreEqual(101, array[5]); // The first check fails due to the array covariance test mentioned in the Memory2D tests. // The others just validate a number of cases with invalid arguments (eg. out of range). @@ -161,15 +161,15 @@ public void Test_Span2DT_Array2DConstructor_1() Span2D span2d = new(array); Assert.IsFalse(span2d.IsEmpty); - Assert.AreEqual(span2d.Length, 6); - Assert.AreEqual(span2d.Width, 3); - Assert.AreEqual(span2d.Height, 2); + Assert.AreEqual(6, span2d.Length); + Assert.AreEqual(3, span2d.Width); + Assert.AreEqual(2, span2d.Height); span2d[0, 1] = 99; span2d[1, 2] = 101; - Assert.AreEqual(array[0, 1], 99); - Assert.AreEqual(array[1, 2], 101); + Assert.AreEqual(99, array[0, 1]); + Assert.AreEqual(101, array[1, 2]); _ = Assert.ThrowsException(() => new Span2D(new string[1, 2])); } @@ -187,15 +187,15 @@ public void Test_Span2DT_Array2DConstructor_2() Span2D span2d = new(array, 0, 1, 2, 2); Assert.IsFalse(span2d.IsEmpty); - Assert.AreEqual(span2d.Length, 4); - Assert.AreEqual(span2d.Width, 2); - Assert.AreEqual(span2d.Height, 2); + Assert.AreEqual(4, span2d.Length); + Assert.AreEqual(2, span2d.Width); + Assert.AreEqual(2, span2d.Height); span2d[0, 0] = 99; span2d[1, 1] = 101; - Assert.AreEqual(array[0, 1], 99); - Assert.AreEqual(array[1, 2], 101); + Assert.AreEqual(99, array[0, 1]); + Assert.AreEqual(101, array[1, 2]); _ = Assert.ThrowsException(() => new Span2D(new string[1, 2], 0, 0, 2, 2)); } @@ -219,16 +219,16 @@ public void Test_Span2DT_Array3DConstructor_1() Span2D span2d = new(array, 1); Assert.IsFalse(span2d.IsEmpty); - Assert.AreEqual(span2d.Length, 6); - Assert.AreEqual(span2d.Width, 3); - Assert.AreEqual(span2d.Height, 2); + Assert.AreEqual(6, span2d.Length); + Assert.AreEqual(3, span2d.Width); + Assert.AreEqual(2, span2d.Height); span2d[0, 1] = 99; span2d[1, 2] = 101; - Assert.AreEqual(span2d[0, 0], 10); - Assert.AreEqual(array[1, 0, 1], 99); - Assert.AreEqual(array[1, 1, 2], 101); + Assert.AreEqual(10, span2d[0, 0]); + Assert.AreEqual(99, array[1, 0, 1]); + Assert.AreEqual(101, array[1, 1, 2]); _ = Assert.ThrowsException(() => new Span2D(array, -1)); _ = Assert.ThrowsException(() => new Span2D(array, 20)); @@ -253,16 +253,16 @@ public void Test_Span2DT_Array3DConstructor_2() Span2D span2d = new(array, 1, 0, 1, 2, 2); Assert.IsFalse(span2d.IsEmpty); - Assert.AreEqual(span2d.Length, 4); - Assert.AreEqual(span2d.Width, 2); - Assert.AreEqual(span2d.Height, 2); + Assert.AreEqual(4, span2d.Length); + Assert.AreEqual(2, span2d.Width); + Assert.AreEqual(2, span2d.Height); span2d[0, 1] = 99; span2d[1, 1] = 101; - Assert.AreEqual(span2d[0, 0], 20); - Assert.AreEqual(array[1, 0, 2], 99); - Assert.AreEqual(array[1, 1, 2], 101); + Assert.AreEqual(20, span2d[0, 0]); + Assert.AreEqual(99, array[1, 0, 2]); + Assert.AreEqual(101, array[1, 1, 2]); _ = Assert.ThrowsException(() => new Span2D(array, -1, 1, 1, 1, 1)); _ = Assert.ThrowsException(() => new Span2D(array, 1, -1, 1, 1, 1)); @@ -335,7 +335,7 @@ public void Test_Span2DT_FillAndClear_2() { 4, 42, 42 } }; - CollectionAssert.AreEqual(array, filled); + CollectionAssert.AreEqual(filled, array); span2d.Clear(); @@ -345,7 +345,7 @@ public void Test_Span2DT_FillAndClear_2() { 4, 0, 0 } }; - CollectionAssert.AreEqual(array, cleared); + CollectionAssert.AreEqual(cleared, array); } [TestMethod] @@ -400,7 +400,7 @@ public void Test_Span2DT_CopyTo_2() int[] expected = { 2, 3, 5, 6 }; - CollectionAssert.AreEqual(target, expected); + CollectionAssert.AreEqual(expected, target); _ = Assert.ThrowsException(() => new Span2D(array).CopyTo(Span.Empty)); _ = Assert.ThrowsException(() => new Span2D(array, 0, 1, 2, 2).CopyTo(Span.Empty)); @@ -450,7 +450,7 @@ public void Test_Span2DT_CopyTo2D_2() { 5, 6 } }; - CollectionAssert.AreEqual(target, expected); + CollectionAssert.AreEqual(expected, target); _ = Assert.ThrowsException(() => new Span2D(array).CopyTo(new Span2D(target))); } @@ -474,7 +474,7 @@ public void Test_Span2DT_TryCopyTo() int[] expected = { 1, 2, 3, 4, 5, 6 }; - CollectionAssert.AreEqual(target, expected); + CollectionAssert.AreEqual(expected, target); } [TestMethod] @@ -500,7 +500,7 @@ public void Test_Span2DT_TryCopyTo2D() { 4, 5, 6 } }; - CollectionAssert.AreEqual(target, expected); + CollectionAssert.AreEqual(expected, target); } [TestMethod] @@ -592,7 +592,7 @@ public unsafe void Test_Span2DT_Range_Indexer_1() Span2D span2d = new(array); Span2D slice = span2d[1.., 1..]; - Assert.AreEqual(slice.Length, 9); + Assert.AreEqual(9, slice.Length); Assert.IsTrue(Unsafe.AreSame(ref array[1, 1], ref slice[0, 0])); Assert.IsTrue(Unsafe.AreSame(ref array[3, 3], ref slice[2, 2])); } @@ -605,7 +605,7 @@ public unsafe void Test_Span2DT_Range_Indexer_2() Span2D span2d = new(array); Span2D slice = span2d[0..^2, 1..^1]; - Assert.AreEqual(slice.Length, 4); + Assert.AreEqual(4, slice.Length); Assert.IsTrue(Unsafe.AreSame(ref array[0, 1], ref slice[0, 0])); Assert.IsTrue(Unsafe.AreSame(ref array[1, 2], ref slice[1, 1])); } @@ -639,20 +639,20 @@ public void Test_Span2DT_Slice_1() Span2D slice1 = span2d.Slice(1, 1, 1, 2); - Assert.AreEqual(slice1.Length, 2); - Assert.AreEqual(slice1.Height, 1); - Assert.AreEqual(slice1.Width, 2); - Assert.AreEqual(slice1[0, 0], 5); - Assert.AreEqual(slice1[0, 1], 6); + Assert.AreEqual(2, slice1.Length); + Assert.AreEqual(1, slice1.Height); + Assert.AreEqual(2, slice1.Width); + Assert.AreEqual(5, slice1[0, 0]); + Assert.AreEqual(6, slice1[0, 1]); Span2D slice2 = span2d.Slice(0, 1, 2, 2); - Assert.AreEqual(slice2.Length, 4); - Assert.AreEqual(slice2.Height, 2); - Assert.AreEqual(slice2.Width, 2); - Assert.AreEqual(slice2[0, 0], 2); - Assert.AreEqual(slice2[1, 0], 5); - Assert.AreEqual(slice2[1, 1], 6); + Assert.AreEqual(4, slice2.Length); + Assert.AreEqual(2, slice2.Height); + Assert.AreEqual(2, slice2.Width); + Assert.AreEqual(2, slice2[0, 0]); + Assert.AreEqual(5, slice2[1, 0]); + Assert.AreEqual(6, slice2[1, 1]); // Some checks for invalid arguments _ = Assert.ThrowsException(() => new Span2D(array).Slice(-1, 1, 1, 1)); @@ -678,26 +678,26 @@ public void Test_Span2DT_Slice_2() // Same as above, but with some different slicing Span2D slice1 = span2d.Slice(0, 0, 2, 2); - Assert.AreEqual(slice1.Length, 4); - Assert.AreEqual(slice1.Height, 2); - Assert.AreEqual(slice1.Width, 2); - Assert.AreEqual(slice1[0, 0], 1); - Assert.AreEqual(slice1[1, 1], 5); + Assert.AreEqual(4, slice1.Length); + Assert.AreEqual(2, slice1.Height); + Assert.AreEqual(2, slice1.Width); + Assert.AreEqual(1, slice1[0, 0]); + Assert.AreEqual(5, slice1[1, 1]); Span2D slice2 = slice1.Slice(1, 0, 1, 2); - Assert.AreEqual(slice2.Length, 2); - Assert.AreEqual(slice2.Height, 1); - Assert.AreEqual(slice2.Width, 2); - Assert.AreEqual(slice2[0, 0], 4); - Assert.AreEqual(slice2[0, 1], 5); + Assert.AreEqual(2, slice2.Length); + Assert.AreEqual(1, slice2.Height); + Assert.AreEqual(2, slice2.Width); + Assert.AreEqual(4, slice2[0, 0]); + Assert.AreEqual(5, slice2[0, 1]); Span2D slice3 = slice2.Slice(0, 1, 1, 1); - Assert.AreEqual(slice3.Length, 1); - Assert.AreEqual(slice3.Height, 1); - Assert.AreEqual(slice3.Width, 1); - Assert.AreEqual(slice3[0, 0], 5); + Assert.AreEqual(1, slice3.Length); + Assert.AreEqual(1, slice3.Height); + Assert.AreEqual(1, slice3.Width); + Assert.AreEqual(5, slice3[0, 0]); } #if NET6_0_OR_GREATER @@ -742,7 +742,7 @@ public void Test_Span2DT_TryGetSpan_From1DArray_1() bool success = span2d.TryGetSpan(out Span span); Assert.IsTrue(success); - Assert.AreEqual(span.Length, span2d.Length); + Assert.AreEqual(span2d.Length, span.Length); Assert.IsTrue(Unsafe.AreSame(ref array[0], ref span[0])); } @@ -756,7 +756,7 @@ public void Test_Span2DT_TryGetSpan_From1DArray_2() bool success = span2d.TryGetSpan(out Span span); Assert.IsTrue(success); - Assert.AreEqual(span.Length, span2d.Length); + Assert.AreEqual(span2d.Length, span.Length); Assert.IsTrue(Unsafe.AreSame(ref array[3], ref span[0])); } @@ -770,7 +770,7 @@ public void Test_Span2DT_TryGetSpan_From1DArray_3() bool success = span2d.TryGetSpan(out Span span); Assert.IsFalse(success); - Assert.AreEqual(span.Length, 0); + Assert.AreEqual(0, span.Length); } // See https://github.com/CommunityToolkit/WindowsCommunityToolkit/issues/3947 @@ -783,7 +783,7 @@ public void Test_Span2DT_TryGetSpan_From1DArray_4() bool success = span2d.TryGetSpan(out Span span); Assert.IsTrue(success); - Assert.AreEqual(span.Length, span2d.Length); + Assert.AreEqual(span2d.Length, span.Length); Assert.IsTrue(Unsafe.AreSame(ref array[0], ref span[0])); } @@ -808,10 +808,10 @@ public void Test_Span2DT_TryGetSpan_From2DArray_1() #if NETFRAMEWORK // Can't get a Span over a T[,] array on .NET Standard 2.0 Assert.IsFalse(success); - Assert.AreEqual(span.Length, 0); + Assert.AreEqual(0, span.Length); #else Assert.IsTrue(success); - Assert.AreEqual(span.Length, span2d.Length); + Assert.AreEqual(span2d.Length, span.Length); #endif } @@ -849,8 +849,8 @@ public void Test_Span2DT_ToArray_1() int[,] copy = span2d.ToArray(); - Assert.AreEqual(copy.GetLength(0), array.GetLength(0)); - Assert.AreEqual(copy.GetLength(1), array.GetLength(1)); + Assert.AreEqual(array.GetLength(0), copy.GetLength(0)); + Assert.AreEqual(array.GetLength(1), copy.GetLength(1)); CollectionAssert.AreEqual(array, copy); } @@ -869,8 +869,8 @@ public void Test_Span2DT_ToArray_2() int[,] copy = span2d.ToArray(); - Assert.AreEqual(copy.GetLength(0), 2); - Assert.AreEqual(copy.GetLength(1), 2); + Assert.AreEqual(2, copy.GetLength(0)); + Assert.AreEqual(2, copy.GetLength(1)); int[,] expected = { @@ -929,7 +929,7 @@ public void Test_Span2DT_ToString() const string expected = "CommunityToolkit.HighPerformance.Span2D[2, 3]"; - Assert.AreEqual(text, expected); + Assert.AreEqual(expected, text); } [TestMethod] @@ -988,7 +988,7 @@ public void Test_Span2DT_GetRow() int[] expected = { 4, 5, 6 }; - CollectionAssert.AreEqual(enumerable.ToArray(), expected); + CollectionAssert.AreEqual(expected, enumerable.ToArray()); _ = Assert.ThrowsException(() => new Span2D(array).GetRow(-1)); _ = Assert.ThrowsException(() => new Span2D(array).GetRow(2)); @@ -1013,7 +1013,7 @@ public unsafe void Test_Span2DT_Pointer_GetRow() int[] expected = { 4, 5, 6 }; - CollectionAssert.AreEqual(enumerable.ToArray(), expected); + CollectionAssert.AreEqual(expected, enumerable.ToArray()); _ = Assert.ThrowsException(() => new Span2D(array, 2, 3, 0).GetRow(-1)); _ = Assert.ThrowsException(() => new Span2D(array, 2, 3, 0).GetRow(2)); @@ -1034,7 +1034,7 @@ public void Test_Span2DT_GetColumn() int[] expected = { 3, 6 }; - CollectionAssert.AreEqual(enumerable.ToArray(), expected); + CollectionAssert.AreEqual(expected, enumerable.ToArray()); _ = Assert.ThrowsException(() => new Span2D(array).GetColumn(-1)); _ = Assert.ThrowsException(() => new Span2D(array).GetColumn(3)); @@ -1059,7 +1059,7 @@ public unsafe void Test_Span2DT_Pointer_GetColumn() int[] expected = { 3, 6 }; - CollectionAssert.AreEqual(enumerable.ToArray(), expected); + CollectionAssert.AreEqual(expected, enumerable.ToArray()); _ = Assert.ThrowsException(() => new Span2D(array, 2, 3, 0).GetColumn(-1)); _ = Assert.ThrowsException(() => new Span2D(array, 2, 3, 0).GetColumn(3)); @@ -1094,7 +1094,7 @@ public void Test_Span2DT_GetEnumerator() int[] expected = { 2, 3, 5, 6 }; - CollectionAssert.AreEqual(result, expected); + CollectionAssert.AreEqual(expected, result); } [TestMethod] @@ -1126,7 +1126,7 @@ ref Unsafe.AsRef(&array[((i / 2) * 3) + (i % 2) + 1]), int[] expected = { 2, 3, 5, 6 }; - CollectionAssert.AreEqual(result, expected); + CollectionAssert.AreEqual(expected, result); } [TestMethod] diff --git a/tests/CommunityToolkit.HighPerformance.UnitTests/Streams/Test_IBufferWriterStream.cs b/tests/CommunityToolkit.HighPerformance.UnitTests/Streams/Test_IBufferWriterStream.cs index 4bbaab6bb..d0113461f 100644 --- a/tests/CommunityToolkit.HighPerformance.UnitTests/Streams/Test_IBufferWriterStream.cs +++ b/tests/CommunityToolkit.HighPerformance.UnitTests/Streams/Test_IBufferWriterStream.cs @@ -52,7 +52,7 @@ public void Test_IBufferWriterStream_Write_Array() // that the state of the writer is consistent, and the written content matches. stream.Write(data, 0, data.Length); - Assert.AreEqual(writer.WrittenCount, data.Length); + Assert.AreEqual(data.Length, writer.WrittenCount); Assert.IsTrue(writer.WrittenSpan.SequenceEqual(data)); // A few tests with invalid inputs (null buffers, invalid indices, etc.) @@ -78,7 +78,7 @@ public async Task Test_IBufferWriterStream_WriteAsync_Array() // Same test as above, but using an asynchronous write instead await stream.WriteAsync(data, 0, data.Length); - Assert.AreEqual(writer.WrittenCount, data.Length); + Assert.AreEqual(data.Length, writer.WrittenCount); Assert.IsTrue(writer.WrittenSpan.SequenceEqual(data)); _ = await Assert.ThrowsExceptionAsync(() => stream.WriteAsync(null!, 0, 10)); @@ -104,14 +104,14 @@ public void Test_IBufferWriterStream_WriteByte() { // Since we're enumerating, we can also double check the current written count // at each iteration, to ensure the writes are done correctly every time. - Assert.AreEqual(writer.WrittenCount, item.Index); + Assert.AreEqual(item.Index, writer.WrittenCount); // Write a number of bytes one by one to test this API as well stream.WriteByte(item.Value); } // Validate the final written length and actual data - Assert.AreEqual(writer.WrittenCount, data.Length); + Assert.AreEqual(data.Length, writer.WrittenCount); Assert.IsTrue(data.SequenceEqual(writer.WrittenSpan)); _ = Assert.ThrowsException(() => stream.ReadByte()); @@ -129,7 +129,7 @@ public void Test_IBufferWriterStream_Write_Span() // Stream class doesn't have Spam or Memory public APIs there. stream.Write(data.Span); - Assert.AreEqual(writer.WrittenCount, data.Length); + Assert.AreEqual(data.Length, writer.WrittenCount); Assert.IsTrue(data.Span.SequenceEqual(writer.WrittenSpan)); } @@ -144,7 +144,7 @@ public async Task Test_IBufferWriterStream_WriteAsync_Memory() // Same as the other asynchronous test above, but writing from a Memory await stream.WriteAsync(data); - Assert.AreEqual(writer.WrittenCount, data.Length); + Assert.AreEqual(data.Length, writer.WrittenCount); Assert.IsTrue(data.Span.SequenceEqual(writer.WrittenSpan)); } } diff --git a/tests/CommunityToolkit.HighPerformance.UnitTests/Streams/Test_IMemoryOwnerStream.cs b/tests/CommunityToolkit.HighPerformance.UnitTests/Streams/Test_IMemoryOwnerStream.cs index c2a9266d8..c4ef26baf 100644 --- a/tests/CommunityToolkit.HighPerformance.UnitTests/Streams/Test_IMemoryOwnerStream.cs +++ b/tests/CommunityToolkit.HighPerformance.UnitTests/Streams/Test_IMemoryOwnerStream.cs @@ -22,8 +22,8 @@ public void Test_IMemoryOwnerStream_Lifecycle() Assert.IsTrue(stream.CanRead); Assert.IsTrue(stream.CanSeek); Assert.IsTrue(stream.CanWrite); - Assert.AreEqual(stream.Length, buffer.Length); - Assert.AreEqual(stream.Position, 0); + Assert.AreEqual(buffer.Length, stream.Length); + Assert.AreEqual(0, stream.Position); stream.Dispose(); diff --git a/tests/CommunityToolkit.HighPerformance.UnitTests/Streams/Test_MemoryStream.ThrowExceptions.cs b/tests/CommunityToolkit.HighPerformance.UnitTests/Streams/Test_MemoryStream.ThrowExceptions.cs index 6025c590c..e04c0e660 100644 --- a/tests/CommunityToolkit.HighPerformance.UnitTests/Streams/Test_MemoryStream.ThrowExceptions.cs +++ b/tests/CommunityToolkit.HighPerformance.UnitTests/Streams/Test_MemoryStream.ThrowExceptions.cs @@ -23,7 +23,7 @@ public void Test_MemoryStream_ParameterName_ThrowArgumentExceptionForPosition() } catch (ArgumentOutOfRangeException e) when (e.GetType() == typeof(ArgumentOutOfRangeException)) { - Assert.AreEqual(e.ParamName, nameof(Stream.Position)); + Assert.AreEqual(nameof(Stream.Position), e.ParamName); return; } @@ -45,7 +45,7 @@ public void Test_MemoryStream_ParameterName_ThrowArgumentExceptionForSeekOrigin( System.Reflection.MethodInfo? method = stream.GetType().GetMethod(nameof(Stream.Seek)); string? name = method!.GetParameters()[1].Name; - Assert.AreEqual(e.ParamName, name); + Assert.AreEqual(name, e.ParamName); return; } @@ -75,7 +75,7 @@ from method in typeof(Stream).GetMethods() normalParams[2].ParameterType == typeof(int) select normalParams[0].Name).Single(); - Assert.AreEqual(e.ParamName, name); + Assert.AreEqual(name, e.ParamName); return; } @@ -105,7 +105,7 @@ from method in typeof(Stream).GetMethods() normalParams[2].ParameterType == typeof(int) select normalParams[1].Name).Single(); - Assert.AreEqual(e.ParamName, name); + Assert.AreEqual(name, e.ParamName); return; } @@ -135,7 +135,7 @@ from method in typeof(Stream).GetMethods() normalParams[2].ParameterType == typeof(int) select normalParams[2].Name).Single(); - Assert.AreEqual(e.ParamName, name); + Assert.AreEqual(name, e.ParamName); return; } @@ -165,7 +165,7 @@ from method in typeof(Stream).GetMethods() normalParams[2].ParameterType == typeof(int) select normalParams[0].Name).Single(); - Assert.AreEqual(e.ParamName, name); + Assert.AreEqual(name, e.ParamName); return; } diff --git a/tests/CommunityToolkit.HighPerformance.UnitTests/Streams/Test_MemoryStream.cs b/tests/CommunityToolkit.HighPerformance.UnitTests/Streams/Test_MemoryStream.cs index 9b057975e..bd01a3a5e 100644 --- a/tests/CommunityToolkit.HighPerformance.UnitTests/Streams/Test_MemoryStream.cs +++ b/tests/CommunityToolkit.HighPerformance.UnitTests/Streams/Test_MemoryStream.cs @@ -23,8 +23,8 @@ public void Test_MemoryStream_Lifecycle() Assert.IsTrue(stream.CanRead); Assert.IsTrue(stream.CanSeek); Assert.IsTrue(stream.CanWrite); - Assert.AreEqual(stream.Length, memory.Length); - Assert.AreEqual(stream.Position, 0); + Assert.AreEqual(memory.Length, stream.Length); + Assert.AreEqual(0, stream.Position); stream.Dispose(); @@ -40,11 +40,11 @@ public void Test_MemoryStream_Seek() { Stream stream = new byte[100].AsMemory().AsStream(); - Assert.AreEqual(stream.Position, 0); + Assert.AreEqual(0, stream.Position); stream.Position = 42; - Assert.AreEqual(stream.Position, 42); + Assert.AreEqual(42, stream.Position); _ = Assert.ThrowsException(() => stream.Position = -1); _ = Assert.ThrowsException(() => stream.Position = 120); @@ -54,7 +54,7 @@ public void Test_MemoryStream_Seek() _ = Assert.ThrowsException(() => stream.Seek(-1, SeekOrigin.Begin)); _ = Assert.ThrowsException(() => stream.Seek(120, SeekOrigin.Begin)); - Assert.AreEqual(stream.Position, 0); + Assert.AreEqual(0, stream.Position); _ = stream.Seek(-1, SeekOrigin.End); @@ -70,7 +70,7 @@ public void Test_MemoryStream_Seek() _ = Assert.ThrowsException(() => stream.Seek(-64, SeekOrigin.Current)); _ = Assert.ThrowsException(() => stream.Seek(80, SeekOrigin.Current)); - Assert.AreEqual(stream.Position, 32); + Assert.AreEqual(32, stream.Position); } // See https://github.com/CommunityToolkit/WindowsCommunityToolkit/issues/3536 @@ -87,24 +87,24 @@ public void Test_MemoryStream_WriteToEndAndRefreshPosition() { int read = stream.Read(temp, 0, 1); - Assert.AreEqual(read, 1); - Assert.AreEqual(stream.Position, i + 1); + Assert.AreEqual(1, read); + Assert.AreEqual(i + 1, stream.Position); } - Assert.AreEqual(stream.Position, array.Length); + Assert.AreEqual(array.Length, stream.Position); // These should not throw, seeking to the end is valid stream.Position = stream.Position; - Assert.AreEqual(stream.Position, array.Length); + Assert.AreEqual(array.Length, stream.Position); _ = stream.Seek(array.Length, SeekOrigin.Begin); - Assert.AreEqual(stream.Position, array.Length); + Assert.AreEqual(array.Length, stream.Position); _ = stream.Seek(0, SeekOrigin.Current); - Assert.AreEqual(stream.Position, array.Length); + Assert.AreEqual(array.Length, stream.Position); _ = stream.Seek(0, SeekOrigin.End); - Assert.AreEqual(stream.Position, array.Length); + Assert.AreEqual(array.Length, stream.Position); } [TestMethod] @@ -116,7 +116,7 @@ public void Test_MemoryStream_ReadWrite_Array() stream.Write(data, 0, data.Length); - Assert.AreEqual(stream.Position, data.Length); + Assert.AreEqual(data.Length, stream.Position); stream.Position = 0; @@ -124,8 +124,8 @@ public void Test_MemoryStream_ReadWrite_Array() int bytesRead = stream.Read(result, 0, result.Length); - Assert.AreEqual(bytesRead, result.Length); - Assert.AreEqual(stream.Position, data.Length); + Assert.AreEqual(result.Length, bytesRead); + Assert.AreEqual(data.Length, stream.Position); Assert.IsTrue(data.AsSpan().SequenceEqual(result)); _ = Assert.ThrowsException(() => stream.Write(null!, 0, 10)); @@ -148,7 +148,7 @@ public async Task Test_MemoryStream_ReadWriteAsync_Array() await stream.WriteAsync(data, 0, data.Length); - Assert.AreEqual(stream.Position, data.Length); + Assert.AreEqual(data.Length, stream.Position); stream.Position = 0; @@ -156,8 +156,8 @@ public async Task Test_MemoryStream_ReadWriteAsync_Array() int bytesRead = await stream.ReadAsync(result, 0, result.Length); - Assert.AreEqual(bytesRead, result.Length); - Assert.AreEqual(stream.Position, data.Length); + Assert.AreEqual(result.Length, bytesRead); + Assert.AreEqual(data.Length, stream.Position); Assert.IsTrue(data.AsSpan().SequenceEqual(result)); _ = await Assert.ThrowsExceptionAsync(() => stream.WriteAsync(null!, 0, 10)); @@ -180,12 +180,12 @@ public void Test_MemoryStream_ReadWriteByte() foreach (HighPerformance.Enumerables.ReadOnlySpanEnumerable.Item item in data.Enumerate()) { - Assert.AreEqual(stream.Position, item.Index); + Assert.AreEqual(item.Index, stream.Position); stream.WriteByte(item.Value); } - Assert.AreEqual(stream.Position, data.Length); + Assert.AreEqual(data.Length, stream.Position); stream.Position = 0; @@ -196,14 +196,14 @@ public void Test_MemoryStream_ReadWriteByte() value = checked((byte)stream.ReadByte()); } - Assert.AreEqual(stream.Position, data.Length); + Assert.AreEqual(data.Length, stream.Position); Assert.IsTrue(data.SequenceEqual(result)); _ = Assert.ThrowsException(() => stream.WriteByte(128)); int exitCode = stream.ReadByte(); - Assert.AreEqual(exitCode, -1); + Assert.AreEqual(-1, exitCode); } [TestMethod] @@ -217,7 +217,7 @@ public void Test_MemoryStream_ReadWrite_Span() // Stream class doesn't have Spam or Memory public APIs there. stream.Write(data.Span); - Assert.AreEqual(stream.Position, data.Length); + Assert.AreEqual(data.Length, stream.Position); stream.Position = 0; @@ -225,8 +225,8 @@ public void Test_MemoryStream_ReadWrite_Span() int bytesRead = stream.Read(result); - Assert.AreEqual(bytesRead, result.Length); - Assert.AreEqual(stream.Position, data.Length); + Assert.AreEqual(result.Length, bytesRead); + Assert.AreEqual(data.Length, stream.Position); Assert.IsTrue(data.Span.SequenceEqual(result)); } @@ -239,7 +239,7 @@ public async Task Test_MemoryStream_ReadWriteAsync_Memory() await stream.WriteAsync(data); - Assert.AreEqual(stream.Position, data.Length); + Assert.AreEqual(data.Length, stream.Position); stream.Position = 0; @@ -247,8 +247,8 @@ public async Task Test_MemoryStream_ReadWriteAsync_Memory() int bytesRead = await stream.ReadAsync(result); - Assert.AreEqual(bytesRead, result.Length); - Assert.AreEqual(stream.Position, data.Length); + Assert.AreEqual(result.Length, bytesRead); + Assert.AreEqual(data.Length, stream.Position); Assert.IsTrue(data.Span.SequenceEqual(result.Span)); } @@ -261,7 +261,7 @@ public void Test_MemoryStream_CopyTo() source.Write(data.Span); - Assert.AreEqual(source.Position, data.Length); + Assert.AreEqual(data.Length, source.Position); source.Position = 0; @@ -277,8 +277,8 @@ public void Test_MemoryStream_CopyTo() int bytesRead = destination.Read(result.Span); - Assert.AreEqual(bytesRead, result.Length); - Assert.AreEqual(destination.Position, data.Length); + Assert.AreEqual(result.Length, bytesRead); + Assert.AreEqual(data.Length, destination.Position); Assert.IsTrue(data.Span.SequenceEqual(result.Span)); } @@ -291,7 +291,7 @@ public async Task Test_MemoryStream_CopyToAsync() await source.WriteAsync(data); - Assert.AreEqual(source.Position, data.Length); + Assert.AreEqual(data.Length, source.Position); source.Position = 0; @@ -307,8 +307,8 @@ public async Task Test_MemoryStream_CopyToAsync() int bytesRead = await destination.ReadAsync(result); - Assert.AreEqual(bytesRead, result.Length); - Assert.AreEqual(destination.Position, data.Length); + Assert.AreEqual(result.Length, bytesRead); + Assert.AreEqual(data.Length, destination.Position); Assert.IsTrue(data.Span.SequenceEqual(result.Span)); } diff --git a/tests/CommunityToolkit.HighPerformance.UnitTests/Test_Box{T}.cs b/tests/CommunityToolkit.HighPerformance.UnitTests/Test_Box{T}.cs index 2a3115c46..aaa1100cd 100644 --- a/tests/CommunityToolkit.HighPerformance.UnitTests/Test_Box{T}.cs +++ b/tests/CommunityToolkit.HighPerformance.UnitTests/Test_Box{T}.cs @@ -65,9 +65,9 @@ private static void Test(T value, T test) { Box? box = value; - Assert.AreEqual(box.GetReference(), value); - Assert.AreEqual(box.ToString(), value.ToString()); - Assert.AreEqual(box.GetHashCode(), value.GetHashCode()); + Assert.AreEqual(value, box.GetReference()); + Assert.AreEqual(value.ToString(), box.ToString()); + Assert.AreEqual(value.GetHashCode(), box.GetHashCode()); object obj = value; @@ -76,22 +76,22 @@ private static void Test(T value, T test) Assert.IsTrue(success); Assert.IsTrue(ReferenceEquals(obj, box)); Assert.IsNotNull(box); - Assert.AreEqual(box.GetReference(), value); - Assert.AreEqual(box.ToString(), value.ToString()); - Assert.AreEqual(box.GetHashCode(), value.GetHashCode()); + Assert.AreEqual(value, box.GetReference()); + Assert.AreEqual(value.ToString(), box.ToString()); + Assert.AreEqual(value.GetHashCode(), box.GetHashCode()); box = Box.DangerousGetFrom(obj); Assert.IsTrue(ReferenceEquals(obj, box)); - Assert.AreEqual(box.GetReference(), value); - Assert.AreEqual(box.ToString(), value.ToString()); - Assert.AreEqual(box.GetHashCode(), value.GetHashCode()); + Assert.AreEqual(value, box.GetReference()); + Assert.AreEqual(value.ToString(), box.ToString()); + Assert.AreEqual(value.GetHashCode(), box.GetHashCode()); box.GetReference() = test; - Assert.AreEqual(box.GetReference(), test); - Assert.AreEqual(box.ToString(), test.ToString()); - Assert.AreEqual(box.GetHashCode(), test.GetHashCode()); + Assert.AreEqual(test, box.GetReference()); + Assert.AreEqual(test.ToString(), box.ToString()); + Assert.AreEqual(test.GetHashCode(), box.GetHashCode()); Assert.AreEqual(obj, test); } } diff --git a/tests/CommunityToolkit.HighPerformance.UnitTests/Test_NullableRef{T}.cs b/tests/CommunityToolkit.HighPerformance.UnitTests/Test_NullableRef{T}.cs index 7799a67ff..1840e3f9d 100644 --- a/tests/CommunityToolkit.HighPerformance.UnitTests/Test_NullableRef{T}.cs +++ b/tests/CommunityToolkit.HighPerformance.UnitTests/Test_NullableRef{T}.cs @@ -24,7 +24,7 @@ public void Test_NullableRefOfT_CreateNullableRefOfT_Ok() reference.Value++; - Assert.AreEqual(value, 2); + Assert.AreEqual(2, value); } [TestMethod] diff --git a/tests/CommunityToolkit.HighPerformance.UnitTests/Test_Ref{T}.cs b/tests/CommunityToolkit.HighPerformance.UnitTests/Test_Ref{T}.cs index ce17f01bb..314b96154 100644 --- a/tests/CommunityToolkit.HighPerformance.UnitTests/Test_Ref{T}.cs +++ b/tests/CommunityToolkit.HighPerformance.UnitTests/Test_Ref{T}.cs @@ -22,7 +22,7 @@ public void Test_RefOfT_CreateRefOfT() reference.Value++; - Assert.AreEqual(value, 2); + Assert.AreEqual(2, value); } } diff --git a/tests/CommunityToolkit.Mvvm.DisableINotifyPropertyChanging.UnitTests/Test_DisableINotifyPropertyChanging.cs b/tests/CommunityToolkit.Mvvm.DisableINotifyPropertyChanging.UnitTests/Test_DisableINotifyPropertyChanging.cs index c5fc2c4a0..50ac2a118 100644 --- a/tests/CommunityToolkit.Mvvm.DisableINotifyPropertyChanging.UnitTests/Test_DisableINotifyPropertyChanging.cs +++ b/tests/CommunityToolkit.Mvvm.DisableINotifyPropertyChanging.UnitTests/Test_DisableINotifyPropertyChanging.cs @@ -38,8 +38,8 @@ public void Test_ObservableObject_Events() model.Data = 42; - Assert.AreEqual(changed.Item1?.PropertyName, nameof(SampleModel.Data)); - Assert.AreEqual(changed.Item2, 42); + Assert.AreEqual(nameof(SampleModel.Data), changed.Item1?.PropertyName); + Assert.AreEqual(42, changed.Item2); } public class SampleModel : ObservableObject diff --git a/tests/CommunityToolkit.Mvvm.Internals.UnitTests/Test_ConditionalWeakTable2.cs b/tests/CommunityToolkit.Mvvm.Internals.UnitTests/Test_ConditionalWeakTable2.cs index 976d12f40..04ebdb4c8 100644 --- a/tests/CommunityToolkit.Mvvm.Internals.UnitTests/Test_ConditionalWeakTable2.cs +++ b/tests/CommunityToolkit.Mvvm.Internals.UnitTests/Test_ConditionalWeakTable2.cs @@ -356,7 +356,7 @@ public void RemoveAll_AddMany_RemoveAll_AllItemsRemoved() { object current = cwt.GetValue(keys[i], _ => values[i]); - Assert.AreSame(current, values[i]); + Assert.AreSame(values[i], current); } int count = 0; @@ -365,8 +365,8 @@ public void RemoveAll_AddMany_RemoveAll_AllItemsRemoved() { while (enumerator.MoveNext()) { - Assert.AreSame(enumerator.GetKey(), keys[count]); - Assert.AreSame(enumerator.GetValue(), values[count]); + Assert.AreSame(keys[count], enumerator.GetKey()); + Assert.AreSame(values[count], enumerator.GetValue()); count++; } diff --git a/tests/CommunityToolkit.Mvvm.Internals.UnitTests/Test_Dictionary2.cs b/tests/CommunityToolkit.Mvvm.Internals.UnitTests/Test_Dictionary2.cs index 06c418c86..f5f1c3563 100644 --- a/tests/CommunityToolkit.Mvvm.Internals.UnitTests/Test_Dictionary2.cs +++ b/tests/CommunityToolkit.Mvvm.Internals.UnitTests/Test_Dictionary2.cs @@ -44,8 +44,8 @@ private static void AddItems(T[] keys) // Verify the key now exists Assert.IsTrue(dictionary.ContainsKey(key)); Assert.IsTrue(dictionary.TryGetValue(key, out obj)); - Assert.AreSame(obj, value); - Assert.AreSame(obj, values[i]); + Assert.AreSame(value, obj); + Assert.AreSame(values[i], obj); // Get the key again, should point to the same location ref object? value2 = ref dictionary.GetOrAddValueRef(key); diff --git a/tests/CommunityToolkit.Mvvm.Internals.UnitTests/Test_Messenger.cs b/tests/CommunityToolkit.Mvvm.Internals.UnitTests/Test_Messenger.cs index 70f5408c2..bd8322dd8 100644 --- a/tests/CommunityToolkit.Mvvm.Internals.UnitTests/Test_Messenger.cs +++ b/tests/CommunityToolkit.Mvvm.Internals.UnitTests/Test_Messenger.cs @@ -41,7 +41,7 @@ void Test() Assert.IsTrue(messenger.IsRegistered(recipient)); - Assert.AreEqual(GetRecipientsMapCount(messenger), 1); + Assert.AreEqual(1, GetRecipientsMapCount(messenger)); GC.KeepAlive(recipient); } @@ -57,7 +57,7 @@ void Test() GC.Collect(); GC.WaitForPendingFinalizers(); - Assert.AreEqual(GetRecipientsMapCount(messenger), 0); + Assert.AreEqual(0, GetRecipientsMapCount(messenger)); GC.KeepAlive(messenger); } diff --git a/tests/CommunityToolkit.Mvvm.UnitTests/Collections/Test_ObservableGroup.cs b/tests/CommunityToolkit.Mvvm.UnitTests/Collections/Test_ObservableGroup.cs index 15c28865f..6ca7cad3c 100644 --- a/tests/CommunityToolkit.Mvvm.UnitTests/Collections/Test_ObservableGroup.cs +++ b/tests/CommunityToolkit.Mvvm.UnitTests/Collections/Test_ObservableGroup.cs @@ -17,8 +17,8 @@ public void Test_ObservableGroup_Ctor_ShouldHaveExpectedState() { ObservableGroup group = new("key"); - Assert.AreEqual(group.Key, "key"); - Assert.AreEqual(group.Count, 0); + Assert.AreEqual("key", group.Key); + Assert.AreEqual(0, group.Count); } [TestMethod] @@ -27,8 +27,8 @@ public void Test_ObservableGroup_Ctor_WithGrouping_ShouldHaveExpectedState() IntGroup source = new("key", new[] { 1, 2, 3 }); ObservableGroup group = new(source); - Assert.AreEqual(group.Key, "key"); - CollectionAssert.AreEqual(group, new[] { 1, 2, 3 }); + Assert.AreEqual("key", group.Key); + CollectionAssert.AreEqual(new[] { 1, 2, 3 }, group); } [TestMethod] @@ -37,8 +37,8 @@ public void Test_ObservableGroup_Ctor_WithCollection_ShouldHaveExpectedState() int[] source = new[] { 1, 2, 3 }; ObservableGroup group = new("key", source); - Assert.AreEqual(group.Key, "key"); - CollectionAssert.AreEqual(group, new[] { 1, 2, 3 }); + Assert.AreEqual("key", group.Key); + CollectionAssert.AreEqual(new[] { 1, 2, 3 }, group); } [TestMethod] @@ -52,8 +52,8 @@ public void Test_ObservableGroup_Add_ShouldRaiseEvent() group.Add(4); - Assert.AreEqual(group.Key, "key"); - CollectionAssert.AreEqual(group, new[] { 1, 2, 3, 4 }); + Assert.AreEqual("key", group.Key); + CollectionAssert.AreEqual(new[] { 1, 2, 3, 4 }, group); Assert.IsTrue(collectionChangedEventRaised); } @@ -68,8 +68,8 @@ public void Test_ObservableGroup_Update_ShouldRaiseEvent() group[1] = 4; - Assert.AreEqual(group.Key, "key"); - CollectionAssert.AreEqual(group, new[] { 1, 4, 3 }); + Assert.AreEqual("key", group.Key); + CollectionAssert.AreEqual(new[] { 1, 4, 3 }, group); Assert.IsTrue(collectionChangedEventRaised); } @@ -84,8 +84,8 @@ public void Test_ObservableGroup_Remove_ShouldRaiseEvent() _ = group.Remove(1); - Assert.AreEqual(group.Key, "key"); - CollectionAssert.AreEqual(group, new[] { 2, 3 }); + Assert.AreEqual("key", group.Key); + CollectionAssert.AreEqual(new[] { 2, 3 }, group); Assert.IsTrue(collectionChangedEventRaised); } @@ -100,8 +100,8 @@ public void Test_ObservableGroup_Clear_ShouldRaiseEvent() group.Clear(); - Assert.AreEqual(group.Key, "key"); - Assert.AreEqual(group.Count, 0); + Assert.AreEqual("key", group.Key); + Assert.AreEqual(0, group.Count); Assert.IsTrue(collectionChangedEventRaised); } @@ -113,8 +113,8 @@ public void Test_ObservableGroup_IReadOnlyObservableGroup_ShouldReturnExpectedVa ObservableGroup group = new("key", Enumerable.Range(0, count)); IReadOnlyObservableGroup iReadOnlyObservableGroup = group; - Assert.AreEqual(iReadOnlyObservableGroup.Key, "key"); - Assert.AreEqual(iReadOnlyObservableGroup.Count, count); + Assert.AreEqual("key", iReadOnlyObservableGroup.Key); + Assert.AreEqual(count, iReadOnlyObservableGroup.Count); } [TestMethod] diff --git a/tests/CommunityToolkit.Mvvm.UnitTests/Collections/Test_ObservableGroupedCollection.cs b/tests/CommunityToolkit.Mvvm.UnitTests/Collections/Test_ObservableGroupedCollection.cs index 0576c9bd3..6c685934d 100644 --- a/tests/CommunityToolkit.Mvvm.UnitTests/Collections/Test_ObservableGroupedCollection.cs +++ b/tests/CommunityToolkit.Mvvm.UnitTests/Collections/Test_ObservableGroupedCollection.cs @@ -18,7 +18,7 @@ public void Test_ObservableGroupedCollection_Ctor_ShouldHaveExpectedValues() { ObservableGroupedCollection groupCollection = new(); - Assert.AreEqual(groupCollection.Count, 0); + Assert.AreEqual(0, groupCollection.Count); } [TestMethod] @@ -31,13 +31,13 @@ public void Test_ObservableGroupedCollection_Ctor_WithGroups_ShouldHaveExpectedV }; ObservableGroupedCollection groupCollection = new(groups); - Assert.AreEqual(groupCollection.Count, 2); + Assert.AreEqual(2, groupCollection.Count); - Assert.AreEqual(groupCollection[0].Key, "A"); - CollectionAssert.AreEqual(groupCollection[0], new[] { 1, 3, 5 }); + Assert.AreEqual("A", groupCollection[0].Key); + CollectionAssert.AreEqual(new[] { 1, 3, 5 }, groupCollection[0]); - Assert.AreEqual(groupCollection[1].Key, "B"); - CollectionAssert.AreEqual(groupCollection[1], new[] { 2, 4, 6 }); + Assert.AreEqual("B", groupCollection[1].Key); + CollectionAssert.AreEqual(new[] { 2, 4, 6 }, groupCollection[1]); } [TestMethod] diff --git a/tests/CommunityToolkit.Mvvm.UnitTests/Collections/Test_ObservableGroupedCollectionExtensions.cs b/tests/CommunityToolkit.Mvvm.UnitTests/Collections/Test_ObservableGroupedCollectionExtensions.cs index 3086e36f4..54e5b0792 100644 --- a/tests/CommunityToolkit.Mvvm.UnitTests/Collections/Test_ObservableGroupedCollectionExtensions.cs +++ b/tests/CommunityToolkit.Mvvm.UnitTests/Collections/Test_ObservableGroupedCollectionExtensions.cs @@ -25,7 +25,7 @@ public void Test_ObservableGroupedCollectionExtensions_FirstGroupByKey_WhenGroup ObservableGroup result = groupedCollection.FirstGroupByKey("B"); - Assert.AreSame(result, target); + Assert.AreSame(target, result); } [TestMethod] @@ -52,7 +52,7 @@ public void Test_ObservableGroupedCollectionExtensions_FirstGroupByKeyOrDefault_ ObservableGroup? result = groupedCollection.FirstGroupByKeyOrDefault("B"); - Assert.AreSame(result, target); + Assert.AreSame(target, result); } [TestMethod] @@ -78,7 +78,7 @@ public void Test_ObservableGroupedCollectionExtensions_FirstGroupByKey_WhenGroup int result = groupedCollection.FirstGroupByKey("B")[2]; - Assert.AreEqual(result, 12); + Assert.AreEqual(12, result); } [TestMethod] @@ -107,7 +107,7 @@ public void Test_ObservableGroupedCollectionExtensions_FirstGroupByKey_WhenGroup int result = groupedCollection.FirstGroupByKey("B")[2]; - Assert.AreEqual(result, 12); + Assert.AreEqual(12, result); } [TestMethod] @@ -118,8 +118,8 @@ public void Test_ObservableGroupedCollectionExtensions_AddGroup_WithItem_ShouldA ObservableGroup addedGroup = groupedCollection.AddGroup("new key", new[] { 23 }); Assert.IsNotNull(addedGroup); - Assert.AreEqual(addedGroup.Key, "new key"); - CollectionAssert.AreEqual(addedGroup, new[] { 23 }); + Assert.AreEqual("new key", addedGroup.Key); + CollectionAssert.AreEqual(new[] { 23 }, addedGroup); CollectionAssert.AreEqual(groupedCollection, new[] { addedGroup }); } @@ -131,8 +131,8 @@ public void Test_ObservableGroupedCollectionExtensions_AddGroup_WithCollection_S ObservableGroup addedGroup = groupedCollection.AddGroup("new key", new[] { 23, 10, 42 }); Assert.IsNotNull(addedGroup); - Assert.AreEqual(addedGroup.Key, "new key"); - CollectionAssert.AreEqual(addedGroup, new[] { 23, 10, 42 }); + Assert.AreEqual("new key", addedGroup.Key); + CollectionAssert.AreEqual(new[] { 23, 10, 42 }, addedGroup); CollectionAssert.AreEqual(groupedCollection, new[] { addedGroup }); } @@ -144,8 +144,8 @@ public void Test_ObservableGroupedCollectionExtensions_AddGroup_WithParamsCollec ObservableGroup addedGroup = groupedCollection.AddGroup("new key", new[] { 23, 10, 42 }); Assert.IsNotNull(addedGroup); - Assert.AreEqual(addedGroup.Key, "new key"); - CollectionAssert.AreEqual(addedGroup, new[] { 23, 10, 42 }); + Assert.AreEqual("new key", addedGroup.Key); + CollectionAssert.AreEqual(new[] { 23, 10, 42 }, addedGroup); CollectionAssert.AreEqual(groupedCollection, new[] { addedGroup }); } @@ -189,8 +189,8 @@ public void Test_ObservableGroupedCollectionExtensions_AddItem_WhenTargetGroupDo ObservableGroup addedGroup = groupedCollection.AddItem("new key", 23); Assert.IsNotNull(addedGroup); - Assert.AreEqual(addedGroup.Key, "new key"); - CollectionAssert.AreEqual(addedGroup, new[] { 23 }); + Assert.AreEqual("new key", addedGroup.Key); + CollectionAssert.AreEqual(new[] { 23 }, addedGroup); CollectionAssert.AreEqual(groupedCollection, new[] { addedGroup }); } @@ -207,20 +207,20 @@ public void Test_ObservableGroupedCollectionExtensions_AddItem_WhenSingleTargetG ObservableGroup addedGroup = groupedCollection.AddItem("B", 23); - Assert.AreSame(addedGroup, targetGroup); - Assert.AreEqual(addedGroup.Key, "B"); - CollectionAssert.AreEqual(addedGroup, new[] { 4, 5, 6, 23 }); + Assert.AreSame(targetGroup, addedGroup); + Assert.AreEqual("B", addedGroup.Key); + CollectionAssert.AreEqual(new[] { 4, 5, 6, 23 }, addedGroup); - Assert.AreEqual(groupedCollection.Count, 3); + Assert.AreEqual(3, groupedCollection.Count); - Assert.AreEqual(groupedCollection[0].Key, "A"); - CollectionAssert.AreEqual(groupedCollection[0], new[] { 1, 2, 3 }); + Assert.AreEqual("A", groupedCollection[0].Key); + CollectionAssert.AreEqual(new[] { 1, 2, 3 }, groupedCollection[0]); - Assert.AreEqual(groupedCollection[1].Key, "B"); - CollectionAssert.AreEqual(groupedCollection[1], new[] { 4, 5, 6, 23 }); + Assert.AreEqual("B", groupedCollection[1].Key); + CollectionAssert.AreEqual(new[] { 4, 5, 6, 23 }, groupedCollection[1]); - Assert.AreEqual(groupedCollection[2].Key, "C"); - CollectionAssert.AreEqual(groupedCollection[2], new[] { 7, 8 }); + Assert.AreEqual("C", groupedCollection[2].Key); + CollectionAssert.AreEqual(new[] { 7, 8 }, groupedCollection[2]); } [TestMethod] @@ -237,23 +237,23 @@ public void Test_ObservableGroupedCollectionExtensions_AddItem_WhenSeveralTarget ObservableGroup addedGroup = groupedCollection.AddItem("B", 23); - Assert.AreSame(addedGroup, targetGroup); - Assert.AreEqual(addedGroup.Key, "B"); - CollectionAssert.AreEqual(addedGroup, new[] { 4, 5, 6, 23 }); + Assert.AreSame(targetGroup, addedGroup); + Assert.AreEqual("B", addedGroup.Key); + CollectionAssert.AreEqual(new[] { 4, 5, 6, 23 }, addedGroup); - Assert.AreEqual(groupedCollection.Count, 4); + Assert.AreEqual(4, groupedCollection.Count); - Assert.AreEqual(groupedCollection[0].Key, "A"); - CollectionAssert.AreEqual(groupedCollection[0], new[] { 1, 2, 3 }); + Assert.AreEqual("A", groupedCollection[0].Key); + CollectionAssert.AreEqual(new[] { 1, 2, 3 }, groupedCollection[0]); - Assert.AreEqual(groupedCollection[1].Key, "B"); - CollectionAssert.AreEqual(groupedCollection[1], new[] { 4, 5, 6, 23 }); + Assert.AreEqual("B", groupedCollection[1].Key); + CollectionAssert.AreEqual(new[] { 4, 5, 6, 23 }, groupedCollection[1]); - Assert.AreEqual(groupedCollection[2].Key, "B"); - CollectionAssert.AreEqual(groupedCollection[2], new[] { 7, 8, 9 }); + Assert.AreEqual("B", groupedCollection[2].Key); + CollectionAssert.AreEqual(new[] { 7, 8, 9 }, groupedCollection[2]); - Assert.AreEqual(groupedCollection[3].Key, "C"); - CollectionAssert.AreEqual(groupedCollection[3], new[] { 10, 11 }); + Assert.AreEqual("C", groupedCollection[3].Key); + CollectionAssert.AreEqual(new[] { 10, 11 }, groupedCollection[3]); } [TestMethod] @@ -325,9 +325,9 @@ public void Test_ObservableGroupedCollectionExtensions_RemoveGroup_WhenGroupDoes groupedCollection.RemoveGroup("I do not exist"); - Assert.AreEqual(groupedCollection.Count, 1); - Assert.AreEqual(groupedCollection[0].Key, "A"); - CollectionAssert.AreEqual(groupedCollection[0], new[] { 1, 2, 3 }); + Assert.AreEqual(1, groupedCollection.Count); + Assert.AreEqual("A", groupedCollection[0].Key); + CollectionAssert.AreEqual(new[] { 1, 2, 3 }, groupedCollection[0]); } [TestMethod] @@ -340,9 +340,9 @@ public void Test_ObservableGroupedCollectionExtensions_RemoveGroup_WhenSingleGro groupedCollection.RemoveGroup("B"); - Assert.AreEqual(groupedCollection.Count, 1); - Assert.AreEqual(groupedCollection[0].Key, "A"); - CollectionAssert.AreEqual(groupedCollection[0], new[] { 1, 2, 3 }); + Assert.AreEqual(1, groupedCollection.Count); + Assert.AreEqual("A", groupedCollection[0].Key); + CollectionAssert.AreEqual(new[] { 1, 2, 3 }, groupedCollection[0]); } [TestMethod] @@ -356,13 +356,13 @@ public void Test_ObservableGroupedCollectionExtensions_RemoveGroup_WhenSeveralGr groupedCollection.RemoveGroup("B"); - Assert.AreEqual(groupedCollection.Count, 2); + Assert.AreEqual(2, groupedCollection.Count); - Assert.AreEqual(groupedCollection[0].Key, "A"); - CollectionAssert.AreEqual(groupedCollection[0], new[] { 1, 2, 3 }); + Assert.AreEqual("A", groupedCollection[0].Key); + CollectionAssert.AreEqual(new[] { 1, 2, 3 }, groupedCollection[0]); - Assert.AreEqual(groupedCollection[1].Key, "B"); - CollectionAssert.AreEqual(groupedCollection[1], new[] { 7, 8 }); + Assert.AreEqual("B", groupedCollection[1].Key); + CollectionAssert.AreEqual(new[] { 7, 8 }, groupedCollection[1]); } [TestMethod] @@ -377,13 +377,13 @@ public void Test_ObservableGroupedCollectionExtensions_RemoveItem_WhenGroupDoesN groupedCollection.RemoveItem("I do not exist", 8, removeGroupIfEmpty); - Assert.AreEqual(groupedCollection.Count, 2); + Assert.AreEqual(2, groupedCollection.Count); - Assert.AreEqual(groupedCollection[0].Key, "A"); - CollectionAssert.AreEqual(groupedCollection[0], new[] { 1, 2, 3 }); + Assert.AreEqual("A", groupedCollection[0].Key); + CollectionAssert.AreEqual(new[] { 1, 2, 3 }, groupedCollection[0]); - Assert.AreEqual(groupedCollection[1].Key, "B"); - CollectionAssert.AreEqual(groupedCollection[1], new[] { 4, 5, 6 }); + Assert.AreEqual("B", groupedCollection[1].Key); + CollectionAssert.AreEqual(new[] { 4, 5, 6 }, groupedCollection[1]); } [TestMethod] @@ -398,13 +398,13 @@ public void Test_ObservableGroupedCollectionExtensions_RemoveItem_WhenGroupExist groupedCollection.RemoveItem("B", 8, removeGroupIfEmpty); - Assert.AreEqual(groupedCollection.Count, 2); + Assert.AreEqual(2, groupedCollection.Count); - Assert.AreEqual(groupedCollection[0].Key, "A"); - CollectionAssert.AreEqual(groupedCollection[0], new[] { 1, 2, 3 }); + Assert.AreEqual("A", groupedCollection[0].Key); + CollectionAssert.AreEqual(new[] { 1, 2, 3 }, groupedCollection[0]); - Assert.AreEqual(groupedCollection[1].Key, "B"); - CollectionAssert.AreEqual(groupedCollection[1], new[] { 4, 5, 6 }); + Assert.AreEqual("B", groupedCollection[1].Key); + CollectionAssert.AreEqual(new[] { 4, 5, 6 }, groupedCollection[1]); } [TestMethod] @@ -419,13 +419,13 @@ public void Test_ObservableGroupedCollectionExtensions_RemoveItem_WhenGroupAndIt groupedCollection.RemoveItem("B", 5, removeGroupIfEmpty); - Assert.AreEqual(groupedCollection.Count, 2); + Assert.AreEqual(2, groupedCollection.Count); - Assert.AreEqual(groupedCollection[0].Key, "A"); - CollectionAssert.AreEqual(groupedCollection[0], new[] { 1, 2, 3 }); + Assert.AreEqual("A", groupedCollection[0].Key); + CollectionAssert.AreEqual(new[] { 1, 2, 3 }, groupedCollection[0]); - Assert.AreEqual(groupedCollection[1].Key, "B"); - CollectionAssert.AreEqual(groupedCollection[1], new[] { 4, 6 }); + Assert.AreEqual("B", groupedCollection[1].Key); + CollectionAssert.AreEqual(new[] { 4, 6 }, groupedCollection[1]); } [TestMethod] @@ -440,15 +440,15 @@ public void Test_ObservableGroupedCollectionExtensions_RemoveItem_WhenRemovingLa groupedCollection.RemoveItem("B", 4, removeGroupIfEmpty); - Assert.AreEqual(groupedCollection.Count, expectGroupRemoved ? 1 : 2); + Assert.AreEqual(expectGroupRemoved ? 1 : 2, groupedCollection.Count); - Assert.AreEqual(groupedCollection[0].Key, "A"); - CollectionAssert.AreEqual(groupedCollection[0], new[] { 1, 2, 3 }); + Assert.AreEqual("A", groupedCollection[0].Key); + CollectionAssert.AreEqual(new[] { 1, 2, 3 }, groupedCollection[0]); if (!expectGroupRemoved) { - Assert.AreEqual(groupedCollection[1].Key, "B"); - Assert.AreEqual(groupedCollection[1].Count, 0); + Assert.AreEqual("B", groupedCollection[1].Key); + Assert.AreEqual(0, groupedCollection[1].Count); } } } diff --git a/tests/CommunityToolkit.Mvvm.UnitTests/Collections/Test_ReadOnlyObservableGroup.cs b/tests/CommunityToolkit.Mvvm.UnitTests/Collections/Test_ReadOnlyObservableGroup.cs index 88da0a1e2..5e0a4feff 100644 --- a/tests/CommunityToolkit.Mvvm.UnitTests/Collections/Test_ReadOnlyObservableGroup.cs +++ b/tests/CommunityToolkit.Mvvm.UnitTests/Collections/Test_ReadOnlyObservableGroup.cs @@ -20,8 +20,8 @@ public void Test_ReadOnlyObservableGroup_Ctor_WithKeyAndOBservableCollection_Sho ObservableCollection source = new(new[] { 1, 2, 3 }); ReadOnlyObservableGroup group = new("key", source); - Assert.AreEqual(group.Key, "key"); - CollectionAssert.AreEqual(group, new[] { 1, 2, 3 }); + Assert.AreEqual("key", group.Key); + CollectionAssert.AreEqual(new[] { 1, 2, 3 }, group); } [TestMethod] @@ -31,8 +31,8 @@ public void Test_ReadOnlyObservableGroup_Ctor_ObservableGroup_ShouldHaveExpected ObservableGroup sourceGroup = new("key", source); ReadOnlyObservableGroup group = new(sourceGroup); - Assert.AreEqual(group.Key, "key"); - CollectionAssert.AreEqual(group, new[] { 1, 2, 3 }); + Assert.AreEqual("key", group.Key); + CollectionAssert.AreEqual(new[] { 1, 2, 3 }, group); } [TestMethod] @@ -41,8 +41,8 @@ public void Test_ReadOnlyObservableGroup_Ctor_WithKeyAndCollection_ShouldHaveExp ObservableCollection source = new() { 1, 2, 3 }; ReadOnlyObservableGroup group = new("key", source); - Assert.AreEqual(group.Key, "key"); - CollectionAssert.AreEqual(group, new[] { 1, 2, 3 }); + Assert.AreEqual("key", group.Key); + CollectionAssert.AreEqual(new[] { 1, 2, 3 }, group); } [TestMethod] @@ -57,8 +57,8 @@ public void Test_ReadOnlyObservableGroup_Add_ShouldRaiseEvent() sourceGroup.Add(4); - Assert.AreEqual(group.Key, "key"); - CollectionAssert.AreEqual(group, new[] { 1, 2, 3, 4 }); + Assert.AreEqual("key", group.Key); + CollectionAssert.AreEqual(new[] { 1, 2, 3, 4 }, group); Assert.IsTrue(collectionChangedEventRaised); } @@ -75,8 +75,8 @@ public void Test_ReadOnlyObservableGroup_Update_ShouldRaiseEvent() sourceGroup[1] = 4; - Assert.AreEqual(group.Key, "key"); - CollectionAssert.AreEqual(group, new[] { 1, 4, 3 }); + Assert.AreEqual("key", group.Key); + CollectionAssert.AreEqual(new[] { 1, 4, 3 }, group); Assert.IsTrue(collectionChangedEventRaised); } @@ -93,8 +93,8 @@ public void Test_ReadOnlyObservableGroup_Remove_ShouldRaiseEvent() _ = sourceGroup.Remove(1); - Assert.AreEqual(group.Key, "key"); - CollectionAssert.AreEqual(group, new[] { 2, 3 }); + Assert.AreEqual("key", group.Key); + CollectionAssert.AreEqual(new[] { 2, 3 }, group); Assert.IsTrue(collectionChangedEventRaised); } @@ -111,8 +111,8 @@ public void Test_ReadOnlyObservableGroup_Clear_ShouldRaiseEvent() sourceGroup.Clear(); - Assert.AreEqual(group.Key, "key"); - CollectionAssert.AreEqual(group, Array.Empty()); + Assert.AreEqual("key", group.Key); + CollectionAssert.AreEqual(Array.Empty(), group); Assert.IsTrue(collectionChangedEventRaised); } @@ -126,8 +126,8 @@ public void Test_ReadOnlyObservableGroup_IReadOnlyObservableGroup_ShouldReturnEx ReadOnlyObservableGroup group = new(sourceGroup); IReadOnlyObservableGroup iReadOnlyObservableGroup = group; - Assert.AreEqual(iReadOnlyObservableGroup.Key, "key"); - Assert.AreEqual(iReadOnlyObservableGroup.Count, count); + Assert.AreEqual("key", iReadOnlyObservableGroup.Key); + Assert.AreEqual(count, iReadOnlyObservableGroup.Count); } [TestMethod] diff --git a/tests/CommunityToolkit.Mvvm.UnitTests/Collections/Test_ReadOnlyObservableGroupedCollection.cs b/tests/CommunityToolkit.Mvvm.UnitTests/Collections/Test_ReadOnlyObservableGroupedCollection.cs index 21b52285c..1353df6cc 100644 --- a/tests/CommunityToolkit.Mvvm.UnitTests/Collections/Test_ReadOnlyObservableGroupedCollection.cs +++ b/tests/CommunityToolkit.Mvvm.UnitTests/Collections/Test_ReadOnlyObservableGroupedCollection.cs @@ -23,8 +23,8 @@ public void Test_ReadOnlyObservableGroupedCollection_Ctor_WithEmptySource_ShoudI ObservableGroupedCollection source = new(); ReadOnlyObservableGroupedCollection readOnlyGroup = new(source); - Assert.AreEqual(readOnlyGroup.Count, 0); - CollectionAssert.AreEqual(readOnlyGroup, Array.Empty()); + Assert.AreEqual(0, readOnlyGroup.Count); + CollectionAssert.AreEqual(Array.Empty(), readOnlyGroup); } [TestMethod] @@ -38,13 +38,13 @@ public void Test_ReadOnlyObservableGroupedCollection_Ctor_WithObservableGroupedC ObservableGroupedCollection source = new(groups); ReadOnlyObservableGroupedCollection readOnlyGroup = new(source); - Assert.AreEqual(readOnlyGroup.Count, 2); + Assert.AreEqual(2, readOnlyGroup.Count); - Assert.AreEqual(readOnlyGroup[0].Key, "A"); - CollectionAssert.AreEquivalent(readOnlyGroup[0], new[] { 1, 3, 5 }); + Assert.AreEqual("A", readOnlyGroup[0].Key); + CollectionAssert.AreEquivalent(new[] { 1, 3, 5 }, readOnlyGroup[0]); - Assert.AreEqual(readOnlyGroup[1].Key, "B"); - CollectionAssert.AreEquivalent(readOnlyGroup[1], new[] { 2, 4, 6 }); + Assert.AreEqual("B", readOnlyGroup[1].Key); + CollectionAssert.AreEquivalent(new[] { 2, 4, 6 }, readOnlyGroup[1]); } [TestMethod] @@ -57,13 +57,13 @@ public void Test_ReadOnlyObservableGroupedCollection_Ctor_WithListOfReadOnlyObse }; ReadOnlyObservableGroupedCollection readOnlyGroup = new(source); - Assert.AreEqual(readOnlyGroup.Count, 2); + Assert.AreEqual(2, readOnlyGroup.Count); - Assert.AreEqual(readOnlyGroup[0].Key, "A"); - CollectionAssert.AreEqual(readOnlyGroup[0], new[] { 1, 3, 5 }); + Assert.AreEqual("A", readOnlyGroup[0].Key); + CollectionAssert.AreEqual(new[] { 1, 3, 5 }, readOnlyGroup[0]); - Assert.AreEqual(readOnlyGroup[1].Key, "B"); - CollectionAssert.AreEqual(readOnlyGroup[1], new[] { 2, 4, 6 }); + Assert.AreEqual("B", readOnlyGroup[1].Key); + CollectionAssert.AreEqual(new[] { 2, 4, 6 }, readOnlyGroup[1]); } [TestMethod] @@ -78,17 +78,17 @@ public void Test_ReadOnlyObservableGroupedCollection_IListImplementation_Propert ReadOnlyObservableGroupedCollection readOnlyGroup = new(source); IList list = readOnlyGroup; - Assert.AreEqual(list.Count, 2); + Assert.AreEqual(2, list.Count); ReadOnlyObservableGroup group0 = (ReadOnlyObservableGroup)list[0]!; - Assert.AreEqual(group0.Key, "A"); - CollectionAssert.AreEqual(group0, new[] { 1, 3, 5 }); + Assert.AreEqual("A", group0.Key); + CollectionAssert.AreEqual(new[] { 1, 3, 5 }, group0); ReadOnlyObservableGroup group1 = (ReadOnlyObservableGroup)list[1]!; - Assert.AreEqual(group1.Key, "B"); - CollectionAssert.AreEqual(group1, new[] { 2, 4, 6 }); + Assert.AreEqual("B", group1.Key); + CollectionAssert.AreEqual(new[] { 2, 4, 6 }, group1); Assert.IsNotNull(list.SyncRoot); Assert.IsTrue(list.IsFixedSize); @@ -144,7 +144,7 @@ public void Test_ReadOnlyObservableGroupedCollection_IListImplementation_IndexOf int index = list.IndexOf(groupToSearch); - Assert.AreEqual(index, groupIndex); + Assert.AreEqual(groupIndex, index); } [TestMethod] @@ -166,7 +166,7 @@ public void Test_ReadOnlyObservableGroupedCollection_IListImplementation_Contain bool result = list.Contains(groupToSearch); - Assert.AreEqual(result, expectedResult); + Assert.AreEqual(expectedResult, result); } [TestMethod] @@ -196,11 +196,11 @@ public void Test_ReadOnlyObservableGroupedCollection_AddGroupInSource_ShouldAddG int expectedReadOnlyGroupCount = sourceInitialItemsCount + 1; - Assert.AreEqual(readOnlyGroup.Count, expectedReadOnlyGroupCount); + Assert.AreEqual(expectedReadOnlyGroupCount, readOnlyGroup.Count); Assert.AreEqual("Add", readOnlyGroup[readOnlyGroup.Count - 1].Key); Assert.IsTrue(isCountPropertyChangedEventRaised); Assert.IsNotNull(collectionChangedEventArgs); - Assert.AreEqual(collectionChangedEventsCount, 1); + Assert.AreEqual(1, collectionChangedEventsCount); bool isAddEventValid = IsAddEventValid(collectionChangedEventArgs, itemsList, expectedInsertionIndex); @@ -232,11 +232,11 @@ public void Test_ReadOnlyObservableGroupedCollection_InsertGroupInSource_ShouldA source.Insert(insertionIndex, new ObservableGroup("Add", itemsList)); - Assert.AreEqual(readOnlyGroup.Count, 3); + Assert.AreEqual(3, readOnlyGroup.Count); Assert.AreEqual("Add", readOnlyGroup[insertionIndex].Key); Assert.IsTrue(isCountPropertyChangedEventRaised); Assert.IsNotNull(collectionChangedEventArgs); - Assert.AreEqual(collectionChangedEventsCount, 1); + Assert.AreEqual(1, collectionChangedEventsCount); bool isAddEventValid = IsAddEventValid(collectionChangedEventArgs, itemsList, addIndex: insertionIndex); @@ -267,14 +267,14 @@ public void Test_ReadOnlyObservableGroupedCollection_RemoveGroupInSource_ShoudRe source.RemoveAt(1); - Assert.AreEqual(readOnlyGroup.Count, 1); + Assert.AreEqual(1, readOnlyGroup.Count); - Assert.AreEqual(readOnlyGroup[0].Key, "A"); - CollectionAssert.AreEquivalent(readOnlyGroup[0], aItemsList); + Assert.AreEqual("A", readOnlyGroup[0].Key); + CollectionAssert.AreEquivalent(aItemsList, readOnlyGroup[0]); Assert.IsTrue(isCountPropertyChangedEventRaised); Assert.IsNotNull(collectionChangedEventArgs); - Assert.AreEqual(collectionChangedEventsCount, 1); + Assert.AreEqual(1, collectionChangedEventsCount); bool isRemoveEventValid = IsRemoveEventValid(collectionChangedEventArgs, bItemsList, 1); @@ -314,8 +314,8 @@ public void Test_ReadOnlyObservableGroupedCollection_MoveGroupInSource_ShoudMove Assert.AreEqual(groups.Count, readOnlyGroup.Count); - Assert.AreEqual(readOnlyGroup[0].Key, "B"); - CollectionAssert.AreEquivalent(readOnlyGroup[0], bItemsList); + Assert.AreEqual("B", readOnlyGroup[0].Key); + CollectionAssert.AreEquivalent(bItemsList, readOnlyGroup[0]); List> tempList = new(groups); IGrouping tempItem = tempList[oldIndex]; @@ -331,7 +331,7 @@ public void Test_ReadOnlyObservableGroupedCollection_MoveGroupInSource_ShoudMove Assert.IsFalse(isCountPropertyChangedEventRaised); Assert.IsNotNull(collectionChangedEventArgs); - Assert.AreEqual(collectionChangedEventsCount, 1); + Assert.AreEqual(1, collectionChangedEventsCount); bool isMoveEventValid = IsMoveEventValid(collectionChangedEventArgs, groups[oldIndex], oldIndex, newIndex); @@ -362,11 +362,11 @@ public void Test_ReadOnlyObservableGroupedCollection_ClearSource_ShoudClear() source.Clear(); - Assert.AreEqual(readOnlyGroup.Count, 0); + Assert.AreEqual(0, readOnlyGroup.Count); Assert.IsTrue(isCountPropertyChangedEventRaised); Assert.IsNotNull(collectionChangedEventArgs); - Assert.AreEqual(collectionChangedEventsCount, 1); + Assert.AreEqual(1, collectionChangedEventsCount); bool isResetEventValid = IsResetEventValid(collectionChangedEventArgs); @@ -398,17 +398,17 @@ public void Test_ReadOnlyObservableGroupedCollection_ReplaceGroupInSource_ShoudR source[0] = new ObservableGroup("C", cItemsList); - Assert.AreEqual(readOnlyGroup.Count, 2); + Assert.AreEqual(2, readOnlyGroup.Count); - Assert.AreEqual(readOnlyGroup[0].Key, "C"); - CollectionAssert.AreEquivalent(readOnlyGroup[0], cItemsList); + Assert.AreEqual("C", readOnlyGroup[0].Key); + CollectionAssert.AreEquivalent(cItemsList, readOnlyGroup[0]); - Assert.AreEqual(readOnlyGroup[1].Key, "B"); - CollectionAssert.AreEquivalent(readOnlyGroup[1], bItemsList); + Assert.AreEqual("B", readOnlyGroup[1].Key); + CollectionAssert.AreEquivalent(bItemsList, readOnlyGroup[1]); Assert.IsFalse(isCountPropertyChangedEventRaised); Assert.IsNotNull(collectionChangedEventArgs); - Assert.AreEqual(collectionChangedEventsCount, 1); + Assert.AreEqual(1, collectionChangedEventsCount); bool isReplaceEventValid = IsReplaceEventValid(collectionChangedEventArgs, aItemsList, cItemsList); diff --git a/tests/CommunityToolkit.Mvvm.UnitTests/Test_ArgumentNullException.ComponentModel.cs b/tests/CommunityToolkit.Mvvm.UnitTests/Test_ArgumentNullException.ComponentModel.cs index 21187ea57..3a8edab44 100644 --- a/tests/CommunityToolkit.Mvvm.UnitTests/Test_ArgumentNullException.ComponentModel.cs +++ b/tests/CommunityToolkit.Mvvm.UnitTests/Test_ArgumentNullException.ComponentModel.cs @@ -312,6 +312,6 @@ private static void Assert(Action action, string parameterName) { System.ArgumentNullException exception = Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsException(action); - Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreEqual(exception.ParamName, parameterName); + Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreEqual(parameterName, exception.ParamName); } } diff --git a/tests/CommunityToolkit.Mvvm.UnitTests/Test_AsyncRelayCommand.cs b/tests/CommunityToolkit.Mvvm.UnitTests/Test_AsyncRelayCommand.cs index c786e0de0..2f76bf8fd 100644 --- a/tests/CommunityToolkit.Mvvm.UnitTests/Test_AsyncRelayCommand.cs +++ b/tests/CommunityToolkit.Mvvm.UnitTests/Test_AsyncRelayCommand.cs @@ -41,8 +41,8 @@ public async Task Test_AsyncRelayCommand_AlwaysEnabled() command.NotifyCanExecuteChanged(); - Assert.AreSame(args.Item1, command); - Assert.AreSame(args.Item2, EventArgs.Empty); + Assert.AreSame(command, args.Item1); + Assert.AreSame(EventArgs.Empty, args.Item2); Assert.IsNull(command.ExecutionTask); Assert.IsFalse(command.IsRunning); @@ -50,20 +50,20 @@ public async Task Test_AsyncRelayCommand_AlwaysEnabled() Task task = command.ExecuteAsync(null); Assert.IsNotNull(command.ExecutionTask); - Assert.AreSame(command.ExecutionTask, task); + Assert.AreSame(task, command.ExecutionTask); Assert.IsTrue(command.IsRunning); await task; Assert.IsFalse(command.IsRunning); - Assert.AreEqual(ticks, 1); + Assert.AreEqual(1, ticks); command.Execute(new object()); await command.ExecutionTask!; - Assert.AreEqual(ticks, 2); + Assert.AreEqual(2, ticks); } [TestMethod] @@ -86,11 +86,11 @@ public void Test_AsyncRelayCommand_WithCanExecuteFunctionTrue() command.Execute(null); - Assert.AreEqual(ticks, 1); + Assert.AreEqual(1, ticks); command.Execute(new object()); - Assert.AreEqual(ticks, 2); + Assert.AreEqual(2, ticks); } [TestMethod] @@ -115,11 +115,11 @@ public void Test_AsyncRelayCommand_WithCanExecuteFunctionFalse() // It is the caller's responsibility to ensure that CanExecute is true // before calling Execute. This check verifies the logic is still called. - Assert.AreEqual(ticks, 1); + Assert.AreEqual(1, ticks); command.Execute(new object()); - Assert.AreEqual(ticks, 2); + Assert.AreEqual(2, ticks); } [TestMethod] @@ -154,19 +154,19 @@ public async Task Test_AsyncRelayCommand_WithCancellation() Assert.IsFalse(command.IsCancellationRequested); // Validate the various event args for all the properties that were updated when executing the command - Assert.AreEqual(args.Count, 4); - Assert.AreEqual(args[0].PropertyName, nameof(IAsyncRelayCommand.ExecutionTask)); - Assert.AreEqual(args[1].PropertyName, nameof(IAsyncRelayCommand.IsRunning)); - Assert.AreEqual(args[2].PropertyName, nameof(IAsyncRelayCommand.CanBeCanceled)); - Assert.AreEqual(args[3].PropertyName, nameof(IAsyncRelayCommand.IsCancellationRequested)); + Assert.AreEqual(4, args.Count); + Assert.AreEqual(nameof(IAsyncRelayCommand.ExecutionTask), args[0].PropertyName); + Assert.AreEqual(nameof(IAsyncRelayCommand.IsRunning), args[1].PropertyName); + Assert.AreEqual(nameof(IAsyncRelayCommand.CanBeCanceled), args[2].PropertyName); + Assert.AreEqual(nameof(IAsyncRelayCommand.IsCancellationRequested), args[3].PropertyName); command.Cancel(); // Verify that these two properties raised notifications correctly when canceling the command too. // We need to ensure all command properties support notifications so that users can bind to them. - Assert.AreEqual(args.Count, 6); - Assert.AreEqual(args[4].PropertyName, nameof(IAsyncRelayCommand.CanBeCanceled)); - Assert.AreEqual(args[5].PropertyName, nameof(IAsyncRelayCommand.IsCancellationRequested)); + Assert.AreEqual(6, args.Count); + Assert.AreEqual(nameof(IAsyncRelayCommand.CanBeCanceled), args[4].PropertyName); + Assert.AreEqual(nameof(IAsyncRelayCommand.IsCancellationRequested), args[5].PropertyName); Assert.IsTrue(command.IsCancellationRequested); @@ -205,8 +205,8 @@ public async Task Test_AsyncRelayCommand_AllowConcurrentExecutions_Enable() command.NotifyCanExecuteChanged(); - Assert.AreSame(args.Item1, command); - Assert.AreSame(args.Item2, EventArgs.Empty); + Assert.AreSame(command, args.Item1); + Assert.AreSame(EventArgs.Empty, args.Item2); args = default; @@ -216,8 +216,8 @@ public async Task Test_AsyncRelayCommand_AllowConcurrentExecutions_Enable() Task task = command.ExecuteAsync(null); Assert.IsNotNull(command.ExecutionTask); - Assert.AreSame(command.ExecutionTask, task); - Assert.AreSame(command.ExecutionTask, cancellationTokenSources[0].Task); + Assert.AreSame(task, command.ExecutionTask); + Assert.AreSame(cancellationTokenSources[0].Task, command.ExecutionTask); Assert.IsTrue(command.IsRunning); // The command can still be executed now @@ -230,8 +230,8 @@ public async Task Test_AsyncRelayCommand_AllowConcurrentExecutions_Enable() Task newTask = command.ExecuteAsync(null); // A new task was returned - Assert.AreSame(command.ExecutionTask, newTask); - Assert.AreSame(command.ExecutionTask, cancellationTokenSources[1].Task); + Assert.AreSame(newTask, command.ExecutionTask); + Assert.AreSame(cancellationTokenSources[1].Task, command.ExecutionTask); cancellationTokenSources[0].SetResult(null); cancellationTokenSources[1].SetResult(null); @@ -279,8 +279,8 @@ private static async Task Test_AsyncRelayCommand_AllowConcurrentExecutions_TestL command.NotifyCanExecuteChanged(); - Assert.AreSame(args.Item1, command); - Assert.AreSame(args.Item2, EventArgs.Empty); + Assert.AreSame(command, args.Item1); + Assert.AreSame(EventArgs.Empty, args.Item2); args = default; @@ -290,13 +290,13 @@ private static async Task Test_AsyncRelayCommand_AllowConcurrentExecutions_TestL Task task = command.ExecuteAsync(null); // CanExecute is raised upon execution - Assert.AreSame(args.Item1, command); - Assert.AreSame(args.Item2, EventArgs.Empty); + Assert.AreSame(command, args.Item1); + Assert.AreSame(EventArgs.Empty, args.Item2); args = default; Assert.IsNotNull(command.ExecutionTask); - Assert.AreSame(command.ExecutionTask, task); + Assert.AreSame(task, command.ExecutionTask); Assert.IsTrue(command.IsRunning); // The command can't be executed now, as there's a pending operation @@ -317,8 +317,8 @@ private static async Task Test_AsyncRelayCommand_AllowConcurrentExecutions_TestL Assert.IsFalse(command.IsRunning); // CanExecute is raised automatically when command execution completes, if concurrent executions are disabled - Assert.AreSame(args.Item1, command); - Assert.AreSame(args.Item2, EventArgs.Empty); + Assert.AreSame(command, args.Item1); + Assert.AreSame(EventArgs.Empty, args.Item2); } [TestMethod] diff --git a/tests/CommunityToolkit.Mvvm.UnitTests/Test_AsyncRelayCommand{T}.cs b/tests/CommunityToolkit.Mvvm.UnitTests/Test_AsyncRelayCommand{T}.cs index 481d72113..c28602596 100644 --- a/tests/CommunityToolkit.Mvvm.UnitTests/Test_AsyncRelayCommand{T}.cs +++ b/tests/CommunityToolkit.Mvvm.UnitTests/Test_AsyncRelayCommand{T}.cs @@ -38,8 +38,8 @@ public async Task Test_AsyncRelayCommandOfT_AlwaysEnabled() command.NotifyCanExecuteChanged(); - Assert.AreSame(args.Item1, command); - Assert.AreSame(args.Item2, EventArgs.Empty); + Assert.AreSame(command, args.Item1); + Assert.AreSame(EventArgs.Empty, args.Item2); Assert.IsNull(command.ExecutionTask); Assert.IsFalse(command.IsRunning); @@ -47,20 +47,20 @@ public async Task Test_AsyncRelayCommandOfT_AlwaysEnabled() Task task = command.ExecuteAsync((object)"42"); Assert.IsNotNull(command.ExecutionTask); - Assert.AreSame(command.ExecutionTask, task); + Assert.AreSame(task, command.ExecutionTask); Assert.IsTrue(command.IsRunning); await task; Assert.IsFalse(command.IsRunning); - Assert.AreEqual(ticks, 42); + Assert.AreEqual(42, ticks); command.Execute("2"); await command.ExecutionTask!; - Assert.AreEqual(ticks, 2); + Assert.AreEqual(2, ticks); ExceptionHelper.ThrowsArgumentExceptionWithParameterName(() => command.CanExecute(new object()), "parameter"); ExceptionHelper.ThrowsArgumentExceptionWithParameterName(() => command.CanExecute(42), "parameter"); @@ -86,11 +86,11 @@ public void Test_AsyncRelayCommandOfT_WithCanExecuteFunctionTrue() command.Execute("42"); - Assert.AreEqual(ticks, 42); + Assert.AreEqual(42, ticks); command.Execute("2"); - Assert.AreEqual(ticks, 2); + Assert.AreEqual(2, ticks); ExceptionHelper.ThrowsArgumentExceptionWithParameterName(() => command.CanExecute(new object()), "parameter"); ExceptionHelper.ThrowsArgumentExceptionWithParameterName(() => command.CanExecute(42), "parameter"); @@ -117,11 +117,11 @@ public void Test_AsyncRelayCommandOfT_WithCanExecuteFunctionFalse() command.Execute("2"); // Like in the RelayCommand test, ensure Execute is unconditionally invoked - Assert.AreEqual(ticks, 2); + Assert.AreEqual(2, ticks); command.Execute("42"); - Assert.AreEqual(ticks, 42); + Assert.AreEqual(42, ticks); ExceptionHelper.ThrowsArgumentExceptionWithParameterName(() => command.CanExecute(new object()), "parameter"); ExceptionHelper.ThrowsArgumentExceptionWithParameterName(() => command.CanExecute(42), "parameter"); @@ -197,17 +197,17 @@ public async Task Test_AsyncRelayCommandOfT_WithCancellation() Assert.IsTrue(command.CanBeCanceled); Assert.IsFalse(command.IsCancellationRequested); - Assert.AreEqual(args.Count, 4); - Assert.AreEqual(args[0].PropertyName, nameof(IAsyncRelayCommand.ExecutionTask)); - Assert.AreEqual(args[1].PropertyName, nameof(IAsyncRelayCommand.IsRunning)); - Assert.AreEqual(args[2].PropertyName, nameof(IAsyncRelayCommand.CanBeCanceled)); - Assert.AreEqual(args[3].PropertyName, nameof(IAsyncRelayCommand.IsCancellationRequested)); + Assert.AreEqual(4, args.Count); + Assert.AreEqual(nameof(IAsyncRelayCommand.ExecutionTask), args[0].PropertyName); + Assert.AreEqual(nameof(IAsyncRelayCommand.IsRunning), args[1].PropertyName); + Assert.AreEqual(nameof(IAsyncRelayCommand.CanBeCanceled), args[2].PropertyName); + Assert.AreEqual(nameof(IAsyncRelayCommand.IsCancellationRequested), args[3].PropertyName); command.Cancel(); - Assert.AreEqual(args.Count, 6); - Assert.AreEqual(args[4].PropertyName, nameof(IAsyncRelayCommand.CanBeCanceled)); - Assert.AreEqual(args[5].PropertyName, nameof(IAsyncRelayCommand.IsCancellationRequested)); + Assert.AreEqual(6, args.Count); + Assert.AreEqual(nameof(IAsyncRelayCommand.CanBeCanceled), args[4].PropertyName); + Assert.AreEqual(nameof(IAsyncRelayCommand.IsCancellationRequested), args[5].PropertyName); Assert.IsTrue(command.IsCancellationRequested); @@ -250,8 +250,8 @@ private static async Task Test_AsyncRelayCommandOfT_AllowConcurrentExecutions_Te command.NotifyCanExecuteChanged(); - Assert.AreSame(args.Item1, command); - Assert.AreSame(args.Item2, EventArgs.Empty); + Assert.AreSame(command, args.Item1); + Assert.AreSame(EventArgs.Empty, args.Item2); Assert.IsNull(command.ExecutionTask); Assert.IsFalse(command.IsRunning); @@ -259,7 +259,7 @@ private static async Task Test_AsyncRelayCommandOfT_AllowConcurrentExecutions_Te Task task = command.ExecuteAsync((object)"42"); Assert.IsNotNull(command.ExecutionTask); - Assert.AreSame(command.ExecutionTask, task); + Assert.AreSame(task, command.ExecutionTask); Assert.IsTrue(command.IsRunning); // The command can't be executed now, as there's a pending operation diff --git a/tests/CommunityToolkit.Mvvm.UnitTests/Test_INotifyPropertyChangedAttribute.cs b/tests/CommunityToolkit.Mvvm.UnitTests/Test_INotifyPropertyChangedAttribute.cs index 095a9fcb0..63c81be25 100644 --- a/tests/CommunityToolkit.Mvvm.UnitTests/Test_INotifyPropertyChangedAttribute.cs +++ b/tests/CommunityToolkit.Mvvm.UnitTests/Test_INotifyPropertyChangedAttribute.cs @@ -34,8 +34,8 @@ public void Test_INotifyPropertyChanged_Events() model.Data = 42; - Assert.AreEqual(changed.Item1?.PropertyName, nameof(SampleModel.Data)); - Assert.AreEqual(changed.Item2, 42); + Assert.AreEqual(nameof(SampleModel.Data), changed.Item1?.PropertyName); + Assert.AreEqual(42, changed.Item2); } [INotifyPropertyChanged] @@ -61,13 +61,13 @@ public void Test_INotifyPropertyChanged_WithoutHelpers() MethodInfo[]? methods = typeof(SampleModelWithoutHelpers).GetMethods(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.DeclaredOnly); - Assert.AreEqual(methods.Length, 2); - Assert.AreEqual(methods[0].Name, "OnPropertyChanged"); - Assert.AreEqual(methods[1].Name, "OnPropertyChanged"); + Assert.AreEqual(2, methods.Length); + Assert.AreEqual("OnPropertyChanged", methods[0].Name); + Assert.AreEqual("OnPropertyChanged", methods[1].Name); System.Type[]? types = typeof(SampleModelWithoutHelpers).GetNestedTypes(BindingFlags.NonPublic); - Assert.AreEqual(types.Length, 0); + Assert.AreEqual(0, types.Length); } [INotifyPropertyChanged(IncludeAdditionalHelperMethods = false)] @@ -89,9 +89,9 @@ public void Test_INotifyPropertyChanged_WithGeneratedProperties() model.X = 42; model.Y = 66; - Assert.AreEqual(eventArgs.Count, 2); - Assert.AreEqual(eventArgs[0].PropertyName, nameof(SampleModelWithINPCAndObservableProperties.X)); - Assert.AreEqual(eventArgs[1].PropertyName, nameof(SampleModelWithINPCAndObservableProperties.Y)); + Assert.AreEqual(2, eventArgs.Count); + Assert.AreEqual(nameof(SampleModelWithINPCAndObservableProperties.X), eventArgs[0].PropertyName); + Assert.AreEqual(nameof(SampleModelWithINPCAndObservableProperties.Y), eventArgs[1].PropertyName); } // See https://github.com/CommunityToolkit/WindowsCommunityToolkit/issues/4167 @@ -119,8 +119,8 @@ public void Test_INotifyPropertyChanged_WithGeneratedProperties_ExternalNetStand model.X = 42; model.Y = 66; - Assert.AreEqual(eventArgs.Count, 2); - Assert.AreEqual(eventArgs[0].PropertyName, nameof(ExternalAssembly.SampleModelWithINPCAndObservableProperties.X)); - Assert.AreEqual(eventArgs[1].PropertyName, nameof(ExternalAssembly.SampleModelWithINPCAndObservableProperties.Y)); + Assert.AreEqual(2, eventArgs.Count); + Assert.AreEqual(nameof(ExternalAssembly.SampleModelWithINPCAndObservableProperties.X), eventArgs[0].PropertyName); + Assert.AreEqual(nameof(ExternalAssembly.SampleModelWithINPCAndObservableProperties.Y), eventArgs[1].PropertyName); } } diff --git a/tests/CommunityToolkit.Mvvm.UnitTests/Test_IRecipientGenerator.cs b/tests/CommunityToolkit.Mvvm.UnitTests/Test_IRecipientGenerator.cs index 782e41450..e1c3239ba 100644 --- a/tests/CommunityToolkit.Mvvm.UnitTests/Test_IRecipientGenerator.cs +++ b/tests/CommunityToolkit.Mvvm.UnitTests/Test_IRecipientGenerator.cs @@ -36,13 +36,13 @@ public void Test_IRecipientGenerator_GeneratedRegistration() _ = messenger.Send(messageA, 42); - Assert.AreSame(recipient.A, messageA); + Assert.AreSame(messageA, recipient.A); Assert.IsNull(recipient.B); _ = messenger.Send(messageB, 42); - Assert.AreSame(recipient.A, messageA); - Assert.AreSame(recipient.B, messageB); + Assert.AreSame(messageA, recipient.A); + Assert.AreSame(messageB, recipient.B); } [TestMethod] diff --git a/tests/CommunityToolkit.Mvvm.UnitTests/Test_Messenger.Observables.cs b/tests/CommunityToolkit.Mvvm.UnitTests/Test_Messenger.Observables.cs index e631eddf9..5d7f05cf8 100644 --- a/tests/CommunityToolkit.Mvvm.UnitTests/Test_Messenger.Observables.cs +++ b/tests/CommunityToolkit.Mvvm.UnitTests/Test_Messenger.Observables.cs @@ -33,14 +33,14 @@ public void Test_Messenger_CreateObservable(Type type) _ = messenger.Send(message2); // The expected messages have been observed - CollectionAssert.AreEqual(messages, new[] { message1, message2 }); + CollectionAssert.AreEqual(new[] { message1, message2 }, messages); disposable.Dispose(); _ = messenger.Send(); // No messages are sent after unsubscribing the observable - CollectionAssert.AreEqual(messages, new[] { message1, message2 }); + CollectionAssert.AreEqual(new[] { message1, message2 }, messages); } [TestMethod] @@ -68,7 +68,7 @@ public void Test_Messenger_CreateObservable_WithToken(Type type) _ = messenger.Send(new MessageA(), 999); // The expected messages have been observed (only for matching tokens) - CollectionAssert.AreEqual(messages, new[] { message1, message2 }); + CollectionAssert.AreEqual(new[] { message1, message2 }, messages); disposable.Dispose(); @@ -76,7 +76,7 @@ public void Test_Messenger_CreateObservable_WithToken(Type type) _ = messenger.Send(new MessageA(), 1); // No messages are sent after unsubscribing the observable (regardless of token) - CollectionAssert.AreEqual(messages, new[] { message1, message2 }); + CollectionAssert.AreEqual(new[] { message1, message2 }, messages); } [TestMethod] diff --git a/tests/CommunityToolkit.Mvvm.UnitTests/Test_Messenger.Request.cs b/tests/CommunityToolkit.Mvvm.UnitTests/Test_Messenger.Request.cs index b6c6f3ac1..6f922971e 100644 --- a/tests/CommunityToolkit.Mvvm.UnitTests/Test_Messenger.Request.cs +++ b/tests/CommunityToolkit.Mvvm.UnitTests/Test_Messenger.Request.cs @@ -38,8 +38,8 @@ void Receive(object recipient, NumberRequestMessage m) int result = messenger.Send(); - Assert.AreSame(test, recipient); - Assert.AreEqual(result, 42); + Assert.AreSame(recipient, test); + Assert.AreEqual(42, result); } [TestMethod] @@ -104,7 +104,7 @@ static void Receive(object recipient, AsyncNumberRequestMessage m) int result = await messenger.Send(); - Assert.AreEqual(result, 42); + Assert.AreEqual(42, result); GC.KeepAlive(recipient); } @@ -137,7 +137,7 @@ void Receive(object recipient, AsyncNumberRequestMessage m) int result = await messenger.Send(); - Assert.AreEqual(result, 42); + Assert.AreEqual(42, result); GC.KeepAlive(recipient); } @@ -199,7 +199,7 @@ static void Receive(object recipient, NumbersCollectionRequestMessage m) IReadOnlyCollection? results = messenger.Send().Responses; - Assert.AreEqual(results.Count, 0); + Assert.AreEqual(0, results.Count); GC.KeepAlive(recipient); } @@ -246,11 +246,11 @@ void Receive3(object recipient, NumbersCollectionRequestMessage m) responses.Add(response); } - Assert.AreSame(r1, recipient1); - Assert.AreSame(r2, recipient2); - Assert.AreSame(r3, recipient3); + Assert.AreSame(recipient1, r1); + Assert.AreSame(recipient2, r2); + Assert.AreSame(recipient3, r3); - CollectionAssert.AreEquivalent(responses, new[] { 1, 2, 3 }); + CollectionAssert.AreEquivalent(new[] { 1, 2, 3 }, responses); } public class NumbersCollectionRequestMessage : CollectionRequestMessage @@ -273,7 +273,7 @@ static void Receive(object recipient, AsyncNumbersCollectionRequestMessage m) IReadOnlyCollection? results = await messenger.Send().GetResponsesAsync(); - Assert.AreEqual(results.Count, 0); + Assert.AreEqual(0, results.Count); GC.KeepAlive(recipient); } @@ -308,7 +308,7 @@ async Task GetNumberAsync() IReadOnlyCollection? responses = await messenger.Send().GetResponsesAsync(); - CollectionAssert.AreEquivalent(responses.ToArray(), new[] { 1, 2, 3, 3 }); + CollectionAssert.AreEquivalent(new[] { 1, 2, 3, 3 }, responses.ToArray()); GC.KeepAlive(recipient1); GC.KeepAlive(recipient2); @@ -351,7 +351,7 @@ async Task GetNumberAsync() responses.Add(response); } - CollectionAssert.AreEquivalent(responses, new[] { 1, 2, 3, 3 }); + CollectionAssert.AreEquivalent(new[] { 1, 2, 3, 3 }, responses); GC.KeepAlive(recipient1); GC.KeepAlive(recipient2); diff --git a/tests/CommunityToolkit.Mvvm.UnitTests/Test_Messenger.cs b/tests/CommunityToolkit.Mvvm.UnitTests/Test_Messenger.cs index 16f5c7afe..323c9e464 100644 --- a/tests/CommunityToolkit.Mvvm.UnitTests/Test_Messenger.cs +++ b/tests/CommunityToolkit.Mvvm.UnitTests/Test_Messenger.cs @@ -222,8 +222,8 @@ public void Test_Messenger_IsRegistered_Register_Send_UnregisterOfTMessage_WithN _ = messenger.Send(new MessageA { Text = nameof(MessageA) }); - Assert.AreSame(recipient, a); - Assert.AreEqual(result, nameof(MessageA)); + Assert.AreSame(a, recipient); + Assert.AreEqual(nameof(MessageA), result); messenger.Unregister(a); @@ -255,7 +255,7 @@ public void Test_Messenger_IsRegistered_Register_Send_UnregisterRecipient_WithNo _ = messenger.Send(new MessageA { Text = nameof(MessageA) }); - Assert.AreEqual(result, nameof(MessageA)); + Assert.AreEqual(nameof(MessageA), result); messenger.UnregisterAll(a); @@ -284,7 +284,7 @@ public void Test_Messenger_IsRegistered_Register_Send_UnregisterOfTMessage_WithT _ = messenger.Send(new MessageA { Text = nameof(MessageA) }, nameof(MessageA)); - Assert.AreEqual(result, nameof(MessageA)); + Assert.AreEqual(nameof(MessageA), result); messenger.Unregister(a, nameof(MessageA)); @@ -355,18 +355,18 @@ public void Test_Messenger_IRecipient_SomeMessages_NoToken(Type type) Assert.IsTrue(messenger.IsRegistered(recipient)); Assert.IsTrue(messenger.IsRegistered(recipient)); - Assert.AreEqual(recipient.As, 0); - Assert.AreEqual(recipient.Bs, 0); + Assert.AreEqual(0, recipient.As); + Assert.AreEqual(0, recipient.Bs); _ = messenger.Send(); - Assert.AreEqual(recipient.As, 1); - Assert.AreEqual(recipient.Bs, 0); + Assert.AreEqual(1, recipient.As); + Assert.AreEqual(0, recipient.Bs); _ = messenger.Send(); - Assert.AreEqual(recipient.As, 1); - Assert.AreEqual(recipient.Bs, 1); + Assert.AreEqual(1, recipient.As); + Assert.AreEqual(1, recipient.Bs); messenger.UnregisterAll(recipient); @@ -397,9 +397,9 @@ public void Test_Messenger_IRecipient_SomeMessages_WithGenericTypeParameters(Typ ValueChangedMessage message2 = messenger.Send(new ValueChangedMessage("Hello")); MessageA message3 = messenger.Send(); - Assert.AreSame(recipient.ReceivedMessage1, message1); - Assert.AreSame(recipient.ReceivedMessage2, message2); - Assert.AreSame(recipient.ReceivedMessage3, message3); + Assert.AreSame(message1, recipient.ReceivedMessage1); + Assert.AreSame(message2, recipient.ReceivedMessage2); + Assert.AreSame(message3, recipient.ReceivedMessage3); messenger.UnregisterAll(recipient); @@ -425,18 +425,18 @@ public void Test_Messenger_IRecipient_SomeMessages_WithToken(Type type) Assert.IsFalse(messenger.IsRegistered(recipient)); Assert.IsFalse(messenger.IsRegistered(recipient)); - Assert.AreEqual(recipient.As, 0); - Assert.AreEqual(recipient.Bs, 0); + Assert.AreEqual(0, recipient.As); + Assert.AreEqual(0, recipient.Bs); _ = messenger.Send(token); - Assert.AreEqual(recipient.As, 0); - Assert.AreEqual(recipient.Bs, 1); + Assert.AreEqual(0, recipient.As); + Assert.AreEqual(1, recipient.Bs); _ = messenger.Send(token); - Assert.AreEqual(recipient.As, 1); - Assert.AreEqual(recipient.Bs, 1); + Assert.AreEqual(1, recipient.As); + Assert.AreEqual(1, recipient.Bs); messenger.UnregisterAll(recipient, token); @@ -458,7 +458,7 @@ public void Test_Messenger_RegisterWithTypeParameter(Type type) _ = messenger.Send(); - Assert.AreEqual(number, 42); + Assert.AreEqual(42, number); } [TestMethod] @@ -589,8 +589,8 @@ void Test() foreach (RecipientWithSomeMessages? recipient in recipients) { - Assert.AreEqual(recipient!.As, 1); - Assert.AreEqual(recipient!.Bs, 2); + Assert.AreEqual(1, recipient!.As); + Assert.AreEqual(2, recipient!.Bs); } foreach (ref RecipientWithSomeMessages? recipient in recipients.AsSpan()) diff --git a/tests/CommunityToolkit.Mvvm.UnitTests/Test_ObservableObject.cs b/tests/CommunityToolkit.Mvvm.UnitTests/Test_ObservableObject.cs index e5da66f5e..6c3c784b7 100644 --- a/tests/CommunityToolkit.Mvvm.UnitTests/Test_ObservableObject.cs +++ b/tests/CommunityToolkit.Mvvm.UnitTests/Test_ObservableObject.cs @@ -46,10 +46,10 @@ public void Test_ObservableObject_Events() model.Data = 42; - Assert.AreEqual(changing.Item1?.PropertyName, nameof(SampleModel.Data)); - Assert.AreEqual(changing.Item2, 0); - Assert.AreEqual(changed.Item1?.PropertyName, nameof(SampleModel.Data)); - Assert.AreEqual(changed.Item2, 42); + Assert.AreEqual(nameof(SampleModel.Data), changing.Item1?.PropertyName); + Assert.AreEqual(0, changing.Item2); + Assert.AreEqual(nameof(SampleModel.Data), changed.Item1?.PropertyName); + Assert.AreEqual(42, changed.Item2); } public class SampleModel : ObservableObject @@ -87,11 +87,11 @@ public void Test_ObservableObject_ProxyCrudWithProperty() model.Name = "Bob"; - Assert.AreEqual(changing.Item1?.PropertyName, nameof(WrappingModelWithProperty.Name)); - Assert.AreEqual(changing.Item2, "Alice"); - Assert.AreEqual(changed.Item1?.PropertyName, nameof(WrappingModelWithProperty.Name)); - Assert.AreEqual(changed.Item2, "Bob"); - Assert.AreEqual(model.PersonProxy.Name, "Bob"); + Assert.AreEqual(nameof(WrappingModelWithProperty.Name), changing.Item1?.PropertyName); + Assert.AreEqual("Alice", changing.Item2); + Assert.AreEqual(nameof(WrappingModelWithProperty.Name), changed.Item1?.PropertyName); + Assert.AreEqual("Bob", changed.Item2); + Assert.AreEqual("Bob", model.PersonProxy.Name); } public class Person @@ -141,11 +141,11 @@ public void Test_ObservableObject_ProxyCrudWithField() model.Name = "Bob"; - Assert.AreEqual(changing.Item1?.PropertyName, nameof(WrappingModelWithField.Name)); - Assert.AreEqual(changing.Item2, "Alice"); - Assert.AreEqual(changed.Item1?.PropertyName, nameof(WrappingModelWithField.Name)); - Assert.AreEqual(changed.Item2, "Bob"); - Assert.AreEqual(model.PersonProxy.Name, "Bob"); + Assert.AreEqual(nameof(WrappingModelWithField.Name), changing.Item1?.PropertyName); + Assert.AreEqual("Alice", changing.Item2); + Assert.AreEqual(nameof(WrappingModelWithField.Name), changed.Item1?.PropertyName); + Assert.AreEqual("Bob", changed.Item2); + Assert.AreEqual("Bob", model.PersonProxy.Name); } public class WrappingModelWithField : ObservableObject @@ -195,10 +195,10 @@ static async Task TestAsync(Action> callback) model.Data = task; Assert.IsFalse(task.IsCompleted); - Assert.AreEqual(changing.Item1?.PropertyName, nameof(SampleModelWithTask.Data)); + Assert.AreEqual(nameof(SampleModelWithTask.Data), changing.Item1?.PropertyName); Assert.IsNull(changing.Item2); - Assert.AreEqual(changed.Item1?.PropertyName, nameof(SampleModelWithTask.Data)); - Assert.AreSame(changed.Item2, task); + Assert.AreEqual(nameof(SampleModelWithTask.Data), changed.Item1?.PropertyName); + Assert.AreSame(task, changed.Item2); changed = default; @@ -207,8 +207,8 @@ static async Task TestAsync(Action> callback) await Task.Delay(100); // Time for the notification to dispatch Assert.IsTrue(task.IsCompleted); - Assert.AreEqual(changed.Item1?.PropertyName, nameof(SampleModel.Data)); - Assert.AreSame(changed.Item2, task); + Assert.AreEqual(nameof(SampleModel.Data), changed.Item1?.PropertyName); + Assert.AreSame(task, changed.Item2); } await TestAsync(tcs => tcs.SetResult(42)); diff --git a/tests/CommunityToolkit.Mvvm.UnitTests/Test_ObservableObjectAttribute.cs b/tests/CommunityToolkit.Mvvm.UnitTests/Test_ObservableObjectAttribute.cs index 78ed9320d..0d30c3d36 100644 --- a/tests/CommunityToolkit.Mvvm.UnitTests/Test_ObservableObjectAttribute.cs +++ b/tests/CommunityToolkit.Mvvm.UnitTests/Test_ObservableObjectAttribute.cs @@ -48,10 +48,10 @@ public void Test_ObservableObjectAttribute_Events() model.Data = 42; - Assert.AreEqual(changing.Item1?.PropertyName, nameof(SampleModel.Data)); - Assert.AreEqual(changing.Item2, 0); - Assert.AreEqual(changed.Item1?.PropertyName, nameof(SampleModel.Data)); - Assert.AreEqual(changed.Item2, 42); + Assert.AreEqual(nameof(SampleModel.Data), changing.Item1?.PropertyName); + Assert.AreEqual(0, changing.Item2); + Assert.AreEqual(nameof(SampleModel.Data), changed.Item1?.PropertyName); + Assert.AreEqual(42, changed.Item2); } [TestMethod] @@ -89,10 +89,10 @@ public void Test_ObservableObjectAttribute_OnSealedClass_Events() model.Data = 42; - Assert.AreEqual(changing.Item1?.PropertyName, nameof(SampleModelSealed.Data)); - Assert.AreEqual(changing.Item2, 0); - Assert.AreEqual(changed.Item1?.PropertyName, nameof(SampleModelSealed.Data)); - Assert.AreEqual(changed.Item2, 42); + Assert.AreEqual(nameof(SampleModelSealed.Data), changing.Item1?.PropertyName); + Assert.AreEqual(0, changing.Item2); + Assert.AreEqual(nameof(SampleModelSealed.Data), changed.Item1?.PropertyName); + Assert.AreEqual(42, changed.Item2); } [ObservableObject] diff --git a/tests/CommunityToolkit.Mvvm.UnitTests/Test_ObservablePropertyAttribute.cs b/tests/CommunityToolkit.Mvvm.UnitTests/Test_ObservablePropertyAttribute.cs index e485793df..3c243d5fc 100644 --- a/tests/CommunityToolkit.Mvvm.UnitTests/Test_ObservablePropertyAttribute.cs +++ b/tests/CommunityToolkit.Mvvm.UnitTests/Test_ObservablePropertyAttribute.cs @@ -60,10 +60,10 @@ public void Test_ObservablePropertyAttribute_Events() model.Data = 42; - Assert.AreEqual(changing.Item1?.PropertyName, nameof(SampleModel.Data)); - Assert.AreEqual(changing.Item2, 0); - Assert.AreEqual(changed.Item1?.PropertyName, nameof(SampleModel.Data)); - Assert.AreEqual(changed.Item2, 42); + Assert.AreEqual(nameof(SampleModel.Data), changing.Item1?.PropertyName); + Assert.AreEqual(0, changing.Item2); + Assert.AreEqual(nameof(SampleModel.Data), changed.Item1?.PropertyName); + Assert.AreEqual(42, changed.Item2); } // See https://github.com/CommunityToolkit/WindowsCommunityToolkit/issues/4225 @@ -99,10 +99,10 @@ public void Test_ObservablePropertyAttributeWithinRegion_Events() model.Counter = 42; - Assert.AreEqual(changing.Item1?.PropertyName, nameof(SampleModel.Counter)); - Assert.AreEqual(changing.Item2, 0); - Assert.AreEqual(changed.Item1?.PropertyName, nameof(SampleModel.Counter)); - Assert.AreEqual(changed.Item2, 42); + Assert.AreEqual(nameof(SampleModel.Counter), changing.Item1?.PropertyName); + Assert.AreEqual(0, changing.Item2); + Assert.AreEqual(nameof(SampleModel.Counter), changed.Item1?.PropertyName); + Assert.AreEqual(42, changed.Item2); } // See https://github.com/CommunityToolkit/WindowsCommunityToolkit/issues/4225 @@ -138,10 +138,10 @@ public void Test_ObservablePropertyAttributeRightBelowRegion_Events() model.Name = "Bob"; - Assert.AreEqual(changing.Item1?.PropertyName, nameof(SampleModel.Name)); - Assert.AreEqual(changing.Item2, null); - Assert.AreEqual(changed.Item1?.PropertyName, nameof(SampleModel.Name)); - Assert.AreEqual(changed.Item2, "Bob"); + Assert.AreEqual(nameof(SampleModel.Name), changing.Item1?.PropertyName); + Assert.AreEqual(null, changing.Item2); + Assert.AreEqual(nameof(SampleModel.Name), changed.Item1?.PropertyName); + Assert.AreEqual("Bob", changed.Item2); } [TestMethod] @@ -166,15 +166,15 @@ public void Test_ValidationAttributes() Assert.IsNotNull(nameProperty.GetCustomAttribute()); Assert.IsNotNull(nameProperty.GetCustomAttribute()); - Assert.AreEqual(nameProperty.GetCustomAttribute()!.Length, 1); + Assert.AreEqual(1, nameProperty.GetCustomAttribute()!.Length); Assert.IsNotNull(nameProperty.GetCustomAttribute()); - Assert.AreEqual(nameProperty.GetCustomAttribute()!.Length, 100); + Assert.AreEqual(100, nameProperty.GetCustomAttribute()!.Length); PropertyInfo ageProperty = typeof(MyFormViewModel).GetProperty(nameof(MyFormViewModel.Age))!; Assert.IsNotNull(ageProperty.GetCustomAttribute()); - Assert.AreEqual(ageProperty.GetCustomAttribute()!.Minimum, 0); - Assert.AreEqual(ageProperty.GetCustomAttribute()!.Maximum, 120); + Assert.AreEqual(0, ageProperty.GetCustomAttribute()!.Minimum); + Assert.AreEqual(120, ageProperty.GetCustomAttribute()!.Maximum); PropertyInfo emailProperty = typeof(MyFormViewModel).GetProperty(nameof(MyFormViewModel.Email))!; @@ -186,21 +186,21 @@ public void Test_ValidationAttributes() Assert.IsNotNull(testAttribute); Assert.IsNull(testAttribute.O); - Assert.AreEqual(testAttribute.T, typeof(SampleModel)); - Assert.AreEqual(testAttribute.Flag, true); - Assert.AreEqual(testAttribute.D, 6.28); - CollectionAssert.AreEqual(testAttribute.Names, new[] { "Bob", "Ross" }); + Assert.AreEqual(typeof(SampleModel), testAttribute.T); + Assert.AreEqual(true, testAttribute.Flag); + Assert.AreEqual(6.28, testAttribute.D); + CollectionAssert.AreEqual(new[] { "Bob", "Ross" }, testAttribute.Names); object[]? nestedArray = (object[]?)testAttribute.NestedArray; Assert.IsNotNull(nestedArray); - Assert.AreEqual(nestedArray!.Length, 3); - Assert.AreEqual(nestedArray[0], 1); - Assert.AreEqual(nestedArray[1], "Hello"); + Assert.AreEqual(3, nestedArray!.Length); + Assert.AreEqual(1, nestedArray[0]); + Assert.AreEqual("Hello", nestedArray[1]); Assert.IsTrue(nestedArray[2] is int[]); - CollectionAssert.AreEqual((int[])nestedArray[2], new[] { 2, 3, 4 }); + CollectionAssert.AreEqual(new[] { 2, 3, 4 }, (int[])nestedArray[2]); - Assert.AreEqual(testAttribute.Animal, Animal.Llama); + Assert.AreEqual(Animal.Llama, testAttribute.Animal); } // See https://github.com/CommunityToolkit/WindowsCommunityToolkit/issues/4216 @@ -215,7 +215,7 @@ public void Test_ObservablePropertyWithValueNamedField() model.Value = "Hello world"; - Assert.AreEqual(model.Value, "Hello world"); + Assert.AreEqual("Hello world", model.Value); CollectionAssert.AreEqual(new[] { nameof(model.Value) }, propertyNames); } @@ -236,7 +236,7 @@ public void Test_ObservablePropertyWithValueNamedField_WithValidationAttributes( model.Value = "Hello world"; - Assert.AreEqual(model.Value, "Hello world"); + Assert.AreEqual("Hello world", model.Value); // The [NotifyDataErrorInfo] attribute wasn't used, so the property shouldn't be validated Assert.IsFalse(errorsChanged); @@ -260,14 +260,14 @@ public void Test_ObservablePropertyWithValueNamedField_WithValidationAttributesA model.Value = "Bo"; Assert.IsTrue(model.HasErrors); - Assert.AreEqual(errors.Count, 1); - Assert.AreEqual(errors[0].PropertyName, nameof(ModelWithValuePropertyWithAutomaticValidation.Value)); + Assert.AreEqual(1, errors.Count); + Assert.AreEqual(nameof(ModelWithValuePropertyWithAutomaticValidation.Value), errors[0].PropertyName); model.Value = "Hello world"; Assert.IsFalse(model.HasErrors); - Assert.AreEqual(errors.Count, 2); - Assert.AreEqual(errors[1].PropertyName, nameof(ModelWithValuePropertyWithAutomaticValidation.Value)); + Assert.AreEqual(2, errors.Count); + Assert.AreEqual(nameof(ModelWithValuePropertyWithAutomaticValidation.Value), errors[1].PropertyName); } [TestMethod] @@ -286,14 +286,14 @@ public void Test_ObservablePropertyWithValueNamedField_WithValidationAttributesA model.Value = "Bo"; Assert.IsTrue(model.HasErrors); - Assert.AreEqual(errors.Count, 1); - Assert.AreEqual(errors[0].PropertyName, nameof(ModelWithValuePropertyWithAutomaticValidationWithClassLevelAttribute.Value)); + Assert.AreEqual(1, errors.Count); + Assert.AreEqual(nameof(ModelWithValuePropertyWithAutomaticValidationWithClassLevelAttribute.Value), errors[0].PropertyName); model.Value = "Hello world"; Assert.IsFalse(model.HasErrors); - Assert.AreEqual(errors.Count, 2); - Assert.AreEqual(errors[1].PropertyName, nameof(ModelWithValuePropertyWithAutomaticValidationWithClassLevelAttribute.Value)); + Assert.AreEqual(2, errors.Count); + Assert.AreEqual(nameof(ModelWithValuePropertyWithAutomaticValidationWithClassLevelAttribute.Value), errors[1].PropertyName); } [TestMethod] @@ -312,14 +312,14 @@ public void Test_ObservablePropertyWithValueNamedField_WithValidationAttributesA model.Value2 = "Bo"; Assert.IsTrue(model.HasErrors); - Assert.AreEqual(errors.Count, 1); - Assert.AreEqual(errors[0].PropertyName, nameof(ModelWithValuePropertyWithAutomaticValidationInheritingClassLevelAttribute.Value2)); + Assert.AreEqual(1, errors.Count); + Assert.AreEqual(nameof(ModelWithValuePropertyWithAutomaticValidationInheritingClassLevelAttribute.Value2), errors[0].PropertyName); model.Value2 = "Hello world"; Assert.IsFalse(model.HasErrors); - Assert.AreEqual(errors.Count, 2); - Assert.AreEqual(errors[1].PropertyName, nameof(ModelWithValuePropertyWithAutomaticValidationInheritingClassLevelAttribute.Value2)); + Assert.AreEqual(2, errors.Count); + Assert.AreEqual(nameof(ModelWithValuePropertyWithAutomaticValidationInheritingClassLevelAttribute.Value2), errors[1].PropertyName); } // See https://github.com/CommunityToolkit/WindowsCommunityToolkit/issues/4184 @@ -345,7 +345,7 @@ public void Test_GeneratedPropertiesWithValidationAttributesOverFields() ValidationResult[] validationErrors = model.GetErrors().ToArray(); - Assert.AreEqual(validationErrors.Length, 2); + Assert.AreEqual(2, validationErrors.Length); CollectionAssert.AreEqual(new[] { nameof(ViewModelWithValidatableGeneratedProperties.First) }, validationErrors[0].MemberNames.ToArray()); CollectionAssert.AreEqual(new[] { nameof(ViewModelWithValidatableGeneratedProperties.Last) }, validationErrors[1].MemberNames.ToArray()); @@ -615,7 +615,7 @@ public void Test_ObservableProperty_ObservableRecipientDoesNotBroadcastByDefault model.Name = null; // The [NotifyPropertyChangedRecipients] attribute wasn't used, so no messages should have been sent - Assert.AreEqual(messages.Count, 0); + Assert.AreEqual(0, messages.Count); } #if NET6_0_OR_GREATER @@ -761,9 +761,9 @@ public void Test_ObservableProperty_WithinGenericTypeWithMultipleTypeParameters( model.UValue = "Hello"; model.List = new List() { 420 }; - Assert.AreEqual(model.Value, true); - Assert.AreEqual(model.TValue, 42); - Assert.AreEqual(model.UValue, "Hello"); + Assert.AreEqual(true, model.Value); + Assert.AreEqual(42, model.TValue); + Assert.AreEqual("Hello", model.UValue); CollectionAssert.AreEqual(new[] { 420 }, model.List); CollectionAssert.AreEqual(new[] { nameof(model.Value), nameof(model.TValue), nameof(model.UValue), nameof(model.List) }, propertyNames); @@ -779,13 +779,13 @@ public void Test_ObservableProperty_WithBaseViewModelWithObservableObjectAttribu model.PropertyChanged += (s, e) => propertyNames.Add(e.PropertyName); - Assert.AreEqual(model.OtherProperty, "Ok"); + Assert.AreEqual("Ok", model.OtherProperty); model.MyProperty = "A"; model.OtherProperty = "B"; - Assert.AreEqual(model.MyProperty, "A"); - Assert.AreEqual(model.OtherProperty, "B"); + Assert.AreEqual("A", model.MyProperty); + Assert.AreEqual("B", model.OtherProperty); CollectionAssert.AreEqual(new[] { nameof(model.MyProperty), nameof(model.OtherProperty) }, propertyNames); } @@ -802,7 +802,7 @@ public void Test_ObservableProperty_ModelWithCultureAwarePropertyName() model.InputFolder = 42; - Assert.AreEqual(model.InputFolder, 42); + Assert.AreEqual(42, model.InputFolder); CollectionAssert.AreEqual(new[] { nameof(model.InputFolder) }, propertyNames); } @@ -838,7 +838,7 @@ public void Test_ObservableProperty_ModelWithNotifyPropertyChangedRecipientsAndD model.SomeProperty = newValue; - Assert.AreEqual(model.SomeProperty, newValue); + Assert.AreEqual(newValue, model.SomeProperty); Assert.IsTrue(isMessageReceived); CollectionAssert.AreEqual(new[] { nameof(model.SomeProperty) }, propertyNames); @@ -865,9 +865,9 @@ public void Test_ObservableProperty_ForwardsSpecialCasesDataAnnotationAttributes DisplayAttribute? displayAttribute = (DisplayAttribute?)propertyInfo.GetCustomAttribute(typeof(DisplayAttribute)); Assert.IsNotNull(displayAttribute); - Assert.AreEqual(displayAttribute!.Name, "MyProperty"); - Assert.AreEqual(displayAttribute.ResourceType, typeof(List)); - Assert.AreEqual(displayAttribute.Prompt, "Foo bar baz"); + Assert.AreEqual("MyProperty", displayAttribute!.Name); + Assert.AreEqual(typeof(List), displayAttribute.ResourceType); + Assert.AreEqual("Foo bar baz", displayAttribute.Prompt); KeyAttribute? keyAttribute = (KeyAttribute?)propertyInfo.GetCustomAttribute(typeof(KeyAttribute)); @@ -881,15 +881,15 @@ public void Test_ObservableProperty_ForwardsSpecialCasesDataAnnotationAttributes UIHintAttribute? uiHintAttribute = (UIHintAttribute?)propertyInfo.GetCustomAttribute(typeof(UIHintAttribute)); Assert.IsNotNull(uiHintAttribute); - Assert.AreEqual(uiHintAttribute!.UIHint, "MyControl"); - Assert.AreEqual(uiHintAttribute.PresentationLayer, "WPF"); - Assert.AreEqual(uiHintAttribute.ControlParameters.Count, 3); + Assert.AreEqual("MyControl", uiHintAttribute!.UIHint); + Assert.AreEqual("WPF", uiHintAttribute.PresentationLayer); + Assert.AreEqual(3, uiHintAttribute.ControlParameters.Count); Assert.IsTrue(uiHintAttribute.ControlParameters.ContainsKey("Foo")); Assert.IsTrue(uiHintAttribute.ControlParameters.ContainsKey("Bar")); Assert.IsTrue(uiHintAttribute.ControlParameters.ContainsKey("Baz")); - Assert.AreEqual(uiHintAttribute.ControlParameters["Foo"], 42); - Assert.AreEqual(uiHintAttribute.ControlParameters["Bar"], 3.14); - Assert.AreEqual(uiHintAttribute.ControlParameters["Baz"], "Hello"); + Assert.AreEqual(42, uiHintAttribute.ControlParameters["Foo"]); + Assert.AreEqual(3.14, uiHintAttribute.ControlParameters["Bar"]); + Assert.AreEqual("Hello", uiHintAttribute.ControlParameters["Baz"]); ScaffoldColumnAttribute? scaffoldColumnAttribute = (ScaffoldColumnAttribute?)propertyInfo.GetCustomAttribute(typeof(ScaffoldColumnAttribute)); @@ -910,7 +910,7 @@ public void Test_ObservableProperty_ModelWithObservablePropertyInRootNamespace() model.Number = 3.14f; // We mostly just need to verify this class compiles fine with the right generated code - CollectionAssert.AreEqual(propertyNames, new[] { nameof(model.Number) }); + CollectionAssert.AreEqual(new[] { nameof(model.Number) }, propertyNames); } // See https://github.com/CommunityToolkit/dotnet/issues/272 @@ -939,14 +939,14 @@ public void Test_ObservableProperty_WithExplicitAttributeForProperty() Assert.IsNotNull(nameProperty.GetCustomAttribute()); Assert.IsNotNull(nameProperty.GetCustomAttribute()); - Assert.AreEqual(nameProperty.GetCustomAttribute()!.Length, 1); + Assert.AreEqual(1, nameProperty.GetCustomAttribute()!.Length); Assert.IsNotNull(nameProperty.GetCustomAttribute()); - Assert.AreEqual(nameProperty.GetCustomAttribute()!.Length, 100); + Assert.AreEqual(100, nameProperty.GetCustomAttribute()!.Length); PropertyInfo lastNameProperty = typeof(MyViewModelWithExplicitPropertyAttributes).GetProperty(nameof(MyViewModelWithExplicitPropertyAttributes.LastName))!; Assert.IsNotNull(lastNameProperty.GetCustomAttribute()); - Assert.AreEqual(lastNameProperty.GetCustomAttribute()!.Name, "lastName"); + Assert.AreEqual("lastName", lastNameProperty.GetCustomAttribute()!.Name); Assert.IsNotNull(lastNameProperty.GetCustomAttribute()); PropertyInfo justOneSimpleAttributeProperty = typeof(MyViewModelWithExplicitPropertyAttributes).GetProperty(nameof(MyViewModelWithExplicitPropertyAttributes.JustOneSimpleAttribute))!; @@ -959,21 +959,21 @@ public void Test_ObservableProperty_WithExplicitAttributeForProperty() Assert.IsNotNull(testAttribute); Assert.IsNull(testAttribute.O); - Assert.AreEqual(testAttribute.T, typeof(MyViewModelWithExplicitPropertyAttributes)); - Assert.AreEqual(testAttribute.Flag, true); - Assert.AreEqual(testAttribute.D, 6.28); - CollectionAssert.AreEqual(testAttribute.Names, new[] { "Bob", "Ross" }); + Assert.AreEqual(typeof(MyViewModelWithExplicitPropertyAttributes), testAttribute.T); + Assert.AreEqual(true, testAttribute.Flag); + Assert.AreEqual(6.28, testAttribute.D); + CollectionAssert.AreEqual(new[] { "Bob", "Ross" }, testAttribute.Names); object[]? nestedArray = (object[]?)testAttribute.NestedArray; Assert.IsNotNull(nestedArray); - Assert.AreEqual(nestedArray!.Length, 3); - Assert.AreEqual(nestedArray[0], 1); - Assert.AreEqual(nestedArray[1], "Hello"); + Assert.AreEqual(3, nestedArray!.Length); + Assert.AreEqual(1, nestedArray[0]); + Assert.AreEqual("Hello", nestedArray[1]); Assert.IsTrue(nestedArray[2] is int[]); - CollectionAssert.AreEqual((int[])nestedArray[2], new[] { 2, 3, 4 }); + CollectionAssert.AreEqual(new[] { 2, 3, 4 }, (int[])nestedArray[2]); - Assert.AreEqual(testAttribute.Animal, Animal.Llama); + Assert.AreEqual(Animal.Llama, testAttribute.Animal); PropertyInfo someComplexRandomAttribute = typeof(MyViewModelWithExplicitPropertyAttributes).GetProperty(nameof(MyViewModelWithExplicitPropertyAttributes.SomeComplexRandomAttribute))!; @@ -983,25 +983,25 @@ public void Test_ObservableProperty_WithExplicitAttributeForProperty() Assert.IsNotNull(testAttribute2); Assert.IsNull(testAttribute2.O); - Assert.AreEqual(testAttribute2.T, typeof(MyViewModelWithExplicitPropertyAttributes)); - Assert.AreEqual(testAttribute2.Flag, true); - Assert.AreEqual(testAttribute2.D, 6.28); + Assert.AreEqual(typeof(MyViewModelWithExplicitPropertyAttributes), testAttribute2.T); + Assert.AreEqual(true, testAttribute2.Flag); + Assert.AreEqual(6.28, testAttribute2.D); Assert.IsNotNull(testAttribute2.Objects); Assert.IsTrue(testAttribute2.Objects is object[]); - Assert.AreEqual(((object[])testAttribute2.Objects).Length, 1); - Assert.AreEqual(((object[])testAttribute2.Objects)[0], "Test"); - CollectionAssert.AreEqual(testAttribute2.Names, new[] { "Bob", "Ross" }); + Assert.AreEqual(1, ((object[])testAttribute2.Objects).Length); + Assert.AreEqual("Test", ((object[])testAttribute2.Objects)[0]); + CollectionAssert.AreEqual(new[] { "Bob", "Ross" }, testAttribute2.Names); object[]? nestedArray2 = (object[]?)testAttribute2.NestedArray; Assert.IsNotNull(nestedArray2); - Assert.AreEqual(nestedArray2!.Length, 4); - Assert.AreEqual(nestedArray2[0], 1); - Assert.AreEqual(nestedArray2[1], "Hello"); - Assert.AreEqual(nestedArray2[2], 42); + Assert.AreEqual(4, nestedArray2!.Length); + Assert.AreEqual(1, nestedArray2[0]); + Assert.AreEqual("Hello", nestedArray2[1]); + Assert.AreEqual(42, nestedArray2[2]); Assert.IsNull(nestedArray2[3]); - Assert.AreEqual(testAttribute2.Animal, (Animal)67); + Assert.AreEqual((Animal)67, testAttribute2.Animal); } // See https://github.com/CommunityToolkit/dotnet/issues/446 diff --git a/tests/CommunityToolkit.Mvvm.UnitTests/Test_ObservableRecipient.cs b/tests/CommunityToolkit.Mvvm.UnitTests/Test_ObservableRecipient.cs index 9149ddcc9..4ee9bed7f 100644 --- a/tests/CommunityToolkit.Mvvm.UnitTests/Test_ObservableRecipient.cs +++ b/tests/CommunityToolkit.Mvvm.UnitTests/Test_ObservableRecipient.cs @@ -49,7 +49,7 @@ public void Test_ObservableRecipient_IsSame(Type type) IMessenger? messenger = (IMessenger)Activator.CreateInstance(type)!; SomeRecipient? viewmodel = new(messenger); - Assert.AreSame(viewmodel.CurrentMessenger, messenger); + Assert.AreSame(messenger, viewmodel.CurrentMessenger); } [TestMethod] @@ -57,7 +57,7 @@ public void Test_ObservableRecipient_Default() { SomeRecipient? viewmodel = new(); - Assert.AreSame(viewmodel.CurrentMessenger, WeakReferenceMessenger.Default); + Assert.AreSame(WeakReferenceMessenger.Default, viewmodel.CurrentMessenger); } [TestMethod] @@ -68,7 +68,7 @@ public void Test_ObservableRecipient_Injection(Type type) IMessenger? messenger = (IMessenger)Activator.CreateInstance(type)!; SomeRecipient? viewmodel = new(messenger); - Assert.AreSame(viewmodel.CurrentMessenger, messenger); + Assert.AreSame(messenger, viewmodel.CurrentMessenger); } [TestMethod] @@ -86,10 +86,10 @@ public void Test_ObservableRecipient_Broadcast(Type type) viewmodel.Data = 42; Assert.IsNotNull(message); - Assert.AreSame(message.Sender, viewmodel); - Assert.AreEqual(message.OldValue, 0); - Assert.AreEqual(message.NewValue, 42); - Assert.AreEqual(message.PropertyName, nameof(SomeRecipient.Data)); + Assert.AreSame(viewmodel, message.Sender); + Assert.AreEqual(0, message.OldValue); + Assert.AreEqual(42, message.NewValue); + Assert.AreEqual(nameof(SomeRecipient.Data), message.PropertyName); } [TestMethod] diff --git a/tests/CommunityToolkit.Mvvm.UnitTests/Test_ObservableRecipientAttribute.cs b/tests/CommunityToolkit.Mvvm.UnitTests/Test_ObservableRecipientAttribute.cs index 9e2ee3dd7..3b2034ca4 100644 --- a/tests/CommunityToolkit.Mvvm.UnitTests/Test_ObservableRecipientAttribute.cs +++ b/tests/CommunityToolkit.Mvvm.UnitTests/Test_ObservableRecipientAttribute.cs @@ -32,19 +32,19 @@ public void Test_ObservableRecipientAttribute_Events() model.Name = "No"; Assert.IsTrue(model.HasErrors); - Assert.AreEqual(args.Count, 2); - Assert.AreEqual(args[0].PropertyName, nameof(Person.Name)); - Assert.AreEqual(args[1].PropertyName, nameof(INotifyDataErrorInfo.HasErrors)); + Assert.AreEqual(2, args.Count); + Assert.AreEqual(nameof(Person.Name), args[0].PropertyName); + Assert.AreEqual(nameof(INotifyDataErrorInfo.HasErrors), args[1].PropertyName); model.Name = "Valid"; Assert.IsFalse(model.HasErrors); - Assert.AreEqual(args.Count, 4); - Assert.AreEqual(args[2].PropertyName, nameof(Person.Name)); - Assert.AreEqual(args[3].PropertyName, nameof(INotifyDataErrorInfo.HasErrors)); + Assert.AreEqual(4, args.Count); + Assert.AreEqual(nameof(Person.Name), args[2].PropertyName); + Assert.AreEqual(nameof(INotifyDataErrorInfo.HasErrors), args[3].PropertyName); Assert.IsNotNull(typeof(Person).GetProperty("Messenger", BindingFlags.Instance | BindingFlags.NonPublic)); - Assert.AreEqual(typeof(Person).GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic).Length, 0); + Assert.AreEqual(0, typeof(Person).GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic).Length); } [ObservableRecipient] @@ -78,7 +78,7 @@ public void Test_ObservableRecipientAttribute_AbstractConstructors() { ConstructorInfo[]? ctors = typeof(AbstractPerson).GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic); - Assert.AreEqual(ctors.Length, 2); + Assert.AreEqual(2, ctors.Length); Assert.IsTrue(ctors.All(static ctor => ctor.IsFamily)); } @@ -92,7 +92,7 @@ public void Test_ObservableRecipientAttribute_NonAbstractConstructors() { ConstructorInfo[]? ctors = typeof(NonAbstractPerson).GetConstructors(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); - Assert.AreEqual(ctors.Length, 2); + Assert.AreEqual(2, ctors.Length); Assert.IsTrue(ctors.All(static ctor => ctor.IsPublic)); } diff --git a/tests/CommunityToolkit.Mvvm.UnitTests/Test_ObservableValidator.cs b/tests/CommunityToolkit.Mvvm.UnitTests/Test_ObservableValidator.cs index b686d2192..06791cb49 100644 --- a/tests/CommunityToolkit.Mvvm.UnitTests/Test_ObservableValidator.cs +++ b/tests/CommunityToolkit.Mvvm.UnitTests/Test_ObservableValidator.cs @@ -35,16 +35,16 @@ public void Test_ObservableValidator_HasErrors() // properties were broadcast as well (both the changed property and HasErrors). We need // this last one to raise notifications too so that users can bind to that in the UI. Assert.IsTrue(model.HasErrors); - Assert.AreEqual(args.Count, 2); - Assert.AreEqual(args[0].PropertyName, nameof(Person.Name)); - Assert.AreEqual(args[1].PropertyName, nameof(INotifyDataErrorInfo.HasErrors)); + Assert.AreEqual(2, args.Count); + Assert.AreEqual(nameof(Person.Name), args[0].PropertyName); + Assert.AreEqual(nameof(INotifyDataErrorInfo.HasErrors), args[1].PropertyName); model.Name = "Valid"; Assert.IsFalse(model.HasErrors); - Assert.AreEqual(args.Count, 4); - Assert.AreEqual(args[2].PropertyName, nameof(Person.Name)); - Assert.AreEqual(args[3].PropertyName, nameof(INotifyDataErrorInfo.HasErrors)); + Assert.AreEqual(4, args.Count); + Assert.AreEqual(nameof(Person.Name), args[2].PropertyName); + Assert.AreEqual(nameof(INotifyDataErrorInfo.HasErrors), args[3].PropertyName); } [TestMethod] @@ -58,31 +58,31 @@ public void Test_ObservableValidator_ErrorsChanged() model.Name = "Foo"; - Assert.AreEqual(errors.Count, 1); - Assert.AreSame(errors[0].Sender, model); - Assert.AreEqual(errors[0].Args.PropertyName, nameof(Person.Name)); + Assert.AreEqual(1, errors.Count); + Assert.AreSame(model, errors[0].Sender); + Assert.AreEqual(nameof(Person.Name), errors[0].Args.PropertyName); errors.Clear(); model.Name = "Bar"; - Assert.AreEqual(errors.Count, 1); - Assert.AreSame(errors[0].Sender, model); - Assert.AreEqual(errors[0].Args.PropertyName, nameof(Person.Name)); + Assert.AreEqual(1, errors.Count); + Assert.AreSame(model, errors[0].Sender); + Assert.AreEqual(nameof(Person.Name), errors[0].Args.PropertyName); errors.Clear(); model.Name = "Valid"; - Assert.AreEqual(errors.Count, 1); - Assert.AreSame(errors[0].Sender, model); - Assert.AreEqual(errors[0].Args.PropertyName, nameof(Person.Name)); + Assert.AreEqual(1, errors.Count); + Assert.AreSame(model, errors[0].Sender); + Assert.AreEqual(nameof(Person.Name), errors[0].Args.PropertyName); errors.Clear(); model.Name = "This is fine"; - Assert.AreEqual(errors.Count, 0); + Assert.AreEqual(0, errors.Count); } [TestMethod] @@ -90,35 +90,35 @@ public void Test_ObservableValidator_GetErrors() { Person? model = new(); - Assert.AreEqual(model.GetErrors(null).Count(), 0); - Assert.AreEqual(model.GetErrors(string.Empty).Count(), 0); - Assert.AreEqual(model.GetErrors("ThereIsntAPropertyWithThisName").Count(), 0); - Assert.AreEqual(model.GetErrors(nameof(Person.Name)).Count(), 0); + Assert.AreEqual(0, model.GetErrors(null).Count()); + Assert.AreEqual(0, model.GetErrors(string.Empty).Count()); + Assert.AreEqual(0, model.GetErrors("ThereIsntAPropertyWithThisName").Count()); + Assert.AreEqual(0, model.GetErrors(nameof(Person.Name)).Count()); model.Name = "Foo"; ValidationResult[]? errors = model.GetErrors(nameof(Person.Name)).ToArray(); - Assert.AreEqual(errors.Length, 1); - Assert.AreEqual(errors[0].MemberNames.First(), nameof(Person.Name)); + Assert.AreEqual(1, errors.Length); + Assert.AreEqual(nameof(Person.Name), errors[0].MemberNames.First()); - Assert.AreEqual(model.GetErrors("ThereIsntAPropertyWithThisName").Count(), 0); + Assert.AreEqual(0, model.GetErrors("ThereIsntAPropertyWithThisName").Count()); errors = model.GetErrors(null).ToArray(); - Assert.AreEqual(errors.Length, 1); - Assert.AreEqual(errors[0].MemberNames.First(), nameof(Person.Name)); + Assert.AreEqual(1, errors.Length); + Assert.AreEqual(nameof(Person.Name), errors[0].MemberNames.First()); errors = model.GetErrors(string.Empty).ToArray(); - Assert.AreEqual(errors.Length, 1); - Assert.AreEqual(errors[0].MemberNames.First(), nameof(Person.Name)); + Assert.AreEqual(1, errors.Length); + Assert.AreEqual(nameof(Person.Name), errors[0].MemberNames.First()); model.Age = -1; errors = model.GetErrors(null).ToArray(); - Assert.AreEqual(errors.Length, 2); + Assert.AreEqual(2, errors.Length); Assert.IsTrue(errors.Any(e => e.MemberNames.First().Equals(nameof(Person.Name)))); Assert.IsTrue(errors.Any(e => e.MemberNames.First().Equals(nameof(Person.Age)))); @@ -126,7 +126,7 @@ public void Test_ObservableValidator_GetErrors() errors = model.GetErrors(null).ToArray(); - Assert.AreEqual(errors.Length, 1); + Assert.AreEqual(1, errors.Length); Assert.IsTrue(errors.Any(e => e.MemberNames.First().Equals(nameof(Person.Name)))); Assert.IsFalse(errors.Any(e => e.MemberNames.First().Equals(nameof(Person.Age)))); } @@ -142,7 +142,7 @@ public void Test_ObservableValidator_ValidateReturn(string value, bool isValid) { Person? model = new() { Name = value }; - Assert.AreEqual(model.HasErrors, !isValid); + Assert.AreEqual(!isValid, model.HasErrors); if (isValid) { @@ -166,28 +166,28 @@ public void Test_ObservableValidator_TrySetProperty() Assert.IsTrue(model.TrySetName("Hello", out IReadOnlyCollection? errors)); Assert.IsTrue(errors.Count == 0); Assert.IsTrue(events.Count == 0); - Assert.AreEqual(model.Name, "Hello"); + Assert.AreEqual("Hello", model.Name); Assert.IsFalse(model.HasErrors); // Invalid value #1, this should be ignored Assert.IsFalse(model.TrySetName(null, out errors)); Assert.IsTrue(errors.Count > 0); Assert.IsTrue(events.Count == 0); - Assert.AreEqual(model.Name, "Hello"); + Assert.AreEqual("Hello", model.Name); Assert.IsFalse(model.HasErrors); // Invalid value #2, same as above Assert.IsFalse(model.TrySetName("This string is too long for the target property in this model and should fail", out errors)); Assert.IsTrue(errors.Count > 0); Assert.IsTrue(events.Count == 0); - Assert.AreEqual(model.Name, "Hello"); + Assert.AreEqual("Hello", model.Name); Assert.IsFalse(model.HasErrors); // Correct value, this should update the property Assert.IsTrue(model.TrySetName("Hello world", out errors)); Assert.IsTrue(errors.Count == 0); Assert.IsTrue(events.Count == 0); - Assert.AreEqual(model.Name, "Hello world"); + Assert.AreEqual("Hello world", model.Name); Assert.IsFalse(model.HasErrors); // Actually set an invalid value to show some errors @@ -204,7 +204,7 @@ public void Test_ObservableValidator_TrySetProperty() Assert.IsTrue(errors.Count == 0); Assert.IsTrue(events.Count == 2); Assert.IsFalse(model.HasErrors); - Assert.AreEqual(model.Name, "This is fine"); + Assert.AreEqual("This is fine", model.Name); } [TestMethod] @@ -219,14 +219,14 @@ public void Test_ObservableValidator_ValidateProperty() model.A = 42; model.B = 30; - Assert.AreEqual(events.Count, 0); + Assert.AreEqual(0, events.Count); Assert.IsFalse(model.HasErrors); // Make B greater than A, hence invalidating A model.B = 50; - Assert.AreEqual(events.Count, 1); - Assert.AreEqual(events.Last().PropertyName, nameof(ComparableModel.A)); + Assert.AreEqual(1, events.Count); + Assert.AreEqual(nameof(ComparableModel.A), events.Last().PropertyName); Assert.IsTrue(model.HasErrors); events.Clear(); @@ -234,9 +234,9 @@ public void Test_ObservableValidator_ValidateProperty() // Make A greater than B, hence making it valid again model.A = 51; - Assert.AreEqual(events.Count, 1); - Assert.AreEqual(events.Last().PropertyName, nameof(ComparableModel.A)); - Assert.AreEqual(model.GetErrors(nameof(ComparableModel.A)).Count(), 0); + Assert.AreEqual(1, events.Count); + Assert.AreEqual(nameof(ComparableModel.A), events.Last().PropertyName); + Assert.AreEqual(0, model.GetErrors(nameof(ComparableModel.A)).Count()); Assert.IsFalse(model.HasErrors); events.Clear(); @@ -244,9 +244,9 @@ public void Test_ObservableValidator_ValidateProperty() // Make A smaller than B, hence invalidating it model.A = 49; - Assert.AreEqual(events.Count, 1); - Assert.AreEqual(events.Last().PropertyName, nameof(ComparableModel.A)); - Assert.AreEqual(model.GetErrors(nameof(ComparableModel.A)).Count(), 1); + Assert.AreEqual(1, events.Count); + Assert.AreEqual(nameof(ComparableModel.A), events.Last().PropertyName); + Assert.AreEqual(1, model.GetErrors(nameof(ComparableModel.A)).Count()); Assert.IsTrue(model.HasErrors); events.Clear(); @@ -254,9 +254,9 @@ public void Test_ObservableValidator_ValidateProperty() // Lower B, hence making A valid again model.B = 20; - Assert.AreEqual(events.Count, 1); - Assert.AreEqual(events.Last().PropertyName, nameof(ComparableModel.A)); - Assert.AreEqual(model.GetErrors(nameof(ComparableModel.A)).Count(), 0); + Assert.AreEqual(1, events.Count); + Assert.AreEqual(nameof(ComparableModel.A), events.Last().PropertyName); + Assert.AreEqual(0, model.GetErrors(nameof(ComparableModel.A)).Count()); Assert.IsFalse(model.HasErrors); } @@ -424,7 +424,7 @@ public void Test_ObservableValidator_CustomValidation() model.A = 10; Assert.IsFalse(model.HasErrors); - Assert.AreEqual(events.Count, 0); + Assert.AreEqual(0, events.Count); } [TestMethod] @@ -438,28 +438,28 @@ public void Test_ObservableValidator_CustomValidationWithInjectedService() model.Name = "This is a valid name"; Assert.IsFalse(model.HasErrors); - Assert.AreEqual(events.Count, 0); + Assert.AreEqual(0, events.Count); model.Name = "This is invalid238!!"; Assert.IsTrue(model.HasErrors); - Assert.AreEqual(events.Count, 1); - Assert.AreEqual(events[0].PropertyName, nameof(ValidationWithServiceModel.Name)); - Assert.AreEqual(model.GetErrors(nameof(ValidationWithServiceModel.Name)).ToArray().Length, 1); + Assert.AreEqual(1, events.Count); + Assert.AreEqual(nameof(ValidationWithServiceModel.Name), events[0].PropertyName); + Assert.AreEqual(1, model.GetErrors(nameof(ValidationWithServiceModel.Name)).ToArray().Length); model.Name = "This is valid but it is too long so the validation will fail anyway"; Assert.IsTrue(model.HasErrors); - Assert.AreEqual(events.Count, 2); - Assert.AreEqual(events[1].PropertyName, nameof(ValidationWithServiceModel.Name)); - Assert.AreEqual(model.GetErrors(nameof(ValidationWithServiceModel.Name)).ToArray().Length, 1); + Assert.AreEqual(2, events.Count); + Assert.AreEqual(nameof(ValidationWithServiceModel.Name), events[1].PropertyName); + Assert.AreEqual(1, model.GetErrors(nameof(ValidationWithServiceModel.Name)).ToArray().Length); model.Name = "This is both too long and it also contains invalid characters, a real disaster!"; Assert.IsTrue(model.HasErrors); - Assert.AreEqual(events.Count, 3); - Assert.AreEqual(events[2].PropertyName, nameof(ValidationWithServiceModel.Name)); - Assert.AreEqual(model.GetErrors(nameof(ValidationWithServiceModel.Name)).ToArray().Length, 2); + Assert.AreEqual(3, events.Count); + Assert.AreEqual(nameof(ValidationWithServiceModel.Name), events[2].PropertyName); + Assert.AreEqual(2, model.GetErrors(nameof(ValidationWithServiceModel.Name)).ToArray().Length); } [TestMethod] @@ -472,15 +472,15 @@ public void Test_ObservableValidator_ValidationWithFormattedDisplayName() // We need to order because there is no guaranteed order on the members of a type ValidationResult[] allErrors = model.GetErrors().OrderBy(error => error.ErrorMessage).ToArray(); - Assert.AreEqual(allErrors.Length, 2); + Assert.AreEqual(2, allErrors.Length); - Assert.AreEqual(allErrors[0].MemberNames.Count(), 1); - Assert.AreEqual(allErrors[0].MemberNames.Single(), nameof(ValidationWithDisplayName.StringMayNotBeEmpty)); - Assert.AreEqual(allErrors[0].ErrorMessage, $"FIRST: {nameof(ValidationWithDisplayName.StringMayNotBeEmpty)}."); + Assert.AreEqual(1, allErrors[0].MemberNames.Count()); + Assert.AreEqual(nameof(ValidationWithDisplayName.StringMayNotBeEmpty), allErrors[0].MemberNames.Single()); + Assert.AreEqual($"FIRST: {nameof(ValidationWithDisplayName.StringMayNotBeEmpty)}.", allErrors[0].ErrorMessage); - Assert.AreEqual(allErrors[1].MemberNames.Count(), 1); - Assert.AreEqual(allErrors[1].MemberNames.Single(), nameof(ValidationWithDisplayName.AnotherRequiredField)); - Assert.AreEqual(allErrors[1].ErrorMessage, $"SECOND: {nameof(ValidationWithDisplayName.AnotherRequiredField)}."); + Assert.AreEqual(1, allErrors[1].MemberNames.Count()); + Assert.AreEqual(nameof(ValidationWithDisplayName.AnotherRequiredField), allErrors[1].MemberNames.Single()); + Assert.AreEqual($"SECOND: {nameof(ValidationWithDisplayName.AnotherRequiredField)}.", allErrors[1].ErrorMessage); } // See: https://github.com/CommunityToolkit/WindowsCommunityToolkit/issues/4272 @@ -554,9 +554,9 @@ public void Test_ObservableValidator_WithGenericTypeParameters() ValidationResult[] errors = model.GetErrors(nameof(model.Value)).ToArray(); Assert.IsNotNull(errors); - Assert.AreEqual(errors.Length, 1); + Assert.AreEqual(1, errors.Length); - CollectionAssert.AreEqual(errors[0].MemberNames.ToArray(), new[] { nameof(model.Value) }); + CollectionAssert.AreEqual(new[] { nameof(model.Value) }, errors[0].MemberNames.ToArray()); model.Value = "Ross"; @@ -692,7 +692,7 @@ public int A public static ValidationResult ValidateA(int x, ValidationContext context) { - Assert.AreEqual(context.MemberName, nameof(A)); + Assert.AreEqual(nameof(A), context.MemberName); if ((int)context.Items[nameof(A)]! == 42) { diff --git a/tests/CommunityToolkit.Mvvm.UnitTests/Test_RelayCommand.cs b/tests/CommunityToolkit.Mvvm.UnitTests/Test_RelayCommand.cs index f7c388699..728257434 100644 --- a/tests/CommunityToolkit.Mvvm.UnitTests/Test_RelayCommand.cs +++ b/tests/CommunityToolkit.Mvvm.UnitTests/Test_RelayCommand.cs @@ -27,16 +27,16 @@ public void Test_RelayCommand_AlwaysEnabled() command.NotifyCanExecuteChanged(); - Assert.AreSame(args.Item1, command); - Assert.AreSame(args.Item2, EventArgs.Empty); + Assert.AreSame(command, args.Item1); + Assert.AreSame(EventArgs.Empty, args.Item2); command.Execute(null); - Assert.AreEqual(ticks, 1); + Assert.AreEqual(1, ticks); command.Execute(new object()); - Assert.AreEqual(ticks, 2); + Assert.AreEqual(2, ticks); } [TestMethod] @@ -51,11 +51,11 @@ public void Test_RelayCommand_WithCanExecuteFunctionTrue() command.Execute(null); - Assert.AreEqual(ticks, 1); + Assert.AreEqual(1, ticks); command.Execute(new object()); - Assert.AreEqual(ticks, 2); + Assert.AreEqual(2, ticks); } [TestMethod] @@ -71,10 +71,10 @@ public void Test_RelayCommand_WithCanExecuteFunctionFalse() command.Execute(null); // Logic is unconditionally invoked, the caller should check CanExecute first - Assert.AreEqual(ticks, 1); + Assert.AreEqual(1, ticks); command.Execute(new object()); - Assert.AreEqual(ticks, 2); + Assert.AreEqual(2, ticks); } } diff --git a/tests/CommunityToolkit.Mvvm.UnitTests/Test_RelayCommandAttribute.cs b/tests/CommunityToolkit.Mvvm.UnitTests/Test_RelayCommandAttribute.cs index ecf4ff05d..fcf664913 100644 --- a/tests/CommunityToolkit.Mvvm.UnitTests/Test_RelayCommandAttribute.cs +++ b/tests/CommunityToolkit.Mvvm.UnitTests/Test_RelayCommandAttribute.cs @@ -27,27 +27,27 @@ public async Task Test_RelayCommandAttribute_RelayCommand() model.IncrementCounterCommand.Execute(null); - Assert.AreEqual(model.Counter, 1); + Assert.AreEqual(1, model.Counter); model.IncrementCounterWithValueCommand.Execute(5); - Assert.AreEqual(model.Counter, 6); + Assert.AreEqual(6, model.Counter); await model.DelayAndIncrementCounterCommand.ExecuteAsync(null); - Assert.AreEqual(model.Counter, 7); + Assert.AreEqual(7, model.Counter); await model.DelayAndIncrementCounterWithTokenCommand.ExecuteAsync(null); - Assert.AreEqual(model.Counter, 8); + Assert.AreEqual(8, model.Counter); await model.DelayAndIncrementCounterWithValueCommand.ExecuteAsync(5); - Assert.AreEqual(model.Counter, 13); + Assert.AreEqual(13, model.Counter); await model.DelayAndIncrementCounterWithValueAndTokenCommand.ExecuteAsync(5); - Assert.AreEqual(model.Counter, 18); + Assert.AreEqual(18, model.Counter); List tasks = new(); @@ -62,7 +62,7 @@ public async Task Test_RelayCommandAttribute_RelayCommand() // All values should already be in the list, as commands are executed // concurrently. Each invocation should still be pending here, but the // values are added to the list before starting the delay. - CollectionAssert.AreEqual(model.Values, Enumerable.Range(0, 10).ToArray()); + CollectionAssert.AreEqual(Enumerable.Range(0, 10).ToArray(), model.Values); await Task.WhenAll(tasks); @@ -84,7 +84,7 @@ public async Task Test_RelayCommandAttribute_RelayCommand() Assert.AreEqual(1, tasks.Count); // Only the first item should have been added - CollectionAssert.AreEqual(model.Values, new[] { 0 }); + CollectionAssert.AreEqual(new[] { 0 }, model.Values); model.ResetTcs(); model.Values.Clear(); @@ -102,7 +102,7 @@ public async Task Test_RelayCommandAttribute_RelayCommand() Assert.AreEqual(10, tasks.Count); - CollectionAssert.AreEqual(model.Values, Enumerable.Range(0, 10).ToArray()); + CollectionAssert.AreEqual(Enumerable.Range(0, 10).ToArray(), model.Values); model.Values.Clear(); tasks.Clear(); @@ -118,7 +118,7 @@ public async Task Test_RelayCommandAttribute_RelayCommand() Assert.AreEqual(1, tasks.Count); // Same as above, only the first one is added - CollectionAssert.AreEqual(model.Values, new[] { 0 }); + CollectionAssert.AreEqual(new[] { 0 }, model.Values); model.Values.Clear(); tasks.Clear(); @@ -131,7 +131,7 @@ public async Task Test_RelayCommandAttribute_RelayCommand() Assert.AreEqual(10, tasks.Count); - CollectionAssert.AreEqual(model.Values, Enumerable.Range(0, 10).ToArray()); + CollectionAssert.AreEqual(Enumerable.Range(0, 10).ToArray(), model.Values); } [TestMethod] @@ -143,7 +143,7 @@ public void Test_RelayCommandAttribute_CanExecute_NoParameters_Property() model.IncrementCounter_NoParameters_PropertyCommand.Execute(null); - Assert.AreEqual(model.Counter, 1); + Assert.AreEqual(1, model.Counter); model.Flag = false; @@ -152,7 +152,7 @@ public void Test_RelayCommandAttribute_CanExecute_NoParameters_Property() // This and all test above also verify the logic is unconditionally invoked if CanExecute is ignored model.IncrementCounter_NoParameters_PropertyCommand.Execute(null); - Assert.AreEqual(model.Counter, 2); + Assert.AreEqual(2, model.Counter); } [TestMethod] @@ -164,7 +164,7 @@ public void Test_RelayCommandAttribute_CanExecute_NoParameters_GeneratedProperty model.IncrementCounter_NoParameters_GeneratedPropertyCommand.Execute(null); - Assert.AreEqual(model.Counter, 1); + Assert.AreEqual(1, model.Counter); model.SetGeneratedFlag(false); @@ -172,7 +172,7 @@ public void Test_RelayCommandAttribute_CanExecute_NoParameters_GeneratedProperty model.IncrementCounter_NoParameters_GeneratedPropertyCommand.Execute(null); - Assert.AreEqual(model.Counter, 2); + Assert.AreEqual(2, model.Counter); } [TestMethod] @@ -184,7 +184,7 @@ public void Test_RelayCommandAttribute_CanExecute_WithParameter_Property() model.IncrementCounter_WithParameter_PropertyCommand.Execute(null); - Assert.AreEqual(model.Counter, 1); + Assert.AreEqual(1, model.Counter); model.Flag = false; @@ -192,7 +192,7 @@ public void Test_RelayCommandAttribute_CanExecute_WithParameter_Property() model.IncrementCounter_WithParameter_PropertyCommand.Execute(null); - Assert.AreEqual(model.Counter, 2); + Assert.AreEqual(2, model.Counter); } [TestMethod] @@ -204,7 +204,7 @@ public void Test_RelayCommandAttribute_CanExecute_WithParameter_GeneratedPropert model.IncrementCounter_WithParameter_GeneratedPropertyCommand.Execute(null); - Assert.AreEqual(model.Counter, 1); + Assert.AreEqual(1, model.Counter); model.SetGeneratedFlag(false); @@ -212,7 +212,7 @@ public void Test_RelayCommandAttribute_CanExecute_WithParameter_GeneratedPropert model.IncrementCounter_WithParameter_GeneratedPropertyCommand.Execute(null); - Assert.AreEqual(model.Counter, 2); + Assert.AreEqual(2, model.Counter); } [TestMethod] @@ -224,7 +224,7 @@ public void Test_RelayCommandAttribute_CanExecute_NoParameters_MethodWithNoParam model.IncrementCounter_NoParameters_MethodWithNoParametersCommand.Execute(null); - Assert.AreEqual(model.Counter, 1); + Assert.AreEqual(1, model.Counter); model.Flag = false; @@ -232,7 +232,7 @@ public void Test_RelayCommandAttribute_CanExecute_NoParameters_MethodWithNoParam model.IncrementCounter_WithParameter_PropertyCommand.Execute(null); - Assert.AreEqual(model.Counter, 2); + Assert.AreEqual(2, model.Counter); } [TestMethod] @@ -244,7 +244,7 @@ public void Test_RelayCommandAttribute_CanExecute_WithParameters_MethodWithNoPar model.IncrementCounter_WithParameters_MethodWithNoParametersCommand.Execute(null); - Assert.AreEqual(model.Counter, 1); + Assert.AreEqual(1, model.Counter); model.Flag = false; @@ -252,7 +252,7 @@ public void Test_RelayCommandAttribute_CanExecute_WithParameters_MethodWithNoPar model.IncrementCounter_WithParameters_MethodWithNoParametersCommand.Execute(null); - Assert.AreEqual(model.Counter, 2); + Assert.AreEqual(2, model.Counter); } [TestMethod] @@ -262,13 +262,13 @@ public void Test_RelayCommandAttribute_CanExecute_WithParameters_MethodWithMatch model.IncrementCounter_WithParameters_MethodWithMatchingParameterCommand.Execute(new User { Name = nameof(CanExecuteViewModel) }); - Assert.AreEqual(model.Counter, 1); + Assert.AreEqual(1, model.Counter); Assert.IsFalse(model.IncrementCounter_WithParameters_MethodWithMatchingParameterCommand.CanExecute(new User())); model.IncrementCounter_WithParameters_MethodWithMatchingParameterCommand.Execute(new User()); - Assert.AreEqual(model.Counter, 2); + Assert.AreEqual(2, model.Counter); } [TestMethod] @@ -280,7 +280,7 @@ public async Task Test_RelayCommandAttribute_CanExecute_Async_NoParameters_Prope await model.IncrementCounter_Async_NoParameters_PropertyCommand.ExecuteAsync(null); - Assert.AreEqual(model.Counter, 1); + Assert.AreEqual(1, model.Counter); model.Flag = false; @@ -288,7 +288,7 @@ public async Task Test_RelayCommandAttribute_CanExecute_Async_NoParameters_Prope await model.IncrementCounter_Async_NoParameters_PropertyCommand.ExecuteAsync(null); - Assert.AreEqual(model.Counter, 2); + Assert.AreEqual(2, model.Counter); } [TestMethod] @@ -300,7 +300,7 @@ public async Task Test_RelayCommandAttribute_CanExecute_Async_WithParameter_Prop await model.IncrementCounter_Async_WithParameter_PropertyCommand.ExecuteAsync(null); - Assert.AreEqual(model.Counter, 1); + Assert.AreEqual(1, model.Counter); model.Flag = false; @@ -308,7 +308,7 @@ public async Task Test_RelayCommandAttribute_CanExecute_Async_WithParameter_Prop await model.IncrementCounter_Async_WithParameter_PropertyCommand.ExecuteAsync(null); - Assert.AreEqual(model.Counter, 2); + Assert.AreEqual(2, model.Counter); } [TestMethod] @@ -320,7 +320,7 @@ public async Task Test_RelayCommandAttribute_CanExecute_Async_NoParameters_Metho await model.IncrementCounter_Async_NoParameters_MethodWithNoParametersCommand.ExecuteAsync(null); - Assert.AreEqual(model.Counter, 1); + Assert.AreEqual(1, model.Counter); model.Flag = false; @@ -328,7 +328,7 @@ public async Task Test_RelayCommandAttribute_CanExecute_Async_NoParameters_Metho await model.IncrementCounter_Async_WithParameter_PropertyCommand.ExecuteAsync(null); - Assert.AreEqual(model.Counter, 2); + Assert.AreEqual(2, model.Counter); } [TestMethod] @@ -340,7 +340,7 @@ public async Task Test_RelayCommandAttribute_CanExecute_Async_WithParameters_Met await model.IncrementCounter_Async_WithParameters_MethodWithNoParametersCommand.ExecuteAsync(null); - Assert.AreEqual(model.Counter, 1); + Assert.AreEqual(1, model.Counter); model.Flag = false; @@ -348,7 +348,7 @@ public async Task Test_RelayCommandAttribute_CanExecute_Async_WithParameters_Met await model.IncrementCounter_Async_WithParameters_MethodWithNoParametersCommand.ExecuteAsync(null); - Assert.AreEqual(model.Counter, 2); + Assert.AreEqual(2, model.Counter); } [TestMethod] @@ -358,13 +358,13 @@ public async Task Test_RelayCommandAttribute_CanExecute_Async_WithParameters_Met await model.IncrementCounter_Async_WithParameters_MethodWithMatchingParameterCommand.ExecuteAsync(new User { Name = nameof(CanExecuteViewModel) }); - Assert.AreEqual(model.Counter, 1); + Assert.AreEqual(1, model.Counter); Assert.IsFalse(model.IncrementCounter_Async_WithParameters_MethodWithMatchingParameterCommand.CanExecute(new User())); await model.IncrementCounter_Async_WithParameters_MethodWithMatchingParameterCommand.ExecuteAsync(new User()); - Assert.AreEqual(model.Counter, 2); + Assert.AreEqual(2, model.Counter); } [TestMethod] @@ -575,22 +575,22 @@ public void Test_RelayCommandAttribute_WithExplicitAttributesForFieldAndProperty Assert.IsNotNull(fooField.GetCustomAttribute()); Assert.IsNotNull(fooField.GetCustomAttribute()); - Assert.AreEqual(fooField.GetCustomAttribute()!.Length, 1); + Assert.AreEqual(1, fooField.GetCustomAttribute()!.Length); Assert.IsNotNull(fooField.GetCustomAttribute()); - Assert.AreEqual(fooField.GetCustomAttribute()!.Length, 100); + Assert.AreEqual(100, fooField.GetCustomAttribute()!.Length); PropertyInfo fooProperty = typeof(MyViewModelWithExplicitFieldAndPropertyAttributes).GetProperty("FooCommand")!; Assert.IsNotNull(fooProperty.GetCustomAttribute()); Assert.IsNotNull(fooProperty.GetCustomAttribute()); - Assert.AreEqual(fooProperty.GetCustomAttribute()!.Length, 1); + Assert.AreEqual(1, fooProperty.GetCustomAttribute()!.Length); Assert.IsNotNull(fooProperty.GetCustomAttribute()); - Assert.AreEqual(fooProperty.GetCustomAttribute()!.Length, 100); + Assert.AreEqual(100, fooProperty.GetCustomAttribute()!.Length); PropertyInfo barProperty = typeof(MyViewModelWithExplicitFieldAndPropertyAttributes).GetProperty("BarCommand")!; Assert.IsNotNull(barProperty.GetCustomAttribute()); - Assert.AreEqual(barProperty.GetCustomAttribute()!.Name, "bar"); + Assert.AreEqual("bar", barProperty.GetCustomAttribute()!.Name); Assert.IsNotNull(barProperty.GetCustomAttribute()); PropertyInfo bazProperty = typeof(MyViewModelWithExplicitFieldAndPropertyAttributes).GetProperty("BazCommand")!; @@ -601,21 +601,21 @@ static void ValidateTestAttribute(TestValidationAttribute testAttribute) { Assert.IsNotNull(testAttribute); Assert.IsNull(testAttribute.O); - Assert.AreEqual(testAttribute.T, typeof(MyViewModelWithExplicitFieldAndPropertyAttributes)); - Assert.AreEqual(testAttribute.Flag, true); - Assert.AreEqual(testAttribute.D, 6.28); - CollectionAssert.AreEqual(testAttribute.Names, new[] { "Bob", "Ross" }); + Assert.AreEqual(typeof(MyViewModelWithExplicitFieldAndPropertyAttributes), testAttribute.T); + Assert.AreEqual(true, testAttribute.Flag); + Assert.AreEqual(6.28, testAttribute.D); + CollectionAssert.AreEqual(new[] { "Bob", "Ross" }, testAttribute.Names); object[]? nestedArray = (object[]?)testAttribute.NestedArray; Assert.IsNotNull(nestedArray); - Assert.AreEqual(nestedArray!.Length, 3); - Assert.AreEqual(nestedArray[0], 1); - Assert.AreEqual(nestedArray[1], "Hello"); + Assert.AreEqual(3, nestedArray!.Length); + Assert.AreEqual(1, nestedArray[0]); + Assert.AreEqual("Hello", nestedArray[1]); Assert.IsTrue(nestedArray[2] is int[]); - CollectionAssert.AreEqual((int[])nestedArray[2], new[] { 2, 3, 4 }); + CollectionAssert.AreEqual(new[] { 2, 3, 4 }, (int[])nestedArray[2]); - Assert.AreEqual(testAttribute.Animal, Test_ObservablePropertyAttribute.Animal.Llama); + Assert.AreEqual(Test_ObservablePropertyAttribute.Animal.Llama, testAttribute.Animal); } FieldInfo fooBarField = typeof(MyViewModelWithExplicitFieldAndPropertyAttributes).GetField("fooBarCommand", BindingFlags.Instance | BindingFlags.NonPublic)!; @@ -638,25 +638,25 @@ static void ValidateTestAttribute(TestValidationAttribute testAttribute) Assert.IsNotNull(testAttribute2); Assert.IsNull(testAttribute2.O); - Assert.AreEqual(testAttribute2.T, typeof(MyViewModelWithExplicitFieldAndPropertyAttributes)); - Assert.AreEqual(testAttribute2.Flag, true); - Assert.AreEqual(testAttribute2.D, 6.28); + Assert.AreEqual(typeof(MyViewModelWithExplicitFieldAndPropertyAttributes), testAttribute2.T); + Assert.AreEqual(true, testAttribute2.Flag); + Assert.AreEqual(6.28, testAttribute2.D); Assert.IsNotNull(testAttribute2.Objects); Assert.IsTrue(testAttribute2.Objects is object[]); - Assert.AreEqual(((object[])testAttribute2.Objects).Length, 1); - Assert.AreEqual(((object[])testAttribute2.Objects)[0], "Test"); - CollectionAssert.AreEqual(testAttribute2.Names, new[] { "Bob", "Ross" }); + Assert.AreEqual(1, ((object[])testAttribute2.Objects).Length); + Assert.AreEqual("Test", ((object[])testAttribute2.Objects)[0]); + CollectionAssert.AreEqual(new[] { "Bob", "Ross" }, testAttribute2.Names); object[]? nestedArray2 = (object[]?)testAttribute2.NestedArray; Assert.IsNotNull(nestedArray2); - Assert.AreEqual(nestedArray2!.Length, 4); - Assert.AreEqual(nestedArray2[0], 1); - Assert.AreEqual(nestedArray2[1], "Hello"); - Assert.AreEqual(nestedArray2[2], 42); + Assert.AreEqual(4, nestedArray2!.Length); + Assert.AreEqual(1, nestedArray2[0]); + Assert.AreEqual("Hello", nestedArray2[1]); + Assert.AreEqual(42, nestedArray2[2]); Assert.IsNull(nestedArray2[3]); - Assert.AreEqual(testAttribute2.Animal, (Test_ObservablePropertyAttribute.Animal)67); + Assert.AreEqual((Test_ObservablePropertyAttribute.Animal)67, testAttribute2.Animal); } // See https://github.com/CommunityToolkit/dotnet/issues/632 @@ -674,24 +674,24 @@ public void Test_RelayCommandAttribute_WithPartialCommandMethodDefinitions() Assert.IsNotNull(bazField.GetCustomAttribute()); Assert.IsNotNull(bazField.GetCustomAttribute()); - Assert.AreEqual(bazField.GetCustomAttribute()!.Length, 1); + Assert.AreEqual(1, bazField.GetCustomAttribute()!.Length); PropertyInfo bazProperty = typeof(ModelWithPartialCommandMethods).GetProperty("BazCommand")!; Assert.IsNotNull(bazProperty.GetCustomAttribute()); - Assert.AreEqual(bazProperty.GetCustomAttribute()!.Length, 2); + Assert.AreEqual(2, bazProperty.GetCustomAttribute()!.Length); Assert.IsNotNull(bazProperty.GetCustomAttribute()); FieldInfo fooBarField = typeof(ModelWithPartialCommandMethods).GetField("fooBarCommand", BindingFlags.Instance | BindingFlags.NonPublic)!; Assert.IsNotNull(fooBarField.GetCustomAttribute()); Assert.IsNotNull(fooBarField.GetCustomAttribute()); - Assert.AreEqual(fooBarField.GetCustomAttribute()!.Length, 1); + Assert.AreEqual(1, fooBarField.GetCustomAttribute()!.Length); PropertyInfo fooBarProperty = typeof(ModelWithPartialCommandMethods).GetProperty("FooBarCommand")!; Assert.IsNotNull(fooBarProperty.GetCustomAttribute()); - Assert.AreEqual(fooBarProperty.GetCustomAttribute()!.Length, 2); + Assert.AreEqual(2, fooBarProperty.GetCustomAttribute()!.Length); Assert.IsNotNull(fooBarProperty.GetCustomAttribute()); } diff --git a/tests/CommunityToolkit.Mvvm.UnitTests/Test_RelayCommand{T}.cs b/tests/CommunityToolkit.Mvvm.UnitTests/Test_RelayCommand{T}.cs index e4064bc40..d0c6b0974 100644 --- a/tests/CommunityToolkit.Mvvm.UnitTests/Test_RelayCommand{T}.cs +++ b/tests/CommunityToolkit.Mvvm.UnitTests/Test_RelayCommand{T}.cs @@ -34,16 +34,16 @@ public void Test_RelayCommandOfT_AlwaysEnabled() command.NotifyCanExecuteChanged(); - Assert.AreSame(args.Item1, command); - Assert.AreSame(args.Item2, EventArgs.Empty); + Assert.AreSame(command, args.Item1); + Assert.AreSame(EventArgs.Empty, args.Item2); command.Execute((object)"Hello"); - Assert.AreEqual(text, "Hello"); + Assert.AreEqual("Hello", text); command.Execute(null); - Assert.AreEqual(text, null); + Assert.AreEqual(null, text); } [TestMethod] @@ -64,7 +64,7 @@ public void Test_RelayCommand_WithCanExecuteFunction() command.Execute((object)"Hello"); - Assert.AreEqual(text, "Hello"); + Assert.AreEqual("Hello", text); command.Execute(null);