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>
/// <returns>A newly-created <see cref="TestHttpClient"/>.</returns>
/// <exception cref="ArgumentNullException"><paramref name="baseUrl"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentException">
/// <para><paramref name="baseUrl"/> is not a valid absolute URL.</para>
/// <para>- or -</para>
/// <para><paramref name="baseUrl"/>'s scheme is neither <c>http</c> nor <c>https</c>.</para>
/// </exception>
/// <seealso cref="Create(ITestWebServer)"/>
/// <seealso cref="Create(string, Action{HttpClientHandler})"/>
/// <seealso cref="Create(Uri)"/>
/// <seealso cref="Create(Uri, Action{HttpClientHandler})"/>
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(string baseUrl)
        {
            Validate.Url(nameof(baseUrl), baseUrl, UriKind.Absolute, true);
#pragma warning disable CA2000 
            var handler = new HttpClientHandler();
#pragma warning restore CA2000
            try
            {
#pragma warning disable CA5399 
                return new TestHttpClient(handler, baseUrl);
#pragma warning restore CA5399
            }
            catch
            {
                handler.Dispose();
                throw;
            }
        }
public static TestHttpClient Create ( string baseUrl ) { Validate . Url ( nameof ( baseUrl ) , baseUrl , UriKind . Absolute , true ) ; pragma warning disable CA2000 var handler = new HttpClientHandler ( ) ; pragma warning restore CA2000 try { 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 - Mostly fine for testing purposes.
A newly-created .
A newly - created .
None
None
baseUrl
string
The base URL of the server.
The base URL of the server .
seealso
None
seealso
None
seealso
None
seealso
None