Note

Access to this page requires authorization. You can try signing in or .

Access to this page requires authorization. You can try .

TestServer Class

Definition

Namespace:
Microsoft.AspNetCore.TestHost
Assembly:
Microsoft.AspNetCore.TestHost.dll
Package:
Microsoft.AspNetCore.TestHost v1.0.0
Package:
Microsoft.AspNetCore.TestHost v1.1.0
Package:
Microsoft.AspNetCore.TestHost v10.0.0
Package:
Microsoft.AspNetCore.TestHost v11.0.0-preview.4.26230.115
Package:
Microsoft.AspNetCore.TestHost v2.0.0
Package:
Microsoft.AspNetCore.TestHost v2.1.0
Package:
Microsoft.AspNetCore.TestHost v2.2.0
Package:
Microsoft.AspNetCore.TestHost v3.0.3
Package:
Microsoft.AspNetCore.TestHost v3.1.18
Package:
Microsoft.AspNetCore.TestHost v5.0.9
Package:
Microsoft.AspNetCore.TestHost v6.0.6
Package:
Microsoft.AspNetCore.TestHost v7.0.5
Package:
Microsoft.AspNetCore.TestHost v8.0.19
Package:
Microsoft.AspNetCore.TestHost v9.0.8
Source:
TestServer.cs
Source:
TestServer.cs
Source:
TestServer.cs
Source:
TestServer.cs
Source:
TestServer.cs
Source:
TestServer.cs
Source:
TestServer.cs
Source:
TestServer.cs
Source:
TestServer.cs
Source:
TestServer.cs
Source:
TestServer.cs

Important

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

An IServer implementation for executing tests.

public ref class TestServer : IDisposable, Microsoft::AspNetCore::Hosting::Server::IServer
public class TestServer : IDisposable, Microsoft.AspNetCore.Hosting.Server.IServer
type TestServer = class
 interface IServer
 interface IDisposable
Public Class TestServer
Implements IDisposable, IServer
Inheritance
TestServer
Implements

Constructors

Name Description
TestServer(IServiceProvider, IFeatureCollection, IOptions<TestServerOptions>)

For use with IHostBuilder.

TestServer(IServiceProvider, IFeatureCollection)

For use with IHostBuilder.

TestServer(IServiceProvider, IOptions<TestServerOptions>)

For use with IHostBuilder.

TestServer(IServiceProvider)

For use with IHostBuilder.

TestServer(IWebHostBuilder, IFeatureCollection)
Obsolete.

For use with IWebHostBuilder.

TestServer(IWebHostBuilder)
Obsolete.

For use with IWebHostBuilder.

Properties

Name Description
AllowSynchronousIO

Gets or sets a value that controls whether synchronous IO is allowed for the Request and Response. The default value is false.

BaseAddress

Gets or sets the base address associated with the HttpClient returned by the test server. Defaults to http://localhost/.

Features

Gets the collection of server features associated with the test server.

Host
Obsolete.

Gets the IWebHost instance associated with the test server.

PreserveExecutionContext

Gets or sets a value that controls if ExecutionContext and AsyncLocal<T> values are preserved from the client to the server. The default value is false.

Services

Gets the service provider associated with the test server.

Methods

Name Description
CreateClient()

Creates a HttpClient for processing HTTP requests/responses with the test server.

CreateHandler()

Creates a custom HttpMessageHandler for processing HTTP requests/responses with the test server.

CreateHandler(Action<HttpContext>)

Creates a custom HttpMessageHandler for processing HTTP requests/responses with custom configuration with the test server.

CreateRequest(String)

Begins constructing a request message for submission.

CreateWebSocketClient()

Creates a WebSocketClient for interacting with the test server.

Dispose()

Dispose the IWebHost object associated with the test server.

SendAsync(Action<HttpContext>, CancellationToken)

Creates, configures, sends, and returns a HttpContext. This completes as soon as the response is started.

Explicit Interface Implementations

Name Description
IServer.Features
IServer.Start<TContext>(IHttpApplication<TContext>)
IServer.StartAsync<TContext>(IHttpApplication<TContext>, CancellationToken)
IServer.StopAsync(CancellationToken)

Applies to


Feedback

Was this page helpful?