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 Index: Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/StochasticSoilModelCollectionTest.cs =================================================================== diff -u -r81fa8a9bf3bd503cbd280e88b8f6037a840cff12 -r33e8882a46b193286ebf3eeec73e81b7c5921489 --- Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/StochasticSoilModelCollectionTest.cs (.../StochasticSoilModelCollectionTest.cs) (revision 81fa8a9bf3bd503cbd280e88b8f6037a840cff12) +++ Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/StochasticSoilModelCollectionTest.cs (.../StochasticSoilModelCollectionTest.cs) (revision 33e8882a46b193286ebf3eeec73e81b7c5921489) @@ -20,88 +20,61 @@ // 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; namespace Ringtoets.Piping.Data.Test { [TestFixture] - public class StochasticSoilModelCollectionTest + public class StochasticSoilModelCollectionTest : + CustomObservableUniqueItemCollectionWithSourcePathTestFixtureBase< + ObservableUniqueItemCollectionWithSourcePath, StochasticSoilModel> { - [Test] - public void DefaultConstructor_ReturnsCollectionWithPath() + protected override ObservableUniqueItemCollectionWithSourcePath CreateCollection() { - // Call - var collection = new StochasticSoilModelCollection(); - - // Assert - Assert.IsInstanceOf>(collection); + return new StochasticSoilModelCollection(); } - [Test] - public void AddRange_StochasticSoilModelsWithDifferentNames_AddsSoilModels() + protected override IEnumerable UniqueElements() { - // Setup - var stochasticSoilModelsToAdd = new[] - { - new StochasticSoilModel(5, "Model A", "segmentA"), - new StochasticSoilModel(6, "Model B", "segmentA") - }; - - var collection = new StochasticSoilModelCollection(); - const string expectedFilePath = "other/path"; - - // Call - collection.AddRange(stochasticSoilModelsToAdd, expectedFilePath); - - // Assert - Assert.AreEqual(expectedFilePath, collection.SourcePath); - CollectionAssert.AreEqual(stochasticSoilModelsToAdd, collection); + yield return new StochasticSoilModel(5, "Model A", "segmentA"); + yield return new StochasticSoilModel(6, "Model B", "segmentA"); } - [Test] - public void AddRange_WithStochasticSoilModelsWithEqualNames_ThrowsArgumentException() + protected override IEnumerable SingleNonUniqueElements() { - // Setup - var collection = new StochasticSoilModelCollection(); const string someName = "Soil model"; - var modelsToAdd = new[] - { - new StochasticSoilModel(5, someName, "segmentA"), - new StochasticSoilModel(6, someName, "segmentB") - }; - - // Call - TestDelegate call = () => collection.AddRange(modelsToAdd, "valid/file/path"); - - // Assert - string message = $"Stochastische ondergrondmodellen moeten een unieke naam hebben. Gevonden dubbele elementen: {someName}."; - TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, message); + yield return new StochasticSoilModel(5, someName, "segmentA"); + yield return new StochasticSoilModel(6, someName, "segmentB"); } - [Test] - public void AddRange_WithMultipleStochasticSoilModelsWithEqualNames_ThrowsArgumentException() + protected override IEnumerable MultipleNonUniqueElements() { - // Setup - var collection = new StochasticSoilModelCollection(); const string someName = "Soil model"; const string someOtherName = "Other soil model"; - var modelsToAdd = new[] - { - new StochasticSoilModel(5, someName, "segmentA"), - new StochasticSoilModel(6, someName, "segmentB"), - new StochasticSoilModel(7, someOtherName, "segmentC"), - new StochasticSoilModel(8, someOtherName, "segmentD"), - new StochasticSoilModel(9, someOtherName, "segmentE") - }; + yield return new StochasticSoilModel(5, someName, "segmentA"); + yield return new StochasticSoilModel(6, someName, "segmentB"); + yield return new StochasticSoilModel(7, someOtherName, "segmentC"); + yield return new StochasticSoilModel(8, someOtherName, "segmentD"); + yield return new StochasticSoilModel(9, someOtherName, "segmentE"); + } - // Call - TestDelegate call = () => collection.AddRange(modelsToAdd, "valid/file/path"); + protected override void AssertSingleNonUniqueElements(ArgumentException exception, IEnumerable itemsToAdd) + { + string someName = itemsToAdd.First().Name; + Assert.AreEqual("Stochastische ondergrondmodellen moeten een unieke naam hebben. " + + $"Gevonden dubbele elementen: {someName}.", exception.Message); + } - // Assert - string message = $"Stochastische ondergrondmodellen moeten een unieke naam hebben. Gevonden dubbele elementen: {someName}, {someOtherName}."; - TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, message); + protected override void AssertMultipleNonUniqueElements(ArgumentException exception, IEnumerable itemsToAdd) + { + string someName = itemsToAdd.First().Name; + string someOtherName = itemsToAdd.First(i => i.Name != someName).Name; + Assert.AreEqual("Stochastische ondergrondmodellen moeten een unieke naam hebben. " + + $"Gevonden dubbele elementen: {someName}, {someOtherName}.", exception.Message); } } } \ No newline at end of file