Index: Riskeer/Common/src/Riskeer.Common.Forms/ChangeHandlers/ClearCalculationOutputChangeHandlerBase.cs
===================================================================
diff -u -r551adc15997614cd3df87522131fc90f4cd2484a -raad9f6c1881b26d0833fef4f9bb5882f4dc385ed
--- Riskeer/Common/src/Riskeer.Common.Forms/ChangeHandlers/ClearCalculationOutputChangeHandlerBase.cs (.../ClearCalculationOutputChangeHandlerBase.cs) (revision 551adc15997614cd3df87522131fc90f4cd2484a)
+++ Riskeer/Common/src/Riskeer.Common.Forms/ChangeHandlers/ClearCalculationOutputChangeHandlerBase.cs (.../ClearCalculationOutputChangeHandlerBase.cs) (revision aad9f6c1881b26d0833fef4f9bb5882f4dc385ed)
@@ -32,19 +32,20 @@
///
/// Base class for handling clearing calculation output.
///
- public abstract class ClearCalculationOutputChangeHandlerBase : IClearCalculationOutputChangeHandler
+ /// The type of the calculation.
+ public abstract class ClearCalculationOutputChangeHandlerBase : IClearCalculationOutputChangeHandler
+ where TCalculation : ICalculation
{
- private readonly IEnumerable calculations;
private readonly IInquiryHelper inquiryHelper;
///
- /// Creates a new instance of .
+ /// 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)
+ protected ClearCalculationOutputChangeHandlerBase(IEnumerable calculations, IInquiryHelper inquiryHelper, IViewCommands viewCommands)
{
if (calculations == null)
{
@@ -61,15 +62,10 @@
throw new ArgumentNullException(nameof(viewCommands));
}
- this.calculations = calculations;
+ Calculations = calculations;
this.inquiryHelper = inquiryHelper;
ViewCommands = viewCommands;
}
-
- ///
- /// Gets the .
- ///
- protected IViewCommands ViewCommands { get; }
public bool InquireConfirmation()
{
@@ -80,15 +76,25 @@
{
DoPreUpdateActions();
- foreach (ICalculation calculation in calculations)
+ foreach (TCalculation calculation in Calculations)
{
calculation.ClearOutput();
}
- return calculations;
+ return (IEnumerable) Calculations;
}
///
+ /// Gets the calculations.
+ ///
+ protected IEnumerable Calculations { get; }
+
+ ///
+ /// Gets the .
+ ///
+ protected IViewCommands ViewCommands { get; }
+
+ ///
/// Performs pre-update actions
///
protected abstract void DoPreUpdateActions();
Index: Riskeer/Common/src/Riskeer.Common.Forms/ChangeHandlers/StructuresClearCalculationOutputChangeHandler.cs
===================================================================
diff -u
--- Riskeer/Common/src/Riskeer.Common.Forms/ChangeHandlers/StructuresClearCalculationOutputChangeHandler.cs (revision 0)
+++ Riskeer/Common/src/Riskeer.Common.Forms/ChangeHandlers/StructuresClearCalculationOutputChangeHandler.cs (revision aad9f6c1881b26d0833fef4f9bb5882f4dc385ed)
@@ -0,0 +1,47 @@
+// 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.Gui.Commands;
+using Core.Common.Gui.Helpers;
+using Core.Common.Util.Extensions;
+using Riskeer.Common.Data.Structures;
+
+namespace Riskeer.Common.Forms.ChangeHandlers
+{
+ ///
+ /// Class for handling clearing the output of
+ ///
+ /// The type of structures input.
+ public class StructuresClearCalculationOutputChangeHandler : ClearCalculationOutputChangeHandlerBase>
+ where TStructuresInput : IStructuresCalculationInput, new()
+ {
+ public StructuresClearCalculationOutputChangeHandler(
+ IEnumerable> calculations,
+ IInquiryHelper inquiryHelper, IViewCommands viewCommands)
+ : base(calculations, inquiryHelper, viewCommands) {}
+
+ protected override void DoPreUpdateActions()
+ {
+ Calculations.ForEachElementDo(calculation => ViewCommands.RemoveAllViewsForItem(calculation.Output));
+ }
+ }
+}
\ No newline at end of file
Index: Riskeer/Common/test/Riskeer.Common.Forms.Test/ChangeHandlers/ClearCalculationOutputChangeHandlerBaseTest.cs
===================================================================
diff -u -r551adc15997614cd3df87522131fc90f4cd2484a -raad9f6c1881b26d0833fef4f9bb5882f4dc385ed
--- Riskeer/Common/test/Riskeer.Common.Forms.Test/ChangeHandlers/ClearCalculationOutputChangeHandlerBaseTest.cs (.../ClearCalculationOutputChangeHandlerBaseTest.cs) (revision 551adc15997614cd3df87522131fc90f4cd2484a)
+++ Riskeer/Common/test/Riskeer.Common.Forms.Test/ChangeHandlers/ClearCalculationOutputChangeHandlerBaseTest.cs (.../ClearCalculationOutputChangeHandlerBaseTest.cs) (revision aad9f6c1881b26d0833fef4f9bb5882f4dc385ed)
@@ -39,11 +39,11 @@
public void Constructor_CalculationsNull_ThrowsArgumentNullException()
{
// Setup
- var mocks = new MockRepository();
- var inquiryHelper = mocks.Stub();
- var viewCommands = mocks.Stub();
- mocks.ReplayAll();
-
+ var mocks = new MockRepository();
+ var inquiryHelper = mocks.Stub();
+ var viewCommands = mocks.Stub();
+ mocks.ReplayAll();
+
// Call
void Call() => new TestClearCalculationOutputChangeHandler(null, inquiryHelper, viewCommands);
@@ -60,7 +60,7 @@
var mocks = new MockRepository();
var viewCommands = mocks.Stub();
mocks.ReplayAll();
-
+
// Call
void Call() => new TestClearCalculationOutputChangeHandler(Enumerable.Empty(), null, viewCommands);
@@ -111,18 +111,18 @@
{
// 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();
@@ -141,37 +141,37 @@
calculation2.Expect(c => c.ClearOutput());
mocks.ReplayAll();
- ICalculation[] calculations =
+ 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
+
+ private class TestClearCalculationOutputChangeHandler : ClearCalculationOutputChangeHandlerBase
{
- public TestClearCalculationOutputChangeHandler(IEnumerable calculations, IInquiryHelper inquiryHelper, IViewCommands viewCommands)
+ public TestClearCalculationOutputChangeHandler(IEnumerable calculations, IInquiryHelper inquiryHelper, IViewCommands viewCommands)
: base(calculations, inquiryHelper, viewCommands) {}
-
+
+ public bool DoPreUpdateActionsExecuted { get; private set; }
+
protected override void DoPreUpdateActions()
{
DoPreUpdateActionsExecuted = true;
}
-
- public bool DoPreUpdateActionsExecuted { get; private set; }
- }
+ }
}
}
\ No newline at end of file
Index: Riskeer/Common/test/Riskeer.Common.Forms.Test/ChangeHandlers/StructuresClearCalculationOutputChangeHandlerTest.cs
===================================================================
diff -u
--- Riskeer/Common/test/Riskeer.Common.Forms.Test/ChangeHandlers/StructuresClearCalculationOutputChangeHandlerTest.cs (revision 0)
+++ Riskeer/Common/test/Riskeer.Common.Forms.Test/ChangeHandlers/StructuresClearCalculationOutputChangeHandlerTest.cs (revision aad9f6c1881b26d0833fef4f9bb5882f4dc385ed)
@@ -0,0 +1,87 @@
+// 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.Linq;
+using Core.Common.Gui.Commands;
+using Core.Common.Gui.Helpers;
+using NUnit.Framework;
+using Rhino.Mocks;
+using Riskeer.Common.Data.Structures;
+using Riskeer.Common.Data.TestUtil;
+using Riskeer.Common.Forms.ChangeHandlers;
+
+namespace Riskeer.Common.Forms.Test.ChangeHandlers
+{
+ [TestFixture]
+ public class StructuresClearCalculationOutputChangeHandlerTest
+ {
+ [Test]
+ public void Constructor_ExpectedValues()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var inquiryHelper = mocks.Stub();
+ var viewCommands = mocks.Stub();
+ mocks.ReplayAll();
+
+ // Call
+ var changeHandler = new StructuresClearCalculationOutputChangeHandler(
+ Enumerable.Empty>(), inquiryHelper, viewCommands);
+
+ // Assert
+ Assert.IsInstanceOf>>(changeHandler);
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void GivenChangeHandler_WhenClearingCalculations_ThenViewsClosedForOutputs()
+ {
+ // Given
+ var calculations = new[]
+ {
+ new TestStructuresCalculationScenario
+ {
+ Output = new TestStructuresOutput()
+ },
+ new TestStructuresCalculationScenario
+ {
+ Output = new TestStructuresOutput()
+ }
+ };
+
+ var mocks = new MockRepository();
+ var inquiryHelper = mocks.Stub();
+ var viewCommands = mocks.StrictMock();
+ viewCommands.Expect(vc => vc.RemoveAllViewsForItem(calculations[0].Output));
+ viewCommands.Expect(vc => vc.RemoveAllViewsForItem(calculations[1].Output));
+ mocks.ReplayAll();
+
+ var changeHandler = new StructuresClearCalculationOutputChangeHandler(
+ calculations, inquiryHelper, viewCommands);
+
+ // When
+ changeHandler.ClearCalculations();
+
+ // Then
+ mocks.VerifyAll();
+ }
+ }
+}
\ No newline at end of file