public void GivenCalculationsWithIllustrationPoints_WhenClearIllustrationPointsClickedAndContinue_ThenInquiryAndIllustrationPointsCleared( Func <IAssessmentSection, HydraulicBoundaryLocationCalculation> getHydraulicLocationCalculationFunc) { // Given var random = new Random(21); IAssessmentSection assessmentSection = GetConfiguredAssessmentSectionWithHydraulicBoundaryLocationCalculations(); HydraulicBoundaryLocationCalculation calculation = getHydraulicLocationCalculationFunc(assessmentSection); calculation.Output = new TestHydraulicBoundaryLocationCalculationOutput(random.NextDouble(), new TestGeneralResultSubMechanismIllustrationPoint()); HydraulicBoundaryLocationCalculation[] calculationsWithOutput = GetAllWaterLevelCalculationsWithOutput(assessmentSection).ToArray(); var messageBoxText = ""; DialogBoxHandler = (name, wnd) => { var helper = new MessageBoxTester(wnd); messageBoxText = helper.Text; helper.ClickOk(); }; var context = new WaterLevelCalculationsForNormTargetProbabilitiesGroupContext(new ObservableList <HydraulicBoundaryLocation>(), assessmentSection); var mockRepository = new MockRepository(); using (var treeViewControl = new TreeViewControl()) { var calculationObserver = mockRepository.StrictMock <IObserver>(); calculationObserver.Expect(o => o.UpdateObserver()); IGui gui = StubFactory.CreateGuiStub(mockRepository); gui.Stub(cmp => cmp.MainWindow).Return(mockRepository.Stub <IMainWindow>()); gui.Stub(cmp => cmp.Get(context, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); mockRepository.ReplayAll(); calculation.Attach(calculationObserver); using (var plugin = new RiskeerPlugin()) { TreeNodeInfo info = GetInfo(plugin); plugin.Gui = gui; using (ContextMenuStrip contextMenuAdapter = info.ContextMenuStrip(context, null, treeViewControl)) { // When contextMenuAdapter.Items[contextMenuClearIllustrationPointsIndex].PerformClick(); // Then const string expectedMessage = "Weet u zeker dat u alle berekende illustratiepunten bij 'Waterstanden bij vaste doelkans' wilt wissen?"; Assert.AreEqual(expectedMessage, messageBoxText); Assert.IsTrue(calculationsWithOutput.All(calc => calc.HasOutput)); Assert.IsFalse(calculation.Output.HasGeneralResult); } } } mockRepository.VerifyAll(); }
public void ContextMenuStrip_WaterLevelCalculationsWithoutIllustrationPoints_ContextMenuItemClearAllIllustrationPointsDisabled() { // Setup IAssessmentSection assessmentSection = GetConfiguredAssessmentSectionWithHydraulicBoundaryLocationCalculations(); var nodeData = new WaterLevelCalculationsForNormTargetProbabilitiesGroupContext(new ObservableList <HydraulicBoundaryLocation>(), assessmentSection); var mockRepository = new MockRepository(); using (var treeViewControl = new TreeViewControl()) { IGui gui = StubFactory.CreateGuiStub(mockRepository); gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); gui.Stub(cmp => cmp.MainWindow).Return(mockRepository.Stub <IMainWindow>()); mockRepository.ReplayAll(); using (var plugin = new RiskeerPlugin()) { TreeNodeInfo info = GetInfo(plugin); plugin.Gui = gui; // Call using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) { // Assert ToolStripItem contextMenuItem = contextMenu.Items[contextMenuClearIllustrationPointsIndex]; Assert.IsFalse(contextMenuItem.Enabled); } } } mockRepository.VerifyAll(); // Expect no calls on arguments }
public void ContextMenuStrip_Always_AddCustomItems() { // Setup IAssessmentSection assessmentSection = new AssessmentSectionStub(); var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); var nodeData = new WaterLevelCalculationsForNormTargetProbabilitiesGroupContext(new ObservableList <HydraulicBoundaryLocation>(), assessmentSection); var mockRepository = new MockRepository(); using (var treeViewControl = new TreeViewControl()) { IGui gui = StubFactory.CreateGuiStub(mockRepository); gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilder); gui.Stub(cmp => cmp.MainWindow).Return(mockRepository.Stub <IMainWindow>()); mockRepository.ReplayAll(); using (var plugin = new RiskeerPlugin()) { TreeNodeInfo info = GetInfo(plugin); plugin.Gui = gui; // Call using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, assessmentSection, treeViewControl)) { // Assert Assert.AreEqual(8, menu.Items.Count); TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuRunWaterLevelCalculationsIndex, "Alles be&rekenen", "Er is geen hydraulische belastingendatabase geïmporteerd.", RiskeerCommonFormsResources.CalculateAllIcon, false); TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuClearIllustrationPointsIndex, "Wis alle illustratiepunten...", "Er zijn geen berekeningen met illustratiepunten om te wissen.", RiskeerCommonFormsResources.ClearIllustrationPointsIcon, false); } } } // Assert mockRepository.VerifyAll(); }
public void ContextMenuStrip_Always_CallsContextMenuBuilderMethods() { // Setup IAssessmentSection assessmentSection = new AssessmentSectionStub(); var mockRepository = new MockRepository(); var menuBuilder = mockRepository.StrictMock <IContextMenuBuilder>(); using (mockRepository.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.AddCustomItem(null)).IgnoreArguments().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.Build()).Return(null); } var nodeData = new WaterLevelCalculationsForNormTargetProbabilitiesGroupContext(new ObservableList <HydraulicBoundaryLocation>(), assessmentSection); using (var treeViewControl = new TreeViewControl()) { IGui gui = StubFactory.CreateGuiStub(mockRepository); gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilder); gui.Stub(cmp => cmp.MainWindow).Return(mockRepository.Stub <IMainWindow>()); mockRepository.ReplayAll(); using (var plugin = new RiskeerPlugin()) { TreeNodeInfo info = GetInfo(plugin); plugin.Gui = gui; // Call info.ContextMenuStrip(nodeData, null, treeViewControl); } } // Assert mockRepository.VerifyAll(); }
public void ContextMenuStrip_WaterLevelCalculationsWithIllustrationPoints_ContextMenuItemClearAllIllustrationPointsEnabledAndTooltipSet( Func <IAssessmentSection, HydraulicBoundaryLocationCalculation> getHydraulicLocationCalculationFunc) { // Setup var random = new Random(21); IAssessmentSection assessmentSection = GetConfiguredAssessmentSectionWithHydraulicBoundaryLocationCalculations(); HydraulicBoundaryLocationCalculation calculation = getHydraulicLocationCalculationFunc(assessmentSection); calculation.Output = new TestHydraulicBoundaryLocationCalculationOutput(random.NextDouble(), new TestGeneralResultSubMechanismIllustrationPoint()); var nodeData = new WaterLevelCalculationsForNormTargetProbabilitiesGroupContext(new ObservableList <HydraulicBoundaryLocation>(), assessmentSection); var mockRepository = new MockRepository(); using (var treeViewControl = new TreeViewControl()) { IGui gui = StubFactory.CreateGuiStub(mockRepository); gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); gui.Stub(cmp => cmp.MainWindow).Return(mockRepository.Stub <IMainWindow>()); mockRepository.ReplayAll(); using (var plugin = new RiskeerPlugin()) { TreeNodeInfo info = GetInfo(plugin); plugin.Gui = gui; // Call using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) { // Assert ToolStripItem contextMenuItem = contextMenu.Items[contextMenuClearIllustrationPointsIndex]; Assert.AreEqual("Wis alle illustratiepunten...", contextMenuItem.Text); Assert.AreEqual("Wis alle berekende illustratiepunten.", contextMenuItem.ToolTipText); TestHelper.AssertImagesAreEqual(RiskeerCommonFormsResources.ClearIllustrationPointsIcon, contextMenuItem.Image); Assert.IsTrue(contextMenuItem.Enabled); } } } mockRepository.VerifyAll(); // Expect no calls on arguments }
public void ContextMenuStrip_AllRequiredInputSet_ContextMenuItemCalculateAllEnabled() { // Setup IAssessmentSection assessmentSection = new AssessmentSectionStub(); assessmentSection.HydraulicBoundaryDatabase.FilePath = Path.Combine(TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO, nameof(HydraulicBoundaryDatabase)), "complete.sqlite"); HydraulicBoundaryDatabaseTestHelper.SetHydraulicBoundaryLocationConfigurationSettings(assessmentSection.HydraulicBoundaryDatabase); var nodeData = new WaterLevelCalculationsForNormTargetProbabilitiesGroupContext(new ObservableList <HydraulicBoundaryLocation>(), assessmentSection); var mockRepository = new MockRepository(); using (var treeViewControl = new TreeViewControl()) { IGui gui = StubFactory.CreateGuiStub(mockRepository); gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); gui.Stub(cmp => cmp.MainWindow).Return(mockRepository.Stub <IMainWindow>()); mockRepository.ReplayAll(); using (var plugin = new RiskeerPlugin()) { TreeNodeInfo info = GetInfo(plugin); plugin.Gui = gui; // Call using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) { // Assert const string expectedItemText = "Alles be&rekenen"; const string expectedItemTooltip = "Alle waterstanden berekenen."; TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuRunWaterLevelCalculationsIndex, expectedItemText, expectedItemTooltip, RiskeerCommonFormsResources.CalculateAllIcon); } } } mockRepository.VerifyAll(); // Expect no calls on arguments }
public void Constructor_ExpectedValues() { // Setup var mockRepository = new MockRepository(); var assessmentSection = mockRepository.Stub <IAssessmentSection>(); mockRepository.ReplayAll(); var locations = new ObservableList <HydraulicBoundaryLocation>(); // Call var context = new WaterLevelCalculationsForNormTargetProbabilitiesGroupContext(locations, assessmentSection); // Assert Assert.IsInstanceOf <ObservableWrappedObjectContextBase <ObservableList <HydraulicBoundaryLocation> > >(context); Assert.AreSame(locations, context.WrappedData); Assert.AreSame(assessmentSection, context.AssessmentSection); mockRepository.VerifyAll(); }
public void ContextMenuStrip_HydraulicBoundaryDatabaseLinkedToInvalidFile_ContextMenuItemCalculateAllDisabledAndTooltipSet() { // Setup IAssessmentSection assessmentSection = new AssessmentSectionStub(); assessmentSection.HydraulicBoundaryDatabase.FilePath = "invalidFilePath"; var nodeData = new WaterLevelCalculationsForNormTargetProbabilitiesGroupContext(new ObservableList <HydraulicBoundaryLocation>(), assessmentSection); var mockRepository = new MockRepository(); using (var treeViewControl = new TreeViewControl()) { IGui gui = StubFactory.CreateGuiStub(mockRepository); gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); gui.Stub(cmp => cmp.MainWindow).Return(mockRepository.Stub <IMainWindow>()); mockRepository.ReplayAll(); using (var plugin = new RiskeerPlugin()) { TreeNodeInfo info = GetInfo(plugin); plugin.Gui = gui; // Call using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) { // Assert ToolStripItem contextMenuItem = contextMenu.Items[contextMenuRunWaterLevelCalculationsIndex]; Assert.AreEqual("Alles be&rekenen", contextMenuItem.Text); StringAssert.Contains("Herstellen van de verbinding met de hydraulische belastingendatabase is mislukt.", contextMenuItem.ToolTipText); TestHelper.AssertImagesAreEqual(RiskeerCommonFormsResources.CalculateAllIcon, contextMenuItem.Image); Assert.IsFalse(contextMenuItem.Enabled); } } } mockRepository.VerifyAll(); // Expect no calls on arguments }
public void CreateFileExporter_WithContext_ReturnFileExporter() { // Setup var assessmentSection = new AssessmentSectionStub(); var context = new WaterLevelCalculationsForNormTargetProbabilitiesGroupContext( new ObservableList <HydraulicBoundaryLocation>(), assessmentSection); const string filePath = "test"; using (var plugin = new RiskeerPlugin()) { ExportInfo info = GetExportInfo(plugin); // Call IFileExporter fileExporter = info.CreateFileExporter(context, filePath); // Assert Assert.IsInstanceOf <HydraulicBoundaryLocationCalculationsForTargetProbabilitiesExporter>(fileExporter); } }
public void ChildNodeObjects_Always_ReturnsChildrenOfData() { // Setup const double signalFloodingProbability = 0.002; const double maximumAllowableFloodingProbability = 0.005; var assessmentSection = new AssessmentSectionStub(); assessmentSection.FailureMechanismContribution.MaximumAllowableFloodingProbability = maximumAllowableFloodingProbability; assessmentSection.FailureMechanismContribution.SignalFloodingProbability = signalFloodingProbability; var locations = new ObservableList <HydraulicBoundaryLocation>(); var calculationsGroupContext = new WaterLevelCalculationsForNormTargetProbabilitiesGroupContext(locations, assessmentSection); using (var plugin = new RiskeerPlugin()) { TreeNodeInfo info = GetInfo(plugin); // Call object[] childNodeObjects = info.ChildNodeObjects(calculationsGroupContext); // Assert Assert.AreEqual(2, childNodeObjects.Length); WaterLevelCalculationsForNormTargetProbabilityContext[] calculationsContexts = childNodeObjects.OfType <WaterLevelCalculationsForNormTargetProbabilityContext>().ToArray(); Assert.AreEqual(2, calculationsContexts.Length); Assert.AreSame(assessmentSection.WaterLevelCalculationsForMaximumAllowableFloodingProbability, calculationsContexts[0].WrappedData); Assert.AreSame(assessmentSection, calculationsContexts[0].AssessmentSection); Assert.AreEqual(maximumAllowableFloodingProbability, calculationsContexts[0].GetNormFunc()); Assert.AreSame(assessmentSection.WaterLevelCalculationsForSignalFloodingProbability, calculationsContexts[1].WrappedData); Assert.AreSame(assessmentSection, calculationsContexts[1].AssessmentSection); Assert.AreEqual(signalFloodingProbability, calculationsContexts[1].GetNormFunc()); } }
public void GivenValidCalculations_WhenCalculatingAllFromContextMenu_ThenLogMessagesAddedOutputSet() { // Given const double signalFloodingProbability = 0.002; const double maximumAllowableFloodingProbability = 0.005; var mockRepository = new MockRepository(); var assessmentSection = new AssessmentSectionStub { HydraulicBoundaryDatabase = { FilePath = Path.Combine(testDataPath, "HRD ijsselmeer.sqlite") }, FailureMechanismContribution = { MaximumAllowableFloodingProbability = maximumAllowableFloodingProbability, SignalFloodingProbability = signalFloodingProbability } }; HydraulicBoundaryDatabaseTestHelper.SetHydraulicBoundaryLocationConfigurationSettings(assessmentSection.HydraulicBoundaryDatabase); var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation("locationName"); assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] { hydraulicBoundaryLocation }); var context = new WaterLevelCalculationsForNormTargetProbabilitiesGroupContext(new ObservableList <HydraulicBoundaryLocation>(), assessmentSection); using (var treeViewControl = new TreeViewControl()) { IMainWindow mainWindow = MainWindowTestHelper.CreateMainWindowStub(mockRepository); IGui gui = StubFactory.CreateGuiStub(mockRepository); gui.Stub(g => g.MainWindow).Return(mainWindow); gui.Stub(cmp => cmp.Get(context, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); gui.Stub(g => g.ProjectStore).Return(mockRepository.Stub <IStoreProject>()); gui.Stub(g => g.DocumentViewController).Return(mockRepository.Stub <IDocumentViewController>()); var designWaterLevelCalculator = new TestDesignWaterLevelCalculator { Converged = false }; var calculatorFactory = mockRepository.Stub <IHydraRingCalculatorFactory>(); calculatorFactory.Expect(cf => cf.CreateDesignWaterLevelCalculator(Arg <HydraRingCalculationSettings> .Is.NotNull)) .WhenCalled(invocation => { HydraRingCalculationSettingsTestHelper.AssertHydraRingCalculationSettings( HydraulicBoundaryCalculationSettingsFactory.CreateSettings(assessmentSection.HydraulicBoundaryDatabase), (HydraRingCalculationSettings)invocation.Arguments[0]); }) .Return(designWaterLevelCalculator) .Repeat .Times(2); mockRepository.ReplayAll(); DialogBoxHandler = (name, wnd) => { // Expect an activity dialog which is automatically closed }; using (var plugin = new RiskeerPlugin()) { TreeNodeInfo info = GetInfo(plugin); plugin.Gui = gui; plugin.Activate(); using (ContextMenuStrip contextMenuAdapter = info.ContextMenuStrip(context, null, treeViewControl)) using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { // When void Call() => contextMenuAdapter.Items[contextMenuRunWaterLevelCalculationsIndex].PerformClick(); // Then TestHelper.AssertLogMessages(Call, messages => { string[] msgs = messages.ToArray(); Assert.AreEqual(16, msgs.Length); const string calculationTypeDisplayName = "Waterstand"; const string calculationDisplayName = "Waterstand berekening"; HydraulicBoundaryLocationCalculationActivityLogTestHelper.AssertHydraulicBoundaryLocationCalculationMessages( hydraulicBoundaryLocation.Name, calculationTypeDisplayName, calculationDisplayName, "1/200", msgs, 0); HydraulicBoundaryLocationCalculationActivityLogTestHelper.AssertHydraulicBoundaryLocationCalculationMessages( hydraulicBoundaryLocation.Name, calculationTypeDisplayName, calculationDisplayName, "1/500", msgs, 8); }); AssertHydraulicBoundaryLocationCalculationOutput(designWaterLevelCalculator, assessmentSection.WaterLevelCalculationsForSignalFloodingProbability.Single().Output); AssertHydraulicBoundaryLocationCalculationOutput(designWaterLevelCalculator, assessmentSection.WaterLevelCalculationsForMaximumAllowableFloodingProbability.Single().Output); } } } mockRepository.VerifyAll(); }