有人可以看看这段代码并告诉我是否有任何明显的原因它不应该工作?当在我的代码中调用 service.getResponse 时,模拟框架只返回 null,而不是我指定的对象。
[Test]
public void Get_All_Milestones()
{
var mockRepo = new MockRepository();
var service = mockRepo.DynamicMock<IRestfulService>();
var request = new RestRequestObject
{
Password = "testpw!",
UserName = "user",
SecureMode = true,
Url = "www.updatelog.com/",
Command = String.Format("projects/{0}/milestones/list", 123456),
Method = "POST"
};
var response = new RestResponseObject
{
StatusCode = 200,
ErrorsExist = false,
Response =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<milestones type=\"array\">\n <milestone>\n <completed type=\"boolean\">false</completed>\n <created-on type=\"datetime\">2008-10-02T17:37:51Z</created-on>\n <creator-id type=\"integer\">3028235</creator-id>\n <deadline type=\"date\">2008-10-20</deadline>\n <id type=\"integer\">7553836</id>\n <project-id type=\"integer\">123456</project-id>\n <responsible-party-id type=\"integer\">3028295</responsible-party-id>\n <responsible-party-type>Person</responsible-party-type>\n <title>Atb2 Editor Substantially Done</title>\n <wants-notification type=\"boolean\">true</wants-notification>\n </milestone>\n</milestones>\n"
};
using(mockRepo.Record())
{
Expect
.Call(service.GetResponse(request))
.Return(response);
}
using(mockRepo.Playback())
{
var dal = new DataAccess(service);
var result = dal.GetMilestones(123456);
Assert.IsNotNull(result, "The result should not be null.");
Assert.AreNotEqual(0, result.Count, "There should be exactly one item in this list.");
Assert.AreEqual(123456, result[0].ProjectId, "The project ids don't match.");
Assert.AreEqual(7553836, result[0].Id, "The ids don't match.");
}
mockRepo.VerifyAll();
}