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)); }
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); }
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)); }
public ConventionCustomer CreateCustomer(ConventionCustomer customer) { // Just for tests; Normally, should check to ensure the ID does not exist. _customers.Add(customer); return(customer); }
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()); }