[HttpGet("ordersbystatus")] //Получение заказов по статусу -Ok public async Task <IActionResult> GetOrdersByStatus([FromBody] GetOrderByStatus request) { if (ModelState.IsValid) { List <Order> filteredorders = await unitOfWork.Orders.GetAsync(request.orderStatus); if (filteredorders.Count > 0) { return(Json(filteredorders)); } else { return(NotFound("Order is not found")); } } else { return(BadRequest("Incorrect input")); } }
public async void GetOrdersByStatusOk() { //Arrange GetOrderByStatus request = new GetOrderByStatus() { orderStatus = OrderStatus.New }; var unitofworkMock = GetUnitOfWorkMock(); unitofworkMock.Setup(u => u.Orders.GetAsync(It.IsAny <OrderStatus>())) .ReturnsAsync(GetOrdersMock().FindAll(o => o.OrderStatus == request.orderStatus)); UserController userController = new UserController( unitofworkMock.Object); //Act var result = await userController.GetOrdersByStatus(request) as JsonResult; //Assert var orders = Assert.IsType <List <Order> >(result.Value); Assert.Equal(orders.Count, 1); }
public async void GetOrdersByStatusNotFound() { //Arrange GetOrderByStatus request = new GetOrderByStatus() { orderStatus = OrderStatus.Finished }; var unitofworkMock = GetUnitOfWorkMock(); unitofworkMock.Setup(u => u.Orders.GetAsync(It.IsAny <OrderStatus>())) .ReturnsAsync(GetOrdersMock().FindAll(o => o.OrderStatus == request.orderStatus)); UserController userController = new UserController( unitofworkMock.Object); //Act var result = await userController.GetOrdersByStatus(request) as NotFoundObjectResult; //Assert var orderserror = Assert.IsType <string>(result.Value); Assert.Equal(orderserror, "Order is not found"); }