示例#1
0
		public void Ctor_01()
		{
			// 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(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);
            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.IsFalse(state.IsUnloadedAtDestination);
			Assert.AreSame(id, state.Identifier);
            foreach (object mock in mocks)
                mock.VerifyAllExpectations();
		}
示例#2
0
		public void Equals_01()
		{
            List<object> mocks = new List<object>();

			UnLocode code = new UnLocode("START");
			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(new UnLocode("ENDLC")).Repeat.Any();
            mocks.Add(itinerary);
            IRouteSpecification specification = MockRepository.GenerateStrictMock<IRouteSpecification>();
            specification.Expect(s => s.IsSatisfiedBy(itinerary)).Return(true).Repeat.Any();
			specification.Expect(s => s.Equals(specification)).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:
			CargoState state1 = new InPortCargo(previousState, code, arrival);
			CargoState state2 = new InPortCargo(previousState, code, arrival);
			CargoState state3 = state1.ClearCustoms(location, arrival + TimeSpan.FromDays(1));
		
			// assert:
			Assert.IsTrue(state1.Equals(state1));
			Assert.IsFalse(state1.Equals(state2)); // differente calculation date
			Assert.IsFalse(state1.Equals(state3));
			Assert.IsFalse(state3.Equals(state1));
			Assert.IsFalse(state3.Equals(state2));
            foreach (object mock in mocks)
                mock.VerifyAllExpectations();

		}
示例#3
0
		public void Unload_04()
		{
			// 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();
			InPortCargo state = new InPortCargo(previousState, code, arrival);
		
			// act:
			Assert.Throws<ArgumentNullException>(delegate { state.Unload(null, arrival + TimeSpan.FromDays(2)); });
		
			// assert:
            foreach (object mock in mocks)
                mock.VerifyAllExpectations();

		}
示例#4
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();

		}
示例#5
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();
		}
示例#6
0
		public void LoadOn_02()
		{
			// arrange:
			UnLocode code = new UnLocode("FINAL");
			UnLocode voyageLocation = new UnLocode("OTHER");
			TrackingId id = new TrackingId("CRG01");
			DateTime arrival = DateTime.UtcNow;
			IRouteSpecification specification = MockRepository.GenerateStrictMock<IRouteSpecification>();
			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();
			specification.Expect(s => s.IsSatisfiedBy(itinerary)).Return(true).Repeat.AtLeastOnce();
			CargoState previousState = MockRepository.GenerateStrictMock<CargoState>(id, specification);
			previousState.Expect(s => s.LastKnownLocation).Return(code).Repeat.Any();
			previousState = MockRepository.GenerateStrictMock<CargoState>(previousState, itinerary);
			InPortCargo state = new InPortCargo(previousState, voyageLocation, arrival);
		
			// act:
			Assert.Throws<ArgumentNullException>(delegate { state.LoadOn(null, DateTime.UtcNow + TimeSpan.FromDays(2)); });
		
			// assert:
			itinerary.VerifyAllExpectations();
			specification.VerifyAllExpectations();
		}
示例#7
0
		public void Claim_01()
		{
			// arrange:
			UnLocode code = new UnLocode("FINAL");
			TrackingId id = new TrackingId("CRG01");
			DateTime arrival = DateTime.UtcNow;
			IRouteSpecification specification = MockRepository.GenerateStrictMock<IRouteSpecification>();
			ILocation location = MockRepository.GenerateStrictMock<ILocation>();
			location.Expect(l => l.UnLocode).Return(code).Repeat.AtLeastOnce();
			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();
			specification.Expect(s => s.IsSatisfiedBy(itinerary)).Return(true).Repeat.AtLeastOnce();
			CargoState previousState = MockRepository.GenerateStrictMock<CargoState>(id, specification);
			previousState.Expect(s => s.LastKnownLocation).Return(code).Repeat.Any();
			previousState = MockRepository.GenerateStrictMock<CargoState>(previousState, itinerary);
			InPortCargo state = new InPortCargo(previousState, code, arrival);
		
			// act:
			CargoState newState = state.Claim(location, DateTime.UtcNow + TimeSpan.FromDays(2));
		
			// assert:
			Assert.IsNotNull(newState);
			Assert.IsInstanceOf<ClaimedCargo>(newState);
			location.VerifyAllExpectations();
			itinerary.VerifyAllExpectations();
			specification.VerifyAllExpectations();
		}
示例#8
0
		public void Recieve_01()
		{
			// arrange:
			UnLocode code = new UnLocode("START");
			ILocation location = MockRepository.GenerateStrictMock<ILocation>();
			DateTime arrival = DateTime.UtcNow;
			TrackingId id = new TrackingId("CARGO01");
			IRouteSpecification specification = MockRepository.GenerateStrictMock<IRouteSpecification>();
			CargoState previousState = MockRepository.GenerateStrictMock<CargoState>(id, specification);
			previousState.Expect(s => s.LastKnownLocation).Return(code).Repeat.Any();
			InPortCargo state = new InPortCargo(previousState, code, arrival);
		
			// assert:
			Assert.Throws<InvalidOperationException>(delegate { state.Recieve(location, arrival); });
			specification.VerifyAllExpectations();
			location.VerifyAllExpectations();
		}
示例#9
0
		public void SpecifyNewRoute_05()
		{
			// arrange:
			TrackingId id = new TrackingId("CRG01");
			IRouteSpecification specification = MockRepository.GenerateStrictMock<IRouteSpecification>();
			UnLocode code = new UnLocode("START");
			DateTime arrival = DateTime.UtcNow;
			CargoState previousState = MockRepository.GenerateStrictMock<CargoState>(id, specification);
			previousState.Expect(s => s.LastKnownLocation).Return(code).Repeat.Any();
			InPortCargo state = new InPortCargo(previousState, code, arrival);
			
			// assert:
			Assert.Throws<ArgumentNullException>(delegate {state.SpecifyNewRoute(null);});
		}
示例#10
0
		public void AssignToRoute_01()
		{
			// arrange:
			UnLocode code = new UnLocode("START");
			TrackingId id = new TrackingId("CRG01");
			DateTime arrival = DateTime.UtcNow;
			IRouteSpecification specification = MockRepository.GenerateStrictMock<IRouteSpecification>();
			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();
			IItinerary itinerary2 = MockRepository.GenerateStrictMock<IItinerary>();
			itinerary2.Expect(i => i.Equals(itinerary)).Return(false).Repeat.AtLeastOnce();
			itinerary2.Expect(i => i.FinalArrivalDate).Return(DateTime.UtcNow + TimeSpan.FromDays(1)).Repeat.Any();
			specification.Expect(s => s.IsSatisfiedBy(itinerary)).Return(true).Repeat.AtLeastOnce();
			specification.Expect(s => s.IsSatisfiedBy(itinerary2)).Return(true).Repeat.AtLeastOnce();
			CargoState previousState = MockRepository.GenerateStrictMock<CargoState>(id, specification);
			previousState.Expect(s => s.LastKnownLocation).Return(code).Repeat.Any();
			previousState = MockRepository.GenerateStrictMock<CargoState>(previousState, itinerary);
			InPortCargo state = new InPortCargo(previousState, code, arrival);
		
			// act:
			CargoState newState = state.AssignToRoute(itinerary2);
		
			// assert:
			Assert.IsNotNull(newState);
			Assert.AreNotSame(state, newState);
			Assert.IsTrue(RoutingStatus.Routed == newState.RoutingStatus);
			Assert.IsTrue(state.TransportStatus == newState.TransportStatus);
			itinerary.VerifyAllExpectations();
			itinerary2.VerifyAllExpectations();
			specification.VerifyAllExpectations();
		}
示例#11
0
		public void SpecifyNewRoute_04()
		{
			// arrange:
			TrackingId id = new TrackingId("CRG01");
			IRouteSpecification specification = MockRepository.GenerateStrictMock<IRouteSpecification>();
			UnLocode code = new UnLocode("START");
			DateTime arrival = DateTime.UtcNow;
			IItinerary itinerary = MockRepository.GenerateStrictMock<IItinerary>();
			itinerary.Expect(i => i.FinalArrivalDate).Return(DateTime.UtcNow + TimeSpan.FromDays(1)).Repeat.Any();
			IRouteSpecification specification2 = MockRepository.GenerateStrictMock<IRouteSpecification>();
			specification.Expect(s => s.Equals(specification2)).Return(false).Repeat.Any();
			specification2.Expect(s => s.Equals(specification)).Return(false).Repeat.Any();
			specification.Expect(s => s.IsSatisfiedBy(itinerary)).Return(true).Repeat.Any();
			specification2.Expect(s => s.IsSatisfiedBy(itinerary)).Return(false).Repeat.Any();
			CargoState previousState = MockRepository.GenerateStrictMock<CargoState>(id, specification);
			previousState.Expect(s => s.LastKnownLocation).Return(code).Repeat.Any();
			previousState = MockRepository.GenerateStrictMock<CargoState>(previousState, itinerary);
			InPortCargo state = new InPortCargo(previousState, code, arrival);
			
			// act:
			CargoState newState = state.SpecifyNewRoute(specification2);
		
			// assert:
			Assert.AreSame(specification2, newState.RouteSpecification);
			Assert.IsTrue(RoutingStatus.Misrouted == newState.RoutingStatus);
			Assert.IsTrue(state.TransportStatus == newState.TransportStatus);
			Assert.AreSame(code, newState.LastKnownLocation);
			itinerary.VerifyAllExpectations();
			specification.VerifyAllExpectations();
			specification2.VerifyAllExpectations();
		}
示例#12
0
		public void SpecifyNewRoute_02()
		{
			// arrange:
			TrackingId id = new TrackingId("CRG01");
			IRouteSpecification specification = MockRepository.GenerateStrictMock<IRouteSpecification>();
			UnLocode code = new UnLocode("START");
			ILocation location = MockRepository.GenerateStrictMock<ILocation>();
			location.Expect(l => l.UnLocode).Return(code).Repeat.AtLeastOnce();
			DateTime arrival = DateTime.UtcNow;
			IRouteSpecification specification2 = MockRepository.GenerateStrictMock<IRouteSpecification>();
			specification.Expect(s => s.Equals(specification2)).Return(true).Repeat.Any();
			specification2.Expect(s => s.Equals(specification)).Return(true).Repeat.Any();
			CargoState previousState = MockRepository.GenerateStrictMock<CargoState>(id, specification);
			previousState.Expect(s => s.LastKnownLocation).Return(code).Repeat.Any();
			InPortCargo state = new InPortCargo(previousState, code, arrival);
			
			// act:
			CargoState newState = state.SpecifyNewRoute(specification2);
		
			// assert:
			Assert.AreSame(state, newState);
		}
示例#13
0
		public void ClearCustoms_03()
		{
			// arrange:
			UnLocode code = new UnLocode("START");
			ILocation location = MockRepository.GenerateStrictMock<ILocation>();
			location.Expect(l => l.UnLocode).Return(code).Repeat.AtLeastOnce();
			DateTime arrival = DateTime.UtcNow;
			DateTime customs = arrival - TimeSpan.FromHours(1);
			TrackingId id = new TrackingId("CARGO01");
			IRouteSpecification specification = MockRepository.GenerateStrictMock<IRouteSpecification>();
			CargoState previousState = MockRepository.GenerateStrictMock<CargoState>(id, specification);
			previousState.Expect(s => s.LastKnownLocation).Return(code).Repeat.Any();
			InPortCargo state = new InPortCargo(previousState, code, arrival);
		
			// assert:
			Assert.Throws<ArgumentException>( delegate { state.ClearCustoms(location, customs); });
		}
示例#14
0
		public void ClearCustoms_02()
		{
			// arrange:
			UnLocode code1 = new UnLocode("FSTCD");
			UnLocode code2 = new UnLocode("SNDCD");
			ILocation location1 = MockRepository.GenerateStrictMock<ILocation>();
			location1.Expect(l => l.UnLocode).Return(code1).Repeat.AtLeastOnce();
			ILocation location2 = MockRepository.GenerateStrictMock<ILocation>();
			location2.Expect(l => l.UnLocode).Return(code2).Repeat.AtLeastOnce();
			DateTime arrival = DateTime.UtcNow;
			TrackingId id = new TrackingId("CARGO01");
			IRouteSpecification specification = MockRepository.GenerateStrictMock<IRouteSpecification>();
			CargoState previousState = MockRepository.GenerateStrictMock<CargoState>(id, specification);
			previousState.Expect(s => s.LastKnownLocation).Return(code1).Repeat.Any();
			InPortCargo state = new InPortCargo(previousState, code1, arrival);
		
			// assert:
			Assert.Throws<ArgumentException>( delegate { state.ClearCustoms(location2, DateTime.UtcNow); });
		}	
示例#15
0
		public void ClearCustoms_01()
		{
			// arrange:
			UnLocode code = new UnLocode("START");
			ILocation location = MockRepository.GenerateStrictMock<ILocation>();
			location.Expect(l => l.UnLocode).Return(code).Repeat.AtLeastOnce();
			DateTime arrival = DateTime.UtcNow;
			TrackingId id = new TrackingId("CARGO01");
			IRouteSpecification specification = MockRepository.GenerateStrictMock<IRouteSpecification>();
            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();
            specification.Expect(s => s.IsSatisfiedBy(itinerary)).Return(true).Repeat.Any();
            CargoState previousState = MockRepository.GenerateStrictMock<CargoState>(id, specification);
            previousState = MockRepository.GenerateStrictMock<CargoState>(previousState, specification);
            previousState = MockRepository.GenerateStrictMock<CargoState>(previousState, itinerary);
            previousState.Expect(s => s.LastKnownLocation).Return(code).Repeat.Any();
            InPortCargo state = new InPortCargo(previousState, code, arrival);
		
			// act:
			CargoState newState = state.ClearCustoms(location, DateTime.UtcNow);
		
			// assert:
			Assert.IsNotNull(newState);
			Assert.IsTrue(TransportStatus.InPort == state.TransportStatus);
			Assert.AreSame(code, state.LastKnownLocation);
			Assert.Throws<InvalidOperationException>(delegate { newState.ClearCustoms(location, DateTime.UtcNow); }); // Can't clear customs twice.
			Assert.AreSame(id, state.Identifier);
            Assert.IsFalse(newState.IsUnloadedAtDestination);
            itinerary.VerifyAllExpectations();
            specification.VerifyAllExpectations();
            location.VerifyAllExpectations();
            previousState.VerifyAllExpectations();
		}