示例#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();
        }
示例#2
0
        public void VerifyingExceptionIfEventIsNotAttached()
        {
            IWithEvents events = MockRepository.Mock <IWithEvents>();

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

            Assert.Throws <ExpectationViolationException>(
                () => events.VerifyExpectations());
        }
示例#3
0
        public void VerifyingThatEventWasAttached()
        {
            IWithEvents events = (IWithEvents)mocks.StrictMock(typeof(IWithEvents));

            events.Blah += new EventHandler(events_Blah);
            mocks.ReplayAll();
            MethodThatSubscribeToEventBlah(events);
            mocks.VerifyAll();
        }
示例#4
0
        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());
        }
示例#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 = (IWithEvents)mocks.StrictMock(typeof(IWithEvents));

            events.Blah += new EventHandler(events_Blah);
            LastCall.IgnoreArguments();
            mocks.ReplayAll();
            events.Blah += new EventHandler(events_Blah_Other);
            mocks.VerifyAll();
        }
示例#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 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();
        }
示例#10
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();
        }
示例#11
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]));
        }
示例#12
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));
        }
示例#13
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();
        }
示例#14
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);
        }
示例#15
0
        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));
        }
示例#16
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();
        }
示例#17
0
        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);
            });
        }
示例#18
0
        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);
        }
示例#19
0
        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);
        }
示例#20
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();
        }
示例#21
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 }));
        }
示例#22
0
        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);
        }
示例#23
0
        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();
        }
示例#24
0
        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);
        }
示例#25
0
        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);
        }
示例#26
0
        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();
        }
示例#27
0
        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();
        }
示例#28
0
 private void MethodUnderTest(IWithEvents events)
 {
     events.Blah += new EventHandler(events_Blah);
 }
示例#29
0
 public void MethodThatSubscribeToEventBlah(IWithEvents events)
 {
     events.Blah += new EventHandler(events_Blah);
 }
 public void MethodThatSubscribeToEventBlah(IWithEvents events)
 {
     events.Blah += new EventHandler(events_Blah);
 }