Click or drag to resize

CouchbaseFixture Class

Used to run the Docker couchbase-dev container on the current machine as a test fixture while tests are being performed and then deletes the container when the fixture is disposed.
Inheritance Hierarchy

Namespace:  Neon.Xunit.Couchbase
Assembly:  Neon.Xunit.Couchbase (in Neon.Xunit.Couchbase.dll) Version: 2.14.0
public sealed class CouchbaseFixture : ContainerFixture

The CouchbaseFixture type exposes the following members.

Public methodCouchbaseFixture
Constructs the fixture.
Public propertyBucket
Returns the Couchbase Bucket to be used to interact with Couchbase.
Public propertyContainerId
Returns the running container's short ID or null if the container has not been started.
(Inherited from ContainerFixture.)
Public propertyContainerName
Returns the running container's name or null if the container has not been started.
(Inherited from ContainerFixture.)
Public propertyIsRunning
Returns true if the fixture has been initialized.
(Inherited from TestFixture.)
Public propertyjsonClient
Returns the JsonClient.
Public propertyPassword
Returns the Couchbase password.
Public propertySettings
Returns the CouchbaseSettings used to connect to the bucket.
Public propertyState
Used by unit test classes to persist arbitrary name/value information across individual unit tests.
(Inherited from TestFixture.)
Public propertyUsername
Returns the Couchbase username.
Public methodClear
Removes all data and indexes from the database bucket and then recreates the primary index if an index was specified when the fixture was started.
Public methodDispose
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
(Inherited from TestFixture.)
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodOnRestart

Called when an already started fixture is being restarted. This provides the fixture an opportunity to do some custom initialization. This base method does nothing.

Note Note
This method is intended only for use by test fixture implementations. Unit tests or test fixtures should never call this directly.
(Inherited from TestFixture.)
Public methodReset
This method completely resets the fixture by removing the Couchbase container from Docker. Use Clear if you just want to clear the database.
(Overrides ContainerFixtureReset.)
Public methodRestart
Restarts the container. This is a handy way to deploy a fresh container with the same properties while running unit tests.
(Inherited from ContainerFixture.)
Public methodStart(Action)
Starts the fixture if it hasn't already been started including invoking the optional Action when the first time Start(Action) is called for a fixture instance.
(Inherited from TestFixture.)
Public methodStart(String, String, String, IEnumerableString, IEnumerableString, Boolean, Boolean, ContainerLimits) (Inherited from ContainerFixture.)
Public methodStart(CouchbaseSettings, String, String, String, String, String, Boolean, String, ContainerLimits)

Starts a Couchbase container if it's not already running. You'll generally want to call this in your test class constructor instead of Start(Action).

Public methodStartAsComposed(String, String, String, IEnumerableString, IEnumerableString, Boolean, Boolean, ContainerLimits)
Used to start the fixture within a ComposedFixture.
(Inherited from ContainerFixture.)
Public methodStartAsComposed(CouchbaseSettings, String, String, String, String, String, Boolean, String, ContainerLimits)
Used to start the fixture within a ComposedFixture.
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Note Note

IMPORTANT: The base Neon TestFixture implementation DOES NOT support parallel test execution because fixtures may impact global machine state like starting a Docker container, modifying the local DNS hosts file, or configuring a test database.

You should explicitly disable parallel execution in all test assemblies that rely on 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
    [CollectionDefinition(TestCollection.NonParallel, DisableParallelization = true)]
    public void Test()

This fixture assumes that Couchbase is not currently running on the local workstation or as a container named cb-test. You may see port conflict errors if either of these conditions are not true.

A somewhat safer but slower alternative, is to use the DockerFixture instead and add CouchbaseFixture as a subfixture. The advantage is that DockerFixture will ensure that all (potentially conflicting) containers are removed before the Couchbase fixture is started.

Note Note
This fixture calls PersistableInitialize to ensure that any type filters for generated IPersistableType classes are automatically registered with Linq2Couchbase.
Thread Safety
Instance members of this type are safe for multi-threaded operations.
See Also