/// <summary> /// Creates new <see cref="Cargo"/> object with provided tracking id and route specification. /// </summary> /// <param name="trackingId">Tracking id of this cargo.</param> /// <param name="routeSpecification">Route specification.</param> public Cargo(TrackingId trackingId, RouteSpecification routeSpecification) { if (trackingId == null) throw new ArgumentNullException("trackingId"); if (routeSpecification == null) throw new ArgumentNullException("routeSpecification"); TrackingId = trackingId; // Cargo origin never changes, even if the route specification changes. // However, at creation, cargo orgin can be derived from the initial route specification. Origine = routeSpecification.Origin; RouteSpecification = routeSpecification; Delivery = Delivery.DerivedFrom(RouteSpecification, Itinerary, HandlingHistory.EmptyHistory); }
public ItineraryTests() { _voyage = new VoyageBuilder(new VoyageNumber("0123"), _shanghai) .AddMovement(_rotterdam, DateTime.Now, DateTime.Now) .AddMovement(_gothenburg, DateTime.Now, DateTime.Now) .Build(); _wrongVoyage = new VoyageBuilder(new VoyageNumber("666"), _newyork) .AddMovement(new BookingApi.Domain.Location.Location(UnLocodeHelpers.GetNewUnLocode(), "STOCKHOLM"), DateTime.Now, DateTime.Now) .AddMovement(_helsinki, DateTime.Now, DateTime.Now) .Build(); _trackingId = new TrackingId("CARGO1"); _routeSpecification = new RouteSpecification(_shanghai, _gothenburg, DateTime.Now); _cargo = new BookingApi.Domain.Cargo.Cargo(_trackingId, _routeSpecification); _itinerary = new Itinerary(new List<Leg> { new Leg(_voyage, _shanghai, DateTime.Now, _rotterdam, DateTime.Now), new Leg(_voyage, _rotterdam, DateTime.Now, _gothenburg, DateTime.Now) }); }
public HandlingEventTests() { var trackingId = new TrackingId("XYZ"); _hongkong = new BookingApi.Domain.Location.Location(UnLocodeHelpers.GetNewUnLocode(), "HONGKONG"); _newYork = new BookingApi.Domain.Location.Location(UnLocodeHelpers.GetNewUnLocode(), "NEW YORK"); _helsinki = new BookingApi.Domain.Location.Location(UnLocodeHelpers.GetNewUnLocode(), "HELSINKI"); _chicago = new BookingApi.Domain.Location.Location(UnLocodeHelpers.GetNewUnLocode(), "CHICAGO"); _hambourg = new BookingApi.Domain.Location.Location(UnLocodeHelpers.GetNewUnLocode(), "HAMBOURG"); var routeSpecification = new RouteSpecification(_hongkong, _newYork, DateTime.Now); _cargo = new BookingApi.Domain.Cargo.Cargo(trackingId, routeSpecification); _voyage = new VoyageBuilder(new VoyageNumber("X25"), _hongkong) .AddMovement(_newYork, DateTime.Now, DateTime.Now) .Build(); _voyage2 = new VoyageBuilder(new VoyageNumber("CM004"), _newYork) .AddMovement(_chicago, DateTime.Now, DateTime.Now) .Build(); _voyage3 = new VoyageBuilder(new VoyageNumber("CM005"), _chicago) .AddMovement(_hambourg, DateTime.Now, DateTime.Now) .Build(); }
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 firstOrDefaultLeg = itinerary.Legs.FirstOrDefault(x => x.LoadLocation == LastEvent.Location); return firstOrDefaultLeg != null ? new HandlingActivity(HandlingEventType.Unload, firstOrDefaultLeg.UnloadLocation, firstOrDefaultLeg.Voyage) : 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, firstLeg.Voyage); default: return null; } }
private bool CalculateUnloadedAtDestination(RouteSpecification specification) { return LastEvent != null && LastEvent.EventType == HandlingEventType.Unload && specification.Destination == LastEvent.Location; }
private Delivery(HandlingEvent lastHandlingEvent, Itinerary itinerary, RouteSpecification specification) { _calculatedAt = DateTime.Now; _lastEvent = lastHandlingEvent; _misdirected = CalculateMisdirectionStatus(itinerary); _routingStatus = CalculateRoutingStatus(itinerary, specification); _transportStatus = CalculateTransportStatus(); _lastKnownLocation = CalculateLastKnownLocation(); _currentVoyage = CalculateCurrentVoyage(); _eta = CalculateEta(itinerary); _nextExpectedActivity = CalculateNextExpectedActivity(specification, itinerary); _isUnloadedAtDestination = CalculateUnloadedAtDestination(specification); }
/// <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("Route specification is required.", "routeSpecification"); return new Delivery(_lastEvent, itinerary, routeSpecification); }
/// <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="handlingHistory">Delivery history.</param> /// <returns>Delivery status description.</returns> public static Delivery DerivedFrom(RouteSpecification specification, Itinerary itinerary, HandlingHistory handlingHistory) { if (specification == null) throw new ArgumentNullException("specification", "Route specification is required"); if (handlingHistory == null) throw new ArgumentNullException("handlingHistory", "Handling history is required"); var lastHandlingEvent = handlingHistory.MostRecentlyCompletedEvent; return new Delivery(lastHandlingEvent, itinerary, specification); }
/// <summary> /// Specifies a new route for this cargo. /// </summary> /// <param name="routeSpecification">Route specification.</param> public virtual void SpecifyNewRoute(RouteSpecification routeSpecification) { if (routeSpecification == null) throw new ArgumentNullException("routeSpecification", "Route specification is required"); RouteSpecification = routeSpecification; // Handling consistency within the Cargo aggregate synchronously Delivery = Delivery.UpdateOnRouting(RouteSpecification, Itinerary); }
public void should_construct_correctly_cargo() { var trackingId = new TrackingId("XYZ"); var arrivalDeadline = new DateTime(2009, 3, 13); var routeSpecification = new RouteSpecification(_stockholm, _melbourne, arrivalDeadline); var cargo = new BookingApi.Domain.Cargo.Cargo(trackingId, routeSpecification); Assert.Equal(RoutingStatus.NotRouted, cargo.Delivery.RoutingStatus); Assert.Equal(TransportStatus.NotReceived, cargo.Delivery.TransportStatus); Assert.Equal(BookingApi.Domain.Location.Location.Unknown, cargo.Delivery.LastKnownLocation); Assert.Equal(BookingApi.Domain.Voyage.Voyage.Empty, cargo.Delivery.CurrentVoyage); }
public void should_pass_equality() { var spec1 = new RouteSpecification(_stockholm, _hongkong, DateTime.Now); var spec2 = new RouteSpecification(_stockholm, _melbourne, DateTime.Now); var cargo1 = new BookingApi.Domain.Cargo.Cargo(new TrackingId("ABC"), spec1); var cargo2 = new BookingApi.Domain.Cargo.Cargo(new TrackingId("CBA"), spec1); var cargo3 = new BookingApi.Domain.Cargo.Cargo(new TrackingId("ABC"), spec2); var cargo4 = new BookingApi.Domain.Cargo.Cargo(new TrackingId("ABC"), spec1); Assert.True(cargo1.Equals(cargo4)); Assert.True(cargo1.Equals(cargo3)); Assert.True(cargo3.Equals(cargo4)); Assert.False(cargo1.Equals(cargo2)); }