public void TestCalculateExpirationDate() { IPackageRepository packageRepository = new MockPackageRepository(); PackageService packageService = new PackageService(packageRepository); StandardPackageType packageType = MockDataAccess.GetPackageType(3); DateTime todaysDate = DateTime.Today; DateTime expirationDate = packageService.CalculateExpirationDate(packageType, todaysDate); Assert.AreEqual <DateTime>(todaysDate.AddMonths(packageType.ShelfLifeUnits), expirationDate); }
public void TestRegisterPackageExpirationDateTooEarly() { IPackageRepository packageRepository = new MockPackageRepository(); PackageService packageService = new PackageService(packageRepository); StandardPackageType packageType = MockDataAccess.GetPackageType(3); DistributionCentre location = MockDataAccess.GetDistributionCentre(2); DateTime expirationDate = DateTime.Today.AddDays(-1); string barCode; var result = packageService.Register(packageType, location, expirationDate, out barCode); int newPackageId = result.Id; Assert.AreEqual <bool>(result.Success, false); Assert.AreEqual <string>(result.ErrorMessage, PackageResult.ExpirationDateCannotBeEarlierThanToday); }
public void TestRegisterPackage() { IPackageRepository packageRepository = new MockPackageRepository(); PackageService packageService = new PackageService(packageRepository); StandardPackageType packageType = MockDataAccess.GetPackageType(3); DistributionCentre location = MockDataAccess.GetDistributionCentre(2); DateTime expirationDate = DateTime.Today.AddMonths(2); string barCode; var result = packageService.Register(packageType, location, expirationDate, out barCode); int newPackageId = result.Id; string compareBarCode = string.Format("{0:D5}{1:yyMMdd}{2:D5}", packageType.PackageTypeId, expirationDate, newPackageId); Assert.AreEqual <string>(compareBarCode, barCode); }
public Package Get(int?packageId, string barcode) { List <Package> packages = MockDataAccess.GetAllPackages(); for (int i = 0; i < packages.Count; i++) { if (packages[i].BarCode == barcode) { return(packages[i]); } } Package package = new Package { PackageId = packageId ?? 1, PackageType = MockDataAccess.GetPackageType(2), BarCode = string.IsNullOrEmpty(barcode) ? "000012015070100001" : barcode, ExpirationDate = new DateTime(2015, 7, 1), CurrentLocation = MockDataAccess.GetDistributionCentre(4), CurrentStatus = PackageStatus.InStock }; return(package); }
public StandardPackageType GetStandardPackageType(int packageTypeId) { return(MockDataAccess.GetPackageType(packageTypeId)); }