コード例 #1
0
        public ITestActionResult GetNameById([FromODataUri] int CustomerId)
        {
            ConventionCustomer customer = ModelDataBase.Instance.Customers.Where(c => c.ID == CustomerId).FirstOrDefault();

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

            return(Ok(customer.Name));
        }
コード例 #2
0
        public async Task AttributeRouting_TopFunctionWithOneParameters()
        {
            // Arrange
            const int          CustomerId       = 407;                                                // a magic customer id, just for test
            ConventionCustomer expectedCustomer = ModelDataBase.Instance.GetCustomerById(CustomerId); // expected customer instance
            string             requestUri       = "http://localhost/GetConventionCustomerById(CustomerId=" + CustomerId + ")";
            HttpRequestMessage request          = new HttpRequestMessage(HttpMethod.Get, requestUri);

            // Act
            var response = await _client.SendAsync(request);

            string responseString = await response.Content.ReadAsStringAsync();

            // Assert
            Assert.NotNull(expectedCustomer);
            Assert.True(response.IsSuccessStatusCode);
            Assert.Contains("\"@odata.context\":\"http://localhost/$metadata#ConventionCustomers/$entity\"", responseString);
            string expect = "\"ID\":" + expectedCustomer.ID;

            Assert.Contains(expect, responseString);
            expect = "\"Name\":\"" + expectedCustomer.Name + "\"";
            Assert.Contains(expect, responseString);
        }
コード例 #3
0
        public ConventionCustomer CreateCustomerById(int customerId)
        {
            ConventionCustomer customer = _customers.Where(c => c.ID == customerId).FirstOrDefault();

            if (customer != null)
            {
                string message = String.Format("Customer with ID {0} already exists.", customerId);
                throw new Exception(message);
            }

            _customers.Add(new ConventionCustomer()
            {
                ID      = customerId,
                Name    = "Name " + customerId,
                Address = new ConventionAddress()
                {
                    Street  = "Street " + customerId,
                    City    = "City " + customerId,
                    ZipCode = (201100 + customerId).ToString()
                }
            });

            return(GetCustomerById(customerId));
        }
コード例 #4
0
 public ConventionCustomer CreateCustomer(ConventionCustomer customer)
 {
     // Just for tests; Normally, should check to ensure the ID does not exist.
     _customers.Add(customer);
     return(customer);
 }
コード例 #5
0
        public ConventionOrder GetConventionOrderByCustomerIdAndOrderName(int CustomerId, [FromODataUri] string OrderName)
        {
            ConventionCustomer customer = ModelDataBase.Instance.Customers.Where(c => c.ID == CustomerId).FirstOrDefault();

            return(customer.Orders.Where(o => o.OrderName == OrderName).FirstOrDefault());
        }