Example #1
0
        public void Test()
        {
            EventChannel eventChannel = new EventChannel();

            SubscriberTest subscriber  = new SubscriberTest("group1", eventChannel);
            SubscriberTest subscriber2 = new SubscriberTest("group2", eventChannel);


            eventChannel.Publish("group1", new PublisherDataTest("evnType1", "test 1"));
            eventChannel.Publish("group1", new PublisherDataTest("evnType2", "data text"));

            eventChannel.Publish("group2", new PublisherDataTest("evnType1", "test 111"));

            subscriber.Remove();

            eventChannel.Publish("group1", new PublisherDataTest("evnType1", "test 2"));
            eventChannel.Publish("group2", new PublisherDataTest("evnType1", "test 3"));
        }
        public void Subscribe_OneSubscription_HandlerShouldBeCalledWithCorrectMessage()
        {
            // Arrange
            var channel     = new EventChannel <string>();
            var mockHandler = new Mock <ITestHandler <string> >();

            // Act
            channel.Subscribe(mockHandler.Object.Handle);
            channel.Publish("Apple");

            // Assert
            mockHandler.Verify(h => h.Handle("Apple"), Times.Once());
        }
        public void Subscribe_MultipleSubscriptions_HandlersShouldBeCalledWithCorrectMessage()
        {
            // Arrange
            var channel      = new EventChannel <string>();
            var mockHandler1 = new Mock <ITestHandler <string> >();
            var mockHandler2 = new Mock <ITestHandler <string> >();

            // Act
            channel.Subscribe(mockHandler1.Object.Handle);
            channel.Subscribe(mockHandler2.Object.Handle);
            channel.Publish("Orange");

            // Assert
            mockHandler1.Verify(h => h.Handle("Orange"), Times.Once());
            mockHandler2.Verify(h => h.Handle("Orange"), Times.Once());
        }
 protected virtual void NotifyClicked()
 {
     onClickEventChannel.Publish();
 }