Ejemplo n.º 1
0
        public async Task LoadPackCommandHandler_Success()
        {
            //Arrange
            int productsQuantity = 50;
            int loadedQuantity   = 0;

            var packToDelivery = new PackToDelivery {
                ProductsQuantity = productsQuantity
            };
            var loadingPlace = new LoadingPlace {
                LoadedQuantity = loadedQuantity, AmountOfSpace = productsQuantity
            };

            packToDeliveryRepo.Setup(x => x.GetByConditionFirst(It.IsAny <Expression <Func <PackToDelivery, bool> > >()))
            .Returns(Task.FromResult(packToDelivery));

            loadingPlaceRepo.Setup(x => x.GetByConditionFirst(It.IsAny <Expression <Func <LoadingPlace, bool> > >()))
            .Returns(Task.FromResult(loadingPlace));

            //Act
            var action = await commandHandler.Handle(command, It.IsAny <CancellationToken>());

            //Assert
            Assert.Equal(Unit.Value, action);
            loadingPlaceRepo.Verify(x => x.SaveAllAsync(), Times.Once);
            bus.Verify(x => x.Publish(It.IsAny <ChangeOrderStatusEvent>(), It.IsAny <CancellationToken>()), Times.Once);
        }
 private void CheckIfHaveAnyPacks(LoadingPlace loadingPlace)
 {
     if (loadingPlace.PacksToDelivery.Count > 0)
     {
         throw new ArgumentException("The loading place could not be removed, because packs were loaded.");
     }
 }
Ejemplo n.º 3
0
 private void ValidateLoadingPlaceAmountOfSpace(PackToDelivery pack, LoadingPlace loadingPlace)
 {
     if (pack.ProductsQuantity > (loadingPlace.AmountOfSpace - loadingPlace.LoadedQuantity))
     {
         throw new LackOfSpaceException();
     }
 }
 public UpdateLoadingPlaceTest()
 {
     deliveryService    = new Mock <IDeliveryService>();
     deliveryController = new DeliveryController(deliveryService.Object);
     loadingPlace       = new LoadingPlace {
         Id = loadingPlaceId
     };
 }
Ejemplo n.º 5
0
 private async Task ChangePacksStatusToSended(LoadingPlace loadingPlace)
 {
     foreach (var pack in loadingPlace.PacksToDelivery)
     {
         pack.PackStatus = PackStatus.Sended;
         await bus.Publish(new ChangeOrderStatusEvent(pack.OrderId, OrderStatus.Sended));
     }
 }
Ejemplo n.º 6
0
 public AddLoadingPlaceCommandHandlerTest()
 {
     loadingPlaceRepo = new Mock <ILoadingPlaceRepo>();
     mapper           = new Mock <IMapper>();
     command          = new AddLoadingPlaceCommand();
     commandHandler   = new AddLoadingPlaceCommandHandler(loadingPlaceRepo.Object, mapper.Object);
     loadingPlace     = new LoadingPlace();
 }
 public UpdateLoadingPlaceCommandHandlerTest()
 {
     loadingPlaceRepo = new Mock <ILoadingPlaceRepo>();
     mapper           = new Mock <IMapper>();
     commandHandler   = new UpdateLoadingPlaceCommandHandler(loadingPlaceRepo.Object, mapper.Object);
     loadingPlace     = new LoadingPlace {
         LoadedQuantity = loadedQuantity
     };
 }
Ejemplo n.º 8
0
        public async Task <IActionResult> CreateLoadingPlace(LoadingPlace loadingPlace)
        {
            if (!ModelState.IsValid)
            {
                return(await ReturnViewWithPostPutVM());
            }

            await deliveryService.AddLoadingPlace(loadingPlace);

            return(RedirectToAction("IndexLoadingPlace"));
        }
Ejemplo n.º 9
0
 public GetLoadingPlaceQueryHandlerTest()
 {
     loadingPlaceRepo = new Mock <ILoadingPlaceRepo>();
     mapper           = new Mock <IMapper>();
     query            = new GetLoadingPlaceQuery(loadingPlaceId);
     queryHandler     = new GetLoadingPlaceQueryHandler(loadingPlaceRepo.Object, mapper.Object);
     loadingPlace     = new LoadingPlace {
         Id = loadingPlaceId
     };
     loadingPlaceDto = new GetLoadingPlaceDto {
         Id = loadingPlaceId
     };
 }
Ejemplo n.º 10
0
 public CompleteDeliveryCommandHandlerTest()
 {
     loadingPlaceRepo = new Mock <ILoadingPlaceRepo>();
     bus             = new Mock <IBus>();
     command         = new CompleteDeliveryCommand(id);
     commandHandler  = new CompleteDeliveryCommandHandler(loadingPlaceRepo.Object, bus.Object);
     packsToDelivery = new List <PackToDelivery> {
         new PackToDelivery(), new PackToDelivery()
     };
     loadingPlace = new LoadingPlace {
         PacksToDelivery = packsToDelivery
     };
 }
Ejemplo n.º 11
0
        public async Task CreateLoadingPlace_PostAction_ValidModel_Success()
        {
            //Arrange
            var loadingPlace = new LoadingPlace {
                Id = loadingPlaceId, LoadingPlaceName = "Name", AmountOfSpace = 1
            };

            //Act
            var action = await deliveryController.CreateLoadingPlace(loadingPlace) as RedirectToActionResult;

            //Assert
            deliveryService.Verify(x => x.AddLoadingPlace(loadingPlace), Times.Once);
            Assert.Equal("IndexLoadingPlace", action.ActionName);
        }
Ejemplo n.º 12
0
        public async Task <IActionResult> UpdateLoadingPlace(LoadingPlace loadingPlace)
        {
            if (loadingPlace.AmountOfSpace < loadingPlace.LoadedQuantity)
            {
                ModelState.AddModelError("", "AmountOfSpace must be greater than LoadedQuantity");
            }

            if (!ModelState.IsValid)
            {
                return(await ReturnViewWithPostPutVM(loadingPlace.Id));
            }

            await deliveryService.UpdateLoadingPlace(loadingPlace);

            return(RedirectToAction("IndexLoadingPlace"));
        }
Ejemplo n.º 13
0
        public async Task CreateLoadingPlace_PostAction_NotValidModel_Success()
        {
            //Arrange
            var loadingPlace = new LoadingPlace {
                Id = loadingPlaceId
            };

            deliveryController.ModelState.AddModelError("", "");

            //Act
            var action = await deliveryController.CreateLoadingPlace(loadingPlace) as ViewResult;

            var model = action.Model as PostPutLoadingPlaceViewModel;

            //Assert
            Assert.NotNull(model.LoadingPlace);
        }
Ejemplo n.º 14
0
        public async Task DeleteLoadingPlaceCommandHandler_PacksCountGreaterThanZero_ThrowsArgumentException()
        {
            //Arrange
            var packToDeliveries = new List <PackToDelivery> {
                new PackToDelivery()
            };
            var loadingPlace = new LoadingPlace {
                PacksToDelivery = packToDeliveries
            };

            loadingPlaceRepo.Setup(x => x.GetByConditionWithIncludeFirst(
                                       It.IsAny <Expression <Func <LoadingPlace, bool> > >(), It.IsAny <Expression <Func <LoadingPlace, ICollection <PackToDelivery> > > >()))
            .Returns(Task.FromResult(loadingPlace));

            //Assert
            await Assert.ThrowsAsync <ArgumentException>(() => commandHandler.Handle(command, It.IsAny <CancellationToken>()));
        }
Ejemplo n.º 15
0
        public async Task DeleteLoadingPlaceCommandHandler_Success()
        {
            //Arrange
            var loadingPlace = new LoadingPlace {
                PacksToDelivery = new List <PackToDelivery>()
            };

            loadingPlaceRepo.Setup(x => x.GetByConditionWithIncludeFirst(
                                       It.IsAny <Expression <Func <LoadingPlace, bool> > >(), It.IsAny <Expression <Func <LoadingPlace, ICollection <PackToDelivery> > > >()))
            .Returns(Task.FromResult(loadingPlace));

            //Act
            var action = await commandHandler.Handle(command, It.IsAny <CancellationToken>());

            //Assert
            Assert.Equal(Unit.Value, action);
            loadingPlaceRepo.Verify(x => x.Delete(loadingPlace), Times.Once);
            loadingPlaceRepo.Verify(x => x.SaveAllAsync(), Times.Once);
        }
Ejemplo n.º 16
0
        public async Task LoadPackCommandHandler_ThrowsLackOfSpaceException()
        {
            //Arrange
            int productsQuantity = 100;
            int loadedQuantity   = 50;

            var packToDelivery = new PackToDelivery {
                ProductsQuantity = productsQuantity
            };
            var loadingPlace = new LoadingPlace {
                LoadedQuantity = loadedQuantity, AmountOfSpace = productsQuantity
            };

            packToDeliveryRepo.Setup(x => x.GetByConditionFirst(It.IsAny <Expression <Func <PackToDelivery, bool> > >()))
            .Returns(Task.FromResult(packToDelivery));

            loadingPlaceRepo.Setup(x => x.GetByConditionFirst(It.IsAny <Expression <Func <LoadingPlace, bool> > >()))
            .Returns(Task.FromResult(loadingPlace));

            //Assert
            await Assert.ThrowsAsync <LackOfSpaceException>(() => commandHandler.Handle(command, It.IsAny <CancellationToken>()));
        }
Ejemplo n.º 17
0
 private void IncreaseLoadingPlaceLoadedQuantity(PackToDelivery pack, LoadingPlace loadingPlace)
 {
     loadingPlace.LoadedQuantity    += pack.ProductsQuantity;
     loadingPlace.LoadingPlaceStatus = LoadingPlaceStatus.Loading;
 }
Ejemplo n.º 18
0
        public async Task UpdateLoadingPlace(LoadingPlace loadingPlace)
        {
            var updateLoadingPlaceUrl = $"{baseUrl}loadingPlace";

            await customHttpClient.PutAsync(updateLoadingPlaceUrl, loadingPlace, token);
        }
Ejemplo n.º 19
0
        public async Task AddLoadingPlace(LoadingPlace loadingPlace)
        {
            var addLoadingPlaceUrl = $"{baseUrl}loadingPlace";

            await customHttpClient.PostAsync(addLoadingPlaceUrl, loadingPlace, token);
        }
Ejemplo n.º 20
0
        public Route FindBestRouteToAttendDelivery(List <LoadingPlace> loadingPlaces, Delivery delivery)
        {
            double        minDistance = double.MaxValue;
            int           loadingPlaceMinDistanceId = 0;
            PossibleRoute possibleRoute             = new PossibleRoute();

            foreach (var loadingPlace in loadingPlaces)
            {
                int currentDistancePrecedingNode = int.MaxValue;
                foreach (var truckMixer in loadingPlace.TruckMixers)
                {
                    foreach (var route in truckMixer.Routes)
                    {
                        if (route.TotalVolume + delivery.Volume <= truckMixer.Capacity)
                        {
                            RouteNode lastRouteNode         = route.RouteNodes.Last();
                            double    distancePrecedingNode = delivery.GeoCoordinates.GetDistanceTo(lastRouteNode.GeoCordinates);
                            int       minutesToTravel       = 2 * (int)distancePrecedingNode;

                            if (distancePrecedingNode < currentDistancePrecedingNode &&
                                lastRouteNode.EndService.AddMinutes(minutesToTravel) <= delivery.ServiceTimeBegin)
                            {
                                if (delivery.ServiceTimeBegin.Subtract(lastRouteNode.EndService.AddMinutes(minutesToTravel)).TotalMinutes <= 60)
                                {
                                    possibleRoute.LoadingPlaceId        = loadingPlace.LoadingPlaceId;
                                    possibleRoute.TruckMixerId          = truckMixer.TruckMixerId;
                                    possibleRoute.RouteId               = route.RouteId;
                                    possibleRoute.MinutesToTravel       = minutesToTravel;
                                    possibleRoute.DistancePrecedingNode = distancePrecedingNode;
                                }
                            }
                        }
                    }
                }

                double distanceCurrentLoadingPlace = delivery.GeoCoordinates.GetDistanceTo(loadingPlace.GeoCordinates);
                if (distanceCurrentLoadingPlace < minDistance)
                {
                    loadingPlaceMinDistanceId = loadingPlace.LoadingPlaceId;
                    minDistance = distanceCurrentLoadingPlace;
                }
            }

            if (possibleRoute.DistancePrecedingNode <= minDistance)
            {
                LoadingPlace loadingPlacePossibleSelected = loadingPlaces.FirstOrDefault(l => l.LoadingPlaceId == possibleRoute.LoadingPlaceId);
                TruckMixer   truckMixerPossibleSelected   = loadingPlacePossibleSelected.TruckMixers.FirstOrDefault(tm => tm.TruckMixerId == possibleRoute.TruckMixerId);
                Route        routePossibleSelected        = truckMixerPossibleSelected.Routes.FirstOrDefault(r => r.RouteId == possibleRoute.RouteId);
                routePossibleSelected.RouteNodes.Add(new RouteNode()
                {
                    RouteNodeId     = routePossibleSelected.NextRouteNodeId,
                    RouteId         = routePossibleSelected.RouteId,
                    DeliveryOrderId = delivery.DeliveryOrderId,
                    DeliveryId      = delivery.DeliveryId,
                    BeginService    = delivery.ServiceTimeBegin,
                    EndService      = delivery.ServiceTimeBegin.AddMinutes(delivery.CustomerRmcDischargeRate * delivery.Volume),
                    Longitude       = delivery.Longitude,
                    Latitude        = delivery.Latitude
                });
                routePossibleSelected.NextRouteNodeId++;
                truckMixerPossibleSelected.EndLastService = delivery.ServiceTimeBegin.
                                                            AddMinutes(delivery.CustomerRmcDischargeRate * delivery.Volume).
                                                            AddMinutes(2 * delivery.GeoCoordinates.GetDistanceTo(loadingPlacePossibleSelected.GeoCordinates));
            }
            else
            {
                LoadingPlace loadingPlaceMinDistanceSelected = loadingPlaces.FirstOrDefault(l => l.LoadingPlaceId == loadingPlaceMinDistanceId);
            }

            return(new Route());
        }
Ejemplo n.º 21
0
 public static int GetTravelTime(this Delivery delivery, LoadingPlace loadingPlace)
 {
     return(0);
 }
 private async Task DeleteLoadingPlace(LoadingPlace loadingPlace)
 {
     loadingPlaceRepo.Delete(loadingPlace);
     await loadingPlaceRepo.SaveAllAsync();
 }
Ejemplo n.º 23
0
 private async Task AddLoadingPlace(LoadingPlace loadingPlace)
 {
     loadingPlaceRepo.Add(loadingPlace);
     await loadingPlaceRepo.SaveAllAsync();
 }
 private void ClearLoadedQuantityFromLoadingPlace(LoadingPlace loadingPlace)
 {
     loadingPlace.LoadedQuantity     = 0;
     loadingPlace.LoadingPlaceStatus = LoadingPlaceStatus.Waiting_For_Loading;
 }
Ejemplo n.º 25
0
 private void SetPackLoadingPlace(PackToDelivery pack, LoadingPlace loadingPlace)
 {
     pack.LoadingPlace = loadingPlace;
     pack.PackStatus   = PackStatus.Ready_To_Send;
 }
 private void CheckIfAmountOfSpaceIsGreaterThanLoadedQuantity(UpdateLoadingPlaceCommand request, LoadingPlace loadingPlace)
 {
     if (request.AmountOfSpace < loadingPlace.LoadedQuantity)
     {
         throw new ArgumentException("Amount of space must be greater than loaded quantity.");
     }
 }