Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Helpers/SynchronizeCalculationWithForeshoreProfileHelper.cs =================================================================== diff -u -r89a67df36f92a18beb34c2978db1332f8525214d -rb7c78a363e31e9911179086d4aa73561deb6b4d4 --- Ringtoets/Common/src/Ringtoets.Common.Forms/Helpers/SynchronizeCalculationWithForeshoreProfileHelper.cs (.../SynchronizeCalculationWithForeshoreProfileHelper.cs) (revision 89a67df36f92a18beb34c2978db1332f8525214d) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/Helpers/SynchronizeCalculationWithForeshoreProfileHelper.cs (.../SynchronizeCalculationWithForeshoreProfileHelper.cs) (revision b7c78a363e31e9911179086d4aa73561deb6b4d4) @@ -43,21 +43,23 @@ public static void UpdateForeshoreProfileDerivedCalculationInput(ICalculation calculation) where TInput : ICalculationInput, IHasForeshoreProfile { - if (!calculation.InputParameters.IsForeshoreProfileParametersSynchronized) + if (calculation.InputParameters.IsForeshoreProfileParametersSynchronized) { - calculation.InputParameters.SynchronizeForeshoreProfileParameters(); + return; + } - var affectedObjects = new List - { - calculation.InputParameters - }; + calculation.InputParameters.SynchronizeForeshoreProfileParameters(); - affectedObjects.AddRange(RingtoetsCommonDataSynchronizationService.ClearCalculationOutput(calculation)); + var affectedObjects = new List + { + calculation.InputParameters + }; - foreach (IObservable affectedObject in affectedObjects) - { - affectedObject.NotifyObservers(); - } + affectedObjects.AddRange(RingtoetsCommonDataSynchronizationService.ClearCalculationOutput(calculation)); + + foreach (IObservable affectedObject in affectedObjects) + { + affectedObject.NotifyObservers(); } } } Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Helpers/SynchronizeCalculationWithForeshoreProfileHelperTest.cs =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Helpers/SynchronizeCalculationWithForeshoreProfileHelperTest.cs (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Helpers/SynchronizeCalculationWithForeshoreProfileHelperTest.cs (revision b7c78a363e31e9911179086d4aa73561deb6b4d4) @@ -0,0 +1,83 @@ +// Copyright (C) Stichting Deltares 2017. 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 NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.Common.Forms.Helpers; + +namespace Ringtoets.Common.Forms.Test.Helpers +{ + [TestFixture] + public class SynchronizeCalculationWithForeshoreProfileHelperTest + { + [Test] + public void UpdateForeshoreProfileDerivedCalculationInput_ForeshoreProfileSynchronized_DoesNotNotifyObservers() + { + // Setup + var mocks = new MockRepository(); + var calculationInputMock = mocks.StrictMock(); + calculationInputMock.Expect(ci => ci.IsForeshoreProfileParametersSynchronized).Return(true); + + var calculationMock = mocks.StrictMock>(); + calculationMock.Stub(c => c.InputParameters).Return(calculationInputMock); + mocks.ReplayAll(); + + // Call + SynchronizeCalculationWithForeshoreProfileHelper.UpdateForeshoreProfileDerivedCalculationInput(calculationMock); + + // Assert + mocks.VerifyAll(); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void UpdateForeshoreProfileDerivedCalculationInput_ForeshoreProfileNotSynchronized_NotifyObservers(bool hasOutput) + { + // Setup + var mocks = new MockRepository(); + var calculationInputMock = mocks.StrictMock(); + calculationInputMock.Expect(ci => ci.IsForeshoreProfileParametersSynchronized).Return(false); + calculationInputMock.Expect(ci => ci.SynchronizeForeshoreProfileParameters()); + calculationInputMock.Expect(ci => ci.NotifyObservers()); + + var calculationMock = mocks.StrictMock>(); + calculationMock.Stub(c => c.InputParameters).Return(calculationInputMock); + calculationMock.Expect(c => c.HasOutput).Return(hasOutput); + if (hasOutput) + { + calculationMock.Expect(c => c.ClearOutput()); + calculationMock.Expect(c => c.NotifyObservers()); + } + mocks.ReplayAll(); + + // Call + SynchronizeCalculationWithForeshoreProfileHelper.UpdateForeshoreProfileDerivedCalculationInput(calculationMock); + + // Assert + mocks.VerifyAll(); + } + + public interface ICalculationInputWithForeshoreProfile : ICalculationInput, IHasForeshoreProfile {} + } +} \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Ringtoets.Common.Forms.Test.csproj =================================================================== diff -u -r2702ecf9aaf678cf869dc330f8ff560b3de4672a -rb7c78a363e31e9911179086d4aa73561deb6b4d4 --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Ringtoets.Common.Forms.Test.csproj (.../Ringtoets.Common.Forms.Test.csproj) (revision 2702ecf9aaf678cf869dc330f8ff560b3de4672a) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Ringtoets.Common.Forms.Test.csproj (.../Ringtoets.Common.Forms.Test.csproj) (revision b7c78a363e31e9911179086d4aa73561deb6b4d4) @@ -73,6 +73,7 @@ +