Index: Riskeer/Common/src/Riskeer.Common.Forms/ChangeHandlers/ClearIllustrationPointsOfStructuresCalculationHandler.cs =================================================================== diff -u -rddad7117cf82255493a1a9f80b2c6562dc88bfd2 -r2306643c0ad2a3cf0d9e086afaddc773ffd65df1 --- Riskeer/Common/src/Riskeer.Common.Forms/ChangeHandlers/ClearIllustrationPointsOfStructuresCalculationHandler.cs (.../ClearIllustrationPointsOfStructuresCalculationHandler.cs) (revision ddad7117cf82255493a1a9f80b2c6562dc88bfd2) +++ Riskeer/Common/src/Riskeer.Common.Forms/ChangeHandlers/ClearIllustrationPointsOfStructuresCalculationHandler.cs (.../ClearIllustrationPointsOfStructuresCalculationHandler.cs) (revision 2306643c0ad2a3cf0d9e086afaddc773ffd65df1) @@ -20,6 +20,7 @@ // All rights reserved. using System; +using Core.Common.Gui.Commands; using Core.Common.Gui.Helpers; using Riskeer.Common.Data.Structures; @@ -36,15 +37,18 @@ /// /// The calculation to clear the illustration points for. /// Object responsible for inquiring confirmation. + /// The view commands used to close views for the illustration points. /// Thrown when any parameter is null. public ClearIllustrationPointsOfStructuresCalculationHandler( - IStructuresCalculation calculation, IInquiryHelper inquiryHelper) - : base(calculation, inquiryHelper) {} + IStructuresCalculation calculation, IInquiryHelper inquiryHelper, IViewCommands viewCommands) + : base(calculation, inquiryHelper, viewCommands) {} public override bool ClearIllustrationPoints() { if (Calculation.HasOutput && Calculation.Output.HasGeneralResult) { + ViewCommands.RemoveAllViewsForItem(Calculation.Output.GeneralResult); + Calculation.ClearIllustrationPoints(); return true; } Index: Riskeer/Common/test/Riskeer.Common.Forms.Test/ChangeHandlers/ClearIllustrationPointsOfStructuresCalculationHandlerTest.cs =================================================================== diff -u -rddad7117cf82255493a1a9f80b2c6562dc88bfd2 -r2306643c0ad2a3cf0d9e086afaddc773ffd65df1 --- Riskeer/Common/test/Riskeer.Common.Forms.Test/ChangeHandlers/ClearIllustrationPointsOfStructuresCalculationHandlerTest.cs (.../ClearIllustrationPointsOfStructuresCalculationHandlerTest.cs) (revision ddad7117cf82255493a1a9f80b2c6562dc88bfd2) +++ Riskeer/Common/test/Riskeer.Common.Forms.Test/ChangeHandlers/ClearIllustrationPointsOfStructuresCalculationHandlerTest.cs (.../ClearIllustrationPointsOfStructuresCalculationHandlerTest.cs) (revision 2306643c0ad2a3cf0d9e086afaddc773ffd65df1) @@ -19,7 +19,7 @@ // 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 NUnit.Framework; using Rhino.Mocks; @@ -34,59 +34,80 @@ public class ClearIllustrationPointsOfStructuresCalculationHandlerTest { [Test] - public void Constructor_WithArguments_ExpectedValues() + public void Constructor_ExpectedValues() { // Setup var mocks = new MockRepository(); var inquiryHelper = mocks.Stub(); + var viewCommands = mocks.Stub(); mocks.ReplayAll(); var calculation = new TestStructuresCalculation(); // Call - var handler = new ClearIllustrationPointsOfStructuresCalculationHandler(calculation, inquiryHelper); + var handler = new ClearIllustrationPointsOfStructuresCalculationHandler(calculation, inquiryHelper, viewCommands); // Assert Assert.IsInstanceOf>(handler); mocks.VerifyAll(); } [Test] - [TestCaseSource(nameof(GetCalculationConfigurations))] - public void ClearIllustrationPoints_WithVariousCalculationConfigurations_ClearsIllustrationPointsAndReturnsExpectedResult( - TestStructuresCalculation calculation, bool expectedResult) + [TestCase(true)] + [TestCase(false)] + public void GivenCalculationWithoutIllustrationPoints_WhenClearIllustrationPoints_ThenNothingHappensAndReturnFalse( + bool hasOutput) { - // Setup + // Given var mocks = new MockRepository(); - var inquiryHelper = mocks.StrictMock(); + var inquiryHelper = mocks.Stub(); + var viewCommands = mocks.StrictMock(); mocks.ReplayAll(); - var handler = new ClearIllustrationPointsOfStructuresCalculationHandler(calculation, inquiryHelper); + var calculation = new TestStructuresCalculation + { + Output = hasOutput + ? new TestStructuresOutput() + : null + }; - bool hasOutput = calculation.HasOutput; + var handler = new ClearIllustrationPointsOfStructuresCalculationHandler(calculation, inquiryHelper, viewCommands); - // Call + // When bool isCalculationAffected = handler.ClearIllustrationPoints(); - // Assert - Assert.AreEqual(expectedResult, isCalculationAffected); + // Then + Assert.IsFalse(isCalculationAffected); Assert.AreEqual(hasOutput, calculation.HasOutput); - Assert.IsNull(calculation.Output?.GeneralResult); mocks.VerifyAll(); } - private static IEnumerable GetCalculationConfigurations() + [Test] + public void GivenCalculationWithIllustrationPoints_WhenClearIllustrationPoints_ThenViewClosedAndIllustrationPointsClearedAndReturnTrue() { - yield return new TestCaseData(new TestStructuresCalculation(), false); - yield return new TestCaseData(new TestStructuresCalculation + // Given + var calculation = new TestStructuresCalculation { - Output = new TestStructuresOutput() - }, false); - yield return new TestCaseData(new TestStructuresCalculation - { Output = new TestStructuresOutput(new TestGeneralResultFaultTreeIllustrationPoint()) - }, true); + }; + + var mocks = new MockRepository(); + var inquiryHelper = mocks.Stub(); + var viewCommands = mocks.StrictMock(); + viewCommands.Expect(vc => vc.RemoveAllViewsForItem(calculation.Output.GeneralResult)); + mocks.ReplayAll(); + + var handler = new ClearIllustrationPointsOfStructuresCalculationHandler(calculation, inquiryHelper, viewCommands); + + // When + bool isCalculationAffected = handler.ClearIllustrationPoints(); + + // Then + Assert.IsTrue(isCalculationAffected); + Assert.IsTrue(calculation.HasOutput); + Assert.IsNull(calculation.Output.GeneralResult); + mocks.VerifyAll(); } } } \ No newline at end of file