Exemplo n.º 1
0
        public async void DeliverTheVehicleResultVehicleIsDelivered()
        {
            var commonId = 1;
            var suite    = new OrderStateServiceTestSuite();

            var driver = new Driver {
                Id = commonId++
            };
            var order = new Order {
                Id = commonId++, DriverId = driver.Id
            };
            var currentState = new OrderState {
                Id = commonId++, OrderId = order.Id, Status = OrderStatus.VehicleIsLoaded
            };

            suite.DriverServiceMock
            .Setup(m => m.IsExist(driver.Id))
            .ReturnsAsync(true);
            suite.OrderServiceMock
            .Setup(m => m.Get(order.Id))
            .ReturnsAsync(order);
            suite.OrderStateRepositoryMock
            .Setup(m => m.GetCurrentState(order.Id))
            .ReturnsAsync(currentState);

            await suite.OrderStateService.DeliverTheVehicle(order.Id, driver.Id);

            suite.OrderStateRepositoryMock
            .Verify(m => m.Add(It.Is <OrderState>(
                                   s => s.OrderId.Equals(order.Id) &&
                                   s.Status.Equals(OrderStatus.VehicleIsDelivered))));
        }
Exemplo n.º 2
0
        public async void LoadTheVehicleWhenOrderStatusIsUnsuitable()
        {
            var commonId = 1;
            var suite    = new OrderStateServiceTestSuite();

            var driver = new Driver {
                Id = commonId++
            };
            var order = new Order {
                Id = commonId++, DriverId = driver.Id
            };
            var currentState = new OrderState {
                Id = commonId++, OrderId = order.Id, Status = OrderStatus.WentToCustomer
            };

            suite.DriverServiceMock
            .Setup(m => m.IsExist(driver.Id))
            .ReturnsAsync(true);
            suite.OrderServiceMock
            .Setup(m => m.Get(order.Id))
            .ReturnsAsync(order);
            suite.OrderStateRepositoryMock
            .Setup(m => m.GetCurrentState(order.Id))
            .ReturnsAsync(currentState);

            await Assert.ThrowsAsync <OrderStatusException>(() => suite.OrderStateService.LoadTheVehicle(order.Id, driver.Id));
        }
Exemplo n.º 3
0
        public async void ConfirmByDriver()
        {
            var commonId = 1;
            var suite    = new OrderStateServiceTestSuite();

            var driver = new Driver {
                Id = commonId++
            };
            var order = new Order {
                Id = commonId++, DriverId = driver.Id
            };
            var currentState = new OrderState {
                Id = commonId++, OrderId = order.Id, Status = OrderStatus.AssignedDriver
            };

            suite.DriverServiceMock
            .Setup(m => m.IsExist(driver.Id))
            .ReturnsAsync(true);
            suite.OrderServiceMock
            .Setup(m => m.Get(order.Id))
            .ReturnsAsync(order);
            suite.OrderStateRepositoryMock
            .Setup(m => m.GetCurrentState(order.Id))
            .ReturnsAsync(currentState);

            await suite.OrderStateService.ConfirmByDriver(order.Id, driver.Id);

            suite.OrderStateRepositoryMock
            .Verify(m => m.Add(It.Is <OrderState>(
                                   s => s.OrderId.Equals(order.Id) &&
                                   s.Status.Equals(OrderStatus.ConfirmedByDriver))));
        }
Exemplo n.º 4
0
        public async void ArriveAtLoading()
        {
            var commonId = 1;
            var suite    = new OrderStateServiceTestSuite();

            var driver = new Driver {
                Id = commonId++
            };
            var order = new Order {
                Id = commonId++, DriverId = driver.Id
            };
            var currentState = new OrderState {
                Id = commonId++, OrderId = order.Id, Status = OrderStatus.WentToCustomer
            };

            suite.DriverServiceMock
            .Setup(m => m.IsExist(driver.Id))
            .ReturnsAsync(true);
            suite.OrderServiceMock
            .Setup(m => m.Get(order.Id))
            .ReturnsAsync(order);
            suite.OrderStateRepositoryMock
            .Setup(m => m.GetCurrentState(order.Id))
            .ReturnsAsync(currentState);

            await suite.OrderStateService.ArriveAtLoadingPlace(order.Id, driver.Id);

            suite.OrderStateRepositoryMock
            .Verify(m => m.Add(It.Is <OrderState>(
                                   s => s.OrderId.Equals(order.Id) &&
                                   s.Status.Equals(OrderStatus.ArrivedAtLoadingPlace))));
        }
Exemplo n.º 5
0
        public async void AssignToDriverWhenAnotherDispatcher()
        {
            var commonId = 1;
            var suite    = new OrderStateServiceTestSuite();

            var orderDispatcher = new Dispatcher {
                Id = commonId++
            };
            var anotherDispatcherId = commonId++;
            var driver = new Driver {
                Id = commonId++
            };
            var order = new Order {
                Id = commonId++, DispatcherId = orderDispatcher.Id
            };
            var currentState = new OrderState {
                Id = commonId++, OrderId = order.Id, Status = OrderStatus.AssignedDispatcher
            };

            suite.DispatcherServiceMock
            .Setup(m => m.IsExist(It.IsAny <int>()))
            .ReturnsAsync(true);
            suite.DriverServiceMock
            .Setup(m => m.IsExist(driver.Id))
            .ReturnsAsync(true);
            suite.OrderServiceMock
            .Setup(m => m.Get(order.Id))
            .ReturnsAsync(order);
            suite.OrderStateRepositoryMock
            .Setup(m => m.GetCurrentState(order.Id))
            .ReturnsAsync(currentState);

            await Assert.ThrowsAsync <AccessViolationException>(() => suite.OrderStateService.AssignToDriver(order.Id, anotherDispatcherId, driver.Id));
        }
Exemplo n.º 6
0
        public async void AssignToDriverWhenDispatcherDoesNotFound()
        {
            var commonId = 1;
            var suite    = new OrderStateServiceTestSuite();

            var driver = new Driver {
                Id = commonId++
            };
            var notExistingDispatcher = commonId++;
            var order = new Order {
                Id = commonId++, DispatcherId = commonId++
            };
            var currentState = new OrderState {
                Id = commonId++, OrderId = order.Id, Status = OrderStatus.AssignedDispatcher
            };

            suite.DriverServiceMock
            .Setup(m => m.IsExist(driver.Id))
            .ReturnsAsync(true);
            suite.DispatcherServiceMock
            .Setup(m => m.IsExist(notExistingDispatcher))
            .ReturnsAsync(false);
            suite.OrderServiceMock
            .Setup(m => m.Get(order.Id))
            .ReturnsAsync(order);
            suite.OrderStateRepositoryMock
            .Setup(m => m.GetCurrentState(order.Id))
            .ReturnsAsync(currentState);

            await Assert.ThrowsAsync <EntityNotFoundException>("Dispatcher", () => suite.OrderStateService.AssignToDriver(order.Id, notExistingDispatcher, driver.Id));
        }
Exemplo n.º 7
0
        public async void AssignOrderToDispatcher()
        {
            var commonId = 1;
            var suite    = new OrderStateServiceTestSuite();

            var dispatcher = new Dispatcher {
                Id = commonId++
            };
            var order = new Order {
                Id = commonId++
            };
            var currentState = new OrderState {
                Id = commonId++, OrderId = order.Id, Status = OrderStatus.Accepted
            };

            suite.DispatcherServiceMock
            .Setup(m => m.IsExist(dispatcher.Id))
            .ReturnsAsync(true);
            suite.OrderServiceMock
            .Setup(m => m.Get(order.Id))
            .ReturnsAsync(order);
            suite.OrderStateRepositoryMock
            .Setup(m => m.GetCurrentState(order.Id))
            .ReturnsAsync(currentState);

            await suite.OrderStateService.AssignToDispatcher(order.Id, dispatcher.Id);

            suite.OrderStateRepositoryMock
            .Verify(m => m.Add(It.Is <OrderState>(
                                   s => s.OrderId.Equals(order.Id) &&
                                   s.Status.Equals(OrderStatus.AssignedDispatcher))));
            suite.OrderServiceMock
            .Verify(m => m.AssignDispatcher(order.Id, dispatcher.Id));
        }
Exemplo n.º 8
0
        public async void AssignToDriverWnenOrderStatusIsUnsuitable()
        {
            var commonId = 1;
            var suite    = new OrderStateServiceTestSuite();

            var dispatcher = new Dispatcher {
                Id = commonId++
            };
            var driver = new Driver {
                Id = commonId++
            };
            var order = new Order {
                Id = commonId++, DispatcherId = dispatcher.Id
            };
            var currentState = new OrderState {
                Id = commonId++, OrderId = order.Id, Status = OrderStatus.New
            };

            suite.DispatcherServiceMock
            .Setup(m => m.IsExist(dispatcher.Id))
            .ReturnsAsync(true);
            suite.DriverServiceMock
            .Setup(m => m.IsExist(driver.Id))
            .ReturnsAsync(true);
            suite.OrderServiceMock
            .Setup(m => m.Get(order.Id))
            .ReturnsAsync(order);
            suite.OrderStateRepositoryMock
            .Setup(m => m.GetCurrentState(order.Id))
            .ReturnsAsync(currentState);

            await Assert.ThrowsAsync <OrderStatusException>(() => suite.OrderStateService.AssignToDriver(order.Id, dispatcher.Id, driver.Id));
        }
Exemplo n.º 9
0
        public async void Trade()
        {
            var commonId = 1;
            var suite    = new OrderStateServiceTestSuite();

            var order = new Order {
                Id = commonId++
            };
            var currentState = new OrderState {
                Id = commonId++, OrderId = order.Id, Status = OrderStatus.ReadyForTrade
            };

            suite.OrderServiceMock
            .Setup(m => m.Get(order.Id))
            .ReturnsAsync(order);
            suite.OrderStateRepositoryMock
            .Setup(m => m.GetCurrentState(order.Id))
            .ReturnsAsync(currentState);

            await suite.OrderStateService.Trade(order.Id);

            suite.OrderStateRepositoryMock
            .Verify(m => m.Add(It.Is <OrderState>(
                                   s => s.OrderId.Equals(order.Id) &&
                                   s.Status.Equals(OrderStatus.SentToTrading))));
        }
Exemplo n.º 10
0
        public async void ReadyToTradeWhenModeratorIsOther()
        {
            var commonId = 1;
            var suite    = new OrderStateServiceTestSuite();

            var moderator = new Moderator {
                Id = commonId++
            };
            var order = new Order {
                Id = commonId++, ModeratorId = -1
            };
            var currentState = new OrderState {
                Id = commonId++, OrderId = order.Id, Status = OrderStatus.Accepted
            };

            suite.ModeratorServiceMock
            .Setup(m => m.IsExist(moderator.Id))
            .ReturnsAsync(true);
            suite.OrderServiceMock
            .Setup(m => m.Get(order.Id))
            .ReturnsAsync(order);
            suite.OrderStateRepositoryMock
            .Setup(m => m.GetCurrentState(order.Id))
            .ReturnsAsync(currentState);

            await Assert.ThrowsAsync <AccessViolationException>(() => suite.OrderStateService.ReadyToTrade(order.Id, moderator.Id));
        }
Exemplo n.º 11
0
        public async void ReadyToTrade()
        {
            var commonId = 1;
            var suite    = new OrderStateServiceTestSuite();

            var moderator = new Moderator {
                Id = commonId++
            };
            var order = new Order {
                Id = commonId++, ModeratorId = moderator.Id
            };
            var currentState = new OrderState {
                Id = commonId++, OrderId = order.Id, Status = OrderStatus.Accepted
            };

            suite.ModeratorServiceMock
            .Setup(m => m.IsExist(moderator.Id))
            .ReturnsAsync(true);
            suite.OrderServiceMock
            .Setup(m => m.Get(order.Id))
            .ReturnsAsync(order);
            suite.OrderStateRepositoryMock
            .Setup(m => m.GetCurrentState(order.Id))
            .ReturnsAsync(currentState);

            await suite.OrderStateService.ReadyToTrade(order.Id, moderator.Id);

            suite.OrderStateRepositoryMock
            .Verify(m => m.Add(It.Is <OrderState>(
                                   s => s.OrderId.Equals(order.Id) &&
                                   s.Status.Equals(OrderStatus.ReadyForTrade))));
        }
Exemplo n.º 12
0
        public async void GetStatesWithNewCurentStatus()
        {
            var suite  = new OrderStateServiceTestSuite();
            var status = OrderStatus.New;

            var newStates = await suite.OrderStateService.GetByCurrentStatus(status);

            suite.OrderStateRepositoryMock
            .Verify(m => m.GetStatesByCurrentStatus(status));
        }
Exemplo n.º 13
0
        public async void GetAcceptedStatesCount()
        {
            var suite  = new OrderStateServiceTestSuite();
            var status = OrderStatus.Accepted;

            var count = await suite.OrderStateService.GetCountByCurrentStatus(status);

            suite.OrderStateRepositoryMock
            .Verify(m => m.GetCountStatesByCurrentStatus(status));
        }
Exemplo n.º 14
0
        public async void DeliverTheVehicleWhenDriverDoesNotExist()
        {
            var commonId            = 1;
            var suite               = new OrderStateServiceTestSuite();
            var notExistingDriverId = commonId++;
            var order               = new Order {
                Id = commonId++, DriverId = notExistingDriverId
            };

            suite.DriverServiceMock
            .Setup(m => m.IsExist(1))
            .ReturnsAsync(false);
            suite.OrderServiceMock
            .Setup(m => m.Get(order.Id))
            .ReturnsAsync(order);

            await Assert.ThrowsAsync <EntityNotFoundException>("Driver", () => suite.OrderStateService.DeliverTheVehicle(order.Id, notExistingDriverId));
        }
Exemplo n.º 15
0
        public async void DeliverTheVehicleWhenAnotherDriver()
        {
            var commonId = 1;
            var suite    = new OrderStateServiceTestSuite();

            var driver = new Driver {
                Id = commonId++
            };
            var order = new Order {
                Id = commonId++, DriverId = commonId++
            };

            suite.DriverServiceMock
            .Setup(m => m.IsExist(driver.Id))
            .ReturnsAsync(true);
            suite.OrderServiceMock
            .Setup(m => m.Get(order.Id))
            .ReturnsAsync(order);

            await Assert.ThrowsAsync <AccessViolationException>(() => suite.OrderStateService.DeliverTheVehicle(order.Id, driver.Id));
        }
Exemplo n.º 16
0
        public async void TradeWnenOrderStatusIsUnsuitable()
        {
            var commonId = 1;
            var suite    = new OrderStateServiceTestSuite();

            var order = new Order {
                Id = commonId++
            };
            var currentState = new OrderState {
                Id = commonId++, OrderId = order.Id, Status = OrderStatus.Accepted
            };

            suite.OrderServiceMock
            .Setup(m => m.Get(order.Id))
            .ReturnsAsync(order);
            suite.OrderStateRepositoryMock
            .Setup(m => m.GetCurrentState(order.Id))
            .ReturnsAsync(currentState);

            await Assert.ThrowsAsync <OrderStatusException>(() => suite.OrderStateService.Trade(order.Id));
        }