Index: Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.Forms/ChangeHandlers/ClearMacroStabilityInwardsCalculationOutputChangeHandler.cs =================================================================== diff -u --- Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.Forms/ChangeHandlers/ClearMacroStabilityInwardsCalculationOutputChangeHandler.cs (revision 0) +++ Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.Forms/ChangeHandlers/ClearMacroStabilityInwardsCalculationOutputChangeHandler.cs (revision 2fed233880b3042ff467cd7ea150e8aa5be2fd28) @@ -0,0 +1,54 @@ +// 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.Gui.Commands; +using Core.Common.Gui.Helpers; +using Core.Common.Util.Extensions; +using Riskeer.Common.Forms.ChangeHandlers; +using Riskeer.MacroStabilityInwards.Data; + +namespace Riskeer.MacroStabilityInwards.Forms.ChangeHandlers +{ + /// + /// Class for handling clearing the output of . + /// + public class ClearMacroStabilityInwardsCalculationOutputChangeHandler : ClearCalculationOutputChangeHandlerBase + { + /// + /// Creates a new instance of . + /// + /// The calculations to clear the output for. + /// Object responsible for inquiring confirmation. + /// The view commands used to close views for the calculation output. + /// Thrown when any parameter is null. + public ClearMacroStabilityInwardsCalculationOutputChangeHandler( + 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/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.Forms.Test/ChangeHandlers/ClearMacroStabilityInwardsCalculationOutputChangeHandlerTest.cs =================================================================== diff -u --- Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.Forms.Test/ChangeHandlers/ClearMacroStabilityInwardsCalculationOutputChangeHandlerTest.cs (revision 0) +++ Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.Forms.Test/ChangeHandlers/ClearMacroStabilityInwardsCalculationOutputChangeHandlerTest.cs (revision 2fed233880b3042ff467cd7ea150e8aa5be2fd28) @@ -0,0 +1,88 @@ +// 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.Forms.ChangeHandlers; +using Riskeer.MacroStabilityInwards.Data; +using Riskeer.MacroStabilityInwards.Data.TestUtil; +using Riskeer.MacroStabilityInwards.Forms.ChangeHandlers; + +namespace Riskeer.MacroStabilityInwards.Forms.Test.ChangeHandlers +{ + [TestFixture] + public class ClearMacroStabilityInwardsCalculationOutputChangeHandlerTest + { + [Test] + public void Constructor_ExpectedValues() + { + // Setup + var mocks = new MockRepository(); + var inquiryHelper = mocks.Stub(); + var viewCommands = mocks.Stub(); + mocks.ReplayAll(); + + // Call + var changeHandler = new ClearMacroStabilityInwardsCalculationOutputChangeHandler( + Enumerable.Empty(), inquiryHelper, viewCommands); + + // Assert + Assert.IsInstanceOf>(changeHandler); + mocks.VerifyAll(); + } + + [Test] + public void GivenChangeHandler_WhenClearingCalculations_ThenViewsClosedForOutputs() + { + // Given + var calculations = new[] + { + new MacroStabilityInwardsCalculationScenario + { + Output = MacroStabilityInwardsOutputTestFactory.CreateOutput() + }, + new MacroStabilityInwardsCalculationScenario + { + Output = MacroStabilityInwardsOutputTestFactory.CreateOutput() + } + }; + + 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 ClearMacroStabilityInwardsCalculationOutputChangeHandler( + calculations, inquiryHelper, viewCommands); + + // When + changeHandler.ClearCalculations(); + + // Then + mocks.VerifyAll(); + } + } +} \ No newline at end of file Index: Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.Forms.Test/Riskeer.MacroStabilityInwards.Forms.Test.csproj =================================================================== diff -u -r08e8d26a0715f0f3db57c1d3e86256aa06934db4 -r2fed233880b3042ff467cd7ea150e8aa5be2fd28 --- Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.Forms.Test/Riskeer.MacroStabilityInwards.Forms.Test.csproj (.../Riskeer.MacroStabilityInwards.Forms.Test.csproj) (revision 08e8d26a0715f0f3db57c1d3e86256aa06934db4) +++ Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.Forms.Test/Riskeer.MacroStabilityInwards.Forms.Test.csproj (.../Riskeer.MacroStabilityInwards.Forms.Test.csproj) (revision 2fed233880b3042ff467cd7ea150e8aa5be2fd28) @@ -14,33 +14,33 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + +