src/packages/EmbedIO.Testing/TestHttpClient.cs
/// <summary>
/// Creates a test client that communicates over the network
/// (typically with a <see cref="WebServer"/>).
/// </summary>
/// <param name="baseUrl">The base URL of the server.</param>
/// <param name="configureHandler">A callback used to configure the client's
/// handler before creating the client.</param>
/// <returns>A newly-created <see cref="TestHttpClient"/>.</returns>
/// <exception cref="ArgumentNullException">
/// <para><paramref name="baseUrl"/> is <see langword="null"/>.</para>
/// <para>- or -</para>
/// <para><paramref name="configureHandler"/> is <see langword="null"/>.</para>
/// </exception>
/// <seealso cref="Create(ITestWebServer)"/>
/// <seealso cref="Create(string)"/>
/// <seealso cref="Create(string, Action{HttpClientHandler})"/>
/// <seealso cref="Create(Uri)"/>
Creates a test client that communicates over the network
(typically with a ).
Creates a test client that communicates over the network ( typically with a ) .
public static TestHttpClient Create(Uri baseUrl, Action<HttpClientHandler> configureHandler)
        {
            Validate.NotNull(nameof(baseUrl), baseUrl);
            Validate.NotNull(nameof(configureHandler), configureHandler);
#pragma warning disable CA2000 
            var handler = new HttpClientHandler();
#pragma warning restore CA2000
            try
            {
                configureHandler(handler);
#pragma warning disable CA5399 
                return new TestHttpClient(handler, baseUrl);
#pragma warning restore CA5399
            }
            catch
            {
                handler.Dispose();
                throw;
            }
        }
public static TestHttpClient Create ( Uri baseUrl , Action < HttpClientHandler > configureHandler ) { Validate . NotNull ( nameof ( baseUrl ) , baseUrl ) ; Validate . NotNull ( nameof ( configureHandler ) , configureHandler ) ; pragma warning disable CA2000 var handler = new HttpClientHandler ( ) ; pragma warning restore CA2000 try { configureHandler ( handler ) ; pragma warning disable CA5399 return new TestHttpClient ( handler , baseUrl ) ; pragma warning restore CA5399 } catch { handler . Dispose ( ) ; throw ; } }
Creates a test client that communicates over the network
(typically with a ).
Creates a test client that communicates over the network ( typically with a ) .
// Dispose handler before it goes out of scope - Ownership of handler is transferred to the TestHttpClient instance. // CheckCertificateRevocationList not enabled on handler - configureHandler can do that, if needed.
A newly-created .
A newly - created .
None
baseUrl
Uri
The base URL of the server.
The base URL of the server .
configureHandler
Action<HttpClientHandler>
A callback used to configure the client's
handler before creating the client.
A callback used to configure the client ' s handler before creating the client .
seealso
None
seealso
None
seealso
None
seealso
None