public void CallPayloadHandlerSetHttpRequestMessageContent() { var testContentType = "testContentType"; var mockPayloadHandler = Substitute.For <IPayloadHandler>(); mockPayloadHandler.ContentType.Returns(testContentType); var testHttpMessage = new HttpRequestMessage(); // Registering the payload handler sets it as the handler for its content type; in this case "testContentType" PayloadHandler.TryRegister(mockPayloadHandler); // Setting ContentType on the request causes the internal payload handler to be set to the PayloadHandler registered for the specified content type var testHttpRequest = new TestHttpRequest { ContentType = testContentType }; testHttpRequest.GetPayloadHandler().GetType().Should().NotBe(typeof(JsonPayloadHandler)); // the actual type is a mock testHttpRequest.SetHttpRequestMessageContent(testHttpMessage); mockPayloadHandler .Received(1) .SetHttpRequestMessageContent(Arg.Is(testHttpRequest), Arg.Is(testHttpMessage)); }
/// <summary> /// Initializes a new instance of the <see cref="OktaClient"/> class using the specified <see cref="HttpClient"/>. /// </summary> /// <param name="apiClientConfiguration"> /// The client configuration. If <c>null</c>, the library will attempt to load /// configuration from an <c>okta.yaml</c> file or environment variables. /// </param> /// <param name="httpClient">The HTTP client to use for requests to the Okta API.</param> /// <param name="logger">The logging interface to use, if any.</param> /// <param name="retryStrategy">The retry strategy interface to use, if any.</param> /// <param name="serializer">The JSON serializer to use, if any. Using the <c>DefaultSerializer</c> is still strongly recommended since it has all the behavior this SDK needs to work properly. /// If a custom serializer is used, the developer is responsible to add the required logic for this SDK to continue working properly. See <see cref="DefaultSerializer"/> to check out what settings can be configured. /// </param> public OktaClient(OktaClientConfiguration apiClientConfiguration, HttpClient httpClient, ILogger logger = null, IRetryStrategy retryStrategy = null, ISerializer serializer = null) { Configuration = GetConfigurationOrDefault(apiClientConfiguration); OktaClientConfigurationValidator.Validate(Configuration); logger = logger ?? NullLogger.Instance; serializer = serializer ?? new DefaultSerializer(); var resourceFactory = new ResourceFactory(this, logger); IOAuthTokenProvider oAuthTokenProvider = (Configuration.AuthorizationMode == AuthorizationMode.PrivateKey) ? new DefaultOAuthTokenProvider(Configuration, resourceFactory, logger: logger) : NullOAuthTokenProvider.Instance; var requestExecutor = new DefaultRequestExecutor(Configuration, httpClient, logger, retryStrategy, oAuthTokenProvider); _dataStore = new DefaultDataStore( requestExecutor, serializer, resourceFactory, logger); PayloadHandler.TryRegister <PkixCertPayloadHandler>(); PayloadHandler.TryRegister <PemFilePayloadHandler>(); PayloadHandler.TryRegister <X509CaCertPayloadHandler>(); }