Esempio n. 1
0
      public void IsExpected_ReceiveEvent_FirstLegLocationMathesEventLocation_True()
      {
         Itinerary itinerary = new Itinerary(new[]{new Leg(Krakow, DateTime.Now, Warszawa, DateTime.Now  )});
         HandlingEvent @event = new HandlingEvent(HandlingEventType.Receive, Krakow, DateTime.Now, DateTime.Now);

         Assert.IsTrue(itinerary.IsExpected(@event));
      }
Esempio n. 2
0
      public void IsExpected_ReceiveEvent_FirstLegLocationDoesntMatchEventLocation_False()
      {
         Itinerary itinerary = new Itinerary(new[] { new Leg(Krakow, DateTime.Now, Warszawa, DateTime.Now) });
         HandlingEvent @event = new HandlingEvent(HandlingEventType.Receive, Warszawa, DateTime.Now, DateTime.Now, null);

         Assert.IsFalse(itinerary.IsExpected(@event));
      }
Esempio n. 3
0
        public void Claim_event_is_not_expected_by_an_empty_itinerary()
        {
            var cargoWithEmptyItinerary = new Itinerary(new Leg[] { });

            cargoWithEmptyItinerary
                .IsNotExpectedToBe(HandlingEventType.Claim).In(Krakow);
        }
 public CargoWasAssignedToRouteEvent(Cargo cargo, Itinerary oldItinerary, Itinerary newItinerary, Delivery delivery)
 {
    _cargo = cargo;
    _delivery = delivery;
    _newItinerary = newItinerary;
    _oldItinerary = oldItinerary;
 }
Esempio n. 5
0
      public void IsExpected_ClaimEvent_Empty_False()
      {
         Itinerary itinerary = new Itinerary(new Leg[] { });
         HandlingEvent @event = new HandlingEvent(HandlingEventType.Claim, Krakow, DateTime.Now, DateTime.Now, null);

         Assert.IsFalse(itinerary.IsExpected(@event));
      }
Esempio n. 6
0
 private static bool CalculateMisdirectionStatus(HandlingEvent lastEvent, Itinerary itinerary)
 {
     if (lastEvent == null)
     {
         return(false);
     }
     return(!itinerary.IsExpected(lastEvent));
 }
 public IList<LegDTO> ToLegDTOs(Itinerary itinerary)
 {
    if (itinerary == null)
    {
       return new List<LegDTO>();
    }
    return itinerary.Legs.Select(x => _legDTOAssembler.ToDTO(x)).ToList();
 }
Esempio n. 8
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));
 }
Esempio n. 9
0
 private static RoutingStatus CalculateRoutingStatus(Itinerary itinerary, RouteSpecification specification)
 {
     if (itinerary == null)
     {
         return(RoutingStatus.NotRouted);
     }
     return(specification.IsSatisfiedBy(itinerary) ? RoutingStatus.Routed : RoutingStatus.Misrouted);
 }
Esempio n. 10
0
 private bool CalculateMisdirectionStatus(Itinerary itinerary)
 {
     if (LastEvent == null)
     {
         return(false);
     }
     return(!itinerary.IsExpected(LastEvent));
 }
  public RouteCandidateDTO ToDTO(Itinerary itinerary)
 {
     var legs = itinerary.Legs.Select(ToLegDTO).ToList();
     return new RouteCandidateDTO
                {
                    Legs = legs
                };
 }
Esempio n. 12
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");
     }
     Itinerary = itinerary;
     Delivery  = Delivery.UpdateOnRouting(RouteSpecification, Itinerary);
 }
Esempio n. 13
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");
     }
     Itinerary = itinerary;
     Delivery = Delivery.UpdateOnRouting(RouteSpecification, Itinerary);
 }
Esempio n. 14
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");
    }
    Delivery delivery = Delivery.DerivedFrom(_routeSpecification, itinerary, _lastHandlingEvent);
    CargoWasAssignedToRouteEvent @event = new CargoWasAssignedToRouteEvent(this, _itinerary, itinerary, delivery);
    _itinerary = itinerary;         
    DomainEvents.Raise(@event);
 }      
Esempio n. 15
0
      public void IsExpected_ClainEvent_LastLegLocationDoesntMatchEventLocation_False()
      {
         Itinerary itinerary = new Itinerary(new[]
                                                {
                                                   new Leg(Krakow, DateTime.Now, Warszawa, DateTime.Now),
                                                   new Leg(Warszawa, DateTime.Now, Wroclaw, DateTime.Now)                                                   
                                                });
         HandlingEvent @event = new HandlingEvent(HandlingEventType.Claim, Warszawa, DateTime.Now, DateTime.Now, null);

         Assert.IsFalse(itinerary.IsExpected(@event));
      }
        public void It_is_not_satisfied_if_destination_does_not_match()
        {
            var specification = new RouteSpecification(Krakow, Wroclaw, ArrivalDeadline);

            var itinerary = new Itinerary(new[]
                                              {
                                                  new Leg(null, Krakow, new DateTime(2011, 12, 1), Warszawa,
                                                          new DateTime(2011, 12, 2))
                                              });
            Assert.IsFalse(specification.IsSatisfiedBy(itinerary));
        }
Esempio n. 17
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");
            }
            Delivery delivery = Delivery.DerivedFrom(_routeSpecification, itinerary, _lastHandlingEvent);
            CargoWasAssignedToRouteEvent @event = new CargoWasAssignedToRouteEvent(this, _itinerary, itinerary, delivery);

            _itinerary = itinerary;
            DomainEvents.Raise(@event);
        }
Esempio n. 18
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);
        }
        public void It_is_satisfied_if_origin_and_destination_match_and_deadline_is_not_exceeded()
        {
            var specification = new RouteSpecification(Krakow, Wroclaw, ArrivalDeadline);

            var itinerary = new Itinerary(new[]
                                              {
                                                  new Leg(null, Krakow, new DateTime(2011, 12, 1), Warszawa,
                                                          new DateTime(2011, 12, 2)),
                                                  new Leg(null, Warszawa, new DateTime(2011, 12, 13), Wroclaw,
                                                          ArrivalDeadline)
                                              });
            Assert.IsTrue(specification.IsSatisfiedBy(itinerary));
        }
Esempio n. 20
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");
         }
         if (!RouteSpecification.IsSatisfiedBy(itinerary))
         {
            throw new InvalidOperationException("Provided itinerary doesn't satisfy this cargo's route specification.");
         }

         Publish(this, new CargoAssignedToRouteEvent(itinerary, DeliveryStatus.Derive(RouteSpecification, itinerary)));
      }      
Esempio n. 21
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");
            }
            if (!_routeSpecification.IsSatisfiedBy(itinerary))
            {
                throw new InvalidOperationException("Provided itinerary doesn't satisfy this cargo's route specification.");
            }

            Publish(this, new CargoAssignedToRouteEvent(itinerary, _deliveryStatus.Derive(_routeSpecification, itinerary)));
        }
Esempio n. 22
0
        private Delivery(HandlingEvent lastHandlingEvent, Itinerary itinerary, RouteSpecification specification)
        {
            _calculatedAt = DateTime.Now;
            _lastEvent    = lastHandlingEvent;

            _isMisdirected           = CalculateMisdirectionStatus(itinerary);
            _routingStatus           = CalculateRoutingStatus(itinerary, specification);
            _transportStatus         = CalculateTransportStatus();
            _lastKnownLocation       = CalculateLastKnownLocation();
            _estimatedTimeOfArrival  = CalculateEta(itinerary);
            _nextExpectedActivity    = CalculateNextExpectedActivity(specification, itinerary);
            _isUnloadedAtDestination = CalculateUnloadedAtDestination(specification);
        }
 public CargoHasBeenAssignedToRouteEvent(Cargo source, Itinerary oldItinerary) : base(source)
 {
     _oldItinerary = oldItinerary;
 }
Esempio n. 24
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);
 }
Esempio n. 25
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));
 }
Esempio n. 26
0
      private Delivery(HandlingEvent lastHandlingEvent, Itinerary itinerary, RouteSpecification specification)
      {
         CalculatedAt = DateTime.Now;
         LastEvent = lastHandlingEvent;

         IsMisdirected = CalculateMisdirectionStatus(itinerary, lastHandlingEvent);
         RoutingStatus = CalculateRoutingStatus(itinerary, specification);
         TransportStatus = CalculateTransportStatus(lastHandlingEvent);
         LastKnownLocation = CalculateLastKnownLocation(lastHandlingEvent);
         EstimatedTimeOfArrival = CalculateEta(itinerary);
         NextExpectedActivity = CalculateNextExpectedActivity(specification, itinerary, lastHandlingEvent);
         IsUnloadedAtDestination = CalculateUnloadedAtDestination(specification, lastHandlingEvent);
      }
Esempio n. 27
0
 private DateTime?CalculateEta(Itinerary itinerary)
 {
     return(OnTrack ? itinerary.FinalArrivalDate : null);
 }
Esempio n. 28
0
 /// <summary>
 /// Creates a new delivery snapshot based only on route specification and itinerary.
 /// </summary>
 /// <param name="specification">Current route specification.</param>
 /// <param name="itinerary">Current itinerary.</param>
 /// <returns>Delivery status description.</returns>
 public static Delivery DerivedFrom(RouteSpecification specification, Itinerary itinerary)
 {
    return new Delivery(null, itinerary, specification);
 }
Esempio n. 29
0
        private HandlingActivity CalculateNextExpectedActivity(HandlingEvent lastEvent, 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;
            }
        }
Esempio n. 30
0
 private DateTime? CalculateEta(Itinerary itinerary)
 {
     return OnTrack ? itinerary.FinalArrivalDate : null;
 }
Esempio n. 31
0
 private bool CalculateMisdirectionStatus(Itinerary itinerary)
 {
    if (LastEvent == null)
    {
       return false;
    }
    return !itinerary.IsExpected(LastEvent);
 }
 public RouteCandidateDTO ToDTO(Itinerary itinerary)
 {
    return new RouteCandidateDTO(itinerary.Legs.Select(x => _legDTOAssembler.ToDTO(x)).ToList());
 }      
Esempio n. 33
0
 public CargoAssignedToRouteEvent(Itinerary newItinerary, Delivery delivery)
 {
     _delivery     = delivery;
     _newItinerary = newItinerary;
 }
Esempio n. 34
0
 /// <summary>
 /// Creates a new delivery snapshot based on the previous (current) one and (possibly changed)
 /// specification and itinerary.
 /// </summary>
 /// <param name="specification">Current route specification.</param>
 /// <param name="itinerary">Current itinerary.</param>
 /// <returns>Delivery status description.</returns>
 public Delivery Derive(RouteSpecification specification, Itinerary itinerary)
 {
    return new Delivery(LastEvent, itinerary, specification);
 }
Esempio n. 35
0
      public void IsExpected_LoadEvent_NoLegLocationMathesEventLocation_True()
      {
         Itinerary itinerary = new Itinerary(new[]
                                                {
                                                   new Leg(Krakow, DateTime.Now, Warszawa, DateTime.Now),
                                                   new Leg(Warszawa, DateTime.Now, Wroclaw, DateTime.Now)                                                   
                                                });

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

         Assert.IsFalse(itinerary.IsExpected(@event));
      }
Esempio n. 36
0
 private static RoutingStatus CalculateRoutingStatus(Itinerary itinerary, RouteSpecification specification)
 {
     if (itinerary == null)
     {
         return RoutingStatus.NotRouted;
     }
     return specification.IsSatisfiedBy(itinerary) ? RoutingStatus.Routed : RoutingStatus.Misrouted;
 }
Esempio n. 37
0
 private void OnCargoAssignedToRoute(CargoAssignedToRouteEvent @event)
 {
     _itinerary      = @event.NewItinerary;
     _deliveryStatus = @event.Delivery;
 }
Esempio n. 38
0
 private static bool CalculateMisdirectionStatus(HandlingEvent lastEvent, Itinerary itinerary)
 {
     if (lastEvent == null)
     {
         return false;
     }
     return !itinerary.IsExpected(lastEvent);
 }
Esempio n. 39
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);
 }
Esempio n. 40
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;         
 }
Esempio n. 41
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);
            }
        }
Esempio n. 42
0
 /// <summary>
 /// Creates a new delivery snapshot based on the previous (current) one and (possibly changed)
 /// specification and itinerary.
 /// </summary>
 /// <param name="specification">Current route specification.</param>
 /// <param name="itinerary">Current itinerary.</param>
 /// <returns>Delivery status description.</returns>
 public Delivery Derive(RouteSpecification specification, Itinerary itinerary)
 {
     return(new Delivery(_lastEvent, itinerary, specification));
 }
Esempio n. 43
0
 public ItineraryTestHelper(bool expected, HandlingEventType eventType, Itinerary itinerary)
 {
     _expected = expected;
     _itinerary = itinerary;
     _eventType = eventType;
 }
Esempio n. 44
0
 /// <summary>
 /// Creates a new delivery snapshot based only on route specification and itinerary.
 /// </summary>
 /// <param name="specification">Current route specification.</param>
 /// <param name="itinerary">Current itinerary.</param>
 /// <returns>Delivery status description.</returns>
 public static Delivery DerivedFrom(RouteSpecification specification, Itinerary itinerary)
 {
     return(new Delivery(null, itinerary, specification));
 }
Esempio n. 45
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);
 }
Esempio n. 46
0
 private void OnCargoAssignedToRoute(CargoAssignedToRouteEvent @event)
 {
    _itinerary = @event.NewItinerary;
    _deliveryStatus = @event.Delivery;
 }
Esempio n. 47
0
 public void AssignCargoToRoute(TrackingId trackingId, Itinerary itinerary)
 {
    Cargo cargo = _cargoRepository.Find(trackingId);
    cargo.AssignToRoute(itinerary);
 }
Esempio n. 48
0
        private Delivery(HandlingEvent lastHandlingEvent, Itinerary itinerary, RouteSpecification specification)
        {
            _calculatedAt = DateTime.Now;
            _lastEvent = lastHandlingEvent;

            _misdirected = CalculateMisdirectionStatus(LastEvent, itinerary);
            _routingStatus = CalculateRoutingStatus(itinerary, specification);
            _transportStatus = CalculateTransportStatus(LastEvent);
            _lastKnownLocation = CalculateLastKnownLocation(LastEvent);
            _eta = CalculateEta(itinerary);
            _nextExpectedActivity = CalculateNextExpectedActivity(LastEvent, specification, itinerary);
            _isUnloadedAtDestination = CalculateUnloadedAtDestination(LastEvent, specification);
        }