public void MessageBoxOkHandler(string name, System.IntPtr hWnd)
 {
     MessageBoxTester messageBox = new MessageBoxTester(hWnd);
     Assert.Equal("test string", messageBox.Text);
     Assert.Equal("caption", messageBox.Title);
     messageBox.ClickOk();
 }
 public void SimpleOKHandler(string name, System.IntPtr hWnd)
 {
     MessageBoxTester messageBox = new MessageBoxTester(hWnd);
     Assert.Equal("Just An OK Button", messageBox.Text);
     Assert.Equal("JustOK", messageBox.Title);
     messageBox.SendCommand(MessageBoxTester.Command.OK);
 }
        public void MessageBoxCancelHandler(string name, System.IntPtr hWnd)
        {
            MessageBoxTester messageBox = new MessageBoxTester(hWnd);

            Assert.Equal("test string", messageBox.Text);
            Assert.Equal("caption", messageBox.Title);
            messageBox.ClickCancel();
        }
        public void SimpleOKHandler(string name, System.IntPtr hWnd)
        {
            MessageBoxTester messageBox = new MessageBoxTester(hWnd);

            Assert.Equal("Just An OK Button", messageBox.Text);
            Assert.Equal("JustOK", messageBox.Title);
            messageBox.SendCommand(MessageBoxTester.Command.OK);
        }
Esempio n. 5
0
        public void MessageBoxCancelHandler()
        {
            MessageBoxTester messageBox = new MessageBoxTester("caption");

            Assert.AreEqual("test string", messageBox.Text);
            Assert.AreEqual("caption", messageBox.Title);
            messageBox.ClickCancel();
        }
        public void CalculationsView_EditingPropertyViaDataGridView_ObserversCorrectlyNotified(
            int cellIndex,
            object newValue,
            bool useCalculationWithOutput)
        {
            // Setup
            var mocks = new MockRepository();
            var calculationObserver = mocks.StrictMock <IObserver>();
            var inputObserver       = mocks.StrictMock <IObserver>();

            if (useCalculationWithOutput)
            {
                DialogBoxHandler = (name, wnd) =>
                {
                    var tester = new MessageBoxTester(wnd);
                    tester.ClickOk();
                };

                calculationObserver.Expect(o => o.UpdateObserver());
            }

            inputObserver.Expect(o => o.UpdateObserver());

            var assessmentSection = mocks.Stub <IAssessmentSection>();

            ConfigureHydraulicBoundaryDatabase(assessmentSection);
            assessmentSection.Stub(a => a.Attach(null)).IgnoreArguments();
            assessmentSection.Stub(a => a.Detach(null)).IgnoreArguments();
            assessmentSection.Replay();

            GrassCoverErosionInwardsFailureMechanism failureMechanism = ConfigureFailureMechanism();
            CalculationGroup calculationGroup = ConfigureCalculationGroup(failureMechanism, assessmentSection);

            ShowCalculationsView(calculationGroup, failureMechanism, assessmentSection);

            mocks.ReplayAll();

            var calculationScenario = (GrassCoverErosionInwardsCalculationScenario)calculationGroup.Children[1];

            if (useCalculationWithOutput)
            {
                calculationScenario.Output = new GrassCoverErosionInwardsOutput(new TestOvertoppingOutput(2.4),
                                                                                new TestDikeHeightOutput(4.2),
                                                                                new TestOvertoppingRateOutput(1.0));
            }

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

            var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject;

            // Call
            dataGridView.Rows[1].Cells[cellIndex].Value = newValue is double value ? (RoundedDouble)value : newValue;

            // Assert
            calculationScenario.Output = null;
            mocks.VerifyAll();
        }
        public void GivenCalculationsWithoutOutput_WhenChangingProbability_ThenActionPerformedAndContributionNotified(
            NormativeProbabilityType normativeProbabilityType, Func <AssessmentSection, IEnumerable <HydraulicBoundaryLocationCalculation> > getLocationCalculationsFunc,
            WaveConditionsInputWaterLevelType waterLevelType)
        {
            // Given
            DialogBoxHandler = (name, wnd) =>
            {
                var tester = new MessageBoxTester(wnd);
                tester.ClickOk();
            };

            AssessmentSection assessmentSection = TestDataGenerator.GetAssessmentSectionWithAllCalculationConfigurations();

            assessmentSection.FailureMechanismContribution.NormativeProbabilityType = normativeProbabilityType;

            IEnumerable <HydraulicBoundaryLocationCalculation> calculationsBelongingToNorm = getLocationCalculationsFunc(assessmentSection);

            var waveConditionsCalculations = new List <ICalculation <WaveConditionsInput> >();

            waveConditionsCalculations.AddRange(assessmentSection.GrassCoverErosionOutwards.Calculations
                                                .Cast <GrassCoverErosionOutwardsWaveConditionsCalculation>());
            waveConditionsCalculations.AddRange(assessmentSection.StabilityStoneCover.Calculations
                                                .Cast <StabilityStoneCoverWaveConditionsCalculation>());
            waveConditionsCalculations.AddRange(assessmentSection.WaveImpactAsphaltCover.Calculations
                                                .Cast <WaveImpactAsphaltCoverWaveConditionsCalculation>());

            var mocks    = new MockRepository();
            var observer = mocks.StrictMock <IObserver>();

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

            calculationsBelongingToNorm.ForEachElementDo(c =>
            {
                c.Output = null;
                c.Attach(observer);
            });
            waveConditionsCalculations.ForEachElementDo(c =>
            {
                c.InputParameters.WaterLevelType = waterLevelType;
                c.ClearOutput();
                c.Attach(observer);
            });

            assessmentSection.FailureMechanismContribution.Attach(observer);

            var handler = new FailureMechanismContributionNormChangeHandler(assessmentSection);

            // When
            var actionPerformed = false;

            void Call() => handler.ChangeProbability(() => actionPerformed = true);

            // Then
            TestHelper.AssertLogMessagesCount(Call, 0);
            Assert.IsTrue(actionPerformed);
            mocks.VerifyAll();
        }
Esempio n. 8
0
        public void VerifyUpdates_CalculationWithOutputs_AlwaysReturnsExpectedInquiryMessage(bool isActionConfirmed)
        {
            // Setup
            var mocks      = new MockRepository();
            var mainWindow = mocks.Stub <IMainWindow>();
            var gui        = mocks.Stub <IGui>();

            gui.Stub(g => g.MainWindow).Return(mainWindow);
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            mocks.ReplayAll();

            TestPipingFailureMechanism failureMechanism = TestPipingFailureMechanism.GetFailureMechanismWithSurfaceLinesAndStochasticSoilModels();
            var calculationWithOutput = new ProbabilisticPipingCalculationScenario
            {
                Output = PipingTestDataGenerator.GetRandomProbabilisticPipingOutputWithIllustrationPoints()
            };

            failureMechanism.CalculationsGroup.Children.Add(calculationWithOutput);

            var context = new PipingFailureMechanismSectionsContext(failureMechanism, assessmentSection);

            using (var plugin = new PipingPlugin())
            {
                plugin.Gui = gui;

                string textBoxMessage = null;
                DialogBoxHandler = (name, wnd) =>
                {
                    var helper = new MessageBoxTester(wnd);
                    textBoxMessage = helper.Text;

                    if (isActionConfirmed)
                    {
                        helper.ClickOk();
                    }
                    else
                    {
                        helper.ClickCancel();
                    }
                };

                UpdateInfo updateInfo = GetUpdateInfo(plugin);

                // Call
                bool updatesVerified = updateInfo.VerifyUpdates(context);

                // Assert
                string expectedInquiryMessage = "Als u de vakindeling wijzigt, dan worden de resultaten van alle probabilistische piping berekeningen verwijderd." +
                                                $"{Environment.NewLine}{Environment.NewLine}Weet u zeker dat u wilt doorgaan?";
                Assert.AreEqual(expectedInquiryMessage, textBoxMessage);
                Assert.AreEqual(isActionConfirmed, updatesVerified);
            }

            mocks.VerifyAll();
        }
        public void SetPropertyValueAfterConfirmation_CalculationsForTargetProbabilityWithAndWithoutOutput_AllCalculationOutputClearedAndReturnsAllAffectedObjects()
        {
            // Setup
            DialogBoxHandler = (name, wnd) =>
            {
                var tester = new MessageBoxTester(wnd);
                tester.ClickOk();
            };

            AssessmentSection assessmentSection = TestDataGenerator.GetAssessmentSectionWithAllCalculationConfigurations();

            HydraulicBoundaryLocationCalculationsForTargetProbability calculationsForTargetProbability = assessmentSection.WaterLevelCalculationsForUserDefinedTargetProbabilities
                                                                                                         .First();

            var waveConditionsCalculations = new List <ICalculation <WaveConditionsInput> >();

            waveConditionsCalculations.AddRange(assessmentSection.GrassCoverErosionOutwards.Calculations
                                                .Cast <GrassCoverErosionOutwardsWaveConditionsCalculation>());
            waveConditionsCalculations.AddRange(assessmentSection.StabilityStoneCover.Calculations
                                                .Cast <StabilityStoneCoverWaveConditionsCalculation>());
            waveConditionsCalculations.AddRange(assessmentSection.WaveImpactAsphaltCover.Calculations
                                                .Cast <WaveImpactAsphaltCoverWaveConditionsCalculation>());

            waveConditionsCalculations.ForEachElementDo(c =>
            {
                c.InputParameters.WaterLevelType = WaveConditionsInputWaterLevelType.UserDefinedTargetProbability;
                c.InputParameters.CalculationsTargetProbability = calculationsForTargetProbability;
            });

            var expectedAffectedObjects = new List <IObservable>
            {
                calculationsForTargetProbability
            };

            expectedAffectedObjects.AddRange(calculationsForTargetProbability.HydraulicBoundaryLocationCalculations.Where(c => c.HasOutput));
            expectedAffectedObjects.AddRange(waveConditionsCalculations.Where(c => c.HasOutput));

            var handler = new WaterLevelHydraulicBoundaryLocationCalculationsForTargetProbabilityChangeHandler(calculationsForTargetProbability, assessmentSection);

            IEnumerable <IObservable> affectedObjects = null;

            // Call
            void Call() => affectedObjects = handler.SetPropertyValueAfterConfirmation(() => {});

            // Assert
            var expectedMessages = new[]
            {
                "Alle bijbehorende hydraulische belastingen zijn verwijderd."
            };

            TestHelper.AssertLogMessagesAreGenerated(Call, expectedMessages, 1);
            CollectionAssert.AreEquivalent(expectedAffectedObjects, affectedObjects);
            CollectionAssert.IsEmpty(calculationsForTargetProbability.HydraulicBoundaryLocationCalculations.Where(c => c.HasOutput));
            CollectionAssert.IsEmpty(waveConditionsCalculations.Where(c => c.HasOutput));
        }
        public void VerifyUpdates_CalculationWithOutputs_AlwaysReturnsExpectedInquiryMessage(bool isActionConfirmed)
        {
            // Setup
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            var mainWindow = mocks.Stub <IMainWindow>();
            var gui        = mocks.Stub <IGui>();

            gui.Stub(g => g.MainWindow).Return(mainWindow);
            mocks.ReplayAll();

            using (var plugin = new GrassCoverErosionInwardsPlugin())
            {
                plugin.Gui = gui;

                var failureMechanism = new GrassCoverErosionInwardsFailureMechanism();
                failureMechanism.CalculationsGroup.Children.Add(new GrassCoverErosionInwardsCalculation
                {
                    Output = new TestGrassCoverErosionInwardsOutput()
                });

                var dikeProfiles = new DikeProfileCollection();
                var context      = new DikeProfilesContext(dikeProfiles, failureMechanism, assessmentSection);

                UpdateInfo updateInfo = GetUpdateInfo(plugin);

                string textBoxMessage = null;
                DialogBoxHandler = (name, wnd) =>
                {
                    var helper = new MessageBoxTester(wnd);
                    textBoxMessage = helper.Text;

                    if (isActionConfirmed)
                    {
                        helper.ClickOk();
                    }
                    else
                    {
                        helper.ClickCancel();
                    }
                };

                // Call
                bool updatesVerified = updateInfo.VerifyUpdates(context);

                // Assert
                string expectedInquiryMessage = "Als dijkprofielen wijzigen door het bijwerken, " +
                                                "dan worden de resultaten van berekeningen die deze dijkprofielen gebruiken " +
                                                $"verwijderd.{Environment.NewLine}{Environment.NewLine}Weet u zeker dat u wilt doorgaan?";
                Assert.AreEqual(expectedInquiryMessage, textBoxMessage);
                Assert.AreEqual(isActionConfirmed, updatesVerified);
                mocks.VerifyAll();
            }
        }
Esempio n. 11
0
        public void VerifyUpdates_CalculationWithOutputs_AlwaysReturnsExpectedInquiryMessage(bool isActionConfirmed)
        {
            // Setup
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            var mainWindow = mocks.Stub <IMainWindow>();
            var gui        = mocks.Stub <IGui>();

            gui.Stub(g => g.MainWindow).Return(mainWindow);
            mocks.ReplayAll();

            plugin.Gui = gui;

            var failureMechanism      = new MacroStabilityInwardsFailureMechanism();
            var calculationWithOutput = new MacroStabilityInwardsCalculationScenario
            {
                Output = MacroStabilityInwardsOutputTestFactory.CreateOutput()
            };

            failureMechanism.CalculationsGroup.Children.Add(calculationWithOutput);

            var stochasticSoilModelCollection = new MacroStabilityInwardsStochasticSoilModelCollection();
            var context = new MacroStabilityInwardsStochasticSoilModelCollectionContext(stochasticSoilModelCollection, failureMechanism, assessmentSection);

            string textBoxMessage = null;

            DialogBoxHandler = (name, wnd) =>
            {
                var helper = new MessageBoxTester(wnd);
                textBoxMessage = helper.Text;

                if (isActionConfirmed)
                {
                    helper.ClickOk();
                }
                else
                {
                    helper.ClickCancel();
                }
            };

            // Call
            bool updatesVerified = importInfo.VerifyUpdates(context);

            // Assert
            string expectedInquiryMessage = "Als u stochastische ondergrondmodellen importeert, " +
                                            "dan worden alle rekenresultaten van dit faalmechanisme verwijderd." +
                                            $"{Environment.NewLine}{Environment.NewLine}Weet u zeker dat u wilt doorgaan?";

            Assert.AreEqual(expectedInquiryMessage, textBoxMessage);
            Assert.AreEqual(isActionConfirmed, updatesVerified);
            mocks.VerifyAll();
        }
Esempio n. 12
0
        public void VerifyUpdates_CalculationWithOutputs_AlwaysReturnsExpectedInquiryMessage(bool isActionConfirmed)
        {
            // Setup
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();
            var mainWindow        = mocks.Stub <IMainWindow>();
            var gui = mocks.Stub <IGui>();

            gui.Stub(g => g.MainWindow).Return(mainWindow);
            mocks.ReplayAll();

            var failureMechanism = new StabilityPointStructuresFailureMechanism();

            failureMechanism.CalculationsGroup.Children.Add(new StructuresCalculation <StabilityPointStructuresInput>
            {
                Output = new TestStructuresOutput()
            });

            var structures = new StructureCollection <StabilityPointStructure>();
            var context    = new StabilityPointStructuresContext(structures, failureMechanism, assessmentSection);

            string textBoxMessage = null;

            DialogBoxHandler = (name, wnd) =>
            {
                var helper = new MessageBoxTester(wnd);
                textBoxMessage = helper.Text;

                if (isActionConfirmed)
                {
                    helper.ClickOk();
                }
                else
                {
                    helper.ClickCancel();
                }
            };

            using (var plugin = new StabilityPointStructuresPlugin())
            {
                plugin.Gui = gui;
                ImportInfo importInfo = GetImportInfo(plugin);

                // Call
                bool updatesVerified = importInfo.VerifyUpdates(context);

                // Assert
                string expectedInquiryMessage = "Als u kunstwerken importeert, dan worden alle rekenresultaten van dit faalmechanisme verwijderd." +
                                                $"{Environment.NewLine}{Environment.NewLine}Weet u zeker dat u wilt doorgaan?";
                Assert.AreEqual(expectedInquiryMessage, textBoxMessage);
                Assert.AreEqual(isActionConfirmed, updatesVerified);
                mocks.VerifyAll();
            }
        }
Esempio n. 13
0
        public void VerifyUpdates_CalculationWithOutputs_AlwaysReturnsExpectedInquiryMessage(bool isActionConfirmed)
        {
            // Setup
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            var mainWindow = mocks.Stub <IMainWindow>();
            var gui        = mocks.Stub <IGui>();

            gui.Stub(g => g.MainWindow).Return(mainWindow);
            mocks.ReplayAll();

            plugin.Gui = gui;

            var failureMechanism      = new PipingFailureMechanism();
            var calculationWithOutput = new SemiProbabilisticPipingCalculationScenario
            {
                Output = PipingTestDataGenerator.GetRandomSemiProbabilisticPipingOutput()
            };

            failureMechanism.CalculationsGroup.Children.Add(calculationWithOutput);

            var surfaceLines = new PipingSurfaceLineCollection();
            var context      = new PipingSurfaceLinesContext(surfaceLines, failureMechanism, assessmentSection);

            string textBoxMessage = null;

            DialogBoxHandler = (name, wnd) =>
            {
                var helper = new MessageBoxTester(wnd);
                textBoxMessage = helper.Text;

                if (isActionConfirmed)
                {
                    helper.ClickOk();
                }
                else
                {
                    helper.ClickCancel();
                }
            };

            // Call
            bool updatesVerified = importInfo.VerifyUpdates(context);

            // Assert
            string expectedInquiryMessage = "Als u profielschematisaties importeert, " +
                                            "dan worden alle rekenresultaten van dit faalmechanisme verwijderd." +
                                            $"{Environment.NewLine}{Environment.NewLine}Weet u zeker dat u wilt doorgaan?";

            Assert.AreEqual(expectedInquiryMessage, textBoxMessage);
            Assert.AreEqual(isActionConfirmed, updatesVerified);
            mocks.VerifyAll();
        }
        public void GivenCalculationsWithOutput_WhenChangingNormativeProbabilityType_ThenAllDependingOutputClearedAndActionPerformedAndAllAffectedObjectsNotified()
        {
            // Given
            DialogBoxHandler = (name, wnd) =>
            {
                var tester = new MessageBoxTester(wnd);
                tester.ClickOk();
            };

            AssessmentSection assessmentSection = TestDataGenerator.GetAssessmentSectionWithAllCalculationConfigurations();

            var expectedAffectedCalculations = new List <ICalculation>();

            expectedAffectedCalculations.AddRange(assessmentSection.Piping.Calculations
                                                  .OfType <SemiProbabilisticPipingCalculationScenario>()
                                                  .Where(c => c.HasOutput && !c.InputParameters.UseAssessmentLevelManualInput));
            expectedAffectedCalculations.AddRange(assessmentSection.MacroStabilityInwards.Calculations
                                                  .OfType <MacroStabilityInwardsCalculationScenario>()
                                                  .Where(c => c.HasOutput && !c.InputParameters.UseAssessmentLevelManualInput));

            IEnumerable <IObservable> expectedAffectedObjects =
                expectedAffectedCalculations.Concat(new IObservable[]
            {
                assessmentSection.FailureMechanismContribution
            })
                .ToArray();

            var mocks    = new MockRepository();
            var observer = mocks.StrictMock <IObserver>();

            observer.Expect(o => o.UpdateObserver()).Repeat.Times(expectedAffectedObjects.Count());
            mocks.ReplayAll();

            expectedAffectedObjects.ForEachElementDo(obj => obj.Attach(observer));

            var handler = new FailureMechanismContributionNormChangeHandler(assessmentSection);

            // When
            var actionPerformed = false;

            void Call() => handler.ChangeNormativeProbabilityType(() => actionPerformed = true);

            // Then
            var expectedMessages = new[]
            {
                $"De resultaten van {expectedAffectedCalculations.Count} semi-probabilistische berekeningen zonder handmatige waterstand zijn verwijderd."
            };

            TestHelper.AssertLogMessagesAreGenerated(Call, expectedMessages, 1);
            Assert.IsTrue(actionPerformed);
            CollectionAssert.IsEmpty(expectedAffectedCalculations.Where(c => c.HasOutput));
            mocks.VerifyAll();
        }
        public void SetPropertyValueAfterConfirmation_IfConfirmationRequiredThenGiven_SetValueCalledAffectedObjectsReturned(ChangePropertyTestCase testCase)
        {
            // Setup
            bool dialogBoxWillBeShown = testCase.ExpectedAffectedCalculations.Any();

            var title   = "";
            var message = "";

            if (dialogBoxWillBeShown)
            {
                DialogBoxHandler = (name, wnd) =>
                {
                    var tester = new MessageBoxTester(wnd);
                    title   = tester.Title;
                    message = tester.Text;

                    tester.ClickOk();
                };
            }

            var testFailureMechanism = new TestCalculatableFailureMechanism(testCase.Calculations);
            var propertySet          = 0;

            var changeHandler = new FailureMechanismPropertyChangeHandler <ICalculatableFailureMechanism>();

            // Precondition
            Assert.IsTrue(testCase.ExpectedAffectedCalculations.All(c => c.HasOutput));

            // Call
            IEnumerable <IObservable> affectedObjects = changeHandler.SetPropertyValueAfterConfirmation(
                testFailureMechanism,
                3,
                (f, v) => propertySet++);

            // Assert
            if (dialogBoxWillBeShown)
            {
                Assert.AreEqual("Bevestigen", title);
                string expectedMessage = "Als u deze parameter wijzigt, zal de uitvoer van alle berekeningen in dit faalmechanisme verwijderd worden."
                                         + Environment.NewLine + Environment.NewLine +
                                         "Weet u zeker dat u wilt doorgaan?";
                Assert.AreEqual(expectedMessage, message);
            }

            Assert.AreEqual(1, propertySet);
            var expectedAffectedObjects = new List <IObservable>(testCase.ExpectedAffectedCalculations)
            {
                testFailureMechanism
            };

            CollectionAssert.AreEqual(expectedAffectedObjects, affectedObjects);
            Assert.IsTrue(testCase.Calculations.All(c => !c.HasOutput));
        }
Esempio n. 16
0
        public void Validation()
        {
            FMainDS.LoadAll();
            FMainDS.DeleteAllRows();
            FMainDS.SaveChanges();

            TFrmSetupCorporateExchangeRate mainScreen = new TFrmSetupCorporateExchangeRate(null);

            mainScreen.Show();

            ButtonTester       btnNew           = new ButtonTester("btnNew", mainScreen);
            TCmbAutoPopulated  cmbFromCurrency  = (new TCmbAutoPopulatedTester("cmbDetailFromCurrencyCode", mainScreen)).Properties;
            TCmbAutoPopulated  cmbToCurrency    = (new TCmbAutoPopulatedTester("cmbDetailToCurrencyCode", mainScreen)).Properties;
            TtxtPetraDate      dtpEffectiveDate = (new TTxtPetraDateTester("dtpDetailDateEffectiveFrom", mainScreen)).Properties;
            TTxtNumericTextBox txtExchangeRate  = (new TTxtNumericTextBoxTester("txtDetailRateOfExchange", mainScreen)).Properties;

            btnNew.Click();

            // Set up some bad entries
            dtpEffectiveDate.Text = "";
            txtExchangeRate.NumberValueDecimal = 0.0m;

            string dlgText      = String.Empty;
            bool   dlgDisplayed = false;

            // Click the New button and discover what validation errors we have
            // Note - we do not put assert's inside the delegate because we want the dialog to close.
            //   If the dialog is left hanging this might do bad stuff to automated testing
            ModalFormHandler = delegate(string name, IntPtr hWnd, Form form)
            {
                MessageBoxTester tester = new MessageBoxTester(hWnd);
                dlgText      = tester.Text;
                dlgDisplayed = true;
                tester.SendCommand(MessageBoxTester.Command.OK);
            };

            btnNew.Click();

            // Check that we did display the dialog and that we picked up the validation errors we predicted
            Assert.IsTrue(dlgDisplayed);
            Assert.IsTrue(dlgText.Contains(CommonErrorCodes.ERR_NOUNDEFINEDDATE));
            Assert.IsTrue(dlgText.Contains(CommonErrorCodes.ERR_INVALIDNUMBER));

            // Close without saving
            ModalFormHandler = delegate(string name, IntPtr hWnd, Form form)
            {
                MessageBoxTester tester = new MessageBoxTester(hWnd);
                tester.SendCommand(MessageBoxTester.Command.No);
            };

            mainScreen.Close();
        }
Esempio n. 17
0
        public void VerifyUpdates_CalculationWithOutputs_AlwaysReturnsExpectedInquiryMessage(bool isActionConfirmed)
        {
            // Setup
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();
            var mainWindow        = mocks.Stub <IMainWindow>();
            var gui = mocks.Stub <IGui>();

            gui.Stub(g => g.MainWindow).Return(mainWindow);
            mocks.ReplayAll();

            plugin.Gui = gui;

            var failureMechanism = new HeightStructuresFailureMechanism();

            failureMechanism.CalculationsGroup.Children.Add(new StructuresCalculation <HeightStructuresInput>
            {
                Output = new TestStructuresOutput()
            });

            var structures = new StructureCollection <HeightStructure>();
            var context    = new HeightStructuresContext(structures, failureMechanism, assessmentSection);

            string textBoxMessage = null;

            DialogBoxHandler = (name, wnd) =>
            {
                var helper = new MessageBoxTester(wnd);
                textBoxMessage = helper.Text;

                if (isActionConfirmed)
                {
                    helper.ClickOk();
                }
                else
                {
                    helper.ClickCancel();
                }
            };

            // Call
            bool updatesVerified = updateInfo.VerifyUpdates(context);

            // Assert
            string expectedInquiryMessage = "Wanneer de kunstwerken wijzigen als gevolg van het bijwerken " +
                                            "zullen de resultaten van berekeningen die deze kunstwerken gebruiken worden verwijderd." +
                                            $"{Environment.NewLine}{Environment.NewLine}Weet u zeker dat u wilt doorgaan?";

            Assert.AreEqual(expectedInquiryMessage, textBoxMessage);
            Assert.AreEqual(isActionConfirmed, updatesVerified);
            mocks.VerifyAll();
        }
Esempio n. 18
0
        private void HandleMessageBox(string name, IntPtr hWnd)
        {
            NumberOfMessageBoxes++;

            MessageBoxTester tester = new MessageBoxTester(hWnd);

            TLogging.Log("HandleMessageBox: " + NumberOfMessageBoxes.ToString() + ": " +
                         tester.Text.Replace(Environment.NewLine, " "));

            DialogBoxHandler = HandleMessageBox;

            tester.SendCommand(MessageBoxTester.Command.OK);
        }
Esempio n. 19
0
        public void TestCancelBatchBug121()
        {
            TFrmGLBatch frmBatch = new TFrmGLBatch(null);

            frmBatch.LedgerNumber = FLedgerNumber;
            frmBatch.Show();

            // create a new batch and save
            ToolStripButtonTester btnSave     = new ToolStripButtonTester("tbbSave");
            ButtonTester          btnNewBatch = new ButtonTester("ucoBatches.btnNew");

            btnNewBatch.Click();
            TextBoxTester txtDetailBatchDescription = new TextBoxTester("txtDetailBatchDescription");

            txtDetailBatchDescription.Properties.Text = "Created by test TestCancelBatchBug121";
            btnSave.Click();

            // cancel that batch. no saving necessary
            ButtonTester btnCancelBatch = new ButtonTester("ucoBatches.btnCancel");

            ModalFormHandler = delegate(string name, IntPtr hWnd, Form form)
            {
                MessageBoxTester tester = new MessageBoxTester(hWnd);
                Assert.AreEqual("Form Contains Invalid Data", tester.Title);

                // there is a second message box after confirming the cancellation, telling the user the cancellation was successful.
                // because the ModalFormHandler is reset after handling the first message box, we need to set up a new handler.
                ModalFormHandler = delegate(string name2, IntPtr hWnd2, Form form2)
                {
                    MessageBoxTester tester2 = new MessageBoxTester(hWnd2);
                    // Assert.AreEqual("Success", tester.Title);
                    tester2.SendCommand(MessageBoxTester.Command.Yes);
                };

                tester.SendCommand(MessageBoxTester.Command.Yes);
            };

            btnCancelBatch.Click();

            // add a new batch
            btnNewBatch.Click();
            txtDetailBatchDescription.Properties.Text = "Created by test TestCancelBatchBug121, not cancelled";

            // save: the bug caused exception "Forgot to call AcceptChanges"
            btnSave.Click();

            Assert.AreEqual(false, btnSave.Properties.Enabled, "Save button should be disabled because all changes have been saved");

            frmBatch.Close();
        }
        public void SetPropertyValueAfterConfirmation_IfConfirmationRequiredThenGiven_SetValueCalledAffectedObjectsReturned(ChangePropertyTestCase testCase)
        {
            // Setup
            bool dialogBoxWillBeShown = testCase.Calculation.HasOutput;

            var title   = "";
            var message = "";

            if (dialogBoxWillBeShown)
            {
                DialogBoxHandler = (name, wnd) =>
                {
                    var tester = new MessageBoxTester(wnd);
                    title   = tester.Title;
                    message = tester.Text;

                    tester.ClickOk();
                };
            }

            var calculationInput = new TestCalculationInput();
            var propertySet      = 0;

            var changeHandler = new ObservablePropertyChangeHandler(testCase.Calculation, calculationInput);

            // Precondition
            Assert.AreEqual(dialogBoxWillBeShown, testCase.Calculation.HasOutput);

            // Call
            IEnumerable <IObservable> affectedObjects = changeHandler.SetPropertyValueAfterConfirmation(() => propertySet++);

            // Assert
            var expectedAffectedObjects = new List <IObservable>();

            if (dialogBoxWillBeShown)
            {
                Assert.AreEqual("Bevestigen", title);
                string expectedMessage = "Als u een parameter in deze berekening wijzigt, zal de uitvoer van deze berekening verwijderd worden."
                                         + Environment.NewLine + Environment.NewLine +
                                         "Weet u zeker dat u wilt doorgaan?";
                Assert.AreEqual(expectedMessage, message);

                expectedAffectedObjects.Add(testCase.Calculation);
            }

            expectedAffectedObjects.Add(calculationInput);
            CollectionAssert.AreEquivalent(expectedAffectedObjects, affectedObjects);
            Assert.AreEqual(1, propertySet);
            Assert.IsFalse(testCase.Calculation.HasOutput);
        }
Esempio n. 21
0
        private void バリデーションメッセージ確認(string text, string message)
        {
            var target = new FizzBuzzForm();

            target.Show();

            DialogBoxHandler = (title, handle) =>
            {
                var messageBox = new MessageBoxTester(handle);
                Assert.That(messageBox.Text, Is.EqualTo(message));
                messageBox.ClickOk();
            };

            new TextBoxTester("maxNumberTextBox", target).Enter(text);
            new ButtonTester("fizzBuzzButton", target).Click();
        }
Esempio n. 22
0
        public void InvertRate()
        {
            FMainDS.LoadAll();
            FMainDS.DeleteAllRows();
            FMainDS.InsertStandardRows();
            FMainDS.SaveChanges();

            TFrmSetupCorporateExchangeRate mainScreen = new TFrmSetupCorporateExchangeRate(null);

            mainScreen.Show();

            // Toolstrip
            ToolStripButton btnSave = (new ToolStripButtonTester("tbbSave", mainScreen)).Properties;

            // Grid
            TSgrdDataGrid grdDetails = (TSgrdDataGrid)(new TSgrdDataGridPagedTester("grdDetails", mainScreen)).Properties;

            // Panel and controls
            Panel              pnlDetails       = (new PanelTester("pnlDetails", mainScreen)).Properties;
            ButtonTester       btnNew           = new ButtonTester("btnNew", mainScreen);
            TCmbAutoPopulated  cmbFromCurrency  = (new TCmbAutoPopulatedTester("cmbDetailFromCurrencyCode", mainScreen)).Properties;
            TCmbAutoPopulated  cmbToCurrency    = (new TCmbAutoPopulatedTester("cmbDetailToCurrencyCode", mainScreen)).Properties;
            TtxtPetraDate      dtpEffectiveDate = (new TTxtPetraDateTester("dtpDetailDateEffectiveFrom", mainScreen)).Properties;
            TTxtNumericTextBox txtExchangeRate  = (new TTxtNumericTextBoxTester("txtDetailRateOfExchange", mainScreen)).Properties;
            ButtonTester       btnInvert        = new ButtonTester("btnInvertExchangeRate", mainScreen);

            // Select the first row in the grid.  New rows should be based on data row 5
            SelectRowInGrid(1, 5);

            // Check that Invert enabled and test that it works
            btnNew.Click();
            Assert.IsTrue(btnInvert.Properties.Enabled);
            txtExchangeRate.NumberValueDecimal = 5.0m;
            btnInvert.Click();
            Assert.AreEqual(0.2m, txtExchangeRate.NumberValueDecimal);
            btnInvert.Click();
            Assert.AreEqual(5.0m, txtExchangeRate.NumberValueDecimal);

            ModalFormHandler = delegate(string name, IntPtr hWnd, Form form)
            {
                MessageBoxTester tester = new MessageBoxTester(hWnd);
                tester.SendCommand(MessageBoxTester.Command.OK);
            };

            mainScreen.SaveChanges();
            mainScreen.Close();
        }
Esempio n. 23
0
        public void InquirePerformOptionalStep_VariousScenarios_ReturnExpectedValue(DialogResult clickedResult,
                                                                                    OptionalStepResult expectedResult)
        {
            // Setup
            dialogParent.Expect(d => d.Handle).Repeat.AtLeastOnce().Return(default(IntPtr));
            mocks.ReplayAll();

            var helper = new DialogBasedInquiryHelper(dialogParent);

            string actualQuery = null;
            string title       = null;

            DialogBoxHandler = (name, wnd) =>
            {
                var tester = new MessageBoxTester(wnd);
                actualQuery = tester.Text;
                title       = tester.Title;

                switch (clickedResult)
                {
                case DialogResult.Yes:
                    tester.SendCommand(MessageBoxTester.Command.Yes);
                    break;

                case DialogResult.No:
                    tester.SendCommand(MessageBoxTester.Command.No);
                    break;

                case DialogResult.Cancel:
                    tester.SendCommand(MessageBoxTester.Command.Cancel);
                    break;
                }
            };

            const string description = "A";
            const string query       = "B";

            // Call
            OptionalStepResult result = helper.InquirePerformOptionalStep(description, query);

            // Assert
            Assert.AreEqual(expectedResult, result);

            Assert.AreEqual(description, title);
            Assert.AreEqual(query, actualQuery);
            mocks.VerifyAll();
        }
        /// <summary>
        /// The delegate to handle the message box is installed.
        /// </summary>
        /// <param name="cmd">Contains a NUnit.Extensions.Forms.MessageBoxTester.Command to
        /// insert the desired reaction.</param>
        public void WaitForMessageBox(NUnit.Extensions.Forms.MessageBoxTester.Command cmd)
        {
            lastMessageTitle = "";
            lastMessageText  = "";

            ModalFormHandler = delegate(string name, IntPtr hWnd, Form form)
            {
                MessageBoxTester tester = new MessageBoxTester(hWnd);

                System.Console.WriteLine("Title: " + tester.Title);
                System.Console.WriteLine("Message: " + tester.Text);

                lastMessageTitle = tester.Title;
                lastMessageText  = tester.Text;

                tester.SendCommand(cmd);
            };
        }
Esempio n. 25
0
        public void GivenReferenceLineWithGeometry_WhenCancelingReferenceLineImport_ThenKeepOriginalReferenceLine()
        {
            // Given
            var mocks        = new MockRepository();
            var viewCommands = mocks.Stub <IViewCommands>();

            mocks.ReplayAll();

            var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike);

            ReferenceLineTestFactory.SetReferenceLineGeometry(assessmentSection.ReferenceLine);
            Point2D[] originalReferenceLineGeometry = assessmentSection.ReferenceLine.Points.ToArray();

            var    handler = new ReferenceLineUpdateHandler(assessmentSection, viewCommands);
            string path    = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO, "traject_10-2.shp");

            var    importer = new ReferenceLineImporter(assessmentSection.ReferenceLine, handler, path);
            string messageBoxTitle = null, messageBoxText = null;

            DialogBoxHandler = (name, wnd) =>
            {
                var messageBoxTester = new MessageBoxTester(wnd);

                messageBoxTitle = messageBoxTester.Title;
                messageBoxText  = messageBoxTester.Text;

                messageBoxTester.ClickCancel();
            };

            // When
            bool importSuccessful = importer.Import();

            // Then
            Assert.IsFalse(importSuccessful);
            CollectionAssert.AreEqual(originalReferenceLineGeometry, assessmentSection.ReferenceLine.Points);

            Assert.AreEqual("Bevestigen", messageBoxTitle);
            string expectedText = "Na het importeren van een aangepaste ligging van de referentielijn zullen alle geïmporteerde en berekende gegevens van alle faalmechanismen worden gewist." + Environment.NewLine +
                                  Environment.NewLine + "Wilt u doorgaan?";

            Assert.AreEqual(expectedText, messageBoxText);
            mocks.VerifyAll();
        }
        public void GivenCalculationsWithoutOutput_WhenChangingNormativeProbabilityType_ThenActionPerformedAndContributionNotified()
        {
            // Given
            DialogBoxHandler = (name, wnd) =>
            {
                var tester = new MessageBoxTester(wnd);
                tester.ClickOk();
            };

            AssessmentSection assessmentSection = TestDataGenerator.GetAssessmentSectionWithAllCalculationConfigurations();

            var calculations = new List <ICalculation>();

            calculations.AddRange(assessmentSection.Piping.Calculations
                                  .OfType <SemiProbabilisticPipingCalculationScenario>()
                                  .Where(c => c.HasOutput && !c.InputParameters.UseAssessmentLevelManualInput));
            calculations.AddRange(assessmentSection.MacroStabilityInwards.Calculations
                                  .OfType <MacroStabilityInwardsCalculationScenario>()
                                  .Where(c => c.HasOutput && !c.InputParameters.UseAssessmentLevelManualInput));

            calculations.ForEachElementDo(c => c.ClearOutput());

            var mocks    = new MockRepository();
            var observer = mocks.StrictMock <IObserver>();

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

            assessmentSection.FailureMechanismContribution.Attach(observer);

            var handler = new FailureMechanismContributionNormChangeHandler(assessmentSection);

            // When
            var actionPerformed = false;

            void Call() => handler.ChangeNormativeProbabilityType(() => actionPerformed = true);

            // Then
            TestHelper.AssertLogMessagesCount(Call, 0);
            Assert.IsTrue(actionPerformed);
            mocks.VerifyAll();
        }
        public void SetPropertyValueAfterConfirmation_ConfirmationGiven_HandlerExecuted()
        {
            // Setup
            DialogBoxHandler = (name, wnd) =>
            {
                var tester = new MessageBoxTester(wnd);
                tester.ClickOk();
            };

            var handler = new DuneLocationCalculationsForTargetProbabilityChangeHandler(
                CreateCalculationsForTargetProbabilityWithAndWithoutOutput());

            var handlerExecuted = false;

            // Call
            handler.SetPropertyValueAfterConfirmation(() => handlerExecuted = true);

            // Assert
            Assert.IsTrue(handlerExecuted);
        }
Esempio n. 28
0
        public void GivenExceptionDialog_WhenSaveProjectClicked_ThenSaveProjectAsCalledAndMessageBoxShown(bool saveSuccessful, string expectedDialogTitle, string expectedDialogMessage)
        {
            // Setup
            var mocks         = new MockRepository();
            var commandsOwner = mocks.StrictMock <ICommandsOwner>();
            var commands      = mocks.StrictMock <IStorageCommands>();

            commandsOwner.Expect(co => co.StorageCommands).Return(commands);
            commands.Expect(c => c.SaveProjectAs()).Return(saveSuccessful);
            mocks.ReplayAll();

            var messageBoxTitle = "";
            var messageBoxText  = "";

            // Setup
            DialogBoxHandler = (name, wnd) =>
            {
                var openedDialog = new MessageBoxTester(wnd);
                messageBoxTitle = openedDialog.Title;
                messageBoxText  = openedDialog.Text;
                openedDialog.ClickOk();
            };

            var exception = new Exception("Test");

            using (var dialog = new ExceptionDialog(new UserControl(), commandsOwner, exception))
            {
                dialog.Show();

                var buttonTester = new ButtonTester("buttonSaveProject");

                // Call
                buttonTester.Click();

                // Assert
                Assert.AreEqual(expectedDialogTitle, messageBoxTitle);
                Assert.AreEqual(expectedDialogMessage, messageBoxText);
            }

            mocks.VerifyAll();
        }
Esempio n. 29
0
        public void ConfirmUpdate_ClickDialog_ReturnTrueIfOkAndFalseIfCancel(bool clickOk)
        {
            // Setup
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();
            var viewCommands      = mocks.Stub <IViewCommands>();

            mocks.ReplayAll();

            string dialogTitle = null, dialogMessage = null;

            DialogBoxHandler = (name, wnd) =>
            {
                var tester = new MessageBoxTester(wnd);
                dialogTitle   = tester.Title;
                dialogMessage = tester.Text;
                if (clickOk)
                {
                    tester.ClickOk();
                }
                else
                {
                    tester.ClickCancel();
                }
            };

            var handler = new ReferenceLineUpdateHandler(assessmentSection, viewCommands);

            // Call
            bool result = handler.ConfirmUpdate();

            // Assert
            Assert.AreEqual(clickOk, result);

            Assert.AreEqual("Bevestigen", dialogTitle);
            Assert.AreEqual("Na het importeren van een aangepaste ligging van de referentielijn zullen alle geïmporteerde en berekende gegevens van alle faalmechanismen worden gewist." + Environment.NewLine +
                            Environment.NewLine +
                            "Wilt u doorgaan?",
                            dialogMessage);
            mocks.VerifyAll();
        }
Esempio n. 30
0
        public void GivenExceptionDialog_WhenSaveProjectClickedAndExceptionThrown_ThenUnsuccessfulMessageShown()
        {
            // Setup
            var mocks         = new MockRepository();
            var commandsOwner = mocks.StrictMock <ICommandsOwner>();
            var commands      = mocks.StrictMock <IStorageCommands>();

            commandsOwner.Expect(co => co.StorageCommands).Return(commands);
            commands.Expect(c => c.SaveProjectAs()).Throw(new Exception());
            mocks.ReplayAll();

            var messageBoxTitle = "";
            var messageBoxText  = "";

            // Setup
            DialogBoxHandler = (name, wnd) =>
            {
                var openedDialog = new MessageBoxTester(wnd);
                messageBoxTitle = openedDialog.Title;
                messageBoxText  = openedDialog.Text;
                openedDialog.ClickOk();
            };

            var exception = new Exception("Test");

            using (var dialog = new ExceptionDialog(new UserControl(), commandsOwner, exception))
            {
                dialog.Show();
                var buttonTester = new ButtonTester("buttonSaveProject");

                // Call
                buttonTester.Click();

                // Assert
                Assert.AreEqual("Project is niet opgeslagen", messageBoxTitle);
                Assert.AreEqual("Opslaan van project is mislukt.", messageBoxText);
            }

            mocks.VerifyAll();
        }
        public void SetPropertyValueAfterConfirmation_ConfirmationNotGiven_SetValueNotCalledReturnsNoAffectedObjects()
        {
            // Setup
            DialogBoxHandler = (name, wnd) =>
            {
                var tester = new MessageBoxTester(wnd);
                tester.ClickCancel();
            };

            DuneLocationCalculationsForTargetProbability calculationsForTargetProbability = CreateCalculationsForTargetProbabilityWithAndWithoutOutput();
            var handler = new DuneLocationCalculationsForTargetProbabilityChangeHandler(calculationsForTargetProbability);

            var propertySet = 0;

            // Call
            IEnumerable <IObservable> affectedObjects = handler.SetPropertyValueAfterConfirmation(() => propertySet++);

            // Assert
            Assert.AreEqual(0, propertySet);
            Assert.AreEqual(2, calculationsForTargetProbability.DuneLocationCalculations.Count(dlc => dlc.Output != null));
            CollectionAssert.IsEmpty(affectedObjects);
        }
Esempio n. 32
0
        public void ProjectDataDeleted_Always_CallsRemoveAllViewsForItemWithTag()
        {
            // Setup
            var mocks        = new MockRepository();
            var project      = mocks.Stub <IProject>();
            var viewCommands = mocks.StrictMock <IViewCommands>();

            viewCommands.Expect(vc => vc.RemoveAllViewsForItem(project));
            mocks.ReplayAll();

            IEnumerable <TreeNodeInfo> treeNodeInfos = new[]
            {
                new TreeNodeInfo
                {
                    TagType   = typeof(IProject),
                    CanRemove = (item, parent) => true
                }
            };

            DialogBoxHandler = (name, wnd) =>
            {
                var messageBox = new MessageBoxTester(wnd);
                messageBox.ClickOk();
            };

            using (var explorer = new ProjectExplorer(viewCommands, treeNodeInfos)
            {
                Data = project
            })
            {
                var treeViewControl = TypeUtils.GetField <TreeViewControl>(explorer, "treeViewControl");

                // Call
                treeViewControl.TryRemoveNodeForData(project);
            }

            // Assert
            mocks.VerifyAll();
        }
Esempio n. 33
0
 public void oldhandler(string name, System.IntPtr hWnd, System.Windows.Forms.Form form)
 {
     MessageBoxTester mb = new MessageBoxTester(hWnd);
     Assert.Equal("Old", mb.Text);
     mb.ClickOk();
 }
Esempio n. 34
0
 public void oldhandler()
 {
     MessageBoxTester mb = new MessageBoxTester("Old");
     Assert.AreEqual("Old", mb.Text);
     mb.ClickOk();
 }
Esempio n. 35
0
 public void newhandler()
 {
     MessageBoxTester mb = new MessageBoxTester("New");
     Assert.AreEqual("New", mb.Text);
     mb.ClickOk();
 }
Esempio n. 36
0
 public void falsehandler()
 {
     MessageBoxTester mb = new MessageBoxTester("False");
     Assert.AreEqual("False", mb.Text);
     mb.ClickOk();
 }
Esempio n. 37
0
 public void NoModalFound()
 {
     Assert.Throws<ControlNotVisibleException>(delegate { string text = new MessageBoxTester("NotFound").Text; });
 }
Esempio n. 38
0
 public void OKAndCancelHandler(string name, System.IntPtr hWnd)
 {
     MessageBoxTester messageBox = new MessageBoxTester(hWnd);
     messageBox.SendCommand(MessageBoxTester.Command.Cancel);
 }
Esempio n. 39
0
 /// <summary>
 /// A <see cref="ModalFormActivatedHwnd"/> that tries to click the OK button of the modal form.
 ///</summary>
 public void UnexpectedModal(IntPtr hWnd)
 {
     MessageBoxTester messageBox = new MessageBoxTester(hWnd);
     messageBox.ClickOk();
 }
Esempio n. 40
0
 public void newhandler(string name, IntPtr hWnd, Form form)
 {
     MessageBoxTester mb = new MessageBoxTester(hWnd);
     Assert.Equal("New", mb.Text);
     mb.ClickOk();
 }