Esempio n. 1
0
        public void TestIsUtcAndDateOnlyAssertion()
        {
            var dateTimeNow       = DateTime.Now;
            var dateTimeOffsetNow = DateTimeOffset.Now.ToOffset(TimeSpan.FromHours(1));

            var ex = Assert.Throws <ArgumentException>(() => DateTimeCode.IsUtcAndDateOnly(dateTimeNow, "arg00"));

            Assert.That(ex.Message, Does.Contain("arg00"));
            Assert.That(ex.Message, Does.Contain("argument should be in UTC"));

            ex = Assert.Throws <ArgumentException>(() => DateTimeCode.IsUtcAndDateOnly(dateTimeOffsetNow, "arg00"));
            Assert.That(ex.Message, Does.Contain("arg00"));
            Assert.That(ex.Message, Does.Contain("argument should be in UTC"));

            ex = Assert.Throws <ArgumentException>(() => DateTimeCode.IsUtcAndDateOnly(dateTimeNow.ToUniversalTime(), "arg00"));
            Assert.That(ex.Message, Does.Contain("arg00"));
            Assert.That(ex.Message, Does.Contain("argument should be a date without time component"));

            ex = Assert.Throws <ArgumentException>(() => DateTimeCode.IsUtcAndDateOnly(dateTimeOffsetNow.ToUniversalTime(), "arg00"));
            Assert.That(ex.Message, Does.Contain("arg00"));
            Assert.That(ex.Message, Does.Contain("argument should be a date without time component"));

            Assert.DoesNotThrow(() => DateTimeCode.IsUtcAndDateOnly(dateTimeNow.ToUniversalTime().Date, "arg00"));
            Assert.DoesNotThrow(() => DateTimeCode.IsUtcAndDateOnly(dateTimeOffsetNow.ToUniversalTime().TruncateTime(), "arg00"));
        }
Esempio n. 2
0
        public void TestLastDayOfYear()
        {
            var dateTimeNow       = DateTime.Now;
            var dateTimeOffsetNow = DateTimeOffset.Now;

            var ex = Assert.Throws <ArgumentException>(() => DateTimeCode.LastDayOfYear(dateTimeNow, "arg00"));

            Assert.That(ex.Message, Does.Contain("arg00"));
            Assert.That(ex.Message, Does.Contain("argument should be a last day of year"));

            ex = Assert.Throws <ArgumentException>(() => DateTimeCode.LastDayOfYear(dateTimeOffsetNow, "arg00"));
            Assert.That(ex.Message, Does.Contain("arg00"));
            Assert.That(ex.Message, Does.Contain("argument should be a last day of year"));

            Assert.DoesNotThrow(() => DateTimeCode.DateOnly(dateTimeNow.Date.LastDayOfYear(), "arg00"));
            Assert.DoesNotThrow(() => DateTimeCode.DateOnly(dateTimeOffsetNow.Date.LastDayOfYear(), "arg00"));
        }
Esempio n. 3
0
        public void TestDateOnlyAssertion()
        {
            var dateTimeNow       = DateTime.Now;
            var dateTimeOffsetNow = DateTimeOffset.Now;

            var ex = Assert.Throws <ArgumentException>(() => DateTimeCode.DateOnly(dateTimeNow, "arg00"));

            Assert.That(ex.Message, Does.Contain("arg00"));
            Assert.That(ex.Message, Does.Contain("argument should be a date without time component"));

            ex = Assert.Throws <ArgumentException>(() => DateTimeCode.DateOnly(dateTimeOffsetNow, "arg00"));
            Assert.That(ex.Message, Does.Contain("arg00"));
            Assert.That(ex.Message, Does.Contain("argument should be a date without time component"));

            Assert.DoesNotThrow(() => DateTimeCode.DateOnly(dateTimeNow.Date, "arg00"));
            Assert.DoesNotThrow(() => DateTimeCode.DateOnly(dateTimeOffsetNow.Date, "arg00"));
        }