Пример #1
0
        public void stub()
        {
            var now = DateTime.Today.AddDays(1).AddHours(8);

            var clock      = new Clock();
            var systemTime = new SystemTime(clock, new MachineTimeZoneContext());

            clock.LocalNow(now);

            systemTime.LocalTime().Time.ShouldEqual(now);
            systemTime.LocalTime().TimeOfDay.ShouldEqual(800.ToTime());
            systemTime.LocalTime().Date.Day.ShouldEqual(DateTime.Today.AddDays(1));
        }
Пример #2
0
        public void time_zone_is_used_to_calculate_local_time()
        {
            TimeZoneInfo.GetSystemTimeZones().Each(zone =>
            {
                var time   = new SystemTime(new Clock(), new SimpleTimeZoneContext(zone));
                var first  = time.LocalTime().Time;
                var second = DateTime.UtcNow.ToLocalTime(zone);

                second.Subtract(first).TotalMilliseconds.ShouldBeLessThan(100);
            });
        }
Пример #3
0
        public void stub_then_back_to_live()
        {
            var now = DateTime.Today.AddDays(1).AddHours(8);

            var clock      = new Clock();
            var systemTime = new SystemTime(clock, new MachineTimeZoneContext());

            clock.LocalNow(now);

            systemTime.LocalTime().Time.ShouldEqual(now);

            clock.Live();

            var firstNow  = SystemTime.Default().LocalTime().Time;
            var secondNow = DateTime.Now;

            secondNow.Subtract(firstNow).TotalSeconds.ShouldBeLessThan(1);
        }