Index: Ringtoets/Common/src/Ringtoets.Common.Forms/ExportInfos/RingtoetsExportInfoFactory.cs =================================================================== diff -u -refe27abe1b815a414878320d663d811d10475a12 -rd6e6041931d39b07ebb06bd0919a5d338736704e --- Ringtoets/Common/src/Ringtoets.Common.Forms/ExportInfos/RingtoetsExportInfoFactory.cs (.../RingtoetsExportInfoFactory.cs) (revision efe27abe1b815a414878320d663d811d10475a12) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/ExportInfos/RingtoetsExportInfoFactory.cs (.../RingtoetsExportInfoFactory.cs) (revision d6e6041931d39b07ebb06bd0919a5d338736704e) @@ -27,7 +27,6 @@ using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Forms.PresentationObjects; using Ringtoets.Common.Forms.Properties; -using CoreCommonGuiResources = Core.Common.Gui.Properties.Resources; namespace Ringtoets.Common.Forms.ExportInfos { Index: Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.Plugin/StabilityPointStructuresPlugin.cs =================================================================== diff -u -r5bbbdab924d1cc6c4959ac892903120acdbc82fb -rd6e6041931d39b07ebb06bd0919a5d338736704e --- Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.Plugin/StabilityPointStructuresPlugin.cs (.../StabilityPointStructuresPlugin.cs) (revision 5bbbdab924d1cc6c4959ac892903120acdbc82fb) +++ Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.Plugin/StabilityPointStructuresPlugin.cs (.../StabilityPointStructuresPlugin.cs) (revision d6e6041931d39b07ebb06bd0919a5d338736704e) @@ -36,6 +36,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; @@ -45,6 +46,7 @@ using Ringtoets.StabilityPointStructures.Forms.PresentationObjects; using Ringtoets.StabilityPointStructures.Forms.PropertyClasses; using Ringtoets.StabilityPointStructures.Forms.Views; +using Ringtoets.StabilityPointStructures.IO.Exporters; using Ringtoets.StabilityPointStructures.IO.Importers; using Ringtoets.StabilityPointStructures.Service; using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; @@ -84,16 +86,16 @@ }; yield return new ViewInfo< - FailureMechanismSectionResultContext, - IEnumerable, - StabilityPointStructuresFailureMechanismResultView> - { - GetViewName = (view, context) => RingtoetsCommonFormsResources.FailureMechanism_AssessmentResult_DisplayName, - Image = RingtoetsCommonFormsResources.FailureMechanismSectionResultIcon, - CloseForData = CloseFailureMechanismResultViewForData, - GetViewData = context => context.WrappedData, - AfterCreate = (view, context) => view.FailureMechanism = context.FailureMechanism - }; + FailureMechanismSectionResultContext, + IEnumerable, + StabilityPointStructuresFailureMechanismResultView> + { + GetViewName = (view, context) => RingtoetsCommonFormsResources.FailureMechanism_AssessmentResult_DisplayName, + Image = RingtoetsCommonFormsResources.FailureMechanismSectionResultIcon, + CloseForData = CloseFailureMechanismResultViewForData, + GetViewData = context => context.WrappedData, + AfterCreate = (view, context) => view.FailureMechanism = context.FailureMechanism + }; yield return new ViewInfo { @@ -191,11 +193,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 StabilityPointStructuresCalculationConfigurationExporter(context.WrappedData.Children, filePath), + context => context.WrappedData.Children.Any()); + + yield return RingtoetsExportInfoFactory.CreateCalculationConfigurationExportInfo( + (context, filePath) => new StabilityPointStructuresCalculationConfigurationExporter(new[] + { + context.WrappedData + }, filePath)); + } + #region ViewInfo #region StabilityPointStructuresFailureMechanismView ViewInfo @@ -206,7 +221,7 @@ var failureMechanism = o as StabilityPointStructuresFailureMechanism; var viewFailureMechanismContext = (StabilityPointStructuresFailureMechanismContext) view.Data; - var viewFailureMechanism = viewFailureMechanismContext.WrappedData; + StabilityPointStructuresFailureMechanism viewFailureMechanism = viewFailureMechanismContext.WrappedData; return assessmentSection != null ? ReferenceEquals(viewFailureMechanismContext.Parent, assessmentSection) @@ -279,7 +294,7 @@ private static void ValidateAll(IEnumerable> calculations, IAssessmentSection assessmentSection) { - foreach (var calculation in calculations) + foreach (StructuresCalculation calculation in calculations) { StabilityPointStructuresCalculationService.Validate(calculation, assessmentSection); } @@ -294,7 +309,8 @@ calc, assessmentSection.HydraulicBoundaryDatabase.FilePath, failureMechanism, - assessmentSection)).ToArray()); + assessmentSection)) + .ToArray()); } #endregion @@ -556,7 +572,7 @@ private static void GenerateStabilityPointStructuresCalculations(IEnumerable sectionResults, IEnumerable structures, IList calculations) { - foreach (var structure in structures) + foreach (StabilityPointStructure structure in structures) { var calculation = new StructuresCalculation { @@ -578,7 +594,7 @@ var parentGroupContext = (StabilityPointStructuresCalculationGroupContext) parentNodeData; parentGroupContext.WrappedData.Children.Remove(context.WrappedData); - var stabilityPointStructuresCalculations = context.FailureMechanism.Calculations.Cast>().ToArray(); + StructuresCalculation[] stabilityPointStructuresCalculations = context.FailureMechanism.Calculations.Cast>().ToArray(); StructuresHelper.UpdateCalculationToSectionResultAssignments(context.FailureMechanism.SectionResults, stabilityPointStructuresCalculations); Index: Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Plugin.Test/ExportInfos/StabilityPointStructuresCalculationContextExportInfoTest.cs =================================================================== diff -u --- Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Plugin.Test/ExportInfos/StabilityPointStructuresCalculationContextExportInfoTest.cs (revision 0) +++ Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Plugin.Test/ExportInfos/StabilityPointStructuresCalculationContextExportInfoTest.cs (revision d6e6041931d39b07ebb06bd0919a5d338736704e) @@ -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.StabilityPointStructures.Data; +using Ringtoets.StabilityPointStructures.Data.TestUtil; +using Ringtoets.StabilityPointStructures.Forms.PresentationObjects; +using Ringtoets.StabilityPointStructures.IO.Exporters; +using CoreCommonGuiResources = Core.Common.Gui.Properties.Resources; + +namespace Ringtoets.StabilityPointStructures.Plugin.Test.ExportInfos +{ + [TestFixture] + public class StabilityPointStructuresCalculationContextExportInfoTest + { + [Test] + public void Initialized_Always_ExpectedPropertiesSet() + { + // Setup + using (var plugin = new StabilityPointStructuresPlugin()) + { + // 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 StabilityPointStructuresCalculationContext(new TestStabilityPointStructuresCalculation(), + new StabilityPointStructuresFailureMechanism(), + assessmentSection); + + using (var plugin = new StabilityPointStructuresPlugin()) + { + 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 StabilityPointStructuresPlugin()) + { + 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 StabilityPointStructuresCalculationContext(new TestStabilityPointStructuresCalculation(), + new StabilityPointStructuresFailureMechanism(), + assessmentSection); + + using (var plugin = new StabilityPointStructuresPlugin()) + { + ExportInfo info = GetExportInfo(plugin); + + // Call + bool isEnabled = info.IsEnabled(context); + + // Assert + Assert.IsTrue(isEnabled); + } + mocks.VerifyAll(); + } + + private static ExportInfo GetExportInfo(PluginBase plugin) + { + return plugin.GetExportInfos().First(ei => ei.DataType == typeof(StabilityPointStructuresCalculationContext)); + } + } +} \ No newline at end of file Index: Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Plugin.Test/ExportInfos/StabilityPointStructuresCalculationGroupContextExportInfoTest.cs =================================================================== diff -u --- Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Plugin.Test/ExportInfos/StabilityPointStructuresCalculationGroupContextExportInfoTest.cs (revision 0) +++ Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Plugin.Test/ExportInfos/StabilityPointStructuresCalculationGroupContextExportInfoTest.cs (revision d6e6041931d39b07ebb06bd0919a5d338736704e) @@ -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.StabilityPointStructures.Data; +using Ringtoets.StabilityPointStructures.Data.TestUtil; +using Ringtoets.StabilityPointStructures.Forms.PresentationObjects; +using Ringtoets.StabilityPointStructures.IO.Exporters; +using CoreCommonGuiResources = Core.Common.Gui.Properties.Resources; + +namespace Ringtoets.StabilityPointStructures.Plugin.Test.ExportInfos +{ + [TestFixture] + public class StabilityPointStructuresCalculationGroupContextExportInfoTest + { + [Test] + public void Initialized_Always_ExpectedPropertiesSet() + { + // Setup + using (var plugin = new StabilityPointStructuresPlugin()) + { + // 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 StabilityPointStructuresCalculationGroupContext(new CalculationGroup(), + new StabilityPointStructuresFailureMechanism(), + assessmentSection); + + using (var plugin = new StabilityPointStructuresPlugin()) + { + 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 StabilityPointStructuresPlugin()) + { + 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 StabilityPointStructuresCalculationGroupContext(new CalculationGroup(), + new StabilityPointStructuresFailureMechanism(), + assessmentSection); + + using (var plugin = new StabilityPointStructuresPlugin()) + { + 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 TestStabilityPointStructuresCalculation()); + } + + var context = new StabilityPointStructuresCalculationGroupContext(calculationGroup, + new StabilityPointStructuresFailureMechanism(), + assessmentSection); + + using (var plugin = new StabilityPointStructuresPlugin()) + { + ExportInfo info = GetExportInfo(plugin); + + // Call + bool isEnabled = info.IsEnabled(context); + + // Assert + Assert.IsTrue(isEnabled); + } + mocks.VerifyAll(); + } + + private static ExportInfo GetExportInfo(PluginBase plugin) + { + return plugin.GetExportInfos().First(ei => ei.DataType == typeof(StabilityPointStructuresCalculationGroupContext)); + } + } +} \ No newline at end of file Index: Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Plugin.Test/Ringtoets.StabilityPointStructures.Plugin.Test.csproj =================================================================== diff -u -r3014d0ced22c45300938639e7958ea0850485240 -rd6e6041931d39b07ebb06bd0919a5d338736704e --- Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Plugin.Test/Ringtoets.StabilityPointStructures.Plugin.Test.csproj (.../Ringtoets.StabilityPointStructures.Plugin.Test.csproj) (revision 3014d0ced22c45300938639e7958ea0850485240) +++ Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Plugin.Test/Ringtoets.StabilityPointStructures.Plugin.Test.csproj (.../Ringtoets.StabilityPointStructures.Plugin.Test.csproj) (revision d6e6041931d39b07ebb06bd0919a5d338736704e) @@ -63,6 +63,8 @@ Properties\GlobalAssembly.cs + + Index: Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Plugin.Test/StabilityPointStructuresPluginTest.cs =================================================================== diff -u -r0cc64a130e25bd1cb8ffa996799b2556c7798269 -rd6e6041931d39b07ebb06bd0919a5d338736704e --- Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Plugin.Test/StabilityPointStructuresPluginTest.cs (.../StabilityPointStructuresPluginTest.cs) (revision 0cc64a130e25bd1cb8ffa996799b2556c7798269) +++ Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Plugin.Test/StabilityPointStructuresPluginTest.cs (.../StabilityPointStructuresPluginTest.cs) (revision d6e6041931d39b07ebb06bd0919a5d338736704e) @@ -22,12 +22,9 @@ using System.Collections.Generic; using System.Linq; using Core.Common.Controls.TreeView; -using Core.Common.Gui; -using Core.Common.Gui.Commands; using Core.Common.Gui.Plugin; using Core.Common.Gui.TestUtil; using NUnit.Framework; -using Rhino.Mocks; using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Forms.PresentationObjects; using Ringtoets.StabilityPointStructures.Data; @@ -147,5 +144,21 @@ Assert.IsTrue(importInfos.Any(i => i.DataType == typeof(StabilityPointStructuresContext))); } } + + [Test] + public void GetExportInfos_ReturnsSupportedExportInfos() + { + // Setup + using (var plugin = new StabilityPointStructuresPlugin()) + { + // Call + ExportInfo[] exportInfos = plugin.GetExportInfos().ToArray(); + + // Assert + Assert.AreEqual(2, exportInfos.Length); + Assert.IsTrue(exportInfos.Any(tni => tni.DataType == typeof(StabilityPointStructuresCalculationGroupContext))); + Assert.IsTrue(exportInfos.Any(tni => tni.DataType == typeof(StabilityPointStructuresCalculationContext))); + } + } } } \ No newline at end of file