Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.IO/HeightStructuresCalculationConfigurationExporter.cs =================================================================== diff -u -rcc1268d7cb906524d4cabcd4cbd9ae16676cf059 -rbe64b9f33b3065a4d80c0a93c1cafe3d74f43513 --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.IO/HeightStructuresCalculationConfigurationExporter.cs (.../HeightStructuresCalculationConfigurationExporter.cs) (revision cc1268d7cb906524d4cabcd4cbd9ae16676cf059) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.IO/HeightStructuresCalculationConfigurationExporter.cs (.../HeightStructuresCalculationConfigurationExporter.cs) (revision be64b9f33b3065a4d80c0a93c1cafe3d74f43513) @@ -37,7 +37,7 @@ HeightStructuresCalculationConfigurationWriter, StructuresCalculation, HeightStructureCalculationConfiguration - > + > { /// /// Creates a new instance of . @@ -46,8 +46,7 @@ /// The path of the XML file to export to. /// Thrown when is null. /// Thrown when is invalid. - public HeightStructuresCalculationConfigurationExporter(IEnumerable calculations, string filePath) : base(calculations, filePath) - {} + public HeightStructuresCalculationConfigurationExporter(IEnumerable calculations, string filePath) : base(calculations, filePath) {} protected override HeightStructureCalculationConfiguration ToConfiguration(StructuresCalculation calculation) { @@ -94,20 +93,22 @@ }; } - calculationConfiguration.WaveReduction = new WaveReductionConfiguration(); - - if (input.UseBreakWater) - { - calculationConfiguration.WaveReduction.UseBreakWater = true; - calculationConfiguration.WaveReduction.BreakWaterType = (ReadBreakWaterType) input.BreakWater.Type; - calculationConfiguration.WaveReduction.BreakWaterHeight = input.BreakWater.Height; - } if (input.ForeshoreProfile != null) { calculationConfiguration.ForeshoreProfileName = input.ForeshoreProfile?.Name; - calculationConfiguration.WaveReduction.UseForeshoreProfile = input.UseForeshore; + calculationConfiguration.WaveReduction = new WaveReductionConfiguration + { + UseForeshoreProfile = input.UseForeshore, + UseBreakWater = input.UseBreakWater + }; + if (input.UseBreakWater) + { + calculationConfiguration.WaveReduction.BreakWaterType = (ReadBreakWaterType) input.BreakWater.Type; + calculationConfiguration.WaveReduction.BreakWaterHeight = input.BreakWater.Height; + } } + calculationConfiguration.StormDuration = new MeanVariationCoefficientStochastConfiguration { Mean = input.StormDuration.Mean Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/HeightStructuresPlugin.cs =================================================================== diff -u -r37fc59cc0f3becb92e14b8263bd8e9fc71aa0e79 -rbe64b9f33b3065a4d80c0a93c1cafe3d74f43513 --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/HeightStructuresPlugin.cs (.../HeightStructuresPlugin.cs) (revision 37fc59cc0f3becb92e14b8263bd8e9fc71aa0e79) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/HeightStructuresPlugin.cs (.../HeightStructuresPlugin.cs) (revision be64b9f33b3065a4d80c0a93c1cafe3d74f43513) @@ -37,6 +37,7 @@ using Ringtoets.Common.Data.Structures; using Ringtoets.Common.Forms; using Ringtoets.Common.Forms.ChangeHandlers; +using Ringtoets.Common.Forms.ExportInfos; using Ringtoets.Common.Forms.Helpers; using Ringtoets.Common.Forms.PresentationObjects; using Ringtoets.Common.Forms.TreeNodeInfos; @@ -87,11 +88,24 @@ Category = RingtoetsCommonFormsResources.Ringtoets_Category, Image = RingtoetsCommonFormsResources.StructuresIcon, FileFilterGenerator = new FileFilterGenerator(RingtoetsCommonIOResources.Shape_file_filter_Extension, - RingtoetsCommonIOResources.Shape_file_filter_Description), + RingtoetsCommonIOResources.Shape_file_filter_Description), IsEnabled = context => context.AssessmentSection.ReferenceLine != null }; } + public override IEnumerable GetExportInfos() + { + yield return RingtoetsExportInfoFactory.CreateCalculationGroupConfigurationExportInfo( + (context, filePath) => new HeightStructuresCalculationConfigurationExporter(context.WrappedData.Children, filePath), + context => context.WrappedData.Children.Any()); + + yield return RingtoetsExportInfoFactory.CreateCalculationConfigurationExportInfo( + (context, filePath) => new HeightStructuresCalculationConfigurationExporter(new[] + { + context.WrappedData + }, filePath)); + } + public override IEnumerable GetViewInfos() { yield return new ViewInfo @@ -103,28 +117,28 @@ }; yield return new ViewInfo< - HeightStructuresScenariosContext, - CalculationGroup, - HeightStructuresScenariosView> - { - GetViewData = context => context.WrappedData, - GetViewName = (view, calculationGroup) => RingtoetsCommonFormsResources.Scenarios_DisplayName, - AfterCreate = (view, context) => view.FailureMechanism = context.ParentFailureMechanism, - CloseForData = CloseScenariosViewForData, - Image = RingtoetsCommonFormsResources.ScenariosIcon - }; + HeightStructuresScenariosContext, + CalculationGroup, + HeightStructuresScenariosView> + { + GetViewData = context => context.WrappedData, + GetViewName = (view, calculationGroup) => RingtoetsCommonFormsResources.Scenarios_DisplayName, + AfterCreate = (view, context) => view.FailureMechanism = context.ParentFailureMechanism, + CloseForData = CloseScenariosViewForData, + Image = RingtoetsCommonFormsResources.ScenariosIcon + }; yield return new ViewInfo< - FailureMechanismSectionResultContext, - IEnumerable, - HeightStructuresFailureMechanismResultView> - { - GetViewName = (view, results) => RingtoetsCommonFormsResources.FailureMechanism_AssessmentResult_DisplayName, - Image = RingtoetsCommonFormsResources.FailureMechanismSectionResultIcon, - CloseForData = CloseFailureMechanismResultViewForData, - GetViewData = context => context.WrappedData, - AfterCreate = (view, context) => view.FailureMechanism = context.FailureMechanism - }; + FailureMechanismSectionResultContext, + IEnumerable, + HeightStructuresFailureMechanismResultView> + { + GetViewName = (view, results) => RingtoetsCommonFormsResources.FailureMechanism_AssessmentResult_DisplayName, + Image = RingtoetsCommonFormsResources.FailureMechanismSectionResultIcon, + CloseForData = CloseFailureMechanismResultViewForData, + GetViewData = context => context.WrappedData, + AfterCreate = (view, context) => view.FailureMechanism = context.FailureMechanism + }; } public override IEnumerable GetTreeNodeInfos() @@ -470,6 +484,9 @@ var builder = new RingtoetsContextMenuBuilder(Gui.Get(context, treeViewControl)); var isNestedGroup = parentData is HeightStructuresCalculationGroupContext; + builder.AddExportItem() + .AddSeparator(); + if (!isNestedGroup) { builder.AddCustomItem(CreateGenerateHeightStructuresCalculationsItem(context)) @@ -639,7 +656,9 @@ StructuresCalculation calculation = context.WrappedData; - return builder.AddRenameItem() + return builder.AddExportItem() + .AddSeparator() + .AddRenameItem() .AddValidateCalculationItem( context, Validate, Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Data.TestUtil/TestHeightStructure.cs =================================================================== diff -u -r85d3615793ddf3f8f72eb02409a23286396f5cf1 -rbe64b9f33b3065a4d80c0a93c1cafe3d74f43513 --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Data.TestUtil/TestHeightStructure.cs (.../TestHeightStructure.cs) (revision 85d3615793ddf3f8f72eb02409a23286396f5cf1) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Data.TestUtil/TestHeightStructure.cs (.../TestHeightStructure.cs) (revision be64b9f33b3065a4d80c0a93c1cafe3d74f43513) @@ -68,29 +68,29 @@ }, FlowWidthAtBottomProtection = { - Mean = (RoundedDouble) 345.678, - StandardDeviation = (RoundedDouble) 0.34567 + Mean = (RoundedDouble) 345.68, + StandardDeviation = (RoundedDouble) 0.35 }, CriticalOvertoppingDischarge = { - Mean = (RoundedDouble) 456.789, - CoefficientOfVariation = (RoundedDouble) 0.45678 + Mean = (RoundedDouble) 456.79, + CoefficientOfVariation = (RoundedDouble) 0.46 }, WidthFlowApertures = { - Mean = (RoundedDouble) 567.890, - StandardDeviation = (RoundedDouble) 0.56789 + Mean = (RoundedDouble) 567.89, + StandardDeviation = (RoundedDouble) 0.57 }, FailureProbabilityStructureWithErosion = 0.67890, StorageStructureArea = { - Mean = (RoundedDouble) 112.223, - CoefficientOfVariation = (RoundedDouble) 0.11222 + Mean = (RoundedDouble) 112.22, + CoefficientOfVariation = (RoundedDouble) 0.11 }, AllowedLevelIncreaseStorage = { - Mean = (RoundedDouble) 225.336, - StandardDeviation = (RoundedDouble) 0.22533 + Mean = (RoundedDouble) 225.34, + StandardDeviation = (RoundedDouble) 0.23 } }) {} } Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.IO.Test/HeightStructuresCalculationConfigurationExporterTest.cs =================================================================== diff -u -rcc1268d7cb906524d4cabcd4cbd9ae16676cf059 -rbe64b9f33b3065a4d80c0a93c1cafe3d74f43513 --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.IO.Test/HeightStructuresCalculationConfigurationExporterTest.cs (.../HeightStructuresCalculationConfigurationExporterTest.cs) (revision cc1268d7cb906524d4cabcd4cbd9ae16676cf059) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.IO.Test/HeightStructuresCalculationConfigurationExporterTest.cs (.../HeightStructuresCalculationConfigurationExporterTest.cs) (revision be64b9f33b3065a4d80c0a93c1cafe3d74f43513) @@ -39,53 +39,88 @@ public class HeightStructuresCalculationConfigurationExporterTest : CustomSchemaCalculationConfigurationExporterDesignGuidelinesTestFixture< HeightStructuresCalculationConfigurationExporter, - HeightStructuresCalculationConfigurationWriter, - StructuresCalculation, + HeightStructuresCalculationConfigurationWriter, + StructuresCalculation, HeightStructureCalculationConfiguration> { + private static IEnumerable Calculations + { + get + { + yield return new TestCaseData("completeConfiguration", new[] + { + CreateFullCalculation() + }) + .SetName("Calculation configuration with all parameters set"); + yield return new TestCaseData("sparseConfiguration", new[] + { + CreateSparseCalculation() + }) + .SetName("Calculation configuration with none of its parameters set"); + yield return new TestCaseData("configurationWithStructure", new[] + { + CreateCalculationWithStructure() + }) + .SetName("Calculation configuration with a structure set"); + yield return new TestCaseData("configurationWithForeshoreProfile", new[] + { + CreateCalculationWithForeshoreProfile() + }) + .SetName("Calculation configuration with foreshore profile"); + yield return new TestCaseData("configurationWithUseBreakWater", new[] + { + CreateCalculationWithUseBreakWater() + }) + .SetName("Calculation configuration with use breakwater true"); + yield return new TestCaseData("folderWithSubfolderAndCalculation", new[] + { + new CalculationGroup("Testmap", false) + { + Children = + { + CreateFullCalculation(), + new CalculationGroup("Nested", false) + { + Children = + { + CreateSparseCalculation() + } + } + } + } + }) + .SetName("Calculation configuration with hierarchy"); + } + } + [Test] - public void Export_ValidData_ReturnTrueAndWritesFile() + [TestCaseSource(nameof(Calculations))] + public void Export_ValidData_ReturnTrueAndWritesFile(string fileName, ICalculationBase[] calculations) { // Setup - StructuresCalculation calculation = CreateFullCalculation(); - StructuresCalculation calculation2 = new StructuresCalculation - { - Name = "Berekening 2" - }; + string testDirectory = TestHelper.GetTestDataPath( + TestDataPath.Ringtoets.HeightStructures.IO, + nameof(HeightStructuresCalculationConfigurationExporter)); - CalculationGroup calculationGroup2 = new CalculationGroup("Nested", false) - { - Children = - { - calculation2 - } - }; + string expectedXmlFilePath = Path.Combine(testDirectory, $"{fileName}.xml"); - CalculationGroup calculationGroup = new CalculationGroup("Testmap", false) - { - Children = - { - calculation, - calculationGroup2 - } - }; - - string expectedXmlFilePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.HeightStructures.IO, - Path.Combine(nameof(HeightStructuresCalculationConfigurationWriter), - "folderWithSubfolderAndCalculation.xml")); - // Call and Assert - WriteAndValidate(new[] + WriteAndValidate(calculations, expectedXmlFilePath); + } + + private static ICalculation CreateSparseCalculation() + { + return new StructuresCalculation { - calculationGroup - }, expectedXmlFilePath); + Name = "sparse config" + }; } private static StructuresCalculation CreateFullCalculation() { return new TestHeightStructuresCalculation { - Name = "Berekening 1", + Name = "full config", InputParameters = { HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation("Locatie1"), @@ -100,40 +135,40 @@ Type = BreakWaterType.Dam, Height = (RoundedDouble) 1.234 }, - StormDuration = new VariationCoefficientLogNormalDistribution() + StormDuration = new VariationCoefficientLogNormalDistribution { Mean = (RoundedDouble) 6.0 }, - ModelFactorSuperCriticalFlow = new NormalDistribution() + ModelFactorSuperCriticalFlow = new NormalDistribution { Mean = (RoundedDouble) 1.10 }, - FlowWidthAtBottomProtection = new LogNormalDistribution() + FlowWidthAtBottomProtection = new LogNormalDistribution { Mean = (RoundedDouble) 15.2, StandardDeviation = (RoundedDouble) 0.1 }, - WidthFlowApertures = new NormalDistribution() + WidthFlowApertures = new NormalDistribution { Mean = (RoundedDouble) 13.2, StandardDeviation = (RoundedDouble) 0.3 }, - StorageStructureArea = new VariationCoefficientLogNormalDistribution() + StorageStructureArea = new VariationCoefficientLogNormalDistribution { Mean = (RoundedDouble) 15000, CoefficientOfVariation = (RoundedDouble) 0.01 }, - AllowedLevelIncreaseStorage = new LogNormalDistribution() + AllowedLevelIncreaseStorage = new LogNormalDistribution { Mean = (RoundedDouble) 0.2, StandardDeviation = (RoundedDouble) 0.01 }, - LevelCrestStructure = new NormalDistribution() + LevelCrestStructure = new NormalDistribution { Mean = (RoundedDouble) 4.3, StandardDeviation = (RoundedDouble) 0.2 }, - CriticalOvertoppingDischarge = new VariationCoefficientLogNormalDistribution() + CriticalOvertoppingDischarge = new VariationCoefficientLogNormalDistribution { Mean = (RoundedDouble) 2, CoefficientOfVariation = (RoundedDouble) 0.1 @@ -142,6 +177,50 @@ }; } + private static StructuresCalculation CreateCalculationWithForeshoreProfile() + { + return new StructuresCalculation + { + Name = "with foreshore profile", + InputParameters = + { + ForeshoreProfile = new TestForeshoreProfile("profiel1"), + UseForeshore = true + } + }; + } + + private static StructuresCalculation CreateCalculationWithUseBreakWater() + { + return new StructuresCalculation + { + Name = "with use breakwater", + InputParameters = + { + ForeshoreProfile = new TestForeshoreProfile("profiel1"), + BreakWater = + { + Type = BreakWaterType.Caisson, + Height = (RoundedDouble) 1.23 + }, + UseBreakWater = true, + UseForeshore = false + } + }; + } + + private static StructuresCalculation CreateCalculationWithStructure() + { + return new StructuresCalculation + { + Name = "with structure", + InputParameters = + { + Structure = new TestHeightStructure("kunstwerk1"), + } + }; + } + protected override StructuresCalculation CreateCalculation() { return new TestHeightStructuresCalculation(); Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/ExportInfos/HeightStructuresCalculationContextExportInfoTest.cs =================================================================== diff -u --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/ExportInfos/HeightStructuresCalculationContextExportInfoTest.cs (revision 0) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/ExportInfos/HeightStructuresCalculationContextExportInfoTest.cs (revision be64b9f33b3065a4d80c0a93c1cafe3d74f43513) @@ -0,0 +1,131 @@ +// Copyright (C) Stichting Deltares 2016. 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.Linq; +using Core.Common.Base.IO; +using Core.Common.Gui; +using Core.Common.Gui.Plugin; +using Core.Common.TestUtil; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.HeightStructures.Data; +using Ringtoets.HeightStructures.Data.TestUtil; +using Ringtoets.HeightStructures.Forms.PresentationObjects; +using Ringtoets.HeightStructures.IO; +using CoreCommonGuiResources = Core.Common.Gui.Properties.Resources; + +namespace Ringtoets.HeightStructures.Plugin.Test.ExportInfos +{ + [TestFixture] + public class HeightStructuresCalculationContextExportInfoTest + { + [Test] + public void Initialized_Always_ExpectedPropertiesSet() + { + // Setup + using (var plugin = new HeightStructuresPlugin()) + { + // Call + ExportInfo info = GetExportInfo(plugin); + + // Assert + Assert.IsNotNull(info.CreateFileExporter); + Assert.IsNotNull(info.IsEnabled); + Assert.AreEqual("Ringtoets berekeningenconfiguratie (*.xml)", info.Name); + Assert.AreEqual("Algemeen", info.Category); + TestHelper.AssertImagesAreEqual(CoreCommonGuiResources.ExportIcon, info.Image); + Assert.IsNotNull(info.FileFilterGenerator); + } + } + + [Test] + public void CreateFileExporter_Always_ReturnFileExporter() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var context = new HeightStructuresCalculationContext(new TestHeightStructuresCalculation(), + new HeightStructuresFailureMechanism(), + assessmentSection); + + using (var plugin = new HeightStructuresPlugin()) + { + ExportInfo info = GetExportInfo(plugin); + + // Call + IFileExporter fileExporter = info.CreateFileExporter(context, "test"); + + // Assert + Assert.IsInstanceOf(fileExporter); + } + mocks.VerifyAll(); + } + + [Test] + public void FileFilterGenerator_Always_ReturnFileFilter() + { + // Setup + using (var plugin = new HeightStructuresPlugin()) + { + ExportInfo info = GetExportInfo(plugin); + + // Call + FileFilterGenerator fileFilterGenerator = info.FileFilterGenerator; + + // Assert + Assert.AreEqual("Ringtoets berekeningenconfiguratie (*.xml)|*.xml", fileFilterGenerator.Filter); + } + } + + [Test] + public void IsEnabled_Always_ReturnTrue() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var context = new HeightStructuresCalculationContext(new TestHeightStructuresCalculation(), + new HeightStructuresFailureMechanism(), + assessmentSection); + + using (var plugin = new HeightStructuresPlugin()) + { + ExportInfo info = GetExportInfo(plugin); + + // Call + bool isEnabled = info.IsEnabled(context); + + // Assert + Assert.IsTrue(isEnabled); + } + mocks.VerifyAll(); + } + + private static ExportInfo GetExportInfo(HeightStructuresPlugin plugin) + { + return plugin.GetExportInfos().First(ei => ei.DataType == typeof(HeightStructuresCalculationContext)); + } + } +} \ No newline at end of file Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/ExportInfos/HeightStructuresCalculationGroupContextExportInfoTest.cs =================================================================== diff -u --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/ExportInfos/HeightStructuresCalculationGroupContextExportInfoTest.cs (revision 0) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/ExportInfos/HeightStructuresCalculationGroupContextExportInfoTest.cs (revision be64b9f33b3065a4d80c0a93c1cafe3d74f43513) @@ -0,0 +1,171 @@ +// Copyright (C) Stichting Deltares 2016. 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.Linq; +using Core.Common.Base.IO; +using Core.Common.Gui; +using Core.Common.Gui.Plugin; +using Core.Common.TestUtil; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.HeightStructures.Data; +using Ringtoets.HeightStructures.Data.TestUtil; +using Ringtoets.HeightStructures.Forms.PresentationObjects; +using Ringtoets.HeightStructures.IO; +using CoreCommonGuiResources = Core.Common.Gui.Properties.Resources; + +namespace Ringtoets.HeightStructures.Plugin.Test.ExportInfos +{ + [TestFixture] + public class HeightStructuresCalculationGroupContextExportInfoTest + { + [Test] + public void Initialized_Always_ExpectedPropertiesSet() + { + // Setup + using (var plugin = new HeightStructuresPlugin()) + { + // Call + ExportInfo info = GetExportInfo(plugin); + + // Assert + Assert.IsNotNull(info.CreateFileExporter); + Assert.IsNotNull(info.IsEnabled); + Assert.AreEqual("Ringtoets berekeningenconfiguratie (*.xml)", info.Name); + Assert.AreEqual("Algemeen", info.Category); + TestHelper.AssertImagesAreEqual(CoreCommonGuiResources.ExportIcon, info.Image); + Assert.IsNotNull(info.FileFilterGenerator); + } + } + + [Test] + public void CreateFileExporter_Always_ReturnFileExporter() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var context = new HeightStructuresCalculationGroupContext(new CalculationGroup(), + new HeightStructuresFailureMechanism(), + assessmentSection); + + using (var plugin = new HeightStructuresPlugin()) + { + ExportInfo info = GetExportInfo(plugin); + + // Call + IFileExporter fileExporter = info.CreateFileExporter(context, "test"); + + // Assert + Assert.IsInstanceOf(fileExporter); + } + mocks.VerifyAll(); + } + + [Test] + public void FileFilterGenerator_Always_ReturnFileFilter() + { + // Setup + using (var plugin = new HeightStructuresPlugin()) + { + ExportInfo info = GetExportInfo(plugin); + + // Call + FileFilterGenerator fileFilterGenerator = info.FileFilterGenerator; + + // Assert + Assert.AreEqual("Ringtoets berekeningenconfiguratie (*.xml)|*.xml", fileFilterGenerator.Filter); + } + } + + [Test] + public void IsEnabled_CalculationGroupNoChildren_ReturnFalse() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var context = new HeightStructuresCalculationGroupContext(new CalculationGroup(), + new HeightStructuresFailureMechanism(), + assessmentSection); + + using (var plugin = new HeightStructuresPlugin()) + { + ExportInfo info = GetExportInfo(plugin); + + // Call + bool isEnabled = info.IsEnabled(context); + + // Assert + Assert.IsFalse(isEnabled); + } + mocks.VerifyAll(); + } + + [Test] + [TestCase(true, false)] + [TestCase(false, true)] + public void IsEnabled_CalculationGroupWithChildren_ReturnTrue(bool hasNestedGroup, bool hasCalculation) + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var calculationGroup = new CalculationGroup(); + + if (hasNestedGroup) + { + calculationGroup.Children.Add(new CalculationGroup()); + } + + if (hasCalculation) + { + calculationGroup.Children.Add(new TestHeightStructuresCalculation()); + } + + var context = new HeightStructuresCalculationGroupContext(calculationGroup, + new HeightStructuresFailureMechanism(), + assessmentSection); + + using (var plugin = new HeightStructuresPlugin()) + { + ExportInfo info = GetExportInfo(plugin); + + // Call + bool isEnabled = info.IsEnabled(context); + + // Assert + Assert.IsTrue(isEnabled); + } + mocks.VerifyAll(); + } + + private static ExportInfo GetExportInfo(HeightStructuresPlugin plugin) + { + return plugin.GetExportInfos().First(ei => ei.DataType == typeof(HeightStructuresCalculationGroupContext)); + } + } +} \ No newline at end of file Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/HeightStructuresPluginTest.cs =================================================================== diff -u -r65a75a24ebfe5942a69176ea6eaa858c29e6bdd5 -rbe64b9f33b3065a4d80c0a93c1cafe3d74f43513 --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/HeightStructuresPluginTest.cs (.../HeightStructuresPluginTest.cs) (revision 65a75a24ebfe5942a69176ea6eaa858c29e6bdd5) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/HeightStructuresPluginTest.cs (.../HeightStructuresPluginTest.cs) (revision be64b9f33b3065a4d80c0a93c1cafe3d74f43513) @@ -144,5 +144,20 @@ Assert.IsTrue(importInfos.Any(i => i.DataType == typeof(HeightStructuresContext))); } } + [Test] + public void GetExportInfos_ReturnsSupportedExportInfos() + { + // Setup + using (var plugin = new HeightStructuresPlugin()) + { + // Call + ExportInfo[] exportInfos = plugin.GetExportInfos().ToArray(); + + // Assert + Assert.AreEqual(2, exportInfos.Length); + Assert.IsTrue(exportInfos.Any(tni => tni.DataType == typeof(HeightStructuresCalculationGroupContext))); + Assert.IsTrue(exportInfos.Any(tni => tni.DataType == typeof(HeightStructuresCalculationContext))); + } + } } } \ No newline at end of file Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/Ringtoets.HeightStructures.Plugin.Test.csproj =================================================================== diff -u -r6a5d7b40b7ba4dcb73e393075338352d194e97c2 -rbe64b9f33b3065a4d80c0a93c1cafe3d74f43513 --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/Ringtoets.HeightStructures.Plugin.Test.csproj (.../Ringtoets.HeightStructures.Plugin.Test.csproj) (revision 6a5d7b40b7ba4dcb73e393075338352d194e97c2) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/Ringtoets.HeightStructures.Plugin.Test.csproj (.../Ringtoets.HeightStructures.Plugin.Test.csproj) (revision be64b9f33b3065a4d80c0a93c1cafe3d74f43513) @@ -63,6 +63,8 @@ Properties\GlobalAssembly.cs + + Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/TreeNodeInfos/HeightStructuresCalculationContextTreeNodeInfoTest.cs =================================================================== diff -u -rc990bf404015584981f3ec1d22ecec12a7b037f3 -rbe64b9f33b3065a4d80c0a93c1cafe3d74f43513 --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/TreeNodeInfos/HeightStructuresCalculationContextTreeNodeInfoTest.cs (.../HeightStructuresCalculationContextTreeNodeInfoTest.cs) (revision c990bf404015584981f3ec1d22ecec12a7b037f3) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/TreeNodeInfos/HeightStructuresCalculationContextTreeNodeInfoTest.cs (.../HeightStructuresCalculationContextTreeNodeInfoTest.cs) (revision be64b9f33b3065a4d80c0a93c1cafe3d74f43513) @@ -54,9 +54,9 @@ [TestFixture] public class HeightStructuresCalculationContextTreeNodeInfoTest : NUnitFormTest { - private const int contextMenuValidateIndex = 1; - private const int contextMenuCalculateIndex = 2; - private const int contextMenuClearIndex = 4; + private const int contextMenuValidateIndex = 3; + private const int contextMenuCalculateIndex = 4; + private const int contextMenuClearIndex = 6; private readonly string testDataPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, "HydraulicBoundaryDatabaseImporter"); private MockRepository mocks; @@ -181,6 +181,8 @@ var menuBuilderMock = mocks.StrictMock(); using (mocks.Ordered()) { + menuBuilderMock.Expect(mb => mb.AddExportItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddRenameItem()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilderMock); @@ -240,7 +242,7 @@ using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, assessmentSection, treeViewControl)) { // Assert - Assert.AreEqual(11, menu.Items.Count); + Assert.AreEqual(13, menu.Items.Count); TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuValidateIndex, "&Valideren", Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/TreeNodeInfos/HeightStructuresCalculationGroupContextTreeNodeInfoTest.cs =================================================================== diff -u -rc990bf404015584981f3ec1d22ecec12a7b037f3 -rbe64b9f33b3065a4d80c0a93c1cafe3d74f43513 --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/TreeNodeInfos/HeightStructuresCalculationGroupContextTreeNodeInfoTest.cs (.../HeightStructuresCalculationGroupContextTreeNodeInfoTest.cs) (revision c990bf404015584981f3ec1d22ecec12a7b037f3) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/TreeNodeInfos/HeightStructuresCalculationGroupContextTreeNodeInfoTest.cs (.../HeightStructuresCalculationGroupContextTreeNodeInfoTest.cs) (revision be64b9f33b3065a4d80c0a93c1cafe3d74f43513) @@ -54,18 +54,18 @@ [TestFixture] public class HeightStructuresCalculationGroupContextTreeNodeInfoTest : NUnitFormTest { - private const int contextMenuGenerateCalculationsIndexRootGroup = 0; - private const int contextMenuAddCalculationGroupIndexRootGroup = 2; - private const int contextMenuAddCalculationIndexRootGroup = 3; - private const int contextMenuValidateAllIndexRootGroup = 5; - private const int contextMenuCalculateAllIndexRootGroup = 6; - private const int contextMenuClearAllIndexRootGroup = 8; + private const int contextMenuGenerateCalculationsIndexRootGroup = 2; + private const int contextMenuAddCalculationGroupIndexRootGroup = 4; + private const int contextMenuAddCalculationIndexRootGroup = 5; + private const int contextMenuValidateAllIndexRootGroup = 7; + private const int contextMenuCalculateAllIndexRootGroup = 8; + private const int contextMenuClearAllIndexRootGroup = 10; - private const int contextMenuAddCalculationGroupIndexNestedGroup = 0; - private const int contextMenuAddCalculationIndexNestedGroup = 1; - private const int contextMenuValidateAllIndexNestedGroup = 4; - private const int contextMenuCalculateAllIndexNestedGroup = 5; - private const int contextMenuClearAllIndexNestedGroup = 7; + private const int contextMenuAddCalculationGroupIndexNestedGroup = 2; + private const int contextMenuAddCalculationIndexNestedGroup = 3; + private const int contextMenuValidateAllIndexNestedGroup = 6; + private const int contextMenuCalculateAllIndexNestedGroup = 7; + private const int contextMenuClearAllIndexNestedGroup = 9; private readonly string testDataPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, "HydraulicBoundaryDatabaseImporter"); private IGui guiStub; @@ -183,6 +183,8 @@ var menuBuilderMock = mocks.StrictMock(); using (mocks.Ordered()) { + menuBuilderMock.Expect(mb => mb.AddExportItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilderMock); @@ -238,7 +240,7 @@ using (ContextMenuStrip menu = info.ContextMenuStrip(groupContext, null, treeViewControl)) { // Assert - Assert.AreEqual(15, menu.Items.Count); + Assert.AreEqual(17, menu.Items.Count); TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuGenerateCalculationsIndexRootGroup, "Genereer &berekeningen...", @@ -298,7 +300,7 @@ using (ContextMenuStrip menu = info.ContextMenuStrip(groupContext, null, treeViewControl)) { // Assert - Assert.AreEqual(15, menu.Items.Count); + Assert.AreEqual(17, menu.Items.Count); TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuGenerateCalculationsIndexRootGroup, "Genereer &berekeningen...", @@ -326,6 +328,8 @@ var menuBuilderMock = mocks.StrictMock(); using (mocks.Ordered()) { + menuBuilderMock.Expect(mb => mb.AddExportItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); @@ -382,7 +386,7 @@ using (ContextMenuStrip menu = info.ContextMenuStrip(groupContext, parentGroupContext, treeViewControl)) { // Assert - Assert.AreEqual(14, menu.Items.Count); + Assert.AreEqual(16, menu.Items.Count); TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuAddCalculationGroupIndexNestedGroup, "&Map toevoegen",