小编use*_*848的帖子

如何在测试方法Moq中设置查询字符串的值

我有以下控制器操作方法,我正在为此方法编写单元测试

    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)

c# nunit unit-testing moq

8
推荐指数
1
解决办法
9936
查看次数

模拟 C# 中同一个类中的方法

我的代码是这样的 我试图模拟我在 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)

c# nunit unit-testing moq

1
推荐指数
1
解决办法
3513
查看次数

标签 统计

c# ×2

moq ×2

nunit ×2

unit-testing ×2