我只是在學習如何使用帶有MSTest的Moq。我有以下方法我想測試一下,在現有的一個應用:如何使用MSTest和Moq對此進行模擬
/// <summary>
/// Return the marker equipment Id value give a coater equipment Id value.
/// </summary>
/// <param name="coaterEquipmentId">The target coater</param>
/// <returns>The marker equipment Id value</returns>
internal static string GetMarkerEquipmentId(string coaterEquipmentId)
{
return CicApplication.CoaterInformationCache
.Where(row => row.CoaterEquipmentId == coaterEquipmentId)
.Select(row => row.MarkerEquipmentId)
.First();
}
的CicApplication對象是一個名爲CoaterInformationCache屬性,這是CoaterInformation類列表的「全球性」的對象。
我假設我將需要以某種方式模擬CicApplication.CoaterInformationCache,我可能需要傳遞此方法一個包含CoaterInformation類列表的接口,而不是通過僅包含運行時值的全局對象訪問列表?
非常感謝
作爲全局或靜態不是艱難的部分;它並沒有將這個屬性作爲一個接口,並且沒有辦法設置它,這是真正的問題。 –
謝謝霍恩先生。非常有見地的答案。 –