コード例 #1
0
        public void CanConvert_DateTimeType_True()
        {
            // arrange
            DateTimeValueConverter converter = new DateTimeValueConverter();
            DateTimeType           type      = new DateTimeType();

            // act
            bool result = converter.CanConvert(type);

            // assert
            Assert.True(result);
        }
コード例 #2
0
        public void Convert_Null_NullableDateTimeDefault()
        {
            // arrange
            DateTimeValueConverter converter = new DateTimeValueConverter();
            DateTimeType           type      = new DateTimeType();

            DateTime?expectedUtcOutput = default(DateTime?);

            // act
            bool result = converter.TryConvert(
                typeof(DateTimeOffset), typeof(DateTime?),
                null, out object convertedValue);

            // assert
            Assert.True(result);
            Assert.Equal(expectedUtcOutput, convertedValue);
        }
コード例 #3
0
        public void Convert_DateTimeOffset_LocalNullableDateTime()
        {
            // arrange
            DateTimeValueConverter converter = new DateTimeValueConverter();
            DateTimeType           type      = new DateTimeType();
            DateTimeOffset         input     = new DateTimeOffset(
                new DateTime(2018, 04, 05, 13, 15, 0),
                new TimeSpan(4, 0, 0));

            DateTime?expectedUtcOutput = new DateTime(
                2018, 04, 05, 09, 15, 0, DateTimeKind.Utc);

            // act
            bool result = converter.TryConvert(
                typeof(DateTimeOffset), typeof(DateTime?),
                input, out object convertedValue);

            // assert
            Assert.True(result);
            Assert.IsType <DateTime>(convertedValue);
            Assert.Equal(expectedUtcOutput, ((DateTime)convertedValue).ToUniversalTime());
        }