public void ReadSource_CanReadDynamicPropertiesForInheritanceOpenEntityType() { // Arrange ODataConventionModelBuilder builder = new ODataConventionModelBuilder(); builder.EntityType <SimpleOpenCustomer>(); builder.EnumType <SimpleEnum>(); IEdmModel model = builder.GetEdmModel(); IEdmEntityTypeReference vipCustomerTypeReference = model.GetEdmTypeReference(typeof(SimpleVipCustomer)).AsEntity(); var deserializer = new ODataResourceDeserializer(_deserializerProvider); ODataResource resource = new ODataResource { Properties = new[] { // declared properties new ODataProperty { Name = "CustomerId", Value = 121 }, new ODataProperty { Name = "Name", Value = "VipName #121" }, new ODataProperty { Name = "VipNum", Value = "Vip Num 001" }, // dynamic properties new ODataProperty { Name = "GuidProperty", Value = new Guid("181D3A20-B41A-489F-9F15-F91F0F6C9ECA") }, }, TypeName = typeof(SimpleVipCustomer).FullName }; ODataDeserializerContext readContext = new ODataDeserializerContext() { Model = model }; ODataResourceWrapper resourceWrapper = new ODataResourceWrapper(resource); // Act SimpleVipCustomer customer = deserializer.ReadResource(resourceWrapper, vipCustomerTypeReference, readContext) as SimpleVipCustomer; // Assert Assert.NotNull(customer); // Verify the declared properties Assert.Equal(121, customer.CustomerId); Assert.Equal("VipName #121", customer.Name); Assert.Equal("Vip Num 001", customer.VipNum); // Verify the dynamic properties Assert.NotNull(customer.CustomerProperties); Assert.Equal(1, customer.CustomerProperties.Count()); Assert.Equal(new Guid("181D3A20-B41A-489F-9F15-F91F0F6C9ECA"), customer.CustomerProperties["GuidProperty"]); }
private static IList <SimpleOpenCustomer> CreateCustomers() { int[] IntValues = { 200, 100, 300, 0, 400 }; IList <SimpleOpenCustomer> customers = Enumerable.Range(0, 5).Select(i => new SimpleOpenCustomer { CustomerId = i, Name = "FirstName " + i, Address = new SimpleOpenAddress { Street = "Street " + i, City = "City " + i, Properties = new Dictionary <string, object> { { "IntProp", IntValues[i] } } }, Website = "WebSite #" + i }).ToList(); customers[2].CustomerProperties = new Dictionary <string, object> { { "Token", new Guid("2C1F450A-A2A7-4FE1-A25D-4D9332FC0694") }, { "IntList", new List <int> { 1, 2, 3, 4, 5, 6, 7 } }, }; customers[4].CustomerProperties = new Dictionary <string, object> { { "Token", new Guid("A6A594ED-375B-424E-AC0A-945D89CF7B9B") }, { "IntList", new List <int> { 1, 2, 3, 4, 5, 6, 7 } }, }; SimpleOpenAddress address = new SimpleOpenAddress { Street = "SubStreet", City = "City" }; customers[3].CustomerProperties = new Dictionary <string, object> { { "ComplexList", new[] { address, address } } }; SimpleVipCustomer vipCustomer = new SimpleVipCustomer { CustomerId = 9, Name = "VipCustomer", Address = new SimpleOpenAddress { Street = "Vip Street ", City = "Vip City ", }, VipNum = "99-001", CustomerProperties = new Dictionary <string, object> { { "ListProp", IntValues }, { "DateList", new[] { Date.MinValue, Date.MaxValue } }, { "Receipt", null } } }; customers.Add(vipCustomer); return(customers); }