Esempio n. 1
0
        public IHttpActionResult 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));
        }
Esempio n. 2
0
        public IHttpActionResult 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.NotNull(dynamicProperty);
            Assert.Equal(new Guid("2E724E81-8462-4BA0-B920-DC87A61C8EA3"), dynamicProperty.Value);

            dynamicProperty = origin.DynamicProperties.FirstOrDefault(e => e.Key == "BirthDay");
            Assert.NotNull(dynamicProperty);
            Assert.Equal(new Date(2016, 1, 29), dynamicProperty.Value);

            return(Updated(customer));
        }
Esempio n. 3
0
        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 IHttpActionResult GetAddress(int key)
        {
            IList <OpenCustomer> customers = CreateCustomers();
            OpenCustomer         customer  = customers.Where(c => c.CustomerId == key).FirstOrDefault();

            if (customer == null)
            {
                return(NotFound());
            }

            OpenAddress address = customer.Address;

            // Add more dynamic properties
            address.DynamicProperties.Add("Country", "My Dynamic Country");
            address.DynamicProperties.Add("Token", new Guid("2C1F450A-A2A7-4FE1-A25D-4D9332FC0694"));
            return(Ok(address));
        }
 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);
 }