Index: Riskeer/HeightStructures/test/Riskeer.HeightStructures.Forms.Test/Views/HeightStructuresCalculationsViewTest.cs =================================================================== diff -u -r0857aff3d2bcce3efb678e5c1090832dd5c52776 -r2847b64c3282ae0ffe00fe36c0be047498898971 --- Riskeer/HeightStructures/test/Riskeer.HeightStructures.Forms.Test/Views/HeightStructuresCalculationsViewTest.cs (.../HeightStructuresCalculationsViewTest.cs) (revision 0857aff3d2bcce3efb678e5c1090832dd5c52776) +++ Riskeer/HeightStructures/test/Riskeer.HeightStructures.Forms.Test/Views/HeightStructuresCalculationsViewTest.cs (.../HeightStructuresCalculationsViewTest.cs) (revision 2847b64c3282ae0ffe00fe36c0be047498898971) @@ -26,6 +26,7 @@ using Core.Common.Base; using Core.Common.Base.Data; using Core.Common.Base.Geometry; +using Core.Common.Controls.DataGrid; using NUnit.Extensions.Forms; using NUnit.Framework; using Rhino.Mocks; @@ -36,6 +37,7 @@ using Riskeer.Common.Data.Hydraulics; using Riskeer.Common.Data.Structures; using Riskeer.Common.Data.TestUtil; +using Riskeer.Common.Forms; using Riskeer.Common.Forms.Views; using Riskeer.HeightStructures.Data; using Riskeer.HeightStructures.Data.TestUtil; @@ -545,6 +547,147 @@ mocks.VerifyAll(); } + [Test] + public void GivenCalculationsView_WhenGenerateCalculationsButtonClicked_ThenShowViewWithForeshoreProfiles() + { + // Given + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + ConfigureHydraulicBoundaryDatabase(assessmentSection); + mocks.ReplayAll(); + + HeightStructuresFailureMechanism failureMechanism = ConfigureFailureMechanism(); + ShowCalculationsView(failureMechanism.CalculationsGroup, failureMechanism, assessmentSection); + + var button = new ButtonTester("generateButton", testForm); + + StructureSelectionDialog selectionDialog = null; + DataGridViewControl grid = null; + var rows = 0; + DialogBoxHandler = (name, wnd) => + { + selectionDialog = (StructureSelectionDialog) new FormTester(name).TheObject; + grid = (DataGridViewControl) new ControlTester("DataGridViewControl", selectionDialog).TheObject; + rows = grid.Rows.Count; + + new ButtonTester("CustomCancelButton", selectionDialog).Click(); + }; + + // When + button.Click(); + + // Then + Assert.NotNull(selectionDialog); + Assert.NotNull(grid); + Assert.AreEqual(failureMechanism.ForeshoreProfiles.Count, rows); + mocks.VerifyAll(); + } + + [Test] + public void GivenCalculationsViewGenerateCalculationsButtonClicked_WhenDialogClosed_ThenNotifyCalculationGroup() + { + // Given + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + ConfigureHydraulicBoundaryDatabase(assessmentSection); + var observer = mocks.StrictMock(); + observer.Expect(o => o.UpdateObserver()); + mocks.ReplayAll(); + + HeightStructuresFailureMechanism failureMechanism = ConfigureFailureMechanism(); + failureMechanism.CalculationsGroup.Attach(observer); + + ShowCalculationsView(failureMechanism.CalculationsGroup, failureMechanism, assessmentSection); + + var button = new ButtonTester("generateButton", testForm); + + DialogBoxHandler = (name, wnd) => + { + var selectionDialog = (StructureSelectionDialog) new FormTester(name).TheObject; + var selectionView = (DataGridViewControl) new ControlTester("DataGridViewControl", selectionDialog).TheObject; + selectionView.Rows[0].Cells[0].Value = true; + + // When + new ButtonTester("DoForSelectedButton", selectionDialog).Click(); + }; + + button.Click(); + + // Then + mocks.VerifyAll(); + } + + [Test] + public void GivenCalculationsViewGenerateCalculationsButtonClicked_WhenForeshoreProfileSelectedAndDialogClosed_ThenUpdateSectionResultScenarios() + { + // Given + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + ConfigureHydraulicBoundaryDatabase(assessmentSection); + mocks.ReplayAll(); + + HeightStructuresFailureMechanism failureMechanism = ConfigureFailureMechanism(); + + ShowCalculationsView(failureMechanism.CalculationsGroup, failureMechanism, assessmentSection); + + var button = new ButtonTester("generateButton", testForm); + + DialogBoxHandler = (name, wnd) => + { + var selectionDialog = (StructureSelectionDialog) new FormTester(name).TheObject; + var selectionView = (DataGridViewControl) new ControlTester("DataGridViewControl", selectionDialog).TheObject; + selectionView.Rows[0].Cells[0].Value = true; + + // When + new ButtonTester("DoForSelectedButton", selectionDialog).Click(); + }; + + button.Click(); + + // Then + StructuresCalculationScenario[] calculationScenarios = failureMechanism.Calculations.OfType>().ToArray(); + HeightStructuresFailureMechanismSectionResult failureMechanismSectionResult1 = failureMechanism.SectionResults.First(); + HeightStructuresFailureMechanismSectionResult failureMechanismSectionResult2 = failureMechanism.SectionResults.ElementAt(1); + + Assert.AreEqual(1, failureMechanismSectionResult1.GetCalculationScenarios(calculationScenarios).Count()); + CollectionAssert.IsEmpty(failureMechanismSectionResult2.GetCalculationScenarios(calculationScenarios)); + mocks.VerifyAll(); + } + + [Test] + public void GivenCalculationsViewGenerateCalculationsCancelButtonClicked_WhenDialogClosed_CalculationsNotUpdatedAndCalculationGroupNotNotified() + { + // Given + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + ConfigureHydraulicBoundaryDatabase(assessmentSection); + var observer = mocks.StrictMock(); + mocks.ReplayAll(); + + HeightStructuresFailureMechanism failureMechanism = ConfigureFailureMechanism(); + ShowCalculationsView(failureMechanism.CalculationsGroup, failureMechanism, assessmentSection); + + failureMechanism.CalculationsGroup.Attach(observer); + + var button = new ButtonTester("generateButton", testForm); + + DialogBoxHandler = (name, wnd) => + { + var selectionDialog = (StructureSelectionDialog) new FormTester(name).TheObject; + var selectionView = (DataGridViewControl) new ControlTester("DataGridViewControl", selectionDialog).TheObject; + selectionView.Rows[0].Cells[0].Value = true; + + // When + new ButtonTester("CustomCancelButton", selectionDialog).Click(); + }; + + button.Click(); + + // Then + CollectionAssert.IsEmpty(failureMechanism.Calculations); + mocks.VerifyAll(); // No observer notified + } + public override void Setup() { base.Setup();