Index: Riskeer/Revetment/src/Riskeer.Revetment.Forms/ChangeHandlers/WaveConditionsCalculationOutputChangeHandler.cs =================================================================== diff -u --- Riskeer/Revetment/src/Riskeer.Revetment.Forms/ChangeHandlers/WaveConditionsCalculationOutputChangeHandler.cs (revision 0) +++ Riskeer/Revetment/src/Riskeer.Revetment.Forms/ChangeHandlers/WaveConditionsCalculationOutputChangeHandler.cs (revision 2788b491af7cf0f5238c4ecef3831d8f409451a0) @@ -0,0 +1,82 @@ +// Copyright (C) Stichting Deltares 2019. All rights reserved. +// +// This file is part of Riskeer. +// +// Riskeer 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 Core.Common.Gui.Helpers; +using Riskeer.Common.Data.Calculation; +using Riskeer.Common.Forms.ChangeHandlers; +using Riskeer.Revetment.Data; +using RiskeerCommonFormsResources = Riskeer.Common.Forms.Properties.Resources; + +namespace Riskeer.Revetment.Forms.ChangeHandlers +{ + /// + /// Class for handling clearing wave conditions calculation output. + /// + public class WaveConditionsCalculationOutputChangeHandler : IClearCalculationOutputChangeHandler + { + private readonly IEnumerable> calculations; + private readonly IInquiryHelper inquiryHelper; + + /// + /// Creates a new instance of . + /// + /// The calculations to clear the output for. + /// Object responsible for inquiring confirmation. + /// Thrown when any parameter is null. + public WaveConditionsCalculationOutputChangeHandler(IEnumerable> calculations, + IInquiryHelper inquiryHelper) + { + if (calculations == null) + { + throw new ArgumentNullException(nameof(calculations)); + } + + if (inquiryHelper == null) + { + throw new ArgumentNullException(nameof(inquiryHelper)); + } + + this.calculations = calculations; + this.inquiryHelper = inquiryHelper; + } + + public bool InquireConfirmation() + { + return inquiryHelper.InquireContinuation(RiskeerCommonFormsResources.FailureMechanism_ContextMenuStrip_Are_you_sure_clear_all_output); + } + + public IEnumerable ClearCalculations() + { + var affectedCalculations = new List(); + + foreach (ICalculation calculation in calculations) + { + calculation.ClearOutput(); + affectedCalculations.Add(calculation); + } + + return affectedCalculations; + } + } +} \ No newline at end of file Index: Riskeer/Revetment/src/Riskeer.Revetment.Forms/Riskeer.Revetment.Forms.csproj =================================================================== diff -u -r08e8d26a0715f0f3db57c1d3e86256aa06934db4 -r2788b491af7cf0f5238c4ecef3831d8f409451a0 --- Riskeer/Revetment/src/Riskeer.Revetment.Forms/Riskeer.Revetment.Forms.csproj (.../Riskeer.Revetment.Forms.csproj) (revision 08e8d26a0715f0f3db57c1d3e86256aa06934db4) +++ Riskeer/Revetment/src/Riskeer.Revetment.Forms/Riskeer.Revetment.Forms.csproj (.../Riskeer.Revetment.Forms.csproj) (revision 2788b491af7cf0f5238c4ecef3831d8f409451a0) @@ -12,16 +12,16 @@ - - - - - - - - - - + + + + + + + + + + Index: Riskeer/Revetment/test/Riskeer.Revetment.Forms.Test/ChangeHandlers/WaveConditionsCalculationOutputChangeHandlerTest.cs =================================================================== diff -u --- Riskeer/Revetment/test/Riskeer.Revetment.Forms.Test/ChangeHandlers/WaveConditionsCalculationOutputChangeHandlerTest.cs (revision 0) +++ Riskeer/Revetment/test/Riskeer.Revetment.Forms.Test/ChangeHandlers/WaveConditionsCalculationOutputChangeHandlerTest.cs (revision 2788b491af7cf0f5238c4ecef3831d8f409451a0) @@ -0,0 +1,134 @@ +// Copyright (C) Stichting Deltares 2019. All rights reserved. +// +// This file is part of Riskeer. +// +// Riskeer 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.Gui.Helpers; +using NUnit.Framework; +using Rhino.Mocks; +using Riskeer.Common.Data.Calculation; +using Riskeer.Common.Forms.ChangeHandlers; +using Riskeer.Revetment.Data; +using Riskeer.Revetment.Forms.ChangeHandlers; + +namespace Riskeer.Revetment.Forms.Test.ChangeHandlers +{ + [TestFixture] + public class WaveConditionsCalculationOutputChangeHandlerTest + { + [Test] + public void Constructor_CalculationsNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var inquiryHelper = mocks.Stub(); + mocks.ReplayAll(); + + // Call + void Call() => new WaveConditionsCalculationOutputChangeHandler(null, inquiryHelper); + + // Assert + var exception = Assert.Throws(Call); + Assert.AreEqual("calculations", exception.ParamName); + mocks.VerifyAll(); + } + + [Test] + public void Constructor_InquiryHelperNull_ThrowsArgumentNullException() + { + // Call + void Call() => new WaveConditionsCalculationOutputChangeHandler(Enumerable.Empty>(), null); + + // Assert + var exception = Assert.Throws(Call); + Assert.AreEqual("inquiryHelper", exception.ParamName); + } + + [Test] + public void Constructor_ExpectedValues() + { + // Setup + var mocks = new MockRepository(); + var inquiryHelper = mocks.Stub(); + mocks.ReplayAll(); + + // Call + var changeHandler = new WaveConditionsCalculationOutputChangeHandler(Enumerable.Empty>(), inquiryHelper); + + // Assert + Assert.IsInstanceOf(changeHandler); + mocks.VerifyAll(); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void InquireConfirmation_Always_DisplaysInquiryAndReturnsConfirmation(bool expectedConfirmation) + { + // Setup + const string expectedInquiry = "Weet u zeker dat u alle uitvoer wilt wissen?"; + + var mocks = new MockRepository(); + var inquiryHelper = mocks.StrictMock(); + inquiryHelper.Expect(h => h.InquireContinuation(expectedInquiry)).Return(expectedConfirmation); + mocks.ReplayAll(); + + var changeHandler = new WaveConditionsCalculationOutputChangeHandler(Enumerable.Empty>(), inquiryHelper); + + // Call + bool confirmation = changeHandler.InquireConfirmation(); + + // Assert + Assert.AreEqual(expectedConfirmation, confirmation); + mocks.VerifyAll(); + } + + [Test] + public void ClearCalculations_Always_ClearsOutput() + { + // Setup + var mocks = new MockRepository(); + var inquiryHelper = mocks.Stub(); + var calculation1 = mocks.StrictMock>(); + calculation1.Expect(c => c.ClearOutput()); + var calculation2 = mocks.StrictMock>(); + calculation2.Expect(c => c.ClearOutput()); + mocks.ReplayAll(); + + ICalculation[] calculations = + { + calculation1, + calculation2 + }; + + var changeHandler = new WaveConditionsCalculationOutputChangeHandler(calculations, inquiryHelper); + + // Call + IEnumerable affectedCalculations = changeHandler.ClearCalculations(); + + // Assert + CollectionAssert.AreEqual(calculations, affectedCalculations); + mocks.VerifyAll(); + } + } +} \ No newline at end of file Index: Riskeer/Revetment/test/Riskeer.Revetment.Forms.Test/Riskeer.Revetment.Forms.Test.csproj =================================================================== diff -u -r08e8d26a0715f0f3db57c1d3e86256aa06934db4 -r2788b491af7cf0f5238c4ecef3831d8f409451a0 --- Riskeer/Revetment/test/Riskeer.Revetment.Forms.Test/Riskeer.Revetment.Forms.Test.csproj (.../Riskeer.Revetment.Forms.Test.csproj) (revision 08e8d26a0715f0f3db57c1d3e86256aa06934db4) +++ Riskeer/Revetment/test/Riskeer.Revetment.Forms.Test/Riskeer.Revetment.Forms.Test.csproj (.../Riskeer.Revetment.Forms.Test.csproj) (revision 2788b491af7cf0f5238c4ecef3831d8f409451a0) @@ -12,21 +12,21 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + +