Example #1
0
        public void EnterInvalidDates()
        {
            TtxtPetraDate dtpDate = new TtxtPetraDate();

            dtpDate.Name         = "dtpDate";
            dtpDate.DateChanged += new TPetraDateChangedEventHandler(DateChanged);
            dtpDate.TextChanged += new EventHandler(TextChanged);

            Form TestForm = new Form();

            TestForm.Controls.Add(dtpDate);

            TestForm.Show();

            TTxtPetraDateTester tester = new TTxtPetraDateTester("dtpDate");

            TextChangedCalled    = 0;
            DateChangedCalled    = 0;
            NumberOfMessageBoxes = 0;

            DialogBoxHandler       = HandleMessageBox;
            tester.Properties.Text = "30";

            Assert.AreEqual(1, NumberOfMessageBoxes, "entering an invalid date should only show a messagebox once");
            Assert.IsTrue(TVerificationHelper.AreVerificationResultsIdentical(tester.Properties.DateVerificationResult,
                                                                              Ict.Common.Verification.TDateChecks.GetInvalidDateVerificationResult("Date", null), false, false));

            TextChangedCalled    = 0;
            DateChangedCalled    = 0;
            NumberOfMessageBoxes = 0;

            DialogBoxHandler       = HandleMessageBox;
            tester.Properties.Text = "301210000";

            Assert.AreEqual(1, NumberOfMessageBoxes, "entering an invalid date should only show a messagebox once: year 10000");

            DialogBoxHandler = null;

            NumberOfMessageBoxes = 0;

            DialogBoxHandler = HandleMessageBox;

            tester.Properties.AllowEmpty = false;
            tester.Properties.Text       = "01-JAN-2010";
            tester.Properties.Text       = "";

            Assert.AreEqual(1, NumberOfMessageBoxes, "entering an invalid date should only show a messagebox once: year 10000");
            Assert.IsTrue(TVerificationHelper.AreVerificationResultsIdentical(tester.Properties.DateVerificationResult,
                                                                              new TVerificationResult(null, ErrorCodes.GetErrorInfo(CommonErrorCodes.ERR_NOUNDEFINEDDATE,
                                                                                                                                    CommonResourcestrings.StrInvalidDateEntered + Environment.NewLine +
                                                                                                                                    "{0} must not be empty.", new string[] { "'Date'" }))));

            DialogBoxHandler = null;
        }