Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Ringtoets.Common.Forms.csproj =================================================================== diff -u -rc2ab4d0607360bf72be79d5373469d38292aab94 -ra39fb3074f6c4cfa06efce5663d8ee428587dddb --- Ringtoets/Common/src/Ringtoets.Common.Forms/Ringtoets.Common.Forms.csproj (.../Ringtoets.Common.Forms.csproj) (revision c2ab4d0607360bf72be79d5373469d38292aab94) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/Ringtoets.Common.Forms.csproj (.../Ringtoets.Common.Forms.csproj) (revision a39fb3074f6c4cfa06efce5663d8ee428587dddb) @@ -119,6 +119,16 @@ + + + UserControl + + + UserControl + + + FailureMechanismSectionsView.cs + UserControl @@ -209,6 +219,10 @@ ScenarioSelectionControl.cs + + FailureMechanismSectionsView.cs + Designer + GeneralResultFaultTreeIllustrationPointView.cs Designer Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Views/FailureMechanismSectionRow.cs =================================================================== diff -u --- Ringtoets/Common/src/Ringtoets.Common.Forms/Views/FailureMechanismSectionRow.cs (revision 0) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/Views/FailureMechanismSectionRow.cs (revision a39fb3074f6c4cfa06efce5663d8ee428587dddb) @@ -0,0 +1,57 @@ +// Copyright (C) Stichting Deltares 2017. 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 Core.Common.Base.Data; +using Ringtoets.Common.Data.FailureMechanism; + +namespace Ringtoets.Common.Forms.Views +{ + public class FailureMechanismSectionRow + { + /// + /// Creates a new instance of . + /// + /// The to use. + /// Thrown when + /// is null. + public FailureMechanismSectionRow(FailureMechanismSection section) + { + if (section == null) + { + throw new ArgumentNullException(nameof(section)); + } + + Name = section.Name; + Length = section.Length; + } + + /// + /// Gets the name of the section. + /// + public string Name { get; } + + /// + /// Gets the length of the section + /// + public RoundedDouble Length { get; } + } +} \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Views/FailureMechanismSectionsTable.cs =================================================================== diff -u --- Ringtoets/Common/src/Ringtoets.Common.Forms/Views/FailureMechanismSectionsTable.cs (revision 0) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/Views/FailureMechanismSectionsTable.cs (revision a39fb3074f6c4cfa06efce5663d8ee428587dddb) @@ -0,0 +1,60 @@ +// Copyright (C) Stichting Deltares 2017. 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.Collections.Generic; +using System.Linq; +using Core.Common.Controls.DataGrid; +using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.Common.Forms.Properties; + +namespace Ringtoets.Common.Forms.Views +{ + public class FailureMechanismSectionsTable : DataGridViewControl + { + /// + /// Creates a new instance of . + /// + public FailureMechanismSectionsTable() + { + AddColumns(); + } + + /// + /// Sets the given for which the properties + /// are shown in the table. + /// + /// The collection of sections to show. + public void SetData(IEnumerable sections) + { + SetDataSource(sections?.Select((section, index) => new FailureMechanismSectionRow(section)).ToArray()); + } + + private void AddColumns() + { + AddTextBoxColumn(nameof(FailureMechanismSection.Name), + Resources.FailureMechanismSection_Name_DisplayName, + true); + AddTextBoxColumn(nameof(FailureMechanismSection.Length), + Resources.FailureMechanismSection_Length_DisplayName, + true); + } + } +} \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Views/FailureMechanismSectionsView.Designer.cs =================================================================== diff -u --- Ringtoets/Common/src/Ringtoets.Common.Forms/Views/FailureMechanismSectionsView.Designer.cs (revision 0) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/Views/FailureMechanismSectionsView.Designer.cs (revision a39fb3074f6c4cfa06efce5663d8ee428587dddb) @@ -0,0 +1,67 @@ +// Copyright (C) Stichting Deltares 2017. 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.Windows.Forms; + +namespace Ringtoets.Common.Forms.Views +{ + partial class FailureMechanismSectionsView + { + + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FailureMechanismSectionsView)); + this.failureMechanismSectionsTable = new Ringtoets.Common.Forms.Views.FailureMechanismSectionsTable(); + this.SuspendLayout(); + // + // failureMechanismSectionsTable + // + resources.ApplyResources(this.failureMechanismSectionsTable, "failureMechanismSectionsTable"); + this.failureMechanismSectionsTable.MultiSelect = true; + this.failureMechanismSectionsTable.Name = "failureMechanismSectionsTable"; + this.failureMechanismSectionsTable.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.RowHeaderSelect; + // + // FailureMechanismSectionsView + // + this.Controls.Add(this.failureMechanismSectionsTable); + this.Name = "FailureMechanismSectionsView"; + resources.ApplyResources(this, "$this"); + this.ResumeLayout(false); + + } + + + #endregion + + private FailureMechanismSectionsTable failureMechanismSectionsTable; + } +} Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Views/FailureMechanismSectionsView.cs =================================================================== diff -u --- Ringtoets/Common/src/Ringtoets.Common.Forms/Views/FailureMechanismSectionsView.cs (revision 0) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/Views/FailureMechanismSectionsView.cs (revision a39fb3074f6c4cfa06efce5663d8ee428587dddb) @@ -0,0 +1,86 @@ +// Copyright (C) Stichting Deltares 2017. 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.Windows.Forms; +using Core.Common.Base; +using Core.Common.Controls.Views; +using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.Common.Forms.PresentationObjects; + +namespace Ringtoets.Common.Forms.Views +{ + /// + /// View for the , from which the + /// and can be seen in a grid. + /// + public partial class FailureMechanismSectionsView : UserControl, IView, IObserver + { + private FailureMechanismSectionsContext data; + + /// + /// Creates a new instance of . + /// + public FailureMechanismSectionsView() + { + InitializeComponent(); + } + + public object Data + { + get + { + return data; + } + set + { + data?.Detach(this); + data = value as FailureMechanismSectionsContext; + data?.Attach(this); + + UpdateTableData(); + } + } + + public void UpdateObserver() + { + UpdateTableData(); + } + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing) + { + components?.Dispose(); + } + + base.Dispose(disposing); + } + + private void UpdateTableData() + { + failureMechanismSectionsTable.SetData(((FailureMechanismSectionsContext) Data)?.WrappedData.Sections); + } + } +} \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Views/FailureMechanismSectionsView.resx =================================================================== diff -u --- Ringtoets/Common/src/Ringtoets.Common.Forms/Views/FailureMechanismSectionsView.resx (revision 0) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/Views/FailureMechanismSectionsView.resx (revision a39fb3074f6c4cfa06efce5663d8ee428587dddb) @@ -0,0 +1,159 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + Fill + + + + 0, 0 + + + 750, 420 + + + + 0 + + + failureMechanismSectionsTable + + + Ringtoets.Common.Forms.Views.FailureMechanismSectionsTable, Ringtoets.Common.Forms, Version=18.1.1.1, Culture=neutral, PublicKeyToken=null + + + $this + + + 0 + + + True + + + 750, 420 + + + FailureMechanismSectionsView + + + System.Windows.Forms.UserControl, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Ringtoets.Common.Forms.Test.csproj =================================================================== diff -u -rc2ab4d0607360bf72be79d5373469d38292aab94 -ra39fb3074f6c4cfa06efce5663d8ee428587dddb --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Ringtoets.Common.Forms.Test.csproj (.../Ringtoets.Common.Forms.Test.csproj) (revision c2ab4d0607360bf72be79d5373469d38292aab94) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Ringtoets.Common.Forms.Test.csproj (.../Ringtoets.Common.Forms.Test.csproj) (revision a39fb3074f6c4cfa06efce5663d8ee428587dddb) @@ -116,6 +116,9 @@ + + + Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Views/FailureMechanismSectionRowTest.cs =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Views/FailureMechanismSectionRowTest.cs (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Views/FailureMechanismSectionRowTest.cs (revision a39fb3074f6c4cfa06efce5663d8ee428587dddb) @@ -0,0 +1,63 @@ +// Copyright (C) Stichting Deltares 2017. 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 Core.Common.Base.Geometry; +using NUnit.Framework; +using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Forms.Views; + +namespace Ringtoets.Common.Forms.Test.Views +{ + [TestFixture] + public class FailureMechanismSectionRowTest + { + [Test] + public void Constructor_SliceNull_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => new FailureMechanismSectionRow(null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("section", paramName); + } + + [Test] + public void Constructor_WithSlice_ExpectedValues() + { + // Setup + var section = new FailureMechanismSection("test", new[] + { + new Point2D(0.0, 0.0), + new Point2D(0.0, 10.0) + }); + + // Call + var sectionRow = new FailureMechanismSectionRow(section); + + // Assert + Assert.AreEqual("test", sectionRow.Name); + Assert.AreEqual(10.0, sectionRow.Length, sectionRow.Length.GetAccuracy()); + } + } +} \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Views/FailureMechanismSectionsTableTest.cs =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Views/FailureMechanismSectionsTableTest.cs (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Views/FailureMechanismSectionsTableTest.cs (revision a39fb3074f6c4cfa06efce5663d8ee428587dddb) @@ -0,0 +1,163 @@ +// Copyright (C) Stichting Deltares 2017. 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.Windows.Forms; +using Core.Common.Base.Geometry; +using NUnit.Framework; +using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.Common.Forms.Views; + +namespace Ringtoets.Common.Forms.Test.Views +{ + [TestFixture] + public class FailureMechanismSectionsTableTest + { + private const int nameColumnIndex = 0; + private const int lengthColumnIndex = 1; + + [Test] + public void Constructor_InitializesWithColumns() + { + // Call + using (var table = new FailureMechanismSectionsTable()) + { + // Assert + DataGridViewColumn nameColumn = table.GetColumnFromIndex(nameColumnIndex); + Assert.AreEqual("Naam", nameColumn.HeaderText); + DataGridViewColumn lengthColumn = table.GetColumnFromIndex(lengthColumnIndex); + Assert.AreEqual("Lengte [m]", lengthColumn.HeaderText); + + Assert.Throws(() => table.GetColumnFromIndex(lengthColumnIndex + 1)); + + CollectionAssert.IsEmpty(table.Rows); + } + } + + [Test] + public void SetData_NoDataAlreadySet_SetNewData() + { + // Setup + using (var table = new FailureMechanismSectionsTable()) + { + var sections = new[] + { + CreateFailureMechanismSection("a"), + CreateFailureMechanismSection("b"), + CreateFailureMechanismSection("c") + }; + + // Call + table.SetData(sections); + + // Assert + Assert.AreEqual(3, table.Rows.Count); + } + } + + [Test] + public void SetData_SetNullDataAfterDataAlreadySet_ClearsData() + { + // Setup + using (var table = new FailureMechanismSectionsTable()) + { + var sections = new[] + { + CreateFailureMechanismSection("a"), + CreateFailureMechanismSection("b"), + CreateFailureMechanismSection("c") + }; + table.SetData(sections); + + // Call + table.SetData(null); + + // Assert + Assert.AreEqual(0, table.Rows.Count); + } + } + + [Test] + public void SetData_SetNewDataAfterDataAlreadySet_ClearDataAndAddNewData() + { + // Setup + using (var table = new FailureMechanismSectionsTable()) + { + var sections = new[] + { + CreateFailureMechanismSection("a"), + CreateFailureMechanismSection("b"), + CreateFailureMechanismSection("c") + }; + table.SetData(new[] + { + CreateFailureMechanismSection("d") + }); + + // Call + table.SetData(sections); + + // Assert + Assert.AreEqual(3, table.Rows.Count); + } + } + + [Test] + public void SetData_WithData_ExpectedValuesInTable() + { + // Setup + using (var table = new FailureMechanismSectionsTable()) + { + var sections = new[] + { + CreateFailureMechanismSection("a"), + CreateFailureMechanismSection("b"), + CreateFailureMechanismSection("c") + }; + + // Call + table.SetData(sections); + + // Assert + Assert.AreEqual(3, table.Rows.Count); + for (var i = 0; i < table.Rows.Count; i++) + { + FailureMechanismSection section = sections[i]; + DataGridViewCellCollection rowCells = table.Rows[i].Cells; + + Assert.AreEqual(section.Name, + rowCells[nameColumnIndex].Value); + Assert.AreEqual(section.Length, + rowCells[lengthColumnIndex].Value); + } + } + } + + private static FailureMechanismSection CreateFailureMechanismSection(string name) + { + var random = new Random(39); + return new FailureMechanismSection(name, new[] + { + new Point2D(random.NextDouble(), random.NextDouble()) + }); + } + } +} \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Views/FailureMechanismSectionsViewTest.cs =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Views/FailureMechanismSectionsViewTest.cs (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Views/FailureMechanismSectionsViewTest.cs (revision a39fb3074f6c4cfa06efce5663d8ee428587dddb) @@ -0,0 +1,232 @@ +// Copyright (C) Stichting Deltares 2017. 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; +using Core.Common.Base.Geometry; +using Core.Common.Controls.Views; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Forms.PresentationObjects; +using Ringtoets.Common.Forms.TestUtil; +using Ringtoets.Common.Forms.Views; + +namespace Ringtoets.Common.Forms.Test.Views +{ + [TestFixture] + public class FailureMechanismSectionsViewTest + { + [Test] + public void DefaultConstructor_DefaultValues() + { + // Call + using (var view = new FailureMechanismSectionsView()) + { + // Assert + Assert.IsInstanceOf(view); + Assert.IsInstanceOf(view); + Assert.IsNull(view.Data); + Assert.AreEqual(1, view.Controls.Count); + } + } + + [Test] + public void DefaultConstructor_Always_AddEmptyTableControl() + { + // Call + using (var view = new FailureMechanismSectionsView()) + { + // Assert + FailureMechanismSectionsTable tableControl = GetSectionsTable(view); + Assert.NotNull(tableControl); + Assert.AreEqual(DockStyle.Fill, tableControl.Dock); + CollectionAssert.IsEmpty(tableControl.Rows); + } + } + + [Test] + public void Data_FailureMechanismSectionsContext_DataSet() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + var failureMechanism = mocks.Stub(); + + mocks.ReplayAll(); + + using (var view = new FailureMechanismSectionsView()) + { + var context = new FailureMechanismSectionsContext(failureMechanism, assessmentSection); + + // Call + view.Data = context; + + // Assert + Assert.AreSame(context, view.Data); + } + + mocks.VerifyAll(); + } + + [Test] + public void Data_OtherThanFailureMechanismSectionsContext_DataNull() + { + // Setup + using (var view = new FailureMechanismSectionsView()) + { + var data = new object(); + + // Call + view.Data = data; + + // Assert + Assert.IsNull(view.Data); + } + } + + [Test] + public void Data_SetToNull_TableDataCleared() + { + // Setup + var mocks = new MockRepository(); + var random = new Random(39); + var assessmentSection = mocks.Stub(); + var failureMechanism = new TestFailureMechanism(); + failureMechanism.AddSection(new FailureMechanismSection("A", new[] + { + new Point2D(random.NextDouble(), random.NextDouble()) + })); + var context = new FailureMechanismSectionsContext(failureMechanism, assessmentSection); + + mocks.ReplayAll(); + + using (var view = new FailureMechanismSectionsView + { + Data = context + }) + { + FailureMechanismSectionsTable sectionsTable = GetSectionsTable(view); + + // Precondition + Assert.NotNull(sectionsTable); + Assert.AreEqual(1, sectionsTable.Rows.Count); + + // Call + view.Data = null; + + // Assert + Assert.IsNull(view.Data); + CollectionAssert.IsEmpty(sectionsTable.Rows); + } + } + + [Test] + public void GivenViewWithSections_WhenSectionsUpdated_ThenDataTableUpdated() + { + // Given + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + var observer = mocks.StrictMock(); + observer.Expect(o => o.UpdateObserver()); + + mocks.ReplayAll(); + + var failureMechanism = new TestFailureMechanism(); + failureMechanism.AddSection(new FailureMechanismSection("A", new[] + { + new Point2D(0.0, 0.0) + })); + var context = new FailureMechanismSectionsContext(failureMechanism, assessmentSection); + + using (var view = new FailureMechanismSectionsView + { + Data = context + }) + { + FailureMechanismSectionsTable sectionsTable = GetSectionsTable(view); + + // Precondition + Assert.AreEqual(1, sectionsTable.Rows.Count); + + // When + context.WrappedData.Attach(observer); + context.WrappedData.AddSection(new FailureMechanismSection("A", new[] + { + new Point2D(0.0, 0.0) + })); + context.WrappedData.NotifyObservers(); + + // Then + Assert.AreEqual(2, sectionsTable.Rows.Count); + mocks.VerifyAll(); + } + } + + [Test] + public void GivenViewWithSections_WhenSectionsCleared_ThenDataTableCleared() + { + // Given + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + var observer = mocks.StrictMock(); + observer.Expect(o => o.UpdateObserver()); + + mocks.ReplayAll(); + + var failureMechanism = new TestFailureMechanism(); + failureMechanism.AddSection(new FailureMechanismSection("A", new[] + { + new Point2D(0.0, 0.0) + })); + var context = new FailureMechanismSectionsContext(failureMechanism, assessmentSection); + + using (var view = new FailureMechanismSectionsView + { + Data = context + }) + { + FailureMechanismSectionsTable sectionsTable = GetSectionsTable(view); + + // Precondition + Assert.AreEqual(1, sectionsTable.Rows.Count); + + // When + context.WrappedData.Attach(observer); + context.WrappedData.ClearAllSections(); + context.WrappedData.NotifyObservers(); + + // Then + Assert.AreEqual(0, sectionsTable.Rows.Count); + mocks.VerifyAll(); + } + } + + private static FailureMechanismSectionsTable GetSectionsTable(FailureMechanismSectionsView view) + { + return ControlTestHelper.GetControls(view, "failureMechanismSectionsTable").Single(); + } + } +} \ No newline at end of file Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs =================================================================== diff -u -rb19983374f4a64979bbb5167bcab288a921aa5e5 -ra39fb3074f6c4cfa06efce5663d8ee428587dddb --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs (.../RingtoetsPlugin.cs) (revision b19983374f4a64979bbb5167bcab288a921aa5e5) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs (.../RingtoetsPlugin.cs) (revision a39fb3074f6c4cfa06efce5663d8ee428587dddb) @@ -451,6 +451,13 @@ CloseForData = CloseCommentViewForData }; + yield return new ViewInfo + { + GetViewName = (view, context) => RingtoetsCommonFormsResources.FailureMechanismSections_DisplayName, + Image = RingtoetsCommonFormsResources.SectionsIcon, + CloseForData = CloseFailureMechanismSectionsViewForData, + }; + yield return new ViewInfo, WaveConditionsInputView> { Image = RingtoetsCommonFormsResources.GenericInputOutputIcon, @@ -1038,6 +1045,30 @@ #endregion + #region FailureMechanismSectionsView ViewInfo + + private static bool CloseFailureMechanismSectionsViewForData(FailureMechanismSectionsView view, object o) + { + var assessmentSection = o as IAssessmentSection; + var failureMechanism = o as IFailureMechanism; + var failureMechanismContext = o as IFailureMechanismContext; + + if (failureMechanismContext != null) + { + failureMechanism = failureMechanismContext.WrappedData; + } + + if (assessmentSection != null) + { + failureMechanism = assessmentSection.GetFailureMechanisms() + .FirstOrDefault(fm => fm == ((FailureMechanismSectionsContext) view.Data).WrappedData); + } + + return failureMechanism != null && ReferenceEquals(((FailureMechanismSectionsContext) view.Data).WrappedData, failureMechanism); + } + + #endregion + #region WaveConditionsInputViewInfo private static IWaveConditionsInputViewStyle GetWaveConditionsInputViewStyle(WaveConditionsInputContext context) @@ -1071,6 +1102,8 @@ private ContextMenuStrip FailureMechanismSectionsContextMenuStrip(FailureMechanismSectionsContext nodeData, object parentData, TreeViewControl treeViewControl) { return Gui.Get(nodeData, treeViewControl) + .AddOpenItem() + .AddSeparator() .AddImportItem() .Build(); } Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Ringtoets.Integration.Plugin.Test.csproj =================================================================== diff -u -r7aff630a7c9bb21707781ca2bd0f977d4715891d -ra39fb3074f6c4cfa06efce5663d8ee428587dddb --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Ringtoets.Integration.Plugin.Test.csproj (.../Ringtoets.Integration.Plugin.Test.csproj) (revision 7aff630a7c9bb21707781ca2bd0f977d4715891d) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Ringtoets.Integration.Plugin.Test.csproj (.../Ringtoets.Integration.Plugin.Test.csproj) (revision a39fb3074f6c4cfa06efce5663d8ee428587dddb) @@ -87,6 +87,7 @@ + Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/RingtoetsPluginTest.cs =================================================================== diff -u -r443fd7cc3d1e9397cbeef55bdc20777dd50f98de -ra39fb3074f6c4cfa06efce5663d8ee428587dddb --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/RingtoetsPluginTest.cs (.../RingtoetsPluginTest.cs) (revision 443fd7cc3d1e9397cbeef55bdc20777dd50f98de) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/RingtoetsPluginTest.cs (.../RingtoetsPluginTest.cs) (revision a39fb3074f6c4cfa06efce5663d8ee428587dddb) @@ -356,7 +356,7 @@ ViewInfo[] viewInfos = plugin.GetViewInfos().ToArray(); // Assert - Assert.AreEqual(16, viewInfos.Length); + Assert.AreEqual(17, viewInfos.Length); PluginTestHelper.AssertViewInfoDefined( viewInfos, @@ -450,6 +450,11 @@ typeof(StructuresOutputContext), typeof(IStructuresCalculation), typeof(GeneralResultFaultTreeIllustrationPointView)); + + PluginTestHelper.AssertViewInfoDefined( + viewInfos, + typeof(FailureMechanismSectionsContext), + typeof(FailureMechanismSectionsView)); } } Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/TreeNodeInfos/FailureMechanismSectionsContextTreeNodeInfoTest.cs =================================================================== diff -u -r3178e116f5e59e03078d465efeb303c5e232c7bf -ra39fb3074f6c4cfa06efce5663d8ee428587dddb --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/TreeNodeInfos/FailureMechanismSectionsContextTreeNodeInfoTest.cs (.../FailureMechanismSectionsContextTreeNodeInfoTest.cs) (revision 3178e116f5e59e03078d465efeb303c5e232c7bf) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/TreeNodeInfos/FailureMechanismSectionsContextTreeNodeInfoTest.cs (.../FailureMechanismSectionsContextTreeNodeInfoTest.cs) (revision a39fb3074f6c4cfa06efce5663d8ee428587dddb) @@ -76,6 +76,7 @@ Assert.IsNull(info.CanInsert); Assert.IsNull(info.OnDrop); } + mocks.VerifyAll(); } @@ -95,6 +96,7 @@ // Assert Assert.AreEqual("Vakindeling", text); } + mocks.VerifyAll(); } @@ -114,6 +116,7 @@ // Assert TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.SectionsIcon, image); } + mocks.VerifyAll(); } @@ -124,6 +127,8 @@ var menuBuilder = mocks.StrictMock(); using (mocks.Ordered()) { + menuBuilder.Expect(mb => mb.AddOpenItem()).Return(menuBuilder); + menuBuilder.Expect(mb => mb.AddSeparator()).Return(menuBuilder); menuBuilder.Expect(mb => mb.AddImportItem()).Return(menuBuilder); menuBuilder.Expect(mb => mb.Build()).Return(null); } @@ -150,6 +155,7 @@ info.ContextMenuStrip(context, null, treeViewControl); } } + // Assert mocks.VerifyAll(); } @@ -175,6 +181,7 @@ // Assert Assert.AreEqual(Color.FromKnownColor(KnownColor.GrayText), color); } + mocks.VerifyAll(); } @@ -206,6 +213,7 @@ // Assert Assert.AreEqual(Color.FromKnownColor(KnownColor.ControlText), color); } + mocks.VerifyAll(); } Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/ViewInfos/FailureMechanismSectionsViewInfoTest.cs =================================================================== diff -u --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/ViewInfos/FailureMechanismSectionsViewInfoTest.cs (revision 0) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/ViewInfos/FailureMechanismSectionsViewInfoTest.cs (revision a39fb3074f6c4cfa06efce5663d8ee428587dddb) @@ -0,0 +1,283 @@ +// Copyright (C) Stichting Deltares 2017. 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.Drawing; +using System.Linq; +using Core.Common.Gui.Plugin; +using Core.Common.TestUtil; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Forms.PresentationObjects; +using Ringtoets.Common.Forms.Views; +using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; + +namespace Ringtoets.Integration.Plugin.Test.ViewInfos +{ + [TestFixture] + public class FailureMechanismSectionsViewInfoTest + { + private MockRepository mocks; + private RingtoetsPlugin plugin; + private ViewInfo info; + + [SetUp] + public void SetUp() + { + mocks = new MockRepository(); + plugin = new RingtoetsPlugin(); + info = plugin.GetViewInfos().First(tni => tni.ViewType == typeof(FailureMechanismSectionsView)); + } + + [TearDown] + public void TearDown() + { + plugin.Dispose(); + } + + [Test] + public void Initialized_Always_ExpectedPropertiesSet() + { + // Assert + Assert.AreEqual(typeof(FailureMechanismSectionsContext), info.DataType); + } + + [Test] + public void GetViewName_Always_ReturnsViewName() + { + // Setup + var failureMechanism = new TestFailureMechanism(); + var assessmentSection = mocks.Stub(); + var failureMechanismSectionsContext = new FailureMechanismSectionsContext(failureMechanism, assessmentSection); + var view = mocks.StrictMock(); + + mocks.ReplayAll(); + + // Call + string viewName = info.GetViewName(view, failureMechanismSectionsContext); + + // Assert + Assert.AreEqual("Vakindeling", viewName); + mocks.VerifyAll(); + } + + [Test] + public void GetViewData_Always_ReturnsFailureMechanismSectionsContext() + { + // Setup + var failureMechanism = new TestFailureMechanism(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanismSectionsContext = new FailureMechanismSectionsContext(failureMechanism, assessmentSection); + + // Call + object viewData = info.GetViewData(failureMechanismSectionsContext); + + // Assert + Assert.AreSame(failureMechanismSectionsContext, viewData); + } + + [Test] + public void ViewType_Always_ReturnsViewType() + { + // Call + Type viewType = info.ViewType; + + // Assert + Assert.AreEqual(typeof(FailureMechanismSectionsView), viewType); + } + + [Test] + public void DataType_Always_ReturnsDataType() + { + // Call + Type dataType = info.DataType; + + // Assert + Assert.AreEqual(typeof(FailureMechanismSectionsContext), dataType); + } + + [Test] + public void ViewDataType_Always_ReturnViewDataType() + { + // Call + Type viewDataType = info.ViewDataType; + + // Assert + Assert.AreEqual(typeof(FailureMechanismSectionsContext), viewDataType); + } + + [Test] + public void Image_Always_ReturnsSectionsIcon() + { + // Call + Image image = info.Image; + + // Assert + TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.SectionsIcon, image); + } + + [Test] + public void CloseForData_ViewNotCorrespondingToRemovedAssessmentSection_ReturnsFalse() + { + // Setup + var assessmentSection = new ObservableTestAssessmentSectionStub(); + var failureMechanism = new TestFailureMechanism(); + var failureMechanismSectionsContext = new FailureMechanismSectionsContext(failureMechanism, assessmentSection); + + using (var view = new FailureMechanismSectionsView + { + Data = failureMechanismSectionsContext + }) + { + // Call + bool closeForData = info.CloseForData(view, assessmentSection); + + // Assert + Assert.IsFalse(closeForData); + } + } + + [Test] + public void CloseForData_ViewCorrespondingToRemovedAssessmentSection_ReturnsTrue() + { + // Setup + var assessmentSection = mocks.Stub(); + var failureMechanism = new TestFailureMechanism(); + assessmentSection.Stub(asm => asm.GetFailureMechanisms()).Return(new[] + { + failureMechanism + }); + var failureMechanismSectionsContext = new FailureMechanismSectionsContext(failureMechanism, assessmentSection); + + mocks.ReplayAll(); + + using (var view = new FailureMechanismSectionsView + { + Data = failureMechanismSectionsContext + }) + { + // Call + bool closeForData = info.CloseForData(view, assessmentSection); + + // Assert + Assert.IsTrue(closeForData); + } + + mocks.VerifyAll(); + } + + [Test] + public void CloseForData_ViewCorrespondingToRemovedFailureMechanism_ReturnsTrue() + { + // Setup + var failureMechanism = new TestFailureMechanism(); + var failureMechanismSectionsContext = new FailureMechanismSectionsContext(failureMechanism, + new ObservableTestAssessmentSectionStub()); + + using (var view = new FailureMechanismSectionsView + { + Data = failureMechanismSectionsContext + }) + { + // Call + bool closeForData = info.CloseForData(view, failureMechanism); + + // Assert + Assert.IsTrue(closeForData); + } + } + + [Test] + public void CloseForData_ViewNotCorrespondingToRemovedFailureMechanism_ReturnsFalse() + { + // Setup + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanismSectionsContext = new FailureMechanismSectionsContext(new TestFailureMechanism(), assessmentSection); + var failureMechanismSectionsContext2 = new FailureMechanismSectionsContext(new TestFailureMechanism(), assessmentSection); + + using (var view = new FailureMechanismSectionsView + { + Data = failureMechanismSectionsContext + }) + { + // Call + bool closeForData = info.CloseForData(view, failureMechanismSectionsContext2); + + // Assert + Assert.IsFalse(closeForData); + } + } + + [Test] + public void CloseForData_ViewNotCorrespondingToRemovedFailureMechanismContext_ReturnsFalse() + { + // Setup + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanismContext = new FailureMechanismContext(new TestFailureMechanism(), assessmentSection); + var failureMechanismSectionsContext = new FailureMechanismSectionsContext(new TestFailureMechanism(), assessmentSection); + + using (var view = new FailureMechanismSectionsView + { + Data = failureMechanismSectionsContext + }) + { + // Call + bool closeForData = info.CloseForData(view, failureMechanismContext); + + // Assert + Assert.IsFalse(closeForData); + } + } + + [Test] + public void CloseForData_ViewCorrespondingToRemovedFailureMechanismContext_ReturnsTrue() + { + // Setup + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new TestFailureMechanism(); + var failureMechanismContext = new FailureMechanismContext(failureMechanism, assessmentSection); + var failureMechanismSectionsContext = new FailureMechanismSectionsContext(failureMechanism, assessmentSection); + + using (var view = new FailureMechanismSectionsView + { + Data = failureMechanismSectionsContext + }) + { + // Call + bool closeForData = info.CloseForData(view, failureMechanismContext); + + // Assert + Assert.IsTrue(closeForData); + } + } + } +} \ No newline at end of file