-
Notifications
You must be signed in to change notification settings - Fork 3
Xunit Support Classes
EDennis.AspNetCore.Base provides a number of abstract Xunit test classes and supporting classes for performing various kinds of Xunit integration tests. There are four broad categories of integration tests supported: (1) Repo Tests, which directly test repo class methods; (2) Controller Tests, which directly test controller methods (actions); (3) ApiClient Tests, which directly test ApiClient methods; and (4) Endpoint Tests, which test an API endpoint. Only the Endpoint Tests make use of the Microsoft's WebApplicationFactory. All other tests use special factory classes that do not derive from WebApplicationFactory.
Four abstract classes provide support for testing repo methods. There is one abstract class for each of the four types of repos.
This class instantiates a ReadonlyRepo for use in directly testing the repo's public methods. The instantiated repo is exposed as a property called Repo.
ReadonlyRepoTests has three type parameters.
| Type Parameter | Constraints |
|---|---|
TRepo |
The type of the instantiate repo, which must extend ReadonlyRepo<TEntity,TContext> |
TEntity |
TEntity is a class with a default constructor |
TContext |
TContext extends Microsoft.EntityFrameworkCore.DbContext |
ReadonlyRepoTests has a single constructor with two arguments.
| Parameter | Description |
|---|---|
ITestOutputHelper output |
The Xunit helper class for piping messages to the test output console |
ConfigurationFactory<TRepo> fixture |
A class for finding the applicable appsettings.Development.json file and generating an IConfiguration from that file |
ReadonlyRepoTests exposes two public properties.
| Property | Description |
|---|---|
public TRepo Repo |
Provides direct access to the Repo object |
public ITestOutputHelper Output |
The Xunit.Abstractions helper object for writing to the test output console |
public class TodoRepoTests : ReadonlyRepoTests<
TodoRepo, Todo, TodoContext> {
public TodoRepoTests(ITestOutputHelper output,
ConfigurationFactory<TodoRepo> fixture)
: base(output, fixture) { }
// test methods...
}StateAgencyBackgroundCheckRepoTests
This class instantiates a ReadonlyTemporalRepo for use in directly testing the repo's public methods. The instantiated repo is exposed as a property called Repo.
ReadonlyTemporalRepoTests has four type parameters.
| Type Parameter | Constraints |
|---|---|
TRepo |
The type of the instantiate repo, which must extend ReadonlyRepo<TEntity,TContext> |
TEntity |
TEntity is a class with a default constructor and implements IEFCoreTemporalModel |
TContext |
TContext extends Microsoft.EntityFrameworkCore.DbContext (for current records) |
THistoryContext |
THistoryContext extends Microsoft.EntityFrameworkCore.DbContext (for history records) |
ReadonlyTemporalRepoTests has a single constructor with two arguments.
| Parameter | Description |
|---|---|
ITestOutputHelper output |
The Xunit helper class for piping messages to the test output console |
ConfigurationFactory<TRepo> fixture |
A class for finding the applicable appsettings.Development.json file and generating an IConfiguration from that file |
ReadonlyTemporalRepoTests exposes two public properties.
| Property | Description |
|---|---|
public TRepo Repo |
Provides direct access to the Repo object |
public ITestOutputHelper Output |
The Xunit.Abstractions helper object for writing to the test output console |
public class TodoRepoTests : ReadonlyTemporalRepoTests<
TodoRepo, Todo, TodoContext, TodoHistoryContext> {
public TodoRepoTests(ITestOutputHelper output,
ConfigurationFactory<TodoRepo> fixture)
: base(output, fixture) { }
// test methods...
}FederalAgencyBackgroundCheckRepoTests
This class instantiates a WriteableRepo for use in directly testing the repo's public methods. The instantiated repo is exposed as a property called Repo.
WriteableRepoTests has three type parameters.
| Type Parameter | Constraints |
|---|---|
TRepo |
The type of the instantiate repo, which must extend WriteableRepo<TEntity,TContext> |
TEntity |
TEntity is a class with a default constructor |
TContext |
TContext extends Microsoft.EntityFrameworkCore.DbContext |
WriteableRepoTests has a single constructor with two required arguments and one optional argument.
| Parameter | Required? | Description |
|---|---|---|
ITestOutputHelper output |
Yes | The Xunit helper class for piping messages to the test output console |
ConfigurationFactory<TRepo> fixture |
Yes | A class for finding the applicable appsettings.Development.json file and generating an IConfiguration from that file |
string userName |
No | The SysUser value to attached to the updated record (default = "tester@example.org") |
WriteableRepoTests exposes three public properties.
| Property | Description |
|---|---|
public TRepo Repo |
Provides direct access to the Repo object |
public ITestOutputHelper Output |
The Xunit.Abstractions helper object for writing to the test output console |
public string InstanceName |
The generated name of the in-memory database (a GUID string) |
public class TodoRepoTests : WriteableRepoTests<
TodoRepo, Todo, TodoContext> {
public TodoRepoTests(ITestOutputHelper output,
ConfigurationFactory<TodoRepo> fixture, "bob@example.org")
: base(output, fixture) { }
// test methods...
}This class instantiates a WriteableTemporalRepo for use in directly testing the repo's public methods. The instantiated repo is exposed as a property called Repo.
WriteableTemporalRepoTests has four type parameters.
| Type Parameter | Constraints |
|---|---|
TRepo |
The type of the instantiate repo, which must extend WriteableTemporalRepo<TEntity,TContext> |
TEntity |
TEntity is a class with a default constructor |
TContext |
TContext extends Microsoft.EntityFrameworkCore.DbContext (for current records) |
THistoryContext |
THistoryContext extends Microsoft.EntityFrameworkCore.DbContext (for history records) |
WriteableTemporalRepoTests has a single constructor with two required arguments and one optional argument.
| Parameter | Required? | Description |
|---|---|---|
ITestOutputHelper output |
Yes | The Xunit helper class for piping messages to the test output console |
ConfigurationFactory<TRepo> fixture |
Yes | A class for finding the applicable appsettings.Development.json file and generating an IConfiguration from that file |
string userName |
No | The SysUser value to attached to the updated record (default = "tester@example.org") |
WriteableTemporalRepoTests exposes four public properties.
| Property | Description |
|---|---|
public TRepo Repo |
Provides direct access to the Repo object |
public ITestOutputHelper Output |
The Xunit.Abstractions helper object for writing to the test output console |
public string InstanceName |
The generated name of the in-memory database (current records) |
public string HistoryInstanceName |
The generated name of the in-memory database (history records) |
public class TodoRepoTests : WriteableTemporalRepoTests<
TodoRepo, Todo, TodoContext, TodoHistoryContext> {
public TodoRepoTests(ITestOutputHelper output,
ConfigurationFactory<TodoRepo> fixture, "alice@example.org")
: base(output, fixture) { }
// test methods...
}AgencyInvestigatorCheckRepoTests
EDennis.AspNetCore.Base does not provide any base test classes for testing controller methods directly. Instead, the library provides factory classes that make it easy to instantiate controllers with Repo or ApiClient dependencies in their constructors. The factory classes provide flexibility over base classes -- allowing the developer to inject any number and kind of Repo classes and any number and kind of ApiClient classes into a controller for testing.
(to be continued)
(to be continued)
(to be continued)
(to be continued)
(to be continued)
(to be continued)
(to be continued)
(to be continued)
(to be continued)
(to be continued)
(to be continued)
(to be continued)
(to be continued)
(to be continued)
(to be continued)
(to be continued)
(to be continued)
Development Support
- Temporal Entities
- Base Repository Classes
- Base API Controller Classes
- ApiClient and SecureApiClient
- Security Utilities
- IServiceCollection Extension Methods
- HttpClient Extension Methods
- ScopeProperties
- MigrationsExtensionsDbContextDesignTimeFactory
Testing Support
- API Launcher
- Testing Strategy and Infrastructure
- Xunit Support Classes
- Testing Security Utilities
Related Projects