コード例 #1
0
        public void FindTheNearestCourier_From3Distances_ReturnKeyForTheNearestDistance(double distance1, double distance2, double distance3, int result)
        {
            Dictionary <int, double> distances = new Dictionary <int, double>();

            distances.Add(1, distance1);
            distances.Add(2, distance2);
            distances.Add(3, distance3);

            var locationServiceMock = new Mock <ILocationService>();
            var vehicleServiceMock  = new Mock <IVehicleService>();
            var packageServiceMock  = new Mock <IPackageService>();
            var jsonSerializerMock  = new Mock <IJsonSerializer>();
            var userServiceMock     = new Mock <IUserService>();
            var timeProvider        = new Mock <ITimeProvider>();

            var service = new WaybillsService(
                locationServiceMock.Object,
                vehicleServiceMock.Object,
                packageServiceMock.Object,
                jsonSerializerMock.Object,
                userServiceMock.Object,
                timeProvider.Object);

            int nearestDistance = service.FindTheNearestCourier(distances);

            nearestDistance.Should().Be(result);
        }
コード例 #2
0
        public void PreparingTodaysParcelsForShippin_NoPackages_ReturnNullListPackages()
        {
            List <Package> packages = new List <Package>();

            List <User> users = new List <User>();

            users.Add(new User()
            {
                Id = 1, Type = TypeOfUser.Driver
            });

            var packageServiceMock = new Mock <IPackageService>();

            packageServiceMock
            .Setup(x => x.GetPackagesWithStatus(StateOfPackage.AwaitingPosting))
            .Returns(packages);

            var userServiceMock = new Mock <IUserService>();

            userServiceMock
            .Setup(x => x.GetAllDrivers())
            .Returns(users);

            var locationServiceMock = new Mock <ILocationService>();
            var vehicleServiceMock  = new Mock <IVehicleService>();
            var jsonSerializerMock  = new Mock <IJsonSerializer>();
            var timeProvider        = new Mock <ITimeProvider>();

            var service = new WaybillsService(
                locationServiceMock.Object,
                vehicleServiceMock.Object,
                packageServiceMock.Object,
                jsonSerializerMock.Object,
                userServiceMock.Object,
                timeProvider.Object);

            List <Package> todaysPackage = service.PreparingTodaysParcelsForShippin();

            todaysPackage.Should().BeNull();
        }
コード例 #3
0
        public void GetLocation_ProvideValidAddress_ReturnsGeoCoordinates()
        {
            var address = new Address()
            {
                Street = "aleja Grunwaldzka",
                Number = 26,
                City   = "Gdañsk",
            };

            var pckgService = new Mock <IPackagesService>();
            var vhService   = new Mock <IVehiclesService>();
            var usrService  = new Mock <IUsersService>();
            var serializer  = new Mock <ISerializer>();
            var geoService  = new Mock <IGeographicDataService>();

            IWaybillsService wbService = new WaybillsService(pckgService.Object,
                                                             usrService.Object, vhService.Object, serializer.Object, geoService.Object);

            var coordinates = wbService.GetLocation(address);

            coordinates.Latitude.Should().BeApproximately(54.3754, 0.001);
            coordinates.Longitude.Should().BeApproximately(18.6159, 0.001);
        }
コード例 #4
0
        public void AssignPackagesToCouriers_GivePackageAndDriverWithoutVehile_ReturnEmptyList()
        {
            List <Package> packages = new List <Package>();

            packages.Add(new Package()
            {
                Id           = 3,
                RecipientLat = 54,
                RecipientLon = 18,
                Sender       = new User()
                {
                    lat = 53.5,
                    lon = 19
                },
                Size = PackageSize.Average
            });

            List <User> users = new List <User>();

            users.Add(new User()
            {
                Id = 5, Street = "Œliska", StreetNumber = "28C", City = "Gdynia"
            });

            Dictionary <int, int>    vehiclesCapacity = new Dictionary <int, int>();
            Dictionary <int, double> distance         = new Dictionary <int, double>();

            distance.Add(3, 20);

            List <Vehicle> vehicles = new List <Vehicle>();

            var userServiceMock = new Mock <IUserService>();

            userServiceMock
            .Setup(x => x.GetAllDrivers())
            .Returns(users);

            var vehicleServiceMock = new Mock <IVehicleService>();

            vehicleServiceMock
            .Setup(x => x.GetAllVehicles())
            .Returns(vehicles);

            vehicleServiceMock
            .Setup(x => x.GetVehicle(5))
            .Returns(new Vehicle());

            var locationServiceMock = new Mock <ILocationService>();

            locationServiceMock
            .Setup(y => y.CountDistancesFromPackageToCouriers(users, It.IsAny <Package>()))
            .Returns(distance);

            var packageServiceMock = new Mock <IPackageService>();
            var jsonSerializerMock = new Mock <IJsonSerializer>();
            var timeProvider       = new Mock <ITimeProvider>();

            var service = new WaybillsService(
                locationServiceMock.Object,
                vehicleServiceMock.Object,
                packageServiceMock.Object,
                jsonSerializerMock.Object,
                userServiceMock.Object,
                timeProvider.Object);

            List <Package> todaysPackage = service.AssignPackagesToCouriers(packages, users, vehiclesCapacity);

            todaysPackage.Should().BeEmpty();
        }
コード例 #5
0
        public void AssignPackagesToCouriers_Give4Packages_ReturnListWith3Positions()
        {
            List <Package> packages = new List <Package>();

            packages.Add(new Package()
            {
                Id = 1, Size = PackageSize.Average, Sender = new User()
                {
                    lat = 53.5, lon = 19
                }
            });
            packages.Add(new Package()
            {
                Id = 2, Size = PackageSize.Large, Sender = new User()
                {
                    lat = 53.5, lon = 19
                }
            });
            packages.Add(new Package()
            {
                Id = 3, Size = PackageSize.Average, Sender = new User()
                {
                    lat = 53.5, lon = 19
                }
            });
            packages.Add(new Package()
            {
                Id = 4, Size = PackageSize.Small, Sender = new User()
                {
                    lat = 53.5, lon = 19
                }
            });

            List <User> users = new List <User>();

            users.Add(new User()
            {
                Id = 5, Street = "Œliska", StreetNumber = "28C", City = "Gdynia"
            });
            users.Add(new User()
            {
                Id = 6, Street = "Niska", StreetNumber = "5", City = "Bydgoszcz"
            });

            Dictionary <int, double> distance = new Dictionary <int, double>();

            distance.Add(5, 20);
            distance.Add(6, 150);

            Dictionary <int, int> vehiclesCapacity = new Dictionary <int, int>();

            vehiclesCapacity.Add(5, 220);

            List <Vehicle> vehicles = new List <Vehicle>();

            vehicles.Add(new Vehicle()
            {
                Id = 5, AverageSpeed = 120
            });
            vehicles.Add(new Vehicle()
            {
                Id = 6, AverageSpeed = 100
            });

            var userServiceMock = new Mock <IUserService>();

            userServiceMock
            .Setup(x => x.GetAllDrivers())
            .Returns(users);

            var vehicleServiceMock = new Mock <IVehicleService>();

            vehicleServiceMock
            .Setup(x => x.GetVehicle(5))
            .Returns(new Vehicle()
            {
                Id = 5
            });

            vehicleServiceMock
            .Setup(x => x.GetAllVehicles())
            .Returns(vehicles);

            var locationServiceMock = new Mock <ILocationService>();

            locationServiceMock
            .Setup(y => y.CountDistancesFromPackageToCouriers(users, It.IsAny <Package>()))
            .Returns(distance);

            var packageServiceMock = new Mock <IPackageService>();
            var jsonSerializerMock = new Mock <IJsonSerializer>();
            var timeProvider       = new Mock <ITimeProvider>();

            var service = new WaybillsService(
                locationServiceMock.Object,
                vehicleServiceMock.Object,
                packageServiceMock.Object,
                jsonSerializerMock.Object,
                userServiceMock.Object,
                timeProvider.Object);

            List <Package> todaysPackage = service.AssignPackagesToCouriers(packages, users, vehiclesCapacity);

            todaysPackage.Should().HaveCount(3);
            Assert.IsTrue(todaysPackage.Contains(packages[0]));
            Assert.IsTrue(todaysPackage.Contains(packages[1]));
            Assert.IsFalse(todaysPackage.Contains(packages[2]));
            Assert.IsTrue(todaysPackage.Contains(packages[3]));
        }
コード例 #6
0
        public void AssignPackagesToCouriers_Give1Package_ReturnListWith1Position()
        {
            List <Package> packages = new List <Package>();

            packages.Add(new Package()
            {
                Id           = 3,
                RecipientLat = 54,
                RecipientLon = 18,
                Sender       = new User()
                {
                    lat = 53.5,
                    lon = 19
                },
                Size = PackageSize.Average
            });

            List <User> users = new List <User>();

            users.Add(new User()
            {
                Id = 5, lat = 52, lon = 21
            });
            users.Add(new User()
            {
                Id = 6, lat = 53, lon = 20
            });

            Dictionary <int, double> distance = new Dictionary <int, double>();

            distance.Add(5, 20);
            distance.Add(6, 150);

            List <Vehicle> vehicles = new List <Vehicle>();

            vehicles.Add(new Vehicle()
            {
                Id = 5, AverageSpeed = 120
            });
            vehicles.Add(new Vehicle()
            {
                Id = 6, AverageSpeed = 100
            });

            Dictionary <int, int> vehiclesCapacity = new Dictionary <int, int>();

            vehiclesCapacity.Add(5, 200);

            LocationCoordinates firstPackageSender = new LocationCoordinates();

            var userServiceMock = new Mock <IUserService>();

            userServiceMock
            .Setup(x => x.GetAllDrivers())
            .Returns(users);

            var vehicleServiceMock = new Mock <IVehicleService>();

            vehicleServiceMock
            .Setup(x => x.GetAllVehicles())
            .Returns(vehicles);

            vehicleServiceMock
            .Setup(x => x.GetVehicle(5))
            .Returns(new Vehicle()
            {
                Id = 5
            });

            var locationServiceMock = new Mock <ILocationService>();

            locationServiceMock
            .Setup(y => y.CountDistancesFromPackageToCouriers(users, It.IsAny <Package>()))
            .Returns(distance);

            var packageServiceMock = new Mock <IPackageService>();
            var jsonSerializerMock = new Mock <IJsonSerializer>();
            var timeProvider       = new Mock <ITimeProvider>();

            var service = new WaybillsService(
                locationServiceMock.Object,
                vehicleServiceMock.Object,
                packageServiceMock.Object,
                jsonSerializerMock.Object,
                userServiceMock.Object,
                timeProvider.Object);

            List <Package> todaysPackage = service.AssignPackagesToCouriers(packages, users, vehiclesCapacity);

            todaysPackage.Should().HaveCount(1);
        }
コード例 #7
0
        public void ChooseDriver_ProvideValidData_ReturnsClosestDriver()
        {
            var sender = new User()
            {
                Email     = "*****@*****.**",
                FirstName = "Anna",
                LastName  = "Nowak",
                Address   = new Address()
                {
                    Street = "Chyloñska",
                    Number = 84,
                    City   = "Gdynia"
                },
                UserType = UserType.Customer
            };

            var driver1 = new User()
            {
                Email     = "*****@*****.**",
                FirstName = "Jan",
                LastName  = "Kowalski",
                Address   = new Address()
                {
                    Street = "Olsztyñska",
                    Number = 18,
                    City   = "Gdañsk"
                },
                UserType = UserType.Driver,
                Vehicle  = new Vehicle()
                {
                    Capacity = 100,
                    Load     = 0
                }
            };

            var driver2 = new User()
            {
                Email     = "*****@*****.**",
                FirstName = "Krzysztof",
                LastName  = "Nowak",
                Address   = new Address()
                {
                    Street = "Jagielloñska",
                    Number = 18,
                    City   = "Olsztyn"
                },
                UserType = UserType.Driver,
                Vehicle  = new Vehicle()
                {
                    Capacity = 100,
                    Load     = 0
                }
            };

            Package package = new Package()
            {
                Number          = Guid.NewGuid(),
                Sender          = sender,
                ReceiverAddress = new Address()
                {
                    Street = "Piastowska",
                    Number = 60,
                    City   = "Gdañsk"
                },
                Size   = Size.Small,
                Status = Status.PendingSending
            };

            var pckgService = new Mock <IPackagesService>();
            var vhService   = new Mock <IVehiclesService>();
            var usrService  = new Mock <IUsersService>();
            var serializer  = new Mock <ISerializer>();
            var geoService  = new Mock <IGeographicDataService>();

            IWaybillsService wbService = new WaybillsService(pckgService.Object,
                                                             usrService.Object, vhService.Object, serializer.Object, geoService.Object);

            var closestDriver = wbService.ChooseDriver(package, new List <User>
            {
                driver1,
                driver2
            });

            closestDriver.Should().BeSameAs(driver1);
        }
コード例 #8
0
        public void MatchPackages_OverloadedDrivers_PackagesNotMatched()
        {
            var sender1 = new User()
            {
                Email     = "*****@*****.**",
                FirstName = "Anna",
                LastName  = "Nowak",
                Address   = new Address()
                {
                    Street = "Chyloñska",
                    Number = 84,
                    City   = "Gdynia"
                },
                UserType = UserType.Customer
            };

            var sender2 = new User()
            {
                Email     = "*****@*****.**",
                FirstName = "Katarzyna",
                LastName  = "Malinowska",
                Address   = new Address()
                {
                    Street = "Dworcowa",
                    Number = 70,
                    City   = "Olsztyn"
                },
                UserType = UserType.Customer
            };

            var driver1 = new User()
            {
                Email     = "*****@*****.**",
                FirstName = "Jan",
                LastName  = "Kowalski",
                Address   = new Address()
                {
                    Street = "Olsztyñska",
                    Number = 18,
                    City   = "Gdañsk"
                },
                UserType = UserType.Driver,
                Vehicle  = new Vehicle()
                {
                    Capacity = 100,
                    Load     = 95
                },
                Packages = new List <Package>()
            };

            var driver2 = new User()
            {
                Email     = "*****@*****.**",
                FirstName = "Krzysztof",
                LastName  = "Nowak",
                Address   = new Address()
                {
                    Street = "Jagielloñska",
                    Number = 18,
                    City   = "Olsztyn"
                },
                UserType = UserType.Driver,
                Vehicle  = new Vehicle()
                {
                    Capacity = 100,
                    Load     = 95
                },
                Packages = new List <Package>()
            };

            Package package1 = new Package()
            {
                Number          = Guid.NewGuid(),
                Sender          = sender1,
                ReceiverAddress = new Address()
                {
                    Street = "Piastowska",
                    Number = 60,
                    City   = "Gdañsk"
                },
                Size   = Size.Small,
                Status = Status.PendingSending
            };

            Package package2 = new Package()
            {
                Number          = Guid.NewGuid(),
                Sender          = sender2,
                ReceiverAddress = new Address()
                {
                    Street = "Traktorowa",
                    Number = 13,
                    City   = "Olsztyn"
                },
                Size   = Size.Medium,
                Status = Status.PendingSending
            };

            var pckgService = new Mock <IPackagesService>();
            var vhService   = new Mock <IVehiclesService>();
            var usrService  = new Mock <IUsersService>();
            var serializer  = new Mock <ISerializer>();
            var geoService  = new Mock <IGeographicDataService>();

            pckgService.Setup(s => s.GetAllPackagesToBeSend())
            .Returns(new List <Package>
            {
                package1,
                package2,
            });

            usrService.Setup(u => u.GetAllDrivers()).Returns(new List <User>
            {
                driver1,
                driver2,
            });

            IWaybillsService wbService = new WaybillsService(pckgService.Object,
                                                             usrService.Object, vhService.Object, serializer.Object, geoService.Object);

            wbService.MatchPackages();

            package1.Status.Should().Be(Status.PendingSending);
            package2.Status.Should().Be(Status.PendingSending);
        }