Index: Riskeer/GrassCoverErosionInwards/test/Riskeer.GrassCoverErosionInwards.Integration.Test/GrassCoverErosionInwardsScenariosViewIntegrationTest.cs =================================================================== diff -u -r9b642748438acbabb3f67559e289ec49525aaf4b -r65e9bbe5a99736fdc6e6dae703186816f07fa910 --- Riskeer/GrassCoverErosionInwards/test/Riskeer.GrassCoverErosionInwards.Integration.Test/GrassCoverErosionInwardsScenariosViewIntegrationTest.cs (.../GrassCoverErosionInwardsScenariosViewIntegrationTest.cs) (revision 9b642748438acbabb3f67559e289ec49525aaf4b) +++ Riskeer/GrassCoverErosionInwards/test/Riskeer.GrassCoverErosionInwards.Integration.Test/GrassCoverErosionInwardsScenariosViewIntegrationTest.cs (.../GrassCoverErosionInwardsScenariosViewIntegrationTest.cs) (revision 65e9bbe5a99736fdc6e6dae703186816f07fa910) @@ -55,7 +55,7 @@ Path.Combine("DikeProfiles", "Voorlanden 6-3.shp")); [Test] - public void ScenariosView_ImportDikeSection_ChangesCorrectlyObservedAndSynced() + public void ScenariosView_ImportFailureMechanismSections_ChangesCorrectlyObservedAndSynced() { // Setup using (var form = new Form()) Index: Riskeer/HeightStructures/src/Riskeer.HeightStructures.Forms/Views/HeightStructuresScenarioRow.cs =================================================================== diff -u -r6b101883cf554150bd1454ba54784cf325a6e07c -r65e9bbe5a99736fdc6e6dae703186816f07fa910 --- Riskeer/HeightStructures/src/Riskeer.HeightStructures.Forms/Views/HeightStructuresScenarioRow.cs (.../HeightStructuresScenarioRow.cs) (revision 6b101883cf554150bd1454ba54784cf325a6e07c) +++ Riskeer/HeightStructures/src/Riskeer.HeightStructures.Forms/Views/HeightStructuresScenarioRow.cs (.../HeightStructuresScenarioRow.cs) (revision 65e9bbe5a99736fdc6e6dae703186816f07fa910) @@ -32,7 +32,7 @@ /// Container of a , /// which takes care of the representation of properties in a grid. /// - internal class HeightStructuresScenarioRow : ScenarioRow> + public class HeightStructuresScenarioRow : ScenarioRow> { private readonly HeightStructuresFailureMechanism failureMechanism; private readonly IAssessmentSection assessmentSection; Index: Riskeer/HeightStructures/src/Riskeer.HeightStructures.Forms/Views/HeightStructuresScenariosView.Designer.cs =================================================================== diff -u -r86594ccd7329d320872573a1d066fe18959d3cea -r65e9bbe5a99736fdc6e6dae703186816f07fa910 --- Riskeer/HeightStructures/src/Riskeer.HeightStructures.Forms/Views/HeightStructuresScenariosView.Designer.cs (.../HeightStructuresScenariosView.Designer.cs) (revision 86594ccd7329d320872573a1d066fe18959d3cea) +++ Riskeer/HeightStructures/src/Riskeer.HeightStructures.Forms/Views/HeightStructuresScenariosView.Designer.cs (.../HeightStructuresScenariosView.Designer.cs) (revision 65e9bbe5a99736fdc6e6dae703186816f07fa910) @@ -19,8 +19,6 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. -using Riskeer.Common.Forms; - namespace Riskeer.HeightStructures.Forms.Views { partial class HeightStructuresScenariosView @@ -38,33 +36,8 @@ /// private void InitializeComponent() { - this.scenarioSelectionControl = new Riskeer.Common.Forms.ScenarioSelectionControl(); - this.SuspendLayout(); - // - // scenarioSelectionControl - // - this.scenarioSelectionControl.AutoScroll = true; - this.scenarioSelectionControl.Dock = System.Windows.Forms.DockStyle.Fill; - this.scenarioSelectionControl.Location = new System.Drawing.Point(0, 0); - this.scenarioSelectionControl.Name = "scenarioSelectionControl"; - this.scenarioSelectionControl.Size = new System.Drawing.Size(160, 160); - this.scenarioSelectionControl.TabIndex = 0; - // - // HeightStructuresScenariosView - // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.AutoScroll = true; - this.Controls.Add(this.scenarioSelectionControl); - this.MinimumSize = new System.Drawing.Size(160, 160); - this.Name = "HeightStructuresScenariosView"; - this.Size = new System.Drawing.Size(160, 160); - this.ResumeLayout(false); - } #endregion - - private ScenarioSelectionControl scenarioSelectionControl; } } Index: Riskeer/HeightStructures/src/Riskeer.HeightStructures.Forms/Views/HeightStructuresScenariosView.cs =================================================================== diff -u -r6b101883cf554150bd1454ba54784cf325a6e07c -r65e9bbe5a99736fdc6e6dae703186816f07fa910 --- Riskeer/HeightStructures/src/Riskeer.HeightStructures.Forms/Views/HeightStructuresScenariosView.cs (.../HeightStructuresScenariosView.cs) (revision 6b101883cf554150bd1454ba54784cf325a6e07c) +++ Riskeer/HeightStructures/src/Riskeer.HeightStructures.Forms/Views/HeightStructuresScenariosView.cs (.../HeightStructuresScenariosView.cs) (revision 65e9bbe5a99736fdc6e6dae703186816f07fa910) @@ -22,12 +22,12 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Windows.Forms; -using Core.Common.Base; -using Core.Common.Controls.Views; +using Core.Common.Base.Geometry; +using Riskeer.Common.Data.AssessmentSection; using Riskeer.Common.Data.Calculation; +using Riskeer.Common.Data.FailureMechanism; using Riskeer.Common.Data.Structures; -using Riskeer.Common.Util; +using Riskeer.Common.Forms.Views; using Riskeer.HeightStructures.Data; namespace Riskeer.HeightStructures.Forms.Views @@ -37,105 +37,43 @@ /// Shows a grid view where for each failure mechanism section, a calculation within the section /// can be selected. /// - public partial class HeightStructuresScenariosView : UserControl, IView + public partial class HeightStructuresScenariosView : ScenariosView, HeightStructuresInput, HeightStructuresScenarioRow, HeightStructuresFailureMechanism> { - private readonly RecursiveObserver calculationInputObserver; - private readonly RecursiveObserver calculationGroupObserver; - private readonly Observer failureMechanismObserver; - private HeightStructuresFailureMechanism failureMechanism; - private CalculationGroup data; + private readonly IAssessmentSection assessmentSection; /// /// Creates a new instance of . /// - public HeightStructuresScenariosView() + /// The data to show in this view. + /// The + /// the belongs to. + /// The assessment section the scenarios belong to. + /// Thrown when any parameter + /// is null. + public HeightStructuresScenariosView(CalculationGroup calculationGroup, HeightStructuresFailureMechanism failureMechanism, IAssessmentSection assessmentSection) + : base(calculationGroup, failureMechanism) { - InitializeComponent(); - - failureMechanismObserver = new Observer(UpdateDataGridViewDataSource); - - // The concat is needed to observe the input of calculations in child groups. - calculationInputObserver = new RecursiveObserver( - UpdateDataGridViewDataSource, cg => cg.Children.Concat(cg.Children - .OfType>() - .Select(c => c.InputParameters))); - calculationGroupObserver = new RecursiveObserver(UpdateDataGridViewDataSource, c => c.Children); - } - - /// - /// Gets or sets the failure mechanism. - /// - public HeightStructuresFailureMechanism FailureMechanism - { - get + if (assessmentSection == null) { - return failureMechanism; + throw new ArgumentNullException(nameof(assessmentSection)); } - set - { - failureMechanism = value; - failureMechanismObserver.Observable = failureMechanism; - UpdateDataGridViewDataSource(); - } - } - public object Data - { - get - { - return data; - } - set - { - data = value as CalculationGroup; - - calculationInputObserver.Observable = data; - calculationGroupObserver.Observable = data; - UpdateDataGridViewDataSource(); - } + this.assessmentSection = assessmentSection; } - protected override void OnLoad(EventArgs e) + protected override HeightStructuresInput GetCalculationInput(StructuresCalculationScenario calculationScenario) { - // Necessary to correctly load the content of the dropdown lists of the comboboxes... - UpdateDataGridViewDataSource(); - base.OnLoad(e); + return calculationScenario.InputParameters; } - protected override void Dispose(bool disposing) + protected override IEnumerable GetScenarioRows(FailureMechanismSection failureMechanismSection) { - failureMechanismObserver?.Dispose(); - calculationInputObserver.Dispose(); - calculationGroupObserver.Dispose(); + IEnumerable lineSegments = Math2D.ConvertPointsToLineSegments(failureMechanismSection.Points); + IEnumerable> calculations = CalculationGroup.GetCalculations() + .OfType>() + .Where(cs => cs.IsStructureIntersectionWithReferenceLineInSection(lineSegments)); - if (disposing) - { - components?.Dispose(); - } - - base.Dispose(disposing); + return calculations.Select(c => new HeightStructuresScenarioRow(c, FailureMechanism, assessmentSection)).ToList(); } - - private void UpdateDataGridViewDataSource() - { - scenarioSelectionControl.EndEdit(); - - if (FailureMechanism?.SectionResults == null || data?.Children == null) - { - scenarioSelectionControl.ClearDataSource(); - } - else - { - ICalculation[] calculations = data.GetCalculations().ToArray(); - - IDictionary> calculationsPerSegment = - StructuresHelper.CollectCalculationsPerSection(failureMechanism.Sections, calculations.Cast>()); - - // List scenarioRows = - // FailureMechanism.SectionResults.Select(sectionResult => new HeightStructuresScenarioRow(sectionResult)).ToList(); - // - // scenarioSelectionControl.UpdateDataGridViewDataSource(calculations, scenarioRows, calculationsPerSegment); - } - } } } \ No newline at end of file Index: Riskeer/HeightStructures/src/Riskeer.HeightStructures.Plugin/HeightStructuresPlugin.cs =================================================================== diff -u -r33b37f9cbd7e2b5664fc666dab41ddd424ed3818 -r65e9bbe5a99736fdc6e6dae703186816f07fa910 --- Riskeer/HeightStructures/src/Riskeer.HeightStructures.Plugin/HeightStructuresPlugin.cs (.../HeightStructuresPlugin.cs) (revision 33b37f9cbd7e2b5664fc666dab41ddd424ed3818) +++ Riskeer/HeightStructures/src/Riskeer.HeightStructures.Plugin/HeightStructuresPlugin.cs (.../HeightStructuresPlugin.cs) (revision 65e9bbe5a99736fdc6e6dae703186816f07fa910) @@ -177,7 +177,7 @@ { GetViewData = context => context.WrappedData, GetViewName = (view, context) => RiskeerCommonFormsResources.Scenarios_DisplayName, - AfterCreate = (view, context) => view.FailureMechanism = context.ParentFailureMechanism, + CreateInstance = context => new HeightStructuresScenariosView(context.WrappedData, context.ParentFailureMechanism, context.AssessmentSection), CloseForData = CloseScenariosViewForData, Image = RiskeerCommonFormsResources.ScenariosIcon }; Index: Riskeer/HeightStructures/test/Riskeer.HeightStructures.Forms.Test/Views/HeightStructuresScenariosViewTest.cs =================================================================== diff -u -r86594ccd7329d320872573a1d066fe18959d3cea -r65e9bbe5a99736fdc6e6dae703186816f07fa910 --- Riskeer/HeightStructures/test/Riskeer.HeightStructures.Forms.Test/Views/HeightStructuresScenariosViewTest.cs (.../HeightStructuresScenariosViewTest.cs) (revision 86594ccd7329d320872573a1d066fe18959d3cea) +++ Riskeer/HeightStructures/test/Riskeer.HeightStructures.Forms.Test/Views/HeightStructuresScenariosViewTest.cs (.../HeightStructuresScenariosViewTest.cs) (revision 65e9bbe5a99736fdc6e6dae703186816f07fa910) @@ -19,20 +19,20 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. -using System.Collections.Generic; -using System.Drawing; -using System.Linq; +using System; using System.Windows.Forms; +using Core.Common.Base.Data; using Core.Common.Base.Geometry; -using Core.Common.Controls.DataGrid; -using Core.Common.Controls.Views; using NUnit.Extensions.Forms; using NUnit.Framework; +using Rhino.Mocks; +using Riskeer.Common.Data.AssessmentSection; using Riskeer.Common.Data.Calculation; using Riskeer.Common.Data.FailureMechanism; using Riskeer.Common.Data.Structures; using Riskeer.Common.Data.TestUtil; -using Riskeer.Common.Forms; +using Riskeer.Common.Forms.Helpers; +using Riskeer.Common.Forms.Views; using Riskeer.HeightStructures.Data; using Riskeer.HeightStructures.Data.TestUtil; using Riskeer.HeightStructures.Forms.Views; @@ -42,6 +42,11 @@ [TestFixture] public class HeightStructuresScenariosViewTest { + private const int isRelevantColumnIndex = 0; + private const int contributionColumnIndex = 1; + private const int nameColumnIndex = 2; + private const int failureProbabilityColumnIndex = 3; + private Form testForm; [SetUp] @@ -57,347 +62,129 @@ } [Test] - public void DefaultConstructor_DataGridViewCorrectlyInitialized() + public void Constructor_AssessmentSectionNull_ThrowsArgumentNullException() { // Call - using (HeightStructuresScenariosView view = ShowScenariosView()) - { - // Assert - Assert.IsInstanceOf(view); - Assert.IsInstanceOf(view); - Assert.IsTrue(view.AutoScroll); - Assert.IsNull(view.Data); - Assert.IsNull(view.FailureMechanism); + void Call() => new HeightStructuresScenariosView(new CalculationGroup(), new HeightStructuresFailureMechanism(), null); - var scenarioSelectionControl = new ControlTester("scenarioSelectionControl").TheObject as ScenarioSelectionControl; - - Assert.NotNull(scenarioSelectionControl); - Assert.AreEqual(new Size(0, 0), scenarioSelectionControl.MinimumSize); - } + // Assert + var exception = Assert.Throws(Call); + Assert.AreEqual("assessmentSection", exception.ParamName); } [Test] - public void Data_ValidDataSet_ValidData() + public void Constructor_ExpectedValues() { // Setup - using (HeightStructuresScenariosView view = ShowScenariosView()) - { - var calculationGroup = new CalculationGroup(); + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); - // Call - view.Data = calculationGroup; + var calculationGroup = new CalculationGroup(); + // Call + using (var view = new HeightStructuresScenariosView(calculationGroup, new HeightStructuresFailureMechanism(), assessmentSection)) + { // Assert + Assert.IsInstanceOf, HeightStructuresInput, HeightStructuresScenarioRow, HeightStructuresFailureMechanism>>(view); Assert.AreSame(calculationGroup, view.Data); } - } - [Test] - public void FailureMechanism_ValidFailureMechanismSet_ValidFailureMechanism() - { - // Setup - using (HeightStructuresScenariosView view = ShowScenariosView()) - { - var failureMechanism = new HeightStructuresFailureMechanism(); - - // Call - view.FailureMechanism = failureMechanism; - - // Assert - Assert.AreSame(failureMechanism, view.FailureMechanism); - } + mocks.VerifyAll(); } [Test] - public void Data_WithFailureMechanism_UpdateScenarioControl() + public void Constructor_DataGridViewCorrectlyInitialized() { - // Setup - using (HeightStructuresScenariosView view = ShowScenariosView()) - { - HeightStructuresFailureMechanism failureMechanism = CreateCompleteFailureMechanism(); - view.FailureMechanism = failureMechanism; + // Call + ShowHeightStructuresScenariosView(new HeightStructuresFailureMechanism()); - // Call - view.Data = failureMechanism.CalculationsGroup; - - // Assert - AssertDataGridView(failureMechanism, false, new[] - { - new[] - { - "", - "CalculationA" - }, - new[] - { - "", - "CalculationB" - } - }); - } + // Assert + var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; + Assert.AreEqual(4, dataGridView.ColumnCount); + Assert.AreEqual("In oordeel", dataGridView.Columns[isRelevantColumnIndex].HeaderText); + Assert.AreEqual("Bijdrage aan\r\nscenario\r\n[%]", dataGridView.Columns[contributionColumnIndex].HeaderText); + Assert.AreEqual("Naam", dataGridView.Columns[nameColumnIndex].HeaderText); + Assert.AreEqual("Faalkans\r\n[1/jaar]", dataGridView.Columns[failureProbabilityColumnIndex].HeaderText); } [Test] - public void Data_SetToNullAfterGridViewShowsData_ClearsScenarioControl() + public void HeightStructuresScenarioView_CalculationsWithAllDataSet_DataGridViewCorrectlyInitialized() { - // Setup - using (HeightStructuresScenariosView view = ShowScenariosView()) - { - HeightStructuresFailureMechanism failureMechanism = CreateCompleteFailureMechanism(); - view.FailureMechanism = failureMechanism; - view.Data = failureMechanism.CalculationsGroup; + // Call + ShowFullyConfiguredHeightStructuresScenariosView(); - // Call - view.Data = null; + var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; - // Assert - AssertDataGridView(failureMechanism, true); - } - } + // Assert + DataGridViewRowCollection rows = dataGridView.Rows; + Assert.AreEqual(2, rows.Count); - [Test] - public void FailureMechanism_FailureMechanismSetToNull_UpdateScenarioControl() - { - // Setup - using (HeightStructuresScenariosView view = ShowScenariosView()) - { - HeightStructuresFailureMechanism failureMechanism = CreateCompleteFailureMechanism(); - view.Data = failureMechanism.CalculationsGroup; + DataGridViewCellCollection cells = rows[0].Cells; + Assert.AreEqual(4, cells.Count); + Assert.IsTrue(Convert.ToBoolean(cells[isRelevantColumnIndex].FormattedValue)); + Assert.AreEqual(new RoundedDouble(2, 100).ToString(), cells[contributionColumnIndex].FormattedValue); + Assert.AreEqual("Calculation 1", cells[nameColumnIndex].FormattedValue); + Assert.AreEqual("-", cells[failureProbabilityColumnIndex].FormattedValue); - // Call - view.FailureMechanism = failureMechanism; - - // Assert - AssertDataGridView(failureMechanism, false, new[] - { - new[] - { - "", - "CalculationA" - }, - new[] - { - "", - "CalculationB" - } - }); - } + cells = rows[1].Cells; + Assert.AreEqual(4, cells.Count); + Assert.IsTrue(Convert.ToBoolean(cells[isRelevantColumnIndex].FormattedValue)); + Assert.AreEqual(new RoundedDouble(2, 100).ToString(), cells[contributionColumnIndex].FormattedValue); + Assert.AreEqual("Calculation 2", cells[nameColumnIndex].FormattedValue); + Assert.AreEqual(ProbabilityFormattingHelper.Format(0.5), cells[failureProbabilityColumnIndex].FormattedValue); } - [Test] - public void FailureMechanism_WithoutData_ClearsScenarioControl() + private void ShowFullyConfiguredHeightStructuresScenariosView() { - // Setup - using (HeightStructuresScenariosView view = ShowScenariosView()) - { - HeightStructuresFailureMechanism failureMechanism = CreateCompleteFailureMechanism(); - view.Data = failureMechanism.CalculationsGroup; - view.FailureMechanism = failureMechanism; + var structure1 = new TestHeightStructure(new Point2D(0.0, 0.0)); + var structure2 = new TestHeightStructure(new Point2D(5.0, 0.0)); - // Call - view.FailureMechanism = null; + var failureMechanism = new HeightStructuresFailureMechanism(); - // Assert - AssertDataGridView(failureMechanism, true); - } - } - - [Test] - public void NotifyFailureMechanism_SectionsUpdatedAfterFullInitialization_NewRowAddedToView() - { - // Setup - using (HeightStructuresScenariosView view = ShowScenariosView()) + FailureMechanismTestHelper.SetSections(failureMechanism, new[] { - HeightStructuresFailureMechanism failureMechanism = CreateCompleteFailureMechanism(); - view.Data = failureMechanism.CalculationsGroup; - view.FailureMechanism = failureMechanism; - - List newSections = view.FailureMechanism.Sections.ToList(); - newSections.Add(new FailureMechanismSection("SectionC", new[] + new FailureMechanismSection("Section 1", new[] { - view.FailureMechanism.Sections.Last().EndPoint, - new Point2D(30, 30) - })); - - // Call - failureMechanism.NotifyObservers(); - - // Assert - AssertDataGridView(failureMechanism, false, new[] + new Point2D(0.0, 0.0), + new Point2D(5.0, 0.0) + }), + new FailureMechanismSection("Section 2", new[] { - new[] - { - "", - "CalculationA" - }, - new[] - { - "", - "CalculationB" - }, - new[] - { - "" - } - }); - } - } + new Point2D(5.0, 0.0), + new Point2D(10.0, 0.0) + }) + }); - [Test] - public void NotifyCalculation_CalculationChangedStructure_CalculationMovedToOtherSectionResultOptions() - { - // Setup - using (HeightStructuresScenariosView view = ShowScenariosView()) + failureMechanism.CalculationsGroup.Children.AddRange(new[] { - HeightStructuresFailureMechanism failureMechanism = CreateCompleteFailureMechanism(); - view.Data = failureMechanism.CalculationsGroup; - view.FailureMechanism = failureMechanism; - - var calculationA = (StructuresCalculation) failureMechanism.CalculationsGroup.Children[0]; - var calculationB = (StructuresCalculation) failureMechanism.CalculationsGroup.Children[1]; - - calculationA.InputParameters.Structure = calculationB.InputParameters.Structure; - - // Call - calculationA.NotifyObservers(); - - // Assert - AssertDataGridView(failureMechanism, false, new[] + new StructuresCalculationScenario { - new[] + Name = "Calculation 1", + InputParameters = { - "" - }, - new[] - { - "", - "CalculationA", - "CalculationB" + Structure = structure1 } - }); - } - } - - [Test] - public void NotifyCalculationGroup_CalculationAdded_CalculationAddedToSectionResultOptions() - { - // Setup - using (HeightStructuresScenariosView view = ShowScenariosView()) - { - HeightStructuresFailureMechanism failureMechanism = CreateCompleteFailureMechanism(); - view.Data = failureMechanism.CalculationsGroup; - view.FailureMechanism = failureMechanism; - - var calculationB = (StructuresCalculation) failureMechanism.CalculationsGroup.Children[1]; - var calculationC = new StructuresCalculation + }, + new StructuresCalculationScenario { - Name = "CalculationC" - }; - failureMechanism.CalculationsGroup.Children.Add(calculationC); - - calculationC.InputParameters.Structure = calculationB.InputParameters.Structure; - - // Call - failureMechanism.CalculationsGroup.NotifyObservers(); - - // Assert - AssertDataGridView(failureMechanism, false, new[] - { - new[] + Name = "Calculation 2", + InputParameters = { - "", - "CalculationA" + Structure = structure2 }, - new[] - { - "", - "CalculationB", - "CalculationC" - } - }); - } - } - - private static void AssertDataGridView( - HeightStructuresFailureMechanism failureMechanism, - bool shouldBeCleared, - string[][] expectedComboBoxItemTexts = null) - { - var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; - int rowCount = dataGridView.RowCount; - - if (shouldBeCleared) - { - Assert.AreEqual(0, rowCount); - } - else - { - Assert.NotNull(expectedComboBoxItemTexts); - var dataGridViewColumn = (DataGridViewComboBoxColumn) dataGridView.Columns[1]; - - Assert.AreEqual(failureMechanism.SectionResults.Count(), rowCount); - Assert.AreEqual(failureMechanism.Calculations.Count(), dataGridViewColumn.Items.Count); - - for (var i = 0; i < rowCount; i++) - { - var cell = (DataGridViewComboBoxCell) dataGridView[1, i]; - IEnumerable> items = cell.Items.OfType>(); - Assert.AreEqual(expectedComboBoxItemTexts[i], items.Select(r => r.DisplayName)); + Output = new TestStructuresOutput(0.2) } - } - } - - private HeightStructuresFailureMechanism CreateCompleteFailureMechanism() - { - var failureMechanism = new HeightStructuresFailureMechanism(); - var matchingPointA = new Point2D(0, 0); - var matchingPointB = new Point2D(20, 20); - var calculationA = new StructuresCalculation - { - Name = "CalculationA", - InputParameters = - { - Structure = new TestHeightStructure(matchingPointA) - } - }; - var calculationB = new StructuresCalculation - { - Name = "CalculationB", - InputParameters = - { - Structure = new TestHeightStructure(matchingPointB) - } - }; - var connectionPoint = new Point2D(10, 10); - var failureMechanismSectionA = new FailureMechanismSection("sectionA", new[] - { - matchingPointA, - connectionPoint }); - var failureMechanismSectionB = new FailureMechanismSection("sectionB", new[] - { - connectionPoint, - matchingPointB - }); - failureMechanism.CalculationsGroup.Children.Add(calculationA); - failureMechanism.CalculationsGroup.Children.Add(calculationB); - FailureMechanismTestHelper.SetSections(failureMechanism, new[] - { - failureMechanismSectionA, - failureMechanismSectionB - }); - - return failureMechanism; + ShowHeightStructuresScenariosView(failureMechanism); } - private HeightStructuresScenariosView ShowScenariosView() + private void ShowHeightStructuresScenariosView(HeightStructuresFailureMechanism failureMechanism) { - var scenariosView = new HeightStructuresScenariosView(); + var scenariosView = new HeightStructuresScenariosView(failureMechanism.CalculationsGroup, failureMechanism, new AssessmentSectionStub()); testForm.Controls.Add(scenariosView); testForm.Show(); - - return scenariosView; } } } \ No newline at end of file Index: Riskeer/HeightStructures/test/Riskeer.HeightStructures.Integration.Test/HeightStructuresScenariosViewIntegrationTest.cs =================================================================== diff -u -re7f074df2c06a1c0b7d628f75dd87f0552d11e08 -r65e9bbe5a99736fdc6e6dae703186816f07fa910 --- Riskeer/HeightStructures/test/Riskeer.HeightStructures.Integration.Test/HeightStructuresScenariosViewIntegrationTest.cs (.../HeightStructuresScenariosViewIntegrationTest.cs) (revision e7f074df2c06a1c0b7d628f75dd87f0552d11e08) +++ Riskeer/HeightStructures/test/Riskeer.HeightStructures.Integration.Test/HeightStructuresScenariosViewIntegrationTest.cs (.../HeightStructuresScenariosViewIntegrationTest.cs) (revision 65e9bbe5a99736fdc6e6dae703186816f07fa910) @@ -19,10 +19,11 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. -using System.Collections.Generic; +using System; using System.IO; using System.Linq; using System.Windows.Forms; +using Core.Common.Base.Data; using Core.Common.TestUtil; using NUnit.Extensions.Forms; using NUnit.Framework; @@ -45,6 +46,11 @@ [TestFixture] public class HeightStructuresScenariosViewIntegrationTest { + private const int isRelevantColumnIndex = 0; + private const int contributionColumnIndex = 1; + private const int nameColumnIndex = 2; + private const int failureProbabilityColumnIndex = 3; + private readonly string filePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.HeightStructures.Integration, Path.Combine("HeightStructures", "kunstwerken_6_3.shp")); @@ -57,35 +63,22 @@ var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); DataImportHelper.ImportReferenceLine(assessmentSection); - var view = new HeightStructuresScenariosView - { - Data = assessmentSection.HeightStructures.CalculationsGroup, - FailureMechanism = assessmentSection.HeightStructures - }; + var view = new HeightStructuresScenariosView(assessmentSection.HeightStructures.CalculationsGroup, assessmentSection.HeightStructures, assessmentSection); form.Controls.Add(view); form.Show(); - var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; + var listBox = (ListBox) new ControlTester("listBox").TheObject; // Precondition - Assert.AreEqual(0, dataGridView.RowCount); + CollectionAssert.IsEmpty(listBox.Items); // Call IFailureMechanism failureMechanism = assessmentSection.HeightStructures; DataImportHelper.ImportFailureMechanismSections(assessmentSection, failureMechanism); assessmentSection.HeightStructures.NotifyObservers(); // Assert - Assert.AreEqual(283, dataGridView.RowCount); - - IEnumerable expectedValues = assessmentSection.HeightStructures.SectionResults.Select(sr => sr.Section.Name); - var foundValues = new List(); - foreach (DataGridViewRow row in dataGridView.Rows) - { - foundValues.Add(row.Cells[0].FormattedValue.ToString()); - } - - CollectionAssert.AreEqual(expectedValues, foundValues); + CollectionAssert.AreEqual(assessmentSection.HeightStructures.Sections, listBox.Items); } } @@ -103,26 +96,31 @@ DataImportHelper.ImportReferenceLine(assessmentSection); HeightStructuresFailureMechanism failureMechanism = assessmentSection.HeightStructures; DataImportHelper.ImportFailureMechanismSections(assessmentSection, failureMechanism); - new HeightStructuresImporter(assessmentSection.HeightStructures.HeightStructures, - assessmentSection.ReferenceLine, - filePath, messageProvider, new HeightStructureReplaceDataStrategy(failureMechanism)) - .Import(); CalculationGroup calculationsGroup = assessmentSection.HeightStructures.CalculationsGroup; - var view = new HeightStructuresScenariosView - { - Data = calculationsGroup, - FailureMechanism = assessmentSection.HeightStructures - }; + var view = new HeightStructuresScenariosView(calculationsGroup, assessmentSection.HeightStructures, assessmentSection); + form.Controls.Add(view); form.Show(); + var structuresImporter = new HeightStructuresImporter(assessmentSection.HeightStructures.HeightStructures, + assessmentSection.ReferenceLine, + filePath, messageProvider, new HeightStructureReplaceDataStrategy(failureMechanism)); + structuresImporter.Import(); + + var listBox = (ListBox) new ControlTester("listBox").TheObject; var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; + listBox.SelectedItem = failureMechanism.Sections.ElementAt(13); + + // Precondition + DataGridViewRowCollection rows = dataGridView.Rows; + CollectionAssert.IsEmpty(rows); + // Call foreach (HeightStructure structure in assessmentSection.HeightStructures.HeightStructures) { - calculationsGroup.Children.Add(new StructuresCalculation + calculationsGroup.Children.Add(new StructuresCalculationScenario { Name = NamingHelper.GetUniqueName(((CalculationGroup) view.Data).Children, structure.Name, c => c.Name), InputParameters = @@ -135,10 +133,14 @@ calculationsGroup.NotifyObservers(); // Assert - DataGridViewCell dataGridViewCell = dataGridView.Rows[13].Cells[1]; - Assert.AreEqual(2, ((DataGridViewComboBoxCell) dataGridViewCell).Items.Count); - Assert.AreEqual("", ((DataGridViewComboBoxCell) dataGridViewCell).Items[0].ToString()); - Assert.AreEqual("Eerste kunstwerk 6-3", ((DataGridViewComboBoxCell) dataGridViewCell).Items[1].ToString()); + Assert.AreEqual(1, rows.Count); + + DataGridViewCellCollection cells = rows[0].Cells; + Assert.AreEqual(4, cells.Count); + Assert.IsTrue(Convert.ToBoolean(cells[isRelevantColumnIndex].FormattedValue)); + Assert.AreEqual(new RoundedDouble(2, 100).ToString(), cells[contributionColumnIndex].FormattedValue); + Assert.AreEqual("Eerste kunstwerk 6-3", cells[nameColumnIndex].FormattedValue); + Assert.AreEqual("-", cells[failureProbabilityColumnIndex].FormattedValue); } mocks.VerifyAll(); @@ -158,25 +160,21 @@ DataImportHelper.ImportReferenceLine(assessmentSection); HeightStructuresFailureMechanism failureMechanism = assessmentSection.HeightStructures; DataImportHelper.ImportFailureMechanismSections(assessmentSection, failureMechanism); - new HeightStructuresImporter(assessmentSection.HeightStructures.HeightStructures, - assessmentSection.ReferenceLine, - filePath, messageProvider, new HeightStructureReplaceDataStrategy(failureMechanism)) - .Import(); CalculationGroup calculationsGroup = assessmentSection.HeightStructures.CalculationsGroup; - var view = new HeightStructuresScenariosView - { - Data = calculationsGroup, - FailureMechanism = assessmentSection.HeightStructures - }; + var view = new HeightStructuresScenariosView(calculationsGroup, assessmentSection.HeightStructures, assessmentSection); + form.Controls.Add(view); form.Show(); - var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; + var structuresImporter = new HeightStructuresImporter(assessmentSection.HeightStructures.HeightStructures, + assessmentSection.ReferenceLine, + filePath, messageProvider, new HeightStructureReplaceDataStrategy(failureMechanism)); + structuresImporter.Import(); foreach (HeightStructure structure in assessmentSection.HeightStructures.HeightStructures) { - calculationsGroup.Children.Add(new StructuresCalculation + calculationsGroup.Children.Add(new StructuresCalculationScenario { Name = NamingHelper.GetUniqueName(calculationsGroup.Children, structure.Name, c => c.Name), InputParameters = @@ -188,18 +186,26 @@ calculationsGroup.NotifyObservers(); + var listBox = (ListBox) new ControlTester("listBox").TheObject; + var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; + + listBox.SelectedItem = failureMechanism.Sections.ElementAt(13); + + // Precondition + DataGridViewRowCollection rows = dataGridView.Rows; + Assert.AreEqual(1, rows.Count); + + DataGridViewCellCollection cells = rows[0].Cells; + Assert.AreEqual("Eerste kunstwerk 6-3", cells[nameColumnIndex].FormattedValue); + // Call - foreach (ICalculationBase calculationBase in calculationsGroup.Children) + foreach (StructuresCalculationScenario calculation in calculationsGroup.Children.Cast>()) { - var calculation = (StructuresCalculation) calculationBase; calculation.Name += "_changed"; } // Assert - DataGridViewCell dataGridViewCell = dataGridView.Rows[13].Cells[1]; - Assert.AreEqual(2, ((DataGridViewComboBoxCell) dataGridViewCell).Items.Count); - Assert.AreEqual("", ((DataGridViewComboBoxCell) dataGridViewCell).Items[0].ToString()); - Assert.AreEqual("Eerste kunstwerk 6-3_changed", ((DataGridViewComboBoxCell) dataGridViewCell).Items[1].ToString()); + Assert.AreEqual("Eerste kunstwerk 6-3_changed", cells[nameColumnIndex].FormattedValue); } mocks.VerifyAll(); @@ -219,24 +225,19 @@ DataImportHelper.ImportReferenceLine(assessmentSection); HeightStructuresFailureMechanism failureMechanism = assessmentSection.HeightStructures; DataImportHelper.ImportFailureMechanismSections(assessmentSection, failureMechanism); - new HeightStructuresImporter(assessmentSection.HeightStructures.HeightStructures, - assessmentSection.ReferenceLine, - filePath, messageProvider, new HeightStructureReplaceDataStrategy(failureMechanism)) - .Import(); - var view = new HeightStructuresScenariosView - { - Data = assessmentSection.HeightStructures.CalculationsGroup, - FailureMechanism = assessmentSection.HeightStructures - }; + var view = new HeightStructuresScenariosView(assessmentSection.HeightStructures.CalculationsGroup, assessmentSection.HeightStructures, assessmentSection); form.Controls.Add(view); form.Show(); - var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; + var structuresImporter = new HeightStructuresImporter(assessmentSection.HeightStructures.HeightStructures, + assessmentSection.ReferenceLine, + filePath, messageProvider, new HeightStructureReplaceDataStrategy(failureMechanism)); + structuresImporter.Import(); foreach (HeightStructure structure in assessmentSection.HeightStructures.HeightStructures) { - assessmentSection.HeightStructures.CalculationsGroup.Children.Add(new StructuresCalculation + assessmentSection.HeightStructures.CalculationsGroup.Children.Add(new StructuresCalculationScenario { Name = NamingHelper.GetUniqueName(assessmentSection.HeightStructures.CalculationsGroup.Children, structure.Name + "Calculation", c => c.Name), InputParameters = @@ -246,22 +247,26 @@ }); } + var listBox = (ListBox) new ControlTester("listBox").TheObject; + var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; + + listBox.SelectedItem = failureMechanism.Sections.ElementAt(13); + + // Precondition + DataGridViewRowCollection rows = dataGridView.Rows; + Assert.AreEqual(1, rows.Count); + Assert.AreEqual("Eerste kunstwerk 6-3Calculation", rows[0].Cells[nameColumnIndex].FormattedValue); + // Call CalculationGroup calculationsGroup = assessmentSection.HeightStructures.CalculationsGroup; ((StructuresCalculation) calculationsGroup.Children[1]).InputParameters.Structure = ((StructuresCalculation) calculationsGroup.Children[0]).InputParameters.Structure; calculationsGroup.NotifyObservers(); // Assert - DataGridViewCell dataGridViewCell = dataGridView.Rows[13].Cells[1]; - Assert.AreEqual(3, ((DataGridViewComboBoxCell) dataGridViewCell).Items.Count); - Assert.AreEqual("", ((DataGridViewComboBoxCell) dataGridViewCell).Items[0].ToString()); - Assert.AreEqual("Eerste kunstwerk 6-3Calculation", ((DataGridViewComboBoxCell) dataGridViewCell).Items[1].ToString()); - Assert.AreEqual("Tweede kunstwerk 6-3Calculation", ((DataGridViewComboBoxCell) dataGridViewCell).Items[2].ToString()); - - DataGridViewCell dataGridViewCellWithRemovedCalculation = dataGridView.Rows[56].Cells[1]; - Assert.AreEqual(1, ((DataGridViewComboBoxCell) dataGridViewCellWithRemovedCalculation).Items.Count); - Assert.AreEqual("", ((DataGridViewComboBoxCell) dataGridViewCellWithRemovedCalculation).Items[0].ToString()); + Assert.AreEqual(2, rows.Count); + Assert.AreEqual("Eerste kunstwerk 6-3Calculation", rows[0].Cells[nameColumnIndex].FormattedValue); + Assert.AreEqual("Tweede kunstwerk 6-3Calculation", rows[1].Cells[nameColumnIndex].FormattedValue); } mocks.VerifyAll(); Index: Riskeer/HeightStructures/test/Riskeer.HeightStructures.Plugin.Test/ViewInfos/HeightStructuresScenariosViewInfoTest.cs =================================================================== diff -u -r33b37f9cbd7e2b5664fc666dab41ddd424ed3818 -r65e9bbe5a99736fdc6e6dae703186816f07fa910 --- Riskeer/HeightStructures/test/Riskeer.HeightStructures.Plugin.Test/ViewInfos/HeightStructuresScenariosViewInfoTest.cs (.../HeightStructuresScenariosViewInfoTest.cs) (revision 33b37f9cbd7e2b5664fc666dab41ddd424ed3818) +++ Riskeer/HeightStructures/test/Riskeer.HeightStructures.Plugin.Test/ViewInfos/HeightStructuresScenariosViewInfoTest.cs (.../HeightStructuresScenariosViewInfoTest.cs) (revision 65e9bbe5a99736fdc6e6dae703186816f07fa910) @@ -21,6 +21,7 @@ using System.Drawing; using System.Linq; +using Core.Common.Controls.Views; using Core.Common.Gui.Plugin; using Core.Common.TestUtil; using NUnit.Framework; @@ -104,45 +105,21 @@ } [Test] - public void CloseForData_AssessmentSectionRemovedWithoutFailureMechanism_ReturnFalse() - { - // Setup - using (var view = new HeightStructuresScenariosView - { - Data = new CalculationGroup() - }) - { - var assessmentSection = mocks.Stub(); - assessmentSection.Stub(section => section.GetFailureMechanisms()).Return(new IFailureMechanism[0]); - mocks.ReplayAll(); - - // Call - bool closeForData = info.CloseForData(view, assessmentSection); - - // Assert - Assert.IsFalse(closeForData); - mocks.VerifyAll(); - } - } - - [Test] public void CloseForData_ViewNotCorrespondingToRemovedAssessmentSection_ReturnFalse() { // Setup - using (var view = new HeightStructuresScenariosView + var unrelatedFailureMechanism = new HeightStructuresFailureMechanism(); + + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + assessmentSection.Stub(asm => asm.GetFailureMechanisms()).Return(new[] { - Data = new CalculationGroup() - }) - { - var unrelatedFailureMechanism = new HeightStructuresFailureMechanism(); + unrelatedFailureMechanism + }); + mocks.ReplayAll(); - var assessmentSection = mocks.Stub(); - assessmentSection.Stub(asm => asm.GetFailureMechanisms()).Return(new[] - { - unrelatedFailureMechanism - }); - mocks.ReplayAll(); - + using (var view = new HeightStructuresScenariosView(new CalculationGroup(), new HeightStructuresFailureMechanism(), assessmentSection)) + { // Precondition Assert.AreNotSame(view.Data, unrelatedFailureMechanism.CalculationsGroup); @@ -151,8 +128,9 @@ // Assert Assert.IsFalse(closeForData); - mocks.VerifyAll(); } + + mocks.VerifyAll(); } [Test] @@ -161,18 +139,16 @@ // Setup var relatedFailureMechanism = new HeightStructuresFailureMechanism(); - using (var view = new HeightStructuresScenariosView + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + assessmentSection.Stub(asm => asm.GetFailureMechanisms()).Return(new[] { - Data = relatedFailureMechanism.CalculationsGroup - }) - { - var assessmentSection = mocks.Stub(); - assessmentSection.Stub(asm => asm.GetFailureMechanisms()).Return(new[] - { - relatedFailureMechanism - }); - mocks.ReplayAll(); + relatedFailureMechanism + }); + mocks.ReplayAll(); + using (var view = new HeightStructuresScenariosView(relatedFailureMechanism.CalculationsGroup, relatedFailureMechanism, assessmentSection)) + { // Precondition Assert.AreSame(view.Data, relatedFailureMechanism.CalculationsGroup); @@ -181,209 +157,136 @@ // Assert Assert.IsTrue(closeForData); - mocks.VerifyAll(); } + + mocks.VerifyAll(); } [Test] public void CloseForData_ViewNotCorrespondingToRemovedFailureMechanism_ReturnFalse() { // Setup - using (var view = new HeightStructuresScenariosView + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + using (var view = new HeightStructuresScenariosView(new CalculationGroup(), new HeightStructuresFailureMechanism(), assessmentSection)) { - Data = new CalculationGroup() - }) - { // Call bool closeForData = info.CloseForData(view, new HeightStructuresFailureMechanism()); // Assert Assert.IsFalse(closeForData); } + + mocks.VerifyAll(); } [Test] public void CloseForData_ViewCorrespondingToRemovedFailureMechanism_ReturnTrue() { // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + var correspondingFailureMechanism = new HeightStructuresFailureMechanism(); - using (var view = new HeightStructuresScenariosView + using (var view = new HeightStructuresScenariosView(correspondingFailureMechanism.CalculationsGroup, correspondingFailureMechanism, assessmentSection)) { - Data = correspondingFailureMechanism.CalculationsGroup - }) - { // Call bool closeForData = info.CloseForData(view, correspondingFailureMechanism); // Assert Assert.IsTrue(closeForData); } - } - [Test] - public void CloseForData_AssessmentSectionRemovedWithoutHeightStructuresFailureMechanism_ReturnsFalse() - { - // Setup - var assessmentSection = mocks.Stub(); - assessmentSection.Stub(asm => asm.GetFailureMechanisms()).Return(new IFailureMechanism[0]); - mocks.ReplayAll(); - - var view = new HeightStructuresScenariosView - { - Data = new CalculationGroup() - }; - - // Call - bool closeForData = info.CloseForData(view, assessmentSection); - - // Assert - Assert.IsFalse(closeForData); mocks.VerifyAll(); } [Test] - public void CloseForData_ViewNotCorrespondingToRemovedAssessmentSection_ReturnsFalse() + public void CloseForData_AssessmentSectionRemovedWithoutHeightStructuresFailureMechanism_ReturnFalse() { // Setup + var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); - assessmentSection.Stub(asm => asm.GetFailureMechanisms()).Return(new[] - { - new HeightStructuresFailureMechanism() - }); - + assessmentSection.Stub(asm => asm.GetFailureMechanisms()).Return(new IFailureMechanism[0]); mocks.ReplayAll(); - var view = new HeightStructuresScenariosView + using (var view = new HeightStructuresScenariosView(new CalculationGroup(), new HeightStructuresFailureMechanism(), assessmentSection)) { - Data = new CalculationGroup() - }; + // Call + bool closeForData = info.CloseForData(view, assessmentSection); - // Call - bool closeForData = info.CloseForData(view, assessmentSection); + // Assert + Assert.IsFalse(closeForData); + } - // Assert - Assert.IsFalse(closeForData); mocks.VerifyAll(); } [Test] - public void CloseForData_ViewCorrespondingToRemovedAssessmentSection_ReturnsTrue() + public void CloseForData_ViewNotCorrespondingToRemovedFailureMechanismContext_ReturnFalse() { // Setup + var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); - var failureMechanism = new HeightStructuresFailureMechanism(); - assessmentSection.Stub(asm => asm.GetFailureMechanisms()).Return(new[] - { - failureMechanism - }); - mocks.ReplayAll(); - var view = new HeightStructuresScenariosView - { - Data = failureMechanism.CalculationsGroup - }; - - // Call - bool closeForData = info.CloseForData(view, assessmentSection); - - // Assert - Assert.IsTrue(closeForData); - mocks.VerifyAll(); - } - - [Test] - public void CloseForData_ViewNotCorrespondingToRemovedFailureMechanism_ReturnsFalse() - { - // Setup - var view = new HeightStructuresScenariosView(); var failureMechanism = new HeightStructuresFailureMechanism(); - - view.Data = new CalculationGroup(); - - // Call - bool closeForData = info.CloseForData(view, failureMechanism); - - // Assert - Assert.IsFalse(closeForData); - } - - [Test] - public void CloseForData_ViewCorrespondingToRemovedFailureMechanism_ReturnsTrue() - { - // Setup - var view = new HeightStructuresScenariosView(); - var failureMechanism = new HeightStructuresFailureMechanism(); - - view.Data = failureMechanism.CalculationsGroup; - - // Call - bool closeForData = info.CloseForData(view, failureMechanism); - - // Assert - Assert.IsTrue(closeForData); - } - - [Test] - public void CloseForData_ViewNotCorrespondingToRemovedFailureMechanismContext_ReturnsFalse() - { - // Setup - var assessmentSection = mocks.Stub(); - mocks.ReplayAll(); - - var view = new HeightStructuresScenariosView(); - var failureMechanism = new HeightStructuresFailureMechanism(); var failureMechanismContext = new HeightStructuresFailureMechanismContext(new HeightStructuresFailureMechanism(), assessmentSection); - view.Data = failureMechanism.CalculationsGroup; + using (var view = new HeightStructuresScenariosView(failureMechanism.CalculationsGroup, failureMechanism, assessmentSection)) + { + // Call + bool closeForData = info.CloseForData(view, failureMechanismContext); - // Call - bool closeForData = info.CloseForData(view, failureMechanismContext); + // Assert + Assert.IsFalse(closeForData); + } - // Assert - Assert.IsFalse(closeForData); mocks.VerifyAll(); } [Test] - public void CloseForData_ViewCorrespondingToRemovedFailureMechanismContext_ReturnsTrue() + public void CloseForData_ViewCorrespondingToRemovedFailureMechanismContext_ReturnTrue() { // Setup + var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); mocks.ReplayAll(); - var view = new HeightStructuresScenariosView(); var failureMechanism = new HeightStructuresFailureMechanism(); var failureMechanismContext = new HeightStructuresFailureMechanismContext(failureMechanism, assessmentSection); - view.Data = failureMechanism.CalculationsGroup; + using (var view = new HeightStructuresScenariosView(failureMechanism.CalculationsGroup, failureMechanism, assessmentSection)) + { + // Call + bool closeForData = info.CloseForData(view, failureMechanismContext); - // Call - bool closeForData = info.CloseForData(view, failureMechanismContext); + // Assert + Assert.IsTrue(closeForData); + } - // Assert - Assert.IsTrue(closeForData); mocks.VerifyAll(); } [Test] - public void AfterCreate_Always_SetsSpecificPropertiesToView() + public void CreateInstance_WithContext_ReturnsHeightStructuresScenariosView() { // Setup + var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); mocks.ReplayAll(); - using (var view = new HeightStructuresScenariosView()) - { - var group = new CalculationGroup(); - var failureMechanism = new HeightStructuresFailureMechanism(); - var context = new HeightStructuresScenariosContext(group, failureMechanism, assessmentSection); + var group = new CalculationGroup(); + var context = new HeightStructuresScenariosContext(group, new HeightStructuresFailureMechanism(), assessmentSection); - // Call - info.AfterCreate(view, context); - + // Call + using (IView view = info.CreateInstance(context)) + { // Assert - Assert.AreSame(failureMechanism, view.FailureMechanism); + Assert.IsInstanceOf(view); + Assert.AreSame(group, view.Data); } mocks.VerifyAll();