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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 3
0
        public void SCNetworkControllerTest()
        {
            //WcfScServiceHost scnet = new WcfScServiceHost();

            DiscoveryClient discoveryClient = new DiscoveryClient(new UdpDiscoveryEndpoint());

            Collection <EndpointDiscoveryMetadata> helloWorldServices = discoveryClient.Find(new FindCriteria(typeof(IWcfScDataTransferService))).Endpoints;

            discoveryClient.Close();

            if (helloWorldServices.Count == 0)
            {
                Console.WriteLine("No services");
                return;
            }
            else
            {
                IWcfScDataTransferServiceCallback evnt = new MySubscriber();
                InstanceContext    evntCntx            = new InstanceContext(evnt);
                EventServiceClient proxy = new EventServiceClient(evntCntx);
                proxy.SubscribeAllConnectedEvent();
                string output = proxy.Connect(ConnectionClients.Controller);
                Console.WriteLine(output);

                //EndpointAddress serviceAddress = helloWorldServices[0].Address;

                //var binding = new NetTcpBinding();
                //var factory = new ChannelFactory<IWcfScDataTransferService>(binding);
                //IWcfScDataTransferService channel = factory.CreateChannel(serviceAddress);
                //string result = channel.SayHello("Unit Test John");
                //Console.WriteLine(result);
            }
        }
Exemplo n.º 4
0
 public Form1()
 {
     InitializeComponent();
     receiveAddr   = ConfigurationManager.AppSettings["receiveAddr"];
     _mySubscriber = new MySubscriber(receiveAddr);
     _mySubscriber.Subscriber <string>();
     _mySubscriber.Notify += OnmySubscriber_Notify;
 }
Exemplo n.º 5
0
        public SubscriberForm()
        {
            InitializeComponent();

            m_Publisher  = new MyPublisher();
            m_Subscriber = new MySubscriber();

            Text = "Main Thread ID: " + Thread.CurrentThread.ManagedThreadId.ToString();
        }
Exemplo n.º 6
0
        public async Task BasicTestamentServiceTest(bool flushTestaments)
        {
            WampPlayground playground = new WampPlayground();

            playground.Host.RealmContainer.GetRealmByName("realm1")
            .HostTestamentService();

            PublisherSubscriber publisherSubscriber =
                await playground.GetPublisherSubscriberDualChannel();

            MySubscriber mySubscriber = new MySubscriber();

            await publisherSubscriber.Subscriber.RealmProxy.Services
            .RegisterSubscriber(mySubscriber);

            MyClass instance = new MyClass()
            {
                Counter = 1, Foo = new int[] { 1, 2, 3 }
            };
            await publisherSubscriber
            .Publisher.RealmProxy.GetTestamentServiceProxy()
            .AddTestamentAsync("com.myapp.topic2", new object[]
            {
                47,
                23
            }, new Dictionary <string, object>()
            {
                {
                    "c", "Hello"
                },
                { "d", instance }
            });

            Assert.That(mySubscriber.Counter, Is.EqualTo(0));

            if (flushTestaments)
            {
                await publisherSubscriber.Publisher.RealmProxy.GetTestamentServiceProxy().FlushTestamentsAsync();
            }

            publisherSubscriber.Publisher.Close();

            if (flushTestaments)
            {
                Assert.That(mySubscriber.Counter, Is.EqualTo(0));
            }
            else
            {
                Assert.That(mySubscriber.Counter, Is.EqualTo(1));

                Assert.That(mySubscriber.Number1, Is.EqualTo(47));
                Assert.That(mySubscriber.Number2, Is.EqualTo(23));
                Assert.That(mySubscriber.C, Is.EqualTo("Hello"));
                Assert.That(mySubscriber.D, Is.EqualTo(instance));
            }
        }
Exemplo n.º 7
0
        public EventsClient()
        {
            InitializeComponent();

            m_Publisher  = new MyPublisher();
            m_Subscriber = new MySubscriber();

            m_Publisher.MyEvent += m_Subscriber.OnMyEvent;
            m_Publisher.MyEvent += m_Subscriber.OnMyEvent;
        }
        public async Task SubscriberGetsEventAsParameters()
        {
            WampPlayground playground = new WampPlayground();

            PublisherSubscriber dualChannel = await playground.GetPublisherSubscriberDualChannel();

            IWampChannel publisher  = dualChannel.Publisher;
            IWampChannel subscriber = dualChannel.Subscriber;

            MySubscriber mySubscriber = new MySubscriber();

            IAsyncDisposable disposable =
                await subscriber.RealmProxy.Services.RegisterSubscriber
                    (mySubscriber);

            IWampTopicProxy topicProxy =
                publisher.RealmProxy.TopicContainer.GetTopicByUri("com.myapp.topic2");

            MyClass instance = new MyClass()
            {
                Counter = 1,
                Foo     = new[] { 1, 2, 3 }
            };

            long?publish =
                await topicProxy.Publish(new PublishOptions(), new object[]
            {
                47,
                23,
            },
                                         new Dictionary <string, object>()
            {
                { "d", instance },
                { "c", "Hello" }
            });


            Assert.That(mySubscriber.Number1, Is.EqualTo(47));
            Assert.That(mySubscriber.Number2, Is.EqualTo(23));
            Assert.That(mySubscriber.C, Is.EqualTo("Hello"));
            Assert.That(mySubscriber.D, Is.EqualTo(instance));
        }
        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);
        }