/// <summary>
		/// Checks whether provided event is expected according to this itinerary specification.
		/// Test if the given handling event is expected when executing this itinerary.
		/// </summary>
		/// <param name="event">A handling event.</param>
		/// <returns>True, if it is expected. Otherwise - false.</returns>
		public virtual bool IsExpected(HandlingEvent @event)
		{
			if (IsEmpty)
				return true;

			if (@event.EventType == HandlingEventType.Receive)
			{
				//Check that the first leg's origin is the event's location
				Leg firstLeg = _legs.First();
				return firstLeg.LoadLocation == @event.Location;
			}

			if (@event.EventType == HandlingEventType.Claim)
			{
				//Check that the last leg's destination is from the event's location
				Leg lastLeg = _legs.Last();
				return lastLeg.UnloadLocation == @event.Location;
			}

			if (@event.EventType == HandlingEventType.Load)
			{
				//Check that the there is one leg with same load location and voyage
				return _legs.Any(x => x.LoadLocation == @event.Location && x.Voyage == @event.Voyage);
			}

			if (@event.EventType == HandlingEventType.Unload)
			{
				//Check that the there is one leg with same unload location and voyage
				return _legs.Any(x => x.UnloadLocation == @event.Location && x.Voyage == @event.Voyage);
			}
			
			return true;
		}
        public void should_handle_unloaded_from_the_wrong_ship_wrong_location()
        {
            var handlingEvent = new HandlingEvent(HandlingEventType.Unload, _helsinki, DateTime.Now, DateTime.Now, _cargo, _wrongVoyage);
            Assert.False(_itinerary.IsExpected(handlingEvent));

            handlingEvent = new HandlingEvent(HandlingEventType.Claim, _rotterdam, DateTime.Now, DateTime.Now, _cargo);
            Assert.False(_itinerary.IsExpected(handlingEvent));
        }
        public HandlingHistoryTests()
        {
            var shanghai = new BookingApi.Domain.Location.Location(UnLocodeHelpers.GetNewUnLocode(), "SHANGHAI");
            var dallas = new BookingApi.Domain.Location.Location(UnLocodeHelpers.GetNewUnLocode(), "DALLAS");
            var hongkong = new BookingApi.Domain.Location.Location(UnLocodeHelpers.GetNewUnLocode(), "HONGKONG");

            _cargo = new BookingApi.Domain.Cargo.Cargo(new TrackingId("ABC"), new RouteSpecification(shanghai, dallas, new DateTime(2009, 4, 1)));
            _voyage = new VoyageBuilder(new VoyageNumber("X25"), hongkong)
                                                                        .AddMovement(shanghai, DateTime.Now, DateTime.Now)
                                                                        .AddMovement(dallas, DateTime.Now, DateTime.Now)
                                                                        .Build();

            _handlingEvent1 = new HandlingEvent(HandlingEventType.Load, shanghai, new DateTime(100), new DateTime(2009, 3, 5), _cargo, _voyage);
            _handlingEvent1Duplicate = new HandlingEvent(HandlingEventType.Load, shanghai, new DateTime(200), new DateTime(2009, 3, 5), _cargo, _voyage);
            _handlingEvent2 = new HandlingEvent(HandlingEventType.Unload, dallas, new DateTime(150), new DateTime(2009, 3, 10), _cargo, _voyage);

            _handlingHistory = new HandlingHistory(new List<HandlingEvent> {_handlingEvent2, _handlingEvent1, _handlingEvent1Duplicate});
        }
		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);
		}
        public void should_equal_events()
        {
            var timeOccured = DateTime.Now;
            var timeRegistered = DateTime.Now;

            var e1 = new HandlingEvent(HandlingEventType.Load, _chicago, timeRegistered, timeOccured, _cargo, _voyage3);
            var e2 = new HandlingEvent(HandlingEventType.Load, _chicago, timeRegistered, timeOccured, _cargo, _voyage3);

            Assert.True(e1.Equals(e2));
            Assert.True(e2.Equals(e1));

            Assert.True(e1.Equals(e1));

            Assert.False(e2.Equals(null));
            Assert.False(e2.Equals(new object()));
        }
 public void should_equal_current_location_with_handlingEvent_location_for_unload()
 {
     var e1 = new HandlingEvent(HandlingEventType.Unload, _hambourg, DateTime.Now, DateTime.Now, _cargo, _voyage2);
     Assert.Equal(_hambourg, e1.Location);
 }
 public void should_equal_current_location_with_handlingEvent_location_for_received()
 {
     var e1 = new HandlingEvent(HandlingEventType.Receive, _chicago, DateTime.Now, DateTime.Now, _cargo);
     Assert.Equal(_chicago, e1.Location);
 }
 public void should_equal_location_with_handlingEvent_location_for_claim()
 {
     var e1 = new HandlingEvent(HandlingEventType.Claim, _helsinki, DateTime.Now, DateTime.Now, _cargo);
     Assert.Equal(_helsinki, e1.Location);
 }
        public void should_equal_location_with_handlingEvent_location()
        {
            var e1 = new HandlingEvent(HandlingEventType.Load, _hongkong, DateTime.Now, DateTime.Now, _cargo, _voyage);
            Assert.Equal(_hongkong, e1.Location);

            var e2 = new HandlingEvent(HandlingEventType.Unload, _newYork, DateTime.Now, DateTime.Now, _cargo, _voyage);
            Assert.Equal(_newYork, e2.Location);
        }
        public void should_pass_the_happy_path()
        {
            var handlingEvent = new HandlingEvent(HandlingEventType.Receive, _shanghai, DateTime.Now, DateTime.Now, _cargo);
            Assert.True(_itinerary.IsExpected(handlingEvent));

            handlingEvent = new HandlingEvent(HandlingEventType.Load, _shanghai, DateTime.Now, DateTime.Now, _cargo, _voyage);
            Assert.True(_itinerary.IsExpected(handlingEvent));

            handlingEvent = new HandlingEvent(HandlingEventType.Unload, _rotterdam, DateTime.Now, DateTime.Now, _cargo, _voyage);
            Assert.True(_itinerary.IsExpected(handlingEvent));

            handlingEvent = new HandlingEvent(HandlingEventType.Load, _rotterdam, DateTime.Now, DateTime.Now, _cargo, _voyage);
            Assert.True(_itinerary.IsExpected(handlingEvent));

            handlingEvent = new HandlingEvent(HandlingEventType.Unload, _gothenburg, DateTime.Now, DateTime.Now, _cargo, _voyage);
            Assert.True(_itinerary.IsExpected(handlingEvent));

            handlingEvent = new HandlingEvent(HandlingEventType.Claim, _gothenburg, DateTime.Now, DateTime.Now, _cargo);
            Assert.True(_itinerary.IsExpected(handlingEvent));
        }
 public void should_handle_when_loaded_onto_the_wrong_ship_correct_location()
 {
     var handlingEvent = new HandlingEvent(HandlingEventType.Load, _rotterdam, DateTime.Now, DateTime.Now, _cargo, _wrongVoyage);
     Assert.False(_itinerary.IsExpected(handlingEvent));
 }
 public void should_handle_receive_at_wrong_location()
 {
     var handlingEvent = new HandlingEvent(HandlingEventType.Receive, new BookingApi.Domain.Location.Location(UnLocodeHelpers.GetNewUnLocode(), "HANGZOU"), DateTime.Now, DateTime.Now, _cargo);
     Assert.False(_itinerary.IsExpected(handlingEvent));
 }
 public void should_change_nothing_custom_event()
 {
     var handlingEvent = new HandlingEvent(HandlingEventType.Customs, _gothenburg, DateTime.Now, DateTime.Now, _cargo);
     Assert.True(_itinerary.IsExpected(handlingEvent));
 }