为什么下面的响应在我的测试中总是为空?
SSO.cs
public class SSO : ISSO
{
const string SSO_URL = "http://localhost";
const string SSO_PROFILE_URL = "http://localhost";
public AuthenticateResponse Authenticate(string userName, string password)
{
return GetResponse(SSO_URL);
}
public void GetProfile(string key)
{
throw new NotImplementedException();
}
public virtual AuthenticateResponse GetResponse(string url)
{
return new AuthenticateResponse();
}
}
public class AuthenticateResponse
{
public bool Expired { get; set; }
}SSOTest.cs
[TestMethod()]
public void Authenticate_Expired_ReturnTrue()
{
var target = MockRepository.GenerateStub<SSO>();
AuthenticateResponse authResponse = new AuthenticateResponse() { Expired = true };
target.Expect(t => t.GetResponse("")).Return(authResponse);
target.Replay();
var response = target.Authenticate("mflynn", "password");
Assert.IsTrue(response.Expired);
}发布于 2011-06-18 04:58:44
你的期望是不正确的。您定义了希望在GetResponse上使用空字符串作为参数,但却传入了值SSO_URL。因此,不满足期望,返回null。
您有两个选项可以纠正此错误
一种方法是在期望上设置IgnoreArguments()
target.Expect(t => t.GetResponse("")).IgnoreArguments().Return(authResponse);另一种方法是将SSO_URL作为参数传递给GetResponse方法,如下所示
target.Expect(t => t.GetResponse("http://localhost")).Return(authResponse);https://stackoverflow.com/questions/6391655
复制相似问题