public void CreateResource_CreateDeltaWith_OpenComplexType() { // Arrange ODataConventionModelBuilder builder = new ODataConventionModelBuilder(); builder.ComplexType <SimpleOpenAddress>(); IEdmModel model = builder.GetEdmModel(); IEdmComplexTypeReference addressTypeReference = model.GetEdmTypeReference(typeof(SimpleOpenAddress)).AsComplex(); ODataDeserializerContext readContext = new ODataDeserializerContext { Model = model, ResourceType = typeof(Delta <SimpleOpenAddress>) }; var structuralProperties = addressTypeReference.StructuralProperties().Select(p => p.Name); // Act Delta <SimpleOpenAddress> resource = ODataComplexTypeDeserializer.CreateResource(addressTypeReference, readContext) as Delta <SimpleOpenAddress>; // Assert Assert.NotNull(resource); Assert.Equal(structuralProperties, resource.GetUnchangedPropertyNames()); }
public void ReadFromStreamAsync_ForComplexType_WithNestedComplexType() { // Arrange const string content = "{\"value\":{" + "\"City\":\"UpdatedCity\"," + "\"Location\": {" + "\"Latitude\": 30.6," + "\"Longitude\": 101.313" + "}," + "\"SubLocation\": {" + // dynamic property "\"@odata.type\":\"#System.Web.OData.Formatter.Deserialization.Location\"," + "\"Latitude\": 15.5," + "\"Longitude\": 130.88" + "}" + "}}"; ODataComplexTypeDeserializer deserializer = new ODataComplexTypeDeserializer(new DefaultODataDeserializerProvider()); ODataConventionModelBuilder builder = new ODataConventionModelBuilder(); builder.ComplexType <Region>(); IEdmModel model = builder.GetEdmModel(); ODataDeserializerContext readContext = new ODataDeserializerContext { Model = model, ResourceType = typeof(Delta <Region>) }; // Act object value = deserializer.Read(GetODataMessageReader(GetODataMessage(content), model), typeof(Delta <Region>), readContext); // Assert Delta <Region> region = Assert.IsType <Delta <Region> >(value); Assert.NotNull(region); Assert.Equal(new[] { "City", "Location" }, region.GetChangedPropertyNames()); Assert.Empty(region.GetUnchangedPropertyNames()); object propertyValue; Assert.True(region.TryGetPropertyValue("City", out propertyValue)); string cityValue = Assert.IsType <string>(propertyValue); Assert.Equal("UpdatedCity", cityValue); Assert.True(region.TryGetPropertyValue("Location", out propertyValue)); Location locationValue = Assert.IsType <Location>(propertyValue); Assert.Equal(30.6, locationValue.Latitude); Assert.Equal(101.313, locationValue.Longitude); // dynamic property Assert.True(region.TryGetPropertyValue("SubLocation", out propertyValue)); locationValue = Assert.IsType <Location>(propertyValue); Assert.Equal(15.5, locationValue.Latitude); Assert.Equal(130.88, locationValue.Longitude); }
public void TestDelta_IgnoredMember() { //Arrange var delta = new Delta <NewCustomerDataContract>(); //Act var properties = delta.GetUnchangedPropertyNames().ToList(); //Assert Assert.Equal(2, properties.Count); Assert.Equal("Name", properties[0]); Assert.Equal("Street", properties[1]); }
public void TestDelta_IgnoresUnmapped() { //Arrange var delta = new Delta <NewCustomerUnmapped>(); //Act var properties = delta.GetUnchangedPropertyNames().ToList(); //Assert Assert.Equal(3, properties.Count); Assert.Equal("Id", properties.First()); Assert.Equal("City", properties[1]); Assert.Equal("State", properties[2]); }
public void ReadFromStreamAsync_ForOpenComplexType_ForPatchModel() { // Arrange const string content = "{\"value\":{" + "\"Street\":\"UpdateStreet\"," + "\"[email protected]\":\"#Date\"," + "\"Publish\":\"2016-02-22\"" + "}}"; ODataComplexTypeDeserializer deserializer = new ODataComplexTypeDeserializer(new DefaultODataDeserializerProvider()); ODataConventionModelBuilder builder = new ODataConventionModelBuilder(); builder.ComplexType <SimpleOpenAddress>(); IEdmModel model = builder.GetEdmModel(); ODataDeserializerContext readContext = new ODataDeserializerContext { Model = model, ResourceType = typeof(Delta <SimpleOpenAddress>) }; // Act object value = deserializer.Read(GetODataMessageReader(GetODataMessage(content), model), typeof(Delta <SimpleOpenAddress>), readContext); // Assert Delta <SimpleOpenAddress> address = Assert.IsType <Delta <SimpleOpenAddress> >(value); Assert.NotNull(address); Assert.Equal(new[] { "Street" }, address.GetChangedPropertyNames()); Assert.Equal(new[] { "City" }, address.GetUnchangedPropertyNames()); SimpleOpenAddress origin = new SimpleOpenAddress(); Assert.Null(origin.Street); // guard Assert.Null(origin.City); // guard Assert.Null(origin.Properties); // guard address.Patch(origin); // DO PATCH Assert.Equal("UpdateStreet", origin.Street); Assert.Null(origin.City); // not changed KeyValuePair <string, object> dynamicProperty = Assert.Single(origin.Properties); Assert.Equal("Publish", dynamicProperty.Key); Assert.Equal(new Date(2016, 2, 22), dynamicProperty.Value); }
public void CreateEntityResource_CreatesDeltaWith_ExpectedUpdatableProperties() { // Arrange var deserializer = new ODataEntityDeserializer(_deserializerProvider); ODataDeserializerContext readContext = new ODataDeserializerContext { Model = _readContext.Model, ResourceType = typeof(Delta <Product>) }; var structuralProperties = _productEdmType.StructuralProperties().Select(p => p.Name); // Act Delta <Product> resource = deserializer.CreateEntityResource(_productEdmType, readContext) as Delta <Product>; // Assert Assert.NotNull(resource); Assert.Equal(structuralProperties, resource.GetUnchangedPropertyNames()); }
public void CreateResource_CreatesDeltaWith_ExpectedUpdatableProperties() { // Arrange ODataDeserializerContext readContext = new ODataDeserializerContext { Model = _edmModel, ResourceType = typeof(Delta <ODataEntityDeserializerTests.Address>) }; var structuralProperties = _addressEdmType.StructuralProperties().Select(p => p.Name); // Act Delta <ODataEntityDeserializerTests.Address> resource = ODataComplexTypeDeserializer.CreateResource(_addressEdmType, readContext) as Delta <ODataEntityDeserializerTests.Address>; // Assert Assert.NotNull(resource); Assert.Equal(structuralProperties, resource.GetUnchangedPropertyNames()); }