public void Read_PatchMode()
        {
            // Arrange
            string         content            = Resources.SupplierPatch;
            IEdmEntityType supplierEntityType =
                EdmTestHelpers.GetModel().FindType("ODataDemo.Supplier") as IEdmEntityType;

            var readContext = new ODataDeserializerContext
            {
                Path         = new ODataPath(new EntitySetPathSegment(_edmModel.EntityContainer.FindEntitySet("Suppliers"))),
                Model        = _edmModel,
                ResourceType = typeof(Delta <Supplier>)
            };

            ODataEntityDeserializer deserializer =
                new ODataEntityDeserializer(_deserializerProvider);

            // Act
            Delta <Supplier> supplier = deserializer.Read(GetODataMessageReader(GetODataMessage(content), _edmModel),
                                                          typeof(Delta <Supplier>), readContext) as Delta <Supplier>;

            // Assert
            Assert.NotNull(supplier);
            Assert.Equal(supplier.GetChangedPropertyNames(), new string[] { "ID", "Name", "Address" });

            Assert.Equal((supplier as dynamic).Name, "Supplier Name");
            Assert.Equal("Supplier City", (supplier as dynamic).Address.City);
            Assert.Equal("123456", (supplier as dynamic).Address.ZipCode);
        }
        public void ReadInline()
        {
            // Arrange
            var deserializerProvider = new Mock <ODataDeserializerProvider>(EdmTestHelpers.GetModel()).Object;
            var deserializer         = new ODataComplexTypeDeserializer(_addressEdmType, deserializerProvider);

            ODataComplexValue complexValue = new ODataComplexValue
            {
                Properties = new[]
                {
                    new ODataProperty {
                        Name = "Street", Value = "12"
                    },
                    new ODataProperty {
                        Name = "City", Value = "Redmond"
                    }
                },
                TypeName = "ODataDemo.Address"
            };

            // Act
            ODataEntityDeserializerTests.Address address =
                deserializer.ReadInline(
                    complexValue,
                    new ODataDeserializerContext()) as ODataEntityDeserializerTests.Address;

            // Assert
            Assert.NotNull(address);
            Assert.Equal(address.Street, "12");
            Assert.Equal(address.City, "Redmond");
            Assert.Null(address.Country);
            Assert.Null(address.State);
            Assert.Null(address.ZipCode);
        }
        public void ReadFromStreamAsync_ComplexTypeAndInlineData()
        {
            // Arrange
            string         content            = Resources.SupplierRequestEntry;
            IEdmEntityType supplierEntityType =
                EdmTestHelpers.GetModel().FindType("ODataDemo.Supplier") as IEdmEntityType;

            ODataEntityDeserializer deserializer = new ODataEntityDeserializer(_deserializerProvider);

            var readContext = new ODataDeserializerContext
            {
                Path         = new ODataPath(new EntitySetPathSegment(_edmModel.EntityContainer.FindEntitySet("Suppliers"))),
                Model        = _edmModel,
                ResourceType = typeof(Supplier)
            };

            // Act
            Supplier supplier = deserializer.Read(GetODataMessageReader(GetODataMessage(content), _edmModel),
                                                  typeof(Supplier), readContext) as Supplier;

            // Assert
            Assert.Equal(supplier.Name, "Supplier Name");

            Assert.NotNull(supplier.Products);
            Assert.Equal(6, supplier.Products.Count);
            Assert.Equal("soda", supplier.Products.ToList()[1].Name);

            Assert.NotNull(supplier.Address);
            Assert.Equal("Supplier City", supplier.Address.City);
            Assert.Equal("123456", supplier.Address.ZipCode);
        }
Пример #4
0
        public void Constructor_Succeeds_ForValidComplexType()
        {
            var deserializerProvider = new Mock <ODataDeserializerProvider>().Object;
            var deserializer         = new ODataComplexTypeDeserializer(_addressEdmType, deserializerProvider);

            Assert.Equal(deserializer.DeserializerProvider, deserializerProvider);
            Assert.Equal(deserializer.ComplexType.Definition, EdmTestHelpers.GetEdmType("ODataDemo.Address"));
            Assert.Equal(deserializer.ODataPayloadKind, ODataPayloadKind.Property);
        }
Пример #5
0
        private void Read_ThrowsOnUnknownEntityType(string content, bool json, string expectedMessage)
        {
            IEdmEntityType supplierEntityType =
                EdmTestHelpers.GetModel().FindType("ODataDemo.Supplier") as IEdmEntityType;

            ODataEntityDeserializer deserializer = new ODataEntityDeserializer(_deserializerProvider);

            Assert.Throws <ODataException>(() => deserializer.Read(GetODataMessageReader(GetODataMessage(content, json), _edmModel),
                                                                   typeof(Product), _readContext), expectedMessage);
        }
        public void ReadInline_Throws_ForNonODataComplexValues()
        {
            var deserializerProvider = new Mock <ODataDeserializerProvider>(EdmTestHelpers.GetModel()).Object;
            var deserializer         = new ODataComplexTypeDeserializer(_addressEdmType, deserializerProvider);

            Assert.ThrowsArgument(() =>
            {
                deserializer.ReadInline(10, new ODataDeserializerContext());
            }, "item");
        }
Пример #7
0
        public void Read_Throws_On_UnknownEntityType()
        {
            IEdmEntityType supplierEntityType = EdmTestHelpers.GetModel().FindType("ODataDemo.Supplier") as IEdmEntityType;

            ODataEntityDeserializer deserializer = new ODataEntityDeserializer(_productEdmType, _deserializerProvider);

            Assert.Throws <ODataException>(
                () => deserializer.Read(GetODataMessageReader(GetODataMessage(BaselineResource.SuppliersInsertData), _edmModel), _readContext),
                "An entry with type 'ODataDemo.Supplier' was found, but it is not assignable to the expected type 'ODataDemo.Product'. The type specified in the entry must be equal to either the expected type or a derived type.");
        }
        public void Read_ThrowsOnUnknownEntityType()
        {
            // Arrange
            string         content            = Resources.SupplierRequestEntry;
            IEdmEntityType supplierEntityType =
                EdmTestHelpers.GetModel().FindType("ODataDemo.Supplier") as IEdmEntityType;

            ODataEntityDeserializer deserializer = new ODataEntityDeserializer(_deserializerProvider);

            // Act & Assert
            Assert.Throws <ODataException>(() => deserializer.Read(GetODataMessageReader(GetODataMessage(content), _edmModel),
                                                                   typeof(Product), _readContext), "The property 'Concurrency' does not exist on type 'ODataDemo.Product'. Make sure to only use property names that are defined by the type.");
        }
Пример #9
0
        public void Read_PatchMode_PatchKeyModeIsThrow()
        {
            IEdmEntityType supplierEntityType = EdmTestHelpers.GetModel().FindType("ODataDemo.Supplier") as IEdmEntityType;

            _readContext.IsPatchMode  = true;
            _readContext.PatchKeyMode = PatchKeyMode.Throw;

            ODataEntityDeserializer deserializer = new ODataEntityDeserializer(_supplierEdmType, _deserializerProvider);

            Assert.Throws <InvalidOperationException>(
                () => deserializer.Read(GetODataMessageReader(GetODataMessage(BaselineResource.SuppliersPatchData), _edmModel), _readContext),
                "Cannot apply PATCH on key property 'ID' on entity type 'ODataDemo.Supplier' when 'PatchKeyMode' is 'Throw'.");
        }
        public ODataEntityDeserializerTests()
        {
            _edmModel = EdmTestHelpers.GetModel();
            IEdmEntitySet entitySet = _edmModel.EntityContainers().Single().FindEntitySet("Products");

            _readContext = new ODataDeserializerContext
            {
                Path  = new ODataPath(new EntitySetPathSegment(entitySet)),
                Model = _edmModel
            };
            _productEdmType       = _edmModel.GetEdmTypeReference(typeof(Product)).AsEntity();
            _supplierEdmType      = _edmModel.GetEdmTypeReference(typeof(Supplier)).AsEntity();
            _deserializerProvider = new DefaultODataDeserializerProvider();
        }
        public ODataResourceDeserializerTests()
        {
            _edmModel = EdmTestHelpers.GetModel();
            IEdmEntitySet entitySet = _edmModel.EntityContainer.FindEntitySet("Products");

            _readContext = new ODataDeserializerContext
            {
                Path         = new ODataPath(new EntitySetSegment(entitySet)),
                Model        = _edmModel,
                ResourceType = typeof(Product)
            };
            _productEdmType       = _edmModel.GetEdmTypeReference(typeof(Product)).AsEntity();
            _supplierEdmType      = _edmModel.GetEdmTypeReference(typeof(Supplier)).AsEntity();
            _addressEdmType       = _edmModel.GetEdmTypeReference(typeof(Address)).AsComplex();
            _deserializerProvider = DependencyInjectionHelper.GetDefaultODataDeserializerProvider();
        }
Пример #12
0
        public void Read_PatchMode()
        {
            IEdmEntityType supplierEntityType = EdmTestHelpers.GetModel().FindType("ODataDemo.Supplier") as IEdmEntityType;

            _readContext.IsPatchMode = true;

            ODataEntityDeserializer deserializer = new ODataEntityDeserializer(_supplierEdmType, _deserializerProvider);
            Delta <Supplier>        supplier     = deserializer.Read(GetODataMessageReader(GetODataMessage(BaselineResource.SuppliersPatchData), _edmModel), _readContext) as Delta <Supplier>;

            Assert.NotNull(supplier);
            Assert.Equal(supplier.GetChangedPropertyNames(), new string[] { "Name", "Address" });

            Assert.Equal((supplier as dynamic).Name, "Supplier Name");
            Assert.Equal("Supplier City", (supplier as dynamic).Address.City);
            Assert.Equal("123456", (supplier as dynamic).Address.ZipCode);
        }
Пример #13
0
        public void ReadFromStreamAsync_ComplexTypeAndInlineData()
        {
            IEdmEntityType supplierEntityType = EdmTestHelpers.GetModel().FindType("ODataDemo.Supplier") as IEdmEntityType;

            ODataEntityDeserializer deserializer = new ODataEntityDeserializer(_supplierEdmType, _deserializerProvider);
            Supplier supplier = deserializer.Read(GetODataMessageReader(GetODataMessage(BaselineResource.SuppliersInsertData), _edmModel), _readContext) as Supplier;

            Assert.Equal(supplier.Name, "Supplier Name");

            Assert.NotNull(supplier.Products);
            Assert.Equal(6, supplier.Products.Count);
            Assert.Equal("soda", supplier.Products.ToList()[1].Name);

            Assert.NotNull(supplier.Address);
            Assert.Equal("Supplier City", supplier.Address.City);
            Assert.Equal("123456", supplier.Address.ZipCode);
        }
Пример #14
0
        private void Read_PatchMode(string content, bool json)
        {
            IEdmEntityType supplierEntityType =
                EdmTestHelpers.GetModel().FindType("ODataDemo.Supplier") as IEdmEntityType;

            _readContext.ResourceType = typeof(Delta <Supplier>);

            ODataEntityDeserializer deserializer =
                new ODataEntityDeserializer(_deserializerProvider);
            Delta <Supplier> supplier = deserializer.Read(GetODataMessageReader(GetODataMessage(content, json), _edmModel),
                                                          typeof(Delta <Supplier>), _readContext) as Delta <Supplier>;

            Assert.NotNull(supplier);
            Assert.Equal(supplier.GetChangedPropertyNames(), new string[] { "ID", "Name", "Address" });

            Assert.Equal((supplier as dynamic).Name, "Supplier Name");
            Assert.Equal("Supplier City", (supplier as dynamic).Address.City);
            Assert.Equal("123456", (supplier as dynamic).Address.ZipCode);
        }
Пример #15
0
        private void ReadFromStreamAsync_ComplexTypeAndInlineData(string content, bool json)
        {
            IEdmEntityType supplierEntityType =
                EdmTestHelpers.GetModel().FindType("ODataDemo.Supplier") as IEdmEntityType;

            ODataEntityDeserializer deserializer = new ODataEntityDeserializer(_deserializerProvider);
            Supplier supplier = deserializer.Read(GetODataMessageReader(GetODataMessage(content, json), _edmModel),
                                                  typeof(Supplier), _readContext) as Supplier;

            Assert.Equal(supplier.Name, "Supplier Name");

            Assert.NotNull(supplier.Products);
            Assert.Equal(6, supplier.Products.Count);
            Assert.Equal("soda", supplier.Products.ToList()[1].Name);

            Assert.NotNull(supplier.Address);
            Assert.Equal("Supplier City", supplier.Address.City);
            Assert.Equal("123456", supplier.Address.ZipCode);
        }