Exemple #1
0
        public void ToStringExact()
        {
            NhsDate date = new NhsDate(new System.DateTime(1974, 3, 26));

            Assert.AreEqual("26-Mar-1974", date.ToString());

            Assert.AreEqual("26-Mar-1974", date.ToString(false), "Check that default for 'include day of week' flag is correct");

            // try with includeDayOfWeek flag
            Assert.AreEqual("Tue 26-Mar-1974", date.ToString(true));
        }
Exemple #2
0
        public void ParseMonthAndYear()
        {
            System.DateTime baseDateTime = System.DateTime.Now;

            NhsDate date = new NhsDate(baseDateTime);

            date.DateType = DateType.YearMonth;
            date.Year     = 1974;
            date.Month    = 3;

            NhsDate parsedDate;

            Assert.IsTrue(NhsDate.TryParseExact("jan-2008", out parsedDate, CultureInfo.InvariantCulture), "Try parse failed");
            Assert.AreEqual(parsedDate.Month, 1, "Month not being parsed");
            Assert.AreEqual(parsedDate.Year, 2008, "Month not being parsed");

            Assert.IsTrue(NhsDate.TryParseExact("january-2008", out parsedDate, CultureInfo.InvariantCulture), "Try parse failed");
            Assert.AreEqual(parsedDate.Month, 1, "Month not being parsed");
            Assert.AreEqual(parsedDate.Year, 2008, "Month not being parsed");

            Assert.IsTrue(NhsDate.TryParseExact("1-2008", out parsedDate, CultureInfo.InvariantCulture), "Try parse failed");
            Assert.AreEqual(parsedDate.Month, 1, "Month not being parsed");
            Assert.AreEqual(parsedDate.Year, 2008, "Month not being parsed");

            Assert.IsTrue(NhsDate.TryParseExact("10-2008", out parsedDate, CultureInfo.InvariantCulture), "Try parse failed");
            Assert.AreEqual(parsedDate.Month, 10, "Month not being parsed");
            Assert.AreEqual(parsedDate.Year, 2008, "Month not being parsed");

            Assert.IsTrue(NhsDate.TryParseExact(date.ToString(), out parsedDate, CultureInfo.InvariantCulture), string.Format(CultureInfo.InvariantCulture, "TryParse failed with date, {0}", date.ToString()));

            Assert.AreEqual(date.Month, parsedDate.Month, "Parse did not error but Month does not match");
            Assert.AreEqual(date.DateType, parsedDate.DateType, "Parse did not error but DateType does not match");
            Assert.AreEqual(date.Year, parsedDate.Year, "Parse did not error but Year does not match");
        }
Exemple #3
0
        public void ToStringNull()
        {
            NhsDate date = new NhsDate();

            date.DateType = DateType.Null;
            Assert.IsTrue(date.ToString().Length == 0);
        }
Exemple #4
0
        public void ParseDateText()
        {
            NhsDate date = new NhsDate("26-March-1974");

            NhsDate parsedDate;

            Assert.IsTrue(NhsDate.TryParseExact(date.ToString(), out parsedDate, CultureInfo.InvariantCulture), string.Format(CultureInfo.InvariantCulture, "TryParse failed with date, {0}", date.ToString()));

            Assert.AreEqual(date.DateType, parsedDate.DateType, "Parse did not error but DateType does not match");
            Assert.AreEqual(date.DateValue, parsedDate.DateValue, "Parse did not error but DateValue does not match");
        }
Exemple #5
0
        public void DateOfBirthDayTextMonthYearTest()
        {
            Parser target = new Parser();

            NhsDate expectedNhsDate = new NhsDate(new DateTime(1960, 4, 15));

            target.Text = "May Williams 15-April-1960";
            target.Parse();

            // Can't check for equivalence using Assert.AreEqual<NhsDate>(expectedNhsDate, target.DateOfBirth)
            // because NhsDate doesn't override the equality operator so check using ToString() calls...
            Assert.AreEqual <string>(expectedNhsDate.ToString(), target.DateOfBirth.ToString(), "NhsCui.Toolkit.Parser.DateOfBirth was not set correctly by Parse method.");
        }
Exemple #6
0
        public void DateOfBirthUpperTest()
        {
            Parser target = new Parser();

            NhsDate expectedNhsDate = new NhsDate(1954, 7);

            target.Text = "May Williams June-1954-July-1954";
            target.Parse();

            // Can't check for equivalence using Assert.AreEqual<NhsDate>(expectedNhsDate, target.DateOfBirth)
            // because NhsDate doesn't override the equality operator so check using ToString() calls...
            Assert.AreEqual <string>(expectedNhsDate.ToString(), target.DateOfBirthUpper.ToString(), "NhsCui.Toolkit.Parser.DateOfBirthUpper was not set correctly by Parse method.");
        }
Exemple #7
0
        public void ToStringYear()
        {
            System.DateTime baseDateTime = System.DateTime.Now;

            NhsDate date = new NhsDate(baseDateTime);

            date.DateType = DateType.Year;

            Assert.AreEqual("0000", date.ToString(), "Check the default of Year when an explicit date is passed to ctor");

            date = new NhsDate(baseDateTime.Year);

            date.DateType = DateType.Year;

            Assert.AreEqual(baseDateTime.Year.ToString(CultureInfo.CurrentCulture), date.ToString());
        }
Exemple #8
0
        public void ParseCase4Test()
        {
            Parser target = new Parser();

            NhsDate expectedNhsDate = new NhsDate(1954, 6);

            target.Text = "May Williams June-1954";
            target.Parse();

            Assert.AreEqual <string>("May", target.GivenName, "NhsCui.Toolkit.Parser.GivenName was not set correctly in Parse Case 4.");
            Assert.AreEqual <string>("Williams", target.FamilyName, "NhsCui.Toolkit.Parser.FamilyName was not set correctly in Parse Case 4.");

            // Can't check for equivalence using Assert.AreEqual<NhsDate>(expectedNhsDate, target.DateOfBirth)
            // because NhsDate doesn't override the equality operator so check using ToString() calls...
            Assert.AreEqual <string>(expectedNhsDate.ToString(), target.DateOfBirth.ToString(), "NhsCui.Toolkit.Parser.Address was not set correctly in Parse Case 4.");
        }
Exemple #9
0
        public void ParseCase9Test()
        {
            Parser target = new Parser();

            target.Text = "Mr Smith 1964";
            NhsDate expectedNhsDate = new NhsDate(1964);

            target.Parse();

            Assert.AreEqual <Gender>(Gender.Male, target.Gender, "NhsCui.Toolkit.Parser.Gender was not set correctly in Parse Case 9.");
            Assert.AreEqual <string>("Mr", target.Title, "NhsCui.Toolkit.Parser.Title was not set correctly in Parse Case 9.");
            Assert.AreEqual <string>("Smith", target.FamilyName, "NhsCui.Toolkit.Parser.FamilyName was not set correctly in Parse Case 9.");

            // Can't check for equivalence using Assert.AreEqual<NhsDate>(expectedNhsDate, target.DateOfBirth)
            // because NhsDate doesn't override the equality operator so check using ToString() calls...
            Assert.AreEqual <string>(expectedNhsDate.ToString(), target.DateOfBirth.ToString(), "NhsCui.Toolkit.Parser.DateOfBirth was not set correctly in Parse Case 9.");
        }
Exemple #10
0
        public void ParseCase3Test()
        {
            Parser target = new Parser();

            NhsDate expectedNhsDate = new NhsDate(1964, 9);

            target.Text = "John Smith Sept-1964 30";
            target.Parse();

            Assert.AreEqual <string>("John", target.GivenName, "NhsCui.Toolkit.Parser.GivenName was not set correctly in Parse Case 3.");
            Assert.AreEqual <string>("Smith", target.FamilyName, "NhsCui.Toolkit.Parser.FamilyName was not set correctly in Parse Case 3.");

            // Can't check for equivalence using Assert.AreEqual<NhsDate>(expectedNhsDate, target.DateOfBirth)
            // because NhsDate doesn't override the equality operator so check using ToString() calls...
            Assert.AreEqual <string>(expectedNhsDate.ToString(), target.DateOfBirth.ToString(), "NhsCui.Toolkit.Parser.Address was not set correctly in Parse Case 3.");
            Assert.AreEqual <int>(30, target.Age, "NhsCui.Toolkit.Parser.Age was not set correctly in Parse Case 3.");
        }
Exemple #11
0
        public void ParseNullIndex()
        {
            NhsDate date = new NhsDate();

            date.DateType  = DateType.NullIndex;
            date.NullIndex = 14;

            // Muddy the water by assigning Month and year
            date.Year  = 2007;
            date.Month = 3;

            NhsDate parsedDate;

            Assert.IsTrue(NhsDate.TryParseExact(date.ToString(), out parsedDate, CultureInfo.InvariantCulture), string.Format(CultureInfo.InvariantCulture, "TryParse failed with date, {0}", date.ToString()));

            Assert.AreEqual(date.DateType, parsedDate.DateType, "Parse did not error but DateType does not match");
            Assert.AreEqual(date.NullIndex, parsedDate.NullIndex, "Parse did not error but NullIndex does not match");
        }
Exemple #12
0
        /// <summary>
        /// update text displayed in textbox
        /// </summary>
        private void UpdateTextBox()
        {
            NhsDate value = this.Value;

            string[] nullStrings = this.NullStrings;

            if (value.DateType != DateType.NullIndex || nullStrings == null ||
                value.NullIndex < 0 || value.NullIndex >= nullStrings.Length)
            {
                this.TextBox.Text = value.ToString(
                    this.DisplayDayOfWeek,
                    false,
                    this.DisplayDateAsText,
                    CultureInfo.CurrentCulture);
            }
            else
            {
                this.TextBox.Text = nullStrings[value.NullIndex];
            }
        }
Exemple #13
0
        public void ParseCase14Test()
        {
            // Extra case to test for the PSIB Sample input string
            Parser  target          = new Parser();
            NhsDate expectedNhsDate = new NhsDate("18-May-1972");

            target.Text = "mr john evans 64 chester str e182ng 34 18/05/1972 1234567890";
            target.Parse();

            Assert.AreEqual <string>("evans", target.FamilyName, "NhsCui.Toolkit.Parser.FamilyName was not set correctly in Parse Case 14.");
            Assert.AreEqual <string>("john", target.GivenName, "NhsCui.Toolkit.Parser.GivenName was not set correctly in Parse Case 14.");
            Assert.AreEqual <string>("1234567890", target.NhsNumber, "NhsCui.Toolkit.Parser.NhsNumber was not set correctly in Parse Case 14.");
            Assert.AreEqual <int>(34, target.Age, "NhsCui.Toolkit.Parser.Age was not set correctly in Parse Case 14.");
            Assert.AreEqual <string>(expectedNhsDate.ToString(), target.DateOfBirth.ToString(), "NhsCui.Toolkit.Parser.DateOfBirth was not set correctly in Parse Case 14.");

            // Can't check for equivalence using Assert.AreEqual<NhsDate>(expectedNhsDate, target.DateOfBirth)
            // because NhsDate doesn't override the equality operator so check using ToString() calls...
            Assert.AreEqual <Gender>(Gender.Male, target.Gender, "NhsCui.Toolkit.Parser.Gender was not set correctly in Parse Case 14.");
            Assert.AreEqual <string>("mr", target.Title, "NhsCui.Toolkit.Parser.Title was not set correctly in Parse Case 14.");
            Assert.AreEqual <string>("64 chester str", target.Address, "NhsCui.Toolkit.Parser.Address was not set correctly in Parse Case 14.");
            Assert.AreEqual <string>("e182ng", target.Postcode, "NhsCui.Toolkit.Parser.Postcode was not set correctly in Parse Case 14.");
        }
Exemple #14
0
        public void ToStringYearMonth()
        {
            System.DateTime baseDateTime = System.DateTime.Now;

            NhsDate date = new NhsDate(baseDateTime);

            date.DateType = DateType.YearMonth;

            Assert.AreEqual(string.Format(CultureInfo.InvariantCulture, "{0}-{1}", CultureInfo.CurrentUICulture.DateTimeFormat.MonthNames[1 - 1], "0000"), date.ToString(), "Check the default of Month and Year when an explicit date is passed to ctor");

            // Now set the date to a year and a month which is what DateType = YearMonth prefers
            date = new NhsDate(1974, 3);

            Assert.AreEqual(
                string.Format(CultureInfo.InvariantCulture, "{0}-{1}", CultureInfo.CurrentUICulture.DateTimeFormat.MonthNames[3 - 1], "1974"), date.ToString());
        }
Exemple #15
0
        public void ToStringExactGetRelativeText()
        {
            NhsDate date = new NhsDate(System.DateTime.Today);

            GlobalizationService gc = new GlobalizationService();

            // Today works
            Assert.AreEqual(NhsCui.Toolkit.Test.NhsCui_Toolkit_DateAndTime_Resources_NhsDateResourcesAccessor.Today, date.ToString(false, false, true, CultureInfo.CurrentCulture), "RelativeText of Today is not working");

            date.DateValue = DateTime.Today.AddDays(1);

            Assert.AreEqual(NhsCui.Toolkit.Test.NhsCui_Toolkit_DateAndTime_Resources_NhsDateResourcesAccessor.Tomorrow, date.ToString(false, false, true, CultureInfo.CurrentCulture), "RelativeText of Tomorrow is not working");

            date.DateValue = DateTime.Today.AddDays(-1);

            Assert.AreEqual(NhsCui.Toolkit.Test.NhsCui_Toolkit_DateAndTime_Resources_NhsDateResourcesAccessor.Yesterday, date.ToString(false, false, true, CultureInfo.CurrentCulture), "RelativeText of Yesterday is not working");

            // Check the "Who Wins condition when "Show Day of Week" and "Show Relative Text" are both true
            Assert.AreEqual(NhsCui.Toolkit.Test.NhsCui_Toolkit_DateAndTime_Resources_NhsDateResourcesAccessor.Yesterday, date.ToString(true, false, true, CultureInfo.CurrentCulture), "When includeDayOfWeek, showRelativeText are both true, showRelativeText should win. It is not");

            DateTime testDate = new DateTime(1974, 3, 26);

            date.DateValue = testDate;

            Assert.AreEqual(testDate.ToString(gc.ShortDatePattern, CultureInfo.CurrentCulture), date.ToString(), "Check that default for 'include day of week' flag is correct");

            // try with includeDayOfWeek flag

            Assert.AreEqual(testDate.ToString(gc.ShortDatePatternWithDayOfWeek, CultureInfo.CurrentCulture), date.ToString(true), "Check that default for 'include day of week' flag is correct");
        }