Beispiel #1
0
        public void SubtractDateTimeDateTime_SetAndReset()
        {
            //  #   Arrange.
            Abstractions.DateTime.SetSubtractDateTimeDateTimeOperator(null);

            var anyDateTimeFirstTicks  = 334455;
            var anyDateTimeSecondTicks = 223344;
            var expected = new System.DateTime(anyDateTimeFirstTicks) - new System.DateTime(anyDateTimeSecondTicks);
            var actual   = new Abstractions.DateTime(anyDateTimeFirstTicks) - new Abstractions.DateTime(anyDateTimeSecondTicks);

            AssertEquals(expected, actual, because: "Sanity test that we know what we are testing.");

            var anyFakeDateTime = new Abstractions.TimeSpan(2);

            //  #   Act.
            Abstractions.DateTime.SetSubtractDateTimeDateTimeOperator(() => anyFakeDateTime);

            //  #   Assert.
            actual = new Abstractions.DateTime(anyDateTimeFirstTicks) - new Abstractions.DateTime(anyDateTimeSecondTicks);
            actual.Should().Be(anyFakeDateTime);

            //  #   Act.
            Abstractions.DateTime.SetSubtractDateTimeDateTimeOperator(null);

            //  #   Assert.
            actual = new Abstractions.DateTime(anyDateTimeFirstTicks) - new Abstractions.DateTime(anyDateTimeSecondTicks);
            AssertEquals(expected, actual);
        }
Beispiel #2
0
 protected internal static void AssertEquals(
     System.TimeSpan expected,
     Abstractions.TimeSpan actual,
     string because = "")
 {
     expected.Ticks.Should().Be(actual.Ticks, because);
 }
        public void GetTicks()
        {
            //  #   Arrange.
            var anyTicks = AnyTicks();

            //  #   Act.
            var sut = new Abstractions.TimeSpan(anyTicks);

            //  #   Assert.
            sut.Ticks.Should().Be(anyTicks);
        }
        public void Constructor_Ticks_Kind_ShouldCreate()
        {
            //  #   Arrange.
            var anyTicks       = AnyTicks();
            var systemTimeSpan = new System.TimeSpan(anyTicks);

            //  #   Act.
            var sut = new Abstractions.TimeSpan(anyTicks);

            //  #   Assert.
            AssertEquals(systemTimeSpan, sut);
        }
        public void Constructor_Days_Hours_Minutes_Seconds_Milliseconds_ShouldCreate()
        {
            //  #   Arrange.
            var anyDays         = 11;
            var anyHours        = 12;
            var anyMinutes      = 34;
            var anySeconds      = 45;
            var anyMilliseconds = 123;
            var systemTimeSpan  = new System.TimeSpan(anyDays, anyHours, anyMinutes, anySeconds, anyMilliseconds);

            //  #   Act.
            var sut = new Abstractions.TimeSpan(anyDays, anyHours, anyMinutes, anySeconds, anyMilliseconds);

            //  #   Assert.
            AssertEquals(systemTimeSpan, sut);
        }
 private static void AssertEquals(
     System.TimeSpan expected,
     Abstractions.TimeSpan actual,
     string because = "")
 {
     actual.TotalMilliseconds.Should().Be(expected.TotalMilliseconds, because);
     actual.TotalHours.Should().Be(expected.TotalHours, because);
     actual.TotalDays.Should().Be(expected.TotalDays, because);
     actual.Ticks.Should().Be(expected.Ticks, because);
     actual.Seconds.Should().Be(expected.Seconds, because);
     actual.Minutes.Should().Be(expected.Minutes, because);
     actual.Milliseconds.Should().Be(expected.Milliseconds, because);
     actual.Hours.Should().Be(expected.Hours, because);
     actual.Days.Should().Be(expected.Days, because);
     actual.TotalMinutes.Should().Be(expected.TotalMinutes, because);
     actual.TotalSeconds.Should().Be(expected.TotalSeconds, because);
 }
        public void Add_ShouldMimicSystem()
        {
            var anyTimeSpanTicks = 100;
            var anyDateTimeTicks = 200;

            var anyTimeSpan = new Abstractions.TimeSpan(anyTimeSpanTicks);
            var sut = new Abstractions.DateTime(anyDateTimeTicks);

            var anySystemTimeSpan = new System.TimeSpan(anyTimeSpanTicks);
            var anySystemDateTime = new System.DateTime(anyDateTimeTicks);
            var expectedResult = anySystemDateTime.Add(anySystemTimeSpan); ;

            //  Act.
            var res = sut.Add(anyTimeSpan);

            //  Assert.
            AssertEquals(expectedResult, res);
        }
        public void Add_ShouldThrownIfOutOfRange()
        {
            var subtract = new Abstractions.TimeSpan(-1);
            var add = new Abstractions.TimeSpan(1);

            //  Act.
            var tooLowException = Record.Exception(() =>
            {
                Abstractions.DateTime.MinValue.Add(subtract);
            });
            var tooHighException = Record.Exception(() =>
            {
                Abstractions.DateTime.MaxValue.Add(add);
            });

            //  Assert.
            tooLowException.Should().BeOfType<System.ArgumentOutOfRangeException>();
            tooHighException.Should().BeOfType<System.ArgumentOutOfRangeException>();
        }
        public void GettersShouldReturnRespectiveValue()
        {
            //  #   Arrange.
            var anyDays         = 11;
            var anyHours        = 12;
            var anyMinutes      = 34;
            var anySeconds      = 45;
            var anyMilliseconds = 123;
            var sut             = new Abstractions.TimeSpan(anyDays, anyHours, anyMinutes, anySeconds, anyMilliseconds);
            var systemTimeSpan  = new System.TimeSpan(anyDays, anyHours, anyMinutes, anySeconds, anyMilliseconds);

            //  #   Act and Assert.
            sut.TotalMilliseconds.Should().Be(systemTimeSpan.TotalMilliseconds);
            sut.TotalHours.Should().Be(systemTimeSpan.TotalHours);
            sut.TotalDays.Should().Be(systemTimeSpan.TotalDays);
            sut.Ticks.Should().Be(systemTimeSpan.Ticks);
            sut.Seconds.Should().Be(anySeconds);
            sut.Minutes.Should().Be(anyMinutes);
            sut.Milliseconds.Should().Be(anyMilliseconds);
            sut.TotalMinutes.Should().Be(systemTimeSpan.TotalMinutes);
            sut.TotalSeconds.Should().Be(systemTimeSpan.TotalSeconds);
        }