Пример #1
0
        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();
        }
Пример #2
0
        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();
        }
Пример #3
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();
        }
Пример #4
0
        public void VerifyingExceptionIfEventIsNotAttached()
        {
            IWithEvents events = MockRepository.Mock <IWithEvents>();

            events.ExpectEvent(x => x.Blah += new EventHandler(events_Blah));

            Assert.Throws <ExpectationViolationException>(
                () => events.VerifyExpectations());
        }
Пример #5
0
        public void VerifyingThatEventWasAttached()
        {
            IWithEvents events = MockRepository.Mock <IWithEvents>();

            events.ExpectEvent(x => x.Blah += new EventHandler(events_Blah));

            MethodThatSubscribeToEventBlah(events);

            events.VerifyExpectations();
        }
Пример #6
0
        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();
        }
Пример #7
0
        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();
        }
Пример #8
0
        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());
        }
Пример #9
0
        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]));
        }
Пример #10
0
        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();
        }
Пример #11
0
        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 }));
        }
Пример #12
0
        public void UsingEventRaiserCreate()
        {
            IWithEvents eventHolder = MockRepository.Mock <IWithEvents>();

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