Index: Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/RingtoetsPipingSurfaceLineCollectionTest.cs =================================================================== diff -u -r81fa8a9bf3bd503cbd280e88b8f6037a840cff12 -r33e8882a46b193286ebf3eeec73e81b7c5921489 --- Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/RingtoetsPipingSurfaceLineCollectionTest.cs (.../RingtoetsPipingSurfaceLineCollectionTest.cs) (revision 81fa8a9bf3bd503cbd280e88b8f6037a840cff12) +++ Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/RingtoetsPipingSurfaceLineCollectionTest.cs (.../RingtoetsPipingSurfaceLineCollectionTest.cs) (revision 33e8882a46b193286ebf3eeec73e81b7c5921489) @@ -20,114 +20,125 @@ // All rights reserved. using System; +using System.Collections.Generic; +using System.Linq; using Core.Common.Base; using Core.Common.TestUtil; using NUnit.Framework; +using Ringtoets.Common.Data.TestUtil; using Ringtoets.Piping.Primitives; namespace Ringtoets.Piping.Data.Test { [TestFixture] - public class RingtoetsPipingSurfaceLineCollectionTest + public class RingtoetsPipingSurfaceLineCollectionTest : + CustomObservableUniqueItemCollectionWithSourcePathTestFixtureBase< + ObservableUniqueItemCollectionWithSourcePath, RingtoetsPipingSurfaceLine> { [Test] - public void DefaultConstructor_DefaultValues() + public void AddRange_MultipleSurfaceLinesWithSameNames_ThrowsArgumentException() { - // Call - var collection = new RingtoetsPipingSurfaceLineCollection(); - - // Assert - Assert.IsInstanceOf>(collection); - } - - [Test] - public void AddRange_SurfaceLinesWithDifferentNames_AddsSurfaceLines() - { // Setup + const string duplicateNameOne = "Duplicate name it is"; + const string duplicateNameTwo = "Duplicate name again"; var surfaceLinesToAdd = new[] { new RingtoetsPipingSurfaceLine { - Name = "Name A" + Name = duplicateNameOne }, new RingtoetsPipingSurfaceLine { - Name = "Name B" + Name = duplicateNameOne + }, + new RingtoetsPipingSurfaceLine + { + Name = duplicateNameTwo + }, + new RingtoetsPipingSurfaceLine + { + Name = duplicateNameTwo } }; var collection = new RingtoetsPipingSurfaceLineCollection(); - const string expectedFilePath = "other/path"; // Call - collection.AddRange(surfaceLinesToAdd, expectedFilePath); + TestDelegate call = () => collection.AddRange(surfaceLinesToAdd, "path"); // Assert - Assert.AreEqual(expectedFilePath, collection.SourcePath); - CollectionAssert.AreEqual(surfaceLinesToAdd, collection); + string message = $"Profielschematisaties moeten een unieke naam hebben. Gevonden dubbele elementen: {duplicateNameOne}, " + + $"{duplicateNameTwo}."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, message); } - [Test] - public void AddRange_SurfaceLinesWithSameNames_ThrowsArgumentException() + protected override ObservableUniqueItemCollectionWithSourcePath CreateCollection() { - // Setup - const string duplicateName = "Duplicate name it is"; - var surfaceLinesToAdd = new[] + return new RingtoetsPipingSurfaceLineCollection(); + } + + protected override IEnumerable UniqueElements() + { + yield return new RingtoetsPipingSurfaceLine { - new RingtoetsPipingSurfaceLine - { - Name = duplicateName - }, - new RingtoetsPipingSurfaceLine - { - Name = duplicateName - } + Name = "Name A" }; + yield return new RingtoetsPipingSurfaceLine + { + Name = "Name B" + }; + } - var collection = new RingtoetsPipingSurfaceLineCollection(); + protected override IEnumerable SingleNonUniqueElements() + { + const string duplicateName = "Duplicate name it is"; - // Call - TestDelegate call = () => collection.AddRange(surfaceLinesToAdd, "path"); + yield return new RingtoetsPipingSurfaceLine + { + Name = duplicateName + }; + yield return new RingtoetsPipingSurfaceLine + { + Name = duplicateName + }; + } - // Assert - string message = $"Profielschematisaties moeten een unieke naam hebben. Gevonden dubbele elementen: {duplicateName}."; - TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, message); + protected override void AssertSingleNonUniqueElements(ArgumentException exception, IEnumerable itemsToAdd) + { + string duplicateName = itemsToAdd.First().Name; + Assert.AreEqual($"Profielschematisaties moeten een unieke naam hebben. Gevonden dubbele elementen: {duplicateName}.", + exception.Message); } - [Test] - public void AddRange_MultipleSurfaceLinesWithSameNames_ThrowsArgumentException() + protected override IEnumerable MultipleNonUniqueElements() { - // Setup const string duplicateNameOne = "Duplicate name it is"; const string duplicateNameTwo = "Duplicate name again"; - var surfaceLinesToAdd = new[] - { + yield return new RingtoetsPipingSurfaceLine { Name = duplicateNameOne - }, - new RingtoetsPipingSurfaceLine - { - Name = duplicateNameOne - }, - new RingtoetsPipingSurfaceLine - { - Name = duplicateNameTwo - }, - new RingtoetsPipingSurfaceLine - { - Name = duplicateNameTwo - } + }; + yield return new RingtoetsPipingSurfaceLine + { + Name = duplicateNameOne }; + yield return new RingtoetsPipingSurfaceLine + { + Name = duplicateNameTwo + }; + yield return new RingtoetsPipingSurfaceLine + { + Name = duplicateNameTwo + }; + } - var collection = new RingtoetsPipingSurfaceLineCollection(); - - // Call - TestDelegate call = () => collection.AddRange(surfaceLinesToAdd, "path"); - - // Assert - string message = $"Profielschematisaties moeten een unieke naam hebben. Gevonden dubbele elementen: {duplicateNameOne}, {duplicateNameTwo}."; - TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, message); + protected override void AssertMultipleNonUniqueElements(ArgumentException exception, IEnumerable itemsToAdd) + { + string duplicateNameOne = itemsToAdd.First().Name; + string duplicateNameTwo = itemsToAdd.First(i => i.Name != duplicateNameOne).Name; + Assert.AreEqual("Profielschematisaties moeten een unieke naam hebben. Gevonden dubbele elementen: " + + $"{duplicateNameOne}, {duplicateNameTwo}.", exception.Message); } } } \ No newline at end of file