Exemple #1
0
        public static MockHttpMessageHandler AddTokenResponse(
            this MockHttpManager httpManager,
            TokenResponseType responseType,
            IDictionary <string, string> expectedRequestHeaders = null)
        {
            HttpResponseMessage responseMessage;

            switch (responseType)
            {
            case TokenResponseType.Valid_UserFlows:
                responseMessage = MockHelpers.CreateSuccessTokenResponseMessage(
                    TestConstants.Uid,
                    TestConstants.DisplayableId,
                    TestConstants.s_scope.ToArray());

                break;

            case TokenResponseType.Valid_ClientCredentials:
                responseMessage = MockHelpers.CreateSuccessfulClientCredentialTokenResponseMessage();

                break;

            case TokenResponseType.Invalid_AADUnavailable503:
                responseMessage = MockHelpers.CreateFailureMessage(
                    System.Net.HttpStatusCode.ServiceUnavailable, "service down");

                break;

            case TokenResponseType.InvalidGrant:
                responseMessage = MockHelpers.CreateInvalidGrantTokenResponseMessage();
                break;

            case TokenResponseType.InvalidClient:

                responseMessage = MockHelpers.CreateInvalidClientResponseMessage();
                break;

            default:
                throw new NotImplementedException();
            }

            var responseHandler = new MockHttpMessageHandler()
            {
                ExpectedMethod         = HttpMethod.Post,
                ExpectedRequestHeaders = expectedRequestHeaders,
                ResponseMessage        = responseMessage,
            };

            httpManager.AddMockHandler(responseHandler);

            return(responseHandler);
        }
Exemple #2
0
 public static void AddSuccessTokenResponseMockHandlerForGet(
     this MockHttpManager httpManager,
     IDictionary <string, string> bodyParameters  = null,
     IDictionary <string, string> queryParameters = null)
 {
     httpManager.AddMockHandler(
         new MockHttpMessageHandler()
     {
         ExpectedMethod      = HttpMethod.Get,
         ExpectedPostData    = bodyParameters,
         ExpectedQueryParams = queryParameters,
         ResponseMessage     = MockHelpers.CreateSuccessTokenResponseMessage()
     });
 }
 public static void AddSuccessTokenResponseMockHandlerForPost(
     this MockHttpManager httpManager,
     string authority,
     IDictionary <string, string> bodyParameters  = null,
     IDictionary <string, string> queryParameters = null,
     bool foci = false)
 {
     httpManager.AddMockHandler(
         new MockHttpMessageHandler()
     {
         ExpectedUrl         = authority + "oauth2/v2.0/token",
         ExpectedMethod      = HttpMethod.Post,
         ExpectedPostData    = bodyParameters,
         ExpectedQueryParams = queryParameters,
         ResponseMessage     = MockHelpers.CreateSuccessTokenResponseMessage(foci)
     });
 }
        public static MockHttpMessageHandler AddSuccessTokenResponseMockHandlerForPost(
            this MockHttpManager httpManager,
            string authority = TestConstants.AuthorityCommonTenant,
            IDictionary <string, string> bodyParameters  = null,
            IDictionary <string, string> queryParameters = null,
            bool foci = false,
            HttpResponseMessage responseMessage = null)
        {
            var handler = new MockHttpMessageHandler()
            {
                ExpectedUrl         = authority + "oauth2/v2.0/token",
                ExpectedMethod      = HttpMethod.Post,
                ExpectedPostData    = bodyParameters,
                ExpectedQueryParams = queryParameters,
                ResponseMessage     = responseMessage ?? MockHelpers.CreateSuccessTokenResponseMessage(foci)
            };

            httpManager.AddMockHandler(handler);
            return(handler);
        }