Ejemplo n.º 1
0
        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();
        }
Ejemplo n.º 2
0
        public void VerifyingThatAnEventWasFired()
        {
            IEventSubscriber subscriber = MockRepository.Mock <IEventSubscriber>();

            subscriber.SetUnexpectedBehavior(UnexpectedCallBehaviors.BaseOrDefault);
            IWithEvents events = new WithEvents();

            // This doesn't create an expectation because no method is called on subscriber!!
            events.Blah += new EventHandler(subscriber.Hanlder);
            subscriber.Expect(x => x.Hanlder(events, EventArgs.Empty));

            events.RaiseEvent();

            subscriber.VerifyExpectations();
        }
Ejemplo n.º 3
0
        public void VerifyingThatAnEventWasFiredThrowsForDifferentArgument()
        {
            IEventSubscriber subscriber = MockRepository.Mock <IEventSubscriber>();

            subscriber.SetUnexpectedBehavior(UnexpectedCallBehaviors.BaseOrDefault);
            IWithEvents events = new WithEvents();

            // This doesn't create an expectation because no method is called on subscriber!!
            events.Blah += new EventHandler(subscriber.Hanlder);
            subscriber.Expect(x => x.Hanlder(events, new EventArgs()));

            events.RaiseEvent();

            Assert.Throws <ExpectationViolationException>(
                () => subscriber.VerifyExpectations(true));
        }