Exemplo n.º 1
0
        public void TestCurrentLocationUnloadEvent()
        {
            var ev = new HandlingEvent(cargo, new DateTime(), new DateTime(), HandlingType.UNLOAD,
                                                 SampleLocations.HAMBURG, SampleVoyages.CM004);

            Assert.AreEqual(SampleLocations.HAMBURG, ev.Location);
        }
Exemplo n.º 2
0
        public void TestCurrentLocationReceivedEvent()
        {
            var ev = new HandlingEvent(cargo, new DateTime(), new DateTime(), HandlingType.RECEIVE,
                                                 SampleLocations.CHICAGO);

            Assert.AreEqual(SampleLocations.CHICAGO, ev.Location);
        }
Exemplo n.º 3
0
        public void testNewWithCarrierMovement()
        {
            HandlingEvent e1 = new HandlingEvent(cargo,
                DateTime.Now,
                DateTime.Now,
                HandlingActivityType.LOAD,
                L.HONGKONG,
                SampleVoyages.continental1,
                new OperatorCode("ABCDE"));
            Assert.AreEqual(L.HONGKONG, e1.Location);

            HandlingEvent e2 = new HandlingEvent(cargo,
                DateTime.Now,
                DateTime.Now,
                HandlingActivityType.UNLOAD,
                L.NEWYORK,
                SampleVoyages.continental1,
                new OperatorCode("ABCDE"));
            Assert.AreEqual(L.NEWYORK, e2.Location);

            // These event types prohibit a carrier movement association
            foreach(
                HandlingActivityType type in
                    new[] {HandlingActivityType.CLAIM, HandlingActivityType.RECEIVE, HandlingActivityType.CUSTOMS})
            {
                try
                {
                    new HandlingEvent(cargo,
                        DateTime.Now,
                        DateTime.Now,
                        type,
                        L.HONGKONG,
                        SampleVoyages.continental1,
                        new OperatorCode("ABCDE"));
                    Assert.Fail("Handling event type " + type + " prohibits carrier movement");
                }
                catch(ArgumentException expected)
                {
                }
            }

            // These event types requires a carrier movement association
            foreach(HandlingActivityType type in new[] {HandlingActivityType.LOAD, HandlingActivityType.UNLOAD})
            {
                try
                {
                    new HandlingEvent(cargo,
                        DateTime.Now,
                        DateTime.Now,
                        type,
                        L.HONGKONG,
                        null,
                        new OperatorCode("ABCDE"));
                    Assert.Fail("Handling event type " + type + " requires carrier movement");
                }
                catch(ArgumentException expected)
                {
                }
            }
        }
        public void Save()
        {
            //TODO:atrosin make the method transaction  

            Location location = locationRepository.Find(new UnLocode("SESTO"));

            Cargo cargo = cargoRepository.Find(new TrackingId("XYZ"));
            var completionTime = new DateTime(2008, 2, 2);
            var registrationTime = new DateTime(2008, 3, 3);
            var evnt = new HandlingEvent(cargo, completionTime, registrationTime, HandlingType.CLAIM, location);

            handlingEventRepository.Store(evnt);

            Flush();

            IList list = GetPlainHandlingEventListFromDb(evnt);

            Assert.IsNotNull(list, "The object is not inserted");
            Assert.AreEqual(list.Count, 4, "The number of retrivied objects is not as expected");
            Assert.AreEqual(1, list[0] /*CARGO_ID*/);
            Assert.AreEqual(completionTime, list[1] /*COMPLETIONTIME*/);
            Assert.AreEqual(registrationTime, list[2] /*REGISTRATIONTIME*/);
            Assert.AreEqual("CLAIM", list[3] /*TYPE*/);
            // TODO: the rest of the columns
        }
Exemplo n.º 5
0
 /// <summary>
 /// Checks whether provided event is expected according to this itinerary specification.
 /// </summary>
 /// <param name="event">A handling event.</param>
 /// <returns>True, if it is expected. Otherwise - false. If itinerary is empty, returns false.</returns>
 public virtual bool IsExpected(HandlingEvent @event)
 {
    if (IsEmpty)
    {
       return false;
    }
    if (@event.EventType == HandlingEventType.Receive)
    {
       Leg firstLeg = _legs.First();
       return firstLeg.LoadLocation == @event.Location;
    }
    if (@event.EventType == HandlingEventType.Claim)
    {
       Leg lastLeg = _legs.Last();
       return lastLeg.UnloadLocation == @event.Location;
    }
    if (@event.EventType == HandlingEventType.Load)
    {
       return _legs.Any(x => x.LoadLocation == @event.Location);            
    }
    if (@event.EventType == HandlingEventType.Unload)
    {
       return _legs.Any(x => x.UnloadLocation == @event.Location);
    }
    //@event.EventType == HandlingEventType.Customs
    return true;
 }
Exemplo n.º 6
0
 private Handling assembleFrom(HandlingEvent handlingEvent)
 {
     Handling handling = new Handling();
     handling.setLocation(handlingEvent.Location.Name);
     handling.setType(handlingEvent.Activity.Type.ToString());
     handling.setVoyage(handlingEvent.Voyage.VoyageNumber.Value);
     return handling;
 }
 private static IList GetPlainHandlingEventListFromDb(HandlingEvent evnt)
 {
     return
         UnitOfWork.CurrentSession.CreateSQLQuery(
             "select CARGO_ID, COMPLETIONTIME, REGISTRATIONTIME, TYPE from HandlingEvent where id = ?")
             .SetInt32(0, GetIntId(evnt))
             .List()[0] as object[];
 }
        public void store(HandlingEvent @event)
        {
            var trackingId = @event.Cargo.TrackingId;
            List<HandlingEvent> list;
            if(eventMap.TryGetValue(trackingId, out list) == false)
                eventMap[trackingId] = list = new List<HandlingEvent>();

            list.Add(@event);
        }
        public void TestCargoOnTrack()
        {
            var trackingId = new TrackingId("CARGO1");
            var routeSpecification = new RouteSpecification(SampleLocations.SHANGHAI,
                                                                           SampleLocations.GOTHENBURG, dateTime);
            var cargo = new Cargo(trackingId, routeSpecification);

            var itinerary = new Itinerary(
                new List<Leg>
                    {
                        new Leg(voyage, SampleLocations.SHANGHAI, SampleLocations.ROTTERDAM, dateTime, dateTime),
                        new Leg(voyage, SampleLocations.ROTTERDAM, SampleLocations.GOTHENBURG, dateTime, dateTime)
                    });

            //Happy path
            var evnt = new HandlingEvent(cargo, dateTime, dateTime, HandlingType.RECEIVE,
                                                   SampleLocations.SHANGHAI);
            Assert.IsTrue(itinerary.IsExpected(evnt));

            evnt = new HandlingEvent(cargo, dateTime, dateTime, HandlingType.LOAD, SampleLocations.SHANGHAI, voyage);
            Assert.IsTrue(itinerary.IsExpected(evnt));

            evnt = new HandlingEvent(cargo, dateTime, dateTime, HandlingType.UNLOAD, SampleLocations.ROTTERDAM, voyage);
            Assert.IsTrue(itinerary.IsExpected(evnt));

            evnt = new HandlingEvent(cargo, dateTime, dateTime, HandlingType.LOAD, SampleLocations.ROTTERDAM, voyage);
            Assert.IsTrue(itinerary.IsExpected(evnt));

            evnt = new HandlingEvent(cargo, dateTime, dateTime, HandlingType.UNLOAD, SampleLocations.GOTHENBURG, voyage);
            Assert.IsTrue(itinerary.IsExpected(evnt));

            evnt = new HandlingEvent(cargo, dateTime, dateTime, HandlingType.CLAIM, SampleLocations.GOTHENBURG);
            Assert.IsTrue(itinerary.IsExpected(evnt));

            //Customs evnt changes nothing
            evnt = new HandlingEvent(cargo, dateTime, dateTime, HandlingType.CUSTOMS, SampleLocations.GOTHENBURG);
            Assert.IsTrue(itinerary.IsExpected(evnt));

            //Received at the wrong location
            evnt = new HandlingEvent(cargo, dateTime, dateTime, HandlingType.RECEIVE, SampleLocations.HANGZOU);
            Assert.IsFalse(itinerary.IsExpected(evnt));

            //Loaded to onto the wrong ship, correct location
            evnt = new HandlingEvent(cargo, dateTime, dateTime, HandlingType.LOAD, SampleLocations.ROTTERDAM,
                                     wrongVoyage);
            Assert.IsFalse(itinerary.IsExpected(evnt));

            //Unloaded from the wrong ship in the wrong location
            evnt = new HandlingEvent(cargo, dateTime, dateTime, HandlingType.UNLOAD, SampleLocations.HELSINKI,
                                     wrongVoyage);
            Assert.IsFalse(itinerary.IsExpected(evnt));

            evnt = new HandlingEvent(cargo, dateTime, dateTime, HandlingType.CLAIM, SampleLocations.ROTTERDAM);
            Assert.IsFalse(itinerary.IsExpected(evnt));
        }
Exemplo n.º 10
0
        public void testMostRecentHandling()
        {
            Cargo         cargo         = CargoRepository.find(new TrackingId("XYZ"));
            HandlingEvent handlingEvent = HandlingEventRepository.mostRecentHandling(cargo);

            Assert.AreEqual(cargo, handlingEvent.Cargo);
            Assert.AreEqual(DateTime.Parse("2007-09-27 04:00"), handlingEvent.CompletionTime);

            Assert.AreEqual(HandlingActivity.ClaimIn(SampleLocations.MELBOURNE), handlingEvent.Activity);
            Assert.AreEqual(handlingEvent.Activity, HandlingActivity.ClaimIn(SampleLocations.MELBOURNE));
        }
Exemplo n.º 11
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));
        }
Exemplo n.º 12
0
 private CargoHandlingEventViewModel BuildHandlingEventViewModel(HandlingEvent handlingEvent)
 {
     return(new CargoHandlingEventViewModel {
         Location = handlingEvent.Location.Name,
         Time = handlingEvent.CompletionTime.ToString("yyyy-MM-dd hh:mm"),
         Type = handlingEvent.Type.ToString(),
         VoyageNumber = handlingEvent.Voyage.VoyageNumber.Value,
         IsExpected = handlingEvent.Cargo.Itinerary.IsExpectedActivity(handlingEvent.Activity),
         Description = GetHandlingEventDescription(handlingEvent),
     });
 }
Exemplo n.º 13
0
        public void IsExpected_ClainEvent_LastLegLocationMathesEventLocation_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.Claim, Wroclaw, DateTime.Now, DateTime.Now);

            Assert.IsTrue(itinerary.IsExpected(@event));
        }
Exemplo n.º 14
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));
        }
Exemplo n.º 15
0
        public object Handle(RegisterHandlingEventCommand command)
        {
            var trackingId = new TrackingId(command.TrackingId);
            var cargo      = _cargoRepository.Find(trackingId);
            var occuranceLocationUnLocode = new UnLocode(command.OccuranceLocation);
            var occuranceLocation         = _locationRepository.Find(occuranceLocationUnLocode);
            var evnt = new HandlingEvent(command.Type, occuranceLocation, DateTime.Now, command.CompletionTime, cargo);

            _handlingEventRepository.Store(evnt);

            return(null);
        }
Exemplo n.º 16
0
        public void testCurrentLocationUnloadEvent()
        {
            HandlingEvent ev = new HandlingEvent(cargo,
                                                 DateTime.Now,
                                                 DateTime.Now,
                                                 HandlingActivityType.UNLOAD,
                                                 L.HAMBURG,
                                                 SampleVoyages.continental2,
                                                 new OperatorCode("ABCDE"));

            Assert.AreEqual(L.HAMBURG, ev.Location);
        }
Exemplo n.º 17
0
        /// <summary>
        ///  Test if the given handling event is expected when executing this itinerary.
        /// </summary>
        /// <param name="handlingEvent">event Event to test.</param>
        /// <returns>true if the event is expected</returns>
        public bool IsExpected(HandlingEvent handlingEvent)
        {
            //TODO: atrosin revise the logic if it is transl corectlly
            if (legs.IsEmpty())
            {
                return(true);
            }

            if (handlingEvent.Type == HandlingType.RECEIVE)
            {
                //Check that the first leg's origin is the event's location
                Leg leg = legs[0];
                return(leg.LoadLocation.Equals(handlingEvent.Location));
            }

            if (handlingEvent.Type == HandlingType.LOAD)
            {
                //Check that the there is one leg with same load location and voyage
                foreach (Leg leg in legs)
                {
                    if (leg.LoadLocation.SameIdentityAs(handlingEvent.Location) &&
                        leg.Voyage.SameIdentityAs(handlingEvent.Voyage))
                    {
                        return(true);
                    }
                }
                return(false);
            }

            if (handlingEvent.Type == HandlingType.UNLOAD)
            {
                //Check that the there is one leg with same unload location and voyage
                foreach (Leg leg in legs)
                {
                    if (leg.UnloadLocation.Equals(handlingEvent.Location) &&
                        leg.Voyage.Equals(handlingEvent.Voyage))
                    {
                        return(true);
                    }
                }
                return(false);
            }

            if (handlingEvent.Type == HandlingType.CLAIM)
            {
                //Check that the last leg's destination is from the event's location
                Leg leg = LastLeg;
                return(leg.UnloadLocation.Equals(handlingEvent.Location));
            }

            //HandlingEvent.Type.CUSTOMS;
            return(true);
        }
        public void store(HandlingEvent @event)
        {
            var trackingId = @event.Cargo.TrackingId;
            List <HandlingEvent> list;

            if (eventMap.TryGetValue(trackingId, out list) == false)
            {
                eventMap[trackingId] = list = new List <HandlingEvent>();
            }

            list.Add(@event);
        }
Exemplo n.º 19
0
        public void Ctor__EventGiven__LastKnownLocationIsSetToTheEventLocation(
            RouteSpecification routeSpec
            , HandlingEvent @event)
        {
            // ARRANGE
            var itinerary = new Fixture().Customize(new DefaultItineraryCustomization()).Create <Itinerary>();

            // ACT
            var sut = new Delivery(routeSpec, itinerary, @event);

            // ASSERT
            Assert.Equal(@event.Location, sut.LastKnownLocation);
        }
Exemplo n.º 20
0
        public void Ctor__RouteSpecNotSatisifiedByItinerary__NextExpectedActivitySetToNone(
            RouteSpecification routeSpec,
            HandlingEvent @event)
        {
            // ARRANGE
            var itinerary = new Fixture().Customize(new DefaultItineraryCustomization()).Create <Itinerary>();

            // ACT
            var sut = new Delivery(routeSpec, itinerary, @event);

            // ASSERT
            Assert.Null(sut.NextExpectedHandlingActivity);
        }
Exemplo n.º 21
0
        public void Ctor__EventWithAVoyageNumber__CurrentVoyageIsSetToEventVoyage(
            RouteSpecification routeSpec
            , HandlingEvent @event)
        {
            // ARRANGE
            var itinerary = new Fixture().Customize(new DefaultItineraryCustomization()).Create <Itinerary>();

            // ACT
            var sut = new Delivery(routeSpec, itinerary, @event);

            // ASSERT
            Assert.Equal(@event.Voyage, sut.CurrentVoyage);
        }
        protected void SetUp()
        {
            cargo = new Cargo(new TrackingId("ABC"), new RouteSpecification(SampleLocations.SHANGHAI, SampleLocations.DALLAS, DateTime.Parse("2009-04-01")));
            voyage = new Voyage.Builder(new VoyageNumber("X25"), SampleLocations.HONGKONG).
              AddMovement(SampleLocations.SHANGHAI, new DateTime(), new DateTime()).
              AddMovement(SampleLocations.DALLAS, new DateTime(), new DateTime()).
              Build();
            event1 = new HandlingEvent(cargo, DateTime.Parse("2009-03-05"), new DateTime(100), HandlingType.LOAD, SampleLocations.SHANGHAI, voyage);
            event1duplicate = new HandlingEvent(cargo, DateTime.Parse("2009-03-05"), new DateTime(200), HandlingType.LOAD, SampleLocations.SHANGHAI, voyage);
            event2 = new HandlingEvent(cargo, DateTime.Parse("2009-03-10"), new DateTime(150), HandlingType.UNLOAD, SampleLocations.DALLAS, voyage);

            handlingHistory = new HandlingHistory(new List<HandlingEvent>{event2, event1, event1duplicate});
        }
Exemplo n.º 23
0
        public void testFindByCargoId()
        {
            TrackingId trackingId = new TrackingId("FGH");
            Cargo      cargo      = cargoRepository.find(trackingId);

            Assert.AreEqual(SampleLocations.HONGKONG, cargo.RouteSpecification.Origin);
            Assert.AreEqual(SampleLocations.HELSINKI, cargo.RouteSpecification.Destination);

            IEnumerable <HandlingEvent> events =
                HandlingEventRepository.lookupHandlingHistoryOfCargo(cargo).distinctEventsByCompletionTime();

            Assert.AreEqual(2, events.Count());

            HandlingEvent firstEvent = events.ElementAt(0);

            assertHandlingEvent(cargo, firstEvent, HandlingActivityType.RECEIVE, SampleLocations.HONGKONG, 100, 160, Voyage.None);

            HandlingEvent secondEvent = events.ElementAt(1);

            Voyage hongkongMelbourneTokyoAndBack =
                new Voyage.Builder(new VoyageNumber("0303"), SampleLocations.HONGKONG).addMovement(SampleLocations.MELBOURNE,
                                                                                                   new DateTime(1),
                                                                                                   new DateTime(2)).addMovement(SampleLocations.TOKYO, new DateTime(3), new DateTime(4)).addMovement(SampleLocations.HONGKONG,
                                                                                                                                                                                                     new DateTime(5),
                                                                                                                                                                                                     new DateTime(6)).build();

            assertHandlingEvent(cargo,
                                secondEvent,
                                HandlingActivityType.LOAD,
                                SampleLocations.HONGKONG,
                                150,
                                110,
                                hongkongMelbourneTokyoAndBack);

            IEnumerable <Leg> legs = cargo.Itinerary.Legs;

            Assert.AreEqual(3, legs.Count());

            Leg firstLeg = legs.ElementAt(0);

            assertLeg(firstLeg, "0101", SampleLocations.HONGKONG, SampleLocations.MELBOURNE);

            Leg secondLeg = legs.ElementAt(1);

            assertLeg(secondLeg, "0101", SampleLocations.MELBOURNE, SampleLocations.STOCKHOLM);

            Leg thirdLeg = legs.ElementAt(2);

            assertLeg(thirdLeg, "0101", SampleLocations.STOCKHOLM, SampleLocations.HELSINKI);
        }
Exemplo n.º 24
0
        public void testMostRecentLoadOrUnload()
        {
            // TODO
            HandlingEvent event3Customs = new HandlingEvent(cargo,
                                                            DateTime.Parse("2009-03-11"),
                                                            DateTime.Parse("2009-03-11"),
                                                            HandlingActivityType.CUSTOMS,
                                                            L.DALLAS);

            handlingHistory = HandlingHistory.fromEvents(new[] { event2, event1, event1duplicate, event3Customs });

            Assert.AreEqual(event3Customs, handlingHistory.mostRecentlyCompletedEvent());
            Assert.AreEqual(event2, handlingHistory.mostRecentPhysicalHandling());
        }
Exemplo n.º 25
0
        // TODO: Generate test data some better way
        private Cargo PopulateCargoReceivedStockholm()
        {
            Cargo cargo = new Cargo(new TrackingId("XYZ"),
                                    new RouteSpecification(SampleLocations.STOCKHOLM, SampleLocations.MELBOURNE,
                                                           DateTime.Now));

            HandlingEvent he = new HandlingEvent(cargo, GetDate("2007-12-01"), DateTime.Now, HandlingType.RECEIVE,
                                                 SampleLocations.STOCKHOLM);

            events.Add(he);
            cargo.DeriveDeliveryProgress(new HandlingHistory(events));

            return(cargo);
        }
Exemplo n.º 26
0
        private Delivery(HandlingEvent lastHandlingEvent, Itinerary itinerary,
                         RouteSpecification specification)
        {
            m_calculatedAt = DateTime.Now;
            m_lastEvent    = lastHandlingEvent;

            m_misdirected       = CalculateMisdirectionStatus(itinerary);
            m_routingStatus     = CalculateRoutingStatus(itinerary, specification);
            m_transportStatus   = CalculateTransportStatus();
            m_lastKnownLocation = CalculateLastKnownLocation();
            m_eta = CalculateEta(itinerary);
            m_nextExpectedActivity    = CalculateNextExpectedActivity(specification, itinerary);
            m_isUnloadedAtDestination = CalculateUnloadedAtDestination(specification);
        }
        public void Store(HandlingEvent evnt)
        {
            TrackingId trackingId = evnt.Cargo.TrackingId;

            List<HandlingEvent> list;
            if (!eventMap.ContainsKey(trackingId))
            {
                list = new List<HandlingEvent>();
                eventMap.Add(trackingId, list);
            }

            list = eventMap[trackingId];

            list.Add(evnt);
        }
Exemplo n.º 28
0
        public void RegisterHandlingEvent__EmitsHandlingEventRegisteredEvent_and_EmitsDeliveryStateChangedEvent(
            Domain.Shipping.Cargo.Cargo sut,
            HandlingEvent @event
            )
        {
            // ACT
            sut.RegisterHandlingEvent(@event);

            // ASSERT
            Assert.Equal(@event, sut.LastHandlingEvent);
            Assert.Equal(@event, sut.Delivery.LastHandlingEvent);

            sut.Events[1].Should().BeEquivalentTo(new Events.HandlingEventRegistered(@event));
            sut.Events[2].Should().BeEquivalentTo(new Events.DeliveryStateChanged(sut.TrackingId, sut.Delivery));
        }
Exemplo n.º 29
0
        protected void SetUp()
        {
            cargo  = new Cargo(new TrackingId("ABC"), new RouteSpecification(SampleLocations.SHANGHAI, SampleLocations.DALLAS, DateTime.Parse("2009-04-01")));
            voyage = new Voyage.Builder(new VoyageNumber("X25"), SampleLocations.HONGKONG).
                     AddMovement(SampleLocations.SHANGHAI, new DateTime(), new DateTime()).
                     AddMovement(SampleLocations.DALLAS, new DateTime(), new DateTime()).
                     Build();
            event1          = new HandlingEvent(cargo, DateTime.Parse("2009-03-05"), new DateTime(100), HandlingType.LOAD, SampleLocations.SHANGHAI, voyage);
            event1duplicate = new HandlingEvent(cargo, DateTime.Parse("2009-03-05"), new DateTime(200), HandlingType.LOAD, SampleLocations.SHANGHAI, voyage);
            event2          = new HandlingEvent(cargo, DateTime.Parse("2009-03-10"), new DateTime(150), HandlingType.UNLOAD, SampleLocations.DALLAS, voyage);

            handlingHistory = new HandlingHistory(new List <HandlingEvent> {
                event2, event1, event1duplicate
            });
        }
Exemplo n.º 30
0
        /// <summary>
        /// Updates delivery progress information according to handling history.
        /// </summary>
        /// <param name="lastHandlingEvent">Most recent handling event.</param>
        public void DeriveDeliveryProgress(HandlingEvent lastHandlingEvent)
        {
            Delivery = Delivery.DerivedFrom(RouteSpecification, Itinerary, lastHandlingEvent);

            if (Delivery.IsMisdirected)
            {
                m_eventAggegator.Publish <CargoWasMisdirectedEvent>(
                    new CargoWasMisdirectedEvent(this));
            }
            else if (Delivery.IsUnloadedAtDestination)
            {
                m_eventAggegator.Publish <CargoHasArrivedEvent>(
                    new CargoHasArrivedEvent(this));
            }
        }
Exemplo n.º 31
0
        /// <summary>
        /// Internal constructor.
        /// </summary>
        /// <param name="lastEvent">last event</param>
        /// <param name="itinerary">itinerary</param>
        /// <param name="routeSpecification">route specification</param>
        private Delivery(HandlingEvent lastEvent, Itinerary itinerary, RouteSpecification routeSpecification)
        {
            NO_ACTIVITY    = null;
            calculatedAt   = DateTime.Now;
            this.lastEvent = lastEvent;

            misdirected       = CalculateMisdirectionStatus(itinerary);
            routingStatus     = CalculateRoutingStatus(itinerary, routeSpecification);
            transportStatus   = CalculateTransportStatus();
            lastKnownLocation = CalculateLastKnownLocation();
            currentVoyage     = CalculateCurrentVoyage();
            eta = CalculateEta(itinerary);
            nextExpectedActivity    = CalculateNextExpectedActivity(routeSpecification, itinerary);
            isUnloadedAtDestination = CalculateUnloadedAtDestination(routeSpecification);
        }
Exemplo n.º 32
0
        public void FindByCargoId()
        {
            TrackingId trackingId = new TrackingId("FGH");
            Cargo      cargo      = cargoRepository.Find(trackingId);

            Assert.AreEqual(SampleLocations.STOCKHOLM, cargo.Origin);
            Assert.AreEqual(SampleLocations.HONGKONG, cargo.RouteSpecification.Origin);
            Assert.AreEqual(SampleLocations.HELSINKI, cargo.RouteSpecification.Destination);

            Assert.IsNotNull(cargo.Delivery);

            IList <HandlingEvent> events =
                handlingEventRepository.LookupHandlingHistoryOfCargo(trackingId).DistinctEventsByCompletionTime();

            Assert.AreEqual(2, events.Count);

            HandlingEvent firstEvent = events[0];

            AssertHandlingEvent(cargo, firstEvent, HandlingType.RECEIVE, SampleLocations.HONGKONG, 100, 160, Voyage.NONE);

            HandlingEvent secondEvent = events[1];

            Voyage hongkongMelbourneTokyoAndBack = new Voyage.Builder(
                new VoyageNumber("0303"), SampleLocations.HONGKONG).
                                                   AddMovement(SampleLocations.MELBOURNE, new DateTime(), new DateTime()).
                                                   AddMovement(SampleLocations.TOKYO, new DateTime(), new DateTime()).
                                                   AddMovement(SampleLocations.HONGKONG, new DateTime(), new DateTime()).
                                                   Build();

            AssertHandlingEvent(cargo, secondEvent, HandlingType.LOAD, SampleLocations.HONGKONG, 150, 110,
                                hongkongMelbourneTokyoAndBack);

            IList <Leg> legs = cargo.Itinerary.Legs;

            Assert.AreEqual(3, legs.Count);

            Leg firstLeg = legs[0];

            AssertLeg(firstLeg, "0101", SampleLocations.HONGKONG, SampleLocations.MELBOURNE);

            Leg secondLeg = legs[1];

            AssertLeg(secondLeg, "0101", SampleLocations.MELBOURNE, SampleLocations.STOCKHOLM);

            Leg thirdLeg = legs[2];

            AssertLeg(thirdLeg, "0101", SampleLocations.STOCKHOLM, SampleLocations.HELSINKI);
        }
        private void AssertHandlingEvent(Cargo cargo, HandlingEvent evnt, HandlingType expectedEventType,
                                         Location expectedLocation, int completionTimeMs, int registrationTimeMs,
                                         Voyage voyage)
        {
            Assert.AreEqual(expectedEventType, evnt.Type);
            Assert.AreEqual(expectedLocation, evnt.Location);

            DateTime expectedCompletionTime = SampleDataGenerator.Offset(completionTimeMs);
            Assert.AreEqual(expectedCompletionTime, evnt.CompletionTime);

            DateTime expectedRegistrationTime = SampleDataGenerator.Offset(registrationTimeMs);
            Assert.AreEqual(expectedRegistrationTime, evnt.RegistrationTime);

            Assert.AreEqual(voyage, evnt.Voyage);
            Assert.AreEqual(cargo, evnt.Cargo);
        }
Exemplo n.º 34
0
        public void Store(HandlingEvent evnt)
        {
            TrackingId trackingId = evnt.Cargo.trackingId;

            List <HandlingEvent> list;

            if (!eventMap.ContainsKey(trackingId))
            {
                list = new List <HandlingEvent>();
                eventMap.Add(trackingId, list);
            }

            list = eventMap[trackingId];

            list.Add(evnt);
        }
        public void TestCreateHandlingEventWithoutCarrierMovement()
        {
            cargoRepositoryMock.Setup(rep => rep.Find(trackingId)).Returns(cargo);


            UnLocode      unLocode       = SampleLocations.STOCKHOLM.UnLocode;
            DateTime      completionTime = DateTime.Now.AddDays(10);
            HandlingEvent handlingEvent  = factory.CreateHandlingEvent(
                DateTime.Now, completionTime, trackingId, null, unLocode, HandlingType.CLAIM
                );

            Assert.IsNotNull(handlingEvent);
            Assert.AreEqual(SampleLocations.STOCKHOLM, handlingEvent.Location);
            Assert.AreEqual(Voyage.NONE, handlingEvent.Voyage);
            Assert.AreEqual(cargo, handlingEvent.Cargo);
            Assert.AreEqual(completionTime, handlingEvent.CompletionTime);
            Assert.IsTrue(handlingEvent.RegistrationTime.Before(DateTime.Now.AddMinutes(1)));
        }
Exemplo n.º 36
0
        private void AssertHandlingEvent(Cargo cargo, HandlingEvent evnt, HandlingType expectedEventType,
                                         Location expectedLocation, int completionTimeMs, int registrationTimeMs,
                                         Voyage voyage)
        {
            Assert.AreEqual(expectedEventType, evnt.Type);
            Assert.AreEqual(expectedLocation, evnt.Location);

            DateTime expectedCompletionTime = SampleDataGenerator.Offset(completionTimeMs);

            Assert.AreEqual(expectedCompletionTime, evnt.CompletionTime);

            DateTime expectedRegistrationTime = SampleDataGenerator.Offset(registrationTimeMs);

            Assert.AreEqual(expectedRegistrationTime, evnt.RegistrationTime);

            Assert.AreEqual(voyage, evnt.Voyage);
            Assert.AreEqual(cargo, evnt.Cargo);
        }
Exemplo n.º 37
0
        public void HandlingHistoryWithSamePropertiesShouldBeSame()
        {
            DateTime now = DateTime.Now;
            var handlingEvent1 = new HandlingEvent(new TrackingId("CARGO_ABC123"),
                                                   now,
                                                   now,
                                                   HandlingActivityType.Load,
                                                   Location.Location.HongKong,
                                                   new VoyageNumber("ABC"),
                                                   new OperatorCode("PAUL RAYNER"));

            var handlingEvent2 = new HandlingEvent(new TrackingId("CARGO_ABC123"),
                                                   now,
                                                   now,
                                                   HandlingActivityType.Load,
                                                   Location.Location.HongKong,
                                                   new VoyageNumber("ABC"),
                                                   new OperatorCode("PAUL RAYNER"));
        }
Exemplo n.º 38
0
        public void TestEqualsAndSameAs()
        {
            var timeOccured = new DateTime();
            var timeRegistered = new DateTime();

            var ev1 = new HandlingEvent(cargo, timeOccured, timeRegistered, HandlingType.LOAD, SampleLocations.CHICAGO,
                                                  SampleVoyages.CM005);
            var ev2 = new HandlingEvent(cargo, timeOccured, timeRegistered, HandlingType.LOAD, SampleLocations.CHICAGO,
                                                  SampleVoyages.CM005);

            // Two handling events are not equal() even if all non-uuid fields are identical
            Assert.IsTrue(ev1.Equals(ev2));
            Assert.IsTrue(ev2.Equals(ev1));

            Assert.IsTrue(ev1.Equals(ev1));

            Assert.IsFalse(ev2.Equals(null));
            Assert.IsFalse(ev2.Equals(new Object()));
        }
        public void testCreateHandlingEventWithoutCarrierMovement()
        {
            cargoRepository.Expect(c => c.find(trackingId)).Return(cargo);

            UnLocode      unLocode      = L.STOCKHOLM.UnLocode;
            HandlingEvent handlingEvent = factory.createHandlingEvent(new DateTime(100),
                                                                      trackingId,
                                                                      null,
                                                                      unLocode,
                                                                      HandlingActivityType.CLAIM,
                                                                      new OperatorCode("ABCDE"));

            Assert.IsNotNull(handlingEvent);
            Assert.AreEqual(L.STOCKHOLM, handlingEvent.Location);
            Assert.AreEqual(Voyage.None, handlingEvent.Voyage);
            Assert.AreEqual(cargo, handlingEvent.Cargo);
            Assert.AreEqual(new DateTime(100), handlingEvent.CompletionTime);
            Assert.True(handlingEvent.RegistrationTime < DateTime.Now.AddMilliseconds(1));
        }
Exemplo n.º 40
0
        public void TestEqualsAndSameAs()
        {
            var timeOccured    = new DateTime();
            var timeRegistered = new DateTime();

            var ev1 = new HandlingEvent(cargo, timeOccured, timeRegistered, HandlingType.LOAD, SampleLocations.CHICAGO,
                                        SampleVoyages.CM005);
            var ev2 = new HandlingEvent(cargo, timeOccured, timeRegistered, HandlingType.LOAD, SampleLocations.CHICAGO,
                                        SampleVoyages.CM005);

            // Two handling events are not equal() even if all non-uuid fields are identical
            Assert.IsTrue(ev1.Equals(ev2));
            Assert.IsTrue(ev2.Equals(ev1));

            Assert.IsTrue(ev1.Equals(ev1));

            Assert.IsFalse(ev2.Equals(null));
            Assert.IsFalse(ev2.Equals(new Object()));
        }
Exemplo n.º 41
0
        protected void setUp()
        {
            cargo = new Cargo(new TrackingId("ABC"),
                              new RouteSpecification(L.SHANGHAI, L.DALLAS, DateTime.Parse("2009-04-01")));
            cargo2 = new Cargo(new TrackingId("DEF"),
                               new RouteSpecification(L.SHANGHAI, L.NEWYORK, DateTime.Parse("2009-04-15")));

            voyage =
                new Voyage.Builder(new VoyageNumber("X25"), L.HONGKONG).addMovement(L.SHANGHAI,
                                                                                    new DateTime(1),
                                                                                    new DateTime(2)).addMovement(L.DALLAS, new DateTime(3), new DateTime(4)).build();
            event1 = new HandlingEvent(cargo,
                                       DateTime.Parse("2009-03-05"),
                                       DateTime.Parse("2009-03-05"),
                                       HandlingActivityType.LOAD,
                                       L.SHANGHAI,
                                       voyage,
                                       new OperatorCode("ABCDE"));
            event1duplicate = new HandlingEvent(cargo,
                                                DateTime.Parse("2009-03-05"),
                                                DateTime.Parse("2009-03-07"),
                                                HandlingActivityType.LOAD,
                                                L.SHANGHAI,
                                                voyage,
                                                new OperatorCode("ABCDE"));
            event2 = new HandlingEvent(cargo,
                                       DateTime.Parse("2009-03-10"),
                                       DateTime.Parse("2009-03-06"),
                                       HandlingActivityType.UNLOAD,
                                       L.DALLAS,
                                       voyage,
                                       new OperatorCode("ABCDE"));
            eventOfCargo2 = new HandlingEvent(cargo2,
                                              DateTime.Parse("2009-03-11"),
                                              DateTime.Parse("2009-03-08"),
                                              HandlingActivityType.LOAD,
                                              L.GOTHENBURG,
                                              voyage,
                                              new OperatorCode("ABCDE"));
        }
Exemplo n.º 42
0
        protected void setUp()
        {
            cargo = new Cargo(new TrackingId("ABC"),
                new RouteSpecification(L.SHANGHAI, L.DALLAS, DateTime.Parse("2009-04-01")));
            cargo2 = new Cargo(new TrackingId("DEF"),
                new RouteSpecification(L.SHANGHAI, L.NEWYORK, DateTime.Parse("2009-04-15")));

            voyage =
                new Voyage.Builder(new VoyageNumber("X25"), L.HONGKONG).addMovement(L.SHANGHAI,
                    new DateTime(1),
                    new DateTime(2)).addMovement(L.DALLAS, new DateTime(3), new DateTime(4)).build();
            event1 = new HandlingEvent(cargo,
                DateTime.Parse("2009-03-05"),
                DateTime.Parse("2009-03-05"),
                HandlingActivityType.LOAD,
                L.SHANGHAI,
                voyage,
                new OperatorCode("ABCDE"));
            event1duplicate = new HandlingEvent(cargo,
                DateTime.Parse("2009-03-05"),
                DateTime.Parse("2009-03-07"),
                HandlingActivityType.LOAD,
                L.SHANGHAI,
                voyage,
                new OperatorCode("ABCDE"));
            event2 = new HandlingEvent(cargo,
                DateTime.Parse("2009-03-10"),
                DateTime.Parse("2009-03-06"),
                HandlingActivityType.UNLOAD,
                L.DALLAS,
                voyage,
                new OperatorCode("ABCDE"));
            eventOfCargo2 = new HandlingEvent(cargo2,
                DateTime.Parse("2009-03-11"),
                DateTime.Parse("2009-03-08"),
                HandlingActivityType.LOAD,
                L.GOTHENBURG,
                voyage,
                new OperatorCode("ABCDE"));
        }
Exemplo n.º 43
0
        public void TestNewWithCarrierMovement()
        {
            var e1 = new HandlingEvent(cargo, new DateTime(), new DateTime(), HandlingType.LOAD, SampleLocations.HONGKONG, SampleVoyages.CM003);

            Assert.AreEqual(SampleLocations.HONGKONG, e1.Location);

            var e2 = new HandlingEvent(cargo, new DateTime(), new DateTime(), HandlingType.UNLOAD, SampleLocations.NEWYORK, SampleVoyages.CM003);

            Assert.AreEqual(SampleLocations.NEWYORK, e2.Location);

            // These event types prohibit a carrier movement association
            foreach (var type in new List <HandlingType> {
                HandlingType.CLAIM, HandlingType.RECEIVE, HandlingType.CUSTOMS
            })
            {
                try
                {
                    new HandlingEvent(cargo, new DateTime(), new DateTime(), type, SampleLocations.HONGKONG, SampleVoyages.CM003);
                }
                catch (Exception)
                {
                    Assert.Fail("Handling event type " + type + " prohibits carrier movement");
                }
            }

            // These event types requires a carrier movement association
            foreach (var type in new List <HandlingType> {
                HandlingType.LOAD, HandlingType.UNLOAD
            })
            {
                try
                {
                    new HandlingEvent(cargo, new DateTime(), new DateTime(), type, SampleLocations.HONGKONG, null);
                }
                catch (Exception)
                {
                    Assert.Fail("Handling event type " + type + " requires carrier movement");
                }
            }
        }
 public void CargoWasHandled(HandlingEvent evnt)
 {
     System.Console.WriteLine("EVENT: cargo was handled: " + evnt);
     cargoInspectionService.InspectCargo(evnt.Cargo.TrackingId);
 }
 public HandlingEventViewAdapter(HandlingEvent handlingEvent, Cargo cargo)
 {
    _handlingEvent = handlingEvent;
    _cargo = cargo;
 }
Exemplo n.º 46
0
 public void notifyOfHandlingEvent(HandlingEvent @event)
 {
     var cargo = @event.Cargo;
     nmsOperations.SendWithDelegate(cargoHandledDestination, s => s.CreateObjectMessage(cargo.TrackingId));
 }
Exemplo n.º 47
0
 /// <summary>
 /// Updates delivery progress information according to handling history.
 /// </summary>
 /// <param name="lastHandlingEvent">Most recent handling event.</param>
 public virtual void DeriveDeliveryProgress(HandlingEvent lastHandlingEvent)
 {
     Delivery = Delivery.DerivedFrom(RouteSpecification, Itinerary, lastHandlingEvent);
 }
Exemplo n.º 48
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;
            }
        }
Exemplo n.º 49
0
 private static bool CalculateUnloadedAtDestination(HandlingEvent lastEvent, RouteSpecification specification)
 {
     return lastEvent != null &&
              lastEvent.EventType == HandlingEventType.Unload &&
              specification.Destination == lastEvent.Location;
 }
Exemplo n.º 50
0
 private static Location.Location CalculateLastKnownLocation(HandlingEvent lastEvent)
 {
     return lastEvent != null ? lastEvent.Location : null;
 }
Exemplo n.º 51
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);
 }
Exemplo n.º 52
0
 private static bool CalculateMisdirectionStatus(HandlingEvent lastEvent, Itinerary itinerary)
 {
     if (lastEvent == null)
     {
         return false;
     }
     return !itinerary.IsExpected(lastEvent);
 }
Exemplo n.º 53
0
 private CargoHandlingEventViewModel BuildHandlingEventViewModel(HandlingEvent handlingEvent)
 {
     return new CargoHandlingEventViewModel {
         Location = handlingEvent.Location.Name,
         Time = handlingEvent.CompletionTime.ToString("yyyy-MM-dd hh:mm"),
         Type = handlingEvent.Type.ToString(),
         VoyageNumber = handlingEvent.Voyage.VoyageNumber.Value,
         IsExpected = handlingEvent.Cargo.Itinerary.IsExpectedActivity(handlingEvent.Activity),
         Description = GetHandlingEventDescription(handlingEvent),                
     };
 }
Exemplo n.º 54
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);
        }
Exemplo n.º 55
0
        private string GetHandlingEventDescription(HandlingEvent handlingEvent)
        {
            switch(handlingEvent.Type)
            {
                case HandlingActivityType.LOAD:
                    return String.Format("Loaded onto voyage {0} in {1}, at {2}.", 
                        handlingEvent.Voyage.VoyageNumber.Value,
                        handlingEvent.Location.Name,
                        handlingEvent.CompletionTime.ToShortTimeString());

                case HandlingActivityType.UNLOAD:
                    return String.Format("Unloaded off voyage {0} in {1}, at {2}.",
                        handlingEvent.Voyage.VoyageNumber.Value,
                        handlingEvent.Location.Name,
                        handlingEvent.CompletionTime.ToShortTimeString());

                case HandlingActivityType.RECEIVE:
                    return String.Format("Received in {0}, at {1}.",
                        handlingEvent.Location.Name,
                        handlingEvent.CompletionTime.ToShortTimeString());

                case HandlingActivityType.CLAIM:
                    return String.Format("Claimed in {0}, at {1}.",
                        handlingEvent.Location.Name,
                        handlingEvent.CompletionTime.ToShortTimeString());

                case HandlingActivityType.CUSTOMS:
                    return String.Format("Cleared customs in {0}, at {1}.",
                        handlingEvent.Location.Name,
                        handlingEvent.CompletionTime.ToShortTimeString());

                default:
                    return "Cargo has not yet been received.";
            }
        }
 public void Store(HandlingEvent handlingEvent)
 {
     Session.Save(handlingEvent);
 }
Exemplo n.º 57
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="handlingEvent"> handling event</param>
 /// <param name="cargo">Cargo</param>
 public HandlingEventViewAdapter(HandlingEvent handlingEvent, Cargo cargo)
 {
     this.handlingEvent = handlingEvent;
     this.cargo         = cargo;
 }
Exemplo n.º 58
0
 public void TestNewWithLocation()
 {
     var e1 = new HandlingEvent(cargo, new DateTime(), new DateTime(), HandlingType.CLAIM, SampleLocations.HELSINKI);
     Assert.AreEqual(SampleLocations.HELSINKI, e1.Location);
 }
Exemplo n.º 59
0
        public void TestNewWithCarrierMovement()
        {
            var e1 = new HandlingEvent(cargo, new DateTime(), new DateTime(), HandlingType.LOAD, SampleLocations.HONGKONG, SampleVoyages.CM003);
            Assert.AreEqual(SampleLocations.HONGKONG, e1.Location);

            var e2 = new HandlingEvent(cargo, new DateTime(), new DateTime(), HandlingType.UNLOAD, SampleLocations.NEWYORK, SampleVoyages.CM003);
            Assert.AreEqual(SampleLocations.NEWYORK, e2.Location);

            // These event types prohibit a carrier movement association
            foreach (var type in new List<HandlingType>{HandlingType.CLAIM,HandlingType.RECEIVE,HandlingType.CUSTOMS})
            {
                try
                {
                    new HandlingEvent(cargo, new DateTime(), new DateTime(), type, SampleLocations.HONGKONG, SampleVoyages.CM003);
                }
                catch (Exception)
                {
                    Assert.Fail("Handling event type " + type + " prohibits carrier movement");
                }
            }

            // These event types requires a carrier movement association
            foreach (var type in new List<HandlingType> { HandlingType.LOAD, HandlingType.UNLOAD })
            {
                try
                {
                    new HandlingEvent(cargo, new DateTime(), new DateTime(), type, SampleLocations.HONGKONG, null);
                }
                catch (Exception)
                {
                    Assert.Fail("Handling event type " + type + " requires carrier movement");
                }
            }
        }
Exemplo n.º 60
0
        private static TransportStatus CalculateTransportStatus(HandlingEvent lastEvent)
        {
            if (lastEvent == null)
            {
                return TransportStatus.NotReceived;
            }

            switch (lastEvent.EventType)
            {
                case HandlingEventType.Load:
                    return TransportStatus.OnboardCarrier;
                case HandlingEventType.Unload:
                case HandlingEventType.Receive:
                case HandlingEventType.Customs:
                    return TransportStatus.InPort;
                case HandlingEventType.Claim:
                    return TransportStatus.Claimed;
                default:
                    return TransportStatus.Unknown;
            }
        }