我有以下方法:使用MOQ測試此代碼的正確方法是什麼?
public void MoveChannelUp(string channelName)
{
var liveChannels = _repository.GetChannels<LiveChannel>();
var channels = GetModifiedChannelsList(channelName, liveChannels);
_repository.SaveChannels(channels);
}
我想,這樣的正確的渠道參數傳遞給建立在SaveChannels的期望()調用
我想:
channelsRepository.Setup(x => x.SaveChannels(reorderedChannels));
其中reorderedChannels是我期望的GetModifiedChannelsList()調用將返回,但我得到了模擬驗證異常(可能是由於重新排序的Channel不同於頻道???)
所以這是GetModifiedChanneslsList(),我真的想測試(我知道我可以使用反射來測試這一點)
那麼,如何檢驗正確的頻道列表被傳遞到SaveChannels()?
我對Moq也相當陌生。也許你可以試試Moq'It'幫手,我試過了,看到一個例子:http://www.ienablemuch.com/2012/02/primer-on-unit-testing-with-moq.html –