本文整理汇总了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());
}
示例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);
}