public ITestActionResult PutToAddress(int key, Delta <OpenAddress> address) { IList <OpenCustomer> customers = CreateCustomers(); OpenCustomer customer = customers.FirstOrDefault(c => c.CustomerId == key); if (customer == null) { return(NotFound()); } // Verify the origin address OpenAddress origin = customer.Address; VerifyOriginAddress(key, origin); address.Put(origin); // Do put // Verify the put address Assert.Equal("UpdatedStreet", origin.Street); Assert.Equal("UpdatedCity", origin.City); Assert.NotNull(origin.DynamicProperties); KeyValuePair <string, object> dynamicProperty = Assert.Single(origin.DynamicProperties); // only one Assert.Equal("Publish", dynamicProperty.Key); Assert.Equal(new Date(2016, 2, 2), dynamicProperty.Value); return(Updated(customer)); }
public ITestActionResult PatchToAddress(int key, Delta <OpenAddress> address) { IList <OpenCustomer> customers = CreateCustomers(); OpenCustomer customer = customers.FirstOrDefault(c => c.CustomerId == key); if (customer == null) { return(NotFound()); } // Verify the origin address OpenAddress origin = customer.Address; VerifyOriginAddress(key, origin); address.Patch(origin); // Do patch // Verify the patched address Assert.Equal("UpdatedStreet", origin.Street); Assert.Equal("City " + key, origin.City); // not changed Assert.NotNull(origin.DynamicProperties); Assert.Equal(3, origin.DynamicProperties.Count); // include the origin dynamic properties KeyValuePair <string, object> dynamicProperty = origin.DynamicProperties.FirstOrDefault(e => e.Key == "Token"); Assert.Equal(new Guid("2E724E81-8462-4BA0-B920-DC87A61C8EA3"), dynamicProperty.Value); dynamicProperty = origin.DynamicProperties.FirstOrDefault(e => e.Key == "BirthDay"); Assert.Equal(new Date(2016, 1, 29), dynamicProperty.Value); return(Updated(customer)); }
private static void VerifyOriginAddress(int key, OpenAddress address) { Assert.NotNull(address); Assert.Equal("Street " + key, address.Street); Assert.Equal("City " + key, address.City); Assert.NotNull(address.DynamicProperties); KeyValuePair <string, object> dynamicProperty = Assert.Single(address.DynamicProperties); Assert.Equal("IntProp", dynamicProperty.Key); Assert.Equal(new int[] { 200, 100, 300, 0, 400 }[key], dynamicProperty.Value); }
public ITestActionResult GetAddress(int key) { IList <OpenCustomer> customers = CreateCustomers(); OpenCustomer customer = customers.FirstOrDefault(c => c.CustomerId == key); if (customer == null) { return(NotFound()); } OpenAddress address = customer.Address; // Add more dynamic properties address.DynamicProperties.Add("Place", "My Dynamic Place"); address.DynamicProperties.Add("Token", new Guid("2C1F450A-A2A7-4FE1-A25D-4D9332FC0694")); address.DynamicProperties.Add("Birthday", new Date(2015, 3, 2)); address.DynamicProperties.Add("Region", null); return(Ok(address)); }