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


C# EventAggregator.Publish方法代码示例

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


在下文中一共展示了EventAggregator.Publish方法的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: Context

        public void Context()
        {
            _session = MockRepository.GenerateMock<ISession>();
            _session.Stub(x => x.Save(Arg<object>.Is.NotNull))
                .WhenCalled(x => _saved.Add(x.Arguments.First()));
            var container = IoC.Container;
            container.Configure(x => x.For<ISession>().Use(_session));
            var eventAggregator = new EventAggregator(container);

            eventAggregator.Publish(new SubscriptionCreated());
        }
开发者ID:mattiasbrand,项目名称:InProcessEventAggregator,代码行数:11,代码来源:EventAggregatorTests.cs

示例3: 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

示例4: 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

示例5: Subscribe_WhenGivenEvent_ShouldRaiseEvent

        public void Subscribe_WhenGivenEvent_ShouldRaiseEvent()
        {
            var eventWasRaised = false;
            var eventBus = new EventAggregator();

            eventBus.GetEvent<TestEvent>().Subscribe(new Observer<TestEvent>(x => eventWasRaised = true));

            eventBus.Publish(new TestEvent());

            Assert.IsTrue(eventWasRaised);
        }
开发者ID:dcga,项目名称:Reactive.EventAggregator.Net35,代码行数:11,代码来源:ConcurrentDictionaryTests.cs

示例6: Unsubscribe_WhenGivenEvent_ShouldNotRaiseEvent

        public void Unsubscribe_WhenGivenEvent_ShouldNotRaiseEvent()
        {
            var eventWasRaised = false;
            var eventBus = new EventAggregator();

            var subscription = eventBus.GetEvent<TestEvent>().Subscribe(new Observer<TestEvent>(x => eventWasRaised = true));

            subscription.Dispose();
            eventBus.Publish(new TestEvent());

            Assert.IsFalse(eventWasRaised);
        }
开发者ID:dcga,项目名称:Reactive.EventAggregator.Net35,代码行数:12,代码来源:ConcurrentDictionaryTests.cs

示例7: 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

示例8: 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

示例9: testing_subscribe

        public void testing_subscribe()
        {
            // arrange
            var eventWasRaised = false;
            var eventPublisher = new EventAggregator();

            // act
            eventPublisher.GetEvent<SampleEvent>()
                .Subscribe(se => eventWasRaised = true);

            eventPublisher.Publish(new SampleEvent());
            
            // assert
            eventWasRaised.ShouldBe(true);
        }
开发者ID:shiftkey,项目名称:Reactive.EventAggregator,代码行数:15,代码来源:SimpleTests.cs

示例10: 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

示例11: testing_selective_subscribe_ignored

        public void testing_selective_subscribe_ignored()
        {
            // arrange
            var eventWasRaised = false;
            var eventPublisher = new EventAggregator();

            // act
            eventPublisher.GetEvent<SampleEvent>()
                .Where(se => se.Status != 1)
                .Subscribe(se => eventWasRaised = true);

            eventPublisher.Publish(new SampleEvent { Status = 1 });

            // assert
            eventWasRaised.ShouldBe(false);
        }
开发者ID:shiftkey,项目名称:Reactive.EventAggregator,代码行数:16,代码来源:SimpleTests.cs

示例12: ShellViewModel

        public ShellViewModel(EventAggregator eventAggregator, IRoutingState router)
        {
            var logger = NLog.LogManager.GetCurrentClassLogger();

            _router = router;

            OnCompomentsRegisted = Observable.Create<Unit>(observer => Scheduler.Default.Schedule(() =>
            {
                logger.Info(string.Format("Starting Compoments Registration on thread {0}.", Thread.CurrentThread));

                eventAggregator.Publish(new OpenNewLifetimeScopeCommand(builder =>
                {
                    builder.RegisterType<WelcomeViewModel>().InstancePerLifetimeScope();
                    builder.RegisterType<Welcome>().As<IViewFor<WelcomeViewModel>>().InstancePerLifetimeScope();

                    builder.RegisterType<NextPage1ViewModel>().InstancePerLifetimeScope();
                    builder.RegisterType<NextPage1>().As<IViewFor<NextPage1ViewModel>>().InstancePerLifetimeScope();
                }));
                observer.OnNext(Unit.Default);
                observer.OnCompleted();
            }));
        }
开发者ID:jaohaohsuan,项目名称:ReactiveuiTrial,代码行数:22,代码来源:ShellViewModel.cs

示例13: RaiseCanExecuteChangedShouldBeInvokedOnStateChangedMessage

 public void RaiseCanExecuteChangedShouldBeInvokedOnStateChangedMessage()
 {
     var notifier = new EventAggregator(true);
     bool isInvoked = false;
     var relayCommand = CreateCommand(NodoAction, o => true);
     relayCommand.CanExecuteMode = ExecutionMode.None;
     relayCommand.CanExecuteChanged += (sender, args) =>
     {
         isInvoked = true;
     };
     relayCommand.AddNotifier(notifier);
     notifier.Publish(notifier, StateChangedMessage.Empty);
     isInvoked.ShouldBeTrue();
 }
开发者ID:dbeattie71,项目名称:MugenMvvmToolkit,代码行数:14,代码来源:RelayCommandTest.cs

示例14: 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

示例15: A_valid_message_is_invoked_on_the_supplied_marshaller

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

            eventAggregator.Subscribe(handlerMock.Object);
            eventAggregator.Publish(new object(), action => marshallerCalled = true);

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


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