public async Task Create_NewOrder_And_Check_ReturnOrderObject() { // Add new Order with mocking/test var order = MockOrder.Order(); // Create/Initiate Client API endpoint using (var client = new TestClientProvider().Client) { // Create Json Object serialized // https://stackoverflow.com/questions/16098573/how-to-send-json-in-c-sharp-with-datacontractjsonserializer-without-charset var json = JsonObjectHelper.Serialize(order); var content = new StringContent(json, Encoding.UTF8, "application/json"); // Send post request to API endpoint and get response // TRY TO CHANCE Dummy Total AND POST WILL FAIL - see method : ValidateOrder.TotalCost(Order order) / sum all order/s var response = await client.PostAsync("api/orders/create", content); // Debug scope to see the object returned var newOrder = await JsonObjectHelper.Deserialize <Order>(response); // Test/Assert/Confirm 1 Assert.NotNull(newOrder); // Check/Assert THAT returned Order is not null // Test/Assert/Confirm 2 Assert.NotEqual(Guid.Empty, newOrder.Id); // Check/Assert THAT returned Order has a valid Guid Id // Test/Assert/Confirm 3 Assert.Equal(1, newOrder.StatusId); // Check/Assert THAT returned Order has a status -Accepted- aka 1 // Clean up and remove testorder using (var context = new TestDbContextProvider().DbContext) { context.Remove(newOrder); await context.SaveChangesAsync(); } } }
public async void Dispose() { using (var context = new TestDbContextProvider().DbContext) { context.Remove(Order); await context.SaveChangesAsync(); } }
public async Task <Order> CreateMockOrder() { using (var context = new TestDbContextProvider().DbContext) { // Create mock Order var order = MockOrder.Order(); // Add/Save to Db in memory, dummy Order context.Orders.Add(order); await context.SaveChangesAsync(); return(order); } }