示例#1
0
      public void IsExpected_ReceiveEvent_FirstLegLocationDoesntMatchEventLocation_False()
      {
         Itinerary itinerary = new Itinerary(new[] { new Leg(null, Krakow, DateTime.Now, Warszawa, DateTime.Now) });
         HandlingEvent @event = new HandlingEvent(HandlingEventType.Receive, Warszawa, DateTime.Now, DateTime.Now);

         Assert.IsFalse(itinerary.IsExpected(@event));
      }
示例#2
0
      public void IsExpected_ClaimEvent_Empty_False()
      {
         Itinerary itinerary = new Itinerary(new Leg[] { });
         HandlingEvent @event = new HandlingEvent(HandlingEventType.Claim, Krakow, DateTime.Now, DateTime.Now);

         Assert.IsFalse(itinerary.IsExpected(@event));
      }
示例#3
0
 private bool CalculateMisdirectionStatus(Itinerary itinerary)
 {
     if (LastEvent == null)
     {
         return(false);
     }
     return(!itinerary.IsExpected(LastEvent));
 }
示例#4
0
 private static RoutingStatus CalculateRoutingStatus(Itinerary itinerary, RouteSpecification specification)
 {
     if (itinerary == null)
     {
         return(RoutingStatus.NotRouted);
     }
     return(specification.IsSatisfiedBy(itinerary) ? RoutingStatus.Routed : RoutingStatus.Misrouted);
 }
 public IList<LegDTO> ToLegDTOs(Itinerary itinerary)
 {
    if (itinerary == null)
    {
       return new List<LegDTO>();
    }
    return itinerary.Legs.Select(x => _legDTOAssembler.ToDTO(x)).ToList();
 }
示例#6
0
 /// <summary>
 /// Creates a new delivery snapshot to reflect changes in routing, i.e. when the route
 /// specification or the itinerary has changed but no additional handling of the
 /// cargo has been performed.
 /// </summary>
 /// <param name="routeSpecification">Current route specification.</param>
 /// <param name="itinerary">Current itinerary.</param>
 /// <returns>New delivery status description.</returns>
 public Delivery UpdateOnRouting(RouteSpecification routeSpecification, Itinerary itinerary)
 {
     if (routeSpecification == null)
     {
         throw new ArgumentNullException("routeSpecification");
     }
     return(new Delivery(_lastEvent, itinerary, routeSpecification));
 }
示例#7
0
 /// <summary>
 /// Assigns cargo to a provided route.
 /// </summary>
 /// <param name="itinerary">New itinerary</param>
 public virtual void AssignToRoute(Itinerary itinerary)
 {
    if (itinerary == null)
    {
       throw new ArgumentNullException("itinerary");
    }
    CargoHasBeenAssignedToRouteEvent @event = new CargoHasBeenAssignedToRouteEvent(this, Itinerary);
    Itinerary = itinerary;
    Delivery = Delivery.UpdateOnRouting(RouteSpecification, Itinerary);
    DomainEvents.Raise(@event);
 }
示例#8
0
      public void IsExpected_ClainEvent_LastLegLocationDoesntMatchEventLocation_False()
      {
         Itinerary itinerary = new Itinerary(new[]
                                                {
                                                   new Leg(null, Krakow, DateTime.Now, Warszawa, DateTime.Now),
                                                   new Leg(null, Warszawa, DateTime.Now, Wroclaw, DateTime.Now)                                                   
                                                });
         HandlingEvent @event = new HandlingEvent(HandlingEventType.Claim, Warszawa, DateTime.Now, DateTime.Now);

         Assert.IsFalse(itinerary.IsExpected(@event));
      }
示例#9
0
      public void IsExpected_LoadEvent_FirstLegLocationMathesEventLocation_True()
      {
         Itinerary itinerary = new Itinerary(new[]
                                                {
                                                   new Leg(null, Krakow, DateTime.Now, Warszawa, DateTime.Now),
                                                   new Leg(null, Warszawa, DateTime.Now, Wroclaw, DateTime.Now)                                                   
                                                });

         HandlingEvent @event = new HandlingEvent(HandlingEventType.Load, Krakow, DateTime.Now, DateTime.Now);         

         Assert.IsTrue(itinerary.IsExpected(@event));
      }
示例#10
0
        /// <summary>
        /// Assigns cargo to a provided route.
        /// </summary>
        /// <param name="itinerary">New itinerary</param>
        public virtual void AssignToRoute(Itinerary itinerary)
        {
            if (itinerary == null)
            {
                throw new ArgumentNullException("itinerary");
            }
            CargoHasBeenAssignedToRouteEvent @event = new CargoHasBeenAssignedToRouteEvent(this, Itinerary);

            Itinerary = itinerary;
            Delivery  = Delivery.UpdateOnRouting(RouteSpecification, Itinerary);
            DomainEvents.Raise(@event);
        }
示例#11
0
        private Delivery(HandlingEvent lastHandlingEvent, Itinerary itinerary, RouteSpecification specification)
        {
            _calculatedAt = DateTime.Now;
            _lastEvent    = lastHandlingEvent;

            _misdirected       = CalculateMisdirectionStatus(itinerary);
            _routingStatus     = CalculateRoutingStatus(itinerary, specification);
            _transportStatus   = CalculateTransportStatus();
            _lastKnownLocation = CalculateLastKnownLocation();
            _eta = CalculateEta(itinerary);
            _nextExpectedActivity    = CalculateNextExpectedActivity(specification, itinerary);
            _isUnloadedAtDestination = CalculateUnloadedAtDestination(specification);
        }
示例#12
0
 /// <summary>
 /// Checks whether provided itinerary (a description of transporting steps) satisfies this
 /// specification.
 /// </summary>
 /// <param name="itinerary">An itinerary.</param>
 /// <returns>True, if cargo can be transported from <see cref="Origin"/> to <see cref="Destination"/>
 /// before <see cref="ArrivalDeadline"/> using provided itinerary.
 /// </returns>
 public virtual bool IsSatisfiedBy(Itinerary itinerary)
 {
     return(Origin == itinerary.InitialDepartureLocation &&
            Destination == itinerary.FinalArrivalLocation &&
            ArrivalDeadline > itinerary.FinalArrivalDate);
 }
示例#13
0
 /// <summary>
 /// Creates a new delivery snapshot based on the complete handling history of a cargo, as well 
 /// as its route specification and itinerary.
 /// </summary>
 /// <param name="specification">Current route specification.</param>
 /// <param name="itinerary">Current itinerary.</param>
 /// <param name="lastHandlingEvent">Most recent handling event.</param>
 /// <returns>Delivery status description.</returns>
 public static Delivery DerivedFrom(RouteSpecification specification, Itinerary itinerary, HandlingEvent lastHandlingEvent)
 {
    return new Delivery(lastHandlingEvent, itinerary, specification);
 }
示例#14
0
 private bool CalculateMisdirectionStatus(Itinerary itinerary)
 {
    if (LastEvent == null)
    {
       return false;
    }
    return !itinerary.IsExpected(LastEvent);
 }
示例#15
0
 private static RoutingStatus CalculateRoutingStatus(Itinerary itinerary, RouteSpecification specification)
 {
    if (itinerary == null)
    {
       return RoutingStatus.NotRouted;
    }
    return specification.IsSatisfiedBy(itinerary) ? RoutingStatus.Routed : RoutingStatus.Misrouted;
 }
示例#16
0
      private HandlingActivity CalculateNextExpectedActivity(RouteSpecification routeSpecification, Itinerary itinerary)
      {
         if (!OnTrack)
         {
            return null;
         }

         if (LastEvent == null)
         {
            return new HandlingActivity(HandlingEventType.Receive, routeSpecification.Origin);
         }

         switch (LastEvent.EventType)
         {
            case HandlingEventType.Load:

               Leg lastLeg = itinerary.Legs.FirstOrDefault(x => x.LoadLocation == LastEvent.Location);
               return lastLeg != null ? new HandlingActivity(HandlingEventType.Unload, lastLeg.UnloadLocation) : null;

            case HandlingEventType.Unload:
               IEnumerator<Leg> enumerator = itinerary.Legs.GetEnumerator();
               while (enumerator.MoveNext())
               {
                  if (enumerator.Current.UnloadLocation == LastEvent.Location)
                  {
                     Leg currentLeg = enumerator.Current;
                     return enumerator.MoveNext() ? new HandlingActivity(HandlingEventType.Load, enumerator.Current.LoadLocation) : new HandlingActivity(HandlingEventType.Claim, currentLeg.UnloadLocation);
                  }
               }
               return null;

            case HandlingEventType.Receive:
               Leg firstLeg = itinerary.Legs.First();
               return new HandlingActivity(HandlingEventType.Load, firstLeg.LoadLocation);
            default:
               return null;
         }
      }
示例#17
0
 /// <summary>
 /// Creates a new delivery snapshot based on the complete handling history of a cargo, as well
 /// as its route specification and itinerary.
 /// </summary>
 /// <param name="specification">Current route specification.</param>
 /// <param name="itinerary">Current itinerary.</param>
 /// <param name="lastHandlingEvent">Most recent handling event.</param>
 /// <returns>Delivery status description.</returns>
 public static Delivery DerivedFrom(RouteSpecification specification, Itinerary itinerary, HandlingEvent lastHandlingEvent)
 {
     return(new Delivery(lastHandlingEvent, itinerary, specification));
 }
示例#18
0
 private DateTime?CalculateEta(Itinerary itinerary)
 {
     return(OnTrack ? itinerary.FinalArrivalDate : null);
 }
示例#19
0
 /// <summary>
 /// Creates a new delivery snapshot to reflect changes in routing, i.e. when the route 
 /// specification or the itinerary has changed but no additional handling of the 
 /// cargo has been performed.
 /// </summary>
 /// <param name="routeSpecification">Current route specification.</param>
 /// <param name="itinerary">Current itinerary.</param>
 /// <returns>New delivery status description.</returns>
 public Delivery UpdateOnRouting(RouteSpecification routeSpecification, Itinerary itinerary)
 {
    if (routeSpecification == null)
    {
       throw new ArgumentNullException("routeSpecification");
    }
    return new Delivery(_lastEvent, itinerary, routeSpecification);
 }
示例#20
0
 public void AssignCargoToRoute(TrackingId trackingId, Itinerary itinerary)
 {
    Cargo cargo = _cargoRepository.Find(trackingId);
    cargo.AssignToRoute(itinerary);
 }
示例#21
0
        private HandlingActivity CalculateNextExpectedActivity(RouteSpecification routeSpecification, Itinerary itinerary)
        {
            if (!OnTrack)
            {
                return(null);
            }

            if (LastEvent == null)
            {
                return(new HandlingActivity(HandlingEventType.Receive, routeSpecification.Origin));
            }

            switch (LastEvent.EventType)
            {
            case HandlingEventType.Load:

                Leg lastLeg = itinerary.Legs.FirstOrDefault(x => x.LoadLocation == LastEvent.Location);
                return(lastLeg != null ? new HandlingActivity(HandlingEventType.Unload, lastLeg.UnloadLocation) : null);

            case HandlingEventType.Unload:
                IEnumerator <Leg> enumerator = itinerary.Legs.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    if (enumerator.Current.UnloadLocation == LastEvent.Location)
                    {
                        Leg currentLeg = enumerator.Current;
                        return(enumerator.MoveNext() ? new HandlingActivity(HandlingEventType.Load, enumerator.Current.LoadLocation) : new HandlingActivity(HandlingEventType.Claim, currentLeg.UnloadLocation));
                    }
                }
                return(null);

            case HandlingEventType.Receive:
                Leg firstLeg = itinerary.Legs.First();
                return(new HandlingActivity(HandlingEventType.Load, firstLeg.LoadLocation));

            default:
                return(null);
            }
        }
示例#22
0
 /// <summary>
 /// Checks whether provided itinerary (a description of transporting steps) satisfies this
 /// specification.
 /// </summary>
 /// <param name="itinerary">An itinerary.</param>
 /// <returns>True, if cargo can be transported from <see cref="Origin"/> to <see cref="Destination"/>
 /// before <see cref="ArrivalDeadline"/> using provided itinerary.
 /// </returns>
 public virtual bool IsSatisfiedBy(Itinerary itinerary)
 {
    return Origin == itinerary.InitialDepartureLocation &&
           Destination == itinerary.FinalArrivalLocation &&
           ArrivalDeadline > itinerary.FinalArrivalDate;         
 }
 public RouteCandidateDTO ToDTO(Itinerary itinerary)
 {
    return new RouteCandidateDTO(itinerary.Legs.Select(x => _legDTOAssembler.ToDTO(x)).ToList());
 }      
示例#24
0
      private Delivery(HandlingEvent lastHandlingEvent, Itinerary itinerary, RouteSpecification specification)
      {
         _calculatedAt = DateTime.Now;
         _lastEvent = lastHandlingEvent;

         _misdirected = CalculateMisdirectionStatus(itinerary);
         _routingStatus = CalculateRoutingStatus(itinerary, specification);
         _transportStatus = CalculateTransportStatus();
         _lastKnownLocation = CalculateLastKnownLocation();
         _eta = CalculateEta(itinerary);
         _nextExpectedActivity = CalculateNextExpectedActivity(specification, itinerary);
         _isUnloadedAtDestination = CalculateUnloadedAtDestination(specification);
      }
示例#25
0
 private DateTime? CalculateEta(Itinerary itinerary)
 {
    return OnTrack ? itinerary.FinalArrivalDate : null;
 }
 public CargoHasBeenAssignedToRouteEvent(DomainModel.Operations.Cargo.Cargo source, Itinerary oldItinerary) : base(source)
 {
     _oldItinerary = oldItinerary;
 }