public void ContextMenuStrip_ClickOnAddTargetProbabilityItem_CalculationsForTargetProbabilityAddedAndObserversNotified() { // Given var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike) { HydraulicBoundaryDatabase = { Locations = { new TestHydraulicBoundaryLocation("Location 1"), new TestHydraulicBoundaryLocation("Location 2") } } }; var calculations = new ObservableList <HydraulicBoundaryLocationCalculationsForTargetProbability>(); var context = new WaveHeightCalculationsForUserDefinedTargetProbabilitiesGroupContext(calculations, assessmentSection); var mockRepository = new MockRepository(); var calculationsObserver = mockRepository.StrictMock <IObserver>(); calculationsObserver.Expect(o => o.UpdateObserver()); calculations.Attach(calculationsObserver); 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>()); mockRepository.ReplayAll(); using (var plugin = new RiskeerPlugin()) { TreeNodeInfo info = GetInfo(plugin); plugin.Gui = gui; plugin.Activate(); using (ContextMenuStrip contextMenuAdapter = info.ContextMenuStrip(context, null, treeViewControl)) { // When contextMenuAdapter.Items[contextMenuAddTargetProbabilityIndex].PerformClick(); // Then Assert.AreEqual(1, calculations.Count); Assert.AreEqual(0.01, calculations[0].TargetProbability); Assert.AreEqual(2, calculations[0].HydraulicBoundaryLocationCalculations.Count); } } } mockRepository.VerifyAll(); }
public void AfterCreate_WithGuiSet_SetsSpecificPropertiesToView() { // Setup var mocks = new MockRepository(); IGui gui = StubFactory.CreateGuiStub(mocks); gui.Stub(g => g.ViewCommands).Return(mocks.Stub <IViewCommands>()); gui.Stub(g => g.MainWindow).Return(mocks.Stub <IMainWindow>()); gui.Stub(g => g.DocumentViewController).Return(mocks.Stub <IDocumentViewController>()); gui.Stub(g => g.ProjectStore).Return(mocks.Stub <IStoreProject>()); mocks.ReplayAll(); double GetNormFunc() => 0.01; var assessmentSection = new AssessmentSectionStub(); var calculations = new ObservableList <HydraulicBoundaryLocationCalculation>(); var context = new WaterLevelCalculationsForNormTargetProbabilityContext(calculations, assessmentSection, GetNormFunc); using (var view = new DesignWaterLevelCalculationsView(new ObservableList <HydraulicBoundaryLocationCalculation>(), new AssessmentSectionStub(), GetNormFunc, () => "1/100")) using (var plugin = new RiskeerPlugin()) { ViewInfo info = GetViewInfo(plugin); plugin.Gui = gui; plugin.Activate(); // Call info.AfterCreate(view, context); // Assert Assert.IsInstanceOf <IHydraulicBoundaryLocationCalculationGuiService>(view.CalculationGuiService); } mocks.VerifyAll(); }
public void GivenValidCalculations_WhenCalculatingAllFromContextMenu_ThenLogMessagesAddedOutputSet() { // Given var mockRepository = new MockRepository(); var assessmentSection = new AssessmentSectionStub { HydraulicBoundaryDatabase = { FilePath = Path.Combine(testDataPath, "HRD ijsselmeer.sqlite") } }; HydraulicBoundaryDatabaseTestHelper.SetHydraulicBoundaryLocationConfigurationSettings(assessmentSection.HydraulicBoundaryDatabase); var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation("locationName"); assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] { hydraulicBoundaryLocation }); var context = new WaveHeightCalculationsForUserDefinedTargetProbabilitiesGroupContext( assessmentSection.WaveHeightCalculationsForUserDefinedTargetProbabilities, 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 waveHeightCalculator = new TestWaveHeightCalculator { Converged = false }; var calculatorFactory = mockRepository.Stub <IHydraRingCalculatorFactory>(); calculatorFactory.Expect(cf => cf.CreateWaveHeightCalculator(Arg <HydraRingCalculationSettings> .Is.NotNull)) .WhenCalled(invocation => { HydraRingCalculationSettingsTestHelper.AssertHydraRingCalculationSettings( HydraulicBoundaryCalculationSettingsFactory.CreateSettings(assessmentSection.HydraulicBoundaryDatabase), (HydraRingCalculationSettings)invocation.Arguments[0]); }) .Return(waveHeightCalculator) .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[contextMenuRunWaveHeightCalculationsIndex].PerformClick(); // Then TestHelper.AssertLogMessages(Call, messages => { string[] msgs = messages.ToArray(); Assert.AreEqual(16, msgs.Length); const string calculationTypeDisplayName = "Golfhoogte"; const string calculationDisplayName = "Golfhoogte berekening"; HydraulicBoundaryLocationCalculationActivityLogTestHelper.AssertHydraulicBoundaryLocationCalculationMessages( hydraulicBoundaryLocation.Name, calculationTypeDisplayName, calculationDisplayName, "1/4.000", msgs, 0); HydraulicBoundaryLocationCalculationActivityLogTestHelper.AssertHydraulicBoundaryLocationCalculationMessages( hydraulicBoundaryLocation.Name, calculationTypeDisplayName, calculationDisplayName, "1/40.000", msgs, 8); }); AssertHydraulicBoundaryLocationCalculationOutput(waveHeightCalculator, assessmentSection.WaveHeightCalculationsForUserDefinedTargetProbabilities[0].HydraulicBoundaryLocationCalculations[0].Output); AssertHydraulicBoundaryLocationCalculationOutput(waveHeightCalculator, assessmentSection.WaveHeightCalculationsForUserDefinedTargetProbabilities[1].HydraulicBoundaryLocationCalculations[0].Output); } } } mockRepository.VerifyAll(); }
public void GivenValidCalculations_WhenCalculatingAllFromContextMenu_ThenAllCalculationsScheduled() { // Given string validFilePath = Path.Combine(testDataPath, "HRD dutch coast south.sqlite"); var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike) { HydraulicBoundaryDatabase = { FilePath = validFilePath } }; HydraulicBoundaryDatabaseTestHelper.SetHydraulicBoundaryLocationConfigurationSettings(assessmentSection.HydraulicBoundaryDatabase); SetHydraulicBoundaryLocationCalculationsForUserDefinedTargetProbabilities(assessmentSection); var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation("locationName"); assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] { hydraulicBoundaryLocation }); var context = new HydraulicBoundaryDatabaseContext(assessmentSection.HydraulicBoundaryDatabase, assessmentSection); using (var treeViewControl = new TreeViewControl()) using (var plugin = new RiskeerPlugin()) { IMainWindow mainWindow = MainWindowTestHelper.CreateMainWindowStub(mocks); IGui gui = StubFactory.CreateGuiStub(mocks); gui.Stub(g => g.MainWindow).Return(mainWindow); gui.Stub(cmp => cmp.Get(context, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); gui.Stub(g => g.DocumentViewController).Return(mocks.Stub <IDocumentViewController>()); gui.Stub(g => g.ViewCommands).Return(mocks.Stub <IViewCommands>()); gui.Stub(g => g.ProjectStore).Return(mocks.Stub <IStoreProject>()); var calculatorFactory = mocks.Stub <IHydraRingCalculatorFactory>(); var designWaterLevelCalculator = new TestDesignWaterLevelCalculator { Converged = false }; var waveHeightCalculator = new TestWaveHeightCalculator { Converged = false }; HydraulicBoundaryCalculationSettings expectedSettings = HydraulicBoundaryCalculationSettingsFactory.CreateSettings(assessmentSection.HydraulicBoundaryDatabase); calculatorFactory.Expect(cf => cf.CreateDesignWaterLevelCalculator(Arg <HydraRingCalculationSettings> .Is.NotNull)) .WhenCalled(invocation => { HydraRingCalculationSettingsTestHelper.AssertHydraRingCalculationSettings( expectedSettings, (HydraRingCalculationSettings)invocation.Arguments[0]); }) .Return(designWaterLevelCalculator) .Repeat .Times(4); calculatorFactory.Expect(cf => cf.CreateWaveHeightCalculator(Arg <HydraRingCalculationSettings> .Is.NotNull)) .WhenCalled(invocation => { HydraRingCalculationSettingsTestHelper.AssertHydraRingCalculationSettings( expectedSettings, (HydraRingCalculationSettings)invocation.Arguments[0]); }).Return(waveHeightCalculator) .Repeat .Times(2); mocks.ReplayAll(); TreeNodeInfo info = GetInfo(plugin); plugin.Gui = gui; plugin.Activate(); DialogBoxHandler = (name, wnd) => { // Expect an activity dialog which is automatically closed }; using (ContextMenuStrip contextMenuAdapter = info.ContextMenuStrip(context, null, treeViewControl)) using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { // When void Call() => contextMenuAdapter.Items[contextMenuCalculateAllIndex].PerformClick(); // Then TestHelper.AssertLogMessages(Call, messages => { string[] msgs = messages.ToArray(); Assert.AreEqual(48, msgs.Length); const string designWaterLevelCalculationTypeDisplayName = "Waterstand"; const string designWaterLevelCalculationDisplayName = "Waterstand berekening"; HydraulicBoundaryLocationCalculationActivityLogTestHelper.AssertHydraulicBoundaryLocationCalculationMessages( hydraulicBoundaryLocation.Name, designWaterLevelCalculationTypeDisplayName, designWaterLevelCalculationDisplayName, "1/30.000", msgs, 0); HydraulicBoundaryLocationCalculationActivityLogTestHelper.AssertHydraulicBoundaryLocationCalculationMessages( hydraulicBoundaryLocation.Name, designWaterLevelCalculationTypeDisplayName, designWaterLevelCalculationDisplayName, "1/30.000 (1)", msgs, 8); HydraulicBoundaryLocationCalculationActivityLogTestHelper.AssertHydraulicBoundaryLocationCalculationMessages( hydraulicBoundaryLocation.Name, designWaterLevelCalculationTypeDisplayName, designWaterLevelCalculationDisplayName, "1/10", msgs, 16); HydraulicBoundaryLocationCalculationActivityLogTestHelper.AssertHydraulicBoundaryLocationCalculationMessages( hydraulicBoundaryLocation.Name, designWaterLevelCalculationTypeDisplayName, designWaterLevelCalculationDisplayName, "1/100", msgs, 24); const string waveHeightCalculationTypeDisplayName = "Golfhoogte"; const string waveHeightCalculationDisplayName = "Golfhoogte berekening"; HydraulicBoundaryLocationCalculationActivityLogTestHelper.AssertHydraulicBoundaryLocationCalculationMessages( hydraulicBoundaryLocation.Name, waveHeightCalculationTypeDisplayName, waveHeightCalculationDisplayName, "1/40", msgs, 32); HydraulicBoundaryLocationCalculationActivityLogTestHelper.AssertHydraulicBoundaryLocationCalculationMessages( hydraulicBoundaryLocation.Name, waveHeightCalculationTypeDisplayName, waveHeightCalculationDisplayName, "1/400", msgs, 40); }); } } mocks.VerifyAll(); }