public void RaiseEvent() { IWithEvents eventHolder = MockRepository.Mock <IWithEvents>(); eventHolder.SetUnexpectedBehavior(UnexpectedCallBehaviors.BaseOrDefault); eventHolder.ExpectEvent(x => x.Blah += null) .IgnoreArguments(); eventHolder.Expect(x => x.RaiseEvent()) .DoInstead(new System.Threading.ThreadStart(delegate() { eventHolder.Raise(x => x.Blah += null, new object[] { this, EventArgs.Empty }); })); IEventSubscriber eventSubscriber = MockRepository.Mock <IEventSubscriber>(); eventSubscriber.SetUnexpectedBehavior(UnexpectedCallBehaviors.BaseOrDefault); eventSubscriber.Expect(x => x.Hanlder(this, EventArgs.Empty)); eventHolder.Blah += new EventHandler(eventSubscriber.Hanlder); eventHolder.RaiseEvent(); eventHolder.VerifyExpectations(); eventSubscriber.VerifyExpectations(); }
public void VerifyingExceptionIfEventIsNotAttached() { IWithEvents events = MockRepository.Mock <IWithEvents>(); events.ExpectEvent(x => x.Blah += new EventHandler(events_Blah)); Assert.Throws <ExpectationViolationException>( () => events.VerifyExpectations()); }
public void VerifyingThatEventWasAttached() { IWithEvents events = (IWithEvents)mocks.StrictMock(typeof(IWithEvents)); events.Blah += new EventHandler(events_Blah); mocks.ReplayAll(); MethodThatSubscribeToEventBlah(events); mocks.VerifyAll(); }
public void VerifyingExceptionIfEventIsNotAttached() { IWithEvents events = (IWithEvents)mocks.StrictMock(typeof(IWithEvents)); events.Blah += new EventHandler(events_Blah); mocks.ReplayAll(); Assert.Throws <ExpectationViolationException>("IWithEvents.add_Blah(System.EventHandler); Expected #1, Actual #0.", () => mocks.VerifyAll()); }
public void VerifyingThatEventWasAttached() { IWithEvents events = MockRepository.Mock <IWithEvents>(); events.ExpectEvent(x => x.Blah += new EventHandler(events_Blah)); MethodThatSubscribeToEventBlah(events); events.VerifyExpectations(); }
public void VerifyingThatCanAttackOtherEvent() { IWithEvents events = (IWithEvents)mocks.StrictMock(typeof(IWithEvents)); events.Blah += new EventHandler(events_Blah); LastCall.IgnoreArguments(); mocks.ReplayAll(); events.Blah += new EventHandler(events_Blah_Other); mocks.VerifyAll(); }
public void VerifyingThatEventWasAttached() { IWithEvents events = MockRepository.Mock <IWithEvents>(); events.SetUnexpectedBehavior(UnexpectedCallBehaviors.BaseOrDefault); events.ExpectEvent(x => x.Blah += new EventHandler(events_Blah)); MethodThatSubscribeToEventBlah(events); events.VerifyExpectations(); }
public void VerifyingExceptionIfEventIsNotAttached() { IWithEvents events = MockRepository.Mock <IWithEvents>(); events.SetUnexpectedBehavior(UnexpectedCallBehaviors.BaseOrDefault); events.ExpectEvent(x => x.Blah += new EventHandler(events_Blah)); Assert.Throws <ExpectationViolationException>( () => events.VerifyExpectations()); }
public void CanSetExpectationToUnsubscribeFromEvent() { IWithEvents events = (IWithEvents)mocks.StrictMock(typeof(IWithEvents)); events.Blah += new EventHandler(events_Blah); events.Blah -= new EventHandler(events_Blah); mocks.ReplayAll(); events.Blah += new EventHandler(events_Blah); events.Blah -= new EventHandler(events_Blah); mocks.VerifyAll(); }
public void VerifyingThatCanAttackOtherEvent() { IWithEvents events = MockRepository.Mock <IWithEvents>(); events.ExpectEvent(x => x.Blah += new EventHandler(events_Blah)) .IgnoreArguments(); events.Blah += new EventHandler(events_Blah_Other); events.VerifyExpectations(); }
public void BetterErrorMessageOnIncorrectParametersCount() { IWithEvents events = MockRepository.Mock <IWithEvents>(); events.ExpectEvent(x => x.Blah += null) .IgnoreArguments(); events.Blah += delegate { }; Assert.Throws <InvalidOperationException>( () => events.Raise(x => x.Blah += null, new object[0])); }
public void BetterErrorMessageOnIncorrectParameters() { IWithEvents events = (IWithEvents)mocks.StrictMock(typeof(IWithEvents)); events.Blah += null; raiser = LastCall.IgnoreArguments().GetEventRaiser(); mocks.ReplayAll(); events.Blah += delegate { }; Assert.Throws <InvalidOperationException>( "Parameter #2 is System.Int32 but should be System.EventArgs", () => raiser.Raise("", 1)); }
public void VerifyingThatCanAttackOtherEvent() { IWithEvents events = MockRepository.Mock <IWithEvents>(); events.SetUnexpectedBehavior(UnexpectedCallBehaviors.BaseOrDefault); events.ExpectEvent(x => x.Blah += new EventHandler(events_Blah)) .IgnoreArguments(); events.Blah += new EventHandler(events_Blah_Other); events.VerifyExpectations(); }
public void RaiseEventUsingExtensionMethod() { IWithEvents eventHolder = (IWithEvents)mocks.Stub(typeof(IWithEvents)); bool called = false; eventHolder.Blah += delegate { called = true; }; eventHolder.Raise(stub => stub.Blah += null, this, EventArgs.Empty); Assert.True(called); }
public void BetterErrorMessageOnIncorrectParametersCount() { IWithEvents events = (IWithEvents)mocks.StrictMock(typeof(IWithEvents)); events.Blah += null; raiser = LastCall.IgnoreArguments().GetEventRaiser(); mocks.ReplayAll(); events.Blah += delegate { }; Assert.Throws <InvalidOperationException>( "You have called the event raiser with the wrong number of parameters. Expected 2 but was 0", () => raiser.Raise(null)); }
public void CanSetExpectationToUnsubscribeFromEvent() { IWithEvents events = MockRepository.Mock <IWithEvents>(); events.ExpectEvent(x => x.Blah += new EventHandler(events_Blah)); events.ExpectEvent(x => x.Blah -= new EventHandler(events_Blah)); events.Blah += new EventHandler(events_Blah); events.Blah -= new EventHandler(events_Blah); events.VerifyExpectations(); }
public void VerifyingThatEventWasAttached() { MockRepository mocks = new MockRepository(); IWithEvents events = mocks.StrictMock <IWithEvents>(); With.Mocks(mocks).Expecting(delegate { events.Blah += new EventHandler(events_Blah); }) .Verify(delegate { MethodThatSubscribeToEventBlah(events); }); }
public void RaiseEventUsingExtensionMethod() { IWithEvents eventHolder = MockRepository.Mock <IWithEvents>(); bool called = false; eventHolder.Blah += delegate { called = true; }; eventHolder.Raise(stub => stub.Blah += null, EventArgs.Empty); Assert.True(called); }
public void UsingEvents_Interface() { LogInvocationInterceptor logger = new LogInvocationInterceptor(); IWithEvents proxy = (IWithEvents)generator.CreateInterfaceProxyWithTarget(typeof(IWithEvents), new FakeWithEvents(), logger); Assert.IsNotNull(proxy); proxy.Foo += null; proxy.Foo -= null; Assert.AreEqual(2, logger.Invocations.Count); }
public void CanSetExpectationToUnsubscribeFromEvent() { IWithEvents events = MockRepository.Mock <IWithEvents>(); events.SetUnexpectedBehavior(UnexpectedCallBehaviors.BaseOrDefault); events.ExpectEvent(x => x.Blah += new EventHandler(events_Blah)); events.ExpectEvent(x => x.Blah -= new EventHandler(events_Blah)); events.Blah += new EventHandler(events_Blah); events.Blah -= new EventHandler(events_Blah); events.VerifyExpectations(); }
public void BetterErrorMessageOnIncorrectParameters() { IWithEvents events = MockRepository.Mock <IWithEvents>(); events.SetUnexpectedBehavior(UnexpectedCallBehaviors.BaseOrDefault); events.ExpectEvent(x => x.Blah += null) .IgnoreArguments(); events.Blah += delegate { }; Assert.Throws <InvalidOperationException>( () => events.Raise(x => x.Blah += null, new object[] { "", 1 })); }
public void RaiseEventUsingExtensionMethod() { IWithEvents eventHolder = MockRepository.Mock <IWithEvents>(); eventHolder.SetUnexpectedBehavior(UnexpectedCallBehaviors.BaseOrDefault); bool called = false; eventHolder.Blah += delegate { called = true; }; eventHolder.Raise(stub => stub.Blah += null, EventArgs.Empty); Assert.True(called); }
public void UsingEventRaiserFromExtensionMethod() { IWithEvents eventHolder = MockRepository.Mock <IWithEvents>(); eventHolder.StubEvent(x => x.Blah += null); bool called = false; eventHolder.Blah += delegate { called = true; }; eventHolder.Raise(x => x.Blah += null, EventArgs.Empty); Assert.True(called); eventHolder.VerifyAllExpectations(); }
public void UsingEventRaiserCreate() { IWithEvents eventHolder = (IWithEvents)mocks.Stub(typeof(IWithEvents)); IEventRaiser eventRaiser = EventRaiser.Create(eventHolder, "Blah"); bool called = false; eventHolder.Blah += delegate { called = true; }; mocks.ReplayAll(); eventRaiser.Raise(this, EventArgs.Empty); mocks.VerifyAll(); Assert.True(called); }
public void UsingEventRaiserFromExtensionMethod() { IWithEvents eventHolder = (IWithEvents)mocks.Stub(typeof(IWithEvents)); IEventRaiser eventRaiser = eventHolder.GetEventRaiser(stub => stub.Blah += null); mocks.ReplayAll(); bool called = false; eventHolder.Blah += delegate { called = true; }; eventRaiser.Raise(this, EventArgs.Empty); mocks.VerifyAll(); Assert.True(called); }
public void UsingEventRaiserCreate() { IWithEvents eventHolder = MockRepository.Mock <IWithEvents>(); eventHolder.SetUnexpectedBehavior(UnexpectedCallBehaviors.BaseOrDefault); eventHolder.ExpectEvent(x => x.Blah += null); bool called = false; eventHolder.Blah += delegate { called = true; }; eventHolder.Raise(x => x.Blah += null, EventArgs.Empty); Assert.True(called); eventHolder.VerifyExpectations(); }
public void RaiseEvent() { IWithEvents eventHolder = (IWithEvents)mocks.StrictMock(typeof(IWithEvents)); eventHolder.Blah += null; LastCall.IgnoreArguments(); raiser = LastCall.GetEventRaiser(); eventHolder.RaiseEvent(); LastCall.Do(new System.Threading.ThreadStart(UseEventRaiser)); IEventSubscriber eventSubscriber = (IEventSubscriber)mocks.StrictMock(typeof(IEventSubscriber)); eventSubscriber.Hanlder(this, EventArgs.Empty); mocks.ReplayAll(); eventHolder.Blah += new EventHandler(eventSubscriber.Hanlder); eventHolder.RaiseEvent(); mocks.VerifyAll(); }
private void MethodUnderTest(IWithEvents events) { events.Blah += new EventHandler(events_Blah); }
public void MethodThatSubscribeToEventBlah(IWithEvents events) { events.Blah += new EventHandler(events_Blah); }