我有一个事件如下
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()
提前致谢。