示例#1
0
        public void Equals_01(int index)
        {
            // arrange:
            VoyageNumber     number          = new VoyageNumber("VYGTEST01");
            UnLocode         initialLocation = new UnLocode("DPLOC");
            ICarrierMovement movement        = MockRepository.GenerateStrictMock <ICarrierMovement, IObject>();

            movement.Expect(m => m.DepartureLocation).Return(initialLocation).Repeat.Any();
            ISchedule schedule = MockRepository.GenerateStrictMock <ISchedule>();

            schedule.Expect(s => s.MovementsCount).Return(3).Repeat.Any();
            schedule.Expect(s => s.Equals(schedule)).Return(true).Repeat.Any();
            schedule.Expect(s => s[index]).Return(movement).Repeat.Any();

            // act:
            StoppedVoyage state1 = new StoppedVoyage(number, schedule, index);
            StoppedVoyage state2 = new StoppedVoyage(number, schedule, index);

            // assert:
            Assert.IsFalse(state1.Equals(null));
            Assert.IsTrue(state1.Equals(state1));
            Assert.IsTrue(state1.Equals(state2));
            Assert.IsTrue(state2.Equals(state1));
            Assert.IsTrue(state1.Equals((object)state1));
            Assert.IsTrue(state1.Equals((object)state2));
            Assert.IsTrue(state2.Equals((object)state1));
            Assert.AreEqual(state1.GetHashCode(), state2.GetHashCode());
            schedule.VerifyAllExpectations();
            movement.VerifyAllExpectations();
        }
        /// <summary>
        /// Creates a handling event.
        /// </summary>
        /// <param name="completionTime">when the event was completed, for example finished loading</param>
        /// <param name="trackingId">cargo tracking id</param>
        /// <param name="voyageNumber">voyage number</param>
        /// <param name="unlocode">United Nations Location Code for the location of the event</param>
        /// <param name="type">type of event</param>
        /// <param name="operatorCode">operator code</param>
        /// <returns>A handling event.</returns>
        /// <exception cref="UnknownVoyageException">if there's no voyage with this number</exception>
        /// <exception cref="UnknownCargoException">if there's no cargo with this tracking id</exception>
        /// <exception cref="UnknownLocationException">if there's no location with this UN Locode</exception>
        public HandlingEvent createHandlingEvent(DateTime completionTime, TrackingId trackingId,
                                                 VoyageNumber voyageNumber, UnLocode unlocode,
                                                 HandlingActivityType type, OperatorCode operatorCode)
        {
            var cargo = findCargo(trackingId);
            var voyage = findVoyage(voyageNumber);
            var location = findLocation(unlocode);

            try
            {
                var registrationTime = DateTime.Now;
                if(voyage == null)
                {
                    return new HandlingEvent(cargo, completionTime, registrationTime, type, location);
                }
                else
                {
                    return new HandlingEvent(cargo, completionTime, registrationTime, type, location, voyage, operatorCode);
                }
            }
            catch(Exception e)
            {
                throw new CannotCreateHandlingEventException(e.Message, e);
            }
        }
示例#3
0
        public void StopOverAt_aLocation_willNotFireStopped_whenTheStateDontChange()
        {
            // arrange:
            VoyageNumber number   = new VoyageNumber("VYG01");
            ISchedule    schedule = MockRepository.GenerateStrictMock <ISchedule>();
            ILocation    location = MockRepository.GenerateStrictMock <ILocation>();
            VoyageState  state    = MockRepository.GeneratePartialMock <VoyageState>(number, schedule);

            state.Expect(s => s.StopOverAt(location)).Return(state).Repeat.Once();
            state.Expect(s => s.Equals(state)).Return(true).Repeat.Once();
            VoyageEventArgs eventArguments = null;
            IVoyage         eventSender    = null;

            // act:
            IVoyage voyage = MockRepository.GeneratePartialMock <Challenge00.DDDSample.Voyage.Voyage>(state);

            voyage.Stopped += delegate(object sender, VoyageEventArgs e) {
                eventArguments = e;
                eventSender    = sender as IVoyage;
            };
            voyage.StopOverAt(location);

            // assert:
            Assert.AreEqual(number, voyage.Number);
            Assert.IsNull(eventSender);
            Assert.IsNull(eventArguments);
            state.VerifyAllExpectations();
            schedule.VerifyAllExpectations();
            location.VerifyAllExpectations();
        }
 public Voyage find(VoyageNumber voyageNumber)
 {
     return(sessionFactory.GetCurrentSession().
            CreateQuery("from Voyage where VoyageNumber = :vn").
            SetParameter("vn", voyageNumber).
            UniqueResult <Voyage>());
 }
示例#5
0
        /// <summary>
        /// Creates a handling event.
        /// </summary>
        /// <param name="completionTime">when the event was completed, for example finished loading</param>
        /// <param name="trackingId">cargo tracking id</param>
        /// <param name="voyageNumber">voyage number</param>
        /// <param name="unlocode">United Nations Location Code for the location of the event</param>
        /// <param name="type">type of event</param>
        /// <param name="operatorCode">operator code</param>
        /// <returns>A handling event.</returns>
        /// <exception cref="UnknownVoyageException">if there's no voyage with this number</exception>
        /// <exception cref="UnknownCargoException">if there's no cargo with this tracking id</exception>
        /// <exception cref="UnknownLocationException">if there's no location with this UN Locode</exception>
        public HandlingEvent createHandlingEvent(DateTime completionTime, TrackingId trackingId,
                                                 VoyageNumber voyageNumber, UnLocode unlocode,
                                                 HandlingActivityType type, OperatorCode operatorCode)
        {
            var cargo    = findCargo(trackingId);
            var voyage   = findVoyage(voyageNumber);
            var location = findLocation(unlocode);

            try
            {
                var registrationTime = DateTime.Now;
                if (voyage == null)
                {
                    return(new HandlingEvent(cargo, completionTime, registrationTime, type, location));
                }
                else
                {
                    return(new HandlingEvent(cargo, completionTime, registrationTime, type, location, voyage, operatorCode));
                }
            }
            catch (Exception e)
            {
                throw new CannotCreateHandlingEventException(e.Message, e);
            }
        }
示例#6
0
        public void StopOverAt_aLocation_dontBlockInvalidOperationExceptionFromCurrentState()
        {
            // arrange:
            VoyageNumber number   = new VoyageNumber("VYG01");
            ISchedule    schedule = MockRepository.GenerateStrictMock <ISchedule>();
            ILocation    location = MockRepository.GenerateStrictMock <ILocation>();
            VoyageState  state    = MockRepository.GeneratePartialMock <VoyageState>(number, schedule);

            state.Expect(s => s.StopOverAt(location)).Throw(new InvalidOperationException()).Repeat.Once();
            VoyageEventArgs eventArguments = null;
            IVoyage         eventSender    = null;

            // act:
            IVoyage voyage = MockRepository.GeneratePartialMock <Challenge00.DDDSample.Voyage.Voyage>(state);

            voyage.Stopped += delegate(object sender, VoyageEventArgs e) {
                eventArguments = e;
                eventSender    = sender as IVoyage;
            };
            Assert.Throws <InvalidOperationException>(delegate { voyage.StopOverAt(location); });

            // assert:
            Assert.IsNull(eventSender);
            Assert.IsNull(eventArguments);
            state.VerifyAllExpectations();
            schedule.VerifyAllExpectations();
            location.VerifyAllExpectations();
        }
        public void RegisterHandlingEvent(DateTime completionTime,
                                          TrackingId trackingId,
                                          VoyageNumber voyageNumber,
                                          UnLocode unLocode,
                                          HandlingType type)
        {
            //TODO: Revise transaciton and UoW logic
            using (var transactionScope = new TransactionScope())
            {
                var registrationTime = new DateTime();

                /* Using a factory to create a HandlingEvent (aggregate). This is where
                 * it is determined wether the incoming data, the attempt, actually is capable
                 * of representing a real handling event. */
                HandlingEvent evnt = handlingEventFactory.CreateHandlingEvent(
                    registrationTime, completionTime, trackingId, voyageNumber, unLocode, type);

                /* Store the new handling event, which updates the persistent
                 * state of the handling event aggregate (but not the cargo aggregate -
                 * that happens asynchronously!)*/

                handlingEventRepository.Store(evnt);

                /* Publish an event stating that a cargo has been handled. */
                applicationEvents.CargoWasHandled(evnt);

                transactionScope.Complete();
            }
            logger.Info("Registered handling event");
        }
        public void RegisterHandlingEvent(DateTime completionTime,
                                          TrackingId trackingId,
                                          VoyageNumber voyageNumber,
                                          UnLocode unLocode,
                                          HandlingType type)
        {
            //TODO: Revise transaciton and UoW logic
            using (var transactionScope = new TransactionScope())
            {
                var registrationTime = new DateTime();

                /* Using a factory to create a HandlingEvent (aggregate). This is where
               it is determined wether the incoming data, the attempt, actually is capable
               of representing a real handling event. */
                HandlingEvent evnt = handlingEventFactory.CreateHandlingEvent(
                    registrationTime, completionTime, trackingId, voyageNumber, unLocode, type);

                /* Store the new handling event, which updates the persistent
                   state of the handling event aggregate (but not the cargo aggregate -
                   that happens asynchronously!)*/

                handlingEventRepository.Store(evnt);

                /* Publish an event stating that a cargo has been handled. */
                applicationEvents.CargoWasHandled(evnt);

                transactionScope.Complete();
            }
            logger.Info("Registered handling event");
        }
示例#9
0
        public void Ctor_withValidState_askTheStateForEverything()
        {
            // arrange:
            VoyageNumber number    = new VoyageNumber("VYG01");
            UnLocode     departure = new UnLocode("DPLOC");
            UnLocode     arrival   = new UnLocode("ARLOC");
            ISchedule    schedule  = MockRepository.GenerateStrictMock <ISchedule>();
            VoyageState  state     = MockRepository.GeneratePartialMock <VoyageState>(number, schedule);

            state.Expect(s => s.LastKnownLocation).Return(departure).Repeat.Once();
            state.Expect(s => s.NextExpectedLocation).Return(arrival).Repeat.Once();
            state.Expect(s => s.IsMoving).Return(false).Repeat.Once();

            // act:
            IVoyage voyage = MockRepository.GeneratePartialMock <Challenge00.DDDSample.Voyage.Voyage>(state);

            // assert:
            Assert.AreEqual(number, voyage.Number);
            Assert.AreSame(departure, voyage.LastKnownLocation);
            Assert.AreSame(arrival, voyage.NextExpectedLocation);
            Assert.AreSame(schedule, voyage.Schedule);
            Assert.IsFalse(voyage.IsMoving);
            state.VerifyAllExpectations();
            schedule.VerifyAllExpectations();
        }
示例#10
0
		public MovingVoyage (VoyageNumber number, ISchedule schedule, int movementIndex)
			: base(number, schedule)
		{
			if(movementIndex < 0 || movementIndex >= schedule.MovementsCount)
				throw new ArgumentOutOfRangeException("movementIndex");
			_movementIndex = movementIndex;
		}
示例#11
0
        public void StopOverAt_Destination_01(int index, int movementsCount)
        {
            // arrange:
            VoyageNumber number   = new VoyageNumber("VYGTEST01");
            ISchedule    schedule = MockRepository.GenerateStrictMock <ISchedule>();

            schedule.Expect(s => s.MovementsCount).Return(movementsCount).Repeat.Any();
            UnLocode         arrivalLocation = new UnLocode("ARLOC");
            ICarrierMovement movement1       = MockRepository.GenerateStrictMock <ICarrierMovement>();

            movement1.Expect(m => m.ArrivalLocation).Return(arrivalLocation).Repeat.Times(3);
            schedule.Expect(s => s[index]).Return(movement1).Repeat.Times(3);
            ILocation location = MockRepository.GenerateStrictMock <ILocation>();

            location.Expect(l => l.UnLocode).Return(arrivalLocation).Repeat.Any();


            // act:
            MovingVoyage state   = new MovingVoyage(number, schedule, index);
            VoyageState  stopped = state.StopOverAt(location);

            // assert:
            Assert.IsInstanceOf <CompletedVoyage>(stopped);
            Assert.AreSame(state.NextExpectedLocation, stopped.LastKnownLocation);
            Assert.IsFalse(stopped.IsMoving);
            schedule.VerifyAllExpectations();
            movement1.VerifyAllExpectations();
            location.VerifyAllExpectations();
        }
 public Voyage find(VoyageNumber voyageNumber)
 {
     return sessionFactory.GetCurrentSession().
       CreateQuery("from Voyage where VoyageNumber = :vn").
       SetParameter("vn", voyageNumber).
       UniqueResult<Voyage>();
 }
示例#13
0
文件: Leg.cs 项目: hungdluit/Epic.NET
		public Leg (IVoyage voyage, ILocation loadLocation, DateTime loadTime, ILocation unloadLocation, DateTime unloadTime)
		{
			if(null == voyage)
				throw new ArgumentNullException("voyage");
			if(null == loadLocation)
				throw new ArgumentNullException("loadLocation");
			if(null == unloadLocation)
				throw new ArgumentNullException("unloadLocation");
			if(loadTime >= unloadTime)
				throw new ArgumentException("Unload time must follow the load time.","unloadTime");
			if(loadLocation.UnLocode.Equals(unloadLocation.UnLocode))
				throw new ArgumentException("The locations must not be differents.", "unloadLocation");
			if(!voyage.WillStopOverAt(loadLocation))
			{
				string message = string.Format("The voyage {0} will not stop over the load location {1}.", voyage.Number, loadLocation.UnLocode);
				throw new ArgumentException(message, "loadLocation");
			}
			if(!voyage.WillStopOverAt(unloadLocation))
			{
				string message = string.Format("The voyage {0} will not stop over the unload location {1}.", voyage.Number, unloadLocation.UnLocode);
				throw new ArgumentException(message, "unloadLocation");
			}
			
			_voyage = voyage.Number;
			_loadLocation = loadLocation.UnLocode;
			_unloadLocation = unloadLocation.UnLocode;
			_loadTime = loadTime;
			_unloadTime = unloadTime;
		}
示例#14
0
		public void Ctor_withValidArgs_works(EventType type)
		{
			// arrange:
			List<object> mocks = new List<object>();
			Username userId = new Username("Giacomo");
			IUser user = MockRepository.GenerateStrictMock<IUser>();
			user.Expect(u => u.Username).Return(userId).Repeat.Once();
			mocks.Add(user);
			TrackingId cargoId = new TrackingId("CARGO001");
			UnLocode location = new UnLocode("UNLOC");
			VoyageNumber voyage = new VoyageNumber("VYG001");
			ICargo cargo = MockRepository.GenerateStrictMock<ICargo>();
			cargo.Expect(c => c.TrackingId).Return(cargoId).Repeat.Once();
			IDelivery delivery = MockRepository.GenerateStrictMock<IDelivery>();
			delivery.Expect(d => d.LastKnownLocation).Return(location).Repeat.Once();
			delivery.Expect(d => d.CurrentVoyage).Return(voyage).Repeat.Once();
			mocks.Add(delivery);
			cargo.Expect(c => c.Delivery).Return(delivery).Repeat.Twice();
			mocks.Add(cargo);
			DateTime completionDate = DateTime.UtcNow;
			
			// act:
			IEvent underTest = new Event(user, cargo, type, completionDate);
		
			// assert:
			Assert.AreSame(userId, underTest.User);
			Assert.AreSame(cargoId, underTest.Cargo);
			Assert.AreSame(location, underTest.Location);
			Assert.AreSame(voyage, underTest.Voyage);
			Assert.AreEqual(completionDate, underTest.Date);
			Assert.AreEqual(type, underTest.Type);
			foreach(object mock in mocks)
				mock.VerifyAllExpectations();
		}
示例#15
0
        public void WillStopOverAt_08()
        {
            // arrange:
            VoyageNumber number   = new VoyageNumber("VYGTEST01");
            ISchedule    schedule = MockRepository.GenerateStrictMock <ISchedule>();

            schedule.Expect(s => s.MovementsCount).Return(3).Repeat.Any();
            UnLocode         loc1 = new UnLocode("DPLOC");
            ICarrierMovement mov1 = MockRepository.GenerateStrictMock <ICarrierMovement>();

            mov1.Expect(m => m.DepartureLocation).Return(loc1).Repeat.AtLeastOnce();
            //mov1.Expect(m => m.ArrivalLocation).Return(loc2).Repeat.AtLeastOnce();
            schedule.Expect(s => s[0]).Return(mov1).Repeat.Any();
            ILocation location = MockRepository.GenerateStrictMock <ILocation>();

            location.Expect(l => l.UnLocode).Return(loc1).Repeat.AtLeastOnce();

            // act:
            StoppedVoyage state = new StoppedVoyage(number, schedule, 0);
            bool          willStopOverAtLocation = state.WillStopOverAt(location);

            // assert:
            Assert.IsTrue(willStopOverAtLocation);
            location.VerifyAllExpectations();
            schedule.VerifyAllExpectations();
            mov1.VerifyAllExpectations();
        }
示例#16
0
        public void Ctor_withValidArguments_works()
        {
            // arrange:
            VoyageNumber number    = new VoyageNumber("VYG01");
            UnLocode     departure = new UnLocode("DPLOC");
            UnLocode     arrival   = new UnLocode("ARLOC");
            ISchedule    schedule  = MockRepository.GenerateStrictMock <ISchedule>();

            schedule.Expect(s => s.MovementsCount).Return(3).Repeat.Any();
            ICarrierMovement movement = MockRepository.GenerateStrictMock <ICarrierMovement>();

            movement.Expect(m => m.DepartureLocation).Return(departure).Repeat.Once();
            movement.Expect(m => m.ArrivalLocation).Return(arrival).Repeat.Once();
            schedule.Expect(s => s[0]).Return(movement).Repeat.AtLeastOnce();

            // act:
            IVoyage voyage = new Challenge00.DDDSample.Voyage.Voyage(number, schedule);

            // assert:
            Assert.AreEqual(number, voyage.Number);
            Assert.AreSame(departure, voyage.LastKnownLocation);
            Assert.AreSame(arrival, voyage.NextExpectedLocation);
            Assert.AreSame(schedule, voyage.Schedule);
            Assert.IsFalse(voyage.IsMoving);
        }
示例#17
0
        public void StopOverAt_01(int index)
        {
            // arrange:
            VoyageNumber number   = new VoyageNumber("VYGTEST01");
            ISchedule    schedule = MockRepository.GenerateStrictMock <ISchedule>();

            schedule.Expect(s => s.MovementsCount).Return(3).Repeat.Any();
            UnLocode         initialLocation = new UnLocode("DPLOC");
            ICarrierMovement movement        = MockRepository.GenerateStrictMock <ICarrierMovement>();

            movement.Expect(m => m.DepartureLocation).Return(initialLocation).Repeat.Once();
            schedule.Expect(s => s[index]).Return(movement).Repeat.Once();
            ILocation location = MockRepository.GenerateStrictMock <ILocation>();

            location.Expect(l => l.UnLocode).Return(initialLocation).Repeat.Any();


            // act:
            StoppedVoyage state   = new StoppedVoyage(number, schedule, index);
            VoyageState   arrived = state.StopOverAt(location);

            // assert:
            Assert.AreSame(state, arrived);
            schedule.VerifyAllExpectations();
            movement.VerifyAllExpectations();
            location.VerifyAllExpectations();
        }
示例#18
0
        public void DepartFrom_01(int index)
        {
            // arrange:
            VoyageNumber number   = new VoyageNumber("VYGTEST01");
            ISchedule    schedule = MockRepository.GenerateStrictMock <ISchedule>();

            schedule.Expect(s => s.MovementsCount).Return(3).Repeat.Any();
            UnLocode         initialLocation     = new UnLocode("DPLOC");
            UnLocode         destinationLocation = new UnLocode("ARLOC");
            ICarrierMovement movement            = MockRepository.GenerateStrictMock <ICarrierMovement>();

            movement.Expect(m => m.DepartureLocation).Return(initialLocation).Repeat.Any();
            movement.Expect(m => m.ArrivalLocation).Return(destinationLocation).Repeat.Any();
            schedule.Expect(s => s[index]).Return(movement).Repeat.Any();
            ILocation location = MockRepository.GenerateStrictMock <ILocation>();

            location.Expect(l => l.UnLocode).Return(initialLocation).Repeat.Any();

            // act:
            StoppedVoyage state  = new StoppedVoyage(number, schedule, index);
            VoyageState   moving = state.DepartFrom(location);

            // assert:
            Assert.IsInstanceOf <MovingVoyage>(moving);
            Assert.AreSame(state.LastKnownLocation, moving.LastKnownLocation);
            Assert.AreSame(state.NextExpectedLocation, moving.NextExpectedLocation);
            schedule.VerifyAllExpectations();
            movement.VerifyAllExpectations();
            location.VerifyAllExpectations();
        }
示例#19
0
        public void SubmitReport(HandlingReport handlingReport)
        {
            IList <string> errors = new List <string>();

            DateTime?    completionTime = HandlingReportParser.ParseCompletionTime(handlingReport, errors);
            VoyageNumber voyageNumber   = HandlingReportParser.ParseVoyageNumber(handlingReport.VoyageNumber, errors);
            HandlingType type           = HandlingReportParser.ParseEventType(handlingReport.Type, errors);
            UnLocode     unLocode       = HandlingReportParser.ParseUnLocode(handlingReport.UnLocode, errors);

            foreach (string trackingIdStr in handlingReport.TrackingIds)
            {
                TrackingId trackingId = HandlingReportParser.ParseTrackingId(trackingIdStr, errors);

                if (errors.IsEmpty())
                {
                    DateTime registrationTime = DateTime.Now;
                    var      attempt          = new HandlingEventRegistrationAttempt(
                        registrationTime, completionTime.Value, trackingId, voyageNumber, type, unLocode);
                    applicationEvents.ReceivedHandlingEventRegistrationAttempt(attempt);
                }
                else
                {
                    string errorString = String.Join("\r\n", errors.ToArray());
                    logger.Error("Parse error in handling report: " + errorString);

                    throw new FaultException <HandlingReportException>(new HandlingReportException(errorString), new FaultReason(errorString));
                }
            }
        }
示例#20
0
		public void Ctor_01()
		{
			// arrange:
			GList mocks = new GList();
			TrackingId id = new TrackingId("START");
			DateTime loadTime = DateTime.Now;
			VoyageNumber voyageNumber = new VoyageNumber("VYG001");
			UnLocode location = new UnLocode("CURLC");
            IItinerary itinerary = MockRepository.GenerateStrictMock<IItinerary>();
            itinerary.Expect(i => i.Equals(null)).IgnoreArguments().Return(false).Repeat.Any();
            itinerary.Expect(i => i.FinalArrivalDate).Return(DateTime.UtcNow + TimeSpan.FromDays(1)).Repeat.Any();
            itinerary.Expect(i => i.FinalArrivalLocation).Return(new UnLocode("ENDLC")).Repeat.Any();
            mocks.Add(itinerary);
            IRouteSpecification specification = MockRepository.GenerateStrictMock<IRouteSpecification>();
            specification.Expect(s => s.IsSatisfiedBy(itinerary)).Return(true).Repeat.Any();
            CargoState previousState = MockRepository.GenerateStrictMock<CargoState>(id, specification);
            mocks.Add(previousState);
            previousState = MockRepository.GenerateStrictMock<CargoState>(previousState, itinerary);
            mocks.Add(previousState);
			IVoyage voyage = MockRepository.GenerateStrictMock<IVoyage>();
			voyage.Expect(v => v.Number).Return(voyageNumber).Repeat.AtLeastOnce();
			voyage.Expect(v => v.LastKnownLocation).Return(location).Repeat.AtLeastOnce();
			mocks.Add(voyage);
			
			// act:
			CargoState state = new OnboardCarrierCargo(previousState, voyage, loadTime);
		
			// assert:
			Assert.IsNotNull(state);
			Assert.AreSame(voyageNumber, state.CurrentVoyage);
			Assert.AreEqual(TransportStatus.OnboardCarrier, state.TransportStatus);
			Assert.AreSame(location, state.LastKnownLocation);
			foreach(object mock in mocks)
				mock.VerifyAllExpectations();
		}
示例#21
0
        public void DepartFrom_02(int index)
        {
            // arrange:
            VoyageNumber number   = new VoyageNumber("VYGTEST01");
            ISchedule    schedule = MockRepository.GenerateStrictMock <ISchedule>();

            schedule.Expect(s => s.MovementsCount).Return(3).Repeat.Any();
            UnLocode         initialLocation = new UnLocode("DPLOC");
            ICarrierMovement movement        = MockRepository.GenerateStrictMock <ICarrierMovement>();

            movement.Expect(m => m.DepartureLocation).Return(initialLocation).Repeat.Any();
            schedule.Expect(s => s[index]).Return(movement).Repeat.Any();
            ILocation location = MockRepository.GenerateStrictMock <ILocation>();

            location.Expect(l => l.UnLocode).Return(new UnLocode("ANTHR")).Repeat.Any();

            // act:
            StoppedVoyage state = new StoppedVoyage(number, schedule, index);

            // assert:
            Assert.Throws <ArgumentException>(delegate { state.DepartFrom(location); });
            schedule.VerifyAllExpectations();
            movement.VerifyAllExpectations();
            location.VerifyAllExpectations();
        }
示例#22
0
        public void WillStopOverAt_06()
        {
            // arrange:
            VoyageNumber number   = new VoyageNumber("VYGTEST01");
            ISchedule    schedule = MockRepository.GenerateStrictMock <ISchedule>();

            schedule.Expect(s => s.MovementsCount).Return(3).Repeat.Any();
            UnLocode         loc3 = new UnLocode("ARLCB");
            UnLocode         loc4 = new UnLocode("ARLCC");
            ICarrierMovement mov3 = MockRepository.GenerateStrictMock <ICarrierMovement>();

            mov3.Expect(m => m.DepartureLocation).Return(loc3).Repeat.Any();
            mov3.Expect(m => m.ArrivalLocation).Return(loc4).Repeat.AtLeastOnce();
            schedule.Expect(s => s[2]).Return(mov3).Repeat.Any();
            ILocation location    = MockRepository.GenerateStrictMock <ILocation>();
            UnLocode  outLocation = new UnLocode("LCOUT");

            location.Expect(l => l.UnLocode).Return(outLocation).Repeat.AtLeastOnce();

            // act:
            StoppedVoyage state = new StoppedVoyage(number, schedule, 2);
            bool          willStopOverAtLocation = state.WillStopOverAt(location);

            // assert:
            Assert.IsFalse(willStopOverAtLocation);
            location.VerifyAllExpectations();
            schedule.VerifyAllExpectations();
            mov3.VerifyAllExpectations();
        }
示例#23
0
        public void Ctor_02()
        {
            // arrange:
            VoyageNumber number = new VoyageNumber("VYGTEST01");

            // act:
            new StoppedVoyage(number, null, 0);
        }
示例#24
0
		public void Ctor_02 ()
		{
			// arrange:
			VoyageNumber number = new VoyageNumber("VYGTEST01");
		
			// act:
			new CompletedVoyage(number, null);
		}
示例#25
0
		public void Ctor_02 ()
		{
			// arrange:
			VoyageNumber number = new VoyageNumber("VYGTEST01");
		
			// act:
			new MovingVoyage(number, null, 0);
		}
示例#26
0
        public void Ctor_02()
        {
            // arrange:
            VoyageNumber number = new VoyageNumber("VYGTEST01");

            // act:
            new CompletedVoyage(number, null);
        }
示例#27
0
        public void Equals_ForSameReference_ReturnsTrue()
        {
            var sut = new VoyageNumber("9aA9iDDU2");

            var actual = sut.Equals(sut);

            Assert.IsTrue(actual);
        }
        protected static LegDTO ToLegDTO(Leg leg)
        {
            VoyageNumber voyageNumber = leg.Voyage.voyageNumber;
            UnLocode     from         = leg.LoadLocation.UnLocode;
            UnLocode     to           = leg.UnloadLocation.UnLocode;

            return(new LegDTO(voyageNumber.IdString, from.IdString, to.IdString, leg.LoadTime, leg.UnloadTime));
        }
示例#29
0
        public void SameValueAs_ForSameValue_ReturnsTrue()
        {
            var sut1 = new VoyageNumber("9aA9iDDU2");
            var sut2 = new VoyageNumber("9aA9iDDU2");

            var actual = sut1.SameValueAs(sut2);

            Assert.IsTrue(actual);
        }
 public void Ctor__UnLoadTimeGiven_IsEarlierThanLoadTime__ThrowsArgumentException(
     VoyageNumber voyage,
     UnLocode loadLocation,
     UnLocode unloadLocation,
     DateTime loadTime
     )
 {
     Assert.Throws <ArgumentException>(() => new Leg(voyage, loadLocation, unloadLocation, loadTime, loadTime.Subtract(TimeSpan.FromSeconds(1))));
 }
示例#31
0
		public OnboardCarrierCargo (CargoState previousState, IVoyage voyage, DateTime loadDate)
			: base(previousState)
		{
			if(null == voyage)
				throw new ArgumentNullException("voyage");
			_voyage = voyage.Number;
			_date = loadDate;
			_lastKnownLocation = voyage.LastKnownLocation;
		}
示例#32
0
        public void ToString_ContainsTheValue()
        {
            const string number = "9aA9iDDU2";
            var          sut    = new VoyageNumber(number);

            var actual = sut.ToString();

            Assert.IsTrue(actual.Contains(number));
        }
示例#33
0
        public void SameValueAs_ForDifferentValue_ReturnsTrue()
        {
            var sut1 = new VoyageNumber("9aA9iDDU2");
            var sut2 = new VoyageNumber("U982aJnNd");

            var actual = sut1.SameValueAs(sut2);

            Assert.IsFalse(actual);
        }
 public void Ctor__NoUnLoadLocationGiven__ThrowsArgumentNullException(
     VoyageNumber voyage,
     UnLocode loadLocation,
     DateTime loadTime,
     DateTime unloadTime
     )
 {
     Assert.Throws <ArgumentNullException>(() => new Leg(voyage, loadLocation, null, loadTime, unloadTime));
 }
示例#35
0
		public void Ctor_03(int index)
		{
			// arrange:
			VoyageNumber number = new VoyageNumber("VYGTEST01");
			ISchedule schedule = MockRepository.GenerateStrictMock<ISchedule>();
			schedule.Expect(s => s.MovementsCount).Return(3).Repeat.Any();
		
			// act:
			new MovingVoyage(number, schedule, index);
		}
示例#36
0
        public void TestHashCode()
        {
            const string number   = "aaa";
            var          expected = number.GetHashCode();
            var          sut      = new VoyageNumber(number);

            var actual = sut.GetHashCode();

            Assert.AreEqual(expected, actual);
        }
示例#37
0
        public void TestIdString()
        {
            const string number = "9aA9iDDU2";

            var sut = new VoyageNumber(number);

            var actual = sut.IdString;

            Assert.AreEqual(number, actual);
        }
示例#38
0
        public void Voyage_LiveCycle_05()
        {
            // arrange:
            UnLocode  code1 = new UnLocode("CODAA");
            ILocation loc1  = MockRepository.GenerateStrictMock <ILocation>();

            loc1.Expect(l => l.UnLocode).Return(code1).Repeat.Any();
            loc1.Expect(l => l.Name).Return("First location").Repeat.Any();
            UnLocode  code2 = new UnLocode("CODAB");
            ILocation loc2  = MockRepository.GenerateStrictMock <ILocation>();

            loc2.Expect(l => l.UnLocode).Return(code2).Repeat.Any();
            loc2.Expect(l => l.Name).Return("Second location").Repeat.Any();
            UnLocode  code3 = new UnLocode("CODAC");
            ILocation loc3  = MockRepository.GenerateStrictMock <ILocation>();

            loc3.Expect(l => l.UnLocode).Return(code3).Repeat.Any();
            loc3.Expect(l => l.Name).Return("Third location").Repeat.Any();

            ISchedule schedule = new Schedule();

            schedule = schedule.Append(new CarrierMovement(loc1, DateTime.UtcNow, loc2, DateTime.UtcNow + TimeSpan.FromDays(2)));
            schedule = schedule.Append(new CarrierMovement(loc2, DateTime.UtcNow + TimeSpan.FromDays(3), loc3, DateTime.UtcNow + TimeSpan.FromDays(4)));

            VoyageNumber    number        = new VoyageNumber("TESTVYG");
            VoyageEventArgs departedEvent = null;
            VoyageEventArgs stoppedEvent  = null;

            Challenge00.DDDSample.Voyage.Voyage voyage = new Challenge00.DDDSample.Voyage.Voyage(number, schedule);
            voyage.DepartFrom(loc1);
            voyage.StopOverAt(loc2);
            voyage.DepartFrom(loc2);
            voyage.Departed += delegate(object sender, VoyageEventArgs e) {
                departedEvent = e;
            };
            voyage.Stopped += delegate(object sender, VoyageEventArgs e) {
                stoppedEvent = e;
            };

            // act:
            voyage.StopOverAt(loc3);

            // assert:
            Assert.AreSame(number, voyage.Number);
            Assert.IsFalse(voyage.IsMoving);
            Assert.AreEqual(code3, voyage.LastKnownLocation);
            Assert.AreEqual(code3, voyage.NextExpectedLocation);
            Assert.IsNull(departedEvent);
            Assert.IsNotNull(stoppedEvent);
            Assert.AreEqual(code2, stoppedEvent.PreviousLocation);
            Assert.AreEqual(code3, stoppedEvent.DestinationLocation);
            loc1.VerifyAllExpectations();
            loc2.VerifyAllExpectations();
            loc3.VerifyAllExpectations();
        }
示例#39
0
 public OnboardCarrierCargo(CargoState previousState, IVoyage voyage, DateTime loadDate)
     : base(previousState)
 {
     if (null == voyage)
     {
         throw new ArgumentNullException("voyage");
     }
     _voyage            = voyage.Number;
     _date              = loadDate;
     _lastKnownLocation = voyage.LastKnownLocation;
 }
示例#40
0
        public void Ctor_03(int index)
        {
            // arrange:
            VoyageNumber number   = new VoyageNumber("VYGTEST01");
            ISchedule    schedule = MockRepository.GenerateStrictMock <ISchedule>();

            schedule.Expect(s => s.MovementsCount).Return(3).Repeat.Any();

            // act:
            new StoppedVoyage(number, schedule, index);
        }
示例#41
0
        public void updateItineraries(VoyageNumber voyageNumber)
        {
            var voyage = voyageRepository.find(voyageNumber);
            var affectedCargos = cargoRepository.findCargosOnVoyage(voyage);

            foreach(Cargo cargo in affectedCargos)
            {
                var newItinerary = cargo.Itinerary.WithRescheduledVoyage(voyage);
                cargo.AssignToRoute(newItinerary);
                LOG.Info("Updated itinerary of cargo " + cargo);
            }
        }
示例#42
0
        public void updateItineraries(VoyageNumber voyageNumber)
        {
            var voyage         = voyageRepository.find(voyageNumber);
            var affectedCargos = cargoRepository.findCargosOnVoyage(voyage);

            foreach (Cargo cargo in affectedCargos)
            {
                var newItinerary = cargo.Itinerary.WithRescheduledVoyage(voyage);
                cargo.AssignToRoute(newItinerary);
                LOG.Info("Updated itinerary of cargo " + cargo);
            }
        }
示例#43
0
		public void Ctor_01()
		{
			// arrange:
			VoyageNumber number = new VoyageNumber("VYGTEST01");
			ISchedule schedule = MockRepository.GenerateStrictMock<ISchedule>();
			schedule.Expect(s => s.MovementsCount).Return(3).Repeat.Any();
		
			// act:
			CompletedVoyage state = new CompletedVoyage(number, schedule);
		
			// assert:
			Assert.AreSame(schedule, state.Schedule);
			Assert.IsFalse(state.IsMoving);
		}
 public HandlingEventRegistrationAttempt(DateTime registrationDate,
     DateTime completionDate,
     TrackingId trackingId,
     VoyageNumber voyageNumber,
     HandlingType type,
     UnLocode unLocode)
 {
     registrationTime = registrationDate;
     completionTime = completionDate;
     this.trackingId = trackingId;
     this.voyageNumber = voyageNumber;
     this.type = type;
     this.unLocode = unLocode;
 }
        private Voyage findVoyage(VoyageNumber voyageNumber)
        {
            if(voyageNumber == null)
            {
                return null;
            }

            var voyage = voyageRepository.find(voyageNumber);
            if(voyage == null)
            {
                throw new UnknownVoyageException(voyageNumber);
            }

            return voyage;
        }
示例#46
0
 internal static Itinerary fromDTO(RouteCandidateDTO routeCandidateDTO,
                          VoyageRepository voyageRepository,
                          LocationRepository locationRepository)
 {
     var legs = new List<Leg>(routeCandidateDTO.getLegs().Count());
     foreach(LegDTO legDTO in routeCandidateDTO.getLegs())
     {
         var voyageNumber = new VoyageNumber(legDTO.getVoyageNumber());
         var voyage = voyageRepository.find(voyageNumber);
         var from = locationRepository.find(new UnLocode(legDTO.getFrom()));
         var to = locationRepository.find(new UnLocode(legDTO.getTo()));
         legs.Add(Leg.DeriveLeg(voyage, from, to));
     }
     return new Itinerary(legs);
 }
示例#47
0
        public void TestCreateHandlingEventUnknownCarrierMovement()
        {
            cargoRepositoryMock.Setup(rep => rep.Find(trackingId)).Returns(cargo);

            try
            {
                var invalid = new VoyageNumber("XXX");
                DateTime completionTime = DateTime.Now.AddDays(10);
                factory.CreateHandlingEvent(
                    DateTime.Now, completionTime, trackingId, invalid, SampleLocations.STOCKHOLM.UnLocode,
                    HandlingType.LOAD
                    );
                Assert.Fail("Expected UnknownVoyageException");
            }
            catch (UnknownVoyageException expected) {}
        }
        /// <summary>
        /// Assemble a Itinerary from provided RouteCandidateDTO. 
        /// </summary>
        /// <param name="routeCandidateDTO">route candidate DTO</param>
        /// <param name="voyageRepository">voyage repository</param>
        /// <param name="locationRepository">location repository</param>
        /// <returns>An itinerary</returns>
        public Itinerary FromDTO(RouteCandidateDTO routeCandidateDTO,
                                 IVoyageRepository voyageRepository,
                                 ILocationRepository locationRepository)
        {
            var legs = new List<Leg>(routeCandidateDTO.Legs.Count);

            foreach (LegDTO legDTO in routeCandidateDTO.Legs)
            {
                VoyageNumber voyageNumber = new VoyageNumber(legDTO.VoyageNumber);
                Voyage voyage = voyageRepository.Find(voyageNumber);
                Location from = locationRepository.Find(new UnLocode(legDTO.FromLocation));
                Location to = locationRepository.Find(new UnLocode(legDTO.ToLocation));
                legs.Add(new Leg(voyage, from, to, legDTO.LoadTime, legDTO.UnloadTime));
            }

            return new Itinerary(legs);
        }
示例#49
0
		public void Voyage_LiveCycle_01 ()
		{
			// arrange:
			UnLocode code1 = new UnLocode("CODAA");
			ILocation loc1 = MockRepository.GenerateStrictMock<ILocation>();
			loc1.Expect(l => l.UnLocode).Return(code1).Repeat.Any();
			loc1.Expect(l => l.Name).Return("First location").Repeat.Any();
			UnLocode code2 = new UnLocode("CODAB");
			ILocation loc2 = MockRepository.GenerateStrictMock<ILocation>();
			loc2.Expect(l => l.UnLocode).Return(code2).Repeat.Any();
			loc2.Expect(l => l.Name).Return("Second location").Repeat.Any();
			UnLocode code3 = new UnLocode("CODAC");
			ILocation loc3 = MockRepository.GenerateStrictMock<ILocation>();
			loc3.Expect(l => l.UnLocode).Return(code3).Repeat.Any();
			loc3.Expect(l => l.Name).Return("Third location").Repeat.Any();
			
			ISchedule schedule = new Schedule();
			schedule = schedule.Append(new CarrierMovement(loc1, DateTime.UtcNow, loc2, DateTime.UtcNow + TimeSpan.FromDays(2)));
			schedule = schedule.Append(new CarrierMovement(loc2, DateTime.UtcNow + TimeSpan.FromDays(3), loc3, DateTime.UtcNow + TimeSpan.FromDays(4)));

			VoyageNumber number = new VoyageNumber("TESTVYG");
			VoyageEventArgs departedEvent = null;
			VoyageEventArgs stoppedEvent = null;
			
			// act:
			Challenge00.DDDSample.Voyage.Voyage voyage = new Challenge00.DDDSample.Voyage.Voyage(number, schedule);
			voyage.Departed += delegate(object sender, VoyageEventArgs e) {
				departedEvent = e;
			};
			voyage.Stopped += delegate(object sender, VoyageEventArgs e) {
				stoppedEvent = e;
			};
			
			// assert:
			Assert.AreSame(number, voyage.Number);
			Assert.IsFalse(voyage.IsMoving);
			Assert.AreEqual(code1, voyage.LastKnownLocation);
			Assert.AreEqual(code2, voyage.NextExpectedLocation);
			Assert.IsNull(departedEvent);
			Assert.IsNull(stoppedEvent);
			loc1.VerifyAllExpectations();
			loc2.VerifyAllExpectations();
			loc3.VerifyAllExpectations();
		}
示例#50
0
		public void LastKnownLocation_01()
		{
			// arrange:
			VoyageNumber number = new VoyageNumber("VYGTEST01");
			ISchedule schedule = MockRepository.GenerateStrictMock<ISchedule>();
			schedule.Expect(s => s.MovementsCount).Return(3).Repeat.Any();
			UnLocode arrivalLocation = new UnLocode("ATEND");
			ICarrierMovement movement = MockRepository.GenerateStrictMock<ICarrierMovement>();
			movement.Expect(m => m.ArrivalLocation).Return(arrivalLocation).Repeat.Once();
			schedule.Expect(s => s[2]).Return(movement).Repeat.Once();
		
			// act:
			CompletedVoyage state = new CompletedVoyage(number, schedule);
		
			// assert:
			Assert.AreSame(arrivalLocation, state.LastKnownLocation);
			movement.VerifyAllExpectations();
			schedule.VerifyAllExpectations();
		}
        public void registerHandlingEvent(DateTime completionTime, TrackingId trackingId,
                                          VoyageNumber voyageNumber, UnLocode unLocode,
                                          HandlingActivityType type, OperatorCode operatorCode)
        {
            // Using a factory to create a HandlingEvent (aggregate). This is where
            // it is determined wether the incoming data, the attempt, actually is capable
            // of representing a real handling handlingEvent.
            var handlingEvent = handlingEventFactory.createHandlingEvent(
              completionTime, trackingId, voyageNumber, unLocode, type, operatorCode
            );

            // Store the new handling handlingEvent, which updates the persistent
            // state of the handling handlingEvent aggregate (but not the cargo aggregate -
            // that happens asynchronously!)
            handlingEventRepository.store(handlingEvent);

            // Publish a system event
            systemEvents.notifyOfHandlingEvent(handlingEvent);

            LOG.Info("Registered handling event: " + handlingEvent);
        }
示例#52
0
        /// <summary>
        /// Creates handling event
        /// throws UnknownVoyageException   if there's no voyage with this number
        /// throws UnknownCargoException    if there's no cargo with this tracking id
        /// throws UnknownLocationException if there's no location with this UN Locode
        /// </summary>
        /// <param name="registrationTime"> time when this event was received by the system</param>
        /// <param name="completionTime">when the event was completed, for example finished loading</param>
        /// <param name="trackingId">cargo tracking id</param>
        /// <param name="voyageNumber">voyage number</param>
        /// <param name="unlocode">United Nations Location Code for the location of the event</param>
        /// <param name="type">type of event</param>
        /// <returns> A handling event.</returns>
        public HandlingEvent CreateHandlingEvent(DateTime registrationTime, DateTime completionTime,
            TrackingId trackingId, VoyageNumber voyageNumber, UnLocode unlocode,
            HandlingType type)
        {
            Cargo cargo = FindCargo(trackingId);
            Voyage voyage = FindVoyage(voyageNumber);
            Location location = FindLocation(unlocode);

            try
            {
                if (voyage == null)
                {
                    return new HandlingEvent(cargo, completionTime, registrationTime, type, location);
                }

                return new HandlingEvent(cargo, completionTime, registrationTime, type, location, voyage);
            }
            catch (Exception e)
            {
                throw new CannotCreateHandlingEventException(e);
            }
        }
示例#53
0
		public void Ctor_withValidArguments_works ()
		{
			// arrange:
			VoyageNumber number = new VoyageNumber("VYG01");
			UnLocode departure = new UnLocode("DPLOC");
			UnLocode arrival = new UnLocode("ARLOC");
			ISchedule schedule = MockRepository.GenerateStrictMock<ISchedule>();
			schedule.Expect(s => s.MovementsCount).Return(3).Repeat.Any();
			ICarrierMovement movement = MockRepository.GenerateStrictMock<ICarrierMovement>();
			movement.Expect(m => m.DepartureLocation).Return(departure).Repeat.Once();
			movement.Expect(m => m.ArrivalLocation).Return(arrival).Repeat.Once();
			schedule.Expect(s => s[0]).Return(movement).Repeat.AtLeastOnce();
			
			// act:
			IVoyage voyage = new Challenge00.DDDSample.Voyage.Voyage(number, schedule);
			
			// assert:
			Assert.AreEqual(number, voyage.Number);
			Assert.AreSame(departure, voyage.LastKnownLocation);
			Assert.AreSame(arrival, voyage.NextExpectedLocation);
			Assert.AreSame(schedule, voyage.Schedule);
			Assert.IsFalse(voyage.IsMoving);
		}
示例#54
0
		public void Ctor_01()
		{
			// arrange:
			DateTime loadTime = DateTime.UtcNow;
			DateTime unloadTime = DateTime.UtcNow + TimeSpan.FromDays(3);
			
			VoyageNumber voyageNumber = new VoyageNumber("VYGTEST");
			IVoyage voyage = MockRepository.GenerateStrictMock<IVoyage>();
			voyage.Expect(v => v.Number).Return(voyageNumber).Repeat.Any();
			
			UnLocode code1 = new UnLocode("CODAA");
			ILocation loc1 = MockRepository.GenerateStrictMock<ILocation>();
			loc1.Expect(l => l.UnLocode).Return(code1).Repeat.Any();

			UnLocode code2 = new UnLocode("CODAB");
			ILocation loc2 = MockRepository.GenerateStrictMock<ILocation>();
			loc2.Expect(l => l.UnLocode).Return(code2).Repeat.Any();
			
			voyage.Expect(v => v.WillStopOverAt(loc1)).Return(true).Repeat.AtLeastOnce();
			voyage.Expect(v => v.WillStopOverAt(loc2)).Return(true).Repeat.AtLeastOnce();
			
			// act:
			ILeg leg = new Leg(voyage, loc1, loadTime, loc2, unloadTime);
		
			// assert:
			Assert.IsTrue(leg.Equals(leg));
			Assert.IsTrue(leg.Equals((object)leg));
			Assert.IsFalse(leg.Equals(null));
			Assert.AreEqual(voyageNumber, leg.Voyage);
			Assert.AreEqual(code1, leg.LoadLocation);
			Assert.AreEqual(code2, leg.UnloadLocation);
			Assert.AreEqual(loadTime, leg.LoadTime);
			Assert.AreEqual(unloadTime, leg.UnloadTime);
			voyage.VerifyAllExpectations();
			loc1.VerifyAllExpectations();
			loc2.VerifyAllExpectations();
		}
示例#55
0
		public void Ctor_withValidState_askTheStateForEverything()
		{
			// arrange:
			VoyageNumber number = new VoyageNumber("VYG01");
			UnLocode departure = new UnLocode("DPLOC");
			UnLocode arrival = new UnLocode("ARLOC");
			ISchedule schedule = MockRepository.GenerateStrictMock<ISchedule>();
			VoyageState state = MockRepository.GeneratePartialMock<VoyageState>(number, schedule);
			state.Expect(s => s.LastKnownLocation).Return(departure).Repeat.Once();
			state.Expect(s => s.NextExpectedLocation).Return(arrival).Repeat.Once();
			state.Expect(s => s.IsMoving).Return(false).Repeat.Once();
			
			// act:
			IVoyage voyage = MockRepository.GeneratePartialMock<Challenge00.DDDSample.Voyage.Voyage>(state);
			
			// assert:
			Assert.AreEqual(number, voyage.Number);
			Assert.AreSame(departure, voyage.LastKnownLocation);
			Assert.AreSame(arrival, voyage.NextExpectedLocation);
			Assert.AreSame(schedule, voyage.Schedule);
			Assert.IsFalse(voyage.IsMoving);
			state.VerifyAllExpectations();
			schedule.VerifyAllExpectations();
		}
示例#56
0
        public void testCargoFromHongkongToStockholm()
        {
            //Test setup: A cargo should be shipped from Hongkong to Stockholm,
            //and it should arrive in no more than two weeks. 
            Location origin = SampleLocations.HONGKONG;
            Location destination = SampleLocations.STOCKHOLM;
            DateTime arrivalDeadline = DateUtil.ToDate("2009-03-18");


            //  Use case 1: booking 
            //A new cargo is booked, and the unique tracking id is assigned to the cargo. 
            TrackingId trackingId = bookingService.BookNewCargo(
                origin.UnLocode, destination.UnLocode, arrivalDeadline);

            //      The tracking id can be used to lookup the cargo in the repository.
            //Important: The cargo, and thus the domain model, is responsible for determining
            //the status of the cargo, whether it is on the right track or not and so on.
            //This is core domain logic.

            //Tracking the cargo basically amounts to presenting information extracted from
            //the cargo aggregate in a suitable way. 
            Cargo cargo = cargoRepository.Find(trackingId);
            Assert.IsNotNull(cargo);
            Assert.AreEqual(TransportStatus.NOT_RECEIVED, cargo.Delivery.TransportStatus);
            Assert.AreEqual(RoutingStatus.NOT_ROUTED, cargo.Delivery.RoutingStatus);
            Assert.IsFalse(cargo.Delivery.IsMisdirected);
            Assert.AreEqual(cargo.Delivery.EstimatedTimeOfArrival, Delivery.ETA_UNKOWN);
            Assert.IsNull(cargo.Delivery.NextExpectedActivity);


            //   Use case 2: routing 
            //A number of possible routes for this cargo is requested and may be
            //presented to the customer in some way for him/her to choose from.
            //Selection could be affected by things like price and time of delivery,
            //but this test simply uses an arbitrary selection to mimic that process.

            //The cargo is then assigned to the selected route, described by an itinerary.
            IList<Itinerary> itineraries = bookingService.RequestPossibleRoutesForCargo(trackingId);
            Itinerary itinerary = SelectPreferedItinerary(itineraries);
            cargo.AssignToRoute(itinerary);

            Assert.AreEqual(TransportStatus.NOT_RECEIVED, cargo.Delivery.TransportStatus);
            Assert.AreEqual(RoutingStatus.ROUTED, cargo.Delivery.RoutingStatus);
            Assert.AreNotEqual(Delivery.ETA_UNKOWN, cargo.Delivery.EstimatedTimeOfArrival);
            Assert.AreEqual(new HandlingActivity(HandlingType.RECEIVE, SampleLocations.HONGKONG),
                            cargo.Delivery.NextExpectedActivity);


            //   Use case 3: handling

            //A handling event registration attempt will be formed from parsing
            //the data coming in as a handling report either via
            //the web service interface or as an uploaded CSV file.

            //The handling event factory tries to create a HandlingEvent from the attempt,
            //and if the factory decides that this is a plausible handling event, it is stored.
            //If the attempt is invalid, for example if no cargo exists for the specfied tracking id,
            //the attempt is rejected.

            //Handling begins: cargo is received in Hongkong.     
            handlingEventService.RegisterHandlingEvent(
                DateUtil.ToDate("2009-03-01"), trackingId, null, SampleLocations.HONGKONG.UnLocode,
                HandlingType.RECEIVE);

            Assert.AreEqual(TransportStatus.IN_PORT, cargo.Delivery.TransportStatus);
            Assert.AreEqual(SampleLocations.HONGKONG, cargo.Delivery.LastKnownLocation);

            // Next event: Load onto voyage CM003 in Hongkong
            handlingEventService.RegisterHandlingEvent(
                DateUtil.ToDate("2009-03-03"), trackingId, SampleVoyages.v100.voyageNumber,
                SampleLocations.HONGKONG.UnLocode, HandlingType.LOAD);

            // Check current state - should be ok
            Assert.AreEqual(SampleVoyages.v100, cargo.Delivery.CurrentVoyage);
            Assert.AreEqual(SampleLocations.HONGKONG, cargo.Delivery.LastKnownLocation);
            Assert.AreEqual(TransportStatus.ONBOARD_CARRIER, cargo.Delivery.TransportStatus);
            Assert.IsFalse(cargo.Delivery.IsMisdirected);
            Assert.AreEqual(
                new HandlingActivity(HandlingType.UNLOAD, SampleLocations.NEWYORK, SampleVoyages.v100),
                cargo.Delivery.NextExpectedActivity);

            //Here's an attempt to register a handling event that's not valid
            //because there is no voyage with the specified voyage number,
            //and there's no location with the specified UN Locode either.

            //This attempt will be rejected and will not affect the cargo delivery in any way.
            VoyageNumber noSuchVoyageNumber = new VoyageNumber("XX000");
            UnLocode noSuchUnLocode = new UnLocode("ZZZZZ");
            try
            {
                handlingEventService.RegisterHandlingEvent(
                    DateUtil.ToDate("2009-03-05"), trackingId, noSuchVoyageNumber, noSuchUnLocode,
                    HandlingType.LOAD);
                Assert.Fail("Should not be able to register a handling event with invalid location and voyage");
            }
            catch (CannotCreateHandlingEventException expected) {}


            // Cargo is now (incorrectly) unloaded in Tokyo
            handlingEventService.RegisterHandlingEvent(
                DateUtil.ToDate("2009-03-05"), trackingId, SampleVoyages.v100.voyageNumber,
                SampleLocations.TOKYO.UnLocode, HandlingType.UNLOAD);

            // Check current state - cargo is misdirected!
            Assert.AreEqual(Voyage.NONE, cargo.Delivery.CurrentVoyage);
            Assert.AreEqual(SampleLocations.TOKYO, cargo.Delivery.LastKnownLocation);
            Assert.AreEqual(TransportStatus.IN_PORT, cargo.Delivery.TransportStatus);
            Assert.IsTrue(cargo.Delivery.IsMisdirected);
            Assert.IsNull(cargo.Delivery.NextExpectedActivity);


            // -- Cargo needs to be rerouted --
            // TODO cleaner reroute from "earliest location from where the new route originates"

            // Specify a new route, this time from Tokyo (where it was incorrectly unloaded) to Stockholm
            RouteSpecification fromTokyo = new RouteSpecification(SampleLocations.TOKYO, SampleLocations.STOCKHOLM,
                                                                  arrivalDeadline);
            cargo.SpecifyNewRoute(fromTokyo);

            // The old itinerary does not satisfy the new specification
            Assert.AreEqual(RoutingStatus.MISROUTED, cargo.Delivery.RoutingStatus);
            Assert.IsNull(cargo.Delivery.NextExpectedActivity);

            // Repeat procedure of selecting one out of a number of possible routes satisfying the route spec
            IList<Itinerary> newItineraries = bookingService.RequestPossibleRoutesForCargo(cargo.trackingId);
            Itinerary newItinerary = SelectPreferedItinerary(newItineraries);
            cargo.AssignToRoute(newItinerary);

            // New itinerary should satisfy new route
            Assert.AreEqual(RoutingStatus.ROUTED, cargo.Delivery.RoutingStatus);

            // TODO we can't handle the face that after a reroute, the cargo isn't misdirected anymore
            //Assert.IsFalse(cargo.isMisdirected());
            //Assert.AreEqual(new HandlingActivity(LOAD, TOKYO), cargo.nextExpectedActivity());


            // -- Cargo has been rerouted, shipping continues --


            // Load in Tokyo
            handlingEventService.RegisterHandlingEvent(
                DateUtil.ToDate("2009-03-08"), trackingId, SampleVoyages.v300.voyageNumber,
                SampleLocations.TOKYO.UnLocode, HandlingType.LOAD);

            // Check current state - should be ok
            Assert.AreEqual(SampleVoyages.v300, cargo.Delivery.CurrentVoyage);
            Assert.AreEqual(SampleLocations.TOKYO, cargo.Delivery.LastKnownLocation);
            Assert.AreEqual(TransportStatus.ONBOARD_CARRIER, cargo.Delivery.TransportStatus);
            Assert.IsFalse(cargo.Delivery.IsMisdirected);
            Assert.AreEqual(
                new HandlingActivity(HandlingType.UNLOAD, SampleLocations.HAMBURG, SampleVoyages.v300),
                cargo.Delivery.NextExpectedActivity);

            // Unload in Hamburg
            handlingEventService.RegisterHandlingEvent(
                DateUtil.ToDate("2009-03-12"), trackingId, SampleVoyages.v300.voyageNumber,
                SampleLocations.HAMBURG.UnLocode, HandlingType.UNLOAD);

            // Check current state - should be ok
            Assert.AreEqual(Voyage.NONE, cargo.Delivery.CurrentVoyage);
            Assert.AreEqual(SampleLocations.HAMBURG, cargo.Delivery.LastKnownLocation);
            Assert.AreEqual(TransportStatus.IN_PORT, cargo.Delivery.TransportStatus);
            Assert.IsFalse(cargo.Delivery.IsMisdirected);
            Assert.AreEqual(
                new HandlingActivity(HandlingType.LOAD, SampleLocations.HAMBURG, SampleVoyages.v400),
                cargo.Delivery.NextExpectedActivity);


            // Load in Hamburg
            handlingEventService.RegisterHandlingEvent(
                DateUtil.ToDate("2009-03-14"), trackingId, SampleVoyages.v400.voyageNumber,
                SampleLocations.HAMBURG.UnLocode, HandlingType.LOAD);

            // Check current state - should be ok
            Assert.AreEqual(SampleVoyages.v400, cargo.Delivery.CurrentVoyage);
            Assert.AreEqual(SampleLocations.HAMBURG, cargo.Delivery.LastKnownLocation);
            Assert.AreEqual(TransportStatus.ONBOARD_CARRIER, cargo.Delivery.TransportStatus);
            Assert.IsFalse(cargo.Delivery.IsMisdirected);
            Assert.AreEqual(
                new HandlingActivity(HandlingType.UNLOAD, SampleLocations.STOCKHOLM, SampleVoyages.v400),
                cargo.Delivery.NextExpectedActivity);


            // Unload in Stockholm
            handlingEventService.RegisterHandlingEvent(
                DateUtil.ToDate("2009-03-15"), trackingId, SampleVoyages.v400.voyageNumber,
                SampleLocations.STOCKHOLM.UnLocode, HandlingType.UNLOAD);

            // Check current state - should be ok
            Assert.AreEqual(Voyage.NONE, cargo.Delivery.CurrentVoyage);
            Assert.AreEqual(SampleLocations.STOCKHOLM, cargo.Delivery.LastKnownLocation);
            Assert.AreEqual(TransportStatus.IN_PORT, cargo.Delivery.TransportStatus);
            Assert.IsFalse(cargo.Delivery.IsMisdirected);
            Assert.AreEqual(new HandlingActivity(HandlingType.CLAIM, SampleLocations.STOCKHOLM),
                            cargo.Delivery.NextExpectedActivity);

            // Finally, cargo is claimed in Stockholm. This ends the cargo lifecycle from our perspective.
            handlingEventService.RegisterHandlingEvent(
                DateUtil.ToDate("2009-03-16"), trackingId, null, SampleLocations.STOCKHOLM.UnLocode,
                HandlingType.CLAIM);

            // Check current state - should be ok
            Assert.AreEqual(Voyage.NONE, cargo.Delivery.CurrentVoyage);
            Assert.AreEqual(SampleLocations.STOCKHOLM, cargo.Delivery.LastKnownLocation);
            Assert.AreEqual(TransportStatus.CLAIMED, cargo.Delivery.TransportStatus);
            Assert.IsFalse(cargo.Delivery.IsMisdirected);
            Assert.IsNull(cargo.Delivery.NextExpectedActivity);
        }
示例#57
0
		public CompletedVoyage (VoyageNumber number, ISchedule schedule)
			: base(number, schedule)
		{
		}
示例#58
0
		public void LoadOn_06()
		{
			// arrange:
            List<object> mocks = new List<object>();

            UnLocode code = new UnLocode("FINAL");
            TrackingId id = new TrackingId("CRG01");
			VoyageNumber voyageNumber = new VoyageNumber("ATEST");
            DateTime arrival = DateTime.UtcNow;
			UnLocode voyageLocation = new UnLocode("OTHER");
            IItinerary itinerary = MockRepository.GenerateStrictMock<IItinerary>();
            itinerary.Expect(i => i.Equals(null)).IgnoreArguments().Return(false).Repeat.Any();
            itinerary.Expect(i => i.FinalArrivalDate).Return(DateTime.UtcNow + TimeSpan.FromDays(1)).Repeat.Any();
            itinerary.Expect(i => i.FinalArrivalLocation).Return(code).Repeat.AtLeastOnce();
            mocks.Add(itinerary);
            IRouteSpecification specification = MockRepository.GenerateStrictMock<IRouteSpecification>();
            specification.Expect(s => s.IsSatisfiedBy(itinerary)).Return(true).Repeat.AtLeastOnce();
            mocks.Add(specification);
			IVoyage voyage = MockRepository.GenerateStrictMock<IVoyage>();
			voyage.Expect(v => v.IsMoving).Return(false).Repeat.AtLeastOnce();
			voyage.Expect(v => v.LastKnownLocation).Return(voyageLocation).Repeat.AtLeastOnce();
			voyage.Expect(v => v.Number).Return(voyageNumber).Repeat.AtLeastOnce();
			mocks.Add(voyage);
            CargoState previousState = MockRepository.GenerateStrictMock<CargoState>(id, specification);
            previousState.Expect(s => s.LastKnownLocation).Return(code).Repeat.Any();
            mocks.Add(previousState);
            previousState = MockRepository.GenerateStrictMock<CargoState>(previousState, itinerary);
            mocks.Add(previousState);
            InPortCargo state = new InPortCargo(previousState, voyageLocation, arrival);
			
			// act:
			Assert.Throws<ArgumentException>(delegate { state.LoadOn(voyage, arrival - TimeSpan.FromDays(2)); });
		
			// assert:
			foreach (object mock in mocks)
                mock.VerifyAllExpectations();
		}
示例#59
0
		public void Unload_03()
		{
			// arrange:
            List<object> mocks = new List<object>();

			UnLocode code = new UnLocode("START");
			VoyageNumber voyageNumber = new VoyageNumber("ATEST");
			ILocation location = MockRepository.GenerateStrictMock<ILocation>();
			location.Expect(l => l.UnLocode).Return(code).Repeat.AtLeastOnce();
            mocks.Add(location);
			DateTime arrival = DateTime.UtcNow;
			TrackingId id = new TrackingId("CARGO01");
            IItinerary itinerary = MockRepository.GenerateStrictMock<IItinerary>();
            itinerary.Expect(i => i.Equals(null)).IgnoreArguments().Return(false).Repeat.Any();
            itinerary.Expect(i => i.FinalArrivalDate).Return(DateTime.UtcNow + TimeSpan.FromDays(1)).Repeat.Any();
            itinerary.Expect(i => i.FinalArrivalLocation).Return(code).Repeat.Any();
            mocks.Add(itinerary);
            IRouteSpecification specification = MockRepository.GenerateStrictMock<IRouteSpecification>();
            specification.Expect(s => s.IsSatisfiedBy(itinerary)).Return(true).Repeat.Any();
            mocks.Add(specification);
			IVoyage voyage = MockRepository.GenerateStrictMock<IVoyage>();
			voyage.Expect(v => v.Number).Return(voyageNumber).Repeat.Any();
			mocks.Add(voyage);
			CargoState previousState = MockRepository.GenerateStrictMock<CargoState>(id, specification);
            mocks.Add(previousState);
            previousState = MockRepository.GenerateStrictMock<CargoState>(previousState, itinerary);
            mocks.Add(previousState);
            previousState.Expect(s => s.LastKnownLocation).Return(code).Repeat.Any();
			InPortCargo state = new InPortCargo(previousState, code, arrival);
			CargoState customCleared = state.ClearCustoms(location, arrival + TimeSpan.FromDays(1));
		
			// act:
			Assert.Throws<InvalidOperationException>(delegate { customCleared.Unload(voyage, arrival + TimeSpan.FromDays(2)); });
		
			// assert:
            foreach (object mock in mocks)
                mock.VerifyAllExpectations();

		}
 public Voyage find(VoyageNumber voyageNumber)
 {
     return SampleVoyages.lookup(voyageNumber);
 }