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)); }
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)); }
private bool CalculateMisdirectionStatus(Itinerary itinerary) { if (LastEvent == null) { return(false); } return(!itinerary.IsExpected(LastEvent)); }
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(); }
/// <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)); }
/// <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 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)); }
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)); }
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); }
/// <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); }
/// <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); }
private bool CalculateMisdirectionStatus(Itinerary itinerary) { if (LastEvent == null) { return false; } return !itinerary.IsExpected(LastEvent); }
private static RoutingStatus CalculateRoutingStatus(Itinerary itinerary, RouteSpecification specification) { if (itinerary == null) { return RoutingStatus.NotRouted; } return specification.IsSatisfiedBy(itinerary) ? RoutingStatus.Routed : RoutingStatus.Misrouted; }
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; } }
/// <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)); }
private DateTime?CalculateEta(Itinerary itinerary) { return(OnTrack ? itinerary.FinalArrivalDate : null); }
/// <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); }
public void AssignCargoToRoute(TrackingId trackingId, Itinerary itinerary) { Cargo cargo = _cargoRepository.Find(trackingId); cargo.AssignToRoute(itinerary); }
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); } }
/// <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()); }
private DateTime? CalculateEta(Itinerary itinerary) { return OnTrack ? itinerary.FinalArrivalDate : null; }
public CargoHasBeenAssignedToRouteEvent(DomainModel.Operations.Cargo.Cargo source, Itinerary oldItinerary) : base(source) { _oldItinerary = oldItinerary; }