private Leg ToLeg(TransitEdge edge)
 {
     return(new Leg(
                voyageRepository.Find(new VoyageNumber(edge.VoyageNumber)),
                locationRepository.Find(new UnLocode(edge.FromUnLocode)),
                locationRepository.Find(new UnLocode(edge.ToUnLocode)),
                edge.FromDate, edge.ToDate));
 }
Exemple #2
0
        public Leg FromDTO(LegDTO legDto)
        {
            var loadLocation   = _locationRepository.Find(new UnLocode(legDto.From));
            var unloadLocation = _locationRepository.Find(new UnLocode(legDto.To));
            var voyage         = _voyageRepository.Find(legDto.VoyageId);

            return(new Leg(voyage, loadLocation, legDto.LoadTime, unloadLocation, legDto.UnloadTime));
        }
        public void Find()
        {
            Voyage voyage = voyageRepository.Find(new VoyageNumber("0101"));

            Assert.IsNotNull(voyage);
            Assert.AreEqual("0101", voyage.VoyageNumber.IdString);

            //TODO adapt

            /*Assert.AreEqual(STOCKHOLM, carrierMovement.DepartureLocation);
             * Assert.AreEqual(HELSINKI, carrierMovement.ArrivalLocation);
             * Assert.AreEqual(DateTestUtil.ToDate("2007-09-23", "02:00"), carrierMovement.DepartureTime());
             * Assert.AreEqual(DateTestUtil.ToDate("2007-09-23", "03:00"), carrierMovement.ArrivalTime());*/
        }
Exemple #4
0
        private Voyage FindVoyage(VoyageNumber voyageNumber)
        {
            if (voyageNumber == null)
            {
                return(null);
            }

            Voyage voyage = voyageRepository.Find(voyageNumber);

            if (voyage == null)
            {
                throw new UnknownVoyageException(voyageNumber);
            }

            return(voyage);
        }
        /// <summary>
        /// Assemble a Itinerary from provided RouteCandidateDTO.
        /// </summary>
        /// <param name="routeCandidateDTO">route candidate DTO</param>
        /// <param name="voyageRepository">voyage repository</param>
        /// <param name="locationRepository">location repository</param>
        /// <returns>An itinerary</returns>
        public Itinerary FromDTO(RouteCandidateDTO routeCandidateDTO,
                                 IVoyageRepository voyageRepository,
                                 ILocationRepository locationRepository)
        {
            var legs = new List <Leg>(routeCandidateDTO.Legs.Count);

            foreach (LegDTO legDTO in routeCandidateDTO.Legs)
            {
                VoyageNumber voyageNumber = new VoyageNumber(legDTO.VoyageNumber);
                Voyage       voyage       = voyageRepository.Find(voyageNumber);
                Location     from         = locationRepository.Find(new UnLocode(legDTO.FromLocation));
                Location     to           = locationRepository.Find(new UnLocode(legDTO.ToLocation));
                legs.Add(new Leg(voyage, from, to, legDTO.LoadTime, legDTO.UnloadTime));
            }

            return(new Itinerary(legs));
        }
        /// <summary>
        /// Assemble a Itinerary from provided RouteCandidateDTO. 
        /// </summary>
        /// <param name="routeCandidateDTO">route candidate DTO</param>
        /// <param name="voyageRepository">voyage repository</param>
        /// <param name="locationRepository">location repository</param>
        /// <returns>An itinerary</returns>
        public Itinerary FromDTO(RouteCandidateDTO routeCandidateDTO,
                                 IVoyageRepository voyageRepository,
                                 ILocationRepository locationRepository)
        {
            var legs = new List<Leg>(routeCandidateDTO.Legs.Count);

            foreach (LegDTO legDTO in routeCandidateDTO.Legs)
            {
                VoyageNumber voyageNumber = new VoyageNumber(legDTO.VoyageNumber);
                Voyage voyage = voyageRepository.Find(voyageNumber);
                Location from = locationRepository.Find(new UnLocode(legDTO.FromLocation));
                Location to = locationRepository.Find(new UnLocode(legDTO.ToLocation));
                legs.Add(new Leg(voyage, from, to, legDTO.LoadTime, legDTO.UnloadTime));
            }

            return new Itinerary(legs);
        }
        public void Save()
        {
            //TODO: atrosin make the method transactional because it modifies data
            TrackingId trackingId  = new TrackingId("AAA");
            Location   origin      = locationRepository.Find(SampleLocations.STOCKHOLM.UnLocode);
            Location   destination = locationRepository.Find(SampleLocations.MELBOURNE.UnLocode);

            Cargo cargo = new Cargo(trackingId, new RouteSpecification(origin, destination, new DateTime()));

            cargoRepository.Store(cargo);

            cargo.AssignToRoute(new Itinerary(
                                    new List <Leg>
            {
                new Leg(
                    voyageRepository.Find(new VoyageNumber("0101")),
                    locationRepository.Find(SampleLocations.STOCKHOLM.UnLocode),
                    locationRepository.Find(SampleLocations.MELBOURNE.UnLocode),
                    new DateTime(), new DateTime())
            }));

            Flush();


            IList cargoListFromDb = GetPlainCargoListFromDbByTrackId(trackingId);

            Assert.AreEqual("AAA", cargoListFromDb[0] /*TRACKING_ID*/);

            int originId = GetIntId(origin);

            Assert.AreEqual(originId, cargoListFromDb[1] /*SPEC_ORIGIN_ID*/);

            int destinationId = GetIntId(destination);

            Assert.AreEqual(destinationId, cargoListFromDb[2] /*SPEC_DESTINATION_ID*/);

            UnitOfWork.CurrentSession.Clear();

            Cargo loadedCargo = cargoRepository.Find(trackingId);

            Assert.AreEqual(1, loadedCargo.Itinerary.Legs.Count);
        }