Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
        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));
        }
Ejemplo 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);
        }
Ejemplo n.º 4
0
        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));
        }
Ejemplo n.º 5
0
        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.True(origin.DynamicProperties.Count >= 3); // Including the origin dynamic properties

            KeyValuePair <string, object> dynamicPropertyBirthDay = origin.DynamicProperties.FirstOrDefault(e => e.Key == "BirthDay");

            Assert.Equal(new Date(2016, 1, 29), dynamicPropertyBirthDay.Value);

            string dynamicPropertyToken = origin.DynamicProperties.FirstOrDefault(e => e.Key == "Token")
                                          .Value.ToString().ToUpperInvariant();

            switch (dynamicPropertyToken)
            {
            case "2E724E81-8462-4BA0-B920-DC87A61C8EA3":
                // All changed non-dynamic properties: ["Street"]
                Assert.True(address.GetChangedPropertyNames().Count() == 1);
                break;

            case "9B198CA0-9546-4162-A4C0-14EAA255ACA7":

                // All changed non-dynamic properties: ["Street", "LineB"]
                Assert.True(address.GetChangedPropertyNames().Count() == 2);

                Assert.Null(origin.LineA);

                Assert.NotNull(origin.LineB);
                Assert.Equal("DescriptionB", origin.LineB.Description);

                // Fee is not overwritten.
                Assert.Equal(LineDetails.DefaultValue_Fee, origin.LineB.Fee);
                break;

            case "A4D09554-5551-4B36-A1CB-CFBCDB1F4EAD":

                // All changed non-dynamic properties: ["Street", "LineA", "LineB"]
                Assert.True(address.GetChangedPropertyNames().Count() == 3);

                // --- LineA ---
                Assert.NotNull(origin.LineA);
                Assert.Equal("DescriptionA", origin.LineA.Description);

                // LineA.Fee is left as uninitialized.
                Assert.Equal(LineDetails.UninitializedValue_Fee, origin.LineA.Fee);

                Assert.NotNull(origin.LineA.PhoneInfo);
                Assert.Equal("ContactNameA", origin.LineA.PhoneInfo.ContactName);
                Assert.Equal(7654321, origin.LineA.PhoneInfo.PhoneNumber);

                // --- LineB ---
                Assert.NotNull(origin.LineB);
                Assert.Null(origin.LineB.Description);

                // LineB.Fee is originally initialized for OpenAddress is created for each customer.
                Assert.Equal(LineDetails.DefaultValue_Fee, origin.LineB.Fee);

                Assert.NotNull(origin.LineB.PhoneInfo);
                Assert.Equal("ContactNameB", origin.LineB.PhoneInfo.ContactName);
                Assert.Equal(0, origin.LineB.PhoneInfo.PhoneNumber);
                break;

            case "2D071BD4-E4FB-4639-8024-BBC173850441":
                // All changed non-dynamic properties: ["Street", "LineA"]
                Assert.True(address.GetChangedPropertyNames().Count() == 2);

                // --- LineA ---
                Assert.NotNull(origin.LineA);
                Assert.Equal("LineDetailsWithNewDeepSubNode.", origin.LineA.Description);
                Assert.Equal(LineDetails.UninitializedValue_Fee, origin.LineA.Fee);

                Assert.NotNull(origin.LineA.PhoneInfo);
                Assert.Equal("ContactNameA", origin.LineA.PhoneInfo.ContactName);
                Assert.Equal(0, origin.LineA.PhoneInfo.PhoneNumber);

                Assert.NotNull(origin.LineA.PhoneInfo.Spec);
                Assert.Null(origin.LineA.PhoneInfo.Spec.Make);
                Assert.Equal(6, origin.LineA.PhoneInfo.Spec.ScreenSize);

                // --- LineB ---
                Assert.NotNull(origin.LineB);
                break;

            case "250EFC6E-8FA4-4B68-951C-F1E26DE09D1D":
                Assert.True(origin.DynamicProperties.ContainsKey("Telephone"));
                // Telephone dynamic property
                Phone telephone = origin.DynamicProperties["Telephone"] as Phone;
                Assert.NotNull(telephone);
                Assert.Equal("ContactNameX", telephone.ContactName);
                Assert.Equal(13, telephone.PhoneNumber);

                // Nested complex property
                Assert.NotNull(telephone.Spec);
                Assert.Equal(7, telephone.Spec.ScreenSize);
                break;

            case "40CEEEDE-031C-45CB-9E44-E6017D635814":
                Assert.True(origin.DynamicProperties.ContainsKey("Building"));
                // Building dynamic property
                Building building = origin.DynamicProperties["Building"] as Building;
                Assert.NotNull(building);
                Assert.Equal("BuildingNameY", building.BuildingName);

                // Nested telephone complex dynamic property
                Assert.True(building.DynamicProperties.ContainsKey("Telephone"));
                Phone phone = building.DynamicProperties["Telephone"] as Phone;
                Assert.NotNull(phone);
                Assert.Equal("ContactNameZ", phone.ContactName);
                Assert.Equal(17, phone.PhoneNumber);

                // Nested complex property
                Assert.NotNull(phone.Spec);
                Assert.Equal(5, phone.Spec.ScreenSize);
                break;

            default:
                // Error
                Assert.True(false, "Unexpected token value " + dynamicPropertyToken);
                break;
            }

            return(Updated(customer));
        }