Class DockerComposeFixture
Used to run a docker-compose application on the current machine as a test fixture while tests are being performed and then deletes the applicatiuon when the fixture is disposed.
note
The DockerComposeFixture and DockerFixture fixtures are not compatible with each other. You may only use one of these at a time.
Implements
Inherited Members
Namespace: Neon.Xunit
Assembly: Neon.Xunit.dll
Syntax
public class DockerComposeFixture : TestFixture, ITestFixture
Remarks
note
IMPORTANT: The base Neon TestFixture implementation DOES NOT
support parallel test execution. You need to explicitly disable parallel execution in
all test assemblies that rely on thesex test fixtures by adding a C# file called
AssemblyInfo.cs
with:
[assembly: CollectionBehavior(DisableTestParallelization = true, MaxParallelThreads = 1)]
and then define your test classes like:
public class MyTests : IClassFixture<DockerComposeFixture>, IDisposable
{
[Collection(TestCollection.NonParallel)]
[CollectionDefinition(TestCollection.NonParallel, DisableParallelization = true)]
[Fact]
public void Test()
{
}
}
Constructors
DockerComposeFixture()
Constructor.
Declaration
public DockerComposeFixture()
Properties
ApplicationName
Returns the running application name or null
if the compose file
has not been started.
Declaration
public string ApplicationName { get; }
Property Value
Type | Description |
---|---|
string |
Methods
Dispose(bool)
Releases all associated resources.
Declaration
protected override void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
bool | disposing | Pass |
Overrides
~DockerComposeFixture()
Finalizer.
Declaration
protected ~DockerComposeFixture()
Reset()
INTERNAL USE ONLY: Resets the fixture state.
Declaration
public override void Reset()
Overrides
Restart()
Restarts the application. This is a handy way to deploy a fresh instance with the same properties while running unit tests.
Declaration
public virtual void Restart()
Start(string, string, bool, string[])
Starts the fixture by running a Docker compose application.
note
You'll need to call StartAsComposed(string, string, bool, string[]) instead when this fixture is being added to a ComposedFixture.
Declaration
public TestFixtureStatus Start(string name, string composeFile, bool keepOpen = false, string[] customContainerNames = null)
Parameters
Type | Name | Description |
---|---|---|
string | name | Specifies the application name. |
string | composeFile | Specifies the contents of the docker-compose.yml file defining the application. |
bool | keepOpen | Optionally indicates that the application should continue to run after the fixture is disposed. |
string[] | customContainerNames | Optionally specifies custom container names deployed by the Docker Compose file that will not be prefixed by the application name. The fixture needs to know these so it can remove the containers when required. |
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
note
You must specify a valid application name
so that the fixure
can remove any existing application with the same name before starting the new instance
of the application. This is very useful during test debugging when the test might be
interrupted during debugging or when keepOpen
=true
.
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Thrown if this is not called from within the Action method passed Start(Action) |
StartAsComposed(string, string, bool, string[])
Used to start the fixture within a ComposedFixture.
Declaration
public void StartAsComposed(string name, string composeFile, bool keepOpen = false, string[] customContainerNames = null)
Parameters
Type | Name | Description |
---|---|---|
string | name | Specifies the application name. |
string | composeFile | Specifies the contents of the docker-compose.yml file defining the application. |
bool | keepOpen | Optionally indicates that the application should continue to run after the fixture is disposed. |
string[] | customContainerNames | Optionally specifies custom container names deployed by the Docker Compose file that will not be prefixed by the application name. The fixture needs to know these so it can remove the containers when required. |
Remarks
note
You must specify a valid application name
so that the fixure
can remove any existing application with the same name before starting the new instance
of the application. This is very useful during test debugging when the test might be
interrupted during debugging or when keepOpen
=true
.
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Thrown if this is not called from within the Action method passed Start(Action) |