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 VerifyingExceptionIfEventIsNotAttached()
        {
            IWithEvents events = MockRepository.Mock <IWithEvents>();

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

            Assert.Throws <ExpectationViolationException>(
                () => events.VerifyExpectations());
        }
Ejemplo n.º 3
0
        public void VerifyingThatEventWasAttached()
        {
            IWithEvents events = (IWithEvents)mocks.StrictMock(typeof(IWithEvents));

            events.Blah += new EventHandler(events_Blah);
            mocks.ReplayAll();
            MethodThatSubscribeToEventBlah(events);
            mocks.VerifyAll();
        }
Ejemplo n.º 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());
        }
Ejemplo n.º 5
0
        public void VerifyingThatEventWasAttached()
        {
            IWithEvents events = MockRepository.Mock <IWithEvents>();

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

            MethodThatSubscribeToEventBlah(events);

            events.VerifyExpectations();
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 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());
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 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]));
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 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);
            });
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 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 }));
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 28
0
 private void MethodUnderTest(IWithEvents events)
 {
     events.Blah += new EventHandler(events_Blah);
 }
Ejemplo n.º 29
0
 public void MethodThatSubscribeToEventBlah(IWithEvents events)
 {
     events.Blah += new EventHandler(events_Blah);
 }
Ejemplo n.º 30
0
 public void MethodThatSubscribeToEventBlah(IWithEvents events)
 {
     events.Blah += new EventHandler(events_Blah);
 }