public void Http_Post_Order() { var uri = "http://localhost/NortwindApi/"; using (var client = new HttpClient()) { client.BaseAddress = new Uri(uri); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); client.SetBasicAuthentication("*****@*****.**", "Wayne!"); var model = new OrderModel() { CustomerID = "VINET", ShipCity = "Boston", IsShipped = true }; HttpResponseMessage response = client.PostAsJsonAsync("api/orders", model).Result; Assert.IsTrue(response.IsSuccessStatusCode); var content = response.Content.ReadAsStringAsync().Result; Assert.IsTrue(!String.IsNullOrEmpty(content)); var order = JsonConvert.DeserializeObject<Order>(content); Assert.IsNotNull(order); } }
public static Order Parse(OrderModel model) { return new Order { CustomerID = model.CustomerID, OrderID = model.OrderID, ShipCity = model.ShipCity }; }