Exemplo n.º 1
0
        public void TestClockExtensionMethods()
        {
            // Arrange
            var localTimeZone        = TimeZoneInfo.Local;
            var currentUtcDateTime   = new DateTimeOffset(1968, 5, 20, 20, 2, 42, 123, TimeSpan.Zero);
            var currentLocalDateTime = TimeZoneInfo.ConvertTime(currentUtcDateTime, localTimeZone);
            var clock = new TestClock
            {
                LocalTimeZone      = localTimeZone,
                CurrentUtcDateTime = currentUtcDateTime
            };

            // Act
            var currentLocalDate      = clock.GetCurrentLocalDate();
            var currentLocalTimeOfDay = clock.GetCurrentLocalTimeOfDay();

            var currentUtcDate      = clock.GetCurrentUtcDate();
            var currentUtcTimeOfDay = clock.GetCurrentUtcTimeOfDay();

            // Assert
            Assert.NotNull(clock);
            Assert.Equal(currentLocalDateTime.Date, currentLocalDate);
            Assert.Equal(currentLocalDateTime.TimeOfDay, currentLocalTimeOfDay);
            Assert.Equal(currentUtcDateTime.Date, currentUtcDate);
            Assert.Equal(currentUtcDateTime.TimeOfDay, currentUtcTimeOfDay);
        }