Пример #1
0
        public void testIsMisdirectedCustomsInWrongLocation()
        {
            Cargo cargo = shanghaiSeattleChicagoOnPacific2AndContinental3();

            cargo.Handled(HandlingActivity.CustomsIn(L.CHICAGO));
            Assert.IsTrue(cargo.IsMisdirected);
        }
Пример #2
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="cargo">cargo</param>
        /// <param name="completionTime">completion time, the reported time that the event actually happened (e.g. the receive took place).</param>
        /// <param name="registrationTime">registration time, the time the message is received</param>
        /// <param name="type">type of event</param>
        /// <param name="location">where the event took place</param>
        /// <param name="voyage">the voyage</param>
        /// <param name="operatorCode">operator code for port operator</param>
        internal HandlingEvent(Cargo cargo,
                               DateTime completionTime,
                               DateTime registrationTime,
                               HandlingActivityType type,
                               Location location,
                               Voyage voyage,
                               OperatorCode operatorCode)
        {
            Validate.notNull(cargo, "Cargo is required");
            Validate.notNull(location, "Location is required");
            Validate.notNull(voyage, "Voyage is required");
            Validate.notNull(operatorCode, "Operator code is required");

            if (!type.isVoyageRelated())
            {
                throw new ArgumentException("Voyage is not allowed with event type " + type);
            }

            SequenceNumber   = EventSequenceNumber.Next();
            Cargo            = cargo;
            CompletionTime   = completionTime;
            RegistrationTime = registrationTime;
            Activity         = new HandlingActivity(type, location, voyage);
            OperatorCode     = operatorCode;
        }
Пример #3
0
        public String GetNextExpectedActivity()
        {
            HandlingActivity activity = cargo.Delivery.NextExpectedActivity;

            if (activity == null)
            {
                return("");
            }

            //TODO: atrosin refactor repetead string format\concatination
            string       text = "Next expected activity is to ";
            HandlingType type = activity.Type;

            if (type.SameValueAs(HandlingType.LOAD))
            {
                return
                    (text + type.DisplayName.ToLower() + " cargo into voyage " + activity.Voyage.VoyageNumber +
                     " in " + activity.Location.Name);
            }
            else if (type.SameValueAs(HandlingType.UNLOAD))
            {
                return
                    (text + type.DisplayName.ToLower() + " cargo off of " + activity.Voyage.VoyageNumber +
                     " in " + activity.Location.Name);
            }
            else
            {
                return(text + type.DisplayName.ToLower() + " cargo in " + activity.Location.Name);
            }
        }
Пример #4
0
        public void testIsMisdirectedClaimedInWrongLocation()
        {
            Cargo cargo = shanghaiSeattleChicagoOnPacific2AndContinental3();

            cargo.Handled(HandlingActivity.ClaimIn(L.SEATTLE));
            Assert.IsTrue(cargo.IsMisdirected);
        }
Пример #5
0
        public void testIsMisdirectedUnloadInWrongLocation()
        {
            Cargo cargo = shanghaiSeattleChicagoOnPacific2AndContinental3();

            cargo.Handled(HandlingActivity.UnloadOff(V.pacific2).In(L.TOKYO));
            Assert.IsTrue(cargo.IsMisdirected);
        }
Пример #6
0
        public void testIsMisdirectedIncorrectReceive()
        {
            Cargo cargo = shanghaiSeattleChicagoOnPacific2AndContinental3();

            cargo.Handled(HandlingActivity.ReceiveIn(L.TOKYO));
            Assert.IsTrue(cargo.IsMisdirected);
        }
Пример #7
0
        public void testOnHandling()
        {
            Delivery delivery = Delivery.BeforeHandling();

            HandlingActivity load = HandlingActivity.LoadOnto(V.HONGKONG_TO_NEW_YORK).In(L.HONGKONG);

            delivery = delivery.OnHandling(load);

            Assert.That(delivery.MostRecentHandlingActivity, Is.EqualTo(load));
            Assert.That(delivery.MostRecentPhysicalHandlingActivity, Is.EqualTo(load));

            HandlingActivity customs = HandlingActivity.CustomsIn(L.NEWYORK);

            delivery = delivery.OnHandling(customs);

            Assert.That(delivery.MostRecentHandlingActivity, Is.EqualTo(customs));
            Assert.That(delivery.MostRecentPhysicalHandlingActivity, Is.EqualTo(load));

            HandlingActivity loadAgain = HandlingActivity.LoadOnto(V.NEW_YORK_TO_DALLAS).In(L.NEWYORK);

            delivery = delivery.OnHandling(loadAgain);

            Assert.That(delivery.MostRecentHandlingActivity, Is.EqualTo(loadAgain));
            Assert.That(delivery.MostRecentPhysicalHandlingActivity, Is.EqualTo(loadAgain));
        }
Пример #8
0
        public void testUpdateOnHandlingWhenMisdirected()
        {
            // Unload in L.HAMBURG, which is the wrong location
            HandlingActivity handlingActivity = new HandlingActivity(HandlingActivityType.UNLOAD,
                                                                     L.HAMBURG,
                                                                     V.DALLAS_TO_HELSINKI);
            Delivery newDelivery = delivery.OnHandling(handlingActivity);

            Assert.AreEqual(Voyage.None, newDelivery.CurrentVoyage);
            Assert.AreEqual(L.HAMBURG, newDelivery.LastKnownLocation);
            Assert.AreEqual(TransportStatus.IN_PORT, newDelivery.TransportStatus);

            // Next handling activity is undefined. Need a new itinerary to know what to do.

            Assert.IsFalse(newDelivery.IsUnloadedIn(routeSpecification.Destination));

            Assert.AreEqual(RoutingStatus.ROUTED, routeSpecification.StatusOf(itinerary));

            Assert.IsTrue(delivery.LastUpdatedOn < (newDelivery.LastUpdatedOn));

            // New route specification, old itinerary
            RouteSpecification newRouteSpecification = routeSpecification.WithOrigin(L.HAMBURG);

            Assert.AreEqual(RoutingStatus.MISROUTED, newRouteSpecification.StatusOf(itinerary));

            Itinerary newItinerary = new Itinerary(Leg.DeriveLeg(V.DALLAS_TO_HELSINKI, L.HAMBURG, L.STOCKHOLM));

            Assert.AreEqual(RoutingStatus.ROUTED, newRouteSpecification.StatusOf(newItinerary));
            Assert.AreEqual(TransportStatus.IN_PORT, newDelivery.TransportStatus);
        }
Пример #9
0
 private LegActivityMatch(Leg leg, LegEnd legEnd, HandlingActivity handlingActivity, Itinerary itinerary)
 {
     Leg              = leg;
     LegEnd           = legEnd;
     HandlingActivity = handlingActivity;
     Itinerary        = itinerary;
 }
Пример #10
0
        public void testIsMisdirectedLoadOntoWrongVoyage()
        {
            Cargo cargo = shanghaiSeattleChicagoOnPacific2AndContinental3();

            cargo.Handled(HandlingActivity.LoadOnto(V.pacific1).In(L.HONGKONG));
            Assert.IsTrue(cargo.IsMisdirected);
        }
Пример #11
0
 private Delivery(HandlingActivity mostRecentHandlingActivity,
                  HandlingActivity mostRecentPhysicalHandlingActivity)
 {
     MostRecentHandlingActivity         = mostRecentHandlingActivity;
     MostRecentPhysicalHandlingActivity = mostRecentPhysicalHandlingActivity;
     LastUpdatedOn = DateTime.Now;
 }
Пример #12
0
        public void compareMatches()
        {
            Itinerary itinerary = new Itinerary(Leg.DeriveLeg(V.pacific1, L.TOKYO, L.LONGBEACH),
                                                Leg.DeriveLeg(V.continental2, L.LONGBEACH, L.DALLAS));

            LegActivityMatch startMatch = LegActivityMatch.Match(Leg.DeriveLeg(V.pacific1, L.TOKYO, L.LONGBEACH),
                                                                 HandlingActivity.LoadOnto(V.pacific1).In(L.TOKYO),
                                                                 itinerary);

            Assert.That(startMatch.HandlingActivity, Is.EqualTo(HandlingActivity.LoadOnto(V.pacific1).In(L.TOKYO)));
            Assert.That(startMatch.Leg, Is.EqualTo(Leg.DeriveLeg(V.pacific1, L.TOKYO, L.LONGBEACH)));

            LegActivityMatch endMatch = LegActivityMatch.Match(Leg.DeriveLeg(V.pacific1, L.TOKYO, L.LONGBEACH),
                                                               HandlingActivity.UnloadOff(V.pacific1).In(L.LONGBEACH),
                                                               itinerary);

            Assert.That(endMatch.HandlingActivity, Is.EqualTo(HandlingActivity.UnloadOff(V.pacific1).In(L.LONGBEACH)));
            Assert.That(endMatch.Leg, Is.EqualTo(Leg.DeriveLeg(V.pacific1, L.TOKYO, L.LONGBEACH)));

            LegActivityMatch nextMatch = LegActivityMatch.Match(Leg.DeriveLeg(V.continental2, L.LONGBEACH, L.DALLAS),
                                                                HandlingActivity.LoadOnto(V.continental2).In(L.LONGBEACH),
                                                                itinerary);

            Assert.That(nextMatch.HandlingActivity,
                        Is.EqualTo(HandlingActivity.LoadOnto(V.continental2).In(L.LONGBEACH)));
            Assert.That(nextMatch.Leg, Is.EqualTo(Leg.DeriveLeg(V.continental2, L.LONGBEACH, L.DALLAS)));

            Assert.That(startMatch.CompareTo(endMatch), Is.EqualTo(-1));
            Assert.That(endMatch.CompareTo(startMatch), Is.EqualTo(1));
            Assert.That(endMatch.CompareTo(nextMatch), Is.EqualTo(-1));
            Assert.That(nextMatch.CompareTo(endMatch), Is.EqualTo(1));

            Assert.That(startMatch.CompareTo(startMatch), Is.EqualTo(0));
        }
Пример #13
0
        public void testIsMisdirectedHappyPath()
        {
            Cargo cargo = shanghaiSeattleChicagoOnPacific2AndContinental3();

            //A cargo with no handling events is not misdirected
            Assert.IsFalse(cargo.IsMisdirected);

            cargo.Handled(HandlingActivity.ReceiveIn(L.SHANGHAI));
            Assert.IsFalse(cargo.IsMisdirected);

            cargo.Handled(HandlingActivity.LoadOnto(V.pacific2).In(L.SHANGHAI));
            Assert.IsFalse(cargo.IsMisdirected);

            cargo.Handled(HandlingActivity.UnloadOff(V.pacific2).In(L.SEATTLE));
            Assert.IsFalse(cargo.IsMisdirected);

            cargo.Handled(HandlingActivity.CustomsIn(L.SEATTLE));
            Assert.IsFalse(cargo.IsMisdirected);

            cargo.Handled(HandlingActivity.LoadOnto(V.continental3).In(L.SEATTLE));
            Assert.IsFalse(cargo.IsMisdirected);

            cargo.Handled(HandlingActivity.UnloadOff(V.continental3).In(L.CHICAGO));
            Assert.IsFalse(cargo.IsMisdirected);

            cargo.Handled(HandlingActivity.ClaimIn(L.CHICAGO));
            Assert.IsFalse(cargo.IsMisdirected);
        }
Пример #14
0
 public static LegActivityMatch IfUnloadLocationSame(Leg leg,
                                                     HandlingActivity handlingActivity,
                                                     Itinerary itinerary)
 {
     return(leg.UnloadLocation.sameAs(handlingActivity.Location)
         ? new LegActivityMatch(leg, LegEnd.UnloadEnd, handlingActivity, itinerary)
         : NoMatch(handlingActivity, itinerary));
 }
Пример #15
0
        /// <summary>
        /// Derives a new delivery when a cargo has been handled.
        /// </summary>
        /// <param name="newHandlingActivity">handling activity</param>
        /// <returns>An up to date delivery</returns>
        internal Delivery OnHandling(HandlingActivity newHandlingActivity)
        {
            Validate.notNull(newHandlingActivity, "Handling activity is required");

            return(newHandlingActivity.Type.isPhysical()
                ? new Delivery(newHandlingActivity, newHandlingActivity)
                : new Delivery(newHandlingActivity, MostRecentPhysicalHandlingActivity));
        }
Пример #16
0
        public void copy()
        {
            HandlingActivity activity = HandlingActivity.LoadOnto(V.pacific2).In(L.SEATTLE);
            HandlingActivity copy     = activity.Copy();

            Assert.True(activity.sameValueAs(copy));
            Assert.False(activity == copy);
        }
Пример #17
0
        public void testIfCargoIsOnTrack()
        {
            Itinerary itinerary = new Itinerary(Leg.DeriveLeg(voyage, L.SHANGHAI, L.ROTTERDAM),
                                                Leg.DeriveLeg(voyage, L.ROTTERDAM, L.GOTHENBURG));

            // HandlingActivity.Load(cargo, HandlingActivityType.RECEIVE, L.SHANGHAI, toDate("2009-05-03"))
            //Happy path
            HandlingActivity receiveShanghai = new HandlingActivity(HandlingActivityType.RECEIVE, L.SHANGHAI);

            Assert.IsTrue(itinerary.IsExpectedActivity(receiveShanghai));

            HandlingActivity loadShanghai = new HandlingActivity(HandlingActivityType.LOAD, L.SHANGHAI, voyage);

            Assert.IsTrue(itinerary.IsExpectedActivity(loadShanghai));

            HandlingActivity unloadRotterdam = new HandlingActivity(HandlingActivityType.UNLOAD, L.ROTTERDAM, voyage);

            Assert.IsTrue(itinerary.IsExpectedActivity(unloadRotterdam));

            HandlingActivity loadRotterdam = new HandlingActivity(HandlingActivityType.LOAD, L.ROTTERDAM, voyage);

            Assert.IsTrue(itinerary.IsExpectedActivity(loadRotterdam));

            HandlingActivity unloadGothenburg = new HandlingActivity(HandlingActivityType.UNLOAD, L.GOTHENBURG, voyage);

            Assert.IsTrue(itinerary.IsExpectedActivity(unloadGothenburg));

            HandlingActivity claimGothenburg = new HandlingActivity(HandlingActivityType.CLAIM, L.GOTHENBURG);

            Assert.IsTrue(itinerary.IsExpectedActivity(claimGothenburg));

            //TODO Customs event can only be interpreted properly by knowing the destination of the cargo.
            // This can be inferred from the Itinerary, but it isn't definitive. So, do we answer based on
            // the end of the itinerary (even though this would probably not be used in the app) or do we
            // ignore this at itinerary level somehow and leave it purely as a cargo responsibility.
            // (See customsClearancePoint tests in CargoTest)
            //    HandlingActivity customsGothenburg = new HandlingActivity(CUSTOMS, L.GOTHENBURG);
            //    Assert.IsTrue(itinerary.isExpectedActivity(customsGothenburg));

            //Received at the wrong location
            HandlingActivity receiveHangzou = new HandlingActivity(HandlingActivityType.RECEIVE, L.HANGZOU);

            Assert.IsFalse(itinerary.IsExpectedActivity(receiveHangzou));

            //Loaded to onto the wrong ship, correct location
            HandlingActivity loadRotterdam666 = new HandlingActivity(HandlingActivityType.LOAD, L.ROTTERDAM, wrongVoyage);

            Assert.IsFalse(itinerary.IsExpectedActivity(loadRotterdam666));

            //Unloaded from the wrong ship in the wrong location
            HandlingActivity unloadHelsinki = new HandlingActivity(HandlingActivityType.UNLOAD, L.HELSINKI, wrongVoyage);

            Assert.IsFalse(itinerary.IsExpectedActivity(unloadHelsinki));

            HandlingActivity claimRotterdam = new HandlingActivity(HandlingActivityType.CLAIM, L.ROTTERDAM);

            Assert.IsFalse(itinerary.IsExpectedActivity(claimRotterdam));
        }
Пример #18
0
        public void matchActivity()
        {
            Leg newYorkToDallas = Leg.DeriveLeg(voyage, L.NEWYORK, L.DALLAS);

            Assert.True(newYorkToDallas.MatchesActivity(HandlingActivity.LoadOnto(voyage).In(L.NEWYORK)));
            Assert.True(newYorkToDallas.MatchesActivity(HandlingActivity.UnloadOff(voyage).In(L.DALLAS)));
            Assert.False(newYorkToDallas.MatchesActivity(HandlingActivity.LoadOnto(voyage).In(L.DALLAS)));
            Assert.False(newYorkToDallas.MatchesActivity(HandlingActivity.UnloadOff(voyage).In(L.NEWYORK)));
        }
Пример #19
0
        /// <summary>
        /// Updates all aspects of the cargo aggregate status
        /// based on the current route specification, itinerary and handling of the cargo.
        /// </summary>
        /// <remarks>
        /// When either of those three changes, i.e. when a new route is specified for the cargo,
        /// the cargo is assigned to a route or when the cargo is handled, the status must be
        /// re-calculated.
        /// <p/>
        /// <see cref="Freight.RouteSpecification"/> and <see cref="Freight.Itinerary"/> are both inside the Cargo
        /// aggregate, so changes to them cause the status to be updated <b>synchronously</b>,
        /// but handling cause the status update to happen <b>asynchronously</b>
        /// since <see cref="HandlingEvent"/> is in a different aggregate.
        /// </remarks>
        /// <param name="handlingActivity">handling activity</param>
        public virtual void Handled(HandlingActivity handlingActivity)
        {
            Validate.notNull(handlingActivity, "Handling activity is required");

            if (SuccedsMostRecentActivity(handlingActivity))
            {
                Delivery = Delivery.OnHandling(handlingActivity);
            }
        }
Пример #20
0
        public void deriveActivities()
        {
            Leg newYorkToDallas = Leg.DeriveLeg(voyage, L.NEWYORK, L.DALLAS);

            Assert.That(newYorkToDallas.DeriveLoadActivity(),
                        Is.EqualTo(HandlingActivity.LoadOnto(voyage).In(L.NEWYORK)));
            Assert.That(newYorkToDallas.DeriveUnloadActivity(),
                        Is.EqualTo(HandlingActivity.UnloadOff(voyage).In(L.DALLAS)));
        }
Пример #21
0
 public Delivery(HandlingActivity nextExpectedActivity, HandlingActivity lastKnownActivity, RoutingStatus routingStatus, TransportStatus transportStatus, DateTime? estimatedTimeOfArrival, bool isUnloadedAtDestination, bool isMisdirected, DateTime calculatedAt)
 {
    NextExpectedActivity = nextExpectedActivity;
    LastKnownActivity = lastKnownActivity;
    RoutingStatus = routingStatus;
    TransportStatus = transportStatus;
    EstimatedTimeOfArrival = estimatedTimeOfArrival;
    IsUnloadedAtDestination = isUnloadedAtDestination;
    IsMisdirected = isMisdirected;
    CalculatedAt = calculatedAt;
 }
Пример #22
0
        public void testMostRecentHandling()
        {
            Cargo         cargo         = CargoRepository.find(new TrackingId("XYZ"));
            HandlingEvent handlingEvent = HandlingEventRepository.mostRecentHandling(cargo);

            Assert.AreEqual(cargo, handlingEvent.Cargo);
            Assert.AreEqual(DateTime.Parse("2007-09-27 04:00"), handlingEvent.CompletionTime);

            Assert.AreEqual(HandlingActivity.ClaimIn(SampleLocations.MELBOURNE), handlingEvent.Activity);
            Assert.AreEqual(handlingEvent.Activity, HandlingActivity.ClaimIn(SampleLocations.MELBOURNE));
        }
Пример #23
0
        private LegActivityMatch FindLegMatchingActivity(HandlingActivity handlingActivity)
        {
            foreach (var leg in Legs)
            {
                if (leg.MatchesActivity(handlingActivity))
                {
                    return(LegActivityMatch.Match(leg, handlingActivity, this));
                }
            }

            return(LegActivityMatch.NoMatch(handlingActivity, this));
        }
Пример #24
0
        private bool SuccedsMostRecentActivity(HandlingActivity newHandlingActivity)
        {
            if (!Delivery.HasBeenHandled)
            {
                return(true);
            }

            var mostRecentPhysicalHandlingActivity = Delivery.MostRecentPhysicalHandlingActivity;
            var priorActivity = Itinerary.StrictlyPriorOf(mostRecentPhysicalHandlingActivity, newHandlingActivity);

            return(!newHandlingActivity.sameValueAs(priorActivity));
        }
Пример #25
0
        public void testIfCargoIsOnTrack()
        {
            Itinerary itinerary = new Itinerary(Leg.DeriveLeg(voyage, L.SHANGHAI, L.ROTTERDAM),
                Leg.DeriveLeg(voyage, L.ROTTERDAM, L.GOTHENBURG));

            // HandlingActivity.Load(cargo, HandlingActivityType.RECEIVE, L.SHANGHAI, toDate("2009-05-03"))
            //Happy path
            HandlingActivity receiveShanghai = new HandlingActivity(HandlingActivityType.RECEIVE, L.SHANGHAI);
            Assert.IsTrue(itinerary.IsExpectedActivity(receiveShanghai));

            HandlingActivity loadShanghai = new HandlingActivity(HandlingActivityType.LOAD, L.SHANGHAI, voyage);
            Assert.IsTrue(itinerary.IsExpectedActivity(loadShanghai));

            HandlingActivity unloadRotterdam = new HandlingActivity(HandlingActivityType.UNLOAD, L.ROTTERDAM, voyage);
            Assert.IsTrue(itinerary.IsExpectedActivity(unloadRotterdam));

            HandlingActivity loadRotterdam = new HandlingActivity(HandlingActivityType.LOAD, L.ROTTERDAM, voyage);
            Assert.IsTrue(itinerary.IsExpectedActivity(loadRotterdam));

            HandlingActivity unloadGothenburg = new HandlingActivity(HandlingActivityType.UNLOAD, L.GOTHENBURG, voyage);
            Assert.IsTrue(itinerary.IsExpectedActivity(unloadGothenburg));

            HandlingActivity claimGothenburg = new HandlingActivity(HandlingActivityType.CLAIM, L.GOTHENBURG);
            Assert.IsTrue(itinerary.IsExpectedActivity(claimGothenburg));

            //TODO Customs event can only be interpreted properly by knowing the destination of the cargo.
            // This can be inferred from the Itinerary, but it isn't definitive. So, do we answer based on
            // the end of the itinerary (even though this would probably not be used in the app) or do we
            // ignore this at itinerary level somehow and leave it purely as a cargo responsibility.
            // (See customsClearancePoint tests in CargoTest)
            //    HandlingActivity customsGothenburg = new HandlingActivity(CUSTOMS, L.GOTHENBURG);
            //    Assert.IsTrue(itinerary.isExpectedActivity(customsGothenburg));

            //Received at the wrong location
            HandlingActivity receiveHangzou = new HandlingActivity(HandlingActivityType.RECEIVE, L.HANGZOU);
            Assert.IsFalse(itinerary.IsExpectedActivity(receiveHangzou));

            //Loaded to onto the wrong ship, correct location
            HandlingActivity loadRotterdam666 = new HandlingActivity(HandlingActivityType.LOAD, L.ROTTERDAM, wrongVoyage);
            Assert.IsFalse(itinerary.IsExpectedActivity(loadRotterdam666));

            //Unloaded from the wrong ship in the wrong location
            HandlingActivity unloadHelsinki = new HandlingActivity(HandlingActivityType.UNLOAD, L.HELSINKI, wrongVoyage);
            Assert.IsFalse(itinerary.IsExpectedActivity(unloadHelsinki));

            HandlingActivity claimRotterdam = new HandlingActivity(HandlingActivityType.CLAIM, L.ROTTERDAM);
            Assert.IsFalse(itinerary.IsExpectedActivity(claimRotterdam));
        }
Пример #26
0
 public static TransportStatus DeriveTransportStatus(this TransportStatus transportStatus,
                                                      HandlingActivity handlingActivity)
 {
     switch (handlingActivity.Type)
     {
         case HandlingActivityType.Load:
             return TransportStatus.OnboardCarrier;
         case HandlingActivityType.Receive:
         case HandlingActivityType.Unload:
             return TransportStatus.InPort;
         case HandlingActivityType.Claim:
             return TransportStatus.Claimed;
         default:
             return TransportStatus.Unknown;
     }
 }
Пример #27
0
        /// <summary>
        /// True if this legs matches the handling activity, i.e. the voyage and load location is the same in case of a load activity and so on.
        /// </summary>
        /// <param name="handlingActivity">handling activity</param>
        /// <returns>True if this legs matches the handling activity, i.e. the voyage and load location is the same in case of a load activity and so on.</returns>
        protected internal virtual bool MatchesActivity(HandlingActivity handlingActivity)
        {
            if (Voyage.sameAs(handlingActivity.Voyage))
            {
                if (handlingActivity.Type == HandlingActivityType.LOAD)
                {
                    return(LoadLocation.sameAs(handlingActivity.Location));
                }
                if (handlingActivity.Type == HandlingActivityType.UNLOAD)
                {
                    return(UnloadLocation.sameAs(handlingActivity.Location));
                }
            }

            return(false);
        }
Пример #28
0
        public static LegActivityMatch Match(Leg leg, HandlingActivity handlingActivity, Itinerary itinerary)
        {
            switch (handlingActivity.Type)
            {
            case HandlingActivityType.RECEIVE:
            case HandlingActivityType.LOAD:
                return(new LegActivityMatch(leg, LegEnd.LoadEnd, handlingActivity, itinerary));

            case HandlingActivityType.UNLOAD:
            case HandlingActivityType.CLAIM:
            case HandlingActivityType.CUSTOMS:
                return(new LegActivityMatch(leg, LegEnd.UnloadEnd, handlingActivity, itinerary));

            default:
                return(NoMatch(handlingActivity, itinerary));
            }
        }
Пример #29
0
        public void testIsReadyToClaimWithDestinationSameAsCustomsClearancePoint()
        {
            Cargo cargo = new Cargo(new TrackingId("CARGO1"),
                                    new RouteSpecification(L.SHANGHAI, L.SEATTLE, DateTime.Parse("2009-12-24")));
            Itinerary itinerary = new Itinerary(Leg.DeriveLeg(V.pacific2, L.SHANGHAI, L.SEATTLE));

            cargo.AssignToRoute(itinerary);
            Assert.IsTrue(cargo.RouteSpecification.Destination.sameAs(cargo.CustomsClearancePoint));
            Assert.IsFalse(cargo.IsReadyToClaim);

            cargo.Handled(HandlingActivity.UnloadOff(V.pacific2).In(L.SEATTLE));
            Assert.IsFalse(cargo.IsReadyToClaim);

            cargo.Handled(HandlingActivity.CustomsIn(L.SEATTLE));
            Assert.IsTrue(cargo.IsReadyToClaim);

            cargo.Handled(HandlingActivity.ClaimIn(L.SEATTLE));
            Assert.IsFalse(cargo.IsReadyToClaim);
        }
Пример #30
0
        /// <summary>
        /// Gets the activity which is strictly prior to the other, according to the itinerary, or null if neither is strictly prior.
        /// </summary>
        /// <param name="handlingActivity1">handling activity</param>
        /// <param name="handlingActivity2">handling activity</param>
        /// <returns>The activity which is strictly prior to the other, according to the itinerary, or null if neither is strictly prior.</returns>
        internal HandlingActivity StrictlyPriorOf(HandlingActivity handlingActivity1, HandlingActivity handlingActivity2)
        {
            var match1   = MatchLeg(handlingActivity1);
            var match2   = MatchLeg(handlingActivity2);
            var compared = match1.CompareTo(match2);

            if (compared < 0)
            {
                return(match1.HandlingActivity);
            }
            else if (compared > 0)
            {
                return(match2.HandlingActivity);
            }
            else
            {
                return(null);
            }
        }
Пример #31
0
 /// <summary>
 /// Gets the leg match of this handling activity. Never null.
 /// </summary>
 /// <param name="handlingActivity">handling activity</param>
 /// <returns>The leg match of this handling activity. Never null.</returns>
 internal LegActivityMatch MatchLeg(HandlingActivity handlingActivity)
 {
     if (handlingActivity == null)
     {
         return(LegActivityMatch.NoMatch(handlingActivity, this));
     }
     else if (handlingActivity.Type == HandlingActivityType.RECEIVE)
     {
         return(LegActivityMatch.IfLoadLocationSame(FirstLeg, handlingActivity, this));
     }
     else if (handlingActivity.Type == HandlingActivityType.CLAIM)
     {
         return(LegActivityMatch.IfUnloadLocationSame(LastLeg, handlingActivity, this));
     }
     else
     {
         return(FindLegMatchingActivity(handlingActivity));
     }
 }
Пример #32
0
        public void testLatestLeg()
        {
            Leg shanghaiToLongBeach = Leg.DeriveLeg(pacific, L.SHANGHAI, L.LONGBEACH);
            Leg longBeachToNewYork  = Leg.DeriveLeg(transcontinental, L.LONGBEACH, L.NEWYORK);
            Leg newYorkToRotterdam  = Leg.DeriveLeg(atlantic, L.NEWYORK, L.ROTTERDAM);

            Itinerary itinerary = new Itinerary(shanghaiToLongBeach, longBeachToNewYork, newYorkToRotterdam);

            HandlingActivity notOnRoute        = HandlingActivity.LoadOnto(pacific).In(L.STOCKHOLM);
            HandlingActivity loadInShanghai    = HandlingActivity.LoadOnto(pacific).In(L.SHANGHAI);
            HandlingActivity unloadInLongbeach = HandlingActivity.UnloadOff(pacific).In(L.LONGBEACH);

            Assert.That(itinerary.StrictlyPriorOf(loadInShanghai, unloadInLongbeach), Is.EqualTo(loadInShanghai));
            Assert.That(itinerary.StrictlyPriorOf(unloadInLongbeach, loadInShanghai), Is.EqualTo(loadInShanghai));

            Assert.That(itinerary.StrictlyPriorOf(unloadInLongbeach, notOnRoute), Is.EqualTo(unloadInLongbeach));
            Assert.That(itinerary.StrictlyPriorOf(notOnRoute, loadInShanghai), Is.EqualTo(loadInShanghai));

            Assert.IsNull(itinerary.StrictlyPriorOf(unloadInLongbeach, unloadInLongbeach));
        }
Пример #33
0
        public void testIsReadyToClaimWithDestinationDifferentFromCustomsClearancePoint()
        {
            Cargo cargo = new Cargo(new TrackingId("CARGO1"),
                                    new RouteSpecification(L.HONGKONG, L.NEWYORK, DateTime.Parse("2009-12-24")));
            Itinerary itinerary = new Itinerary(Leg.DeriveLeg(V.pacific1, L.HONGKONG, L.LONGBEACH),
                                                Leg.DeriveLeg(V.continental2, L.LONGBEACH, L.NEWYORK));

            cargo.AssignToRoute(itinerary);
            Assert.IsFalse(cargo.RouteSpecification.Destination.sameAs(cargo.CustomsClearancePoint));
            Assert.IsFalse(cargo.IsReadyToClaim);

            cargo.Handled(HandlingActivity.UnloadOff(V.pacific1).In(L.LONGBEACH));
            Assert.IsFalse(cargo.IsReadyToClaim);

            cargo.Handled(HandlingActivity.LoadOnto(V.continental2).In(L.LONGBEACH));
            Assert.IsFalse(cargo.IsReadyToClaim);

            cargo.Handled(HandlingActivity.UnloadOff(V.continental2).In(L.NEWYORK));
            Assert.IsTrue(cargo.IsReadyToClaim);
        }
Пример #34
0
        public static TransportStatus derivedFrom(HandlingActivity handlingActivity)
        {
            if(handlingActivity == null)
            {
                return TransportStatus.NOT_RECEIVED;
            }

            switch(handlingActivity.Type)
            {
                case HandlingActivityType.LOAD:
                    return TransportStatus.ONBOARD_CARRIER;

                case HandlingActivityType.UNLOAD:
                case HandlingActivityType.RECEIVE:
                case HandlingActivityType.CUSTOMS:
                    return TransportStatus.IN_PORT;

                case HandlingActivityType.CLAIM:
                    return TransportStatus.CLAIMED;

                default:
                    return TransportStatus.UNKNOWN;
            }
        }
Пример #35
0
 public void UpdateHistory(HandlingActivity nextExpectedActivity, HandlingActivity lastKnownActivity, RoutingStatus routingStatus, TransportStatus transportStatus, DateTime? estimatedTimeOfArrival, bool isUnloadedAtDestination, bool isMisdirected, DateTime calculatedAt)
 {
    var delivery = new Delivery(nextExpectedActivity, lastKnownActivity, routingStatus, transportStatus, estimatedTimeOfArrival, isUnloadedAtDestination, isMisdirected, calculatedAt);
    History.Add(delivery);
    CurrentInformation = delivery;
 }
Пример #36
0
        public void testUpdateOnHandlingWhenMisdirected()
        {
            // Unload in L.HAMBURG, which is the wrong location
            HandlingActivity handlingActivity = new HandlingActivity(HandlingActivityType.UNLOAD,
                L.HAMBURG,
                V.DALLAS_TO_HELSINKI);
            Delivery newDelivery = delivery.OnHandling(handlingActivity);

            Assert.AreEqual(Voyage.None, newDelivery.CurrentVoyage);
            Assert.AreEqual(L.HAMBURG, newDelivery.LastKnownLocation);
            Assert.AreEqual(TransportStatus.IN_PORT, newDelivery.TransportStatus);

            // Next handling activity is undefined. Need a new itinerary to know what to do.

            Assert.IsFalse(newDelivery.IsUnloadedIn(routeSpecification.Destination));

            Assert.AreEqual(RoutingStatus.ROUTED, routeSpecification.StatusOf(itinerary));

            Assert.IsTrue(delivery.LastUpdatedOn < (newDelivery.LastUpdatedOn));

            // New route specification, old itinerary
            RouteSpecification newRouteSpecification = routeSpecification.WithOrigin(L.HAMBURG);
            Assert.AreEqual(RoutingStatus.MISROUTED, newRouteSpecification.StatusOf(itinerary));

            Itinerary newItinerary = new Itinerary(Leg.DeriveLeg(V.DALLAS_TO_HELSINKI, L.HAMBURG, L.STOCKHOLM));

            Assert.AreEqual(RoutingStatus.ROUTED, newRouteSpecification.StatusOf(newItinerary));
            Assert.AreEqual(TransportStatus.IN_PORT, newDelivery.TransportStatus);
        }
Пример #37
0
        public void testUpdateOnHandlingHappyPath()
        {
            // 1. HandlingActivityType.RECEIVE

            HandlingActivity handlingActivity = new HandlingActivity(HandlingActivityType.RECEIVE, L.HANGZOU);
            Delivery newDelivery = delivery.OnHandling(handlingActivity);

            // Changed on handling
            Assert.AreEqual(Voyage.None, newDelivery.CurrentVoyage);
            Assert.AreEqual(L.HANGZOU, newDelivery.LastKnownLocation);
            Assert.AreEqual(TransportStatus.IN_PORT, newDelivery.TransportStatus);

            // Changed on handling and/or (re-)routing
            Assert.IsFalse(newDelivery.IsUnloadedIn(routeSpecification.Destination));

            // Changed on (re-)routing
            Assert.AreEqual(RoutingStatus.ROUTED, routeSpecification.StatusOf(itinerary));

            // Updated on every calculation
            Assert.IsTrue(delivery.LastUpdatedOn < (newDelivery.LastUpdatedOn));

            // 2. Load

            handlingActivity = new HandlingActivity(HandlingActivityType.LOAD, L.HANGZOU, V.HONGKONG_TO_NEW_YORK);
            newDelivery = newDelivery.OnHandling(handlingActivity);

            Assert.AreEqual(V.HONGKONG_TO_NEW_YORK, newDelivery.CurrentVoyage);
            Assert.AreEqual(L.HANGZOU, newDelivery.LastKnownLocation);
            Assert.AreEqual(TransportStatus.ONBOARD_CARRIER, newDelivery.TransportStatus);

            Assert.IsFalse(newDelivery.IsUnloadedIn(routeSpecification.Destination));

            Assert.AreEqual(RoutingStatus.ROUTED, routeSpecification.StatusOf(itinerary));

            Assert.IsTrue(delivery.LastUpdatedOn < (newDelivery.LastUpdatedOn));

            // Skipping intermediate load/unloads

            // 3. Unload

            handlingActivity = new HandlingActivity(HandlingActivityType.UNLOAD, L.STOCKHOLM, V.DALLAS_TO_HELSINKI);
            newDelivery = newDelivery.OnHandling(handlingActivity);

            Assert.AreEqual(Voyage.None, newDelivery.CurrentVoyage);
            Assert.AreEqual(L.STOCKHOLM, newDelivery.LastKnownLocation);
            Assert.AreEqual(TransportStatus.IN_PORT, newDelivery.TransportStatus);

            Assert.IsTrue(newDelivery.IsUnloadedIn(routeSpecification.Destination));

            Assert.AreEqual(RoutingStatus.ROUTED, routeSpecification.StatusOf(itinerary));

            Assert.IsTrue(delivery.LastUpdatedOn < (newDelivery.LastUpdatedOn));

            // 4. Claim

            handlingActivity = new HandlingActivity(HandlingActivityType.CLAIM, L.STOCKHOLM);
            newDelivery = newDelivery.OnHandling(handlingActivity);

            Assert.AreEqual(Voyage.None, newDelivery.CurrentVoyage);
            Assert.AreEqual(L.STOCKHOLM, newDelivery.LastKnownLocation);
            Assert.AreEqual(TransportStatus.CLAIMED, newDelivery.TransportStatus);

            Assert.IsFalse(newDelivery.IsUnloadedIn(routeSpecification.Destination));

            Assert.AreEqual(RoutingStatus.ROUTED, routeSpecification.StatusOf(itinerary));

            Assert.IsTrue(delivery.LastUpdatedOn < (newDelivery.LastUpdatedOn));
        }
Пример #38
0
 public void Handled(HandlingActivity handlingActivity)
 {
     TransportStatus = TransportStatus.DeriveTransportStatus(handlingActivity);
     LastKnownLocation = handlingActivity.Location;
 }