コード例 #1
0
        protected void LocalTime_ExpectDeserializeToThrowSerializationException()
        {
            // arrange
            ScalarType scalar       = CreateType <LocalTimeType>();
            object     runtimeValue = new IntValueNode(1);

            // act
            Exception?result = Record.Exception(() => scalar.Deserialize(runtimeValue));

            // assert
            Assert.IsType <SerializationException>(result);
        }
コード例 #2
0
        protected void ExpectDeserializeToThrowSerializationException <TType>(object runtimeValue)
            where TType : ScalarType
        {
            // arrange
            ScalarType scalar = CreateType <TType>();

            // act
            Exception?result = Record.Exception(() => scalar.Deserialize(runtimeValue));

            // assert
            Assert.IsType <SerializationException>(result);
        }
コード例 #3
0
        protected void LocalCurrency_ExpectDeserializeStringToMatch()
        {
            // arrange
            ScalarType    scalar       = CreateType <LocalCurrencyType>();
            const decimal runtimeValue = 7.99m;

            // act
            var deserializedValue = (decimal)scalar.Deserialize("$7.99") !;

            // assert
            Assert.Equal(runtimeValue, deserializedValue);
        }
コード例 #4
0
        protected void LocalTime_ExpectDeserializeDateTimeToMatch()
        {
            // arrange
            ScalarType scalar      = CreateType <LocalTimeType>();
            object     resultValue = new DateTime(2018, 6, 11, 8, 46, 14, DateTimeKind.Utc);


            // act
            object?result = scalar.Deserialize(resultValue);

            // assert
            Assert.Equal(resultValue, result);
        }
コード例 #5
0
        protected void UtcOffset_ExpectDeserializeTimeSpanToMatch()
        {
            // arrange
            ScalarType scalar       = CreateType <UtcOffsetType>();
            object     resultValue  = new TimeSpan(4, 0, 0);
            object     runtimeValue = new TimeSpan(4, 0, 0);

            // act
            object?result = scalar.Deserialize(resultValue);

            // assert
            Assert.Equal(result, runtimeValue);
        }
コード例 #6
0
        protected void UtcOffset_ExpectDeserializeStringToMatch()
        {
            // arrange
            ScalarType scalar       = CreateType <UtcOffsetType>();
            var        runtimeValue = new TimeSpan(4, 0, 0);

            // act
            var deserializedValue = (TimeSpan)scalar
                                    .Deserialize("+04:00") !;

            // assert
            Assert.Equal(runtimeValue, deserializedValue);
        }
コード例 #7
0
        protected void LocalCurrency_ExpectDeserializeDecimalToMatch()
        {
            // arrange
            ScalarType scalar      = CreateType <LocalCurrencyType>();
            object     resultValue = 0.99m;


            // act
            object?result = scalar.Deserialize(resultValue);

            // assert
            Assert.Equal(resultValue, result);
        }
コード例 #8
0
        protected void LocalTime_ExpectDeserializeStringToMatch()
        {
            // arrange
            ScalarType scalar       = CreateType <LocalTimeType>();
            var        runtimeValue = new DateTimeOffset(
                new DateTime(2018, 6, 11, 8, 46, 14),
                new TimeSpan(4, 0, 0));

            // act
            var deserializedValue = (DateTime)scalar.Deserialize("2018-06-11T08:46:14+04:00") !;

            // assert
            Assert.Equal(runtimeValue, deserializedValue);
        }
コード例 #9
0
        protected void ExpectDeserializeToMatch <TType>(
            object?resultValue,
            object?runtimeValue)
            where TType : ScalarType
        {
            // arrange
            ScalarType scalar = CreateType <TType>();

            // act
            object?result = scalar.Deserialize(resultValue);

            // assert
            Assert.Equal(resultValue, runtimeValue);
        }
コード例 #10
0
        protected void LocalTime_ExpectDeserializeDateTimeOffsetToMatch()
        {
            // arrange
            ScalarType scalar = CreateType <LocalTimeType>();
            object     input  = new DateTimeOffset(
                new DateTime(2018, 6, 11, 8, 46, 14),
                new TimeSpan(4, 0, 0));
            object expected = new DateTime(2018, 6, 11, 8, 46, 14);

            // act
            object?result = scalar.Deserialize(input);

            // assert
            Assert.Equal(result, expected);
        }