Exemple #1
0
        public void TestOverridingTheCurrentDateTime()
        {
            DateTime currentDataTime  = DateTime.Now;
            DateTime overRideDataTime = DateTimeOverride.Now;

            DateTimeTestsHelper.DateTimesAreWithIn2Seconds(currentDataTime, overRideDataTime);

            using (new DateTimeOverRideSetter(Christmas1900))
            {
                DateShouldBeChristmas1900(DateTimeOverride.Now, dateFormat);
            }

            Assert.IsFalse(DateTimeOverride.Now.ToString(dateFormat) == Christmas1900.ToString(dateFormat));
        }
Exemple #2
0
        public void TestOverridingTheCurrentDateTimeUTC()
        {
            DateTime currentDataTime  = DateTime.UtcNow;
            DateTime overRideDataTime = DateTimeOverride.UtcNow;

            DateTimeTestsHelper.DateTimesAreWithIn2Seconds(currentDataTime, overRideDataTime);

            //Sets the current date time to be Christmas 1900
            WriteLine($"The UTC Date/Time before the using is {DateTime.UtcNow} ");
            using (new DateTimeOverRideSetterUTC(Christmas1900))
            {
                WriteLine($"The UTC Date/Time with in the using statement is Christmase 1900  {DateTimeOverride.UtcNow} ");
                DateShouldBeChristmas1900(DateTimeOverride.UtcNow, dateFormat);
            }

            WriteLine($"The UTC Date/Time after the using statement is {DateTime.UtcNow} ");
            //Once the using is complete the date time should be current date time
            var CurrentDate = DateTimeOverride.UtcNow;

            Assert.IsFalse(CurrentDate.ToString(dateFormat) == Christmas1900.ToString(dateFormat));
        }