- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个事件如下
namespace MyProject
{
public class MyEvent
{
public MyEvent(int favoriteNumber)
{
this.FavoriteNumber = favoriteNumber;
}
public int FavoriteNumber { get; private set; }
}
}
我有一个引发此事件的方法。
using Caliburn.Micro;
//please assume the rest like initializing etc.
namespace MyProject
{
private IEventAggregator eventAggregator;
public void Navigate()
{
eventAggregator.PublishOnUIThreadAsync(new MyEvent(5));
}
}
如果我只使用 PublishOnUIThread,下面的代码(在单元测试中)工作正常。
eventAggregatorMock.Verify(item => item.Publish(It.IsAny<MyEvent>(), Execute.OnUIThread), Times.Once);
但是我如何检查相同的异步版本?
eventAggregatorMock.Verify(item => item.Publish(It.IsAny<MyEvent>(), Execute.OnUIThreadAsync), Times.Once);
验证异步方法时遇到问题。假设private Mock<IEventAggregator> eventAggregatorMock;
。该部分Execute.OnUIThreadAsync
给出错误 'Task Execute.OnUIThreadAsync' has the wrong return type
.
我也尝试过
eventAggregatorMock.Verify(item => item.Publish(It.IsAny<MyEvent>(), action => Execute.OnUIThreadAsync(action)), Times.Once);
但是说,System.NotSupportedException: Unsupported expression: action => action.OnUIThreadAsync()
提前致谢。
最佳答案
IEvenAggregator.Publish
定义为
void Publish(object message, Action<System.Action> marshal);
因此,您需要提供正确的表达式来匹配该定义。
eventAggregatorMock.Verify(_ => _.Publish(It.IsAny<MyEvent>(),
It.IsAny<Action<System.Action>>()), Times.Once);
此外,PublishOnUIThreadAsync
扩展方法返回一个任务
/// <summary>
/// Publishes a message on the UI thread asynchrone.
/// </summary>
/// <param name="eventAggregator">The event aggregator.</param>
/// <param name="message">The message instance.</param>
public static Task PublishOnUIThreadAsync(this IEventAggregator eventAggregator, object message) {
Task task = null;
eventAggregator.Publish(message, action => task = action.OnUIThreadAsync());
return task;
}
所以应该等待
public async Task Navigate() {
await eventAggregator.PublishOnUIThreadAsync(new MyEvent(5));
}
关于.net - Caliburn EventAggregator moq 验证 PublishOnUIThreadAsync 异步方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45954868/
我有以下设置: Silverlight 应用程序拆分 xaps/模块 我使用 MEF 作为 DI 框架来连接 我的应用程序的各个部分。 我有 2 个区域: 一个(左边的)填充有 ListView (例
Micro 2.x 用户, 我在模拟(使用最小起订量)和验证对 EventAggregator.PublishOnUIThread 的调用时遇到问题,因为它是一种扩展方法! 查看源代码让我想出了另一个
这是线程安全的吗? Prism 中的 EventAggregator 是一个非常简单的类,只有一个方法。当我注意到空检查和创建新类型以添加到私有(private) _events 集合中时没有锁定
多亏了这个SO answer我已经成功地测试了 PRISM EventAggregator 的发布事件(用 FakeItEasy 伪装) [TestCase] public void test_tha
我试图让我的 IEventAggregator 允许我在一个模块中发布和事件并在另一个模块中捕获它。我在一个模块/项目中尝试了下面的代码,效果很好。只有当我有一个模块/项目发布事件而另一个订阅它时,它
我通过 Prism 指导工作,并认为我掌握了他们的大多数通信工具。 命令非常简单,因此很明显,DelegateCommand 将仅用于将 View 与其 Model 连接起来。 当涉及到跨模块通信时,
寻找一个简单的 helloWorld EventAggregator 示例。我试图理解这一点,并且在遵循 RI 示例时遇到了一些困难。 谢谢 N 最佳答案 Prism 4.0 包括 EventAggr
我有一个与这篇文章类似的问题 Prism CompositePresentationEvent fires twice 我的问题是 Publish 只触发一次,但 Subscribe 中的代码执行了两
我正在尝试在模块级别而不是从类内部访问 Aurelia EventAggregator 服务。它在一个类中工作正常,我在其中 @inject 事件聚合器,但在外部不行。 import {inject}
我按照教程http://aurelia.io/hub.html#/doc/article/aurelia/framework/latest/contact-manager-tutorial/1进行操作
我在 Prism 中使用 EventAggregator,我希望事件持久化,这意味着当客户端订阅某个事件时,聚合器将之前错过的事件发布给客户端。有没有办法支持这个? 我知道这听起来更像是消息队列之类的
我一直在寻找 Composite Application Library ,这很棒,但我无法决定何时使用 EventAggregator...或者更确切地说 - 何时不使用它。 再看看 StockTr
我正在构建一个 Backbone 应用程序,使用 require.js 进行模块化加载,并使用 Marionette 来帮助我的应用程序结构和功能。我已经为事件聚合器设置了一个 require 模块,
我正在学习 Prism 。几个小时我就遇到了一个问题,订阅事件时,订阅方法没有被调用。我正在使用 Prism 和 Autofac . 在下面的简化示例中,主视图型号 Publish("dupa");事
我正在使用 Prism 的 EventAggregator 在模块的 ViewModel 之间进行松散耦合的通信。我在 ViewModelA 中有几个属性(例如 FirstName、LastName)
在我的复合 WPF 应用程序中,我有一个事件,当用户双击控件时发布。模块订阅事件并在必要时执行操作。 此事件似乎随机停止工作。有时当我运行应用程序时,我可以毫无问题地触发事件,有时我只能在模块停止接收
我开始使用 Prism 和 MVVM 开发一个 WPF 项目,我正在尝试使用 eventAggregator,但是当执行下面的行时会引发异常: IServiceLocator ob = Service
我想使用反射订阅 EventAggregator 事件,因为我试图在运行时动态连接 Prism 模块之间的事件订阅。 (我使用的是 Silverlight 5、Prism 和 MEF)。 我想要实现的
我了解 EventAggregator 在 Caliburn Micro 中是如何工作的,但我不明白这一点: 我们以此为例: View 模型 A private IEventAggregator _e
为了简单的模块间通信,有经典的 .NET 事件,但现在太多了,并且存在通过模块相互调用的事件链。 比如 Event_A 触发 Event_B 触发 Event_C。 EventAggregator 对
我是一名优秀的程序员,十分优秀!