Index: Core/Common/test/Core.Common.TestUtil.Test/TestHelperTest.cs =================================================================== diff -u -r9ca2ce99f8b1d93fb1edde4e505b5acc5094a256 -r1b1fb73a7519560cd8d2f53e7a7471be26d34ba7 --- Core/Common/test/Core.Common.TestUtil.Test/TestHelperTest.cs (.../TestHelperTest.cs) (revision 9ca2ce99f8b1d93fb1edde4e505b5acc5094a256) +++ Core/Common/test/Core.Common.TestUtil.Test/TestHelperTest.cs (.../TestHelperTest.cs) (revision 1b1fb73a7519560cd8d2f53e7a7471be26d34ba7) @@ -731,6 +731,222 @@ } } + [Test] + public void AssertCollectionAreSame_ExpectedCollectionShorterThanActual_ThrowsException() + { + // Setup + var objectA = new object(); + var objectB = new object(); + var objectC = new object(); + var objectD = new object(); + + // Call + TestDelegate test = () => TestHelper.AssertCollectionAreSame(new[] + { + objectA, + objectB, + objectC + }, new[] + { + objectA, + objectB, + objectC, + objectD + }); + + // Assert + Assert.Throws(test); + } + + [Test] + public void AssertCollectionAreSame_ExpectedCollectionLongerThanActual_ThrowsException() + { + // Setup + var objectA = new object(); + var objectB = new object(); + var objectC = new object(); + var objectD = new object(); + + // Call + TestDelegate test = () => TestHelper.AssertCollectionAreSame(new[] + { + objectA, + objectB, + objectC, + objectD + }, new[] + { + objectA, + objectB, + objectC + }); + + // Assert + Assert.Throws(test); + } + + [Test] + public void AssertCollectionAreSame_CollectionsDifferent_ThrowsException() + { + // Setup + var objectA = new object(); + var objectB = new object(); + var objectC = new object(); + var objectD = new object(); + + // Call + TestDelegate test = () => TestHelper.AssertCollectionAreSame(new[] + { + objectA, + objectB, + objectD + }, new[] + { + objectA, + objectB, + objectC + }); + + // Assert + Assert.Throws(test); + } + + [Test] + public void AssertCollectionAreSame_CollectionsSame_DoesNotThrowException() + { + // Setup + var objectA = new object(); + var objectB = new object(); + var objectC = new object(); + var objectD = new object(); + + // Call + TestDelegate test = () => TestHelper.AssertCollectionAreSame(new[] + { + objectA, + objectB, + objectC, + objectD + }, new[] + { + objectA, + objectB, + objectC, + objectD + }); + + // Assert + Assert.DoesNotThrow(test); + } + + [Test] + public void AssertCollectionAreNotSame_ExpectedCollectionShorterThanActual_ThrowsException() + { + // Setup + var objectA = new object(); + var objectB = new object(); + var objectC = new object(); + var objectD = new object(); + + // Call + TestDelegate test = () => TestHelper.AssertCollectionAreNotSame(new[] + { + objectA, + objectB, + objectC + }, new[] + { + objectA, + objectB, + objectC, + objectD + }); + + // Assert + Assert.Throws(test); + } + + [Test] + public void AssertCollectionAreNotSame_ExpectedCollectionLongerThanActual_ThrowsException() + { + // Setup + var objectA = new object(); + var objectB = new object(); + var objectC = new object(); + var objectD = new object(); + + // Call + TestDelegate test = () => TestHelper.AssertCollectionAreNotSame(new[] + { + objectA, + objectB, + objectC, + objectD + }, new[] + { + objectA, + objectB, + objectC + }); + + // Assert + Assert.Throws(test); + } + + [Test] + public void AssertCollectionAreNotSame_CollectionsDifferent_DoesNotThrowException() + { + // Setup + var objectA = new object(); + var objectB = new object(); + var objectC = new object(); + var objectD = new object(); + + // Call + TestDelegate test = () => TestHelper.AssertCollectionAreNotSame(new[] + { + objectA, + objectB, + objectD + }, new[] + { + objectA, + objectB, + objectC + }); + + // Assert + Assert.Throws(test); + } + + [Test] + public void AssertCollectionAreNotSame_CollectionsSame_ThrowsException() + { + // Setup + var objectA = new object(); + var objectB = new object(); + var objectC = new object(); + var objectD = new object(); + + // Call + TestDelegate test = () => TestHelper.AssertCollectionAreNotSame(new[] + { + objectA, + objectB, + objectC, + objectD + }, new[] + { + objectA, + objectB, + objectC, + objectD + }); + + // Assert + Assert.Throws(test); + } + public class TestEqualSameObject { private readonly int someInt; Index: Core/Common/test/Core.Common.TestUtil/TestHelper.cs =================================================================== diff -u -r9ca2ce99f8b1d93fb1edde4e505b5acc5094a256 -r1b1fb73a7519560cd8d2f53e7a7471be26d34ba7 --- Core/Common/test/Core.Common.TestUtil/TestHelper.cs (.../TestHelper.cs) (revision 9ca2ce99f8b1d93fb1edde4e505b5acc5094a256) +++ Core/Common/test/Core.Common.TestUtil/TestHelper.cs (.../TestHelper.cs) (revision 1b1fb73a7519560cd8d2f53e7a7471be26d34ba7) @@ -391,11 +391,17 @@ } /// - /// Determines whether to objects are copies of eachother by verifying that they are + /// Determines whether objects are copies of eachother by verifying that they are /// equal, but not the same. /// /// The object which should be equal, but not same as . /// The object which should be equal, but not same as . + /// Thrown when either: + /// + /// is not equal to + /// is the same as + /// + /// public static void AssertAreEqualButNotSame(object objectA, object objectB) { Assert.AreEqual(objectA, objectB, "Objects should be equal."); @@ -406,6 +412,60 @@ } } + /// + /// Asserts that all elements in the collections are the same. + /// + /// The expected collection of elements. + /// The actual collection of elements. + /// Thrown when either: + /// + /// has more or less elements than + /// contains an element at a position that is not the same + /// element in at that position. + /// + /// + public static void AssertCollectionAreSame(System.Collections.IEnumerable expected, System.Collections.IEnumerable actual) + { + var expectedEnumerator = expected.GetEnumerator(); + var actualEnumerator = actual.GetEnumerator(); + + while (expectedEnumerator.MoveNext()) + { + Assert.IsTrue(actualEnumerator.MoveNext()); + { + Assert.AreSame(expectedEnumerator.Current, actualEnumerator.Current); + } + } + Assert.IsFalse(actualEnumerator.MoveNext()); + } + + /// + /// Asserts that all elements in the collections are not the same. + /// + /// The expected collection of elements. + /// The actual collection of elements. + /// Thrown when either: + /// + /// has more or less elements than + /// contains an element at a position that is the same + /// element in at that position. + /// + /// + public static void AssertCollectionAreNotSame(System.Collections.IEnumerable expected, System.Collections.IEnumerable actual) + { + var expectedEnumerator = expected.GetEnumerator(); + var actualEnumerator = actual.GetEnumerator(); + + while (expectedEnumerator.MoveNext()) + { + Assert.IsTrue(actualEnumerator.MoveNext()); + { + Assert.AreNotSame(expectedEnumerator.Current, actualEnumerator.Current); + } + } + Assert.IsFalse(actualEnumerator.MoveNext()); + } + private static void AssertIsFasterThan(float maxMilliseconds, string message, Action action, bool rankHddAccess) { var stopwatch = new Stopwatch(); Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/DikeProfiles/DikeProfileTest.cs =================================================================== diff -u -r9ca2ce99f8b1d93fb1edde4e505b5acc5094a256 -r1b1fb73a7519560cd8d2f53e7a7471be26d34ba7 --- Ringtoets/Common/test/Ringtoets.Common.Data.Test/DikeProfiles/DikeProfileTest.cs (.../DikeProfileTest.cs) (revision 9ca2ce99f8b1d93fb1edde4e505b5acc5094a256) +++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/DikeProfiles/DikeProfileTest.cs (.../DikeProfileTest.cs) (revision 1b1fb73a7519560cd8d2f53e7a7471be26d34ba7) @@ -782,15 +782,9 @@ // Assert TestHelper.AssertAreEqualButNotSame(expectedWorldReferencePoint, dikeProfileToUpdate.WorldReferencePoint); CollectionAssert.AreEqual(expectedForeshoreGeometry, dikeProfileToUpdate.ForeshoreGeometry); - for (var i = 0; i < expectedForeshoreGeometry.Length; i++) - { - Assert.AreNotSame(expectedForeshoreGeometry[i], dikeProfileToUpdate.ForeshoreGeometry.ElementAt(i)); - } + TestHelper.AssertCollectionAreNotSame(expectedForeshoreGeometry, dikeProfileToUpdate.ForeshoreGeometry); CollectionAssert.AreEqual(expectedDikeGeometry, dikeProfileToUpdate.DikeGeometry); - for (var i = 0; i < expectedDikeGeometry.Length; i++) - { - Assert.AreNotSame(expectedDikeGeometry[i], dikeProfileToUpdate.DikeGeometry.ElementAt(i)); - } + TestHelper.AssertCollectionAreNotSame(expectedDikeGeometry, dikeProfileToUpdate.DikeGeometry); TestHelper.AssertAreEqualButNotSame(expectedBreakWater, dikeProfileToUpdate.BreakWater); Assert.AreEqual(expectedId, dikeProfileToUpdate.Id); Index: Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/RingtoetsPipingSurfaceLineTest.cs =================================================================== diff -u -r9ca2ce99f8b1d93fb1edde4e505b5acc5094a256 -r1b1fb73a7519560cd8d2f53e7a7471be26d34ba7 --- Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/RingtoetsPipingSurfaceLineTest.cs (.../RingtoetsPipingSurfaceLineTest.cs) (revision 9ca2ce99f8b1d93fb1edde4e505b5acc5094a256) +++ Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/RingtoetsPipingSurfaceLineTest.cs (.../RingtoetsPipingSurfaceLineTest.cs) (revision 1b1fb73a7519560cd8d2f53e7a7471be26d34ba7) @@ -1143,10 +1143,7 @@ TestHelper.AssertAreEqualButNotSame(expectedSurfaceLine.ReferenceLineIntersectionWorldPoint, actualSurfaceLine.ReferenceLineIntersectionWorldPoint); CollectionAssert.AreEqual(expectedSurfaceLine.Points, actualSurfaceLine.Points); - for (var i = 0; i < expectedSurfaceLine.Points.Length; i++) - { - Assert.AreNotSame(expectedSurfaceLine.Points[i], actualSurfaceLine.Points[i]); - } + TestHelper.AssertCollectionAreNotSame(expectedSurfaceLine.Points, actualSurfaceLine.Points); TestHelper.AssertAreEqualButNotSame(expectedSurfaceLine.BottomDitchDikeSide, actualSurfaceLine.BottomDitchDikeSide); TestHelper.AssertAreEqualButNotSame(expectedSurfaceLine.BottomDitchPolderSide, actualSurfaceLine.BottomDitchPolderSide); TestHelper.AssertAreEqualButNotSame(expectedSurfaceLine.DikeToeAtPolder, actualSurfaceLine.DikeToeAtPolder);