Class NeonServiceFixture<TService>
Fixture for testing a NeonService.
Implements
Inherited Members
Namespace: Neon.Xunit
Assembly: Neon.Xunit.dll
Syntax
public class NeonServiceFixture<TService> : TestFixture, ITestFixture where TService : NeonService
Type Parameters
Name | Description |
---|---|
TService | Fixture for testing a . |
Constructors
NeonServiceFixture()
Constructs the fixture.
Declaration
public NeonServiceFixture()
Properties
Service
Returns the service instance.
Declaration
public TService Service { get; }
Property Value
Type | Description |
---|---|
TService |
Methods
Dispose(bool)
Releases all associated resources.
Declaration
protected override void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
bool | disposing | Pass |
Overrides
~NeonServiceFixture()
Finalizer.
Declaration
protected ~NeonServiceFixture()
GetHttpClient(string, HttpClientHandler)
Returns a HttpClient instance configured to communicate with the service via the named HTTP/HTTPS endpoint.
Declaration
public HttpClient GetHttpClient(string endpointName = "", HttpClientHandler handler = null)
Parameters
Type | Name | Description |
---|---|---|
string | endpointName | Optionally specifies HTTP/HTTPS endpoint name as defined by the service description (defaults to Empty). |
HttpClientHandler | handler | Optionally specifies a custom HTTP handler. |
Returns
Type | Description |
---|---|
HttpClient | The configured HttpClient. |
Remarks
The client returned will have it's BaseAddress initialized with the URL of the service including the path prefix defined by the endpoint.
note
The client returned will be cached such that subsequent calls will return the same client instance for the endpoint. This cache will be cleared if the service fixture is restarted.
note
Do not dispose the client returned since it will be cached by the fixture and
then be disposed when the fixture is restarted or disposed. The optional
handler
passed will also be disposed when fixture will
also be disposed automatically.
Exceptions
Type | Condition |
---|---|
KeyNotFoundException | Thrown if the named endpoint doesn't exist. |
InvalidOperationException |
GetJsonClient(string, HttpClientHandler)
Returns a JsonClient instance configured to communicate with the service via the named HTTP/HTTPS endpoint.
Declaration
public JsonClient GetJsonClient(string endpointName = "", HttpClientHandler handler = null)
Parameters
Type | Name | Description |
---|---|---|
string | endpointName | Optionally specifies HTTP/HTTPS endpoint name as defined by the service description (defaults to Empty). |
HttpClientHandler | handler | Optionally specifies a custom HTTP handler. |
Returns
Type | Description |
---|---|
JsonClient | The configured HttpClient. |
Remarks
The client returned will have it's BaseAddress initialized with the URL of the service including the path prefix defined by the endpoint.
note
The client returned will be cached such that subsequent calls will return the same client instance for the endpoint. This cache will be cleared if the service fixture is restarted.
note
Do not dispose the client returned since it will be cached by the fixture and
then be disposed when the fixture is restarted or disposed. The optional
handler
passed will also be disposed when fixture will
also be disposed automatically.
Reset()
INTERNAL USE ONLY: Resets the fixture state.
Declaration
public override void Reset()
Overrides
Restart(Func<TService>, TimeSpan)
Restarts the service unless it never been started.
Declaration
public void Restart(Func<TService> serviceCreator = null, TimeSpan runningTimeout = default)
Parameters
Type | Name | Description |
---|---|---|
Func<TService> | serviceCreator | Callback that creates and returns the new service instance. |
TimeSpan | runningTimeout | Optionally specifies the maximum time the fixture should wait for the service to transition to the Running state. This defaults to 30 seconds. |
Remarks
This method first calls the serviceCreator
callback and expects
it to return a new service instance that has been initialized by setting its environment
variables and configuration files as required. The callback should not start thge service.
Exceptions
Type | Condition |
---|---|
TimeoutException | Thrown if the service didn't transition to the running (or terminated) state
within |
Start(Action)
DON'T USE THIS: Use Start(Func<TService>, ServiceMap, TimeSpan) instead for this fixture.
Declaration
public override TestFixtureStatus Start(Action action = null)
Parameters
Type | Name | Description |
---|---|---|
Action | action | The initialization action. |
Returns
Type | Description |
---|---|
TestFixtureStatus | Started if the fixture wasn't previously started and this method call started it or AlreadyRunning if the fixture was already running. |
Overrides
Start(Func<TService>, ServiceMap, TimeSpan)
Starts the fixture including a TService
service instance if
the fixture is not already running.
Declaration
public TestFixtureStatus Start(Func<TService> serviceCreator, ServiceMap serviceMap = null, TimeSpan readyTimeout = default)
Parameters
Type | Name | Description |
---|---|---|
Func<TService> | serviceCreator | Callback that creates and returns the new service instance. |
ServiceMap | serviceMap | Optionally passed as the service map describing an emulated deployment. When this is
not |
TimeSpan | readyTimeout | Optionally specifies the maximum time the fixture should wait for the service to transition to the Running state. This defaults to 30 seconds. |
Returns
Type | Description |
---|---|
TestFixtureStatus | Started if the fixture wasn't previously started and this method call started it or AlreadyRunning if the fixture was already running. |
Remarks
This method first calls the serviceCreator
callback and expects it to
return a new service instance that has been initialized by setting its environment variables
and configuration files as required. The callback should not start the service.
Exceptions
Type | Condition |
---|---|
TimeoutException | Thrown if the service didn't transition to the running (or terminated) state
within |
StartAsComposed(Func<TService>, ServiceMap, TimeSpan)
Used to start the fixture within a ComposedFixture.
Declaration
public void StartAsComposed(Func<TService> serviceCreator, ServiceMap serviceMap = null, TimeSpan readyTimeout = default)
Parameters
Type | Name | Description |
---|---|---|
Func<TService> | serviceCreator | Callback that creates and returns the new service instance. |
ServiceMap | serviceMap | Optionally passed as the service map describing an emulated deployment. When this is
not |
TimeSpan | readyTimeout | Optionally specifies the maximum time the fixture should wait for the service to transition to the Running state. This defaults to 30 seconds. |
Exceptions
Type | Condition |
---|---|
TimeoutException | Thrown if the service didn't transition to the running (or terminated) state
within |