ArturRios.Util.Test
2.0.0
dotnet add package ArturRios.Util.Test --version 2.0.0
NuGet\Install-Package ArturRios.Util.Test -Version 2.0.0
<PackageReference Include="ArturRios.Util.Test" Version="2.0.0" />
<PackageVersion Include="ArturRios.Util.Test" Version="2.0.0" />
<PackageReference Include="ArturRios.Util.Test" />
paket add ArturRios.Util.Test --version 2.0.0
#r "nuget: ArturRios.Util.Test, 2.0.0"
#:package ArturRios.Util.Test@2.0.0
#addin nuget:?package=ArturRios.Util.Test&version=2.0.0
#tool nuget:?package=ArturRios.Util.Test&version=2.0.0
Test Util
ArturRios.Util.Test is a small .NET library of test-support utilities for xUnit projects. It bundles the
helpers that come up again and again when testing services and web APIs: extra assertions, environment-aware
test attributes, in-memory fakes for repositories and schedulers, and a base class for functional web API tests.
Installation
dotnet add package ArturRios.Util.Test
The package targets net10.0 and builds on other ArturRios.* packages
(ArturRios.Util,
ArturRios.Data,
ArturRios.Mediator,
ArturRios.Configuration and
ArturRios.Util.WebApi) plus xunit and
Microsoft.AspNetCore.Mvc.Testing.
What's inside
| Component | Role |
|---|---|
CustomAssert |
Extra xUnit assertions for null/empty checks on collections and strings |
UnitFactAttribute, UnitTheoryAttribute, FunctionalFactAttribute, FunctionalTheoryAttribute |
Test attributes that can skip tests per environment or on a condition |
FakeRepository<T> |
In-memory ICrudRepository<T> / IRangeRepository<T> implementation |
FakeScheduler |
Simulates a delayed command/query dispatch through a CommandQueryMediator |
WebApiTest<T> |
Base class for functional web API tests using an in-memory host |
TestException |
Exception raised by the utilities when a test-support operation fails |
Quick Start
Custom assertions
CustomAssert.NullOrEmpty(collection); // passes for null or empty
CustomAssert.NotNullOrEmpty(collection); // passes only for a non-empty collection
CustomAssert.NullOrWhiteSpace(text);
CustomAssert.NotNullOrWhiteSpace(text);
Environment-aware attributes
// Runs everywhere except Production.
[UnitFact([EnvironmentType.Production])]
public void Calculates_totals() { /* ... */ }
// Skipped whenever the condition is true, on any environment.
[FunctionalFact(skipCondition: FeatureFlags.PaymentsDisabled)]
public void Charges_card() { /* ... */ }
In-memory repository
var repository = new FakeRepository<Person>();
var id = repository.Create(new Person { Name = "Ann" }); // ids start at 1
var person = repository.GetById(id);
repository.Update(new Person { Id = id, Name = "Ann Smith" });
repository.Delete(new Person { Id = id });
Functional web API test
public class ProductsApiTests : WebApiTest<Program>
{
public ProductsApiTests() : base(EnvironmentType.Local) { }
[Fact]
public async Task Creates_a_product()
{
await AuthenticateAndAuthorizeAsync(new Credentials("user@test.com", "secret123"), "/auth");
var response = await Gateway.PostAsync<DataOutput<ProductOutput>>("/products", new { Name = "Widget" });
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}
}
Documentation
Full documentation, with per-component guides, lives at artur-rios.github.io/dotnet-test-util:
Versioning
Semantic Versioning (SemVer). Breaking changes result in a new major version. New methods or non-breaking behavior changes increment the minor version; fixes or tweaks increment the patch.
Build, test and publish
Use the official .NET CLI to build, test and publish the project and Git for source control. If you want, optional helper toolsets I built to facilitate these tasks are available:
Legal Details
This project is licensed under the MIT License. A copy of the license is available at LICENSE in the repository.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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
- ArturRios.Configuration (>= 1.0.0)
- ArturRios.Data.Relational.Core (>= 3.0.0)
- ArturRios.Mediator (>= 1.0.1)
- ArturRios.Util (>= 1.4.0)
- ArturRios.Util.WebApi (>= 2.1.0)
- Microsoft.AspNetCore.Mvc.Testing (>= 10.0.10)
- Newtonsoft.Json (>= 13.0.4)
- xunit (>= 2.9.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.