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);
        }