IsoplaneApplication class
Runs your application in the Isoplane sandbox for an integration test, and gives the test an HttpClient to call it with.
public sealed class IsoplaneApplication : IAsyncDisposable
Public Members
| name | description |
|---|---|
| Client { get; } | An HttpClient for calling the running application. |
| DiagnosticOutput { get; } | What the isoplane command has printed while building and running the application, most recent last. |
| DisposeAsync() | Stops the application and releases its port and its Client. |
| static StartAsync(…) | Builds the application and starts it in the sandbox, returning once it is ready to receive requests. |
Remarks
Use it to test the application as a client would, running as it runs under Isoplane. Test logic that does not depend on the sandbox with ordinary unit tests, which are faster.
StartAsync runs the isoplane command on the test machine to build the project and start it, so the command must be installed there, at the same version as this package. The test itself runs outside the sandbox, in any test framework. Dispose the application to stop it; await using does so.
Starting builds the project, so tests that can share one running application are faster when they do, through a fixture of the test framework. Two applications running at the same time need separate project directories. Test an application sets up a test project from scratch.
Examples
An xUnit test of the application in the sibling directory MyApi:
[Fact]
public async Task The_home_page_answers()
{
using var startup = new CancellationTokenSource(TimeSpan.FromMinutes(10));
var project = Path.GetFullPath("../../../../MyApi", AppContext.BaseDirectory);
await using var app = await IsoplaneApplication.StartAsync(project, cancellationToken: startup.Token);
using var response = await app.Client.GetAsync("/");
Assert.True(response.IsSuccessStatusCode, app.DiagnosticOutput);
}
See Also
- namespace Isoplane.Testing