Index: Riskeer/Piping/src/Riskeer.Piping.Plugin/ImportInfos/PipingImportInfoFactory.cs =================================================================== diff -u -rc277d670676a9c439a1191d8617d1f20c3117a36 -r1dfc093cdcb5e769cb4da55ffb020f0ab8bb071b --- Riskeer/Piping/src/Riskeer.Piping.Plugin/ImportInfos/PipingImportInfoFactory.cs (.../PipingImportInfoFactory.cs) (revision c277d670676a9c439a1191d8617d1f20c3117a36) +++ Riskeer/Piping/src/Riskeer.Piping.Plugin/ImportInfos/PipingImportInfoFactory.cs (.../PipingImportInfoFactory.cs) (revision 1dfc093cdcb5e769cb4da55ffb020f0ab8bb071b) @@ -21,13 +21,16 @@ using System; using System.Linq; +using Core.Common.Gui.Helpers; using Core.Common.Gui.Plugin; using Core.Common.Util; using Riskeer.Common.IO.FileImporters; using Riskeer.Common.IO.FileImporters.MessageProviders; using Riskeer.Piping.Data; +using Riskeer.Piping.Forms.ChangeHandlers; using Riskeer.Piping.Forms.PresentationObjects; using Riskeer.Piping.Plugin.FileImporter; +using Riskeer.Piping.Plugin.Properties; using RiskeerCommonFormsResources = Riskeer.Common.Forms.Properties.Resources; using RiskeerCommonIOResources = Riskeer.Common.IO.Properties.Resources; @@ -41,17 +44,16 @@ /// /// Creates a object for a . /// - /// The to verify whether changes that are - /// induced by the importer are allowed. + /// Object responsible for inquiring required data. /// An object. - /// Thrown when + /// Thrown when /// is null. public static ImportInfo CreateFailureMechanismSectionsImportInfo( - Func verifyUpdatesFunc) + IInquiryHelper inquiryHelper) { - if (verifyUpdatesFunc == null) + if (inquiryHelper == null) { - throw new ArgumentNullException(nameof(verifyUpdatesFunc)); + throw new ArgumentNullException(nameof(inquiryHelper)); } return new ImportInfo @@ -66,7 +68,14 @@ context.WrappedData, context.AssessmentSection.ReferenceLine, filePath, new PipingFailureMechanismSectionReplaceStrategy((PipingFailureMechanism) context.WrappedData), new ImportMessageProvider()), - VerifyUpdates = verifyUpdatesFunc + VerifyUpdates = context => + { + var changeHandler = new PipingFailureMechanismCalculationChangeHandler( + (PipingFailureMechanism) context.WrappedData, + Resources.PipingImportInfoFactory_VerifyFailureMechanismSectionImport_When_importing_Sections_probabilistic_calculation_output_will_be_cleared_confirm, + inquiryHelper); + return !changeHandler.RequireConfirmation() || changeHandler.InquireConfirmation(); + } }; } } Index: Riskeer/Piping/src/Riskeer.Piping.Plugin/Properties/Resources.Designer.cs =================================================================== diff -u -rb03e4918d94a87bef23992b2d0b242cc6b8719c6 -r1dfc093cdcb5e769cb4da55ffb020f0ab8bb071b --- Riskeer/Piping/src/Riskeer.Piping.Plugin/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision b03e4918d94a87bef23992b2d0b242cc6b8719c6) +++ Riskeer/Piping/src/Riskeer.Piping.Plugin/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 1dfc093cdcb5e769cb4da55ffb020f0ab8bb071b) @@ -118,6 +118,18 @@ } /// + /// Looks up a localized string similar to Als u een vakindeling importeert, dan worden de resultaten van alle probabilistische piping berekeningen verwijderd. + /// + ///Weet u zeker dat u wilt doorgaan?. + /// + public static string PipingImportInfoFactory_VerifyFailureMechanismSectionImport_When_importing_Sections_probabilistic_calculation_output_will_be_cleared_confirm { + get { + return ResourceManager.GetString("PipingImportInfoFactory_VerifyFailureMechanismSectionImport_When_importing_Sectio" + + "ns_probabilistic_calculation_output_will_be_cleared_confirm", resourceCulture); + } + } + + /// /// Looks up a localized string similar to Alle berekeningen met een profielschematisatie bijwerken.. /// public static string PipingPlugin_CreateUpdateEntryAndExitPointItem_Update_all_calculations_with_surface_line_ToolTip { Index: Riskeer/Piping/src/Riskeer.Piping.Plugin/Properties/Resources.resx =================================================================== diff -u -rb03e4918d94a87bef23992b2d0b242cc6b8719c6 -r1dfc093cdcb5e769cb4da55ffb020f0ab8bb071b --- Riskeer/Piping/src/Riskeer.Piping.Plugin/Properties/Resources.resx (.../Resources.resx) (revision b03e4918d94a87bef23992b2d0b242cc6b8719c6) +++ Riskeer/Piping/src/Riskeer.Piping.Plugin/Properties/Resources.resx (.../Resources.resx) (revision 1dfc093cdcb5e769cb4da55ffb020f0ab8bb071b) @@ -170,4 +170,9 @@ Voeg een nieuwe probabilistische berekening toe aan deze map met berekeningen. + + Als u een vakindeling importeert, dan worden de resultaten van alle probabilistische piping berekeningen verwijderd. + +Weet u zeker dat u wilt doorgaan? + \ No newline at end of file Index: Riskeer/Piping/test/Riskeer.Piping.Plugin.Test/ImportInfos/PipingFailureMechanismSectionsContextImportInfoTest.cs =================================================================== diff -u --- Riskeer/Piping/test/Riskeer.Piping.Plugin.Test/ImportInfos/PipingFailureMechanismSectionsContextImportInfoTest.cs (revision 0) +++ Riskeer/Piping/test/Riskeer.Piping.Plugin.Test/ImportInfos/PipingFailureMechanismSectionsContextImportInfoTest.cs (revision 1dfc093cdcb5e769cb4da55ffb020f0ab8bb071b) @@ -0,0 +1,270 @@ +// 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.Drawing; +using Core.Common.Base.IO; +using Core.Common.Gui.Helpers; +using Core.Common.Gui.Plugin; +using Core.Common.TestUtil; +using Core.Common.Util; +using NUnit.Framework; +using Rhino.Mocks; +using Riskeer.Common.Data.AssessmentSection; +using Riskeer.Common.Data.TestUtil; +using Riskeer.Common.IO.FileImporters; +using Riskeer.Piping.Data; +using Riskeer.Piping.Data.Probabilistic; +using Riskeer.Piping.Data.SemiProbabilistic; +using Riskeer.Piping.Data.TestUtil; +using Riskeer.Piping.Forms.PresentationObjects; +using Riskeer.Piping.Plugin.ImportInfos; +using RiskeerCommonFormsResources = Riskeer.Common.Forms.Properties.Resources; + +namespace Riskeer.Piping.Plugin.Test.ImportInfos +{ + [TestFixture] + public class PipingFailureMechanismSectionsContextImportInfoTest + { + [Test] + public void Name_Always_ReturnExpectedName() + { + // Setup + var mocks = new MockRepository(); + var inquiryHelper = mocks.Stub(); + mocks.ReplayAll(); + + ImportInfo importInfo = GetImportInfo(inquiryHelper); + + // Call + string name = importInfo.Name; + + // Assert + Assert.AreEqual("Vakindeling", name); + mocks.VerifyAll(); + } + + [Test] + public void Category_Always_ReturnExpectedCategory() + { + // Setup + var mocks = new MockRepository(); + var inquiryHelper = mocks.Stub(); + mocks.ReplayAll(); + + ImportInfo importInfo = GetImportInfo(inquiryHelper); + + // Call + string category = importInfo.Category; + + // Assert + Assert.AreEqual("Algemeen", category); + mocks.VerifyAll(); + } + + [Test] + public void Image_Always_ReturnExpectedIcon() + { + // Setup + var mocks = new MockRepository(); + var inquiryHelper = mocks.Stub(); + mocks.ReplayAll(); + + ImportInfo importInfo = GetImportInfo(inquiryHelper); + + // Call + Image image = importInfo.Image; + + // Assert + TestHelper.AssertImagesAreEqual(RiskeerCommonFormsResources.SectionsIcon, image); + mocks.VerifyAll(); + } + + [Test] + public void IsEnabled_ReferenceLineWithoutGeometry_ReturnFalse() + { + // Setup + var mocks = new MockRepository(); + var inquiryHelper = mocks.Stub(); + var assessmentSection = mocks.Stub(); + assessmentSection.Stub(a => a.ReferenceLine).Return(new ReferenceLine()); + mocks.ReplayAll(); + + var context = new PipingFailureMechanismSectionsContext(new PipingFailureMechanism(), assessmentSection); + ImportInfo importInfo = GetImportInfo(inquiryHelper); + + // Call + bool isEnabled = importInfo.IsEnabled(context); + + // Assert + Assert.IsFalse(isEnabled); + mocks.VerifyAll(); + } + + [Test] + public void IsEnabled_ReferenceLineWithGeometry_ReturnTrue() + { + // Setup + var mocks = new MockRepository(); + var inquiryHelper = mocks.Stub(); + var assessmentSection = mocks.Stub(); + assessmentSection.Stub(a => a.ReferenceLine).Return(ReferenceLineTestFactory.CreateReferenceLineWithGeometry()); + mocks.ReplayAll(); + + var context = new PipingFailureMechanismSectionsContext(new PipingFailureMechanism(), assessmentSection); + ImportInfo importInfo = GetImportInfo(inquiryHelper); + + // Call + bool isEnabled = importInfo.IsEnabled(context); + + // Assert + Assert.IsTrue(isEnabled); + mocks.VerifyAll(); + } + + [Test] + public void FileFilterGenerator_Always_ReturnExpectedFileFilter() + { + // Setup + var mocks = new MockRepository(); + var inquiryHelper = mocks.Stub(); + mocks.ReplayAll(); + + ImportInfo importInfo = GetImportInfo(inquiryHelper); + + // Call + FileFilterGenerator fileFilterGenerator = importInfo.FileFilterGenerator; + + // Assert + Assert.AreEqual("Shapebestand (*.shp)|*.shp", fileFilterGenerator.Filter); + mocks.VerifyAll(); + } + + [Test] + public void VerifyUpdates_NoProbabilisticCalculations_ReturnsTrue() + { + // Setup + var mocks = new MockRepository(); + var inquiryHelper = mocks.StrictMock(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new PipingFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(new SemiProbabilisticPipingCalculationScenario + { + Output = PipingTestDataGenerator.GetRandomSemiProbabilisticPipingOutput() + }); + + var context = new PipingFailureMechanismSectionsContext(failureMechanism, assessmentSection); + ImportInfo importInfo = GetImportInfo(inquiryHelper); + + // Call + bool updatesVerified = importInfo.VerifyUpdates(context); + + // Assert + Assert.IsTrue(updatesVerified); + mocks.VerifyAll(); + } + + [Test] + public void VerifyUpdates_ProbabilisticCalculationsWithoutOutput_ReturnsTrue() + { + // Setup + var mocks = new MockRepository(); + var inquiryHelper = mocks.StrictMock(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new PipingFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(new ProbabilisticPipingCalculationScenario()); + + var context = new PipingFailureMechanismSectionsContext(failureMechanism, assessmentSection); + ImportInfo importInfo = GetImportInfo(inquiryHelper); + + // Call + bool updatesVerified = importInfo.VerifyUpdates(context); + + // Assert + Assert.IsTrue(updatesVerified); + mocks.VerifyAll(); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void VerifyUpdates_CalculationWithOutputs_AlwaysReturnsExpectedInquiryMessage(bool isActionConfirmed) + { + // Setup + string expectedInquiryMessage = "Als u een vakindeling importeert, dan worden de resultaten van alle probabilistische piping berekeningen verwijderd." + + $"{Environment.NewLine}{Environment.NewLine}Weet u zeker dat u wilt doorgaan?"; + + var mocks = new MockRepository(); + var inquiryHelper = mocks.StrictMock(); + inquiryHelper.Expect(ih => ih.InquireContinuation(expectedInquiryMessage)) + .Return(isActionConfirmed); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new PipingFailureMechanism(); + var calculationWithOutput = new ProbabilisticPipingCalculationScenario + { + Output = PipingTestDataGenerator.GetRandomProbabilisticPipingOutputWithIllustrationPoints() + }; + failureMechanism.CalculationsGroup.Children.Add(calculationWithOutput); + + var context = new PipingFailureMechanismSectionsContext(failureMechanism, assessmentSection); + ImportInfo importInfo = GetImportInfo(inquiryHelper); + + // Call + bool updatesVerified = importInfo.VerifyUpdates(context); + + // Assert + Assert.AreEqual(isActionConfirmed, updatesVerified); + mocks.VerifyAll(); + } + + [Test] + public void CreateFileImporter_Always_ReturnFileImporter() + { + // Setup + var mocks = new MockRepository(); + var inquiryHelper = mocks.Stub(); + var assessmentSection = mocks.Stub(); + assessmentSection.Stub(a => a.ReferenceLine).Return(new ReferenceLine()); + mocks.ReplayAll(); + + var context = new PipingFailureMechanismSectionsContext(new PipingFailureMechanism(), assessmentSection); + ImportInfo importInfo = GetImportInfo(inquiryHelper); + + // Call + IFileImporter importer = importInfo.CreateFileImporter(context, ""); + + // Assert + Assert.IsInstanceOf(importer); + mocks.VerifyAll(); + } + + private static ImportInfo GetImportInfo(IInquiryHelper inquiryHelper) + { + return PipingImportInfoFactory.CreateFailureMechanismSectionsImportInfo(inquiryHelper); + } + } +} \ No newline at end of file Index: Riskeer/Piping/test/Riskeer.Piping.Plugin.Test/ImportInfos/PipingImportInfoFactoryTest.cs =================================================================== diff -u -rc277d670676a9c439a1191d8617d1f20c3117a36 -r1dfc093cdcb5e769cb4da55ffb020f0ab8bb071b --- Riskeer/Piping/test/Riskeer.Piping.Plugin.Test/ImportInfos/PipingImportInfoFactoryTest.cs (.../PipingImportInfoFactoryTest.cs) (revision c277d670676a9c439a1191d8617d1f20c3117a36) +++ Riskeer/Piping/test/Riskeer.Piping.Plugin.Test/ImportInfos/PipingImportInfoFactoryTest.cs (.../PipingImportInfoFactoryTest.cs) (revision 1dfc093cdcb5e769cb4da55ffb020f0ab8bb071b) @@ -20,15 +20,10 @@ // All rights reserved. using System; -using Core.Common.Base.Geometry; +using Core.Common.Gui.Helpers; using Core.Common.Gui.Plugin; -using Core.Common.TestUtil; -using Core.Common.Util; using NUnit.Framework; -using Riskeer.Common.Data.TestUtil; -using Riskeer.Common.IO.FileImporters; -using Riskeer.Common.Primitives; -using Riskeer.Piping.Data; +using Rhino.Mocks; using Riskeer.Piping.Forms.PresentationObjects; using Riskeer.Piping.Plugin.ImportInfos; using RiskeerCommonFormsResources = Riskeer.Common.Forms.Properties.Resources; @@ -39,51 +34,29 @@ public class PipingImportInfoFactoryTest { [Test] - public void CreateFailureMechanismSectionsImportInfo_VerifyUpdatesFuncNull_ThrowsArgumentNullException() + public void CreateFailureMechanismSectionsImportInfo_InquiryHelperNull_ThrowsArgumentNullException() { // Call void Call() => PipingImportInfoFactory.CreateFailureMechanismSectionsImportInfo(null); // Assert var exception = Assert.Throws(Call); - Assert.AreEqual("verifyUpdatesFunc", exception.ParamName); + Assert.AreEqual("inquiryHelper", exception.ParamName); } - + [Test] - [TestCase(true)] - [TestCase(false)] - public void CreateFailureMechanismSectionsImportInfo_WithData_ReturnsImportInfo(bool isEnabled) + public void CreateFailureMechanismSectionsImportInfo_WithData_ReturnsImportInfo() { // Setup - var assessmentSection = new AssessmentSectionStub(); - if (isEnabled) - { - assessmentSection.ReferenceLine.SetGeometry(new[] - { - new Point2D(0, 0) - }); - } + var mocks = new MockRepository(); + var inquiryHelper = mocks.Stub(); + mocks.ReplayAll(); - var context = new PipingFailureMechanismSectionsContext(new PipingFailureMechanism(), assessmentSection); - - // Call - Func verifyUpdatesFunc = c => true; - ImportInfo importInfo = PipingImportInfoFactory.CreateFailureMechanismSectionsImportInfo( - verifyUpdatesFunc); + ImportInfo importInfo = PipingImportInfoFactory.CreateFailureMechanismSectionsImportInfo(inquiryHelper); // Assert - Assert.AreEqual("Vakindeling", importInfo.Name); - Assert.AreEqual("Algemeen", importInfo.Category); - - FileFilterGenerator fileFilterGenerator = importInfo.FileFilterGenerator; - Assert.AreEqual("Shapebestand (*.shp)|*.shp", fileFilterGenerator.Filter); - - TestHelper.AssertImagesAreEqual(RiskeerCommonFormsResources.SectionsIcon, importInfo.Image); - - Assert.AreEqual(isEnabled, importInfo.IsEnabled(context)); - Assert.IsInstanceOf(importInfo.CreateFileImporter(context, "")); - Assert.AreSame(verifyUpdatesFunc, importInfo.VerifyUpdates); + Assert.IsNotNull(importInfo); } } } \ No newline at end of file