public void GetTypeCode_should_MimicSystem()
        {
            var anyTicks = 43;
            var expected = new System.DateTime(anyTicks).GetTypeCode();

            //  Act.
            var res = new Abstractions.DateTime(anyTicks).GetTypeCode();

            //  Assert.
            res.Should().Be(expected);
        }
        public void ToBinary_should_MimicSystem()
        {
            var anyTicks = 424242;
            var expected = new System.DateTime(anyTicks).ToBinary();

            //  Act.
            var res = new Abstractions.DateTime(anyTicks).ToBinary();

            //  Assert.
            Assert.Equal(expected, res);
        }
        public void ToLocalTime_should_MimicSystem()
        {
            var anyTicks = new System.DateTime(2019, 10, 06).Ticks;
            var expected = new System.DateTime(anyTicks).ToLocalTime();

            //  Act.
            var res = new Abstractions.DateTime(anyTicks).ToLocalTime();

            //  Assert.
            AssertEquals(expected, res);
        }
        public void ToShortTimeString_MimicSystem()
        {
            var anyTicks = 1234;
            var expected = new System.DateTime(anyTicks).ToShortTimeString();

            //  Act.
            var res = new Abstractions.DateTime(anyTicks).ToShortTimeString();

            //  Assert.
            res.Should().Be(expected);
        }
        public void GetHashCode_Should_MimicSystem()
        {
            var anyTicks = 42;
            var expected = (new System.DateTime(anyTicks)).GetHashCode();

            //  Act.
            var actual = new Abstractions.DateTime(anyTicks).GetHashCode();

            //  Assert.
            actual.Should().Be(expected);
        }
        public void IsDaylightSavingTime_should_MimicSystem()
        {
            var anyTicks = 43;
            var expected = new System.DateTime(anyTicks).IsDaylightSavingTime();

            //  Act.
            var res = new Abstractions.DateTime(anyTicks).IsDaylightSavingTime();

            //  Assert.
            res.Should().Be(expected);
        }
Пример #7
0
        public void Constructor_Ticks_ShouldCreate()
        {
            //  #   Arrange.
            var anyTicks       = AnyTicks();
            var systemDateTime = new System.DateTime(anyTicks);

            //  #   Act.
            var res = new Abstractions.DateTime(anyTicks);

            //  #   Assert.
            AssertEquals(systemDateTime, res);
        }
Пример #8
0
        public void AddOperator_MimicSystem()
        {
            var anyDateTimeTicks = 334455;
            var anyTimeSpanTicks = 223344;
            var expected         = new System.DateTime(anyDateTimeTicks) + new System.TimeSpan(anyTimeSpanTicks);

            //  #   Act.
            var res = new Abstractions.DateTime(anyDateTimeTicks) + new Abstractions.TimeSpan(anyTimeSpanTicks);

            //  #   Assert.
            AssertEquals(expected, res);
        }
Пример #9
0
        public void SubtractDateTimeDateTimeOperator_MimicSystem()
        {
            var anyDateTimeFirstTicks  = 334455;
            var anyDateTimeSecondTicks = 223344;
            var expected = new System.DateTime(anyDateTimeFirstTicks) - new System.DateTime(anyDateTimeSecondTicks);

            //  #   Act.
            var res = new Abstractions.DateTime(anyDateTimeFirstTicks) - new Abstractions.DateTime(anyDateTimeSecondTicks);

            //  #   Assert.
            AssertEquals(expected, res);
        }
        public void ToAbstractionsDateTimeShouldConvert()
        {
            var anyTicks = 637126222737764398;
            var anyKind  = System.DateTimeKind.Local;
            var expected = new Abstractions.DateTime(anyTicks, anyKind);

            //  Act.
            var actual = new System.DateTime(anyTicks, anyKind).ToAbstractionsDateTime();

            //  Assert.
            actual.Should().Be(expected);
        }
        public void CompareToObject_Should_ThrowForNonDateTimeArgument()
        {
            object nonDate = "2019-09-26 18:47:48";
            var date = new Abstractions.DateTime(1);

            //  Act.
            var res = Record.Exception(() =>
            {
                date.CompareTo(nonDate);
            });

            res.Should().BeOfType<System.ArgumentException>();
        }
        public void GetDateTimeFormatsChar_should_ThrowExceptions()
        {
            var anyDate = new Abstractions.DateTime(2009, 7, 28, 5, 23, 15);

            //  Act.
            // Use an invalid format.
            var res = Record.Exception(() =>
            {
                anyDate.GetDateTimeFormats('a');
            });

            res.Should().BeOfType<System.FormatException>();
        }
        public void SubtractTimeSpan_should_MimicSystem()
        {
            var anyLargerTicks = 1234;
            var anyLesserTicks = 34;
            var expected = new System.DateTime(anyLargerTicks)
                .Subtract(new System.TimeSpan(anyLesserTicks));

            //  Act.
            var result = new Abstractions.DateTime(anyLargerTicks)
                .Subtract(new Abstractions.TimeSpan(anyLesserTicks));

            //  Assert.
            result.Should().Be(expected);
        }
        public void SubtractDateTime_should_MimicSystem()
        {
            var anyLargerTicks = 1234;
            var anyLesserTicks = 34;
            var expected = new System.DateTime(anyLargerTicks)
                .Subtract(new System.DateTime(anyLesserTicks));

            //  Act.
            var result = new Abstractions.DateTime(anyLargerTicks)
                .Subtract(new Abstractions.DateTime(anyLesserTicks));

            //  Assert.
            AssertEquals(expected, result);
        }
        public void ToString_MimicSystem()
        {
            // Warning: This test reacts to the current culture and may change between environments.
            var anyTicks = 123456;
            var systemDateTime = new System.DateTime(anyTicks);
            var sut = new Abstractions.DateTime(anyTicks);
            var expected = systemDateTime.ToString();

            //  Act.
            var res = sut.ToString();

            //  Assert.
            res.Should().Be(expected);
        }
        public void GetDateTimeFormats_should_MimicSystem()
        {
            var anyDate = new Abstractions.DateTime(2009, 7, 28, 5, 23, 15);
            var anySystemDate = new System.DateTime(anyDate.Ticks, anyDate.Kind);

            var expectedResult = anySystemDate.GetDateTimeFormats();
            // We cannot check for the exact result because it depends on the environment.

            //  Act.
            var res = anyDate.GetDateTimeFormats();

            //  Assert.
            res.Should().Equal(expectedResult);
        }
        public void ToUniversalTime_MimicSystem()
        {
            var anyTicks = 123456;
            var anyDateTimeKindExceptUtc = System.DateTimeKind.Local;
            var systemDateTime = new System.DateTime(anyTicks, anyDateTimeKindExceptUtc);
            var sut = new Abstractions.DateTime(anyTicks, anyDateTimeKindExceptUtc);
            var expected = systemDateTime.ToUniversalTime();

            //  Act.
            var res = sut.ToUniversalTime();

            //  Assert.
            res.Should().Be(expected);
        }
        public void GetDateTimeFormatsCharIFormatProvider_should_ThrowExceptions()
        {
            var anyDate = new Abstractions.DateTime(2009, 7, 28, 5, 23, 15);
            System.IFormatProvider culture = new CultureInfo("fr-FR", true);

            //  Act.
            // Use an invalid format.
            var res = Record.Exception(() =>
            {
                anyDate.GetDateTimeFormats('a', culture);
            });

            res.Should().BeOfType<System.FormatException>();
        }
        public void ToStringIFormatProvider_MimicSystem()
        {
            var anyTicks = 123456;
            System.IFormatProvider culture = new CultureInfo("fr-FR", true);
            var systemDateTime = new System.DateTime(anyTicks);
            var sut = new Abstractions.DateTime(anyTicks);
            var expected = systemDateTime.ToString(culture);

            //  Act.
            var res = sut.ToString(culture);

            //  Assert.
            res.Should().Be(expected);
        }
        public void ToStringString_MimicSystem()
        {
            var anyTicks = 123456;
            var anyFormat = "u";
            var systemDateTime = new System.DateTime(anyTicks);
            var sut = new Abstractions.DateTime(anyTicks);
            var expected = systemDateTime.ToString(anyFormat);

            //  Act.
            var res = sut.ToString(anyFormat);

            //  Assert.
            res.Should().Be(expected);
        }
        public void GetDateTimeFormatsIFormatProvider_should_MimicSystem()
        {
            var anyDate = new Abstractions.DateTime(2009, 7, 28, 5, 23, 15);
            var anySystemDate = new System.DateTime(anyDate.Ticks, anyDate.Kind);
            System.IFormatProvider culture = new CultureInfo("fr-FR", true);

            var expectedResult = anySystemDate.GetDateTimeFormats(culture);

            //  Act.
            // Get the short date formats using the "fr-FR" culture.
            var res = anyDate.GetDateTimeFormats(culture);

            //  Assert.
            res.Should().Equal(expectedResult);
        }
Пример #22
0
        public void LaterThanOrEqualOperator_MimicSystem(
            long ticks1, System.DateTimeKind kind1,
            long ticks2, System.DateTimeKind kind2,
            string because)
        {
            var a        = new Abstractions.DateTime(ticks1, kind1);
            var b        = new Abstractions.DateTime(ticks2, kind2);
            var expected = new System.DateTime(ticks1, kind1) >= new System.DateTime(ticks2, kind2);

            //  #   Act.
            var res = a >= b;

            //  Assert.
            res.Should().Be(expected, because);
        }
        public void AddHours_ShouldMimicSystem()
        {
            var anyDateTimeTicks = 200;
            var anyHours = 5.5d;

            var sut = new Abstractions.DateTime(anyDateTimeTicks);
            var systemDateTime = new System.DateTime(anyDateTimeTicks);

            //  Act.
            var res = sut.AddHours(anyHours);

            //  Assert.
            var expectedResult = systemDateTime.AddHours(anyHours);
            AssertEquals(expectedResult, res);
        }
        public void ToStringString_ThrowIfInvalidArgument()
        {
            var anyTicks = 123456;
            var anyNotValidFormat = "x";
            var sut = new Abstractions.DateTime(anyTicks);

            //  Act.
            var res = Record.Exception(() =>
            {
                sut.ToString(anyNotValidFormat);
            });

            //  Assert.
            res.Should().BeOfType<System.FormatException>();
        }
        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 ToStringStringIFormatProvider_ThrowForBadIndata(string format, string because)
        {
            // The dotnet standard 2.0 documentation says ToString can throw an exception for not valid 
            // custom format pattern. I have found no way to execute this so that case is not tested.
            // Exceptions:
            //   T:System.FormatException:
            //     The length of format is 1, and it is not one of the format specifier characters
            //     defined for System.Globalization.DateTimeFormatInfo. -or- format does not contain
            //     a valid custom format pattern.
            var anyTicks = 1234567;
            System.IFormatProvider culture = new CultureInfo("fr-FR", true);
            var sut = new Abstractions.DateTime(anyTicks);

            //  Act.
            var res = Record.Exception(() =>
            {
                sut.ToString(format, culture);
            });

            //  Assert.
            res.Should().BeOfType<System.FormatException>(because);
        }
        public void GetDateTimeFormatsCharIFormatProvider_should_MimicSystem()
        {
            var anyDate = new Abstractions.DateTime(2009, 7, 28, 5, 23, 15);
            var anySystemDate = new System.DateTime(anyDate.Ticks, anyDate.Kind);
            System.IFormatProvider culture = new CultureInfo("fr-FR", true);

            var expectedResult = anySystemDate.GetDateTimeFormats('d', culture);
            expectedResult.Should().Equal(new[]
            {
                "28/07/2009",
                "28/07/09",
                "28.07.09",
                "28-07-09",
                "2009-07-28",
            }, "Sanity check we have setup the test correctly");

            //  Act.
            // Get the short date formats using the "fr-FR" culture.
            var res = anyDate.GetDateTimeFormats('d', culture);

            //  Assert.
            res.Should().Equal(expectedResult);
        }