1
我有一個AccountController其構造函數需要從我的自定義IOpenIdAuthentication接口派生的對象。默認情況下,這是一個包含OpenIdRelyingParty的對象。接口看起來是這樣的:如何對使用DotNetOpenId的ASP.NET MVC控制器進行單元測試?
public interface IOpenIdAuthentication {
IAuthenticationResponse Response { get; }
IAuthenticationRequest CreateRequest(string identifier);
}
我可以嘲笑IAuthenticationResponse:
_mockResponse = new Mock<IAuthenticationResponse>(MockBehavior.Loose);
_mockResponse.SetupGet(r => r.ClaimedIdentifier).Returns(identifier);
_mockResponse.SetupGet(r => r.Status)
.Returns(AuthenticationStatus.Authenticated);
// ... removed the formatting of 'friendlyId' ...
_mockResponse.SetupGet(r => r.FriendlyIdentifierForDisplay).Returns(friendlyId);
不過,我不知道如何嘲笑IAuthenticationRequest,因爲它似乎要複雜得多。有任何想法嗎?
啊,謝謝!我之前沒有使用模擬框架,所以我不確定是否必須模擬對象的每個部分。 – 2009-06-09 21:05:53