FEFF.TestFixtures.AspNetCore
1.3.5
Prefix Reserved
See the version list below for details.
dotnet add package FEFF.TestFixtures.AspNetCore --version 1.3.5
NuGet\Install-Package FEFF.TestFixtures.AspNetCore -Version 1.3.5
<PackageReference Include="FEFF.TestFixtures.AspNetCore" Version="1.3.5" />
<PackageVersion Include="FEFF.TestFixtures.AspNetCore" Version="1.3.5" />
<PackageReference Include="FEFF.TestFixtures.AspNetCore" />
paket add FEFF.TestFixtures.AspNetCore --version 1.3.5
#r "nuget: FEFF.TestFixtures.AspNetCore, 1.3.5"
#:package FEFF.TestFixtures.AspNetCore@1.3.5
#addin nuget:?package=FEFF.TestFixtures.AspNetCore&version=1.3.5
#tool nuget:?package=FEFF.TestFixtures.AspNetCore&version=1.3.5
FEFF.TestFixtures
Integrations:
Fixture libraries:
✅ Replace setup/teardown methods and test-class "Disposable pattern" with reusable Fixtures.
✅ Fixtures can depend on other fixtures.
✅ Fixtures can be configured via standard IServiceProvider.
✅ Set of fixtures to simplify testing AspNetCore applications.
Terminology and Goals
A fixture is a reusable component used for testing purposes. Fixtures can be packaged into libraries and reused by any number of testing projects. The fixture is a class containing three optional parts:
- Setup code in the constructor;
- State;
- Teardown code in Dispose() or DisposeAsync().
The scope of a fixture defines its lifetime. Within a scope, each fixture is created only once (lazily on demand) and destroyed at the end of the scope. If the fixture implements Dispose() or DisposeAsync(), those methods are called.
The available scopes are defined by the test framework used. For Xunit Integration, they are:
| Scope name | Description |
|---|---|
| test-case | Fixtures are created and destroyed for each test case |
| class | Fixtures are created and destroyed once for each test class |
| collection | Fixtures are created and destroyed once for each test collection |
| assembly | Fixtures are created and destroyed once for a test assembly |
Every request for the same fixture within the same scope returns the same fixture instance. Therefore, class-, collection-, and assembly-level fixtures can share state between all tests within the same scope.
Getting started (Xunit.V3)
Add a library reference to a test project:
dotnet add package FEFF.TestFixtures.XunitV3
Add an assembly-level attribute to initialize the extension:
[assembly: FEFF.TestFixtures.Xunit.TestFixturesExtension]
Use the TestContext.Current.GetFeffFixture<T>() extension method to get the required fixture instance at any point during a test:
public class SystemUnderTest
{
public static void Write(string filePath) =>
File.WriteAllText(filePath, "some-data", Encoding.UTF8);
}
public class ExampleTests
{
protected TmpDirectoryFixture TmpDir { get; } = TestContext.Current.GetFeffFixture<TmpDirectoryFixture>();
[Fact]
public void File__should_be_created()
{
// Arrange
var filePath = TmpDir.Path + "/file.tmp";
File.Exists(filePath).Should().BeFalse();
// Act
SystemUnderTest.Write(filePath);
// Assert
File.Exists(filePath)
.Should().BeTrue();
File.ReadAllText(filePath, Encoding.UTF8)
.Should().Be("some-data");
}
}
In this example, TmpDir is created when the fixture is first requested in the test class constructor. The scope of the fixture in this example is 'test-case'.
The TmpDir and its contents are automatically deleted after the test finishes.
This example uses AwesomeAssertions for the Should() assertion DSL.
See the source code for this example.
Defining other scopes for a fixture
The scope of a fixture is defined by the test creator using an overloaded method:
TestContext.Current.GetFeffFixture<T>(FixtureScopeType scopeType)
Also note that multiple instances of the fixture can exist in different scopes if needed.
Creating a fixture
Just create a class with the FixtureAttribute.
Let's examine the source code for the TmpDirectoryFixture we used above.
[Fixture]
public sealed class TmpDirectoryFixture : IDisposable
{
public string Path { get; } = Directory.CreateTempSubdirectory().FullName;
public void Dispose()
{
// double dispose guard
try
{
Directory.Delete(Path, true);
}
catch (DirectoryNotFoundException)
{
}
}
}
Where:
| Fixture function | Implementation |
|---|---|
| Setup | Constructor |
| State | 'Path' property |
| Teardown | IDisposable |
Fixture Dependencies
Fixtures can depend on other fixtures. Dependencies are injected via the constructor:
[Fixture]
public class MyCustomFixture1
{
}
[Fixture]
public class MyCustomFixture2
{
}
[Fixture]
public record MyFixtureSet(
MyCustomFixture1 F1,
MyCustomFixture2 F2,
);
public class ExampleTests
{
protected MyFixtureSet Set { get; } = TestContext.Current.GetFeffFixture<MyFixtureSet>();
//...
}
Note:
- All fixture dependencies (
MyCustomFixture1andMyCustomFixture2) exist in the same scope as the dependent fixture (MyFixtureSetin the example above). - Fixtures cannot have cyclic dependencies.
Advanced usage
Add/Get Fixture by Interface
Documentation is currently under development. See examples.
Fixture Factory Internals
Documentation is currently under development. See examples.
Advanced Fixture Registration
Documentation is currently under development. See examples.
Configuring Fixtures
Documentation is currently under development. See examples.
Fixture List
FEFF.TestFixtures Library
- EnvironmentFixture
- Snapshots the process environment and restores it after a test (the test scope)
- TmpDirectoryFixture
- Creates a unique directory and removes it along with its contents after a test (the test scope)
- Can optionally skip deletion
- TmpScopeIdFixture
- Generates a string that is unique for each scope (e.g., for each test)
FEFF.TestFixtures.AspNetCore Fixture Library
- AppManagerFixture
- Starts and stops the application via TestHost
- Allows modification of Configuration/ServiceCollection before the application starts
- AppClientFixture
- Creates and disposes an HttpClient for testing
- AppServicesFixture
- Provides access to the application's service provider in the test context
- Creates and disposes ServiceScope
- FakeLoggerFixture
- Replaces Logger<> with FakeLogger
- FakeTimeFixture
- Replaces TimeProvider with FakeTimeProvider
- FakeRandomFixture
- Replaces Random with FakeRandom
- TmpDatabaseNameFixture
- Updates connection strings to use a unique database name for test isolation
FEFF.TestFixtures.AspNetCore.EF Fixture Library
- EnsureDbFixture
- Creates the database on test application start (DbContext.EnsureCreated)
- Removes the database at the end of the fixture scope (e.g., after a test) (DbContext.EnsureDeleted)
[FEFF.TestFixtures.AspNetCore-Preview]
- AuthorizedAppClientFixture
- Creates and disposes an authenticated HttpClient for testing
- The user must provide a valid JWT
- SignalrClientFixture
- Creates and disposes a SignalR client for testing
- Fixture provides awaitable events for server messages
- The user must provide a path to the SignalR Hub within the tested API
- The user can optionally provide a JWT to authenticate the SignalR client
[Development in Progress]
- A unique Redis key prefix for test isolation
- A unique S3 path prefix for test isolation
- Fake outbound HTTP connection to stub integrations with third-party APIs
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- FEFF.TestFixtures (>= 1.3.5)
- Microsoft.AspNetCore.Mvc.Testing (>= 10.0.5)
- Microsoft.Extensions.Diagnostics.Testing (>= 10.4.0)
- Microsoft.Extensions.TimeProvider.Testing (>= 10.4.0)
-
net8.0
- FEFF.TestFixtures (>= 1.3.5)
- Microsoft.AspNetCore.Mvc.Testing (>= 8.0.25)
- Microsoft.Extensions.Diagnostics.Testing (>= 10.4.0)
- Microsoft.Extensions.TimeProvider.Testing (>= 10.4.0)
-
net9.0
- FEFF.TestFixtures (>= 1.3.5)
- Microsoft.AspNetCore.Mvc.Testing (>= 9.0.14)
- Microsoft.Extensions.Diagnostics.Testing (>= 10.4.0)
- Microsoft.Extensions.TimeProvider.Testing (>= 10.4.0)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on FEFF.TestFixtures.AspNetCore:
| Package | Downloads |
|---|---|
|
FEFF.TestFixtures.AspNetCore.EF
A library of fixtures used to test AspNetCore appications with EntityFrameworkCore. |
|
|
FEFF.TestFixtures.AspNetCore.SignalR
A library of fixtures used to test AspNetCore appications with SignalR-Client. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.6.1 | 229 | 6/1/2026 |
| 1.6.0 | 300 | 5/6/2026 |
| 1.5.1 | 143 | 4/29/2026 |
| 1.5.0 | 250 | 4/28/2026 |
| 1.4.6 | 160 | 4/23/2026 |
| 1.4.5 | 152 | 4/22/2026 |
| 1.4.4 | 120 | 4/15/2026 |
| 1.4.3-alpha | 117 | 4/15/2026 |
| 1.4.2 | 211 | 4/13/2026 |
| 1.4.1 | 132 | 4/11/2026 |
| 1.3.5 | 123 | 4/11/2026 |
| 1.3.4 | 125 | 4/9/2026 |
| 1.3.3 | 123 | 4/9/2026 |
| 1.3.2 | 117 | 4/5/2026 |
| 1.3.1 | 106 | 4/3/2026 |
| 1.3.0-alpha | 105 | 4/2/2026 |
| 1.2.2-alpha | 180 | 3/28/2026 |
| 1.2.1-alpha | 103 | 3/25/2026 |
| 1.2.0-alpha | 107 | 3/23/2026 |
| 0.0.12-alpha | 118 | 4/15/2026 |