public async void ShouldDeleteOrder() { using (var client = new HttpClient()) { await AccountTestHelpers.LoginAsAdmin(ServiceAddress, $"api/account/login", client); var targetUrl = $"{ServiceAddress}{RootAddressOrderController}/{_orderId}"; var response = await client.DeleteAsync(targetUrl); Assert.True(response.IsSuccessStatusCode, response.ReasonPhrase); List <Order> orders = await OrderTestHelpers.GetOrders(ServiceAddress, RootAddressProductController, client); Assert.Single(orders); await AccountTestHelpers.Logout(ServiceAddress, $"api/account/logout", client); } }
public async void ShouldGetOrdersForCurrentCustomer() { using (var client = new HttpClient()) { await AccountTestHelpers.LoginAsUser(ServiceAddress, $"api/account/login", client); await OrderTestHelpers.Create3OrdersForCurrentUser(ServiceAddress, "api/orders/user", client); var response = await client.GetAsync($"{ServiceAddress}api/orders/user"); Assert.True(response.IsSuccessStatusCode); var jsonResponse = await response.Content.ReadAsStringAsync(); var orders = JsonConvert.DeserializeObject <List <Order> >(jsonResponse); Assert.Equal(3, orders.Count); await AccountTestHelpers.Logout(ServiceAddress, $"api/account/logout", client); } }
public async void ShouldCalculateTotalOfOrder() { using (var client = new HttpClient()) { await AccountTestHelpers.LoginAsUser(ServiceAddress, $"api/account/login", client); object data = new Order { Name = "NameCustomer1", Address = "AddressCustomer1", Shipped = false, CartLines = new List <CartLine> { new CartLine { ProductId = 1, Quantity = 1, }, new CartLine { ProductId = 2, Quantity = 1, } }, PaymentNavigation = new Payment() { CardNumber = "111", CardExpiry = "222", CardSecurityCode = "333" } }; var myContent = JsonConvert.SerializeObject(data); var targetUrl = $"{ServiceAddress}api/orders"; var response = await client.PostAsync(targetUrl, new StringContent(myContent, Encoding.UTF8, "application/json")); Assert.True(response.IsSuccessStatusCode, response.ReasonPhrase); // validate the order was added List <Order> orders = await OrderTestHelpers.GetOrders(ServiceAddress, $"api/orders", client); var order = orders[orders.Count - 1]; Assert.Equal(323.95M, order.Total); await AccountTestHelpers.Logout(ServiceAddress, $"api/account/logout", client); } }
public async void ShouldMarkAnOrderAsShipped() { using (var client = new HttpClient()) { await AccountTestHelpers.LoginAsAdmin(ServiceAddress, $"api/account/login", client); var order = await OrderTestHelpers.GetOrder(_orderId, ServiceAddress, RootAddressOrderController, client); var targetUrl = $"{ServiceAddress}{RootAddressOrderController}/shipped/{_orderId}"; var response = await client.PostAsync(targetUrl, null); Assert.True(response.IsSuccessStatusCode, response.ReasonPhrase); var updatedOrder = await OrderTestHelpers.GetOrder(_orderId, ServiceAddress, RootAddressOrderController, client); Assert.True(updatedOrder.Shipped); await AccountTestHelpers.Logout(ServiceAddress, $"api/account/logout", client); } }
public async void ShouldUpdateAnOrder() { using (var client = new HttpClient()) { await AccountTestHelpers.LoginAsAdmin(ServiceAddress, $"api/account/login", client); var order = await OrderTestHelpers.GetOrder(_orderId, ServiceAddress, RootAddressOrderController, client); order.Address = "newAddress"; var json = JsonConvert.SerializeObject(order); var targetUrl = $"{ServiceAddress}{RootAddressOrderController}/{_orderId}"; var response = await client.PutAsync(targetUrl, new StringContent(json, Encoding.UTF8, "application/json")); Assert.True(response.IsSuccessStatusCode, response.ReasonPhrase); var updatedOrder = await OrderTestHelpers.GetOrder(_orderId, ServiceAddress, RootAddressOrderController, client); Assert.Equal("newAddress", updatedOrder.Address); await AccountTestHelpers.Logout(ServiceAddress, $"api/account/logout", client); } }