Exemple #1
0
        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);
        }
Exemple #2
0
        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);
        }
Exemple #3
0
        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);
        }
Exemple #4
0
        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);
        }
Exemple #5
0
 public StandardPackageType GetStandardPackageType(int packageTypeId)
 {
     return(MockDataAccess.GetPackageType(packageTypeId));
 }