Index: Riskeer/Common/src/Riskeer.Common.Forms/ChangeHandlers/ClearCalculationOutputChangeHandlerBase.cs
===================================================================
diff -u
--- Riskeer/Common/src/Riskeer.Common.Forms/ChangeHandlers/ClearCalculationOutputChangeHandlerBase.cs (revision 0)
+++ Riskeer/Common/src/Riskeer.Common.Forms/ChangeHandlers/ClearCalculationOutputChangeHandlerBase.cs (revision 551adc15997614cd3df87522131fc90f4cd2484a)
@@ -0,0 +1,96 @@
+// 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.Commands;
+using Core.Common.Gui.Helpers;
+using Riskeer.Common.Data.Calculation;
+using Riskeer.Common.Forms.Properties;
+
+namespace Riskeer.Common.Forms.ChangeHandlers
+{
+ ///
+ /// Base class for handling clearing calculation output.
+ ///
+ public abstract class ClearCalculationOutputChangeHandlerBase : 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.
+ protected ClearCalculationOutputChangeHandlerBase(IEnumerable calculations, IInquiryHelper inquiryHelper, IViewCommands viewCommands)
+ {
+ if (calculations == null)
+ {
+ throw new ArgumentNullException(nameof(calculations));
+ }
+
+ if (inquiryHelper == null)
+ {
+ throw new ArgumentNullException(nameof(inquiryHelper));
+ }
+
+ if (viewCommands == null)
+ {
+ throw new ArgumentNullException(nameof(viewCommands));
+ }
+
+ this.calculations = calculations;
+ this.inquiryHelper = inquiryHelper;
+ ViewCommands = viewCommands;
+ }
+
+ ///
+ /// Gets the .
+ ///
+ protected IViewCommands ViewCommands { get; }
+
+ public bool InquireConfirmation()
+ {
+ return inquiryHelper.InquireContinuation(Resources.FailureMechanism_ContextMenuStrip_Are_you_sure_clear_all_output);
+ }
+
+ public IEnumerable ClearCalculations()
+ {
+ DoPreUpdateActions();
+
+ foreach (ICalculation calculation in calculations)
+ {
+ calculation.ClearOutput();
+ }
+
+ return calculations;
+ }
+
+ ///
+ /// Performs pre-update actions
+ ///
+ protected abstract void DoPreUpdateActions();
+ }
+}
\ No newline at end of file
Index: Riskeer/Common/src/Riskeer.Common.Forms/ChangeHandlers/IClearCalculationOutputChangeHandler.cs
===================================================================
diff -u
--- Riskeer/Common/src/Riskeer.Common.Forms/ChangeHandlers/IClearCalculationOutputChangeHandler.cs (revision 0)
+++ Riskeer/Common/src/Riskeer.Common.Forms/ChangeHandlers/IClearCalculationOutputChangeHandler.cs (revision 551adc15997614cd3df87522131fc90f4cd2484a)
@@ -0,0 +1,44 @@
+// 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.Collections.Generic;
+using Core.Common.Base;
+
+namespace Riskeer.Common.Forms.ChangeHandlers
+{
+ ///
+ /// Interface for handling clearing calculation output.
+ ///
+ public interface IClearCalculationOutputChangeHandler
+ {
+ ///
+ /// Gets confirmation for clearing the illustration points.
+ ///
+ /// true when confirmation is given, false otherwise.
+ bool InquireConfirmation();
+
+ ///
+ /// Clears all illustration points and returns the affected objects.
+ ///
+ /// The affected objects by the operation.
+ IEnumerable ClearCalculations();
+ }
+}
\ No newline at end of file
Index: Riskeer/Common/test/Riskeer.Common.Forms.Test/ChangeHandlers/ClearCalculationOutputChangeHandlerBaseTest.cs
===================================================================
diff -u
--- Riskeer/Common/test/Riskeer.Common.Forms.Test/ChangeHandlers/ClearCalculationOutputChangeHandlerBaseTest.cs (revision 0)
+++ Riskeer/Common/test/Riskeer.Common.Forms.Test/ChangeHandlers/ClearCalculationOutputChangeHandlerBaseTest.cs (revision 551adc15997614cd3df87522131fc90f4cd2484a)
@@ -0,0 +1,177 @@
+// 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.Commands;
+using Core.Common.Gui.Helpers;
+using NUnit.Framework;
+using Rhino.Mocks;
+using Riskeer.Common.Data.Calculation;
+using Riskeer.Common.Forms.ChangeHandlers;
+
+namespace Riskeer.Common.Forms.Test.ChangeHandlers
+{
+ [TestFixture]
+ public class ClearCalculationOutputChangeHandlerBaseTest
+ {
+ [Test]
+ public void Constructor_CalculationsNull_ThrowsArgumentNullException()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var inquiryHelper = mocks.Stub();
+ var viewCommands = mocks.Stub();
+ mocks.ReplayAll();
+
+ // Call
+ void Call() => new TestClearCalculationOutputChangeHandler(null, inquiryHelper, viewCommands);
+
+ // Assert
+ var exception = Assert.Throws(Call);
+ Assert.AreEqual("calculations", exception.ParamName);
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void Constructor_InquiryHelperNull_ThrowsArgumentNullException()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var viewCommands = mocks.Stub();
+ mocks.ReplayAll();
+
+ // Call
+ void Call() => new TestClearCalculationOutputChangeHandler(Enumerable.Empty(), null, viewCommands);
+
+ // Assert
+ var exception = Assert.Throws(Call);
+ Assert.AreEqual("inquiryHelper", exception.ParamName);
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void Constructor_ViewCommandsNull_ThrowsArgumentNullException()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var inquiryHelper = mocks.Stub();
+ mocks.ReplayAll();
+
+ // Call
+ void Call() => new TestClearCalculationOutputChangeHandler(Enumerable.Empty(), inquiryHelper, null);
+
+ // Assert
+ var exception = Assert.Throws(Call);
+ Assert.AreEqual("viewCommands", exception.ParamName);
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void Constructor_ExpectedValues()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var inquiryHelper = mocks.Stub();
+ var viewCommands = mocks.Stub();
+ mocks.ReplayAll();
+
+ // Call
+ var changeHandler = new TestClearCalculationOutputChangeHandler(Enumerable.Empty(), inquiryHelper, viewCommands);
+
+ // 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);
+ var viewCommands = mocks.Stub();
+ mocks.ReplayAll();
+
+ var changeHandler = new TestClearCalculationOutputChangeHandler(Enumerable.Empty(), inquiryHelper, viewCommands);
+
+ // Call
+ bool confirmation = changeHandler.InquireConfirmation();
+
+ // Assert
+ Assert.AreEqual(expectedConfirmation, confirmation);
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void ClearCalculations_Always_ExecutesPreUpdateActionsAndClearsOutput()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var inquiryHelper = mocks.Stub();
+ var viewCommands = 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 TestClearCalculationOutputChangeHandler(calculations, inquiryHelper, viewCommands);
+
+ // Precondition
+ Assert.IsFalse(changeHandler.DoPreUpdateActionsExecuted);
+
+ // Call
+ IEnumerable affectedCalculations = changeHandler.ClearCalculations();
+
+ // Assert
+ Assert.IsTrue(changeHandler.DoPreUpdateActionsExecuted);
+ CollectionAssert.AreEqual(calculations, affectedCalculations);
+ mocks.VerifyAll();
+ }
+
+ private class TestClearCalculationOutputChangeHandler : ClearCalculationOutputChangeHandlerBase
+ {
+ public TestClearCalculationOutputChangeHandler(IEnumerable calculations, IInquiryHelper inquiryHelper, IViewCommands viewCommands)
+ : base(calculations, inquiryHelper, viewCommands) {}
+
+ protected override void DoPreUpdateActions()
+ {
+ DoPreUpdateActionsExecuted = true;
+ }
+
+ public bool DoPreUpdateActionsExecuted { get; private set; }
+ }
+ }
+}
\ No newline at end of file