Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/TreeNodeInfos/GrassCoverErosionInwardsCalculationContextTreeNodeInfoTest.cs =================================================================== diff -u -rf8732f8bbec8b197d9bc91e91d27e0c9d20b4ed3 -r8a482f64da54bd72583411ba20668c58b2ae0184 --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/TreeNodeInfos/GrassCoverErosionInwardsCalculationContextTreeNodeInfoTest.cs (.../GrassCoverErosionInwardsCalculationContextTreeNodeInfoTest.cs) (revision f8732f8bbec8b197d9bc91e91d27e0c9d20b4ed3) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/TreeNodeInfos/GrassCoverErosionInwardsCalculationContextTreeNodeInfoTest.cs (.../GrassCoverErosionInwardsCalculationContextTreeNodeInfoTest.cs) (revision 8a482f64da54bd72583411ba20668c58b2ae0184) @@ -25,7 +25,6 @@ using System.Linq; using System.Windows.Forms; using Core.Common.Base; -using Core.Common.Base.Data; using Core.Common.Base.Geometry; using Core.Common.Controls.TreeView; using Core.Common.Gui; @@ -276,7 +275,7 @@ } [Test] - public void ContextMenuStrip_CalculationWithoutDikeProfile_ContextMenuItemUpdateDikeProfileDisabled() + public void ContextMenuStrip_CalculationWithoutDikeProfile_ContextMenuItemUpdateDikeProfileDisabledAndToolTipSet() { // Setup var assessmentSection = mocks.Stub(); @@ -309,7 +308,7 @@ } [Test] - public void ContextMenuStrip_CalculationWithDikeProfile_ContextMenuItemUpdateDikeProfileEnabled() + public void ContextMenuStrip_CalculationWithDikeProfileAndInputInSync_ContextMenuItemUpdateDikeProfileDisabledAndToolTipSet() { // Setup var assessmentSection = mocks.Stub(); @@ -340,62 +339,56 @@ TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuUpdateDikeProfileIndex, "&Bijwerken dijkprofiel...", - "Berekening bijwerken met het dijkprofiel.", - RingtoetsCommonFormsResources.UpdateItemIcon); + "Er zijn geen wijzigingen om bij te werken.", + RingtoetsCommonFormsResources.UpdateItemIcon, + false); } } } [Test] - public void GivenCalculationWithDikeProfileWithoutOutput_WhenDikeProfileAndInputOutOfSyncAndUpdateClicked_ThenNoInquiryAndCalculationUpdatedAndInputObserverNotified() + public void ContextMenuStrip_CalculationWithDikeProfileAndInputOutOfSync_ContextMenuItemUpdateDikeProfileEnabledAndToolTipSet() { - // Given + // Setup var assessmentSection = mocks.Stub(); - var dikeProfile = new TestDikeProfile(); + + var testDikeProfile = new TestDikeProfile(); var calculation = new GrassCoverErosionInwardsCalculation { InputParameters = { - DikeProfile = dikeProfile + DikeProfile = testDikeProfile } }; - var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + var failureMechanism = new TestGrassCoverErosionInwardsFailureMechanism(); var nodeData = new GrassCoverErosionInwardsCalculationContext(calculation, failureMechanism, assessmentSection); + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); - var inputObserver = mocks.StrictMock(); - inputObserver.Expect(obs => obs.UpdateObserver()); - calculation.InputParameters.Attach(inputObserver); - - var calculationObserver = mocks.StrictMock(); - calculation.Attach(calculationObserver); - using (var treeViewControl = new TreeViewControl()) { - var mainWindow = mocks.Stub(); var gui = mocks.Stub(); - gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); - gui.Stub(g => g.MainWindow).Return(mainWindow); + gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilder); mocks.ReplayAll(); plugin.Gui = gui; + ChangeDikeProfile(testDikeProfile); + + // Call using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, assessmentSection, treeViewControl)) { - // When - UpdateDikeProfile(dikeProfile); - menu.Items[contextMenuUpdateDikeProfileIndex].PerformClick(); - - // Then - Assert.IsFalse(calculation.HasOutput); - AssertGrassCoverErosionInwardsInput(dikeProfile, calculation.InputParameters); - - // Note: observer assertions are verified in the TearDown() + // Assert + TestHelper.AssertContextMenuStripContainsItem(menu, + contextMenuUpdateDikeProfileIndex, + "&Bijwerken dijkprofiel...", + "Berekening bijwerken met het dijkprofiel.", + RingtoetsCommonFormsResources.UpdateItemIcon); } } } [Test] - public void GivenCalculationWithDikeProfileWithOutput_WhenDikeProfileAndInputOutOfSyncAndUpdateClickedAndCancelled_ThenInquiryAndCalculationNotUpdatedAndObserversNotNotified() + public void GivenCalculationWithoutOutputAndWithInputOutOfSync_WhenUpdateDikeProfileClicked_ThenNoInquiryAndCalculationUpdatedAndInputObserverNotified() { // Given var assessmentSection = mocks.Stub(); @@ -405,34 +398,18 @@ InputParameters = { DikeProfile = dikeProfile - }, - Output = new TestGrassCoverErosionInwardsOutput() + } }; - - GrassCoverErosionInwardsInput calculationInput = calculation.InputParameters; - RoundedDouble expectedOrientation = calculationInput.Orientation; - RoundedDouble expectedDikeHeight = calculationInput.DikeHeight; - bool expectedUseBreakWater = calculationInput.UseBreakWater; - BreakWater expectedBreakWater = calculationInput.BreakWater; - bool expectedUseForeshore = calculationInput.UseForeshore; - var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); var nodeData = new GrassCoverErosionInwardsCalculationContext(calculation, failureMechanism, assessmentSection); var inputObserver = mocks.StrictMock(); - calculationInput.Attach(inputObserver); + inputObserver.Expect(obs => obs.UpdateObserver()); + calculation.InputParameters.Attach(inputObserver); var calculationObserver = mocks.StrictMock(); calculation.Attach(calculationObserver); - string textBoxMessage = null; - DialogBoxHandler = (name, wnd) => - { - var helper = new MessageBoxTester(wnd); - textBoxMessage = helper.Text; - helper.ClickCancel(); - }; - using (var treeViewControl = new TreeViewControl()) { var mainWindow = mocks.Stub(); @@ -442,38 +419,28 @@ mocks.ReplayAll(); plugin.Gui = gui; + + ChangeDikeProfile(dikeProfile); + using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, assessmentSection, treeViewControl)) { // When - UpdateDikeProfile(dikeProfile); menu.Items[contextMenuUpdateDikeProfileIndex].PerformClick(); // Then - Assert.IsTrue(calculation.HasOutput); + Assert.IsFalse(calculation.HasOutput); + Assert.IsTrue(calculation.InputParameters.IsDikeProfileInputSynchronized); - Assert.AreSame(dikeProfile, calculationInput.DikeProfile); - Assert.AreEqual(expectedOrientation, calculationInput.Orientation); - Assert.AreEqual(expectedDikeHeight, calculationInput.DikeHeight); - Assert.AreEqual(expectedUseBreakWater, calculationInput.UseBreakWater); - Assert.AreEqual(expectedBreakWater, calculationInput.BreakWater); - Assert.AreEqual(expectedUseForeshore, calculationInput.UseForeshore); - - string expectedMessage = "Wanneer het dijkprofiel wijzigt als gevolg van het bijwerken, " + - "zal het resultaat van deze berekening worden " + - $"verwijderd.{Environment.NewLine}{Environment.NewLine}Weet u zeker dat u wilt doorgaan?"; - Assert.AreEqual(expectedMessage, textBoxMessage); - // Note: observer assertions are verified in the TearDown() } } } [Test] - public void GivenCalculationWithDikeProfileWithOutput_WhenDikeProfileAndInputOutOfSyncAndUpdateClickedAndContinued_ThenInquiryAndUpdatesCalculationAndObserversNotified() + public void GivenCalculationWithOutputAndInputInSync_WhenUpdateDikeProfileClicked_ThenNoInquiryAndCalculationNotUpdatedAndObserversNotNotified() { // Given var assessmentSection = mocks.Stub(); - var dikeProfile = new TestDikeProfile(); var calculation = new GrassCoverErosionInwardsCalculation { @@ -483,25 +450,16 @@ }, Output = new TestGrassCoverErosionInwardsOutput() }; + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); var nodeData = new GrassCoverErosionInwardsCalculationContext(calculation, failureMechanism, assessmentSection); var inputObserver = mocks.StrictMock(); - inputObserver.Expect(obs => obs.UpdateObserver()); calculation.InputParameters.Attach(inputObserver); var calculationObserver = mocks.StrictMock(); - calculationObserver.Expect(obs => obs.UpdateObserver()); calculation.Attach(calculationObserver); - string textBoxMessage = null; - DialogBoxHandler = (name, wnd) => - { - var helper = new MessageBoxTester(wnd); - textBoxMessage = helper.Text; - helper.ClickOk(); - }; - using (var treeViewControl = new TreeViewControl()) { var mainWindow = mocks.Stub(); @@ -515,77 +473,47 @@ using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, assessmentSection, treeViewControl)) { // When - UpdateDikeProfile(dikeProfile); menu.Items[contextMenuUpdateDikeProfileIndex].PerformClick(); // Then - Assert.IsFalse(calculation.HasOutput); - AssertGrassCoverErosionInwardsInput(dikeProfile, calculation.InputParameters); + Assert.IsTrue(calculation.HasOutput); + Assert.IsTrue(calculation.InputParameters.IsDikeProfileInputSynchronized); - string expectedMessage = "Wanneer het dijkprofiel wijzigt als gevolg van het bijwerken, " + - "zal het resultaat van deze berekening worden " + - $"verwijderd.{Environment.NewLine}{Environment.NewLine}Weet u zeker dat u wilt doorgaan?"; - Assert.AreEqual(expectedMessage, textBoxMessage); - // Note: observer assertions are verified in the TearDown() } } } [Test] - public void GivenCalculationWithDikeProfileWithOutput_WhenDikeProfileAndInputInSyncAndUpdateClickedAndContinued_ThenInquiryAndCalculationNotUpdatedAndObserversNotNotified() + public void GivenCalculationWithOutputAndInputOutOfSync_WhenUpdateDikeProfileClickedAndCancelled_ThenInquiryAndCalculationNotUpdatedAndObserversNotNotified() { // Given var assessmentSection = mocks.Stub(); - - var dikeProfile = new DikeProfile(new Point2D(0, 0), - new[] - { - new RoughnessPoint(new Point2D(1.1, 2.2), 3), - new RoughnessPoint(new Point2D(3.3, 4.4), 5) - }, - new[] - { - new Point2D(1.1, 2.2), - new Point2D(3.3, 4.4) - }, - new BreakWater(BreakWaterType.Caisson, 10), - new DikeProfile.ConstructionProperties - { - Id = "ID" - }); - const double orientation = 10; - const double dikeHeight = 10; - const bool useBreakWater = true; - const bool useForeshore = true; + var dikeProfile = new TestDikeProfile(); var calculation = new GrassCoverErosionInwardsCalculation { InputParameters = { - DikeProfile = dikeProfile, - DikeHeight = (RoundedDouble) dikeHeight, - Orientation = (RoundedDouble) orientation, - UseForeshore = useForeshore, - UseBreakWater = useBreakWater + DikeProfile = dikeProfile }, Output = new TestGrassCoverErosionInwardsOutput() }; + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + var nodeData = new GrassCoverErosionInwardsCalculationContext(calculation, failureMechanism, assessmentSection); + var inputObserver = mocks.StrictMock(); calculation.InputParameters.Attach(inputObserver); var calculationObserver = mocks.StrictMock(); calculation.Attach(calculationObserver); - var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); - var nodeData = new GrassCoverErosionInwardsCalculationContext(calculation, failureMechanism, assessmentSection); - string textBoxMessage = null; DialogBoxHandler = (name, wnd) => { var helper = new MessageBoxTester(wnd); textBoxMessage = helper.Text; - helper.ClickOk(); + helper.ClickCancel(); }; using (var treeViewControl = new TreeViewControl()) @@ -598,18 +526,18 @@ plugin.Gui = gui; + ChangeDikeProfile(dikeProfile); + using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, assessmentSection, treeViewControl)) { // When - UpdateDikeProfile(dikeProfile); menu.Items[contextMenuUpdateDikeProfileIndex].PerformClick(); // Then Assert.IsTrue(calculation.HasOutput); - AssertGrassCoverErosionInwardsInput(dikeProfile, calculation.InputParameters); + Assert.IsFalse(calculation.InputParameters.IsDikeProfileInputSynchronized); - string expectedMessage = "Wanneer het dijkprofiel wijzigt als gevolg van het bijwerken, " + - "zal het resultaat van deze berekening worden " + + string expectedMessage = "Als u kiest voor bijwerken, dan wordt het resultaat van deze berekening " + $"verwijderd.{Environment.NewLine}{Environment.NewLine}Weet u zeker dat u wilt doorgaan?"; Assert.AreEqual(expectedMessage, textBoxMessage); @@ -619,14 +547,12 @@ } [Test] - public void GivenCalculationWithDikeProfileWithOutput_WhenDikeProfileAndInputPartiallyOutOfSyncAndUpdateClicked_ThenInquiryAndUpdatesCalculationAndNotifiesObserver() + public void GivenCalculationWithOutputAndInputOutOfSync_WhenUpdateDikeProfileClickedAndContinued_ThenInquiryAndUpdatesCalculationAndObserversNotified() { // Given var assessmentSection = mocks.Stub(); var dikeProfile = new TestDikeProfile(); - UpdateDikeProfile(dikeProfile); - var calculation = new GrassCoverErosionInwardsCalculation { InputParameters = @@ -635,6 +561,8 @@ }, Output = new TestGrassCoverErosionInwardsOutput() }; + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + var nodeData = new GrassCoverErosionInwardsCalculationContext(calculation, failureMechanism, assessmentSection); var inputObserver = mocks.StrictMock(); inputObserver.Expect(obs => obs.UpdateObserver()); @@ -644,9 +572,6 @@ calculationObserver.Expect(obs => obs.UpdateObserver()); calculation.Attach(calculationObserver); - var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); - var nodeData = new GrassCoverErosionInwardsCalculationContext(calculation, failureMechanism, assessmentSection); - string textBoxMessage = null; DialogBoxHandler = (name, wnd) => { @@ -665,19 +590,18 @@ plugin.Gui = gui; + ChangeDikeProfile(dikeProfile); + using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, assessmentSection, treeViewControl)) { // When - GrassCoverErosionInwardsInput inputParameters = calculation.InputParameters; - inputParameters.Orientation = (RoundedDouble) 11.0; menu.Items[contextMenuUpdateDikeProfileIndex].PerformClick(); // Then Assert.IsFalse(calculation.HasOutput); - AssertGrassCoverErosionInwardsInput(dikeProfile, calculation.InputParameters); + Assert.IsTrue(calculation.InputParameters.IsDikeProfileInputSynchronized); - string expectedMessage = "Wanneer het dijkprofiel wijzigt als gevolg van het bijwerken, " + - "zal het resultaat van deze berekening worden " + + string expectedMessage = "Als u kiest voor bijwerken, dan wordt het resultaat van deze berekening " + $"verwijderd.{Environment.NewLine}{Environment.NewLine}Weet u zeker dat u wilt doorgaan?"; Assert.AreEqual(expectedMessage, textBoxMessage); @@ -1032,12 +956,12 @@ { string[] msgs = messages.ToArray(); Assert.AreEqual(6, msgs.Length); - StringAssert.StartsWith(string.Format("Validatie van '{0}' gestart om: ", calculation.Name), msgs[0]); - StringAssert.StartsWith(string.Format("Validatie van '{0}' beëindigd om: ", calculation.Name), msgs[1]); - StringAssert.StartsWith(string.Format("Berekening van '{0}' gestart om: ", calculation.Name), msgs[2]); + StringAssert.StartsWith($"Validatie van '{calculation.Name}' gestart om: ", msgs[0]); + StringAssert.StartsWith($"Validatie van '{calculation.Name}' beëindigd om: ", msgs[1]); + StringAssert.StartsWith($"Berekening van '{calculation.Name}' gestart om: ", msgs[2]); StringAssert.StartsWith("De overloop en overslag berekening is uitgevoerd op de tijdelijke locatie", msgs[3]); - StringAssert.StartsWith(string.Format("Berekening van '{0}' beëindigd om: ", calculation.Name), msgs[4]); - StringAssert.StartsWith(string.Format("Uitvoeren van '{0}' is gelukt.", calculation.Name), msgs[5]); + StringAssert.StartsWith($"Berekening van '{calculation.Name}' beëindigd om: ", msgs[4]); + StringAssert.StartsWith($"Uitvoeren van '{calculation.Name}' is gelukt.", msgs[5]); }); Assert.AreNotSame(initialOutput, calculation.Output); @@ -1098,8 +1022,8 @@ TestHelper.AssertLogMessages(action, messages => { string[] msgs = messages.ToArray(); - StringAssert.StartsWith(string.Format("Validatie van '{0}' gestart om: ", calculation.Name), msgs[0]); - StringAssert.StartsWith(string.Format("Validatie van '{0}' beëindigd om: ", calculation.Name), msgs[1]); + StringAssert.StartsWith($"Validatie van '{calculation.Name}' gestart om: ", msgs[0]); + StringAssert.StartsWith($"Validatie van '{calculation.Name}' beëindigd om: ", msgs[1]); }); } } @@ -1230,36 +1154,24 @@ Assert.IsNull(result.Calculation); } - private static void UpdateDikeProfile(DikeProfile dikeProfile) + private static void ChangeDikeProfile(DikeProfile dikeProfile) { - var dikeProfileToUpdateFrom = new DikeProfile(dikeProfile.WorldReferencePoint, - dikeProfile.DikeGeometry, - new[] - { - new Point2D(1.1, 2.2), - new Point2D(3.3, 4.4) - }, - new BreakWater(BreakWaterType.Caisson, 10), - new DikeProfile.ConstructionProperties - { - Id = dikeProfile.Id, - DikeHeight = 10, - Orientation = 10 - }); - - dikeProfile.CopyProperties(dikeProfileToUpdateFrom); + dikeProfile.CopyProperties(new DikeProfile(dikeProfile.WorldReferencePoint, + dikeProfile.DikeGeometry, + new[] + { + new Point2D(1.1, 2.2), + new Point2D(3.3, 4.4) + }, + new BreakWater(BreakWaterType.Caisson, 10), + new DikeProfile.ConstructionProperties + { + Id = dikeProfile.Id, + DikeHeight = 10, + Orientation = 10 + })); } - private static void AssertGrassCoverErosionInwardsInput(DikeProfile dikeProfile, GrassCoverErosionInwardsInput inputParameters) - { - Assert.AreSame(dikeProfile, inputParameters.DikeProfile); - Assert.AreEqual(dikeProfile.Orientation, inputParameters.Orientation); - Assert.AreEqual(dikeProfile.DikeHeight, inputParameters.DikeHeight); - Assert.AreEqual(dikeProfile.HasBreakWater, inputParameters.UseBreakWater); - Assert.AreEqual(dikeProfile.BreakWater, inputParameters.BreakWater); - Assert.AreEqual(dikeProfile.ForeshoreGeometry.Count() > 1, inputParameters.UseForeshore); - } - public override void TearDown() { plugin.Dispose();