Example #1
0
		public void Claim_atFinalArrivalLocation_dontBlockExceptionsFromCurrentState()
		{
			// arrange:
			GList mocks = new GList();
			DateTime date = DateTime.Now + TimeSpan.FromDays(1);
			Exception eThrown = new Exception("Catch me.");
			TrackingId identifier = new TrackingId("CARGO01");
			ILocation location = MockRepository.GenerateStrictMock<ILocation>();
			mocks.Add(location);
			IRouteSpecification route = MockRepository.GenerateStrictMock<IRouteSpecification>();
			mocks.Add(route);
			
			CargoState mockState1 = MockRepository.GeneratePartialMock<CargoState>(identifier, route);
			mockState1.Expect(s => s.Claim(location, date)).Throw(eThrown);
			mocks.Add(mockState1);
			
			HandlingEventArgs eventArguments = null;
			ICargo eventSender = null;
		
			// act:
			TCargo underTest = new FakeCargo(mockState1);
			underTest.Claimed += delegate(object sender, HandlingEventArgs e) {
				eventArguments = e;
				eventSender = sender as ICargo;
			};
			Assert.Throws<Exception>(delegate { underTest.Claim(location, date); }, "Catch me.");
		
			// assert:
			Assert.IsNull(eventArguments);
			Assert.IsNull(eventSender);
			foreach(object mock in mocks)
				mock.VerifyAllExpectations();
		}
Example #2
0
		public void Claim_atFinalArrivalLocation_delegateLogicToCurrentState()
		{
			// arrange:
			GList mocks = new GList();
			TrackingId identifier = new TrackingId("CARGO01");
			DateTime date = DateTime.Now + TimeSpan.FromDays(1);
			UnLocode unlocode = new UnLocode("FINAL");
			ILocation location = MockRepository.GenerateStrictMock<ILocation>();
			mocks.Add(location);
			IRouteSpecification route = MockRepository.GenerateStrictMock<IRouteSpecification>();
			mocks.Add(route);
			IRouteSpecification route2 = MockRepository.GenerateStrictMock<IRouteSpecification>();
			mocks.Add(route2);
			CargoState mockState1 = MockRepository.GeneratePartialMock<CargoState>(identifier, route);
			CargoState mockState2 = MockRepository.GeneratePartialMock<CargoState>(mockState1, route2);
			mockState1.Expect(s => s.Claim(location, date)).Return(mockState2).Repeat.Once();
			mockState1.Expect(s => s.Equals(mockState2)).Return(false).Repeat.Any();
			mockState2.Expect(s => s.LastKnownLocation).Return(unlocode).Repeat.AtLeastOnce();
			mockState2.Expect(s => s.TransportStatus).Return(TransportStatus.Claimed).Repeat.AtLeastOnce();
			mocks.Add(mockState1);
			mocks.Add(mockState2);
			
			HandlingEventArgs eventArguments = null;
			ICargo eventSender = null;
		
			// act:
			TCargo underTest = new FakeCargo(mockState1);
			underTest.Claimed += delegate(object sender, HandlingEventArgs e) {
				eventArguments = e;
				eventSender = sender as ICargo;
			};
			underTest.Claim(location, date);
		
			// assert:
			Assert.AreEqual(TransportStatus.Claimed, underTest.Delivery.TransportStatus);
			Assert.AreSame(unlocode, underTest.Delivery.LastKnownLocation);
			Assert.IsNotNull(eventArguments);
			Assert.AreSame(unlocode, eventArguments.Delivery.LastKnownLocation);
			Assert.AreSame(underTest, eventSender);
			foreach(object mock in mocks)
				mock.VerifyAllExpectations();
		}