public async Task <ActionResult <OrderFullDto> > CarLeave(OrderPatchDto orderPatchDto) { await orderService.UpdateOrderCloseTime(orderPatchDto.OrderNumber); await orderService.CloseOrder(orderPatchDto.OrderNumber); return(Ok(await GetByNumber(orderPatchDto.OrderNumber))); }
public async Task Should_Patch_Order_When_Car_Leaves() { // given var client = GetClient(); var parkingLotDto = new ParkingLotDto() { Name = "parkinglot1", Capacity = 5, Location = "Beijing", }; var parkingLotContent = JsonConvert.SerializeObject(parkingLotDto); StringContent parkingLotcontent = new StringContent(parkingLotContent, Encoding.UTF8, MediaTypeNames.Application.Json); // when await client.PostAsync("/parkinglots", parkingLotcontent); var orderCreateDto = new OrderCreateDto() { ParkingLotName = "parkinglot1", PlateNumber = "abc123", }; var httpContent = JsonConvert.SerializeObject(orderCreateDto); StringContent content = new StringContent(httpContent, Encoding.UTF8, MediaTypeNames.Application.Json); // when var postResponse = await client.PostAsync("/orders", content); var responseBody = await postResponse.Content.ReadAsStringAsync(); var orderPatchDto = new OrderPatchDto() { OrderNumber = responseBody, }; var patchContent = JsonConvert.SerializeObject(orderPatchDto); StringContent content2 = new StringContent(patchContent, Encoding.UTF8, MediaTypeNames.Application.Json); await client.PatchAsync($"/orders/{responseBody}", content2); var orderResponse = await client.GetAsync($"/orders/{responseBody}"); var body = await orderResponse.Content.ReadAsStringAsync(); var returnOrder = JsonConvert.DeserializeObject <OrderFullDto>(body); // then Assert.Equal(OrderFullDto.OrderStatus.Close, returnOrder.Status); }