Index: Application/Ringtoets/src/Application.Ringtoets.Migration.Core/Resources/DatabaseStructure17.1.sql =================================================================== diff -u -rfe88135b797eda12b8e4d9b829036d2d7a52b10f -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Application/Ringtoets/src/Application.Ringtoets.Migration.Core/Resources/DatabaseStructure17.1.sql (.../DatabaseStructure17.1.sql) (revision fe88135b797eda12b8e4d9b829036d2d7a52b10f) +++ Application/Ringtoets/src/Application.Ringtoets.Migration.Core/Resources/DatabaseStructure17.1.sql (.../DatabaseStructure17.1.sql) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -1,6 +1,6 @@ /* ---------------------------------------------------- */ /* Generated by Enterprise Architect Version 12.0 */ -/* Created On : 10-Apr-2017 13:58:22 */ +/* Created On : 11-Apr-2017 10:44:39 */ /* DBMS : SQLite */ /* ---------------------------------------------------- */ @@ -464,6 +464,7 @@ 'GrassCoverErosionInwardsFailureMechanismMetaEntityId' INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, 'FailureMechanismEntityId' INTEGER NOT NULL, 'N' INT (4) NOT NULL, + 'DikeProfileCollectionSourcePath' TEXT, CONSTRAINT 'FK_GrassCoverErosionInwardsFailureMechanismMetaEntity_FailureMechanismEntity' FOREIGN KEY ('FailureMechanismEntityId') REFERENCES 'FailureMechanismEntity' ('FailureMechanismEntityId') ON DELETE Cascade ON UPDATE Cascade ) ; @@ -841,7 +842,8 @@ 'Y' REAL, 'X0' REAL, 'Order' INT (4) NOT NULL, - CONSTRAINT 'FK_DikeProfileEntity_FailureMechanismEntity' FOREIGN KEY ('FailureMechanismEntityId') REFERENCES 'FailureMechanismEntity' ('FailureMechanismEntityId') ON DELETE Cascade ON UPDATE Cascade + CONSTRAINT 'FK_DikeProfileEntity_FailureMechanismEntity' FOREIGN KEY ('FailureMechanismEntityId') REFERENCES 'FailureMechanismEntity' ('FailureMechanismEntityId') ON DELETE Cascade ON UPDATE Cascade, + CONSTRAINT 'UQ_DikeProfileEntity_IdFailureMechanismEntityId' UNIQUE ('Id','FailureMechanismEntityId') ) ; Index: Application/Ringtoets/src/Application.Ringtoets.Migration.Core/Resources/Migration_5_17.1.sql =================================================================== diff -u -rfe88135b797eda12b8e4d9b829036d2d7a52b10f -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Application/Ringtoets/src/Application.Ringtoets.Migration.Core/Resources/Migration_5_17.1.sql (.../Migration_5_17.1.sql) (revision fe88135b797eda12b8e4d9b829036d2d7a52b10f) +++ Application/Ringtoets/src/Application.Ringtoets.Migration.Core/Resources/Migration_5_17.1.sql (.../Migration_5_17.1.sql) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -33,8 +33,8 @@ SELECT [DikeProfileEntityId], [FailureMechanismEntityId], - [Name], - [Name], + CASE WHEN Suffix THEN [Name] || '(' || Suffix || ')' ELSE [Name] END as [Name], + CASE WHEN Suffix THEN [Name] || '(' || Suffix || ')' ELSE [Name] END as [Name], [Orientation], [BreakWaterType], [BreakWaterHeight], @@ -44,8 +44,13 @@ [X], [Y], [X0], - [Order] - FROM [SOURCEPROJECT].DikeProfileEntity; + [Order] + FROM (SELECT *, (SELECT count(*) + FROM [SOURCEPROJECT].DikeProfileEntity + WHERE DP.DikeProfileEntityId > DikeProfileEntityId + AND DP.Name IS Name + AND DP.FailuremechanismEntityId = FailuremechanismEntityId) as Suffix + FROM [SOURCEPROJECT].DikeProfileEntity DP); INSERT INTO DuneErosionSectionResultEntity SELECT * FROM [SOURCEPROJECT].DuneErosionSectionResultEntity; INSERT INTO FailureMechanismEntity SELECT * FROM [SOURCEPROJECT].FailureMechanismEntity; INSERT INTO FailureMechanismSectionEntity SELECT * FROM [SOURCEPROJECT].FailureMechanismSectionEntity; @@ -114,7 +119,17 @@ 1 FROM [SOURCEPROJECT].GrassCoverErosionInwardsCalculationEntity; INSERT INTO GrassCoverErosionInwardsDikeHeightOutputEntity SELECT * FROM [SOURCEPROJECT].GrassCoverErosionInwardsDikeHeightOutputEntity; -INSERT INTO GrassCoverErosionInwardsFailureMechanismMetaEntity SELECT * FROM [SOURCEPROJECT].GrassCoverErosionInwardsFailureMechanismMetaEntity; +INSERT INTO GrassCoverErosionInwardsFailureMechanismMetaEntity ( + [GrassCoverErosionInwardsFailureMechanismMetaEntityId], + [FailureMechanismEntityId], + [N], + [DikeProfileCollectionSourcePath]) +SELECT + [GrassCoverErosionInwardsFailureMechanismMetaEntityId], + [FailureMechanismEntityId], + [N], + "Onbekend" + FROM [SOURCEPROJECT].GrassCoverErosionInwardsFailureMechanismMetaEntity; INSERT INTO GrassCoverErosionInwardsOutputEntity SELECT * FROM [SOURCEPROJECT].GrassCoverErosionInwardsOutputEntity; INSERT INTO GrassCoverErosionInwardsSectionResultEntity SELECT * FROM [SOURCEPROJECT].GrassCoverErosionInwardsSectionResultEntity; INSERT INTO GrassCoverErosionOutwardsFailureMechanismMetaEntity SELECT * FROM [SOURCEPROJECT].GrassCoverErosionOutwardsFailureMechanismMetaEntity; Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj =================================================================== diff -u -reec680fe322aea5d1ecf8fdf1f14a273afdf6c53 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj (.../Application.Ringtoets.Storage.csproj) (revision eec680fe322aea5d1ecf8fdf1f14a273afdf6c53) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj (.../Application.Ringtoets.Storage.csproj) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -346,7 +346,6 @@ - Fisheye: Tag 56ac4eb28f5fcc5b20117474e9e4030399d6806a refers to a dead (removed) revision in file `Application/Ringtoets/src/Application.Ringtoets.Storage/Create/GrassCoverErosionInwards/GeneralGrassCoverErosionInwardsInputCreateExtensions.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Create/GrassCoverErosionInwards/GrassCoverErosionInwardsFailureMechanismCreateExtensions.cs =================================================================== diff -u -r0fbb881c5c82f540f01772234b3c1faadfab07f9 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Application/Ringtoets/src/Application.Ringtoets.Storage/Create/GrassCoverErosionInwards/GrassCoverErosionInwardsFailureMechanismCreateExtensions.cs (.../GrassCoverErosionInwardsFailureMechanismCreateExtensions.cs) (revision 0fbb881c5c82f540f01772234b3c1faadfab07f9) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Create/GrassCoverErosionInwards/GrassCoverErosionInwardsFailureMechanismCreateExtensions.cs (.../GrassCoverErosionInwardsFailureMechanismCreateExtensions.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -52,7 +52,12 @@ private static void AddEntitiesForGeneralInput(GrassCoverErosionInwardsFailureMechanism mechanism, FailureMechanismEntity entity) { - entity.GrassCoverErosionInwardsFailureMechanismMetaEntities.Add(mechanism.GeneralInput.Create()); + var metaEntity = new GrassCoverErosionInwardsFailureMechanismMetaEntity + { + N = mechanism.GeneralInput.N, + DikeProfileCollectionSourcePath = mechanism.DikeProfiles.SourcePath + }; + entity.GrassCoverErosionInwardsFailureMechanismMetaEntities.Add(metaEntity); } private static void AddEntitiesForDikeProfiles(GrassCoverErosionInwardsFailureMechanism mechanism, PersistenceRegistry registry, FailureMechanismEntity entity) Index: Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/GrassCoverErosionInwardsFailureMechanismMetaEntity.cs =================================================================== diff -u -r5e44a4eb7c69ccaca763dce7cd7735e33a1f3c85 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/GrassCoverErosionInwardsFailureMechanismMetaEntity.cs (.../GrassCoverErosionInwardsFailureMechanismMetaEntity.cs) (revision 5e44a4eb7c69ccaca763dce7cd7735e33a1f3c85) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/GrassCoverErosionInwardsFailureMechanismMetaEntity.cs (.../GrassCoverErosionInwardsFailureMechanismMetaEntity.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -35,6 +35,7 @@ public long GrassCoverErosionInwardsFailureMechanismMetaEntityId { get; set; } public long FailureMechanismEntityId { get; set; } public int N { get; set; } + public string DikeProfileCollectionSourcePath { get; set; } public virtual FailureMechanismEntity FailureMechanismEntity { get; set; } } Index: Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/RingtoetsEntities.Designer.cs =================================================================== diff -u -r5e44a4eb7c69ccaca763dce7cd7735e33a1f3c85 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/RingtoetsEntities.Designer.cs (.../RingtoetsEntities.Designer.cs) (revision 5e44a4eb7c69ccaca763dce7cd7735e33a1f3c85) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/RingtoetsEntities.Designer.cs (.../RingtoetsEntities.Designer.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -1,25 +1,4 @@ -// Copyright (C) Stichting Deltares 2016. All rights reserved. -// -// This file is part of Ringtoets. -// -// Ringtoets is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . -// -// All names, logos, and references to "Deltares" are registered trademarks of -// Stichting Deltares and remain full property of Stichting Deltares at all times. -// All rights reserved. - -// T4 code generation is enabled for model 'D:\repos\WettelijkToetsInstrumentarium\Application\Ringtoets\src\Application.Ringtoets.Storage\DbContext\RingtoetsEntities.edmx'. +// T4 code generation is enabled for model 'D:\Checkout\Application\Ringtoets\src\Application.Ringtoets.Storage\DbContext\RingtoetsEntities.edmx'. // To enable legacy code generation, change the value of the 'Code Generation Strategy' designer // property to 'Legacy ObjectContext'. This property is available in the Properties Window when the model // is open in the designer. Index: Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/RingtoetsEntities.edmx =================================================================== diff -u -rfe88135b797eda12b8e4d9b829036d2d7a52b10f -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/RingtoetsEntities.edmx (.../RingtoetsEntities.edmx) (revision fe88135b797eda12b8e4d9b829036d2d7a52b10f) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/RingtoetsEntities.edmx (.../RingtoetsEntities.edmx) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -4,7 +4,7 @@ - + @@ -324,6 +324,7 @@ + @@ -3460,6 +3461,7 @@ + @@ -5742,6 +5744,7 @@ + Index: Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/RingtoetsEntities.edmx.diagram =================================================================== diff -u -rfe88135b797eda12b8e4d9b829036d2d7a52b10f -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/RingtoetsEntities.edmx.diagram (.../RingtoetsEntities.edmx.diagram) (revision fe88135b797eda12b8e4d9b829036d2d7a52b10f) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/RingtoetsEntities.edmx.diagram (.../RingtoetsEntities.edmx.diagram) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -5,75 +5,75 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + + Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Read/FailureMechanismEntityReadExtensions.cs =================================================================== diff -u -r0fbb881c5c82f540f01772234b3c1faadfab07f9 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Application/Ringtoets/src/Application.Ringtoets.Storage/Read/FailureMechanismEntityReadExtensions.cs (.../FailureMechanismEntityReadExtensions.cs) (revision 0fbb881c5c82f540f01772234b3c1faadfab07f9) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Read/FailureMechanismEntityReadExtensions.cs (.../FailureMechanismEntityReadExtensions.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -192,11 +192,17 @@ entity.GrassCoverErosionInwardsFailureMechanismMetaEntities.Single().Read(input); } - private static void ReadDikeProfiles(this FailureMechanismEntity entity, ICollection dikeProfiles, ReadConversionCollector collector) + private static void ReadDikeProfiles(this FailureMechanismEntity entity, DikeProfileCollection dikeProfiles, ReadConversionCollector collector) { - foreach (DikeProfileEntity dikeProfileEntity in entity.DikeProfileEntities) + if (entity.DikeProfileEntities.Any()) { - dikeProfiles.Add(dikeProfileEntity.Read(collector)); + GrassCoverErosionInwardsFailureMechanismMetaEntity metaEntity = + entity.GrassCoverErosionInwardsFailureMechanismMetaEntities.Single(); + string sourcePath = metaEntity.DikeProfileCollectionSourcePath; + + dikeProfiles.AddRange(entity.DikeProfileEntities + .OrderBy(dp => dp.Order) + .Select(dp => dp.Read(collector)), sourcePath); } } Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj =================================================================== diff -u -reec680fe322aea5d1ecf8fdf1f14a273afdf6c53 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision eec680fe322aea5d1ecf8fdf1f14a273afdf6c53) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -142,7 +142,6 @@ - Fisheye: Tag 56ac4eb28f5fcc5b20117474e9e4030399d6806a refers to a dead (removed) revision in file `Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/GrassCoverErosionInwards/GeneralGrassCoverErosionInwardsInputCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/GrassCoverErosionInwards/GrassCoverErosionInwardsFailureMechanismCreateExtensionsTest.cs =================================================================== diff -u -r5e44a4eb7c69ccaca763dce7cd7735e33a1f3c85 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/GrassCoverErosionInwards/GrassCoverErosionInwardsFailureMechanismCreateExtensionsTest.cs (.../GrassCoverErosionInwardsFailureMechanismCreateExtensionsTest.cs) (revision 5e44a4eb7c69ccaca763dce7cd7735e33a1f3c85) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/GrassCoverErosionInwards/GrassCoverErosionInwardsFailureMechanismCreateExtensionsTest.cs (.../GrassCoverErosionInwardsFailureMechanismCreateExtensionsTest.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -78,7 +78,7 @@ var registry = new PersistenceRegistry(); // Call - var entity = failureMechanism.Create(registry); + FailureMechanismEntity entity = failureMechanism.Create(registry); // Assert Assert.IsNotNull(entity); @@ -91,6 +91,7 @@ Assert.AreEqual(1, entity.GrassCoverErosionInwardsFailureMechanismMetaEntities.Count); GrassCoverErosionInwardsFailureMechanismMetaEntity generalInputEntity = entity.GrassCoverErosionInwardsFailureMechanismMetaEntities.First(); Assert.AreEqual(failureMechanism.GeneralInput.N, generalInputEntity.N); + Assert.IsNull(generalInputEntity.DikeProfileCollectionSourcePath); } [Test] @@ -139,7 +140,7 @@ var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); // Call - var entity = failureMechanism.Create(new PersistenceRegistry()); + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); // Assert Assert.IsEmpty(entity.FailureMechanismSectionEntities); @@ -153,7 +154,7 @@ failureMechanism.AddSection(new TestFailureMechanismSection()); // Call - var entity = failureMechanism.Create(new PersistenceRegistry()); + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); // Assert Assert.AreEqual(1, entity.FailureMechanismSectionEntities.Count); @@ -168,7 +169,7 @@ var registry = new PersistenceRegistry(); // Call - var entity = failureMechanism.Create(registry); + FailureMechanismEntity entity = failureMechanism.Create(registry); // Assert CollectionAssert.IsEmpty(entity.DikeProfileEntities); @@ -178,16 +179,25 @@ public void Create_WithDikeProfiles_AddDikeProfileEntities() { // Setup + const string sourcePath = "some/path/to/my/dikeprofiles"; var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); - failureMechanism.DikeProfiles.Add(new TestDikeProfile()); - failureMechanism.DikeProfiles.Add(new TestDikeProfile()); + failureMechanism.DikeProfiles.AddRange(new[] + { + new TestDikeProfile(string.Empty, "id1"), + new TestDikeProfile(string.Empty, "id2") + }, sourcePath); + var registry = new PersistenceRegistry(); // Call - var entity = failureMechanism.Create(registry); + FailureMechanismEntity entity = failureMechanism.Create(registry); // Assert Assert.AreEqual(2, entity.DikeProfileEntities.Count); + + GrassCoverErosionInwardsFailureMechanismMetaEntity generalInputEntity = + entity.GrassCoverErosionInwardsFailureMechanismMetaEntities.First(); + Assert.AreEqual(sourcePath, generalInputEntity.DikeProfileCollectionSourcePath); } [Test] Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/IntegrationTests/StorageSqLiteIntegrationTest.cs =================================================================== diff -u -r8cb270db5fbcb82f19d6f3a390f083e9e0516d8c -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/IntegrationTests/StorageSqLiteIntegrationTest.cs (.../StorageSqLiteIntegrationTest.cs) (revision 8cb270db5fbcb82f19d6f3a390f083e9e0516d8c) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/IntegrationTests/StorageSqLiteIntegrationTest.cs (.../StorageSqLiteIntegrationTest.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -98,7 +98,7 @@ string firstRingtoetsFile = GetRandomRingtoetsFile(); string secondRingtoetsFile = GetRandomRingtoetsFile(); - StorageSqLite storage = new StorageSqLite(); + var storage = new StorageSqLite(); storage.StageProject(fullProject); storage.SaveProjectAs(firstRingtoetsFile); @@ -120,11 +120,11 @@ string tempRingtoetsFile = GetRandomRingtoetsFile(); // When - var entityBeforeSave = fullProject.Create(new PersistenceRegistry()); + ProjectEntity entityBeforeSave = fullProject.Create(new PersistenceRegistry()); byte[] hash1 = FingerprintHelper.Get(entityBeforeSave); - StorageSqLite storage = new StorageSqLite(); + var storage = new StorageSqLite(); storage.StageProject(fullProject); storage.SaveProjectAs(tempRingtoetsFile); @@ -145,14 +145,14 @@ public void LoadProject_FullTestProjectSaved_ProjectAsEntitiesInNewStorage() { // Setup - StorageSqLite storage = new StorageSqLite(); + var storage = new StorageSqLite(); RingtoetsProject fullProject = RingtoetsProjectTestHelper.GetFullTestProject(); storage.StageProject(fullProject); string tempRingtoetsFile = GetRandomRingtoetsFile(); storage.SaveProjectAs(tempRingtoetsFile); // Call - RingtoetsProject loadedProject = (RingtoetsProject) storage.LoadProject(tempRingtoetsFile); + var loadedProject = (RingtoetsProject) storage.LoadProject(tempRingtoetsFile); // Assert AssertProjectsAreEqual(fullProject, loadedProject); @@ -195,7 +195,7 @@ { // Given string tempRingtoetsFile = GetRandomRingtoetsFile(); - var expectedProjectName = Path.GetFileNameWithoutExtension(tempRingtoetsFile); + string expectedProjectName = Path.GetFileNameWithoutExtension(tempRingtoetsFile); var mocks = new MockRepository(); var projectMigrator = mocks.Stub(); @@ -205,7 +205,7 @@ var projectStore = new StorageSqLite(); RingtoetsProject fullProject = RingtoetsProjectTestHelper.GetFullTestProject(); - var expectedProjectDescription = fullProject.Description; + string expectedProjectDescription = fullProject.Description; // Precondition SqLiteDatabaseHelper.CreateValidRingtoetsDatabase(tempRingtoetsFile, fullProject); @@ -353,8 +353,8 @@ IEnumerable expectedSectionResults, IEnumerable actualSectionResults) { - var expectedSectionResultsArray = expectedSectionResults.ToArray(); - var actualSectionResultsArray = actualSectionResults.ToArray(); + StrengthStabilityLengthwiseConstructionFailureMechanismSectionResult[] expectedSectionResultsArray = expectedSectionResults.ToArray(); + StrengthStabilityLengthwiseConstructionFailureMechanismSectionResult[] actualSectionResultsArray = actualSectionResults.ToArray(); Assert.AreEqual(expectedSectionResultsArray.Length, actualSectionResultsArray.Length); @@ -372,8 +372,8 @@ IEnumerable expectedSectionResults, IEnumerable actualSectionResults) { - var expectedSectionResultsArray = expectedSectionResults.ToArray(); - var actualSectionResultsArray = actualSectionResults.ToArray(); + TechnicalInnovationFailureMechanismSectionResult[] expectedSectionResultsArray = expectedSectionResults.ToArray(); + TechnicalInnovationFailureMechanismSectionResult[] actualSectionResultsArray = actualSectionResults.ToArray(); Assert.AreEqual(expectedSectionResultsArray.Length, actualSectionResultsArray.Length); @@ -391,8 +391,8 @@ IEnumerable expectedSectionResults, IEnumerable actualSectionResults) { - var expectedSectionResultsArray = expectedSectionResults.ToArray(); - var actualSectionResultsArray = actualSectionResults.ToArray(); + WaterPressureAsphaltCoverFailureMechanismSectionResult[] expectedSectionResultsArray = expectedSectionResults.ToArray(); + WaterPressureAsphaltCoverFailureMechanismSectionResult[] actualSectionResultsArray = actualSectionResults.ToArray(); Assert.AreEqual(expectedSectionResultsArray.Length, actualSectionResultsArray.Length); @@ -410,8 +410,8 @@ IEnumerable expectedSectionResults, IEnumerable actualSectionResults) { - var expectedSectionResultsArray = expectedSectionResults.ToArray(); - var actualSectionResultsArray = actualSectionResults.ToArray(); + MacrostabilityInwardsFailureMechanismSectionResult[] expectedSectionResultsArray = expectedSectionResults.ToArray(); + MacrostabilityInwardsFailureMechanismSectionResult[] actualSectionResultsArray = actualSectionResults.ToArray(); Assert.AreEqual(expectedSectionResultsArray.Length, actualSectionResultsArray.Length); @@ -430,8 +430,8 @@ IEnumerable expectedSectionResults, IEnumerable actualSectionResults) { - var expectedSectionResultsArray = expectedSectionResults.ToArray(); - var actualSectionResultsArray = actualSectionResults.ToArray(); + MacrostabilityOutwardsFailureMechanismSectionResult[] expectedSectionResultsArray = expectedSectionResults.ToArray(); + MacrostabilityOutwardsFailureMechanismSectionResult[] actualSectionResultsArray = actualSectionResults.ToArray(); Assert.AreEqual(expectedSectionResultsArray.Length, actualSectionResultsArray.Length); @@ -450,8 +450,8 @@ IEnumerable expectedSectionResults, IEnumerable actualSectionResults) { - var expectedSectionResultsArray = expectedSectionResults.ToArray(); - var actualSectionResultsArray = actualSectionResults.ToArray(); + GrassCoverSlipOffInwardsFailureMechanismSectionResult[] expectedSectionResultsArray = expectedSectionResults.ToArray(); + GrassCoverSlipOffInwardsFailureMechanismSectionResult[] actualSectionResultsArray = actualSectionResults.ToArray(); Assert.AreEqual(expectedSectionResultsArray.Length, actualSectionResultsArray.Length); @@ -470,8 +470,8 @@ IEnumerable expectedSectionResults, IEnumerable actualSectionResults) { - var expectedSectionResultsArray = expectedSectionResults.ToArray(); - var actualSectionResultsArray = actualSectionResults.ToArray(); + GrassCoverSlipOffOutwardsFailureMechanismSectionResult[] expectedSectionResultsArray = expectedSectionResults.ToArray(); + GrassCoverSlipOffOutwardsFailureMechanismSectionResult[] actualSectionResultsArray = actualSectionResults.ToArray(); Assert.AreEqual(expectedSectionResultsArray.Length, actualSectionResultsArray.Length); @@ -490,8 +490,8 @@ IEnumerable expectedSectionResults, IEnumerable actualSectionResults) { - var expectedSectionResultsArray = expectedSectionResults.ToArray(); - var actualSectionResultsArray = actualSectionResults.ToArray(); + MicrostabilityFailureMechanismSectionResult[] expectedSectionResultsArray = expectedSectionResults.ToArray(); + MicrostabilityFailureMechanismSectionResult[] actualSectionResultsArray = actualSectionResults.ToArray(); Assert.AreEqual(expectedSectionResultsArray.Length, actualSectionResultsArray.Length); @@ -510,8 +510,8 @@ IEnumerable expectedSectionResults, IEnumerable actualSectionResults) { - var expectedSectionResultsArray = expectedSectionResults.ToArray(); - var actualSectionResultsArray = actualSectionResults.ToArray(); + PipingStructureFailureMechanismSectionResult[] expectedSectionResultsArray = expectedSectionResults.ToArray(); + PipingStructureFailureMechanismSectionResult[] actualSectionResultsArray = actualSectionResults.ToArray(); Assert.AreEqual(expectedSectionResultsArray.Length, actualSectionResultsArray.Length); @@ -538,8 +538,8 @@ private static void AssertFailureMechanismSections(IEnumerable expectedSections, IEnumerable actualSections) { - var expectedSectionsArray = expectedSections.ToArray(); - var actualSectionsArray = actualSections.ToArray(); + FailureMechanismSection[] expectedSectionsArray = expectedSections.ToArray(); + FailureMechanismSection[] actualSectionsArray = actualSections.ToArray(); Assert.AreEqual(expectedSectionsArray.Length, actualSectionsArray.Length); @@ -569,7 +569,7 @@ Assert.AreEqual(expectedModels.SourcePath, actualModels.SourcePath); Assert.AreEqual(expectedModels.Count, actualModels.Count); - for (int i = 0; i < expectedModels.Count; i++) + for (var i = 0; i < expectedModels.Count; i++) { StochasticSoilModel expectedModel = expectedModels[i]; StochasticSoilModel actualModel = actualModels[i]; @@ -594,7 +594,7 @@ Assert.Less(0, actualStochasticSoilProfiles.Count); Assert.AreEqual(expectedStochasticSoilProfiles.Count, actualStochasticSoilProfiles.Count); - for (int i = 0; i < expectedStochasticSoilProfiles.Count; i++) + for (var i = 0; i < expectedStochasticSoilProfiles.Count; i++) { StochasticSoilProfile expectedProfile = expectedStochasticSoilProfiles[i]; StochasticSoilProfile actualProfile = actualStochasticSoilProfiles[i]; @@ -613,7 +613,7 @@ Assert.Less(0, actualLayerArray.Length); Assert.AreEqual(expectedLayerArray.Length, actualLayerArray.Length); - for (int i = 0; i < expectedLayerArray.Length; i++) + for (var i = 0; i < expectedLayerArray.Length; i++) { PipingSoilLayer expectedLayer = actualLayerArray[i]; PipingSoilLayer actualLayer = expectedLayerArray[i]; @@ -637,7 +637,7 @@ Assert.Greater(expectedSurfaceLines.Count, 0); Assert.AreEqual(expectedSurfaceLines.Count, actualSurfaceLines.Count); - for (int i = 0; i < expectedSurfaceLines.Count; i++) + for (var i = 0; i < expectedSurfaceLines.Count; i++) { RingtoetsPipingSurfaceLine expectedSurfaceLine = expectedSurfaceLines.ElementAt(i); RingtoetsPipingSurfaceLine actualSurfaceLine = expectedSurfaceLines.ElementAt(i); @@ -669,7 +669,7 @@ Assert.AreEqual(expectedRootCalculationGroup.IsNameEditable, actualRootCalculationGroup.IsNameEditable); Assert.AreEqual(expectedRootCalculationGroup.Children.Count, actualRootCalculationGroup.Children.Count); - for (int i = 0; i < expectedRootCalculationGroup.Children.Count; i++) + for (var i = 0; i < expectedRootCalculationGroup.Children.Count; i++) { ICalculationBase expectedChild = expectedRootCalculationGroup.Children[i]; ICalculationBase actualChild = actualRootCalculationGroup.Children[i]; @@ -791,10 +791,10 @@ Assert.AreEqual(expectedOutput.CalculationConvergence, actualOutput.CalculationConvergence); } - private static void AssertDikeProfiles(IList expectedDikeProfiles, IList actualDikeProfiles) + private static void AssertDikeProfiles(DikeProfileCollection expectedDikeProfiles, DikeProfileCollection actualDikeProfiles) { Assert.AreEqual(expectedDikeProfiles.Count, actualDikeProfiles.Count); - for (int i = 0; i < expectedDikeProfiles.Count; i++) + for (var i = 0; i < expectedDikeProfiles.Count; i++) { AssertDikeProfile(expectedDikeProfiles[i], actualDikeProfiles[i]); } @@ -816,7 +816,7 @@ IList actualDikeProfiles) { Assert.AreEqual(expectedForeshoreProfiles.Count, actualDikeProfiles.Count); - for (int i = 0; i < expectedForeshoreProfiles.Count; i++) + for (var i = 0; i < expectedForeshoreProfiles.Count; i++) { AssertForeshoreProfile(expectedForeshoreProfiles[i], actualDikeProfiles[i]); } @@ -849,7 +849,7 @@ RoughnessPoint[] actualRoughnessPoints) { Assert.AreEqual(expectedRoughnessPoints.Length, actualRoughnessPoints.Length); - for (int i = 0; i < expectedRoughnessPoints.Length; i++) + for (var i = 0; i < expectedRoughnessPoints.Length; i++) { AssertRoughnessPoint(expectedRoughnessPoints[i], actualRoughnessPoints[i]); } @@ -919,8 +919,8 @@ private static void AssertFailureMechanismSectionResults(IEnumerable expectedSectionResults, IEnumerable actualSectionResults) { - var expectedSectionResultsArray = expectedSectionResults.ToArray(); - var actualSectionResultsArray = actualSectionResults.ToArray(); + StabilityPointStructuresFailureMechanismSectionResult[] expectedSectionResultsArray = expectedSectionResults.ToArray(); + StabilityPointStructuresFailureMechanismSectionResult[] actualSectionResultsArray = actualSectionResults.ToArray(); Assert.AreEqual(expectedSectionResultsArray.Length, actualSectionResultsArray.Length); @@ -946,7 +946,7 @@ ObservableList actualStabilityPointStructures) { Assert.AreEqual(expectedStabilityPointStructures.Count, actualStabilityPointStructures.Count); - for (int i = 0; i < expectedStabilityPointStructures.Count; i++) + for (var i = 0; i < expectedStabilityPointStructures.Count; i++) { AssertStabilityPointStructure(expectedStabilityPointStructures[i], actualStabilityPointStructures[i]); } @@ -1065,8 +1065,8 @@ private static void AssertFailureMechanismSectionResults(IEnumerable expectedSectionResults, IEnumerable actualSectionResults) { - var expectedSectionResultsArray = expectedSectionResults.ToArray(); - var actualSectionResultsArray = actualSectionResults.ToArray(); + ClosingStructuresFailureMechanismSectionResult[] expectedSectionResultsArray = expectedSectionResults.ToArray(); + ClosingStructuresFailureMechanismSectionResult[] actualSectionResultsArray = actualSectionResults.ToArray(); Assert.AreEqual(expectedSectionResultsArray.Length, actualSectionResultsArray.Length); @@ -1085,7 +1085,7 @@ ObservableList actualClosingStructures) { Assert.AreEqual(expectedClosingStructures.Count, actualClosingStructures.Count); - for (int i = 0; i < expectedClosingStructures.Count; i++) + for (var i = 0; i < expectedClosingStructures.Count; i++) { AssertClosingStructure(expectedClosingStructures[i], actualClosingStructures[i]); } @@ -1181,8 +1181,8 @@ IEnumerable expectedSectionResults, IEnumerable actualSectionResults) { - var expectedSectionResultsArray = expectedSectionResults.ToArray(); - var actualSectionResultsArray = actualSectionResults.ToArray(); + DuneErosionFailureMechanismSectionResult[] expectedSectionResultsArray = expectedSectionResults.ToArray(); + DuneErosionFailureMechanismSectionResult[] actualSectionResultsArray = actualSectionResults.ToArray(); Assert.AreEqual(expectedSectionResultsArray.Length, actualSectionResultsArray.Length); @@ -1258,8 +1258,8 @@ private static void AssertFailureMechanismSectionResults(IEnumerable expectedSectionResults, IEnumerable actualSectionResults) { - var expectedSectionResultsArray = expectedSectionResults.ToArray(); - var actualSectionResultsArray = actualSectionResults.ToArray(); + HeightStructuresFailureMechanismSectionResult[] expectedSectionResultsArray = expectedSectionResults.ToArray(); + HeightStructuresFailureMechanismSectionResult[] actualSectionResultsArray = actualSectionResults.ToArray(); Assert.AreEqual(expectedSectionResultsArray.Length, actualSectionResultsArray.Length); @@ -1285,7 +1285,7 @@ ObservableList actualHeightStructures) { Assert.AreEqual(expectedHeightStructures.Count, actualHeightStructures.Count); - for (int i = 0; i < expectedHeightStructures.Count; i++) + for (var i = 0; i < expectedHeightStructures.Count; i++) { AssertHeightStructure(expectedHeightStructures[i], actualHeightStructures[i]); } @@ -1364,8 +1364,8 @@ IEnumerable expectedSectionResults, IEnumerable actualSectionResults) { - var expectedSectionResultsArray = expectedSectionResults.ToArray(); - var actualSectionResultsArray = actualSectionResults.ToArray(); + PipingFailureMechanismSectionResult[] expectedSectionResultsArray = expectedSectionResults.ToArray(); + PipingFailureMechanismSectionResult[] actualSectionResultsArray = actualSectionResults.ToArray(); Assert.AreEqual(expectedSectionResultsArray.Length, actualSectionResultsArray.Length); @@ -1488,8 +1488,8 @@ IEnumerable expectedSectionResults, IEnumerable actualSectionResults) { - var expectedSectionResultsArray = expectedSectionResults.ToArray(); - var actualSectionResultsArray = actualSectionResults.ToArray(); + GrassCoverErosionInwardsFailureMechanismSectionResult[] expectedSectionResultsArray = expectedSectionResults.ToArray(); + GrassCoverErosionInwardsFailureMechanismSectionResult[] actualSectionResultsArray = actualSectionResults.ToArray(); Assert.AreEqual(expectedSectionResultsArray.Length, actualSectionResultsArray.Length); @@ -1601,8 +1601,8 @@ private static void AssertFailureMechanismSectionResults(IEnumerable expectedSectionResults, IEnumerable actualSectionResults) { - var expectedSectionResultsArray = expectedSectionResults.ToArray(); - var actualSectionResultsArray = actualSectionResults.ToArray(); + GrassCoverErosionOutwardsFailureMechanismSectionResult[] expectedSectionResultsArray = expectedSectionResults.ToArray(); + GrassCoverErosionOutwardsFailureMechanismSectionResult[] actualSectionResultsArray = actualSectionResults.ToArray(); Assert.AreEqual(expectedSectionResultsArray.Length, actualSectionResultsArray.Length); @@ -1652,8 +1652,8 @@ private static void AssertFailureMechanismSectionResults(IEnumerable expectedSectionResults, IEnumerable actualSectionResults) { - var expectedSectionResultsArray = expectedSectionResults.ToArray(); - var actualSectionResultsArray = actualSectionResults.ToArray(); + StabilityStoneCoverFailureMechanismSectionResult[] expectedSectionResultsArray = expectedSectionResults.ToArray(); + StabilityStoneCoverFailureMechanismSectionResult[] actualSectionResultsArray = actualSectionResults.ToArray(); Assert.AreEqual(expectedSectionResultsArray.Length, actualSectionResultsArray.Length); @@ -1703,8 +1703,8 @@ private static void AssertFailureMechanismSectionResults(IEnumerable expectedSectionResults, IEnumerable actualSectionResults) { - var expectedSectionResultsArray = expectedSectionResults.ToArray(); - var actualSectionResultsArray = actualSectionResults.ToArray(); + WaveImpactAsphaltCoverFailureMechanismSectionResult[] expectedSectionResultsArray = expectedSectionResults.ToArray(); + WaveImpactAsphaltCoverFailureMechanismSectionResult[] actualSectionResultsArray = actualSectionResults.ToArray(); Assert.AreEqual(expectedSectionResultsArray.Length, actualSectionResultsArray.Length); @@ -1756,7 +1756,7 @@ List actualHydraulicBoundaryLocations) { Assert.AreEqual(expectedHydraulicBoundaryLocations.Count, actualHydraulicBoundaryLocations.Count); - for (int i = 0; i < expectedHydraulicBoundaryLocations.Count; i++) + for (var i = 0; i < expectedHydraulicBoundaryLocations.Count; i++) { HydraulicBoundaryLocation expectedBoundaryLocation = expectedHydraulicBoundaryLocations[i]; HydraulicBoundaryLocation actualBoundaryLocation = actualHydraulicBoundaryLocations[i]; Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/FailureMechanismEntityReadExtensionsTest.cs =================================================================== diff -u -r36b8629b18443a58866edc869420795588eaf168 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/FailureMechanismEntityReadExtensionsTest.cs (.../FailureMechanismEntityReadExtensionsTest.cs) (revision 36b8629b18443a58866edc869420795588eaf168) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/FailureMechanismEntityReadExtensionsTest.cs (.../FailureMechanismEntityReadExtensionsTest.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -509,6 +509,7 @@ Assert.IsEmpty(failureMechanism.Sections); Assert.AreEqual(3, failureMechanism.GeneralInput.N); + Assert.IsNull(failureMechanism.DikeProfiles.SourcePath); } [Test] @@ -517,13 +518,15 @@ // Setup string emptyDikeGeometryXml = new RoughnessPointXmlSerializer().ToXml(new RoughnessPoint[0]); string emptyForeshoreBinaryXml = new Point2DXmlSerializer().ToXml(new Point2D[0]); + const string sourcePath = "some/path/to/my/dikeprofiles"; var entity = new FailureMechanismEntity { GrassCoverErosionInwardsFailureMechanismMetaEntities = { new GrassCoverErosionInwardsFailureMechanismMetaEntity { - N = 3 + N = 3, + DikeProfileCollectionSourcePath = sourcePath } }, DikeProfileEntities = @@ -551,6 +554,7 @@ // Assert Assert.AreEqual(2, failureMechanism.DikeProfiles.Count); + Assert.AreEqual(sourcePath, failureMechanism.DikeProfiles.SourcePath); } [Test] Index: Application/Ringtoets/test/Application.Ringtoets.Storage.TestUtil/RingtoetsProjectTestHelper.cs =================================================================== diff -u -r8cb270db5fbcb82f19d6f3a390f083e9e0516d8c -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Application/Ringtoets/test/Application.Ringtoets.Storage.TestUtil/RingtoetsProjectTestHelper.cs (.../RingtoetsProjectTestHelper.cs) (revision 8cb270db5fbcb82f19d6f3a390f083e9e0516d8c) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.TestUtil/RingtoetsProjectTestHelper.cs (.../RingtoetsProjectTestHelper.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -162,7 +162,7 @@ private static void SetSectionResults(IEnumerable sectionResults) { var random = new Random(21); - foreach (var sectionResult in sectionResults) + foreach (StrengthStabilityLengthwiseConstructionFailureMechanismSectionResult sectionResult in sectionResults) { sectionResult.AssessmentLayerOne = GetAssessmentLayerOneState(); sectionResult.AssessmentLayerThree = (RoundedDouble) random.NextDouble(); @@ -172,7 +172,7 @@ private static void SetSectionResults(IEnumerable sectionResults) { var random = new Random(21); - foreach (var sectionResult in sectionResults) + foreach (TechnicalInnovationFailureMechanismSectionResult sectionResult in sectionResults) { sectionResult.AssessmentLayerOne = GetAssessmentLayerOneState(); sectionResult.AssessmentLayerThree = (RoundedDouble) random.NextDouble(); @@ -182,7 +182,7 @@ private static void SetSectionResults(IEnumerable sectionResults) { var random = new Random(21); - foreach (var sectionResult in sectionResults) + foreach (WaterPressureAsphaltCoverFailureMechanismSectionResult sectionResult in sectionResults) { sectionResult.AssessmentLayerOne = GetAssessmentLayerOneState(); sectionResult.AssessmentLayerThree = (RoundedDouble) random.NextDouble(); @@ -192,7 +192,7 @@ private static void SetSectionResults(IEnumerable sectionResults) { var random = new Random(21); - foreach (var sectionResult in sectionResults) + foreach (MacrostabilityOutwardsFailureMechanismSectionResult sectionResult in sectionResults) { sectionResult.AssessmentLayerOne = GetAssessmentLayerOneState(); sectionResult.AssessmentLayerTwoA = (RoundedDouble) random.NextDouble(); @@ -203,7 +203,7 @@ private static void SetSectionResults(IEnumerable sectionResults) { var random = new Random(21); - foreach (var sectionResult in sectionResults) + foreach (MacrostabilityInwardsFailureMechanismSectionResult sectionResult in sectionResults) { sectionResult.AssessmentLayerOne = GetAssessmentLayerOneState(); sectionResult.AssessmentLayerTwoA = (RoundedDouble) random.NextDouble(); @@ -214,7 +214,7 @@ private static void SetSectionResults(IEnumerable sectionResults) { var random = new Random(21); - foreach (var sectionResult in sectionResults) + foreach (GrassCoverSlipOffInwardsFailureMechanismSectionResult sectionResult in sectionResults) { sectionResult.AssessmentLayerOne = GetAssessmentLayerOneState(); sectionResult.AssessmentLayerTwoA = GetAssessmentLayerTwoAResult(); @@ -225,7 +225,7 @@ private static void SetSectionResults(IEnumerable sectionResults) { var random = new Random(21); - foreach (var sectionResult in sectionResults) + foreach (GrassCoverSlipOffOutwardsFailureMechanismSectionResult sectionResult in sectionResults) { sectionResult.AssessmentLayerOne = GetAssessmentLayerOneState(); sectionResult.AssessmentLayerTwoA = GetAssessmentLayerTwoAResult(); @@ -236,7 +236,7 @@ private static void SetSectionResults(IEnumerable sectionResults) { var random = new Random(21); - foreach (var sectionResult in sectionResults) + foreach (MicrostabilityFailureMechanismSectionResult sectionResult in sectionResults) { sectionResult.AssessmentLayerOne = GetAssessmentLayerOneState(); sectionResult.AssessmentLayerTwoA = GetAssessmentLayerTwoAResult(); @@ -247,7 +247,7 @@ private static void SetSectionResults(IEnumerable sectionResults) { var random = new Random(21); - foreach (var sectionResult in sectionResults) + foreach (PipingStructureFailureMechanismSectionResult sectionResult in sectionResults) { sectionResult.AssessmentLayerOne = GetAssessmentLayerOneState(); sectionResult.AssessmentLayerTwoA = GetAssessmentLayerTwoAResult(); @@ -412,7 +412,7 @@ { var random = new Random(21); var firstSectionResultHasCalculation = false; - foreach (var sectionResult in sectionResults) + foreach (StabilityPointStructuresFailureMechanismSectionResult sectionResult in sectionResults) { sectionResult.AssessmentLayerOne = GetAssessmentLayerOneState(); sectionResult.AssessmentLayerThree = (RoundedDouble) random.NextDouble(); @@ -490,7 +490,7 @@ { var random = new Random(21); var firstSectionResultHasCalculation = false; - foreach (var sectionResult in sectionResults) + foreach (ClosingStructuresFailureMechanismSectionResult sectionResult in sectionResults) { sectionResult.AssessmentLayerOne = GetAssessmentLayerOneState(); sectionResult.AssessmentLayerThree = (RoundedDouble) random.NextDouble(); @@ -515,7 +515,7 @@ private static void SetSectionResults(IEnumerable sectionResults) { var random = new Random(21); - foreach (var sectionResult in sectionResults) + foreach (DuneErosionFailureMechanismSectionResult sectionResult in sectionResults) { sectionResult.AssessmentLayerOne = GetAssessmentLayerOneState(); sectionResult.AssessmentLayerTwoA = GetAssessmentLayerTwoAResult(); @@ -571,7 +571,7 @@ { failureMechanism.GeneralInput.N = 5; - var hydraulicBoundaryLocations = assessmentSection.HydraulicBoundaryDatabase.Locations; + List hydraulicBoundaryLocations = assessmentSection.HydraulicBoundaryDatabase.Locations; var heightStructure = new TestHeightStructure(); failureMechanism.HeightStructures.Add(heightStructure); @@ -615,7 +615,7 @@ { var random = new Random(21); var firstSectionResultHasCalculation = false; - foreach (var sectionResult in sectionResults) + foreach (HeightStructuresFailureMechanismSectionResult sectionResult in sectionResults) { sectionResult.AssessmentLayerOne = GetAssessmentLayerOneState(); sectionResult.AssessmentLayerThree = (RoundedDouble) random.NextDouble(); @@ -635,7 +635,7 @@ { pipingFailureMechanism.PipingProbabilityAssessmentInput.A = 0.9; - var referenceLineGeometryPoints = assessmentSection.ReferenceLine.Points.ToArray(); + Point2D[] referenceLineGeometryPoints = assessmentSection.ReferenceLine.Points.ToArray(); PipingSoilProfile pipingSoilProfile = new TestPipingSoilProfile(); PipingSoilLayer pipingSoilLayer = pipingSoilProfile.Layers.First(); @@ -794,7 +794,7 @@ private static void SetSectionResults(IEnumerable sectionResults) { var random = new Random(21); - foreach (var sectionResult in sectionResults) + foreach (PipingFailureMechanismSectionResult sectionResult in sectionResults) { sectionResult.AssessmentLayerOne = GetAssessmentLayerOneState(); sectionResult.AssessmentLayerThree = (RoundedDouble) random.NextDouble(); @@ -842,43 +842,48 @@ IAssessmentSection assessmentSection) { failureMechanism.GeneralInput.N = 15; - var dikeProfile = new DikeProfile(new Point2D(1, 2), - new[] - { - new RoughnessPoint(new Point2D(1, 2), 1), - new RoughnessPoint(new Point2D(3, 4), 0.5) - }, - new[] - { - new Point2D(5, 6), - new Point2D(7, 8) - }, - new BreakWater(BreakWaterType.Caisson, 15), - new DikeProfile.ConstructionProperties - { - Id = "id", - DikeHeight = 1.1, - Name = "2.2", - Orientation = 3.3, - X0 = 4.4 - }); - failureMechanism.DikeProfiles.Add(dikeProfile); - failureMechanism.DikeProfiles.Add(new DikeProfile(new Point2D(9, 10), - new[] - { - new RoughnessPoint(new Point2D(11, 12), 1), - new RoughnessPoint(new Point2D(13, 14), 0.5) - }, - new Point2D[0], - null, - new DikeProfile.ConstructionProperties - { - Id = "id", - DikeHeight = 5.5, - Name = "6.6", - Orientation = 7.7, - X0 = 8.8 - })); + var dikeProfile1 = new DikeProfile(new Point2D(1, 2), + new[] + { + new RoughnessPoint(new Point2D(1, 2), 1), + new RoughnessPoint(new Point2D(3, 4), 0.5) + }, + new[] + { + new Point2D(5, 6), + new Point2D(7, 8) + }, + new BreakWater(BreakWaterType.Caisson, 15), + new DikeProfile.ConstructionProperties + { + Id = "id", + DikeHeight = 1.1, + Name = "2.2", + Orientation = 3.3, + X0 = 4.4 + }); + var dikeProfile2 = new DikeProfile(new Point2D(9, 10), + new[] + { + new RoughnessPoint(new Point2D(11, 12), 1), + new RoughnessPoint(new Point2D(13, 14), 0.5) + }, + new Point2D[0], + null, + new DikeProfile.ConstructionProperties + { + Id = "id2", + DikeHeight = 5.5, + Name = "6.6", + Orientation = 7.7, + X0 = 8.8 + }); + failureMechanism.DikeProfiles.AddRange(new[] + { + dikeProfile1, + dikeProfile2 + }, "some/path/to/dikeprofiles"); + failureMechanism.CalculationsGroup.Children.Add(new CalculationGroup { Name = "GEKB A", @@ -893,15 +898,15 @@ }, InputParameters = { - DikeProfile = dikeProfile, + DikeProfile = dikeProfile1, HydraulicBoundaryLocation = assessmentSection.HydraulicBoundaryDatabase.Locations[0], BreakWater = { - Height = (RoundedDouble) (dikeProfile.BreakWater.Height + 0.3), + Height = (RoundedDouble) (dikeProfile1.BreakWater.Height + 0.3), Type = BreakWaterType.Wall }, - DikeHeight = (RoundedDouble) (dikeProfile.DikeHeight + 0.2), - Orientation = dikeProfile.Orientation, + DikeHeight = (RoundedDouble) (dikeProfile1.DikeHeight + 0.2), + Orientation = dikeProfile1.Orientation, CriticalFlowRate = { Mean = (RoundedDouble) 1.1, @@ -937,7 +942,7 @@ { var random = new Random(21); var firstSectionResultHasCalculation = false; - foreach (var sectionResult in sectionResults) + foreach (GrassCoverErosionInwardsFailureMechanismSectionResult sectionResult in sectionResults) { sectionResult.AssessmentLayerOne = GetAssessmentLayerOneState(); sectionResult.AssessmentLayerThree = (RoundedDouble) random.NextDouble(); @@ -957,7 +962,7 @@ { failureMechanism.GeneralInput.N = 15; - var hydraulicBoundaryLocations = failureMechanism.HydraulicBoundaryLocations; + ObservableList hydraulicBoundaryLocations = failureMechanism.HydraulicBoundaryLocations; hydraulicBoundaryLocations.Add(new HydraulicBoundaryLocation(0, "HL 1", 100, 200)); hydraulicBoundaryLocations.Add(new HydraulicBoundaryLocation(45, "HL 2", 123, 150)); @@ -1036,7 +1041,7 @@ private static void SetSectionResults(IEnumerable sectionResults) { var random = new Random(21); - foreach (var sectionResult in sectionResults) + foreach (GrassCoverErosionOutwardsFailureMechanismSectionResult sectionResult in sectionResults) { sectionResult.AssessmentLayerOne = GetAssessmentLayerOneState(); sectionResult.AssessmentLayerTwoA = GetAssessmentLayerTwoAResult(); @@ -1129,7 +1134,7 @@ private static void SetSectionResults(IEnumerable sectionResults) { var random = new Random(21); - foreach (var sectionResult in sectionResults) + foreach (StabilityStoneCoverFailureMechanismSectionResult sectionResult in sectionResults) { sectionResult.AssessmentLayerOne = GetAssessmentLayerOneState(); sectionResult.AssessmentLayerTwoA = GetAssessmentLayerTwoAResult(); @@ -1218,7 +1223,7 @@ private static void SetSectionResults(IEnumerable sectionResults) { var random = new Random(21); - foreach (var sectionResult in sectionResults) + foreach (WaveImpactAsphaltCoverFailureMechanismSectionResult sectionResult in sectionResults) { sectionResult.AssessmentLayerOne = GetAssessmentLayerOneState(); sectionResult.AssessmentLayerTwoA = GetAssessmentLayerTwoAResult(); Index: Core/Common/src/Core.Common.Base/IO/FileImporterBase.cs =================================================================== diff -u -r110999cffbcac705d99ff96033e9eabb0e0b5e12 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Core/Common/src/Core.Common.Base/IO/FileImporterBase.cs (.../FileImporterBase.cs) (revision 110999cffbcac705d99ff96033e9eabb0e0b5e12) +++ Core/Common/src/Core.Common.Base/IO/FileImporterBase.cs (.../FileImporterBase.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -58,12 +58,6 @@ ImportTarget = importTarget; } - protected virtual void DoPostImportUpdates() - { - var observableTarget = ImportTarget as IObservable; - observableTarget?.NotifyObservers(); - } - public void SetProgressChanged(OnProgressChanged action) { ProgressChanged = action; @@ -125,15 +119,22 @@ /// protected bool Canceled { get; private set; } + protected virtual void DoPostImportUpdates() + { + var observableTarget = ImportTarget as IObservable; + observableTarget?.NotifyObservers(); + } + /// - /// This method logs messages when the importer is canceled in a cancelable state. + /// This method logs messages when the importer is canceled in a cancellable state. /// protected abstract void LogImportCanceledMessage(); /// /// This method returns the result of the import action. /// /// True if the import was successful, false if otherwise. + /// Implementations of this method are allowed to throw exceptions of any kind. protected abstract bool OnImport(); protected void NotifyProgress(string currentStepName, int currentStep, int totalNumberOfSteps) Index: Core/Common/src/Core.Common.Base/ObservableUniqueItemCollectionWithSourcePath.cs =================================================================== diff -u -r1b9445050ddc7786014349d7014c7c4d85242a5d -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Core/Common/src/Core.Common.Base/ObservableUniqueItemCollectionWithSourcePath.cs (.../ObservableUniqueItemCollectionWithSourcePath.cs) (revision 1b9445050ddc7786014349d7014c7c4d85242a5d) +++ Core/Common/src/Core.Common.Base/ObservableUniqueItemCollectionWithSourcePath.cs (.../ObservableUniqueItemCollectionWithSourcePath.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -23,6 +23,7 @@ using System.Collections; using System.Collections.Generic; using System.Linq; +using Core.Common.Base.Properties; using Core.Common.Utils; namespace Core.Common.Base @@ -186,13 +187,17 @@ private void ValidateItems(IEnumerable items) { IEnumerable> duplicateItems = - items.GroupBy(getUniqueFeature) + items.Concat(collection).GroupBy(getUniqueFeature) .Where(group => group.Count() > 1); if (duplicateItems.Any()) { - var duplicateFeatures = string.Join(", ", duplicateItems.Select(group => group.First())); - string exceptionMessage = $"{typeDescriptor} moeten een unieke {featureDescription} hebben. Gevonden dubbele elementen: {duplicateFeatures}."; + string duplicateFeatures = string.Join(", ", duplicateItems.Select(group => getUniqueFeature(group.First()))); + string exceptionMessage = string.Format( + Resources.ObservableUniqueItemCollectionWithSourcePath_ValidateItems_TypeDescriptor_0_must_have_unique_FeatureDescription_1_Found_duplicate_items_DuplicateFeatures_2, + typeDescriptor, + featureDescription, + duplicateFeatures); throw new ArgumentException(exceptionMessage); } } Index: Core/Common/src/Core.Common.Base/Properties/Resources.Designer.cs =================================================================== diff -u -r8eb717ca45b6518cccfef85e481e0da52ce1df4e -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Core/Common/src/Core.Common.Base/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 8eb717ca45b6518cccfef85e481e0da52ce1df4e) +++ Core/Common/src/Core.Common.Base/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -218,6 +218,16 @@ } /// + /// Looks up a localized string similar to {0} moeten een unieke {1} hebben. Gevonden dubbele elementen: {2}.. + /// + public static string ObservableUniqueItemCollectionWithSourcePath_ValidateItems_TypeDescriptor_0_must_have_unique_FeatureDescription_1_Found_duplicate_items_DuplicateFeatures_2 { + get { + return ResourceManager.GetString("ObservableUniqueItemCollectionWithSourcePath_ValidateItems_TypeDescriptor_0_must_" + + "have_unique_FeatureDescription_1_Found_duplicate_items_DuplicateFeatures_2", resourceCulture); + } + } + + /// /// Looks up a localized string similar to Vector moet 2 dimensies hebben, maar heeft er {0}.. /// public static string Point2D_AddVector_Vector_must_be_2D_but_has_Dimensionality_0_ { Index: Core/Common/src/Core.Common.Base/Properties/Resources.resx =================================================================== diff -u -r8eb717ca45b6518cccfef85e481e0da52ce1df4e -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Core/Common/src/Core.Common.Base/Properties/Resources.resx (.../Resources.resx) (revision 8eb717ca45b6518cccfef85e481e0da52ce1df4e) +++ Core/Common/src/Core.Common.Base/Properties/Resources.resx (.../Resources.resx) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -186,4 +186,7 @@ {0} (*.{1})|*.{2} + + {0} moeten een unieke {1} hebben. Gevonden dubbele elementen: {2}. + \ No newline at end of file Index: Core/Common/test/Core.Common.Base.Test/ObservableUniqueItemCollectionWithSourcePathTest.cs =================================================================== diff -u -r1b9445050ddc7786014349d7014c7c4d85242a5d -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Core/Common/test/Core.Common.Base.Test/ObservableUniqueItemCollectionWithSourcePathTest.cs (.../ObservableUniqueItemCollectionWithSourcePathTest.cs) (revision 1b9445050ddc7786014349d7014c7c4d85242a5d) +++ Core/Common/test/Core.Common.Base.Test/ObservableUniqueItemCollectionWithSourcePathTest.cs (.../ObservableUniqueItemCollectionWithSourcePathTest.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -30,9 +30,9 @@ [TestFixture] public class ObservableUniqueItemCollectionWithSourcePathTest { - private readonly Func getUniqueFeature = item => item.Name; private const string typeDescriptor = "TestItems"; private const string featureDescription = "Feature"; + private readonly Func getUniqueFeature = item => item.Name; [Test] public void DefaultConstructor_getUniqueFeatureNull_ThrowsArgumentNullException() @@ -116,7 +116,7 @@ TestDelegate call = () => collection.AddRange(items, "path"); // Assert - string message = "Collection cannot contain null."; + var message = "Collection cannot contain null."; string paramName = TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, message).ParamName; Assert.AreEqual("items", paramName); } @@ -248,6 +248,39 @@ } [Test] + public void GivenCollectionWithItems_WhenAddRangeWithItemsAlreadyInCollection_ThenThrowsArgumentException() + { + // Given + const string filePath = "some/file/path"; + var collection = new ConcreteObservableUniqueItemCollectionWithSourcePath( + getUniqueFeature, typeDescriptor, featureDescription); + + const string duplicateNameOne = "Item A"; + const string duplicateNameTwo = "Item B"; + var expectedCollection = new[] + { + new TestItem(duplicateNameOne), + new TestItem(duplicateNameTwo), + new TestItem("Item C"), + new TestItem("Item D") + }; + collection.AddRange(expectedCollection, filePath); + + // When + TestDelegate call = () => collection.AddRange(new[] + { + new TestItem(duplicateNameOne), + new TestItem(duplicateNameTwo) + }, "other/path"); + + // Then + string message = $"TestItems moeten een unieke Feature hebben. Gevonden dubbele elementen: {duplicateNameOne}, {duplicateNameTwo}."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, message); + CollectionAssert.AreEqual(expectedCollection, collection); + Assert.AreEqual(filePath, collection.SourcePath); + } + + [Test] public void Count_CollectionFilledWithElements_ReturnsExpectedNumberOfElements() { // Setup @@ -493,23 +526,18 @@ private class ConcreteObservableUniqueItemCollectionWithSourcePath : ObservableUniqueItemCollectionWithSourcePath where TObject : class { - public ConcreteObservableUniqueItemCollectionWithSourcePath(Func getUniqueFeature, string typeDescriptor, string featureDescription) + public ConcreteObservableUniqueItemCollectionWithSourcePath(Func getUniqueFeature, string typeDescriptor, string featureDescription) : base(getUniqueFeature, typeDescriptor, featureDescription) {} } private class TestItem { - public string Name { get; } - public TestItem(string name) { Name = name; } - public override string ToString() - { - return Name; - } + public string Name { get; } } } } \ No newline at end of file Index: Ringtoets.sln =================================================================== diff -u -rc63ac515f0ce88fbc058e1838d1a43ed6a912360 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets.sln (.../Ringtoets.sln) (revision c63ac515f0ce88fbc058e1838d1a43ed6a912360) +++ Ringtoets.sln (.../Ringtoets.sln) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -1477,6 +1477,8 @@ {C90B77DA-E421-43CC-B82E-529651BC21AC} = {C90B77DA-E421-43CC-B82E-529651BC21AC} EndProjectSection EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ringtoets.Common.IO.TestUtil.Test", "Ringtoets\Common\test\Ringtoets.Common.IO.TestUtil.Test\Ringtoets.Common.IO.TestUtil.Test.csproj", "{516E7E2A-83F6-43EB-895A-A1F4F90FA531}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution CreateInstaller|x86 = CreateInstaller|x86 @@ -3186,6 +3188,7 @@ {1F4D7974-2E42-4EA4-BDF7-C7BAFF2FE57C}.ReleaseForCodeCoverage|x86.Build.0 = ReleaseForCodeCoverage|x86 {CD7F7458-A273-4855-9744-4CCAFE0499D0}.CreateInstaller|x86.ActiveCfg = Release|x86 {CD7F7458-A273-4855-9744-4CCAFE0499D0}.CreateInstallerWithDemoProject|x86.ActiveCfg = Release|x86 + {CD7F7458-A273-4855-9744-4CCAFE0499D0}.CreateInstallerWithDemoProject|x86.Deploy.0 = Release|x86 {CD7F7458-A273-4855-9744-4CCAFE0499D0}.Debug|x86.ActiveCfg = Debug|x86 {CD7F7458-A273-4855-9744-4CCAFE0499D0}.Debug|x86.Build.0 = Debug|x86 {CD7F7458-A273-4855-9744-4CCAFE0499D0}.Release|x86.ActiveCfg = Release|x86 @@ -3720,6 +3723,14 @@ {33508D7C-1602-4C0D-8503-73AAE98C19E5}.Release|x86.Build.0 = Release|x86 {33508D7C-1602-4C0D-8503-73AAE98C19E5}.ReleaseForCodeCoverage|x86.ActiveCfg = ReleaseForCodeCoverage|x86 {33508D7C-1602-4C0D-8503-73AAE98C19E5}.ReleaseForCodeCoverage|x86.Build.0 = ReleaseForCodeCoverage|x86 + {516E7E2A-83F6-43EB-895A-A1F4F90FA531}.CreateInstaller|x86.ActiveCfg = Release|x86 + {516E7E2A-83F6-43EB-895A-A1F4F90FA531}.CreateInstallerWithDemoProject|x86.ActiveCfg = Release|x86 + {516E7E2A-83F6-43EB-895A-A1F4F90FA531}.Debug|x86.ActiveCfg = Debug|x86 + {516E7E2A-83F6-43EB-895A-A1F4F90FA531}.Debug|x86.Build.0 = Debug|x86 + {516E7E2A-83F6-43EB-895A-A1F4F90FA531}.Release|x86.ActiveCfg = Release|x86 + {516E7E2A-83F6-43EB-895A-A1F4F90FA531}.Release|x86.Build.0 = Release|x86 + {516E7E2A-83F6-43EB-895A-A1F4F90FA531}.ReleaseForCodeCoverage|x86.ActiveCfg = ReleaseForCodeCoverage|x86 + {516E7E2A-83F6-43EB-895A-A1F4F90FA531}.ReleaseForCodeCoverage|x86.Build.0 = ReleaseForCodeCoverage|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -4043,6 +4054,7 @@ {AA3AB46F-1664-40C4-A620-A12513184BD4} = {79419C3E-046C-4DC1-8C69-F14911F22C75} {3DEC1E30-0804-4BC9-8D04-4D7B4854E21B} = {1C1E8754-CF61-4858-9CEE-3E5DE344474F} {33508D7C-1602-4C0D-8503-73AAE98C19E5} = {B5F4F5A5-FD36-405D-ABA1-56C270207C8F} + {516E7E2A-83F6-43EB-895A-A1F4F90FA531} = {B5F4F5A5-FD36-405D-ABA1-56C270207C8F} EndGlobalSection GlobalSection(TextTemplating) = postSolution TextTemplating = 1 Index: Ringtoets/Common/src/Ringtoets.Common.Data/DikeProfiles/BreakWater.cs =================================================================== diff -u -r30b8231f92b90ea4b05e98e3d0285368f6dfe2e4 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Common/src/Ringtoets.Common.Data/DikeProfiles/BreakWater.cs (.../BreakWater.cs) (revision 30b8231f92b90ea4b05e98e3d0285368f6dfe2e4) +++ Ringtoets/Common/src/Ringtoets.Common.Data/DikeProfiles/BreakWater.cs (.../BreakWater.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -60,5 +60,36 @@ height = value.ToPrecision(height.NumberOfDecimalPlaces); } } + + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) + { + return false; + } + if (ReferenceEquals(this, obj)) + { + return true; + } + if (obj.GetType() != GetType()) + { + return false; + } + return Equals((BreakWater) obj); + } + + public override int GetHashCode() + { + unchecked + { + int hashCode = height.GetHashCode(); + return (hashCode * 397) ^ (int) Type; + } + } + + private bool Equals(BreakWater other) + { + return height.Equals(other.height) && Type == other.Type; + } } } \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Data/DikeProfiles/DikeProfile.cs =================================================================== diff -u -rba715436cd0186ee10a1edc13d547ee27bea4c89 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Common/src/Ringtoets.Common.Data/DikeProfiles/DikeProfile.cs (.../DikeProfile.cs) (revision ba715436cd0186ee10a1edc13d547ee27bea4c89) +++ Ringtoets/Common/src/Ringtoets.Common.Data/DikeProfiles/DikeProfile.cs (.../DikeProfile.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -22,6 +22,7 @@ using System; using System.Collections.Generic; using System.Linq; +using Core.Common.Base; using Core.Common.Base.Data; using Core.Common.Base.Geometry; using Ringtoets.Common.Data.Properties; @@ -31,7 +32,7 @@ /// /// Definition for a dike profile for a failure mechanism. /// - public class DikeProfile + public class DikeProfile : Observable { /// /// Creates a new instance of the class. @@ -44,8 +45,13 @@ /// Thrown when either , /// , or /// is null. - /// Thrown when any element of - /// or is null. + /// Thrown when: + /// + /// any element of + /// or is null. + /// is null, is empty + /// or whitespaces. + /// public DikeProfile(Point2D worldCoordinate, IEnumerable dikeGeometry, IEnumerable foreshoreGeometry, BreakWater breakWater, ConstructionProperties properties) { @@ -70,7 +76,7 @@ /// /// Gets the foreshore profile. /// - public ForeshoreProfile ForeshoreProfile { get; } + public ForeshoreProfile ForeshoreProfile { get; private set; } /// /// Gets the ID of the dike profile. @@ -177,19 +183,93 @@ /// public RoundedDouble DikeHeight { get; private set; } + /// + /// Copies all the properties of the to + /// the current instance. + /// + /// The dike profile to copy the properties + /// from. + /// Thrown when + /// is null. + public void CopyProperties(DikeProfile fromDikeProfile) + { + if (fromDikeProfile == null) + { + throw new ArgumentNullException(nameof(fromDikeProfile)); + } + + SetGeometry(fromDikeProfile.DikeGeometry); + DikeHeight = fromDikeProfile.DikeHeight; + CopyForeshoreProfileProperties(fromDikeProfile); + } + public override string ToString() { return Name; } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) + { + return false; + } + if (ReferenceEquals(this, obj)) + { + return true; + } + if (obj.GetType() != GetType()) + { + return false; + } + return Equals((DikeProfile) obj); + } + + public override int GetHashCode() + { + unchecked + { + int hashCode = ForeshoreProfile.GetHashCode(); + hashCode = (hashCode * 397) ^ DikeHeight.GetHashCode(); + + foreach (RoughnessPoint point in DikeGeometry) + { + hashCode = (hashCode * 397) ^ point.GetHashCode(); + } + + return hashCode; + } + } + + private void CopyForeshoreProfileProperties(DikeProfile fromDikeProfile) + { + ForeshoreProfile = new ForeshoreProfile(fromDikeProfile.WorldReferencePoint, + fromDikeProfile.ForeshoreGeometry, + fromDikeProfile.BreakWater, + new ForeshoreProfile.ConstructionProperties + { + Id = fromDikeProfile.Id, + Name = fromDikeProfile.Name, + Orientation = fromDikeProfile.Orientation, + X0 = fromDikeProfile.X0 + }); + } + + private bool Equals(DikeProfile other) + { + return Equals(ForeshoreProfile, other.ForeshoreProfile) + && DikeHeight.Equals(other.DikeHeight) + && EqualDikeGeometry(other.DikeGeometry); + } + private void SetGeometry(IEnumerable points) { if (points == null) { throw new ArgumentNullException(nameof(points), Resources.DikeProfile_SetGeometry_Collection_of_points_for_geometry_is_null); } - var roughnessPoints = points.ToArray(); + RoughnessPoint[] roughnessPoints = points.ToArray(); if (roughnessPoints.Any(p => p == null)) { throw new ArgumentException(Resources.DikeProfile_SetGeometry_A_point_in_the_collection_is_null); @@ -198,6 +278,25 @@ DikeGeometry = roughnessPoints; } + private bool EqualDikeGeometry(RoughnessPoint[] otherPoints) + { + int nrOfPoints = DikeGeometry.Length; + if (otherPoints.Length != nrOfPoints) + { + return false; + } + + for (var i = 0; i < nrOfPoints; i++) + { + if (!DikeGeometry[i].Equals(otherPoints[i])) + { + return false; + } + } + + return true; + } + /// /// Class holding the various construction parameters for . /// Index: Ringtoets/Common/src/Ringtoets.Common.Data/DikeProfiles/DikeProfileCollection.cs =================================================================== diff -u --- Ringtoets/Common/src/Ringtoets.Common.Data/DikeProfiles/DikeProfileCollection.cs (revision 0) +++ Ringtoets/Common/src/Ringtoets.Common.Data/DikeProfiles/DikeProfileCollection.cs (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -0,0 +1,40 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using Core.Common.Base; +using Ringtoets.Common.Data.Properties; + +namespace Ringtoets.Common.Data.DikeProfiles +{ + /// + /// A collection of . The ids of the + /// are unique within the collection. + /// + public class DikeProfileCollection : ObservableUniqueItemCollectionWithSourcePath + { + /// + /// Instantiates a . + /// + public DikeProfileCollection() : base(profile => profile.Id, + Resources.DikeProfileCollection_TypeDescriptor, + Resources.DikeProfileCollection_UniqueFeature_id_FeatureDescription) {} + } +} \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Data/DikeProfiles/ForeshoreProfile.cs =================================================================== diff -u -r5e44a4eb7c69ccaca763dce7cd7735e33a1f3c85 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Common/src/Ringtoets.Common.Data/DikeProfiles/ForeshoreProfile.cs (.../ForeshoreProfile.cs) (revision 5e44a4eb7c69ccaca763dce7cd7735e33a1f3c85) +++ Ringtoets/Common/src/Ringtoets.Common.Data/DikeProfiles/ForeshoreProfile.cs (.../ForeshoreProfile.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -131,9 +131,56 @@ return Name; } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) + { + return false; + } + if (ReferenceEquals(this, obj)) + { + return true; + } + if (obj.GetType() != GetType()) + { + return false; + } + return Equals((ForeshoreProfile) obj); + } + + public override int GetHashCode() + { + unchecked + { + int hashCode = Id.GetHashCode(); + hashCode = (hashCode * 397) ^ (Name?.GetHashCode() ?? 0); + hashCode = (hashCode * 397) ^ WorldReferencePoint.GetHashCode(); + hashCode = (hashCode * 397) ^ X0.GetHashCode(); + hashCode = (hashCode * 397) ^ Orientation.GetHashCode(); + hashCode = (hashCode * 397) ^ (BreakWater?.GetHashCode() ?? 0); + + foreach (Point2D point in Geometry) + { + hashCode = (hashCode * 397) ^ point.GetHashCode(); + } + return hashCode; + } + } + + private bool Equals(ForeshoreProfile other) + { + return Id.Equals(other.Id) + && string.Equals(Name, other.Name) + && WorldReferencePoint.Equals(other.WorldReferencePoint) + && X0.Equals(other.X0) + && Orientation.Equals(other.Orientation) + && Equals(BreakWater, other.BreakWater) + && EqualGeometry(other.Geometry.ToArray()); + } + private void SetGeometry(IEnumerable points) { - var foreshorePoints = points.ToArray(); + Point2D[] foreshorePoints = points.ToArray(); if (foreshorePoints.Any(p => p == null)) { throw new ArgumentException(Resources.ForeshoreProfile_SetGeometry_A_point_in_the_collection_is_null); @@ -142,6 +189,26 @@ Geometry = new RoundedPoint2DCollection(2, foreshorePoints); } + private bool EqualGeometry(Point2D[] otherGeometry) + { + Point2D[] pointsArray = Geometry.ToArray(); + + int nrOfPoints = pointsArray.Length; + if (otherGeometry.Length != nrOfPoints) + { + return false; + } + + for (var i = 0; i < nrOfPoints; i++) + { + if (!pointsArray[i].Equals(otherGeometry[i])) + { + return false; + } + } + return true; + } + /// /// Class holding the various construction parameters for . /// Index: Ringtoets/Common/src/Ringtoets.Common.Data/DikeProfiles/RoughnessPoint.cs =================================================================== diff -u -rb2b9fdf365e70928a05c57966eeed30d9050e528 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Common/src/Ringtoets.Common.Data/DikeProfiles/RoughnessPoint.cs (.../RoughnessPoint.cs) (revision b2b9fdf365e70928a05c57966eeed30d9050e528) +++ Ringtoets/Common/src/Ringtoets.Common.Data/DikeProfiles/RoughnessPoint.cs (.../RoughnessPoint.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -59,5 +59,38 @@ /// Gets the roughness of the . /// public RoundedDouble Roughness { get; private set; } + + public override bool Equals(object obj) + { + + if (ReferenceEquals(null, obj)) + { + return false; + } + if (ReferenceEquals(this, obj)) + { + return true; + } + if (obj.GetType() != GetType()) + { + return false; + } + return Equals((RoughnessPoint)obj); + } + + private bool Equals(RoughnessPoint other) + { + return Equals(Point, other.Point) && Roughness.Equals(other.Roughness); + } + + public override int GetHashCode() + { + unchecked + { + int hashCode = Roughness.GetHashCode(); + hashCode = (hashCode * 397) ^ (Point?.GetHashCode() ?? 0); + return hashCode; + } + } } } \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Data/Exceptions/DikeProfileUpdateException.cs =================================================================== diff -u --- Ringtoets/Common/src/Ringtoets.Common.Data/Exceptions/DikeProfileUpdateException.cs (revision 0) +++ Ringtoets/Common/src/Ringtoets.Common.Data/Exceptions/DikeProfileUpdateException.cs (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -0,0 +1,68 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Runtime.Serialization; + +namespace Ringtoets.Common.Data.Exceptions +{ + /// + /// Exception that is thrown when updating data of a dike profile has failed. + /// + [Serializable] + public class DikeProfileUpdateException : Exception + { + /// + /// Initializes a new instance of the class. + /// + public DikeProfileUpdateException() {} + + /// + /// Initializes a new instance of the class + /// with a specified error message. + /// + /// The error message that explains the reason for the exception. + public DikeProfileUpdateException(string message) : base(message) {} + + /// + /// Initializes a new instance of the class + /// with a specified error message and a reference to the inner exception that is + /// the cause of this exception. + /// + /// The error message that explains the reason for the exception. + /// The exception that is the cause of the current exception, + /// or null if no inner exception is specified. + public DikeProfileUpdateException(string message, Exception inner) : base(message, inner) {} + + /// + /// Initializes a new instance of with + /// serialized data. + /// The that holds the serialized + /// object data about the exception being thrown. + /// The that contains contextual + /// information about the source or destination. + /// The parameter is + /// null. + /// The class name is null or + /// is zero (0). + protected DikeProfileUpdateException(SerializationInfo info, StreamingContext context) : base(info, context) {} + } +} \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Data/Exceptions/UpdateDataException.cs =================================================================== diff -u --- Ringtoets/Common/src/Ringtoets.Common.Data/Exceptions/UpdateDataException.cs (revision 0) +++ Ringtoets/Common/src/Ringtoets.Common.Data/Exceptions/UpdateDataException.cs (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -0,0 +1,68 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Runtime.Serialization; + +namespace Ringtoets.Common.Data.Exceptions +{ + /// + /// Exception that is thrown when updating data has failed. + /// + [Serializable] + public class UpdateDataException : Exception + { + /// + /// Initializes a new instance of the class. + /// + public UpdateDataException() {} + + /// + /// Initializes a new instance of the class + /// with a specified error message. + /// + /// The error message that explains the reason for the exception. + public UpdateDataException(string message) : base(message) {} + + /// + /// Initializes a new instance of the class + /// with a specified error message and a reference to the inner exception that is + /// the cause of this exception. + /// + /// The error message that explains the reason for the exception. + /// The exception that is the cause of the current exception, + /// or null if no inner exception is specified. + public UpdateDataException(string message, Exception inner) : base(message, inner) {} + + /// + /// Initializes a new instance of with + /// serialized data. + /// The that holds the serialized + /// object data about the exception being thrown. + /// The that contains contextual + /// information about the source or destination. + /// The parameter is + /// null. + /// The class name is null or + /// is zero (0). + protected UpdateDataException(SerializationInfo info, StreamingContext context) : base(info, context) {} + } +} \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Data/Properties/Resources.Designer.cs =================================================================== diff -u -r49bbac8914b80005625cc41f2dee8a4812b67ab8 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Common/src/Ringtoets.Common.Data/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 49bbac8914b80005625cc41f2dee8a4812b67ab8) +++ Ringtoets/Common/src/Ringtoets.Common.Data/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -335,6 +335,24 @@ } /// + /// Looks up a localized string similar to Dijkprofielen. + /// + public static string DikeProfileCollection_TypeDescriptor { + get { + return ResourceManager.GetString("DikeProfileCollection_TypeDescriptor", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to id. + /// + public static string DikeProfileCollection_UniqueFeature_id_FeatureDescription { + get { + return ResourceManager.GetString("DikeProfileCollection_UniqueFeature_id_FeatureDescription", resourceCulture); + } + } + + /// /// Looks up a localized string similar to Berekeningen. /// public static string FailureMechanism_Calculations_DisplayName { @@ -578,5 +596,15 @@ return ResourceManager.GetString("StructureInflowModelType_LowSill_DisplayName", resourceCulture); } } + + /// + /// Looks up a localized string similar to Geïmporteerde data moet unieke elementen bevatten.. + /// + public static string UpdateDataStrategyBase_UpdateTargetCollectionData_Imported_data_must_contain_unique_items { + get { + return ResourceManager.GetString("UpdateDataStrategyBase_UpdateTargetCollectionData_Imported_data_must_contain_uniq" + + "ue_items", resourceCulture); + } + } } } Index: Ringtoets/Common/src/Ringtoets.Common.Data/Properties/Resources.resx =================================================================== diff -u -r49bbac8914b80005625cc41f2dee8a4812b67ab8 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Common/src/Ringtoets.Common.Data/Properties/Resources.resx (.../Resources.resx) (revision 49bbac8914b80005625cc41f2dee8a4812b67ab8) +++ Ringtoets/Common/src/Ringtoets.Common.Data/Properties/Resources.resx (.../Resources.resx) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -282,4 +282,13 @@ OpenStreetMap + + Geïmporteerde data moet unieke elementen bevatten. + + + Dijkprofielen + + + id + \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Data/Ringtoets.Common.Data.csproj =================================================================== diff -u -rc90fad2c6d012238ac0b62e52f9820047de76ad6 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Common/src/Ringtoets.Common.Data/Ringtoets.Common.Data.csproj (.../Ringtoets.Common.Data.csproj) (revision c90fad2c6d012238ac0b62e52f9820047de76ad6) +++ Ringtoets/Common/src/Ringtoets.Common.Data/Ringtoets.Common.Data.csproj (.../Ringtoets.Common.Data.csproj) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -53,9 +53,11 @@ + + @@ -110,6 +112,7 @@ + Index: Ringtoets/Common/src/Ringtoets.Common.Data/UpdateDataStrategies/ReplaceDataStrategyBase.cs =================================================================== diff -u -rdd4e75e27880fc06f6823cca424a010ab19adb33 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Common/src/Ringtoets.Common.Data/UpdateDataStrategies/ReplaceDataStrategyBase.cs (.../ReplaceDataStrategyBase.cs) (revision dd4e75e27880fc06f6823cca424a010ab19adb33) +++ Ringtoets/Common/src/Ringtoets.Common.Data/UpdateDataStrategies/ReplaceDataStrategyBase.cs (.../ReplaceDataStrategyBase.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -22,6 +22,7 @@ using System; using System.Collections.Generic; using Core.Common.Base; +using Ringtoets.Common.Data.Exceptions; using Ringtoets.Common.Data.FailureMechanism; namespace Ringtoets.Common.Data.UpdateDataStrategies @@ -33,8 +34,8 @@ /// The target data type. /// The failure mechanism in which the target collection should be updated. public abstract class ReplaceDataStrategyBase - where TTargetData : class - where TFailureMechanism : IFailureMechanism + where TTargetData : class + where TFailureMechanism : IFailureMechanism { private readonly TFailureMechanism failureMechanism; @@ -63,27 +64,22 @@ protected abstract IEnumerable ClearData(TFailureMechanism failureMechanism); /// - /// Replaces the data of the with the imported data in . + /// Replaces the data of the with the imported data in . /// - /// The collection that needs to be updated. + /// The collection that needs to be updated. /// The data that was imported. /// The source file path where the imported data comes from. /// An with affected objects. /// Thrown when any of the input parameters are null. - /// Thrown when: - /// - /// contains null items. - /// contains duplicate items. - /// is not a valid file path - /// + /// Thrown when replacing the data has failed. protected IEnumerable ReplaceTargetCollectionWithImportedData( - ObservableUniqueItemCollectionWithSourcePath targetCollection, + ObservableUniqueItemCollectionWithSourcePath targetDataCollection, IEnumerable importedDataCollection, string sourceFilePath) { - if (targetCollection == null) + if (targetDataCollection == null) { - throw new ArgumentNullException(nameof(targetCollection)); + throw new ArgumentNullException(nameof(targetDataCollection)); } if (importedDataCollection == null) { @@ -96,15 +92,30 @@ var affectedObjects = new List(); affectedObjects.AddRange(ClearData(failureMechanism)); - AddData(targetCollection, importedDataCollection, sourceFilePath); + AddData(targetDataCollection, importedDataCollection, sourceFilePath); return affectedObjects; } + /// + /// Adds read data from the to the . + /// + /// The target collection which needs to be updated. + /// The data that was imported. + /// The source file path where the imported data comes from. + /// Thrown when an error occurs while + /// adding data to the . private static void AddData(ObservableUniqueItemCollectionWithSourcePath targetCollection, - IEnumerable readData, string sourceFilePath) + IEnumerable importedDataCollection, string sourceFilePath) { - targetCollection.AddRange(readData, sourceFilePath); + try + { + targetCollection.AddRange(importedDataCollection, sourceFilePath); + } + catch (ArgumentException e) + { + throw new UpdateDataException(e.Message, e); + } } } } \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Data/UpdateDataStrategies/UpdateDataStrategyBase.cs =================================================================== diff -u -r9997d3038d16fb710ffc92f95c781639d63d7855 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Common/src/Ringtoets.Common.Data/UpdateDataStrategies/UpdateDataStrategyBase.cs (.../UpdateDataStrategyBase.cs) (revision 9997d3038d16fb710ffc92f95c781639d63d7855) +++ Ringtoets/Common/src/Ringtoets.Common.Data/UpdateDataStrategies/UpdateDataStrategyBase.cs (.../UpdateDataStrategyBase.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -24,7 +24,9 @@ using System.Linq; using Core.Common.Base; using Core.Common.Utils; +using Ringtoets.Common.Data.Exceptions; using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.Common.Data.Properties; namespace Ringtoets.Common.Data.UpdateDataStrategies { @@ -42,7 +44,7 @@ where TTargetData : class where TFailureMechanism : IFailureMechanism { - protected readonly TFailureMechanism failureMechanism; + protected readonly TFailureMechanism FailureMechanism; private readonly IEqualityComparer equalityComparer; /// @@ -63,7 +65,7 @@ } this.equalityComparer = equalityComparer; - this.failureMechanism = failureMechanism; + FailureMechanism = failureMechanism; } /// @@ -92,11 +94,7 @@ /// the . /// The source file path. /// A of affected objects. - /// Thrown when any of the input parameters are null. - /// Thrown when duplicate items are being added to the - /// . - /// Thrown when duplicate items are found during the - /// update of the items in the . + /// Thrown when an error occurred while updating the data. protected IEnumerable UpdateTargetCollectionData(ObservableUniqueItemCollectionWithSourcePath targetDataCollection, IEnumerable importedDataCollection, string sourceFilePath) @@ -114,7 +112,18 @@ throw new ArgumentNullException(nameof(sourceFilePath)); } - return ModifyDataCollection(targetDataCollection, importedDataCollection, sourceFilePath); + try + { + return ModifyDataCollection(targetDataCollection, importedDataCollection, sourceFilePath); + } + catch (ArgumentException e) + { + throw new UpdateDataException(e.Message, e); + } + catch (InvalidOperationException e) + { + throw new UpdateDataException(Resources.UpdateDataStrategyBase_UpdateTargetCollectionData_Imported_data_must_contain_unique_items, e); + } } /// @@ -169,11 +178,14 @@ } /// - /// Updates all the objects and their dependent data that needs to be updated with data from the imported data collection. + /// Updates all the objects and their dependent data that needs to be + /// updated with data from the imported data collection. /// /// The objects that need to be updated. /// The data to update from. /// A of affected items. + /// Thrown when the imported + /// contains duplicate items. private IEnumerable UpdateData(IEnumerable objectsToUpdate, IEnumerable importedDataCollection) { Index: Ringtoets/Common/src/Ringtoets.Common.Forms/ChangeHandlers/FailureMechanismCalculationChangeHandler.cs =================================================================== diff -u --- Ringtoets/Common/src/Ringtoets.Common.Forms/ChangeHandlers/FailureMechanismCalculationChangeHandler.cs (revision 0) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/ChangeHandlers/FailureMechanismCalculationChangeHandler.cs (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -0,0 +1,79 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Linq; +using Core.Common.Gui; +using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.Common.IO; + +namespace Ringtoets.Common.Forms.ChangeHandlers +{ + /// + /// Class which can, if required, inquire the user for a confirmation when a change to the + /// failure mechanism requires calculation results to be altered. + /// + public class FailureMechanismCalculationChangeHandler : IConfirmDataChangeHandler + { + private readonly string query; + private readonly IFailureMechanism failureMechanism; + private readonly IInquiryHelper inquiryHandler; + + /// + /// Creates a new instance of . + /// + /// Failure mechanism for which to handle changes of the failure mechanism. + /// The query which should be displayed when inquiring for a confirmation. + /// Object responsible for inquiring required data. + /// Thrown when any input parameter is null. + public FailureMechanismCalculationChangeHandler(IFailureMechanism failureMechanism, + string query, + IInquiryHelper inquiryHandler) + { + if (failureMechanism == null) + { + throw new ArgumentNullException(nameof(failureMechanism)); + } + if (query == null) + { + throw new ArgumentNullException(nameof(query)); + } + if (inquiryHandler == null) + { + throw new ArgumentNullException(nameof(inquiryHandler)); + } + + this.failureMechanism = failureMechanism; + this.query = query; + this.inquiryHandler = inquiryHandler; + } + + public bool RequireConfirmation() + { + return failureMechanism.Calculations.Any(calc => calc.HasOutput); + } + + public bool InquireConfirmation() + { + return inquiryHandler.InquireContinuation(query); + } + } +} \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.Designer.cs =================================================================== diff -u -r92df0a0ac0a4e0ccd5d7505d748f55167c2aac81 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 92df0a0ac0a4e0ccd5d7505d748f55167c2aac81) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -710,6 +710,15 @@ } /// + /// Looks up a localized string similar to Er zijn geen berekeningen om bij te werken.. + /// + public static string CreateUpdateContextMenuItem_No_calculations_to_update_ToolTip { + get { + return ResourceManager.GetString("CreateUpdateContextMenuItem_No_calculations_to_update_ToolTip", resourceCulture); + } + } + + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// public static System.Drawing.Bitmap DatabaseIcon { Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.resx =================================================================== diff -u -r92df0a0ac0a4e0ccd5d7505d748f55167c2aac81 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.resx (.../Resources.resx) (revision 92df0a0ac0a4e0ccd5d7505d748f55167c2aac81) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.resx (.../Resources.resx) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -935,4 +935,7 @@ Ringtoets berekeningenconfiguratie (*.xml) + + Er zijn geen berekeningen om bij te werken. + \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Ringtoets.Common.Forms.csproj =================================================================== diff -u -rf1f130fa156455abb12b76404c36be9c71f797df -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Common/src/Ringtoets.Common.Forms/Ringtoets.Common.Forms.csproj (.../Ringtoets.Common.Forms.csproj) (revision f1f130fa156455abb12b76404c36be9c71f797df) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/Ringtoets.Common.Forms.csproj (.../Ringtoets.Common.Forms.csproj) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -47,6 +47,7 @@ Properties\GlobalAssembly.cs + Index: Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/DikeProfilesImporter.cs =================================================================== diff -u -r1f549a37af503f5da697652b5e5199f8d29ac0fe -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/DikeProfilesImporter.cs (.../DikeProfilesImporter.cs) (revision 1f549a37af503f5da697652b5e5199f8d29ac0fe) +++ Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/DikeProfilesImporter.cs (.../DikeProfilesImporter.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -27,42 +27,62 @@ using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.DikeProfiles; using Ringtoets.Common.IO.DikeProfiles; +using Ringtoets.Common.IO.FileImporters.MessageProviders; using Ringtoets.Common.IO.Properties; +using RingtoetsCommonDataResources = Ringtoets.Common.Data.Properties.Resources; namespace Ringtoets.Common.IO.FileImporters { /// /// Imports point shapefiles containing dike profile locations and text files containing dike schematizations. /// - public class DikeProfilesImporter : ProfilesImporter> + public class DikeProfilesImporter : ProfilesImporter { + private readonly IDikeProfileUpdateDataStrategy dikeProfileUpdateDataStrategy; + private IEnumerable updatedInstances; + /// /// Creates a new instance of . /// /// The dike profiles to import on. /// The reference line used to check if the /// objects found in the file are intersecting it. /// The path to the file to import from. - /// Thrown when , - /// or is null. - public DikeProfilesImporter(ObservableList importTarget, ReferenceLine referenceLine, string filePath) - : base(referenceLine, filePath, importTarget) {} + /// The strategy to update the dike profiles + /// with the imported data. + /// The message provide to provide the messages during importer action. + /// Thrown when any input parameter is null. + public DikeProfilesImporter(DikeProfileCollection importTarget, ReferenceLine referenceLine, + string filePath, + IDikeProfileUpdateDataStrategy dikeProfileUpdateStrategy, + IImporterMessageProvider messageProvider) + : base(referenceLine, filePath, importTarget, messageProvider) + { + if (dikeProfileUpdateStrategy == null) + { + throw new ArgumentNullException(nameof(dikeProfileUpdateStrategy)); + } + dikeProfileUpdateDataStrategy = dikeProfileUpdateStrategy; + updatedInstances = Enumerable.Empty(); + } + protected override void CreateProfiles(ReadResult importProfileLocationResult, ReadResult importDikeProfileDataResult) { IEnumerable importedDikeProfiles = CreateDikeProfiles(importProfileLocationResult.Items, importDikeProfileDataResult.Items); - foreach (DikeProfile dikeProfile in importedDikeProfiles) - { - ImportTarget.Add(dikeProfile); - } + updatedInstances = dikeProfileUpdateDataStrategy.UpdateDikeProfilesWithImportedData(ImportTarget, + importedDikeProfiles, + FilePath); } protected override void LogImportCanceledMessage() { - Log.Info(Resources.DikeProfilesImporter_HandleUserCancelingImport_dikeprofile_import_aborted); + string logMessage = MessageProvider.GetCancelledLogMessageText( + RingtoetsCommonDataResources.DikeProfileCollection_TypeDescriptor); + Log.Info(logMessage); } protected override bool DikeProfileDataIsValid(DikeProfileData data, string prflFilePath) @@ -75,6 +95,14 @@ return false; } + protected override void DoPostImportUpdates() + { + foreach (IObservable updatedInstance in updatedInstances) + { + updatedInstance.NotifyObservers(); + } + } + private IEnumerable CreateDikeProfiles(IEnumerable dikeProfileLocationCollection, ICollection dikeProfileDataCollection) { @@ -83,7 +111,7 @@ { string id = dikeProfileLocation.Id; - var dikeProfileData = GetMatchingDikeProfileData(dikeProfileDataCollection, id); + DikeProfileData dikeProfileData = GetMatchingDikeProfileData(dikeProfileDataCollection, id); if (dikeProfileData == null) { Log.ErrorFormat(Resources.DikeProfilesImporter_GetMatchingDikeProfileData_no_dikeprofiledata_for_location_0_, id); @@ -99,7 +127,7 @@ private static DikeProfile CreateDikeProfile(ProfileLocation dikeProfileLocation, DikeProfileData dikeProfileData) { - var dikeProfile = new DikeProfile(dikeProfileLocation.Point, dikeProfileData.DikeGeometry, + return new DikeProfile(dikeProfileLocation.Point, dikeProfileData.DikeGeometry, dikeProfileData.ForeshoreGeometry.Select(fg => fg.Point).ToArray(), CreateBreakWater(dikeProfileData), new DikeProfile.ConstructionProperties @@ -110,8 +138,6 @@ Orientation = dikeProfileData.Orientation, DikeHeight = dikeProfileData.DikeHeight }); - - return dikeProfile; } } } \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/ForeshoreProfilesImporter.cs =================================================================== diff -u -r1f549a37af503f5da697652b5e5199f8d29ac0fe -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/ForeshoreProfilesImporter.cs (.../ForeshoreProfilesImporter.cs) (revision 1f549a37af503f5da697652b5e5199f8d29ac0fe) +++ Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/ForeshoreProfilesImporter.cs (.../ForeshoreProfilesImporter.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -27,6 +27,7 @@ using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.DikeProfiles; using Ringtoets.Common.IO.DikeProfiles; +using Ringtoets.Common.IO.FileImporters.MessageProviders; using Ringtoets.Common.IO.Properties; namespace Ringtoets.Common.IO.FileImporters @@ -46,7 +47,7 @@ /// Thrown when , /// or is null. public ForeshoreProfilesImporter(ObservableList importTarget, ReferenceLine referenceLine, string filePath) - : base(referenceLine, filePath, importTarget) {} + : base(referenceLine, filePath, importTarget, new ImportMessageProvider()) {} protected override void CreateProfiles(ReadResult importProfileLocationResult, ReadResult importDikeProfileDataResult) Index: Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/IDikeProfileUpdateDataStrategy.cs =================================================================== diff -u --- Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/IDikeProfileUpdateDataStrategy.cs (revision 0) +++ Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/IDikeProfileUpdateDataStrategy.cs (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -0,0 +1,54 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Collections.Generic; +using Core.Common.Base; +using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.Common.Data.Exceptions; + +namespace Ringtoets.Common.IO.FileImporters +{ + /// + /// Interface describing the method of updating the date model after new + /// dike profiles have been imported. + /// + public interface IDikeProfileUpdateDataStrategy + { + /// + /// Adds the imported data to the . + /// + /// The target collection which needs + /// to be updated. + /// The imported dike profiles. + /// The source path from where the dike profiles + /// were imported from. + /// An of updated instances. + /// Thrown when any input + /// argument is null. + /// Thrown + /// when applying the strategy has failed. + IEnumerable UpdateDikeProfilesWithImportedData( + DikeProfileCollection targetDataCollection, + IEnumerable importedDataCollection, + string sourceFilePath); + } +} \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/ProfilesImporter.cs =================================================================== diff -u -rba715436cd0186ee10a1edc13d547ee27bea4c89 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/ProfilesImporter.cs (.../ProfilesImporter.cs) (revision ba715436cd0186ee10a1edc13d547ee27bea4c89) +++ Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/ProfilesImporter.cs (.../ProfilesImporter.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -33,6 +33,7 @@ using Ringtoets.Common.Data.DikeProfiles; using Ringtoets.Common.IO.DikeProfiles; using Ringtoets.Common.IO.Exceptions; +using Ringtoets.Common.IO.FileImporters.MessageProviders; using Ringtoets.Common.IO.Properties; namespace Ringtoets.Common.IO.FileImporters @@ -46,23 +47,31 @@ { protected readonly ILog Log = LogManager.GetLogger(typeof(ProfilesImporter)); private readonly ReferenceLine referenceLine; + protected readonly IImporterMessageProvider MessageProvider; /// /// Initializes a new instance of . /// /// The reference line used to check if the imported profiles are intersecting it. /// The path to the file to import from. /// The import target. + /// The message provider to provide messages during the import. /// Thrown when , /// or is null. - protected ProfilesImporter(ReferenceLine referenceLine, string filePath, T importTarget) : base(filePath, importTarget) + protected ProfilesImporter(ReferenceLine referenceLine, string filePath, T importTarget, + IImporterMessageProvider messageProvider) : base(filePath, importTarget) { if (referenceLine == null) { throw new ArgumentNullException(nameof(referenceLine)); } + if (messageProvider == null) + { + throw new ArgumentNullException(nameof(messageProvider)); + } this.referenceLine = referenceLine; + MessageProvider = messageProvider; } protected override bool OnImport() @@ -81,7 +90,7 @@ return false; } - NotifyProgress(Resources.Importer_ProgressText_Adding_imported_data_to_data_model, 1, 1); + NotifyProgress(MessageProvider.GetAddDataToModelProgressText(), 1, 1); CreateProfiles(importDikeProfilesResult, importDikeProfileDataResult); return true; Index: Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.Designer.cs =================================================================== diff -u -rb09f4737de300a8cdedc66f9d6ade8bffbd4f619 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision b09f4737de300a8cdedc66f9d6ade8bffbd4f619) +++ Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -640,21 +640,21 @@ } /// - /// Looks up a localized string similar to Kan geen geldige gegevens vinden voor dijkprofiellocatie met ID '{0}'.. + /// Looks up a localized string similar to Dijkprofiellocaties. /// - public static string DikeProfilesImporter_GetMatchingDikeProfileData_no_dikeprofiledata_for_location_0_ { + public static string DikeProfilesImporter_DisplayName { get { - return ResourceManager.GetString("DikeProfilesImporter_GetMatchingDikeProfileData_no_dikeprofiledata_for_location_0" + - "_", resourceCulture); + return ResourceManager.GetString("DikeProfilesImporter_DisplayName", resourceCulture); } } /// - /// Looks up a localized string similar to Dijkprofielen importeren is afgebroken. Geen gegevens ingelezen.. + /// Looks up a localized string similar to Kan geen geldige gegevens vinden voor dijkprofiellocatie met ID '{0}'.. /// - public static string DikeProfilesImporter_HandleUserCancelingImport_dikeprofile_import_aborted { + public static string DikeProfilesImporter_GetMatchingDikeProfileData_no_dikeprofiledata_for_location_0_ { get { - return ResourceManager.GetString("DikeProfilesImporter_HandleUserCancelingImport_dikeprofile_import_aborted", resourceCulture); + return ResourceManager.GetString("DikeProfilesImporter_GetMatchingDikeProfileData_no_dikeprofiledata_for_location_0" + + "_", resourceCulture); } } Index: Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.resx =================================================================== diff -u -rb09f4737de300a8cdedc66f9d6ade8bffbd4f619 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.resx (.../Resources.resx) (revision b09f4737de300a8cdedc66f9d6ade8bffbd4f619) +++ Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.resx (.../Resources.resx) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -354,9 +354,6 @@ Kan geen geldige gegevens vinden voor dijkprofiellocatie met ID '{0}'. - - Dijkprofielen importeren is afgebroken. Geen gegevens ingelezen. - Profielgegevens definiëren geen dijkgeometrie. Bestand '{0}' wordt overgeslagen. @@ -643,4 +640,7 @@ Er kan geen spreiding voor stochast 'afvoercoefficient' opgegeven worden. + + Dijkprofiellocaties + \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.IO/Ringtoets.Common.IO.csproj =================================================================== diff -u -r52cc989dff0f8f10fe0db1222ca2bd386c1d8188 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Common/src/Ringtoets.Common.IO/Ringtoets.Common.IO.csproj (.../Ringtoets.Common.IO.csproj) (revision 52cc989dff0f8f10fe0db1222ca2bd386c1d8188) +++ Ringtoets/Common/src/Ringtoets.Common.IO/Ringtoets.Common.IO.csproj (.../Ringtoets.Common.IO.csproj) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -75,6 +75,7 @@ + Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/DikeProfiles/BreakWaterTest.cs =================================================================== diff -u -r30b8231f92b90ea4b05e98e3d0285368f6dfe2e4 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Common/test/Ringtoets.Common.Data.Test/DikeProfiles/BreakWaterTest.cs (.../BreakWaterTest.cs) (revision 30b8231f92b90ea4b05e98e3d0285368f6dfe2e4) +++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/DikeProfiles/BreakWaterTest.cs (.../BreakWaterTest.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -32,11 +32,11 @@ public void Constructor_Always_ExpectedValues() { // Setup - BreakWaterType type = BreakWaterType.Caisson; + const BreakWaterType type = BreakWaterType.Caisson; const double height = 100.1; // Call - BreakWater breakWater = new BreakWater(type, height); + var breakWater = new BreakWater(type, height); // Assert Assert.AreEqual(type, breakWater.Type); @@ -50,9 +50,9 @@ public void Properties_Type_ReturnsExpectedValue(BreakWaterType newType) { // Setup - BreakWaterType type = BreakWaterType.Caisson; + const BreakWaterType type = BreakWaterType.Caisson; const double height = 100.1; - BreakWater breakWater = new BreakWater(type, height); + var breakWater = new BreakWater(type, height); // Call breakWater.Type = newType; @@ -65,15 +65,166 @@ public void Properties_Height_ReturnsExpectedValue() { // Setup - BreakWaterType type = BreakWaterType.Caisson; + const BreakWaterType type = BreakWaterType.Caisson; const double height = 100.10; - BreakWater breakWater = new BreakWater(type, height); + var breakWater = new BreakWater(type, height); // Call breakWater.Height = (RoundedDouble) 10.00; // Assert Assert.AreEqual(10.0, breakWater.Height.Value); } + + [Test] + public void Equals_ToItself_ReturnsTrue() + { + // Setup + var breakWater = new BreakWater(BreakWaterType.Caisson, 100.10); + + // Call + bool isBreakWaterEqualToItself = breakWater.Equals(breakWater); + + // Assert + Assert.IsTrue(isBreakWaterEqualToItself); + } + + [Test] + public void Equals_AllPropertiesEqual_ReturnsTrue() + { + // Setup + const BreakWaterType type = BreakWaterType.Caisson; + const double height = 100.10; + + var breakWaterOne = new BreakWater(type, height); + var breakWaterTwo = new BreakWater(type, height); + + // Call + bool isBreakWaterOneEqualToTwo = breakWaterOne.Equals(breakWaterTwo); + bool isBreakWaterTwoEqualToOne = breakWaterTwo.Equals(breakWaterOne); + + // Assert + Assert.IsTrue(isBreakWaterOneEqualToTwo); + Assert.IsTrue(isBreakWaterTwoEqualToOne); + } + + [Test] + public void Equals_ToSameReference_ReturnsTrue() + { + // Setup + var breakWaterOne = new BreakWater(BreakWaterType.Caisson, 100.10); + BreakWater breakWaterTwo = breakWaterOne; + + // Call + bool isBreakWaterOneEqualToTwo = breakWaterOne.Equals(breakWaterTwo); + bool isBreakWaterTwoEqualToOne = breakWaterTwo.Equals(breakWaterOne); + + // Assert + Assert.IsTrue(isBreakWaterOneEqualToTwo); + Assert.IsTrue(isBreakWaterTwoEqualToOne); + } + + [Test] + public void Equals_TransitivePropertyEqualBreakWater_ReturnsTrue() + { + // Setup + const BreakWaterType type = BreakWaterType.Caisson; + const double height = 100.10; + + var breakWaterOne = new BreakWater(type, height); + var breakWaterTwo = new BreakWater(type, height); + var breakWaterThree = new BreakWater(type, height); + + // Call + bool isBreakWaterOneEqualToTwo = breakWaterOne.Equals(breakWaterTwo); + bool isBreakWaterTwoEqualToThree = breakWaterTwo.Equals(breakWaterThree); + bool isBreakWaterOneEqualToThree = breakWaterOne.Equals(breakWaterThree); + + // Assert + Assert.IsTrue(isBreakWaterOneEqualToTwo); + Assert.IsTrue(isBreakWaterTwoEqualToThree); + Assert.IsTrue(isBreakWaterOneEqualToThree); + } + + [Test] + public void Equals_ToNull_ReturnsFalse() + { + // Setup + var breakWater = new BreakWater(BreakWaterType.Caisson, 100.10); + + // Call + bool isBreakWaterEqualToNull = breakWater.Equals(null); + + // Assert + Assert.IsFalse(isBreakWaterEqualToNull); + } + + [Test] + public void Equals_ToDifferentType_ReturnsFalse() + { + // Setup + var breakWater = new BreakWater(BreakWaterType.Caisson, 100.10); + var differentType = new object(); + + // Call + bool isBreakWaterEqualToDifferentType = breakWater.Equals(differentType); + + // Assert + Assert.IsFalse(isBreakWaterEqualToDifferentType); + } + + [Test] + public void Equals_DifferentBreakWaterType_ReturnsFalse() + { + // Setup + const double height = 100.10; + + var breakWaterOne = new BreakWater(BreakWaterType.Caisson, height); + var breakWaterTwo = new BreakWater(BreakWaterType.Wall, height); + + // Call + bool isBreakWaterOneEqualToTwo = breakWaterOne.Equals(breakWaterTwo); + bool isBreakWaterTwoEqualToOne = breakWaterTwo.Equals(breakWaterOne); + + // Assert + Assert.IsFalse(isBreakWaterOneEqualToTwo); + Assert.IsFalse(isBreakWaterTwoEqualToOne); + } + + [Test] + public void Equals_DifferentHeight_ReturnsFalse() + { + // Setup + const BreakWaterType type = BreakWaterType.Caisson; + + var breakWaterOne = new BreakWater(type, 100.10); + var breakWaterTwo = new BreakWater(type, 100.20); + + // Call + bool isBreakWaterOneEqualToTwo = breakWaterOne.Equals(breakWaterTwo); + bool isBreakWaterTwoEqualToOne = breakWaterTwo.Equals(breakWaterOne); + + // Assert + Assert.IsFalse(isBreakWaterOneEqualToTwo); + Assert.IsFalse(isBreakWaterTwoEqualToOne); + } + + [Test] + public void GetHashCode_EqualBreakWater_ReturnsSameHashCode() + { + // Setup + const BreakWaterType type = BreakWaterType.Caisson; + const double height = 100.10; + + var breakWaterOne = new BreakWater(type, height); + var breakWaterTwo = new BreakWater(type, height); + + // Call + int hashCodeOne = breakWaterOne.GetHashCode(); + int hashCodeTwo = breakWaterTwo.GetHashCode(); + + // Assert + Assert.AreEqual(hashCodeOne, hashCodeTwo); + } } } \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/DikeProfiles/DikeProfileCollectionTest.cs =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.Data.Test/DikeProfiles/DikeProfileCollectionTest.cs (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/DikeProfiles/DikeProfileCollectionTest.cs (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -0,0 +1,110 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +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 + { + [Test] + public void DefaultConstructor_ReturnsCollectionWithPath() + { + // Call + var collection = new DikeProfileCollection(); + + // Assert + Assert.IsInstanceOf>(collection); + } + + [Test] + public void AddRange_DikeProfilesWithDifferentIds_AddsDikeProfiles() + { + // 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); + } + + [Test] + public void AddRange_WithDikeProfilesWithEqualIds_ThrowsArgumentException() + { + // 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) + }; + + // 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); + } + + [Test] + public void AddRange_WithMultipleDikeProfilesWithEqualIds_ThrowsArgumentException() + { + // 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"); + + // Assert + string message = $"Dijkprofielen moeten een unieke id hebben. Gevonden dubbele elementen: {someId}, {someotherId}."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, message); + } + } +} \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/DikeProfiles/DikeProfileTest.cs =================================================================== diff -u -r1f549a37af503f5da697652b5e5199f8d29ac0fe -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Common/test/Ringtoets.Common.Data.Test/DikeProfiles/DikeProfileTest.cs (.../DikeProfileTest.cs) (revision 1f549a37af503f5da697652b5e5199f8d29ac0fe) +++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/DikeProfiles/DikeProfileTest.cs (.../DikeProfileTest.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -20,6 +20,7 @@ // All rights reserved. using System; +using Core.Common.Base; using Core.Common.Base.Data; using Core.Common.Base.Geometry; using Core.Common.TestUtil; @@ -35,7 +36,7 @@ public void Constructor_ValidParameters_ExpectedValues() { // Setup - string validId = "id"; + const string validId = "id"; var worldCoordinate = new Point2D(1.1, 2.2); var dikeGeometry = new[] { @@ -57,6 +58,7 @@ }); // Assert + Assert.IsInstanceOf(dikeProfile); Assert.IsInstanceOf(dikeProfile.Orientation); Assert.IsInstanceOf(dikeProfile.DikeHeight); Assert.IsInstanceOf(dikeProfile.X0); @@ -319,10 +321,525 @@ }); // Call - var result = dikeProfile.ToString(); + string result = dikeProfile.ToString(); // Assert Assert.AreEqual(testName, result); } + + [Test] + public void Equals_ToItself_ReturnsTrue() + { + // Setup + DikeProfile dikeProfile = CreateFullyDefinedDikeProfile(); + + // Call + bool isEqualToItself = dikeProfile.Equals(dikeProfile); + + // Assert + Assert.IsTrue(isEqualToItself); + } + + [Test] + public void Equals_ToNull_ReturnsFalse() + { + // Setup + DikeProfile dikeProfile = CreateFullyDefinedDikeProfile(); + + // Call + bool isDikeProfileEqualToNull = dikeProfile.Equals(null); + + // Assert + Assert.IsFalse(isDikeProfileEqualToNull); + } + + [Test] + public void Equal_ToDifferentType_ReturnsFalse() + { + // Setup + DikeProfile dikeProfile = CreateFullyDefinedDikeProfile(); + + var differentType = new object(); + + // Call + bool isDikeProfileEqualToDifferentObject = dikeProfile.Equals(differentType); + + // Assert + Assert.IsFalse(isDikeProfileEqualToDifferentObject); + } + + [Test] + public void Equals_DifferentWorldReferencePoints_ReturnsFalse() + { + // Setup + DikeProfile dikeProfileOne = CreateFullyDefinedDikeProfile(); + + var dikeProfileTwo = new DikeProfile(new Point2D(500, 1000), + dikeProfileOne.DikeGeometry, + dikeProfileOne.ForeshoreGeometry, + dikeProfileOne.BreakWater, + new DikeProfile.ConstructionProperties + { + Name = dikeProfileOne.Name, + Id = dikeProfileOne.Id, + Orientation = dikeProfileOne.Orientation, + DikeHeight = dikeProfileOne.DikeHeight, + X0 = dikeProfileOne.DikeHeight + }); + + // Call + bool isDikeProfileOneEqualToTwo = dikeProfileOne.Equals(dikeProfileTwo); + bool isDikeProfileTwoEqualToOne = dikeProfileTwo.Equals(dikeProfileOne); + + // Assert + Assert.IsFalse(isDikeProfileOneEqualToTwo); + Assert.IsFalse(isDikeProfileTwoEqualToOne); + } + + [Test] + public void Equals_DifferentDikeGeometry_ReturnsFalse() + { + // Setup + DikeProfile dikeProfileOne = CreateFullyDefinedDikeProfile(); + + var dikeGeometry = new[] + { + new RoughnessPoint(new Point2D(1, 0), 1), + new RoughnessPoint(new Point2D(2, 1), 3) + }; + var dikeProfileTwo = new DikeProfile(dikeProfileOne.WorldReferencePoint, + dikeGeometry, + dikeProfileOne.ForeshoreGeometry, + dikeProfileOne.BreakWater, + new DikeProfile.ConstructionProperties + { + Name = dikeProfileOne.Name, + Id = dikeProfileOne.Id, + Orientation = dikeProfileOne.Orientation, + DikeHeight = dikeProfileOne.DikeHeight, + X0 = dikeProfileOne.DikeHeight + }); + + // Call + bool isDikeProfileOneEqualToTwo = dikeProfileOne.Equals(dikeProfileTwo); + bool isDikeProfileTwoEqualToOne = dikeProfileTwo.Equals(dikeProfileOne); + + // Assert + Assert.IsFalse(isDikeProfileOneEqualToTwo); + Assert.IsFalse(isDikeProfileTwoEqualToOne); + } + + [Test] + public void Equals_DifferentForeshoreGeometry_ReturnsFalse() + { + // Setup + DikeProfile dikeProfileOne = CreateFullyDefinedDikeProfile(); + + var foreshoreGeometry = new[] + { + new Point2D(50, 100), + new Point2D(100, 50) + }; + var dikeProfileTwo = new DikeProfile(dikeProfileOne.WorldReferencePoint, + dikeProfileOne.DikeGeometry, + foreshoreGeometry, + dikeProfileOne.BreakWater, + new DikeProfile.ConstructionProperties + { + Name = dikeProfileOne.Name, + Id = dikeProfileOne.Id, + Orientation = dikeProfileOne.Orientation, + DikeHeight = dikeProfileOne.DikeHeight, + X0 = dikeProfileOne.DikeHeight + }); + + // Call + bool isDikeProfileOneEqualToTwo = dikeProfileOne.Equals(dikeProfileTwo); + bool isDikeProfileTwoEqualToOne = dikeProfileTwo.Equals(dikeProfileOne); + + // Assert + Assert.IsFalse(isDikeProfileOneEqualToTwo); + Assert.IsFalse(isDikeProfileTwoEqualToOne); + } + + [Test] + public void Equals_DifferentBreakWater_ReturnsFalse() + { + // Setup + DikeProfile dikeProfileOne = CreateFullyDefinedDikeProfile(); + + var dikeProfileTwo = new DikeProfile(dikeProfileOne.WorldReferencePoint, + dikeProfileOne.DikeGeometry, + dikeProfileOne.ForeshoreGeometry, + null, + new DikeProfile.ConstructionProperties + { + Name = dikeProfileOne.Name, + Id = dikeProfileOne.Id, + Orientation = dikeProfileOne.Orientation, + DikeHeight = dikeProfileOne.DikeHeight, + X0 = dikeProfileOne.DikeHeight + }); + + // Call + bool isDikeProfileOneEqualToTwo = dikeProfileOne.Equals(dikeProfileTwo); + bool isDikeProfileTwoEqualToOne = dikeProfileTwo.Equals(dikeProfileOne); + + // Assert + Assert.IsFalse(isDikeProfileOneEqualToTwo); + Assert.IsFalse(isDikeProfileTwoEqualToOne); + } + + [Test] + public void Equals_DifferentIds_ReturnsFalse() + { + // Setup + DikeProfile dikeProfileOne = CreateFullyDefinedDikeProfile(); + + var dikeProfileTwo = new DikeProfile(dikeProfileOne.WorldReferencePoint, + dikeProfileOne.DikeGeometry, + dikeProfileOne.ForeshoreGeometry, + dikeProfileOne.BreakWater, + new DikeProfile.ConstructionProperties + { + Name = dikeProfileOne.Name, + Id = "Different ID", + Orientation = dikeProfileOne.Orientation, + DikeHeight = dikeProfileOne.DikeHeight, + X0 = dikeProfileOne.DikeHeight + }); + + // Call + bool isDikeProfileOneEqualToTwo = dikeProfileOne.Equals(dikeProfileTwo); + bool isDikeProfileTwoEqualToOne = dikeProfileTwo.Equals(dikeProfileOne); + + // Assert + Assert.IsFalse(isDikeProfileOneEqualToTwo); + Assert.IsFalse(isDikeProfileTwoEqualToOne); + } + + [Test] + public void Equals_DifferentNames_ReturnsFalse() + { + // Setup + DikeProfile dikeProfileOne = CreateFullyDefinedDikeProfile(); + + var dikeProfileTwo = new DikeProfile(dikeProfileOne.WorldReferencePoint, + dikeProfileOne.DikeGeometry, + dikeProfileOne.ForeshoreGeometry, + dikeProfileOne.BreakWater, + new DikeProfile.ConstructionProperties + { + Name = "Different Name", + Id = dikeProfileOne.Id, + Orientation = dikeProfileOne.Orientation, + DikeHeight = dikeProfileOne.DikeHeight, + X0 = dikeProfileOne.DikeHeight + }); + + // Call + bool isDikeProfileOneEqualToTwo = dikeProfileOne.Equals(dikeProfileTwo); + bool isDikeProfileTwoEqualToOne = dikeProfileTwo.Equals(dikeProfileOne); + + // Assert + Assert.IsFalse(isDikeProfileOneEqualToTwo); + Assert.IsFalse(isDikeProfileTwoEqualToOne); + } + + [Test] + public void Equals_DifferentX0_ReturnsFalse() + { + // Setup + const string id = "ID"; + const string name = "Just a name"; + const double orientation = 179; + const double dikeHeight = 0.5; + DikeProfile dikeProfileOne = CreateDikeProfile(new DikeProfile.ConstructionProperties + { + Id = id, + Name = name, + X0 = 10.0, + Orientation = orientation, + DikeHeight = dikeHeight + }); + + DikeProfile dikeProfileTwo = CreateDikeProfile(new DikeProfile.ConstructionProperties + { + Id = id, + Name = name, + X0 = 11.0, + Orientation = orientation, + DikeHeight = dikeHeight + }); + + // Call + bool isDikeProfileOneEqualToTwo = dikeProfileOne.Equals(dikeProfileTwo); + bool isDikeProfileTwoEqualToOne = dikeProfileTwo.Equals(dikeProfileOne); + + // Assert + Assert.IsFalse(isDikeProfileOneEqualToTwo); + Assert.IsFalse(isDikeProfileTwoEqualToOne); + } + + [Test] + public void Equals_DifferentOrientation_ReturnsFalse() + { + // Setup + const string id = "ID"; + const string name = "Just a name"; + const double x0 = 179; + const double dikeHeight = 0.5; + DikeProfile dikeProfileOne = CreateDikeProfile(new DikeProfile.ConstructionProperties + { + Id = id, + Name = name, + X0 = x0, + Orientation = 180, + DikeHeight = dikeHeight + }); + + DikeProfile dikeProfileTwo = CreateDikeProfile(new DikeProfile.ConstructionProperties + { + Id = id, + Name = name, + X0 = x0, + Orientation = 170, + DikeHeight = dikeHeight + }); + + // Call + bool isDikeProfileOneEqualToTwo = dikeProfileOne.Equals(dikeProfileTwo); + bool isDikeProfileTwoEqualToOne = dikeProfileTwo.Equals(dikeProfileOne); + + // Assert + Assert.IsFalse(isDikeProfileOneEqualToTwo); + Assert.IsFalse(isDikeProfileTwoEqualToOne); + } + + [Test] + public void Equals_DifferentDikeHeight_ReturnsFalse() + { + // Setup + const string id = "ID"; + const string name = "Just a name"; + const double orientation = 179; + const double x0 = 0.5; + DikeProfile dikeProfileOne = CreateDikeProfile(new DikeProfile.ConstructionProperties + { + Id = id, + Name = name, + X0 = x0, + Orientation = orientation, + DikeHeight = 0.5 + }); + + DikeProfile dikeProfileTwo = CreateDikeProfile(new DikeProfile.ConstructionProperties + { + Id = id, + Name = name, + X0 = x0, + Orientation = orientation, + DikeHeight = 0.3 + }); + + // Call + bool isDikeProfileOneEqualToTwo = dikeProfileOne.Equals(dikeProfileTwo); + bool isDikeProfileTwoEqualToOne = dikeProfileTwo.Equals(dikeProfileOne); + + // Assert + Assert.IsFalse(isDikeProfileOneEqualToTwo); + Assert.IsFalse(isDikeProfileTwoEqualToOne); + } + + [Test] + public void Equals_AllPropertiesEqual_ReturnsTrue() + { + // Setup + DikeProfile dikeProfileOne = CreateFullyDefinedDikeProfile(); + DikeProfile dikeProfileTwo = CreateFullyDefinedDikeProfile(); + + // Call + bool isDikeProfileOneEqualToTwo = dikeProfileOne.Equals(dikeProfileTwo); + bool isDikeProfileTwoEqualToOne = dikeProfileTwo.Equals(dikeProfileOne); + + // Assert + Assert.IsTrue(isDikeProfileOneEqualToTwo); + Assert.IsTrue(isDikeProfileTwoEqualToOne); + } + + [Test] + public void Equals_TransitivePropertyAllPropertiesEqual_ReturnsTrue() + { + // Setup + DikeProfile dikeProfileOne = CreateFullyDefinedDikeProfile(); + DikeProfile dikeProfileTwo = CreateFullyDefinedDikeProfile(); + DikeProfile dikeProfileThree = CreateFullyDefinedDikeProfile(); + + // Call + bool isDikeProfileOneEqualToTwo = dikeProfileOne.Equals(dikeProfileTwo); + bool isDikeProfileTwoEqualToThree = dikeProfileTwo.Equals(dikeProfileThree); + bool isDikeProfileOneEqualToThree = dikeProfileOne.Equals(dikeProfileThree); + + // Assert + Assert.IsTrue(isDikeProfileOneEqualToTwo); + Assert.IsTrue(isDikeProfileTwoEqualToThree); + Assert.IsTrue(isDikeProfileOneEqualToThree); + } + + [Test] + public void Equals_SameReference_ReturnsTrue() + { + // Setup + DikeProfile dikeProfileOne = CreateFullyDefinedDikeProfile(); + DikeProfile dikeProfileTwo = dikeProfileOne; + + // Call + bool isDikeProfileOneEqualToTwo = dikeProfileOne.Equals(dikeProfileTwo); + bool isDikeProfileTwoEqualToOne = dikeProfileTwo.Equals(dikeProfileOne); + + // Assert + Assert.IsTrue(isDikeProfileOneEqualToTwo); + Assert.IsTrue(isDikeProfileTwoEqualToOne); + } + + [Test] + public void GetHashCode_EqualDikeProfiles_ReturnsSameHashCode() + { + // Setup + DikeProfile dikeProfileOne = CreateFullyDefinedDikeProfile(); + DikeProfile dikeProfileTwo = CreateFullyDefinedDikeProfile(); + + // Call + int hashCodeOne = dikeProfileOne.GetHashCode(); + int hashCodeTwo = dikeProfileTwo.GetHashCode(); + + // Assert + Assert.AreEqual(hashCodeOne, hashCodeTwo); + } + + [Test] + public void CopyProperties_FromDikeProfileNull_ThrowsArgumentNullException() + { + // Setup + DikeProfile dikeProfile = CreateFullyDefinedDikeProfile(); + + // Call + TestDelegate call = () => dikeProfile.CopyProperties(null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("fromDikeProfile", exception.ParamName); + } + + [Test] + public void CopyProperties_FromDikeProfileAllPropertiesChanged_PropertiesUpdated() + { + // Setup + DikeProfile dikeProfileToUpdate = CreateFullyDefinedDikeProfile(); + + const string expectedId = "new_id"; + const string expectedName = "new_name"; + + var random = new Random(21); + double expectedX0 = dikeProfileToUpdate.X0 + random.NextDouble(); + var expectedOrientation = new RoundedDouble(2, (dikeProfileToUpdate.Orientation + random.NextDouble()) % 360); + var expectedDikeHeight = new RoundedDouble(2, dikeProfileToUpdate.DikeHeight + random.NextDouble()); + + double expectedBreakWaterHeight = dikeProfileToUpdate.BreakWater.Height + random.NextDouble(); + var expectedBreakWater = new BreakWater(random.NextEnumValue(), expectedBreakWaterHeight); + + var expectedForeshoreGeometry = new[] + { + new Point2D(10, 10), + new Point2D(15, 10) + }; + + var expectedDikeGeometry = new[] + { + new RoughnessPoint(new Point2D(10, 10), 1), + new RoughnessPoint(new Point2D(15, 10), 2) + }; + + var expectedWorldReferencePoint = new Point2D(13, 37); + + var dikeProfileToUpdateFrom = new DikeProfile(expectedWorldReferencePoint, + expectedDikeGeometry, + expectedForeshoreGeometry, + expectedBreakWater, + new DikeProfile.ConstructionProperties + { + Id = expectedId, + Name = expectedName, + X0 = expectedX0, + Orientation = expectedOrientation, + DikeHeight = expectedDikeHeight + }); + + // Call + dikeProfileToUpdate.CopyProperties(dikeProfileToUpdateFrom); + + // Assert + Assert.AreEqual(expectedWorldReferencePoint, dikeProfileToUpdate.WorldReferencePoint); + CollectionAssert.AreEqual(expectedForeshoreGeometry, dikeProfileToUpdate.ForeshoreGeometry); + CollectionAssert.AreEqual(expectedDikeGeometry, dikeProfileToUpdate.DikeGeometry); + Assert.AreEqual(expectedBreakWater, dikeProfileToUpdate.BreakWater); + + Assert.AreEqual(expectedId, dikeProfileToUpdate.Id); + Assert.AreEqual(expectedName, dikeProfileToUpdate.Name); + Assert.AreEqual(expectedX0, dikeProfileToUpdate.X0); + Assert.AreEqual(expectedOrientation, dikeProfileToUpdate.Orientation); + Assert.AreEqual(expectedDikeHeight, dikeProfileToUpdate.DikeHeight); + } + + /// + /// Creates a default with all properties set. + /// + /// A fully defined . + private static DikeProfile CreateFullyDefinedDikeProfile() + { + const string id = "id"; + const string name = "What's in a name?"; + + const double x0 = 13.37; + const double orientation = 179; + const double dikeHeight = 10; + + return CreateDikeProfile(new DikeProfile.ConstructionProperties + { + Id = id, + Name = name, + X0 = x0, + Orientation = orientation, + DikeHeight = dikeHeight + }); + } + + /// + /// Creates a with all properties set, except for the + /// parameters related to which + /// are user specified. + /// + /// The construction properties. + /// A with default parameters and + /// specified values of the . + /// Thrown when + /// is null, empty or a whitespace. + private static DikeProfile CreateDikeProfile(DikeProfile.ConstructionProperties properties) + { + var worldCoordinate = new Point2D(0, 0); + var foreshoreGeometry = new[] + { + new Point2D(0, 1), + new Point2D(2, 1) + }; + var dikeGeometry = new[] + { + new RoughnessPoint(new Point2D(0, 1), 1), + new RoughnessPoint(new Point2D(1, 2), 3) + }; + var breakWater = new BreakWater(BreakWaterType.Caisson, 1.3); + + return new DikeProfile(worldCoordinate, dikeGeometry, foreshoreGeometry, breakWater, properties); + } } } \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/DikeProfiles/ForeshoreProfileTest.cs =================================================================== diff -u -r1f549a37af503f5da697652b5e5199f8d29ac0fe -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Common/test/Ringtoets.Common.Data.Test/DikeProfiles/ForeshoreProfileTest.cs (.../ForeshoreProfileTest.cs) (revision 1f549a37af503f5da697652b5e5199f8d29ac0fe) +++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/DikeProfiles/ForeshoreProfileTest.cs (.../ForeshoreProfileTest.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -35,7 +35,7 @@ public void Constructor_ValidParameters_ExpectedValues() { // Setup - string validId = "id"; + const string validId = "id"; var worldCoordinate = new Point2D(1.1, 2.2); var foreshoreGeometry = new[] @@ -273,10 +273,369 @@ }); // Call - var result = foreshoreProfile.ToString(); + string result = foreshoreProfile.ToString(); // Assert Assert.AreEqual(testName, result); } + + [Test] + public void Equals_ToItself_ReturnsTrue() + { + // Setup + ForeshoreProfile foreshoreProfile = CreateFullyDefinedForeshoreProfile(); + + // Call + bool isEqualToItself = foreshoreProfile.Equals(foreshoreProfile); + + // Assert + Assert.IsTrue(isEqualToItself); + } + + [Test] + public void Equals_ToNull_ReturnsFalse() + { + // Setup + ForeshoreProfile foreshoreProfile = CreateFullyDefinedForeshoreProfile(); + + // Call + bool isForeshoreProfileEqualToNull = foreshoreProfile.Equals(null); + + // Assert + Assert.IsFalse(isForeshoreProfileEqualToNull); + } + + [Test] + public void Equal_ToDifferentType_ReturnsFalse() + { + // Setup + ForeshoreProfile foreshoreProfile = CreateFullyDefinedForeshoreProfile(); + var differentType = new object(); + + // Call + bool isForeshoreProfileEqualToDifferentObject = foreshoreProfile.Equals(differentType); + + // Assert + Assert.IsFalse(isForeshoreProfileEqualToDifferentObject); + } + + [Test] + public void Equals_DifferentWorldReferencePoints_ReturnsFalse() + { + // Setup + ForeshoreProfile foreshoreProfileOne = CreateFullyDefinedForeshoreProfile(); + var foreshoreProfileTwo = new ForeshoreProfile(new Point2D(13, 37), + foreshoreProfileOne.Geometry, + foreshoreProfileOne.BreakWater, + new ForeshoreProfile.ConstructionProperties + { + Id = foreshoreProfileOne.Id, + Name = foreshoreProfileOne.Name, + X0 = foreshoreProfileOne.X0, + Orientation = foreshoreProfileOne.Orientation + }); + + // Call + bool isForeshoreProfileOneEqualToTwo = foreshoreProfileOne.Equals(foreshoreProfileTwo); + bool isForeshoreProfileTwoEqualToOne = foreshoreProfileTwo.Equals(foreshoreProfileOne); + + // Assert + Assert.IsFalse(isForeshoreProfileOneEqualToTwo); + Assert.IsFalse(isForeshoreProfileTwoEqualToOne); + } + + [Test] + public void Equals_DifferentForeshoreGeometry_ReturnsFalse() + { + // Setup + ForeshoreProfile foreshoreProfileOne = CreateFullyDefinedForeshoreProfile(); + + var foreshoreGeometry = new[] + { + new Point2D(10, 10), + new Point2D(11, 11) + }; + var foreshoreProfileTwo = new ForeshoreProfile(foreshoreProfileOne.WorldReferencePoint, + foreshoreGeometry, + foreshoreProfileOne.BreakWater, + new ForeshoreProfile.ConstructionProperties + { + Id = foreshoreProfileOne.Id, + Name = foreshoreProfileOne.Name, + X0 = foreshoreProfileOne.X0, + Orientation = foreshoreProfileOne.Orientation + }); + + // Call + bool isForeshoreProfileOneEqualToTwo = foreshoreProfileOne.Equals(foreshoreProfileTwo); + bool isForeshoreProfileTwoEqualToOne = foreshoreProfileTwo.Equals(foreshoreProfileOne); + + // Assert + Assert.IsFalse(isForeshoreProfileOneEqualToTwo); + Assert.IsFalse(isForeshoreProfileTwoEqualToOne); + } + + [Test] + public void Equals_DifferentBreakWater_ReturnsFalse() + { + // Setup + ForeshoreProfile foreshoreProfileOne = CreateFullyDefinedForeshoreProfile(); + var foreshoreProfileTwo = new ForeshoreProfile(foreshoreProfileOne.WorldReferencePoint, + foreshoreProfileOne.Geometry, + null, + new ForeshoreProfile.ConstructionProperties + { + Id = foreshoreProfileOne.Id, + Name = foreshoreProfileOne.Name, + X0 = foreshoreProfileOne.X0, + Orientation = foreshoreProfileOne.Orientation + }); + + // Call + bool isForeshoreProfileOneEqualToTwo = foreshoreProfileOne.Equals(foreshoreProfileTwo); + bool isForeshoreProfileTwoEqualToOne = foreshoreProfileTwo.Equals(foreshoreProfileOne); + + // Assert + Assert.IsFalse(isForeshoreProfileOneEqualToTwo); + Assert.IsFalse(isForeshoreProfileTwoEqualToOne); + } + + [Test] + public void Equals_DifferentIds_ReturnsFalse() + { + // Setup + const string name = "Just a name"; + const double x0 = 10.0; + const double orientation = 179; + ForeshoreProfile foreshoreProfileOne = CreateForeshoreProfile(new ForeshoreProfile.ConstructionProperties + { + Id = "id1", + Name = name, + X0 = x0, + Orientation = orientation + }); + + ForeshoreProfile foreshoreProfileTwo = CreateForeshoreProfile(new ForeshoreProfile.ConstructionProperties + { + Id = "id2", + Name = name, + X0 = x0, + Orientation = orientation + }); + + // Call + bool isForeshoreProfileOneEqualToTwo = foreshoreProfileOne.Equals(foreshoreProfileTwo); + bool isForeshoreProfileTwoEqualToOne = foreshoreProfileTwo.Equals(foreshoreProfileOne); + + // Assert + Assert.IsFalse(isForeshoreProfileOneEqualToTwo); + Assert.IsFalse(isForeshoreProfileTwoEqualToOne); + } + + [Test] + public void Equals_DifferentNames_ReturnsFalse() + { + // Setup + const string id = "id"; + const double x0 = 10.0; + const double orientation = 179; + ForeshoreProfile foreshoreProfileOne = CreateForeshoreProfile(new ForeshoreProfile.ConstructionProperties + { + Id = id, + Name = "Name 1", + X0 = x0, + Orientation = orientation + }); + + ForeshoreProfile foreshoreProfileTwo = CreateForeshoreProfile(new ForeshoreProfile.ConstructionProperties + { + Id = id, + Name = "Name 2", + X0 = x0, + Orientation = orientation + }); + + // Call + bool isForeshoreProfileOneEqualToTwo = foreshoreProfileOne.Equals(foreshoreProfileTwo); + bool isForeshoreProfileTwoEqualToOne = foreshoreProfileTwo.Equals(foreshoreProfileOne); + + // Assert + Assert.IsFalse(isForeshoreProfileOneEqualToTwo); + Assert.IsFalse(isForeshoreProfileTwoEqualToOne); + } + + [Test] + public void Equals_DifferentX0_ReturnsFalse() + { + // Setup + const string id = "ID"; + const string name = "Just a name"; + const double orientation = 179; + ForeshoreProfile foreshoreProfileOne = CreateForeshoreProfile(new ForeshoreProfile.ConstructionProperties + { + Id = id, + Name = name, + X0 = 10.0, + Orientation = orientation + }); + + ForeshoreProfile foreshoreProfileTwo = CreateForeshoreProfile(new ForeshoreProfile.ConstructionProperties + { + Id = id, + Name = name, + X0 = 11.0, + Orientation = orientation + }); + + // Call + bool isForeshoreProfileOneEqualToTwo = foreshoreProfileOne.Equals(foreshoreProfileTwo); + bool isForeshoreProfileTwoEqualToOne = foreshoreProfileTwo.Equals(foreshoreProfileOne); + + // Assert + Assert.IsFalse(isForeshoreProfileOneEqualToTwo); + Assert.IsFalse(isForeshoreProfileTwoEqualToOne); + } + + [Test] + public void Equals_DifferentOrientation_ReturnsFalse() + { + // Setup + const string id = "ID"; + const string name = "Just a name"; + const double x0 = 13.37; + ForeshoreProfile foreshoreProfileOne = CreateForeshoreProfile(new ForeshoreProfile.ConstructionProperties + { + Id = id, + Name = name, + X0 = x0, + Orientation = 179 + }); + + ForeshoreProfile foreshoreProfileTwo = CreateForeshoreProfile(new ForeshoreProfile.ConstructionProperties + { + Id = id, + Name = name, + X0 = x0, + Orientation = 180 + }); + + // Call + bool isForeshoreProfileOneEqualToTwo = foreshoreProfileOne.Equals(foreshoreProfileTwo); + bool isForeshoreProfileTwoEqualToOne = foreshoreProfileTwo.Equals(foreshoreProfileOne); + + // Assert + Assert.IsFalse(isForeshoreProfileOneEqualToTwo); + Assert.IsFalse(isForeshoreProfileTwoEqualToOne); + } + + [Test] + public void Equals_AllPropertiesEqual_ReturnsTrue() + { + // Setup + ForeshoreProfile foreshoreProfileOne = CreateFullyDefinedForeshoreProfile(); + ForeshoreProfile foreshoreProfileTwo = CreateFullyDefinedForeshoreProfile(); + + // Call + bool isForeshoreProfileOneEqualToTwo = foreshoreProfileOne.Equals(foreshoreProfileTwo); + bool isForeshoreProfileTwoEqualToOne = foreshoreProfileTwo.Equals(foreshoreProfileOne); + + // Assert + Assert.IsTrue(isForeshoreProfileOneEqualToTwo); + Assert.IsTrue(isForeshoreProfileTwoEqualToOne); + } + + [Test] + public void Equals_TransitivePropertyAllPropertiesEqual_ReturnsTrue() + { + // Setup + ForeshoreProfile foreshoreProfileOne = CreateFullyDefinedForeshoreProfile(); + ForeshoreProfile foreshoreProfileTwo = CreateFullyDefinedForeshoreProfile(); + ForeshoreProfile foreshoreProfileThree = CreateFullyDefinedForeshoreProfile(); + + // Call + bool isForeshoreProfileOneEqualToTwo = foreshoreProfileOne.Equals(foreshoreProfileTwo); + bool isForeshoreProfileTwoEqualToThree = foreshoreProfileTwo.Equals(foreshoreProfileThree); + bool isForeshoreProfileOneEqualToThree = foreshoreProfileOne.Equals(foreshoreProfileThree); + + // Assert + Assert.IsTrue(isForeshoreProfileOneEqualToTwo); + Assert.IsTrue(isForeshoreProfileTwoEqualToThree); + Assert.IsTrue(isForeshoreProfileOneEqualToThree); + } + + [Test] + public void Equals_SameReference_ReturnsTrue() + { + // Setup + ForeshoreProfile foreshoreProfileOne = CreateFullyDefinedForeshoreProfile(); + ForeshoreProfile foreshoreProfileTwo = foreshoreProfileOne; + + // Call + bool isForeshoreProfileOneEqualToTwo = foreshoreProfileOne.Equals(foreshoreProfileTwo); + bool isForeshoreProfileTwoEqualToOne = foreshoreProfileTwo.Equals(foreshoreProfileOne); + + // Assert + Assert.IsTrue(isForeshoreProfileOneEqualToTwo); + Assert.IsTrue(isForeshoreProfileTwoEqualToOne); + } + + [Test] + public void GetHashCode_EqualForeshoreProfiles_ReturnsSameHashCode() + { + // Setup + ForeshoreProfile foreshoreProfileOne = CreateFullyDefinedForeshoreProfile(); + ForeshoreProfile foreshoreProfileTwo = CreateFullyDefinedForeshoreProfile(); + + // Call + int hashCodeOne = foreshoreProfileOne.GetHashCode(); + int hashCodeTwo = foreshoreProfileTwo.GetHashCode(); + + // Assert + Assert.AreEqual(hashCodeOne, hashCodeTwo); + } + + /// + /// Creates a default with all properties set. + /// + /// A fully defined . + private static ForeshoreProfile CreateFullyDefinedForeshoreProfile() + { + const string id = "id"; + const string name = "What's in a name?"; + + const double x0 = 13.37; + const double orientation = 179; + + return CreateForeshoreProfile(new ForeshoreProfile.ConstructionProperties + { + Id = id, + Name = name, + X0 = x0, + Orientation = orientation + }); + } + + /// + /// Creates a with all properties set, except for the + /// parameters related to which + /// are user specified. + /// + /// The construction properties. + /// A with default parameters and + /// specified values of the . + /// Thrown when + /// is null, empty or a whitespace. + private static ForeshoreProfile CreateForeshoreProfile(ForeshoreProfile.ConstructionProperties properties) + { + var worldCoordinate = new Point2D(0, 0); + var geometry = new[] + { + new Point2D(0, 1), + new Point2D(2, 1) + }; + var breakWater = new BreakWater(BreakWaterType.Caisson, 1.3); + + return new ForeshoreProfile(worldCoordinate, geometry, breakWater, properties); + } } } \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/DikeProfiles/RoughnessPointTest.cs =================================================================== diff -u -r30b8231f92b90ea4b05e98e3d0285368f6dfe2e4 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Common/test/Ringtoets.Common.Data.Test/DikeProfiles/RoughnessPointTest.cs (.../RoughnessPointTest.cs) (revision 30b8231f92b90ea4b05e98e3d0285368f6dfe2e4) +++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/DikeProfiles/RoughnessPointTest.cs (.../RoughnessPointTest.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -56,5 +56,156 @@ var exception = Assert.Throws(test); Assert.AreEqual("point", exception.ParamName); } + + [Test] + public void Equals_ToItself_ReturnsTrue() + { + // Setup + var roughnessPoint = new RoughnessPoint(new Point2D(0, 0), 0); + + // Call + bool isRougnessPointEqualToItself = roughnessPoint.Equals(roughnessPoint); + + // Assert + Assert.IsTrue(isRougnessPointEqualToItself); + } + + [Test] + public void Equals_ToSameReference_ReturnsTrue() + { + // Setup + var roughnessPointOne = new RoughnessPoint(new Point2D(0, 0), 0); + var roughnessPointTwo = roughnessPointOne; + + // Call + bool isRoughnessPointOneEqualToTwo = roughnessPointOne.Equals(roughnessPointTwo); + bool isRoughnessPointTwoEqualToOne = roughnessPointTwo.Equals(roughnessPointOne); + + // Assert + Assert.IsTrue(isRoughnessPointOneEqualToTwo); + Assert.IsTrue(isRoughnessPointTwoEqualToOne); + } + + [Test] + public void Equals_PropertiesEqual_ReturnsTrue() + { + // Setup + var geometryPoint = new Point2D(0, 0); + const double roughness = 3.14; + + var roughnessPointOne = new RoughnessPoint(geometryPoint, roughness); + var roughnessPointTwo = new RoughnessPoint(geometryPoint, roughness); + + // Call + bool isRoughnessPointOneEqualToTwo = roughnessPointOne.Equals(roughnessPointTwo); + bool isRoughnessPointTwoEqualToOne = roughnessPointTwo.Equals(roughnessPointOne); + + // Assert + Assert.IsTrue(isRoughnessPointOneEqualToTwo); + Assert.IsTrue(isRoughnessPointTwoEqualToOne); + } + + [Test] + public void Equals_TransitivePropertyPropertiesEqual_ReturnsTrue() + { + // Setup + var geometryPoint = new Point2D(0, 0); + const double roughness = 3.14; + + var roughnessPointOne = new RoughnessPoint(geometryPoint, roughness); + var roughnessPointTwo = new RoughnessPoint(geometryPoint, roughness); + var roughnessPointThree = new RoughnessPoint(geometryPoint, roughness); + + // Call + bool isRoughnessPointOneEqualToTwo = roughnessPointOne.Equals(roughnessPointTwo); + bool isRoughnessPointTwoEqualToThree = roughnessPointTwo.Equals(roughnessPointThree); + bool isRoughnessPointOneEqualToThree = roughnessPointOne.Equals(roughnessPointThree); + + // Assert + Assert.IsTrue(isRoughnessPointOneEqualToTwo); + Assert.IsTrue(isRoughnessPointTwoEqualToThree); + Assert.IsTrue(isRoughnessPointOneEqualToThree); + } + + [Test] + public void Equals_DifferentGeometryPoint_ReturnsTrue() + { + // Setup + const double roughness = 3.14; + + var roughnessPointOne = new RoughnessPoint(new Point2D(0, 0), roughness); + var roughnessPointTwo = new RoughnessPoint(new Point2D(1, 1), roughness); + + // Call + bool isRoughnessPointOneEqualToTwo = roughnessPointOne.Equals(roughnessPointTwo); + bool isRoughnessPointTwoEqualToOne = roughnessPointTwo.Equals(roughnessPointOne); + + // Assert + Assert.IsFalse(isRoughnessPointOneEqualToTwo); + Assert.IsFalse(isRoughnessPointTwoEqualToOne); + } + + [Test] + public void Equals_DifferentRoughness_ReturnsFalse() + { + // Setup + var geometryPoint = new Point2D(0, 0); + + var roughnessPointOne = new RoughnessPoint(geometryPoint, 3.14); + var roughnessPointTwo = new RoughnessPoint(geometryPoint, 3.00); + + // Call + bool isRoughnessPointOneEqualToTwo = roughnessPointOne.Equals(roughnessPointTwo); + bool isRoughnessPointTwoEqualToOne = roughnessPointTwo.Equals(roughnessPointOne); + + // Assert + Assert.IsFalse(isRoughnessPointOneEqualToTwo); + Assert.IsFalse(isRoughnessPointTwoEqualToOne); + } + + [Test] + public void Equals_ToNull_ReturnsTrue() + { + // Setup + var roughnessPoint = new RoughnessPoint(new Point2D(0, 0), 0); + + // Call + bool isRougnessPointEqualToNull = roughnessPoint.Equals(null); + + // Assert + Assert.IsFalse(isRougnessPointEqualToNull); + } + + [Test] + public void Equals_ToDifferentType_ReturnsFalse() + { + // Setup + var roughnessPoint = new RoughnessPoint(new Point2D(0, 0), 0); + var differentType = new object(); + + // Call + bool isRougnessPointEqualToDifferentType = roughnessPoint.Equals(differentType); + + // Assert + Assert.IsFalse(isRougnessPointEqualToDifferentType); + } + + [Test] + public void GetHashCode_EqualRoughnessPoint_ReturnsSameHashCode() + { + // Setup + var geometryPoint = new Point2D(0, 0); + const double roughness = 3.14; + + var roughnessPointOne = new RoughnessPoint(geometryPoint, roughness); + var roughnessPointTwo = new RoughnessPoint(geometryPoint, roughness); + + // Call + int hashCodeOne = roughnessPointOne.GetHashCode(); + int hashCodeTwo = roughnessPointTwo.GetHashCode(); + + // Assert + Assert.AreEqual(hashCodeOne, hashCodeTwo); + } } } \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/Exceptions/DikeProfileUpdateExceptionTest.cs =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.Data.Test/Exceptions/DikeProfileUpdateExceptionTest.cs (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/Exceptions/DikeProfileUpdateExceptionTest.cs (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -0,0 +1,32 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.Exceptions; + +namespace Ringtoets.Common.Data.Test.Exceptions +{ + [TestFixture] + public class DikeProfileUpdateExceptionTest + : CustomExceptionDesignGuidelinesTestFixture {} +} \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/Exceptions/UpdateDataExceptionTest.cs =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.Data.Test/Exceptions/UpdateDataExceptionTest.cs (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/Exceptions/UpdateDataExceptionTest.cs (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -0,0 +1,32 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.Exceptions; + +namespace Ringtoets.Common.Data.Test.Exceptions +{ + [TestFixture] + public class UpdateDataExceptionTest : + CustomExceptionDesignGuidelinesTestFixture {} +} \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/Ringtoets.Common.Data.Test.csproj =================================================================== diff -u -rc90fad2c6d012238ac0b62e52f9820047de76ad6 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Common/test/Ringtoets.Common.Data.Test/Ringtoets.Common.Data.Test.csproj (.../Ringtoets.Common.Data.Test.csproj) (revision c90fad2c6d012238ac0b62e52f9820047de76ad6) +++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/Ringtoets.Common.Data.Test.csproj (.../Ringtoets.Common.Data.Test.csproj) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -66,8 +66,10 @@ + + @@ -104,6 +106,7 @@ + Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/UpdateDataStrategies/ReplaceDataStrategyBaseTest.cs =================================================================== diff -u -r66239a42b315209acc4d124200c58d8be1a18195 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Common/test/Ringtoets.Common.Data.Test/UpdateDataStrategies/ReplaceDataStrategyBaseTest.cs (.../ReplaceDataStrategyBaseTest.cs) (revision 66239a42b315209acc4d124200c58d8be1a18195) +++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/UpdateDataStrategies/ReplaceDataStrategyBaseTest.cs (.../ReplaceDataStrategyBaseTest.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -24,6 +24,7 @@ using System.Linq; using Core.Common.Base; using NUnit.Framework; +using Ringtoets.Common.Data.Exceptions; using Ringtoets.Common.Data.TestUtil; using Ringtoets.Common.Data.UpdateDataStrategies; @@ -64,7 +65,7 @@ // Assert string paramName = Assert.Throws(call).ParamName; - Assert.AreEqual("targetCollection", paramName); + Assert.AreEqual("targetDataCollection", paramName); } [Test] @@ -112,7 +113,7 @@ } [Test] - public void ReplaceData_ImportedDataCollectionContainsDuplicateItems_ThrowsArgumentException() + public void ReplaceData_ImportedDataCollectionContainsDuplicateItems_ThrowsUpdateDataException() { // Setup var strategy = new ConcreteStrategyClass(new TestFailureMechanism()); @@ -130,13 +131,14 @@ // Assert CollectionAssert.IsEmpty(collection); - var exception = Assert.Throws(call); + var exception = Assert.Throws(call); string expectedMessage = $"TestItem moeten een unieke naam hebben. Gevonden dubbele elementen: {duplicateName}."; Assert.AreEqual(expectedMessage, exception.Message); + Assert.IsInstanceOf(exception.InnerException); } [Test] - public void ReplaceData_ImportedDataCollectionContainsNull_ThrowsArgumentException() + public void ReplaceData_ImportedDataCollectionContainsNull_ThrowsUpdateDataException() { // Setup var strategy = new ConcreteStrategyClass(new TestFailureMechanism()); @@ -154,13 +156,15 @@ // Assert CollectionAssert.IsEmpty(collection); - Assert.Throws(call); + + var exception = Assert.Throws(call); + Assert.IsInstanceOf(exception.InnerException); } [Test] [TestCase("")] [TestCase(" ")] - public void ReplaceData_InvalidSourceFilePath_ThrowsArgumentException(string invalidPath) + public void ReplaceData_InvalidSourceFilePath_ThrowsUpdateDataException(string invalidPath) { // Setup var strategy = new ConcreteStrategyClass(new TestFailureMechanism()); @@ -178,7 +182,9 @@ // Assert CollectionAssert.IsEmpty(collection); - Assert.Throws(call); + + var exception = Assert.Throws(call); + Assert.IsInstanceOf(exception.InnerException); } [Test] Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/UpdateDataStrategies/UpdateDataStrategyBaseTest.cs =================================================================== diff -u -r9997d3038d16fb710ffc92f95c781639d63d7855 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Common/test/Ringtoets.Common.Data.Test/UpdateDataStrategies/UpdateDataStrategyBaseTest.cs (.../UpdateDataStrategyBaseTest.cs) (revision 9997d3038d16fb710ffc92f95c781639d63d7855) +++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/UpdateDataStrategies/UpdateDataStrategyBaseTest.cs (.../UpdateDataStrategyBaseTest.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -24,6 +24,7 @@ using System.Linq; using Core.Common.Base; using NUnit.Framework; +using Ringtoets.Common.Data.Exceptions; using Ringtoets.Common.Data.TestUtil; using Ringtoets.Common.Data.UpdateDataStrategies; @@ -203,7 +204,7 @@ } [Test] - public void UpdateTargetCollectionData_ImportedDataContainsDuplicateData_ThrowsArgumentException() + public void UpdateTargetCollectionData_ImportedDataContainsDuplicateData_ThrowsUpdateDataException() { // Setup var collection = new TestUniqueItemCollection(); @@ -225,9 +226,10 @@ TestDelegate call = () => strategy.ConcreteUpdateData(collection, importedCollection, sourceFilePath); // Assert - var exception = Assert.Throws(call); + var exception = Assert.Throws(call); string message = $"TestItem moeten een unieke naam hebben. Gevonden dubbele elementen: {duplicateName}."; Assert.AreEqual(message, exception.Message); + Assert.IsInstanceOf(exception.InnerException); CollectionAssert.IsEmpty(collection); } @@ -440,6 +442,37 @@ } [Test] + public void UpdateTargetCollectionData_CollectionNotEmptyAndImportedDataHasDuplicateDefinitions_ThrowsUpdateDataException() + { + // Setup + const string name = "Double Defined Name"; + var currentCollection = new[] + { + new TestItem(name) + }; + var collection = new TestUniqueItemCollection(); + collection.AddRange(currentCollection, sourceFilePath); + + var importedItems = new[] + { + new TestItem(name), + new TestItem(name) + }; + + var strategy = new ConcreteUpdateDataStrategy(new TestFailureMechanism()); + + // Call + TestDelegate call = () => strategy.ConcreteUpdateData(collection, + importedItems, + sourceFilePath); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("Geïmporteerde data moet unieke elementen bevatten.", exception.Message); + Assert.IsInstanceOf(exception.InnerException); + } + + [Test] public void UpdateTargetCollectionData_CalledWithSameObjectReferences_ReturnsOnlyDistinctObjects() { // Setup Index: Ringtoets/Common/test/Ringtoets.Common.Data.TestUtil.Test/TestDikeProfileTest.cs =================================================================== diff -u -rba715436cd0186ee10a1edc13d547ee27bea4c89 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Common/test/Ringtoets.Common.Data.TestUtil.Test/TestDikeProfileTest.cs (.../TestDikeProfileTest.cs) (revision ba715436cd0186ee10a1edc13d547ee27bea4c89) +++ Ringtoets/Common/test/Ringtoets.Common.Data.TestUtil.Test/TestDikeProfileTest.cs (.../TestDikeProfileTest.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -75,6 +75,31 @@ } [Test] + public void Constructor_WithNameAndId_ExpectedValues() + { + // Setup + const string name = "A"; + const string id = "Just an id"; + + // Call + var testProfile = new TestDikeProfile(name, id); + + // Assert + Assert.IsInstanceOf(testProfile); + Assert.IsNotNull(testProfile.ForeshoreProfile); + Assert.IsNull(testProfile.BreakWater); + CollectionAssert.IsEmpty(testProfile.DikeGeometry); + Assert.AreEqual(0, testProfile.DikeHeight.Value); + CollectionAssert.IsEmpty(testProfile.ForeshoreGeometry); + Assert.IsFalse(testProfile.HasBreakWater); + Assert.AreEqual(id, testProfile.Id); + Assert.AreEqual(name, testProfile.Name); + Assert.AreEqual(0, testProfile.Orientation.Value); + Assert.AreEqual(new Point2D(0, 0), testProfile.WorldReferencePoint); + Assert.AreEqual(0, testProfile.X0); + } + + [Test] public void Constructor_WithPoint_ExpectedValues() { // Setup @@ -99,6 +124,31 @@ } [Test] + public void Constructor_WithPointAndId_ExpectedValues() + { + // Setup + var point = new Point2D(1.1, 2.2); + const string id = "Just an id"; + + // Call + var testProfile = new TestDikeProfile(point, id); + + // Assert + Assert.IsInstanceOf(testProfile); + Assert.IsNotNull(testProfile.ForeshoreProfile); + Assert.IsNull(testProfile.BreakWater); + CollectionAssert.IsEmpty(testProfile.DikeGeometry); + Assert.AreEqual(0, testProfile.DikeHeight.Value); + CollectionAssert.IsEmpty(testProfile.ForeshoreGeometry); + Assert.IsFalse(testProfile.HasBreakWater); + Assert.AreEqual(id, testProfile.Id); + Assert.AreEqual(id, testProfile.Name); + Assert.AreEqual(0, testProfile.Orientation.Value); + Assert.AreEqual(point, testProfile.WorldReferencePoint); + Assert.AreEqual(0, testProfile.X0); + } + + [Test] public void Constructor_WithNameAndPoint_ExpectedValues() { // Setup @@ -127,10 +177,10 @@ public void Constructor_WithForeshoreGeometry_ExpectedValues() { // Setup - IEnumerable foreshoreProfileGeometry = new [] + IEnumerable foreshoreProfileGeometry = new[] { - new Point2D(0, 0), - new Point2D(1, 1), + new Point2D(0, 0), + new Point2D(1, 1), new Point2D(2, 2), }; @@ -150,5 +200,63 @@ Assert.AreEqual(new Point2D(0, 0), testProfile.WorldReferencePoint); Assert.AreEqual(0, testProfile.X0); } + + [Test] + public void Constructor_WithForeshoreProfileAndId_ExpectedValues() + { + // Setup + const string id = "Just an id"; + IEnumerable foreshoreProfileGeometry = new[] + { + new Point2D(0, 0), + new Point2D(1, 1), + new Point2D(2, 2), + }; + + // Call + var testProfile = new TestDikeProfile(foreshoreProfileGeometry, id); + + // Assert + Assert.IsInstanceOf(testProfile); + Assert.IsNotNull(testProfile.ForeshoreProfile); + Assert.IsNull(testProfile.BreakWater); + CollectionAssert.IsEmpty(testProfile.DikeGeometry); + Assert.AreEqual(0, testProfile.DikeHeight.Value); + CollectionAssert.AreEqual(foreshoreProfileGeometry, testProfile.ForeshoreGeometry); + Assert.IsFalse(testProfile.HasBreakWater); + Assert.AreEqual(id, testProfile.Id); + Assert.AreEqual(id, testProfile.Name); + Assert.AreEqual(0, testProfile.Orientation.Value); + Assert.AreEqual(new Point2D(0, 0), testProfile.WorldReferencePoint); + Assert.AreEqual(0, testProfile.X0); + } + + [Test] + public void Constructor_WithDikeGeometry_ExpectedValues() + { + // Setup + IEnumerable foreshoreProfileGeometry = new[] + { + new RoughnessPoint(new Point2D(0, 0), 5), + new RoughnessPoint(new Point2D(1, 1), 6), + new RoughnessPoint(new Point2D(2, 2), 7) + }; + + var testProfile = new TestDikeProfile(foreshoreProfileGeometry); + + // Assert + Assert.IsInstanceOf(testProfile); + Assert.IsNotNull(testProfile.ForeshoreProfile); + Assert.IsNull(testProfile.BreakWater); + CollectionAssert.AreEqual(foreshoreProfileGeometry, testProfile.DikeGeometry); + Assert.AreEqual(0, testProfile.DikeHeight.Value); + CollectionAssert.IsEmpty(testProfile.ForeshoreGeometry); + Assert.IsFalse(testProfile.HasBreakWater); + Assert.AreEqual("id", testProfile.Id); + Assert.AreEqual("id", testProfile.Name); + Assert.AreEqual(0, testProfile.Orientation.Value); + Assert.AreEqual(new Point2D(0, 0), testProfile.WorldReferencePoint); + Assert.AreEqual(0, testProfile.X0); + } } } \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Data.TestUtil/TestDikeProfile.cs =================================================================== diff -u -rba715436cd0186ee10a1edc13d547ee27bea4c89 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Common/test/Ringtoets.Common.Data.TestUtil/TestDikeProfile.cs (.../TestDikeProfile.cs) (revision ba715436cd0186ee10a1edc13d547ee27bea4c89) +++ Ringtoets/Common/test/Ringtoets.Common.Data.TestUtil/TestDikeProfile.cs (.../TestDikeProfile.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -19,6 +19,7 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System; using System.Collections.Generic; using System.Linq; using Core.Common.Base.Geometry; @@ -37,18 +38,42 @@ public TestDikeProfile() : this(new Point2D(0, 0)) {} /// - /// Initializes default at the world origin. + /// Initializes default at the world origin + /// with a specified name. /// /// The name of the dike profile. public TestDikeProfile(string name) : this(name, new Point2D(0, 0)) {} /// - /// Initializes default at the world location. + /// Initializes default at the world origin + /// with a specified name and ID. /// + /// The name of the dike profile. + /// The ID of the dike profile. + /// Thrown when is + /// null, empty, or consists of whitespace. + public TestDikeProfile(string name, string id) + : this(id, name, new Point2D(0, 0), Enumerable.Empty(), Enumerable.Empty()) {} + + /// + /// Initializes default at a specified world + /// location. + /// /// The world coordinate of the dike profile. public TestDikeProfile(Point2D point) : this(null, point) {} /// + /// Initializes default at a specified world + /// location and ID. + /// + /// The world coordinate of the dike profile. + /// The ID of the dike profile. + /// Thrown when is + /// null, empty, or consists of whitespace. + public TestDikeProfile(Point2D point, string id) + : this(id, null, point, Enumerable.Empty(), Enumerable.Empty()) {} + + /// /// Initializes default at the world origin with /// a specified foreshore profile geometry. /// @@ -58,6 +83,17 @@ /// /// Initializes default at the world origin with + /// a specified foreshore profile geometry and ID. + /// + /// The geometry of the . + /// The ID of the dike profile. + /// Thrown when is + /// null, empty, or consists of whitespace. + public TestDikeProfile(IEnumerable foreshoreProfileGeometry, string id) + : this(id, null, new Point2D(0, 0), Enumerable.Empty(), foreshoreProfileGeometry) {} + + /// + /// Initializes default at the world origin with /// a specified dike profile geometry. /// /// The geometry of the . @@ -69,7 +105,8 @@ /// /// The name of the dike profile. /// The world coordinate of the dike profile. - public TestDikeProfile(string name, Point2D point) : this("id", name, point, Enumerable.Empty(), Enumerable.Empty()) {} + public TestDikeProfile(string name, Point2D point) + : this("id", name, point, Enumerable.Empty(), Enumerable.Empty()) {} /// /// Initializes default at the world location with @@ -80,6 +117,8 @@ /// The world coordinate of the dike profile. /// The geometry of the dike. /// The geometry of the . + /// Thrown when is + /// null, empty, or consists of whitespace. private TestDikeProfile(string id, string name, Point2D point, IEnumerable dikeGeometry, IEnumerable foreshoreProfileGeometry) : base(point, dikeGeometry, foreshoreProfileGeometry, null, new ConstructionProperties { Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/ChangeHandlers/FailureMechanismCalculationChangeHandlerTest.cs =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/ChangeHandlers/FailureMechanismCalculationChangeHandlerTest.cs (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/ChangeHandlers/FailureMechanismCalculationChangeHandlerTest.cs (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -0,0 +1,205 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Linq; +using Core.Common.Gui; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Forms.ChangeHandlers; +using Ringtoets.Common.IO; + +namespace Ringtoets.Common.Forms.Test.ChangeHandlers +{ + [TestFixture] + public class FailureMechanismCalculationChangeHandlerTest + { + [Test] + public void Constructor_WithoutFailureMechanism_ThrowsArgumentNullException() + { + // Setup + var mockRepository = new MockRepository(); + var inquiryHandler = mockRepository.Stub(); + mockRepository.ReplayAll(); + + // Call + TestDelegate test = () => new FailureMechanismCalculationChangeHandler(null, string.Empty, inquiryHandler); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("failureMechanism", paramName); + mockRepository.VerifyAll(); + } + + [Test] + public void Constructor_WithoutQuery_ThrowsArgumentNullException() + { + // Setup + var mockRepository = new MockRepository(); + var inquiryHandler = mockRepository.Stub(); + var failureMechanism = mockRepository.Stub(); + mockRepository.ReplayAll(); + + // Call + TestDelegate test = () => new FailureMechanismCalculationChangeHandler(failureMechanism, null, inquiryHandler); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("query", paramName); + mockRepository.VerifyAll(); + } + + [Test] + public void Constructor_WithoutInquiryHandler_ThrowsArgumentNullException() + { + // Setup + var mockRepository = new MockRepository(); + var failureMechanism = mockRepository.Stub(); + mockRepository.ReplayAll(); + + // Call + TestDelegate test = () => new FailureMechanismCalculationChangeHandler(failureMechanism, string.Empty, null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("inquiryHandler", paramName); + mockRepository.VerifyAll(); + } + + [Test] + public void Constructor_WithParameters_ImplementsExpectedInterface() + { + // Setup + var mockRepository = new MockRepository(); + var inquiryHandler = mockRepository.Stub(); + var failureMechanism = mockRepository.Stub(); + mockRepository.ReplayAll(); + + // Call + var handler = new FailureMechanismCalculationChangeHandler(failureMechanism, string.Empty, inquiryHandler); + + // Assert + Assert.IsInstanceOf(handler); + mockRepository.VerifyAll(); + } + + [Test] + public void RequireConfirmation_FailureMechanismWithoutCalculations_ReturnsFalse() + { + // Setup + var mockRepository = new MockRepository(); + var inquiryHandler = mockRepository.StrictMock(); + mockRepository.ReplayAll(); + + var failureMechanism = new TestFailureMechanism(Enumerable.Empty()); + + var handler = new FailureMechanismCalculationChangeHandler(failureMechanism, string.Empty, inquiryHandler); + + // Call + bool requireConfirmation = handler.RequireConfirmation(); + + // Assert + Assert.IsFalse(requireConfirmation); + mockRepository.VerifyAll(); + } + + [Test] + public void RequireConfirmation_FailureMechanismWithCalculationWithoutOutput_ReturnFalse() + { + // Setup + var mockRepository = new MockRepository(); + var inquiryHandler = mockRepository.StrictMock(); + + var calculation = mockRepository.StrictMock(); + calculation.Expect(calc => calc.HasOutput).Return(false); + mockRepository.ReplayAll(); + + var failureMechanism = new TestFailureMechanism(new[] + { + calculation + }); + + var handler = new FailureMechanismCalculationChangeHandler(failureMechanism, string.Empty, inquiryHandler); + + // Call + bool requireConfirmation = handler.RequireConfirmation(); + + // Assert + Assert.IsFalse(requireConfirmation); + mockRepository.VerifyAll(); + } + + [Test] + public void RequireConfirmation_FailureMechanismWithCalculationWithOutput_ReturnTrue() + { + // Setup + var mockRepository = new MockRepository(); + var inquiryHandler = mockRepository.StrictMock(); + + var calculation = mockRepository.StrictMock(); + calculation.Expect(calc => calc.HasOutput).Return(true); + mockRepository.ReplayAll(); + + var failureMechanism = new TestFailureMechanism(new[] + { + calculation + }); + + var handler = new FailureMechanismCalculationChangeHandler(failureMechanism, string.Empty, inquiryHandler); + + // Call + bool requireConfirmation = handler.RequireConfirmation(); + + // Assert + Assert.IsTrue(requireConfirmation); + mockRepository.VerifyAll(); + } + + [Test] + [TestCase("I am a query", true)] + [TestCase("I am a query", false)] + [TestCase("", true)] + [TestCase("", false)] + [TestCase(" ", true)] + [TestCase(" ", false)] + public void InquireConfirmation_Always_ShowsConfirmationDialogReturnResultOfInquiry(string message, bool expectedResult) + { + // Setup + var mockRepository = new MockRepository(); + var inquiryHandler = mockRepository.StrictMock(); + inquiryHandler.Expect(ih => ih.InquireContinuation(message)).Return(expectedResult); + var failureMechanism = mockRepository.Stub(); + mockRepository.ReplayAll(); + + var handler = new FailureMechanismCalculationChangeHandler(failureMechanism, message, inquiryHandler); + + // Call + bool result = handler.InquireConfirmation(); + + // Assert + Assert.AreEqual(expectedResult, result); + mockRepository.VerifyAll(); + } + } +} \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Ringtoets.Common.Forms.Test.csproj =================================================================== diff -u -rc63ac515f0ce88fbc058e1838d1a43ed6a912360 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Ringtoets.Common.Forms.Test.csproj (.../Ringtoets.Common.Forms.Test.csproj) (revision c63ac515f0ce88fbc058e1838d1a43ed6a912360) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Ringtoets.Common.Forms.Test.csproj (.../Ringtoets.Common.Forms.Test.csproj) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -67,6 +67,7 @@ Properties\GlobalAssembly.cs + @@ -196,6 +197,10 @@ {4d840673-3812-4338-a352-84854e32b8a0} Ringtoets.Common.Forms + + {52BA7627-CBAB-4209-BE77-3B5F31378277} + Ringtoets.Common.IO + {d951d6da-fe83-4920-9fdb-63bf96480b54} Ringtoets.Common.Service Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/FileImporters/DikeProfilesImporterTest.cs =================================================================== diff -u -r1f549a37af503f5da697652b5e5199f8d29ac0fe -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/FileImporters/DikeProfilesImporterTest.cs (.../DikeProfilesImporterTest.cs) (revision 1f549a37af503f5da697652b5e5199f8d29ac0fe) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/FileImporters/DikeProfilesImporterTest.cs (.../DikeProfilesImporterTest.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -22,40 +22,63 @@ using System; using System.Collections.Generic; using System.IO; -using System.Linq; using Core.Common.Base; using Core.Common.Base.Data; using Core.Common.Base.Geometry; using Core.Common.TestUtil; using NUnit.Framework; +using Rhino.Mocks; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.DikeProfiles; using Ringtoets.Common.IO.FileImporters; +using Ringtoets.Common.IO.FileImporters.MessageProviders; +using Ringtoets.Common.IO.TestUtil; namespace Ringtoets.Common.IO.Test.FileImporters { [TestFixture] public class DikeProfilesImporterTest { + private MockRepository mocks; + + [SetUp] + public void Setup() + { + mocks = new MockRepository(); + } + + [TearDown] + public void TearDown() + { + mocks.VerifyAll(); + } + [Test] public void Constructor_WithValidParameters_ReturnsNewInstance() { // Setup - var importTarget = new ObservableList(); + var messageProvider = mocks.Stub(); + mocks.ReplayAll(); + + var importTarget = new DikeProfileCollection(); var referenceLine = new ReferenceLine(); // Call - var importer = new DikeProfilesImporter(importTarget, referenceLine, ""); + var importer = new DikeProfilesImporter(importTarget, referenceLine, "", new TestDikeProfileUpdateStrategy(), messageProvider); // Assert - Assert.IsInstanceOf>>(importer); + Assert.IsInstanceOf>(importer); } [Test] public void Constructor_ImportTargetNull_ThrowArgumentNullException() { + // Setup + var messageProvider = mocks.Stub(); + mocks.ReplayAll(); + // Call - TestDelegate call = () => new DikeProfilesImporter(null, new ReferenceLine(), ""); + TestDelegate call = () => new DikeProfilesImporter(null, new ReferenceLine(), "", new TestDikeProfileUpdateStrategy(), messageProvider); // Assert var exception = Assert.Throws(call); @@ -65,8 +88,12 @@ [Test] public void Constructor_ReferenceLineNull_ThrowArgumentNullException() { + // Setup + var messageProvider = mocks.Stub(); + mocks.ReplayAll(); + // Call - TestDelegate call = () => new DikeProfilesImporter(new ObservableList(), null, ""); + TestDelegate call = () => new DikeProfilesImporter(new DikeProfileCollection(), null, "", new TestDikeProfileUpdateStrategy(), messageProvider); // Assert var exception = Assert.Throws(call); @@ -76,75 +103,118 @@ [Test] public void Constructor_FilePathNull_ThrowArgumentNullException() { + // Setup + var messageProvider = mocks.Stub(); + mocks.ReplayAll(); + // Call - TestDelegate call = () => new DikeProfilesImporter(new ObservableList(), new ReferenceLine(), null); + TestDelegate call = () => new DikeProfilesImporter(new DikeProfileCollection(), new ReferenceLine(), null, new TestDikeProfileUpdateStrategy(), messageProvider); // Assert var exception = Assert.Throws(call); Assert.AreEqual("filePath", exception.ParamName); } [Test] + public void Constructor_UpdateStrategyNull_ThrowsArgumentNullException() + { + // Setup + var messageProvider = mocks.Stub(); + mocks.ReplayAll(); + + // Call + TestDelegate call = () => new DikeProfilesImporter(new DikeProfileCollection(), new ReferenceLine(), string.Empty, null, messageProvider); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("dikeProfileUpdateStrategy", exception.ParamName); + } + + [Test] + public void Constructor_MessageProviderNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => new DikeProfilesImporter(new DikeProfileCollection(), new ReferenceLine(), string.Empty, + new TestDikeProfileUpdateStrategy(), null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("messageProvider", exception.ParamName); + } + + [Test] public void Import_FromFileWithUnmatchableId_TrueAndLogError() { // Setup + var messageProvider = mocks.Stub(); + mocks.ReplayAll(); + string filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, Path.Combine("DikeProfiles", "IpflWithUnmatchableId", "Voorlanden_12-2_UnmatchableId.shp")); ReferenceLine referenceLine = CreateMatchingReferenceLine(); - var dikeProfiles = new ObservableList(); - - var dikeProfilesImporter = new DikeProfilesImporter(dikeProfiles, referenceLine, filePath); + var dikeProfilesImporter = new DikeProfilesImporter(new DikeProfileCollection(), + referenceLine, filePath, + new TestDikeProfileUpdateStrategy(), messageProvider); var importResult = false; // Call Action call = () => importResult = dikeProfilesImporter.Import(); // Assert - TestHelper.AssertLogMessages(call, messages => - { - string[] messageArray = messages.ToArray(); - string expectedMessage = "Kan geen geldige gegevens vinden voor dijkprofiellocatie met ID 'unmatchable'."; - Assert.AreEqual(expectedMessage, messageArray[0]); - }); + const string expectedMessage = "Kan geen geldige gegevens vinden voor dijkprofiellocatie met ID 'unmatchable'."; + var expectedLogMessage = new Tuple(expectedMessage, LogLevelConstant.Error); + TestHelper.AssertLogMessageWithLevelIsGenerated(call, expectedLogMessage, 1); Assert.IsTrue(importResult); } [Test] public void Import_FiveDikeProfilesWithoutGeometries_TrueAndLogWarningAndNoDikeProfiles() { // Setup + var messageProvider = mocks.Stub(); + mocks.ReplayAll(); + string fileDirectory = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Integration.Plugin, Path.Combine("DikeProfiles", "NoDikeProfileGeometries")); string filePath = Path.Combine(fileDirectory, "Voorlanden 12-2.shp"); ReferenceLine referenceLine = CreateMatchingReferenceLine(); - var dikeProfiles = new ObservableList(); - var dikeProfilesImporter = new DikeProfilesImporter(dikeProfiles, referenceLine, filePath); + var updateStrategy = new TestDikeProfileUpdateStrategy(); + var dikeProfilesImporter = new DikeProfilesImporter(new DikeProfileCollection(), referenceLine, filePath, updateStrategy, messageProvider); // Call - bool importResult = false; + var importResult = false; Action call = () => importResult = dikeProfilesImporter.Import(); // Assert - string[] expectedMessages = + var expectedMessages = new[] { - string.Format("Profielgegevens definiëren geen dijkgeometrie. Bestand '{0}' wordt overgeslagen.", Path.Combine(fileDirectory, "profiel001 - Ringtoets.prfl")), - string.Format("Profielgegevens definiëren geen dijkgeometrie. Bestand '{0}' wordt overgeslagen.", Path.Combine(fileDirectory, "profiel002 - Ringtoets.prfl")), - string.Format("Profielgegevens definiëren geen dijkgeometrie. Bestand '{0}' wordt overgeslagen.", Path.Combine(fileDirectory, "profiel003 - Ringtoets.prfl")), - string.Format("Profielgegevens definiëren geen dijkgeometrie. Bestand '{0}' wordt overgeslagen.", Path.Combine(fileDirectory, "profiel004 - Ringtoets.prfl")), - string.Format("Profielgegevens definiëren geen dijkgeometrie. Bestand '{0}' wordt overgeslagen.", Path.Combine(fileDirectory, "profiel005 - Ringtoets.prfl")) + Tuple.Create($"Profielgegevens definiëren geen dijkgeometrie. Bestand '{Path.Combine(fileDirectory, "profiel001 - Ringtoets.prfl")}' wordt overgeslagen.", + LogLevelConstant.Warn), + Tuple.Create($"Profielgegevens definiëren geen dijkgeometrie. Bestand '{Path.Combine(fileDirectory, "profiel002 - Ringtoets.prfl")}' wordt overgeslagen.", + LogLevelConstant.Warn), + Tuple.Create($"Profielgegevens definiëren geen dijkgeometrie. Bestand '{Path.Combine(fileDirectory, "profiel003 - Ringtoets.prfl")}' wordt overgeslagen.", + LogLevelConstant.Warn), + Tuple.Create($"Profielgegevens definiëren geen dijkgeometrie. Bestand '{Path.Combine(fileDirectory, "profiel004 - Ringtoets.prfl")}' wordt overgeslagen.", + LogLevelConstant.Warn), + Tuple.Create($"Profielgegevens definiëren geen dijkgeometrie. Bestand '{Path.Combine(fileDirectory, "profiel005 - Ringtoets.prfl")}' wordt overgeslagen.", + LogLevelConstant.Warn) }; - TestHelper.AssertLogMessagesAreGenerated(call, expectedMessages); + TestHelper.AssertLogMessagesWithLevelAreGenerated(call, expectedMessages); Assert.IsTrue(importResult); - Assert.AreEqual(0, dikeProfiles.Count); + Assert.IsTrue(updateStrategy.Updated); + Assert.AreEqual(0, updateStrategy.ReadDikeProfiles.Length); } [Test] public void Import_OneDikeProfileLocationNotCloseEnoughToReferenceLine_TrueAndLogErrorAndFourDikeProfiles() { // Setup + var messageProvider = mocks.Stub(); + mocks.ReplayAll(); + string filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, Path.Combine("DikeProfiles", "AllOkTestData", "Voorlanden 12-2.shp")); @@ -159,8 +229,8 @@ var referenceLine = new ReferenceLine(); referenceLine.SetGeometry(referencePoints); - var dikeProfiles = new ObservableList(); - var dikeProfilesImporter = new DikeProfilesImporter(dikeProfiles, referenceLine, filePath); + var updateDataStrategy = new TestDikeProfileUpdateStrategy(); + var dikeProfilesImporter = new DikeProfilesImporter(new DikeProfileCollection(), referenceLine, filePath, updateDataStrategy, messageProvider); var importResult = false; @@ -171,32 +241,40 @@ string expectedMessage = "Fout bij het lezen van profiellocatie 5. De profiellocatie met " + "ID 'profiel005' ligt niet op de referentielijn. " + "Dit profiel wordt overgeslagen."; - TestHelper.AssertLogMessageIsGenerated(call, expectedMessage); + var expectedLogMessage = new Tuple(expectedMessage, + LogLevelConstant.Error); + TestHelper.AssertLogMessageWithLevelIsGenerated(call, expectedLogMessage, 1); Assert.IsTrue(importResult); - Assert.AreEqual(4, dikeProfiles.Count); + Assert.IsTrue(updateDataStrategy.Updated); + Assert.AreEqual(4, updateDataStrategy.ReadDikeProfiles.Length); } [Test] public void Import_AllOkTestData_TrueAndLogMessagesAndFiveDikeProfiles() { // Setup + const string expectedAddDataToModelProgressText = "Adding data"; + var messageProvider = mocks.StrictMock(); + messageProvider.Expect(mp => mp.GetAddDataToModelProgressText()).Return(expectedAddDataToModelProgressText); + mocks.ReplayAll(); + string filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, Path.Combine("DikeProfiles", "AllOkTestData", "Voorlanden 12-2.shp")); ReferenceLine referenceLine = CreateMatchingReferenceLine(); var progressChangeNotifications = new List(); - var dikeProfiles = new ObservableList(); - var dikeProfilesImporter = new DikeProfilesImporter(dikeProfiles, referenceLine, filePath); + var updateDataStrategy = new TestDikeProfileUpdateStrategy(); + var dikeProfilesImporter = new DikeProfilesImporter(new DikeProfileCollection(), referenceLine, filePath, updateDataStrategy, messageProvider); dikeProfilesImporter.SetProgressChanged((description, step, steps) => { progressChangeNotifications.Add(new ProgressNotification(description, step, steps)); }); // Call bool importResult = dikeProfilesImporter.Import(); // Assert Assert.IsTrue(importResult); - List expectedProgressMessages = new List + var expectedProgressMessages = new List { new ProgressNotification("Inlezen van profiellocaties uit een shapebestand.", 1, 1), new ProgressNotification("Inlezen van profiellocatie.", 1, 5), @@ -210,28 +288,36 @@ new ProgressNotification("Inlezen van profielgegevens.", 3, 5), new ProgressNotification("Inlezen van profielgegevens.", 4, 5), new ProgressNotification("Inlezen van profielgegevens.", 5, 5), - new ProgressNotification("Geïmporteerde data toevoegen aan het toetsspoor.", 1, 1) + new ProgressNotification(expectedAddDataToModelProgressText, 1, 1) }; ValidateProgressMessages(expectedProgressMessages, progressChangeNotifications); - Assert.AreEqual(5, dikeProfiles.Count); + + Assert.IsTrue(updateDataStrategy.Updated); + Assert.AreEqual(5, updateDataStrategy.ReadDikeProfiles.Length); } [Test] public void Import_AllOkTestData_CorrectDikeProfileProperties() { // Setup + var messageProvider = mocks.Stub(); + mocks.ReplayAll(); + string filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, Path.Combine("DikeProfiles", "AllOkTestData", "Voorlanden 12-2.shp")); ReferenceLine referenceLine = CreateMatchingReferenceLine(); - var dikeProfiles = new ObservableList(); - var dikeProfilesImporter = new DikeProfilesImporter(dikeProfiles, referenceLine, filePath); + var updateDataStrategy = new TestDikeProfileUpdateStrategy(); + var dikeProfilesImporter = new DikeProfilesImporter(new DikeProfileCollection(), referenceLine, filePath, updateDataStrategy, messageProvider); // Call dikeProfilesImporter.Import(); // Assert + Assert.IsTrue(updateDataStrategy.Updated); + + DikeProfile[] dikeProfiles = updateDataStrategy.ReadDikeProfiles; DikeProfile dikeProfile1 = dikeProfiles[0]; Assert.AreEqual("profiel001", dikeProfile1.Id); Assert.AreEqual("profiel001", dikeProfile1.Name); @@ -266,23 +352,28 @@ public void Import_AllDamTypes_TrueAndLogMessagesAndFiveDikeProfiles() { // Setup + const string expectedAddDataToModelProgressText = "Adding data"; + var messageProvider = mocks.Stub(); + messageProvider.Expect(mp => mp.GetAddDataToModelProgressText()).Return(expectedAddDataToModelProgressText); + mocks.ReplayAll(); + string filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, Path.Combine("DikeProfiles", "AllDamTypes", "Voorlanden 12-2.shp")); ReferenceLine referenceLine = CreateMatchingReferenceLine(); var progressChangeNotifications = new List(); - var dikeProfiles = new ObservableList(); - var dikeProfilesImporter = new DikeProfilesImporter(dikeProfiles, referenceLine, filePath); + var updateDataStrategy = new TestDikeProfileUpdateStrategy(); + var dikeProfilesImporter = new DikeProfilesImporter(new DikeProfileCollection(), referenceLine, filePath, updateDataStrategy, messageProvider); dikeProfilesImporter.SetProgressChanged((description, step, steps) => progressChangeNotifications.Add(new ProgressNotification(description, step, steps))); // Call bool importResult = dikeProfilesImporter.Import(); // Assert Assert.IsTrue(importResult); - List expectedProgressMessages = new List + var expectedProgressMessages = new List { new ProgressNotification("Inlezen van profiellocaties uit een shapebestand.", 1, 1), new ProgressNotification("Inlezen van profiellocatie.", 1, 5), @@ -296,22 +387,31 @@ new ProgressNotification("Inlezen van profielgegevens.", 3, 5), new ProgressNotification("Inlezen van profielgegevens.", 4, 5), new ProgressNotification("Inlezen van profielgegevens.", 5, 5), - new ProgressNotification("Geïmporteerde data toevoegen aan het toetsspoor.", 1, 1) + new ProgressNotification(expectedAddDataToModelProgressText, 1, 1) }; ValidateProgressMessages(expectedProgressMessages, progressChangeNotifications); - Assert.AreEqual(5, dikeProfiles.Count); + Assert.IsTrue(updateDataStrategy.Updated); + Assert.AreEqual(5, updateDataStrategy.ReadDikeProfiles.Length); } [Test] public void Import_CancelOfImportWhileReadingProfileLocations_CancelImportAndLogs() { // Setup + const string cancelledLogMessage = "Operation Cancelled"; + + var mocks = new MockRepository(); + var messageProvider = mocks.StrictMock(); + messageProvider.Expect(mp => mp.GetCancelledLogMessageText("Dijkprofielen")).Return(cancelledLogMessage); + mocks.ReplayAll(); + string filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, Path.Combine("DikeProfiles", "AllOkTestData", "Voorlanden 12-2.shp")); ReferenceLine referenceLine = CreateMatchingReferenceLine(); - var dikeProfiles = new ObservableList(); - var dikeProfilesImporter = new DikeProfilesImporter(dikeProfiles, referenceLine, filePath); + var updateDataStrategy = new TestDikeProfileUpdateStrategy(); + var dikeProfilesImporter = new DikeProfilesImporter(new DikeProfileCollection(), referenceLine, filePath, + updateDataStrategy, messageProvider); dikeProfilesImporter.SetProgressChanged((description, step, steps) => { if (description.Contains("Inlezen van profiellocaties uit een shapebestand.")) @@ -320,27 +420,35 @@ } }); - bool importResult = true; + var importResult = true; // Call Action call = () => importResult = dikeProfilesImporter.Import(); // Assert - TestHelper.AssertLogMessageIsGenerated(call, "Dijkprofielen importeren is afgebroken. Geen gegevens ingelezen.", 1); + var expectedLogMessage = new Tuple(cancelledLogMessage, + LogLevelConstant.Info); + TestHelper.AssertLogMessageWithLevelIsGenerated(call, expectedLogMessage, 1); Assert.IsFalse(importResult); - CollectionAssert.IsEmpty(dikeProfiles); + Assert.IsFalse(updateDataStrategy.Updated); } [Test] public void Import_CancelOfImportWhileReadingDikeProfileData_CancelImportAndLogs() { // Setup + const string cancelledLogMessage = "Operation Cancelled"; + var messageProvider = mocks.StrictMock(); + messageProvider.Expect(mp => mp.GetCancelledLogMessageText("Dijkprofielen")).Return(cancelledLogMessage); + mocks.ReplayAll(); + string filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, Path.Combine("DikeProfiles", "AllOkTestData", "Voorlanden 12-2.shp")); ReferenceLine referenceLine = CreateMatchingReferenceLine(); - var dikeProfiles = new ObservableList(); - var dikeProfilesImporter = new DikeProfilesImporter(dikeProfiles, referenceLine, filePath); + var updateDataStrategy = new TestDikeProfileUpdateStrategy(); + var dikeProfilesImporter = new DikeProfilesImporter(new DikeProfileCollection(), referenceLine, filePath, + updateDataStrategy, messageProvider); dikeProfilesImporter.SetProgressChanged((description, step, steps) => { if (description.Contains("Inlezen van profielgegevens uit een prfl bestand.")) @@ -349,34 +457,39 @@ } }); - bool importResult = true; + var importResult = true; // Call Action call = () => importResult = dikeProfilesImporter.Import(); // Assert - TestHelper.AssertLogMessageIsGenerated(call, "Dijkprofielen importeren is afgebroken. Geen gegevens ingelezen.", 1); + var expectedLogMessage = new Tuple(cancelledLogMessage, + LogLevelConstant.Info); + TestHelper.AssertLogMessageWithLevelIsGenerated(call, expectedLogMessage, 1); Assert.IsFalse(importResult); - CollectionAssert.IsEmpty(dikeProfiles); + Assert.IsFalse(updateDataStrategy.Updated); } [Test] public void Import_ReuseOfCanceledImportToValidTargetWithValidFile_TrueAndLogMessagesAndFiveDikeProfiles() { // Setup + var messageProvider = mocks.Stub(); + mocks.ReplayAll(); + string filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, Path.Combine("DikeProfiles", "AllOkTestData", "Voorlanden 12-2.shp")); ReferenceLine referenceLine = CreateMatchingReferenceLine(); - var dikeProfiles = new ObservableList(); - var dikeProfilesImporter = new DikeProfilesImporter(dikeProfiles, referenceLine, filePath); + var updateDataStrategy = new TestDikeProfileUpdateStrategy(); + var dikeProfilesImporter = new DikeProfilesImporter(new DikeProfileCollection(), referenceLine, filePath, updateDataStrategy, messageProvider); dikeProfilesImporter.SetProgressChanged((description, step, steps) => dikeProfilesImporter.Cancel()); - // Pre-condition + // Pre-condition bool importResult = dikeProfilesImporter.Import(); Assert.IsFalse(importResult); - CollectionAssert.IsEmpty(dikeProfiles); + CollectionAssert.IsEmpty(new DikeProfileCollection()); dikeProfilesImporter.SetProgressChanged(null); @@ -385,11 +498,47 @@ // Assert Assert.IsTrue(importResult); - Assert.AreEqual(5, dikeProfiles.Count); + Assert.IsTrue(updateDataStrategy.Updated); + Assert.AreEqual(5, updateDataStrategy.ReadDikeProfiles.Length); } - private ReferenceLine CreateMatchingReferenceLine() + [Test] + public void DoPostImport_AfterImport_ObserversNotified() { + // Setup + var messageProvider = mocks.Stub(); + var observableA = mocks.StrictMock(); + observableA.Expect(o => o.NotifyObservers()); + var observableB = mocks.StrictMock(); + observableB.Expect(o => o.NotifyObservers()); + mocks.ReplayAll(); + + var updateDataStrategy = new TestDikeProfileUpdateStrategy(); + updateDataStrategy.UpdatedInstances = new[] + { + observableA, + observableB + }; + + string filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, + Path.Combine("DikeProfiles", "AllOkTestData", "Voorlanden 12-2.shp")); + ReferenceLine referenceLine = CreateMatchingReferenceLine(); + + var importer = new DikeProfilesImporter(new DikeProfileCollection(), + referenceLine, + filePath, + updateDataStrategy, messageProvider); + importer.Import(); + + // Call + importer.DoPostImport(); + + // Assert + // Asserts done in TearDown() + } + + private static ReferenceLine CreateMatchingReferenceLine() + { var referenceLine = new ReferenceLine(); referenceLine.SetGeometry(new[] { @@ -402,13 +551,14 @@ return referenceLine; } - private static void ValidateProgressMessages(List expectedProgressMessages, List progressChangeNotifications) + private static void ValidateProgressMessages(List expectedProgressMessages, + List progressChangeNotifications) { Assert.AreEqual(expectedProgressMessages.Count, progressChangeNotifications.Count); for (var i = 0; i < expectedProgressMessages.Count; i++) { - var notification = expectedProgressMessages[i]; - var actualNotification = progressChangeNotifications[i]; + ProgressNotification notification = expectedProgressMessages[i]; + ProgressNotification actualNotification = progressChangeNotifications[i]; Assert.AreEqual(notification.Text, actualNotification.Text); Assert.AreEqual(notification.CurrentStep, actualNotification.CurrentStep); Assert.AreEqual(notification.TotalSteps, actualNotification.TotalSteps); Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/FileImporters/ProfilesImporterTest.cs =================================================================== diff -u -r7b85dbce8bcc39e824c367468892764778527ce4 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/FileImporters/ProfilesImporterTest.cs (.../ProfilesImporterTest.cs) (revision 7b85dbce8bcc39e824c367468892764778527ce4) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/FileImporters/ProfilesImporterTest.cs (.../ProfilesImporterTest.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -30,9 +30,11 @@ using Core.Common.TestUtil; using Core.Common.Utils.Builders; using NUnit.Framework; +using Rhino.Mocks; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.IO.DikeProfiles; using Ringtoets.Common.IO.FileImporters; +using Ringtoets.Common.IO.FileImporters.MessageProviders; using CoreCommonUtilsResources = Core.Common.Utils.Properties.Resources; namespace Ringtoets.Common.IO.Test.FileImporters @@ -44,11 +46,29 @@ private readonly ReferenceLine testReferenceLine = new ReferenceLine(); private readonly string testFilePath = string.Empty; + private MockRepository mocks; + + [SetUp] + public void Setup() + { + mocks = new MockRepository(); + } + + [TearDown] + public void TearDown() + { + mocks.VerifyAll(); + } + [Test] public void ParameteredConstructor_ExpectedValues() { + // Setup + var messageProvider = mocks.Stub(); + mocks.ReplayAll(); + // Call - var importer = new TestProfilesImporter(testImportTarget, testReferenceLine, testFilePath); + var importer = new TestProfilesImporter(testImportTarget, testReferenceLine, testFilePath, messageProvider); // Assert Assert.IsInstanceOf(importer); @@ -57,8 +77,12 @@ [Test] public void ParameteredConstructor_ImportTargetNull_ThrowArgumentNullException() { + // Setup + var messageProvider = mocks.Stub(); + mocks.ReplayAll(); + // Call - TestDelegate call = () => new TestProfilesImporter(null, testReferenceLine, testFilePath); + TestDelegate call = () => new TestProfilesImporter(null, testReferenceLine, testFilePath, messageProvider); // Assert var exception = Assert.Throws(call); @@ -68,8 +92,12 @@ [Test] public void ParameteredConstructor_ReferenceLineNull_ThrowArgumentNullException() { + // Setup + var messageProvider = mocks.Stub(); + mocks.ReplayAll(); + // Call - TestDelegate call = () => new TestProfilesImporter(testImportTarget, null, testFilePath); + TestDelegate call = () => new TestProfilesImporter(testImportTarget, null, testFilePath, messageProvider); // Assert var exception = Assert.Throws(call); @@ -79,22 +107,40 @@ [Test] public void ParameteredConstructor_FilePathNull_ThrowArgumentNullException() { + // Setup + var messageProvider = mocks.Stub(); + mocks.ReplayAll(); + // Call - TestDelegate call = () => new TestProfilesImporter(testImportTarget, testReferenceLine, null); + TestDelegate call = () => new TestProfilesImporter(testImportTarget, testReferenceLine, null, messageProvider); // Assert var exception = Assert.Throws(call); Assert.AreEqual("filePath", exception.ParamName); } [Test] + public void ParameteredConstructor_MessageProviderNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => new TestProfilesImporter(testImportTarget, testReferenceLine, testFilePath, null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("messageProvider", exception.ParamName); + } + + [Test] [TestCase("")] [TestCase(" ")] public void Import_FromInvalidEmptyPath_FalseAndLogError(string filePath) { // Setup - var testProfilesImporter = new TestProfilesImporter(testImportTarget, testReferenceLine, filePath); + var messageProvider = mocks.Stub(); + mocks.ReplayAll(); + var testProfilesImporter = new TestProfilesImporter(testImportTarget, testReferenceLine, filePath, messageProvider); + // Call var importResult = true; Action call = () => importResult = testProfilesImporter.Import(); @@ -114,12 +160,15 @@ public void Import_FromPathContainingInvalidPathCharacters_FalseAndLogError() { // Setup + var messageProvider = mocks.Stub(); + mocks.ReplayAll(); + const string filePath = "c:\\Invalid_Characters.shp"; var invalidPathChars = Path.GetInvalidPathChars(); var invalidPath = filePath.Replace('_', invalidPathChars[0]); - var testProfilesImporter = new TestProfilesImporter(testImportTarget, testReferenceLine, invalidPath); + var testProfilesImporter = new TestProfilesImporter(testImportTarget, testReferenceLine, invalidPath, messageProvider); // Call var importResult = true; @@ -140,9 +189,12 @@ public void Import_FromDirectoryPath_FalseAndLogError() { // Setup + var messageProvider = mocks.Stub(); + mocks.ReplayAll(); + string folderPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Integration.Plugin) + Path.DirectorySeparatorChar; - var testProfilesImporter = new TestProfilesImporter(testImportTarget, testReferenceLine, folderPath); + var testProfilesImporter = new TestProfilesImporter(testImportTarget, testReferenceLine, folderPath, messageProvider); // Call var importResult = true; @@ -169,10 +221,13 @@ public void Import_FromFileWithNonPointFeatures_FalseAndLogError(string shapeFileName) { // Setup + var messageProvider = mocks.Stub(); + mocks.ReplayAll(); + string filePath = TestHelper.GetTestDataPath(TestDataPath.Core.Components.Gis.IO, shapeFileName); - var testProfilesImporter = new TestProfilesImporter(testImportTarget, testReferenceLine, filePath); + var testProfilesImporter = new TestProfilesImporter(testImportTarget, testReferenceLine, filePath, messageProvider); // Call var importResult = true; @@ -197,10 +252,13 @@ string shapeFileName, string missingColumnName) { // Setup + var messageProvider = mocks.Stub(); + mocks.ReplayAll(); + string filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Integration.Plugin, Path.Combine("DikeProfiles", shapeFileName)); - var testProfilesImporter = new TestProfilesImporter(testImportTarget, testReferenceLine, filePath); + var testProfilesImporter = new TestProfilesImporter(testImportTarget, testReferenceLine, filePath, messageProvider); // Call var importResult = true; @@ -223,11 +281,14 @@ public void Import_FromFileWithIllegalCharactersInId_TrueAndLogError(string fileName) { // Setup + var messageProvider = mocks.Stub(); + mocks.ReplayAll(); + string filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Integration.Plugin, Path.Combine("DikeProfiles", fileName)); ReferenceLine referenceLine = CreateMatchingReferenceLine(); - var testProfilesImporter = new TestProfilesImporter(new ObservableList(), referenceLine, filePath); + var testProfilesImporter = new TestProfilesImporter(new ObservableList(), referenceLine, filePath, messageProvider); // Call var importResult = true; @@ -247,11 +308,14 @@ public void Import_FromFileWithEmptyEntryForId_TrueAndLogError() { // Setup + var messageProvider = mocks.Stub(); + mocks.ReplayAll(); + string filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Integration.Plugin, Path.Combine("DikeProfiles", "Voorlanden_12-2_EmptyId.shp")); ReferenceLine referenceLine = CreateMatchingReferenceLine(); - var testProfilesImporter = new TestProfilesImporter(new ObservableList(), referenceLine, filePath); + var testProfilesImporter = new TestProfilesImporter(new ObservableList(), referenceLine, filePath, messageProvider); // Call var importResult = true; @@ -275,10 +339,13 @@ public void Import_FromFileWithUnrelatedInvalidPrflFilesInSameFolder_TrueAndIgnoresUnrelatedFiles() { // Setup + var messageProvider = mocks.Stub(); + mocks.ReplayAll(); + string filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Integration.Plugin, Path.Combine("DikeProfiles", "OkTestDataWithUnrelatedPrfl", "Voorland 12-2.shp")); ReferenceLine referenceLine = CreateMatchingReferenceLine(); - var testProfilesImporter = new TestProfilesImporter(new ObservableList(), referenceLine, filePath); + var testProfilesImporter = new TestProfilesImporter(new ObservableList(), referenceLine, filePath, messageProvider); // Call var importResult = true; @@ -293,11 +360,14 @@ public void Import_FromFileWithEmptyEntryForX0_TrueAndLogError() { // Setup + var messageProvider = mocks.Stub(); + mocks.ReplayAll(); + string filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Integration.Plugin, Path.Combine("DikeProfiles", "Voorlanden_12-2_EmptyX0.shp")); ReferenceLine referenceLine = CreateMatchingReferenceLine(); - var testProfilesImporter = new TestProfilesImporter(new ObservableList(), referenceLine, filePath); + var testProfilesImporter = new TestProfilesImporter(new ObservableList(), referenceLine, filePath, messageProvider); // Call var importResult = true; @@ -317,6 +387,9 @@ public void Import_DikeProfileLocationsNotCloseEnoughToReferenceLine_TrueAndLogError() { // Setup + var messageProvider = mocks.Stub(); + mocks.ReplayAll(); + string filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Integration.Plugin, Path.Combine("DikeProfiles", "AllOkTestData", "Voorlanden 12-2.shp")); @@ -330,7 +403,7 @@ }; ReferenceLine referenceLine = new ReferenceLine(); referenceLine.SetGeometry(referencePoints); - var testProfilesImporter = new TestProfilesImporter(new ObservableList(), referenceLine, filePath); + var testProfilesImporter = new TestProfilesImporter(new ObservableList(), referenceLine, filePath, messageProvider); // Call var importResult = true; @@ -348,11 +421,14 @@ public void Import_InvalidDamType_TrueAndLogMessage() { // Setup + var messageProvider = mocks.Stub(); + mocks.ReplayAll(); + string filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Integration.Plugin, Path.Combine("DikeProfiles", "InvalidDamType", "Voorlanden 12-2.shp")); ReferenceLine referenceLine = CreateMatchingReferenceLine(); - var testProfilesImporter = new TestProfilesImporter(new ObservableList(), referenceLine, filePath); + var testProfilesImporter = new TestProfilesImporter(new ObservableList(), referenceLine, filePath, messageProvider); // Call var importResult = true; @@ -372,6 +448,9 @@ public void Import_TwoPrflWithSameId_TrueAndErrorLog() { // Setup + var messageProvider = mocks.Stub(); + mocks.ReplayAll(); + string filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Integration.Plugin, Path.Combine("DikeProfiles", "TwoPrflWithSameId", "profiel001.shp")); @@ -382,7 +461,7 @@ }; ReferenceLine referenceLine = new ReferenceLine(); referenceLine.SetGeometry(referencePoints); - var testProfilesImporter = new TestProfilesImporter(new ObservableList(), referenceLine, filePath); + var testProfilesImporter = new TestProfilesImporter(new ObservableList(), referenceLine, filePath, messageProvider); // Call var importResult = true; @@ -404,11 +483,14 @@ public void Import_FromFileWithDupplicateId_TrueAndLogWarnings() { // Setup + var messageProvider = mocks.Stub(); + mocks.ReplayAll(); + string filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Integration.Plugin, Path.Combine("DikeProfiles", "Voorlanden_12-2_same_id_3_times.shp")); ReferenceLine referenceLine = CreateMatchingReferenceLine(); - var testProfilesImporter = new TestProfilesImporter(new ObservableList(), referenceLine, filePath); + var testProfilesImporter = new TestProfilesImporter(new ObservableList(), referenceLine, filePath, messageProvider); // Call var importResult = true; @@ -429,11 +511,14 @@ public void Import_PrflWithProfileNotZero_TrueAndErrorLog() { // Setup + var messageProvider = mocks.Stub(); + mocks.ReplayAll(); + string filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Integration.Plugin, Path.Combine("DikeProfiles", "PrflWithProfileNotZero", "Voorland_12-2.shp")); ReferenceLine referenceLine = CreateMatchingReferenceLine(); - var testProfilesImporter = new TestProfilesImporter(new ObservableList(), referenceLine, filePath); + var testProfilesImporter = new TestProfilesImporter(new ObservableList(), referenceLine, filePath, messageProvider); // Call var importResult = true; @@ -453,6 +538,9 @@ public void Import_PrflIsIncomplete_FalseAndErrorLog() { // Setup + var messageProvider = mocks.Stub(); + mocks.ReplayAll(); + string filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Integration.Plugin, Path.Combine("DikeProfiles", "PrflIsIncomplete", "Voorland_12-2.shp")); @@ -463,7 +551,7 @@ }; ReferenceLine referenceLine = new ReferenceLine(); referenceLine.SetGeometry(referencePoints); - var testProfilesImporter = new TestProfilesImporter(new ObservableList(), referenceLine, filePath); + var testProfilesImporter = new TestProfilesImporter(new ObservableList(), referenceLine, filePath, messageProvider); // Call var importResult = true; @@ -483,10 +571,13 @@ public void Import_CancelOfImportWhileReadingProfileLocations_CancelsImportAndLogs() { // Setup + var messageProvider = mocks.Stub(); + mocks.ReplayAll(); + string filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Integration.Plugin, Path.Combine("DikeProfiles", "AllOkTestData", "Voorlanden 12-2.shp")); - var testProfilesImporter = new TestProfilesImporter(testImportTarget, testReferenceLine, filePath); + var testProfilesImporter = new TestProfilesImporter(testImportTarget, testReferenceLine, filePath, messageProvider); testProfilesImporter.SetProgressChanged((description, step, steps) => { if (description.Contains("Inlezen van profiellocaties uit een shapebestand.")) @@ -506,6 +597,9 @@ public void Import_CancelOfImportWhileReadingDikeProfileLocations_CancelsImportAndLogs() { // Setup + var messageProvider = mocks.Stub(); + mocks.ReplayAll(); + string filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Integration.Plugin, Path.Combine("DikeProfiles", "AllOkTestData", "Voorlanden 12-2.shp")); @@ -516,7 +610,7 @@ new Point2D(130084.3, 543727.4) }); - var testProfilesImporter = new TestProfilesImporter(testImportTarget, referenceLine, filePath); + var testProfilesImporter = new TestProfilesImporter(testImportTarget, referenceLine, filePath, messageProvider); testProfilesImporter.SetProgressChanged((description, step, steps) => { if (description.Contains("Inlezen van profielgegevens uit een prfl bestand.")) @@ -536,14 +630,19 @@ public void Import_CancelOfImportWhileCreateProfiles_ContinuesImportAndLogs() { // Setup + const string addingDataToModel = "Adding Data to Model"; + var messageProvider = mocks.Stub(); + messageProvider.Stub(mp => mp.GetAddDataToModelProgressText()).Return(addingDataToModel); + mocks.ReplayAll(); + string filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Integration.Plugin, Path.Combine("DikeProfiles", "AllOkTestData", "Voorlanden 12-2.shp")); ReferenceLine referenceLine = CreateMatchingReferenceLine(); - var testProfilesImporter = new TestProfilesImporter(testImportTarget, referenceLine, filePath); + var testProfilesImporter = new TestProfilesImporter(testImportTarget, referenceLine, filePath, messageProvider); testProfilesImporter.SetProgressChanged((description, step, steps) => { - if (description.Contains("Geïmporteerde data toevoegen aan het toetsspoor.")) + if (description.Contains(addingDataToModel)) { testProfilesImporter.Cancel(); } @@ -563,6 +662,9 @@ public void Import_ReuseOfCanceledImportToValidTargetWithValidFile_True() { // Setup + var messageProvider = mocks.Stub(); + mocks.ReplayAll(); + string filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, Path.Combine("DikeProfiles", "AllOkTestData", "Voorlanden 12-2.shp")); @@ -573,7 +675,7 @@ }; ReferenceLine referenceLine = new ReferenceLine(); referenceLine.SetGeometry(referencePoints); - var testProfilesImporter = new TestProfilesImporter(new ObservableList(), referenceLine, filePath); + var testProfilesImporter = new TestProfilesImporter(new ObservableList(), referenceLine, filePath, messageProvider); testProfilesImporter.SetProgressChanged((description, step, steps) => testProfilesImporter.Cancel()); bool importResult = testProfilesImporter.Import(); @@ -589,6 +691,44 @@ Assert.IsTrue(importResult); } + [Test] + public void Import_AddingDataToModel_SetsProgressText() + { + // Setup + const string expectedProgressText = "Adding Data to model"; + var messageProvider = mocks.StrictMock(); + messageProvider.Expect(mp => mp.GetAddDataToModelProgressText()).Return(expectedProgressText); + mocks.ReplayAll(); + + string filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, + Path.Combine("DikeProfiles", "AllOkTestData", "Voorlanden 12-2.shp")); + + var referencePoints = new List + { + new Point2D(130074.3, 543717.4), + new Point2D(130084.3, 543727.4) + }; + ReferenceLine referenceLine = new ReferenceLine(); + referenceLine.SetGeometry(referencePoints); + var testProfilesImporter = new TestProfilesImporter(new ObservableList(), referenceLine, filePath, messageProvider); + + int callcount = 0; + testProfilesImporter.SetProgressChanged((description, step, steps) => + { + if (callcount == 12) + { + Assert.AreEqual(expectedProgressText, description); + } + callcount++; + }); + + // Call + testProfilesImporter.Import(); + + // Assert + // Assert done in TearDown + } + private ReferenceLine CreateMatchingReferenceLine() { ReferenceLine referenceLine = new ReferenceLine(); @@ -605,8 +745,9 @@ private class TestProfilesImporter : ProfilesImporter> { - public TestProfilesImporter(ObservableList importTarget, ReferenceLine referenceLine, string filePath) - : base(referenceLine, filePath, importTarget) {} + public TestProfilesImporter(ObservableList importTarget, ReferenceLine referenceLine, string filePath, + IImporterMessageProvider messageProvider) + : base(referenceLine, filePath, importTarget, messageProvider) {} protected override void CreateProfiles(ReadResult importProfileLocationResult, ReadResult importDikeProfileDataResult) {} @@ -619,5 +760,19 @@ } private class TestProfile {} + + private class ProgressNotification + { + public ProgressNotification(string description, int currentStep, int totalSteps) + { + Text = description; + CurrentStep = currentStep; + TotalSteps = totalSteps; + } + + public string Text { get; private set; } + public int CurrentStep { get; private set; } + public int TotalSteps { get; private set; } + } } } \ No newline at end of file Fisheye: Tag 9c07cee1e1a14a24e2d949bf9b32f294f0988f1f refers to a dead (removed) revision in file `Ringtoets/Common/test/Ringtoets.Common.IO.TestUtil.Test/Properties/AssemblyInfo.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 9c07cee1e1a14a24e2d949bf9b32f294f0988f1f refers to a dead (removed) revision in file `Ringtoets/Common/test/Ringtoets.Common.IO.TestUtil.Test/Ringtoets.Common.IO.TestUtil.Test.csproj'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Common/test/Ringtoets.Common.IO.TestUtil.Test/TestDikeProfileUpdateStrategyTest.cs =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.IO.TestUtil.Test/TestDikeProfileUpdateStrategyTest.cs (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.IO.TestUtil.Test/TestDikeProfileUpdateStrategyTest.cs (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -0,0 +1,84 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System.Collections.Generic; +using System.Linq; +using Core.Common.Base; +using NUnit.Framework; +using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.IO.FileImporters; + +namespace Ringtoets.Common.IO.TestUtil.Test +{ + [TestFixture] + public class TestDikeProfileUpdateStrategyTest + { + [Test] + public void Constructor_CreatesNewInstance() + { + // Call + var strategy = new TestDikeProfileUpdateStrategy(); + + // Assert + Assert.IsInstanceOf(strategy); + } + + [Test] + public void UpdateDikeProfilesWithImportedData_WithoutSettingUpdatedInstances_SetPropertiesAndReturnSetUpdatedInstances() + { + // Setup + var strategy = new TestDikeProfileUpdateStrategy(); + + const string filePath = "path/to/dikeprofiles"; + var readDikeProfiles = new[] + { + new TestDikeProfile("Dike One"), + new TestDikeProfile("Dike Two"), + new TestDikeProfile("Dike Three") + }; + + // Call + strategy.UpdateDikeProfilesWithImportedData(null, readDikeProfiles, filePath); + + // Assert + Assert.AreEqual(filePath, strategy.FilePath); + Assert.IsTrue(strategy.Updated); + CollectionAssert.AreEqual(readDikeProfiles, strategy.ReadDikeProfiles); + } + + [Test] + public void UpdateDikeProfilesWithImportedData_UpdatedInstancesSet_ReturnsSetUpdatedInstances() + { + // Setup + IEnumerable updatedInstances = Enumerable.Empty(); + + var strategy = new TestDikeProfileUpdateStrategy(); + strategy.UpdatedInstances = updatedInstances; + + // Call + strategy.UpdateDikeProfilesWithImportedData(null, Enumerable.Empty(), string.Empty); + + // Assert + Assert.AreSame(updatedInstances, strategy.UpdatedInstances); + } + } +} Index: Ringtoets/Common/test/Ringtoets.Common.IO.TestUtil.Test/packages.config =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.IO.TestUtil.Test/packages.config (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.IO.TestUtil.Test/packages.config (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -0,0 +1,26 @@ + + + + + \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.IO.TestUtil/Ringtoets.Common.IO.TestUtil.csproj =================================================================== diff -u -r43b7d2fe7b1c4209fd2afcd985a5c1f4b7bf14e9 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Common/test/Ringtoets.Common.IO.TestUtil/Ringtoets.Common.IO.TestUtil.csproj (.../Ringtoets.Common.IO.TestUtil.csproj) (revision 43b7d2fe7b1c4209fd2afcd985a5c1f4b7bf14e9) +++ Ringtoets/Common/test/Ringtoets.Common.IO.TestUtil/Ringtoets.Common.IO.TestUtil.csproj (.../Ringtoets.Common.IO.TestUtil.csproj) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -56,6 +56,7 @@ + Index: Ringtoets/Common/test/Ringtoets.Common.IO.TestUtil/TestDikeProfileUpdateStrategy.cs =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.IO.TestUtil/TestDikeProfileUpdateStrategy.cs (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.IO.TestUtil/TestDikeProfileUpdateStrategy.cs (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -0,0 +1,67 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System.Collections.Generic; +using System.Linq; +using Core.Common.Base; +using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.Common.IO.FileImporters; + +namespace Ringtoets.Common.IO.TestUtil +{ + /// + /// Implementation of a + /// which can be used for testing. + /// + public class TestDikeProfileUpdateStrategy : IDikeProfileUpdateDataStrategy + { + /// + /// Gets a value to indicate if + /// was called. + /// + public bool Updated { get; private set; } + + /// + /// Gets the file path that was passed in . + /// + public string FilePath { get; private set; } + + /// + /// Gets the dike profiles which were passed in . + /// + public DikeProfile[] ReadDikeProfiles { get; private set; } + + /// + /// Gets or sets the updated instances that are returned by . + /// + public IEnumerable UpdatedInstances { get; set; } = Enumerable.Empty(); + + public IEnumerable UpdateDikeProfilesWithImportedData(DikeProfileCollection targetDataCollection, + IEnumerable importedDataCollection, + string sourceFilePath) + { + Updated = true; + FilePath = sourceFilePath; + ReadDikeProfiles = importedDataCollection.ToArray(); + return UpdatedInstances; + } + } +} \ No newline at end of file Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Data/GrassCoverErosionInwardsFailureMechanism.cs =================================================================== diff -u -r30b8231f92b90ea4b05e98e3d0285368f6dfe2e4 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Data/GrassCoverErosionInwardsFailureMechanism.cs (.../GrassCoverErosionInwardsFailureMechanism.cs) (revision 30b8231f92b90ea4b05e98e3d0285368f6dfe2e4) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Data/GrassCoverErosionInwardsFailureMechanism.cs (.../GrassCoverErosionInwardsFailureMechanism.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -21,7 +21,6 @@ using System.Collections.Generic; using System.Linq; -using Core.Common.Base; using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.DikeProfiles; using Ringtoets.Common.Data.FailureMechanism; @@ -46,7 +45,7 @@ CalculationsGroup = new CalculationGroup(RingtoetsCommonDataResources.FailureMechanism_Calculations_DisplayName, false); GeneralInput = new GeneralGrassCoverErosionInwardsInput(); sectionResults = new List(); - DikeProfiles = new ObservableList(); + DikeProfiles = new DikeProfileCollection(); } public override IEnumerable Calculations @@ -65,7 +64,7 @@ /// /// Gets the available dike profiles for this instance. /// - public ObservableList DikeProfiles { get; private set; } + public DikeProfileCollection DikeProfiles { get; private set; } public CalculationGroup CalculationsGroup { get; private set; } Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/PresentationObjects/DikeProfilesContext.cs =================================================================== diff -u -rb2b9fdf365e70928a05c57966eeed30d9050e528 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/PresentationObjects/DikeProfilesContext.cs (.../DikeProfilesContext.cs) (revision b2b9fdf365e70928a05c57966eeed30d9050e528) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/PresentationObjects/DikeProfilesContext.cs (.../DikeProfilesContext.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -20,7 +20,6 @@ // All rights reserved. using System; -using Core.Common.Base; using Core.Common.Controls.PresentationObjects; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.DikeProfiles; @@ -29,19 +28,18 @@ namespace Ringtoets.GrassCoverErosionInwards.Forms.PresentationObjects { /// - /// This is a presentation object for for elements - /// of type . + /// This is a presentation object for the . /// - public class DikeProfilesContext : ObservableWrappedObjectContextBase> + public class DikeProfilesContext : ObservableWrappedObjectContextBase { /// /// Initializes a new instance of the class. /// - /// The observable list of dike profiles. + /// The observable collection of dike profiles. /// The parent failure mechanism. /// The parent assessment section. /// Thrown when any input argument is null. - public DikeProfilesContext(ObservableList dikeProfilesList, GrassCoverErosionInwardsFailureMechanism parentFailureMechanism, IAssessmentSection parentAssessmentSection) : base(dikeProfilesList) + public DikeProfilesContext(DikeProfileCollection dikeProfiles, GrassCoverErosionInwardsFailureMechanism parentFailureMechanism, IAssessmentSection parentAssessmentSection) : base(dikeProfiles) { if (parentAssessmentSection == null) { Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Properties/Resources.Designer.cs =================================================================== diff -u -ra39f463976dde75aa79b34ddb0b27323b95e295a -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision a39f463976dde75aa79b34ddb0b27323b95e295a) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -235,6 +235,15 @@ } /// + /// Looks up a localized string similar to De locatie van het bestand waaruit de dijkprofielen zijn geïmporteerd.. + /// + public static string DikeProfileCollection_SourcePath_Description { + get { + return ResourceManager.GetString("DikeProfileCollection_SourcePath_Description", resourceCulture); + } + } + + /// /// Looks up a localized string similar to {0} - {1}. /// public static string GrassCoverErosionInwardsChartDataFactory_Create_DataIdentifier_0_DataTypeDisplayName_1_ { Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Properties/Resources.resx =================================================================== diff -u -ra39f463976dde75aa79b34ddb0b27323b95e295a -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Properties/Resources.resx (.../Resources.resx) (revision a39f463976dde75aa79b34ddb0b27323b95e295a) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Properties/Resources.resx (.../Resources.resx) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -237,4 +237,7 @@ Is convergentie bereikt in de overslagdebiet berekening? + + De locatie van het bestand waaruit de dijkprofielen zijn geïmporteerd. + \ No newline at end of file Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/PropertyClasses/DikeProfileCollectionProperties.cs =================================================================== diff -u --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/PropertyClasses/DikeProfileCollectionProperties.cs (revision 0) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/PropertyClasses/DikeProfileCollectionProperties.cs (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -0,0 +1,62 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using Core.Common.Gui.PropertyBag; +using Core.Common.Utils.Attributes; +using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.GrassCoverErosionInwards.Forms.Properties; +using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; + +namespace Ringtoets.GrassCoverErosionInwards.Forms.PropertyClasses +{ + /// + /// ViewModel of for properties panel. + /// + public class DikeProfileCollectionProperties : ObjectProperties + { + /// + /// Instantiates a . + /// + /// The collection for which the properties are shown. + /// Thrown when + /// is null. + public DikeProfileCollectionProperties(DikeProfileCollection collection) + { + if (collection == null) + { + throw new ArgumentNullException(nameof(collection)); + } + data = collection; + } + + [ResourcesCategory(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.Categories_General))] + [ResourcesDisplayName(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.ObservableCollectionWithSourcePath_SourcePath_DisplayName))] + [ResourcesDescription(typeof(Resources), nameof(Resources.DikeProfileCollection_SourcePath_Description))] + public string SourcePath + { + get + { + return data.SourcePath; + } + } + } +} Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Ringtoets.GrassCoverErosionInwards.Forms.csproj =================================================================== diff -u -r7cc1fd960a912443ccc3c6995eccb5673d1d8d22 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Ringtoets.GrassCoverErosionInwards.Forms.csproj (.../Ringtoets.GrassCoverErosionInwards.Forms.csproj) (revision 7cc1fd960a912443ccc3c6995eccb5673d1d8d22) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Ringtoets.GrassCoverErosionInwards.Forms.csproj (.../Ringtoets.GrassCoverErosionInwards.Forms.csproj) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -44,6 +44,7 @@ Form + Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Views/GrassCoverErosionInwardsFailureMechanismView.cs =================================================================== diff -u -r11eb517ba7a480b4a415855798a7fadefc0cfe54 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Views/GrassCoverErosionInwardsFailureMechanismView.cs (.../GrassCoverErosionInwardsFailureMechanismView.cs) (revision 11eb517ba7a480b4a415855798a7fadefc0cfe54) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Views/GrassCoverErosionInwardsFailureMechanismView.cs (.../GrassCoverErosionInwardsFailureMechanismView.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -50,6 +50,7 @@ private readonly RecursiveObserver calculationInputObserver; private readonly RecursiveObserver calculationGroupObserver; private readonly RecursiveObserver calculationObserver; + private readonly RecursiveObserver dikeProfileObserver; private readonly MapDataCollection mapDataCollection; private readonly MapLineData referenceLineMapData; @@ -70,23 +71,24 @@ { InitializeComponent(); - failureMechanismObserver = new Observer(UpdateMapData); + failureMechanismObserver = new Observer(UpdateAllMapData); assessmentSectionObserver = new Observer(() => { if (!ReferenceEquals(hydraulicBoundaryDatabaseObserver.Observable, data.Parent.HydraulicBoundaryDatabase)) { hydraulicBoundaryDatabaseObserver.Observable = data.Parent.HydraulicBoundaryDatabase; } - UpdateMapData(); + UpdateAllMapData(); }); - hydraulicBoundaryDatabaseObserver = new Observer(UpdateMapData); - dikeProfilesObserver = new Observer(UpdateMapData); + hydraulicBoundaryDatabaseObserver = new Observer(UpdateHydraulicBoundaryLocationsMapData); + dikeProfilesObserver = new Observer(UpdateDikeProfilesMapData); calculationInputObserver = new RecursiveObserver( - UpdateMapData, pcg => pcg.Children.Concat(pcg.Children.OfType().Select(pc => pc.InputParameters))); - calculationGroupObserver = new RecursiveObserver(UpdateMapData, pcg => pcg.Children); - calculationObserver = new RecursiveObserver(UpdateMapData, pcg => pcg.Children); + UpdateCalculationsMapData, pcg => pcg.Children.Concat(pcg.Children.OfType().Select(pc => pc.InputParameters))); + calculationGroupObserver = new RecursiveObserver(UpdateCalculationsMapData, pcg => pcg.Children); + calculationObserver = new RecursiveObserver(UpdateCalculationsMapData, pcg => pcg.Children); + dikeProfileObserver = new RecursiveObserver(UpdateDikeProfilesMapData, dpc => dpc); mapDataCollection = new MapDataCollection(GrassCoverErosionInwardsDataResources.GrassCoverErosionInwardsFailureMechanism_DisplayName); referenceLineMapData = RingtoetsMapDataFactory.CreateReferenceLineMapData(); @@ -123,25 +125,29 @@ failureMechanismObserver.Observable = null; assessmentSectionObserver.Observable = null; hydraulicBoundaryDatabaseObserver.Observable = null; - dikeProfilesObserver.Observable = null; calculationInputObserver.Observable = null; calculationGroupObserver.Observable = null; calculationObserver.Observable = null; + dikeProfilesObserver.Observable = null; + dikeProfileObserver.Observable = null; + ringtoetsMapControl.RemoveAllData(); } else { failureMechanismObserver.Observable = data.WrappedData; assessmentSectionObserver.Observable = data.Parent; hydraulicBoundaryDatabaseObserver.Observable = data.Parent.HydraulicBoundaryDatabase; - dikeProfilesObserver.Observable = data.WrappedData.DikeProfiles; calculationInputObserver.Observable = data.WrappedData.CalculationsGroup; calculationGroupObserver.Observable = data.WrappedData.CalculationsGroup; calculationObserver.Observable = data.WrappedData.CalculationsGroup; - SetMapDataFeatures(); + dikeProfilesObserver.Observable = data.WrappedData.DikeProfiles; + dikeProfileObserver.Observable = data.WrappedData.DikeProfiles; + SetAllMapDataFeatures(); + ringtoetsMapControl.SetAllData(mapDataCollection, data.Parent.BackgroundData); } } @@ -160,49 +166,127 @@ failureMechanismObserver.Dispose(); assessmentSectionObserver.Dispose(); hydraulicBoundaryDatabaseObserver.Dispose(); - dikeProfilesObserver.Dispose(); calculationInputObserver.Dispose(); calculationGroupObserver.Dispose(); calculationObserver.Dispose(); + dikeProfilesObserver.Dispose(); + dikeProfileObserver.Dispose(); + if (disposing) { components?.Dispose(); } base.Dispose(disposing); } - private void UpdateMapData() + private void UpdateAllMapData() { - SetMapDataFeatures(); + UpdateCalculationsMapData(); + UpdateHydraulicBoundaryLocationsMapData(); + UpdateReferenceLineMapData(); - referenceLineMapData.NotifyObservers(); - sectionsMapData.NotifyObservers(); - sectionsStartPointMapData.NotifyObservers(); - sectionsEndPointMapData.NotifyObservers(); - hydraulicBoundaryLocationsMapData.NotifyObservers(); - dikeProfilesMapData.NotifyObservers(); - foreshoreProfilesMapData.NotifyObservers(); + UpdateSectionsMapData(); + UpdateDikeProfilesMapData(); + } + + private void SetAllMapDataFeatures() + { + SetCalculationsMapData(); + SetHydraulicBoundaryLocationsMapData(); + SetReferenceLineMapData(); + + SetSectionsMapData(); + SetDikeProfilesMapData(); + } + + #region Calculations MapData + + private void UpdateCalculationsMapData() + { + SetCalculationsMapData(); calculationsMapData.NotifyObservers(); } - private void SetMapDataFeatures() + private void SetCalculationsMapData() { - ReferenceLine referenceLine = data.Parent.ReferenceLine; - IEnumerable failureMechanismSections = data.WrappedData.Sections; - HydraulicBoundaryDatabase hydraulicBoundaryDatabase = data.Parent.HydraulicBoundaryDatabase; - IEnumerable dikeProfiles = data.WrappedData.DikeProfiles; IEnumerable calculations = data.WrappedData.CalculationsGroup.GetCalculations().Cast(); + calculationsMapData.Features = GrassCoverErosionInwardsMapDataFeaturesFactory.CreateCalculationFeatures(calculations); + } + + #endregion + + #region HydraulicBoundaryLocations MapData + + private void UpdateHydraulicBoundaryLocationsMapData() + { + SetHydraulicBoundaryLocationsMapData(); + hydraulicBoundaryLocationsMapData.NotifyObservers(); + } + + private void SetHydraulicBoundaryLocationsMapData() + { + HydraulicBoundaryDatabase hydraulicBoundaryDatabase = data.Parent.HydraulicBoundaryDatabase; + hydraulicBoundaryLocationsMapData.Features = RingtoetsMapDataFeaturesFactory.CreateHydraulicBoundaryDatabaseFeatures(hydraulicBoundaryDatabase); + } + + #endregion + + #region ReferenceLine MapData + + private void UpdateReferenceLineMapData() + { + SetReferenceLineMapData(); + referenceLineMapData.NotifyObservers(); + } + + private void SetReferenceLineMapData() + { + ReferenceLine referenceLine = data.Parent.ReferenceLine; referenceLineMapData.Features = RingtoetsMapDataFeaturesFactory.CreateReferenceLineFeatures(referenceLine, data.Parent.Id, data.Parent.Name); + } + + #endregion + + #region Sections MapData + + private void UpdateSectionsMapData() + { + SetSectionsMapData(); + sectionsMapData.NotifyObservers(); + sectionsStartPointMapData.NotifyObservers(); + sectionsEndPointMapData.NotifyObservers(); + } + + private void SetSectionsMapData() + { + IEnumerable failureMechanismSections = data.WrappedData.Sections; sectionsMapData.Features = RingtoetsMapDataFeaturesFactory.CreateFailureMechanismSectionFeatures(failureMechanismSections); sectionsStartPointMapData.Features = RingtoetsMapDataFeaturesFactory.CreateFailureMechanismSectionStartPointFeatures(failureMechanismSections); sectionsEndPointMapData.Features = RingtoetsMapDataFeaturesFactory.CreateFailureMechanismSectionEndPointFeatures(failureMechanismSections); - hydraulicBoundaryLocationsMapData.Features = RingtoetsMapDataFeaturesFactory.CreateHydraulicBoundaryDatabaseFeatures(hydraulicBoundaryDatabase); + } + + #endregion + + #region DikeProfiles MapData + + private void UpdateDikeProfilesMapData() + { + SetDikeProfilesMapData(); + dikeProfilesMapData.NotifyObservers(); + foreshoreProfilesMapData.NotifyObservers(); + } + + private void SetDikeProfilesMapData() + { + IEnumerable dikeProfiles = data.WrappedData.DikeProfiles; + dikeProfilesMapData.Features = RingtoetsMapDataFeaturesFactory.CreateDikeProfilesFeatures(dikeProfiles); foreshoreProfilesMapData.Features = RingtoetsMapDataFeaturesFactory.CreateForeshoreProfilesFeatures(dikeProfiles.Select(dp => dp.ForeshoreProfile)); - calculationsMapData.Features = GrassCoverErosionInwardsMapDataFeaturesFactory.CreateCalculationFeatures(calculations); } + + #endregion } } \ No newline at end of file Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Plugin/ChangeHandlers/UpdateDikeProfileParametersChangeHandler.cs =================================================================== diff -u --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Plugin/ChangeHandlers/UpdateDikeProfileParametersChangeHandler.cs (revision 0) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Plugin/ChangeHandlers/UpdateDikeProfileParametersChangeHandler.cs (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -0,0 +1,79 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Collections.Generic; +using System.Linq; +using Core.Common.Gui; +using Ringtoets.Common.IO; +using Ringtoets.GrassCoverErosionInwards.Data; + +namespace Ringtoets.GrassCoverErosionInwards.Plugin.ChangeHandlers +{ + /// + /// Class which can, if required, inquire the user for a confirmation when a change to the + /// derived dike profile parameters requires calculations results to be altered. + /// + public class UpdateDikeProfileParametersChangeHandler : IConfirmDataChangeHandler + { + private readonly string query; + private readonly IEnumerable calculations; + private readonly IInquiryHelper inquiryHandler; + + /// + /// Instantiates a . + /// + /// The calculations for which to handle the change in parameters. + /// The query which should be displayed when inquiring for a confirmation. + /// Object responsible for inquiring the required data. + /// Thrown when any parameter is null. + public UpdateDikeProfileParametersChangeHandler(IEnumerable calculations, + string query, + IInquiryHelper inquiryHandler) + { + if (calculations == null) + { + throw new ArgumentNullException(nameof(calculations)); + } + if (query == null) + { + throw new ArgumentNullException(nameof(query)); + } + if (inquiryHandler == null) + { + throw new ArgumentNullException(nameof(inquiryHandler)); + } + this.calculations = calculations; + this.query = query; + this.inquiryHandler = inquiryHandler; + } + + public bool RequireConfirmation() + { + return calculations.Any(calc => calc.HasOutput); + } + + public bool InquireConfirmation() + { + return inquiryHandler.InquireContinuation(query); + } + } +} \ No newline at end of file Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Plugin/FileImporters/GrassCoverErosionInwardsDikeProfileReplaceDataStrategy.cs =================================================================== diff -u --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Plugin/FileImporters/GrassCoverErosionInwardsDikeProfileReplaceDataStrategy.cs (revision 0) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Plugin/FileImporters/GrassCoverErosionInwardsDikeProfileReplaceDataStrategy.cs (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -0,0 +1,74 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Collections.Generic; +using Core.Common.Base; +using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.Common.Data.Exceptions; +using Ringtoets.Common.Data.UpdateDataStrategies; +using Ringtoets.Common.IO.FileImporters; +using Ringtoets.GrassCoverErosionInwards.Data; +using Ringtoets.GrassCoverErosionInwards.Plugin.Properties; +using Ringtoets.GrassCoverErosionInwards.Service; + +namespace Ringtoets.GrassCoverErosionInwards.Plugin.FileImporters +{ + /// + /// A + /// to replace dike profiles with imported dike profiles. + /// + public class GrassCoverErosionInwardsDikeProfileReplaceDataStrategy + : ReplaceDataStrategyBase, + IDikeProfileUpdateDataStrategy + { + /// + /// Initializes a . + /// + /// The failure mechanism in which the dike profiles are updated. + /// Thrown when + /// is null. + public GrassCoverErosionInwardsDikeProfileReplaceDataStrategy(GrassCoverErosionInwardsFailureMechanism failureMechanism) + : base(failureMechanism) {} + + public IEnumerable UpdateDikeProfilesWithImportedData(DikeProfileCollection targetCollection, + IEnumerable importedDataCollection, + string sourceFilePath) + { + try + { + return ReplaceTargetCollectionWithImportedData(targetCollection, importedDataCollection, sourceFilePath); + } + catch (UpdateDataException e) + { + string message = string.Format( + Resources.DikeProfileReplaceDataStrategy_UpdateDikeProfilesWithImportedData_Importing_DikeProfiles_failed_Reason_0, + e.Message); + throw new DikeProfileUpdateException(message, e); + } + } + + protected override IEnumerable ClearData(GrassCoverErosionInwardsFailureMechanism failureMechanism) + { + return GrassCoverErosionInwardsDataSynchronizationService.RemoveAllDikeProfiles(failureMechanism); + } + } +} \ No newline at end of file Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Plugin/FileImporters/GrassCoverErosionInwardsDikeProfileUpdateDataStrategy.cs =================================================================== diff -u --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Plugin/FileImporters/GrassCoverErosionInwardsDikeProfileUpdateDataStrategy.cs (revision 0) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Plugin/FileImporters/GrassCoverErosionInwardsDikeProfileUpdateDataStrategy.cs (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -0,0 +1,120 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Collections.Generic; +using System.Linq; +using Core.Common.Base; +using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.Common.Data.Exceptions; +using Ringtoets.Common.Data.UpdateDataStrategies; +using Ringtoets.Common.IO.FileImporters; +using Ringtoets.Common.Service; +using Ringtoets.GrassCoverErosionInwards.Data; +using Ringtoets.GrassCoverErosionInwards.Plugin.Properties; +using Ringtoets.GrassCoverErosionInwards.Service; + +namespace Ringtoets.GrassCoverErosionInwards.Plugin.FileImporters +{ + /// + /// An for updating + /// dike profiles based on imported data. + /// + public class GrassCoverErosionInwardsDikeProfileUpdateDataStrategy + : UpdateDataStrategyBase, + IDikeProfileUpdateDataStrategy + { + /// + /// Creates a new instance of . + /// + /// The failure mechanism in which the dike profiles are updated. + /// Thrown when + /// is null. + public GrassCoverErosionInwardsDikeProfileUpdateDataStrategy(GrassCoverErosionInwardsFailureMechanism failureMechanism) + : base(failureMechanism, new DikeProfileIdEqualityComparer()) {} + + public IEnumerable UpdateDikeProfilesWithImportedData(DikeProfileCollection targetDataCollection, + IEnumerable importedDataCollection, + string sourceFilePath) + { + try + { + return UpdateTargetCollectionData(targetDataCollection, importedDataCollection, sourceFilePath); + } + catch (UpdateDataException e) + { + string message = string.Format(Resources.DikeProfileReplaceDataStrategy_UpdateDikeProfilesWithImportedData_Updating_DikeProfiles_failed_Reason_0, e.Message); + throw new DikeProfileUpdateException(message, e); + } + } + + protected override IEnumerable UpdateObjectAndDependentData(DikeProfile objectToUpdate, DikeProfile objectToUpdateFrom) + { + var affectedObjects = new List(); + if (!objectToUpdate.Equals(objectToUpdateFrom)) + { + objectToUpdate.CopyProperties(objectToUpdateFrom); + affectedObjects.Add(objectToUpdate); + affectedObjects.AddRange(UpdateDikeDependentData(objectToUpdate)); + } + + return affectedObjects; + } + + protected override IEnumerable RemoveObjectAndDependentData(DikeProfile removedObject) + { + return GrassCoverErosionInwardsDataSynchronizationService.RemoveDikeProfile(FailureMechanism, + removedObject); + } + + private IEnumerable UpdateDikeDependentData(DikeProfile objectToUpdate) + { + var affectedObjects = new List(); + GrassCoverErosionInwardsCalculation[] affectedCalculations = + FailureMechanism.Calculations + .Cast() + .Where(calc => ReferenceEquals(objectToUpdate, calc.InputParameters.DikeProfile)) + .ToArray(); + foreach (GrassCoverErosionInwardsCalculation calculation in affectedCalculations) + { + affectedObjects.Add(calculation.InputParameters); + affectedObjects.AddRange(RingtoetsCommonDataSynchronizationService.ClearCalculationOutput(calculation)); + } + return affectedObjects; + } + + /// + /// Class for comparing the only by ID. + /// + private class DikeProfileIdEqualityComparer : IEqualityComparer + { + public bool Equals(DikeProfile x, DikeProfile y) + { + return x.Id == y.Id; + } + + public int GetHashCode(DikeProfile obj) + { + return obj.Id.GetHashCode(); + } + } + } +} \ No newline at end of file Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Plugin/GrassCoverErosionInwardsPlugin.cs =================================================================== diff -u -rbf615dd419e3534ef055bf9072a9f7e3ffef0ad6 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Plugin/GrassCoverErosionInwardsPlugin.cs (.../GrassCoverErosionInwardsPlugin.cs) (revision bf615dd419e3534ef055bf9072a9f7e3ffef0ad6) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Plugin/GrassCoverErosionInwardsPlugin.cs (.../GrassCoverErosionInwardsPlugin.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -24,7 +24,10 @@ using System.Drawing; using System.Linq; using System.Windows.Forms; +using Core.Common.Base; +using Core.Common.Base.Data; using Core.Common.Controls.TreeView; +using Core.Common.Gui; using Core.Common.Gui.ContextMenu; using Core.Common.Gui.Forms.ProgressDialog; using Core.Common.Gui.Plugin; @@ -39,6 +42,8 @@ using Ringtoets.Common.Forms.ImportInfos; using Ringtoets.Common.Forms.PresentationObjects; using Ringtoets.Common.Forms.TreeNodeInfos; +using Ringtoets.Common.IO.FileImporters; +using Ringtoets.Common.IO.FileImporters.MessageProviders; using Ringtoets.Common.Service; using Ringtoets.GrassCoverErosionInwards.Data; using Ringtoets.GrassCoverErosionInwards.Forms; @@ -47,9 +52,12 @@ using Ringtoets.GrassCoverErosionInwards.Forms.Views; using Ringtoets.GrassCoverErosionInwards.IO.Exporters; using Ringtoets.GrassCoverErosionInwards.IO.Importers; +using Ringtoets.GrassCoverErosionInwards.Plugin.ChangeHandlers; +using Ringtoets.GrassCoverErosionInwards.Plugin.FileImporters; +using Ringtoets.GrassCoverErosionInwards.Plugin.Properties; using Ringtoets.GrassCoverErosionInwards.Service; using Ringtoets.GrassCoverErosionInwards.Utils; -using GrassCoverErosionInwardsPluginResources = Ringtoets.GrassCoverErosionInwards.Plugin.Properties.Resources; +using RingtoetsCommonIOResources = Ringtoets.Common.IO.Properties.Resources; using RingtoetsCommonDataResources = Ringtoets.Common.Data.Properties.Resources; using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; @@ -76,6 +84,10 @@ new ObservablePropertyChangeHandler(context.Calculation, context.WrappedData)) }; yield return new PropertyInfo(); + yield return new PropertyInfo + { + CreateInstance = context => new DikeProfileCollectionProperties(context.WrappedData) + }; } public override IEnumerable GetImportInfos() @@ -86,8 +98,44 @@ context.WrappedData, context.AvailableHydraulicBoundaryLocations, context.AvailableDikeProfiles)); + + yield return new ImportInfo + { + CreateFileImporter = (context, filePath) => new DikeProfilesImporter(context.WrappedData, + context.ParentAssessmentSection.ReferenceLine, + filePath, + new GrassCoverErosionInwardsDikeProfileReplaceDataStrategy(context.ParentFailureMechanism), + new ImportMessageProvider()), + Name = RingtoetsCommonIOResources.DikeProfilesImporter_DisplayName, + Category = RingtoetsCommonFormsResources.Ringtoets_Category, + Image = RingtoetsCommonFormsResources.DikeProfile, + FileFilterGenerator = DikeProfileImporterFileFilterGenerator(), + IsEnabled = IsDikeProfileImporterEnabled, + VerifyUpdates = context => VerifyDikeProfilesShouldUpdate(context, + Resources.GrassCoverErosionInwardsPlugin_VerifyDikeProfileImport_When_importing_DikeProfiles_Calculation_output_will_be_cleared_confirm) + }; } + public override IEnumerable GetUpdateInfos() + { + yield return new UpdateInfo + { + CreateFileImporter = (context, filePath) => new DikeProfilesImporter(context.WrappedData, + context.ParentAssessmentSection.ReferenceLine, + filePath, + new GrassCoverErosionInwardsDikeProfileUpdateDataStrategy(context.ParentFailureMechanism), + new UpdateMessageProvider()), + Name = RingtoetsCommonIOResources.DikeProfilesImporter_DisplayName, + Category = RingtoetsCommonFormsResources.Ringtoets_Category, + Image = RingtoetsCommonFormsResources.DikeProfile, + FileFilterGenerator = DikeProfileImporterFileFilterGenerator(), + CurrentPath = context => context.WrappedData.SourcePath, + IsEnabled = IsDikeProfileImporterEnabled, + VerifyUpdates = context => VerifyDikeProfilesShouldUpdate(context, + Resources.GrassCoverErosionInwardsPlugin_VerifyDikeProfileUpdate_When_updating_Calculation_with_DikeProfile_data_output_will_be_cleared_confirm) + }; + } + public override IEnumerable GetExportInfos() { yield return RingtoetsExportInfoFactory.CreateCalculationGroupConfigurationExportInfo( @@ -164,11 +212,12 @@ .ToArray(), ContextMenuStrip = (nodeData, parentData, treeViewControl) => Gui.Get(nodeData, treeViewControl) .AddImportItem() + .AddUpdateItem() .AddSeparator() - .AddDeleteChildrenItem() - .AddSeparator() .AddCollapseAllItem() .AddExpandAllItem() + .AddSeparator() + .AddPropertiesItem() .Build() }; @@ -251,7 +300,7 @@ var failureMechanism = o as GrassCoverErosionInwardsFailureMechanism; var viewFailureMechanismContext = (GrassCoverErosionInwardsFailureMechanismContext) view.Data; - var viewFailureMechanism = viewFailureMechanismContext.WrappedData; + GrassCoverErosionInwardsFailureMechanism viewFailureMechanism = viewFailureMechanismContext.WrappedData; return assessmentSection != null ? ReferenceEquals(viewFailureMechanismContext.Parent, assessmentSection) @@ -361,7 +410,7 @@ private static void ValidateAll(IEnumerable grassCoverErosionInwardsCalculations, IAssessmentSection assessmentSection) { - foreach (var calculation in grassCoverErosionInwardsCalculations) + foreach (GrassCoverErosionInwardsCalculation calculation in grassCoverErosionInwardsCalculations) { GrassCoverErosionInwardsCalculationService.Validate(calculation, assessmentSection); } @@ -510,9 +559,10 @@ { CalculationGroup group = context.WrappedData; var builder = new RingtoetsContextMenuBuilder(Gui.Get(context, treeViewControl)); - var isNestedGroup = parentData is GrassCoverErosionInwardsCalculationGroupContext; + bool isNestedGroup = parentData is GrassCoverErosionInwardsCalculationGroupContext; StrictContextMenuItem generateCalculationsItem = CreateGenerateCalculationsItem(context); + StrictContextMenuItem updateDikeProfileItem = CreateUpdateDikeProfileItem(context); builder.AddImportItem() .AddExportItem() @@ -533,7 +583,8 @@ builder.AddRenameItem(); } - builder.AddValidateAllCalculationsInGroupItem( + builder.AddCustomItem(updateDikeProfileItem) + .AddValidateAllCalculationsInGroupItem( context, ValidateAll, ValidateAllDataAvailableAndGetErrorMessage) @@ -562,13 +613,60 @@ .Build(); } + private StrictContextMenuItem CreateUpdateDikeProfileItem(GrassCoverErosionInwardsCalculationGroupContext nodeData) + { + IEnumerable calculations = nodeData.WrappedData + .GetCalculations() + .OfType(); + + var isContextMenuItemEnabled = true; + string toolTipText = + Resources.GrassCoverErosionInwardsPlugin_CreateUpdateDikeProfileItem_Update_all_calculations_with_DikeProfile_Tooltip; + if (!calculations.Any()) + { + toolTipText = RingtoetsCommonFormsResources.CreateUpdateContextMenuItem_No_calculations_to_update_ToolTip; + isContextMenuItemEnabled = false; + } + else if (calculations.All(calc => calc.InputParameters.DikeProfile == null)) + { + toolTipText = Resources.GrassCoverErosionInwardsPlugin_CreateUpdateDikeProfileItem_No_calculations_with_DikeProfile_ToolTip; + isContextMenuItemEnabled = false; + } + + return new StrictContextMenuItem(Resources.GrassCoverErosionInwardsPlugin_CreateUpdateDikeProfileItem_Update_all_DikeProfiles, + toolTipText, + RingtoetsCommonFormsResources.UpdateItemIcon, + (o, args) => UpdateDikeProfileDependentDataOfAllCalculations(nodeData)) + { + Enabled = isContextMenuItemEnabled + }; + } + + private void UpdateDikeProfileDependentDataOfAllCalculations(GrassCoverErosionInwardsCalculationGroupContext nodeData) + { + GrassCoverErosionInwardsCalculation[] calculations = nodeData.WrappedData + .GetCalculations() + .OfType() + .ToArray(); + + string message = + Resources.GrassCoverErosionInwardsPlugin_VerifyDikeProfileUpdate_Confirm_calculation_outputs_cleared_when_updating_DikeProfile_dependent_data; + if (DikeProfileDependentDataShouldUpdate(calculations, message)) + { + foreach (GrassCoverErosionInwardsCalculation calculation in calculations) + { + UpdateDikeProfileDerivedCalculationInput(calculation); + } + } + } + private StrictContextMenuItem CreateGenerateCalculationsItem(GrassCoverErosionInwardsCalculationGroupContext nodeData) { bool isDikeProfileAvailable = nodeData.AvailableDikeProfiles.Any(); string calculationGroupGenerateCalculationsToolTip = isDikeProfileAvailable - ? GrassCoverErosionInwardsPluginResources.GrassCoverErosionInwardsPlugin_CreateGenerateCalculationsItem_ToolTip - : GrassCoverErosionInwardsPluginResources.GrassCoverErosionInwardsPlugin_CreateGenerateCalculationsItem_NoDikeLocations_ToolTip; + ? Resources.GrassCoverErosionInwardsPlugin_CreateGenerateCalculationsItem_ToolTip + : Resources.GrassCoverErosionInwardsPlugin_CreateGenerateCalculationsItem_NoDikeLocations_ToolTip; var generateCalculationsItem = new StrictContextMenuItem( RingtoetsCommonFormsResources.CalculationGroup_Generate_calculations, @@ -592,7 +690,7 @@ private static void GenerateCalculations(CalculationGroup target, GrassCoverErosionInwardsFailureMechanism failureMechanism, IEnumerable dikeProfiles) { - foreach (var profile in dikeProfiles) + foreach (DikeProfile profile in dikeProfiles) { var calculation = new GrassCoverErosionInwardsCalculation { @@ -681,9 +779,12 @@ GrassCoverErosionInwardsCalculation calculation = context.WrappedData; + StrictContextMenuItem updateDikeProfile = CreateUpdateDikeProfileItem(context); + return builder.AddExportItem() .AddSeparator() .AddRenameItem() + .AddCustomItem(updateDikeProfile) .AddValidateCalculationItem( context, Validate, @@ -735,6 +836,117 @@ } } + private StrictContextMenuItem CreateUpdateDikeProfileItem(GrassCoverErosionInwardsCalculationContext context) + { + GrassCoverErosionInwardsInput inputParameters = context.WrappedData.InputParameters; + bool hasDikeProfile = inputParameters.DikeProfile != null; + + string toolTipMessage = hasDikeProfile + ? Resources.GrassCoverErosionInwardsPlugin_CreateUpdateDikeProfileItem_Update_calculation_with_DikeProfile_data_ToolTip + : Resources.GrassCoverErosionInwardsPlugin_CreateUpdateDikeProfileItem_Update_calculation_no_DikeProfile_ToolTip; + + return new StrictContextMenuItem( + Resources.GrassCoverErosionInwardsPlugin_CreateUpdateDikeProfileItem_Update_DikeProfile_data, + toolTipMessage, + RingtoetsCommonFormsResources.UpdateItemIcon, + (o, args) => UpdateDikeProfileDependentDataOfCalculation(context.WrappedData)) + { + Enabled = hasDikeProfile + }; + } + + private void UpdateDikeProfileDependentDataOfCalculation(GrassCoverErosionInwardsCalculation calculation) + { + string message = + Resources.GrassCoverErosionInwardsPlugin_VerifyDikeProfileUpdate_Confirm_calculation_output_cleared_when_updating_DikeProfile_dependent_data; + if (DikeProfileDependentDataShouldUpdate(new[] + { + calculation + }, message)) + { + UpdateDikeProfileDerivedCalculationInput(calculation); + } + } + + private bool DikeProfileDependentDataShouldUpdate(IEnumerable calculations, string query) + { + var changeHandler = new UpdateDikeProfileParametersChangeHandler(calculations, + query, + new DialogBasedInquiryHelper(Gui.MainWindow)); + + return !changeHandler.RequireConfirmation() || changeHandler.InquireConfirmation(); + } + + private static void UpdateDikeProfileDerivedCalculationInput(GrassCoverErosionInwardsCalculation calculation) + { + GrassCoverErosionInwardsInput inputParameters = calculation.InputParameters; + bool currentUseBreakWater = inputParameters.UseBreakWater; + BreakWater currentBreakWater = inputParameters.BreakWater; + RoundedDouble currentOrientation = inputParameters.Orientation; + RoundedDouble currentDikeHeight = inputParameters.DikeHeight; + bool currentUseForeshore = inputParameters.UseForeshore; + + DikeProfile currentDikeProfile = inputParameters.DikeProfile; + + // Reapply the dike profile will update the derived inputs + inputParameters.DikeProfile = currentDikeProfile; + + var affectedObjects = new List(); + if (IsDerivedInputUpdated(currentUseBreakWater, + currentBreakWater, + currentOrientation, + currentDikeHeight, + currentUseForeshore, + inputParameters)) + { + affectedObjects.Add(inputParameters); + affectedObjects.AddRange(RingtoetsCommonDataSynchronizationService.ClearCalculationOutput(calculation)); + } + + foreach (IObservable affectedObject in affectedObjects) + { + affectedObject.NotifyObservers(); + } + } + + private static bool IsDerivedInputUpdated(bool currentUseBreakWater, + BreakWater currentBreakWater, + RoundedDouble currentOrientation, + RoundedDouble currentDikeHeight, + bool currentUseForeshore, + GrassCoverErosionInwardsInput actualInput) + { + return currentUseBreakWater != actualInput.UseBreakWater + && !Equals(currentBreakWater, actualInput.BreakWater) + && currentOrientation != actualInput.Orientation + && currentDikeHeight != actualInput.DikeHeight + && currentUseForeshore != actualInput.UseForeshore; + } + #endregion + + #region Dike Profiles Importer + + private static FileFilterGenerator DikeProfileImporterFileFilterGenerator() + { + return new FileFilterGenerator(RingtoetsCommonIOResources.Shape_file_filter_Extension, + RingtoetsCommonIOResources.Shape_file_filter_Description); + } + + private static bool IsDikeProfileImporterEnabled(DikeProfilesContext context) + { + return context.ParentAssessmentSection.ReferenceLine != null; + } + + private bool VerifyDikeProfilesShouldUpdate(DikeProfilesContext context, string query) + { + var changeHandler = new FailureMechanismCalculationChangeHandler(context.ParentFailureMechanism, + query, + new DialogBasedInquiryHelper(Gui.MainWindow)); + + return !changeHandler.RequireConfirmation() || changeHandler.InquireConfirmation(); + } + + #endregion } } \ No newline at end of file Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Plugin/Properties/Resources.Designer.cs =================================================================== diff -u -r2aeb951ddc6e2137897569a2de4c55c9fb7e2420 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Plugin/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 2aeb951ddc6e2137897569a2de4c55c9fb7e2420) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Plugin/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -82,6 +82,26 @@ } /// + /// Looks up a localized string similar to Het importeren van dijkprofielen is mislukt: {0}. + /// + internal static string DikeProfileReplaceDataStrategy_UpdateDikeProfilesWithImportedData_Importing_DikeProfiles_failed_Reason_0 { + get { + return ResourceManager.GetString("DikeProfileReplaceDataStrategy_UpdateDikeProfilesWithImportedData_Importing_DikeP" + + "rofiles_failed_Reason_0", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Het bijwerken van de dijkprofielen is mislukt: {0}. + /// + internal static string DikeProfileReplaceDataStrategy_UpdateDikeProfilesWithImportedData_Updating_DikeProfiles_failed_Reason_0 { + get { + return ResourceManager.GetString("DikeProfileReplaceDataStrategy_UpdateDikeProfilesWithImportedData_Updating_DikePr" + + "ofiles_failed_Reason_0", resourceCulture); + } + } + + /// /// Looks up a localized string similar to Er zijn geen dijkprofielen beschikbaar om berekeningen voor te genereren.. /// internal static string GrassCoverErosionInwardsPlugin_CreateGenerateCalculationsItem_NoDikeLocations_ToolTip { @@ -99,5 +119,113 @@ return ResourceManager.GetString("GrassCoverErosionInwardsPlugin_CreateGenerateCalculationsItem_ToolTip", resourceCulture); } } + + /// + /// Looks up a localized string similar to Er zijn geen berekeningen met een dijkprofiel.. + /// + internal static string GrassCoverErosionInwardsPlugin_CreateUpdateDikeProfileItem_No_calculations_with_DikeProfile_ToolTip { + get { + return ResourceManager.GetString("GrassCoverErosionInwardsPlugin_CreateUpdateDikeProfileItem_No_calculations_with_D" + + "ikeProfile_ToolTip", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Alle berekeningen bijwerken met het dijkprofiel.. + /// + internal static string GrassCoverErosionInwardsPlugin_CreateUpdateDikeProfileItem_Update_all_calculations_with_DikeProfile_Tooltip { + get { + return ResourceManager.GetString("GrassCoverErosionInwardsPlugin_CreateUpdateDikeProfileItem_Update_all_calculation" + + "s_with_DikeProfile_Tooltip", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to &Bijwerken dijkprofielen. + /// + internal static string GrassCoverErosionInwardsPlugin_CreateUpdateDikeProfileItem_Update_all_DikeProfiles { + get { + return ResourceManager.GetString("GrassCoverErosionInwardsPlugin_CreateUpdateDikeProfileItem_Update_all_DikeProfile" + + "s", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Er moet een dijkprofiel geselecteerd zijn.. + /// + internal static string GrassCoverErosionInwardsPlugin_CreateUpdateDikeProfileItem_Update_calculation_no_DikeProfile_ToolTip { + get { + return ResourceManager.GetString("GrassCoverErosionInwardsPlugin_CreateUpdateDikeProfileItem_Update_calculation_no_" + + "DikeProfile_ToolTip", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Berekening bijwerken met het dijkprofiel.. + /// + internal static string GrassCoverErosionInwardsPlugin_CreateUpdateDikeProfileItem_Update_calculation_with_DikeProfile_data_ToolTip { + get { + return ResourceManager.GetString("GrassCoverErosionInwardsPlugin_CreateUpdateDikeProfileItem_Update_calculation_wit" + + "h_DikeProfile_data_ToolTip", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to &Bijwerken dijkprofiel. + /// + internal static string GrassCoverErosionInwardsPlugin_CreateUpdateDikeProfileItem_Update_DikeProfile_data { + get { + return ResourceManager.GetString("GrassCoverErosionInwardsPlugin_CreateUpdateDikeProfileItem_Update_DikeProfile_dat" + + "a", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Als u dijkprofielen importeert, dan worden alle rekenresultaten van dit toetsspoor verwijderd. + /// + ///Weet u zeker dat u wilt doorgaan?. + /// + internal static string GrassCoverErosionInwardsPlugin_VerifyDikeProfileImport_When_importing_DikeProfiles_Calculation_output_will_be_cleared_confirm { + get { + return ResourceManager.GetString("GrassCoverErosionInwardsPlugin_VerifyDikeProfileImport_When_importing_DikeProfile" + + "s_Calculation_output_will_be_cleared_confirm", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Wanneer het dijkprofiel wijzigt als gevolg van het bijwerken, zal het resultaat van deze berekening worden verwijderd. + /// + ///Weet u zeker dat u wilt doorgaan?. + /// + internal static string GrassCoverErosionInwardsPlugin_VerifyDikeProfileUpdate_Confirm_calculation_output_cleared_when_updating_DikeProfile_dependent_data { + get { + return ResourceManager.GetString("GrassCoverErosionInwardsPlugin_VerifyDikeProfileUpdate_Confirm_calculation_output" + + "_cleared_when_updating_DikeProfile_dependent_data", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Wanneer de dijkprofielen wijzigen als gevolg van het bijwerken, zullen de resultaten van berekeningen die deze dijkprofielen gebruiken, worden verwijderd. + /// + ///Weet u zeker dat u wilt doorgaan?. + /// + internal static string GrassCoverErosionInwardsPlugin_VerifyDikeProfileUpdate_Confirm_calculation_outputs_cleared_when_updating_DikeProfile_dependent_data { + get { + return ResourceManager.GetString("GrassCoverErosionInwardsPlugin_VerifyDikeProfileUpdate_Confirm_calculation_output" + + "s_cleared_when_updating_DikeProfile_dependent_data", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Als dijkprofielen wijzigen door het bijwerken, dan worden de resultaten van berekeningen die deze dijkprofielen gebruiken verwijderd. + /// + ///Weet u zeker dat u wilt doorgaan?. + /// + internal static string GrassCoverErosionInwardsPlugin_VerifyDikeProfileUpdate_When_updating_Calculation_with_DikeProfile_data_output_will_be_cleared_confirm { + get { + return ResourceManager.GetString("GrassCoverErosionInwardsPlugin_VerifyDikeProfileUpdate_When_updating_Calculation_" + + "with_DikeProfile_data_output_will_be_cleared_confirm", resourceCulture); + } + } } } Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Plugin/Properties/Resources.resx =================================================================== diff -u -r2aeb951ddc6e2137897569a2de4c55c9fb7e2420 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Plugin/Properties/Resources.resx (.../Resources.resx) (revision 2aeb951ddc6e2137897569a2de4c55c9fb7e2420) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Plugin/Properties/Resources.resx (.../Resources.resx) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -123,4 +123,48 @@ Genereer berekeningen op basis van geselecteerde dijkprofielen. + + Het importeren van dijkprofielen is mislukt: {0} + + + Het bijwerken van de dijkprofielen is mislukt: {0} + + + Als u dijkprofielen importeert, dan worden alle rekenresultaten van dit toetsspoor verwijderd. + +Weet u zeker dat u wilt doorgaan? + + + Als dijkprofielen wijzigen door het bijwerken, dan worden de resultaten van berekeningen die deze dijkprofielen gebruiken verwijderd. + +Weet u zeker dat u wilt doorgaan? + + + &Bijwerken dijkprofiel + + + Berekening bijwerken met het dijkprofiel. + + + Er moet een dijkprofiel geselecteerd zijn. + + + Wanneer het dijkprofiel wijzigt als gevolg van het bijwerken, zal het resultaat van deze berekening worden verwijderd. + +Weet u zeker dat u wilt doorgaan? + + + Alle berekeningen bijwerken met het dijkprofiel. + + + Er zijn geen berekeningen met een dijkprofiel. + + + &Bijwerken dijkprofielen + + + Wanneer de dijkprofielen wijzigen als gevolg van het bijwerken, zullen de resultaten van berekeningen die deze dijkprofielen gebruiken, worden verwijderd. + +Weet u zeker dat u wilt doorgaan? + \ No newline at end of file Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Plugin/Ringtoets.GrassCoverErosionInwards.Plugin.csproj =================================================================== diff -u -r0d29de0eb92a426c8e1b3725656a3f608b93f951 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Plugin/Ringtoets.GrassCoverErosionInwards.Plugin.csproj (.../Ringtoets.GrassCoverErosionInwards.Plugin.csproj) (revision 0d29de0eb92a426c8e1b3725656a3f608b93f951) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Plugin/Ringtoets.GrassCoverErosionInwards.Plugin.csproj (.../Ringtoets.GrassCoverErosionInwards.Plugin.csproj) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -41,6 +41,9 @@ Properties\GlobalAssembly.cs + + + Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Service/GrassCoverErosionInwardsDataSynchronizationService.cs =================================================================== diff -u -rb2b9fdf365e70928a05c57966eeed30d9050e528 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Service/GrassCoverErosionInwardsDataSynchronizationService.cs (.../GrassCoverErosionInwardsDataSynchronizationService.cs) (revision b2b9fdf365e70928a05c57966eeed30d9050e528) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Service/GrassCoverErosionInwardsDataSynchronizationService.cs (.../GrassCoverErosionInwardsDataSynchronizationService.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -24,6 +24,7 @@ using System.Linq; using Core.Common.Base; using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.DikeProfiles; using Ringtoets.Common.Data.Hydraulics; using Ringtoets.Common.Service; using Ringtoets.GrassCoverErosionInwards.Data; @@ -100,7 +101,7 @@ } var affectedItems = new List(); - foreach (var calculation in failureMechanism.Calculations.Cast()) + foreach (GrassCoverErosionInwardsCalculation calculation in failureMechanism.Calculations.Cast()) { affectedItems.AddRange(ClearCalculationOutput(calculation) .Concat(ClearHydraulicBoundaryLocation(calculation.InputParameters))); @@ -124,11 +125,12 @@ } var observables = new List(); - var removedObjects = failureMechanism.Sections.OfType() - .Concat(failureMechanism.SectionResults) - .Concat(failureMechanism.CalculationsGroup.GetAllChildrenRecursive()) - .Concat(failureMechanism.DikeProfiles) - .ToArray(); + object[] removedObjects = failureMechanism.Sections + .OfType() + .Concat(failureMechanism.SectionResults) + .Concat(failureMechanism.CalculationsGroup.GetAllChildrenRecursive()) + .Concat(failureMechanism.DikeProfiles) + .ToArray(); failureMechanism.ClearAllSections(); observables.Add(failureMechanism); @@ -142,6 +144,91 @@ return new ClearResults(observables, removedObjects); } + /// + /// Removes the from the + /// and clears all the data that depends on it, either directly or indirectly. + /// + /// The failure mechanism. + /// The dike profile to be removed. + /// An of all affected objects by this operation. + /// Thrown when any input argument is null. + public static IEnumerable RemoveDikeProfile(GrassCoverErosionInwardsFailureMechanism failureMechanism, + DikeProfile dikeProfile) + { + if (failureMechanism == null) + { + throw new ArgumentNullException(nameof(failureMechanism)); + } + if (dikeProfile == null) + { + throw new ArgumentNullException(nameof(dikeProfile)); + } + + IEnumerable affectedCalculations = failureMechanism.Calculations + .Cast() + .Where(calc => ReferenceEquals(dikeProfile, calc.InputParameters.DikeProfile)); + + var affectedObjects = new List + { + failureMechanism.DikeProfiles + }; + foreach (GrassCoverErosionInwardsCalculation calculation in affectedCalculations) + { + affectedObjects.AddRange(RingtoetsCommonDataSynchronizationService.ClearCalculationOutput(calculation)); + affectedObjects.AddRange(ClearDikeProfile(calculation.InputParameters)); + } + + failureMechanism.DikeProfiles.Remove(dikeProfile); + return affectedObjects; + } + + /// + /// Removes all the from the + /// and clears all data that depends on it, either directly or indirectly. + /// + /// The failure mechanism for which all + /// the dike profiles need to be removed. + /// An of all affected objects. + /// Thrown when + /// is null. + public static IEnumerable RemoveAllDikeProfiles(GrassCoverErosionInwardsFailureMechanism failureMechanism) + { + if (failureMechanism == null) + { + throw new ArgumentNullException(nameof(failureMechanism)); + } + + IEnumerable affectedCalculations = + failureMechanism.Calculations + .Cast() + .Where(calc => calc.InputParameters.DikeProfile != null) + .ToArray(); + + var affectedObjects = new List(); + foreach (GrassCoverErosionInwardsCalculation calculation in affectedCalculations) + { + affectedObjects.AddRange(RingtoetsCommonDataSynchronizationService.ClearCalculationOutput(calculation)); + affectedObjects.AddRange(ClearDikeProfile(calculation.InputParameters)); + } + + failureMechanism.DikeProfiles.Clear(); + affectedObjects.Add(failureMechanism.DikeProfiles); + return affectedObjects; + } + + private static IEnumerable ClearDikeProfile(GrassCoverErosionInwardsInput inputParameters) + { + if (inputParameters.DikeProfile != null) + { + inputParameters.DikeProfile = null; + return new[] + { + inputParameters + }; + } + return Enumerable.Empty(); + } + private static IEnumerable ClearHydraulicBoundaryLocation(GrassCoverErosionInwardsInput input) { if (input.HydraulicBoundaryLocation != null) Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Data.Test/GrassCoverErosionInwardsFailureMechanismTest.cs =================================================================== diff -u -rc4972d4aec336f991ac1b4ab3dcd56161c238516 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Data.Test/GrassCoverErosionInwardsFailureMechanismTest.cs (.../GrassCoverErosionInwardsFailureMechanismTest.cs) (revision c4972d4aec336f991ac1b4ab3dcd56161c238516) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Data.Test/GrassCoverErosionInwardsFailureMechanismTest.cs (.../GrassCoverErosionInwardsFailureMechanismTest.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -19,6 +19,7 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System.Collections.Generic; using System.Linq; using Core.Common.Base; using Core.Common.Base.Geometry; @@ -123,7 +124,7 @@ mocks.ReplayAll(); // Call - var calculations = failureMechanism.Calculations.ToList(); + List calculations = failureMechanism.Calculations.ToList(); // Assert Assert.AreEqual(2, calculations.Count); @@ -136,16 +137,23 @@ { // Scenario var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + const string filePath = "path"; - DikeProfile dikeProfile1 = new TestDikeProfile(new Point2D(0, 0)); - DikeProfile dikeProfile2 = new TestDikeProfile(new Point2D(1, 1)); - DikeProfile dikeProfile3 = new TestDikeProfile(new Point2D(2, 2)); + DikeProfile dikeProfile1 = new TestDikeProfile(new Point2D(0, 0), "id1"); + DikeProfile dikeProfile2 = new TestDikeProfile(new Point2D(1, 1), "id2"); + DikeProfile dikeProfile3 = new TestDikeProfile(new Point2D(2, 2), "id3"); - failureMechanism.DikeProfiles.Add(dikeProfile1); + failureMechanism.DikeProfiles.AddRange(new[] + { + dikeProfile1 + }, filePath); // Event - failureMechanism.DikeProfiles.Add(dikeProfile2); - failureMechanism.DikeProfiles.Insert(0, dikeProfile3); + failureMechanism.DikeProfiles.AddRange(new[] + { + dikeProfile3, + dikeProfile2 + }, filePath); failureMechanism.DikeProfiles.Remove(dikeProfile1); // Result Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/PresentationObjects/DikeProfilesContextTest.cs =================================================================== diff -u -rc4972d4aec336f991ac1b4ab3dcd56161c238516 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/PresentationObjects/DikeProfilesContextTest.cs (.../DikeProfilesContextTest.cs) (revision c4972d4aec336f991ac1b4ab3dcd56161c238516) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/PresentationObjects/DikeProfilesContextTest.cs (.../DikeProfilesContextTest.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -20,7 +20,6 @@ // All rights reserved. using System; -using Core.Common.Base; using Core.Common.Controls.PresentationObjects; using NUnit.Framework; using Rhino.Mocks; @@ -48,7 +47,7 @@ var context = new DikeProfilesContext(failureMechanism.DikeProfiles, failureMechanism, assessmentSection); // Assert - Assert.IsInstanceOf>>(context); + Assert.IsInstanceOf>(context); Assert.AreSame(failureMechanism.DikeProfiles, context.WrappedData); Assert.AreSame(failureMechanism, context.ParentFailureMechanism); Assert.AreSame(assessmentSection, context.ParentAssessmentSection); @@ -82,7 +81,7 @@ var assessmentSection = mocks.Stub(); mocks.ReplayAll(); - var dikeProfiles = new ObservableList(); + var dikeProfiles = new DikeProfileCollection(); // Call TestDelegate call = () => new DikeProfilesContext(dikeProfiles, null, assessmentSection); Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/PropertyClasses/DikeProfileCollectionPropertiesTest.cs =================================================================== diff -u --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/PropertyClasses/DikeProfileCollectionPropertiesTest.cs (revision 0) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/PropertyClasses/DikeProfileCollectionPropertiesTest.cs (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -0,0 +1,87 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.ComponentModel; +using System.Linq; +using Core.Common.Gui.PropertyBag; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.GrassCoverErosionInwards.Forms.PropertyClasses; + +namespace Ringtoets.GrassCoverErosionInwards.Forms.Test.PropertyClasses +{ + [TestFixture] + public class DikeProfileCollectionPropertiesTest + { + [Test] + public void Constructor_WithoutColleciton_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => new DikeProfileCollectionProperties(null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("collection", paramName); + } + + [Test] + public void Constructor_WithData_ReturnExpectedValues() + { + // Setup + var someFilePath = "location/to/a/file"; + var collection = new DikeProfileCollection(); + collection.AddRange(Enumerable.Empty(), someFilePath); + + // Call + var properties = new DikeProfileCollectionProperties(collection); + + // Assert + Assert.IsInstanceOf>(properties); + Assert.AreSame(collection, properties.Data); + Assert.AreEqual(someFilePath, properties.SourcePath); + } + + [Test] + public void Constructor_WithData_PropertiesHaveExpectedAttributesValues() + { + // Setup + var collection = new DikeProfileCollection(); + + // Call + var properties = new DikeProfileCollectionProperties(collection); + + // Assert + PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties); + Assert.AreEqual(1, dynamicProperties.Count); + + PropertyDescriptor dikeProfileCollectionSourcePathProperty = dynamicProperties[0]; + Assert.IsNotNull(dikeProfileCollectionSourcePathProperty); + Assert.IsTrue(dikeProfileCollectionSourcePathProperty.IsReadOnly); + Assert.AreEqual("Algemeen", dikeProfileCollectionSourcePathProperty.Category); + Assert.AreEqual("Bronlocatie", dikeProfileCollectionSourcePathProperty.DisplayName); + Assert.AreEqual( + "De locatie van het bestand waaruit de dijkprofielen zijn geïmporteerd.", + dikeProfileCollectionSourcePathProperty.Description); + } + } +} Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/PropertyClasses/GrassCoverErosionInwardsInputContextPropertiesTest.cs =================================================================== diff -u -rdab03b7e80b00b4187e2dd118fc0a04a62d22007 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/PropertyClasses/GrassCoverErosionInwardsInputContextPropertiesTest.cs (.../GrassCoverErosionInwardsInputContextPropertiesTest.cs) (revision dab03b7e80b00b4187e2dd118fc0a04a62d22007) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/PropertyClasses/GrassCoverErosionInwardsInputContextPropertiesTest.cs (.../GrassCoverErosionInwardsInputContextPropertiesTest.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -561,13 +561,11 @@ var input = new GrassCoverErosionInwardsInput(); var calculation = new GrassCoverErosionInwardsCalculation(); - var failureMechanism = new GrassCoverErosionInwardsFailureMechanism - { - DikeProfiles = - { - new TestDikeProfile() - } - }; + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + failureMechanism.DikeProfiles.AddRange(new [] + { + new TestDikeProfile() + }, "path"); var inputContext = new GrassCoverErosionInwardsInputContext(input, calculation, failureMechanism, assessmentSection); var properties = new GrassCoverErosionInwardsInputContextProperties(inputContext, handler); @@ -576,7 +574,7 @@ IEnumerable availableDikeProfiles = properties.GetAvailableDikeProfiles(); // Assert - List expectedHydraulicBoundaryLocations = failureMechanism.DikeProfiles; + DikeProfileCollection expectedHydraulicBoundaryLocations = failureMechanism.DikeProfiles; Assert.AreSame(expectedHydraulicBoundaryLocations, availableDikeProfiles); mockRepository.VerifyAll(); } Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/Ringtoets.GrassCoverErosionInwards.Forms.Test.csproj =================================================================== diff -u -r737cd3675ab5bc1b6400e4a0b86ebd543eaee650 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/Ringtoets.GrassCoverErosionInwards.Forms.Test.csproj (.../Ringtoets.GrassCoverErosionInwards.Forms.Test.csproj) (revision 737cd3675ab5bc1b6400e4a0b86ebd543eaee650) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/Ringtoets.GrassCoverErosionInwards.Forms.Test.csproj (.../Ringtoets.GrassCoverErosionInwards.Forms.Test.csproj) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -65,6 +65,7 @@ + Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/UITypeEditors/GrassCoverErosionInwardsInputContextDikeProfileEditorTest.cs =================================================================== diff -u -r277048d204ab4cfad4aa5de4d57ef38b56642c25 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/UITypeEditors/GrassCoverErosionInwardsInputContextDikeProfileEditorTest.cs (.../GrassCoverErosionInwardsInputContextDikeProfileEditorTest.cs) (revision 277048d204ab4cfad4aa5de4d57ef38b56642c25) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/UITypeEditors/GrassCoverErosionInwardsInputContextDikeProfileEditorTest.cs (.../GrassCoverErosionInwardsInputContextDikeProfileEditorTest.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -51,13 +51,11 @@ public void EditValue_WithCurrentItemNotInAvailableItems_ReturnsOriginalValue() { // Setup - var failureMechanism = new GrassCoverErosionInwardsFailureMechanism + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + failureMechanism.DikeProfiles.AddRange(new[] { - DikeProfiles = - { - new TestDikeProfile() - } - }; + new TestDikeProfile() + }, "path"); var grassCoverErosionInwardsInput = new GrassCoverErosionInwardsInput(); var grassCoverErosionInwardsCalculation = new GrassCoverErosionInwardsCalculation(); @@ -83,7 +81,7 @@ var someValue = new object(); // Call - var result = editor.EditValue(descriptorContextMock, serviceProviderMock, someValue); + object result = editor.EditValue(descriptorContextMock, serviceProviderMock, someValue); // Assert Assert.AreSame(someValue, result); @@ -96,13 +94,12 @@ { // Setup DikeProfile dikeProfile = new TestDikeProfile(); - var failureMechanism = new GrassCoverErosionInwardsFailureMechanism + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + failureMechanism.DikeProfiles.AddRange(new[] { - DikeProfiles = - { - dikeProfile - } - }; + dikeProfile + }, "path"); + var grassCoverErosionInwardsInput = new GrassCoverErosionInwardsInput { DikeProfile = dikeProfile @@ -114,7 +111,7 @@ grassCoverErosionInwardsCalculation, failureMechanism, assessmentSection); - + var handler = mockRepository.Stub(); var properties = new GrassCoverErosionInwardsInputContextProperties(inputContext, handler); @@ -133,7 +130,7 @@ var someValue = new object(); // Call - var result = editor.EditValue(descriptorContextMock, serviceProviderMock, someValue); + object result = editor.EditValue(descriptorContextMock, serviceProviderMock, someValue); // Assert Assert.AreSame(dikeProfile, result); Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/Views/GrassCoverErosionInwardsFailureMechanismViewTest.cs =================================================================== diff -u -r11eb517ba7a480b4a415855798a7fadefc0cfe54 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/Views/GrassCoverErosionInwardsFailureMechanismViewTest.cs (.../GrassCoverErosionInwardsFailureMechanismViewTest.cs) (revision 11eb517ba7a480b4a415855798a7fadefc0cfe54) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/Views/GrassCoverErosionInwardsFailureMechanismViewTest.cs (.../GrassCoverErosionInwardsFailureMechanismViewTest.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -22,11 +22,14 @@ using System.Collections.Generic; using System.Linq; using System.Windows.Forms; +using Core.Common.Base; using Core.Common.Base.Geometry; using Core.Components.Gis.Data; +using Core.Components.Gis.Features; using Core.Components.Gis.Forms; using Core.Components.Gis.Geometries; using NUnit.Framework; +using Rhino.Mocks; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.DikeProfiles; using Ringtoets.Common.Data.FailureMechanism; @@ -241,16 +244,20 @@ failureMechanism.AddSection(new FailureMechanismSection("B", geometryPoints.Skip(1).Take(2))); failureMechanism.AddSection(new FailureMechanismSection("C", geometryPoints.Skip(2).Take(2))); - failureMechanism.DikeProfiles.Add(new TestDikeProfile(new[] + failureMechanism.DikeProfiles.AddRange(new[] { - new Point2D(0, 0), - new Point2D(1, 1) - })); - failureMechanism.DikeProfiles.Add(new TestDikeProfile(new[] - { - new Point2D(2, 2), - new Point2D(3, 3) - })); + new TestDikeProfile(new[] + { + new Point2D(0, 0), + new Point2D(1, 1) + }, "id1"), + new TestDikeProfile(new[] + { + new Point2D(2, 2), + new Point2D(3, 3) + }, "id2") + }, "path"); + failureMechanism.CalculationsGroup.Children.Add(calculationA); failureMechanism.CalculationsGroup.Children.Add(calculationB); @@ -265,7 +272,7 @@ MapDataCollection mapData = map.Data; Assert.IsInstanceOf(mapData); - var mapDataList = mapData.Collection.ToList(); + List mapDataList = mapData.Collection.ToList(); Assert.AreEqual(8, mapDataList.Count); MapDataTestHelper.AssertReferenceLineMapData(assessmentSection.ReferenceLine, mapDataList[referenceLineIndex]); MapDataTestHelper.AssertFailureMechanismSectionsMapData(failureMechanism.Sections, mapDataList[sectionsIndex]); @@ -312,6 +319,18 @@ MapData hydraulicBoundaryLocationsMapData = map.Data.Collection.ElementAt(hydraulicBoundaryLocationsIndex); + var mocks = new MockRepository(); + IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); + observers[referenceLineIndex].Expect(obs => obs.UpdateObserver()); + observers[sectionsIndex].Expect(obs => obs.UpdateObserver()); + observers[sectionsStartPointIndex].Expect(obs => obs.UpdateObserver()); + observers[sectionsEndPointIndex].Expect(obs => obs.UpdateObserver()); + observers[hydraulicBoundaryLocationsIndex].Expect(obs => obs.UpdateObserver()); + observers[dikeProfilesIndex].Expect(obs => obs.UpdateObserver()); + observers[foreshoreProfilesIndex].Expect(obs => obs.UpdateObserver()); + observers[calculationsIndex].Expect(obs => obs.UpdateObserver()); + mocks.ReplayAll(); + // Precondition MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(hydraulicBoundaryDatabase1.Locations, hydraulicBoundaryLocationsMapData); @@ -322,6 +341,8 @@ // Assert MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(hydraulicBoundaryDatabase2.Locations, hydraulicBoundaryLocationsMapData); + + mocks.VerifyAll(); } } @@ -352,6 +373,11 @@ MapData hydraulicBoundaryLocationsMapData = map.Data.Collection.ElementAt(hydraulicBoundaryLocationsIndex); + var mocks = new MockRepository(); + IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); + observers[hydraulicBoundaryLocationsIndex].Expect(obs => obs.UpdateObserver()); + mocks.ReplayAll(); + // Precondition MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(hydraulicBoundaryDatabase.Locations, hydraulicBoundaryLocationsMapData); @@ -362,6 +388,8 @@ // Assert MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(hydraulicBoundaryDatabase.Locations, hydraulicBoundaryLocationsMapData); + + mocks.VerifyAll(); } } @@ -397,6 +425,18 @@ MapData hydraulicBoundaryLocationsMapData = map.Data.Collection.ElementAt(hydraulicBoundaryLocationsIndex); + var mocks = new MockRepository(); + IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); + observers[referenceLineIndex].Expect(obs => obs.UpdateObserver()); + observers[sectionsIndex].Expect(obs => obs.UpdateObserver()); + observers[sectionsStartPointIndex].Expect(obs => obs.UpdateObserver()); + observers[sectionsEndPointIndex].Expect(obs => obs.UpdateObserver()); + observers[hydraulicBoundaryLocationsIndex].Expect(obs => obs.UpdateObserver()).Repeat.Twice(); + observers[dikeProfilesIndex].Expect(obs => obs.UpdateObserver()); + observers[foreshoreProfilesIndex].Expect(obs => obs.UpdateObserver()); + observers[calculationsIndex].Expect(obs => obs.UpdateObserver()); + mocks.ReplayAll(); + // Precondition MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(currentHydraulicBoundaryDatabase.Locations, hydraulicBoundaryLocationsMapData); @@ -408,6 +448,8 @@ // Then MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(newHydraulicBoundaryDatabase.Locations, hydraulicBoundaryLocationsMapData); + + mocks.VerifyAll(); } } @@ -443,6 +485,18 @@ MapData referenceLineMapData = map.Data.Collection.ElementAt(referenceLineIndex); + var mocks = new MockRepository(); + IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); + observers[referenceLineIndex].Expect(obs => obs.UpdateObserver()); + observers[sectionsIndex].Expect(obs => obs.UpdateObserver()); + observers[sectionsStartPointIndex].Expect(obs => obs.UpdateObserver()); + observers[sectionsEndPointIndex].Expect(obs => obs.UpdateObserver()); + observers[hydraulicBoundaryLocationsIndex].Expect(obs => obs.UpdateObserver()); + observers[dikeProfilesIndex].Expect(obs => obs.UpdateObserver()); + observers[foreshoreProfilesIndex].Expect(obs => obs.UpdateObserver()); + observers[calculationsIndex].Expect(obs => obs.UpdateObserver()); + mocks.ReplayAll(); + // Precondition MapDataTestHelper.AssertReferenceLineMapData(assessmentSection.ReferenceLine, referenceLineMapData); @@ -453,6 +507,7 @@ // Assert MapDataTestHelper.AssertReferenceLineMapData(assessmentSection.ReferenceLine, referenceLineMapData); + mocks.VerifyAll(); } } @@ -473,6 +528,18 @@ var sectionStartsMapData = (MapPointData) map.Data.Collection.ElementAt(sectionsStartPointIndex); var sectionsEndsMapData = (MapPointData) map.Data.Collection.ElementAt(sectionsEndPointIndex); + var mocks = new MockRepository(); + IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); + observers[referenceLineIndex].Expect(obs => obs.UpdateObserver()); + observers[sectionsIndex].Expect(obs => obs.UpdateObserver()); + observers[sectionsStartPointIndex].Expect(obs => obs.UpdateObserver()); + observers[sectionsEndPointIndex].Expect(obs => obs.UpdateObserver()); + observers[hydraulicBoundaryLocationsIndex].Expect(obs => obs.UpdateObserver()); + observers[dikeProfilesIndex].Expect(obs => obs.UpdateObserver()); + observers[foreshoreProfilesIndex].Expect(obs => obs.UpdateObserver()); + observers[calculationsIndex].Expect(obs => obs.UpdateObserver()); + mocks.ReplayAll(); + failureMechanism.AddSection(new FailureMechanismSection(string.Empty, new[] { new Point2D(1, 2), @@ -486,6 +553,8 @@ MapDataTestHelper.AssertFailureMechanismSectionsMapData(failureMechanism.Sections, sectionMapData); MapDataTestHelper.AssertFailureMechanismSectionsStartPointMapData(failureMechanism.Sections, sectionStartsMapData); MapDataTestHelper.AssertFailureMechanismSectionsEndPointMapData(failureMechanism.Sections, sectionsEndsMapData); + + mocks.VerifyAll(); } } @@ -500,26 +569,80 @@ var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); var failureMechanismContext = new GrassCoverErosionInwardsFailureMechanismContext(failureMechanism, new ObservableTestAssessmentSectionStub()); - failureMechanism.DikeProfiles.Add(new TestDikeProfile()); + failureMechanism.DikeProfiles.AddRange(new[] + { + new TestDikeProfile(string.Empty, "id1") + }, "path"); view.Data = failureMechanismContext; MapData dikeProfileData = map.Data.Collection.ElementAt(dikeProfilesIndex); + var mocks = new MockRepository(); + IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); + observers[dikeProfilesIndex].Expect(obs => obs.UpdateObserver()); + observers[foreshoreProfilesIndex].Expect(obs => obs.UpdateObserver()); + mocks.ReplayAll(); // Precondition AssertDikeProfiles(failureMechanism.DikeProfiles, dikeProfileData); - failureMechanism.DikeProfiles.Add(new TestDikeProfile()); + failureMechanism.DikeProfiles.AddRange(new[] + { + new TestDikeProfile(string.Empty, "id2") + }, "path"); // Call failureMechanism.DikeProfiles.NotifyObservers(); // Assert AssertDikeProfiles(failureMechanism.DikeProfiles, dikeProfileData); + mocks.VerifyAll(); } } [Test] + public void NotifyObservers_DikeProfileUpdated_MapDataUpdated() + { + // Setup + using (var view = new GrassCoverErosionInwardsFailureMechanismView()) + { + IMapControl map = ((RingtoetsMapControl) view.Controls[0]).MapControl; + + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + var failureMechanismContext = new GrassCoverErosionInwardsFailureMechanismContext(failureMechanism, new ObservableTestAssessmentSectionStub()); + + var dikeProfile = new TestDikeProfile(string.Empty, "id1"); + failureMechanism.DikeProfiles.AddRange(new[] + { + dikeProfile + }, "path"); + + view.Data = failureMechanismContext; + + MapData dikeProfileData = map.Data.Collection.ElementAt(dikeProfilesIndex); + + var mocks = new MockRepository(); + IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); + observers[dikeProfilesIndex].Expect(obs => obs.UpdateObserver()); + observers[foreshoreProfilesIndex].Expect(obs => obs.UpdateObserver()); + mocks.ReplayAll(); + + // Precondition + AssertDikeProfiles(failureMechanism.DikeProfiles, dikeProfileData); + + var dikeProfileToUpdateFrom = new TestDikeProfile("A new name", "id1"); + dikeProfile.CopyProperties(dikeProfileToUpdateFrom); + + // Call + dikeProfile.NotifyObservers(); + + // Assert + AssertDikeProfiles(failureMechanism.DikeProfiles, dikeProfileData); + mocks.VerifyAll(); + } + } + + [Test] public void NotifyObservers_ForeshoreProfilesUpdated_MapDataUpdated() { // Setup @@ -530,30 +653,44 @@ var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); var failureMechanismContext = new GrassCoverErosionInwardsFailureMechanismContext(failureMechanism, new ObservableTestAssessmentSectionStub()); - failureMechanism.DikeProfiles.Add(new TestDikeProfile(new[] + var dikeProfile = new TestDikeProfile(new[] { new Point2D(0, 0), new Point2D(1, 1) - })); + }, "id1"); + failureMechanism.DikeProfiles.AddRange(new[] + { + dikeProfile + }, "path"); view.Data = failureMechanismContext; MapData dikeProfileData = map.Data.Collection.ElementAt(foreshoreProfilesIndex); + var mocks = new MockRepository(); + IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); + observers[dikeProfilesIndex].Expect(obs => obs.UpdateObserver()); + observers[foreshoreProfilesIndex].Expect(obs => obs.UpdateObserver()); + mocks.ReplayAll(); + // Precondition MapDataTestHelper.AssertForeshoreProfilesMapData(failureMechanism.DikeProfiles.Select(dp => dp.ForeshoreProfile), dikeProfileData); - failureMechanism.DikeProfiles.Add(new TestDikeProfile(new[] + var dikeProfileToUpdateFrom = new TestDikeProfile(new[] { new Point2D(2, 2), new Point2D(3, 3) - })); + }, "id1"); + dikeProfile.CopyProperties(dikeProfileToUpdateFrom); + // Call failureMechanism.DikeProfiles.NotifyObservers(); // Assert MapDataTestHelper.AssertForeshoreProfilesMapData(failureMechanism.DikeProfiles.Select(dp => dp.ForeshoreProfile), dikeProfileData); + + mocks.VerifyAll(); } } @@ -592,6 +729,10 @@ view.Data = failureMechanismContext; var calculationMapData = (MapLineData) map.Data.Collection.ElementAt(calculationsIndex); + var mocks = new MockRepository(); + IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); + observers[calculationsIndex].Expect(obs => obs.UpdateObserver()); + mocks.ReplayAll(); failureMechanism.CalculationsGroup.Children.Add(calculationB); @@ -600,6 +741,8 @@ // Assert AssertCalculationsMapData(failureMechanism.Calculations.Cast(), calculationMapData); + + mocks.VerifyAll(); } } @@ -611,9 +754,6 @@ { IMapControl map = ((RingtoetsMapControl) view.Controls[0]).MapControl; - var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); - var failureMechanismContext = new GrassCoverErosionInwardsFailureMechanismContext(failureMechanism, new ObservableTestAssessmentSectionStub()); - var dikeProfileA = new TestDikeProfile(new Point2D(1.3, 1.3)); var dikeProfileB = new TestDikeProfile(new Point2D(1.5, 1.5)); @@ -625,17 +765,28 @@ HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation() } }; + + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(calculationA); + var failureMechanismContext = new GrassCoverErosionInwardsFailureMechanismContext(failureMechanism, new ObservableTestAssessmentSectionStub()); view.Data = failureMechanismContext; var calculationMapData = (MapLineData) map.Data.Collection.ElementAt(calculationsIndex); + var mocks = new MockRepository(); + IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); + observers[calculationsIndex].Expect(obs => obs.UpdateObserver()); + mocks.ReplayAll(); + calculationA.InputParameters.DikeProfile = dikeProfileB; // Call calculationA.InputParameters.NotifyObservers(); // Assert AssertCalculationsMapData(failureMechanism.Calculations.Cast(), calculationMapData); + + mocks.VerifyAll(); } } @@ -647,9 +798,6 @@ { IMapControl map = ((RingtoetsMapControl) view.Controls[0]).MapControl; - var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); - var failureMechanismContext = new GrassCoverErosionInwardsFailureMechanismContext(failureMechanism, new ObservableTestAssessmentSectionStub()); - var dikeProfileA = new TestDikeProfile(new Point2D(1.3, 1.3)); var calculationA = new GrassCoverErosionInwardsCalculation @@ -661,17 +809,27 @@ } }; + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(calculationA); + var failureMechanismContext = new GrassCoverErosionInwardsFailureMechanismContext(failureMechanism, new ObservableTestAssessmentSectionStub()); view.Data = failureMechanismContext; var calculationMapData = (MapLineData) map.Data.Collection.ElementAt(calculationsIndex); + var mocks = new MockRepository(); + IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); + observers[calculationsIndex].Expect(obs => obs.UpdateObserver()); + mocks.ReplayAll(); + calculationA.Name = "new name"; // Call calculationA.NotifyObservers(); // Assert AssertCalculationsMapData(failureMechanism.Calculations.Cast(), calculationMapData); + + mocks.VerifyAll(); } } @@ -704,7 +862,7 @@ mapData.Remove(dataToMove); mapData.Add(dataToMove); - var mapDataList = mapData.Collection.ToList(); + List mapDataList = mapData.Collection.ToList(); // Precondition var referenceLineData = (MapLineData) mapDataList[updatedRefenceLineLayerIndex]; @@ -809,7 +967,7 @@ Assert.NotNull(dikeProfiles, "dikeProfiles should never be null."); var dikeProfilesData = (MapLineData) mapData; - var dikeProfileArray = dikeProfiles.ToArray(); + DikeProfile[] dikeProfileArray = dikeProfiles.ToArray(); Assert.IsInstanceOf(mapData); Assert.AreEqual(dikeProfileArray.Length, dikeProfilesData.Features.Length); @@ -827,13 +985,13 @@ { Assert.IsInstanceOf(mapData); var calculationsMapData = (MapLineData) mapData; - var calculationsArray = calculations.ToArray(); - var calculationsFeatures = calculationsMapData.Features.ToArray(); + GrassCoverErosionInwardsCalculation[] calculationsArray = calculations.ToArray(); + MapFeature[] calculationsFeatures = calculationsMapData.Features.ToArray(); Assert.AreEqual(calculationsArray.Length, calculationsFeatures.Length); for (var index = 0; index < calculationsArray.Length; index++) { - var geometries = calculationsFeatures[index].MapGeometries.ToArray(); + MapGeometry[] geometries = calculationsFeatures[index].MapGeometries.ToArray(); Assert.AreEqual(1, geometries.Length); GrassCoverErosionInwardsCalculation calculation = calculationsArray[index]; @@ -851,7 +1009,7 @@ { Assert.AreEqual("Dijken en dammen - Grasbekleding erosie kruin en binnentalud", mapDataCollection.Name); - var mapDataList = mapDataCollection.Collection.ToList(); + List mapDataList = mapDataCollection.Collection.ToList(); Assert.AreEqual(8, mapDataList.Count); @@ -882,5 +1040,53 @@ Assert.AreEqual("Hydraulische randvoorwaarden", hydraulicBoundaryLocationsMapData.Name); Assert.AreEqual("Berekeningen", calculationsMapData.Name); } + + /// + /// Attaches mocked observers to all map data components. + /// + /// The . + /// The map data collection containing the + /// elements. + /// An array of mocked observers attached to the data in . + private static IObserver[] AttachMapDataObservers(MockRepository mocks, IEnumerable mapData) + { + MapData[] mapDataArray = mapData.ToArray(); + + var referenceLineMapDataObserver = mocks.StrictMock(); + mapDataArray[referenceLineIndex].Attach(referenceLineMapDataObserver); + + var sectionsMapDataObserver = mocks.StrictMock(); + mapDataArray[sectionsIndex].Attach(sectionsMapDataObserver); + + var sectionsStartPointMapDataObserver = mocks.StrictMock(); + mapDataArray[sectionsStartPointIndex].Attach(sectionsStartPointMapDataObserver); + + var sectionsEndPointMapDataObserver = mocks.StrictMock(); + mapDataArray[sectionsEndPointIndex].Attach(sectionsEndPointMapDataObserver); + + var hydraulicBoundaryLocationsMapDataObserver = mocks.StrictMock(); + mapDataArray[hydraulicBoundaryLocationsIndex].Attach(hydraulicBoundaryLocationsMapDataObserver); + + var dikeProfilesObserver = mocks.StrictMock(); + mapDataArray[dikeProfilesIndex].Attach(dikeProfilesObserver); + + var foreshoreProfilesObserver = mocks.StrictMock(); + mapDataArray[foreshoreProfilesIndex].Attach(foreshoreProfilesObserver); + + var calculationsMapDataObserver = mocks.StrictMock(); + mapDataArray[calculationsIndex].Attach(calculationsMapDataObserver); + + return new[] + { + referenceLineMapDataObserver, + sectionsMapDataObserver, + sectionsStartPointMapDataObserver, + sectionsEndPointMapDataObserver, + hydraulicBoundaryLocationsMapDataObserver, + dikeProfilesObserver, + foreshoreProfilesObserver, + calculationsMapDataObserver + }; + } } } \ No newline at end of file Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Integration.Test/GrassCoverErosionInwardsInputContextPropertiesIntegrationTest.cs =================================================================== diff -u -r37fc59cc0f3becb92e14b8263bd8e9fc71aa0e79 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Integration.Test/GrassCoverErosionInwardsInputContextPropertiesIntegrationTest.cs (.../GrassCoverErosionInwardsInputContextPropertiesIntegrationTest.cs) (revision 37fc59cc0f3becb92e14b8263bd8e9fc71aa0e79) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Integration.Test/GrassCoverErosionInwardsInputContextPropertiesIntegrationTest.cs (.../GrassCoverErosionInwardsInputContextPropertiesIntegrationTest.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -29,7 +29,6 @@ using Ringtoets.Common.Data.DikeProfiles; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Data.TestUtil; -using Ringtoets.Common.Forms.PropertyClasses; using Ringtoets.Common.Forms.TestUtil; using Ringtoets.GrassCoverErosionInwards.Data; using Ringtoets.GrassCoverErosionInwards.Forms.PresentationObjects; @@ -55,8 +54,8 @@ var assessmentSection = mockRepository.Stub(); mockRepository.ReplayAll(); - DikeProfile dikeProfile1 = new TestDikeProfile(new Point2D(0.51, 0.51)); - DikeProfile dikeProfile2 = new TestDikeProfile(new Point2D(1.51, 1.51)); + DikeProfile dikeProfile1 = new TestDikeProfile(new Point2D(0.51, 0.51), "id1"); + DikeProfile dikeProfile2 = new TestDikeProfile(new Point2D(1.51, 1.51), "id2"); var calculation = new GrassCoverErosionInwardsCalculation { @@ -67,10 +66,12 @@ }; var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + failureMechanism.DikeProfiles.AddRange(new[] + { + dikeProfile1, + dikeProfile2 + }, "path"); - failureMechanism.DikeProfiles.Add(dikeProfile1); - failureMechanism.DikeProfiles.Add(dikeProfile2); - failureMechanism.CalculationsGroup.Children.Add(calculation); failureMechanism.AddSection(new FailureMechanismSection("firstSection", new List @@ -82,7 +83,7 @@ new Point2D(1.1, 1.1), new Point2D(2.2, 2.2) })); - var sectionResults = failureMechanism.SectionResults.ToArray(); + GrassCoverErosionInwardsFailureMechanismSectionResult[] sectionResults = failureMechanism.SectionResults.ToArray(); sectionResults[0].Calculation = calculation; var inputContext = new GrassCoverErosionInwardsInputContext(calculation.InputParameters, calculation, failureMechanism, assessmentSection); @@ -107,8 +108,8 @@ var assessmentSection = mockRepository.Stub(); mockRepository.ReplayAll(); - DikeProfile dikeProfile1 = new TestDikeProfile(new Point2D(0.51, 0.51)); - DikeProfile dikeProfile2 = new TestDikeProfile(new Point2D(1.51, 1.51)); + DikeProfile dikeProfile1 = new TestDikeProfile(new Point2D(0.51, 0.51), "id1"); + DikeProfile dikeProfile2 = new TestDikeProfile(new Point2D(1.51, 1.51), "id2"); var calculation1 = new GrassCoverErosionInwardsCalculation { @@ -128,10 +129,12 @@ }; var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + failureMechanism.DikeProfiles.AddRange(new[] + { + dikeProfile1, + dikeProfile2 + }, "path"); - failureMechanism.DikeProfiles.Add(dikeProfile1); - failureMechanism.DikeProfiles.Add(dikeProfile2); - failureMechanism.CalculationsGroup.Children.Add(calculation1); failureMechanism.CalculationsGroup.Children.Add(calculation2); @@ -144,7 +147,7 @@ new Point2D(1.1, 1.1), new Point2D(2.2, 2.2) })); - var sectionResults = failureMechanism.SectionResults.ToArray(); + GrassCoverErosionInwardsFailureMechanismSectionResult[] sectionResults = failureMechanism.SectionResults.ToArray(); sectionResults[0].Calculation = calculation1; sectionResults[1].Calculation = calculation2; Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Integration.Test/GrassCoverErosionInwardsScenariosViewIntegrationTest.cs =================================================================== diff -u -r1f549a37af503f5da697652b5e5199f8d29ac0fe -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Integration.Test/GrassCoverErosionInwardsScenariosViewIntegrationTest.cs (.../GrassCoverErosionInwardsScenariosViewIntegrationTest.cs) (revision 1f549a37af503f5da697652b5e5199f8d29ac0fe) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Integration.Test/GrassCoverErosionInwardsScenariosViewIntegrationTest.cs (.../GrassCoverErosionInwardsScenariosViewIntegrationTest.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -26,13 +26,17 @@ using Core.Common.TestUtil; using NUnit.Extensions.Forms; using NUnit.Framework; +using Rhino.Mocks; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.DikeProfiles; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Forms.Helpers; using Ringtoets.Common.IO.FileImporters; +using Ringtoets.Common.IO.FileImporters.MessageProviders; using Ringtoets.GrassCoverErosionInwards.Data; using Ringtoets.GrassCoverErosionInwards.Forms.Views; +using Ringtoets.GrassCoverErosionInwards.Plugin.FileImporters; using Ringtoets.Integration.Data; using Ringtoets.Integration.TestUtils; @@ -74,7 +78,7 @@ // Assert Assert.AreEqual(283, dataGridView.RowCount); - var expectedValues = assessmentSection.GrassCoverErosionInwards.SectionResults.Select(sr => sr.Section.Name); + IEnumerable expectedValues = assessmentSection.GrassCoverErosionInwards.SectionResults.Select(sr => sr.Section.Name); var foundValues = new List(); foreach (DataGridViewRow row in dataGridView.Rows) { @@ -90,6 +94,10 @@ // Setup using (var form = new Form()) { + var mocks = new MockRepository(); + var messageProvider = mocks.Stub(); + mocks.ReplayAll(); + var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); DataImportHelper.ImportReferenceLine(assessmentSection); IFailureMechanism failureMechanism = assessmentSection.GrassCoverErosionInwards; @@ -108,11 +116,13 @@ var dikeProfilesImporter = new DikeProfilesImporter(assessmentSection.GrassCoverErosionInwards.DikeProfiles, assessmentSection.ReferenceLine, - filePath); + filePath, new GrassCoverErosionInwardsDikeProfileReplaceDataStrategy( + (GrassCoverErosionInwardsFailureMechanism) failureMechanism), + messageProvider); dikeProfilesImporter.Import(); // Call - foreach (var profile in assessmentSection.GrassCoverErosionInwards.DikeProfiles) + foreach (DikeProfile profile in assessmentSection.GrassCoverErosionInwards.DikeProfiles) { calculationsGroup.Children.Add(new GrassCoverErosionInwardsCalculation { @@ -130,6 +140,8 @@ Assert.AreEqual(2, ((DataGridViewComboBoxCell) dataGridViewCell).Items.Count); Assert.AreEqual("", ((DataGridViewComboBoxCell) dataGridViewCell).Items[0].ToString()); Assert.AreEqual("profiel63p1Naam", ((DataGridViewComboBoxCell) dataGridViewCell).Items[1].ToString()); + + mocks.VerifyAll(); } } @@ -139,6 +151,10 @@ // Setup using (var form = new Form()) { + var mocks = new MockRepository(); + var messageProvider = mocks.Stub(); + mocks.ReplayAll(); + var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); DataImportHelper.ImportReferenceLine(assessmentSection); IFailureMechanism failureMechanism = assessmentSection.GrassCoverErosionInwards; @@ -157,10 +173,13 @@ var dikeProfilesImporter = new DikeProfilesImporter(assessmentSection.GrassCoverErosionInwards.DikeProfiles, assessmentSection.ReferenceLine, - filePath); + filePath, + new GrassCoverErosionInwardsDikeProfileReplaceDataStrategy( + (GrassCoverErosionInwardsFailureMechanism) failureMechanism), + messageProvider); dikeProfilesImporter.Import(); - foreach (var profile in assessmentSection.GrassCoverErosionInwards.DikeProfiles) + foreach (DikeProfile profile in assessmentSection.GrassCoverErosionInwards.DikeProfiles) { calculationsGroup.Children.Add(new GrassCoverErosionInwardsCalculation { @@ -174,7 +193,7 @@ calculationsGroup.NotifyObservers(); // Call - foreach (var calculationBase in calculationsGroup.Children) + foreach (ICalculationBase calculationBase in calculationsGroup.Children) { var calculation = (GrassCoverErosionInwardsCalculation) calculationBase; calculation.Name += "_changed"; @@ -185,6 +204,8 @@ Assert.AreEqual(2, ((DataGridViewComboBoxCell) dataGridViewCell).Items.Count); Assert.AreEqual("", ((DataGridViewComboBoxCell) dataGridViewCell).Items[0].ToString()); Assert.AreEqual("profiel63p1Naam_changed", ((DataGridViewComboBoxCell) dataGridViewCell).Items[1].ToString()); + + mocks.VerifyAll(); } } @@ -194,6 +215,10 @@ // Setup using (var form = new Form()) { + var mocks = new MockRepository(); + var messageProvider = mocks.Stub(); + mocks.ReplayAll(); + var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); DataImportHelper.ImportReferenceLine(assessmentSection); IFailureMechanism failureMechanism = assessmentSection.GrassCoverErosionInwards; @@ -211,10 +236,12 @@ var dikeProfilesImporter = new DikeProfilesImporter(assessmentSection.GrassCoverErosionInwards.DikeProfiles, assessmentSection.ReferenceLine, - filePath); + filePath, new GrassCoverErosionInwardsDikeProfileReplaceDataStrategy( + (GrassCoverErosionInwardsFailureMechanism) failureMechanism), + messageProvider); dikeProfilesImporter.Import(); - foreach (var profile in assessmentSection.GrassCoverErosionInwards.DikeProfiles) + foreach (DikeProfile profile in assessmentSection.GrassCoverErosionInwards.DikeProfiles) { assessmentSection.GrassCoverErosionInwards.CalculationsGroup.Children.Add(new GrassCoverErosionInwardsCalculation { @@ -227,7 +254,7 @@ } // Call - var calculationsGroup = assessmentSection.GrassCoverErosionInwards.CalculationsGroup; + CalculationGroup calculationsGroup = assessmentSection.GrassCoverErosionInwards.CalculationsGroup; ((GrassCoverErosionInwardsCalculation) calculationsGroup.Children[1]).InputParameters.DikeProfile = ((GrassCoverErosionInwardsCalculation) calculationsGroup.Children[0]).InputParameters.DikeProfile; calculationsGroup.NotifyObservers(); @@ -242,6 +269,8 @@ DataGridViewCell dataGridViewCellWithRemovedCalculation = dataGridView.Rows[56].Cells[1]; Assert.AreEqual(1, ((DataGridViewComboBoxCell) dataGridViewCellWithRemovedCalculation).Items.Count); Assert.AreEqual("", ((DataGridViewComboBoxCell) dataGridViewCellWithRemovedCalculation).Items[0].ToString()); + + mocks.VerifyAll(); } } } Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Integration.Test/Ringtoets.GrassCoverErosionInwards.Integration.Test.csproj =================================================================== diff -u -r892addff12de84067aa056391309259e610f2b3c -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Integration.Test/Ringtoets.GrassCoverErosionInwards.Integration.Test.csproj (.../Ringtoets.GrassCoverErosionInwards.Integration.Test.csproj) (revision 892addff12de84067aa056391309259e610f2b3c) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Integration.Test/Ringtoets.GrassCoverErosionInwards.Integration.Test.csproj (.../Ringtoets.GrassCoverErosionInwards.Integration.Test.csproj) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -116,6 +116,10 @@ {D24FA2F7-28A7-413B-AFD3-EE10E985630B} Ringtoets.Common.Forms.TestUtil + + {33508D7C-1602-4C0D-8503-73AAE98C19E5} + Ringtoets.Common.IO.TestUtil + {888D4097-8BC2-4703-9FB1-8744C94D525E} Ringtoets.HydraRing.Calculation @@ -140,6 +144,10 @@ {C540E627-B95B-4CC0-A1B6-A0BDF74936C7} Ringtoets.GrassCoverErosionInwards.Forms + + {20955E2A-8CEB-46B0-ADC4-A97D4C6BBDF5} + Ringtoets.GrassCoverErosionInwards.Plugin + {5D158D8E-A5EB-489C-A885-87E13BC0D3B3} Ringtoets.GrassCoverErosionInwards.Service Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/ChangeHandlers/UpdateDikeProfileParametersChangeHandlerTest.cs =================================================================== diff -u --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/ChangeHandlers/UpdateDikeProfileParametersChangeHandlerTest.cs (revision 0) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/ChangeHandlers/UpdateDikeProfileParametersChangeHandlerTest.cs (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -0,0 +1,184 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Linq; +using Core.Common.Gui; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.IO; +using Ringtoets.GrassCoverErosionInwards.Data; +using Ringtoets.GrassCoverErosionInwards.Data.TestUtil; +using Ringtoets.GrassCoverErosionInwards.Plugin.ChangeHandlers; + +namespace Ringtoets.GrassCoverErosionInwards.Plugin.Test.ChangeHandlers +{ + [TestFixture] + public class UpdateDikeProfileParametersChangeHandlerTest + { + [Test] + public void Constructor_WithoutCalculations_ThrowsArgumentNullException() + { + // Setup + var mockRepository = new MockRepository(); + var inquiryHandler = mockRepository.Stub(); + mockRepository.ReplayAll(); + + // Call + TestDelegate test = () => new UpdateDikeProfileParametersChangeHandler(null, string.Empty, inquiryHandler); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("calculations", paramName); + mockRepository.VerifyAll(); + } + + [Test] + public void Constructor_WithoutInquiryHandler_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => new UpdateDikeProfileParametersChangeHandler(Enumerable.Empty(), + string.Empty, + null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("inquiryHandler", paramName); + } + + [Test] + public void Constructor_WithoutQuery_ThrowsArgumentNullException() + { + // Setup + var mockRepository = new MockRepository(); + var inquiryHandler = mockRepository.Stub(); + mockRepository.ReplayAll(); + + // Call + TestDelegate test = () => new UpdateDikeProfileParametersChangeHandler(Enumerable.Empty(), + null, + inquiryHandler); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("query", paramName); + } + + [Test] + public void Constructor_WithParameters_ImplementsExpectedInterface() + { + // Setup + var mockRepository = new MockRepository(); + var inquiryHandler = mockRepository.StrictMock(); + mockRepository.ReplayAll(); + + // Call + var handler = new UpdateDikeProfileParametersChangeHandler(Enumerable.Empty(), + string.Empty, + inquiryHandler); + + // Assert + Assert.IsInstanceOf(handler); + mockRepository.VerifyAll(); + } + + [Test] + public void RequireConfirmation_WithAllCalculationsWithoutOutput_ReturnFalse() + { + // Setup + var mockRepository = new MockRepository(); + var inquiryHandler = mockRepository.StrictMock(); + mockRepository.ReplayAll(); + + var calculations = new[] + { + new GrassCoverErosionInwardsCalculation() + }; + + var handler = new UpdateDikeProfileParametersChangeHandler(calculations, + string.Empty, + inquiryHandler); + + // Call + bool requireConfirmation = handler.RequireConfirmation(); + + // Assert + Assert.IsFalse(requireConfirmation); + mockRepository.VerifyAll(); + } + + [Test] + public void RequireConfirmation_CalculationsWithOutput_ReturnTrue() + { + // Setup + var mockRepository = new MockRepository(); + var inquiryHandler = mockRepository.StrictMock(); + mockRepository.ReplayAll(); + + var calculations = new[] + { + new GrassCoverErosionInwardsCalculation + { + Output = new TestGrassCoverErosionInwardsOutput() + }, + new GrassCoverErosionInwardsCalculation() + }; + + var handler = new UpdateDikeProfileParametersChangeHandler(calculations, + string.Empty, + inquiryHandler); + + // Call + bool requireConfirmation = handler.RequireConfirmation(); + + // Assert + Assert.IsTrue(requireConfirmation); + mockRepository.VerifyAll(); + } + + [Test] + [TestCase("I am a query", true)] + [TestCase("I am a query", false)] + [TestCase("", true)] + [TestCase("", false)] + [TestCase(" ", true)] + [TestCase(" ", false)] + public void InquireConfirmation_Always_ShowsConfirmationDialogReturnResultOfInquiry(string message, bool expectedResult) + { + // Setup + var mockRepository = new MockRepository(); + var inquiryHandler = mockRepository.StrictMock(); + inquiryHandler.Expect(ih => ih.InquireContinuation(message)).Return(expectedResult); + mockRepository.ReplayAll(); + + var handler = new UpdateDikeProfileParametersChangeHandler(Enumerable.Empty(), + message, + inquiryHandler); + + // Call + bool result = handler.InquireConfirmation(); + + // Assert + Assert.AreEqual(expectedResult, result); + mockRepository.VerifyAll(); + } + } +} \ No newline at end of file Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/FileImporters/GrassCoverErosionInwardsDikeProfileReplaceDataStrategyTest.cs =================================================================== diff -u --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/FileImporters/GrassCoverErosionInwardsDikeProfileReplaceDataStrategyTest.cs (revision 0) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/FileImporters/GrassCoverErosionInwardsDikeProfileReplaceDataStrategyTest.cs (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -0,0 +1,266 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Collections.Generic; +using System.Linq; +using Core.Common.Base; +using NUnit.Framework; +using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.Common.Data.Exceptions; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Data.UpdateDataStrategies; +using Ringtoets.Common.IO.FileImporters; +using Ringtoets.GrassCoverErosionInwards.Data; +using Ringtoets.GrassCoverErosionInwards.Data.TestUtil; +using Ringtoets.GrassCoverErosionInwards.Plugin.FileImporters; + +namespace Ringtoets.GrassCoverErosionInwards.Plugin.Test.FileImporters +{ + [TestFixture] + public class GrassCoverErosionInwardsDikeProfileReplaceDataStrategyTest + { + private const string sourceFilePath = "some/path"; + + [Test] + public void Constructor_FailureMechanismNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => new GrassCoverErosionInwardsDikeProfileReplaceDataStrategy(null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("failureMechanism", exception.ParamName); + } + + [Test] + public void Constructor_CreatesNewInstance() + { + // Call + var strategy = new GrassCoverErosionInwardsDikeProfileReplaceDataStrategy(new GrassCoverErosionInwardsFailureMechanism()); + + // Assert + Assert.IsInstanceOf>(strategy); + Assert.IsInstanceOf(strategy); + } + + [Test] + public void UpdateDikeProfilesWithImportedData_TargetCollectionNull_ThrowsArgumentNullException() + { + // Setup + var strategy = new GrassCoverErosionInwardsDikeProfileReplaceDataStrategy(new GrassCoverErosionInwardsFailureMechanism()); + + // Call + TestDelegate call = () => strategy.UpdateDikeProfilesWithImportedData(null, + Enumerable.Empty(), + string.Empty); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("targetDataCollection", exception.ParamName); + } + + [Test] + public void UpdateDikeProfilesWithImportedData_ImportedDataCollectionNull_ThrowsArgumentNullException() + { + // Setup + var strategy = new GrassCoverErosionInwardsDikeProfileReplaceDataStrategy(new GrassCoverErosionInwardsFailureMechanism()); + + // Call + TestDelegate call = () => strategy.UpdateDikeProfilesWithImportedData(new DikeProfileCollection(), + null, + string.Empty); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("importedDataCollection", exception.ParamName); + } + + [Test] + public void UpdateDikeProfilesWithImportedData_SourceFilePathNull_ThrowsArgumentNullException() + { + // Setup + var strategy = new GrassCoverErosionInwardsDikeProfileReplaceDataStrategy(new GrassCoverErosionInwardsFailureMechanism()); + + // Call + TestDelegate call = () => strategy.UpdateDikeProfilesWithImportedData(new DikeProfileCollection(), + Enumerable.Empty(), + null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("sourceFilePath", exception.ParamName); + } + + [Test] + public void UpdateDikeProfilesWithImportedData_DifferentSourcePath_UpdatesSourcePathOfDataCollection() + { + // Setup + var targetCollection = new DikeProfileCollection(); + + var strategy = new GrassCoverErosionInwardsDikeProfileReplaceDataStrategy(new GrassCoverErosionInwardsFailureMechanism()); + const string newSourcePath = "some/other/path"; + + // Call + IEnumerable affectedObjects = strategy.UpdateDikeProfilesWithImportedData(targetCollection, + Enumerable.Empty(), + newSourcePath); + // Assert + Assert.AreEqual(newSourcePath, targetCollection.SourcePath); + CollectionAssert.AreEqual(new IObservable[] + { + targetCollection + }, affectedObjects); + CollectionAssert.IsEmpty(targetCollection); + } + + [Test] + public void UpdateDikeProfilesWithImportedData_CollectionEmptyAndImportedCollectionNotEmpty_AddsNewDikeProfiles() + { + // Setup + var importedDikeProfiles = new[] + { + new TestDikeProfile() + }; + + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + var strategy = new GrassCoverErosionInwardsDikeProfileReplaceDataStrategy(failureMechanism); + + // Call + IEnumerable affectedObjects = strategy.UpdateDikeProfilesWithImportedData(failureMechanism.DikeProfiles, + importedDikeProfiles, + sourceFilePath); + + // Assert + DikeProfileCollection actualCollection = failureMechanism.DikeProfiles; + CollectionAssert.AreEqual(importedDikeProfiles, actualCollection); + CollectionAssert.AreEqual(new[] + { + actualCollection + }, affectedObjects); + } + + [Test] + public void UpdateDikeProfilesWithImportedData_CollectionAndImportedDataCollectionNotEmpty_ReplacesCurrentWithImportedData() + { + // Setup + var targetDikeProfile = new TestDikeProfile("Name A", "Name A ID"); + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + failureMechanism.DikeProfiles.AddRange(new[] + { + targetDikeProfile + }, sourceFilePath); + + var readDikeProfile = new TestDikeProfile("Name B", "Name B ID"); + + var strategy = new GrassCoverErosionInwardsDikeProfileReplaceDataStrategy(failureMechanism); + + // Call + IEnumerable affectedObjects = strategy.UpdateDikeProfilesWithImportedData( + failureMechanism.DikeProfiles, + new[] + { + readDikeProfile + }, sourceFilePath); + + // Assert + CollectionAssert.AreEqual(new[] + { + failureMechanism.DikeProfiles + }, affectedObjects); + + var expectedDikeProfiles = new[] + { + readDikeProfile + }; + CollectionAssert.AreEqual(expectedDikeProfiles, failureMechanism.DikeProfiles); + } + + [Test] + public void UpdateDikeProfilesWithImportedData_ImportedDataContainsDuplicateIDs_ThrowsUpdateException() + { + // Setup + var targetCollection = new DikeProfileCollection(); + + const string duplicateId = "Duplicate ID it is"; + DikeProfile[] importedSurfaceLines = + { + new TestDikeProfile("Naam A", duplicateId), + new TestDikeProfile("Naam B", duplicateId) + }; + + var strategy = new GrassCoverErosionInwardsDikeProfileReplaceDataStrategy(new GrassCoverErosionInwardsFailureMechanism()); + + // Call + TestDelegate call = () => strategy.UpdateDikeProfilesWithImportedData(targetCollection, + importedSurfaceLines, + sourceFilePath); + + // Assert + var exception = Assert.Throws(call); + string expectedMessage = "Het importeren van dijkprofielen is mislukt: " + + $"Dijkprofielen moeten een unieke id hebben. Gevonden dubbele elementen: {duplicateId}."; + Assert.AreEqual(expectedMessage, exception.Message); + Assert.IsInstanceOf(exception.InnerException); + } + + [Test] + public void UpdateDikeProfilesWithImportedData_CalculationWithOutputAndDikeProfile_CalculationUpdatedAndReturnsAffectedObjects() + { + // Setup + var existingDikeProfile = new TestDikeProfile("test", "ID1"); + + var calculation = new GrassCoverErosionInwardsCalculation + { + InputParameters = + { + DikeProfile = existingDikeProfile + }, + Output = new TestGrassCoverErosionInwardsOutput() + }; + + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + failureMechanism.DikeProfiles.AddRange(new[] + { + existingDikeProfile + }, sourceFilePath); + failureMechanism.CalculationsGroup.Children.Add(calculation); + + var strategy = new GrassCoverErosionInwardsDikeProfileReplaceDataStrategy(failureMechanism); + + // Call + IEnumerable affectedObjects = strategy.UpdateDikeProfilesWithImportedData(failureMechanism.DikeProfiles, + Enumerable.Empty(), + sourceFilePath); + + // Assert + Assert.IsFalse(calculation.HasOutput); + Assert.IsNull(calculation.InputParameters.DikeProfile); + + CollectionAssert.AreEquivalent(new IObservable[] + { + calculation, + calculation.InputParameters, + failureMechanism.DikeProfiles + }, affectedObjects); + } + } +} \ No newline at end of file Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/FileImporters/GrassCoverErosionInwardsDikeProfileUpdateDataStrategyTest.cs =================================================================== diff -u --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/FileImporters/GrassCoverErosionInwardsDikeProfileUpdateDataStrategyTest.cs (revision 0) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/FileImporters/GrassCoverErosionInwardsDikeProfileUpdateDataStrategyTest.cs (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -0,0 +1,627 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Collections.Generic; +using System.Linq; +using Core.Common.Base; +using Core.Common.Base.Data; +using Core.Common.Base.Geometry; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.Common.Data.Exceptions; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Data.UpdateDataStrategies; +using Ringtoets.Common.IO.FileImporters; +using Ringtoets.GrassCoverErosionInwards.Data; +using Ringtoets.GrassCoverErosionInwards.Data.TestUtil; +using Ringtoets.GrassCoverErosionInwards.Plugin.FileImporters; + +namespace Ringtoets.GrassCoverErosionInwards.Plugin.Test.FileImporters +{ + [TestFixture] + public class GrassCoverErosionInwardsDikeProfileUpdateDataStrategyTest + { + private const string sourceFilePath = "some/Path"; + + [Test] + public void Constructor_FailureMechanismNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => new GrassCoverErosionInwardsDikeProfileUpdateDataStrategy(null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("failureMechanism", exception.ParamName); + } + + [Test] + public void Constructor_CreatesNewInstance() + { + // Call + var strategy = new GrassCoverErosionInwardsDikeProfileUpdateDataStrategy(new GrassCoverErosionInwardsFailureMechanism()); + + // Assert + Assert.IsInstanceOf>(strategy); + Assert.IsInstanceOf(strategy); + } + + [Test] + public void UpdateDikeProfilesWithImportedData_TargetCollectionNull_ThrowsArgumentNullException() + { + // Setup + var strategy = new GrassCoverErosionInwardsDikeProfileUpdateDataStrategy(new GrassCoverErosionInwardsFailureMechanism()); + + // Call + TestDelegate call = () => strategy.UpdateDikeProfilesWithImportedData(null, + Enumerable.Empty(), + string.Empty); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("targetDataCollection", exception.ParamName); + } + + [Test] + public void UpdateDikeProfilesWithImportedData_ImportedDataCollectionNull_ThrowsArgumentNullException() + { + // Setup + var strategy = new GrassCoverErosionInwardsDikeProfileUpdateDataStrategy(new GrassCoverErosionInwardsFailureMechanism()); + + // Call + TestDelegate call = () => strategy.UpdateDikeProfilesWithImportedData(new DikeProfileCollection(), + null, + string.Empty); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("importedDataCollection", exception.ParamName); + } + + [Test] + public void UpdateDikeProfilesWithImportedData_SourceFilePathNull_ThrowsArgumentNullException() + { + // Setup + var strategy = new GrassCoverErosionInwardsDikeProfileUpdateDataStrategy(new GrassCoverErosionInwardsFailureMechanism()); + + // Call + TestDelegate call = () => strategy.UpdateDikeProfilesWithImportedData(new DikeProfileCollection(), + Enumerable.Empty(), + null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("sourceFilePath", exception.ParamName); + } + + [Test] + public void UpdateDikeProfilesWithImportedData_CurrentCollectionAndImportedCollectionEmpty_DoesNothing() + { + // Setup + var targetCollection = new DikeProfileCollection(); + var strategy = new GrassCoverErosionInwardsDikeProfileUpdateDataStrategy(new GrassCoverErosionInwardsFailureMechanism()); + + // Call + IEnumerable affectedObjects = strategy.UpdateDikeProfilesWithImportedData(targetCollection, + Enumerable.Empty(), + sourceFilePath); + + // Assert + CollectionAssert.IsEmpty(targetCollection); + CollectionAssert.IsEmpty(affectedObjects); + } + + [Test] + public void UpdateDikeProfilesWithImportedData_DikeProfilePropertiesChanged_UpdateRelevantProperties() + { + // Setup + var dikeProfileToUpdate = new TestDikeProfile("name", "ID A"); + DikeProfile dikeProfileToUpdateFrom = DeepCloneAndModify(dikeProfileToUpdate); + + var targetCollection = new DikeProfileCollection(); + targetCollection.AddRange(new[] + { + dikeProfileToUpdate + }, sourceFilePath); + + var strategy = new GrassCoverErosionInwardsDikeProfileUpdateDataStrategy(new GrassCoverErosionInwardsFailureMechanism()); + + // Call + strategy.UpdateDikeProfilesWithImportedData(targetCollection, + new[] + { + dikeProfileToUpdateFrom + }, sourceFilePath); + + // Assert + Assert.AreSame(dikeProfileToUpdate, targetCollection[0]); + AssertDikeProfile(dikeProfileToUpdateFrom, dikeProfileToUpdate); + } + + [Test] + public void UpdateDikeProfilesWithImportedData_CurrentCollectionEmptyAndReadProfilesHaveDuplicateIds_ThrowsUpdateException() + { + // Setup + const string duplicateId = "A duplicated ID"; + var dikeProfileOne = new TestDikeProfile("name one", duplicateId); + var dikeProfileTwo = new TestDikeProfile("Another dike profile", duplicateId); + + var targetCollection = new DikeProfileCollection(); + var strategy = new GrassCoverErosionInwardsDikeProfileUpdateDataStrategy(new GrassCoverErosionInwardsFailureMechanism()); + + // Call + TestDelegate call = () => strategy.UpdateDikeProfilesWithImportedData(targetCollection, + new[] + { + dikeProfileOne, + dikeProfileTwo + }, sourceFilePath); + + // Assert + var exception = Assert.Throws(call); + + string expectedMessage = "Het bijwerken van de dijkprofielen is mislukt: " + + $"Dijkprofielen moeten een unieke id hebben. Gevonden dubbele elementen: {duplicateId}."; + Assert.AreEqual(expectedMessage, exception.Message); + Assert.IsInstanceOf(exception.InnerException); + + CollectionAssert.IsEmpty(targetCollection); + } + + [Test] + public void UpdateDikeProfilesWithImportedData_CurrentCollectionEmptyAndImportedCollectionNotEmpty_NewProfilesAdded() + { + // Setup + var dikeProfileOne = new TestDikeProfile(string.Empty, "ID One"); + var dikeProfileTwo = new TestDikeProfile(string.Empty, "ID Two"); + var importedDataCollection = new[] + { + dikeProfileOne, + dikeProfileTwo + }; + + var targetCollection = new DikeProfileCollection(); + var strategy = new GrassCoverErosionInwardsDikeProfileUpdateDataStrategy(new GrassCoverErosionInwardsFailureMechanism()); + + // Call + IEnumerable affectedObjects = strategy.UpdateDikeProfilesWithImportedData(targetCollection, + importedDataCollection, + sourceFilePath); + + // Assert + CollectionAssert.AreEqual(importedDataCollection, targetCollection); + CollectionAssert.AreEqual(new IObservable[] + { + targetCollection + }, affectedObjects); + } + + [Test] + public void UpdateDikeProfilesWithImportedData_WithCurrentDikeProfileAndImportedMultipleDikeProfilesWithSameId_ThrowsUpdateException() + { + // Setup + const string duplicateId = "A duplicated ID"; + var expectedDikeProfile = new TestDikeProfile("expectedName", duplicateId); + + var targetCollection = new DikeProfileCollection(); + var expectedTargetCollection = new[] + { + expectedDikeProfile + }; + targetCollection.AddRange(expectedTargetCollection, sourceFilePath); + + var importedTargetCollection = new[] + { + DeepCloneAndModify(expectedDikeProfile), + DeepCloneAndModify(expectedDikeProfile) + }; + + var strategy = new GrassCoverErosionInwardsDikeProfileUpdateDataStrategy(new GrassCoverErosionInwardsFailureMechanism()); + + // Call + TestDelegate call = () => strategy.UpdateDikeProfilesWithImportedData(targetCollection, + importedTargetCollection, + sourceFilePath); + + // Assert + var exception = Assert.Throws(call); + const string expectedMessage = "Het bijwerken van de dijkprofielen is mislukt: " + + "Geïmporteerde data moet unieke elementen bevatten."; + Assert.AreEqual(expectedMessage, exception.Message); + Assert.IsInstanceOf(exception.InnerException); + + CollectionAssert.AreEqual(expectedTargetCollection, targetCollection); + AssertDikeProfile(expectedDikeProfile, targetCollection[0]); + } + + [Test] + public void UpdateDikeProfilesWithImportedData_WithCurrentDikeProfilesAndImportedDataEmpty_RemovesDikeProfiles() + { + // Setup + var dikeProfile = new TestDikeProfile(); + + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + DikeProfileCollection dikeProfileCollection = failureMechanism.DikeProfiles; + dikeProfileCollection.AddRange(new[] + { + dikeProfile + }, sourceFilePath); + + var strategy = new GrassCoverErosionInwardsDikeProfileUpdateDataStrategy(failureMechanism); + + // Call + IEnumerable affectedObjects = strategy.UpdateDikeProfilesWithImportedData(dikeProfileCollection, + Enumerable.Empty(), + sourceFilePath); + + // Assert + CollectionAssert.IsEmpty(dikeProfileCollection); + CollectionAssert.AreEqual(new[] + { + dikeProfileCollection + }, affectedObjects); + } + + [Test] + public void UpdateDikeProfilesWithImportedData_WithCurrentDikeProfilesAndImportedDataFullyOverlaps_UpdatesTargetCollection() + { + // Setup + const string id = "Just an ID"; + var targetDikeProfile = new TestDikeProfile("name", id); + var targetCollection = new DikeProfileCollection(); + targetCollection.AddRange(new[] + { + targetDikeProfile + }, sourceFilePath); + + DikeProfile readDikeProfile = DeepCloneAndModify(targetDikeProfile); + var readDikeProfiles = new[] + { + readDikeProfile + }; + + var strategy = new GrassCoverErosionInwardsDikeProfileUpdateDataStrategy(new GrassCoverErosionInwardsFailureMechanism()); + + // Call + IEnumerable affectedObjects = strategy.UpdateDikeProfilesWithImportedData(targetCollection, + readDikeProfiles, + sourceFilePath); + + // Assert + Assert.AreEqual(1, targetCollection.Count); + Assert.AreSame(targetDikeProfile, targetCollection[0]); + AssertDikeProfile(readDikeProfile, targetDikeProfile); + + CollectionAssert.AreEquivalent(new IObservable[] + { + targetCollection, + targetDikeProfile + }, affectedObjects); + } + + [Test] + public void UpdateDikeProfilesWithImportedData_WithCurrentDikeProfilesAndImportedDataHasNoOverlap_UpdatesTargetCollection() + { + // Setup + const string currentDikeProfileId = "Current ID"; + var targetDikeProfile = new TestDikeProfile(string.Empty, currentDikeProfileId); + + const string readDikeProfileId = "Read ID"; + var readDikeProfile = new TestDikeProfile(string.Empty, readDikeProfileId); + var readDikeProfiles = new[] + { + readDikeProfile + }; + + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + DikeProfileCollection dikeProfiles = failureMechanism.DikeProfiles; + dikeProfiles.AddRange(new[] + { + targetDikeProfile + }, sourceFilePath); + + var strategy = new GrassCoverErosionInwardsDikeProfileUpdateDataStrategy(failureMechanism); + + // Call + IEnumerable affectedObjects = strategy.UpdateDikeProfilesWithImportedData(dikeProfiles, + readDikeProfiles, + sourceFilePath); + + // Assert + Assert.AreEqual(1, dikeProfiles.Count); + Assert.AreSame(readDikeProfile, dikeProfiles[0]); + + CollectionAssert.AreEquivalent(new[] + { + dikeProfiles + }, affectedObjects); + } + + [Test] + public void UpdateDikeProfilesWithImportedData_WithCurrentDikeProfilesAndImportedDataHasPartialOverlap_UpdatesTargetCollection() + { + // Setup + const string addedDikeProfileId = "ID A"; + const string removedDikeProfileId = "ID B"; + const string updatedDikeProfileId = "ID C"; + const string commonName = "Just a name for dike profile"; + + var dikeProfileToBeRemoved = new TestDikeProfile(commonName, removedDikeProfileId); + var dikeProfileToBeUpdated = new TestDikeProfile(commonName, updatedDikeProfileId); + + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + DikeProfileCollection dikeProfiles = failureMechanism.DikeProfiles; + dikeProfiles.AddRange(new[] + { + dikeProfileToBeRemoved, + dikeProfileToBeUpdated + }, sourceFilePath); + + DikeProfile dikeProfileToUpdateFrom = DeepCloneAndModify(dikeProfileToBeUpdated); + var dikeProfileToBeAdded = new TestDikeProfile(commonName, addedDikeProfileId); + var readDikeProfiles = new[] + { + dikeProfileToBeAdded, + dikeProfileToUpdateFrom + }; + + var strategy = new GrassCoverErosionInwardsDikeProfileUpdateDataStrategy(failureMechanism); + + // Call + IEnumerable affectedObjects = strategy.UpdateDikeProfilesWithImportedData(dikeProfiles, + readDikeProfiles, + sourceFilePath); + + // Assert + Assert.AreEqual(2, dikeProfiles.Count); + var expectedDikeProfiles = new[] + { + dikeProfileToBeUpdated, + dikeProfileToBeAdded + }; + CollectionAssert.AreEqual(expectedDikeProfiles, dikeProfiles); + + DikeProfile updatedDikeProfile = dikeProfiles[0]; + Assert.AreSame(dikeProfileToBeUpdated, updatedDikeProfile); + AssertDikeProfile(dikeProfileToUpdateFrom, updatedDikeProfile); + + DikeProfile addedDikeProfile = dikeProfiles[1]; + Assert.AreSame(dikeProfileToBeAdded, addedDikeProfile); + AssertDikeProfile(dikeProfileToBeAdded, addedDikeProfile); + + CollectionAssert.AreEquivalent(new IObservable[] + { + dikeProfileToBeUpdated, + dikeProfiles + }, affectedObjects); + } + + [Test] + public void UpdateDikeProfilesWithImportedData_CalculationWithOutputAssignedToRemovedProfile_UpdatesCalculation() + { + // Setup + var profileToBeRemoved = new TestDikeProfile("Removed profile", "removed profile ID"); + var calculation = new GrassCoverErosionInwardsCalculation + { + InputParameters = + { + DikeProfile = profileToBeRemoved + }, + Output = new TestGrassCoverErosionInwardsOutput() + }; + + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(calculation); + DikeProfileCollection dikeProfileCollection = failureMechanism.DikeProfiles; + dikeProfileCollection.AddRange(new[] + { + profileToBeRemoved + }, sourceFilePath); + + var strategy = new GrassCoverErosionInwardsDikeProfileUpdateDataStrategy(failureMechanism); + + // Call + IEnumerable affectedObjects = strategy.UpdateDikeProfilesWithImportedData(dikeProfileCollection, + Enumerable.Empty(), + sourceFilePath); + + // Assert + Assert.IsFalse(calculation.HasOutput); + Assert.IsNull(calculation.InputParameters.DikeProfile); + + CollectionAssert.AreEquivalent(new IObservable[] + { + dikeProfileCollection, + calculation, + calculation.InputParameters + }, affectedObjects); + } + + [Test] + public void UpdateDikeProfilesWithImportedData_MultipleCalculationWithAssignedProfile_OnlyUpdatesCalculationWithUpdatedProfile() + { + // Setup + var affectedProfile = new TestDikeProfile("Profile to be updated", "ID of updated profile"); + var affectedCalculation = new GrassCoverErosionInwardsCalculation + { + InputParameters = + { + DikeProfile = affectedProfile + }, + Output = new TestGrassCoverErosionInwardsOutput() + }; + + const string unaffectedProfileName = "Unaffected Profile"; + const string unaffectedProfileId = "unaffected profile Id"; + var unaffectedProfile = new TestDikeProfile(unaffectedProfileName, unaffectedProfileId); + var unaffectedCalculation = new GrassCoverErosionInwardsCalculation + { + InputParameters = + { + DikeProfile = unaffectedProfile + }, + Output = new TestGrassCoverErosionInwardsOutput() + }; + + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + DikeProfileCollection dikeProfiles = failureMechanism.DikeProfiles; + dikeProfiles.AddRange(new[] + { + affectedProfile, + unaffectedProfile + }, sourceFilePath); + failureMechanism.CalculationsGroup.Children.Add(affectedCalculation); + failureMechanism.CalculationsGroup.Children.Add(unaffectedCalculation); + + DikeProfile importedAffectedProfile = DeepCloneAndModify(affectedProfile); + var importedUnaffectedProfile = new TestDikeProfile(unaffectedProfileName, unaffectedProfileId); + + var strategy = new GrassCoverErosionInwardsDikeProfileUpdateDataStrategy(failureMechanism); + + // Call + IEnumerable affectedObjects = strategy.UpdateDikeProfilesWithImportedData(dikeProfiles, + new[] + { + importedAffectedProfile, + importedUnaffectedProfile + }, sourceFilePath); + // Assert + Assert.IsTrue(unaffectedCalculation.HasOutput); + DikeProfile inputParametersUnaffectedDikeProfile = unaffectedCalculation.InputParameters.DikeProfile; + Assert.AreSame(unaffectedProfile, inputParametersUnaffectedDikeProfile); + AssertDikeProfile(unaffectedProfile, inputParametersUnaffectedDikeProfile); + + Assert.IsTrue(unaffectedCalculation.HasOutput); + DikeProfile inputParametersAffectedDikeProfile = affectedCalculation.InputParameters.DikeProfile; + Assert.AreSame(affectedProfile, inputParametersAffectedDikeProfile); + AssertDikeProfile(importedAffectedProfile, inputParametersAffectedDikeProfile); + + CollectionAssert.AreEquivalent(new IObservable[] + { + affectedCalculation, + affectedCalculation.InputParameters, + affectedProfile, + dikeProfiles + }, affectedObjects); + } + + [Test] + public void UpdateDikeProfilesWithImportedData_CalculationWithSameReference_OnlyReturnsDistinctCalculation() + { + // Setup + var affectedProfile = new TestDikeProfile("Profile to be updated", "ID of updated profile"); + var affectedCalculation = new GrassCoverErosionInwardsCalculation + { + InputParameters = + { + DikeProfile = affectedProfile + }, + Output = new TestGrassCoverErosionInwardsOutput() + }; + + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(affectedCalculation); + failureMechanism.CalculationsGroup.Children.Add(affectedCalculation); + DikeProfileCollection dikeProfiles = failureMechanism.DikeProfiles; + dikeProfiles.AddRange(new[] + { + affectedProfile + }, sourceFilePath); + + DikeProfile profileToUpdateFrom = DeepCloneAndModify(affectedProfile); + + var strategy = new GrassCoverErosionInwardsDikeProfileUpdateDataStrategy(failureMechanism); + + // Call + IEnumerable affectedObjects = strategy.UpdateDikeProfilesWithImportedData(dikeProfiles, + new[] + { + profileToUpdateFrom + }, sourceFilePath); + // Assert + CollectionAssert.AreEquivalent(new IObservable[] + { + dikeProfiles, + affectedCalculation, + affectedCalculation.InputParameters, + affectedProfile + }, affectedObjects); + } + + /// + /// Makes a deep clone of the and modifies + /// all its parameters, except the ID. + /// + /// The to clone and + /// to modify. + /// A deep clone of with modified + /// parameters. + private static DikeProfile DeepCloneAndModify(DikeProfile dikeProfile) + { + var random = new Random(21); + + Point2D originalWorldCoordinate = dikeProfile.WorldReferencePoint; + var modifiedWorldCoordinate = new Point2D(originalWorldCoordinate.X + random.NextDouble(), + originalWorldCoordinate.Y + random.NextDouble()); + + List modifiedDikeGeometry = dikeProfile.DikeGeometry.ToList(); + modifiedDikeGeometry.Add(new RoughnessPoint(new Point2D(1, 2), 3)); + + List modifiedForeshoreGeometry = dikeProfile.ForeshoreGeometry.ToList(); + modifiedForeshoreGeometry.Add(new Point2D(1, 2)); + + RoundedDouble originalBreakWaterHeight = dikeProfile.BreakWater?.Height ?? (RoundedDouble) 0.0; + var modifiedBreakWater = new BreakWater(random.NextEnumValue(), + originalBreakWaterHeight + random.NextDouble()); + + string modifiedName = $"new_name_{dikeProfile.Name}"; + double modifiedDikeHeight = dikeProfile.DikeHeight + random.NextDouble(); + double modifiedOrientation = dikeProfile.Orientation + random.NextDouble(); + double modifiedX0 = dikeProfile.X0 + random.NextDouble(); + + return new DikeProfile(modifiedWorldCoordinate, modifiedDikeGeometry, + modifiedForeshoreGeometry, modifiedBreakWater, + new DikeProfile.ConstructionProperties + { + Name = modifiedName, + Id = dikeProfile.Id, + DikeHeight = modifiedDikeHeight, + Orientation = modifiedOrientation, + X0 = modifiedX0 + }); + } + + private static void AssertDikeProfile(DikeProfile expectedDikeProfile, DikeProfile actualDikeProfile) + { + Assert.AreEqual(expectedDikeProfile.WorldReferencePoint, actualDikeProfile.WorldReferencePoint); + CollectionAssert.AreEqual(expectedDikeProfile.ForeshoreGeometry, actualDikeProfile.ForeshoreGeometry); + CollectionAssert.AreEqual(expectedDikeProfile.DikeGeometry, actualDikeProfile.DikeGeometry); + Assert.AreEqual(expectedDikeProfile.BreakWater, actualDikeProfile.BreakWater); + + Assert.AreEqual(expectedDikeProfile.Id, actualDikeProfile.Id); + Assert.AreEqual(expectedDikeProfile.Name, actualDikeProfile.Name); + Assert.AreEqual(expectedDikeProfile.X0, actualDikeProfile.X0); + Assert.AreEqual(expectedDikeProfile.Orientation, actualDikeProfile.Orientation); + Assert.AreEqual(expectedDikeProfile.DikeHeight, actualDikeProfile.DikeHeight); + } + } +} \ No newline at end of file Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/GrassCoverErosionInwardsPluginTest.cs =================================================================== diff -u -r9448c9f34da890e184722d00c3f8b4f765a246b0 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/GrassCoverErosionInwardsPluginTest.cs (.../GrassCoverErosionInwardsPluginTest.cs) (revision 9448c9f34da890e184722d00c3f8b4f765a246b0) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/GrassCoverErosionInwardsPluginTest.cs (.../GrassCoverErosionInwardsPluginTest.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -57,7 +57,7 @@ PropertyInfo[] propertyInfos = plugin.GetPropertyInfos().ToArray(); // Assert - Assert.AreEqual(4, propertyInfos.Length); + Assert.AreEqual(5, propertyInfos.Length); PluginTestHelper.AssertPropertyInfoDefined( propertyInfos, @@ -78,6 +78,11 @@ propertyInfos, typeof(GrassCoverErosionInwardsOutput), typeof(GrassCoverErosionInwardsOutputProperties)); + + PluginTestHelper.AssertPropertyInfoDefined( + propertyInfos, + typeof(DikeProfilesContext), + typeof(DikeProfileCollectionProperties)); } } @@ -123,6 +128,21 @@ } [Test] + public void GetUpdateInfos_ReturnsSupportedUpdateInfos() + { + // Setup + using (var plugin = new GrassCoverErosionInwardsPlugin()) + { + // Call + UpdateInfo[] updateInfos = plugin.GetUpdateInfos().ToArray(); + + // Assert + Assert.AreEqual(1, updateInfos.Length); + Assert.IsTrue(updateInfos.Any(i => i.DataType == typeof(DikeProfilesContext))); + } + } + + [Test] public void GetImportInfos_ReturnsSupportedImportInfos() { // Setup @@ -132,8 +152,9 @@ ImportInfo[] importInfos = plugin.GetImportInfos().ToArray(); // Assert - Assert.AreEqual(1, importInfos.Length); + Assert.AreEqual(2, importInfos.Length); Assert.IsTrue(importInfos.Any(tni => tni.DataType == typeof(GrassCoverErosionInwardsCalculationGroupContext))); + Assert.IsTrue(importInfos.Any(tni => tni.DataType == typeof(DikeProfilesContext))); } } Fisheye: Tag d2b9feaf8aceaa9a96d0e6e19fd6fbbee8987ca6 refers to a dead (removed) revision in file `Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/ImportInfos/DikeProfilesContextImportInfoTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/PropertyInfos/DikeProfileCollectionPropertyInfoTest.cs =================================================================== diff -u --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/PropertyInfos/DikeProfileCollectionPropertyInfoTest.cs (revision 0) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/PropertyInfos/DikeProfileCollectionPropertyInfoTest.cs (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -0,0 +1,84 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System.Linq; +using Core.Common.Gui.Plugin; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.GrassCoverErosionInwards.Data; +using Ringtoets.GrassCoverErosionInwards.Forms.PresentationObjects; +using Ringtoets.GrassCoverErosionInwards.Forms.PropertyClasses; + +namespace Ringtoets.GrassCoverErosionInwards.Plugin.Test.PropertyInfos +{ + [TestFixture] + public class DikeProfileCollectionPropertyInfoTest + { + private GrassCoverErosionInwardsPlugin plugin; + private PropertyInfo info; + + [SetUp] + public void SetUp() + { + plugin = new GrassCoverErosionInwardsPlugin(); + info = plugin.GetPropertyInfos().First(tni => tni.PropertyObjectType == typeof(DikeProfileCollectionProperties)); + } + + [TearDown] + public void TearDown() + { + plugin.Dispose(); + } + + [Test] + public void Initialized_Always_ExpectedPropertiesSet() + { + // Assert + Assert.AreEqual(typeof(DikeProfilesContext), info.DataType); + Assert.AreEqual(typeof(DikeProfileCollectionProperties), info.PropertyObjectType); + } + + [Test] + public void CreateInstance_Always_NewPropertiesWithInputContextAsData() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + + var collection = new DikeProfileCollection(); + var context = new DikeProfilesContext(collection, failureMechanism, assessmentSection); + + // Call + var objectProperties = info.CreateInstance(context); + + // Assert + Assert.IsInstanceOf(objectProperties); + Assert.AreSame(collection, objectProperties.Data); + + mocks.VerifyAll(); + } + } +} Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/Ringtoets.GrassCoverErosionInwards.Plugin.Test.csproj =================================================================== diff -u -r9448c9f34da890e184722d00c3f8b4f765a246b0 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/Ringtoets.GrassCoverErosionInwards.Plugin.Test.csproj (.../Ringtoets.GrassCoverErosionInwards.Plugin.Test.csproj) (revision 9448c9f34da890e184722d00c3f8b4f765a246b0) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/Ringtoets.GrassCoverErosionInwards.Plugin.Test.csproj (.../Ringtoets.GrassCoverErosionInwards.Plugin.Test.csproj) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -63,11 +63,16 @@ Properties\GlobalAssembly.cs + + + + + @@ -78,6 +83,7 @@ + @@ -132,6 +138,10 @@ {4d840673-3812-4338-a352-84854e32b8a0} Ringtoets.Common.Forms + + {52ba7627-cbab-4209-be77-3b5f31378277} + Ringtoets.Common.IO + {d951d6da-fe83-4920-9fdb-63bf96480b54} Ringtoets.Common.Service Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/TreeNodeInfos/DikeProfilesContextTreeNodeInfoTest.cs =================================================================== diff -u -rc990bf404015584981f3ec1d22ecec12a7b037f3 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/TreeNodeInfos/DikeProfilesContextTreeNodeInfoTest.cs (.../DikeProfilesContextTreeNodeInfoTest.cs) (revision c990bf404015584981f3ec1d22ecec12a7b037f3) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/TreeNodeInfos/DikeProfilesContextTreeNodeInfoTest.cs (.../DikeProfilesContextTreeNodeInfoTest.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -131,13 +131,11 @@ var asssessmentSection = mocks.Stub(); mocks.ReplayAll(); - var failureMechanism = new GrassCoverErosionInwardsFailureMechanism + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + failureMechanism.DikeProfiles.AddRange(new[] { - DikeProfiles = - { - new TestDikeProfile() - } - }; + new TestDikeProfile() + }, "path"); // Precondition CollectionAssert.IsNotEmpty(failureMechanism.DikeProfiles); @@ -160,21 +158,19 @@ var assessmentSection = mocks.Stub(); mocks.ReplayAll(); - DikeProfile dikeProfile1 = new TestDikeProfile(); - DikeProfile dikeProfile2 = new TestDikeProfile(); - var failureMechanism = new GrassCoverErosionInwardsFailureMechanism + DikeProfile dikeProfile1 = new TestDikeProfile(string.Empty, "id1"); + DikeProfile dikeProfile2 = new TestDikeProfile(string.Empty, "id2"); + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + failureMechanism.DikeProfiles.AddRange(new[] { - DikeProfiles = - { - dikeProfile1, - dikeProfile2 - } - }; + dikeProfile1, + dikeProfile2 + }, "path"); var dikeProfilesContext = new DikeProfilesContext(failureMechanism.DikeProfiles, failureMechanism, assessmentSection); // Call - var children = info.ChildNodeObjects(dikeProfilesContext); + object[] children = info.ChildNodeObjects(dikeProfilesContext); // Assert Assert.AreEqual(2, children.Length); @@ -193,11 +189,12 @@ using (mocks.Ordered()) { menuBuilderMock.Expect(mb => mb.AddImportItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddUpdateItem()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); - menuBuilderMock.Expect(mb => mb.AddDeleteChildrenItem()).Return(menuBuilderMock); - menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddCollapseAllItem()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddExpandAllItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddPropertiesItem()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.Build()).Return(null); } Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/TreeNodeInfos/GrassCoverErosionInwardsCalculationContextTreeNodeInfoTest.cs =================================================================== diff -u -ra0e847cda510ac315d678871c6d30b8225ba7b55 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/TreeNodeInfos/GrassCoverErosionInwardsCalculationContextTreeNodeInfoTest.cs (.../GrassCoverErosionInwardsCalculationContextTreeNodeInfoTest.cs) (revision a0e847cda510ac315d678871c6d30b8225ba7b55) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/TreeNodeInfos/GrassCoverErosionInwardsCalculationContextTreeNodeInfoTest.cs (.../GrassCoverErosionInwardsCalculationContextTreeNodeInfoTest.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -20,10 +20,12 @@ // All rights reserved. using System; +using System.Drawing; using System.IO; using System.Linq; using System.Windows.Forms; using Core.Common.Base; +using Core.Common.Base.Data; using Core.Common.Base.Geometry; using Core.Common.Controls.TreeView; using Core.Common.Gui; @@ -54,9 +56,11 @@ [TestFixture] public class GrassCoverErosionInwardsCalculationContextTreeNodeInfoTest : NUnitFormTest { - private const int contextMenuValidateIndex = 3; - private const int contextMenuCalculateIndex = 4; - private const int contextMenuClearIndex = 6; + private const int contextMenuUpdateDikeProfileIndex = 3; + + private const int contextMenuValidateIndex = 4; + private const int contextMenuCalculateIndex = 5; + private const int contextMenuClearIndex = 7; private readonly string testDataPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, "HydraulicBoundaryDatabaseImporter"); private MockRepository mocks; @@ -105,7 +109,7 @@ mocks.ReplayAll(); // Call - var image = info.Image(null); + Image image = info.Image(null); // Assert TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.CalculationIcon, image); @@ -122,7 +126,7 @@ var calculationContext = new GrassCoverErosionInwardsCalculationContext(calculation, failureMechanism, assessmentSection); // Call - var children = info.ChildNodeObjects(calculationContext).ToArray(); + object[] children = info.ChildNodeObjects(calculationContext).ToArray(); // Assert Assert.AreEqual(3, children.Length); @@ -154,7 +158,7 @@ var calculationContext = new GrassCoverErosionInwardsCalculationContext(calculation, failureMechanism, assessmentSection); // Call - var children = info.ChildNodeObjects(calculationContext).ToArray(); + object[] children = info.ChildNodeObjects(calculationContext).ToArray(); // Assert Assert.AreEqual(3, children.Length); @@ -187,6 +191,7 @@ menuBuilderMock.Expect(mb => mb.AddRenameItem()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddDeleteItem()).Return(menuBuilderMock); @@ -243,28 +248,398 @@ using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, assessmentSection, treeViewControl)) { // Assert - Assert.AreEqual(13, menu.Items.Count); + Assert.AreEqual(14, menu.Items.Count); TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuValidateIndex, - RingtoetsCommonFormsResources.Validate, - RingtoetsCommonFormsResources.Validate_ToolTip, + "&Valideren", + "Valideer de invoer voor deze berekening.", RingtoetsCommonFormsResources.ValidateIcon); TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuCalculateIndex, - RingtoetsCommonFormsResources.Calculate, - RingtoetsCommonFormsResources.Calculate_ToolTip, + "Be&rekenen", + "Voer deze berekening uit.", RingtoetsCommonFormsResources.CalculateIcon); TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuClearIndex, - RingtoetsCommonFormsResources.Clear_output, - RingtoetsCommonFormsResources.ClearOutput_No_output_to_clear, + "&Wis uitvoer...", + "Deze berekening heeft geen uitvoer om te wissen.", RingtoetsCommonFormsResources.ClearIcon, false); } } } [Test] + public void ContextMenu_CalculationWithoutDikeProfile_ContextMenuItemUpdateDikeProfileDisabled() + { + // Setup + var assessmentSection = mocks.Stub(); + + var calculation = new GrassCoverErosionInwardsCalculation(); + var failureMechanism = new TestGrassCoverErosionInwardsFailureMechanism(); + var nodeData = new GrassCoverErosionInwardsCalculationContext(calculation, failureMechanism, assessmentSection); + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mocks.Stub(); + gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilder); + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, assessmentSection, treeViewControl)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(menu, + contextMenuUpdateDikeProfileIndex, + "&Bijwerken dijkprofiel", + "Er moet een dijkprofiel geselecteerd zijn.", + RingtoetsCommonFormsResources.UpdateItemIcon, + false); + } + } + } + + [Test] + public void ContextMenu_CalculationWithDikeProfile_ContextMenuItemUpdateDikeProfileEnabled() + { + // Setup + var assessmentSection = mocks.Stub(); + + var calculation = new GrassCoverErosionInwardsCalculation + { + InputParameters = + { + DikeProfile = new TestDikeProfile() + } + }; + var failureMechanism = new TestGrassCoverErosionInwardsFailureMechanism(); + var nodeData = new GrassCoverErosionInwardsCalculationContext(calculation, failureMechanism, assessmentSection); + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mocks.Stub(); + gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilder); + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, assessmentSection, treeViewControl)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(menu, + contextMenuUpdateDikeProfileIndex, + "&Bijwerken dijkprofiel", + "Berekening bijwerken met het dijkprofiel.", + RingtoetsCommonFormsResources.UpdateItemIcon); + } + } + } + + [Test] + public void GivenCalculationWithDikeProfileWithoutOutput_WhenDikeProfileUpdatedAndUpdateDikeProfileClicked_ThenNoInquiryAndCalculationUpdatedAndInputObserverNotified() + { + using (var treeViewControl = new TreeViewControl()) + { + // Given + var assessmentSection = mocks.Stub(); + var dikeProfile = new TestDikeProfile(); + var calculation = new GrassCoverErosionInwardsCalculation + { + InputParameters = + { + DikeProfile = dikeProfile + } + }; + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + var nodeData = new GrassCoverErosionInwardsCalculationContext(calculation, failureMechanism, assessmentSection); + + var inputObserver = mocks.StrictMock(); + inputObserver.Expect(obs => obs.UpdateObserver()); + calculation.InputParameters.Attach(inputObserver); + + var calculationObserver = mocks.StrictMock(); + calculation.Attach(calculationObserver); + + var mainWindow = mocks.Stub(); + var gui = mocks.Stub(); + gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Stub(g => g.MainWindow).Return(mainWindow); + mocks.ReplayAll(); + + plugin.Gui = gui; + + using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, assessmentSection, treeViewControl)) + { + // When + UpdateDikeProfile(dikeProfile); + menu.Items[contextMenuUpdateDikeProfileIndex].PerformClick(); + + // Then + Assert.IsFalse(calculation.HasOutput); + + GrassCoverErosionInwardsInput inputParameters = calculation.InputParameters; + Assert.AreSame(dikeProfile, inputParameters.DikeProfile); + Assert.AreEqual(dikeProfile.Orientation, inputParameters.Orientation); + Assert.AreEqual(dikeProfile.DikeHeight, inputParameters.DikeHeight); + + Assert.AreEqual(dikeProfile.HasBreakWater, inputParameters.UseBreakWater); + Assert.AreEqual(dikeProfile.BreakWater, inputParameters.BreakWater); + bool expectedUseForeShore = dikeProfile.ForeshoreGeometry.Count() > 1; + Assert.AreEqual(expectedUseForeShore, inputParameters.UseForeshore); + + // Note: observer assertions are verified in the Teardown() + } + } + } + + [Test] + public void GivenCalculationWithDikeProfileWithOutput_WhenDikeProfileHasChangesInDerivedInputAndUpdateDikeProfileClickedAndCancelled_ThenOutputNotRemovedAndObserversNotNotified() + { + using (var treeViewControl = new TreeViewControl()) + { + // Given + var assessmentSection = mocks.Stub(); + var dikeProfile = new TestDikeProfile(); + var calculation = new GrassCoverErosionInwardsCalculation + { + InputParameters = + { + DikeProfile = dikeProfile + }, + Output = new TestGrassCoverErosionInwardsOutput() + }; + + GrassCoverErosionInwardsInput calculationInput = calculation.InputParameters; + RoundedDouble expectedOrientation = calculationInput.Orientation; + RoundedDouble expectedDikeHeight = calculationInput.DikeHeight; + bool expectedUseBreakWater = calculationInput.UseBreakWater; + BreakWater expectedBreakWater = calculationInput.BreakWater; + bool expectedUseForeshore = calculationInput.UseForeshore; + + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + var nodeData = new GrassCoverErosionInwardsCalculationContext(calculation, failureMechanism, assessmentSection); + + var inputObserver = mocks.StrictMock(); + calculationInput.Attach(inputObserver); + + var calculationObserver = mocks.StrictMock(); + calculation.Attach(calculationObserver); + + var mainWindow = mocks.Stub(); + var gui = mocks.Stub(); + gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Stub(g => g.MainWindow).Return(mainWindow); + mocks.ReplayAll(); + + plugin.Gui = gui; + + string textBoxMessage = null; + DialogBoxHandler = (name, wnd) => + { + var helper = new MessageBoxTester(wnd); + textBoxMessage = helper.Text; + helper.ClickCancel(); + }; + + using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, assessmentSection, treeViewControl)) + { + // When + UpdateDikeProfile(dikeProfile); + menu.Items[contextMenuUpdateDikeProfileIndex].PerformClick(); + + // Then + Assert.IsTrue(calculation.HasOutput); + + Assert.AreSame(dikeProfile, calculationInput.DikeProfile); + Assert.AreEqual(expectedOrientation, calculationInput.Orientation); + Assert.AreEqual(expectedDikeHeight, calculationInput.DikeHeight); + + Assert.AreEqual(expectedUseBreakWater, calculationInput.UseBreakWater); + Assert.AreEqual(expectedBreakWater, calculationInput.BreakWater); + Assert.AreEqual(expectedUseForeshore, calculationInput.UseForeshore); + + string expectedMessage = "Wanneer het dijkprofiel wijzigt als gevolg van het bijwerken, " + + "zal het resultaat van deze berekening worden " + + $"verwijderd.{Environment.NewLine}{Environment.NewLine}Weet u zeker dat u wilt doorgaan?"; + Assert.AreEqual(expectedMessage, textBoxMessage); + + // Note: observer assertions are verified in the Teardown() + } + } + } + + [Test] + public void GivenCalculationWithDikeProfileWithOutput_WhenDikeProfileHasChangesInDerivedInputAndUpdateDikeProfileClickedAndContinued_ThenOutputRemovedAndObserversNotified() + { + using (var treeViewControl = new TreeViewControl()) + { + // Given + var assessmentSection = mocks.Stub(); + var dikeProfile = new TestDikeProfile(); + var calculation = new GrassCoverErosionInwardsCalculation + { + InputParameters = + { + DikeProfile = dikeProfile + }, + Output = new TestGrassCoverErosionInwardsOutput() + }; + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + var nodeData = new GrassCoverErosionInwardsCalculationContext(calculation, failureMechanism, assessmentSection); + + var inputObserver = mocks.StrictMock(); + inputObserver.Expect(obs => obs.UpdateObserver()); + calculation.InputParameters.Attach(inputObserver); + + var calculationObserver = mocks.StrictMock(); + calculationObserver.Expect(obs => obs.UpdateObserver()); + calculation.Attach(calculationObserver); + + var mainWindow = mocks.Stub(); + var gui = mocks.Stub(); + gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Stub(g => g.MainWindow).Return(mainWindow); + mocks.ReplayAll(); + + plugin.Gui = gui; + + string textBoxMessage = null; + DialogBoxHandler = (name, wnd) => + { + var helper = new MessageBoxTester(wnd); + textBoxMessage = helper.Text; + helper.ClickOk(); + }; + + using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, assessmentSection, treeViewControl)) + { + // When + UpdateDikeProfile(dikeProfile); + menu.Items[contextMenuUpdateDikeProfileIndex].PerformClick(); + + // Then + Assert.IsFalse(calculation.HasOutput); + + GrassCoverErosionInwardsInput inputParameters = calculation.InputParameters; + Assert.AreSame(dikeProfile, inputParameters.DikeProfile); + Assert.AreEqual(dikeProfile.Orientation, inputParameters.Orientation); + Assert.AreEqual(dikeProfile.DikeHeight, inputParameters.DikeHeight); + + Assert.AreEqual(dikeProfile.HasBreakWater, inputParameters.UseBreakWater); + Assert.AreEqual(dikeProfile.BreakWater, inputParameters.BreakWater); + bool expectedUseForeShore = dikeProfile.ForeshoreGeometry.Count() > 1; + Assert.AreEqual(expectedUseForeShore, inputParameters.UseForeshore); + + string expectedMessage = "Wanneer het dijkprofiel wijzigt als gevolg van het bijwerken, " + + "zal het resultaat van deze berekening worden " + + $"verwijderd.{Environment.NewLine}{Environment.NewLine}Weet u zeker dat u wilt doorgaan?"; + Assert.AreEqual(expectedMessage, textBoxMessage); + + // Note: observer assertions are verified in the Teardown() + } + } + } + + [Test] + public void GivenCalculationWithDikeProfileWithOutput_WhenDikeProfileHasNoChangeInDerivedInputAndUpdateDikeProfileClicked_ThenOutputNotRemovedAndObserversNotNotified() + { + using (var treeViewControl = new TreeViewControl()) + { + // Given + var assessmentSection = mocks.Stub(); + + var dikeProfile = new DikeProfile(new Point2D(0, 0), + new[] + { + new RoughnessPoint(new Point2D(1.1, 2.2), 3), + new RoughnessPoint(new Point2D(3.3, 4.4), 5) + }, + new[] + { + new Point2D(1.1, 2.2), + new Point2D(3.3, 4.4) + }, + new BreakWater(BreakWaterType.Caisson, 10), + new DikeProfile.ConstructionProperties + { + Id = "ID" + }); + const double orientation = 10; + const double dikeHeight = 10; + const bool useBreakWater = true; + const bool useForeshore = true; + var calculation = new GrassCoverErosionInwardsCalculation + { + InputParameters = + { + DikeProfile = dikeProfile, + DikeHeight = (RoundedDouble) dikeHeight, + Orientation = (RoundedDouble) orientation, + UseForeshore = useForeshore, + UseBreakWater = useBreakWater + }, + Output = new TestGrassCoverErosionInwardsOutput() + }; + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + var nodeData = new GrassCoverErosionInwardsCalculationContext(calculation, failureMechanism, assessmentSection); + + var inputObserver = mocks.StrictMock(); + calculation.InputParameters.Attach(inputObserver); + + var calculationObserver = mocks.StrictMock(); + calculation.Attach(calculationObserver); + + var mainWindow = mocks.Stub(); + var gui = mocks.Stub(); + gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Stub(g => g.MainWindow).Return(mainWindow); + mocks.ReplayAll(); + + plugin.Gui = gui; + + string textBoxMessage = null; + DialogBoxHandler = (name, wnd) => + { + var helper = new MessageBoxTester(wnd); + textBoxMessage = helper.Text; + helper.ClickOk(); + }; + + using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, assessmentSection, treeViewControl)) + { + // When + UpdateDikeProfile(dikeProfile); + menu.Items[contextMenuUpdateDikeProfileIndex].PerformClick(); + + // Then + Assert.IsTrue(calculation.HasOutput); + + GrassCoverErosionInwardsInput inputParameters = calculation.InputParameters; + Assert.AreSame(dikeProfile, inputParameters.DikeProfile); + Assert.AreEqual(dikeProfile.Orientation, inputParameters.Orientation); + Assert.AreEqual(dikeProfile.DikeHeight, inputParameters.DikeHeight); + + Assert.AreEqual(dikeProfile.HasBreakWater, inputParameters.UseBreakWater); + Assert.AreEqual(dikeProfile.BreakWater, inputParameters.BreakWater); + bool expectedUseForeShore = dikeProfile.ForeshoreGeometry.Count() > 1; + Assert.AreEqual(expectedUseForeShore, inputParameters.UseForeshore); + + string expectedMessage = "Wanneer het dijkprofiel wijzigt als gevolg van het bijwerken, " + + "zal het resultaat van deze berekening worden " + + $"verwijderd.{Environment.NewLine}{Environment.NewLine}Weet u zeker dat u wilt doorgaan?"; + Assert.AreEqual(expectedMessage, textBoxMessage); + + // Note: observer assertions are verified in the Teardown() + } + } + } + + [Test] public void ContextMenuStrip_NoHydraulicBoundaryDatabase_ContextMenuItemPerformCalculationDisabledAndTooltipSet() { // Setup @@ -560,7 +935,10 @@ { FilePath = validFilePath, Version = "random", - Locations = { hydraulicBoundaryLocation } + Locations = + { + hydraulicBoundaryLocation + } }; assessmentSection.Stub(a => a.FailureMechanismContribution).Return(new FailureMechanismContribution(Enumerable.Empty(), 1, 1)); @@ -605,7 +983,7 @@ // Then TestHelper.AssertLogMessages(action, messages => { - var msgs = messages.ToArray(); + string[] msgs = messages.ToArray(); Assert.AreEqual(6, msgs.Length); StringAssert.StartsWith(string.Format("Validatie van '{0}' gestart om: ", calculation.Name), msgs[0]); StringAssert.StartsWith(string.Format("Validatie van '{0}' beëindigd om: ", calculation.Name), msgs[1]); @@ -637,7 +1015,10 @@ { FilePath = validFilePath, Version = "random", - Locations = { hydraulicBoundaryLocation } + Locations = + { + hydraulicBoundaryLocation + } }; var calculation = new GrassCoverErosionInwardsCalculation @@ -669,7 +1050,7 @@ // Then TestHelper.AssertLogMessages(action, messages => { - var msgs = messages.ToArray(); + string[] msgs = messages.ToArray(); StringAssert.StartsWith(string.Format("Validatie van '{0}' gestart om: ", calculation.Name), msgs[0]); StringAssert.StartsWith(string.Format("Validatie van '{0}' beëindigd om: ", calculation.Name), msgs[1]); }); @@ -728,7 +1109,10 @@ new Point2D(1.0, 1.0) })); DikeProfile dikeProfile = new TestDikeProfile(new Point2D(0.5, 0.5)); - failureMechanism.DikeProfiles.Add(dikeProfile); + failureMechanism.DikeProfiles.AddRange(new[] + { + dikeProfile + }, "path"); var elementToBeRemoved = new GrassCoverErosionInwardsCalculation { @@ -738,7 +1122,7 @@ } }; - var sectionResult = failureMechanism.SectionResults.First(); + GrassCoverErosionInwardsFailureMechanismSectionResult sectionResult = failureMechanism.SectionResults.First(); sectionResult.Calculation = elementToBeRemoved; var calculationContext = new GrassCoverErosionInwardsCalculationContext(elementToBeRemoved, @@ -799,6 +1183,26 @@ Assert.IsNull(result.Calculation); } + private static void UpdateDikeProfile(DikeProfile dikeProfile) + { + var dikeProfileToUpdateFrom = new DikeProfile(dikeProfile.WorldReferencePoint, + dikeProfile.DikeGeometry, + new[] + { + new Point2D(1.1, 2.2), + new Point2D(3.3, 4.4) + }, + new BreakWater(BreakWaterType.Caisson, 10), + new DikeProfile.ConstructionProperties + { + Id = dikeProfile.Id, + DikeHeight = 10, + Orientation = 10 + }); + + dikeProfile.CopyProperties(dikeProfileToUpdateFrom); + } + public override void TearDown() { plugin.Dispose(); Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/TreeNodeInfos/GrassCoverErosionInwardsCalculationGroupContextTreeNodeInfoTest.cs =================================================================== diff -u -ra0e847cda510ac315d678871c6d30b8225ba7b55 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/TreeNodeInfos/GrassCoverErosionInwardsCalculationGroupContextTreeNodeInfoTest.cs (.../GrassCoverErosionInwardsCalculationGroupContextTreeNodeInfoTest.cs) (revision a0e847cda510ac315d678871c6d30b8225ba7b55) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/TreeNodeInfos/GrassCoverErosionInwardsCalculationGroupContextTreeNodeInfoTest.cs (.../GrassCoverErosionInwardsCalculationGroupContextTreeNodeInfoTest.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -19,10 +19,13 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System; +using System.Collections.Generic; using System.IO; using System.Linq; using System.Windows.Forms; using Core.Common.Base; +using Core.Common.Base.Data; using Core.Common.Base.Geometry; using Core.Common.Controls.DataGrid; using Core.Common.Controls.TreeView; @@ -59,15 +62,19 @@ private const int contextMenuGenerateCalculationsIndexRootGroup = 3; private const int contextMenuAddCalculationGroupIndexRootGroup = 5; private const int contextMenuAddCalculationIndexRootGroup = 6; - private const int contextMenuValidateAllIndexRootGroup = 8; - private const int contextMenuCalculateAllIndexRootGroup = 9; - private const int contextMenuClearAllIndexRootGroup = 11; + private const int contextMenuUpdateDikeProfileAllIndexRootGroup = 8; + private const int contextMenuValidateAllIndexRootGroup = 9; + private const int contextMenuCalculateAllIndexRootGroup = 10; + private const int contextMenuClearAllIndexRootGroup = 12; private const int contextMenuAddCalculationGroupIndexNestedGroup = 3; private const int contextMenuAddCalculationIndexNestedGroup = 4; - private const int contextMenuValidateAllIndexNestedGroup = 7; - private const int contextMenuCalculateAllIndexNestedGroup = 8; - private const int contextMenuClearAllIndexNestedGroup = 10; + private const int contextMenuUpdateDikeProfileAllIndexNestedGroup = 7; + private const int contextMenuValidateAllIndexNestedGroup = 8; + private const int contextMenuCalculateAllIndexNestedGroup = 9; + private const int contextMenuClearAllIndexNestedGroup = 11; + + private const string dikeProfileCollectionPath = "some/arbitrary/path"; private readonly string testDataPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, "HydraulicBoundaryDatabaseImporter"); private IGui gui; @@ -129,7 +136,7 @@ assessmentSection); // Call - var children = info.ChildNodeObjects(groupContext); + object[] children = info.ChildNodeObjects(groupContext); // Assert CollectionAssert.IsEmpty(children); @@ -157,7 +164,7 @@ assessmentSection); // Call - var children = info.ChildNodeObjects(groupContext).ToArray(); + object[] children = info.ChildNodeObjects(groupContext).ToArray(); // Assert Assert.AreEqual(group.Children.Count, children.Length); @@ -195,6 +202,7 @@ menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddDeleteChildrenItem()).Return(menuBuilderMock); @@ -243,29 +251,35 @@ using (ContextMenuStrip menu = info.ContextMenuStrip(groupContext, null, treeViewControl)) { // Assert - Assert.AreEqual(18, menu.Items.Count); + Assert.AreEqual(19, menu.Items.Count); TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuAddCalculationGroupIndexRootGroup, - RingtoetsCommonFormsResources.CalculationGroup_Add_CalculationGroup, - RingtoetsCommonFormsResources.CalculationGroup_Add_CalculationGroup_Tooltip, + "&Map toevoegen", + "Voeg een nieuwe berekeningsmap toe aan deze berekeningsmap.", RingtoetsCommonFormsResources.AddFolderIcon); TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuAddCalculationIndexRootGroup, - RingtoetsCommonFormsResources.CalculationGroup_Add_Calculation, - RingtoetsCommonFormsResources.CalculationGroup_Add_Calculation_Tooltip, + "Berekening &toevoegen", + "Voeg een nieuwe berekening toe aan deze berekeningsmap.", RingtoetsCommonFormsResources.FailureMechanismIcon); + TestHelper.AssertContextMenuStripContainsItem(menu, + contextMenuUpdateDikeProfileAllIndexRootGroup, + "&Bijwerken dijkprofielen", + "Er zijn geen berekeningen om bij te werken.", + RingtoetsCommonFormsResources.UpdateItemIcon, + false); TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuValidateAllIndexRootGroup, - RingtoetsCommonFormsResources.Validate_all, - RingtoetsCommonFormsResources.ValidateAll_No_calculations_to_validate, + "Alles &valideren", + "Er zijn geen berekeningen om te valideren.", RingtoetsCommonFormsResources.ValidateAllIcon, false); TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuCalculateAllIndexRootGroup, - RingtoetsCommonFormsResources.Calculate_all, - RingtoetsCommonFormsResources.CalculationGroup_CalculateAll_No_calculations_to_run, + "Alles be&rekenen", + "Er zijn geen berekeningen om uit te voeren.", RingtoetsCommonFormsResources.CalculateAllIcon, false); TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuClearAllIndexRootGroup, - RingtoetsCommonFormsResources.Clear_all_output, - RingtoetsCommonFormsResources.CalculationGroup_ClearOutput_No_calculation_with_output_to_clear, + "&Wis alle uitvoer...", + "Er zijn geen berekeningen met uitvoer om te wissen.", RingtoetsCommonFormsResources.ClearIcon, false); } @@ -300,6 +314,7 @@ menuBuilderMock.Expect(mb => mb.AddRenameItem()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddDeleteItem()).Return(menuBuilderMock); @@ -347,30 +362,36 @@ using (ContextMenuStrip menu = info.ContextMenuStrip(groupContext, parentGroupContext, treeViewControl)) { // Assert - Assert.AreEqual(17, menu.Items.Count); + Assert.AreEqual(18, menu.Items.Count); TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuAddCalculationGroupIndexNestedGroup, - RingtoetsCommonFormsResources.CalculationGroup_Add_CalculationGroup, - RingtoetsCommonFormsResources.CalculationGroup_Add_CalculationGroup_Tooltip, + "&Map toevoegen", + "Voeg een nieuwe berekeningsmap toe aan deze berekeningsmap.", RingtoetsCommonFormsResources.AddFolderIcon); TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuAddCalculationIndexNestedGroup, - RingtoetsCommonFormsResources.CalculationGroup_Add_Calculation, - RingtoetsCommonFormsResources.CalculationGroup_Add_Calculation_Tooltip, + "Berekening &toevoegen", + "Voeg een nieuwe berekening toe aan deze berekeningsmap.", RingtoetsCommonFormsResources.FailureMechanismIcon); + TestHelper.AssertContextMenuStripContainsItem(menu, + contextMenuUpdateDikeProfileAllIndexNestedGroup, + "&Bijwerken dijkprofielen", + "Er zijn geen berekeningen om bij te werken.", + RingtoetsCommonFormsResources.UpdateItemIcon, + false); TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuValidateAllIndexNestedGroup, - RingtoetsCommonFormsResources.Validate_all, - RingtoetsCommonFormsResources.ValidateAll_No_calculations_to_validate, + "Alles &valideren", + "Er zijn geen berekeningen om te valideren.", RingtoetsCommonFormsResources.ValidateAllIcon, false); TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuCalculateAllIndexNestedGroup, - RingtoetsCommonFormsResources.Calculate_all, - RingtoetsCommonFormsResources.CalculationGroup_CalculateAll_No_calculations_to_run, + "Alles be&rekenen", + "Er zijn geen berekeningen om uit te voeren.", RingtoetsCommonFormsResources.CalculateAllIcon, false); TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuClearAllIndexNestedGroup, - RingtoetsCommonFormsResources.Clear_all_output, - RingtoetsCommonFormsResources.CalculationGroup_ClearOutput_No_calculation_with_output_to_clear, + "&Wis alle uitvoer...", + "Er zijn geen berekeningen met uitvoer om te wissen.", RingtoetsCommonFormsResources.ClearIcon, false); } @@ -430,6 +451,561 @@ } [Test] + public void ContextMenuStrip_FailureMechanismWithoutCalculations_ContextMenuItemUpdateDikeProfileAllDisabledAndToolTipSet() + { + // Setup + var group = new CalculationGroup(); + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + + var assessmentSection = mocks.Stub(); + var nodeData = new GrassCoverErosionInwardsCalculationGroupContext(group, + failureMechanism, + assessmentSection); + + using (var treeViewControl = new TreeViewControl()) + { + gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuUpdateDikeProfileAllIndexRootGroup, + "&Bijwerken dijkprofielen", + "Er zijn geen berekeningen om bij te werken.", + RingtoetsCommonFormsResources.UpdateItemIcon, + false); + } + } + } + + [Test] + public void ContextMenuStrip_FailureMechanismWithCalculationsWithoutDikeProfile_ContextMenuItemUpdateDikeProfileAllDisabledAndToolTipSet() + { + // Setup + var group = new CalculationGroup + { + Children = + { + new GrassCoverErosionInwardsCalculation() + } + }; + + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + var assessmentSection = mocks.Stub(); + var nodeData = new GrassCoverErosionInwardsCalculationGroupContext(group, + failureMechanism, + assessmentSection); + + using (var treeViewControl = new TreeViewControl()) + { + gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuUpdateDikeProfileAllIndexRootGroup, + "&Bijwerken dijkprofielen", + "Er zijn geen berekeningen met een dijkprofiel.", + RingtoetsCommonFormsResources.UpdateItemIcon, + false); + } + } + } + + [Test] + public void ContextMenuStrip_FailureMechanismWithCalculationWithDikeProfile_ContextMenuItemUpdateDikeProfileAllEnabledAndToolTipSet() + { + // Setup + var group = new CalculationGroup + { + Children = + { + new GrassCoverErosionInwardsCalculation + { + InputParameters = + { + DikeProfile = new TestDikeProfile() + } + } + } + }; + + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + var assessmentSection = mocks.Stub(); + var nodeData = new GrassCoverErosionInwardsCalculationGroupContext(group, + failureMechanism, + assessmentSection); + + using (var treeViewControl = new TreeViewControl()) + { + gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuUpdateDikeProfileAllIndexRootGroup, + "&Bijwerken dijkprofielen", + "Alle berekeningen bijwerken met het dijkprofiel.", + RingtoetsCommonFormsResources.UpdateItemIcon); + } + } + } + + [Test] + public void GivenCalculationsWithDikeProfileWithoutOutput_WhenDikeProfileUpdatedAndUpdateDikeProfileClicked_ThenNoInquiryAndCalculationUpdatedAndInputObserverNotified() + { + using (var treeViewControl = new TreeViewControl()) + { + // Given + var calculation1InputObserver = mocks.StrictMock(); + calculation1InputObserver.Expect(obs => obs.UpdateObserver()); + var calculation2InputObserver = mocks.StrictMock(); + calculation2InputObserver.Expect(obs => obs.UpdateObserver()); + + var calculation1Observer = mocks.StrictMock(); + var calculation2Observer = mocks.StrictMock(); + + var dikeProfile = new TestDikeProfile(); + var calculation1 = new GrassCoverErosionInwardsCalculation + { + InputParameters = + { + DikeProfile = dikeProfile + } + }; + calculation1.Attach(calculation1Observer); + calculation1.InputParameters.Attach(calculation1InputObserver); + + var calculation2 = new GrassCoverErosionInwardsCalculation + { + InputParameters = + { + DikeProfile = dikeProfile + } + }; + calculation2.Attach(calculation2Observer); + calculation2.InputParameters.Attach(calculation2InputObserver); + + var childGroup = new CalculationGroup(); + childGroup.Children.Add(calculation1); + + var emptyChildGroup = new CalculationGroup(); + var group = new CalculationGroup(); + group.Children.Add(childGroup); + group.Children.Add(emptyChildGroup); + group.Children.Add(calculation2); + + var assessmentSection = mocks.Stub(); + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + var nodeData = new GrassCoverErosionInwardsCalculationGroupContext(group, + failureMechanism, + assessmentSection); + + var mainWindow = mocks.Stub(); + gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Stub(g => g.MainWindow).Return(mainWindow); + mocks.ReplayAll(); + + plugin.Gui = gui; + + using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // When + UpdateDikeProfile(dikeProfile); + menu.Items[contextMenuUpdateDikeProfileAllIndexRootGroup].PerformClick(); + + // Then + Assert.IsFalse(calculation1.HasOutput); + GrassCoverErosionInwardsInput inputParameters1 = calculation1.InputParameters; + Assert.AreSame(dikeProfile, inputParameters1.DikeProfile); + Assert.AreEqual(dikeProfile.Orientation, inputParameters1.Orientation); + Assert.AreEqual(dikeProfile.DikeHeight, inputParameters1.DikeHeight); + Assert.AreEqual(dikeProfile.HasBreakWater, inputParameters1.UseBreakWater); + Assert.AreEqual(dikeProfile.BreakWater, inputParameters1.BreakWater); + bool expectedUseForeshore1 = dikeProfile.ForeshoreGeometry.Count() > 1; + Assert.AreEqual(expectedUseForeshore1, inputParameters1.UseForeshore); + + Assert.IsFalse(calculation2.HasOutput); + GrassCoverErosionInwardsInput inputParameters2 = calculation2.InputParameters; + Assert.AreSame(dikeProfile, inputParameters2.DikeProfile); + Assert.AreEqual(dikeProfile.Orientation, inputParameters2.Orientation); + Assert.AreEqual(dikeProfile.DikeHeight, inputParameters2.DikeHeight); + Assert.AreEqual(dikeProfile.HasBreakWater, inputParameters2.UseBreakWater); + Assert.AreEqual(dikeProfile.BreakWater, inputParameters2.BreakWater); + bool expectedUseForeshore2 = dikeProfile.ForeshoreGeometry.Count() > 1; + Assert.AreEqual(expectedUseForeshore2, inputParameters2.UseForeshore); + + // Note: observer assertions are verified in the Teardown() + } + } + } + + [Test] + public void GivenCalculationWithDikeProfileWithOutput_WhenDikeProfileHasChangesInDerivedInputAndUpdateDikeProfileClickedAndCancelled_ThenOutputNotRemovedAndObserversNotNotified() + { + // Given + using (var treeViewControl = new TreeViewControl()) + { + var calculation1InputObserver = mocks.StrictMock(); + var calculation2InputObserver = mocks.StrictMock(); + + var calculation1Observer = mocks.StrictMock(); + var calculation2Observer = mocks.StrictMock(); + + var dikeProfile = new TestDikeProfile(); + var calculation1 = new GrassCoverErosionInwardsCalculation + { + InputParameters = + { + DikeProfile = dikeProfile + }, + Output = new TestGrassCoverErosionInwardsOutput() + }; + calculation1.Attach(calculation1Observer); + calculation1.InputParameters.Attach(calculation1InputObserver); + GrassCoverErosionInwardsInput calculationInput1 = calculation1.InputParameters; + RoundedDouble expectedOrientation1 = calculationInput1.Orientation; + RoundedDouble expectedDikeHeight1 = calculationInput1.DikeHeight; + bool expectedUseBreakWater1 = calculationInput1.UseBreakWater; + BreakWater expectedBreakWater1 = calculationInput1.BreakWater; + bool expectedUseForeshore1 = calculationInput1.UseForeshore; + + var calculation2 = new GrassCoverErosionInwardsCalculation + { + InputParameters = + { + DikeProfile = dikeProfile + }, + Output = new TestGrassCoverErosionInwardsOutput() + }; + calculation2.Attach(calculation2Observer); + calculation2.InputParameters.Attach(calculation2InputObserver); + GrassCoverErosionInwardsInput calculationInput2 = calculation2.InputParameters; + RoundedDouble expectedOrientation2 = calculationInput2.Orientation; + RoundedDouble expectedDikeHeight2 = calculationInput2.DikeHeight; + bool expectedUseBreakWater2 = calculationInput2.UseBreakWater; + BreakWater expectedBreakWater2 = calculationInput2.BreakWater; + bool expectedUseForeshore2 = calculationInput2.UseForeshore; + + var childGroup = new CalculationGroup(); + childGroup.Children.Add(calculation1); + + var emptyChildGroup = new CalculationGroup(); + var group = new CalculationGroup(); + group.Children.Add(childGroup); + group.Children.Add(emptyChildGroup); + group.Children.Add(calculation2); + + var assessmentSection = mocks.Stub(); + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + var nodeData = new GrassCoverErosionInwardsCalculationGroupContext(group, + failureMechanism, + assessmentSection); + + var mainWindow = mocks.Stub(); + gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Stub(g => g.MainWindow).Return(mainWindow); + mocks.ReplayAll(); + + plugin.Gui = gui; + + string textBoxMessage = null; + DialogBoxHandler = (name, wnd) => + { + var helper = new MessageBoxTester(wnd); + textBoxMessage = helper.Text; + helper.ClickCancel(); + }; + + using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // When + UpdateDikeProfile(dikeProfile); + menu.Items[contextMenuUpdateDikeProfileAllIndexRootGroup].PerformClick(); + + // Then + Assert.IsTrue(calculation1.HasOutput); + GrassCoverErosionInwardsInput inputParameters1 = calculation1.InputParameters; + Assert.AreSame(dikeProfile, inputParameters1.DikeProfile); + Assert.AreEqual(expectedOrientation1, inputParameters1.Orientation); + Assert.AreEqual(expectedDikeHeight1, inputParameters1.DikeHeight); + Assert.AreEqual(expectedUseBreakWater1, inputParameters1.UseBreakWater); + Assert.AreEqual(expectedBreakWater1, inputParameters1.BreakWater); + Assert.AreEqual(expectedUseForeshore1, inputParameters1.UseForeshore); + + Assert.IsTrue(calculation2.HasOutput); + GrassCoverErosionInwardsInput inputParameters2 = calculation2.InputParameters; + Assert.AreSame(dikeProfile, inputParameters2.DikeProfile); + Assert.AreEqual(expectedOrientation2, inputParameters2.Orientation); + Assert.AreEqual(expectedDikeHeight2, inputParameters2.DikeHeight); + Assert.AreEqual(expectedUseBreakWater2, inputParameters2.UseBreakWater); + Assert.AreEqual(expectedBreakWater2, inputParameters2.BreakWater); + Assert.AreEqual(expectedUseForeshore2, inputParameters2.UseForeshore); + + string expectedMessage = "Wanneer de dijkprofielen wijzigen als gevolg van het bijwerken, " + + "zullen de resultaten van berekeningen die deze dijkprofielen gebruiken, worden " + + $"verwijderd.{Environment.NewLine}{Environment.NewLine}Weet u zeker dat u wilt doorgaan?"; + Assert.AreEqual(expectedMessage, textBoxMessage); + + // Note: observer assertions are verified in the Teardown() + } + } + } + + [Test] + public void GivenCalculationWithDikeProfileWithOutput_WhenDikeProfileHasChangesInDerivedInputAndUpdateDikeProfileClickedAndContinued_ThenOutputRemovedAndObserversNotified() + { + using (var treeViewControl = new TreeViewControl()) + { + // Given + var calculation1InputObserver = mocks.StrictMock(); + calculation1InputObserver.Expect(obs => obs.UpdateObserver()); + var calculation2InputObserver = mocks.StrictMock(); + calculation2InputObserver.Expect(obs => obs.UpdateObserver()); + + var calculation1Observer = mocks.StrictMock(); + calculation1Observer.Expect(obs => obs.UpdateObserver()); + var calculation2Observer = mocks.StrictMock(); + calculation2Observer.Expect(obs => obs.UpdateObserver()); + + var dikeProfile = new TestDikeProfile(); + var calculation1 = new GrassCoverErosionInwardsCalculation + { + InputParameters = + { + DikeProfile = dikeProfile + }, + Output = new TestGrassCoverErosionInwardsOutput() + }; + calculation1.Attach(calculation1Observer); + calculation1.InputParameters.Attach(calculation1InputObserver); + + var calculation2 = new GrassCoverErosionInwardsCalculation + { + InputParameters = + { + DikeProfile = dikeProfile + }, + Output = new TestGrassCoverErosionInwardsOutput() + }; + calculation2.Attach(calculation2Observer); + calculation2.InputParameters.Attach(calculation2InputObserver); + + var childGroup = new CalculationGroup(); + childGroup.Children.Add(calculation1); + + var emptyChildGroup = new CalculationGroup(); + var group = new CalculationGroup(); + group.Children.Add(childGroup); + group.Children.Add(emptyChildGroup); + group.Children.Add(calculation2); + + var assessmentSection = mocks.Stub(); + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + var nodeData = new GrassCoverErosionInwardsCalculationGroupContext(group, + failureMechanism, + assessmentSection); + + var mainWindow = mocks.Stub(); + gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Stub(g => g.MainWindow).Return(mainWindow); + mocks.ReplayAll(); + + plugin.Gui = gui; + + string textBoxMessage = null; + DialogBoxHandler = (name, wnd) => + { + var helper = new MessageBoxTester(wnd); + textBoxMessage = helper.Text; + helper.ClickOk(); + }; + + using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // When + UpdateDikeProfile(dikeProfile); + menu.Items[contextMenuUpdateDikeProfileAllIndexRootGroup].PerformClick(); + + // Then + Assert.IsFalse(calculation1.HasOutput); + GrassCoverErosionInwardsInput inputParameters1 = calculation1.InputParameters; + Assert.AreSame(dikeProfile, inputParameters1.DikeProfile); + Assert.AreEqual(dikeProfile.Orientation, inputParameters1.Orientation); + Assert.AreEqual(dikeProfile.DikeHeight, inputParameters1.DikeHeight); + Assert.AreEqual(dikeProfile.HasBreakWater, inputParameters1.UseBreakWater); + Assert.AreEqual(dikeProfile.BreakWater, inputParameters1.BreakWater); + bool expectedUseForeshore1 = dikeProfile.ForeshoreGeometry.Count() > 1; + Assert.AreEqual(expectedUseForeshore1, inputParameters1.UseForeshore); + + Assert.IsFalse(calculation2.HasOutput); + GrassCoverErosionInwardsInput inputParameters2 = calculation2.InputParameters; + Assert.AreSame(dikeProfile, inputParameters2.DikeProfile); + Assert.AreEqual(dikeProfile.Orientation, inputParameters2.Orientation); + Assert.AreEqual(dikeProfile.DikeHeight, inputParameters2.DikeHeight); + Assert.AreEqual(dikeProfile.HasBreakWater, inputParameters2.UseBreakWater); + Assert.AreEqual(dikeProfile.BreakWater, inputParameters2.BreakWater); + bool expectedUseForeshore2 = dikeProfile.ForeshoreGeometry.Count() > 1; + Assert.AreEqual(expectedUseForeshore2, inputParameters2.UseForeshore); + + string expectedMessage = "Wanneer de dijkprofielen wijzigen als gevolg van het bijwerken, " + + "zullen de resultaten van berekeningen die deze dijkprofielen gebruiken, worden " + + $"verwijderd.{Environment.NewLine}{Environment.NewLine}Weet u zeker dat u wilt doorgaan?"; + Assert.AreEqual(expectedMessage, textBoxMessage); + + // Note: observer assertions are verified in the Teardown() + } + } + } + + [Test] + public void GivenCalculationWithDikeProfileWithOutput_WhenDikeProfileHasNoChangeInDerivedInputAndUpdateDikeProfileClicked_ThenOutputNotRemovedAndObserversNotNotified() + { + using (var treeViewControl = new TreeViewControl()) + { + // Given + var calculation1InputObserver = mocks.StrictMock(); + var calculation2InputObserver = mocks.StrictMock(); + + var calculation1Observer = mocks.StrictMock(); + var calculation2Observer = mocks.StrictMock(); + + var dikeProfile = new DikeProfile(new Point2D(0, 0), + new[] + { + new RoughnessPoint(new Point2D(1.1, 2.2), 3), + new RoughnessPoint(new Point2D(3.3, 4.4), 5) + }, + new[] + { + new Point2D(1.1, 2.2), + new Point2D(3.3, 4.4) + }, + new BreakWater(BreakWaterType.Caisson, 10), + new DikeProfile.ConstructionProperties + { + Id = "ID" + }); + const double orientation = 10; + const double dikeHeight = 10; + const bool useBreakWater = true; + const bool useForeshore = true; + var calculation1 = new GrassCoverErosionInwardsCalculation + { + InputParameters = + { + DikeProfile = dikeProfile, + DikeHeight = (RoundedDouble) dikeHeight, + Orientation = (RoundedDouble) orientation, + UseForeshore = useForeshore, + UseBreakWater = useBreakWater + }, + Output = new TestGrassCoverErosionInwardsOutput() + }; + calculation1.Attach(calculation1Observer); + calculation1.InputParameters.Attach(calculation1InputObserver); + + var calculation2 = new GrassCoverErosionInwardsCalculation + { + InputParameters = + { + DikeProfile = dikeProfile, + DikeHeight = (RoundedDouble) dikeHeight, + Orientation = (RoundedDouble) orientation, + UseForeshore = useForeshore, + UseBreakWater = useBreakWater + }, + Output = new TestGrassCoverErosionInwardsOutput() + }; + calculation2.Attach(calculation2Observer); + calculation2.InputParameters.Attach(calculation2InputObserver); + + var childGroup = new CalculationGroup(); + childGroup.Children.Add(calculation1); + + var emptyChildGroup = new CalculationGroup(); + var group = new CalculationGroup(); + var parentGroup = new CalculationGroup(); + + group.Children.Add(childGroup); + group.Children.Add(emptyChildGroup); + group.Children.Add(calculation2); + + var assessmentSection = mocks.Stub(); + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + var nodeData = new GrassCoverErosionInwardsCalculationGroupContext(group, + failureMechanism, + assessmentSection); + var parentNodeData = new GrassCoverErosionInwardsCalculationGroupContext(parentGroup, + failureMechanism, + assessmentSection); + + var mainWindow = mocks.Stub(); + gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Stub(g => g.MainWindow).Return(mainWindow); + gui.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + string textBoxMessage = null; + DialogBoxHandler = (name, wnd) => + { + var helper = new MessageBoxTester(wnd); + textBoxMessage = helper.Text; + helper.ClickOk(); + }; + + using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, parentNodeData, treeViewControl)) + { + // When + UpdateDikeProfile(dikeProfile); + menu.Items[contextMenuUpdateDikeProfileAllIndexNestedGroup].PerformClick(); + + // Then + Assert.IsTrue(calculation1.HasOutput); + GrassCoverErosionInwardsInput inputParameters1 = calculation1.InputParameters; + Assert.AreSame(dikeProfile, inputParameters1.DikeProfile); + Assert.AreEqual(dikeProfile.Orientation, inputParameters1.Orientation); + Assert.AreEqual(dikeProfile.DikeHeight, inputParameters1.DikeHeight); + Assert.AreEqual(dikeProfile.HasBreakWater, inputParameters1.UseBreakWater); + Assert.AreEqual(dikeProfile.BreakWater, inputParameters1.BreakWater); + bool expectedUseForeshore1 = dikeProfile.ForeshoreGeometry.Count() > 1; + Assert.AreEqual(expectedUseForeshore1, inputParameters1.UseForeshore); + + Assert.IsTrue(calculation2.HasOutput); + GrassCoverErosionInwardsInput inputParameters2 = calculation2.InputParameters; + Assert.AreSame(dikeProfile, inputParameters2.DikeProfile); + Assert.AreEqual(dikeProfile.Orientation, inputParameters2.Orientation); + Assert.AreEqual(dikeProfile.DikeHeight, inputParameters2.DikeHeight); + Assert.AreEqual(dikeProfile.HasBreakWater, inputParameters2.UseBreakWater); + Assert.AreEqual(dikeProfile.BreakWater, inputParameters2.BreakWater); + bool expectedUseForeshore2 = dikeProfile.ForeshoreGeometry.Count() > 1; + Assert.AreEqual(expectedUseForeshore2, inputParameters2.UseForeshore); + + string expectedMessage = "Wanneer de dijkprofielen wijzigen als gevolg van het bijwerken, " + + "zullen de resultaten van berekeningen die deze dijkprofielen gebruiken, worden " + + $"verwijderd.{Environment.NewLine}{Environment.NewLine}Weet u zeker dat u wilt doorgaan?"; + Assert.AreEqual(expectedMessage, textBoxMessage); + + // Note: observer assertions are verified in the Teardown() + } + } + } + + [Test] public void ContextMenuStrip_HydraulicBoundaryDatabaseNotValid_ContextMenuItemCalculateAllDisabledAndTooltipSet() { // Setup @@ -803,7 +1379,7 @@ mocks.ReplayAll(); // Call - using (var contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) { // Assert TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuGenerateCalculationsIndexRootGroup, @@ -820,7 +1396,10 @@ { // Setup var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); - failureMechanism.DikeProfiles.Add(new TestDikeProfile()); + failureMechanism.DikeProfiles.AddRange(new[] + { + new TestDikeProfile() + }, dikeProfileCollectionPath); var assessmentSection = mocks.Stub(); @@ -900,7 +1479,7 @@ // Call TestHelper.AssertLogMessages(() => contextMenu.Items[contextMenuValidateAllIndexRootGroup].PerformClick(), messages => { - var messageList = messages.ToList(); + List messageList = messages.ToList(); // Assert Assert.AreEqual(4, messageList.Count); @@ -976,7 +1555,7 @@ // Call TestHelper.AssertLogMessages(() => contextMenu.Items[contextMenuCalculateAllIndexRootGroup].PerformClick(), messages => { - var messageList = messages.ToList(); + List messageList = messages.ToList(); // Assert Assert.AreEqual(12, messageList.Count); @@ -1035,7 +1614,7 @@ // Assert Assert.AreEqual(2, group.Children.Count); - var newlyAddedItem = group.Children.Last(); + ICalculationBase newlyAddedItem = group.Children.Last(); Assert.IsInstanceOf(newlyAddedItem); Assert.AreEqual("Nieuwe map (1)", newlyAddedItem.Name, "An item with the same name default name already exists, therefore '(1)' needs to be appended."); @@ -1081,7 +1660,7 @@ // Assert Assert.AreEqual(2, group.Children.Count); - var newlyAddedItem = group.Children.Last(); + ICalculationBase newlyAddedItem = group.Children.Last(); Assert.IsInstanceOf(newlyAddedItem); Assert.AreEqual("Nieuwe berekening (1)", newlyAddedItem.Name, "An item with the same name default name already exists, therefore '(1)' needs to be appended."); @@ -1097,18 +1676,13 @@ { var assessmentSection = mocks.Stub(); - DikeProfile dikeProfile1 = new TestDikeProfile("Dike profile 1"); - DikeProfile dikeProfile2 = new TestDikeProfile("Dike profile 2"); + DikeProfile dikeProfile1 = new TestDikeProfile("Dike profile 1", "id1"); + DikeProfile dikeProfile2 = new TestDikeProfile("Dike profile 2", "id2"); var existingCalculationGroup = new CalculationGroup(); var existingCalculation = new GrassCoverErosionInwardsCalculation(); var failureMechanism = new GrassCoverErosionInwardsFailureMechanism { - DikeProfiles = - { - dikeProfile1, - dikeProfile2 - }, CalculationsGroup = { Children = @@ -1118,6 +1692,11 @@ } } }; + failureMechanism.DikeProfiles.AddRange(new[] + { + dikeProfile1, + dikeProfile2 + }, dikeProfileCollectionPath); var nodeData = new GrassCoverErosionInwardsCalculationGroupContext(failureMechanism.CalculationsGroup, failureMechanism, @@ -1168,17 +1747,15 @@ { var assessmentSection = mocks.Stub(); - DikeProfile dikeProfile1 = new TestDikeProfile("Dike profile 1"); - DikeProfile dikeProfile2 = new TestDikeProfile("Dike profile 2"); + DikeProfile dikeProfile1 = new TestDikeProfile("Dike profile 1", "id1"); + DikeProfile dikeProfile2 = new TestDikeProfile("Dike profile 2", "id2"); - var failureMechanism = new GrassCoverErosionInwardsFailureMechanism + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + failureMechanism.DikeProfiles.AddRange(new[] { - DikeProfiles = - { - dikeProfile1, - dikeProfile2 - } - }; + dikeProfile1, + dikeProfile2 + }, dikeProfileCollectionPath); var nodeData = new GrassCoverErosionInwardsCalculationGroupContext(failureMechanism.CalculationsGroup, failureMechanism, @@ -1229,10 +1806,6 @@ var failureMechanism = new GrassCoverErosionInwardsFailureMechanism { - DikeProfiles = - { - dikeProfile - }, CalculationsGroup = { Children = @@ -1244,6 +1817,10 @@ } } }; + failureMechanism.DikeProfiles.AddRange(new[] + { + dikeProfile + }, dikeProfileCollectionPath); var nodeData = new GrassCoverErosionInwardsCalculationGroupContext(failureMechanism.CalculationsGroup, failureMechanism, @@ -1278,7 +1855,7 @@ contextMenu.Items[contextMenuGenerateCalculationsIndexRootGroup].PerformClick(); // Then - var grassCoverErosionInwardsCalculations = failureMechanism.Calculations.OfType().ToArray(); + GrassCoverErosionInwardsCalculation[] grassCoverErosionInwardsCalculations = failureMechanism.Calculations.OfType().ToArray(); Assert.AreEqual(2, grassCoverErosionInwardsCalculations.Length); Assert.AreEqual(expectedNewName, grassCoverErosionInwardsCalculations[1].Name); } @@ -1389,6 +1966,26 @@ Assert.IsNull(result.Calculation); } + private static void UpdateDikeProfile(DikeProfile dikeProfile) + { + var dikeProfileToUpdateFrom = new DikeProfile(dikeProfile.WorldReferencePoint, + dikeProfile.DikeGeometry, + new[] + { + new Point2D(1.1, 2.2), + new Point2D(3.3, 4.4) + }, + new BreakWater(BreakWaterType.Caisson, 10), + new DikeProfile.ConstructionProperties + { + Id = dikeProfile.Id, + DikeHeight = 10, + Orientation = 10 + }); + + dikeProfile.CopyProperties(dikeProfileToUpdateFrom); + } + public override void TearDown() { plugin.Dispose(); Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/UpdateInfos/DikeProfilesContextUpdateInfoTest.cs =================================================================== diff -u --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/UpdateInfos/DikeProfilesContextUpdateInfoTest.cs (revision 0) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/UpdateInfos/DikeProfilesContextUpdateInfoTest.cs (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -0,0 +1,284 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Drawing; +using System.Linq; +using Core.Common.Base.IO; +using Core.Common.Gui; +using Core.Common.Gui.Forms.MainWindow; +using Core.Common.Gui.Plugin; +using Core.Common.TestUtil; +using NUnit.Extensions.Forms; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.Common.IO.FileImporters; +using Ringtoets.GrassCoverErosionInwards.Data; +using Ringtoets.GrassCoverErosionInwards.Data.TestUtil; +using Ringtoets.GrassCoverErosionInwards.Forms.PresentationObjects; +using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; + +namespace Ringtoets.GrassCoverErosionInwards.Plugin.Test.UpdateInfos +{ + [TestFixture] + public class DikeProfilesContextUpdateInfoTest : NUnitFormTest + { + [Test] + public void Name_Always_ReturnExpectedName() + { + // Setup + using (var plugin = new GrassCoverErosionInwardsPlugin()) + { + UpdateInfo importInfo = GetUpdateInfo(plugin); + + // Call + string name = importInfo.Name; + + // Assert + Assert.AreEqual("Dijkprofiellocaties", name); + } + } + + [Test] + public void Category_Always_ReturnExpectedCategory() + { + // Setup + using (var plugin = new GrassCoverErosionInwardsPlugin()) + { + UpdateInfo importInfo = GetUpdateInfo(plugin); + + // Call + string category = importInfo.Category; + + // Assert + Assert.AreEqual("Algemeen", category); + } + } + + [Test] + public void Image_Always_ReturnExpectedIcon() + { + // Setup + using (var plugin = new GrassCoverErosionInwardsPlugin()) + { + UpdateInfo importInfo = GetUpdateInfo(plugin); + + // Call + Image image = importInfo.Image; + + // Assert + TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.DikeProfile, image); + } + } + + [Test] + public void IsEnabled_ReferenceLineSet_ReturnTrue() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + assessmentSection.ReferenceLine = new ReferenceLine(); + + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + + var context = new DikeProfilesContext(failureMechanism.DikeProfiles, failureMechanism, assessmentSection); + + using (var plugin = new GrassCoverErosionInwardsPlugin()) + { + UpdateInfo importInfo = GetUpdateInfo(plugin); + + // Call + bool isEnabled = importInfo.IsEnabled(context); + + // Assert + Assert.IsTrue(isEnabled); + } + mocks.VerifyAll(); + } + + [Test] + public void IsEnabled_ReferenceLineNotSet_ReturnFalse() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + + var context = new DikeProfilesContext(failureMechanism.DikeProfiles, failureMechanism, assessmentSection); + + using (var plugin = new GrassCoverErosionInwardsPlugin()) + { + UpdateInfo importInfo = GetUpdateInfo(plugin); + + // Call + bool isEnabled = importInfo.IsEnabled(context); + + // Assert + Assert.IsFalse(isEnabled); + } + mocks.VerifyAll(); + } + + [Test] + public void FileFilterGenerator_Always_ReturnExpectedFileFilter() + { + // Setup + using (var plugin = new GrassCoverErosionInwardsPlugin()) + { + UpdateInfo importInfo = GetUpdateInfo(plugin); + + // Call + FileFilterGenerator fileFilterGenerator = importInfo.FileFilterGenerator; + + // Assert + Assert.AreEqual("Shapebestand (*.shp)|*.shp", fileFilterGenerator.Filter); + } + } + + [Test] + public void VerifyUpdates_CalculationWithoutOutputs_ReturnsTrue() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + + var mainWindow = mocks.Stub(); + var gui = mocks.Stub(); + gui.Stub(g => g.MainWindow).Return(mainWindow); + mocks.ReplayAll(); + + using (var plugin = new GrassCoverErosionInwardsPlugin()) + { + plugin.Gui = gui; + + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(new GrassCoverErosionInwardsCalculation()); + + var dikeProfiles = new DikeProfileCollection(); + var context = new DikeProfilesContext(dikeProfiles, failureMechanism, assessmentSection); + + UpdateInfo updateInfo = GetUpdateInfo(plugin); + + // Call + bool updatesVerified = updateInfo.VerifyUpdates(context); + + // Assert + Assert.IsTrue(updatesVerified); + mocks.VerifyAll(); + } + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void VerifyUpdates_CalculationWithOutputs_AlwaysReturnsExpectedInquiryMessage(bool isActionConfirmed) + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + + var mainWindow = mocks.Stub(); + var gui = mocks.Stub(); + gui.Stub(g => g.MainWindow).Return(mainWindow); + mocks.ReplayAll(); + + using (var plugin = new GrassCoverErosionInwardsPlugin()) + { + plugin.Gui = gui; + + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(new GrassCoverErosionInwardsCalculation + { + Output = new TestGrassCoverErosionInwardsOutput() + }); + + var dikeProfiles = new DikeProfileCollection(); + var context = new DikeProfilesContext(dikeProfiles, failureMechanism, assessmentSection); + + UpdateInfo updateInfo = GetUpdateInfo(plugin); + + string textBoxMessage = null; + DialogBoxHandler = (name, wnd) => + { + var helper = new MessageBoxTester(wnd); + textBoxMessage = helper.Text; + + if (isActionConfirmed) + { + helper.ClickOk(); + } + else + { + helper.ClickCancel(); + } + }; + + // Call + bool updatesVerified = updateInfo.VerifyUpdates(context); + + // Assert + string expectedInquiryMessage = "Als dijkprofielen wijzigen door het bijwerken, " + + "dan worden de resultaten van berekeningen die deze dijkprofielen gebruiken " + + $"verwijderd.{Environment.NewLine}{Environment.NewLine}Weet u zeker dat u wilt doorgaan?"; + Assert.AreEqual(expectedInquiryMessage, textBoxMessage); + Assert.AreEqual(isActionConfirmed, updatesVerified); + mocks.VerifyAll(); + } + } + + [Test] + public void CreateFileImporter_Always_ReturnsFileImporter() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + assessmentSection.ReferenceLine = new ReferenceLine(); + + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + var context = new DikeProfilesContext(failureMechanism.DikeProfiles, failureMechanism, assessmentSection); + + using (var plugin = new GrassCoverErosionInwardsPlugin()) + { + UpdateInfo updateInfo = GetUpdateInfo(plugin); + + // Call + IFileImporter importer = updateInfo.CreateFileImporter(context, string.Empty); + + // Assert + Assert.IsInstanceOf(importer); + mocks.VerifyAll(); + } + } + + private static UpdateInfo GetUpdateInfo(GrassCoverErosionInwardsPlugin plugin) + { + return plugin.GetUpdateInfos().First(ii => ii.DataType == typeof(DikeProfilesContext)); + } + } +} \ No newline at end of file Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Utils.Test/GrassCoverErosionInwardsDataSynchronizationServiceTest.cs =================================================================== diff -u -r8cb270db5fbcb82f19d6f3a390f083e9e0516d8c -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Utils.Test/GrassCoverErosionInwardsDataSynchronizationServiceTest.cs (.../GrassCoverErosionInwardsDataSynchronizationServiceTest.cs) (revision 8cb270db5fbcb82f19d6f3a390f083e9e0516d8c) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Utils.Test/GrassCoverErosionInwardsDataSynchronizationServiceTest.cs (.../GrassCoverErosionInwardsDataSynchronizationServiceTest.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -25,8 +25,10 @@ using Core.Common.Base; using NUnit.Framework; using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.DikeProfiles; using Ringtoets.Common.Data.Hydraulics; using Ringtoets.Common.Data.Probability; +using Ringtoets.Common.Data.TestUtil; using Ringtoets.Common.Service; using Ringtoets.GrassCoverErosionInwards.Data; using Ringtoets.GrassCoverErosionInwards.Data.TestUtil; @@ -52,7 +54,7 @@ public void ClearCalculationOutput_WithCalculation_ClearsOutput() { // Setup - GrassCoverErosionInwardsCalculation calculation = new GrassCoverErosionInwardsCalculation + var calculation = new GrassCoverErosionInwardsCalculation { Output = new GrassCoverErosionInwardsOutput(0, false, new ProbabilityAssessmentOutput(0, 0, 0, 0, 0), new TestSubCalculationAssessmentOutput(0), @@ -182,11 +184,11 @@ // Setup GrassCoverErosionInwardsFailureMechanism failureMechanism = CreateFullyConfiguredFailureMechanism(); - var expectedRemovedObjectInstances = failureMechanism.Sections.OfType() - .Concat(failureMechanism.SectionResults) - .Concat(failureMechanism.CalculationsGroup.GetAllChildrenRecursive()) - .Concat(failureMechanism.DikeProfiles) - .ToArray(); + object[] expectedRemovedObjectInstances = failureMechanism.Sections.OfType() + .Concat(failureMechanism.SectionResults) + .Concat(failureMechanism.CalculationsGroup.GetAllChildrenRecursive()) + .Concat(failureMechanism.DikeProfiles) + .ToArray(); // Call ClearResults result = GrassCoverErosionInwardsDataSynchronizationService.ClearReferenceLineDependentData(failureMechanism); @@ -206,9 +208,135 @@ CollectionAssert.AreEquivalent(expectedRemovedObjectInstances, result.RemovedObjects); } + [Test] + public void RemoveAllDikeProfiles_FailureMechanismNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => GrassCoverErosionInwardsDataSynchronizationService.RemoveAllDikeProfiles(null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("failureMechanism", exception.ParamName); + } + + [Test] + public void RemoveAllDikeProfiles_FullyConfiguredFailureMechanism_RemovesAllDikeProfilesAndDependentData() + { + // Setup + GrassCoverErosionInwardsFailureMechanism failureMechanism = CreateFullyConfiguredFailureMechanism(); + + GrassCoverErosionInwardsCalculation[] calculationsWithDikeProfiles = + failureMechanism.Calculations + .Cast() + .Where(calc => calc.InputParameters.DikeProfile != null) + .ToArray(); + GrassCoverErosionInwardsCalculation[] calculationsWithDikeProfilesAndOutput = + calculationsWithDikeProfiles.Where(calc => calc.HasOutput).ToArray(); + + // Pre-condition + CollectionAssert.IsNotEmpty(calculationsWithDikeProfiles); + + // Call + IEnumerable affectedObjects = + GrassCoverErosionInwardsDataSynchronizationService.RemoveAllDikeProfiles(failureMechanism); + + // Assert + // Note: To make sure the clear is performed regardless of what is done with + // the return result, no ToArray() should be called before these assertions: + CollectionAssert.IsEmpty(failureMechanism.DikeProfiles); + foreach (GrassCoverErosionInwardsCalculation calculation in calculationsWithDikeProfilesAndOutput) + { + Assert.IsFalse(calculation.HasOutput); + } + + IEnumerable expectedAffectedObjects = + calculationsWithDikeProfiles.Select(calc => calc.InputParameters) + .Cast() + .Concat(calculationsWithDikeProfilesAndOutput) + .Concat(new IObservable[] + { + failureMechanism.DikeProfiles + }); + CollectionAssert.AreEquivalent(expectedAffectedObjects, affectedObjects); + } + + [Test] + public void RemoveDikeProfile_FailureMechanismNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => + GrassCoverErosionInwardsDataSynchronizationService.RemoveDikeProfile(null, new TestDikeProfile()); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("failureMechanism", exception.ParamName); + } + + [Test] + public void RemoveDikeProfile_DikeProfileNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => + GrassCoverErosionInwardsDataSynchronizationService.RemoveDikeProfile(new GrassCoverErosionInwardsFailureMechanism(), null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("dikeProfile", exception.ParamName); + } + + [Test] + public void RemoveDikeProfile_FullyConfiguredFailureMechanism_ReturnsOnlyAffectedCalculations() + { + // Setup + GrassCoverErosionInwardsFailureMechanism failureMechanism = CreateFullyConfiguredFailureMechanism(); + DikeProfile profileToBeCleared = failureMechanism.DikeProfiles[0]; + + GrassCoverErosionInwardsCalculation[] affectedCalculationsWithProfile = + failureMechanism.Calculations + .Cast() + .Where(calc => ReferenceEquals(profileToBeCleared, calc.InputParameters.DikeProfile)) + .ToArray(); + GrassCoverErosionInwardsCalculation[] affectedCalculationsWithOutput = + affectedCalculationsWithProfile.Where(calc => calc.HasOutput).ToArray(); + + // Pre-condition + CollectionAssert.IsNotEmpty(affectedCalculationsWithOutput); + + // Call + IEnumerable affectedObjects = + GrassCoverErosionInwardsDataSynchronizationService.RemoveDikeProfile(failureMechanism, profileToBeCleared); + + // Assert + CollectionAssert.DoesNotContain(failureMechanism.DikeProfiles, profileToBeCleared); + + foreach (GrassCoverErosionInwardsCalculation calculation in affectedCalculationsWithOutput) + { + Assert.IsFalse(calculation.HasOutput); + } + + IEnumerable expectedAffectedObjects = + affectedCalculationsWithProfile.Select(calc => calc.InputParameters) + .Cast() + .Concat(affectedCalculationsWithOutput) + .Concat(new IObservable[] + { + failureMechanism.DikeProfiles + }); + CollectionAssert.AreEquivalent(expectedAffectedObjects, affectedObjects); + } + private static GrassCoverErosionInwardsFailureMechanism CreateFullyConfiguredFailureMechanism() { + var testDikeProfile1 = new TestDikeProfile("Profile 1", "ID 1"); + var testDikeProfile2 = new TestDikeProfile("Profile 2", "ID 2"); + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + failureMechanism.DikeProfiles.AddRange(new[] + { + testDikeProfile1, + testDikeProfile2 + }, "some/path/to/dikeprofiles"); + var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, string.Empty, 0, 0); var calculation = new GrassCoverErosionInwardsCalculation(); @@ -235,6 +363,30 @@ HydraulicBoundaryLocation = hydraulicBoundaryLocation } }; + var calculationWithHydraulicBoundaryLocationAndDikeProfile = new GrassCoverErosionInwardsCalculation + { + InputParameters = + { + HydraulicBoundaryLocation = hydraulicBoundaryLocation, + DikeProfile = testDikeProfile1 + } + }; + var calculationWithDikeProfile = new GrassCoverErosionInwardsCalculation + { + InputParameters = + { + DikeProfile = testDikeProfile2 + } + }; + var calculationWithOutputHydraulicBoundaryLocationAndDikeProfile = new GrassCoverErosionInwardsCalculation + { + InputParameters = + { + HydraulicBoundaryLocation = hydraulicBoundaryLocation, + DikeProfile = testDikeProfile1 + }, + Output = new TestGrassCoverErosionInwardsOutput() + }; var subCalculation = new GrassCoverErosionInwardsCalculation(); var subCalculationWithOutput = new GrassCoverErosionInwardsCalculation @@ -260,19 +412,49 @@ HydraulicBoundaryLocation = hydraulicBoundaryLocation } }; + var subCalculationWithHydraulicBoundaryLocationAndDikeProfile = new GrassCoverErosionInwardsCalculation + { + InputParameters = + { + HydraulicBoundaryLocation = hydraulicBoundaryLocation, + DikeProfile = testDikeProfile1 + } + }; + var subCalculationWithDikeProfile = new GrassCoverErosionInwardsCalculation + { + InputParameters = + { + DikeProfile = testDikeProfile2 + } + }; + var subCalculationWithOutputHydraulicBoundaryLocationAndDikeProfile = new GrassCoverErosionInwardsCalculation + { + InputParameters = + { + HydraulicBoundaryLocation = hydraulicBoundaryLocation, + DikeProfile = testDikeProfile1 + }, + Output = new TestGrassCoverErosionInwardsOutput() + }; failureMechanism.CalculationsGroup.Children.Add(calculation); failureMechanism.CalculationsGroup.Children.Add(calculationWithOutput); failureMechanism.CalculationsGroup.Children.Add(calculationWithOutputAndHydraulicBoundaryLocation); failureMechanism.CalculationsGroup.Children.Add(calculationWithHydraulicBoundaryLocation); + failureMechanism.CalculationsGroup.Children.Add(calculationWithDikeProfile); + failureMechanism.CalculationsGroup.Children.Add(calculationWithHydraulicBoundaryLocationAndDikeProfile); + failureMechanism.CalculationsGroup.Children.Add(calculationWithOutputHydraulicBoundaryLocationAndDikeProfile); failureMechanism.CalculationsGroup.Children.Add(new CalculationGroup { Children = { subCalculation, subCalculationWithOutput, subCalculationWithOutputAndHydraulicBoundaryLocation, - subCalculationWithHydraulicBoundaryLocation + subCalculationWithHydraulicBoundaryLocation, + subCalculationWithDikeProfile, + subCalculationWithHydraulicBoundaryLocationAndDikeProfile, + subCalculationWithOutputHydraulicBoundaryLocationAndDikeProfile } }); Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Properties/Resources.Designer.cs =================================================================== diff -u -r32e66ad63b1d2ddd01a6fb7a9fe55c75a7cd276d -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 32e66ad63b1d2ddd01a6fb7a9fe55c75a7cd276d) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -149,15 +149,6 @@ } /// - /// Looks up a localized string similar to Dijkprofiellocaties. - /// - public static string DikeProfilesImporter_DisplayName { - get { - return ResourceManager.GetString("DikeProfilesImporter_DisplayName", resourceCulture); - } - } - - /// /// Looks up a localized string similar to Als u de norm aanpast, dan worden alle rekenresultaten van alle hydraulische randvoorwaarden en toetssporen verwijderd. /// ///Weet u zeker dat u wilt doorgaan?. Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Properties/Resources.resx =================================================================== diff -u -r32e66ad63b1d2ddd01a6fb7a9fe55c75a7cd276d -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Properties/Resources.resx (.../Resources.resx) (revision 32e66ad63b1d2ddd01a6fb7a9fe55c75a7cd276d) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Properties/Resources.resx (.../Resources.resx) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -133,9 +133,6 @@ ..\Resources\Foreshore.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - Dijkprofiellocaties - h(norm) Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs =================================================================== diff -u -rd95fb69687882a10441dbda4682b2cef974f833b -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs (.../RingtoetsPlugin.cs) (revision d95fb69687882a10441dbda4682b2cef974f833b) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs (.../RingtoetsPlugin.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -436,19 +436,6 @@ RingtoetsCommonIOResources.Shape_file_filter_Description), IsEnabled = context => context.ParentAssessmentSection.ReferenceLine != null }; - - yield return new ImportInfo - { - CreateFileImporter = (context, filePath) => new DikeProfilesImporter(context.WrappedData, - context.ParentAssessmentSection.ReferenceLine, - filePath), - Name = RingtoetsIntegrationPluginResources.DikeProfilesImporter_DisplayName, - Category = RingtoetsCommonFormsResources.Ringtoets_Category, - Image = RingtoetsCommonFormsResources.DikeProfile, - FileFilterGenerator = new FileFilterGenerator(RingtoetsCommonIOResources.Shape_file_filter_Extension, - RingtoetsCommonIOResources.Shape_file_filter_Description), - IsEnabled = context => context.ParentAssessmentSection.ReferenceLine != null - }; } public override IEnumerable GetExportInfos() @@ -482,7 +469,7 @@ var project = viewData as RingtoetsProject; if (project != null) { - foreach (var item in project.AssessmentSections) + foreach (AssessmentSection item in project.AssessmentSections) { yield return item; } @@ -630,12 +617,8 @@ Text = dikeProfile => dikeProfile.Name, Image = context => RingtoetsCommonFormsResources.DikeProfile, ContextMenuStrip = (nodeData, parentData, treeViewControl) => Gui.Get(nodeData, treeViewControl) - .AddDeleteItem() - .AddSeparator() .AddPropertiesItem() - .Build(), - CanRemove = CanRemoveDikeProfile, - OnNodeRemoved = OnDikeProfileRemoved + .Build() }; yield return new TreeNodeInfo @@ -762,11 +745,11 @@ { return; } - var sectionsWithDatabase = ringtoetsProject.AssessmentSections.Where(i => i.HydraulicBoundaryDatabase != null); + IEnumerable sectionsWithDatabase = ringtoetsProject.AssessmentSections.Where(i => i.HydraulicBoundaryDatabase != null); foreach (AssessmentSection section in sectionsWithDatabase) { string selectedFile = section.HydraulicBoundaryDatabase.FilePath; - var validationProblem = HydraulicDatabaseHelper.ValidatePathForCalculation(selectedFile); + string validationProblem = HydraulicDatabaseHelper.ValidatePathForCalculation(selectedFile); if (validationProblem != null) { log.WarnFormat( @@ -784,7 +767,7 @@ var failureMechanism = o as IFailureMechanism; var viewFailureMechanismContext = (FailureMechanismContext) view.Data; - var viewFailureMechanism = viewFailureMechanismContext.WrappedData; + IFailureMechanism viewFailureMechanism = viewFailureMechanismContext.WrappedData; return assessmentSection != null ? ReferenceEquals(viewFailureMechanismContext.Parent, assessmentSection) @@ -807,7 +790,7 @@ private static bool CloseFailureMechanismResultViewForData(T view, object dataToCloseFor) where T : IView { - var viewData = view.Data; + object viewData = view.Data; var assessmentSection = dataToCloseFor as IAssessmentSection; var failureMechanism = dataToCloseFor as IFailureMechanism; var failureMechanismContext = dataToCloseFor as IFailureMechanismContext; @@ -837,7 +820,7 @@ private static bool CloseDesignWaterLevelLocationsViewForData(DesignWaterLevelLocationsView view, object dataToCloseFor) { - var viewData = view.AssessmentSection; + IAssessmentSection viewData = view.AssessmentSection; var assessmentSection = dataToCloseFor as IAssessmentSection; return assessmentSection != null && ReferenceEquals(viewData, assessmentSection); @@ -849,7 +832,7 @@ private static bool CloseWaveHeightLocationsViewForData(WaveHeightLocationsView view, object dataToCloseFor) { - var viewData = view.AssessmentSection; + IAssessmentSection viewData = view.AssessmentSection; var assessmentSection = dataToCloseFor as IAssessmentSection; return assessmentSection != null && ReferenceEquals(viewData, assessmentSection); @@ -960,7 +943,7 @@ var stabilityStoneCoverFailureMechanism = failureMechanism as StabilityStoneCoverFailureMechanism; if (stabilityStoneCoverFailureMechanism != null) { - var affectedObservables = RingtoetsDataSynchronizationService.RemoveForeshoreProfile(stabilityStoneCoverFailureMechanism, nodeData); + IEnumerable affectedObservables = RingtoetsDataSynchronizationService.RemoveForeshoreProfile(stabilityStoneCoverFailureMechanism, nodeData); foreach (IObservable affectedObservable in affectedObservables) { affectedObservable.NotifyObservers(); @@ -969,7 +952,7 @@ var waveImpactAsphaltCoverFailureMechanism = failureMechanism as WaveImpactAsphaltCoverFailureMechanism; if (waveImpactAsphaltCoverFailureMechanism != null) { - var affectedObservables = RingtoetsDataSynchronizationService.RemoveForeshoreProfile(waveImpactAsphaltCoverFailureMechanism, nodeData); + IEnumerable affectedObservables = RingtoetsDataSynchronizationService.RemoveForeshoreProfile(waveImpactAsphaltCoverFailureMechanism, nodeData); foreach (IObservable affectedObservable in affectedObservables) { affectedObservable.NotifyObservers(); @@ -978,7 +961,7 @@ var grassCoverErosionOutwardsFailureMechanism = failureMechanism as GrassCoverErosionOutwardsFailureMechanism; if (grassCoverErosionOutwardsFailureMechanism != null) { - var affectedObservables = RingtoetsDataSynchronizationService.RemoveForeshoreProfile(grassCoverErosionOutwardsFailureMechanism, nodeData); + IEnumerable affectedObservables = RingtoetsDataSynchronizationService.RemoveForeshoreProfile(grassCoverErosionOutwardsFailureMechanism, nodeData); foreach (IObservable affectedObservable in affectedObservables) { affectedObservable.NotifyObservers(); @@ -987,7 +970,7 @@ var heightStructuresFailureMechanism = failureMechanism as HeightStructuresFailureMechanism; if (heightStructuresFailureMechanism != null) { - var affectedObservables = RingtoetsDataSynchronizationService.RemoveForeshoreProfile(heightStructuresFailureMechanism, nodeData); + IEnumerable affectedObservables = RingtoetsDataSynchronizationService.RemoveForeshoreProfile(heightStructuresFailureMechanism, nodeData); foreach (IObservable affectedObservable in affectedObservables) { affectedObservable.NotifyObservers(); @@ -996,7 +979,7 @@ var closingStructuresFailureMechanism = failureMechanism as ClosingStructuresFailureMechanism; if (closingStructuresFailureMechanism != null) { - var affectedObservables = RingtoetsDataSynchronizationService.RemoveForeshoreProfile(closingStructuresFailureMechanism, nodeData); + IEnumerable affectedObservables = RingtoetsDataSynchronizationService.RemoveForeshoreProfile(closingStructuresFailureMechanism, nodeData); foreach (IObservable affectedObservable in affectedObservables) { affectedObservable.NotifyObservers(); @@ -1005,7 +988,7 @@ var stabilityPointStructuresFailureMechanism = failureMechanism as StabilityPointStructuresFailureMechanism; if (stabilityPointStructuresFailureMechanism != null) { - var affectedObservables = RingtoetsDataSynchronizationService.RemoveForeshoreProfile(stabilityPointStructuresFailureMechanism, nodeData); + IEnumerable affectedObservables = RingtoetsDataSynchronizationService.RemoveForeshoreProfile(stabilityPointStructuresFailureMechanism, nodeData); foreach (IObservable affectedObservable in affectedObservables) { affectedObservable.NotifyObservers(); @@ -1015,27 +998,6 @@ #endregion - #region DikeProfile TreeNodeInfo - - private static bool CanRemoveDikeProfile(DikeProfile nodeData, object parentData) - { - return parentData is DikeProfilesContext; - } - - private static void OnDikeProfileRemoved(DikeProfile nodeData, object parentData) - { - var parentContext = (DikeProfilesContext) parentData; - var changedObservables = RingtoetsDataSynchronizationService.RemoveDikeProfile(parentContext.ParentFailureMechanism, - nodeData).ToArray(); - - foreach (IObservable observable in changedObservables) - { - observable.NotifyObservers(); - } - } - - #endregion - #region Comment ViewInfo private static bool CloseCommentViewForData(CommentView commentView, object o) @@ -1499,18 +1461,18 @@ /// failed. private void ImportHydraulicBoundaryDatabase(string databaseFile, AssessmentSection assessmentSection) { - var hydraulicBoundaryDatabase = assessmentSection.HydraulicBoundaryDatabase; + HydraulicBoundaryDatabase hydraulicBoundaryDatabase = assessmentSection.HydraulicBoundaryDatabase; - var isHydraulicBoundaryDatabaseSet = hydraulicBoundaryDatabase != null; - var isClearConfirmationRequired = isHydraulicBoundaryDatabaseSet && !HydraulicDatabaseHelper.HaveEqualVersion(hydraulicBoundaryDatabase, databaseFile); - var isClearConfirmationGiven = isClearConfirmationRequired && IsClearCalculationConfirmationGiven(); + bool isHydraulicBoundaryDatabaseSet = hydraulicBoundaryDatabase != null; + bool isClearConfirmationRequired = isHydraulicBoundaryDatabaseSet && !HydraulicDatabaseHelper.HaveEqualVersion(hydraulicBoundaryDatabase, databaseFile); + bool isClearConfirmationGiven = isClearConfirmationRequired && IsClearCalculationConfirmationGiven(); if (isHydraulicBoundaryDatabaseSet && isClearConfirmationRequired && !isClearConfirmationGiven) { return; } - var previousHydraulicBoundaryDatabase = assessmentSection.HydraulicBoundaryDatabase; + HydraulicBoundaryDatabase previousHydraulicBoundaryDatabase = assessmentSection.HydraulicBoundaryDatabase; using (var hydraulicBoundaryLocationsImporter = new HydraulicBoundaryDatabaseImporter()) { if (hydraulicBoundaryLocationsImporter.Import(assessmentSection, databaseFile)) @@ -1542,7 +1504,7 @@ private static bool IsClearCalculationConfirmationGiven() { - var confirmation = MessageBox.Show( + DialogResult confirmation = MessageBox.Show( RingtoetsFormsResources.Delete_Calculations_Text, BaseResources.Confirm, MessageBoxButtons.OKCancel); Fisheye: Tag 56ac4eb28f5fcc5b20117474e9e4030399d6806a refers to a dead (removed) revision in file `Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/ImportInfos/DikeProfilesContextImportInfoTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Ringtoets.Integration.Plugin.Test.csproj =================================================================== diff -u -rc63ac515f0ce88fbc058e1838d1a43ed6a912360 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Ringtoets.Integration.Plugin.Test.csproj (.../Ringtoets.Integration.Plugin.Test.csproj) (revision c63ac515f0ce88fbc058e1838d1a43ed6a912360) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Ringtoets.Integration.Plugin.Test.csproj (.../Ringtoets.Integration.Plugin.Test.csproj) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -82,7 +82,6 @@ - Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/RingtoetsPluginTest.cs =================================================================== diff -u -r7a4f8ff71ae5f81177fe5ff9cd78fdc7f24c69f4 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/RingtoetsPluginTest.cs (.../RingtoetsPluginTest.cs) (revision 7a4f8ff71ae5f81177fe5ff9cd78fdc7f24c69f4) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/RingtoetsPluginTest.cs (.../RingtoetsPluginTest.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -49,7 +49,6 @@ using Ringtoets.Common.Forms.PresentationObjects; using Ringtoets.Common.Forms.PropertyClasses; using Ringtoets.Common.Forms.Views; -using Ringtoets.GrassCoverErosionInwards.Forms.PresentationObjects; using Ringtoets.Integration.Data; using Ringtoets.Integration.Data.StandAlone.SectionResults; using Ringtoets.Integration.Forms.PresentationObjects; @@ -115,8 +114,8 @@ var projectMigrator = mocks.Stub(); mocks.ReplayAll(); - var testDataDir = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, "HydraulicBoundaryDatabaseImporter"); - var testFilePath = Path.Combine(testDataDir, "complete.sqlite"); + string testDataDir = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, "HydraulicBoundaryDatabaseImporter"); + string testFilePath = Path.Combine(testDataDir, "complete.sqlite"); using (var gui = new GuiCore(new MainWindow(), projectStore, projectMigrator, new RingtoetsProjectFactory(), new GuiCoreSettings())) { @@ -180,7 +179,7 @@ Action action = () => gui.SetProject(project, null); // Then - var fileMissingMessage = string.Format("Fout bij het lezen van bestand '{0}': het bestand bestaat niet.", nonExistingFileExistingFile); + string fileMissingMessage = string.Format("Fout bij het lezen van bestand '{0}': het bestand bestaat niet.", nonExistingFileExistingFile); string message = string.Format( RingtoetsCommonServiceResources.Hydraulic_boundary_database_connection_failed_0_, fileMissingMessage); @@ -444,7 +443,7 @@ using (var plugin = new RingtoetsPlugin()) { // Call - var childrenWithViewDefinitions = plugin.GetChildDataWithViewDefinitions(assessmentSectionStub); + IEnumerable childrenWithViewDefinitions = plugin.GetChildDataWithViewDefinitions(assessmentSectionStub); // Assert CollectionAssert.AreEqual(new object[] @@ -467,10 +466,10 @@ using (var plugin = new RingtoetsPlugin()) { // Call - var childrenWithViewDefinitions = plugin.GetChildDataWithViewDefinitions(project); + IEnumerable childrenWithViewDefinitions = plugin.GetChildDataWithViewDefinitions(project); // Assert - var expectedResult = project.AssessmentSections; + IList expectedResult = project.AssessmentSections; CollectionAssert.AreEquivalent(expectedResult, childrenWithViewDefinitions); } } @@ -482,7 +481,7 @@ using (var plugin = new RingtoetsPlugin()) { // Call - var childrenWithViewDefinitions = plugin.GetChildDataWithViewDefinitions(1); + IEnumerable childrenWithViewDefinitions = plugin.GetChildDataWithViewDefinitions(1); // Assert CollectionAssert.IsEmpty(childrenWithViewDefinitions); @@ -499,11 +498,10 @@ ImportInfo[] importInfos = plugin.GetImportInfos().ToArray(); // Assert - Assert.AreEqual(4, importInfos.Length); + Assert.AreEqual(3, importInfos.Length); Assert.IsTrue(importInfos.Any(i => i.DataType == typeof(ReferenceLineContext))); Assert.IsTrue(importInfos.Any(i => i.DataType == typeof(FailureMechanismSectionsContext))); Assert.IsTrue(importInfos.Any(i => i.DataType == typeof(ForeshoreProfilesContext))); - Assert.IsTrue(importInfos.Any(i => i.DataType == typeof(DikeProfilesContext))); } } Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/TreeNodeInfos/DikeProfileTreeNodeInfoTest.cs =================================================================== diff -u -r2a0fbe6ec22928831305671ecd4f41030b827250 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/TreeNodeInfos/DikeProfileTreeNodeInfoTest.cs (.../DikeProfileTreeNodeInfoTest.cs) (revision 2a0fbe6ec22928831305671ecd4f41030b827250) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/TreeNodeInfos/DikeProfileTreeNodeInfoTest.cs (.../DikeProfileTreeNodeInfoTest.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -21,20 +21,14 @@ using System.Drawing; using System.Linq; -using Core.Common.Base; -using Core.Common.Base.Geometry; using Core.Common.Controls.TreeView; using Core.Common.Gui; using Core.Common.Gui.ContextMenu; using Core.Common.TestUtil; using NUnit.Framework; using Rhino.Mocks; -using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.DikeProfiles; -using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Data.TestUtil; -using Ringtoets.GrassCoverErosionInwards.Data; -using Ringtoets.GrassCoverErosionInwards.Forms.PresentationObjects; using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; namespace Ringtoets.Integration.Plugin.Test.TreeNodeInfos @@ -71,8 +65,8 @@ Assert.IsNull(info.ChildNodeObjects); Assert.IsNull(info.CanRename); Assert.IsNull(info.OnNodeRenamed); - Assert.IsNotNull(info.CanRemove); - Assert.IsNotNull(info.OnNodeRemoved); + Assert.IsNull(info.CanRemove); + Assert.IsNull(info.OnNodeRemoved); Assert.IsNull(info.CanCheck); Assert.IsNull(info.IsChecked); Assert.IsNull(info.OnNodeChecked); @@ -107,136 +101,11 @@ } [Test] - public void CanRemove_ParentIsDikeProfilesContext_ReturnTrue() - { - // Setup - var mocks = new MockRepository(); - var assessmentSection = mocks.Stub(); - mocks.ReplayAll(); - - var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); - - var parentData = new DikeProfilesContext(failureMechanism.DikeProfiles, failureMechanism, assessmentSection); - - // Call - bool canRemove = info.CanRemove(null, parentData); - - // Assert - Assert.IsTrue(canRemove); - mocks.VerifyAll(); - } - - [Test] - public void CanRemove_ParentIsNotDikeProfilesContext_ReturnFalse() - { - // Call - bool canRemove = info.CanRemove(null, null); - - // Assert - Assert.IsFalse(canRemove); - } - - [Test] - public void OnNodeRemoved_RemovingProfileAssignedToCalculationOfSectionResult_ProfileRemovedFromFailureMechanismAndCalculationProfileClearedAndSectionResultCalculationCleared() - { - // Setup - var mocks = new MockRepository(); - var assessmentSection = mocks.Stub(); - var observer = mocks.StrictMock(); - observer.Expect(o => o.UpdateObserver()); - var calculation1Observer = mocks.StrictMock(); - calculation1Observer.Expect(o => o.UpdateObserver()); - var calculation2Observer = mocks.StrictMock(); - calculation2Observer.Expect(o => o.UpdateObserver()).Repeat.Never(); - var calculation3Observer = mocks.StrictMock(); - calculation3Observer.Expect(o => o.UpdateObserver()).Repeat.Never(); - mocks.ReplayAll(); - - DikeProfile nodeData = new TestDikeProfile(new Point2D(1, 0)); - DikeProfile otherProfile1 = new TestDikeProfile(new Point2D(2, 0)); - DikeProfile otherProfile2 = new TestDikeProfile(new Point2D(7, 0)); - - var calculation1 = new GrassCoverErosionInwardsCalculation - { - InputParameters = - { - DikeProfile = nodeData - } - }; - calculation1.InputParameters.Attach(calculation1Observer); - var calculation2 = new GrassCoverErosionInwardsCalculation - { - InputParameters = - { - DikeProfile = otherProfile1 - } - }; - calculation2.InputParameters.Attach(calculation2Observer); - var calculation3 = new GrassCoverErosionInwardsCalculation - { - InputParameters = - { - DikeProfile = otherProfile2 - } - }; - calculation3.InputParameters.Attach(calculation3Observer); - - var failureMechanism = new GrassCoverErosionInwardsFailureMechanism - { - DikeProfiles = - { - nodeData, - otherProfile1, - otherProfile2 - }, - CalculationsGroup = - { - Children = - { - calculation1, - calculation2, - calculation3 - } - } - }; - failureMechanism.AddSection(new FailureMechanismSection("A", new[] - { - new Point2D(0, 0), - new Point2D(4, 0) - })); - failureMechanism.AddSection(new FailureMechanismSection("B", new[] - { - new Point2D(4, 0), - new Point2D(9, 0) - })); - failureMechanism.DikeProfiles.Attach(observer); - failureMechanism.SectionResults.ElementAt(0).Calculation = calculation1; - failureMechanism.SectionResults.ElementAt(1).Calculation = calculation3; - - var parentData = new DikeProfilesContext(failureMechanism.DikeProfiles, failureMechanism, assessmentSection); - - // Call - info.OnNodeRemoved(nodeData, parentData); - - // Assert - CollectionAssert.DoesNotContain(failureMechanism.DikeProfiles, nodeData); - - Assert.IsNull(calculation1.InputParameters.DikeProfile); - Assert.IsNotNull(calculation2.InputParameters.DikeProfile); - - Assert.AreSame(calculation2, failureMechanism.SectionResults.ElementAt(0).Calculation); - Assert.AreSame(calculation3, failureMechanism.SectionResults.ElementAt(1).Calculation); - mocks.VerifyAll(); - } - - [Test] public void ContextMenuStrip_Always_CallsBuilder() { // Setup var mocks = new MockRepository(); var menuBuilderMock = mocks.StrictMock(); - menuBuilderMock.Expect(mb => mb.AddDeleteItem()).Return(menuBuilderMock); - menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddPropertiesItem()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.Build()).Return(null); @@ -253,7 +122,7 @@ using (var p = new RingtoetsPlugin()) { p.Gui = gui; - var i = p.GetTreeNodeInfos().First(tni => tni.TagType == typeof(DikeProfile)); + TreeNodeInfo i = p.GetTreeNodeInfos().First(tni => tni.TagType == typeof(DikeProfile)); // Call i.ContextMenuStrip(null, null, treeViewControl); Index: Ringtoets/Integration/test/Ringtoets.Integration.TestUtils/TestDataGenerator.cs =================================================================== diff -u -r8cb270db5fbcb82f19d6f3a390f083e9e0516d8c -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Integration/test/Ringtoets.Integration.TestUtils/TestDataGenerator.cs (.../TestDataGenerator.cs) (revision 8cb270db5fbcb82f19d6f3a390f083e9e0516d8c) +++ Ringtoets/Integration/test/Ringtoets.Integration.TestUtils/TestDataGenerator.cs (.../TestDataGenerator.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -302,8 +302,11 @@ X0 = 0 }); - failureMechanism.DikeProfiles.Add(dikeprofile1); - failureMechanism.DikeProfiles.Add(dikeprofile2); + failureMechanism.DikeProfiles.AddRange(new[] + { + dikeprofile1, + dikeprofile2 + }, "some/path/to/dikeprofiles"); var calculation = new GrassCoverErosionInwardsCalculation(); var calculationWithOutputAndDikeProfileAndHydraulicBoundaryLocation = new GrassCoverErosionInwardsCalculation @@ -860,10 +863,10 @@ private static void SetFullyConfiguredFailureMechanism(GrassCoverErosionOutwardsFailureMechanism failureMechanism, HydraulicBoundaryLocation hydraulicBoundaryLocation) { - HydraulicBoundaryLocation internalHydroLocation = new HydraulicBoundaryLocation(hydraulicBoundaryLocation.Id, - hydraulicBoundaryLocation.Name, - hydraulicBoundaryLocation.Location.X, - hydraulicBoundaryLocation.Location.Y) + var internalHydroLocation = new HydraulicBoundaryLocation(hydraulicBoundaryLocation.Id, + hydraulicBoundaryLocation.Name, + hydraulicBoundaryLocation.Location.X, + hydraulicBoundaryLocation.Location.Y) { WaveHeightOutput = new HydraulicBoundaryLocationOutput( hydraulicBoundaryLocation.WaveHeight + 0.2, double.NaN, double.NaN, double.NaN, double.NaN, Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/Importers/IStochasticSoilModelUpdateModelStrategy.cs =================================================================== diff -u -r352102f53efcda2247dd7ff8c2d833eccc709c4d -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Piping/src/Ringtoets.Piping.IO/Importers/IStochasticSoilModelUpdateModelStrategy.cs (.../IStochasticSoilModelUpdateModelStrategy.cs) (revision 352102f53efcda2247dd7ff8c2d833eccc709c4d) +++ Ringtoets/Piping/src/Ringtoets.Piping.IO/Importers/IStochasticSoilModelUpdateModelStrategy.cs (.../IStochasticSoilModelUpdateModelStrategy.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -34,9 +34,9 @@ public interface IStochasticSoilModelUpdateModelStrategy { /// - /// Adds the imported data to the . + /// Adds the imported data to the . /// - /// The to which the imported data + /// The to which the imported data /// is added. /// The stochastic soil models which were imported. /// The path to the source file from which the soil models were imported. @@ -46,7 +46,7 @@ /// exception. /// A of updated instances. IEnumerable UpdateModelWithImportedData( - StochasticSoilModelCollection targetCollection, + StochasticSoilModelCollection targetDataCollection, IEnumerable readStochasticSoilModels, string sourceFilePath); } Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/Importers/ISurfaceLineUpdateDataStrategy.cs =================================================================== diff -u -re45d53ab48741d0112dca1ad6bb6cf199535c8b7 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Piping/src/Ringtoets.Piping.IO/Importers/ISurfaceLineUpdateDataStrategy.cs (.../ISurfaceLineUpdateDataStrategy.cs) (revision e45d53ab48741d0112dca1ad6bb6cf199535c8b7) +++ Ringtoets/Piping/src/Ringtoets.Piping.IO/Importers/ISurfaceLineUpdateDataStrategy.cs (.../ISurfaceLineUpdateDataStrategy.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -35,9 +35,9 @@ public interface ISurfaceLineUpdateDataStrategy { /// - /// Adds the imported data to the . + /// Adds the imported data to the . /// - /// The target collection which needs to be updated. + /// The target collection which needs to be updated. /// The imported surface lines. /// The source path from where the surface lines were imported from. /// An of updated instances. @@ -46,7 +46,7 @@ /// is set with a more detailed explanation /// of why the exception occurs. IEnumerable UpdateSurfaceLinesWithImportedData( - RingtoetsPipingSurfaceLineCollection targetCollection, + RingtoetsPipingSurfaceLineCollection targetDataCollection, IEnumerable readRingtoetsPipingSurfaceLines, string sourceFilePath); } Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/Importers/StochasticSoilModelImporter.cs =================================================================== diff -u -r7c433a2fecb8c13011283032fefffa662b43c8f5 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Piping/src/Ringtoets.Piping.IO/Importers/StochasticSoilModelImporter.cs (.../StochasticSoilModelImporter.cs) (revision 7c433a2fecb8c13011283032fefffa662b43c8f5) +++ Ringtoets/Piping/src/Ringtoets.Piping.IO/Importers/StochasticSoilModelImporter.cs (.../StochasticSoilModelImporter.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -46,6 +46,7 @@ private readonly ILog log = LogManager.GetLogger(typeof(StochasticSoilModelImporter)); private readonly IImporterMessageProvider messageProvider; private readonly IStochasticSoilModelUpdateModelStrategy modelUpdateStrategy; + private IEnumerable updatedInstances; /// /// Initializes a new instance of the class. @@ -70,11 +71,12 @@ } this.messageProvider = messageProvider; this.modelUpdateStrategy = modelUpdateStrategy; + updatedInstances = Enumerable.Empty(); } protected override void DoPostImportUpdates() { - foreach (IObservable observable in UpdatedInstances) + foreach (IObservable observable in updatedInstances) { observable.NotifyObservers(); } @@ -109,7 +111,7 @@ } NotifyProgress(messageProvider.GetAddDataToModelProgressText(), 1, 1); - UpdatedInstances = modelUpdateStrategy.UpdateModelWithImportedData(ImportTarget, validStochasticSoilModels, FilePath); + updatedInstances = modelUpdateStrategy.UpdateModelWithImportedData(ImportTarget, validStochasticSoilModels, FilePath); return true; } @@ -120,8 +122,6 @@ log.Info(message); } - private IEnumerable UpdatedInstances { get; set; } = Enumerable.Empty(); - /// /// Validate the definition of a . /// Fisheye: Tag 56ac4eb28f5fcc5b20117474e9e4030399d6806a refers to a dead (removed) revision in file `Ringtoets/Piping/src/Ringtoets.Piping.Plugin/ChangeHandlers/RingtoetsPipingSurfaceLineChangeHandler.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 56ac4eb28f5fcc5b20117474e9e4030399d6806a refers to a dead (removed) revision in file `Ringtoets/Piping/src/Ringtoets.Piping.Plugin/ChangeHandlers/StochasticSoilModelChangeHandler.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingSurfaceLinesCsvImporter.cs =================================================================== diff -u -r7c433a2fecb8c13011283032fefffa662b43c8f5 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingSurfaceLinesCsvImporter.cs (.../PipingSurfaceLinesCsvImporter.cs) (revision 7c433a2fecb8c13011283032fefffa662b43c8f5) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingSurfaceLinesCsvImporter.cs (.../PipingSurfaceLinesCsvImporter.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -60,6 +60,7 @@ private readonly IImporterMessageProvider messageProvider; private readonly ISurfaceLineUpdateDataStrategy surfaceLineUpdateStrategy; private readonly ILog log = LogManager.GetLogger(typeof(PipingSurfaceLinesCsvImporter)); + private IEnumerable updatedInstances; private readonly ReferenceLine referenceLine; @@ -96,6 +97,7 @@ this.messageProvider = messageProvider; this.surfaceLineUpdateStrategy = surfaceLineUpdateStrategy; this.referenceLine = referenceLine; + updatedInstances = Enumerable.Empty(); } protected override bool OnImport() @@ -120,7 +122,7 @@ } NotifyProgress(messageProvider.GetAddDataToModelProgressText(), 1, 1); - UpdatedInstances = surfaceLineUpdateStrategy.UpdateSurfaceLinesWithImportedData(ImportTarget, importResults, FilePath); + updatedInstances = surfaceLineUpdateStrategy.UpdateSurfaceLinesWithImportedData(ImportTarget, importResults, FilePath); return true; } @@ -132,14 +134,12 @@ protected override void DoPostImportUpdates() { - foreach (IObservable observable in UpdatedInstances) + foreach (IObservable observable in updatedInstances) { observable.NotifyObservers(); } } - private IEnumerable UpdatedInstances { get; set; } = Enumerable.Empty(); - private ReadResult HandleCriticalReadError(Exception e) { log.ErrorFormat(Resources.PipingSurfaceLinesCsvImporter_CriticalErrorMessage_0_File_Skipped, Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/RingtoetsPipingSurfaceLineReplaceDataStrategy.cs =================================================================== diff -u -rdd4e75e27880fc06f6823cca424a010ab19adb33 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/RingtoetsPipingSurfaceLineReplaceDataStrategy.cs (.../RingtoetsPipingSurfaceLineReplaceDataStrategy.cs) (revision dd4e75e27880fc06f6823cca424a010ab19adb33) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/RingtoetsPipingSurfaceLineReplaceDataStrategy.cs (.../RingtoetsPipingSurfaceLineReplaceDataStrategy.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -22,10 +22,12 @@ using System; using System.Collections.Generic; using Core.Common.Base; +using Ringtoets.Common.Data.Exceptions; using Ringtoets.Common.Data.UpdateDataStrategies; using Ringtoets.Piping.Data; using Ringtoets.Piping.IO.Exceptions; using Ringtoets.Piping.IO.Importers; +using Ringtoets.Piping.Plugin.Properties; using Ringtoets.Piping.Primitives; using Ringtoets.Piping.Service; @@ -44,22 +46,20 @@ /// Thrown when is null. public RingtoetsPipingSurfaceLineReplaceDataStrategy(PipingFailureMechanism failureMechanism) : base(failureMechanism) {} - public IEnumerable UpdateSurfaceLinesWithImportedData(RingtoetsPipingSurfaceLineCollection targetCollection, + public IEnumerable UpdateSurfaceLinesWithImportedData(RingtoetsPipingSurfaceLineCollection targetDataCollection, IEnumerable readRingtoetsPipingSurfaceLines, string sourceFilePath) { try { - return ReplaceTargetCollectionWithImportedData(targetCollection, readRingtoetsPipingSurfaceLines, sourceFilePath); + return ReplaceTargetCollectionWithImportedData(targetDataCollection, readRingtoetsPipingSurfaceLines, sourceFilePath); } - catch (ArgumentNullException) + catch (UpdateDataException e) { - throw; + string message = string.Format(Resources.RingtoetsPipingSurfaceLineReplaceDataStrategy_UpdateSurfaceLinesWithImportedData_Importing_RingtoetsPipingSurfaceLines_failed_Reason_0, + e.Message); + throw new RingtoetsPipingSurfaceLineUpdateException(message, e); } - catch (ArgumentException e) - { - throw new RingtoetsPipingSurfaceLineUpdateException(e.Message, e); - } } protected override IEnumerable ClearData(PipingFailureMechanism failureMechanism) Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/RingtoetsPipingSurfaceLineUpdateDataStrategy.cs =================================================================== diff -u -refb7de8b06cc9433bcf80e2475dc11fecb8d3d8c -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/RingtoetsPipingSurfaceLineUpdateDataStrategy.cs (.../RingtoetsPipingSurfaceLineUpdateDataStrategy.cs) (revision efb7de8b06cc9433bcf80e2475dc11fecb8d3d8c) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/RingtoetsPipingSurfaceLineUpdateDataStrategy.cs (.../RingtoetsPipingSurfaceLineUpdateDataStrategy.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -24,6 +24,7 @@ using System.Linq; using Core.Common.Base; using Core.Common.Base.Data; +using Ringtoets.Common.Data.Exceptions; using Ringtoets.Common.Data.UpdateDataStrategies; using Ringtoets.Common.Service; using Ringtoets.Piping.Data; @@ -50,29 +51,32 @@ public RingtoetsPipingSurfaceLineUpdateDataStrategy(PipingFailureMechanism failureMechanism) : base(failureMechanism, new RingtoetsPipingSurfaceLineNameEqualityComparer()) {} - public IEnumerable UpdateSurfaceLinesWithImportedData(RingtoetsPipingSurfaceLineCollection targetCollection, + public IEnumerable UpdateSurfaceLinesWithImportedData(RingtoetsPipingSurfaceLineCollection targetDataCollection, IEnumerable readRingtoetsPipingSurfaceLines, string sourceFilePath) { try { - return UpdateTargetCollectionData(targetCollection, readRingtoetsPipingSurfaceLines, sourceFilePath); + return UpdateTargetCollectionData(targetDataCollection, readRingtoetsPipingSurfaceLines, sourceFilePath); } - catch (ArgumentNullException) + catch (UpdateDataException e) { - throw; - } - catch (ArgumentException e) - { - throw new RingtoetsPipingSurfaceLineUpdateException(e.Message, e); - } - catch (InvalidOperationException e) - { - string message = Resources.RingtoetsPipingSurfaceLineUpdateDataStrategy_UpdateSurfaceLinesWithImportedData_Update_of_RingtoetsPipingSurfaceLine_has_failed; + string message = + string.Format(Resources.RingtoetsPipingSurfaceLineUpdateDataStrategy_UpdateSurfaceLinesWithImportedData_Update_of_RingtoetsPipingSurfaceLine_has_failed_Reason_0, + e.Message); throw new RingtoetsPipingSurfaceLineUpdateException(message, e); } } + #region Removing Data Functions + + protected override IEnumerable RemoveObjectAndDependentData(RingtoetsPipingSurfaceLine removedSurfaceLine) + { + return PipingDataSynchronizationService.RemoveSurfaceLine(FailureMechanism, removedSurfaceLine); + } + + #endregion + /// /// Class for comparing by only the name. /// @@ -144,7 +148,7 @@ private IEnumerable GetAffectedCalculationWithSurfaceLine(RingtoetsPipingSurfaceLine surfaceLine) { IEnumerable affectedCalculations = - failureMechanism.Calculations + FailureMechanism.Calculations .Cast() .Where(calc => ReferenceEquals(calc.InputParameters.SurfaceLine, surfaceLine)); return affectedCalculations; @@ -153,7 +157,7 @@ private IEnumerable GetAvailableStochasticSoilModels(RingtoetsPipingSurfaceLine surfaceLine) { return PipingCalculationConfigurationHelper.GetStochasticSoilModelsForSurfaceLine(surfaceLine, - failureMechanism.StochasticSoilModels); + FailureMechanism.StochasticSoilModels); } private void ValidateEntryAndExitPoints(RingtoetsPipingSurfaceLine surfaceLine) @@ -179,14 +183,5 @@ } #endregion - - #region Removing Data Functions - - protected override IEnumerable RemoveObjectAndDependentData(RingtoetsPipingSurfaceLine removedSurfaceLine) - { - return PipingDataSynchronizationService.RemoveSurfaceLine(failureMechanism, removedSurfaceLine); - } - - #endregion } } \ No newline at end of file Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/StochasticSoilModelReplaceDataStrategy.cs =================================================================== diff -u -rdd4e75e27880fc06f6823cca424a010ab19adb33 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/StochasticSoilModelReplaceDataStrategy.cs (.../StochasticSoilModelReplaceDataStrategy.cs) (revision dd4e75e27880fc06f6823cca424a010ab19adb33) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/StochasticSoilModelReplaceDataStrategy.cs (.../StochasticSoilModelReplaceDataStrategy.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -22,10 +22,12 @@ using System; using System.Collections.Generic; using Core.Common.Base; +using Ringtoets.Common.Data.Exceptions; using Ringtoets.Common.Data.UpdateDataStrategies; using Ringtoets.Piping.Data; using Ringtoets.Piping.IO.Exceptions; using Ringtoets.Piping.IO.Importers; +using Ringtoets.Piping.Plugin.Properties; using Ringtoets.Piping.Service; namespace Ringtoets.Piping.Plugin.FileImporter @@ -44,22 +46,21 @@ /// Thrown when is null. public StochasticSoilModelReplaceDataStrategy(PipingFailureMechanism failureMechanism) : base(failureMechanism) {} - public IEnumerable UpdateModelWithImportedData(StochasticSoilModelCollection targetCollection, + public IEnumerable UpdateModelWithImportedData(StochasticSoilModelCollection targetDataCollection, IEnumerable readStochasticSoilModels, string sourceFilePath) { try { - return ReplaceTargetCollectionWithImportedData(targetCollection, readStochasticSoilModels, sourceFilePath); + return ReplaceTargetCollectionWithImportedData(targetDataCollection, readStochasticSoilModels, sourceFilePath); } - catch (ArgumentNullException) + catch (UpdateDataException e) { - throw; + string message = + string.Format(Resources.StochasticSoilModelReplaceDataStrategy_UpdateModelWithImportedData_Importing_StochasticSoilModels_failed_Reason_0, + e.Message); + throw new StochasticSoilModelUpdateException(message, e); } - catch (ArgumentException e) - { - throw new StochasticSoilModelUpdateException(e.Message, e); - } } protected override IEnumerable ClearData(PipingFailureMechanism failureMechanism) Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/StochasticSoilModelUpdateDataStrategy.cs =================================================================== diff -u -r66239a42b315209acc4d124200c58d8be1a18195 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/StochasticSoilModelUpdateDataStrategy.cs (.../StochasticSoilModelUpdateDataStrategy.cs) (revision 66239a42b315209acc4d124200c58d8be1a18195) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/StochasticSoilModelUpdateDataStrategy.cs (.../StochasticSoilModelUpdateDataStrategy.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -24,6 +24,7 @@ using System.Linq; using Core.Common.Base; using Core.Common.Utils; +using Ringtoets.Common.Data.Exceptions; using Ringtoets.Common.Data.UpdateDataStrategies; using Ringtoets.Piping.Data; using Ringtoets.Piping.IO.Exceptions; @@ -48,29 +49,32 @@ public StochasticSoilModelUpdateDataStrategy(PipingFailureMechanism failureMechanism) : base(failureMechanism, new SoilModelNameEqualityComparer()) {} - public IEnumerable UpdateModelWithImportedData(StochasticSoilModelCollection targetCollection, + public IEnumerable UpdateModelWithImportedData(StochasticSoilModelCollection targetDataCollection, IEnumerable readStochasticSoilModels, string sourceFilePath) { try { - return UpdateTargetCollectionData(targetCollection, readStochasticSoilModels, sourceFilePath); + return UpdateTargetCollectionData(targetDataCollection, readStochasticSoilModels, sourceFilePath); } - catch (ArgumentNullException) + catch (UpdateDataException e) { - throw; - } - catch (ArgumentException e) - { - throw new StochasticSoilModelUpdateException(e.Message, e); - } - catch (InvalidOperationException e) - { - string message = Resources.StochasticSoilModelUpdateDataStrategy_UpdateModelWithImportedData_Update_of_StochasticSoilModel_failed; + string message = + string.Format(Resources.StochasticSoilModelUpdateDataStrategy_UpdateModelWithImportedData_Update_of_StochasticSoilModel_failed_Reason_0, + e.Message); throw new StochasticSoilModelUpdateException(message, e); } } + #region Remove Data Functions + + protected override IEnumerable RemoveObjectAndDependentData(StochasticSoilModel removedModel) + { + return PipingDataSynchronizationService.RemoveStochasticSoilModel(FailureMechanism, removedModel); + } + + #endregion + /// /// Class for comparing by just the name. /// @@ -112,28 +116,19 @@ }; foreach (StochasticSoilProfile removedProfile in difference.RemovedProfiles) { - affectedObjects.AddRange(PipingDataSynchronizationService.RemoveStochasticSoilProfileFromInput(failureMechanism, removedProfile)); + affectedObjects.AddRange(PipingDataSynchronizationService.RemoveStochasticSoilProfileFromInput(FailureMechanism, removedProfile)); } foreach (StochasticSoilProfile updatedProfile in difference.UpdatedProfiles) { if (!oldProfiles[updatedProfile].Equals(updatedProfile.SoilProfile)) { - affectedObjects.AddRange(PipingDataSynchronizationService.ClearStochasticSoilProfileDependentData(failureMechanism, updatedProfile)); + affectedObjects.AddRange(PipingDataSynchronizationService.ClearStochasticSoilProfileDependentData(FailureMechanism, updatedProfile)); } affectedObjects.Add(updatedProfile); } return affectedObjects; } #endregion - - #region Remove Data Functions - - protected override IEnumerable RemoveObjectAndDependentData(StochasticSoilModel removedModel) - { - return PipingDataSynchronizationService.RemoveStochasticSoilModel(failureMechanism, removedModel); - } - - #endregion } } \ No newline at end of file Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/PipingPlugin.cs =================================================================== diff -u -rc132a551ca0b4be0f9909e2e53d43e064b2cadb1 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/PipingPlugin.cs (.../PipingPlugin.cs) (revision c132a551ca0b4be0f9909e2e53d43e064b2cadb1) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/PipingPlugin.cs (.../PipingPlugin.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -346,15 +346,6 @@ }; } - private static FileFilterGenerator PipingCalculationConfigurationFileFilter - { - get - { - return new FileFilterGenerator(RingtoetsCommonFormsResources.DataTypeDisplayName_xml_file_filter_Extension, - RingtoetsCommonFormsResources.DataTypeDisplayName_xml_file_filter_Description); - } - } - private static FileFilterGenerator StochasticSoilModelFileFilter { get @@ -379,7 +370,9 @@ private bool VerifyStochasticSoilModelUpdates(StochasticSoilModelCollectionContext context, string query) { - var changeHandler = new StochasticSoilModelChangeHandler(context.FailureMechanism, query, new DialogBasedInquiryHelper(Gui.MainWindow)); + var changeHandler = new FailureMechanismCalculationChangeHandler(context.FailureMechanism, + query, + new DialogBasedInquiryHelper(Gui.MainWindow)); return !changeHandler.RequireConfirmation() || changeHandler.InquireConfirmation(); } @@ -581,7 +574,6 @@ .AddImportItem() .AddUpdateItem() .AddSeparator() - .AddSeparator() .AddCollapseAllItem() .AddExpandAllItem() .AddSeparator() @@ -830,7 +822,7 @@ private void UpdatedSurfaceLineDependentDataOfCalculation(PipingCalculation scenario) { string message = - Resources.PipingPlugin_VerifyEntryAndExitPointUpdates_When_updating_entry_and_exit_points_definitions_assigned_to_calculation_output_will_be_cleared_confirm; + Resources.PipingPlugin_VerifyEntryAndExitPointUpdates_Confirm_calculation_output_cleared_when_updating_entry_and_exit_points_definitions; if (VerifyEntryAndExitPointUpdates(new[] { scenario @@ -1050,7 +1042,7 @@ if (!calculations.Any()) { isItemEnabled = false; - toolTipText = Resources.PipingPlugin_CreateUpdateEntryAndExitPointItem_No_calculations_to_update_ToolTip; + toolTipText = RingtoetsCommonFormsResources.CreateUpdateContextMenuItem_No_calculations_to_update_ToolTip; } else if (calculations.All(calc => calc.InputParameters.SurfaceLine == null)) { @@ -1073,7 +1065,7 @@ PipingCalculationScenario[] calculations = nodeData.WrappedData.GetCalculations().OfType().ToArray(); string message = - Resources.PipingPlugin_VerifyEntryAndExitPointUpdates_When_updating_entry_and_exit_points_definitions_assigned_to_calculations_output_will_be_cleared_confirm; + Resources.PipingPlugin_VerifyEntryAndExitPointUpdates_Confirm_calculation_outputs_cleared_when_updating_entry_and_exit_points_definitions; if (VerifyEntryAndExitPointUpdates(calculations, message)) { foreach (PipingCalculationScenario calculation in calculations) @@ -1124,8 +1116,9 @@ private bool VerifyPipingSurfaceLineUpdates(RingtoetsPipingSurfaceLinesContext context, string query) { - var changeHandler = new RingtoetsPipingSurfaceLineChangeHandler(context.FailureMechanism, query, - new DialogBasedInquiryHelper(Gui.MainWindow)); + var changeHandler = new FailureMechanismCalculationChangeHandler(context.FailureMechanism, + query, + new DialogBasedInquiryHelper(Gui.MainWindow)); return !changeHandler.RequireConfirmation() || changeHandler.InquireConfirmation(); } Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Properties/Resources.Designer.cs =================================================================== diff -u -r7c433a2fecb8c13011283032fefffa662b43c8f5 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 7c433a2fecb8c13011283032fefffa662b43c8f5) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -82,15 +82,6 @@ } /// - /// Looks up a localized string similar to Er zijn geen berekeningen om bij te werken.. - /// - public static string PipingPlugin_CreateUpdateEntryAndExitPointItem_No_calculations_to_update_ToolTip { - get { - return ResourceManager.GetString("PipingPlugin_CreateUpdateEntryAndExitPointItem_No_calculations_to_update_ToolTip", resourceCulture); - } - } - - /// /// Looks up a localized string similar to Er zijn geen berekeningen met een profielschematisatie.. /// public static string PipingPlugin_CreateUpdateEntryAndExitPointItem_No_calculations_with_surfaceline_Tooltip { @@ -208,10 +199,10 @@ /// ///Weet u zeker dat u wilt doorgaan?. /// - public static string PipingPlugin_VerifyEntryAndExitPointUpdates_When_updating_entry_and_exit_points_definitions_assigned_to_calculation_output_will_be_cleared_confirm { + public static string PipingPlugin_VerifyEntryAndExitPointUpdates_Confirm_calculation_output_cleared_when_updating_entry_and_exit_points_definitions { get { - return ResourceManager.GetString("PipingPlugin_VerifyEntryAndExitPointUpdates_When_updating_entry_and_exit_points_d" + - "efinitions_assigned_to_calculation_output_will_be_cleared_confirm", resourceCulture); + return ResourceManager.GetString("PipingPlugin_VerifyEntryAndExitPointUpdates_Confirm_calculation_output_cleared_wh" + + "en_updating_entry_and_exit_points_definitions", resourceCulture); } } @@ -220,10 +211,10 @@ /// ///Weet u zeker dat u wilt doorgaan?. /// - public static string PipingPlugin_VerifyEntryAndExitPointUpdates_When_updating_entry_and_exit_points_definitions_assigned_to_calculations_output_will_be_cleared_confirm { + public static string PipingPlugin_VerifyEntryAndExitPointUpdates_Confirm_calculation_outputs_cleared_when_updating_entry_and_exit_points_definitions { get { - return ResourceManager.GetString("PipingPlugin_VerifyEntryAndExitPointUpdates_When_updating_entry_and_exit_points_d" + - "efinitions_assigned_to_calculations_output_will_be_cleared_confirm", resourceCulture); + return ResourceManager.GetString("PipingPlugin_VerifyEntryAndExitPointUpdates_Confirm_calculation_outputs_cleared_w" + + "hen_updating_entry_and_exit_points_definitions", resourceCulture); } } @@ -494,12 +485,22 @@ } /// - /// Looks up a localized string similar to Het bijwerken van de profielschematisaties is mislukt.. + /// Looks up a localized string similar to Het importeren van profielschematisaties is mislukt: {0}. /// - public static string RingtoetsPipingSurfaceLineUpdateDataStrategy_UpdateSurfaceLinesWithImportedData_Update_of_RingtoetsPipingSurfaceLine_has_failed { + public static string RingtoetsPipingSurfaceLineReplaceDataStrategy_UpdateSurfaceLinesWithImportedData_Importing_RingtoetsPipingSurfaceLines_failed_Reason_0 { get { + return ResourceManager.GetString("RingtoetsPipingSurfaceLineReplaceDataStrategy_UpdateSurfaceLinesWithImportedData_" + + "Importing_RingtoetsPipingSurfaceLines_failed_Reason_0", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Het bijwerken van de profielschematisaties is mislukt: {0}. + /// + public static string RingtoetsPipingSurfaceLineUpdateDataStrategy_UpdateSurfaceLinesWithImportedData_Update_of_RingtoetsPipingSurfaceLine_has_failed_Reason_0 { + get { return ResourceManager.GetString("RingtoetsPipingSurfaceLineUpdateDataStrategy_UpdateSurfaceLinesWithImportedData_U" + - "pdate_of_RingtoetsPipingSurfaceLine_has_failed", resourceCulture); + "pdate_of_RingtoetsPipingSurfaceLine_has_failed_Reason_0", resourceCulture); } } @@ -532,12 +533,22 @@ } /// - /// Looks up a localized string similar to Het bijwerken van de stochastische ondergrondmodellen is mislukt.. + /// Looks up a localized string similar to Het importeren van stochastische ondergrondmodellen is mislukt: {0}. /// - public static string StochasticSoilModelUpdateDataStrategy_UpdateModelWithImportedData_Update_of_StochasticSoilModel_failed { + public static string StochasticSoilModelReplaceDataStrategy_UpdateModelWithImportedData_Importing_StochasticSoilModels_failed_Reason_0 { get { + return ResourceManager.GetString("StochasticSoilModelReplaceDataStrategy_UpdateModelWithImportedData_Importing_Stoc" + + "hasticSoilModels_failed_Reason_0", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Het bijwerken van de stochastische ondergrondmodellen is mislukt: {0}. + /// + public static string StochasticSoilModelUpdateDataStrategy_UpdateModelWithImportedData_Update_of_StochasticSoilModel_failed_Reason_0 { + get { return ResourceManager.GetString("StochasticSoilModelUpdateDataStrategy_UpdateModelWithImportedData_Update_of_Stoch" + - "asticSoilModel_failed", resourceCulture); + "asticSoilModel_failed_Reason_0", resourceCulture); } } } Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Properties/Resources.resx =================================================================== diff -u -r7c433a2fecb8c13011283032fefffa662b43c8f5 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Properties/Resources.resx (.../Resources.resx) (revision 7c433a2fecb8c13011283032fefffa662b43c8f5) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Properties/Resources.resx (.../Resources.resx) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -213,16 +213,16 @@ Geen bronbestand bekend om vanaf bij te werken. - - Het bijwerken van de stochastische ondergrondmodellen is mislukt. + + Het bijwerken van de stochastische ondergrondmodellen is mislukt: {0} Als u stochastische ondergrondmodellen importeert, dan worden alle rekenresultaten van dit toetsspoor verwijderd. Weet u zeker dat u wilt doorgaan? - - Het bijwerken van de profielschematisaties is mislukt. + + Het bijwerken van de profielschematisaties is mislukt: {0} Als profielschematisaties wijzigen door het bijwerken, dan worden de resultaten van berekeningen die deze profielschematisaties gebruiken verwijderd. @@ -244,18 +244,15 @@ &Bijwerken alle intrede- en uittredepunten - - Er zijn geen berekeningen om bij te werken. - Er zijn geen berekeningen met een profielschematisatie. - + Wanneer de intrede- of uittredepunten wijzigen als gevolg van het bijwerken, zullen de resultaten van berekeningen die deze profielschematisaties gebruiken, worden verwijderd. Weet u zeker dat u wilt doorgaan? - + Wanneer het intrede- of uittredepunt wijzigt als gevolg van het bijwerken, zal het resultaat van deze berekening worden verwijderd. Weet u zeker dat u wilt doorgaan? @@ -270,4 +267,10 @@ Weet u zeker dat u wilt doorgaan? + + Het importeren van profielschematisaties is mislukt: {0} + + + Het importeren van stochastische ondergrondmodellen is mislukt: {0} + \ No newline at end of file Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Ringtoets.Piping.Plugin.csproj =================================================================== diff -u -r497eff2ae81726e546751a3423f5b7b5b93d1e3e -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Ringtoets.Piping.Plugin.csproj (.../Ringtoets.Piping.Plugin.csproj) (revision 497eff2ae81726e546751a3423f5b7b5b93d1e3e) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Ringtoets.Piping.Plugin.csproj (.../Ringtoets.Piping.Plugin.csproj) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -59,11 +59,9 @@ Properties\GlobalAssembly.cs - - Index: Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/StochasticSoilModelCollectionTest.cs =================================================================== diff -u -raae2ecaacbb094fe66d6a54d6ac4b1e6780b0864 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/StochasticSoilModelCollectionTest.cs (.../StochasticSoilModelCollectionTest.cs) (revision aae2ecaacbb094fe66d6a54d6ac4b1e6780b0864) +++ Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/StochasticSoilModelCollectionTest.cs (.../StochasticSoilModelCollectionTest.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -40,7 +40,7 @@ } [Test] - public void AddRange_SurfaceLinesWithDifferentNames_AddsSurfaceLines() + public void AddRange_StochasticSoilModelsWithDifferentNames_AddsSoilModels() { // Setup var stochasticSoilModelsToAdd = new[] Index: Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/StochasticSoilModelTest.cs =================================================================== diff -u -r303f3924f66df0bc726646b29031a926a94882bc -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/StochasticSoilModelTest.cs (.../StochasticSoilModelTest.cs) (revision 303f3924f66df0bc726646b29031a926a94882bc) +++ Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/StochasticSoilModelTest.cs (.../StochasticSoilModelTest.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -368,6 +368,42 @@ } [Test] + public void Update_ModelsWithAddedProfilesWithSameNames_ThrowsInvalidOperationException() + { + // Setup + var addedProfile = new StochasticSoilProfile(0.2, SoilProfileType.SoilProfile1D, 3) + { + SoilProfile = new TestPipingSoilProfile() + }; + StochasticSoilModel otherModel = CreateEmptyModel(); + otherModel.StochasticSoilProfiles.Add(addedProfile); + + var existingProfile = new StochasticSoilProfile(0.2, SoilProfileType.SoilProfile1D, 3) + { + SoilProfile = new TestPipingSoilProfile() + }; + StochasticSoilModel model = CreateEmptyModel(); + model.StochasticSoilProfiles.Add(existingProfile); + model.StochasticSoilProfiles.Add(existingProfile); + + // Call + TestDelegate call = () => model.Update(otherModel); + + // Assert + Assert.Throws(call); + + Assert.AreEqual(1, otherModel.StochasticSoilProfiles.Count); + Assert.AreEqual(addedProfile, otherModel.StochasticSoilProfiles[0]); + + Assert.AreEqual(2, model.StochasticSoilProfiles.Count); + CollectionAssert.AreEqual(new[] + { + existingProfile, + existingProfile + }, model.StochasticSoilProfiles); + } + + [Test] [TestCase(null)] [TestCase("")] [TestCase("some name")] Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/PropertyClasses/StochasticSoilModelCollectionPropertiesTest.cs =================================================================== diff -u -rc290911dd4647e3115e239c8baf814717c098a5a -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/PropertyClasses/StochasticSoilModelCollectionPropertiesTest.cs (.../StochasticSoilModelCollectionPropertiesTest.cs) (revision c290911dd4647e3115e239c8baf814717c098a5a) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/PropertyClasses/StochasticSoilModelCollectionPropertiesTest.cs (.../StochasticSoilModelCollectionPropertiesTest.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -74,14 +74,14 @@ PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties); Assert.AreEqual(1, dynamicProperties.Count); - PropertyDescriptor stochasticSoilModelIdProperty = dynamicProperties[0]; - Assert.IsNotNull(stochasticSoilModelIdProperty); - Assert.IsTrue(stochasticSoilModelIdProperty.IsReadOnly); - Assert.AreEqual("Algemeen", stochasticSoilModelIdProperty.Category); - Assert.AreEqual("Bronlocatie", stochasticSoilModelIdProperty.DisplayName); + PropertyDescriptor stochasticSoilModelSourcePathProperty = dynamicProperties[0]; + Assert.IsNotNull(stochasticSoilModelSourcePathProperty); + Assert.IsTrue(stochasticSoilModelSourcePathProperty.IsReadOnly); + Assert.AreEqual("Algemeen", stochasticSoilModelSourcePathProperty.Category); + Assert.AreEqual("Bronlocatie", stochasticSoilModelSourcePathProperty.DisplayName); Assert.AreEqual( "De locatie van het bestand waaruit de stochastische ondergrondmodellen zijn geïmporteerd.", - stochasticSoilModelIdProperty.Description); + stochasticSoilModelSourcePathProperty.Description); } } } \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.IO.TestUtil/TestStochasticSoilModelUpdateModelStrategy.cs =================================================================== diff -u -r26da131fa5dbcf95f9a16de6f81eb4acc8d1be14 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Piping/test/Ringtoets.Piping.IO.TestUtil/TestStochasticSoilModelUpdateModelStrategy.cs (.../TestStochasticSoilModelUpdateModelStrategy.cs) (revision 26da131fa5dbcf95f9a16de6f81eb4acc8d1be14) +++ Ringtoets/Piping/test/Ringtoets.Piping.IO.TestUtil/TestStochasticSoilModelUpdateModelStrategy.cs (.../TestStochasticSoilModelUpdateModelStrategy.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -54,7 +54,7 @@ /// public IEnumerable UpdatedInstances { get; set; } = Enumerable.Empty(); - public IEnumerable UpdateModelWithImportedData(StochasticSoilModelCollection targetCollection, + public IEnumerable UpdateModelWithImportedData(StochasticSoilModelCollection targetDataCollection, IEnumerable readStochasticSoilModels, string sourceFilePath) { Fisheye: Tag 56ac4eb28f5fcc5b20117474e9e4030399d6806a refers to a dead (removed) revision in file `Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/ChangeHandlers/RingtoetsPipingSurfaceLineChangeHandlerTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 56ac4eb28f5fcc5b20117474e9e4030399d6806a refers to a dead (removed) revision in file `Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/ChangeHandlers/StochasticSoilModelChangeHandlerTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/ChangeHandlers/UpdateEntryAndExitPointsOfCalculationsChangeHandlerTest.cs =================================================================== diff -u -r7271c497cf19130a691b0b07abe99621957fda2e -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/ChangeHandlers/UpdateEntryAndExitPointsOfCalculationsChangeHandlerTest.cs (.../UpdateEntryAndExitPointsOfCalculationsChangeHandlerTest.cs) (revision 7271c497cf19130a691b0b07abe99621957fda2e) +++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/ChangeHandlers/UpdateEntryAndExitPointsOfCalculationsChangeHandlerTest.cs (.../UpdateEntryAndExitPointsOfCalculationsChangeHandlerTest.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -103,7 +103,7 @@ var inquiryHandler = mockRepository.StrictMock(); mockRepository.ReplayAll(); - IEnumerable calculations = new List + IEnumerable calculations = new[] { new PipingCalculationScenario(new GeneralPipingInput()) }; @@ -126,7 +126,7 @@ var inquiryHandler = mockRepository.StrictMock(); mockRepository.ReplayAll(); - IEnumerable calculations = new List + IEnumerable calculations = new[] { new PipingCalculationScenario(new GeneralPipingInput()) { Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/PipingSurfaceLinesCsvImporterTest.cs =================================================================== diff -u -r7c433a2fecb8c13011283032fefffa662b43c8f5 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/PipingSurfaceLinesCsvImporterTest.cs (.../PipingSurfaceLinesCsvImporterTest.cs) (revision 7c433a2fecb8c13011283032fefffa662b43c8f5) +++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/PipingSurfaceLinesCsvImporterTest.cs (.../PipingSurfaceLinesCsvImporterTest.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -191,9 +191,9 @@ var failureMechanism = new PipingFailureMechanism(); - int callCount = 0; - bool progressStarted = false; - bool progressCharacteristicPointsStarted = false; + var callCount = 0; + var progressStarted = false; + var progressCharacteristicPointsStarted = false; var surfaceLineUpdateStrategy = new TestSurfaceLineUpdateStrategy(); var importer = new PipingSurfaceLinesCsvImporter(failureMechanism.SurfaceLines, referenceLine, validFilePath, messageProvider, surfaceLineUpdateStrategy); @@ -287,7 +287,7 @@ Assert.IsTrue(File.Exists(validFilePath)); // Call - bool importResult = false; + var importResult = false; Action call = () => importResult = importer.Import(); // Assert @@ -308,7 +308,7 @@ // Sample some of the imported data: RingtoetsPipingSurfaceLine firstSurfaceLine = importTargetArray[0]; Assert.AreEqual("Rotterdam1", firstSurfaceLine.Name); - var geometryPoints = firstSurfaceLine.Points.ToArray(); + Point3D[] geometryPoints = firstSurfaceLine.Points.ToArray(); Assert.AreEqual(8, geometryPoints.Length); Assert.AreNotEqual(geometryPoints[0].X, geometryPoints[1].X, "Originally duplicate points at the start have been removed."); @@ -349,7 +349,7 @@ CollectionAssert.IsEmpty(failureMechanism.SurfaceLines); Assert.IsTrue(File.Exists(validFilePath)); - bool importResult = true; + var importResult = true; // Call Action call = () => importResult = importer.Import(); @@ -388,7 +388,7 @@ CollectionAssert.IsEmpty(failureMechanism.SurfaceLines); Assert.IsTrue(File.Exists(validFilePath)); - bool importResult = true; + var importResult = true; // Call Action call = () => importResult = importer.Import(); @@ -435,7 +435,7 @@ CollectionAssert.IsEmpty(failureMechanism.SurfaceLines); Assert.IsTrue(File.Exists(validFilePath)); - bool importResult = false; + var importResult = false; // Call Action call = () => importResult = importer.Import(); @@ -482,7 +482,7 @@ CollectionAssert.IsEmpty(failureMechanism.SurfaceLines); Assert.IsTrue(File.Exists(validFilePath)); - bool importResult = false; + var importResult = false; // Call Action call = () => importResult = importer.Import(); @@ -523,7 +523,7 @@ Assert.IsTrue(File.Exists(validFilePath)); // Setup (second part) - var importResult = importer.Import(); + bool importResult = importer.Import(); Assert.IsFalse(importResult); importer.SetProgressChanged(null); @@ -549,16 +549,16 @@ var surfaceLineUpdateStrategy = new TestSurfaceLineUpdateStrategy(); var importer = new PipingSurfaceLinesCsvImporter(failureMechanism.SurfaceLines, new ReferenceLine(), corruptPath, messageProvider, surfaceLineUpdateStrategy); - bool importResult = true; + var importResult = true; // Call Action call = () => importResult = importer.Import(); // Assert string internalErrorMessage = new FileReaderErrorMessageBuilder(corruptPath) .Build("Er zitten ongeldige tekens in het bestandspad. Alle tekens in het bestandspad moeten geldig zijn."); - var expectedLogMessage = string.Format(PipingPluginResources.PipingSurfaceLinesCsvImporter_CriticalErrorMessage_0_File_Skipped, - internalErrorMessage); + string expectedLogMessage = string.Format(PipingPluginResources.PipingSurfaceLinesCsvImporter_CriticalErrorMessage_0_File_Skipped, + internalErrorMessage); Tuple expectedLogMessageAndLevel = Tuple.Create(expectedLogMessage, LogLevelConstant.Error); TestHelper.AssertLogMessageWithLevelIsGenerated(call, expectedLogMessageAndLevel, 1); AssertUnsuccessfulImport(importResult, surfaceLineUpdateStrategy); @@ -646,7 +646,7 @@ var surfaceLineUpdateStrategy = new TestSurfaceLineUpdateStrategy(); var importer = new PipingSurfaceLinesCsvImporter(failureMechanism.SurfaceLines, new ReferenceLine(), corruptPath, messageProvider, surfaceLineUpdateStrategy); - bool importResult = true; + var importResult = true; // Call Action call = () => importResult = importer.Import(); @@ -675,7 +675,7 @@ var messageProvider = mocks.Stub(); mocks.ReplayAll(); - var copyTargetPath = TestHelper.GetScratchPadPath($"{nameof(Import_FileDeletedDuringRead_AbortImportAndLog)}.csv"); + string copyTargetPath = TestHelper.GetScratchPadPath($"{nameof(Import_FileDeletedDuringRead_AbortImportAndLog)}.csv"); string validFilePath = Path.Combine(ioTestDataPath, "TwoValidSurfaceLines.csv"); File.Copy(validFilePath, copyTargetPath); @@ -787,7 +787,7 @@ var failureMechanism = new PipingFailureMechanism(); - int progressCallCount = 0; + var progressCallCount = 0; var surfaceLineUpdateStrategy = new TestSurfaceLineUpdateStrategy(); var importer = new PipingSurfaceLinesCsvImporter(failureMechanism.SurfaceLines, referenceLine, corruptPath, messageProvider, surfaceLineUpdateStrategy); importer.SetProgressChanged((name, step, steps) => progressCallCount++); @@ -959,8 +959,8 @@ Action call = () => importResult = importer.Import(); // Assert - var expectedLogMessage = string.Format(PipingPluginResources.PipingSurfaceLinesCsvImporter_Import_No_characteristic_points_file_for_surface_line_file_expecting_file_0_, - nonExistingCharacteristicFile); + string expectedLogMessage = string.Format(PipingPluginResources.PipingSurfaceLinesCsvImporter_Import_No_characteristic_points_file_for_surface_line_file_expecting_file_0_, + nonExistingCharacteristicFile); Tuple expectedLogMessageAndLevel = Tuple.Create(expectedLogMessage, LogLevelConstant.Info); TestHelper.AssertLogMessageWithLevelIsGenerated(call, expectedLogMessageAndLevel, 3); @@ -1201,7 +1201,7 @@ var failureMechanism = new PipingFailureMechanism(); - int progressCallCount = 0; + var progressCallCount = 0; var surfaceLineUpdateStrategy = new TestSurfaceLineUpdateStrategy(); var importer = new PipingSurfaceLinesCsvImporter(failureMechanism.SurfaceLines, referenceLine, surfaceLinesFile, messageProvider, surfaceLineUpdateStrategy); importer.SetProgressChanged((name, step, steps) => progressCallCount++); @@ -1274,7 +1274,7 @@ var failureMechanism = new PipingFailureMechanism(); - int progressCallCount = 0; + var progressCallCount = 0; var surfaceLineUpdateStrategy = new TestSurfaceLineUpdateStrategy(); var importer = new PipingSurfaceLinesCsvImporter(failureMechanism.SurfaceLines, referenceLine, surfaceLinesPath, messageProvider, surfaceLineUpdateStrategy); importer.SetProgressChanged((name, step, steps) => progressCallCount++); @@ -1341,7 +1341,7 @@ var failureMechanism = new PipingFailureMechanism(); - int progressCallCount = 0; + var progressCallCount = 0; var surfaceLineUpdateStrategy = new TestSurfaceLineUpdateStrategy(); var importer = new PipingSurfaceLinesCsvImporter(failureMechanism.SurfaceLines, referenceLine, surfaceLinesPath, messageProvider, surfaceLineUpdateStrategy); importer.SetProgressChanged((name, step, steps) => progressCallCount++); @@ -1413,7 +1413,7 @@ var failureMechanism = new PipingFailureMechanism(); - int progressCallCount = 0; + var progressCallCount = 0; var surfaceLineUpdateStrategy = new TestSurfaceLineUpdateStrategy(); var importer = new PipingSurfaceLinesCsvImporter(failureMechanism.SurfaceLines, referenceLine, surfaceLinesPath, messageProvider, surfaceLineUpdateStrategy); importer.SetProgressChanged((name, step, steps) => progressCallCount++); @@ -1424,9 +1424,9 @@ Action call = () => importResult = importer.Import(); // Assert - var pointFormat = string.Format(PipingDataResources.RingtoetsPipingSurfaceLine_SetCharacteristicPointAt_Geometry_does_not_contain_point_at_0_to_assign_as_characteristic_point_1_, - new Point3D(0, 1, 2), - characteristicPointName); + string pointFormat = string.Format(PipingDataResources.RingtoetsPipingSurfaceLine_SetCharacteristicPointAt_Geometry_does_not_contain_point_at_0_to_assign_as_characteristic_point_1_, + new Point3D(0, 1, 2), + characteristicPointName); var expectedLogMessages = new[] { Tuple.Create(string.Format(PipingPluginResources.PipingSurfaceLinesCsvImporter_ReadSurfaceLines_Start_reading_surface_lines_from_File_0_, @@ -1492,9 +1492,9 @@ var failureMechanism = new PipingFailureMechanism(); - int callCount = 0; - bool progressStarted = false; - bool progressCharacteristicPointsStarted = false; + var callCount = 0; + var progressStarted = false; + var progressCharacteristicPointsStarted = false; var surfaceLineUpdateStrategy = new TestSurfaceLineUpdateStrategy(); var importer = new PipingSurfaceLinesCsvImporter(failureMechanism.SurfaceLines, referenceLine, validSurfaceLinesFilePath, messageProvider, surfaceLineUpdateStrategy); @@ -1709,8 +1709,8 @@ Action call = () => importResult = importer.Import(); // Assert - var message = string.Format(PipingPluginResources.PipingSurfaceLinesCsvImporter_CheckCharacteristicPoints_EntryPointL_greater_or_equal_to_ExitPointL_for_0_, - "ArtifcialLocal"); + string message = string.Format(PipingPluginResources.PipingSurfaceLinesCsvImporter_CheckCharacteristicPoints_EntryPointL_greater_or_equal_to_ExitPointL_for_0_, + "ArtifcialLocal"); Tuple expectedLogMessageAndLevel = Tuple.Create(message, LogLevelConstant.Warn); TestHelper.AssertLogMessageWithLevelIsGenerated(call, expectedLogMessageAndLevel); @@ -1727,7 +1727,6 @@ public void DoPostImport_AfterImport_ObserversNotified() { // Setup - var mocks = new MockRepository(); var observableA = mocks.StrictMock(); observableA.Expect(o => o.NotifyObservers()); var observableB = mocks.StrictMock(); @@ -1805,7 +1804,7 @@ public RingtoetsPipingSurfaceLine[] ReadSurfaceLines { get; private set; } public IEnumerable UpdatedInstances { private get; set; } = Enumerable.Empty(); - public IEnumerable UpdateSurfaceLinesWithImportedData(RingtoetsPipingSurfaceLineCollection targetCollection, + public IEnumerable UpdateSurfaceLinesWithImportedData(RingtoetsPipingSurfaceLineCollection targetDataCollection, IEnumerable readRingtoetsPipingSurfaceLines, string sourceFilePath) { Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/RingtoetsPipingSurfaceLineReplaceDataStrategyTest.cs =================================================================== diff -u -raae2ecaacbb094fe66d6a54d6ac4b1e6780b0864 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/RingtoetsPipingSurfaceLineReplaceDataStrategyTest.cs (.../RingtoetsPipingSurfaceLineReplaceDataStrategyTest.cs) (revision aae2ecaacbb094fe66d6a54d6ac4b1e6780b0864) +++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/RingtoetsPipingSurfaceLineReplaceDataStrategyTest.cs (.../RingtoetsPipingSurfaceLineReplaceDataStrategyTest.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -25,6 +25,7 @@ using Core.Common.Base; using Core.Common.Base.Geometry; using NUnit.Framework; +using Ringtoets.Common.Data.Exceptions; using Ringtoets.Common.Data.UpdateDataStrategies; using Ringtoets.Piping.Data; using Ringtoets.Piping.IO.Exceptions; @@ -72,7 +73,7 @@ // Assert string paramName = Assert.Throws(test).ParamName; - Assert.AreEqual("targetCollection", paramName); + Assert.AreEqual("targetDataCollection", paramName); } [Test] @@ -82,7 +83,7 @@ var strategy = new RingtoetsPipingSurfaceLineReplaceDataStrategy(new PipingFailureMechanism()); // Call - TestDelegate test = () => strategy.UpdateSurfaceLinesWithImportedData(new RingtoetsPipingSurfaceLineCollection(), + TestDelegate test = () => strategy.UpdateSurfaceLinesWithImportedData(new RingtoetsPipingSurfaceLineCollection(), null, string.Empty); @@ -98,7 +99,7 @@ var strategy = new RingtoetsPipingSurfaceLineReplaceDataStrategy(new PipingFailureMechanism()); // Call - TestDelegate test = () => strategy.UpdateSurfaceLinesWithImportedData(new RingtoetsPipingSurfaceLineCollection(), + TestDelegate test = () => strategy.UpdateSurfaceLinesWithImportedData(new RingtoetsPipingSurfaceLineCollection(), Enumerable.Empty(), null); @@ -236,8 +237,12 @@ // Assert Assert.IsFalse(calculation.HasOutput); Assert.IsNull(calculation.InputParameters.SurfaceLine); - CollectionAssert.Contains(affectedObjects, calculation); - CollectionAssert.Contains(affectedObjects, calculation.InputParameters); + CollectionAssert.AreEquivalent(new IObservable[] + { + calculation, + calculation.InputParameters, + failureMechanism.SurfaceLines + }, affectedObjects); } [Test] @@ -268,9 +273,10 @@ // Assert var exception = Assert.Throws(call); - string expectedMessage = $"Profielschematisaties moeten een unieke naam hebben. Gevonden dubbele elementen: {duplicateName}."; + string expectedMessage = "Het importeren van profielschematisaties is mislukt: " + + $"Profielschematisaties moeten een unieke naam hebben. Gevonden dubbele elementen: {duplicateName}."; Assert.AreEqual(expectedMessage, exception.Message); - Assert.IsInstanceOf(exception.InnerException); + Assert.IsInstanceOf(exception.InnerException); } } } \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/RingtoetsPipingSurfaceLineUpdateDataStrategyTest.cs =================================================================== diff -u -r9997d3038d16fb710ffc92f95c781639d63d7855 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/RingtoetsPipingSurfaceLineUpdateDataStrategyTest.cs (.../RingtoetsPipingSurfaceLineUpdateDataStrategyTest.cs) (revision 9997d3038d16fb710ffc92f95c781639d63d7855) +++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/RingtoetsPipingSurfaceLineUpdateDataStrategyTest.cs (.../RingtoetsPipingSurfaceLineUpdateDataStrategyTest.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -26,6 +26,7 @@ using Core.Common.Base.Data; using Core.Common.Base.Geometry; using NUnit.Framework; +using Ringtoets.Common.Data.Exceptions; using Ringtoets.Common.Data.UpdateDataStrategies; using Ringtoets.Piping.Data; using Ringtoets.Piping.Data.TestUtil; @@ -299,10 +300,12 @@ // Assert var exception = Assert.Throws(call); - string message = $"Profielschematisaties moeten een unieke naam hebben. Gevonden dubbele elementen: {duplicateName}."; - Assert.AreEqual(message, exception.Message); - Assert.IsInstanceOf(exception.InnerException); + string expectedMessage = "Het bijwerken van de profielschematisaties is mislukt: " + + $"Profielschematisaties moeten een unieke naam hebben. Gevonden dubbele elementen: {duplicateName}."; + Assert.AreEqual(expectedMessage, exception.Message); + Assert.IsInstanceOf(exception.InnerException); + CollectionAssert.IsEmpty(targetCollection); } @@ -387,8 +390,10 @@ // Assert var exception = Assert.Throws(call); - Assert.AreEqual("Het bijwerken van de profielschematisaties is mislukt.", exception.Message); - Assert.IsInstanceOf(exception.InnerException); + string expectedMessage = "Het bijwerken van de profielschematisaties is mislukt: " + + "Geïmporteerde data moet unieke elementen bevatten."; + Assert.AreEqual(expectedMessage, exception.Message); + Assert.IsInstanceOf(exception.InnerException); CollectionAssert.AreEqual(expectedCollection, targetCollection); RingtoetsPipingSurfaceLine actualSurfaceLine = targetCollection[0]; @@ -1120,7 +1125,8 @@ InputParameters = { SurfaceLine = affectedSurfaceLine - } + }, + Output = new TestPipingOutput() }; var failureMechanism = new PipingFailureMechanism(); @@ -1148,6 +1154,7 @@ { failureMechanism.SurfaceLines, affectedSurfaceLine, + affectedCalculation, affectedCalculation.InputParameters }, affectedObjects); } Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/StochasticSoilModelReplaceDataStrategyTest.cs =================================================================== diff -u -raae2ecaacbb094fe66d6a54d6ac4b1e6780b0864 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/StochasticSoilModelReplaceDataStrategyTest.cs (.../StochasticSoilModelReplaceDataStrategyTest.cs) (revision aae2ecaacbb094fe66d6a54d6ac4b1e6780b0864) +++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/StochasticSoilModelReplaceDataStrategyTest.cs (.../StochasticSoilModelReplaceDataStrategyTest.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -24,6 +24,7 @@ using System.Linq; using Core.Common.Base; using NUnit.Framework; +using Ringtoets.Common.Data.Exceptions; using Ringtoets.Common.Data.UpdateDataStrategies; using Ringtoets.Piping.Data; using Ringtoets.Piping.Data.TestUtil; @@ -99,7 +100,7 @@ // Assert string paramName = Assert.Throws(test).ParamName; - Assert.AreEqual("targetCollection", paramName); + Assert.AreEqual("targetDataCollection", paramName); } [Test] @@ -210,8 +211,12 @@ Assert.IsFalse(calculation.HasOutput); Assert.IsNull(calculation.InputParameters.StochasticSoilModel); Assert.IsNull(calculation.InputParameters.StochasticSoilProfile); - CollectionAssert.Contains(affectedObjects, calculation); - CollectionAssert.Contains(affectedObjects, calculation.InputParameters); + CollectionAssert.AreEquivalent(new IObservable[] + { + calculation, + calculation.InputParameters, + failureMechanism.StochasticSoilModels + }, affectedObjects); } [Test] @@ -231,8 +236,9 @@ // Assert var exception = Assert.Throws(test); - Assert.AreEqual("Stochastische ondergrondmodellen moeten een unieke naam hebben. Gevonden dubbele elementen: B.", exception.Message); - Assert.IsInstanceOf(exception.InnerException); + Assert.AreEqual("Het importeren van stochastische ondergrondmodellen is mislukt: " + + "Stochastische ondergrondmodellen moeten een unieke naam hebben. Gevonden dubbele elementen: B.", exception.Message); + Assert.IsInstanceOf(exception.InnerException); } } } \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/StochasticSoilModelUpdateDataStrategyTest.cs =================================================================== diff -u -r9997d3038d16fb710ffc92f95c781639d63d7855 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/StochasticSoilModelUpdateDataStrategyTest.cs (.../StochasticSoilModelUpdateDataStrategyTest.cs) (revision 9997d3038d16fb710ffc92f95c781639d63d7855) +++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/StochasticSoilModelUpdateDataStrategyTest.cs (.../StochasticSoilModelUpdateDataStrategyTest.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -24,6 +24,7 @@ using System.Linq; using Core.Common.Base; using NUnit.Framework; +using Ringtoets.Common.Data.Exceptions; using Ringtoets.Common.Data.UpdateDataStrategies; using Ringtoets.Piping.Data; using Ringtoets.Piping.Data.TestUtil; @@ -128,8 +129,10 @@ // Assert var exception = Assert.Throws(test); - Assert.AreEqual("Het bijwerken van de stochastische ondergrondmodellen is mislukt.", exception.Message); - Assert.IsInstanceOf(exception.InnerException); + const string expectedMessage = "Het bijwerken van de stochastische ondergrondmodellen is mislukt: " + + "Geïmporteerde data moet unieke elementen bevatten."; + Assert.AreEqual(expectedMessage, exception.Message); + Assert.IsInstanceOf(exception.InnerException); } [Test] @@ -152,8 +155,10 @@ // Assert var exception = Assert.Throws(test); - Assert.AreEqual("Stochastische ondergrondmodellen moeten een unieke naam hebben. Gevonden dubbele elementen: non-unique name.", exception.Message); - Assert.IsInstanceOf(exception.InnerException); + const string expectedMessage = "Het bijwerken van de stochastische ondergrondmodellen is mislukt: " + + "Stochastische ondergrondmodellen moeten een unieke naam hebben. Gevonden dubbele elementen: non-unique name."; + Assert.AreEqual(expectedMessage, exception.Message); + Assert.IsInstanceOf(exception.InnerException); CollectionAssert.IsEmpty(targetCollection); } @@ -162,7 +167,7 @@ public void UpdateModelWithImportedData_WithoutCurrentModelAndNoImportedModels_NoChangeNoNotification() { // Setup - var importedStochasticSoilModels = Enumerable.Empty(); + IEnumerable importedStochasticSoilModels = Enumerable.Empty(); var strategy = new StochasticSoilModelUpdateDataStrategy(new PipingFailureMechanism()); var targetCollection = new StochasticSoilModelCollection(); Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/ImportInfos/RingtoetsPipingSurfaceLinesContextImportInfoTest.cs =================================================================== diff -u -r07d5be33d21f07a72ac836b16e9639e7118c8af6 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/ImportInfos/RingtoetsPipingSurfaceLinesContextImportInfoTest.cs (.../RingtoetsPipingSurfaceLinesContextImportInfoTest.cs) (revision 07d5be33d21f07a72ac836b16e9639e7118c8af6) +++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/ImportInfos/RingtoetsPipingSurfaceLinesContextImportInfoTest.cs (.../RingtoetsPipingSurfaceLinesContextImportInfoTest.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -163,10 +163,10 @@ var context = new RingtoetsPipingSurfaceLinesContext(surfaceLines, failureMechanism, assessmentSection); // Call - bool requiresUpdateConfirmation = importInfo.VerifyUpdates(context); + bool updatesVerified = importInfo.VerifyUpdates(context); // Assert - Assert.IsTrue(requiresUpdateConfirmation); + Assert.IsTrue(updatesVerified); mocks.VerifyAll(); } @@ -213,14 +213,14 @@ }; // Call - bool requiresUpdateConfirmation = importInfo.VerifyUpdates(context); + bool updatesVerified = importInfo.VerifyUpdates(context); // Assert string expectedInquiryMessage = "Als u profielschematisaties importeert, " + "dan worden alle rekenresultaten van dit toetsspoor verwijderd." + $"{Environment.NewLine}{Environment.NewLine}Weet u zeker dat u wilt doorgaan?"; Assert.AreEqual(expectedInquiryMessage, textBoxMessage); - Assert.AreEqual(isActionConfirmed, requiresUpdateConfirmation); + Assert.AreEqual(isActionConfirmed, updatesVerified); mocks.VerifyAll(); } Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/ImportInfos/StochasticSoilModelCollectionContextImportInfoTest.cs =================================================================== diff -u -r7c433a2fecb8c13011283032fefffa662b43c8f5 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/ImportInfos/StochasticSoilModelCollectionContextImportInfoTest.cs (.../StochasticSoilModelCollectionContextImportInfoTest.cs) (revision 7c433a2fecb8c13011283032fefffa662b43c8f5) +++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/ImportInfos/StochasticSoilModelCollectionContextImportInfoTest.cs (.../StochasticSoilModelCollectionContextImportInfoTest.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -161,10 +161,10 @@ var context = new StochasticSoilModelCollectionContext(stochasticSoilModelCollection, failureMechanism, assessmentSection); // Call - bool requiresUpdateConfirmation = importInfo.VerifyUpdates(context); + bool updatesVerified = importInfo.VerifyUpdates(context); // Assert - Assert.IsTrue(requiresUpdateConfirmation); + Assert.IsTrue(updatesVerified); mocks.VerifyAll(); } @@ -211,14 +211,14 @@ }; // Call - bool requiresUpdateConfirmation = importInfo.VerifyUpdates(context); + bool updatesVerified = importInfo.VerifyUpdates(context); // Assert string expectedInquiryMessage = "Als u stochastische ondergrondmodellen importeert, " + "dan worden alle rekenresultaten van dit toetsspoor verwijderd." + $"{Environment.NewLine}{Environment.NewLine}Weet u zeker dat u wilt doorgaan?"; Assert.AreEqual(expectedInquiryMessage, textBoxMessage); - Assert.AreEqual(isActionConfirmed, requiresUpdateConfirmation); + Assert.AreEqual(isActionConfirmed, updatesVerified); mocks.VerifyAll(); } Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/Ringtoets.Piping.Plugin.Test.csproj =================================================================== diff -u -r4ce9ecef7e93f14065e8a0c79a81ce43ab2f4c0f -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/Ringtoets.Piping.Plugin.Test.csproj (.../Ringtoets.Piping.Plugin.Test.csproj) (revision 4ce9ecef7e93f14065e8a0c79a81ce43ab2f4c0f) +++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/Ringtoets.Piping.Plugin.Test.csproj (.../Ringtoets.Piping.Plugin.Test.csproj) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -75,10 +75,8 @@ - - Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/TreeNodeInfos/PipingCalculationScenarioContextTreeNodeInfoTest.cs =================================================================== diff -u -rc132a551ca0b4be0f9909e2e53d43e064b2cadb1 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/TreeNodeInfos/PipingCalculationScenarioContextTreeNodeInfoTest.cs (.../PipingCalculationScenarioContextTreeNodeInfoTest.cs) (revision c132a551ca0b4be0f9909e2e53d43e064b2cadb1) +++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/TreeNodeInfos/PipingCalculationScenarioContextTreeNodeInfoTest.cs (.../PipingCalculationScenarioContextTreeNodeInfoTest.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -286,19 +286,20 @@ using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) { // Assert - TestHelper.AssertContextMenuStripContainsItem(contextMenu, - contextMenuCalculateIndex, - "Be&rekenen", - "De bijdrage van dit toetsspoor is nul.", - RingtoetsCommonFormsResources.CalculateIcon, - false); TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuValidateIndex, "&Valideren", "De bijdrage van dit toetsspoor is nul.", RingtoetsCommonFormsResources.ValidateIcon, false); + + TestHelper.AssertContextMenuStripContainsItem(contextMenu, + contextMenuCalculateIndex, + "Be&rekenen", + "De bijdrage van dit toetsspoor is nul.", + RingtoetsCommonFormsResources.CalculateIcon, + false); } } } @@ -329,16 +330,16 @@ { // Assert TestHelper.AssertContextMenuStripContainsItem(contextMenu, - contextMenuCalculateIndex, - "Be&rekenen", - "Voer deze berekening uit.", - RingtoetsCommonFormsResources.CalculateIcon); - - TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuValidateIndex, "&Valideren", "Valideer de invoer voor deze berekening.", RingtoetsCommonFormsResources.ValidateIcon); + + TestHelper.AssertContextMenuStripContainsItem(contextMenu, + contextMenuCalculateIndex, + "Be&rekenen", + "Voer deze berekening uit.", + RingtoetsCommonFormsResources.CalculateIcon); } } } Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/TreeNodeInfos/RingtoetsPipingSurfaceLineCollectionTreeNodeInfoTest.cs =================================================================== diff -u -r0b28e0b79a31d36c59eb077d172faf73c3c4b65d -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/TreeNodeInfos/RingtoetsPipingSurfaceLineCollectionTreeNodeInfoTest.cs (.../RingtoetsPipingSurfaceLineCollectionTreeNodeInfoTest.cs) (revision 0b28e0b79a31d36c59eb077d172faf73c3c4b65d) +++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/TreeNodeInfos/RingtoetsPipingSurfaceLineCollectionTreeNodeInfoTest.cs (.../RingtoetsPipingSurfaceLineCollectionTreeNodeInfoTest.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -218,7 +218,6 @@ menuBuilderMock.Expect(mb => mb.AddImportItem()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddUpdateItem()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); - menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddCollapseAllItem()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddExpandAllItem()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/UpdateInfos/RingtoetsPipingSurfaceLinesContextUpdateInfoTest.cs =================================================================== diff -u -r07d5be33d21f07a72ac836b16e9639e7118c8af6 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/UpdateInfos/RingtoetsPipingSurfaceLinesContextUpdateInfoTest.cs (.../RingtoetsPipingSurfaceLinesContextUpdateInfoTest.cs) (revision 07d5be33d21f07a72ac836b16e9639e7118c8af6) +++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/UpdateInfos/RingtoetsPipingSurfaceLinesContextUpdateInfoTest.cs (.../RingtoetsPipingSurfaceLinesContextUpdateInfoTest.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -164,10 +164,10 @@ var context = new RingtoetsPipingSurfaceLinesContext(surfaceLines, failureMechanism, assessmentSection); // Call - bool requiresUpdateConfirmation = updateInfo.VerifyUpdates(context); + bool updatesVerified = updateInfo.VerifyUpdates(context); // Assert - Assert.IsTrue(requiresUpdateConfirmation); + Assert.IsTrue(updatesVerified); mocks.VerifyAll(); } @@ -214,14 +214,14 @@ }; // Call - bool requiresUpdateConfirmation = updateInfo.VerifyUpdates(context); + bool updatesVerified = updateInfo.VerifyUpdates(context); // Assert string expectedInquiryMessage = "Als profielschematisaties wijzigen door het bijwerken, " + "dan worden de resultaten van berekeningen die deze profielschematisaties gebruiken " + $"verwijderd.{Environment.NewLine}{Environment.NewLine}Weet u zeker dat u wilt doorgaan?"; Assert.AreEqual(expectedInquiryMessage, textBoxMessage); - Assert.AreEqual(isActionConfirmed, requiresUpdateConfirmation); + Assert.AreEqual(isActionConfirmed, updatesVerified); mocks.VerifyAll(); } Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/UpdateInfos/StochasticSoilModelCollectionContextUpdateInfoTest.cs =================================================================== diff -u -r07d5be33d21f07a72ac836b16e9639e7118c8af6 -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/UpdateInfos/StochasticSoilModelCollectionContextUpdateInfoTest.cs (.../StochasticSoilModelCollectionContextUpdateInfoTest.cs) (revision 07d5be33d21f07a72ac836b16e9639e7118c8af6) +++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/UpdateInfos/StochasticSoilModelCollectionContextUpdateInfoTest.cs (.../StochasticSoilModelCollectionContextUpdateInfoTest.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -162,10 +162,10 @@ var context = new StochasticSoilModelCollectionContext(stochasticSoilModelCollection, failureMechanism, assessmentSection); // Call - bool requiresUpdateConfirmation = updateInfo.VerifyUpdates(context); + bool updatesVerified = updateInfo.VerifyUpdates(context); // Assert - Assert.IsTrue(requiresUpdateConfirmation); + Assert.IsTrue(updatesVerified); mocks.VerifyAll(); } @@ -212,14 +212,14 @@ }; // Call - bool requiresUpdateConfirmation = updateInfo.VerifyUpdates(context); + bool updatesVerified = updateInfo.VerifyUpdates(context); // Assert string expectedInquiryMessage = "Als ondergrondschematisaties wijzigen door het bijwerken, " + "dan worden de resultaten van berekeningen die deze ondergrondschematisaties gebruiken " + $"verwijderd.{Environment.NewLine}{Environment.NewLine}Weet u zeker dat u wilt doorgaan?"; Assert.AreEqual(expectedInquiryMessage, textBoxMessage); - Assert.AreEqual(isActionConfirmed, requiresUpdateConfirmation); + Assert.AreEqual(isActionConfirmed, updatesVerified); mocks.VerifyAll(); } Index: build/DatabaseStructure.sql =================================================================== diff -u -rfe88135b797eda12b8e4d9b829036d2d7a52b10f -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- build/DatabaseStructure.sql (.../DatabaseStructure.sql) (revision fe88135b797eda12b8e4d9b829036d2d7a52b10f) +++ build/DatabaseStructure.sql (.../DatabaseStructure.sql) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -1,6 +1,6 @@ /* ---------------------------------------------------- */ /* Generated by Enterprise Architect Version 12.0 */ -/* Created On : 10-Apr-2017 13:58:22 */ +/* Created On : 11-Apr-2017 10:44:39 */ /* DBMS : SQLite */ /* ---------------------------------------------------- */ @@ -464,6 +464,7 @@ 'GrassCoverErosionInwardsFailureMechanismMetaEntityId' INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, 'FailureMechanismEntityId' INTEGER NOT NULL, 'N' INT (4) NOT NULL, + 'DikeProfileCollectionSourcePath' TEXT, CONSTRAINT 'FK_GrassCoverErosionInwardsFailureMechanismMetaEntity_FailureMechanismEntity' FOREIGN KEY ('FailureMechanismEntityId') REFERENCES 'FailureMechanismEntity' ('FailureMechanismEntityId') ON DELETE Cascade ON UPDATE Cascade ) ; @@ -841,7 +842,8 @@ 'Y' REAL, 'X0' REAL, 'Order' INT (4) NOT NULL, - CONSTRAINT 'FK_DikeProfileEntity_FailureMechanismEntity' FOREIGN KEY ('FailureMechanismEntityId') REFERENCES 'FailureMechanismEntity' ('FailureMechanismEntityId') ON DELETE Cascade ON UPDATE Cascade + CONSTRAINT 'FK_DikeProfileEntity_FailureMechanismEntity' FOREIGN KEY ('FailureMechanismEntityId') REFERENCES 'FailureMechanismEntity' ('FailureMechanismEntityId') ON DELETE Cascade ON UPDATE Cascade, + CONSTRAINT 'UQ_DikeProfileEntity_IdFailureMechanismEntityId' UNIQUE ('Id','FailureMechanismEntityId') ) ; Index: design/DatabaseDesign.eap =================================================================== diff -u -rfe88135b797eda12b8e4d9b829036d2d7a52b10f -r56ac4eb28f5fcc5b20117474e9e4030399d6806a Binary files differ Index: design/OpslagMapping.xlsx =================================================================== diff -u -rfe88135b797eda12b8e4d9b829036d2d7a52b10f -r56ac4eb28f5fcc5b20117474e9e4030399d6806a Binary files differ