public void DoesNotIntroduceGhostMethodsThroughRegistrationAndHandlingEvents()
        {
            this.testee = new EventBroker();

            ITestPublisher testPublisher = new MyPublisher();
            ITestSubscriber testSubscriber = new MySubscriber();

            int initialMethodCount = testSubscriber.GetType().GetMethods().GetLength(0);

            this.testee.Register(testPublisher);

            int methodCountAfterRegisteringPublisher = testSubscriber.GetType().GetMethods().GetLength(0);

            this.testee.Register(testSubscriber);

            int methodCountAfterRegisteringSubscriber = testSubscriber.GetType().GetMethods().GetLength(0);

            testPublisher.FireEvent();

            int methodCountAfterFiringEvent = testSubscriber.GetType().GetMethods().GetLength(0);

            methodCountAfterRegisteringPublisher.Should().Be(initialMethodCount, "registration of publisher should not introduce ghost methods");
            methodCountAfterRegisteringSubscriber.Should().Be(initialMethodCount, "registration of subscriber should not introduce ghost methods");
            methodCountAfterFiringEvent.Should().Be(initialMethodCount, "calling handler method should not introduce ghost methods");

            testSubscriber.MyValue.Should().Be(6);
        }
Example #2
0
        public void DoesNotIntroduceGhostMethodsThroughRegistrationAndHandlingEvents()
        {
            this.testee = new EventBroker();

            ITestPublisher  testPublisher  = new MyPublisher();
            ITestSubscriber testSubscriber = new MySubscriber();

            int initialMethodCount = testSubscriber.GetType().GetMethods().GetLength(0);

            this.testee.Register(testPublisher);

            int methodCountAfterRegisteringPublisher = testSubscriber.GetType().GetMethods().GetLength(0);

            this.testee.Register(testSubscriber);

            int methodCountAfterRegisteringSubscriber = testSubscriber.GetType().GetMethods().GetLength(0);

            testPublisher.FireEvent();

            int methodCountAfterFiringEvent = testSubscriber.GetType().GetMethods().GetLength(0);

            methodCountAfterRegisteringPublisher.Should().Be(initialMethodCount, "registration of publisher should not introduce ghost methods");
            methodCountAfterRegisteringSubscriber.Should().Be(initialMethodCount, "registration of subscriber should not introduce ghost methods");
            methodCountAfterFiringEvent.Should().Be(initialMethodCount, "calling handler method should not introduce ghost methods");

            testSubscriber.MyValue.Should().Be(6);
        }
Example #3
0
        private void OnFire(object sender, EventArgs e)
        {
            int num = Convert.ToInt32(m_NumberValue.Text);

            m_Publisher.FireEvent(num);
        }