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


C# EventAggregator.PublishOnCurrentThread方法代码示例

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


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

示例1: 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.PublishOnCurrentThread(new object());

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

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

示例2: 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.PublishOnCurrentThread(new object());

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


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