Beispiel #1
0
        private Result SendPackage(int packageId, int senderCenterId, int receiverCenterId)
        {
            IPackageRepository _mockPackageRepository = new MockPackageRepository();
            PackageService     _packageServices       = new PackageService(_mockPackageRepository);
            Package            _package             = MockDataAccess.GetPackage(packageId);
            DistributionCentre _senderLocation      = MockDataAccess.GetDistributionCentre(senderCenterId);
            DistributionCentre _destinationLocation = MockDataAccess.GetDistributionCentre(receiverCenterId);

            return(_packageServices.Send(_package, _senderLocation, _destinationLocation, DateTime.Today));
        }
Beispiel #2
0
        // Try to send Package into the Sender Centre location
        public void TestSendPackage_SameLocation()
        {
            IPackageRepository _mockPackageRepository = new MockPackageRepository();
            PackageService     _packageServices       = new PackageService(_mockPackageRepository);
            Package            _package        = MockDataAccess.GetPackage(3);
            DistributionCentre _senderLocation = MockDataAccess.GetDistributionCentre(2);
            DateTime           _sendDate       = DateTime.Today;
            var _result = _packageServices.Send(_package, _senderLocation, _senderLocation, _sendDate);

            Assert.AreEqual <bool>(false, _result.Success);
        }
Beispiel #3
0
        public void TestReceivePackage_BarcodeNotFound()
        {
            MockPackageRepository myMockPackageRepo = new MockPackageRepository();
            PackageService        packageService    = new PackageService(myMockPackageRepo);
            DistributionCentre    myReceiverCentre  = MockDataAccess.GetDistributionCentre(3);
            string bCode = "0001015042500004";        // package1.BarCode; //
            Result res   = packageService.Receive(bCode, myReceiverCentre, DateTime.Today);

            Assert.AreEqual <bool>(res.Success, false);
            Assert.AreEqual <string>(res.ErrorMessage, TransitResult.BarCodeNotFound);
        }
Beispiel #4
0
        private Result DiscardPackage(int currentCentreId, string userName, string barCode)
        {
            MockPackageRepository packageRepository = new MockPackageRepository();
            PackageService        _packageService   = new PackageService(packageRepository);
            Employee employee = MockDataAccess.GetEmployee(userName);
            Package  package  = MockDataAccess.GetPackage(barCode);

            package.CurrentLocation = MockDataAccess.GetDistributionCentre(currentCentreId);
            StandardPackageType spt2 = _packageService.GetStandardPackageType(package.PackageType.PackageTypeId);

            return(_packageService.Discard(package.BarCode, employee.Location, employee, package.ExpirationDate, spt2, package.PackageId));
        }
Beispiel #5
0
        // Try to send package to null destination centre
        public void TestSendPackage_SendToNullCentre()
        {
            IPackageRepository _mockPackageRepository = new MockPackageRepository();
            PackageService     _packageServices       = new PackageService(_mockPackageRepository);
            DistributionCentre _senderLocation        = MockDataAccess.GetDistributionCentre(1);
            DistributionCentre _destinationLocation   = MockDataAccess.GetDistributionCentre(2);
            DateTime           _sendDate = DateTime.Today;
            Package            _package  = MockDataAccess.GetPackage(15);
            var _result = _packageServices.Send(_package, _package.CurrentLocation, null, _sendDate);

            Assert.AreEqual <string>("Please Select the Correct Receiver Centre", _result.ErrorMessage);
        }
Beispiel #6
0
        // Try to send Package which is not abvailable
        public void TestSendPackage_PackageNotFond()
        {
            IPackageRepository _mockPackageRepository = new MockPackageRepository();
            PackageService     _packageServices       = new PackageService(_mockPackageRepository);
            DistributionCentre _senderLocation        = MockDataAccess.GetDistributionCentre(1);
            DistributionCentre _destinationLocation   = MockDataAccess.GetDistributionCentre(2);
            DateTime           _sendDate = DateTime.Today;
            Package            _package  = null;
            var _result = _packageServices.Send(_package, _senderLocation, _destinationLocation, _sendDate);

            Assert.AreEqual <string>(_result.ErrorMessage, "Bar Code not found");
        }
Beispiel #7
0
        public void TestReceivePackage_ReceiveDateTooEarly()
        {
            MockPackageRepository myMockPackageRepo = new MockPackageRepository();
            PackageService        packageService    = new PackageService(myMockPackageRepo);
            Package            package1             = MockDataAccess.GetPackage(3);
            DistributionCentre myReceiverCentre     = MockDataAccess.GetDistributionCentre(3);
            int    newTransitId = InsertMockTransit(package1, 2, 3);                                                        // insert transit
            Result res          = packageService.Receive(package1.BarCode, myReceiverCentre, DateTime.Today.AddMonths(-1)); // receive

            Assert.AreEqual <bool>(res.Success, false);
            Assert.AreEqual <string>(res.ErrorMessage, PackageResult.ReceiveDateCannotBeEarlierThanSend);
        }
Beispiel #8
0
        public void TestReceivePackage_CancelTransit()
        {
            MockPackageRepository myMockPackageRepo = new MockPackageRepository();
            PackageService        packageService    = new PackageService(myMockPackageRepo);
            Package            package1             = MockDataAccess.GetPackage(3);
            DistributionCentre myReceiverCentre     = MockDataAccess.GetDistributionCentre(3);
            int    newTransitId  = InsertMockTransit(package1, 2, 3);                                   // insert transit
            Result res           = packageService.CancelTransit(package1.BarCode, DateTime.Today);      // cancel transit
            int    foundTransits = myMockPackageRepo.GetActiveTransitsByPackage(package1).Count;

            Assert.IsTrue(res.Success && foundTransits == 0);
        }
Beispiel #9
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);
        }
Beispiel #10
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);
        }
Beispiel #11
0
        public int InsertMockTransit(Package Package, int SenderId, int ReceiverId)
        {
            DistributionCentre mySenderCentre   = MockDataAccess.GetDistributionCentre(SenderId);
            DistributionCentre myReceiverCentre = MockDataAccess.GetDistributionCentre(ReceiverId);
            PackageTransit     newTransit       = new PackageTransit();

            newTransit.Package        = Package;
            newTransit.DateSent       = DateTime.Today.AddDays(-2);
            newTransit.SenderCentre   = mySenderCentre;
            newTransit.ReceiverCentre = myReceiverCentre;
            int newTransitId = MockDataAccess.InsertPackageTransit(newTransit);

            return(newTransitId);
        }
Beispiel #12
0
        public void TestReceivePackage_Successfully()
        {
            MockPackageRepository myMockPackageRepo = new MockPackageRepository();
            PackageService        packageService    = new PackageService(myMockPackageRepo);
            Package            package1             = MockDataAccess.GetPackage(3);
            DistributionCentre myReceiverCentre     = MockDataAccess.GetDistributionCentre(3);
            int newTransitId = InsertMockTransit(package1, 2, 3);                                       // insert transit

            packageService.Receive(package1.BarCode, myReceiverCentre, DateTime.Today);
            PackageTransit finishedTransit = MockDataAccess.GetPackageTransit(newTransitId);

            Debug.WriteLine(finishedTransit.ToString());
            Assert.IsTrue(finishedTransit.ReceiverCentre == myReceiverCentre);
        }
Beispiel #13
0
        public void TestDistribute_DistributedCurrentLocationError()
        {
            MockPackageRepository packageRepository = new MockPackageRepository();
            PackageService        _packageService   = new PackageService(packageRepository);
            Employee emp = MockDataAccess.GetEmployee(2);
            Package  p   = MockDataAccess.GetPackage(3);

            p.CurrentStatus   = PackageStatus.Distributed;
            p.CurrentLocation = MockDataAccess.GetDistributionCentre(4);
            Result result = _packageService.Distribute(p.BarCode, p.CurrentLocation, emp, p.ExpirationDate, p.PackageType, p.PackageId);

            Assert.AreEqual(false, result.Success);
            //Assert.AreEqual("Package has been already distributed: " + barCode, result.ErrorMessage);
        }
Beispiel #14
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);
        }
Beispiel #15
0
 public Repository.Data.DistributionCentre GetDistributionCentre(int centreId)       // (P. 04-04-2015)
 {
     return(MockDataAccess.GetDistributionCentre(centreId));
 }