Пример #1
0
        public async Task Accept_OrderDoesExist_ResponseContainsExpectedValues()
        {
            await CreateRideWithLogin();

            ClearHeaders();
            //Login
            await LoginOnTaxiCompanyAccount("*****@*****.**");

            var id       = 1;
            var uri      = "/api/order/" + id + "/accept";
            var response = await PutAsync(uri, null);

            var responseObject = GetObject <AcceptOrderResponse>(response);

            AcceptOrderResponse expectedResponse = new AcceptOrderResponse()
            {
                Order = new OrderDto()
                {
                    Id     = 1,
                    Status = OrderStatus.Debited.ToString(),
                    Price  = 100,
                    Rides  = new List <RideDto>()
                    {
                    }
                }
            };

            Assert.That(responseObject.Order.Status, Is.EqualTo(expectedResponse.Order.Status));
        }
Пример #2
0
        public async Task AcceptOrder_WhenCalled_ReturnsExpectedAcceptOrderResponse()
        {
            var taxiCompanyId = "someId";
            var orderId       = 1;

            var orderDto = new OrderDto
            {
                Id     = orderId,
                Price  = 200,
                Rides  = null,
                Status = RideStatus.WaitingForAccept.ToString()
            };

            _mapper.Map <OrderDto>(null).ReturnsForAnyArgs(orderDto);
            var order       = new Order();
            var taxicompany = new TaxiCompany();

            _unitOfWork.OrderRepository.FindByIDAsync(null).ReturnsForAnyArgs(order);
            _unitOfWork.TaxiCompanyRepository.FindByIDAsync(null).ReturnsForAnyArgs(taxicompany);

            var expectedResponse = new AcceptOrderResponse {
                Order = orderDto
            };

            var response = await _orderService.AcceptOrderAsync(taxiCompanyId, orderId);

            Assert.That(response.Order, Is.EqualTo(expectedResponse.Order));
        }
Пример #3
0
        /// <summary>
        /// Changes an order and all its associated rides to the status 'Accepted'.
        /// </summary>
        /// <remarks>
        /// All customers are debited for the cost of the ride.<br/>
        /// All customers will also receive a notification to let them know,<br/>
        /// that the ride they ordered has been accepted and debited.
        /// </remarks>
        /// <param name="taxiCompanyId">The id of the taxi company who accepted the order.</param>
        /// <param name="orderId">The id of the order that should be accepted.</param>
        /// <returns>A response containing the updated order.</returns>
        public async Task <AcceptOrderResponse> AcceptOrderAsync(string taxiCompanyId, int orderId)
        {
            var order = await _unitOfWork.OrderRepository.FindByIDAsync(orderId);

            UpdateState(taxiCompanyId, order);
            await DebitCustomersAsync(order);

            await _unitOfWork.SaveChangesAsync();

            await NotifyCustomersAsync(order);

            var orderDto = _mapper.Map <OrderDto>(order);
            var response = new AcceptOrderResponse {
                Order = orderDto
            };

            return(response);
        }