Index: Ringtoets/Common/test/Ringtoets.Common.Data.TestUtil.Test/TestCalculationWithForeshoreProfileTest.cs =================================================================== diff -u -rb046a5ad0ed9a756aea88e9c0ad543bf657877f9 -rc37f276833a0c2638b9514f528f3434c8d68199c --- Ringtoets/Common/test/Ringtoets.Common.Data.TestUtil.Test/TestCalculationWithForeshoreProfileTest.cs (.../TestCalculationWithForeshoreProfileTest.cs) (revision b046a5ad0ed9a756aea88e9c0ad543bf657877f9) +++ Ringtoets/Common/test/Ringtoets.Common.Data.TestUtil.Test/TestCalculationWithForeshoreProfileTest.cs (.../TestCalculationWithForeshoreProfileTest.cs) (revision c37f276833a0c2638b9514f528f3434c8d68199c) @@ -19,7 +19,9 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using Core.Common.Base; using NUnit.Framework; +using Ringtoets.Common.Data.Calculation; namespace Ringtoets.Common.Data.TestUtil.Test { @@ -34,9 +36,16 @@ TestCalculationWithForeshoreProfile.CreateDefaultCalculation(); // Assert + Assert.IsInstanceOf(calculation); + Assert.IsInstanceOf(calculation); Assert.IsFalse(calculation.HasOutput); - Assert.IsNull(calculation.InputParameters.ForeshoreProfile); Assert.IsNull(calculation.Comments); + + TestCalculationWithForeshoreProfile.TestCalculationInputWithForeshoreProfile input = + calculation.InputParameters; + Assert.IsNull(input.ForeshoreProfile); + Assert.IsFalse(input.UseForeshore); + Assert.IsNull(input.ForeshoreGeometry); } [Test] @@ -57,9 +66,24 @@ TestCalculationWithForeshoreProfile.CreateCalculationWithOutput(foreshoreProfile); // Assert + Assert.IsInstanceOf(calculation); + Assert.IsInstanceOf(calculation); Assert.IsTrue(calculation.HasOutput); - Assert.AreSame(foreshoreProfile, calculation.InputParameters.ForeshoreProfile); Assert.IsNull(calculation.Comments); + + TestCalculationWithForeshoreProfile.TestCalculationInputWithForeshoreProfile input = + calculation.InputParameters; + Assert.AreSame(foreshoreProfile, input.ForeshoreProfile); + Assert.IsFalse(input.UseForeshore); + + if (hasForeshoreProfile) + { + Assert.AreSame(foreshoreProfile.Geometry, input.ForeshoreGeometry); + } + else + { + Assert.IsNull(input.ForeshoreGeometry); + } } [Test] @@ -80,9 +104,24 @@ TestCalculationWithForeshoreProfile.CreateCalculationWithoutOutput(foreshoreProfile); // Assert + Assert.IsInstanceOf(calculation); + Assert.IsInstanceOf(calculation); Assert.IsFalse(calculation.HasOutput); - Assert.AreSame(foreshoreProfile, calculation.InputParameters.ForeshoreProfile); Assert.IsNull(calculation.Comments); + + TestCalculationWithForeshoreProfile.TestCalculationInputWithForeshoreProfile input = + calculation.InputParameters; + Assert.AreSame(foreshoreProfile, input.ForeshoreProfile); + Assert.IsFalse(input.UseForeshore); + + if (hasForeshoreProfile) + { + Assert.AreSame(foreshoreProfile.Geometry, input.ForeshoreGeometry); + } + else + { + Assert.IsNull(input.ForeshoreGeometry); + } } [Test] Index: Ringtoets/Common/test/Ringtoets.Common.Data.TestUtil/TestCalculationWithForeshoreProfile.cs =================================================================== diff -u -r38bc3bb60b50bdfb98f76be1e03f6d663733008d -rc37f276833a0c2638b9514f528f3434c8d68199c --- Ringtoets/Common/test/Ringtoets.Common.Data.TestUtil/TestCalculationWithForeshoreProfile.cs (.../TestCalculationWithForeshoreProfile.cs) (revision 38bc3bb60b50bdfb98f76be1e03f6d663733008d) +++ Ringtoets/Common/test/Ringtoets.Common.Data.TestUtil/TestCalculationWithForeshoreProfile.cs (.../TestCalculationWithForeshoreProfile.cs) (revision c37f276833a0c2638b9514f528f3434c8d68199c) @@ -21,6 +21,7 @@ using System; using Core.Common.Base; +using Core.Common.Base.Data; using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.DikeProfiles; @@ -102,9 +103,21 @@ /// /// A simple input class with a . /// - public class TestCalculationInputWithForeshoreProfile : ICalculationInput, IHasForeshoreProfile + public class TestCalculationInputWithForeshoreProfile : ICalculationInput, IUseForeshore, IHasForeshoreProfile { + public ForeshoreProfile ForeshoreProfile { get; set; } + public bool IsForeshoreProfileInputSynchronized { get; } + public bool UseForeshore { get; set; } + + public RoundedPoint2DCollection ForeshoreGeometry + { + get + { + return ForeshoreProfile?.Geometry; + } + } + public void Attach(IObserver observer) { throw new NotImplementedException(); @@ -120,8 +133,6 @@ throw new NotImplementedException(); } - public ForeshoreProfile ForeshoreProfile { get; set; } - public bool IsForeshoreProfileInputSynchronized { get; } public void SynchronizeForeshoreProfileInput() { throw new NotImplementedException(); Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/FileImporters/ForeshoreProfileUpdateDataStrategy.cs =================================================================== diff -u -re3ec5f4669022733a11c4c3070747331bf36056f -rc37f276833a0c2638b9514f528f3434c8d68199c --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/FileImporters/ForeshoreProfileUpdateDataStrategy.cs (.../ForeshoreProfileUpdateDataStrategy.cs) (revision e3ec5f4669022733a11c4c3070747331bf36056f) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/FileImporters/ForeshoreProfileUpdateDataStrategy.cs (.../ForeshoreProfileUpdateDataStrategy.cs) (revision c37f276833a0c2638b9514f528f3434c8d68199c) @@ -56,23 +56,6 @@ return UpdateTargetCollectionData(targetDataCollection, importedDataCollection, sourceFilePath); } - protected override IEnumerable UpdateObjectAndDependentData(ForeshoreProfile objectToUpdate, ForeshoreProfile objectToUpdateFrom) - { - objectToUpdate.CopyProperties(objectToUpdateFrom); - - var affectedObjects = new List(); - - IEnumerable> affectedCalculations = GetAffectedCalculationWithSurfaceLines(objectToUpdate); - - foreach (ICalculation calculation in affectedCalculations) - { - affectedObjects.Add(calculation.InputParameters); - affectedObjects.AddRange(RingtoetsCommonDataSynchronizationService.ClearCalculationOutput(calculation)); - } - - return affectedObjects; - } - protected override IEnumerable RemoveObjectAndDependentData(ForeshoreProfile removedObject) { IEnumerable> affectedCalculations = GetAffectedCalculationWithSurfaceLines(removedObject); @@ -112,5 +95,36 @@ return obj.Id.GetHashCode(); } } + + #region Update Logic + + protected override IEnumerable UpdateObjectAndDependentData(ForeshoreProfile objectToUpdate, ForeshoreProfile objectToUpdateFrom) + { + objectToUpdate.CopyProperties(objectToUpdateFrom); + + var affectedObjects = new List(); + + IEnumerable> affectedCalculations = GetAffectedCalculationWithSurfaceLines(objectToUpdate); + + foreach (ICalculation calculation in affectedCalculations) + { + affectedObjects.Add(calculation.InputParameters); + affectedObjects.AddRange(RingtoetsCommonDataSynchronizationService.ClearCalculationOutput(calculation)); + + ValidateUseForeshore(calculation, objectToUpdate); + } + + return affectedObjects; + } + + private static void ValidateUseForeshore(ICalculation calculation, ForeshoreProfile foreshoreProfile) + { + if (!foreshoreProfile.Geometry.Any()) + { + ((IUseForeshore) calculation.InputParameters).UseForeshore = false; + } + } + + #endregion } } \ No newline at end of file Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/FileImporters/ForeshoreProfileUpdateDataStrategyTest.cs =================================================================== diff -u -r32ef1a284c06beac64572d830b50f291e390a66d -rc37f276833a0c2638b9514f528f3434c8d68199c --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/FileImporters/ForeshoreProfileUpdateDataStrategyTest.cs (.../ForeshoreProfileUpdateDataStrategyTest.cs) (revision 32ef1a284c06beac64572d830b50f291e390a66d) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/FileImporters/ForeshoreProfileUpdateDataStrategyTest.cs (.../ForeshoreProfileUpdateDataStrategyTest.cs) (revision c37f276833a0c2638b9514f528f3434c8d68199c) @@ -42,7 +42,7 @@ { private const string sourceFilePath = "some/path/to/foreshoreProfiles"; - private static IEnumerable DifferentForeshoreProfileWithSameID + private static IEnumerable DifferentForeshoreProfileWithSameId { get { @@ -164,7 +164,7 @@ } [Test] - [TestCaseSource(nameof(DifferentForeshoreProfileWithSameID))] + [TestCaseSource(nameof(DifferentForeshoreProfileWithSameId))] public void UpdateForeshoreProfilesWithImportedData_ForeshoreProfilePropertiesChanged_UpdateRelevantProperties( ForeshoreProfile readForeshoreProfile) { @@ -191,7 +191,7 @@ Assert.AreSame(profileToBeUpdated, targetCollection[0]); AssertForeshoreProfile(readForeshoreProfile, profileToBeUpdated); } - + [Test] public void UpdateForeshoreProfilesWithImportedData_CurrentCollectionEmptyImportedCollectionContainDuplicateIDs_ThrowUpdateException() { @@ -218,7 +218,7 @@ CollectionAssert.IsEmpty(foreshoreProfiles); } - + [Test] public void UpdateForeshoreProfilesWithImportedData_WithCurrentCollectionNotEmptyAndImportedCollectionHasProfilesWithSameId_ThrowsUpdateException() { @@ -524,6 +524,61 @@ }, affectedObjects); } + [Test] + public void UpdateForeshoreProfilesWithImportedData_CalculationWithOutputAndForeshoreProfileUpdatedWithProfileWithoutGeometry_UpdatesCalculation() + { + // Setup + const string id = "profile ID"; + IEnumerable geometry = new[] + { + new Point2D(1, 2), + new Point2D(3, 4) + }; + + var affectedProfile = new TestForeshoreProfile(id, geometry); + TestCalculationWithForeshoreProfile affectedCalculation = + TestCalculationWithForeshoreProfile.CreateCalculationWithOutput(affectedProfile); + affectedCalculation.InputParameters.UseForeshore = true; + + var profileToUpdateFrom = new TestForeshoreProfile(id, Enumerable.Empty()); + + var foreshoreProfiles = new ForeshoreProfileCollection(); + var originalForeshoreProfiles = new[] + { + affectedProfile + }; + foreshoreProfiles.AddRange(originalForeshoreProfiles, sourceFilePath); + + var failureMechanism = new TestFailureMechanism(new[] + { + affectedCalculation + }); + + var strategy = new ForeshoreProfileUpdateDataStrategy(failureMechanism); + + // Call + IEnumerable affectedObjects = + strategy.UpdateForeshoreProfilesWithImportedData(foreshoreProfiles, + new[] + { + profileToUpdateFrom + }, + sourceFilePath); + + // Assert + Assert.IsFalse(affectedCalculation.HasOutput); + Assert.IsFalse(affectedCalculation.InputParameters.UseForeshore); + AssertForeshoreProfile(affectedProfile, profileToUpdateFrom); + + CollectionAssert.AreEquivalent(new IObservable[] + { + affectedCalculation, + affectedCalculation.InputParameters, + affectedProfile, + foreshoreProfiles + }, affectedObjects); + } + /// /// Makes a deep clone of the foreshore profile and modifies all the properties, /// except the .