Esempio n. 1
0
        public void Iso8601Durations_UseUnsupportedDuration_ThrowArgumentException(
            string duration,
            int hours,
            Iso8601Durations iso8601Durations)
        {
            // Arrange
            var startTime = SystemClock.Instance.GetCurrentInstant();

            // Act and assert
            Assert.Throws <ArgumentException>(() => iso8601Durations.AddDuration(startTime, duration, hours));
        }
Esempio n. 2
0
        public void Iso8601Durations_AddMonthIfConfiguredWrong_ThrowArgumentException(
            int months,
            [Frozen] Mock <IIso8601ConversionConfiguration> configuration,
            Iso8601Durations iso8601Durations)
        {
            // Arrange
            var wrongTimeZone = "NoTimeZoneIsCalledThis";

            configuration.Setup(x => x.GetTZDatabaseName()).Returns(wrongTimeZone);
            var startTime = SystemClock.Instance.GetCurrentInstant();

            // Act and assert
            Assert.Throws <ArgumentException>(() => iso8601Durations.AddDuration(startTime, "P1M", months));
        }
Esempio n. 3
0
        public void Iso8601Durations_AddQuarterOfAnHour(
            int quarters,
            Iso8601Durations iso8601Durations)
        {
            // Arrange
            var startTime = SystemClock.Instance.GetCurrentInstant();

            // Act
            var actual = iso8601Durations.AddDuration(startTime, "PT15M", quarters);

            // Assert
            var duration = actual - startTime;

            duration.Minutes.Should().Be(15 * quarters);
        }
Esempio n. 4
0
        public void Iso8601Durations_AddOneHour(
            int hours,
            Iso8601Durations iso8601Durations)
        {
            // Arrange
            var startTime = SystemClock.Instance.GetCurrentInstant();

            // Act
            var actual = iso8601Durations.AddDuration(startTime, "PT1H", hours);

            // Assert
            var duration = actual - startTime;

            duration.Hours.Should().Be(hours);
        }
Esempio n. 5
0
        public void Iso8601Durations_AddDurationWhenTimeHasAmbiguity_ThrowSkippedTimeException(
            string startTimeString,
            string duration,
            int months,
            string timeZoneId,
            [Frozen] Mock <IIso8601ConversionConfiguration> configuration,
            Iso8601Durations sut)
        {
            // Arrange
            configuration.Setup(x => x.GetTZDatabaseName()).Returns(timeZoneId);
            var startTime = InstantPattern.General.Parse(startTimeString).Value;

            // Act and assert
            Assert.Throws <NodaTime.SkippedTimeException>(() => sut.AddDuration(startTime, duration, months));
        }
Esempio n. 6
0
        public void Iso8601Durations_AddMonth(
            string startTimeString,
            int months,
            string timeZoneId,
            string expectedTimeString,
            [Frozen] Mock <IIso8601ConversionConfiguration> configuration,
            Iso8601Durations sut)
        {
            // Arrange
            configuration.Setup(x => x.GetTZDatabaseName()).Returns(timeZoneId);
            var startTime    = InstantPattern.General.Parse(startTimeString).Value;
            var expectedTime = InstantPattern.General.Parse(expectedTimeString).Value;

            // Act
            var actual = sut.AddDuration(startTime, "P1M", months);

            // Assert
            Assert.Equal(expectedTime, actual);
        }