Superdev.AspNetCore.Testing
1.0.6-pre
Prefix Reserved
See the version list below for details.
dotnet add package Superdev.AspNetCore.Testing --version 1.0.6-pre
NuGet\Install-Package Superdev.AspNetCore.Testing -Version 1.0.6-pre
<PackageReference Include="Superdev.AspNetCore.Testing" Version="1.0.6-pre" />
<PackageVersion Include="Superdev.AspNetCore.Testing" Version="1.0.6-pre" />
<PackageReference Include="Superdev.AspNetCore.Testing" />
paket add Superdev.AspNetCore.Testing --version 1.0.6-pre
#r "nuget: Superdev.AspNetCore.Testing, 1.0.6-pre"
#:package Superdev.AspNetCore.Testing@1.0.6-pre
#addin nuget:?package=Superdev.AspNetCore.Testing&version=1.0.6-pre&prerelease
#tool nuget:?package=Superdev.AspNetCore.Testing&version=1.0.6-pre&prerelease
Superdev.AspNetCore
Superdev.AspNetCore provides reusable, low-dependency building blocks for ASP.NET Core applications. It focuses on pragmatic infrastructure code which can be shared across projects.
Download and Install Superdev.AspNetCore
This library is available on NuGet: https://www.nuget.org/packages/Superdev.AspNetCore Use the following command to install Superdev.AspNetCore using NuGet package manager console:
PM> Install-Package Superdev.AspNetCore
You can use this library in ASP.NET Core projects compatible to .NET 9 and higher.
App Setup
tbd
API Usage
The following documentation covers the reusable building blocks that are already available in this package.
Use claim-based authorization
AuthorizeClaimAttribute allows you to protect endpoints based on the existence or value of claims.
Require a claim to exist:
using Superdev.AspNetCore.Security;
[AuthorizeClaim("permission")]
[HttpGet("profile")]
public IActionResult GetProfile()
{
return this.Ok();
}
Require a specific claim value:
using Superdev.AspNetCore.Security;
[AuthorizeClaim("permission", "admin")]
[HttpDelete("{id}")]
public IActionResult Delete(int id)
{
return this.NoContent();
}
Use more advanced matching with ClaimRequirementType:
using Superdev.AspNetCore.Security;
[AuthorizeClaim(ClaimRequirementType.Any, "permission", "read", "write")]
[HttpGet]
public IActionResult Get()
{
return this.Ok();
}
Use writable options
ConfigureWritable<T> registers a configuration section as normal options and as IWritableOptions<T>.
IWritableOptions<T> can update and persist the section back to appsettings.json.
Register writable options:
using Superdev.AspNetCore.Infrastructure.Configuration;
builder.Services.ConfigureWritable<MyFeatureOptions>(
builder.Configuration.GetSection("MyFeature"));
Update options at runtime:
public class MyController : ControllerBase
{
private readonly IWritableOptions<MyFeatureOptions> options;
public MyController(IWritableOptions<MyFeatureOptions> options)
{
this.options = options;
}
[HttpPost("enable")]
public async Task<IActionResult> EnableAsync()
{
await this.options.UpdatePropertyAsync(x => x.Enabled, true);
return this.Ok();
}
}
Writable options modify the configured JSON file on disk. Use this feature intentionally and avoid exposing it through unprotected endpoints.
Use system abstractions
This package contains lightweight abstractions for system services which make business code easier to test.
Inject IDateTime:
using Superdev.AspNetCore.Services.SystemAbstractions;
public class TokenService
{
private readonly IDateTime dateTime;
public TokenService(IDateTime dateTime)
{
this.dateTime = dateTime;
}
public DateTime GetExpirationUtc()
{
return this.dateTime.UtcNow.AddHours(1);
}
}
Inject IFileSystem:
using Superdev.AspNetCore.Services.SystemAbstractions;
public class DocumentService
{
private readonly IFileSystem fileSystem;
public DocumentService(IFileSystem fileSystem)
{
this.fileSystem = fileSystem;
}
public Task<string> ReadAsync(string path)
{
return this.fileSystem.ReadAllTextAsync(path);
}
}
Use problem details exception handling
ProblemDetailsExceptionHandler converts unhandled exceptions into RFC-style problem details responses.
Register it in Program.cs:
using Superdev.AspNetCore.ExceptionHandling;
builder.Services.AddProblemDetails();
builder.Services.AddExceptionHandler<ProblemDetailsExceptionHandler>();
var app = builder.Build();
app.UseExceptionHandler();
If you also want MVC/ObjectResult responses with status codes >= 400 to be normalized to ProblemDetails, add ProblemDetailsResultFilter:
using Superdev.AspNetCore.ExceptionHandling;
builder.Services.AddControllers(options =>
{
options.Filters.Add<ProblemDetailsResultFilter>();
});
Design Goals
- Keep dependencies minimal and explicit.
- Prefer framework-native ASP.NET Core primitives over large abstraction layers.
- Move only code that is broadly reusable across multiple projects.
- Keep application-specific controllers, DTOs, mappings, secrets and business rules outside this package.
Contribution
Contributors welcome! If you find a bug or you want to propose a new feature, feel free to do so by opening a new issue on github.com.
Links
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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
- Microsoft.AspNetCore.Mvc.Testing (>= 8.0.0)
- Microsoft.AspNetCore.TestHost (>= 8.0.0)
-
net9.0
- Microsoft.AspNetCore.Mvc.Testing (>= 8.0.0)
- Microsoft.AspNetCore.TestHost (>= 8.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
1.0
- Initial release.