我正在使用Typemock進行一些單元測試。我嘲笑靜態類Widget。我想嘲笑Widget.GetPrice(123)的返回返回值A.驗證具有特定參數的方法未使用TypeMock調用
Isolate.Fake.StaticMethods<Widget>();
Isolate.WhenCalled(() => Widget.GetPrice(123)).WillReturn("A");
我也想驗證Widget.GetPrice(456)不叫。
Isolate.Verify.WasNotCalled(() => Widget.GetPrice(456));
看來WasNotCalled沒有考慮參數。測試回來說它失敗B/W Widget.GetPrice實際上被稱爲。
我認爲這樣做的唯一方法是在調用Widget.GetPrice(456)時執行DoInstead調用並增加計數器。測試結束時會檢查計數器是否增加。有沒有更好的方法來做到這一點?