Exemple #1
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();

		}
Exemple #2
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();

		}
Exemple #3
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); });
		}	
Exemple #4
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); });
		}
Exemple #5
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();
		}