Beispiel #1
0
        public void ToStringNull()
        {
            NhsDate date = new NhsDate();

            date.DateType = DateType.Null;
            Assert.IsTrue(date.ToString().Length == 0);
        }
Beispiel #2
0
        public void NullInstructionAddTest()
        {
            DateTime nowAsItWasAtTheStartofTheTest = DateTime.Now;
            NhsDate  date = new NhsDate(nowAsItWasAtTheStartofTheTest);

            NhsDate.Add(date, null);
        }
Beispiel #3
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");
        }
Beispiel #4
0
        /// <summary>
        /// Check if the ControlToValidate is valid
        /// </summary>
        /// <returns>True if control properties is valid</returns>
        protected override bool EvaluateIsValid()
        {
            string       value   = this.GetControlValidationValue(this.ControlToValidate);
            DateInputBox control = this.NamingContainer.FindControl(this.ControlToValidate) as DateInputBox;

            if (value.Length == 0)
            {
                return(true);
            }

            if (value == this.WatermarkText)
            {
                // Essentially box is empty so return valid
                return(true);
            }

            // Don't raise an error for Today, Tomorrow if value is also the same.
            if (value == control.Value.ToString(control.DisplayDayOfWeek, false, control.DisplayDateAsText, CultureInfo.CurrentCulture))
            {
                return(true);
            }

            NhsDate tryParseResult;

            if (!NhsDate.TryParseExact(value, out tryParseResult, System.Threading.Thread.CurrentThread.CurrentCulture))
            {
                control.Value.DateType = DateType.Null;
                return(false);
            }

            return(true);
        }
Beispiel #5
0
        public void InvalidInstructionAddTest()
        {
            DateTime date       = DateTime.Now;
            NhsDate  sourcedate = new NhsDate(date);

            NhsDate.Add(sourcedate, string.Format(CultureInfo.CurrentCulture, "+1{0}", NhsCui.Toolkit.Test.NhsCui_Toolkit_DateAndTime_Resources_NhsDateResourcesAccessor.resourceCulture));
        }
Beispiel #6
0
        public void SourceDateYearAddTest()
        {
            int     year = 2007;
            NhsDate date = new NhsDate(year);

            NhsDate.Add(date, string.Format(CultureInfo.CurrentCulture, "+1{0}", NhsCui.Toolkit.Test.NhsCui_Toolkit_DateAndTime_Resources_NhsDateResourcesAccessor.DaysUnit));
        }
Beispiel #7
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");
        }
        /// <summary>
        /// Check if the ControlToValidate is valid
        /// </summary>
        /// <returns>True if control properties is valid</returns>
        protected override bool EvaluateIsValid()
        {
            string value = this.GetControlValidationValue(this.ControlToValidate);

            NhsDate tryParseResult;

            return(NhsDate.TryParseExact(value, out tryParseResult, System.Threading.Thread.CurrentThread.CurrentCulture));
        }
Beispiel #9
0
        /// <summary>‍
        /// Default constructor
        /// </summary>
        public DateInputBoxExtender()
        {
            this.EnableClientState = true;
            this.state             = new DateInputClientState();
            this.value             = new NhsDate();

            this.ClientStateValuesLoaded += new EventHandler(this.DateInputBoxExtender_ClientStateValuesLoaded);
        }
Beispiel #10
0
        /// <summary>‍
        /// Default constructor
        /// </summary>
        public MonthCalendarExtender()
        {
            this.EnableClientState = true;
            this.state             = new MonthCalendarClientState();
            this.value             = new NhsDate();
            this.value.DateType    = DateType.Exact;

            this.ClientStateValuesLoaded += new EventHandler(this.MonthCalendarExtender_ClientStateValuesLoaded);
        }
Beispiel #11
0
        public void IsNullProperty()
        {
            NhsDate date = new NhsDate();

            // default datetype is exact
            Assert.IsFalse(date.IsNull);
            date.DateType = DateType.Null;
            Assert.IsTrue(date.IsNull);
        }
Beispiel #12
0
        public void DataAddMonthAndDay()
        {
            DateTime nowAsItWasAtTheStartofTheTest = DateTime.Now;

            NhsDate date = new NhsDate(nowAsItWasAtTheStartofTheTest);

            date.Add(string.Format(CultureInfo.CurrentCulture, "+1{0}+1{1}", NhsCui.Toolkit.Test.NhsCui_Toolkit_DateAndTime_Resources_NhsDateResourcesAccessor.MonthsUnit, NhsCui.Toolkit.Test.NhsCui_Toolkit_DateAndTime_Resources_NhsDateResourcesAccessor.DaysUnit));

            Assert.AreEqual(date.DateValue, nowAsItWasAtTheStartofTheTest.AddMonths(1).AddDays(1));
        }
Beispiel #13
0
        public void TryParseFailures()
        {
            NhsDate result;

            Assert.IsFalse(NhsDate.TryParseExact("31-12", out result, CultureInfo.CurrentCulture));

            Assert.IsFalse(NhsDate.TryParseExact("01-2008", out result, CultureInfo.CurrentCulture));

            Assert.IsFalse(NhsDate.TryParseExact("-12", out result, CultureInfo.CurrentCulture));
        }
Beispiel #14
0
        public void DataSubtract2YearsAdd5Days()
        {
            DateTime nowAsItWasAtTheStartofTheTest = DateTime.Now;

            NhsDate date = new NhsDate(nowAsItWasAtTheStartofTheTest);

            date.Add(string.Format(CultureInfo.CurrentCulture, "-2{0}+5{1}", NhsCui.Toolkit.Test.NhsCui_Toolkit_DateAndTime_Resources_NhsDateResourcesAccessor.YearsUnit, NhsCui.Toolkit.Test.NhsCui_Toolkit_DateAndTime_Resources_NhsDateResourcesAccessor.DaysUnit));

            Assert.AreEqual(nowAsItWasAtTheStartofTheTest.AddYears(-2).AddDays(5), date.DateValue);
        }
Beispiel #15
0
        public void DataAdd7Years()
        {
            DateTime nowAsItWasAtTheStartofTheTest = DateTime.Now;

            NhsDate date = new NhsDate(nowAsItWasAtTheStartofTheTest);

            date.Add(string.Format(CultureInfo.CurrentCulture, "+7{0}", NhsCui.Toolkit.Test.NhsCui_Toolkit_DateAndTime_Resources_NhsDateResourcesAccessor.YearsUnit));

            Assert.AreEqual(nowAsItWasAtTheStartofTheTest.AddYears(7), date.DateValue);
        }
Beispiel #16
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");
        }
Beispiel #17
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));
        }
Beispiel #18
0
        /// <summary>‍
        /// Handle loading of client state
        /// </summary>
        /// <param name="sender">sender</param>
        /// <param name="e">args</param>
        private void MonthCalendarExtender_ClientStateValuesLoaded(object sender, EventArgs e)
        {
            if (this.ClientState != null)
            {
                JavaScriptSerializer jss = new JavaScriptSerializer();
                jss.RegisterConverters(new JavaScriptConverter[] { new NhsDateJavascriptConverter() });

                this.state = jss.Deserialize <MonthCalendarClientState>(ClientState);

                this.value = this.state.Value;
            }
        }
Beispiel #19
0
        public void ParseInvalidNullIndex()
        {
            NhsDate parsedDate;

            string invalidNullIndexString = "Null:-256";

            Assert.IsFalse(NhsDate.TryParseExact(invalidNullIndexString, out parsedDate, CultureInfo.InvariantCulture), string.Format(CultureInfo.InvariantCulture, "TryParse failed to return false with string of, {0}", invalidNullIndexString));

            invalidNullIndexString = "Null:124";

            Assert.IsFalse(NhsDate.TryParseExact(invalidNullIndexString, out parsedDate, CultureInfo.InvariantCulture), string.Format(CultureInfo.InvariantCulture, "TryParse failed to return false with string of, {0}", invalidNullIndexString));
        }
        /// <summary>
        /// Converts the provided dictionary into an object of the specified type
        /// </summary>
        /// <param name="dictionary">An IDictionary instance of property data stored as name/value pairs</param>
        /// <param name="type">The Type of the resulting object</param>
        /// <param name="serializer">The JavaScriptSerializer instance</param>
        /// <returns>The deserialized Object</returns>
        /// <remarks>KeyboardShortcut is never sent back up to the server so we do not support Deserialization</remarks>
        /// <exception cref="NotImplementedException">Always returns this exception</exception>
        public override object Deserialize(IDictionary <string, object> dictionary, Type type, JavaScriptSerializer serializer)
        {
            NhsDate deserialisationTarget = new NhsDate();

            deserialisationTarget.DateType  = (dictionary.ContainsKey("_dateType") ? (DateType)dictionary["_dateType"] : (DateType)dictionary["dateType"]);
            deserialisationTarget.DateValue = (dictionary.ContainsKey("_dateValue") ? ((DateTime)dictionary["_dateValue"]).ToLocalTime() : ((DateTime)dictionary["dateValue"]).ToLocalTime());
            deserialisationTarget.Month     = (dictionary.ContainsKey("_month") ? (int)dictionary["_month"] : (int)dictionary["month"]);
            deserialisationTarget.NullIndex = (dictionary.ContainsKey("_nullIndex") ? (int)dictionary["_nullIndex"] : (int)dictionary["nullIndex"]);
            deserialisationTarget.Year      = (dictionary.ContainsKey("_year") ? (int)dictionary["_year"] : (int)dictionary["year"]);

            return(deserialisationTarget);
        }
Beispiel #21
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.");
        }
Beispiel #22
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.");
        }
Beispiel #23
0
        /// <summary>‍
        /// Handle loading of client state
        /// </summary>
        /// <param name="sender">sender</param>
        /// <param name="e">args</param>
        private void DateInputBoxExtender_ClientStateValuesLoaded(object sender, EventArgs e)
        {
            if (this.ClientState != null)
            {
                JavaScriptSerializer jss = new JavaScriptSerializer();
                jss.RegisterConverters(new JavaScriptConverter[] { new NhsDateJavascriptConverter() });

                this.state = jss.Deserialize <DateInputClientState>(ClientState);

                this.value            = this.state.Value;
                this.calendarPosition = this.state.CalendarPosition;
            }
        }
Beispiel #24
0
        public void ConstructNhsDateDateTimeAndBool()
        {
            DateTime baseDateTime = DateTime.Now;

            NhsDate date = new NhsDate(baseDateTime, false);

            Assert.IsTrue(date.DateType == DateType.Exact);
            Assert.IsTrue(date.DateValue == baseDateTime);

            NhsDate date2 = new NhsDate(baseDateTime, true);

            Assert.IsTrue(date2.DateType == DateType.Approximate);
            Assert.IsTrue(date2.DateValue == baseDateTime);
        }
Beispiel #25
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());
        }
Beispiel #26
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());
        }
Beispiel #27
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.");
        }
Beispiel #28
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.");
        }
Beispiel #29
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.");
        }
Beispiel #30
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");
        }