Пример #1
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);
        }
        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);
        }
        public void NoGhostMethodsAreIntroduced()
        {
            this.testee = new EventBroker();

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

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

            this.testee.Register(testPublisher);

            Assert.AreEqual(methodCount, testSubscriber.GetType().GetMethods().GetLength(0), "Registration of publisher introduced ghost methods.");

            this.testee.Register(testSubscriber);

            Assert.AreEqual(methodCount, testSubscriber.GetType().GetMethods().GetLength(0), "Registration of subscriber introduced ghost methods.");

            testPublisher.DoStuff();

            Assert.AreEqual(methodCount, testSubscriber.GetType().GetMethods().GetLength(0), "Calling handler method introduced ghost methods.");
            Assert.AreEqual(6, testSubscriber.MyValue);
        }
        public void NoGhostMethodsAreIntroduced()
        {
            this.testee = new EventBroker();

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

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

            this.testee.Register(testPublisher);

            Assert.AreEqual(methodCount, testSubscriber.GetType().GetMethods().GetLength(0), "Registration of publisher introduced ghost methods.");

            this.testee.Register(testSubscriber);

            Assert.AreEqual(methodCount, testSubscriber.GetType().GetMethods().GetLength(0), "Registration of subscriber introduced ghost methods.");

            testPublisher.DoStuff();

            Assert.AreEqual(methodCount, testSubscriber.GetType().GetMethods().GetLength(0), "Calling handler method introduced ghost methods.");
            Assert.AreEqual(6, testSubscriber.MyValue);
        }