Index: Ringtoets/Common/src/Ringtoets.Common.Forms/ChangeHandlers/CalculationChangeHandler.cs =================================================================== diff -u --- Ringtoets/Common/src/Ringtoets.Common.Forms/ChangeHandlers/CalculationChangeHandler.cs (revision 0) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/ChangeHandlers/CalculationChangeHandler.cs (revision 2702ecf9aaf678cf869dc330f8ff560b3de4672a) @@ -0,0 +1,79 @@ +// Copyright (C) Stichting Deltares 2017. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets 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.Gui; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.IO; + +namespace Ringtoets.Common.Forms.ChangeHandlers +{ + /// + /// Class which can, if required, inquire the user for a confirmation when a change to the + /// calculations requires calculation results to be altered. + /// + public class CalculationChangeHandler : IConfirmDataChangeHandler + { + private readonly string query; + private readonly IEnumerable calculations; + private readonly IInquiryHelper inquiryHandler; + + /// + /// Creates a new instance of . + /// + /// The calculations for which to handle changes. + /// The query which should be displayed when inquiring for a confirmation. + /// Object responsible for inquiring the required data. + /// Thrown when any parameter is null. + public CalculationChangeHandler(IEnumerable calculations, + string query, + IInquiryHelper inquiryHandler) + { + if (calculations == null) + { + throw new ArgumentNullException(nameof(calculations)); + } + if (query == null) + { + throw new ArgumentNullException(nameof(query)); + } + if (inquiryHandler == null) + { + throw new ArgumentNullException(nameof(inquiryHandler)); + } + this.calculations = calculations; + this.query = query; + this.inquiryHandler = inquiryHandler; + } + + public bool RequireConfirmation() + { + return calculations.Any(calc => calc.HasOutput); + } + + public bool InquireConfirmation() + { + return inquiryHandler.InquireContinuation(query); + } + } +} \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Forms/ChangeHandlers/FailureMechanismCalculationChangeHandler.cs =================================================================== diff -u -rb3b6c13cf736c134476b3db34281332d01ca86b1 -r2702ecf9aaf678cf869dc330f8ff560b3de4672a --- Ringtoets/Common/src/Ringtoets.Common.Forms/ChangeHandlers/FailureMechanismCalculationChangeHandler.cs (.../FailureMechanismCalculationChangeHandler.cs) (revision b3b6c13cf736c134476b3db34281332d01ca86b1) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/ChangeHandlers/FailureMechanismCalculationChangeHandler.cs (.../FailureMechanismCalculationChangeHandler.cs) (revision 2702ecf9aaf678cf869dc330f8ff560b3de4672a) @@ -40,7 +40,7 @@ /// /// Creates a new instance of . /// - /// Failure mechanism for which to handle changes of the failure mechanism. + /// Failure mechanism for which to handle changes. /// The query which should be displayed when inquiring for a confirmation. /// Object responsible for inquiring required data. /// Thrown when any input parameter is null. Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Ringtoets.Common.Forms.csproj =================================================================== diff -u -ra7f920661887773056c051edc7872d27f724c840 -r2702ecf9aaf678cf869dc330f8ff560b3de4672a --- Ringtoets/Common/src/Ringtoets.Common.Forms/Ringtoets.Common.Forms.csproj (.../Ringtoets.Common.Forms.csproj) (revision a7f920661887773056c051edc7872d27f724c840) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/Ringtoets.Common.Forms.csproj (.../Ringtoets.Common.Forms.csproj) (revision 2702ecf9aaf678cf869dc330f8ff560b3de4672a) @@ -49,6 +49,7 @@ + Index: Ringtoets/Common/test/Ringtoets.Common.Data.TestUtil/TestCalculation.cs =================================================================== diff -u -rb3b6c13cf736c134476b3db34281332d01ca86b1 -r2702ecf9aaf678cf869dc330f8ff560b3de4672a --- Ringtoets/Common/test/Ringtoets.Common.Data.TestUtil/TestCalculation.cs (.../TestCalculation.cs) (revision b3b6c13cf736c134476b3db34281332d01ca86b1) +++ Ringtoets/Common/test/Ringtoets.Common.Data.TestUtil/TestCalculation.cs (.../TestCalculation.cs) (revision 2702ecf9aaf678cf869dc330f8ff560b3de4672a) @@ -39,7 +39,7 @@ } public string Name { get; set; } - public bool HasOutput { get; } + public bool HasOutput { get; set; } public Comment Comments { get; } public void ClearOutput() {} } Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/ChangeHandlers/CalculationChangeHandlerTest.cs =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/ChangeHandlers/CalculationChangeHandlerTest.cs (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/ChangeHandlers/CalculationChangeHandlerTest.cs (revision 2702ecf9aaf678cf869dc330f8ff560b3de4672a) @@ -0,0 +1,184 @@ +// Copyright (C) Stichting Deltares 2017. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets 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; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Forms.ChangeHandlers; +using Ringtoets.Common.IO; + +namespace Ringtoets.Common.Forms.Test.ChangeHandlers +{ + [TestFixture] + public class CalculationChangeHandlerTest + { + [Test] + public void Constructor_WithoutCalculations_ThrowsArgumentNullException() + { + // Setup + var mockRepository = new MockRepository(); + var inquiryHandler = mockRepository.Stub(); + mockRepository.ReplayAll(); + + // Call + TestDelegate test = () => new CalculationChangeHandler(null, string.Empty, inquiryHandler); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("calculations", paramName); + mockRepository.VerifyAll(); + } + + [Test] + public void Constructor_WithoutInquiryHandler_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => new CalculationChangeHandler(Enumerable.Empty(), + string.Empty, + null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("inquiryHandler", paramName); + } + + [Test] + public void Constructor_WithoutQuery_ThrowsArgumentNullException() + { + // Setup + var mockRepository = new MockRepository(); + var inquiryHandler = mockRepository.Stub(); + mockRepository.ReplayAll(); + + // Call + TestDelegate test = () => new CalculationChangeHandler(Enumerable.Empty(), + null, + inquiryHandler); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("query", paramName); + } + + [Test] + public void Constructor_WithParameters_ImplementsExpectedInterface() + { + // Setup + var mockRepository = new MockRepository(); + var inquiryHandler = mockRepository.StrictMock(); + mockRepository.ReplayAll(); + + // Call + var handler = new CalculationChangeHandler(Enumerable.Empty(), + string.Empty, + inquiryHandler); + + // Assert + Assert.IsInstanceOf(handler); + mockRepository.VerifyAll(); + } + + [Test] + public void RequireConfirmation_WithAllCalculationsWithoutOutput_ReturnFalse() + { + // Setup + var mockRepository = new MockRepository(); + var inquiryHandler = mockRepository.StrictMock(); + mockRepository.ReplayAll(); + + var calculations = new[] + { + new TestCalculation("Test") + }; + + var handler = new CalculationChangeHandler(calculations, + string.Empty, + inquiryHandler); + + // Call + bool requireConfirmation = handler.RequireConfirmation(); + + // Assert + Assert.IsFalse(requireConfirmation); + mockRepository.VerifyAll(); + } + + [Test] + public void RequireConfirmation_CalculationsWithOutput_ReturnTrue() + { + // Setup + var mockRepository = new MockRepository(); + var inquiryHandler = mockRepository.StrictMock(); + mockRepository.ReplayAll(); + + var calculations = new[] + { + new TestCalculation("Test 1") + { + HasOutput = true + }, + new TestCalculation("Test 2") + }; + + var handler = new CalculationChangeHandler(calculations, + string.Empty, + inquiryHandler); + + // Call + bool requireConfirmation = handler.RequireConfirmation(); + + // Assert + Assert.IsTrue(requireConfirmation); + mockRepository.VerifyAll(); + } + + [Test] + [TestCase("I am a query", true)] + [TestCase("I am a query", false)] + [TestCase("", true)] + [TestCase("", false)] + [TestCase(" ", true)] + [TestCase(" ", false)] + public void InquireConfirmation_Always_ShowsConfirmationDialogReturnResultOfInquiry(string message, bool expectedResult) + { + // Setup + var mockRepository = new MockRepository(); + var inquiryHandler = mockRepository.StrictMock(); + inquiryHandler.Expect(ih => ih.InquireContinuation(message)).Return(expectedResult); + mockRepository.ReplayAll(); + + var handler = new CalculationChangeHandler(Enumerable.Empty(), + message, + inquiryHandler); + + // Call + bool result = handler.InquireConfirmation(); + + // Assert + Assert.AreEqual(expectedResult, result); + mockRepository.VerifyAll(); + } + } +} \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Ringtoets.Common.Forms.Test.csproj =================================================================== diff -u -ra7f920661887773056c051edc7872d27f724c840 -r2702ecf9aaf678cf869dc330f8ff560b3de4672a --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Ringtoets.Common.Forms.Test.csproj (.../Ringtoets.Common.Forms.Test.csproj) (revision a7f920661887773056c051edc7872d27f724c840) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Ringtoets.Common.Forms.Test.csproj (.../Ringtoets.Common.Forms.Test.csproj) (revision 2702ecf9aaf678cf869dc330f8ff560b3de4672a) @@ -67,6 +67,7 @@ +