Beispiel #1
0
        public async Task <ActionResult <GetOrderByIdQueryResult> > Get(
            [FromRoute] GetOrderByIdQuery query,
            CancellationToken cancellationToken = default)
        {
            var queryResult = await _queryGateway.SendAsync <GetOrderByIdQuery, GetOrderByIdQueryResult>(query, cancellationToken);

            return(Ok(queryResult));
        }
Beispiel #2
0
        public OrdersControllersTests()
        {
            _createOrderCommand       = A.Fake <CreateOrderCommand>();
            _addProductToOrderCommand = A.Fake <AddProductToOrderCommand>();
            _getOrderByIdQuery        = A.Fake <GetOrderByIdQuery>();
            _addBundleToOrderCommand  = A.Fake <AddBundleToOrderCommand>();

            _ordersController = new OrdersController(_createOrderCommand, _addProductToOrderCommand, _getOrderByIdQuery, _addBundleToOrderCommand);
        }
        public async Task <IActionResult> Get(string id)
        {
            var query = new GetOrderByIdQuery {
                OrderId = id
            };
            var result = await mediator.Send(query);

            return(ConvertToResponse(result));
        }
        public async Task <IActionResult> GetAsync([FromRoute] long id)
        {
            var query = new GetOrderByIdQuery
            {
                Id = id
            };

            var response = await _mediator.Send(query);

            return(Json(response));
        }
Beispiel #5
0
        public async Task Handle_GivenInvalidRequest_ShouldThrowNotFoundException()
        {
            // Arrange
            var query = new GetOrderByIdQuery {
                Id = 1000
            };
            var sut = new GetOrderByIdQueryHandler(this.deletableEntityRepository);

            // Act & Assert
            await Should.ThrowAsync <NotFoundException>(sut.Handle(query, It.IsAny <CancellationToken>()));
        }
        public async Task <IActionResult> Get([FromRoute] GetOrderByIdQuery query)
        {
            var orderDetails = await _mediator.Send(query);

            if (orderDetails == null)
            {
                return(NotFound(query.Id));
            }

            return(Ok(orderDetails));
        }
Beispiel #7
0
        private OrdersService CreateOrdersService(bool empty = false)
        {
            mockDb = empty ? TestDatabaseFactory.CreateEmptyDatabase() : TestDatabaseFactory.CreateDatabase();

            mockQueryAllOrders   = new GetAllOrdersQuery(mockDb);
            mockQueryAllItems    = new GetAllItemsQuery(mockDb);
            mockQueryById        = new GetOrderByIdQuery(mockDb);
            mockQueryAddOrder    = new AddOrderQuery(mockDb);
            mockQueryDeleteOrder = new DeleteOrderQuery(mockDb);

            return(new OrdersService(mockQueryAllOrders, mockQueryAllItems, mockQueryById, mockQueryAddOrder, mockQueryDeleteOrder));
        }
Beispiel #8
0
        public async Task Handle_GivenValidRequest_ShouldReturnOrderLookUpModel()
        {
            // Arrange
            var query = new GetOrderByIdQuery {
                Id = 1
            };
            var sut = new GetOrderByIdQueryHandler(this.deletableEntityRepository);

            // Act
            var order = await sut.Handle(query, It.IsAny <CancellationToken>());

            order.ShouldNotBeNull();
            order.ShouldBeOfType <OrderLookupModel>();
            order.Description.ShouldBe("John");
        }
        public async Task <ActionResult> Get(int id)
        {
            OrderReadDto result;

            try
            {
                var query = new GetOrderByIdQuery(id);
                result = await _mediator.Send(query);
            }
            catch (Exception ex)
            {
                _logger.LogWarning($"Get order by id {id} failed!");
                return(NotFound(ex.Message));
            }

            _logger.LogInformation($"Get order by id {id} success!");
            return(Ok(result));
        }
        public async Task <ActionResult <IEnumerable <OrdersVm> > > GetOrderById(int id)
        {
            try
            {
                var query  = new GetOrderByIdQuery(id);
                var orders = await _mediator.Send(query);

                if (orders == null)
                {
                    return(NotFound());
                }

                return(Ok(orders));
            }
            catch (Exception ex)
            {
                _logger.LogError($"Error getting orders", ex);
                throw new Exception($"Error getting orders", ex);
            }
        }
Beispiel #11
0
 public Contract.DTOs.OrderInfo ExecuteGetOrderByIdQuery(GetOrderByIdQuery query)
 {
     return(Execute <GetOrderByIdQuery, Contract.DTOs.OrderInfo>(query));
 }
Beispiel #12
0
 public async Task <ActionResult <CommandResult <Order> > > GetById([FromBody] GetOrderByIdQuery query)
 {
     return(Ok(await _mediator.Send(query)));
 }