Exemple #1
0
        public void Finish_ValidMacroStabilityInwardsCalculationAndRan_NotifyObserversOfMacroStabilityInwardsCalculation()
        {
            // Setup
            var mocks    = new MockRepository();
            var observer = mocks.StrictMock <IObserver>();

            observer.Expect(o => o.UpdateObserver());
            mocks.ReplayAll();

            MacroStabilityInwardsCalculationScenario validMacroStabilityInwardsCalculation = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(new TestHydraulicBoundaryLocation());

            validMacroStabilityInwardsCalculation.Output = null;
            validMacroStabilityInwardsCalculation.Attach(observer);

            var activity = new MacroStabilityInwardsCalculationActivity(validMacroStabilityInwardsCalculation,
                                                                        new GeneralMacroStabilityInwardsInput(),
                                                                        AssessmentSectionTestHelper.GetTestAssessmentLevel());

            activity.Run();

            // Call
            activity.Finish();

            // Assert
            mocks.VerifyAll();
        }
        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);
                }
            }
        }
Exemple #3
0
        private static void AssertPropertyChangeWithOrWithoutCalculationOutput(
            Action <MacroStabilityInwardsCalculationRow> setProperty,
            Action <MacroStabilityInwardsCalculationScenario> assertions,
            bool hasOutput,
            bool expectUpdates)
        {
            // Setup
            var mockRepository = new MockRepository();
            var inputObserver  = mockRepository.StrictMock <IObserver>();

            if (expectUpdates)
            {
                inputObserver.Expect(o => o.UpdateObserver());
            }

            var calculationObserver = mockRepository.StrictMock <IObserver>();

            if (expectUpdates && hasOutput)
            {
                calculationObserver.Expect(o => o.UpdateObserver());
            }

            var handler = mockRepository.Stub <IObservablePropertyChangeHandler>();

            mockRepository.ReplayAll();

            MacroStabilityInwardsOutput assignedOutput = null;

            MacroStabilityInwardsCalculationScenario calculation = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(new TestHydraulicBoundaryLocation());

            if (hasOutput)
            {
                assignedOutput = MacroStabilityInwardsOutputTestFactory.CreateOutput();
            }

            calculation.Output = assignedOutput;

            var row = new MacroStabilityInwardsCalculationRow(calculation, handler);

            calculation.Attach(calculationObserver);
            calculation.InputParameters.Attach(inputObserver);

            // Call
            setProperty(row);

            // Assert
            assertions(calculation);
            if (expectUpdates)
            {
                Assert.IsNull(calculation.Output);
            }
            else
            {
                Assert.AreSame(assignedOutput, calculation.Output);
            }

            mockRepository.VerifyAll();
        }
        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 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);
                }
            }
        }