Index: Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.IO/Exporters/MacroStabilityInwardsCalculationExporter.cs =================================================================== diff -u -r46fb298c518c3e8ae1b50a637e4186bd0fc07833 -re8c997cca0dcf343c4560301921c37791775d88f --- Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.IO/Exporters/MacroStabilityInwardsCalculationExporter.cs (.../MacroStabilityInwardsCalculationExporter.cs) (revision 46fb298c518c3e8ae1b50a637e4186bd0fc07833) +++ Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.IO/Exporters/MacroStabilityInwardsCalculationExporter.cs (.../MacroStabilityInwardsCalculationExporter.cs) (revision e8c997cca0dcf343c4560301921c37791775d88f) @@ -22,6 +22,7 @@ using System; using Components.Persistence.Stability; using Components.Persistence.Stability.Data; +using Core.Common.Base.Data; using Core.Common.Base.IO; using Core.Common.Util; using log4net; @@ -43,15 +44,18 @@ private readonly MacroStabilityInwardsCalculation calculation; private readonly IPersistenceFactory persistenceFactory; private readonly string filePath; + private readonly Func getNormativeAssessmentLevelFunc; /// /// Creates a new instance of . /// /// The calculation to export. /// The persistence factory to use. /// The file path to export to. - /// Thrown when or - /// is null. + /// + /// for obtaining the normative assessment level. + /// Thrown when , + /// or is null. /// Thrown when is invalid. /// A valid path: /// @@ -62,7 +66,7 @@ /// public MacroStabilityInwardsCalculationExporter(MacroStabilityInwardsCalculation calculation, IPersistenceFactory persistenceFactory, - string filePath) + string filePath, Func getNormativeAssessmentLevelFunc) { if (calculation == null) { @@ -74,16 +78,22 @@ throw new ArgumentNullException(nameof(persistenceFactory)); } + if (getNormativeAssessmentLevelFunc == null) + { + throw new ArgumentNullException(nameof(getNormativeAssessmentLevelFunc)); + } + IOUtils.ValidateFilePath(filePath); this.calculation = calculation; this.persistenceFactory = persistenceFactory; this.filePath = filePath; + this.getNormativeAssessmentLevelFunc = getNormativeAssessmentLevelFunc; } public bool Export() { - PersistableDataModel persistableDataModel = PersistableDataModelFactory.Create(calculation, filePath); + PersistableDataModel persistableDataModel = PersistableDataModelFactory.Create(calculation, getNormativeAssessmentLevelFunc, filePath); try { Index: Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.IO/Factories/PersistableDataModelFactory.cs =================================================================== diff -u -rc9675e594248834c75fe0a05d3d993981b2b1148 -re8c997cca0dcf343c4560301921c37791775d88f --- Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.IO/Factories/PersistableDataModelFactory.cs (.../PersistableDataModelFactory.cs) (revision c9675e594248834c75fe0a05d3d993981b2b1148) +++ Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.IO/Factories/PersistableDataModelFactory.cs (.../PersistableDataModelFactory.cs) (revision e8c997cca0dcf343c4560301921c37791775d88f) @@ -1,4 +1,4 @@ -// Copyright (C) Stichting Deltares 2019. All rights reserved. +// Copyright (C) Stichting Deltares 2019. All rights reserved. // // This file is part of Riskeer. // @@ -21,6 +21,7 @@ using System; using Components.Persistence.Stability.Data; +using Core.Common.Base.Data; using Riskeer.MacroStabilityInwards.Data; using Riskeer.MacroStabilityInwards.Primitives; @@ -35,19 +36,28 @@ /// Creates a new . /// /// The calculation to get the data from. + /// + /// for obtaining the normative assessment level. /// The filePath that is used. /// A created . /// Thrown when - /// is null. + /// or is null. /// Thrown when /// has no output. - public static PersistableDataModel Create(MacroStabilityInwardsCalculation calculation, string filePath) + public static PersistableDataModel Create(MacroStabilityInwardsCalculation calculation, + Func getNormativeAssessmentLevelFunc, + string filePath) { if (calculation == null) { throw new ArgumentNullException(nameof(calculation)); } + if (getNormativeAssessmentLevelFunc == null) + { + throw new ArgumentNullException(nameof(getNormativeAssessmentLevelFunc)); + } + if (!calculation.HasOutput) { throw new InvalidOperationException("Calculation must have output."); Index: Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.Plugin/MacroStabilityInwardsPlugin.cs =================================================================== diff -u -r064fb2c63f6035167b27a1d25de4de655959bbb7 -re8c997cca0dcf343c4560301921c37791775d88f --- Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.Plugin/MacroStabilityInwardsPlugin.cs (.../MacroStabilityInwardsPlugin.cs) (revision 064fb2c63f6035167b27a1d25de4de655959bbb7) +++ Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.Plugin/MacroStabilityInwardsPlugin.cs (.../MacroStabilityInwardsPlugin.cs) (revision e8c997cca0dcf343c4560301921c37791775d88f) @@ -172,9 +172,9 @@ { Name = Resources.MacroStabilityInwardsCalculationExporter_DisplayName, Extension = Resources.Stix_file_filter_extension, - CreateFileExporter = (context, filePath) => new MacroStabilityInwardsCalculationExporter(context.WrappedData, - new PersistenceFactory(), - filePath), + CreateFileExporter = (context, filePath) => new MacroStabilityInwardsCalculationExporter( + context.WrappedData, new PersistenceFactory(), filePath, + () => GetNormativeAssessmentLevel(context.AssessmentSection, context.WrappedData)), IsEnabled = context => context.WrappedData.HasOutput, GetExportPath = () => ExportHelper.GetFilePath(GetInquiryHelper(), new FileFilterGenerator(Resources.Stix_file_filter_extension, Resources.Stix_file_filter_description)) Index: Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.IO.Test/Exporters/MacroStabilityInwardsCalculationExporterTest.cs =================================================================== diff -u -r345ef46acae077c0c400089864a3fddbc786ef9d -re8c997cca0dcf343c4560301921c37791775d88f --- Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.IO.Test/Exporters/MacroStabilityInwardsCalculationExporterTest.cs (.../MacroStabilityInwardsCalculationExporterTest.cs) (revision 345ef46acae077c0c400089864a3fddbc786ef9d) +++ Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.IO.Test/Exporters/MacroStabilityInwardsCalculationExporterTest.cs (.../MacroStabilityInwardsCalculationExporterTest.cs) (revision e8c997cca0dcf343c4560301921c37791775d88f) @@ -45,7 +45,7 @@ mocks.ReplayAll(); // Call - var exporter = new MacroStabilityInwardsCalculationExporter(new MacroStabilityInwardsCalculation(), persistenceFactory, "ValidFilePath"); + var exporter = new MacroStabilityInwardsCalculationExporter(new MacroStabilityInwardsCalculation(), persistenceFactory, "ValidFilePath", AssessmentSectionTestHelper.GetTestAssessmentLevel); // Assert Assert.IsInstanceOf(exporter); @@ -61,7 +61,7 @@ mocks.ReplayAll(); // Call - void Call() => new MacroStabilityInwardsCalculationExporter(null, persistenceFactory, string.Empty); + void Call() => new MacroStabilityInwardsCalculationExporter(null, persistenceFactory, string.Empty, AssessmentSectionTestHelper.GetTestAssessmentLevel); // Assert var exception = Assert.Throws(Call); @@ -73,14 +73,31 @@ public void Constructor_PersistenceFactoryNull_ThrowsArgumentNullException() { // Call - void Call() => new MacroStabilityInwardsCalculationExporter(new MacroStabilityInwardsCalculation(), null, string.Empty); + void Call() => new MacroStabilityInwardsCalculationExporter(new MacroStabilityInwardsCalculation(), null, string.Empty, AssessmentSectionTestHelper.GetTestAssessmentLevel); // Assert var exception = Assert.Throws(Call); Assert.AreEqual("persistenceFactory", exception.ParamName); } [Test] + public void Constructor_GetAssessmentLevelFuncNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var persistenceFactory = mocks.Stub(); + mocks.ReplayAll(); + + // Call + void Call() => new MacroStabilityInwardsCalculationExporter(new MacroStabilityInwardsCalculation(), persistenceFactory, string.Empty, null); + + // Assert + var exception = Assert.Throws(Call); + Assert.AreEqual("getNormativeAssessmentLevelFunc", exception.ParamName); + mocks.VerifyAll(); + } + + [Test] [TestCaseSource(typeof(InvalidPathHelper), nameof(InvalidPathHelper.InvalidPaths))] public void Constructor_FilePathInvalid_ThrowsArgumentException(string filePath) { @@ -90,7 +107,7 @@ mocks.ReplayAll(); // Call - void Call() => new MacroStabilityInwardsCalculationExporter(new MacroStabilityInwardsCalculation(), persistenceFactory, filePath); + void Call() => new MacroStabilityInwardsCalculationExporter(new MacroStabilityInwardsCalculation(), persistenceFactory, filePath, AssessmentSectionTestHelper.GetTestAssessmentLevel); // Assert Assert.Throws(Call); @@ -110,7 +127,7 @@ ThrowException = true }; - var exporter = new MacroStabilityInwardsCalculationExporter(calculation, persistenceFactory, filePath); + var exporter = new MacroStabilityInwardsCalculationExporter(calculation, persistenceFactory, filePath, AssessmentSectionTestHelper.GetTestAssessmentLevel); // Call var exportResult = true; @@ -132,7 +149,7 @@ var persistenceFactory = new MacroStabilityInwardsTestPersistenceFactory(); - var exporter = new MacroStabilityInwardsCalculationExporter(calculation, persistenceFactory, filePath); + var exporter = new MacroStabilityInwardsCalculationExporter(calculation, persistenceFactory, filePath, AssessmentSectionTestHelper.GetTestAssessmentLevel); // Call bool exportResult = exporter.Export(); Index: Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.IO.Test/Factories/PersistableDataModelFactoryTest.cs =================================================================== diff -u -r8baf1e4a72fd086748259c63e6f40f5d8de021e0 -re8c997cca0dcf343c4560301921c37791775d88f --- Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.IO.Test/Factories/PersistableDataModelFactoryTest.cs (.../PersistableDataModelFactoryTest.cs) (revision 8baf1e4a72fd086748259c63e6f40f5d8de021e0) +++ Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.IO.Test/Factories/PersistableDataModelFactoryTest.cs (.../PersistableDataModelFactoryTest.cs) (revision e8c997cca0dcf343c4560301921c37791775d88f) @@ -37,21 +37,32 @@ public void Create_CalculationNull_ThrowsArgumentNullException() { // Call - void Call() => PersistableDataModelFactory.Create(null, string.Empty); + void Call() => PersistableDataModelFactory.Create(null, AssessmentSectionTestHelper.GetTestAssessmentLevel, string.Empty); // Assert var exception = Assert.Throws(Call); Assert.AreEqual("calculation", exception.ParamName); } [Test] + public void Create_GetAssessmentLevelFuncNull_ThrowsArgumentNullException() + { + // Call + void Call() => PersistableDataModelFactory.Create(new MacroStabilityInwardsCalculation(), null, string.Empty); + + // Assert + var exception = Assert.Throws(Call); + Assert.AreEqual("getNormativeAssessmentLevelFunc", exception.ParamName); + } + + [Test] public void Create_CalculationWithoutOutput_ThrowsInvalidOperationException() { // Setup MacroStabilityInwardsCalculationScenario calculation = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(new TestHydraulicBoundaryLocation()); // Call - void Call() => PersistableDataModelFactory.Create(calculation, string.Empty); + void Call() => PersistableDataModelFactory.Create(calculation, AssessmentSectionTestHelper.GetTestAssessmentLevel, string.Empty); // Assert var exception = Assert.Throws(Call); @@ -67,7 +78,7 @@ calculation.Output = MacroStabilityInwardsOutputTestFactory.CreateRandomOutput(); // Call - PersistableDataModel persistableDataModel = PersistableDataModelFactory.Create(calculation, filePath); + PersistableDataModel persistableDataModel = PersistableDataModelFactory.Create(calculation, AssessmentSectionTestHelper.GetTestAssessmentLevel, filePath); // Assert PersistableDataModelTestHelper.AssertPersistableDataModel(calculation, filePath, persistableDataModel);