// rehydration ctor public Cargo(TrackingId trackingId, RouteSpecification routeSpec, Itinerary itinerary, Delivery delivery, HandlingEvent lastHandlingEvent) { TrackingId = trackingId; RouteSpec = routeSpec; Itinerary = itinerary; LastHandlingEvent = lastHandlingEvent; Delivery = new Delivery(RouteSpec, Itinerary, LastHandlingEvent); }
public void ChangeRoute(RouteSpecification routeSpec) { RouteSpec = routeSpec ?? throw new ArgumentNullException(nameof(routeSpec)); Delivery = new Delivery(RouteSpec, Itinerary, LastHandlingEvent); this.Events.Add(new RouteChanged(TrackingId, RouteSpec)); this.Events.Add(new DeliveryStateChanged(TrackingId, Delivery)); }
public Cargo(TrackingId trackingId, RouteSpecification routeSpec) { TrackingId = trackingId ?? throw new ArgumentNullException(nameof(trackingId)); RouteSpec = routeSpec ?? throw new ArgumentNullException(nameof(routeSpec)); Delivery = new Delivery(RouteSpec, null, null); this.Events.Add(new NewBooked(trackingId, routeSpec)); }
private void _calcIsUnloadedAtDestination(RouteSpecification routeSpec, HandlingEvent @event) { if (@event == null) { IsUnloadedAtDestination = false; } else { IsUnloadedAtDestination = routeSpec.Destination.Equals(@event.Location); } }
public void IsSatisfiedBy__OriginGivenIsDifferentThanItineraryFirstLoadingLocation__ReturnsFalse( RouteSpecification sut ) { // ARRANGE // NOTE: relying on A/F to create different locations as the RouteSpecification's Origin and the Itinerary's First Loading Location var itinerary = new Fixture().Customize(new DefaultItineraryCustomization()).Create <Itinerary>(); // ACT var r = sut.IsSatisfiedBy(itinerary); // ASSERT Assert.False(r); }
private void _calcRoutingStatus(RouteSpecification routeSpec, Itinerary itinerary) { if (itinerary == null) { RoutingStatus = RoutingStatus.NotRouted; } else if (routeSpec.IsSatisfiedBy(itinerary)) { RoutingStatus = RoutingStatus.Routed; } else { RoutingStatus = RoutingStatus.MisRouted; } }
public void IsSatisfiedBy__DestinationGivenIsDifferentThanItineraryLastUnLoadingLocation__ReturnFalse( RouteSpecification sut ) { // ARRANGE var itineraryFixture = new Fixture(); itineraryFixture.Customize(new DefaultLegCustomization()); // RouteSpecification's Origin given is the same as Itinerary's First Loading Location itineraryFixture.Customizations.Add(new LegCollectionBuilder(new [] { sut.Origin })); var itinerary = itineraryFixture.Create <Itinerary>(); // ACT var r = sut.IsSatisfiedBy(itinerary); // ASSERT Assert.False(r); }
public Delivery( RouteSpecification routeSpec, Itinerary itinerary, HandlingEvent lastHandlingEvent ) { RouteSpec = routeSpec ?? throw new ArgumentNullException(nameof(routeSpec)); Itinerary = itinerary; LastHandlingEvent = lastHandlingEvent; _calcTransportStatus(lastHandlingEvent); _calcLastKnownLocation(lastHandlingEvent); _calcCurrentVoyage(lastHandlingEvent); _calcNextExpectedHandlingActivity(routeSpec, itinerary, lastHandlingEvent); _calcIsUnloadedAtDestination(routeSpec, lastHandlingEvent); _calcRoutingStatus(routeSpec, itinerary); _calcIsMishandled(itinerary, lastHandlingEvent); }
private void _calcNextExpectedHandlingActivity(RouteSpecification routeSpec, Itinerary itinerary, HandlingEvent @event) { // can't derive next handling activity if there is no itinerary if (itinerary == null) { NextExpectedHandlingActivity = null; return; } // can't derive the next handling activity if the cargo is misrouted _calcRoutingStatus(routeSpec, itinerary); if (RoutingStatus == RoutingStatus.MisRouted) { NextExpectedHandlingActivity = null; return; } // no handling event so far; next one should be receive at itinerary's first leg unload location if (@event == null) { NextExpectedHandlingActivity = new HandlingActivity(HandlingType.Receive, itinerary.FirstLoadLocation, null); return; } switch (@event.Type) { // last handling event = received => next handling activity = load at itinerary's first leg unload location and voyage case HandlingType.Receive: NextExpectedHandlingActivity = new HandlingActivity(HandlingType.Load, itinerary.FirstLoadLocation, itinerary.FirstYoyage); return; // last handling event = load => next handling activity = unload at itinerary's next leg unload location case HandlingType.Load: var leg = itinerary.Of(@event.Location); NextExpectedHandlingActivity = new HandlingActivity(HandlingType.Unload, leg.UnloadLocation, leg.Voyage); return; // last handling event = unload => next handling activity = // a. load at itinerary's next leg load location and voyage, if that leg is not the final one // b. customs at itinerarys's final unload location case HandlingType.Unload: if (@event.Location.Equals(itinerary.LastUnloadLocation)) { NextExpectedHandlingActivity = new HandlingActivity(HandlingType.Customs, itinerary.LastUnloadLocation, null); return; } var nextLeg = itinerary.NextOf(@event.Location); NextExpectedHandlingActivity = new HandlingActivity(HandlingType.Load, nextLeg.LoadLocation, nextLeg.Voyage); return; // last handling event = customs => next handling activity = claim case HandlingType.Customs: NextExpectedHandlingActivity = new HandlingActivity(HandlingType.Claim, itinerary.LastUnloadLocation, null); return; // last handling event = claim => next handling activity = none case HandlingType.Claim: default: NextExpectedHandlingActivity = null; return; } }