Exemplo n.º 1
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;
		}
Exemplo n.º 2
0
        public void Ctor_09()
        {
            // arrange:
            UnLocode code1      = new UnLocode("UNFST");
            DateTime loadTime   = DateTime.UtcNow;
            DateTime unloadTime = loadTime + TimeSpan.FromDays(1);

            ILocation loc1 = MockRepository.GenerateStrictMock <ILocation>();

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

            ILocation loc2 = MockRepository.GenerateStrictMock <ILocation>();

            loc2.Expect(l => l.UnLocode).Return(new UnLocode("SNDLC")).Repeat.AtLeastOnce();
            IVoyage voyage = MockRepository.GenerateStrictMock <IVoyage>();

            voyage.Expect(v => v.Number).Return(new VoyageNumber("VYGTEST")).Repeat.Once();
            voyage.Expect(v => v.WillStopOverAt(loc1)).Return(true).Repeat.Once();
            voyage.Expect(v => v.WillStopOverAt(loc2)).Return(false).Repeat.Once();

            // assert:
            Assert.Throws <ArgumentException>(delegate { new Leg(voyage, loc1, loadTime, loc2, unloadTime); });
            voyage.VerifyAllExpectations();
            loc1.VerifyAllExpectations();
            loc2.VerifyAllExpectations();
        }
Exemplo n.º 3
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();
        }
Exemplo n.º 4
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();
        }
Exemplo n.º 5
0
 public override CargoState LoadOn(IVoyage voyage, DateTime date)
 {
     if (null == voyage)
     {
         throw new ArgumentNullException("voyage");
     }
     if (voyage.IsMoving)
     {
         string message = string.Format("Can not load the cargo {0} on the voyage {1} since it is moving.", Identifier, voyage.Number);
         throw new ArgumentException(message);
     }
     if (this.IsUnloadedAtDestination)
     {
         string message = string.Format("Can not load the cargo {0} on the voyage {1} since it already reached the destination.", Identifier, voyage.Number);
         throw new InvalidOperationException(message);
     }
     if (!_lastKnownLocation.Equals(voyage.LastKnownLocation))
     {
         string message = string.Format("Can not load the cargo {0} (waiting in {2}) on the voyage {1} since it stopped over at {3}.", Identifier, voyage.Number, _lastKnownLocation, voyage.LastKnownLocation);
         throw new ArgumentException(message);
     }
     if (date < this._date)
     {
         string message = string.Format("The cargo {2} arrived in port at {0}. Can not be loaded on the voyage {3} at {1}.", this._date, date, Identifier, voyage.Number);
         throw new ArgumentException(message, "date");
     }
     return(new OnboardCarrierCargo(this, voyage, date));
 }
Exemplo n.º 6
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();
        }
Exemplo n.º 7
0
Arquivo: Leg.cs Projeto: 3j/dddsample
 internal Leg(IVoyage the_voyage, ILocation the_load_location, ILocation the_unload_location, IDate the_load_time,
              IDate the_unload_time)
 {
     underlying_voyage = the_voyage;
     underlying_load_location = the_load_location;
     underlying_unload_location = the_unload_location;
     underlying_load_time = the_load_time;
     underlying_unload_time = the_unload_time;
 }
Exemplo n.º 8
0
		public override CargoState LoadOn (IVoyage voyage, DateTime date)
		{
			if(null == voyage)
				throw new ArgumentNullException("voyage");
			if(voyage.Number.Equals(_voyage))
				return this;
			string message = string.Format("The cargo {0} is loaded on the voyage {1}, so it can not be loaded on the voyage {2}.", Identifier, _voyage, voyage.Number);
			throw new InvalidOperationException(message);
		}
Exemplo n.º 9
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;
		}
Exemplo n.º 10
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;
 }
Exemplo n.º 11
0
        public void Unload_01()
        {
            // arrange:
            TrackingId          id            = new TrackingId("CRG01");
            IRouteSpecification specification = MockRepository.GenerateStrictMock <IRouteSpecification>();
            IVoyage             voyage        = MockRepository.GenerateMock <IVoyage>();
            CargoState          state         = new NewCargo(id, specification);

            // assert:
            Assert.Throws <InvalidOperationException>(delegate { state.Unload(voyage, DateTime.Now); });
        }
Exemplo n.º 12
0
        public void Ctor_03()
        {
            // arrange:
            DateTime loadTime   = DateTime.UtcNow;
            DateTime unloadTime = DateTime.UtcNow + TimeSpan.FromDays(3);

            IVoyage voyage = MockRepository.GenerateStrictMock <IVoyage>();

            ILocation loc = MockRepository.GenerateStrictMock <ILocation>();

            // assert:
            Assert.Throws <ArgumentNullException>(delegate { new Leg(voyage, null, loadTime, loc, unloadTime); });
        }
Exemplo n.º 13
0
        public override CargoState LoadOn(IVoyage voyage, DateTime date)
        {
            if (null == voyage)
            {
                throw new ArgumentNullException("voyage");
            }
            if (voyage.Number.Equals(_voyage))
            {
                return(this);
            }
            string message = string.Format("The cargo {0} is loaded on the voyage {1}, so it can not be loaded on the voyage {2}.", Identifier, _voyage, voyage.Number);

            throw new InvalidOperationException(message);
        }
Exemplo n.º 14
0
        public override CargoState Unload(IVoyage voyage, DateTime date)
        {
            if (null == voyage)
            {
                throw new ArgumentNullException("voyage");
            }
            if (!_customCleared && _lastKnownLocation.Equals(voyage.LastKnownLocation))
            {
                return(this);
            }
            string message = string.Format("The cargo {0} is waiting at {1}, so it can not be unloaded from the voyage {2}.", Identifier, _lastKnownLocation, voyage.Number);

            throw new InvalidOperationException(message);
        }
Exemplo n.º 15
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();
        }
Exemplo n.º 16
0
        public void WillStopOverAt_nullLocation_throwsArgumentNullException()
        {
            // arrange:
            VoyageNumber number   = new VoyageNumber("VYG01");
            ISchedule    schedule = MockRepository.GenerateStrictMock <ISchedule>();
            VoyageState  state    = MockRepository.GeneratePartialMock <VoyageState>(number, schedule);

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

            // assert:
            Assert.Throws <ArgumentNullException>(delegate { voyage.WillStopOverAt(null); });
            state.VerifyAllExpectations();
            schedule.VerifyAllExpectations();
        }
Exemplo n.º 17
0
        public void Unload_04()
        {
            // arrange:
            GList mocks = new GList();

            UnLocode     code         = new UnLocode("START");
            VoyageNumber voyageNumber = new VoyageNumber("ATEST");
            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();
            voyage.Expect(v => v.LastKnownLocation).Return(code).Repeat.AtLeastOnce();
            voyage.Expect(v => v.IsMoving).Return(false).Repeat.AtLeastOnce();
            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();
            OnboardCarrierCargo state = new OnboardCarrierCargo(previousState, voyage, arrival);

            // act:
            CargoState newState = state.Unload(voyage, arrival + TimeSpan.FromDays(2));

            // assert:
            Assert.IsNotNull(newState);
            Assert.IsInstanceOf <InPortCargo>(newState);
            Assert.AreSame(code, newState.LastKnownLocation);
            foreach (object mock in mocks)
            {
                mock.VerifyAllExpectations();
            }
        }
Exemplo n.º 18
0
        public void StateTransitions_01()
        {
            // arrange:
            UnLocode   final         = new UnLocode("FINAL");
            TrackingId id            = new TrackingId("CLAIM");
            ILocation  finalLocation = MockRepository.GenerateStrictMock <ILocation>();

            finalLocation.Expect(l => l.UnLocode).Return(final).Repeat.AtLeastOnce();
            ILocation otherLocation = MockRepository.GenerateStrictMock <ILocation>();

            otherLocation.Expect(l => l.UnLocode).Return(new UnLocode("OTHER")).Repeat.AtLeastOnce();
            IItinerary itinerary = MockRepository.GenerateStrictMock <IItinerary>();

            itinerary.Expect(i => i.FinalArrivalDate).Return(DateTime.UtcNow).Repeat.Any();
            itinerary.Expect(i => i.FinalArrivalLocation).Return(final).Repeat.Any();
            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.Any();
            previousState.Expect(s => s.TransportStatus).Return(TransportStatus.InPort).Repeat.Any();
            IVoyage  voyage    = MockRepository.GenerateStrictMock <IVoyage>();
            DateTime claimDate = DateTime.UtcNow;

            ClaimedCargo state = new ClaimedCargo(previousState, claimDate);

            // act:
            CargoState newState = state.Claim(finalLocation, claimDate);

            // assert:
            Assert.AreSame(state, newState);
            Assert.Throws <ArgumentNullException>(delegate { state.Claim(null, DateTime.UtcNow); });
            Assert.Throws <InvalidOperationException>(delegate { state.Claim(finalLocation, DateTime.UtcNow + TimeSpan.FromSeconds(10)); });
            Assert.Throws <InvalidOperationException>(delegate { state.Claim(otherLocation, claimDate); });
            Assert.Throws <InvalidOperationException>(delegate { state.LoadOn(voyage, DateTime.UtcNow + TimeSpan.FromSeconds(10)); });
            Assert.Throws <InvalidOperationException>(delegate { state.Unload(voyage, DateTime.UtcNow + TimeSpan.FromSeconds(10)); });
            Assert.Throws <InvalidOperationException>(delegate { state.SpecifyNewRoute(MockRepository.GenerateStrictMock <IRouteSpecification>()); });
            Assert.Throws <InvalidOperationException>(delegate { state.AssignToRoute(MockRepository.GenerateStrictMock <IItinerary>()); });
            Assert.Throws <InvalidOperationException>(delegate { state.Recieve(MockRepository.GenerateStrictMock <ILocation>(), DateTime.UtcNow + TimeSpan.FromSeconds(10) + TimeSpan.FromSeconds(10)); });
            Assert.Throws <InvalidOperationException>(delegate { state.ClearCustoms(MockRepository.GenerateStrictMock <ILocation>(), DateTime.UtcNow + TimeSpan.FromSeconds(10)); });
            itinerary.VerifyAllExpectations();
            specification.VerifyAllExpectations();
        }
Exemplo n.º 19
0
        public void WillStopOverAt_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.WillStopOverAt(location)).Throw(new InvalidOperationException()).Repeat.Once();

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

            // assert:
            Assert.Throws <InvalidOperationException>(delegate { voyage.WillStopOverAt(location); });
            location.VerifyAllExpectations();
            state.VerifyAllExpectations();
            schedule.VerifyAllExpectations();
        }
Exemplo n.º 20
0
        public void LoadOn_02()
        {
            // arrange:
            GList mocks = new GList();

            UnLocode     code         = new UnLocode("START");
            VoyageNumber voyageNumber = new VoyageNumber("ATEST");
            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();
            voyage.Expect(v => v.LastKnownLocation).Return(code).Repeat.AtLeastOnce();
            mocks.Add(voyage);
            IVoyage voyage2 = MockRepository.GenerateStrictMock <IVoyage>();

            voyage2.Expect(v => v.Number).Return(new VoyageNumber("VYGOTHER")).Repeat.Any();
            mocks.Add(voyage2);
            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();
            OnboardCarrierCargo state = new OnboardCarrierCargo(previousState, voyage, arrival);

            // assert:
            Assert.Throws <InvalidOperationException>(delegate { state.LoadOn(voyage2, arrival + TimeSpan.FromDays(2)); });
            foreach (object mock in mocks)
            {
                mock.VerifyAllExpectations();
            }
        }
Exemplo n.º 21
0
        public ILeg create_leg_using(IVoyage the_voyage, ILocation the_load_location, ILocation the_unload_location, IDate the_load_time, IDate the_unload_time)
        {
            if (the_voyage == null)
                throw new ArgumentNullException("the_voyage", "Invariant Violated: a valid voyage is required in order to construct a leg.");

            if (the_load_location == null)
                throw new ArgumentNullException("the_load_location", "Invariant Violated: a valid load location is required in order to construct a leg.");

            if (the_unload_location == null)
                throw new ArgumentNullException("the_unload_location", "Invariant Violated: a valid unload location is required in order to construct a leg.");

            if (the_load_time == null)
                throw new ArgumentNullException("the_load_time", "Invariant Violated: a valid load time is required in order to construct a leg.");

            if (the_unload_time == null)
                throw new ArgumentNullException("the_unload_time", "Invariant Violated: a valid unload time is required in order to construct a leg.");

            return new Leg(the_voyage, the_load_location, the_unload_location, the_load_time, the_unload_time);
        }
Exemplo n.º 22
0
        public void WillStopOverAt_aLocation_delegateLogicToCurrentStateThatReturn(bool returnedValue)
        {
            // arrange:
            VoyageNumber number   = new VoyageNumber("VYG01");
            ILocation    location = MockRepository.GenerateStrictMock <ILocation>();
            ISchedule    schedule = MockRepository.GenerateStrictMock <ISchedule>();
            VoyageState  state    = MockRepository.GeneratePartialMock <VoyageState>(number, schedule);

            state.Expect(s => s.WillStopOverAt(location)).Return(returnedValue).Repeat.Once();

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

            // assert:
            Assert.AreEqual(returnedValue, willStopOverAt);
            location.VerifyAllExpectations();
            state.VerifyAllExpectations();
            schedule.VerifyAllExpectations();
        }
Exemplo n.º 23
0
        public void ClearCustoms_01()
        {
            // arrange:
            GList        mocks        = new GList();
            TrackingId   id           = new TrackingId("START");
            DateTime     loadTime     = DateTime.Now;
            VoyageNumber voyageNumber = new VoyageNumber("VYG001");
            UnLocode     locCode      = new UnLocode("CURLC");
            ILocation    location     = MockRepository.GenerateStrictMock <ILocation>();

            location.Expect(l => l.UnLocode).Return(locCode).Repeat.Any();
            mocks.Add(location);
            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();
            mocks.Add(specification);
            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(locCode).Repeat.AtLeastOnce();
            mocks.Add(voyage);
            CargoState state = new OnboardCarrierCargo(previousState, voyage, loadTime);

            // assert:
            Assert.Throws <InvalidOperationException>(delegate { state.ClearCustoms(location, DateTime.Now + TimeSpan.FromDays(1)); });
            foreach (object mock in mocks)
            {
                mock.VerifyAllExpectations();
            }
        }
Exemplo n.º 24
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();
            }
        }
Exemplo n.º 25
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;
        }
Exemplo n.º 26
0
        public void DepartFrom_aLocation_dontCallUnsubscribedHandlersOf_Departed()
        {
            // arrange:
            VoyageNumber number    = new VoyageNumber("VYG01");
            UnLocode     departure = new UnLocode("DPLOC");
            UnLocode     arrival   = new UnLocode("ARLOC");
            ISchedule    schedule  = MockRepository.GenerateStrictMock <ISchedule>();
            ILocation    location  = MockRepository.GenerateStrictMock <ILocation>();
            VoyageState  state     = MockRepository.GeneratePartialMock <VoyageState>(number, schedule);
            VoyageState  state2    = MockRepository.GeneratePartialMock <VoyageState>(number, schedule);

            state.Expect(s => s.DepartFrom(location)).Return(state2).Repeat.Once();
            state.Expect(s => s.Equals(state2)).Return(false).Repeat.Once();
            state2.Expect(s => s.LastKnownLocation).Return(departure).Repeat.Once();
            state2.Expect(s => s.NextExpectedLocation).Return(arrival).Repeat.Once();
            VoyageEventArgs eventArguments = null;
            IVoyage         eventSender    = null;

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

            EventHandler <VoyageEventArgs> handler = delegate(object sender, VoyageEventArgs e) {
                eventArguments = e;
                eventSender    = sender as IVoyage;
            };

            voyage.Departed += handler;
            voyage.Departed -= handler;
            voyage.DepartFrom(location);

            // assert:
            Assert.AreEqual(number, voyage.Number);
            Assert.IsNull(eventSender);
            Assert.IsNull(eventArguments);
            state.VerifyAllExpectations();
            schedule.VerifyAllExpectations();
            location.VerifyAllExpectations();
            state2.VerifyAllExpectations();
        }
Exemplo n.º 27
0
        public void Ctor_05()
        {
            // arrange:
            UnLocode code       = new UnLocode("UNCOD");
            DateTime loadTime   = DateTime.UtcNow;
            DateTime unloadTime = DateTime.UtcNow + TimeSpan.FromDays(3);

            IVoyage voyage = MockRepository.GenerateStrictMock <IVoyage>();

            ILocation loc1 = MockRepository.GenerateStrictMock <ILocation>();

            loc1.Expect(l => l.UnLocode).Return(code).Repeat.Any();

            ILocation loc2 = MockRepository.GenerateStrictMock <ILocation>();

            loc2.Expect(l => l.UnLocode).Return(code).Repeat.Any();

            // assert:
            Assert.Throws <ArgumentException>(delegate { new Leg(voyage, loc1, loadTime, loc2, unloadTime); });
            loc1.VerifyAllExpectations();
            loc2.VerifyAllExpectations();
        }
Exemplo n.º 28
0
 public override CargoState Unload(IVoyage voyage, DateTime date)
 {
     if (null == voyage)
     {
         throw new ArgumentNullException("voyage");
     }
     if (!voyage.Number.Equals(_voyage))
     {
         string message = string.Format("The cargo {0} is loaded on the voyage {1}, so it can not be unloaded from the voyage {2}.", Identifier, _voyage, voyage.Number);
         throw new ArgumentException(message, "voyage");
     }
     if (voyage.IsMoving)
     {
         string message = string.Format("The cargo {0} is loaded on the voyage {1}, since it's moving to {2}.", Identifier, _voyage, voyage.NextExpectedLocation);
         throw new ArgumentException(message, "voyage");
     }
     if (date < this._date)
     {
         string message = string.Format("The cargo {2} was loaded on the voyage {3} at {0}. Can not be unloaded at {1}.", this._date, date, Identifier, voyage.Number);
         throw new ArgumentException(message, "date");
     }
     return(new InPortCargo(this, voyage.LastKnownLocation, date));
 }
Exemplo n.º 29
0
        public void StopOverAt_nextLocation_fireStopped()
        {
            // arrange:
            VoyageNumber number    = new VoyageNumber("VYG01");
            UnLocode     departure = new UnLocode("DPLOC");
            UnLocode     arrival   = new UnLocode("ARLOC");
            ISchedule    schedule  = MockRepository.GenerateStrictMock <ISchedule>();
            ILocation    location  = MockRepository.GenerateStrictMock <ILocation>();
            VoyageState  state     = MockRepository.GeneratePartialMock <VoyageState>(number, schedule);
            VoyageState  state2    = MockRepository.GeneratePartialMock <VoyageState>(number, schedule);

            state.Expect(s => s.StopOverAt(location)).Return(state2).Repeat.Once();
            state.Expect(s => s.Equals(state2)).Return(false).Repeat.Once();
            state.Expect(s => s.LastKnownLocation).Return(departure).Repeat.Once();
            state.Expect(s => s.NextExpectedLocation).Return(arrival).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.AreSame(voyage, eventSender);
            Assert.AreSame(departure, eventArguments.PreviousLocation);
            Assert.AreSame(arrival, eventArguments.DestinationLocation);
            state.VerifyAllExpectations();
            schedule.VerifyAllExpectations();
            location.VerifyAllExpectations();
            state2.VerifyAllExpectations();
        }
Exemplo n.º 30
0
        public void StopOverAt_nullLocation_throwsArgumentNullException()
        {
            // arrange:
            VoyageNumber    number         = new VoyageNumber("VYG01");
            ISchedule       schedule       = MockRepository.GenerateStrictMock <ISchedule>();
            VoyageState     state          = MockRepository.GeneratePartialMock <VoyageState>(number, schedule);
            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 <ArgumentNullException>(delegate { voyage.StopOverAt(null); });

            // assert:
            Assert.IsNull(eventSender);
            Assert.IsNull(eventArguments);
            state.VerifyAllExpectations();
            schedule.VerifyAllExpectations();
        }
Exemplo n.º 31
0
		public override CargoState Unload (IVoyage voyage, DateTime date)
		{
			if(null == voyage)
				throw new ArgumentNullException("voyage");
			if(!voyage.Number.Equals(_voyage))
			{
				string message = string.Format("The cargo {0} is loaded on the voyage {1}, so it can not be unloaded from the voyage {2}.", Identifier, _voyage, voyage.Number);
				throw new ArgumentException(message, "voyage");
			}
			if(voyage.IsMoving)
			{
				string message = string.Format("The cargo {0} is loaded on the voyage {1}, since it's moving to {2}.", Identifier, _voyage, voyage.NextExpectedLocation);
				throw new ArgumentException(message, "voyage");
			}
			if(date < this._date)
			{
				string message = string.Format("The cargo {2} was loaded on the voyage {3} at {0}. Can not be unloaded at {1}.", this._date, date, Identifier, voyage.Number);
				throw new ArgumentException(message, "date");
			}
			return new InPortCargo(this, voyage.LastKnownLocation, date);
		}
Exemplo n.º 32
0
        public override CargoState Unload(IVoyage voyage, DateTime date)
        {
            string message = string.Format("The cargo {0} has been claimed.", Identifier);

            throw new System.InvalidOperationException(message);
        }