Ejemplo n.º 1
0
        public void GetODataSerializer_ActionPayload()
        {
            ODataDeserializerProvider      deserializerProvider = new DefaultODataDeserializerProvider(_edmModel);
            ODataActionPayloadDeserializer basicActionPayload   = deserializerProvider.GetODataDeserializer(typeof(ODataActionParameters)) as ODataActionPayloadDeserializer;

            Assert.NotNull(basicActionPayload);
        }
Ejemplo n.º 2
0
        public void GetODataSerializer_Derived_ActionPayload()
        {
            ODataDeserializerProvider      deserializerProvider = new DefaultODataDeserializerProvider(_edmModel);
            ODataActionPayloadDeserializer derivedActionPayload = deserializerProvider.GetODataDeserializer(typeof(MyActionPayload)) as ODataActionPayloadDeserializer;

            Assert.NotNull(derivedActionPayload);
        }
        public void GetODataSerializer_ActionPayload()
        {
            ODataDeserializerProvider deserializerProvider = new DefaultODataDeserializerProvider();
            ODataActionPayloadDeserializer basicActionPayload = deserializerProvider.GetODataDeserializer(_edmModel, typeof(ODataActionParameters)) as ODataActionPayloadDeserializer;

            Assert.NotNull(basicActionPayload);
        }
 public void Constructor_Throw_ArgumentNull_edmModel()
 {
     Assert.ThrowsArgumentNull(() =>
     {
         var deserializerProvider = new DefaultODataDeserializerProvider(edmModel: null);
     }, "edmModel");
 }
Ejemplo n.º 5
0
        public void ApplyProperty_DoesNotIgnoreKeyProperty()
        {
            // Arrange
            ODataProperty property = new ODataProperty {
                Name = "Key1", Value = "Value1"
            };
            EdmEntityType entityType = new EdmEntityType("namespace", "name");

            entityType.AddKeys(new EdmStructuralProperty(entityType, "Key1", EdmLibHelpers.GetEdmPrimitiveTypeReferenceOrNull(typeof(string))));
            EdmEntityTypeReference    entityTypeReference = new EdmEntityTypeReference(entityType, isNullable: false);
            ODataDeserializerProvider provider            = new DefaultODataDeserializerProvider();

            var  resource     = new Mock <IDelta>(MockBehavior.Strict);
            Type propertyType = typeof(string);

            resource.Setup(r => r.TryGetPropertyType("Key1", out propertyType)).Returns(true).Verifiable();
            resource.Setup(r => r.TrySetPropertyValue("Key1", "Value1")).Returns(true).Verifiable();

            // Act
            DeserializationHelpers.ApplyProperty(property, entityTypeReference, resource.Object, provider, new ODataDeserializerContext {
                IsPatchMode = true
            });

            // Assert
            resource.Verify();
        }
        public void Property_Instance_IsCached()
        {
            DefaultODataDeserializerProvider instance1 = DefaultODataDeserializerProvider.Instance;
            DefaultODataDeserializerProvider instance2 = DefaultODataDeserializerProvider.Instance;

            Assert.Same(instance1, instance2);
        }
Ejemplo n.º 7
0
 public void Constructor_Throw_ArgumentNull_edmModel()
 {
     Assert.ThrowsArgumentNull(() =>
     {
         var deserializerProvider = new DefaultODataDeserializerProvider(edmModel: null);
     }, "edmModel");
 }
        public void CreateEdmTypeDeserializer_Throws_ArgumentNullForEdmType()
        {
            DefaultODataDeserializerProvider deserializerProvider = new DefaultODataDeserializerProvider();

            Assert.ThrowsArgumentNull(
                () => deserializerProvider.CreateEdmTypeDeserializer(edmType: null),
                "edmType");
        }
        public void GetODataDeserializer_Throws_ArgumentNullForModel()
        {
            DefaultODataDeserializerProvider deserializerProvider = new DefaultODataDeserializerProvider();

            Assert.ThrowsArgumentNull(
                () => deserializerProvider.GetODataDeserializer(model: null, type: typeof(int)),
                "model");
        }
        public void GetODataDeserializer_Throws_ArgumentNullForType()
        {
            DefaultODataDeserializerProvider deserializerProvider = new DefaultODataDeserializerProvider();

            Assert.ThrowsArgumentNull(
                () => deserializerProvider.GetODataDeserializer(model: EdmCoreModel.Instance, type: null),
                "type");
        }
Ejemplo n.º 11
0
        public void GetODataDeserializer_Throws_ArgumentNullForModel()
        {
            DefaultODataDeserializerProvider deserializerProvider = new DefaultODataDeserializerProvider();
            HttpRequestMessage request = new HttpRequestMessage();

            Assert.ThrowsArgumentNull(
                () => deserializerProvider.GetODataDeserializer(model: null, type: typeof(int), request: request),
                "model");
        }
        public void GetODataDeserializer_ReturnsSameDeserializer_ForSameType()
        {
            ODataDeserializerProvider deserializerProvider = new DefaultODataDeserializerProvider();

            ODataDeserializer firstCallDeserializer = deserializerProvider.GetODataDeserializer(_edmModel, typeof(ODataEntityDeserializerTests.Supplier));
            ODataDeserializer secondCallDeserializer = deserializerProvider.GetODataDeserializer(_edmModel, typeof(ODataEntityDeserializerTests.Supplier));

            Assert.Same(firstCallDeserializer, secondCallDeserializer);
        }
Ejemplo n.º 13
0
        public void GetODataSerializer_ReturnsSameSerializer_ForSameType()
        {
            ODataDeserializerProvider deserializerProvider = new DefaultODataDeserializerProvider(_edmModel);

            ODataDeserializer firstCallDeserializer  = deserializerProvider.GetODataDeserializer(typeof(ODataEntityDeserializerTests.Supplier));
            ODataDeserializer secondCallDeserializer = deserializerProvider.GetODataDeserializer(typeof(ODataEntityDeserializerTests.Supplier));

            Assert.Same(firstCallDeserializer, secondCallDeserializer);
        }
        public void GetODataDeserializer_Uri()
        {
            ODataDeserializerProvider deserializerProvider = new DefaultODataDeserializerProvider();
            ODataDeserializer deserializer = deserializerProvider.GetODataDeserializer(_edmModel, typeof(Uri));

            Assert.NotNull(deserializer);
            var referenceLinkDeserializer = Assert.IsType<ODataEntityReferenceLinkDeserializer>(deserializer);
            Assert.Equal(ODataPayloadKind.EntityReferenceLink, referenceLinkDeserializer.ODataPayloadKind);
        }
        public void GetODataSerializer_Primitive(Type type, EdmPrimitiveTypeKind primitiveKind)
        {
            ODataDeserializerProvider deserializerProvider = new DefaultODataDeserializerProvider(_edmModel);
            ODataDeserializer deserializer = deserializerProvider.GetODataDeserializer(type);

            Assert.NotNull(deserializer);
            ODataRawValueDeserializer rawValueDeserializer = Assert.IsType<ODataRawValueDeserializer>(deserializer);
            Assert.Equal(ODataPayloadKind.Value, rawValueDeserializer.ODataPayloadKind);
            Assert.Equal(primitiveKind, rawValueDeserializer.PrimitiveTypeReference.PrimitiveDefinition().PrimitiveKind);
        }
Ejemplo n.º 16
0
        public void GetODataSerializer_Uri()
        {
            ODataDeserializerProvider deserializerProvider = new DefaultODataDeserializerProvider(_edmModel);
            ODataDeserializer         deserializer         = deserializerProvider.GetODataDeserializer(typeof(Uri));

            Assert.NotNull(deserializer);
            var referenceLinkDeserializer = Assert.IsType <ODataEntityReferenceLinkDeserializer>(deserializer);

            Assert.Equal(ODataPayloadKind.EntityReferenceLink, referenceLinkDeserializer.ODataPayloadKind);
        }
Ejemplo n.º 17
0
        public void GetODataDeserializer_ActionPayload()
        {
            ODataDeserializerProvider deserializerProvider = new DefaultODataDeserializerProvider();
            HttpRequestMessage        request = new HttpRequestMessage();

            ODataActionPayloadDeserializer basicActionPayload = deserializerProvider.GetODataDeserializer(_edmModel,
                                                                                                          typeof(ODataActionParameters), request) as ODataActionPayloadDeserializer;

            Assert.NotNull(basicActionPayload);
        }
        public void GetODataDeserializer_Primitive(Type type, EdmPrimitiveTypeKind primitiveKind)
        {
            ODataDeserializerProvider deserializerProvider = new DefaultODataDeserializerProvider();
            ODataDeserializer deserializer = deserializerProvider.GetODataDeserializer(_edmModel, type);

            Assert.NotNull(deserializer);
            ODataPrimitiveDeserializer rawValueDeserializer = Assert.IsType<ODataPrimitiveDeserializer>(deserializer);
            Assert.Equal(ODataPayloadKind.Property, rawValueDeserializer.ODataPayloadKind);
            Assert.Equal(primitiveKind, rawValueDeserializer.EdmType.AsPrimitive().PrimitiveDefinition().PrimitiveKind);
        }
        public void SetEdmTypeDeserializer_ThrowsArgumentNull_EdmType()
        {
            // Arrange
            DefaultODataDeserializerProvider deserializerProvider = new DefaultODataDeserializerProvider();

            // Act & Assert
            Assert.ThrowsArgumentNull(
                () => deserializerProvider.SetEdmTypeDeserializer(edmType: null, deserializer: null),
                "edmType");
        }
Ejemplo n.º 20
0
        public void GetODataSerializer_Primitive(Type type, EdmPrimitiveTypeKind primitiveKind)
        {
            ODataDeserializerProvider deserializerProvider = new DefaultODataDeserializerProvider(_edmModel);
            ODataDeserializer         deserializer         = deserializerProvider.GetODataDeserializer(type);

            Assert.NotNull(deserializer);
            ODataRawValueDeserializer rawValueDeserializer = Assert.IsType <ODataRawValueDeserializer>(deserializer);

            Assert.Equal(ODataPayloadKind.Value, rawValueDeserializer.ODataPayloadKind);
            Assert.Equal(primitiveKind, rawValueDeserializer.PrimitiveTypeReference.PrimitiveDefinition().PrimitiveKind);
        }
        public void GetODataDeserializer_Primitive(Type type, EdmPrimitiveTypeKind primitiveKind)
        {
            ODataDeserializerProvider deserializerProvider = new DefaultODataDeserializerProvider();
            ODataDeserializer         deserializer         = deserializerProvider.GetODataDeserializer(_edmModel, type);

            Assert.NotNull(deserializer);
            ODataPrimitiveDeserializer rawValueDeserializer = Assert.IsType <ODataPrimitiveDeserializer>(deserializer);

            Assert.Equal(ODataPayloadKind.Property, rawValueDeserializer.ODataPayloadKind);
            Assert.Equal(primitiveKind, rawValueDeserializer.EdmType.AsPrimitive().PrimitiveDefinition().PrimitiveKind);
        }
        public void GetODataDeserializer_Primitive(Type type, EdmPrimitiveTypeKind primitiveKind)
        {
            ODataDeserializerProvider deserializerProvider = new DefaultODataDeserializerProvider();
            HttpRequestMessage request = new HttpRequestMessage();

            ODataDeserializer deserializer = deserializerProvider.GetODataDeserializer(_edmModel, type, request);

            Assert.NotNull(deserializer);
            ODataPrimitiveDeserializer rawValueDeserializer = Assert.IsType<ODataPrimitiveDeserializer>(deserializer);
            Assert.Equal(ODataPayloadKind.Property, rawValueDeserializer.ODataPayloadKind);
        }
Ejemplo n.º 23
0
        public void GetODataDeserializer_Primitive(Type type, EdmPrimitiveTypeKind primitiveKind)
        {
            ODataDeserializerProvider deserializerProvider = new DefaultODataDeserializerProvider();
            HttpRequestMessage        request = new HttpRequestMessage();

            ODataDeserializer deserializer = deserializerProvider.GetODataDeserializer(_edmModel, type, request);

            Assert.NotNull(deserializer);
            ODataPrimitiveDeserializer rawValueDeserializer = Assert.IsType <ODataPrimitiveDeserializer>(deserializer);

            Assert.Equal(ODataPayloadKind.Property, rawValueDeserializer.ODataPayloadKind);
        }
        public void GetEdmTypeDeserializer_Returns_SetEdmTypeDeserializerInput()
        {
            // Arrange
            DefaultODataDeserializerProvider deserializerProvider = new DefaultODataDeserializerProvider();
            IEdmTypeReference        edmType      = EdmCoreModel.Instance.GetInt32(isNullable: true);
            ODataEdmTypeDeserializer deserializer = new Mock <ODataEdmTypeDeserializer>(edmType, ODataPayloadKind.Property).Object;

            deserializerProvider.SetEdmTypeDeserializer(edmType, deserializer);

            // Act & Assert
            Assert.Same(deserializer, deserializerProvider.GetEdmTypeDeserializer(edmType));
        }
        public void GetODataDeserializer_Complex()
        {
            ODataDeserializerProvider deserializerProvider = new DefaultODataDeserializerProvider();
            ODataDeserializer deserializer = deserializerProvider.GetODataDeserializer(_edmModel, typeof(ODataEntityDeserializerTests.Address));

            Assert.NotNull(deserializer);
            ODataComplexTypeDeserializer complexDeserializer = Assert.IsType<ODataComplexTypeDeserializer>(deserializer);
            Assert.Equal(deserializer.ODataPayloadKind, ODataPayloadKind.Property);
            Assert.Equal(complexDeserializer.DeserializerProvider, deserializerProvider);
            Assert.True(complexDeserializer.ComplexType.IsEquivalentTo(_edmModel.GetEdmTypeReference(typeof(ODataEntityDeserializerTests.Address))));
            Assert.Equal(complexDeserializer.EdmType, complexDeserializer.ComplexType);
        }
Ejemplo n.º 26
0
        public void GetODataDeserializer_ReturnsSameDeserializer_ForSameType()
        {
            ODataDeserializerProvider deserializerProvider = new DefaultODataDeserializerProvider();
            HttpRequestMessage        request = new HttpRequestMessage();

            ODataDeserializer firstCallDeserializer = deserializerProvider.GetODataDeserializer(_edmModel,
                                                                                                typeof(ODataEntityDeserializerTests.Supplier), request);
            ODataDeserializer secondCallDeserializer = deserializerProvider.GetODataDeserializer(_edmModel,
                                                                                                 typeof(ODataEntityDeserializerTests.Supplier), request);

            Assert.Same(firstCallDeserializer, secondCallDeserializer);
        }
Ejemplo n.º 27
0
        public void GetODataDeserializer_Uri()
        {
            ODataDeserializerProvider deserializerProvider = new DefaultODataDeserializerProvider();
            HttpRequestMessage        request = new HttpRequestMessage();

            ODataDeserializer deserializer = deserializerProvider.GetODataDeserializer(_edmModel, typeof(Uri), request);

            Assert.NotNull(deserializer);
            var referenceLinkDeserializer = Assert.IsType <ODataEntityReferenceLinkDeserializer>(deserializer);

            Assert.Equal(ODataPayloadKind.EntityReferenceLink, referenceLinkDeserializer.ODataPayloadKind);
        }
        public void GetODataDeserializer_Entity()
        {
            ODataDeserializerProvider deserializerProvider = new DefaultODataDeserializerProvider();
            ODataDeserializer deserializer = deserializerProvider.GetODataDeserializer(_edmModel, typeof(ODataEntityDeserializerTests.Product));

            Assert.NotNull(deserializer);
            ODataEntityDeserializer entityDeserializer = Assert.IsType<ODataEntityDeserializer>(deserializer);
            Assert.Equal(deserializer.ODataPayloadKind, ODataPayloadKind.Entry);
            Assert.Equal(entityDeserializer.DeserializerProvider, deserializerProvider);
            Assert.True(entityDeserializer.EntityType.IsEquivalentTo(_edmModel.GetEdmTypeReference(typeof(ODataEntityDeserializerTests.Product))));
            Assert.Equal(entityDeserializer.EdmType, entityDeserializer.EntityType);
        }
        public void GetODataDeserializer_Complex()
        {
            ODataDeserializerProvider deserializerProvider = new DefaultODataDeserializerProvider();
            ODataDeserializer         deserializer         = deserializerProvider.GetODataDeserializer(_edmModel, typeof(ODataEntityDeserializerTests.Address));

            Assert.NotNull(deserializer);
            ODataComplexTypeDeserializer complexDeserializer = Assert.IsType <ODataComplexTypeDeserializer>(deserializer);

            Assert.Equal(deserializer.ODataPayloadKind, ODataPayloadKind.Property);
            Assert.Equal(complexDeserializer.DeserializerProvider, deserializerProvider);
            Assert.True(complexDeserializer.ComplexType.IsEquivalentTo(_edmModel.GetEdmTypeReference(typeof(ODataEntityDeserializerTests.Address))));
            Assert.Equal(complexDeserializer.EdmType, complexDeserializer.ComplexType);
        }
        public void GetODataDeserializer_Entity()
        {
            ODataDeserializerProvider deserializerProvider = new DefaultODataDeserializerProvider();
            ODataDeserializer         deserializer         = deserializerProvider.GetODataDeserializer(_edmModel, typeof(ODataEntityDeserializerTests.Product));

            Assert.NotNull(deserializer);
            ODataEntityDeserializer entityDeserializer = Assert.IsType <ODataEntityDeserializer>(deserializer);

            Assert.Equal(deserializer.ODataPayloadKind, ODataPayloadKind.Entry);
            Assert.Equal(entityDeserializer.DeserializerProvider, deserializerProvider);
            Assert.True(entityDeserializer.EntityType.IsEquivalentTo(_edmModel.GetEdmTypeReference(typeof(ODataEntityDeserializerTests.Product))));
            Assert.Equal(entityDeserializer.EdmType, entityDeserializer.EntityType);
        }
        public void GetEdmTypeDeserializer_Caches_CreateDeserializerOutput()
        {
            // Arrange
            DefaultODataDeserializerProvider deserializerProvider = new DefaultODataDeserializerProvider();
            IEdmTypeReference edmType = new Mock <IEdmTypeReference>().Object;

            // Act
            var deserializer1 = deserializerProvider.GetEdmTypeDeserializer(edmType);
            var deserializer2 = deserializerProvider.GetEdmTypeDeserializer(edmType);

            // Assert
            Assert.Same(deserializer1, deserializer2);
        }
        public void GetODataDeserializer_Entity()
        {
            ODataDeserializerProvider deserializerProvider = new DefaultODataDeserializerProvider();
            HttpRequestMessage request = new HttpRequestMessage();

            ODataDeserializer deserializer = deserializerProvider.GetODataDeserializer(_edmModel,
                typeof(ODataEntityDeserializerTests.Product), request);

            Assert.NotNull(deserializer);
            ODataEntityDeserializer entityDeserializer = Assert.IsType<ODataEntityDeserializer>(deserializer);
            Assert.Equal(deserializer.ODataPayloadKind, ODataPayloadKind.Entry);
            Assert.Equal(entityDeserializer.DeserializerProvider, deserializerProvider);
        }
        public void GetODataDeserializer_Complex()
        {
            ODataDeserializerProvider deserializerProvider = new DefaultODataDeserializerProvider();
            HttpRequestMessage request = new HttpRequestMessage();

            ODataDeserializer deserializer = deserializerProvider.GetODataDeserializer(_edmModel,
                typeof(ODataEntityDeserializerTests.Address), request);

            Assert.NotNull(deserializer);
            ODataComplexTypeDeserializer complexDeserializer = Assert.IsType<ODataComplexTypeDeserializer>(deserializer);
            Assert.Equal(deserializer.ODataPayloadKind, ODataPayloadKind.Property);
            Assert.Equal(complexDeserializer.DeserializerProvider, deserializerProvider);
        }
Ejemplo n.º 34
0
        public void GetODataDeserializer_Entity()
        {
            ODataDeserializerProvider deserializerProvider = new DefaultODataDeserializerProvider();
            HttpRequestMessage        request = new HttpRequestMessage();

            ODataDeserializer deserializer = deserializerProvider.GetODataDeserializer(_edmModel,
                                                                                       typeof(ODataEntityDeserializerTests.Product), request);

            Assert.NotNull(deserializer);
            ODataEntityDeserializer entityDeserializer = Assert.IsType <ODataEntityDeserializer>(deserializer);

            Assert.Equal(deserializer.ODataPayloadKind, ODataPayloadKind.Entry);
            Assert.Equal(entityDeserializer.DeserializerProvider, deserializerProvider);
        }
        public void CreateEdmTypeDeserializer_Returns_Null_ForUnsupportedType()
        {
            // Arrange
            Mock <IEdmType> unsupportedEdmType = new Mock <IEdmType>();

            unsupportedEdmType.Setup(e => e.TypeKind).Returns(EdmTypeKind.None);
            Mock <IEdmTypeReference> unsupportedEdmTypeReference = new Mock <IEdmTypeReference>();

            unsupportedEdmTypeReference.Setup(e => e.Definition).Returns(unsupportedEdmType.Object);
            DefaultODataDeserializerProvider deserializerProvider = new DefaultODataDeserializerProvider();

            // Act & Assert
            Assert.Null(deserializerProvider.CreateEdmTypeDeserializer(unsupportedEdmTypeReference.Object));
        }
Ejemplo n.º 36
0
        public void GetODataDeserializer_Complex()
        {
            ODataDeserializerProvider deserializerProvider = new DefaultODataDeserializerProvider();
            HttpRequestMessage        request = new HttpRequestMessage();

            ODataDeserializer deserializer = deserializerProvider.GetODataDeserializer(_edmModel,
                                                                                       typeof(ODataEntityDeserializerTests.Address), request);

            Assert.NotNull(deserializer);
            ODataComplexTypeDeserializer complexDeserializer = Assert.IsType <ODataComplexTypeDeserializer>(deserializer);

            Assert.Equal(deserializer.ODataPayloadKind, ODataPayloadKind.Property);
            Assert.Equal(complexDeserializer.DeserializerProvider, deserializerProvider);
        }
Ejemplo n.º 37
0
        public void ReadInline_Calls_ReadComplexValue()
        {
            // Arrange
            ODataDeserializerProvider           deserializerProvider = new DefaultODataDeserializerProvider();
            Mock <ODataComplexTypeDeserializer> deserializer         = new Mock <ODataComplexTypeDeserializer>(_addressEdmType, deserializerProvider);
            ODataComplexValue        item        = new ODataComplexValue();
            ODataDeserializerContext readContext = new ODataDeserializerContext();

            deserializer.CallBase = true;
            deserializer.Setup(d => d.ReadComplexValue(item, readContext)).Returns(42).Verifiable();

            // Act
            object result = deserializer.Object.ReadInline(item, readContext);

            // Assert
            deserializer.Verify();
            Assert.Equal(42, result);
        }
        public void ReadInline_Calls_ReadComplexValue()
        {
            // Arrange
            ODataDeserializerProvider deserializerProvider = new DefaultODataDeserializerProvider();
            Mock<ODataComplexTypeDeserializer> deserializer = new Mock<ODataComplexTypeDeserializer>(deserializerProvider);
            ODataComplexValue item = new ODataComplexValue();
            ODataDeserializerContext readContext = new ODataDeserializerContext();

            deserializer.CallBase = true;
            deserializer.Setup(d => d.ReadComplexValue(item, _addressEdmType, readContext)).Returns(42).Verifiable();

            // Act
            object result = deserializer.Object.ReadInline(item, _addressEdmType, readContext);

            // Assert
            deserializer.Verify();
            Assert.Equal(42, result);
        }
        public void ReadInline_Calls_ReadFeed()
        {
            // Arrange
            ODataDeserializerProvider    deserializerProvider = new DefaultODataDeserializerProvider();
            Mock <ODataFeedDeserializer> deserializer         = new Mock <ODataFeedDeserializer>(_customersType, deserializerProvider);
            ODataFeedWithEntries         feedWrapper          = new ODataFeedWithEntries(new ODataFeed());
            ODataDeserializerContext     readContext          = new ODataDeserializerContext();
            IEnumerable expectedResult = new object[0];

            deserializer.CallBase = true;
            deserializer.Setup(f => f.ReadFeed(feedWrapper, readContext)).Returns(expectedResult).Verifiable();

            // Act
            var result = deserializer.Object.ReadInline(feedWrapper, readContext);

            // Assert
            deserializer.Verify();
            Assert.Same(expectedResult, result);
        }
        public void ReadInline_Calls_ReadFeed()
        {
            // Arrange
            ODataDeserializerProvider deserializerProvider = new DefaultODataDeserializerProvider();
            Mock<ODataFeedDeserializer> deserializer = new Mock<ODataFeedDeserializer>(deserializerProvider);
            ODataFeedWithEntries feedWrapper = new ODataFeedWithEntries(new ODataFeed());
            ODataDeserializerContext readContext = new ODataDeserializerContext();
            IEnumerable expectedResult = new object[0];

            deserializer.CallBase = true;
            deserializer.Setup(f => f.ReadFeed(feedWrapper, _customerType, readContext)).Returns(expectedResult).Verifiable();

            // Act
            var result = deserializer.Object.ReadInline(feedWrapper, _customersType, readContext);

            // Assert
            deserializer.Verify();
            Assert.Same(expectedResult, result);
        }
Ejemplo n.º 41
0
        public void ApplyProperty_ThrowsOnKeyProperty_WhenPatchKeyModeIsThrow()
        {
            // Arrange
            ODataProperty property = new ODataProperty {
                Name = "Key1", Value = "Value1"
            };
            EdmEntityType entityType = new EdmEntityType("namespace", "name");

            entityType.AddKeys(new EdmStructuralProperty(entityType, "Key1", EdmLibHelpers.GetEdmPrimitiveTypeReferenceOrNull(typeof(string))));
            EdmEntityTypeReference    entityTypeReference = new EdmEntityTypeReference(entityType, isNullable: false);
            ODataDeserializerProvider provider            = new DefaultODataDeserializerProvider(EdmCoreModel.Instance);

            var resource = new Mock <IDelta>(MockBehavior.Strict);

            // Act && Assert
            Assert.Throws <InvalidOperationException>(
                () => ODataEntryDeserializer.ApplyProperty(property, entityTypeReference, resource.Object, provider, new ODataDeserializerContext {
                IsPatchMode = true, PatchKeyMode = PatchKeyMode.Throw
            }),
                "Cannot apply PATCH on key property 'Key1' on entity type 'namespace.name' when 'PatchKeyMode' is 'Throw'.");
        }
Ejemplo n.º 42
0
        public void ApplyProperty_IgnoresKeyProperty_WhenPatchKeyModeIsIgnore()
        {
            // Arrange
            ODataProperty property = new ODataProperty {
                Name = "Key1", Value = "Value1"
            };
            EdmEntityType entityType = new EdmEntityType("namespace", "name");

            entityType.AddKeys(new EdmStructuralProperty(entityType, "Key1", EdmLibHelpers.GetEdmPrimitiveTypeReferenceOrNull(typeof(string))));
            EdmEntityTypeReference    entityTypeReference = new EdmEntityTypeReference(entityType, isNullable: false);
            ODataDeserializerProvider provider            = new DefaultODataDeserializerProvider(EdmCoreModel.Instance);

            var resource = new Mock <IDelta>(MockBehavior.Strict);

            // Act
            ODataEntryDeserializer.ApplyProperty(property, entityTypeReference, resource.Object, provider, new ODataDeserializerContext {
                IsPatchMode = true, PatchKeyMode = PatchKeyMode.Ignore
            });

            // Assert
            resource.Verify();
        }
        public void GetODataDeserializer_ActionPayload()
        {
            ODataDeserializerProvider deserializerProvider = new DefaultODataDeserializerProvider();
            HttpRequestMessage request = new HttpRequestMessage();

            ODataActionPayloadDeserializer basicActionPayload = deserializerProvider.GetODataDeserializer(_edmModel,
                typeof(ODataActionParameters), request) as ODataActionPayloadDeserializer;

            Assert.NotNull(basicActionPayload);
        }
        public void GetODataSerializer_Derived_ActionPayload()
        {
            ODataDeserializerProvider deserializerProvider = new DefaultODataDeserializerProvider();
            ODataActionPayloadDeserializer derivedActionPayload = deserializerProvider.GetODataDeserializer(_edmModel, typeof(MyActionPayload)) as ODataActionPayloadDeserializer;

            Assert.NotNull(derivedActionPayload);
        }
        public void SetEdmTypeDeserializer_ThrowsArgumentNull_EdmType()
        {
            // Arrange
            DefaultODataDeserializerProvider deserializerProvider = new DefaultODataDeserializerProvider();

            // Act & Assert
            Assert.ThrowsArgumentNull(
                () => deserializerProvider.SetEdmTypeDeserializer(edmType: null, deserializer: null),
                "edmType");
        }
        public void GetEdmTypeDeserializer_Returns_SetEdmTypeDeserializerInput()
        {
            // Arrange
            DefaultODataDeserializerProvider deserializerProvider = new DefaultODataDeserializerProvider();
            IEdmTypeReference edmType = EdmCoreModel.Instance.GetInt32(isNullable: true);
            ODataEdmTypeDeserializer deserializer = new Mock<ODataEdmTypeDeserializer>(edmType, ODataPayloadKind.Property).Object;
            deserializerProvider.SetEdmTypeDeserializer(edmType, deserializer);

            // Act & Assert
            Assert.Same(deserializer, deserializerProvider.GetEdmTypeDeserializer(edmType));
        }
        public void GetEdmTypeDeserializer_Caches_CreateDeserializerOutput()
        {
            // Arrange
            DefaultODataDeserializerProvider deserializerProvider = new DefaultODataDeserializerProvider();
            IEdmTypeReference edmType = new Mock<IEdmTypeReference>().Object;

            // Act
            var deserializer1 = deserializerProvider.GetEdmTypeDeserializer(edmType);
            var deserializer2 = deserializerProvider.GetEdmTypeDeserializer(edmType);

            // Assert
            Assert.Same(deserializer1, deserializer2);
        }
        public void GetODataDeserializer_Throws_ArgumentNullForModel()
        {
            DefaultODataDeserializerProvider deserializerProvider = new DefaultODataDeserializerProvider();

            Assert.ThrowsArgumentNull(
                () => deserializerProvider.GetODataDeserializer(model: null, type: typeof(int)),
                "model");
        }
        public void Constructor()
        {
            var deserializerProvider = new DefaultODataDeserializerProvider(_edmModel);

            Assert.Equal(_edmModel, deserializerProvider.EdmModel);
        }
        public void GetODataDeserializer_Throws_ArgumentNullForModel()
        {
            DefaultODataDeserializerProvider deserializerProvider = new DefaultODataDeserializerProvider();
            HttpRequestMessage request = new HttpRequestMessage();

            Assert.ThrowsArgumentNull(
                () => deserializerProvider.GetODataDeserializer(model: null, type: typeof(int), request: request),
                "model");
        }
        public void GetODataDeserializer_Throws_ArgumentNullForType()
        {
            DefaultODataDeserializerProvider deserializerProvider = new DefaultODataDeserializerProvider();
            HttpRequestMessage request = new HttpRequestMessage();

            Assert.ThrowsArgumentNull(
                () => deserializerProvider.GetODataDeserializer(model: EdmCoreModel.Instance, type: null, request: request),
                "type");
        }
Ejemplo n.º 52
0
        public void Constructor()
        {
            var deserializerProvider = new DefaultODataDeserializerProvider(_edmModel);

            Assert.Equal(_edmModel, deserializerProvider.EdmModel);
        }
        public void GetEdmTypeDeserializer_ThrowsArgument_EdmType()
        {
            DefaultODataDeserializerProvider deserializerProvider = new DefaultODataDeserializerProvider();

            Assert.ThrowsArgumentNull(
                () => deserializerProvider.GetEdmTypeDeserializer(edmType: null),
                "edmType");
        }
        public void ApplyProperty_IgnoresKeyProperty_WhenPatchKeyModeIsIgnore()
        {
            // Arrange
            ODataProperty property = new ODataProperty { Name = "Key1", Value = "Value1" };
            EdmEntityType entityType = new EdmEntityType("namespace", "name");
            entityType.AddKeys(new EdmStructuralProperty(entityType, "Key1", EdmLibHelpers.GetEdmPrimitiveTypeReferenceOrNull(typeof(string))));
            EdmEntityTypeReference entityTypeReference = new EdmEntityTypeReference(entityType, isNullable: false);
            ODataDeserializerProvider provider = new DefaultODataDeserializerProvider(EdmCoreModel.Instance);

            var resource = new Mock<IDelta>(MockBehavior.Strict);

            // Act
            ODataEntryDeserializer.ApplyProperty(property, entityTypeReference, resource.Object, provider, new ODataDeserializerContext { IsPatchMode = true, PatchKeyMode = PatchKeyMode.Ignore });

            // Assert
            resource.Verify();
        }
        public void CreateEdmTypeDeserializer_Returns_Null_ForUnsupportedType()
        {
            // Arrange
            Mock<IEdmType> unsupportedEdmType = new Mock<IEdmType>();
            unsupportedEdmType.Setup(e => e.TypeKind).Returns(EdmTypeKind.None);
            Mock<IEdmTypeReference> unsupportedEdmTypeReference = new Mock<IEdmTypeReference>();
            unsupportedEdmTypeReference.Setup(e => e.Definition).Returns(unsupportedEdmType.Object);
            DefaultODataDeserializerProvider deserializerProvider = new DefaultODataDeserializerProvider();

            // Act & Assert
            Assert.Null(deserializerProvider.CreateEdmTypeDeserializer(unsupportedEdmTypeReference.Object));
        }
Ejemplo n.º 56
0
        public void Posting_NonDerivedType_To_Action_Expecting_BaseType_Throws()
        {
            StringContent content = new StringContent("{ '__metadata' : { 'type' : 'System.Web.Http.OData.Builder.TestModels.Motorcycle' } }");
            content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json;odata=verbose");
            IODataRequestMessage oDataRequest = new ODataMessageWrapper(content.ReadAsStreamAsync().Result, content.Headers);
            ODataMessageReader reader = new ODataMessageReader(oDataRequest, new ODataMessageReaderSettings(), _model);

            ODataDeserializerProvider deserializerProvider = new DefaultODataDeserializerProvider();

            ODataDeserializerContext context = new ODataDeserializerContext { Model = _model };
            context.Path = new ODataPath(new ActionPathSegment(_model.EntityContainers().Single().FunctionImports().Single(f => f.Name == "PostMotorcycle_When_Expecting_Car")));

            Assert.Throws<ODataException>(
                () => new ODataEntityDeserializer(deserializerProvider).Read(reader, typeof(Car), context),
                "An entry with type 'System.Web.Http.OData.Builder.TestModels.Motorcycle' was found, " +
                "but it is not assignable to the expected type 'System.Web.Http.OData.Builder.TestModels.Car'. " +
                "The type specified in the entry must be equal to either the expected type or a derived type.");
        }
        public void ApplyProperty_ThrowsOnKeyProperty_WhenPatchKeyModeIsThrow()
        {
            // Arrange
            ODataProperty property = new ODataProperty { Name = "Key1", Value = "Value1" };
            EdmEntityType entityType = new EdmEntityType("namespace", "name");
            entityType.AddKeys(new EdmStructuralProperty(entityType, "Key1", EdmLibHelpers.GetEdmPrimitiveTypeReferenceOrNull(typeof(string))));
            EdmEntityTypeReference entityTypeReference = new EdmEntityTypeReference(entityType, isNullable: false);
            ODataDeserializerProvider provider = new DefaultODataDeserializerProvider(EdmCoreModel.Instance);

            var resource = new Mock<IDelta>(MockBehavior.Strict);

            // Act && Assert
            Assert.Throws<InvalidOperationException>(
                () => ODataEntryDeserializer.ApplyProperty(property, entityTypeReference, resource.Object, provider, new ODataDeserializerContext { IsPatchMode = true, PatchKeyMode = PatchKeyMode.Throw }),
                "Cannot apply PATCH on key property 'Key1' on entity type 'namespace.name' when 'PatchKeyMode' is 'Throw'.");
        }