示例#1
0
        public void EqualityTest()
        {
            // ReSharper disable SuspiciousTypeConversion.Global
            var time0 = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            var time1 = new DateTime(2015, 12, 31, 0, 0, 0, DateTimeKind.Utc);
            var range0 = new DateTimeRange(time0, time1);
            var range1 = new DateTimeRange(time0, time1);
            var range2 = new DateTimeRange(new DateTime(1999, 12, 31, 0, 0, 0, DateTimeKind.Utc), time1);
            var range3 = new DateTimeRange(time0, new DateTime(2016, 1, 1, 0, 0, 0, DateTimeKind.Utc));

            // Equals(DateTimeRange)
            Assert.IsTrue(range0.Equals(range0));
            Assert.IsTrue(range0.Equals(range1));
            Assert.IsFalse(range0.Equals(range2));
            Assert.IsFalse(range0.Equals(range3));

            // Equals(object)
            Assert.IsTrue(range0.Equals((object)range0));
            Assert.IsTrue(range0.Equals((object)range1));
            Assert.IsFalse(range0.Equals((object)range2));
            Assert.IsFalse(range0.Equals((object)range3));
            Assert.IsFalse(range0.Equals(null));
            Assert.IsFalse(range0.Equals(range0.ToString()));

            // == operator
            Assert.IsTrue(range0 == range1);
            Assert.IsFalse(range0 == range2);
            Assert.IsFalse(range0 == range3);

            // != operator
            Assert.IsFalse(range0 != range1);
            Assert.IsTrue(range0 != range2);
            Assert.IsTrue(range0 != range3);
            // ReSharper restore SuspiciousTypeConversion.Global
        }
        public void ToString_DoesDependOnTimeComponents()
        {
            TimeSpan length = RandomDuration(MinSpan + MinSpan, MaxSpan);
            DateTime start = RandomDate(DateTime.MinValue, DateTime.MaxValue - length);
            DateTime end = start + length;
            TimeSpan step = RandomDuration(MinSpan, length - MinSpan);

            DateTimeRange dateRange = new DateTimeRange(start, end, step);
            DateTimeRange dateRangeWithTime = new DateTimeRange(
                start + RandomTimeOffset(),
                end + RandomTimeOffset(),
                step);

            Assert.AreNotEqual(
                dateRange.ToString(),
                dateRangeWithTime.ToString(),
                "String representation of range should depend on the time components");
        }
        public void ToString_IsNotBlank()
        {
            TimeSpan length = RandomDuration(MinSpan + MinSpan, MaxSpan);
            DateTime start = RandomDate(DateTime.MinValue, DateTime.MaxValue - length);
            DateTime end = start + length;
            TimeSpan step = RandomDuration(MinSpan, length - MinSpan);

            DateTimeRange dateRange = new DateTimeRange(start, end, step);

            Assert.AreNotEqual("", dateRange.ToString(), "String representation of range must not be an empty string");
        }
        public void ToString_HasCorrectFormat()
        {
            TimeSpan length = RandomDuration(MinSpan + MinSpan, MaxSpan);
            DateTime start = RandomDate(DateTime.MinValue, DateTime.MaxValue - length);
            DateTime end = start + length;
            TimeSpan step = RandomDuration(MinSpan, length - MinSpan);

            DateTimeRange dateRange = new DateTimeRange(start, end, step);

            Assert.AreEqual($"{start} - {end}", dateRange.ToString());
        }
示例#5
0
        public void ToStringTest()
        {
            var time0 = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            var time1 = new DateTime(2015, 12, 31, 0, 0, 0, DateTimeKind.Utc);
            var range = new DateTimeRange(time0, time1);

            var currentCulture = Thread.CurrentThread.CurrentCulture;
            Thread.CurrentThread.CurrentCulture = new CultureInfo("de-AT");

            Assert.AreEqual("01.01.2000 00:00:00; 31.12.2015 00:00:00", range.ToString());
            Assert.AreEqual("01.01.2000 00:00:00; 31.12.2015 00:00:00", range.ToString(new CultureInfo("de-AT")));
            Assert.AreEqual("01/01/2000 00:00:00, 12/31/2015 00:00:00", range.ToString(CultureInfo.InvariantCulture));

            Thread.CurrentThread.CurrentCulture = currentCulture;
        }