コード例 #1
0
ファイル: StaffLogicTests.cs プロジェクト: Jawohi/src
        public void ReportParcelDelivery_IsOk()
        {
            string trackingId = "123456789";

            DA.Parcel p = new DA.Parcel()
            {
                TrackingId = trackingId
            };

            Mock <IParcelRepository> parcelRepoMock = new Mock <IParcelRepository>();

            parcelRepoMock.Setup(foo => foo.GetByTrackingId(trackingId)).Returns(p);
            parcelRepoMock.Setup(foo => foo.Update(It.IsAny <DA.Parcel>()));

            Mock <IHopRepository>     hopRepoMock = new Mock <IHopRepository>();
            Mock <IWebhookRepository> hookMock    = new Mock <IWebhookRepository>();
            List <DA.Webhook>         webhooks    = new List <DA.Webhook>
            {
                new DA.Webhook(),
                new DA.Webhook()
            };

            hookMock.Setup(foo => foo.GetByTrackingId(trackingId)).Returns(webhooks);

            IStaffLogic staffLogic = new StaffLogic(mapper, parcelRepoMock.Object, hopRepoMock.Object, hookMock.Object, NullLogger <StaffLogic> .Instance);

            //if it doesn't throw, it's ok
            staffLogic.ReportParcelDelivery(trackingId);
        }
コード例 #2
0
ファイル: StaffLogicTests.cs プロジェクト: Jawohi/src
        public void ReportParcelHop_UpdateExpection()
        {
            string trackingId = "123456789";
            string code       = "987654321";

            DA.Parcel p = new DA.Parcel()
            {
                TrackingId = trackingId
            };
            DA.Warehouse w = new DA.Warehouse()
            {
                Code = code
            };

            Mock <IParcelRepository> parcelRepoMock = new Mock <IParcelRepository>();

            parcelRepoMock.Setup(foo => foo.GetByTrackingId(trackingId)).Returns(p);
            parcelRepoMock.Setup(foo => foo.Update(It.IsAny <DA.Parcel>())).Throws(new ParcelNotFoundExpection());

            Mock <IHopRepository> hopRepoMock = new Mock <IHopRepository>();

            hopRepoMock.Setup(foo => foo.GetByCode(code)).Returns(w);
            Mock <IWebhookRepository> hookMock = new Mock <IWebhookRepository>();

            IStaffLogic staffLogic = new StaffLogic(mapper, parcelRepoMock.Object, hopRepoMock.Object, hookMock.Object, NullLogger <StaffLogic> .Instance);

            Assert.Throws <BusinessLayerException>(() => staffLogic.ReportParcelHop(trackingId, code));
        }
コード例 #3
0
        public void ReportParcelDelivery(string parcelID)
        {
            Data.Parcel dataParcel;
            try
            {
                logger.LogDebug($"getting parcel {parcelID} from repo");
                dataParcel = parcelRepository.GetByTrackingId(parcelID);
            }
            catch (DataAccessLayerException e)
            {
                throw new BusinessLayerException("DAL Exception", e);
            }

            Parcel businessParcel = this.mapper.Map <Parcel>(dataParcel);

            businessParcel.ReportDelivery();
            Data.Parcel mappedParcel = this.mapper.Map <Data.Parcel>(businessParcel);

            try
            {
                logger.LogInformation($"updating parcel {parcelID}");
                parcelRepository.Delivered(mappedParcel);

                List <Data.Webhook> dataWebhooks = webhookRepository.GetByTrackingId(parcelID);
                List <Webhook>      webhooks     = new List <Webhook>();
                dataWebhooks.ForEach(hook => webhooks.Add(this.mapper.Map <Webhook>(hook)));
                NotifyAllSubscribers(webhooks);
                DeleteAllSubscribers(webhooks);
            }
            catch (DataAccessLayerException e)
            {
                throw new BusinessLayerException("DAL Exception", e);
            }
        }
コード例 #4
0
ファイル: ReceipientLogicTests.cs プロジェクト: Jawohi/src
        public void TrackParcel_ParcelNotFound()
        {
            string id = "123456789";

            Mock <IParcelRepository> mock = new Mock <IParcelRepository>();

            DA.Parcel wh = new DA.Parcel()
            {
                TrackingId = id, State = DA.Parcel.StateEnum.DeliveredEnum
            };

            mock.Setup(foo => foo.GetByTrackingId(id)).Throws(new ParcelNotFoundExpection());

            IRecipientLogic receipientLogic = new RecipientLogic(mapper, mock.Object, NullLogger <RecipientLogic> .Instance);

            Assert.Throws <BusinessLayerException>(() => receipientLogic.TrackParcel(id));
        }
コード例 #5
0
ファイル: ReceipientLogicTests.cs プロジェクト: Jawohi/src
        public void TrackParcel_ReturnParcel()
        {
            string id = "123456789";

            Mock <IParcelRepository> mock = new Mock <IParcelRepository>();

            DA.Parcel wh = new DA.Parcel()
            {
                TrackingId = id, State = DA.Parcel.StateEnum.DeliveredEnum
            };
            mock.Setup(foo => foo.GetByTrackingId(id)).Returns(wh);

            IRecipientLogic receipientLogic = new RecipientLogic(mapper, mock.Object, NullLogger <RecipientLogic> .Instance);

            Parcel p = receipientLogic.TrackParcel(id);

            Assert.NotNull(p);
            Assert.Equal(p.TrackingId, id);
            Assert.Equal(Parcel.StateEnum.DeliveredEnum, p.State);
        }
コード例 #6
0
ファイル: RecipientLogic.cs プロジェクト: Jawohi/src
        public Parcel TrackParcel(string trackingId)
        {
            try
            {
                logger.LogInformation($"getting parcel {trackingId} from repo");
                Data.Parcel dataParcel     = parcelRepository.GetByTrackingId(trackingId);
                Parcel      businessParcel = this.mapper.Map <Parcel>(dataParcel);

                string senderGeoString    = businessParcel.Sender.ToGeoCodingString();
                string recipientGeoString = businessParcel.Recipient.ToGeoCodingString();
                logger.LogDebug($"converting sender geoCodingString '{senderGeoString}' to Location");
                logger.LogDebug($"converting recepient geoCodingString '{recipientGeoString}' to Location");

                Geocoding.Location senderAddress    = geoCodingAgent.EncodeAddress(senderGeoString);
                Geocoding.Location recipientAddress = geoCodingAgent.EncodeAddress(recipientGeoString);

                Data.Hop dataSenderHop;
                Data.Hop dataRecipientHop;
                try
                {
                    dataSenderHop    = hopRepository.GetByCoordinates(senderAddress.Latitude, senderAddress.Longitude);
                    dataRecipientHop = hopRepository.GetByCoordinates(recipientAddress.Latitude, recipientAddress.Longitude);
                }
                catch (DataAccessLayerException e)
                {
                    throw new BusinessLayerException("DAL Exception", e);
                }

                Data.Warehouse dataWarehouse;
                try
                {
                    logger.LogDebug("load full warehouse hierarchy");
                    dataWarehouse = wareHouseRepository.Read();
                }
                catch (DataAccessLayerException e)
                {
                    throw new BusinessLayerException("DAL Exception", e);
                }

                Hop       senderHop    = this.mapper.Map <Hop>(dataSenderHop);
                Hop       recipientHop = this.mapper.Map <Hop>(dataRecipientHop);
                Warehouse warehouse    = this.mapper.Map <Warehouse>(dataWarehouse);


                logger.LogDebug($"calculating route between sender {senderHop.Code} and recipeint {recipientHop.Code}");
                List <HopArrival> route = routeCalculator.CalculateRoute(warehouse, senderHop.Code, recipientHop.Code, businessParcel.EntryDate);


                //route    Datetime now
                List <HopArrival> soonHop = new List <HopArrival>();
                List <HopArrival> pastHop = new List <HopArrival>();
                foreach (HopArrival ha in route)
                {
                    if (ha.DateTime < DateTime.Now)
                    {
                        pastHop.Add(ha);
                    }
                    else
                    {
                        soonHop.Add(ha);
                    }
                }
                businessParcel.VisitedHops = pastHop;
                businessParcel.FutureHops  = soonHop;

                return(businessParcel);
            }
            catch (DataAccessLayerException e)
            {
                throw new BusinessLayerException();
            }
        }
コード例 #7
0
ファイル: LogisticsPartnerLogic.cs プロジェクト: Jawohi/src
        public string TransferParcel(string parcelID, Parcel parcel)
        {
            string senderGeoString    = parcel.Sender.ToGeoCodingString();
            string recipientGeoString = parcel.Recipient.ToGeoCodingString();

            logger.LogDebug($"converting sender geoCodingString '{senderGeoString}' to Location");
            logger.LogDebug($"converting recepient geoCodingString '{recipientGeoString}' to Location");

            Geocoding.Location senderAddress    = geoCodingAgent.EncodeAddress(senderGeoString);
            Geocoding.Location recipientAddress = geoCodingAgent.EncodeAddress(recipientGeoString);

            Data.Hop dataSenderHop;
            Data.Hop dataRecipientHop;
            try
            {
                dataSenderHop    = hopRepository.GetByCoordinates(senderAddress.Latitude, senderAddress.Longitude);
                dataRecipientHop = hopRepository.GetByCoordinates(recipientAddress.Latitude, recipientAddress.Longitude);
            }
            catch (DataAccessLayerException e)
            {
                throw new BusinessLayerException("DAL Exception", e);
            }

            if (dataSenderHop == null || dataRecipientHop == null)
            {
                string errorMessage = "Error";

                NoHopException e = new NoHopException(errorMessage);
                logger.LogError(e, $"No Hop found");
                throw e;
            }

            Data.Warehouse dataWarehouse;
            try
            {
                logger.LogDebug("load full warehouse hierarchy");
                dataWarehouse = wareHouseRepository.Read();
            }
            catch (DataAccessLayerException e)
            {
                throw new BusinessLayerException("DAL Exception", e);
            }

            Hop       senderHop    = this.mapper.Map <Hop>(dataSenderHop);
            Hop       recipientHop = this.mapper.Map <Hop>(dataRecipientHop);
            Warehouse warehouse    = this.mapper.Map <Warehouse>(dataWarehouse);

            logger.LogDebug($"Submiting parcel {parcelID}");
            parcel.Submit(parcelID);

            logger.LogDebug($"calculating route betweend sender {senderHop.Code} and recipeint {recipientHop.Code}");
            List <HopArrival> route = routeCalculator.CalculateRoute(warehouse, senderHop.Code, recipientHop.Code, parcel.EntryDate);



            logger.LogDebug($"validating parcel ({parcelID})");
            ParcelValidator  validator = new ParcelValidator();
            ValidationResult result    = validator.Validate(parcel);

            if (result.IsValid)
            {
                logger.LogDebug($"Parcel ({parcelID}) was valid");
                Data.Parcel dataParcel = this.mapper.Map <Data.Parcel>(parcel);


                logger.LogInformation("Creating Parcel DB entry");
                try {
                    parcelRepository.Create(dataParcel);
                    return(parcelID);
                }
                catch (DataAccessLayerException e)
                {
                    throw new BusinessLayerException("DAL Exception", e);
                }
            }

            else
            {
                InvalidParcelException e = new InvalidParcelException(string.Join("", result.Errors));
                logger.LogError(e, $"Parcel ({parcelID}) was invalid");
                throw e;
            }
        }