Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/DikeProfiles/DikeProfileCollectionTest.cs =================================================================== diff -u -rb3b6c13cf736c134476b3db34281332d01ca86b1 -ra588b2fbca3ea7073fa3aa30bde0bd59393ff994 --- Ringtoets/Common/test/Ringtoets.Common.Data.Test/DikeProfiles/DikeProfileCollectionTest.cs (.../DikeProfileCollectionTest.cs) (revision b3b6c13cf736c134476b3db34281332d01ca86b1) +++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/DikeProfiles/DikeProfileCollectionTest.cs (.../DikeProfileCollectionTest.cs) (revision a588b2fbca3ea7073fa3aa30bde0bd59393ff994) @@ -20,91 +20,62 @@ // 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.DikeProfiles; using Ringtoets.Common.Data.TestUtil; namespace Ringtoets.Common.Data.Test.DikeProfiles { [TestFixture] - public class DikeProfileCollectionTest + public class DikeProfileCollectionTest : + CustomObservableUniqueItemCollectionWithSourcePathTestFixtureBase< + ObservableUniqueItemCollectionWithSourcePath, DikeProfile> { - [Test] - public void DefaultConstructor_ReturnsCollectionWithPath() + protected override ObservableUniqueItemCollectionWithSourcePath CreateCollection() { - // Call - var collection = new DikeProfileCollection(); - - // Assert - Assert.IsInstanceOf>(collection); + return new DikeProfileCollection(); } - [Test] - public void AddRange_DikeProfilesWithDifferentIds_AddsDikeProfiles() + protected override IEnumerable UniqueElements() { - // Setup - var dikeProfilesToAdd = new[] - { - new TestDikeProfile(string.Empty, "Dike ID A"), - new TestDikeProfile(string.Empty, "Dike ID B") - }; - - var collection = new DikeProfileCollection(); - const string expectedFilePath = "other/path"; - - // Call - collection.AddRange(dikeProfilesToAdd, expectedFilePath); - - // Assert - Assert.AreEqual(expectedFilePath, collection.SourcePath); - CollectionAssert.AreEqual(dikeProfilesToAdd, collection); + yield return new TestDikeProfile(string.Empty, "Dike ID A"); + yield return new TestDikeProfile(string.Empty, "Dike ID B"); } - [Test] - public void AddRange_WithDikeProfilesWithEqualIds_ThrowsArgumentException() + protected override IEnumerable SingleNonUniqueElements() { - // Setup - var collection = new DikeProfileCollection(); const string someId = "Dike profile"; const string name = "Standard Dike Profile Name"; - var modelsToAdd = new[] - { - new TestDikeProfile(name, someId), - new TestDikeProfile(name, someId) - }; + yield return new TestDikeProfile(name, someId); + yield return new TestDikeProfile(name, someId); + } - // Call - TestDelegate call = () => collection.AddRange(modelsToAdd, "valid/file/path"); - - // Assert - string message = $"Dijkprofielen moeten een unieke id hebben. Gevonden dubbele elementen: {someId}."; - TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, message); + protected override void AssertSingleNonUniqueElements(ArgumentException exception, IEnumerable itemsToAdd) + { + string someId = itemsToAdd.First().Id; + Assert.AreEqual($"Dijkprofielen moeten een unieke id hebben. Gevonden dubbele elementen: {someId}.", exception.Message); } - [Test] - public void AddRange_WithMultipleDikeProfilesWithEqualIds_ThrowsArgumentException() + protected override IEnumerable MultipleNonUniqueElements() { - // Setup - var collection = new DikeProfileCollection(); const string someId = "Dike profile"; const string someotherId = "Other dike profile"; const string name = "Some Dike profile Name"; - var modelsToAdd = new[] - { - new TestDikeProfile(name, someId), - new TestDikeProfile(name, someId), - new TestDikeProfile(name, someotherId), - new TestDikeProfile(name, someotherId) - }; - // Call - TestDelegate call = () => collection.AddRange(modelsToAdd, "valid/file/path"); + yield return new TestDikeProfile(name, someId); + yield return new TestDikeProfile(name, someId); + yield return new TestDikeProfile(name, someotherId); + yield return new TestDikeProfile(name, someotherId); + } - // Assert - string message = $"Dijkprofielen moeten een unieke id hebben. Gevonden dubbele elementen: {someId}, {someotherId}."; - TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, message); + protected override void AssertMultipleNonUniqueElements(ArgumentException exception, IEnumerable itemsToAdd) + { + string someId = itemsToAdd.First().Id; + string someotherId = itemsToAdd.First(i => i.Id != someId).Id; + Assert.AreEqual($"Dijkprofielen moeten een unieke id hebben. Gevonden dubbele elementen: {someId}, {someotherId}.", exception.Message); } } } \ No newline at end of file