Index: Riskeer/Common/src/Riskeer.Common.Forms/TreeNodeInfos/RiskeerContextMenuItemFactory.cs
===================================================================
diff -u -re3e21a866796ff70c0b7b28dfba268aae164ff33 -rb7bf733eaf3766a4fe3808ceef56ce2843fc2daa
--- Riskeer/Common/src/Riskeer.Common.Forms/TreeNodeInfos/RiskeerContextMenuItemFactory.cs (.../RiskeerContextMenuItemFactory.cs) (revision e3e21a866796ff70c0b7b28dfba268aae164ff33)
+++ Riskeer/Common/src/Riskeer.Common.Forms/TreeNodeInfos/RiskeerContextMenuItemFactory.cs (.../RiskeerContextMenuItemFactory.cs) (revision b7bf733eaf3766a4fe3808ceef56ce2843fc2daa)
@@ -83,23 +83,26 @@
///
/// Creates a which is bound to the action of clearing the output of all calculations in the calculation group.
///
- /// The calculation group to clear the output for.
+ /// The function to determine whether the context menu item should be enabled.
+ /// Object responsible for clearing the calculation output.
/// The created .
- public static StrictContextMenuItem CreateClearAllCalculationOutputInGroupItem(CalculationGroup calculationGroup)
+ public static StrictContextMenuItem CreateClearAllCalculationOutputInGroupItem(
+ Func isContextItemEnabledFunc, IClearCalculationOutputChangeHandler changeHandler)
{
- var clearAllItem = new StrictContextMenuItem(
+ bool enabled = isContextItemEnabledFunc();
+
+ string toolTip = enabled
+ ? Resources.CalculationGroup_ClearOutput_ToolTip
+ : Resources.CalculationGroup_ClearOutput_No_calculation_with_output_to_clear;
+
+ return new StrictContextMenuItem(
Resources.Clear_all_output,
- Resources.CalculationGroup_ClearOutput_ToolTip,
+ toolTip,
Resources.ClearIcon,
- (o, args) => ClearAllCalculationOutputInGroup(calculationGroup));
-
- if (!calculationGroup.HasOutput())
+ (o, args) => ClearAllCalculationOutput(changeHandler))
{
- clearAllItem.Enabled = false;
- clearAllItem.ToolTipText = Resources.CalculationGroup_ClearOutput_No_calculation_with_output_to_clear;
- }
-
- return clearAllItem;
+ Enabled = enabled
+ };
}
///
@@ -310,7 +313,7 @@
Resources.Clear_all_output,
toolTip,
Resources.ClearIcon,
- (o, args) => ClearAllCalculationOutputInFailureMechanism(changeHandler))
+ (o, args) => ClearAllCalculationOutput(changeHandler))
{
Enabled = enabled
};
@@ -643,7 +646,7 @@
}
}
- private static void ClearAllCalculationOutputInFailureMechanism(IClearCalculationOutputChangeHandler changeHandler)
+ private static void ClearAllCalculationOutput(IClearCalculationOutputChangeHandler changeHandler)
{
if (changeHandler.InquireConfirmation())
{
Index: Riskeer/Common/test/Riskeer.Common.Forms.Test/TreeNodeInfos/RiskeerContextMenuItemFactoryTest.cs
===================================================================
diff -u -re3e21a866796ff70c0b7b28dfba268aae164ff33 -rb7bf733eaf3766a4fe3808ceef56ce2843fc2daa
--- Riskeer/Common/test/Riskeer.Common.Forms.Test/TreeNodeInfos/RiskeerContextMenuItemFactoryTest.cs (.../RiskeerContextMenuItemFactoryTest.cs) (revision e3e21a866796ff70c0b7b28dfba268aae164ff33)
+++ Riskeer/Common/test/Riskeer.Common.Forms.Test/TreeNodeInfos/RiskeerContextMenuItemFactoryTest.cs (.../RiskeerContextMenuItemFactoryTest.cs) (revision b7bf733eaf3766a4fe3808ceef56ce2843fc2daa)
@@ -142,26 +142,16 @@
}
[Test]
- public void CreateClearAllCalculationOutputInGroupItem_GroupWithCalculationOutput_CreatesDecoratedAndEnabledItem()
+ public void CreateClearAllCalculationOutputInGroupItem_EnabledFuncTrue_CreatesDecoratedAndEnabledItem()
{
// Setup
var mocks = new MockRepository();
- var calculationWithOutput = mocks.StrictMock();
-
- calculationWithOutput.Expect(c => c.HasOutput).Return(true);
-
+ var changeHandler = mocks.Stub();
mocks.ReplayAll();
- var calculationGroup = new CalculationGroup
- {
- Children =
- {
- calculationWithOutput
- }
- };
-
// Call
- StrictContextMenuItem toolStripItem = RiskeerContextMenuItemFactory.CreateClearAllCalculationOutputInGroupItem(calculationGroup);
+ StrictContextMenuItem toolStripItem = RiskeerContextMenuItemFactory.CreateClearAllCalculationOutputInGroupItem(
+ () => true, changeHandler);
// Assert
Assert.AreEqual("&Wis alle uitvoer...", toolStripItem.Text);
@@ -173,26 +163,16 @@
}
[Test]
- public void CreateClearAllCalculationOutputInGroupItem_GroupWithoutCalculationOutput_CreatesDecoratedAndDisabledItem()
+ public void CreateClearAllCalculationOutputInGroupItem_EnabledFuncFalse_CreatesDecoratedAndDisabledItem()
{
// Setup
var mocks = new MockRepository();
- var calculationWithoutOutput = mocks.StrictMock();
-
- calculationWithoutOutput.Expect(c => c.HasOutput).Return(false);
-
+ var changeHandler = mocks.Stub();
mocks.ReplayAll();
- var calculationGroup = new CalculationGroup
- {
- Children =
- {
- calculationWithoutOutput
- }
- };
-
// Call
- StrictContextMenuItem toolStripItem = RiskeerContextMenuItemFactory.CreateClearAllCalculationOutputInGroupItem(calculationGroup);
+ StrictContextMenuItem toolStripItem = RiskeerContextMenuItemFactory.CreateClearAllCalculationOutputInGroupItem(
+ () => false, changeHandler);
// Assert
Assert.AreEqual("&Wis alle uitvoer...", toolStripItem.Text);
@@ -204,111 +184,59 @@
}
[Test]
- public void CreateClearAllCalculationOutputInGroupItem_PerformClickOnCreatedItemAndConfirmChange_CalculationOutputClearedAndObserversNotified()
+ public void CreateClearAllCalculationOutputInGroupItem_WhenClickPerformedAndActionContinued_ThenClearCalculationsPerformedAndObserversNotified()
{
- var messageBoxText = "";
- var messageBoxTitle = "";
+ // Given
var mocks = new MockRepository();
- var calculationWithOutputMock1 = mocks.StrictMock();
- var calculationWithOutputMock2 = mocks.StrictMock();
- var calculationWithoutOutput = mocks.StrictMock();
+ var calculation1 = mocks.StrictMock();
+ var calculation2 = mocks.StrictMock();
+ var calculation3 = mocks.StrictMock();
- calculationWithOutputMock1.Stub(c => c.HasOutput).Return(true);
- calculationWithOutputMock2.Stub(c => c.HasOutput).Return(true);
- calculationWithoutOutput.Stub(c => c.HasOutput).Return(false);
+ var changeHandler = mocks.StrictMock();
+ changeHandler.Expect(ch => ch.InquireConfirmation()).Return(true);
+ changeHandler.Expect(ch => ch.ClearCalculations()).Return(new[]
+ {
+ calculation1,
+ calculation2,
+ calculation3
+ });
- calculationWithOutputMock1.Expect(c => c.ClearOutput());
- calculationWithOutputMock1.Expect(c => c.NotifyObservers());
- calculationWithOutputMock2.Expect(c => c.ClearOutput());
- calculationWithOutputMock2.Expect(c => c.NotifyObservers());
-
+ calculation1.Expect(c => c.NotifyObservers());
+ calculation2.Expect(c => c.NotifyObservers());
+ calculation3.Expect(c => c.NotifyObservers());
mocks.ReplayAll();
- DialogBoxHandler = (name, wnd) =>
- {
- var messageBox = new MessageBoxTester(wnd);
- messageBoxText = messageBox.Text;
- messageBoxTitle = messageBox.Title;
+ StrictContextMenuItem toolStripItem = RiskeerContextMenuItemFactory.CreateClearAllCalculationOutputInGroupItem(
+ () => true, changeHandler);
- messageBox.ClickOk();
- };
-
- var calculationGroup = new CalculationGroup
- {
- Children =
- {
- calculationWithOutputMock1,
- new CalculationGroup
- {
- Children =
- {
- calculationWithOutputMock2,
- calculationWithoutOutput
- }
- }
- }
- };
-
- StrictContextMenuItem toolStripItem = RiskeerContextMenuItemFactory.CreateClearAllCalculationOutputInGroupItem(calculationGroup);
-
- // Call
+ // When
toolStripItem.PerformClick();
- // Assert
- Assert.AreEqual("Bevestigen", messageBoxTitle);
- Assert.AreEqual("Weet u zeker dat u alle uitvoer wilt wissen?", messageBoxText);
-
+ // Then
mocks.VerifyAll();
}
[Test]
- public void CreateClearAllCalculationOutputInGroupItem_PerformClickOnCreatedItemAndCancelChange_CalculationOutputNotCleared()
+ public void CreateClearAllCalculationOutputInGroupItem_WhenWhenClickPerformedAndActionCancelled_ThenNothingHappens()
{
+ // Given
var mocks = new MockRepository();
- var calculationWithOutputMock1 = mocks.StrictMock();
- var calculationWithOutputMock2 = mocks.StrictMock();
- var calculationWithoutOutput = mocks.StrictMock();
-
- calculationWithOutputMock1.Stub(c => c.HasOutput).Return(true);
- calculationWithOutputMock2.Stub(c => c.HasOutput).Return(true);
- calculationWithoutOutput.Stub(c => c.HasOutput).Return(false);
-
+ var changeHandler = mocks.StrictMock();
+ changeHandler.Expect(ch => ch.InquireConfirmation()).Return(false);
mocks.ReplayAll();
- DialogBoxHandler = (name, wnd) =>
- {
- var messageBox = new MessageBoxTester(wnd);
+ StrictContextMenuItem toolStripItem = RiskeerContextMenuItemFactory.CreateClearAllCalculationOutputInGroupItem(
+ () => true, changeHandler);
- messageBox.ClickCancel();
- };
-
- var calculationGroup = new CalculationGroup
- {
- Children =
- {
- calculationWithOutputMock1,
- new CalculationGroup
- {
- Children =
- {
- calculationWithOutputMock2,
- calculationWithoutOutput
- }
- }
- }
- };
-
- StrictContextMenuItem toolStripItem = RiskeerContextMenuItemFactory.CreateClearAllCalculationOutputInGroupItem(calculationGroup);
-
- // Call
+ // When
toolStripItem.PerformClick();
- // Assert
+ // Then
mocks.VerifyAll();
}
[Test]
- public void CreateClearAllCalculationOutputInFailureMechanismItem_FailureMechanismWithCalculationOutput_CreatesDecoratedAndEnabledItem()
+ public void CreateClearAllCalculationOutputInFailureMechanismItem_EnabledFuncTrue_CreatesDecoratedAndEnabledItem()
{
// Setup
var mocks = new MockRepository();
@@ -329,7 +257,7 @@
}
[Test]
- public void CreateClearAllCalculationOutputInFailureMechanismItem_FailureMechanismWithoutCalculationOutput_CreatesDecoratedAndDisabledItem()
+ public void CreateClearAllCalculationOutputInFailureMechanismItem_EnabledFuncFalse_CreatesDecoratedAndDisabledItem()
{
// Setup
var mocks = new MockRepository();