示例#1
0
        public void ApproxYobFromAgeTest()
        {
            SystemTime.NowFunction = () => new DateTime(2010, 6, 11, 10, 15, 16, 178);

            // Null age
            var expected = (int?)null;
            var actual   = DateTimeExtensions.ApproxYobFromAge(null);

            Assert.IsNull(actual);

            // Negative age
            expected = null;
            actual   = DateTimeExtensions.ApproxAgeFromYob(-1);
            Assert.IsNull(actual);

            // Future yob
            expected = null;
            actual   = DateTimeExtensions.ApproxAgeFromYob(2011);
            Assert.IsNull(actual);

            // Zero age
            expected = 0;
            actual   = DateTimeExtensions.ApproxAgeFromYob(2010);
            Assert.AreEqual(expected, actual);

            // Future yob
            expected = 3;
            actual   = DateTimeExtensions.ApproxAgeFromYob(2007);
            Assert.AreEqual(expected, actual);
        }
示例#2
0
        public void ApproxAgeFromYobTest()
        {
            SystemTime.NowFunction = () => new DateTime(2010, 6, 11, 10, 15, 16, 178);

            // Null yob
            var expected = (int?)null;
            var actual   = DateTimeExtensions.ApproxAgeFromYob(null);

            Assert.IsNull(actual);

            // Future yob
            expected = 0;
            actual   = DateTimeExtensions.ApproxAgeFromYob(2011);
            Assert.IsNull(actual);

            // Current yob
            expected = 0;
            actual   = DateTimeExtensions.ApproxAgeFromYob(2010);
            Assert.AreEqual(expected, actual);

            // Past yob
            expected = 3;
            actual   = DateTimeExtensions.ApproxAgeFromYob(2007);
            Assert.AreEqual(expected, actual);
        }