private List <ShipmentPackageDTO> GenerateRandomPackageList() { List <ShipmentPackageDTO> packages = new List <ShipmentPackageDTO>(); int packageQuantity = RandomNumberHelper.GetRandomInt(_minQuantity, _maxQuantity); // Get unique 2 digit numbers IEnumerable <int> uniqueAddressNumbers = RandomNumberHelper.GetUniqueRandomNumbers(10, 99, packageQuantity); int[] uniqueAddressNumbersArray = uniqueAddressNumbers.ToArray(); // Get unique MINIMUM 8 digit numbers IEnumerable <int> uniquePackageNumbers = RandomNumberHelper.GetUniqueRandomNumbers(10000000, int.MaxValue, packageQuantity); int[] uniquePackageNumbersArray = uniquePackageNumbers.ToArray(); for (int i = 0; i < packageQuantity; i++) { var package = new ShipmentPackageDTO(); package.PackageWeightInKilos = RandomNumberHelper.GetRandomInt(_minWeight, _maxWeight); package.DeliveryAddressNumber = uniqueAddressNumbersArray[i].ToString(); package.PackageNumber = uniquePackageNumbersArray[i].ToString(); packages.Add(package); } // Order packages by weight so that maximum number of packages can be delivered in short time periods packages = packages.OrderBy(p => p.PackageWeightInKilos).ToList(); return(packages); }
public List <ShipmentPackageDTO> GenerateRandomShipmentPackages() { List <ShipmentPackageDTO> packages = GenerateRandomPackageList(); List <ShipmentPackageDTO> deliverablePackages = new List <ShipmentPackageDTO>(); while (_startTime.AddMinutes(_deliveryTimeBetweenStopsInMinutes * 2) <= _endTime && // 1 delivery time must be reserved for returning to delivery center deliverablePackages.Count < packages.Count) { // Calculate remaining packages IEnumerable <ShipmentPackageDTO> remainingPackages = packages.Except(deliverablePackages); // Calculate deliverable packages for one tour deliverablePackages.AddRange(CalculateDeliverablePackagesForOneTour(remainingPackages)); // Last stop of tour is marked deliverablePackages.Last().LastStopOfTour = true; // Return to delivery center for another load _startTime = _startTime.AddMinutes(_deliveryTimeBetweenStopsInMinutes); } foreach (var package in packages) { ShipmentPackageDTO deliverablePackage = deliverablePackages.FirstOrDefault(dp => dp.PackageNumber == package.PackageNumber); if (deliverablePackage != null) { package.ApproximateDeliveryTime = deliverablePackage.ApproximateDeliveryTime; } } return(packages); }
public QuerySpecificPackageResponse QuerySpecificPackage(string packageNumber) { ShipmentPackageDTO shipmentPackage = _shipmentBusiness.QuerySpecificPackage(packageNumber); QuerySpecificPackageResponse response = new QuerySpecificPackageResponse(shipmentPackage); return(response); }
public void CheckIfQueryingANonExistingPackageReturnsNull() { ShipmentBusiness shipmentBusiness = new ShipmentBusiness(_baseFixture.MockedShipmentPackageGenerator, _baseFixture.MockedCache); List <ShipmentPackageDTO> shipmentPackages = shipmentBusiness.GetShipmentPackages(); ShipmentPackageDTO shipmentPackage = shipmentPackages.First(); ShipmentPackageDTO queriedShipmentPackage = shipmentBusiness.QuerySpecificPackage(shipmentPackage.PackageNumber + "asd"); Assert.True(queriedShipmentPackage == null); }
public void CheckIfQueryingAnExistingPackageReturnsValidPackage() { ShipmentBusiness shipmentBusiness = new ShipmentBusiness(_baseFixture.MockedShipmentPackageGenerator, _baseFixture.MockedCache); List <ShipmentPackageDTO> shipmentPackages = shipmentBusiness.GetShipmentPackages(); ShipmentPackageDTO shipmentPackage = shipmentPackages.First(); ShipmentPackageDTO queriedShipmentPackage = shipmentBusiness.QuerySpecificPackage(shipmentPackage.PackageNumber); Assert.True(queriedShipmentPackage != null && queriedShipmentPackage.Equals(shipmentPackage)); }
public void CheckIfQueryingANonExistingPackageReturnsNull() { ShipmentController shipmentController = new ShipmentController(_baseFixture.MockedShipmentBusiness); GetShipmentPackagesResponse shipmentPackagesResponse = shipmentController.GetShipmentPackages(); ShipmentPackageDTO shipmentPackage = shipmentPackagesResponse.ShipmentPackages.First(); QuerySpecificPackageResponse querySpecificPackageResponse = shipmentController.QuerySpecificPackage(shipmentPackage.PackageNumber + "asd"); Assert.True(querySpecificPackageResponse != null && querySpecificPackageResponse.ShipmentPackage == null); }
public void CheckIfLastDeliverablePackagesDeliveryTimeIsBeforeWorkingHoursEnd() { ShipmentPackageGenerator shipmentPackageGenerator = new ShipmentPackageGenerator(_baseFixture.MockConfiguration); List <ShipmentPackageDTO> packages = shipmentPackageGenerator.GenerateRandomShipmentPackages(); ShipmentPackageDTO lastDeliverablePackage = packages.Last(p => p.ApproximateDeliveryTime.HasValue); int workingHourEndHour, workingHourEndMinute; int.TryParse(_baseFixture.MockConfiguration.GetSection("AppSettings")["WorkingHourEndHour"], out workingHourEndHour); int.TryParse(_baseFixture.MockConfiguration.GetSection("AppSettings")["WorkingHourEndMinute"], out workingHourEndMinute); var endWorkingTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, workingHourEndHour, workingHourEndMinute, 0); Assert.True(lastDeliverablePackage.ApproximateDeliveryTime < endWorkingTime); }
public QuerySpecificPackageResponse(ShipmentPackageDTO package) { ShipmentPackage = package; }