2
我試圖模擬從通用的父類延遲的方法。知道我的代碼看起來像這樣。如何模擬繼承的方法
public interface IBaseRepository<T>
{
IEnumerable<T> FindMany(Func<T, bool> condition);
}
public interface IPersonRepository : IBaseRepository<person>
{
//Here I got some specifics methods for person repository
}
我的測試代碼看起來像這樣;
private IPersonRepository mockPersonRepository { get; set; }
[TestMethod]
public void TestMehtod()
{
LogonModel model = CreateLogonModel("[email protected]", "test", "Index");
person p = new person() { Email = model.Email, password = model.Password, PersonId = 1 };
mockPersonRepository.Stub(x => x.FindMany(y => y.Email == model.Email && y.password == model.Password)).Return(new List<person> {p});
mockPersonRepository.Replay();
var actual = instanceToTest.LogOnPosted(model) as PartialViewResult;
Assert.AreEqual("_Login", actual.ViewName);
}
當我在vs 2010中使用調試工具時,我可以認爲我存根,沒有工作,返回的人總是空。我已經宣佈FindMany方法爲虛擬。
有人知道如何存根該方法嗎?我使用RhinoMocks。
謝謝您的幫助,這真的幫了我!現在我想測試一下,我真的使用傳遞給方法LogonPosted的模型。我怎樣才能做到這一點?我一直試圖這樣做: mockPersonRepository.Expect(x => x.FindMany(Arg>。Matches(y => y(p))))。 但是,如果我設置了我的測試,它總是變綠。我如何期待Im真的用模型中的數據調用personRepository。 –
Rikard