【发布时间】:2016-04-22 17:25:23
【问题描述】:
使用以下代码订阅获取 IEnumerable 集合数据时出现不支持的异常。无法订阅已发布的 Collection 对象。
Mock<IEventAggregator> _mockEventAgg = new Mock<IEventAggregator>();
_mockEventAgg.Setup(x => x.GetEvent<ShowScreenEvent>().Publish(new ObservableCollection<Customer>()
{
// Customer properties or details
}));
_mockEventAgg.Setup(m => m.GetEvent<ShowScreenEvent>().Subscribe(It.IsAny<Action<IEnumerable<Customer>>>()))
.Callback<IEnumerable<Customer>>(customers => SelectedCustomerData = customers);
例外:
Moq.dll 中出现“System.NotSupportedException”类型的异常,但未在用户代码中处理
附加信息:非虚拟(在 VB 中可覆盖)成员的无效设置:m => m.GetEvent().Subscribe(It.IsAny())
【问题讨论】:
-
从读取异常信息来看,
ShowScreenEvent.Subscribe()是非虚拟的吗? -
ShowScreenEvent类继承自PubSubEvent<IEnumerable<Customer>>类 -
看看这个问题stackoverflow.com/questions/35868184/…(你肯定可以将它从 NSubstitute 转换为 Moq)
标签: c# unit-testing moq prism eventaggregator