Esempio n. 1
0
		public void SpecifyNewRoute_withASpecification_dontCallUnsubscribedHandlersOf_NewRouteSpecified()
		{
			// arrange:
			GList mocks = new GList();
			TrackingId identifier = new TrackingId("CARGO01");
			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.SpecifyNewRoute(route2)).Return(mockState2).Repeat.Once();
			mockState1.Expect(s => s.Equals(mockState2)).Return(false).Repeat.Any();
			mocks.Add(mockState1);
			mocks.Add(mockState2);
			
			ChangeEventArgs<IRouteSpecification> eventArguments = null;
			ICargo eventSender = null;
		
			// act:
			EventHandler<ChangeEventArgs<IRouteSpecification>> handler = delegate(object sender, ChangeEventArgs<IRouteSpecification> e) {
				eventArguments = e;
				eventSender = sender as ICargo;
			};
			TCargo underTest = new FakeCargo(mockState1);
			underTest.NewRouteSpecified += handler;
			underTest.NewRouteSpecified -= handler;
			underTest.SpecifyNewRoute(route2);
		
			// assert:
			Assert.AreSame(route2, underTest.RouteSpecification);
			Assert.IsNull(eventArguments);
			Assert.IsNull(eventSender);
			foreach(object mock in mocks)
				mock.VerifyAllExpectations();
		}
Esempio n. 2
0
		public void SpecifyNewRoute_withASpecification_dontBlockExceptionsFromCurrentState()
		{
			// arrange:
			GList mocks = new GList();
			Exception eThrown = new Exception("Catch me.");
			TrackingId identifier = new TrackingId("CARGO01");
			IRouteSpecification route = MockRepository.GenerateStrictMock<IRouteSpecification>();
			mocks.Add(route);
			IRouteSpecification route2 = MockRepository.GenerateStrictMock<IRouteSpecification>();
			mocks.Add(route2);
			CargoState mockState1 = MockRepository.GeneratePartialMock<CargoState>(identifier, route);
			mockState1.Expect(s => s.SpecifyNewRoute(route2)).Throw(eThrown);
			mocks.Add(mockState1);
			
			ChangeEventArgs<IRouteSpecification> eventArguments = null;
			ICargo eventSender = null;
		
			// act:
			TCargo underTest = new FakeCargo(mockState1);
			underTest.NewRouteSpecified += delegate(object sender, ChangeEventArgs<IRouteSpecification> e) {
				eventArguments = e;
				eventSender = sender as ICargo;
			};
			Assert.Throws<Exception>(delegate { underTest.SpecifyNewRoute(route2); }, "Catch me.");
		
			// assert:
			Assert.AreSame(route, underTest.RouteSpecification);
			Assert.IsNull(eventArguments);
			Assert.IsNull(eventSender);
			foreach(object mock in mocks)
				mock.VerifyAllExpectations();
		}