private DataAccess.Entities.TrackingInformation GenerateTrackingInformation(DataAccess.Entities.Parcel parcel) { //Create new empty TrackingInformation var dalTrackInfo = new DataAccess.Entities.TrackingInformation(DataAccess.Entities.TrackingInformation.StateEnum.InTransportEnum); var trackInfoId = _trackingRepo.Create(dalTrackInfo); dalTrackInfo.FutureHops = new List <DataAccess.Entities.HopArrival>(); dalTrackInfo.VisitedHops = new List <DataAccess.Entities.HopArrival>(); //Get destination of parcel var blRecipient = _mapper.Map <Entities.Recipient>(parcel.Recipient); var saRecipient = _mapper.Map <ServiceAgents.DTOs.Recipient>(blRecipient); var saLocation = _encodingAgent.EncodeAddress(saRecipient); var blLocation = _mapper.Map <Entities.Location>(saLocation); //Select nearest truck var truck = SelectNearestTruck(blLocation); if (truck == null) { throw new BlException("The given address is not in the range of service"); } //Get itinerary of parcel and create hop arrival estimations var warehouses = GetItinerary(truck); var date = DateTime.Now; foreach (var wh in warehouses) { date = date.AddDays((double)wh.Duration); var hop = new DataAccess.Entities.HopArrival { DateTime = date, Code = wh.Code, Status = "future", TrackingInformationId = trackInfoId }; _hopArrivalRepo.Create(hop); dalTrackInfo.FutureHops.Add(hop); } date = date.AddDays((double)truck.Duration); var truckHop = new DataAccess.Entities.HopArrival { DateTime = date, Code = truck.Code, Status = "future", TrackingInformationId = trackInfoId }; _hopArrivalRepo.Create(truckHop); dalTrackInfo.FutureHops.Add(truckHop); return(dalTrackInfo); }
public void ScanParcel_ValidInputArguments_HopArrivalUpdated() { var mockMapper = new Mock <AutoMapper.IMapper>(); var mapper = mockMapper.Object; var mockHopArrivalLogicLogger = new Mock <ILogger <HopArrivalLogic> >(); ILogger <HopArrivalLogic> hopArrivalLogicLogger = mockHopArrivalLogicLogger.Object; Interfaces.IHopArrivalLogic hopArrivalLogic = new HopArrivalLogic(mockParcelRepo, mockTrackRepo, mockHopRepo, mockTruckRepo, hopArrivalLogicLogger, mapper); hopArrivalLogic.ScanParcel("TN000001", "WH02"); List <DataAccess.Entities.HopArrival> hopArr = mockHopRepo.GetByTrackingInformationId(1); DataAccess.Entities.HopArrival h = new DataAccess.Entities.HopArrival { Code = "WH02" }; int index = hopArr.FindIndex(a => a.Code == h.Code); Assert.AreEqual(hopArr[index].Status, "visited"); }
private void SetupDALTrackingInfo() { validDALInfo = new DataAccess.Entities.TrackingInformation(DataAccess.Entities.TrackingInformation.StateEnum.InTransportEnum); var hop1 = new DataAccess.Entities.HopArrival { DateTime = DateTime.Now, Code = "WH01", Status = "visited", TrackingInformationId = 1 }; var hop2 = new DataAccess.Entities.HopArrival { DateTime = DateTime.Now.AddDays(1), Code = "WH02", Status = "future", TrackingInformationId = 1 }; var hop3 = new DataAccess.Entities.HopArrival { DateTime = DateTime.Now.AddDays(2), Code = "WH03", Status = "future", TrackingInformationId = 1 }; var hop4 = new DataAccess.Entities.HopArrival { DateTime = DateTime.Now.AddDays(3), Code = "TR01", Status = "future", TrackingInformationId = 1 }; validDALInfo.Id = 1; validDALInfo.VisitedHops.Add(hop1); validDALInfo.FutureHops.Add(hop2); validDALInfo.FutureHops.Add(hop3); validDALInfo.FutureHops.Add(hop4); }