Пример #1
0
        public async Task PutEntityWithStoreGeneratedProperty()
        {
            const string expectedComputedProperty = "ComputedProperty";
            const string expectedName             = "ChangedName";

            // Put a customer
            var putUri      = this.BaseAddress + "/odata/StoreGeneratedPatternCustomers(0)";
            var putCustomer = new StoreGeneratedPatternCustomer()
            {
                Id               = 0,
                Name             = expectedName,
                ComputedProperty = "TestProperty"
            };

            using (var response = await Client.PutAsJsonAsync(putUri, putCustomer))
            {
                Assert.True(response.IsSuccessStatusCode);
            }

            // Get to verify
            var getUri = this.BaseAddress + "/odata/StoreGeneratedPatternCustomers(0)";

            using (var response = await Client.GetAsync(getUri))
            {
                Assert.True(response.IsSuccessStatusCode);
                JObject result           = response.Content.ReadAsAsync <JObject>().Result;
                var     id               = (int)result["Id"];
                var     name             = (string)result["Name"];
                var     computedProperty = (string)result["ComputedProperty"];
                Assert.Equal(0, id);
                Assert.Equal(expectedName, name);
                Assert.Equal(expectedComputedProperty, computedProperty);
            }
        }
Пример #2
0
        public IHttpActionResult Post(StoreGeneratedPatternCustomer customer)
        {
            customer.Id = customers.Max(c => c.Id) + 1;
            customer.ComputedProperty = ComputedPropertyValue;

            customers.Add(customer);
            return(Created(customer));
        }
        public IHttpActionResult Post(StoreGeneratedPatternCustomer customer)
        {
            customer.Id = customers.Max(c => c.Id) + 1;
            customer.ComputedProperty = ComputedPropertyValue;

            customers.Add(customer);
            return Created(customer);
        }
        public IHttpActionResult Put(int key, StoreGeneratedPatternCustomer customer)
        {
            var originalCustomer = customers.Single(c => c.Id == key);
            customer.Id = originalCustomer.Id;
            customer.ComputedProperty = ComputedPropertyValue;

            customers.Remove(originalCustomer);
            customers.Add(customer);
            return Ok(customer);
        }
Пример #5
0
        public IHttpActionResult Put(int key, StoreGeneratedPatternCustomer customer)
        {
            var originalCustomer = customers.Single(c => c.Id == key);

            customer.Id = originalCustomer.Id;
            customer.ComputedProperty = ComputedPropertyValue;

            customers.Remove(originalCustomer);
            customers.Add(customer);
            return(Ok(customer));
        }
Пример #6
0
        public async Task CreateEntityWithStoreGeneratedProperty()
        {
            int          num;
            const string expectedComputedProperty = "ComputedProperty";
            // Get all customers
            var getAllUri = this.BaseAddress + "/odata/StoreGeneratedPatternCustomers";

            using (var response = await Client.GetAsync(getAllUri))
            {
                Assert.True(response.IsSuccessStatusCode);
                var json = await response.Content.ReadAsAsync <JObject>();

                var result = json.GetValue("value") as JArray;
                num = result.Count;
            }

            // Post a new customer
            var postUri      = this.BaseAddress + "/odata/StoreGeneratedPatternCustomers";
            var postCustomer = new StoreGeneratedPatternCustomer()
            {
                Name             = "PostedName",
                ComputedProperty = "TestProperty"
            };
            var content = new ObjectContent(postCustomer.GetType(), postCustomer, new JsonMediaTypeFormatter());

            using (var response = await Client.PostAsync(postUri, content))
            {
                Assert.True(response.IsSuccessStatusCode);
                JObject result           = response.Content.ReadAsAsync <JObject>().Result;
                var     id               = (int)result["Id"];
                var     computedProperty = (string)result["ComputedProperty"];
                Assert.Equal(num, id);
                Assert.Equal(expectedComputedProperty, computedProperty);
            }

            // Get to verify
            var getUri = string.Format("{0}/odata/StoreGeneratedPatternCustomers({1})", this.BaseAddress, num);

            using (var response = await Client.GetAsync(getUri))
            {
                Assert.True(response.IsSuccessStatusCode);
                JObject result           = response.Content.ReadAsAsync <JObject>().Result;
                var     id               = (int)result["Id"];
                var     computedProperty = (string)result["ComputedProperty"];
                Assert.Equal(num, id);
                Assert.Equal(expectedComputedProperty, computedProperty);
            }
        }
        public async Task CreateEntityWithStoreGeneratedProperty()
        {
            int num;
            const string expectedComputedProperty = "ComputedProperty";
            // Get all customers
            var getAllUri = this.BaseAddress + "/odata/StoreGeneratedPatternCustomers";
            using (var response = await Client.GetAsync(getAllUri))
            {
                Assert.True(response.IsSuccessStatusCode);
                var json = await response.Content.ReadAsAsync<JObject>();
                var result = json.GetValue("value") as JArray;
                num = result.Count;
            }

            // Post a new customer
            var postUri = this.BaseAddress + "/odata/StoreGeneratedPatternCustomers";
            var postCustomer = new StoreGeneratedPatternCustomer()
            {
                Name = "PostedName",
                ComputedProperty = "TestProperty"
            };
            var content = new ObjectContent(postCustomer.GetType(), postCustomer, new JsonMediaTypeFormatter());
            using (var response = await Client.PostAsync(postUri, content))
            {
                Assert.True(response.IsSuccessStatusCode);
                JObject result = response.Content.ReadAsAsync<JObject>().Result;
                var id = (int)result["Id"];
                var computedProperty = (string)result["ComputedProperty"];
                Assert.Equal(num, id);
                Assert.Equal(expectedComputedProperty, computedProperty);
            }

            // Get to verify
            var getUri = string.Format("{0}/odata/StoreGeneratedPatternCustomers({1})", this.BaseAddress, num);
            using (var response = await Client.GetAsync(getUri))
            {
                Assert.True(response.IsSuccessStatusCode);
                JObject result = response.Content.ReadAsAsync<JObject>().Result;
                var id = (int)result["Id"];
                var computedProperty = (string)result["ComputedProperty"];
                Assert.Equal(num, id);
                Assert.Equal(expectedComputedProperty, computedProperty);
            }
        }
        public async Task PutEntityWithStoreGeneratedProperty()
        {
            const string expectedComputedProperty = "ComputedProperty";
            const string expectedName = "ChangedName";

            // Put a customer
            var putUri = this.BaseAddress + "/odata/StoreGeneratedPatternCustomers(0)";
            var putCustomer = new StoreGeneratedPatternCustomer()
            {
                Id = 0,
                Name = expectedName,
                ComputedProperty = "TestProperty"
            };
            using (var response = await Client.PutAsJsonAsync(putUri, putCustomer))
            {
                Assert.True(response.IsSuccessStatusCode);
            }

            // Get to verify
            var getUri = this.BaseAddress + "/odata/StoreGeneratedPatternCustomers(0)";
            using (var response = await Client.GetAsync(getUri))
            {
                Assert.True(response.IsSuccessStatusCode);
                JObject result = response.Content.ReadAsAsync<JObject>().Result;
                var id = (int)result["Id"];
                var name = (string)result["Name"];
                var computedProperty = (string)result["ComputedProperty"];
                Assert.Equal(0, id);
                Assert.Equal(expectedName, name);
                Assert.Equal(expectedComputedProperty, computedProperty);
            }
        }