Index: Ringtoets/Piping/src/Ringtoets.Piping.Forms/Factories/PipingAssemblyMapDataFeaturesFactory.cs =================================================================== diff -u -rb9d48f272caaffb9d0ee553ddf12d1d3af8966c2 -r4be49ab92023b8a73056078c2caa86bd5cfdf5e5 --- Ringtoets/Piping/src/Ringtoets.Piping.Forms/Factories/PipingAssemblyMapDataFeaturesFactory.cs (.../PipingAssemblyMapDataFeaturesFactory.cs) (revision b9d48f272caaffb9d0ee553ddf12d1d3af8966c2) +++ Ringtoets/Piping/src/Ringtoets.Piping.Forms/Factories/PipingAssemblyMapDataFeaturesFactory.cs (.../PipingAssemblyMapDataFeaturesFactory.cs) (revision 4be49ab92023b8a73056078c2caa86bd5cfdf5e5) @@ -22,20 +22,16 @@ using System; using System.Collections.Generic; using System.Linq; -using Core.Common.Util; using Core.Components.Gis.Features; -using Ringtoets.AssemblyTool.Data; -using Ringtoets.AssemblyTool.Forms; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.Exceptions; using Ringtoets.Common.Forms.Factories; using Ringtoets.Piping.Data; -using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; namespace Ringtoets.Piping.Forms.Factories { /// - /// Factory for creating collections of for assembly results. + /// Factory for creating collections of for assembly results in a . /// public static class PipingAssemblyMapDataFeaturesFactory { @@ -45,10 +41,18 @@ /// The to create the features for. /// A collection of . /// Thrown when a could not be created. + /// Thrown when + /// is null public static IEnumerable CreateSimpleAssemblyFeatures(PipingFailureMechanism failureMechanism) { - return CreateAssemblyFeatures(failureMechanism, - PipingFailureMechanismAssemblyFactory.AssembleSimpleAssessment).ToArray(); + if (failureMechanism == null) + { + throw new ArgumentNullException(nameof(failureMechanism)); + } + + return AssemblyMapDataFeaturesFactory.CreateAssemblyFeatures( + failureMechanism, + PipingFailureMechanismAssemblyFactory.AssembleSimpleAssessment); } /// @@ -58,13 +62,26 @@ /// The the belongs to. /// A collection of . /// Thrown when a could not be created. + /// Thrown when any parameter is null public static IEnumerable CreateDetailedAssemblyFeatures(PipingFailureMechanism failureMechanism, IAssessmentSection assessmentSection) { - return CreateAssemblyFeatures(failureMechanism, - sectionResult => PipingFailureMechanismAssemblyFactory.AssembleDetailedAssessment(sectionResult, - failureMechanism.Calculations.Cast(), - failureMechanism, - assessmentSection)).ToArray(); + if (failureMechanism == null) + { + throw new ArgumentNullException(nameof(failureMechanism)); + } + + if (assessmentSection == null) + { + throw new ArgumentNullException(nameof(assessmentSection)); + } + + return AssemblyMapDataFeaturesFactory.CreateAssemblyFeatures( + failureMechanism, + sectionResult => PipingFailureMechanismAssemblyFactory.AssembleDetailedAssessment( + sectionResult, + failureMechanism.Calculations.Cast(), + failureMechanism, + assessmentSection)); } /// @@ -74,31 +91,53 @@ /// The the belongs to. /// A collection of . /// Thrown when a could not be created. + /// Thrown when any parameter is null public static IEnumerable CreateTailorMadeAssemblyFeatures(PipingFailureMechanism failureMechanism, IAssessmentSection assessmentSection) { - return CreateAssemblyFeatures(failureMechanism, - sectionResult => PipingFailureMechanismAssemblyFactory.AssembleTailorMadeAssessment(sectionResult, - failureMechanism, - assessmentSection)).ToArray(); + if (failureMechanism == null) + { + throw new ArgumentNullException(nameof(failureMechanism)); + } + + if (assessmentSection == null) + { + throw new ArgumentNullException(nameof(assessmentSection)); + } + + return AssemblyMapDataFeaturesFactory.CreateAssemblyFeatures( + failureMechanism, + sectionResult => PipingFailureMechanismAssemblyFactory.AssembleTailorMadeAssessment(sectionResult, + failureMechanism, + assessmentSection)); } - private static IEnumerable CreateAssemblyFeatures(PipingFailureMechanism failureMechanism, - Func getAssemblyFunc) + /// + /// Creates features for the combined assembly results in . + /// + /// The to create the features for. + /// The the belongs to. + /// A collection of . + /// Thrown when a could not be created. + /// Thrown when any parameter is null + public static IEnumerable CreateCombinedAssemblyFeatures(PipingFailureMechanism failureMechanism, IAssessmentSection assessmentSection) { - for (var i = 0; i < failureMechanism.SectionResults.Count(); i++) + if (failureMechanism == null) { - PipingFailureMechanismSectionResult sectionResult = failureMechanism.SectionResults.ElementAt(i); - MapFeature feature = RingtoetsMapDataFeaturesFactory.CreateSingleLineMapFeature(sectionResult.Section.Points); - FailureMechanismSectionAssembly assemblyResult = getAssemblyFunc(sectionResult); + throw new ArgumentNullException(nameof(failureMechanism)); + } - feature.MetaData[RingtoetsCommonFormsResources.AssemblyCategory_Group_DisplayName] = - new EnumDisplayWrapper( - DisplayFailureMechanismSectionAssemblyCategoryGroupConverter.Convert(assemblyResult.Group)).DisplayName; - - feature.MetaData[RingtoetsCommonFormsResources.MetaData_Probability] = assemblyResult.Probability; - - yield return feature; + if (assessmentSection == null) + { + throw new ArgumentNullException(nameof(assessmentSection)); } + + return AssemblyMapDataFeaturesFactory.CreateAssemblyFeatures( + failureMechanism, + sectionResult => PipingFailureMechanismAssemblyFactory.AssembleCombinedAssessment( + sectionResult, + failureMechanism.Calculations.Cast(), + failureMechanism, + assessmentSection)); } } } \ No newline at end of file Index: Ringtoets/Piping/src/Ringtoets.Piping.Forms/Ringtoets.Piping.Forms.csproj =================================================================== diff -u -rd77f0eae87afa15b1a5484d5ef7c54f952a04166 -r4be49ab92023b8a73056078c2caa86bd5cfdf5e5 --- Ringtoets/Piping/src/Ringtoets.Piping.Forms/Ringtoets.Piping.Forms.csproj (.../Ringtoets.Piping.Forms.csproj) (revision d77f0eae87afa15b1a5484d5ef7c54f952a04166) +++ Ringtoets/Piping/src/Ringtoets.Piping.Forms/Ringtoets.Piping.Forms.csproj (.../Ringtoets.Piping.Forms.csproj) (revision 4be49ab92023b8a73056078c2caa86bd5cfdf5e5) @@ -17,6 +17,7 @@ + Form @@ -147,6 +148,11 @@ Ringtoets.AssemblyTool.Data False + + {22C5DDB8-2491-4BC6-BDC6-2A7B7EBF40C1} + Ringtoets.AssemblyTool.Forms + False + {d4200f43-3f72-4f42-af0a-8ced416a38ec} Ringtoets.Common.Data Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Factories/PipingAssemblyMapDataFeaturesFactoryTest.cs =================================================================== diff -u --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Factories/PipingAssemblyMapDataFeaturesFactoryTest.cs (revision 0) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Factories/PipingAssemblyMapDataFeaturesFactoryTest.cs (revision 4be49ab92023b8a73056078c2caa86bd5cfdf5e5) @@ -0,0 +1,298 @@ +// Copyright (C) Stichting Deltares 2018. 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.TestUtil; +using Core.Common.Util; +using Core.Components.Gis.Features; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.AssemblyTool.Data; +using Ringtoets.AssemblyTool.Forms; +using Ringtoets.AssemblyTool.KernelWrapper.Calculators; +using Ringtoets.AssemblyTool.KernelWrapper.TestUtil.Calculators; +using Ringtoets.AssemblyTool.KernelWrapper.TestUtil.Calculators.Assembly; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Piping.Data; +using Ringtoets.Piping.Forms.Factories; + +namespace Ringtoets.Piping.Forms.Test.Factories +{ + [TestFixture] + public class PipingAssemblyMapDataFeaturesFactoryTest + { + private const string categoryMetaData = "Categorie"; + private const string probabilityMetaData = "Faalkans"; + + [Test] + public void CreateSimpleAssemblyFeatures_FailureMechanismNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => PipingAssemblyMapDataFeaturesFactory.CreateSimpleAssemblyFeatures(null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("failureMechanism", paramName); + } + + [Test] + public void CreateSimpleAssemblyFeatures_WithValidData_ReturnsFeaturesCollection() + { + // Setup + var random = new Random(39); + var failureMechanism = new PipingFailureMechanism(); + FailureMechanismTestHelper.AddSections(failureMechanism, random.Next(0, 10)); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + + calculator.SimpleAssessmentAssemblyOutput = new FailureMechanismSectionAssembly(random.NextDouble(), + random.NextEnumValue()); + + // Call + IEnumerable features = PipingAssemblyMapDataFeaturesFactory.CreateSimpleAssemblyFeatures(failureMechanism); + + // Assert + Assert.AreEqual(failureMechanism.Sections.Count(), features.Count()); + + for (var i = 0; i < features.Count(); i++) + { + FailureMechanismSection section = failureMechanism.Sections.ElementAt(i); + Assert.AreEqual(1, features.ElementAt(i).MapGeometries.Count()); + CollectionAssert.AreEqual(section.Points, features.ElementAt(i).MapGeometries.Single().PointCollections.Single()); + Assert.AreEqual(2, features.ElementAt(i).MetaData.Keys.Count); + Assert.AreEqual(new EnumDisplayWrapper( + DisplayFailureMechanismSectionAssemblyCategoryGroupConverter.Convert(calculator.SimpleAssessmentAssemblyOutput.Group)).DisplayName, + features.ElementAt(i).MetaData[categoryMetaData]); + Assert.AreEqual(calculator.SimpleAssessmentAssemblyOutput.Probability, + features.ElementAt(i).MetaData[probabilityMetaData]); + } + } + } + + [Test] + public void CreateDetailedAssemblyFeatures_FailureMechanismNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + // Call + TestDelegate call = () => PipingAssemblyMapDataFeaturesFactory.CreateDetailedAssemblyFeatures(null, assessmentSection); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("failureMechanism", paramName); + mocks.VerifyAll(); + } + + [Test] + public void CreateDetailedAssemblyFeatures_AssessmentSectionNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => PipingAssemblyMapDataFeaturesFactory.CreateDetailedAssemblyFeatures(new PipingFailureMechanism(), null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("assessmentSection", paramName); + } + + [Test] + public void CreateDetailedAssemblyFeatures_WithValidData_ReturnsFeaturesCollection() + { + // Setup + var random = new Random(39); + var assessmentSection = new AssessmentSectionStub(); + var failureMechanism = new PipingFailureMechanism(); + FailureMechanismTestHelper.AddSections(failureMechanism, random.Next(0, 10)); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + + calculator.DetailedAssessmentAssemblyOutput = new FailureMechanismSectionAssembly(random.NextDouble(), + random.NextEnumValue()); + + // Call + IEnumerable features = PipingAssemblyMapDataFeaturesFactory.CreateDetailedAssemblyFeatures(failureMechanism, + assessmentSection); + + // Assert + Assert.AreEqual(failureMechanism.Sections.Count(), features.Count()); + + for (var i = 0; i < features.Count(); i++) + { + FailureMechanismSection section = failureMechanism.Sections.ElementAt(i); + Assert.AreEqual(1, features.ElementAt(i).MapGeometries.Count()); + CollectionAssert.AreEqual(section.Points, features.ElementAt(i).MapGeometries.Single().PointCollections.Single()); + Assert.AreEqual(2, features.ElementAt(i).MetaData.Keys.Count); + Assert.AreEqual(new EnumDisplayWrapper( + DisplayFailureMechanismSectionAssemblyCategoryGroupConverter.Convert(calculator.DetailedAssessmentAssemblyOutput.Group)).DisplayName, + features.ElementAt(i).MetaData[categoryMetaData]); + Assert.AreEqual(calculator.DetailedAssessmentAssemblyOutput.Probability, + features.ElementAt(i).MetaData[probabilityMetaData]); + } + } + } + + [Test] + public void CreateTailorMadeAssemblyFeatures_FailureMechanismNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + // Call + TestDelegate call = () => PipingAssemblyMapDataFeaturesFactory.CreateTailorMadeAssemblyFeatures(null, assessmentSection); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("failureMechanism", paramName); + mocks.VerifyAll(); + } + + [Test] + public void CreateTailorMadeAssemblyFeatures_AssessmentSectionNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => PipingAssemblyMapDataFeaturesFactory.CreateTailorMadeAssemblyFeatures(new PipingFailureMechanism(), null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("assessmentSection", paramName); + } + + [Test] + public void CreateTailorMadeAssemblyFeatures_WithValidData_ReturnsFeaturesCollection() + { + // Setup + var random = new Random(39); + var assessmentSection = new AssessmentSectionStub(); + var failureMechanism = new PipingFailureMechanism(); + FailureMechanismTestHelper.AddSections(failureMechanism, random.Next(0, 10)); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + + calculator.TailorMadeAssessmentAssemblyOutput = new FailureMechanismSectionAssembly(random.NextDouble(), + random.NextEnumValue()); + + // Call + IEnumerable features = PipingAssemblyMapDataFeaturesFactory.CreateTailorMadeAssemblyFeatures(failureMechanism, + assessmentSection); + + // Assert + Assert.AreEqual(failureMechanism.Sections.Count(), features.Count()); + + for (var i = 0; i < features.Count(); i++) + { + FailureMechanismSection section = failureMechanism.Sections.ElementAt(i); + Assert.AreEqual(1, features.ElementAt(i).MapGeometries.Count()); + CollectionAssert.AreEqual(section.Points, features.ElementAt(i).MapGeometries.Single().PointCollections.Single()); + Assert.AreEqual(2, features.ElementAt(i).MetaData.Keys.Count); + Assert.AreEqual(new EnumDisplayWrapper( + DisplayFailureMechanismSectionAssemblyCategoryGroupConverter.Convert(calculator.TailorMadeAssessmentAssemblyOutput.Group)).DisplayName, + features.ElementAt(i).MetaData[categoryMetaData]); + Assert.AreEqual(calculator.TailorMadeAssessmentAssemblyOutput.Probability, + features.ElementAt(i).MetaData[probabilityMetaData]); + } + } + } + + [Test] + public void CreateCombinedAssemblyFeatures_FailureMechanismNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + // Call + TestDelegate call = () => PipingAssemblyMapDataFeaturesFactory.CreateCombinedAssemblyFeatures(null, assessmentSection); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("failureMechanism", paramName); + mocks.VerifyAll(); + } + + [Test] + public void CreateCombinedAssemblyFeatures_AssessmentSectionNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => PipingAssemblyMapDataFeaturesFactory.CreateCombinedAssemblyFeatures(new PipingFailureMechanism(), null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("assessmentSection", paramName); + } + + [Test] + public void CreateCombinedAssemblyFeatures_WithValidData_ReturnsFeaturesCollection() + { + // Setup + var random = new Random(39); + var assessmentSection = new AssessmentSectionStub(); + var failureMechanism = new PipingFailureMechanism(); + FailureMechanismTestHelper.AddSections(failureMechanism, random.Next(0, 10)); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + + calculator.CombinedAssemblyOutput = new FailureMechanismSectionAssembly(random.NextDouble(), + random.NextEnumValue()); + + // Call + IEnumerable features = PipingAssemblyMapDataFeaturesFactory.CreateCombinedAssemblyFeatures(failureMechanism, + assessmentSection); + + // Assert + Assert.AreEqual(failureMechanism.Sections.Count(), features.Count()); + + for (var i = 0; i < features.Count(); i++) + { + FailureMechanismSection section = failureMechanism.Sections.ElementAt(i); + Assert.AreEqual(1, features.ElementAt(i).MapGeometries.Count()); + CollectionAssert.AreEqual(section.Points, features.ElementAt(i).MapGeometries.Single().PointCollections.Single()); + Assert.AreEqual(2, features.ElementAt(i).MetaData.Keys.Count); + Assert.AreEqual(new EnumDisplayWrapper( + DisplayFailureMechanismSectionAssemblyCategoryGroupConverter.Convert(calculator.CombinedAssemblyOutput.Group)).DisplayName, + features.ElementAt(i).MetaData[categoryMetaData]); + Assert.AreEqual(calculator.CombinedAssemblyOutput.Probability, + features.ElementAt(i).MetaData[probabilityMetaData]); + } + } + } + } +} \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Ringtoets.Piping.Forms.Test.csproj =================================================================== diff -u -r00835f43bb793e1fda36becd6dfd0c5619417927 -r4be49ab92023b8a73056078c2caa86bd5cfdf5e5 --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Ringtoets.Piping.Forms.Test.csproj (.../Ringtoets.Piping.Forms.Test.csproj) (revision 00835f43bb793e1fda36becd6dfd0c5619417927) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Ringtoets.Piping.Forms.Test.csproj (.../Ringtoets.Piping.Forms.Test.csproj) (revision 4be49ab92023b8a73056078c2caa86bd5cfdf5e5) @@ -24,6 +24,7 @@ + @@ -106,6 +107,10 @@ {420ED9C3-0C33-47EA-B893-121A9C0DB4F1} Ringtoets.AssemblyTool.Data + + {22C5DDB8-2491-4BC6-BDC6-2A7B7EBF40C1} + Ringtoets.AssemblyTool.Forms + {358B6DA2-A1DF-477F-B6AC-C30204265CB0} Ringtoets.AssemblyTool.KernelWrapper