Index: Riskeer/Piping/src/Riskeer.Piping.Forms/ChangeHandlers/ClearPipingCalculationOutputChangeHandler.cs =================================================================== diff -u --- Riskeer/Piping/src/Riskeer.Piping.Forms/ChangeHandlers/ClearPipingCalculationOutputChangeHandler.cs (revision 0) +++ Riskeer/Piping/src/Riskeer.Piping.Forms/ChangeHandlers/ClearPipingCalculationOutputChangeHandler.cs (revision 2bd084cf444823f677dd36a9509c234687e4fd16) @@ -0,0 +1,68 @@ +// 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.Data.Calculation; +using Riskeer.Common.Forms.ChangeHandlers; +using Riskeer.Piping.Data; +using Riskeer.Piping.Data.Probabilistic; + +namespace Riskeer.Piping.Forms.ChangeHandlers +{ + /// + /// Class for handling clearing the output of . + /// + public class ClearPipingCalculationOutputChangeHandler : ClearCalculationOutputChangeHandlerBase> + { + private readonly Func, ICalculationOutput> getOutputFunc; + + /// + /// 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. + /// The to get the output of a calculation. + /// Thrown when any parameter is null. + public ClearPipingCalculationOutputChangeHandler( + IEnumerable> calculations, + IInquiryHelper inquiryHelper, IViewCommands viewCommands, + Func, ICalculationOutput> getOutputFunc) + : base(calculations, inquiryHelper, viewCommands) + { + if (getOutputFunc == null) + { + throw new ArgumentNullException(nameof(getOutputFunc)); + } + + this.getOutputFunc = getOutputFunc; + } + + protected override void DoPreUpdateActions() + { + Calculations.ForEachElementDo(calculation => ViewCommands.RemoveAllViewsForItem(getOutputFunc(calculation))); + } + } +} \ No newline at end of file Fisheye: Tag 2bd084cf444823f677dd36a9509c234687e4fd16 refers to a dead (removed) revision in file `Riskeer/Piping/src/Riskeer.Piping.Forms/ChangeHandlers/ClearProbabilisticPipingCalculationOutputChangeHandler.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Riskeer/Piping/test/Riskeer.Piping.Forms.Test/ChangeHandlers/ClearPipingCalculationOutputChangeHandlerTest.cs =================================================================== diff -u --- Riskeer/Piping/test/Riskeer.Piping.Forms.Test/ChangeHandlers/ClearPipingCalculationOutputChangeHandlerTest.cs (revision 0) +++ Riskeer/Piping/test/Riskeer.Piping.Forms.Test/ChangeHandlers/ClearPipingCalculationOutputChangeHandlerTest.cs (revision 2bd084cf444823f677dd36a9509c234687e4fd16) @@ -0,0 +1,111 @@ +// 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.Linq; +using Core.Common.Gui.Commands; +using Core.Common.Gui.Helpers; +using NUnit.Framework; +using Rhino.Mocks; +using Riskeer.Common.Forms.ChangeHandlers; +using Riskeer.Piping.Data; +using Riskeer.Piping.Data.Probabilistic; +using Riskeer.Piping.Data.TestUtil; +using Riskeer.Piping.Forms.ChangeHandlers; + +namespace Riskeer.Piping.Forms.Test.ChangeHandlers +{ + [TestFixture] + public class ClearPipingCalculationOutputChangeHandlerTest + { + [Test] + public void Constructor_GetOutputFuncNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var inquiryHelper = mocks.Stub(); + var viewCommands = mocks.Stub(); + mocks.ReplayAll(); + + // Call + void Call() => new ClearPipingCalculationOutputChangeHandler( + Enumerable.Empty>(), + inquiryHelper, viewCommands, null); + + // Assert + var exception = Assert.Throws(Call); + Assert.AreEqual("getOutputFunc", 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 ClearPipingCalculationOutputChangeHandler( + Enumerable.Empty>(), + inquiryHelper, viewCommands, calculation => null); + + // Assert + Assert.IsInstanceOf>>(changeHandler); + mocks.VerifyAll(); + } + + [Test] + public void GivenChangeHandler_WhenClearingCalculations_ThenViewsClosedForOutputs() + { + // Given + var calculations = new[] + { + new ProbabilisticPipingCalculationScenario + { + Output = PipingTestDataGenerator.GetRandomProbabilisticPipingOutputWithoutIllustrationPoints() + }, + new ProbabilisticPipingCalculationScenario + { + Output = PipingTestDataGenerator.GetRandomProbabilisticPipingOutputWithIllustrationPoints() + } + }; + + 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 ClearPipingCalculationOutputChangeHandler( + calculations, inquiryHelper, viewCommands, calculation => ((ProbabilisticPipingCalculationScenario) calculation).Output); + + // When + changeHandler.ClearCalculations(); + + // Then + mocks.VerifyAll(); + } + } +} \ No newline at end of file Fisheye: Tag 2bd084cf444823f677dd36a9509c234687e4fd16 refers to a dead (removed) revision in file `Riskeer/Piping/test/Riskeer.Piping.Forms.Test/ChangeHandlers/ClearProbabilisticPipingCalculationOutputChangeHandlerTest.cs'. Fisheye: No comparison available. Pass `N' to diff?