我有以下控制器操作方法,我正在为此方法编写单元测试
try
{
if ( Session["token"] == null)
{
//checking whether the user has already given the credentials and got redirected by survey monkey by checking the query string 'code'
if (Request.QueryString["code"] != null)
{
string tempAuthCode = Request.QueryString["code"];
Session["token"] = _surveyMonkeyService.GetSurveyMonkeyToken(ApiKey, ClientSecret, tempAuthCode, RedirectUri, ClientId);
}
else
{
//User coming for the first time directed to authentication page
string redirectUrlToSurveyMonkeyAuthentication = _surveyMonkeyService.GetUrlToSurveyMonkeyAuthentication(RedirectUri, ClientId, ApiKey);
return Redirect(redirectUrlToSurveyMonkeyAuthentication);
}
}
//User is in the same session no need for token again …Run Code Online (Sandbox Code Playgroud) 我的代码是这样的 我试图模拟我在 GetUrlToSurveyMonkeyAuthentication 方法中使用的 htttputility urlencode 方法。
//this is the method which uses urlencode method which is in the same class
public string GetUrlToSurveyMonkeyAuthentication(string redirectUri, string clientId, string apiKey)
{
string urlToOauthSurveyMonkeyAuthentication = SurveyMonkeyBaseUrl + AuthCodeEndUrl + ParameterSeparator + ParameterRedirectUriName + UrlEncodes(redirectUri) + ParameterAdditioner + ParameterClientIdName + UrlEncodes(clientId) + ParameterAdditioner + ParameterResponseTypeName + UrlEncodes(ResponseType) + ParameterAdditioner + ParameterAPIKeyname + UrlEncodes(apiKey);
return urlToOauthSurveyMonkeyAuthentication;
}
// my urlencode method which needs to be mocked it is in the same class SurveyMonkeyAPIService
public …Run Code Online (Sandbox Code Playgroud)