Exemplo n.º 1
0
        public void ToStringAutomaticUnitLength()
        {
            NhsTimeSpan ts = new NhsTimeSpan();

            DateTime baseDateTime = BaseDate;

            ts.IsAge = false;

            ts.From = baseDateTime;

            ts.Granularity = TimeSpanUnit.Years;
            ts.Threshold   = TimeSpanUnit.Minutes;

            ts.To    = baseDateTime.AddDays(2).AddHours(1).AddMinutes(5);
            ts.IsAge = false;
            string formattedTimeSpan = ts.ToString(TimeSpanUnitLength.Automatic, CultureInfo.CurrentCulture);

            Assert.AreEqual("2d 1hr 5min", formattedTimeSpan);

            ts.IsAge          = true;
            formattedTimeSpan = ts.ToString(TimeSpanUnitLength.Automatic, CultureInfo.CurrentCulture);

            // IsAge=true, 2days < timespan < 4 weeks, granularity=days, threshold=days
            Assert.AreEqual("2d", formattedTimeSpan);

            ts.To             = ts.To.AddYears(2);
            formattedTimeSpan = ts.ToString(TimeSpanUnitLength.Automatic, CultureInfo.CurrentCulture);

            // IsAge=true, 2 years < timespan < 18 years, granularity=years, threshold=months
            Assert.AreEqual("2years", formattedTimeSpan);
        }
Exemplo n.º 2
0
        public void ToString_IsAge_LessThan18YearsGreaterThan4Years()
        {
            NhsTimeSpan ts = new NhsTimeSpan();

            DateTime baseDateTime = BaseDate;

            ts.From = baseDateTime;

            ts.To = baseDateTime.AddYears(4).AddDays(39);

            ts.IsAge = true;

            Assert.AreEqual("4y 1m", ts.ToString());
        }
Exemplo n.º 3
0
        public void ToString_IsAge_LessThan2YearsGreaterThan1YearAndAWeek()
        {
            NhsTimeSpan ts = new NhsTimeSpan();

            DateTime baseDateTime = BaseDate;

            ts.From = baseDateTime;

            ts.To = baseDateTime.AddYears(1).AddDays(8).AddHours(5);

            ts.IsAge = true;

            Assert.AreEqual("12m 1w 1d", ts.ToString());
        }
Exemplo n.º 4
0
        public void ToString_IsAge_LessThan2YearsGreaterThan13Months()
        {
            NhsTimeSpan ts = new NhsTimeSpan();

            DateTime baseDateTime = DateTime.Parse("21 January 2007", CultureInfo.CurrentUICulture);

            ts.From = baseDateTime;

            ts.To = baseDateTime.AddYears(1).AddDays(39).AddHours(5);

            ts.IsAge = true;

            Assert.AreEqual("13m 1w 1d", ts.ToString());
        }
Exemplo n.º 5
0
        public void ToString_IsAge_LessThan1YearGreaterThan4WeeksAndADay()
        {
            NhsTimeSpan ts = new NhsTimeSpan();

            DateTime baseDateTime = BaseDate;

            ts.From = baseDateTime;

            ts.To = baseDateTime.AddDays(29).AddHours(5).AddMinutes(2);

            ts.IsAge = true;

            Assert.AreEqual("4w 1d", ts.ToString());
        }
Exemplo n.º 6
0
        public void ToString_IsAge_LessThan1Month()
        {
            NhsTimeSpan ts = new NhsTimeSpan();

            DateTime baseDateTime = BaseDate;

            ts.From = baseDateTime;

            ts.To = baseDateTime.AddDays(27).AddHours(5).AddMinutes(2);

            ts.IsAge = true;

            Assert.AreEqual("27d", ts.ToString());
        }
Exemplo n.º 7
0
        public void ToString_IsAge_LessThan4WeeksGreaterThan2Days()
        {
            NhsTimeSpan ts = new NhsTimeSpan();

            DateTime baseDateTime = BaseDate;

            ts.From = baseDateTime;

            ts.To = baseDateTime.AddDays(3).AddHours(17).AddMinutes(7);

            ts.IsAge = true;

            Assert.AreEqual("3d", ts.ToString());
        }
Exemplo n.º 8
0
        public void ToString_IsAge_GreaterThan2HoursLessThan2Days()
        {
            NhsTimeSpan ts = new NhsTimeSpan();

            DateTime baseDateTime = BaseDate;

            ts.From = baseDateTime;

            ts.To = baseDateTime.AddDays(1).AddHours(2).AddMinutes(5);

            ts.IsAge = true;

            Assert.AreEqual("26hrs", ts.ToString());
        }
Exemplo n.º 9
0
        public void ToString_IsAge_LessThan2Hours()
        {
            NhsTimeSpan ts = new NhsTimeSpan();

            DateTime baseDateTime = BaseDate;

            ts.From = baseDateTime;

            ts.To = baseDateTime.AddMinutes(90);

            ts.IsAge = true;

            Assert.AreEqual("90min", ts.ToString());
        }
Exemplo n.º 10
0
        public void ToString_1Year1Day5Hours()
        {
            NhsTimeSpan ts = new NhsTimeSpan();

            DateTime baseDateTime = BaseDate;

            ts.IsAge = false;

            ts.From = baseDateTime;

            ts.Granularity = TimeSpanUnit.Months;
            ts.Threshold   = TimeSpanUnit.Months;

            ts.To = baseDateTime.AddYears(4).AddDays(39);

            Assert.AreEqual("49m", ts.ToString());
        }
Exemplo n.º 11
0
        public void ToString_3Days17Hours7Minutes()
        {
            NhsTimeSpan ts = new NhsTimeSpan();

            DateTime baseDateTime = BaseDate;

            ts.IsAge = false;

            ts.From = baseDateTime;

            ts.Granularity = TimeSpanUnit.Hours;
            ts.Threshold   = TimeSpanUnit.Hours;

            ts.To = baseDateTime.AddDays(3).AddHours(17).AddMinutes(7);

            Assert.AreEqual("89hrs", ts.ToString());
        }
Exemplo n.º 12
0
        public void ToString_GreaterThan2Hours_LessThan2Days_DaysToMinutes()
        {
            NhsTimeSpan ts = new NhsTimeSpan();

            DateTime baseDateTime = BaseDate;

            ts.IsAge = false;

            ts.From = baseDateTime;

            ts.Granularity = TimeSpanUnit.Days;
            ts.Threshold   = TimeSpanUnit.Minutes;

            ts.To = baseDateTime.AddDays(1).AddHours(2).AddMinutes(5);

            Assert.AreEqual("1d 2hrs 5min", ts.ToString());
        }
Exemplo n.º 13
0
        public void ToString_LessThan2Hours_HoursAndMinutes()
        {
            NhsTimeSpan ts = new NhsTimeSpan();

            DateTime baseDateTime = BaseDate;

            ts.From = baseDateTime;

            ts.To = baseDateTime.AddMinutes(90);

            ts.IsAge = false;

            ts.Granularity = TimeSpanUnit.Hours;
            ts.Threshold   = TimeSpanUnit.Minutes;

            Assert.AreEqual("1hr 30min", ts.ToString());
        }
Exemplo n.º 14
0
        public void ToStringLongUnitLength()
        {
            NhsTimeSpan ts = new NhsTimeSpan();

            DateTime baseDateTime = BaseDate;

            ts.IsAge = false;

            ts.From = baseDateTime;

            ts.Granularity = TimeSpanUnit.Years;
            ts.Threshold   = TimeSpanUnit.Minutes;

            ts.To = baseDateTime.AddYears(3).AddDays(1).AddHours(2).AddMinutes(5);
            string formattedTimeSpan = ts.ToString(TimeSpanUnitLength.Long, CultureInfo.CurrentCulture);

            Assert.AreEqual("3years 1day 2hours 5minutes", formattedTimeSpan);
        }
Exemplo n.º 15
0
        public void Parse_InvalidTextRepeatedValues()
        {
            DateTime baseDateTime = BaseDate;

            NhsTimeSpan timeSpan = new NhsTimeSpan();

            timeSpan.To = baseDateTime.AddDays(3).AddHours(17);

            NhsTimeSpan parsedTimeSpan;

            // Pass a TimeSpan in twice to simulate multiple entries for the same unit e.g "3d 3d"
            Assert.IsFalse(NhsTimeSpan.TryParse(string.Format(CultureInfo.InvariantCulture, "{0} {1}", timeSpan.ToString(), timeSpan.ToString()), out parsedTimeSpan, CultureInfo.InvariantCulture));
        }