当前位置: 首页>>代码示例>>C#>>正文


C# EventAggregator.Subscribe方法代码示例

本文整理汇总了C#中EventAggregator.Subscribe方法的典型用法代码示例。如果您正苦于以下问题:C# EventAggregator.Subscribe方法的具体用法?C# EventAggregator.Subscribe怎么用?C# EventAggregator.Subscribe使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在EventAggregator的用法示例。


在下文中一共展示了EventAggregator.Subscribe方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ObserverShouldOnlyReceiveSubscribedNotifications

        public void ObserverShouldOnlyReceiveSubscribedNotifications()
        {
            // Arrange

            var eventAggregator = new EventAggregator();
            var observer1 = new Mock<IObserve<TestEvent>>();
            var observer2 = new Mock<IObserve<OtherEvent>>();

            eventAggregator.Subscribe(observer1.Object);
            eventAggregator.Subscribe(observer2.Object);

            var testEvent = new TestEvent();
            var otherEvent = new OtherEvent();

            // Act

            eventAggregator.Publish(testEvent);
            eventAggregator.Publish(otherEvent);

            // Assert

            observer1.Verify(x => x.OnNext(It.IsAny<IEvent>()), Times.Once);
            observer1.Verify(x => x.OnNext(testEvent), Times.Once);
            observer2.Verify(x => x.OnNext(otherEvent), Times.Once);
        }
开发者ID:phdesign,项目名称:EventAggregator,代码行数:25,代码来源:EventAggregatorTests.cs

示例2: MainViewModel

        public MainViewModel(EventAggregator eventAggregator)
        {
            _eventAggregator = eventAggregator;
            _eventAggregator.Subscribe<SelectionViewModel>(HandleSelectionViewAdded);
            _eventAggregator.Subscribe<ContentViewModel>(HandleContentViewModelAdded);

            _selectionViewModels = new ObservableCollection<SelectionViewModel>();
            _contentViewModels = new ObservableCollection<ContentViewModel>();
        }
开发者ID:bryceklinker,项目名称:Code,代码行数:9,代码来源:MainViewModel.cs

示例3: A_valid_message_is_published_to_all_handlers

        public void A_valid_message_is_published_to_all_handlers() {
            var eventAggregator = new EventAggregator();
            var handlerMockA = new Mock<IHandle<object>>();
            var handlerMockB = new Mock<IHandle<object>>();


            eventAggregator.Subscribe(handlerMockA.Object);
            eventAggregator.Subscribe(handlerMockB.Object);
            eventAggregator.Publish(new object());

            handlerMockA.Verify(handlerStub => handlerStub.Handle(It.IsAny<object>()),
                                Times.AtLeastOnce());
            handlerMockB.Verify(handlerStub => handlerStub.Handle(It.IsAny<object>()),
                                Times.AtLeastOnce());

        }
开发者ID:yan122725529,项目名称:SqlComPare_Mvvm,代码行数:16,代码来源:EventAggregatorTests.cs

示例4: TryGetEventHandler_should_return_true_when_one_subscriber_exists

        public void TryGetEventHandler_should_return_true_when_one_subscriber_exists()
        {
            var subject = new EventAggregator();
            subject.Subscribe<int>(x => { });

            Action<int> handler;
            subject.TryGetEventHandler(out handler).Should().BeTrue();
        }
开发者ID:fir3pho3nixx,项目名称:mongo-csharp-driver,代码行数:8,代码来源:EventAggregatorTests.cs

示例5: SearchPlayersController

        public SearchPlayersController(EventAggregator eventAggregator, SearchPlayersProducerBoundary producerBoundary, SearchPlayersConsumerBoundary consumerBoundary)
        {
            _eventAggregator = eventAggregator;
            _producerBoundary = producerBoundary;
            _consumerBoundary = consumerBoundary;

            _eventAggregator.Subscribe<SearchPlayersRequest>(HandleSearchPlayersRequest);
        }
开发者ID:bryceklinker,项目名称:Code,代码行数:8,代码来源:SearchPlayersController.cs

示例6: Handler_should_invoke_multiple_subscribers

        public void Handler_should_invoke_multiple_subscribers()
        {
            var subject = new EventAggregator();
            bool called1 = false;
            bool called2 = false;
            bool called3 = false;
            subject.Subscribe<int>(x => called1 = true);
            subject.Subscribe<int>(x => called2 = true);
            subject.Subscribe<int>(x => called3 = true);

            Action<int> handler;
            subject.TryGetEventHandler(out handler);
            handler(42);

            called1.Should().BeTrue();
            called2.Should().BeTrue();
            called3.Should().BeTrue();
        }
开发者ID:fir3pho3nixx,项目名称:mongo-csharp-driver,代码行数:18,代码来源:EventAggregatorTests.cs

示例7: A_valid_subscriber_gets_removed_from_the_handler_list

        public void A_valid_subscriber_gets_removed_from_the_handler_list() {
            var eventAggregator = new EventAggregator();
            var handlerMock = new Mock<IHandle<object>>();

            eventAggregator.Subscribe(handlerMock.Object);
            Assert.True(eventAggregator.HandlerExistsFor(typeof (object)));

            eventAggregator.Unsubscribe(handlerMock.Object);
            Assert.False(eventAggregator.HandlerExistsFor(typeof (object)));
        }
开发者ID:yan122725529,项目名称:SqlComPare_Mvvm,代码行数:10,代码来源:EventAggregatorTests.cs

示例8: A_valid_subscriber_is_assigned_as_a_handler_its_message_type

        public void A_valid_subscriber_is_assigned_as_a_handler_its_message_type() {
            var handlerStub = new Mock<IHandle<object>>().Object;
            var aggregator = new EventAggregator();

            Assert.False(aggregator.HandlerExistsFor(typeof (object)));

            aggregator.Subscribe(handlerStub);

            Assert.True(aggregator.HandlerExistsFor(typeof (object)));
        }
开发者ID:yan122725529,项目名称:SqlComPare_Mvvm,代码行数:10,代码来源:EventAggregatorTests.cs

示例9: SubscriberShouldReceiveMessage_WhenMessagePublished

        public void SubscriberShouldReceiveMessage_WhenMessagePublished()
        {
            var mock = new Mock<ISubscriber<Message1>>();
            var eventAggregator = new EventAggregator();

            eventAggregator.Subscribe(mock.Object);
            var msg = new Message1();
            eventAggregator.Publish(msg);

            mock.Verify(s => s.Handle(msg));
        }
开发者ID:changhongfu,项目名称:TDDKata,代码行数:11,代码来源:EventAggregatorTest.cs

示例10: SubscriberShouldNotReceiveMessageWhichItIsNotSubscribedTo

        public void SubscriberShouldNotReceiveMessageWhichItIsNotSubscribedTo()
        {
            var mock = new Mock<ISubscriber<Message1>>();
            var eventAggregator = new EventAggregator();

            eventAggregator.Subscribe(mock.Object);
            var msg = new Message2();
            eventAggregator.Publish(msg);

            mock.Verify(s => s.Handle(It.IsAny<Message1>()), Times.Never());
        }
开发者ID:changhongfu,项目名称:TDDKata,代码行数:11,代码来源:EventAggregatorTest.cs

示例11: Handler_should_invoke_a_single_subscriber

        public void Handler_should_invoke_a_single_subscriber()
        {
            var subject = new EventAggregator();
            bool called = false;
            subject.Subscribe<int>(x => called = true);

            Action<int> handler;
            subject.TryGetEventHandler(out handler);
            handler(42);

            called.Should().BeTrue();
        }
开发者ID:fir3pho3nixx,项目名称:mongo-csharp-driver,代码行数:12,代码来源:EventAggregatorTests.cs

示例12: BaseObserverReceivesAllEvents

        public void BaseObserverReceivesAllEvents()
        {
            // Arrange

            var eventAggregator = new EventAggregator();
            var observer1 = new Mock<IObserve<IEvent>>();
            var observer2 = new Mock<IObserver<IEvent>>();

            eventAggregator.Subscribe(observer1.Object);
            eventAggregator.Subscribe(observer2.Object);

            var testEvent = new TestEvent();
            var otherEvent = new OtherEvent();

            // Act

            eventAggregator.Publish(testEvent);
            eventAggregator.Publish(otherEvent);

            // Assert

            observer1.Verify(x => x.OnNext(It.IsAny<IEvent>()), Times.Exactly(2));
            observer2.Verify(x => x.OnNext(It.IsAny<IEvent>()), Times.Exactly(2));
        }
开发者ID:phdesign,项目名称:EventAggregator,代码行数:24,代码来源:EventAggregatorTests.cs

示例13: ObserverStopsReceivingEventsWhenUnsubscribed

        public void ObserverStopsReceivingEventsWhenUnsubscribed()
        {
            // Arrange

            var eventAggregator = new EventAggregator();
            var observer1 = new Mock<IObserve<TestEvent>>();

            var unsubscribe = eventAggregator.Subscribe(observer1.Object);
            var testEvent1 = new TestEvent();
            var testEvent2 = new TestEvent();

            // Act

            eventAggregator.Publish(testEvent1);
            unsubscribe.Dispose();
            eventAggregator.Publish(testEvent2);

            // Assert

            observer1.Verify(x => x.OnNext(It.IsAny<IEvent>()), Times.Once);
            observer1.Verify(x => x.OnNext(testEvent1), Times.Once);
            observer1.Verify(x => x.OnNext(testEvent2), Times.Never);
        }
开发者ID:phdesign,项目名称:EventAggregator,代码行数:23,代码来源:EventAggregatorTests.cs

示例14: RegisterEventListenersInEventAggregator

 public void RegisterEventListenersInEventAggregator(EventAggregator eventAggregator)
 {
     eventAggregator.Subscribe<LoginFailed>(LoginFailedSubscriber.Receive);
 }
开发者ID:JogoShugh,项目名称:ModularAspNetMvc,代码行数:4,代码来源:RegisterEventSubscribers.cs

示例15: A_valid_message_invokes_HandlerResultProcessing_when_expected_to

        public void A_valid_message_invokes_HandlerResultProcessing_when_expected_to() {
            var eventAggregator = new EventAggregator();
            var coroutineHandlerMock = new Mock<IHandleWithCoroutine<object>>();
            var taskHandlerMock = new Mock<IHandleWithTask<object>>();
            var coroutineHandlerProcessed = false;
            var taskHandlerProcessed = false;

            coroutineHandlerMock.Setup(handlerStub => handlerStub.Handle(It.IsAny<object>()))
                                .Returns(() => new List<IResult>());

            taskHandlerMock.Setup(handlerStub => handlerStub.Handle(It.IsAny<object>()))
                           .Returns(() => new Task(() => { }));

            EventAggregator.HandlerResultProcessing = (target, result) => {

                if (target is IHandleWithCoroutine<object>) {
                    coroutineHandlerProcessed = true;
                }
                else if (target is IHandleWithTask<object>) {
                    taskHandlerProcessed = true;
                }
            };

            eventAggregator.Subscribe(coroutineHandlerMock.Object);
            eventAggregator.Subscribe(taskHandlerMock.Object);
            eventAggregator.Publish(new object());

            Assert.True(coroutineHandlerProcessed);
            Assert.True(taskHandlerProcessed);
        }
开发者ID:yan122725529,项目名称:SqlComPare_Mvvm,代码行数:30,代码来源:EventAggregatorTests.cs


注:本文中的EventAggregator.Subscribe方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。