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 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 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 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 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 = 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(); }