0
訂閱使用下面的代碼獲取IEnumerable集合數據時不支持異常。無法訂閱發佈的Collection對象。使用Moq測試事件聚合器訂閱的例外情況
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);
例外:
「System.NotSupportedException」類型的異常出現在Moq.dll但在用戶代碼中沒有處理
其他信息:在非虛擬無效設置(在VB中可重寫)成員:m => m.GetEvent()。訂閱(It.IsAny())
從讀取異常消息,是'ShowScreenEvent.Subscribe()'非虛擬? –
'ShowScreenEvent'類正在從'PubSubEvent>'類 –
venkat
inherting看看這個問題http://stackoverflow.com/questions/35868184/nsubstitute-vs-prism-eventaggregator-assert-that-calling-a -method-triggers-even/35889556#35889556(你肯定可以將這個從NSubstitute轉換爲Moq) – Haukinger