Exemple #1
0
        public void EventRaiser_ShouldRaiseEvent_OnlyOnce()
        {
            MockRepository mocks    = new MockRepository();
            IWithEvent     mock     = mocks.StrictMock <IWithEvent>();
            int            countOne = 0;
            int            countTwo = 0;

            mock.Load += null;
            IEventRaiser raiser = LastCall.IgnoreArguments()
                                  .Repeat.Twice()
                                  .GetEventRaiser();

            mocks.ReplayAll();
            mock.Load += delegate { countOne++; };
            mock.Load += delegate { countTwo++; };
            raiser.Raise(this, EventArgs.Empty);
            Assert.Equal(1, countOne);
            Assert.Equal(1, countTwo);
            raiser.Raise(this, EventArgs.Empty);
            Assert.Equal(2, countOne);
            Assert.Equal(2, countTwo);
            raiser.Raise(this, EventArgs.Empty);
            Assert.Equal(3, countOne);
            Assert.Equal(3, countTwo);
        }
Exemple #2
0
        public void EventRaiser_ShouldRaiseEvent_OnlyOnce()
        {
            int countOne = 0;
            int countTwo = 0;

            IWithEvent mock = MockRepository.Mock <IWithEvent>();

            mock.SetUnexpectedBehavior(UnexpectedCallBehaviors.BaseOrDefault);

            mock.ExpectEvent(x => x.Load += null)
            .IgnoreArguments();

            mock.Load += delegate { countOne++; };
            mock.Load += delegate { countTwo++; };

            mock.Raise(x => x.Load += null, EventArgs.Empty);
            Assert.Equal(1, countOne);
            Assert.Equal(1, countTwo);

            mock.Raise(x => x.Load += null, EventArgs.Empty);
            Assert.Equal(2, countOne);
            Assert.Equal(2, countTwo);

            mock.Raise(x => x.Load += null, EventArgs.Empty);
            Assert.Equal(3, countOne);
            Assert.Equal(3, countTwo);
        }
Exemple #3
0
        public void CanSpecifyClearOnlyEvents()
        {
            MockRepository mocks     = new MockRepository();
            IWithEvent     withEvent = mocks.StrictMock <IWithEvent>();
            bool           called    = false;

            withEvent.Load += delegate { called = true; };
            IEventRaiser raiser = LastCall.GetEventRaiser();

            mocks.BackToRecord(withEvent, BackToRecordOptions.EventSubscribers);

            raiser.Raise(this, EventArgs.Empty);

            Assert.False(called);
        }
		public void VerifyingThatEventWasAttached()
		{
			MockRepository mocks = new MockRepository();
			IWithEvent events = (IWithEvent)mocks.StrictMock(typeof(IWithEvent));
			events.Load += null; //ugly syntax, I know, but the only way to get this to work
			IEventRaiser raiser = LastCall.IgnoreArguments().GetEventRaiser();
			mocks.ReplayAll();

			EventConsumer consumerMock = new EventConsumer(events);
			//Next line invokes Load event.
			raiser.Raise(this, EventArgs.Empty);
			mocks.VerifyAll();

			Assert.True(consumerMock.OnLoadCalled);
		}
        public void VerifyingThatEventWasAttached()
        {
            IWithEvent events = MockRepository.Mock <IWithEvent>();

            events.ExpectEvent(x => x.Load += null)
            .IgnoreArguments();

            EventConsumer consumerMock = new EventConsumer(events);

            //Next line invokes Load event.
            events.Raise(x => x.Load += null, EventArgs.Empty);

            Assert.True(consumerMock.OnLoadCalled);
            events.VerifyAllExpectations();
        }
 public EventConsumer(IWithEvent withEvent)
 {
     _withEvent       = withEvent;
     _withEvent.Load += new EventHandler(OnLoad);
 }
		public EventConsumer(IWithEvent withEvent)
		{
			_withEvent = withEvent;
			_withEvent.Load += new EventHandler(OnLoad);
		}