Ejemplo n.º 1
0
		public void Ctor_01()
		{
			// arrange:
			UnLocode final = new UnLocode("FINAL");
			TrackingId id = new TrackingId("CLAIM");
			IItinerary itinerary = MockRepository.GenerateStrictMock<IItinerary>();
			itinerary.Expect(i => i.FinalArrivalDate).Return(DateTime.UtcNow).Repeat.AtLeastOnce();
			itinerary.Expect(i => i.FinalArrivalLocation).Return(final).Repeat.AtLeastOnce();
			IRouteSpecification specification = MockRepository.GenerateStrictMock<IRouteSpecification>();
			specification.Expect(s => s.IsSatisfiedBy(itinerary)).Return(true).Repeat.Any();
			CargoState previousState = MockRepository.GenerateStrictMock<CargoState>(id, specification);
			previousState = MockRepository.GenerateStrictMock<CargoState>(previousState, itinerary);
			previousState.Expect(s => s.IsUnloadedAtDestination).Return(true).Repeat.AtLeastOnce();
			previousState.Expect(s => s.TransportStatus).Return(TransportStatus.InPort).Repeat.AtLeastOnce();
			DateTime claimDate = DateTime.UtcNow;
			
		
			// act:
			ClaimedCargo state = new ClaimedCargo(previousState, claimDate);
		
			// assert:
			Assert.AreEqual(TransportStatus.Claimed, state.TransportStatus);
			Assert.AreEqual(RoutingStatus.Routed, state.RoutingStatus);
			Assert.AreSame(final, state.LastKnownLocation);
			Assert.AreSame(specification, state.RouteSpecification);
			Assert.IsNull(state.CurrentVoyage);
			Assert.IsTrue(state.IsUnloadedAtDestination);
			itinerary.VerifyAllExpectations();
			specification.VerifyAllExpectations();
			previousState.VerifyAllExpectations();
		}
Ejemplo n.º 2
0
		public void Append_01()
		{
			// arrange:
			UnLocode loc1 = new UnLocode("CODLD");
			UnLocode loc2 = new UnLocode("CODUN");
			DateTime arrivalDate = DateTime.UtcNow + TimeSpan.FromDays(10);
			ILeg leg = MockRepository.GenerateStrictMock<ILeg>();
			leg.Expect(l => l.LoadLocation).Return(loc1).Repeat.Once();
			leg.Expect(l => l.UnloadLocation).Return(loc2).Repeat.Once();
			leg.Expect(l => l.UnloadTime).Return(arrivalDate).Repeat.Once();
			Itinerary empty = new Itinerary();
		
			// act:
			IItinerary tested = empty.Append(leg);
		
			// assert:
			Assert.IsNotNull(tested);
			Assert.AreEqual(1, tested.Count());
			Assert.AreSame(leg, tested.First());
			Assert.AreSame(leg, tested.Last());
			Assert.AreEqual(loc1, tested.InitialDepartureLocation);
			Assert.AreEqual(loc2, tested.FinalArrivalLocation);
			Assert.AreEqual(arrivalDate, tested.FinalArrivalDate);
			leg.VerifyAllExpectations();
		}
Ejemplo n.º 3
0
		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;
		}
Ejemplo n.º 4
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);
            }
        }
Ejemplo n.º 5
0
        public void Ctor_02()
        {
            // arrange:
            List<object> mocks = new List<object>();

            UnLocode code = new UnLocode("START");
            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);
            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();

            // act:
            InPortCargo state = new InPortCargo(previousState, code, arrival);

            // assert:
            Assert.IsTrue(TransportStatus.InPort == state.TransportStatus);
			Assert.IsNull(state.CurrentVoyage);
            Assert.AreSame(code, state.LastKnownLocation);
            Assert.IsTrue(state.IsUnloadedAtDestination);
            Assert.AreSame(id, state.Identifier);
            foreach (object mock in mocks)
                mock.VerifyAllExpectations();
        }
Ejemplo n.º 6
0
        public void TestHashCode()
        {
            var allCaps = new UnLocode("ABCDE");
            var mixedCase = new UnLocode("aBcDe");

            Assert.AreEqual(allCaps.GetHashCode(), mixedCase.GetHashCode());
        }
Ejemplo n.º 7
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();
		}
Ejemplo n.º 8
0
		public void Append_03()
		{
			// arrange:
			UnLocode c1 = new UnLocode("LOCDA");
			UnLocode c2 = new UnLocode("LOCDA");
			
			ICarrierMovement m1 = MockRepository.GenerateStrictMock<ICarrierMovement>();
			m1.Expect(m => m.ArrivalLocation).Return(c1).Repeat.Any();
			m1.Expect(m => m.ArrivalTime).Return(DateTime.UtcNow + new TimeSpan(48, 0, 0)).Repeat.Any();
			ICarrierMovement m2 = MockRepository.GenerateStrictMock<ICarrierMovement>();
			m2.Expect(m => m.DepartureLocation).Return(c2).Repeat.Any();
			m2.Expect(m => m.DepartureTime).Return(DateTime.UtcNow + new TimeSpan(72, 0, 0)).Repeat.Any();
			ISchedule empty = new Schedule();
			ISchedule schedule1 = empty.Append(m1);
		
			// act:
			ISchedule schedule2 = schedule1.Append(m2);
		
			// assert:
			Assert.IsFalse(schedule2.Equals(empty));
			Assert.IsFalse(schedule2.Equals(schedule1));
			Assert.AreSame(m1, schedule2[0]);
			Assert.AreSame(m2, schedule2[1]);
			Assert.AreEqual(2, schedule2.Count());			
			Assert.AreEqual(2, schedule2.MovementsCount);
			m1.VerifyAllExpectations();
			m2.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");
        }
Ejemplo n.º 10
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();
		}
 public Location find(UnLocode unLocode)
 {
     return sessionFactory.GetCurrentSession().
       CreateQuery("from Location where UnLocode = ?").
       SetParameter(0, unLocode).
       UniqueResult<Location>();
 }
        public void testSave()
        {
            var unLocode = new UnLocode("SESTO");

            var trackingId = new TrackingId("XYZ");
            var completionTime = DateTime.Parse("2008-01-01");
            HandlingEvent @event = HandlingEventFactory.createHandlingEvent(completionTime,
                trackingId,
                null,
                unLocode,
                HandlingActivityType.CLAIM,
                null);

            HandlingEventRepository.store(@event);

            flush();

            var result = GenericTemplate.QueryForObjectDelegate(CommandType.Text,
                String.Format("select * from HandlingEvent where sequence_number = {0}", @event.SequenceNumber),
                (r, i) => new {CARGO_ID = r["CARGO_ID"], COMPLETIONTIME = r["COMPLETIONTIME"]});

            Assert.AreEqual(1L, result.CARGO_ID);
            Assert.AreEqual(completionTime, result.COMPLETIONTIME);
            // TODO: the rest of the columns
        }
Ejemplo n.º 13
0
        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));
        }
Ejemplo n.º 14
0
		public void Ctor_withNullPreviousLocation_throwsArgumentNullException ()
		{
			// arrange:
			UnLocode destination = new UnLocode("CDDES");
		
			// act:
			new VoyageEventArgs(null, destination);
		}
Ejemplo n.º 15
0
		public void Ctor_withEmptyName_throwsArgumentNullException ()
		{
			// arrange:
			UnLocode code = new UnLocode("UNLOC");
		
			// act:
			Assert.Throws<ArgumentNullException>(delegate{ new Challenge00.DDDSample.Location.Location(code, string.Empty); });
		}
Ejemplo n.º 16
0
      public void ChangeDestination(TrackingId trackingId, UnLocode destinationUnLocode)
      {
         Cargo cargo = _cargoRepository.Find(trackingId);
         Location destination = _locationRepository.Find(destinationUnLocode);

         RouteSpecification routeSpecification = new RouteSpecification(cargo.RouteSpecification.Origin, destination, cargo.RouteSpecification.ArrivalDeadline);
         cargo.SpecifyNewRoute(routeSpecification);
      }
Ejemplo n.º 17
0
		public void Ctor_withNullDestination_throwsArgumentNullException ()
		{
			// arrange:
			UnLocode previous = new UnLocode("CDPRV");
		
			// act:
			new VoyageEventArgs(previous, null);
		}
Ejemplo n.º 18
0
 public void Ctor__NoUnLoadLocationGiven__ThrowsArgumentNullException(
     VoyageNumber voyage,
     UnLocode loadLocation,
     DateTime loadTime,
     DateTime unloadTime
     )
 {
     Assert.Throws <ArgumentNullException>(() => new Leg(voyage, loadLocation, null, loadTime, unloadTime));
 }
Ejemplo n.º 19
0
 public void Ctor__NoVoyageGiven__ThrowsArgumentNullException(
     UnLocode loadLocation,
     UnLocode unloadLocation,
     DateTime loadTime,
     DateTime unloadTime
     )
 {
     Assert.Throws <ArgumentNullException>(() => new Leg(null, loadLocation, unloadLocation, loadTime, unloadTime));
 }
Ejemplo n.º 20
0
        public void Find()
        {
            var melbourne = new UnLocode("AUMEL");
            Location location = locationRepository.Find(melbourne);
            Assert.IsNotNull(location);
            Assert.AreEqual(melbourne, location.UnLocode);

            Assert.IsNull(locationRepository.Find(new UnLocode("NOLOC")));
        }
        private RouteSpecification GetRouteSpecification(BookNewCargoCommand command)
        {
            var originUnLocode      = new UnLocode(command.Origin);
            var origin              = _locationRepository.Find(originUnLocode);
            var destinationUnLocode = new UnLocode(command.Destination);
            var destination         = _locationRepository.Find(destinationUnLocode);

            return(new RouteSpecification(origin, destination, command.ArrivalDeadline));
        }
Ejemplo n.º 22
0
 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))));
 }
Ejemplo n.º 23
0
 public HandlingActivity(HandlingEventType eventType, UnLocode location)
 {
     if (location == null)
     {
         throw new ArgumentNullException("location");
     }
     EventType = eventType;
     Location  = location;
 }
Ejemplo n.º 24
0
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="previousLocation">
		/// A <see cref="ILocation"/>
		/// </param>
		/// <param name="destinationLocation">
		/// A <see cref="ILocation"/>
		/// </param>
		/// <exception cref="ArgumentNullException">Any argument is <value>null</value>.</exception>
		public VoyageEventArgs (UnLocode previousLocation, UnLocode destinationLocation)
		{
			if (null == previousLocation)
				throw new ArgumentNullException ("previousLocation");
			if (null == destinationLocation)
				throw new ArgumentNullException ("destinationLocation");
			PreviousLocation = previousLocation;
			DestinationLocation = destinationLocation;
		}
Ejemplo n.º 25
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;
		}
Ejemplo n.º 26
0
        public void ChangeDestination(TrackingId trackingId, UnLocode destinationUnLocode)
        {
            Cargo    cargo       = _cargoRepository.Find(trackingId);
            Location destination = _locationRepository.Find(destinationUnLocode);

            RouteSpecification routeSpecification = new RouteSpecification(cargo.RouteSpecification.Origin, destination, cargo.RouteSpecification.ArrivalDeadline);

            cargo.SpecifyNewRoute(routeSpecification);
        }
 private static void RegisterHandlingEvent(Guid cargoId, DateTime time, UnLocode location, HandlingEventType eventType)
 {
     InvokeCommand(new RegisterHandlingEventCommand
     {
         CargoId        = cargoId,
         CompletionTime = time,
         Location       = location.CodeString,
         Type           = eventType
     });
 }
Ejemplo n.º 28
0
        public void Find()
        {
            var      melbourne = new UnLocode("AUMEL");
            Location location  = locationRepository.Find(melbourne);

            Assert.IsNotNull(location);
            Assert.AreEqual(melbourne, location.UnLocode);

            Assert.IsNull(locationRepository.Find(new UnLocode("NOLOC")));
        }
Ejemplo n.º 29
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();
        }
Ejemplo n.º 30
0
 public Location Find(UnLocode unLocode)
 {
     foreach (Location location in SampleLocations.GetAll())
     {
         if (location.UnLocode.Equals(unLocode))
         {
             return(location);
         }
     }
     return(null);
 }
Ejemplo n.º 31
0
        private Location FindLocation(UnLocode unlocode)
        {
            Location location = locationRepository.Find(unlocode);

            if (location == null)
            {
                throw new UnknownLocationException(unlocode);
            }

            return(location);
        }
Ejemplo n.º 32
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;
 }
 public Location find(UnLocode unLocode)
 {
     foreach(Location location in SampleLocations.getAll())
     {
         if(location.UnLocode.Equals(unLocode))
         {
             return location;
         }
     }
     return null;
 }
Ejemplo n.º 34
0
        public void testEquals()
        {
            UnLocode allCaps   = new UnLocode("ABCDE");
            UnLocode mixedCase = new UnLocode("aBcDe");

            Assert.IsTrue(allCaps.Equals(mixedCase));
            Assert.IsTrue(mixedCase.Equals(allCaps));
            Assert.IsTrue(allCaps.Equals(allCaps));

            Assert.IsFalse(allCaps.Equals(null));
            Assert.IsFalse(allCaps.Equals(new UnLocode("FGHIJ")));
        }
Ejemplo n.º 35
0
        public void TestEquals()
        {
            var allCaps = new UnLocode("ABCDE");
            var mixedCase = new UnLocode("aBcDe");

            Assert.IsTrue(allCaps.Equals(mixedCase));
            Assert.IsTrue(mixedCase.Equals(allCaps));
            Assert.IsTrue(allCaps.Equals(allCaps));

            Assert.IsFalse(allCaps.Equals(null));
            Assert.IsFalse(allCaps.Equals(new UnLocode("FGHIJ")));
        }
Ejemplo n.º 36
0
        /// <summary>
        /// Specifies a new route for this cargo.
        /// </summary>
        /// <param name="destination">New destination.</param>
        public virtual void SpecifyNewRoute(UnLocode destination)
        {
            if (destination == null)
            {
                throw new ArgumentNullException("destination");
            }
            RouteSpecification routeSpecification = new RouteSpecification(_routeSpecification.Origin, destination,
                                                                           _routeSpecification.ArrivalDeadline);

            Publish(this, new CargoDestinationChangedEvent(routeSpecification,
                                                           _deliveryStatus.Derive(routeSpecification, _itinerary)));
        }
Ejemplo n.º 37
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);
        }
Ejemplo n.º 38
0
        public TrackingId BookNewCargo(UnLocode originUnLocode, UnLocode destinationUnLocode, DateTime arrivalDeadline)
        {
            Location origin      = _locationRepository.Find(originUnLocode);
            Location destination = _locationRepository.Find(destinationUnLocode);

            RouteSpecification routeSpecification = new RouteSpecification(origin, destination, arrivalDeadline);
            TrackingId         trackingId         = _cargoRepository.NextTrackingId();
            Cargo cargo = new Cargo(trackingId, routeSpecification);

            _cargoRepository.Store(cargo);
            return(trackingId);
        }
Ejemplo n.º 39
0
        public void changeDestination(TrackingId trackingId, UnLocode unLocode)
        {
            var cargo = _cargoRepository.find(trackingId);
            Validate.notNull(cargo, "Can't change destination of non-existing cargo " + trackingId);
            var newDestination = _locationRepository.find(unLocode);

            var routeSpecification = cargo.RouteSpecification.WithDestination(newDestination);
            cargo.SpecifyNewRoute(routeSpecification);

            _cargoRepository.store(cargo);
            _logger.Info("Changed destination for cargo " + trackingId + " to " + routeSpecification.Destination);
        }
Ejemplo n.º 40
0
        public void Ctor_withValidArguments_works()
        {
            // arrange:
            UnLocode code = new UnLocode("UNLOC");
            string   name = "Test Location";

            // act:
            ILocation location = new Challenge00.DDDSample.Location.Location(code, name);

            // assert:
            Assert.AreEqual(code, location.UnLocode);
            Assert.AreEqual(name, location.Name);
        }
Ejemplo n.º 41
0
        private Delivery(HandlingEvent lastHandlingEvent, Itinerary itinerary, RouteSpecification specification)
        {
            _calculatedAt = DateTime.Now;
            _lastEvent    = lastHandlingEvent;

            _misdirected       = CalculateMisdirectionStatus(itinerary, lastHandlingEvent);
            _routingStatus     = CalculateRoutingStatus(itinerary, specification);
            _transportStatus   = CalculateTransportStatus(lastHandlingEvent);
            _lastKnownLocation = CalculateLastKnownLocation(lastHandlingEvent);
            _eta = CalculateEta(itinerary);
            _nextExpectedActivity    = CalculateNextExpectedActivity(specification, itinerary, lastHandlingEvent);
            _isUnloadedAtDestination = CalculateUnloadedAtDestination(specification, lastHandlingEvent);
        }
Ejemplo n.º 42
0
      public TrackingId BookNewCargo(string customerLogin, UnLocode originUnLocode, UnLocode destinationUnLocode, DateTime arrivalDeadline)
      {
         var origin = _locationRepository.Find(originUnLocode);
         var destination = _locationRepository.Find(destinationUnLocode);
         var customer = _customerRepository.Find(customerLogin);

         var routeSpecification = new RouteSpecification(origin, destination, arrivalDeadline);
         var trackingId = _cargoRepository.NextTrackingId();
         var cargo = new Cargo(trackingId, routeSpecification, customer);

         _cargoRepository.Store(cargo);
         return trackingId;
      }
Ejemplo n.º 43
0
		public void Ctor_withValidArguments_works()
		{
			// arrange:
			UnLocode code = new UnLocode("UNLOC");
			string name = "Test Location";
		
			// act:
			ILocation location = new Challenge00.DDDSample.Location.Location(code, name);
		
			// assert:
			Assert.AreEqual(code, location.UnLocode);
			Assert.AreEqual(name, location.Name);
		}
Ejemplo n.º 44
0
        public void Ctor_06()
        {
            // arrange:
            UnLocode  arLocode   = new UnLocode("ARLOC");
            ILocation arLocation = MockRepository.GenerateStrictMock <ILocation>();
            DateTime  dpTime     = DateTime.UtcNow - new TimeSpan(48, 0, 0);
            DateTime  arTime     = DateTime.UtcNow + new TimeSpan(48, 0, 0);

            arLocation.Expect(l => l.UnLocode).Return(arLocode).Repeat.AtLeastOnce();

            // act:
            new CarrierMovement(arLocation, dpTime, arLocation, arTime);
        }
Ejemplo n.º 45
0
        public void Ctor_withValidLocations_works()
        {
            // arrange:
            UnLocode previous    = new UnLocode("CDPRV");
            UnLocode destination = new UnLocode("CDDES");

            // act:
            VoyageEventArgs args = new VoyageEventArgs(previous, destination);

            // assert:
            Assert.AreSame(previous, args.PreviousLocation);
            Assert.AreSame(destination, args.DestinationLocation);
        }
Ejemplo n.º 46
0
        public RouteSpecification(UnLocode origin, UnLocode destination, DateTime arrivalDeadline)
        {
            Origin = origin ?? throw new ArgumentNullException(nameof(origin));

            Destination = destination ?? throw new ArgumentNullException(nameof(destination));

            if (origin.Equals(destination))
            {
                throw new InvalidOperationException("Provided origin and destination are the same");
            }

            ArrivalDeadline = arrivalDeadline;
        }
Ejemplo n.º 47
0
        public override bool WillStopOverAt(ILocation location)
        {
            UnLocode locationCode = location.UnLocode;

            for (int i = _movementIndex; i < Schedule.MovementsCount; ++i)
            {
                if (locationCode.Equals(Schedule[i].ArrivalLocation))
                {
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 48
0
		public void Ctor_withValidLocations_works()
		{
			// arrange:
			UnLocode previous = new UnLocode("CDPRV");
			UnLocode destination = new UnLocode("CDDES");
			
			// act:
			VoyageEventArgs args = new VoyageEventArgs(previous, destination);
		
			// assert:
			Assert.AreSame(previous, args.PreviousLocation);
			Assert.AreSame(destination, args.DestinationLocation);
		}
Ejemplo n.º 49
0
        public TrackingId BookNewCargo(string customerLogin, UnLocode originUnLocode, UnLocode destinationUnLocode, DateTime arrivalDeadline)
        {
            var origin      = _locationRepository.Find(originUnLocode);
            var destination = _locationRepository.Find(destinationUnLocode);
            var customer    = _customerRepository.Find(customerLogin);

            var routeSpecification = new RouteSpecification(origin, destination, arrivalDeadline);
            var trackingId         = _cargoRepository.NextTrackingId();
            var cargo = new Cargo(trackingId, routeSpecification, customer);

            _cargoRepository.Store(cargo);
            return(trackingId);
        }
Ejemplo n.º 50
0
        public CarrierMovement(
            UnLocode departureLocation,
            UnLocode arrivalLocation,
            DateTime departureTime,
            DateTime arrivalTime)
        {
            // TODO: validation

            DepartureLocation = departureLocation;
            ArrivalLocation   = arrivalLocation;
            DepartureTime     = departureTime;
            ArrivalTime       = arrivalTime;
        }
Ejemplo n.º 51
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="previousLocation">
 /// A <see cref="ILocation"/>
 /// </param>
 /// <param name="destinationLocation">
 /// A <see cref="ILocation"/>
 /// </param>
 /// <exception cref="ArgumentNullException">Any argument is <value>null</value>.</exception>
 public VoyageEventArgs(UnLocode previousLocation, UnLocode destinationLocation)
 {
     if (null == previousLocation)
     {
         throw new ArgumentNullException("previousLocation");
     }
     if (null == destinationLocation)
     {
         throw new ArgumentNullException("destinationLocation");
     }
     PreviousLocation    = previousLocation;
     DestinationLocation = destinationLocation;
 }
Ejemplo n.º 52
0
        public void testRegisterNew()
        {
            TrackingId expectedTrackingId = new TrackingId("TRK1");
            UnLocode fromUnlocode = new UnLocode("USCHI");
            UnLocode toUnlocode = new UnLocode("SESTO");

            trackingIdFactory.Expect(t => t.nextTrackingId()).Return(expectedTrackingId);
            locationRepository.Expect(l => l.find(fromUnlocode)).Return(L.CHICAGO);
            locationRepository.Expect(l => l.find(toUnlocode)).Return(L.STOCKHOLM);
            cargoRepository.Expect(c => c.store(Arg<Cargo>.Is.TypeOf));

            TrackingId trackingId = bookingService.bookNewCargo(fromUnlocode, toUnlocode, DateTime.Now);
            Assert.AreEqual(expectedTrackingId, trackingId);
        }
Ejemplo n.º 53
0
        public void Equals_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 leg1 = new Leg(voyage, loc1, loadTime, loc2, unloadTime);
            ILeg leg2 = new Leg(voyage, loc1, loadTime, loc2, unloadTime);
            ILeg leg3 = MockRepository.GenerateStrictMock <ILeg>();

            leg3.Expect(l => l.Voyage).Return(voyageNumber).Repeat.AtLeastOnce();
            leg3.Expect(l => l.LoadLocation).Return(code1).Repeat.AtLeastOnce();
            leg3.Expect(l => l.UnloadLocation).Return(code2).Repeat.AtLeastOnce();
            leg3.Expect(l => l.LoadTime).Return(loadTime).Repeat.AtLeastOnce();
            leg3.Expect(l => l.UnloadTime).Return(unloadTime).Repeat.AtLeastOnce();

            // assert:
            Assert.AreEqual(leg1.GetHashCode(), leg2.GetHashCode());
            Assert.IsTrue(leg1.Equals(leg2));
            Assert.IsTrue(leg1.Equals(leg3));
            Assert.IsTrue(leg2.Equals(leg1));
            Assert.IsTrue(leg2.Equals(leg3));
            Assert.IsTrue(leg1.Equals((object)leg2));
            Assert.IsTrue(leg1.Equals((object)leg3));
            Assert.IsTrue(leg2.Equals((object)leg1));
            Assert.IsTrue(leg2.Equals((object)leg3));
            voyage.VerifyAllExpectations();
            loc1.VerifyAllExpectations();
            loc2.VerifyAllExpectations();
            leg3.VerifyAllExpectations();
        }
Ejemplo n.º 54
0
        public void changeDestination(TrackingId trackingId, UnLocode unLocode)
        {
            var cargo = _cargoRepository.find(trackingId);

            Validate.notNull(cargo, "Can't change destination of non-existing cargo " + trackingId);
            var newDestination = _locationRepository.find(unLocode);

            var routeSpecification = cargo.RouteSpecification.WithDestination(newDestination);

            cargo.SpecifyNewRoute(routeSpecification);

            _cargoRepository.store(cargo);
            _logger.Info("Changed destination for cargo " + trackingId + " to " + routeSpecification.Destination);
        }
 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;
 }
Ejemplo n.º 56
0
        public TrackingId bookNewCargo(UnLocode originUnLocode, UnLocode destinationUnLocode, DateTime arrivalDeadline)
        {
            var trackingId = _trackingIdFactory.nextTrackingId();
            var origin = _locationRepository.find(originUnLocode);
            var destination = _locationRepository.find(destinationUnLocode);
            var routeSpecification = new RouteSpecification(origin, destination, arrivalDeadline);

            var cargo = new Cargo(trackingId, routeSpecification);
            _cargoRepository.store(cargo);

            _logger.Info("Booked new cargo with tracking id " + cargo.TrackingId.Value);

            return cargo.TrackingId;
        }
Ejemplo n.º 57
0
 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;
 }
Ejemplo n.º 58
0
		public RouteSpecification (ILocation origin, ILocation destination, DateTime arrivalDeadline)
		{
			if(null == origin || origin is Unknown)
				throw new ArgumentNullException("origin");
			if(null == destination || destination is Unknown)
				throw new ArgumentNullException("destination");
			if(origin.UnLocode.Equals(destination.UnLocode))
				throw new ArgumentException("Origin and destination can't be the same: " + origin.UnLocode);
			if(arrivalDeadline <= DateTime.UtcNow)
				throw new ArgumentException("Arrival deadline can't be in the past: " + arrivalDeadline);
			
			_origin = origin.UnLocode;
			_destination = destination.UnLocode;
			_arrivalDeadline = arrivalDeadline;
		}
Ejemplo n.º 59
0
        public TrackingId bookNewCargo(UnLocode originUnLocode, UnLocode destinationUnLocode, DateTime arrivalDeadline)
        {
            var trackingId         = _trackingIdFactory.nextTrackingId();
            var origin             = _locationRepository.find(originUnLocode);
            var destination        = _locationRepository.find(destinationUnLocode);
            var routeSpecification = new RouteSpecification(origin, destination, arrivalDeadline);

            var cargo = new Cargo(trackingId, routeSpecification);

            _cargoRepository.store(cargo);

            _logger.Info("Booked new cargo with tracking id " + cargo.TrackingId.Value);

            return(cargo.TrackingId);
        }
Ejemplo n.º 60
0
        public void TestCreateHandlingEventUnknownLocation()
        {
            cargoRepositoryMock.Setup(rep => rep.Find(trackingId)).Returns(cargo);

            UnLocode invalid = new UnLocode("NOEXT");
            try
            {
                DateTime completionTime = DateTime.Now.AddDays(10);
                factory.CreateHandlingEvent(
                    DateTime.Now, completionTime, trackingId, SampleVoyages.CM001.voyageNumber, invalid,
                    HandlingType.LOAD
                    );
                Assert.Fail("Expected UnknownLocationException");
            }
            catch (UnknownLocationException expected) {}
        }