Index: Ringtoets/Common/src/Ringtoets.Common.Forms/TreeNodeInfos/RingtoetsContextMenuItemFactory.cs =================================================================== diff -u -r25bebedb3a8c1f321c6f1760192e09d2646a2bdc -rabb4bd5b761f15f17a61959327b368a224b59f47 --- Ringtoets/Common/src/Ringtoets.Common.Forms/TreeNodeInfos/RingtoetsContextMenuItemFactory.cs (.../RingtoetsContextMenuItemFactory.cs) (revision 25bebedb3a8c1f321c6f1760192e09d2646a2bdc) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/TreeNodeInfos/RingtoetsContextMenuItemFactory.cs (.../RingtoetsContextMenuItemFactory.cs) (revision abb4bd5b761f15f17a61959327b368a224b59f47) @@ -371,10 +371,10 @@ } /// - /// Creates a which is bound to the action when updating + /// Creates a which is bound to the action of updating /// the of a . /// - /// The type of calculation input that has can have a foreshore profile. + /// The type of calculation input that can have a foreshore profile. /// The calculation to update. /// Object responsible for inquiring the required data. /// The action to perform when the foreshore profile is updated. @@ -422,10 +422,10 @@ } /// - /// Creates a which is bound to the action when updating + /// Creates a which is bound to the action of updating /// the of the . /// - /// The type of calculation input that has can have a foreshore profile. + /// The type of calculation input that can have a foreshore profile. /// The calculations to update. /// Object responsible for inquiring the required data. /// The action to perform when the foreshore profile is updated. Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/TreeNodeInfos/RingtoetsContextMenuItemFactoryTest.cs =================================================================== diff -u -r25bebedb3a8c1f321c6f1760192e09d2646a2bdc -rabb4bd5b761f15f17a61959327b368a224b59f47 --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/TreeNodeInfos/RingtoetsContextMenuItemFactoryTest.cs (.../RingtoetsContextMenuItemFactoryTest.cs) (revision 25bebedb3a8c1f321c6f1760192e09d2646a2bdc) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/TreeNodeInfos/RingtoetsContextMenuItemFactoryTest.cs (.../RingtoetsContextMenuItemFactoryTest.cs) (revision abb4bd5b761f15f17a61959327b368a224b59f47) @@ -101,7 +101,7 @@ var calculationGroupContext = new TestCalculationGroupContext(calculationGroup, failureMechanismMock); // Call - StrictContextMenuItem toolStripItem = RingtoetsContextMenuItemFactory.CreateAddCalculationItem(calculationGroupContext, context => { }); + StrictContextMenuItem toolStripItem = RingtoetsContextMenuItemFactory.CreateAddCalculationItem(calculationGroupContext, context => {}); // Assert Assert.AreEqual("Berekening &toevoegen", toolStripItem.Text); @@ -611,7 +611,7 @@ // Call StrictContextMenuItem toolStripItem = RingtoetsContextMenuItemFactory.CreateUpdateForeshoreProfileOfCalculationItem( calculationMock, - inquiryHelperMock, c => { }); + inquiryHelperMock, c => {}); // Assert Assert.AreEqual("&Bijwerken voorlandprofiel...", toolStripItem.Text); @@ -637,7 +637,7 @@ // Call StrictContextMenuItem toolStripItem = RingtoetsContextMenuItemFactory.CreateUpdateForeshoreProfileOfCalculationItem( calculationMock, - inquiryHelperMock, c => { }); + inquiryHelperMock, c => {}); // Assert Assert.AreEqual("&Bijwerken voorlandprofiel...", toolStripItem.Text); @@ -748,41 +748,25 @@ #region CreateUpdateForeshoreProfileOfCalculationsItem [Test] - public void CreateUpdateForeshoreProfileOfCalculationsItem_WithoutForeshoreProfile_CreatesDisabledItem() + [Combinatorial] + public void CreateUpdateForeshoreProfileOfCalculationsItem_ForeshoreProfileStates_CreatesExpectedItem( + [Values(true, false)] bool hasForeshoreProfile, + [Values(true, false)] bool isSynchronized) { // Setup var mocks = new MockRepository(); var calculationMock = mocks.StrictMock>(); - calculationMock.Expect(c => c.InputParameters.ForeshoreProfile).Return(null); - - var inquiryHelperMock = mocks.StrictMock(); - mocks.ReplayAll(); - - // Call - StrictContextMenuItem toolStripItem = RingtoetsContextMenuItemFactory.CreateUpdateForeshoreProfileOfCalculationsItem( - new[] - { - calculationMock - }, - inquiryHelperMock, c => { }); - - // Assert - Assert.AreEqual("&Bijwerken voorlandprofielen...", toolStripItem.Text); - Assert.AreEqual("Er zijn geen berekeningen om bij te werken.", toolStripItem.ToolTipText); - TestHelper.AssertImagesAreEqual(RingtoetsFormsResources.UpdateItemIcon, toolStripItem.Image); - Assert.IsFalse(toolStripItem.Enabled); - mocks.VerifyAll(); - } - - [Test] - public void CreateUpdateForeshoreProfileOfCalculationsItem_WithForeshoreProfileSynchronized_CreatesDisabledItem() - { - // Setup - var mocks = new MockRepository(); - var calculationMock = mocks.StrictMock>(); var inputMock = mocks.StrictMock(); - inputMock.Stub(ci => ci.ForeshoreProfile).Return(new TestForeshoreProfile()); - inputMock.Stub(ci => ci.IsForeshoreProfileInputSynchronized).Return(true); + if (hasForeshoreProfile) + { + inputMock.Expect(ci => ci.ForeshoreProfile).Return(new TestForeshoreProfile()); + inputMock.Expect(ci => ci.IsForeshoreProfileInputSynchronized).Return(isSynchronized); + } + else + { + inputMock.Expect(ci => ci.ForeshoreProfile).Return(null); + } + calculationMock.Stub(c => c.InputParameters).Return(inputMock); var inquiryHelperMock = mocks.StrictMock(); @@ -794,96 +778,32 @@ { calculationMock }, - inquiryHelperMock, c => { }); + inquiryHelperMock, c => {}); // Assert Assert.AreEqual("&Bijwerken voorlandprofielen...", toolStripItem.Text); - Assert.AreEqual("Er zijn geen berekeningen om bij te werken.", toolStripItem.ToolTipText); TestHelper.AssertImagesAreEqual(RingtoetsFormsResources.UpdateItemIcon, toolStripItem.Image); - Assert.IsFalse(toolStripItem.Enabled); - mocks.VerifyAll(); - } - [Test] - public void CreateUpdateForeshoreProfileOfCalculationsItem_WithForeshoreProfile_CreatesEnabledItem() - { - // Setup - var mocks = new MockRepository(); - var calculationMock = mocks.StrictMock>(); - var input = mocks.StrictMock(); - input.Expect(i => i.ForeshoreProfile).Return(new TestForeshoreProfile()); - input.Expect(i => i.IsForeshoreProfileInputSynchronized).Return(false); - calculationMock.Stub(c => c.InputParameters).Return(input); - - var calculationWithoutChangesMock = mocks.StrictMock>(); - var inputWithoutChangesMock = mocks.StrictMock(); - inputWithoutChangesMock.Stub(ci => ci.ForeshoreProfile).Return(new TestForeshoreProfile()); - inputWithoutChangesMock.Stub(ci => ci.IsForeshoreProfileInputSynchronized).Return(true); - calculationWithoutChangesMock.Stub(c => c.InputParameters).Return(inputWithoutChangesMock); - - var inquiryHelperMock = mocks.StrictMock(); - mocks.ReplayAll(); - - // Call - StrictContextMenuItem toolStripItem = RingtoetsContextMenuItemFactory.CreateUpdateForeshoreProfileOfCalculationsItem( - new[] - { - calculationMock, - calculationWithoutChangesMock - }, - inquiryHelperMock, c => { }); - - // Assert - Assert.AreEqual("&Bijwerken voorlandprofielen...", toolStripItem.Text); - Assert.AreEqual("Alle berekeningen met een voorlandprofiel bijwerken.", toolStripItem.ToolTipText); - TestHelper.AssertImagesAreEqual(RingtoetsFormsResources.UpdateItemIcon, toolStripItem.Image); - Assert.IsTrue(toolStripItem.Enabled); + if (hasForeshoreProfile && !isSynchronized) + { + Assert.AreEqual("Alle berekeningen met een voorlandprofiel bijwerken.", toolStripItem.ToolTipText); + Assert.IsTrue(toolStripItem.Enabled); + } + else + { + Assert.AreEqual("Er zijn geen berekeningen om bij te werken.", toolStripItem.ToolTipText); + Assert.IsFalse(toolStripItem.Enabled); + } mocks.VerifyAll(); } [Test] - public void CreateUpdateForeshoreProfileOfCalculationsItem_WithoutCalculationOutputPerformClick_PerformsAction() + [Combinatorial] + public void CreateUpdateForeshoreProfileOfCalculationsItem_WithVariousOutputPerformClick_ExpectedAction( + [Values(true, false)] bool hasOutput, + [Values(true, false)] bool continuation) { // Setup - var mocks = new MockRepository(); - var calculationMock = mocks.StrictMock>(); - var input = mocks.StrictMock(); - input.Expect(i => i.ForeshoreProfile).Return(new TestForeshoreProfile()); - input.Expect(i => i.IsForeshoreProfileInputSynchronized).Return(false); - calculationMock.Stub(c => c.InputParameters).Return(input); - calculationMock.Expect(c => c.HasOutput).Return(false); - - var calculationWithoutChangesMock = mocks.StrictMock>(); - var inputWithoutChangesMock = mocks.StrictMock(); - inputWithoutChangesMock.Stub(ci => ci.ForeshoreProfile).Return(new TestForeshoreProfile()); - inputWithoutChangesMock.Stub(ci => ci.IsForeshoreProfileInputSynchronized).Return(true); - calculationWithoutChangesMock.Stub(c => c.InputParameters).Return(inputWithoutChangesMock); - - var inquiryHelperMock = mocks.StrictMock(); - mocks.ReplayAll(); - - ICalculation actionCalculation = null; - StrictContextMenuItem toolStripItem = RingtoetsContextMenuItemFactory.CreateUpdateForeshoreProfileOfCalculationsItem( - new[] - { - calculationMock, - calculationWithoutChangesMock - }, - inquiryHelperMock, - c => { actionCalculation = c; }); - - // Call - toolStripItem.PerformClick(); - - // Assert - Assert.AreSame(calculationMock, actionCalculation); - mocks.VerifyAll(); - } - - [Test] - public void CreateUpdateForeshoreProfileOfCalculationsItem_WithCalculationOutputPerformClickNoContinuation_DoesNotPerformAction() - { - // Setup string inquireContinuationMessage = "Als u kiest voor bijwerken, dan wordt het resultaat van alle bij te werken berekeningen " + $"verwijderd.{Environment.NewLine}{Environment.NewLine}Weet u zeker dat u wilt doorgaan?"; @@ -893,7 +813,7 @@ inputMock.Expect(i => i.ForeshoreProfile).Return(new TestForeshoreProfile()); inputMock.Expect(i => i.IsForeshoreProfileInputSynchronized).Return(false); calculationMock.Stub(c => c.InputParameters).Return(inputMock); - calculationMock.Expect(c => c.HasOutput).Return(true); + calculationMock.Expect(c => c.HasOutput).Return(hasOutput); var calculationWithoutChangesMock = mocks.StrictMock>(); var inputWithoutChangesMock = mocks.StrictMock(); @@ -902,9 +822,13 @@ calculationWithoutChangesMock.Stub(c => c.InputParameters).Return(inputWithoutChangesMock); var inquiryHelperMock = mocks.StrictMock(); - inquiryHelperMock.Expect(i => i.InquireContinuation(inquireContinuationMessage)).Return(false); + if (hasOutput) + { + inquiryHelperMock.Expect(i => i.InquireContinuation(inquireContinuationMessage)).Return(continuation); + } mocks.ReplayAll(); + ICalculation actionCalculation = null; var actionPerformed = false; StrictContextMenuItem toolStripItem = RingtoetsContextMenuItemFactory.CreateUpdateForeshoreProfileOfCalculationsItem( new[] @@ -913,60 +837,27 @@ calculationWithoutChangesMock }, inquiryHelperMock, - c => { actionPerformed = true; }); - - // Call - toolStripItem.PerformClick(); - - // Assert - Assert.IsFalse(actionPerformed); - mocks.VerifyAll(); - } - - [Test] - public void CreateUpdateForeshoreProfileOfCalculationsItem_WithCalculationOutputPerformClickWithContinuation_PerformsAction() - { - // Setup - string inquireContinuationMessage = "Als u kiest voor bijwerken, dan wordt het resultaat van alle bij te werken berekeningen " + - $"verwijderd.{Environment.NewLine}{Environment.NewLine}Weet u zeker dat u wilt doorgaan?"; - - var mocks = new MockRepository(); - var calculationMock = mocks.StrictMock>(); - var input = mocks.StrictMock(); - input.Expect(i => i.ForeshoreProfile).Return(new TestForeshoreProfile()); - input.Expect(i => i.IsForeshoreProfileInputSynchronized).Return(false); - calculationMock.Stub(c => c.InputParameters).Return(input); - calculationMock.Expect(c => c.HasOutput).Return(true); - - var calculationWithoutChangesMock = mocks.StrictMock>(); - var inputWithoutChangesMock = mocks.StrictMock(); - inputWithoutChangesMock.Stub(ci => ci.ForeshoreProfile).Return(new TestForeshoreProfile()); - inputWithoutChangesMock.Stub(ci => ci.IsForeshoreProfileInputSynchronized).Return(true); - calculationWithoutChangesMock.Stub(c => c.InputParameters).Return(inputWithoutChangesMock); - - var inquiryHelperMock = mocks.StrictMock(); - inquiryHelperMock.Expect(i => i.InquireContinuation(inquireContinuationMessage)).Return(true); - mocks.ReplayAll(); - - var actionPerformed = false; - StrictContextMenuItem toolStripItem = RingtoetsContextMenuItemFactory.CreateUpdateForeshoreProfileOfCalculationsItem( - new[] - { - calculationMock, - calculationWithoutChangesMock - }, - inquiryHelperMock, c => { - Assert.AreSame(calculationMock, c); + actionCalculation = c; actionPerformed = true; }); // Call toolStripItem.PerformClick(); // Assert - Assert.IsTrue(actionPerformed); + if (hasOutput && !continuation) + { + Assert.IsFalse(actionPerformed); + Assert.IsNull(actionCalculation); + } + else + { + Assert.IsTrue(actionPerformed); + Assert.AreSame(calculationMock, actionCalculation); + } + mocks.VerifyAll(); }