public void GivenCalculationWithOutput_WhenClearingOutputFromContextMenu_ThenCalculationOutputClearedAndNotified(bool confirm) { // Given using (var treeViewControl = new TreeViewControl()) { var calculation = new MacroStabilityInwardsCalculationScenario(); var failureMechanism = new MacroStabilityInwardsFailureMechanism(); var assessmentSection = mocks.Stub <IAssessmentSection>(); var calculationContext = new MacroStabilityInwardsCalculationScenarioContext(calculation, new CalculationGroup(), Enumerable.Empty <MacroStabilityInwardsSurfaceLine>(), Enumerable.Empty <MacroStabilityInwardsStochasticSoilModel>(), failureMechanism, assessmentSection); var gui = mocks.Stub <IGui>(); gui.Stub(cmp => cmp.Get(calculationContext, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); var observer = mocks.StrictMock <IObserver>(); if (confirm) { observer.Expect(o => o.UpdateObserver()); } mocks.ReplayAll(); plugin.Gui = gui; calculation.Output = MacroStabilityInwardsOutputTestFactory.CreateOutput(); calculation.Attach(observer); string messageBoxText = null, messageBoxTitle = null; DialogBoxHandler = (name, wnd) => { var messageBox = new MessageBoxTester(wnd); messageBoxText = messageBox.Text; messageBoxTitle = messageBox.Title; if (confirm) { messageBox.ClickOk(); } else { messageBox.ClickCancel(); } }; using (ContextMenuStrip contextMenuStrip = info.ContextMenuStrip(calculationContext, null, treeViewControl)) { // When contextMenuStrip.Items[contextMenuClearIndex].PerformClick(); // Then Assert.AreNotEqual(confirm, calculation.HasOutput); Assert.AreEqual("Bevestigen", messageBoxTitle); Assert.AreEqual("Weet u zeker dat u de uitvoer van deze berekening wilt wissen?", messageBoxText); } } }
public void CloseForData_ViewNotCorrespondingToRemovedCalculationScenarioContext_ReturnsFalse() { // Setup var assessmentSection = mocks.Stub <IAssessmentSection>(); mocks.ReplayAll(); var calculation = new MacroStabilityInwardsCalculationScenario(); var calculationToRemove = new MacroStabilityInwardsCalculationScenario(); var calculationScenarioContext = new MacroStabilityInwardsCalculationScenarioContext(calculationToRemove, new CalculationGroup(), Enumerable.Empty <MacroStabilityInwardsSurfaceLine>(), Enumerable.Empty <MacroStabilityInwardsStochasticSoilModel>(), new MacroStabilityInwardsFailureMechanism(), assessmentSection); using (var view = new MacroStabilityInwardsInputView(calculation, new GeneralMacroStabilityInwardsInput(), assessmentSection, GetHydraulicBoundaryLocationCalculation)) { // Call bool closeForData = info.CloseForData(view, calculationScenarioContext); // Assert Assert.IsFalse(closeForData); mocks.VerifyAll(); } }
public void ContextMenuStrip_MacroStabilityInwardsCalculationWithoutOutput_ContextMenuItemClearOutputDisabledAndTooltipSet() { // Setup using (var treeViewControl = new TreeViewControl()) { var calculation = new MacroStabilityInwardsCalculationScenario(); var failureMechanism = new MacroStabilityInwardsFailureMechanism(); var assessmentSection = mocks.Stub <IAssessmentSection>(); var nodeData = new MacroStabilityInwardsCalculationScenarioContext(calculation, new CalculationGroup(), Enumerable.Empty <MacroStabilityInwardsSurfaceLine>(), Enumerable.Empty <MacroStabilityInwardsStochasticSoilModel>(), failureMechanism, assessmentSection); var gui = mocks.Stub <IGui>(); gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); mocks.ReplayAll(); plugin.Gui = gui; // Call using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) { // Assert TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuClearIndex, "&Wis uitvoer...", "Deze berekening heeft geen uitvoer om te wissen.", RiskeerCommonFormsResources.ClearIcon, false); } } }
public void IsEnabled_CalculationWithOutput_ReturnTrue() { // Setup var assessmentSection = mocks.Stub <IAssessmentSection>(); mocks.ReplayAll(); var calculation = new MacroStabilityInwardsCalculationScenario { Output = MacroStabilityInwardsOutputTestFactory.CreateOutput() }; var context = new MacroStabilityInwardsCalculationScenarioContext(calculation, new CalculationGroup(), Enumerable.Empty <MacroStabilityInwardsSurfaceLine>(), Enumerable.Empty <MacroStabilityInwardsStochasticSoilModel>(), new MacroStabilityInwardsFailureMechanism(), assessmentSection); // Call bool isEnabled = info.IsEnabled(context); // Assert Assert.IsTrue(isEnabled); }
public void ContextMenuStrip_Always_CallsContextMenuBuilderMethods() { // Setup using (var treeViewControl = new TreeViewControl()) { var failureMechanism = new MacroStabilityInwardsFailureMechanism(); var assessmentSection = mocks.Stub <IAssessmentSection>(); var nodeData = new MacroStabilityInwardsCalculationScenarioContext(new MacroStabilityInwardsCalculationScenario(), new CalculationGroup(), Enumerable.Empty <MacroStabilityInwardsSurfaceLine>(), Enumerable.Empty <MacroStabilityInwardsStochasticSoilModel>(), failureMechanism, assessmentSection); var menuBuilder = mocks.StrictMock <IContextMenuBuilder>(); using (mocks.Ordered()) { menuBuilder.Expect(mb => mb.AddExportItem()).Return(menuBuilder); menuBuilder.Expect(mb => mb.AddSeparator()).Return(menuBuilder); menuBuilder.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilder); menuBuilder.Expect(mb => mb.AddSeparator()).Return(menuBuilder); menuBuilder.Expect(mb => mb.AddRenameItem()).Return(menuBuilder); menuBuilder.Expect(mb => mb.AddSeparator()).Return(menuBuilder); menuBuilder.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilder); menuBuilder.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilder); menuBuilder.Expect(mb => mb.AddSeparator()).Return(menuBuilder); menuBuilder.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilder); menuBuilder.Expect(mb => mb.AddDeleteItem()).Return(menuBuilder); menuBuilder.Expect(mb => mb.AddSeparator()).Return(menuBuilder); menuBuilder.Expect(mb => mb.AddCollapseAllItem()).Return(menuBuilder); menuBuilder.Expect(mb => mb.AddExpandAllItem()).Return(menuBuilder); menuBuilder.Expect(mb => mb.AddSeparator()).Return(menuBuilder); menuBuilder.Expect(mb => mb.AddPropertiesItem()).Return(menuBuilder); menuBuilder.Expect(mb => mb.Build()).Return(null); } var gui = mocks.Stub <IGui>(); gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilder); mocks.ReplayAll(); plugin.Gui = gui; // Call info.ContextMenuStrip(nodeData, null, treeViewControl); } // Assert // Assert expectancies are called in TearDown() }
public void ContextMenuStrip_AllRequiredInputSet_ContextMenuItemCalculateAndValidateEnabled() { // Setup using (var treeViewControl = new TreeViewControl()) { var calculation = new MacroStabilityInwardsCalculationScenario(); var failureMechanism = new MacroStabilityInwardsFailureMechanism(); var assessmentSection = mocks.Stub <IAssessmentSection>(); var nodeData = new MacroStabilityInwardsCalculationScenarioContext(calculation, new CalculationGroup(), Enumerable.Empty <MacroStabilityInwardsSurfaceLine>(), Enumerable.Empty <MacroStabilityInwardsStochasticSoilModel>(), failureMechanism, assessmentSection); var gui = mocks.Stub <IGui>(); gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); mocks.ReplayAll(); plugin.Gui = gui; // Call using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) { // Assert TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuDuplicateIndex, "D&upliceren", "Dupliceer dit element.", RiskeerCommonFormsResources.CopyHS); TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuValidateIndex, "&Valideren", "Valideer de invoer voor deze berekening.", RiskeerCommonFormsResources.ValidateIcon); TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuCalculateIndex, "Be&rekenen", "Voer deze berekening uit.", RiskeerCommonFormsResources.CalculateIcon); } } }
public void OnNodeRemoved_ParentIsCalculationGroupContext_RemoveCalculationFromGroup() { // Setup var observer = mocks.StrictMock <IObserver>(); observer.Expect(o => o.UpdateObserver()); var elementToBeRemoved = new MacroStabilityInwardsCalculationScenario(); var group = new CalculationGroup(); group.Children.Add(elementToBeRemoved); group.Children.Add(new MacroStabilityInwardsCalculationScenario()); group.Attach(observer); var failureMechanism = new MacroStabilityInwardsFailureMechanism(); var assessmentSection = mocks.Stub <IAssessmentSection>(); mocks.ReplayAll(); var calculationContext = new MacroStabilityInwardsCalculationScenarioContext(elementToBeRemoved, group, Enumerable.Empty <MacroStabilityInwardsSurfaceLine>(), Enumerable.Empty <MacroStabilityInwardsStochasticSoilModel>(), failureMechanism, assessmentSection); var groupContext = new MacroStabilityInwardsCalculationGroupContext(group, null, Enumerable.Empty <MacroStabilityInwardsSurfaceLine>(), Enumerable.Empty <MacroStabilityInwardsStochasticSoilModel>(), failureMechanism, assessmentSection); // Precondition Assert.IsTrue(info.CanRemove(calculationContext, groupContext)); Assert.AreEqual(2, group.Children.Count); // Call info.OnNodeRemoved(calculationContext, groupContext); // Assert Assert.AreEqual(1, group.Children.Count); CollectionAssert.DoesNotContain(group.Children, elementToBeRemoved); }
public void ChildNodeObjects_Always_ReturnOutputChildNode() { // Setup var calculation = new MacroStabilityInwardsCalculationScenario(); var failureMechanism = new MacroStabilityInwardsFailureMechanism(); var assessmentSection = mocks.Stub <IAssessmentSection>(); mocks.ReplayAll(); var calculationContext = new MacroStabilityInwardsCalculationScenarioContext(calculation, new CalculationGroup(), new[] { new MacroStabilityInwardsSurfaceLine(string.Empty) }, new[] { MacroStabilityInwardsStochasticSoilModelTestFactory.CreateValidStochasticSoilModel() }, failureMechanism, assessmentSection); // Call object[] children = info.ChildNodeObjects(calculationContext).ToArray(); // Assert Assert.AreEqual(3, children.Length); var comment = (Comment)children[0]; Assert.AreSame(calculationContext.WrappedData.Comments, comment); var inputContext = (MacroStabilityInwardsInputContext)children[1]; Assert.AreSame(calculationContext.WrappedData.InputParameters, inputContext.WrappedData); CollectionAssert.AreEqual(calculationContext.AvailableMacroStabilityInwardsSurfaceLines, inputContext.AvailableMacroStabilityInwardsSurfaceLines); CollectionAssert.AreEqual(calculationContext.AvailableStochasticSoilModels, inputContext.AvailableStochasticSoilModels); var outputContext = (MacroStabilityInwardsOutputContext)children[2]; Assert.AreSame(calculationContext.WrappedData, outputContext.WrappedData); Assert.AreSame(calculationContext.FailureMechanism, outputContext.FailureMechanism); Assert.AreSame(calculationContext.AssessmentSection, outputContext.AssessmentSection); }
public void GivenInvalidCalculation_WhenValidatingFromContextMenu_ThenLogMessageAddedAndNoNotifyObserver() { // Given using (var treeViewControl = new TreeViewControl()) { var calculation = new MacroStabilityInwardsCalculationScenario(); var failureMechanism = new MacroStabilityInwardsFailureMechanism(); var assessmentSection = new AssessmentSectionStub(); var calculationContext = new MacroStabilityInwardsCalculationScenarioContext(calculation, new CalculationGroup(), Enumerable.Empty <MacroStabilityInwardsSurfaceLine>(), Enumerable.Empty <MacroStabilityInwardsStochasticSoilModel>(), failureMechanism, assessmentSection); var gui = mocks.Stub <IGui>(); gui.Stub(cmp => cmp.Get(calculationContext, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); var observer = mocks.StrictMock <IObserver>(); observer.Expect(o => o.UpdateObserver()).Repeat.Never(); mocks.ReplayAll(); plugin.Gui = gui; calculation.Attach(observer); using (ContextMenuStrip contextMenuStrip = info.ContextMenuStrip(calculationContext, null, treeViewControl)) using (new MacroStabilityInwardsCalculatorFactoryConfig()) { // When void Action() => contextMenuStrip.Items[contextMenuValidateIndex].PerformClick(); // Then const int expectedValidationMessageCount = 3; const int expectedStatusMessageCount = 2; const int expectedLogMessageCount = expectedValidationMessageCount + expectedStatusMessageCount; TestHelper.AssertLogMessagesCount(Action, expectedLogMessageCount); } } }
public void CreateFileExporter_Always_ReturnFileExporter() { // Setup var assessmentSection = mocks.Stub <IAssessmentSection>(); mocks.ReplayAll(); var context = new MacroStabilityInwardsCalculationScenarioContext(new MacroStabilityInwardsCalculationScenario(), new CalculationGroup(), Enumerable.Empty <MacroStabilityInwardsSurfaceLine>(), Enumerable.Empty <MacroStabilityInwardsStochasticSoilModel>(), new MacroStabilityInwardsFailureMechanism(), assessmentSection); // Call IFileExporter fileExporter = info.CreateFileExporter(context, "test"); // Assert Assert.IsInstanceOf <MacroStabilityInwardsCalculationConfigurationExporter>(fileExporter); }
public void ConstructorWithData_Always_ExpectedPropertiesSet() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub <IAssessmentSection>(); mocks.ReplayAll(); var surfaceLines = new[] { new MacroStabilityInwardsSurfaceLine(string.Empty) }; MacroStabilityInwardsStochasticSoilModel[] soilModels = { MacroStabilityInwardsStochasticSoilModelTestFactory.CreateValidStochasticSoilModel() }; var calculation = new MacroStabilityInwardsCalculationScenario(); var failureMechanism = new MacroStabilityInwardsFailureMechanism(); var parent = new CalculationGroup(); // Call var presentationObject = new MacroStabilityInwardsCalculationScenarioContext(calculation, parent, surfaceLines, soilModels, failureMechanism, assessmentSection); // Assert Assert.IsInstanceOf <MacroStabilityInwardsContext <MacroStabilityInwardsCalculationScenario> >(presentationObject); Assert.IsInstanceOf <ICalculationContext <MacroStabilityInwardsCalculationScenario, MacroStabilityInwardsFailureMechanism> >(presentationObject); Assert.AreSame(calculation, presentationObject.WrappedData); Assert.AreSame(parent, presentationObject.Parent); Assert.AreSame(surfaceLines, presentationObject.AvailableMacroStabilityInwardsSurfaceLines); Assert.AreSame(soilModels, presentationObject.AvailableStochasticSoilModels); Assert.AreSame(failureMechanism, presentationObject.FailureMechanism); Assert.AreSame(assessmentSection, presentationObject.AssessmentSection); mocks.VerifyAll(); }
public void GivenValidCalculation_WhenCalculatingFromContextMenu_ThenCalculationNotifiesObservers() { // Given using (var treeViewControl = new TreeViewControl()) { var failureMechanism = new MacroStabilityInwardsFailureMechanism(); var assessmentSection = new AssessmentSectionStub(); var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(); assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] { hydraulicBoundaryLocation }, true); MacroStabilityInwardsCalculationScenario calculation = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(hydraulicBoundaryLocation); var calculationContext = new MacroStabilityInwardsCalculationScenarioContext(calculation, new CalculationGroup(), Enumerable.Empty <MacroStabilityInwardsSurfaceLine>(), Enumerable.Empty <MacroStabilityInwardsStochasticSoilModel>(), failureMechanism, assessmentSection); IMainWindow mainWindow = MainWindowTestHelper.CreateMainWindowStub(mocks); var gui = mocks.Stub <IGui>(); gui.Stub(g => g.MainWindow).Return(mainWindow); gui.Stub(g => g.Get(calculationContext, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); var observer = mocks.StrictMock <IObserver>(); observer.Expect(o => o.UpdateObserver()); mocks.ReplayAll(); plugin.Gui = gui; calculation.Attach(observer); DialogBoxHandler = (name, wnd) => { // Expect an activity dialog which is automatically closed }; using (new MacroStabilityInwardsCalculatorFactoryConfig()) using (ContextMenuStrip contextMenuAdapter = info.ContextMenuStrip(calculationContext, null, treeViewControl)) { // When void Action() => contextMenuAdapter.Items[contextMenuCalculateIndex].PerformClick(); // Then TestHelper.AssertLogMessages(Action, messages => { using (IEnumerator <string> msgs = messages.GetEnumerator()) { Assert.IsTrue(msgs.MoveNext()); Assert.AreEqual($"Uitvoeren van berekening '{calculation.Name}' is gestart.", msgs.Current); Assert.IsTrue(msgs.MoveNext()); CalculationServiceTestHelper.AssertValidationStartMessage(msgs.Current); Assert.IsTrue(msgs.MoveNext()); Assert.AreEqual("Validatie van waterspanningen in extreme omstandigheden is gestart.", msgs.Current); Assert.IsTrue(msgs.MoveNext()); Assert.AreEqual("Validatie van waterspanningen in dagelijkse omstandigheden is gestart.", msgs.Current); Assert.IsTrue(msgs.MoveNext()); CalculationServiceTestHelper.AssertValidationEndMessage(msgs.Current); Assert.IsTrue(msgs.MoveNext()); CalculationServiceTestHelper.AssertCalculationStartMessage(msgs.Current); Assert.IsTrue(msgs.MoveNext()); CalculationServiceTestHelper.AssertCalculationEndMessage(msgs.Current); Assert.IsTrue(msgs.MoveNext()); Assert.AreEqual($"Uitvoeren van berekening '{calculation.Name}' is gelukt.", msgs.Current); } }); Assert.IsNotNull(calculation.Output); } } }
public void GivenInvalidCalculation_WhenCalculatingFromContextMenu_ThenCalculationNotifiesObserversAndLogMessageAdded() { // Given using (var treeViewControl = new TreeViewControl()) { var calculation = new MacroStabilityInwardsCalculationScenario(); var failureMechanism = new MacroStabilityInwardsFailureMechanism(); var assessmentSection = new AssessmentSectionStub(); var calculationContext = new MacroStabilityInwardsCalculationScenarioContext(calculation, new CalculationGroup(), Enumerable.Empty <MacroStabilityInwardsSurfaceLine>(), Enumerable.Empty <MacroStabilityInwardsStochasticSoilModel>(), failureMechanism, assessmentSection); IMainWindow mainWindow = MainWindowTestHelper.CreateMainWindowStub(mocks); var gui = mocks.Stub <IGui>(); gui.Stub(g => g.MainWindow).Return(mainWindow); gui.Stub(cmp => cmp.Get(calculationContext, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); var observer = mocks.StrictMock <IObserver>(); observer.Expect(o => o.UpdateObserver()); mocks.ReplayAll(); plugin.Gui = gui; calculation.Attach(observer); DialogBoxHandler = (name, wnd) => { // Expect an activity dialog which is automatically closed }; using (ContextMenuStrip contextMenuStrip = info.ContextMenuStrip(calculationContext, null, treeViewControl)) { // When void Action() => contextMenuStrip.Items[contextMenuCalculateIndex].PerformClick(); // Then const int expectedValidationMessageCount = 3; TestHelper.AssertLogMessagesWithLevelAndLoggedExceptions(Action, messages => { Tuple <string, Level, Exception>[] tupleArray = messages.ToArray(); string[] msgs = tupleArray.Select(tuple => tuple.Item1).ToArray(); Assert.AreEqual($"Uitvoeren van berekening '{calculation.Name}' is gestart.", msgs[0]); CalculationServiceTestHelper.AssertValidationStartMessage(msgs[1]); for (var i = 0; i < expectedValidationMessageCount; i++) { Assert.AreEqual(Level.Error, tupleArray[2 + i].Item2); } CalculationServiceTestHelper.AssertValidationEndMessage(msgs[5]); Assert.AreEqual($"Uitvoeren van berekening '{calculation.Name}' is mislukt.", msgs[6]); }); Assert.IsNull(calculation.Output); } } }