Click or drag to resize

HostsFixture Class

Used to manage the local DNS resolverhosts file on the current computer.
Inheritance Hierarchy

Namespace:  Neon.Xunit
Assembly:  Neon.Xunit (in Neon.Xunit.dll) Version: 2.14.0
Syntax
public class HostsFixture : TestFixture

The HostsFixture type exposes the following members.

Constructors
  NameDescription
Public methodHostsFixture
Constructs the fixture.
Top
Properties
  NameDescription
Protected propertyInAction
Returns true if the Start(Action) method is running.
(Inherited from TestFixture.)
Protected propertyIsDisposed
Returns true if the instance has been disposed.
(Inherited from TestFixture.)
Public propertyIsRunning
Returns true if the fixture has been initialized.
(Inherited from TestFixture.)
Public propertyState
Used by unit test classes to persist arbitrary name/value information across individual unit tests.
(Inherited from TestFixture.)
Top
Methods
  NameDescription
Public methodAddHostAddress
Adds an IP address to the local DNS resolver's hosts file.
Protected methodCheckDisposed
Verifies that the fixture instance has not been disposed.
(Inherited from TestFixture.)
Protected methodCheckWithinAction
Verifies that the fixture instance's Start(Action) method is executing.
(Inherited from TestFixture.)
Public methodCommit
Commits the DNS records to the hosts file.
Public methodDispose
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
(Inherited from TestFixture.)
Protected methodDispose(Boolean)
Releases all associated resources.
(Overrides TestFixtureDispose(Boolean).)
Public methodStatic memberEnsureReset
Called by TestFixture to ensure that the hosts file contains no DNS records remaining after an interrupted test run.
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Finalizer.
(Overrides TestFixtureFinalize.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(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
INTERNAL USE ONLY: Resets the fixture state.
(Overrides TestFixtureReset.)
Public methodStart
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 methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Remarks
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, configuring environment variables or initializing 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:

C#
[assembly: CollectionBehavior(DisableTestParallelization = true, MaxParallelThreads = 1)]

and then define your test classes like:

C#
public class MyTests
{
    [Collection(TestCollection.NonParallel)]
    [CollectionDefinition(TestCollection.NonParallel, DisableParallelization = true)]
    [Fact]
    public void Test()
    {
    }
}
Thread Safety
Instance members of this type are safe for multi-threaded operations.
See Also