Esempio n. 1
0
        public void ParseLiteral_Should_Pass_When_NullValueNode(string typeName)
        {
            // arrange
            INamedInputType type = CreateInputType(typeName);

            // act
            // assert
            Assert.Null(type.ParseLiteral(NullValueNode.Default));
        }
Esempio n. 2
0
        public void ParseLiteral_Should_Throw_When_NotObjectValueNode(string typeName)
        {
            // arrange
            INamedInputType type = CreateInputType(typeName);

            // act
            // assert
            Assert.Throws <InvalidOperationException>(() => type.ParseLiteral(new ListValueNode()));
        }
Esempio n. 3
0
        public void IsInstanceOfType_Should_Pass_When_GeometryOfType(string typeName)
        {
            // arrange
            INamedInputType type = CreateInputType(typeName);

            // act
            // assert
            Assert.True(type.IsInstanceOfType(_geometry));
        }
Esempio n. 4
0
        public void IsInstanceOfType_Should_Fail_When_NoGeometry(string typeName)
        {
            // arrange
            INamedInputType type = CreateInputType(typeName);

            // act
            // assert
            Assert.False(type.IsInstanceOfType("foo"));
        }
Esempio n. 5
0
        public void IsInstanceOfType_Should_Pass_When_NullValueNode(string typeName)
        {
            // arrange
            INamedInputType type = CreateInputType(typeName);

            // act
            // assert
            Assert.True(type.IsInstanceOfType(NullValueNode.Default));
        }
Esempio n. 6
0
        public void IsInstanceOfType_Should_Pass_When_ObjectValueNode(string typeName)
        {
            // arrange
            INamedInputType type = CreateInputType(typeName);

            // act
            // assert
            Assert.True(type.IsInstanceOfType(new ObjectValueNode()));
        }
Esempio n. 7
0
        public void IsInstanceOfType_Should_Throw_When_Null(string typeName)
        {
            // arrange
            INamedInputType type = CreateInputType(typeName);

            // act
            // assert
            Assert.Throws <ArgumentNullException>(() => type.IsInstanceOfType(null !));
        }
Esempio n. 8
0
        public void ParseResult_Should_Throw_When_InvalidType(string typeName)
        {
            // arrange
            INamedInputType type = CreateInputType(typeName);

            // act
            // assert
            Assert.Throws <SerializationException>(() => type.ParseResult(""));
        }
Esempio n. 9
0
        public void ParseValue_Should_Pass_When_NullValue(string typeName)
        {
            // arrange
            INamedInputType type = CreateInputType(typeName);

            // act
            // assert
            Assert.Equal(NullValueNode.Default, type.ParseValue(null));
        }
        public void Serialize_Should_Pass_When_SerializeNullValue(string typeName)
        {
            // arrange
            INamedInputType type = CreateInputType(typeName);

            // act
            // assert
            Assert.Null(type.Serialize(null));
        }
        public void Serialize_Should_Throw_When_InvalidObjectShouldThrow(string typeName)
        {
            // arrange
            INamedInputType type = CreateInputType(typeName);

            // act
            // assert
            Assert.Throws <SerializationException>(() => type.Serialize(""));
        }
        public void Deserialize_Should_Throw_When_InvalidType(string typeName)
        {
            // arrange
            var             inputParser = new InputParser(new DefaultTypeConverter());
            INamedInputType type        = CreateInputType(typeName);

            // act
            // assert
            Assert.Throws <SerializationException>(() => inputParser.ParseResult("", type));
        }
        public void ParseValue_Should_Pass_When_NullValue(string typeName)
        {
            // arrange
            var             inputFormatter = new InputFormatter();
            INamedInputType type           = CreateInputType(typeName);

            // act
            // assert
            Assert.Equal(NullValueNode.Default, inputFormatter.FormatValue(null, type));
        }
        public void ParseLiteral_Should_Pass_When_NullValueNode(string typeName)
        {
            // arrange
            var             inputParser = new InputParser(new DefaultTypeConverter());
            INamedInputType type        = CreateInputType(typeName);

            // act
            // assert
            Assert.Null(inputParser.ParseLiteral(NullValueNode.Default, type));
        }
Esempio n. 15
0
        public void Deserialize_Should_Pass_When_SerializeNullValue(string typeName)
        {
            // arrange
            var             inputParser = new InputParser(new DefaultTypeConverter());
            INamedInputType type        = CreateInputType(typeName);

            // act
            // assert
            Assert.Null(inputParser.ParseResult(null, type));
        }
        public void ParseValue_Should_Throw_When_InvalidType(string typeName)
        {
            // arrange
            var             inputFormatter = new InputFormatter();
            INamedInputType type           = CreateInputType(typeName);

            // act
            // assert
            Assert.Throws <SerializationException>(() => inputFormatter.FormatValue("", type));
        }
        public void ParseLiteral_Should_Throw_When_NotObjectValueNode(string typeName)
        {
            // arrange
            var             inputParser = new InputParser(new DefaultTypeConverter());
            INamedInputType type        = CreateInputType(typeName);

            // act
            // assert
            Assert.Throws <SerializationException>(
                () => inputParser.ParseLiteral(new ListValueNode(), type));
        }
        public void IsInstanceOfType_Should_Fail_When_DifferentGeoJsonObject(string typeName)
        {
            // arrange
            INamedInputType type = CreateInputType(typeName);

            // act
            // assert
            Assert.False(
                type.IsInstanceOfType(
                    GeometryFactory.Default.CreateGeometryCollection(new[] { new Point(1, 2) })));
        }
        public void ParseLiteral_Should_Throw_When_NoCoordinates(string typeName)
        {
            // arrange
            INamedInputType type      = CreateInputType(typeName);
            var             typeField = new ObjectFieldNode(WellKnownFields.TypeFieldName, _geometryType);
            var             crsField  = new ObjectFieldNode(WellKnownFields.CrsFieldName, 0);
            var             valueNode = new ObjectValueNode(typeField, crsField);

            // act
            Assert.Throws <SerializationException>(() => type.ParseLiteral(valueNode));
        }
 private void VisitLeaf(INamedInputType type, object obj, Action <object> setValue)
 {
     if (type is IHasRuntimeType hasClrType)
     {
         Type currentType = obj.GetType();
         var  normalized  = currentType == hasClrType.RuntimeType
             ? obj
             : _converter.Convert(currentType, hasClrType.RuntimeType, obj);
         setValue(normalized);
     }
 }
Esempio n. 21
0
        public void Serialize_Should_Pass_When_SerializeGeometry(string typeName)
        {
            // arrange
            INamedInputType type = CreateInputType(typeName);

            // act
            object?result = type.Serialize(_geometry);

            // assert
            result.MatchSnapshot();
        }
Esempio n. 22
0
        public void Deserialize_Should_Pass_When_SerializeGeometry(string typeName)
        {
            // arrange
            INamedInputType type = CreateInputType(typeName);

            // act
            object?result = type.Deserialize(_geometry);

            // assert
            Assert.Equal(result, _geometry);
        }
Esempio n. 23
0
        public void ParseValue_Should_Pass_When_Value(string typeName)
        {
            // arrange
            INamedInputType type = CreateInputType(typeName);

            // act
            IValueNode literal = type.ParseValue(_geometry);

            // assert
            literal.ToString().MatchSnapshot();
        }
Esempio n. 24
0
        public void Serialize_Should_Pass_When_Dictionary(string typeName)
        {
            // arrange
            INamedInputType type       = CreateInputType(typeName);
            var             dictionary = new Dictionary <string, object>();

            // act
            object?result = type.Serialize(dictionary);

            // assert
            Assert.Equal(dictionary, result);
        }
Esempio n. 25
0
        public void Deserialize_Should_Pass_When_PassedSerializedResult(string typeName)
        {
            // arrange
            INamedInputType type       = CreateInputType(typeName);
            object?         serialized = type.Serialize(_geometry);

            // act
            object?result = type.Deserialize(serialized);

            // assert
            Assert.True(Assert.IsAssignableFrom <Geometry>(result).Equals(_geometry));
        }
Esempio n. 26
0
        public void ParseResult_Should_Pass_When_Serialized(string typeName)
        {
            // arrange
            INamedInputType type       = CreateInputType(typeName);
            object?         serialized = type.Serialize(_geometry);

            // act
            IValueNode literal = type.ParseResult(serialized);

            // assert
            literal.ToString().MatchSnapshot();
        }
        public void ParseValue_Should_Pass_When_Value(string typeName)
        {
            // arrange
            var             inputFormatter = new InputFormatter();
            INamedInputType type           = CreateInputType(typeName);

            // act
            IValueNode literal = inputFormatter.FormatValue(_geometry, type);

            // assert
            literal.ToString().MatchSnapshot();
        }
        public void Deserialize_Should_Pass_When_SerializeGeometry(string typeName)
        {
            // arrange
            var             inputParser = new InputParser(new DefaultTypeConverter());
            INamedInputType type        = CreateInputType(typeName);

            // act
            var result = inputParser.ParseResult(_geometry, type);

            // assert
            Assert.Equal(result, _geometry);
        }
Esempio n. 29
0
 private void VisitLeaf(
     INamedInputType type, object obj,
     Action <object> setValue, ISet <object> processed)
 {
     if (type is IHasClrType hasClrType)
     {
         Type   currentType = obj.GetType();
         object normalized  = currentType == hasClrType.ClrType
             ? obj
             : _converter.Convert(currentType, hasClrType.ClrType, obj);
         setValue(obj);
     }
 }
Esempio n. 30
0
        public void Deserialize_Should_When_CoordinatesAreMissing(string typeName)
        {
            // arrange
            INamedInputType type       = CreateInputType(typeName);
            var             serialized = new Dictionary <string, object>
            {
                { WellKnownFields.TypeFieldName, _geometryType },
                { WellKnownFields.CrsFieldName, new IntValueNode(0) }
            };

            // act
            // assert
            Assert.Throws <SerializationException>(() => type.Deserialize(serialized));
        }