Index: Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Plugin/ClosingStructuresPlugin.cs =================================================================== diff -u -re4e785f127ce9a2d0d1734c1b51e02d910a31bbe -r86984ca293c30b4f9b47da7825cbae1404fffe08 --- Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Plugin/ClosingStructuresPlugin.cs (.../ClosingStructuresPlugin.cs) (revision e4e785f127ce9a2d0d1734c1b51e02d910a31bbe) +++ Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Plugin/ClosingStructuresPlugin.cs (.../ClosingStructuresPlugin.cs) (revision 86984ca293c30b4f9b47da7825cbae1404fffe08) @@ -24,7 +24,9 @@ using System.Drawing; using System.Linq; using System.Windows.Forms; +using Core.Common.Base; using Core.Common.Controls.TreeView; +using Core.Common.Gui.ContextMenu; using Core.Common.Gui.Forms.ProgressDialog; using Core.Common.Gui.Plugin; using Ringtoets.ClosingStructures.Data; @@ -38,6 +40,7 @@ using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.Probability; using Ringtoets.Common.Data.Structures; +using Ringtoets.Common.Forms; using Ringtoets.Common.Forms.Helpers; using Ringtoets.Common.Forms.PresentationObjects; using Ringtoets.Common.Forms.TreeNodeInfos; @@ -402,6 +405,12 @@ var builder = new RingtoetsContextMenuBuilder(Gui.Get(context, treeViewControl)); var isNestedGroup = parentData is ClosingStructuresCalculationGroupContext; + if (!isNestedGroup) + { + builder.AddCustomItem(CreateGenerateClosingStructuresCalculationsItem(context)) + .AddSeparator(); + } + builder.AddCreateCalculationGroupItem(group) .AddCreateCalculationItem(context, AddCalculation); @@ -435,6 +444,55 @@ .Build(); } + private StrictContextMenuItem CreateGenerateClosingStructuresCalculationsItem(ClosingStructuresCalculationGroupContext nodeData) + { + ObservableList closingStructures = nodeData.FailureMechanism.ClosingStructures; + bool structuresAvailable = closingStructures.Any(); + + string closingStructuresCalculationGroupContextToolTip = structuresAvailable + ? RingtoetsCommonFormsResources.StructuresPlugin_Generate_calculations_for_selected_structures + : RingtoetsCommonFormsResources.StructuresPlugin_No_structures_to_generate_for; + + return new StrictContextMenuItem(RingtoetsCommonFormsResources.CalculationsGroup_Generate_calculations, + closingStructuresCalculationGroupContextToolTip, + RingtoetsCommonFormsResources.GenerateScenariosIcon, + (sender, args) => { ShowClosingStructuresSelectionDialog(nodeData); }) + { + Enabled = structuresAvailable + }; + } + + private void ShowClosingStructuresSelectionDialog(ClosingStructuresCalculationGroupContext nodeData) + { + using (var dialog = new StructureSelectionDialog(Gui.MainWindow, nodeData.FailureMechanism.ClosingStructures)) + { + dialog.ShowDialog(); + + if (dialog.SelectedItems.Any()) + { + GenerateClosingStructuresCalculations(nodeData.FailureMechanism.SectionResults, dialog.SelectedItems, nodeData.WrappedData.Children); + nodeData.NotifyObservers(); + } + } + } + + private static void GenerateClosingStructuresCalculations(IEnumerable sectionResults, IEnumerable structures, IList calculations) + { + foreach (var structure in structures) + { + var calculation = new StructuresCalculation + { + Name = NamingHelper.GetUniqueName(calculations, structure.Name, c => c.Name), + InputParameters = + { + Structure = (ClosingStructure)structure + } + }; + calculations.Add(calculation); + StructuresHelper.Update(sectionResults, calculation); + } + } + private static void ValidateAll(ClosingStructuresCalculationGroupContext context) { ValidateAll(context.WrappedData.GetCalculations().OfType>(), context.AssessmentSection); Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/TreeNodeInfos/ClosingStructuresCalculationGroupContextTreeNodeInfoTest.cs =================================================================== diff -u -rc308077fce571dad955fafc21577c2a99dc5b221 -r86984ca293c30b4f9b47da7825cbae1404fffe08 --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/TreeNodeInfos/ClosingStructuresCalculationGroupContextTreeNodeInfoTest.cs (.../ClosingStructuresCalculationGroupContextTreeNodeInfoTest.cs) (revision c308077fce571dad955fafc21577c2a99dc5b221) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/TreeNodeInfos/ClosingStructuresCalculationGroupContextTreeNodeInfoTest.cs (.../ClosingStructuresCalculationGroupContextTreeNodeInfoTest.cs) (revision 86984ca293c30b4f9b47da7825cbae1404fffe08) @@ -24,6 +24,7 @@ using System.Windows.Forms; using Core.Common.Base; using Core.Common.Base.Geometry; +using Core.Common.Controls.DataGrid; using Core.Common.Controls.TreeView; using Core.Common.Gui; using Core.Common.Gui.Commands; @@ -42,6 +43,8 @@ using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Data.Structures; +using Ringtoets.Common.Forms; +using Ringtoets.Common.Forms.Helpers; using Ringtoets.HydraRing.Data; using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; @@ -50,11 +53,12 @@ [TestFixture] public class ClosingStructuresCalculationGroupContextTreeNodeInfoTest : NUnitFormTest { - private const int contextMenuAddCalculationGroupIndexRootGroup = 0; - private const int contextMenuAddCalculationIndexRootGroup = 1; - private const int contextMenuValidateAllIndexRootGroup = 5; - private const int contextMenuCalculateAllIndexRootGroup = 6; - private const int contextMenuClearAllIndexRootGroup = 7; + private const int contextMenuGenerateCalculationsIndexRootGroup = 0; + private const int contextMenuAddCalculationGroupIndexRootGroup = 2; + private const int contextMenuAddCalculationIndexRootGroup = 3; + private const int contextMenuValidateAllIndexRootGroup = 7; + private const int contextMenuCalculateAllIndexRootGroup = 8; + private const int contextMenuClearAllIndexRootGroup = 9; private const int contextMenuAddCalculationGroupIndexNestedGroup = 0; private const int contextMenuAddCalculationIndexNestedGroup = 1; @@ -184,8 +188,11 @@ assessmentSectionMock); var menuBuilderMock = mocks.StrictMock(); + 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); + menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddDeleteChildrenItem()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); @@ -237,8 +244,13 @@ using (ContextMenuStrip menu = info.ContextMenuStrip(groupContext, null, treeViewControl)) { // Assert - Assert.AreEqual(13, menu.Items.Count); + Assert.AreEqual(15, menu.Items.Count); + TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuGenerateCalculationsIndexRootGroup, + "Genereer &berekeningen...", + "Er zijn geen kunstwerken beschikbaar om berekeningen voor te genereren.", + RingtoetsCommonFormsResources.GenerateScenariosIcon, + false); TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuAddCalculationGroupIndexRootGroup, "&Map toevoegen", "Voeg een nieuwe berekeningsmap toe aan deze berekeningsmap.", @@ -268,6 +280,41 @@ } [Test] + public void ContextMenuStrip_WithoutParentNodeWithStructuresImported_GenerateItemEnabledWithTooltip() + { + // Setup + var group = new CalculationGroup(); + var failureMechanism = new ClosingStructuresFailureMechanism(); + failureMechanism.ClosingStructures.Add(new TestClosingStructure()); + var assessmentSectionStub = mocks.Stub(); + assessmentSectionStub.HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase(); + var groupContext = new ClosingStructuresCalculationGroupContext(group, + failureMechanism, + assessmentSectionStub); + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + using (var treeViewControl = new TreeViewControl()) + { + guiMock.Expect(g => g.Get(groupContext, treeViewControl)).Return(menuBuilder); + guiMock.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); + + mocks.ReplayAll(); + + // Call + using (ContextMenuStrip menu = info.ContextMenuStrip(groupContext, null, treeViewControl)) + { + // Assert + Assert.AreEqual(15, menu.Items.Count); + + TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuGenerateCalculationsIndexRootGroup, + "Genereer &berekeningen...", + "Genereer berekeningen op basis van geselecteerde kunstwerken.", + RingtoetsCommonFormsResources.GenerateScenariosIcon); + } + } + } + + [Test] public void ContextMenuStrip_NestedCalculationGroup_CallsContextMenuBuilderMethods() { // Setup @@ -831,6 +878,189 @@ } [Test] + public void GivenCalculationsViewGenerateScenariosButtonClicked_WhenClosingStructureSelectedAndDialogClosed_ThenCalculationsAddedWithClosingStructureAssigned() + { + // Given + using (var treeViewControl = new TreeViewControl()) + { + var assessmentSectionMock = mocks.StrictMock(); + + ClosingStructure structure1 = new TestClosingStructure("Structure 1"); + ClosingStructure structure2 = new TestClosingStructure("Structure 2"); + + var failureMechanism = new ClosingStructuresFailureMechanism + { + ClosingStructures = + { + structure1, + structure2 + } + }; + + var nodeData = new ClosingStructuresCalculationGroupContext(failureMechanism.CalculationsGroup, + failureMechanism, + assessmentSectionMock); + + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + var mainWindow = mocks.Stub(); + + guiMock.Expect(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilder); + guiMock.Expect(g => g.MainWindow).Return(mainWindow); + guiMock.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); + + mocks.ReplayAll(); + + plugin.Gui = guiMock; + + DialogBoxHandler = (name, wnd) => + { + var selectionDialog = (StructureSelectionDialog) new FormTester(name).TheObject; + var grid = (DataGridViewControl) new ControlTester("DataGridViewControl", selectionDialog).TheObject; + + grid.Rows[0].Cells[0].Value = true; + + new ButtonTester("DoForSelectedButton", selectionDialog).Click(); + }; + + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // When + contextMenu.Items[contextMenuGenerateCalculationsIndexRootGroup].PerformClick(); + + // Then + var closingStructuresCalculations = failureMechanism.Calculations.OfType>().ToArray(); + Assert.AreEqual(1, closingStructuresCalculations.Length); + Assert.AreSame(structure1, closingStructuresCalculations[0].InputParameters.Structure); + } + } + } + + [Test] + public void GivenCalculationsViewGenerateScenariosButtonClicked_WhenCancelButtonClickedAndDialogClosed_ThenCalculationsNotUpdated() + { + // Given + using (var treeViewControl = new TreeViewControl()) + { + var assessmentSectionMock = mocks.StrictMock(); + + ClosingStructure structure1 = new TestClosingStructure("Structure 1"); + ClosingStructure structure2 = new TestClosingStructure("Structure 2"); + + var failureMechanism = new ClosingStructuresFailureMechanism + { + ClosingStructures = + { + structure1, + structure2 + } + }; + + var nodeData = new ClosingStructuresCalculationGroupContext(failureMechanism.CalculationsGroup, + failureMechanism, + assessmentSectionMock); + + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + var mainWindow = mocks.Stub(); + + guiMock.Expect(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilder); + guiMock.Expect(g => g.MainWindow).Return(mainWindow); + guiMock.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); + + mocks.ReplayAll(); + + plugin.Gui = guiMock; + + DialogBoxHandler = (name, wnd) => + { + var selectionDialog = (StructureSelectionDialog) new FormTester(name).TheObject; + var grid = (DataGridViewControl) new ControlTester("DataGridViewControl", selectionDialog).TheObject; + + grid.Rows[0].Cells[0].Value = true; + + new ButtonTester("CustomCancelButton", selectionDialog).Click(); + }; + + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // When + contextMenu.Items[contextMenuGenerateCalculationsIndexRootGroup].PerformClick(); + + // Then + Assert.AreEqual(0, failureMechanism.Calculations.OfType>().Count()); + } + } + } + + [Test] + public void GivenScenariosWithExistingCalculationWithSameName_WhenOkButtonClickedAndDialogClosed_ThenCalculationWithUniqueNameAdded() + { + // Given + using (var treeViewControl = new TreeViewControl()) + { + var assessmentSectionMock = mocks.StrictMock(); + + var existingCalculationName = "Closing structure"; + ClosingStructure closingStructure = new TestClosingStructure(existingCalculationName); + + var failureMechanism = new ClosingStructuresFailureMechanism + { + ClosingStructures = + { + closingStructure + }, + CalculationsGroup = + { + Children = + { + new StructuresCalculation + { + Name = existingCalculationName + } + } + } + }; + + var nodeData = new ClosingStructuresCalculationGroupContext(failureMechanism.CalculationsGroup, + failureMechanism, + assessmentSectionMock); + + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + var mainWindow = mocks.Stub(); + + guiMock.Expect(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilder); + guiMock.Expect(g => g.MainWindow).Return(mainWindow); + guiMock.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); + + mocks.ReplayAll(); + + plugin.Gui = guiMock; + + DialogBoxHandler = (name, wnd) => + { + var selectionDialog = (StructureSelectionDialog) new FormTester(name).TheObject; + var grid = (DataGridViewControl) new ControlTester("DataGridViewControl", selectionDialog).TheObject; + + grid.Rows[0].Cells[0].Value = true; + + new ButtonTester("DoForSelectedButton", selectionDialog).Click(); + }; + + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + string expectedNewName = NamingHelper.GetUniqueName(failureMechanism.CalculationsGroup.Children, existingCalculationName, c => c.Name); + + // When + contextMenu.Items[contextMenuGenerateCalculationsIndexRootGroup].PerformClick(); + + // Then + var closingStructuresCalculations = failureMechanism.Calculations.OfType>().ToArray(); + Assert.AreEqual(2, closingStructuresCalculations.Length); + Assert.AreEqual(expectedNewName, closingStructuresCalculations[1].Name); + } + } + } + + [Test] public void OnNodeRemoved_NestedCalculationGroup_RemoveGroupAndNotifyObservers() { // Setup Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.Designer.cs =================================================================== diff -u -r3b1b80d82960d3bfa4906e06e37e73e4729eb3ad -r86984ca293c30b4f9b47da7825cbae1404fffe08 --- Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 3b1b80d82960d3bfa4906e06e37e73e4729eb3ad) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 86984ca293c30b4f9b47da7825cbae1404fffe08) @@ -2018,6 +2018,15 @@ } /// + /// Looks up a localized string similar to Selecteer kunstwerken. + /// + public static string StructureSelectionDialog_Select_Structures { + get { + return ResourceManager.GetString("StructureSelectionDialog_Select_Structures", resourceCulture); + } + } + + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// public static System.Drawing.Bitmap StructuresIcon { @@ -2109,6 +2118,24 @@ } /// + /// Looks up a localized string similar to Genereer berekeningen op basis van geselecteerde kunstwerken.. + /// + public static string StructuresPlugin_Generate_calculations_for_selected_structures { + get { + return ResourceManager.GetString("StructuresPlugin_Generate_calculations_for_selected_structures", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Er zijn geen kunstwerken beschikbaar om berekeningen voor te genereren.. + /// + public static string StructuresPlugin_No_structures_to_generate_for { + get { + return ResourceManager.GetString("StructuresPlugin_No_structures_to_generate_for", resourceCulture); + } + } + + /// /// Looks up a localized string similar to &Valideren. /// public static string Validate { Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.resx =================================================================== diff -u -r3b1b80d82960d3bfa4906e06e37e73e4729eb3ad -r86984ca293c30b4f9b47da7825cbae1404fffe08 --- Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.resx (.../Resources.resx) (revision 3b1b80d82960d3bfa4906e06e37e73e4729eb3ad) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.resx (.../Resources.resx) (revision 86984ca293c30b4f9b47da7825cbae1404fffe08) @@ -811,4 +811,13 @@ Afwijking golfrichting [°] + + Selecteer kunstwerken + + + Genereer berekeningen op basis van geselecteerde kunstwerken. + + + Er zijn geen kunstwerken beschikbaar om berekeningen voor te genereren. + \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Ringtoets.Common.Forms.csproj =================================================================== diff -u -r46ef6c094cc1589938bc88bee6f5bdac70233462 -r86984ca293c30b4f9b47da7825cbae1404fffe08 --- Ringtoets/Common/src/Ringtoets.Common.Forms/Ringtoets.Common.Forms.csproj (.../Ringtoets.Common.Forms.csproj) (revision 46ef6c094cc1589938bc88bee6f5bdac70233462) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/Ringtoets.Common.Forms.csproj (.../Ringtoets.Common.Forms.csproj) (revision 86984ca293c30b4f9b47da7825cbae1404fffe08) @@ -102,6 +102,9 @@ Form + + Form + Index: Ringtoets/Common/src/Ringtoets.Common.Forms/StructureSelectionDialog.cs =================================================================== diff -u --- Ringtoets/Common/src/Ringtoets.Common.Forms/StructureSelectionDialog.cs (revision 0) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/StructureSelectionDialog.cs (revision 86984ca293c30b4f9b47da7825cbae1404fffe08) @@ -0,0 +1,58 @@ +// 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; +using System.Collections.Generic; +using System.Linq; +using System.Windows.Forms; +using Ringtoets.Common.Data; +using Ringtoets.Common.Forms.Properties; +using Ringtoets.Common.Forms.Views; + +namespace Ringtoets.Common.Forms +{ + /// + /// A dialog which allows the user to make a selection from a given set of . Upon + /// closing of the dialog, the selected can be obtained. + /// + public class StructureSelectionDialog : SelectionDialogBase + { + /// + /// Creates a new instance of . + /// + /// The parent of the dialog. + /// The collection of to show in the dialog. + /// Thrown when any parameter is null. + public StructureSelectionDialog(IWin32Window dialogParent, IEnumerable structures) + : base(dialogParent) + { + if (structures == null) + { + throw new ArgumentNullException("structures"); + } + + Text = Resources.StructureSelectionDialog_Select_Structures; + InitializeDataGridView(Resources.Structure_DisplayName); + + SetDataSource(structures.Select(structure => new SelectableRow(structure, structure.Name)).ToArray()); + } + } +} \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Ringtoets.Common.Forms.Test.csproj =================================================================== diff -u -r75443ac72bf8b348e362dbf4b40f535495f6b2b3 -r86984ca293c30b4f9b47da7825cbae1404fffe08 --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Ringtoets.Common.Forms.Test.csproj (.../Ringtoets.Common.Forms.Test.csproj) (revision 75443ac72bf8b348e362dbf4b40f535495f6b2b3) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Ringtoets.Common.Forms.Test.csproj (.../Ringtoets.Common.Forms.Test.csproj) (revision 86984ca293c30b4f9b47da7825cbae1404fffe08) @@ -93,6 +93,7 @@ + Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/StructureSelectionDialogTest.cs =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/StructureSelectionDialogTest.cs (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/StructureSelectionDialogTest.cs (revision 86984ca293c30b4f9b47da7825cbae1404fffe08) @@ -0,0 +1,144 @@ +// 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; +using System.Linq; +using System.Windows.Forms; +using Core.Common.Base.Geometry; +using Core.Common.Controls.DataGrid; +using NUnit.Extensions.Forms; +using NUnit.Framework; +using Ringtoets.Common.Data; + +namespace Ringtoets.Common.Forms.Test +{ + [TestFixture] + public class StructureSelectionDialogTest + { + private const int selectItemColumnIndex = 0; + private const int nameColumnIndex = 1; + + [Test] + public void Constructor_WithoutParent_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => new StructureSelectionDialog(null, Enumerable.Empty()); + + // Assert + string parameter = Assert.Throws(test).ParamName; + Assert.AreEqual("dialogParent", parameter); + } + + [Test] + public void Constructor_WithoutStructures_ThrowsArgumentNullException() + { + // Setup + using (var viewParent = new Form()) + { + // Call + TestDelegate test = () => new StructureSelectionDialog(viewParent, null); + + // Assert + string parameter = Assert.Throws(test).ParamName; + Assert.AreEqual("structures", parameter); + } + } + + [Test] + public void Constructor_WithParentAndStructures_DefaultProperties() + { + // Setup & Call + using (var viewParent = new Form()) + using (var dialog = new StructureSelectionDialog(viewParent, Enumerable.Empty())) + { + // Assert + Assert.IsInstanceOf>(dialog); + Assert.IsEmpty(dialog.SelectedItems); + Assert.AreEqual("Selecteer kunstwerken", dialog.Text); + } + } + + [Test] + public void Constructor_DataGridViewCorrectlyInitialized() + { + // Setup & Call + using (var viewParent = new Form()) + using (var dialog = new StructureSelectionDialog(viewParent, Enumerable.Empty())) + { + dialog.Show(); + + // Assert + Assert.IsEmpty(dialog.SelectedItems); + + var dataGridViewControl = (DataGridViewControl) new ControlTester("DataGridViewControl", dialog).TheObject; + var dataGridView = dataGridViewControl.Controls.OfType().First(); + Assert.AreEqual(2, dataGridView.ColumnCount); + + var locationCalculateColumn = (DataGridViewCheckBoxColumn) dataGridView.Columns[selectItemColumnIndex]; + Assert.AreEqual("Gebruik", locationCalculateColumn.HeaderText); + Assert.AreEqual("Selected", locationCalculateColumn.DataPropertyName); + Assert.IsFalse(locationCalculateColumn.ReadOnly); + + var nameColumn = (DataGridViewTextBoxColumn) dataGridView.Columns[nameColumnIndex]; + Assert.AreEqual("Kunstwerk", nameColumn.HeaderText); + Assert.AreEqual("Name", nameColumn.DataPropertyName); + Assert.AreEqual(DataGridViewAutoSizeColumnMode.Fill, nameColumn.AutoSizeMode); + Assert.IsTrue(nameColumn.ReadOnly); + } + } + + [Test] + public void Constructor_StructuresOneEntry_OneRowInGrid() + { + // Setup + var testname = "Test"; + var constructionProperties = new StructureBase.ConstructionProperties + { + Name = testname, + Id = "anId", + Location = new Point2D(0, 0), + StructureNormalOrientation = 0.0 + }; + var structure = new TestStructure(constructionProperties); + + // Call + using (var viewParent = new Form()) + using (var dialog = new StructureSelectionDialog(viewParent, new[] + { + structure + })) + { + // Assert + dialog.Show(); + + var dataGridViewControl = (DataGridViewControl) new ControlTester("DataGridViewControl").TheObject; + Assert.AreEqual(1, dataGridViewControl.Rows.Count); + Assert.IsFalse((bool) dataGridViewControl.Rows[0].Cells[selectItemColumnIndex].Value); + Assert.AreEqual(testname, (string) dataGridViewControl.Rows[0].Cells[nameColumnIndex].Value); + } + } + } + + public class TestStructure : StructureBase + { + public TestStructure(ConstructionProperties constructionProperties) : base(constructionProperties) {} + } +} \ No newline at end of file Fisheye: Tag 86984ca293c30b4f9b47da7825cbae1404fffe08 refers to a dead (removed) revision in file `Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Forms/Properties/Resources.Designer.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 86984ca293c30b4f9b47da7825cbae1404fffe08 refers to a dead (removed) revision in file `Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Forms/Properties/Resources.resx'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Forms/PropertyClasses/HeightStructureProperties.cs =================================================================== diff -u -rfd6db3bae09296e4da11ac9fb9e5dde9b31bc178 -r86984ca293c30b4f9b47da7825cbae1404fffe08 --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Forms/PropertyClasses/HeightStructureProperties.cs (.../HeightStructureProperties.cs) (revision fd6db3bae09296e4da11ac9fb9e5dde9b31bc178) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Forms/PropertyClasses/HeightStructureProperties.cs (.../HeightStructureProperties.cs) (revision 86984ca293c30b4f9b47da7825cbae1404fffe08) @@ -28,7 +28,6 @@ using Ringtoets.Common.Forms.Helpers; using Ringtoets.Common.Forms.PropertyClasses; using Ringtoets.HeightStructures.Data; -using Ringtoets.HeightStructures.Forms.Properties; using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; namespace Ringtoets.HeightStructures.Forms.PropertyClasses Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Forms/Ringtoets.HeightStructures.Forms.csproj =================================================================== diff -u -re4e785f127ce9a2d0d1734c1b51e02d910a31bbe -r86984ca293c30b4f9b47da7825cbae1404fffe08 --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Forms/Ringtoets.HeightStructures.Forms.csproj (.../Ringtoets.HeightStructures.Forms.csproj) (revision e4e785f127ce9a2d0d1734c1b51e02d910a31bbe) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Forms/Ringtoets.HeightStructures.Forms.csproj (.../Ringtoets.HeightStructures.Forms.csproj) (revision 86984ca293c30b4f9b47da7825cbae1404fffe08) @@ -48,17 +48,9 @@ - - True - True - Resources.resx - - - Form - UserControl @@ -123,13 +115,6 @@ Copying.licenseheader - - - PublicResXFileCodeGenerator - Resources.Designer.cs - Designer - -