コード例 #1
0
        public void ApplyNavigationProperty_Calls_ReadInlineOnEntry()
        {
            // Arrange
            Mock <ODataEdmTypeDeserializer>  supplierDeserializer = new Mock <ODataEdmTypeDeserializer>(ODataPayloadKind.Feed);
            Mock <ODataDeserializerProvider> deserializerProvider = new Mock <ODataDeserializerProvider>();
            var deserializer = new ODataEntityDeserializer(deserializerProvider.Object);
            ODataNavigationLinkWithItems navigationLink = new ODataNavigationLinkWithItems(new ODataNavigationLink {
                Name = "Supplier"
            });

            navigationLink.NestedItems.Add(new ODataEntryWithNavigationLinks(new ODataEntry()));

            Product  product  = new Product();
            Supplier supplier = new Supplier {
                ID = 42
            };

            deserializerProvider.Setup(d => d.GetEdmTypeDeserializer(It.IsAny <IEdmTypeReference>())).Returns(supplierDeserializer.Object);
            supplierDeserializer
            .Setup(d => d.ReadInline(navigationLink.NestedItems[0], _productEdmType.FindNavigationProperty("Supplier").Type, _readContext))
            .Returns(supplier).Verifiable();

            // Act
            deserializer.ApplyNavigationProperty(product, navigationLink, _productEdmType, _readContext);

            // Assert
            supplierDeserializer.Verify();
            Assert.Equal(supplier, product.Supplier);
        }
コード例 #2
0
        public void ApplyNavigationProperty_Calls_ReadInlineOnFeed()
        {
            // Arrange
            IEdmCollectionTypeReference      productsType         = new EdmCollectionTypeReference(new EdmCollectionType(_productEdmType));
            Mock <ODataEdmTypeDeserializer>  productsDeserializer = new Mock <ODataEdmTypeDeserializer>(ODataPayloadKind.Feed);
            Mock <ODataDeserializerProvider> deserializerProvider = new Mock <ODataDeserializerProvider>();
            var deserializer = new ODataEntityDeserializer(deserializerProvider.Object);
            ODataNavigationLinkWithItems navigationLink = new ODataNavigationLinkWithItems(new ODataNavigationLink {
                Name = "Products"
            });

            navigationLink.NestedItems.Add(new ODataFeedWithEntries(new ODataFeed()));

            Supplier    supplier = new Supplier();
            IEnumerable products = new[] { new Product {
                                               ID = 42
                                           } };

            deserializerProvider.Setup(d => d.GetEdmTypeDeserializer(It.IsAny <IEdmTypeReference>())).Returns(productsDeserializer.Object);
            productsDeserializer
            .Setup(d => d.ReadInline(navigationLink.NestedItems[0], _supplierEdmType.FindNavigationProperty("Products").Type, _readContext))
            .Returns(products).Verifiable();

            // Act
            deserializer.ApplyNavigationProperty(supplier, navigationLink, _supplierEdmType, _readContext);

            // Assert
            productsDeserializer.Verify();
            Assert.Equal(1, supplier.Products.Count());
            Assert.Equal(42, supplier.Products.First().ID);
        }
コード例 #3
0
        public void ApplyNavigationProperty_ThrowsArgumentNull_NavigationLinkWrapper()
        {
            var deserializer = new ODataEntityDeserializer(_deserializerProvider);

            Assert.ThrowsArgumentNull(
                () => deserializer.ApplyNavigationProperty(42, navigationLinkWrapper: null, entityType: _productEdmType,
                                                           readContext: _readContext),
                "navigationLinkWrapper");
        }
コード例 #4
0
        public void ApplyNavigationProperty_ThrowsArgumentNull_EntityResource()
        {
            var deserializer = new ODataEntityDeserializer(_deserializerProvider);
            ODataNavigationLinkWithItems navigationLink = new ODataNavigationLinkWithItems(new ODataNavigationLink());

            Assert.ThrowsArgumentNull(
                () => deserializer.ApplyNavigationProperty(entityResource: null, navigationLinkWrapper: navigationLink,
                                                           entityType: _productEdmType, readContext: _readContext),
                "entityResource");
        }
コード例 #5
0
        public void ApplyNavigationProperty_ThrowsODataException_NavigationPropertyNotfound()
        {
            var deserializer = new ODataEntityDeserializer(_deserializerProvider);
            ODataNavigationLinkWithItems navigationLink = new ODataNavigationLinkWithItems(new ODataNavigationLink {
                Name = "SomeProperty"
            });

            Assert.Throws <ODataException>(
                () => deserializer.ApplyNavigationProperty(42, navigationLink, _productEdmType, _readContext),
                "Cannot find navigation property 'SomeProperty' on the entity type 'ODataDemo.Product'.");
        }
コード例 #6
0
        public void ApplyNavigationProperty_ThrowsODataException_WhenPatchingCollectionNavigationProperty()
        {
            var deserializer = new ODataEntityDeserializer(_deserializerProvider);
            ODataNavigationLinkWithItems navigationLink = new ODataNavigationLinkWithItems(new ODataNavigationLink {
                Name = "Products"
            });

            navigationLink.NestedItems.Add(new ODataFeedWithEntries(new ODataFeed()));
            _readContext.ResourceType = typeof(Delta <Supplier>);

            Assert.Throws <ODataException>(
                () => deserializer.ApplyNavigationProperty(42, navigationLink, _supplierEdmType, _readContext),
                "Cannot apply PATCH to navigation property 'Products' on entity type 'ODataDemo.Supplier'.");
        }
コード例 #7
0
        public void ApplyNavigationProperty_Calls_ReadInlineOnEntry()
        {
            // Arrange
            Mock<ODataEdmTypeDeserializer> supplierDeserializer = new Mock<ODataEdmTypeDeserializer>(ODataPayloadKind.Feed);
            Mock<ODataDeserializerProvider> deserializerProvider = new Mock<ODataDeserializerProvider>();
            var deserializer = new ODataEntityDeserializer(deserializerProvider.Object);
            ODataNavigationLinkWithItems navigationLink = new ODataNavigationLinkWithItems(new ODataNavigationLink { Name = "Supplier" });
            navigationLink.NestedItems.Add(new ODataEntryWithNavigationLinks(new ODataEntry()));

            Product product = new Product();
            Supplier supplier = new Supplier { ID = 42 };

            deserializerProvider.Setup(d => d.GetEdmTypeDeserializer(It.IsAny<IEdmTypeReference>())).Returns(supplierDeserializer.Object);
            supplierDeserializer
                .Setup(d => d.ReadInline(navigationLink.NestedItems[0], _productEdmType.FindNavigationProperty("Supplier").Type, _readContext))
                .Returns(supplier).Verifiable();

            // Act
            deserializer.ApplyNavigationProperty(product, navigationLink, _productEdmType, _readContext);

            // Assert
            supplierDeserializer.Verify();
            Assert.Equal(supplier, product.Supplier);
        }
コード例 #8
0
        public void ApplyNavigationProperty_Calls_ReadInlineOnFeed()
        {
            // Arrange
            IEdmCollectionTypeReference productsType = new EdmCollectionTypeReference(new EdmCollectionType(_productEdmType));
            Mock<ODataEdmTypeDeserializer> productsDeserializer = new Mock<ODataEdmTypeDeserializer>(ODataPayloadKind.Feed);
            Mock<ODataDeserializerProvider> deserializerProvider = new Mock<ODataDeserializerProvider>();
            var deserializer = new ODataEntityDeserializer(deserializerProvider.Object);
            ODataNavigationLinkWithItems navigationLink = new ODataNavigationLinkWithItems(new ODataNavigationLink { Name = "Products" });
            navigationLink.NestedItems.Add(new ODataFeedWithEntries(new ODataFeed()));

            Supplier supplier = new Supplier();
            IEnumerable products = new[] { new Product { ID = 42 } };

            deserializerProvider.Setup(d => d.GetEdmTypeDeserializer(It.IsAny<IEdmTypeReference>())).Returns(productsDeserializer.Object);
            productsDeserializer
                .Setup(d => d.ReadInline(navigationLink.NestedItems[0], _supplierEdmType.FindNavigationProperty("Products").Type, _readContext))
                .Returns(products).Verifiable();

            // Act
            deserializer.ApplyNavigationProperty(supplier, navigationLink, _supplierEdmType, _readContext);

            // Assert
            productsDeserializer.Verify();
            Assert.Equal(1, supplier.Products.Count());
            Assert.Equal(42, supplier.Products.First().ID);
        }
コード例 #9
0
        public void ApplyNavigationProperty_ThrowsODataException_WhenPatchingCollectionNavigationProperty()
        {
            var deserializer = new ODataEntityDeserializer(_deserializerProvider);
            ODataNavigationLinkWithItems navigationLink = new ODataNavigationLinkWithItems(new ODataNavigationLink { Name = "Products" });
            navigationLink.NestedItems.Add(new ODataFeedWithEntries(new ODataFeed()));
            _readContext.ResourceType = typeof(Delta<Supplier>);

            Assert.Throws<ODataException>(
                () => deserializer.ApplyNavigationProperty(42, navigationLink, _supplierEdmType, _readContext),
                "Cannot apply PATCH to navigation property 'Products' on entity type 'ODataDemo.Supplier'.");
        }
コード例 #10
0
        public void ApplyNavigationProperty_ThrowsODataException_NavigationPropertyNotfound()
        {
            var deserializer = new ODataEntityDeserializer(_deserializerProvider);
            ODataNavigationLinkWithItems navigationLink = new ODataNavigationLinkWithItems(new ODataNavigationLink { Name = "SomeProperty" });

            Assert.Throws<ODataException>(
                () => deserializer.ApplyNavigationProperty(42, navigationLink, _productEdmType, _readContext),
                "Cannot find navigation property 'SomeProperty' on the entity type 'ODataDemo.Product'.");
        }
コード例 #11
0
 public void ApplyNavigationProperty_ThrowsArgumentNull_EntityResource()
 {
     var deserializer = new ODataEntityDeserializer(_deserializerProvider);
     ODataNavigationLinkWithItems navigationLink = new ODataNavigationLinkWithItems(new ODataNavigationLink());
     Assert.ThrowsArgumentNull(
         () => deserializer.ApplyNavigationProperty(entityResource: null, navigationLinkWrapper: navigationLink,
             entityType: _productEdmType, readContext: _readContext),
         "entityResource");
 }
コード例 #12
0
 public void ApplyNavigationProperty_ThrowsArgumentNull_NavigationLinkWrapper()
 {
     var deserializer = new ODataEntityDeserializer(_deserializerProvider);
     Assert.ThrowsArgumentNull(
         () => deserializer.ApplyNavigationProperty(42, navigationLinkWrapper: null, entityType: _productEdmType,
             readContext: _readContext),
         "navigationLinkWrapper");
 }