Example #1
0
		public void Claim_atFinalArrivalLocation_dontCallUnsubscribedHandlersOf_Claimed()
		{
			// arrange:
			GList mocks = new GList();
			TrackingId identifier = new TrackingId("CARGO01");
			VoyageNumber voyageNumber = new VoyageNumber("VYG001");
			DateTime arrivalDate = DateTime.Now + TimeSpan.FromDays(30);
			DateTime recieveDate = DateTime.Now + TimeSpan.FromDays(1);
			UnLocode recUnLocode = new UnLocode("RECLC");
			UnLocode endUnLocode = new UnLocode("FINAL");
			IVoyage voyage = MockRepository.GenerateStrictMock<IVoyage>();
			voyage.Expect(v => v.IsMoving).Return(false).Repeat.AtLeastOnce();
			voyage.Expect(v => v.Number).Return(voyageNumber).Repeat.AtLeastOnce();
			voyage.Expect(v => v.LastKnownLocation).Return(recUnLocode).Repeat.Twice();
			voyage.Expect(v => v.LastKnownLocation).Return(endUnLocode).Repeat.Once();
			mocks.Add(voyage);
			ILocation recLocation = MockRepository.GenerateStrictMock<ILocation>();
			recLocation.Expect(l => l.UnLocode).Return(recUnLocode).Repeat.AtLeastOnce();
			mocks.Add(recLocation);
			ILocation clmLocation = MockRepository.GenerateStrictMock<ILocation>();
			clmLocation.Expect(l => l.UnLocode).Return(endUnLocode).Repeat.AtLeastOnce();
			mocks.Add(clmLocation);
			IItinerary itinerary = MockRepository.GenerateStrictMock<IItinerary>();
			itinerary.Expect(i => i.Equals(null)).Return(false).Repeat.Any();
			itinerary.Expect(i => i.FinalArrivalDate).Return(arrivalDate).Repeat.Any();
			itinerary.Expect(i => i.FinalArrivalLocation).Return(endUnLocode).Repeat.Any();
			itinerary.Expect(i => i.InitialDepartureLocation).Return(recUnLocode).Repeat.Any();
			mocks.Add(itinerary);
			IRouteSpecification route = MockRepository.GenerateStrictMock<IRouteSpecification>();
			route.Expect(r => r.IsSatisfiedBy(itinerary)).Return(true).Repeat.AtLeastOnce();
			mocks.Add(route);
			HandlingEventArgs eventArguments = null;
			ICargo eventSender = null;
		
			// act:
			EventHandler<HandlingEventArgs> handler = delegate(object sender, HandlingEventArgs e) {
				eventArguments = e;
				eventSender = sender as ICargo;
			};
			TCargo underTest = new TCargo(identifier, route);
			underTest.AssignToRoute(itinerary);
			underTest.Recieve(recLocation, recieveDate);
			underTest.LoadOn(voyage, recieveDate + TimeSpan.FromDays(1));
			underTest.Unload(voyage, recieveDate + TimeSpan.FromDays(10));
			underTest.Claimed += handler;
			underTest.Claimed -= handler;
			underTest.Claim(clmLocation, recieveDate + TimeSpan.FromDays(11));
		
			// assert:
			Assert.IsNull(eventArguments);
			Assert.IsNull(eventSender);
			foreach(object mock in mocks)
				mock.VerifyAllExpectations();
		}
Example #2
0
		public void Unload_fromVoyage_resetCurrentVoyage()
		{
			// arrange:
			GList mocks = new GList();
			VoyageNumber voyageNumber = new VoyageNumber("VYG001");
			TrackingId identifier = new TrackingId("CARGO01");
			DateTime arrivalDate = DateTime.Now + TimeSpan.FromDays(30);
			DateTime recDate = DateTime.Now + TimeSpan.FromHours(1);
			DateTime loadDate = DateTime.Now + TimeSpan.FromDays(1);
			UnLocode initialLocation = new UnLocode("INITL");
			UnLocode finalLocation = new UnLocode("FINAL");
			ILocation recLocation = MockRepository.GenerateStrictMock<ILocation>();
			recLocation.Expect(l => l.UnLocode).Return(initialLocation).Repeat.AtLeastOnce();
			mocks.Add(recLocation);
			IVoyage voyage = MockRepository.GenerateStrictMock<IVoyage>();
			voyage.Expect(v => v.IsMoving).Return(false).Repeat.AtLeastOnce();
			voyage.Expect(v => v.Number).Return(voyageNumber).Repeat.AtLeastOnce();
			voyage.Expect(v => v.LastKnownLocation).Return(initialLocation).Repeat.Twice();
			voyage.Expect(v => v.LastKnownLocation).Return(finalLocation).Repeat.Once();
			mocks.Add(voyage);
			IItinerary itinerary = MockRepository.GenerateStrictMock<IItinerary>();
			itinerary.Expect(i => i.Equals(null)).Return(false).Repeat.Any();
			itinerary.Expect(i => i.FinalArrivalDate).Return(arrivalDate).Repeat.Any();
			itinerary.Expect(i => i.FinalArrivalLocation).Return(finalLocation).Repeat.Any();
			itinerary.Expect(i => i.InitialDepartureLocation).Return(initialLocation).Repeat.Any();
			mocks.Add(itinerary);
			IRouteSpecification route = MockRepository.GenerateStrictMock<IRouteSpecification>();
			route.Expect(r => r.IsSatisfiedBy(itinerary)).Return(true).Repeat.AtLeastOnce();
			mocks.Add(route);
		
			// act:
			TCargo underTest = new TCargo(identifier, route);
			underTest.AssignToRoute(itinerary);
			underTest.Recieve(recLocation, recDate);
			underTest.LoadOn(voyage, loadDate);
			underTest.Unload(voyage, loadDate + TimeSpan.FromDays(10));
		
			// assert:
			Assert.IsNull(underTest.Delivery.CurrentVoyage);
			foreach(object mock in mocks)
				mock.VerifyAllExpectations();
		}
Example #3
0
		public void Claim_atFinalArrivalLocation_setTheTransportStatusToClaimed()
		{
			// arrange:
			GList mocks = new GList();
			TrackingId identifier = new TrackingId("CARGO01");
			VoyageNumber voyageNumber = new VoyageNumber("VYG001");
			DateTime arrivalDate = DateTime.Now + TimeSpan.FromDays(30);
			DateTime recieveDate = DateTime.Now + TimeSpan.FromDays(1);
			UnLocode recUnLocode = new UnLocode("RECLC");
			UnLocode endUnLocode = new UnLocode("FINAL");
			IVoyage voyage = MockRepository.GenerateStrictMock<IVoyage>();
			voyage.Expect(v => v.IsMoving).Return(false).Repeat.AtLeastOnce();
			voyage.Expect(v => v.Number).Return(voyageNumber).Repeat.AtLeastOnce();
			voyage.Expect(v => v.LastKnownLocation).Return(recUnLocode).Repeat.Twice();
			voyage.Expect(v => v.LastKnownLocation).Return(endUnLocode).Repeat.Once();
			mocks.Add(voyage);
			ILocation recLocation = MockRepository.GenerateStrictMock<ILocation>();
			recLocation.Expect(l => l.UnLocode).Return(recUnLocode).Repeat.AtLeastOnce();
			mocks.Add(recLocation);
			ILocation clmLocation = MockRepository.GenerateStrictMock<ILocation>();
			clmLocation.Expect(l => l.UnLocode).Return(endUnLocode).Repeat.AtLeastOnce();
			mocks.Add(clmLocation);
			IItinerary itinerary = MockRepository.GenerateStrictMock<IItinerary>();
			itinerary.Expect(i => i.Equals(null)).Return(false).Repeat.Any();
			itinerary.Expect(i => i.FinalArrivalDate).Return(arrivalDate).Repeat.Any();
			itinerary.Expect(i => i.FinalArrivalLocation).Return(endUnLocode).Repeat.Any();
			itinerary.Expect(i => i.InitialDepartureLocation).Return(recUnLocode).Repeat.Any();
			mocks.Add(itinerary);
			IRouteSpecification route = MockRepository.GenerateStrictMock<IRouteSpecification>();
			route.Expect(r => r.IsSatisfiedBy(itinerary)).Return(true).Repeat.AtLeastOnce();
			mocks.Add(route);
		
			// act:
			TCargo underTest = new TCargo(identifier, route);
			underTest.AssignToRoute(itinerary);
			underTest.Recieve(recLocation, recieveDate);
			underTest.LoadOn(voyage, recieveDate + TimeSpan.FromDays(1));
			underTest.Unload(voyage, recieveDate + TimeSpan.FromDays(10));
			underTest.Claim(clmLocation, recieveDate + TimeSpan.FromDays(11));

		
			// assert:
			Assert.AreEqual(TransportStatus.Claimed, underTest.Delivery.TransportStatus);
			foreach(object mock in mocks)
				mock.VerifyAllExpectations();
		}
Example #4
0
		public void LoadOn_Voyage_fireLoaded()
		{
			// arrange:
			GList mocks = new GList();
			VoyageNumber voyageNumber = new VoyageNumber("VYG001");
			TrackingId identifier = new TrackingId("CARGO01");
			DateTime arrivalDate = DateTime.Now + TimeSpan.FromDays(30);
			DateTime recDate = DateTime.Now + TimeSpan.FromHours(1);
			DateTime loadDate = DateTime.Now + TimeSpan.FromDays(1);
			UnLocode initialLocation = new UnLocode("INITL");
			ILocation recLocation = MockRepository.GenerateStrictMock<ILocation>();
			recLocation.Expect(l => l.UnLocode).Return(initialLocation).Repeat.AtLeastOnce();
			mocks.Add(recLocation);
			IVoyage voyage = MockRepository.GenerateStrictMock<IVoyage>();
			voyage.Expect(v => v.IsMoving).Return(false).Repeat.AtLeastOnce();
			voyage.Expect(v => v.Number).Return(voyageNumber).Repeat.AtLeastOnce();
			voyage.Expect(v => v.LastKnownLocation).Return(initialLocation).Repeat.AtLeastOnce();
			mocks.Add(voyage);
			IItinerary itinerary = MockRepository.GenerateStrictMock<IItinerary>();
			itinerary.Expect(i => i.Equals(null)).Return(false).Repeat.Any();
			itinerary.Expect(i => i.FinalArrivalDate).Return(arrivalDate).Repeat.Any();
			itinerary.Expect(i => i.FinalArrivalLocation).Return(new UnLocode("FINAL")).Repeat.Any();
			itinerary.Expect(i => i.InitialDepartureLocation).Return(initialLocation).Repeat.Any();
			mocks.Add(itinerary);
			IRouteSpecification route = MockRepository.GenerateStrictMock<IRouteSpecification>();
			route.Expect(r => r.IsSatisfiedBy(itinerary)).Return(true).Repeat.AtLeastOnce();
			mocks.Add(route);
			HandlingEventArgs eventArguments = null;
			ICargo eventSender = null;
		
			// act:
			EventHandler<HandlingEventArgs> handler = delegate(object sender, HandlingEventArgs e) {
				eventArguments = e;
				eventSender = sender as ICargo;
			};
			TCargo underTest = new TCargo(identifier, route);
			underTest.AssignToRoute(itinerary);
			underTest.Recieve(recLocation, recDate);
			underTest.Loaded += handler;
			underTest.LoadOn(voyage, loadDate);
		
			// assert:
			Assert.IsNotNull(eventArguments);
			Assert.AreSame(underTest.Delivery, eventArguments.Delivery);
			Assert.AreSame(eventSender, underTest);
			foreach(object mock in mocks)
				mock.VerifyAllExpectations();
		}