Superdev.AspNetCore.Testing
1.0.9-pre
Prefix Reserved
dotnet add package Superdev.AspNetCore.Testing --version 1.0.9-pre
NuGet\Install-Package Superdev.AspNetCore.Testing -Version 1.0.9-pre
<PackageReference Include="Superdev.AspNetCore.Testing" Version="1.0.9-pre" />
<PackageVersion Include="Superdev.AspNetCore.Testing" Version="1.0.9-pre" />
<PackageReference Include="Superdev.AspNetCore.Testing" />
paket add Superdev.AspNetCore.Testing --version 1.0.9-pre
#r "nuget: Superdev.AspNetCore.Testing, 1.0.9-pre"
#:package Superdev.AspNetCore.Testing@1.0.9-pre
#addin nuget:?package=Superdev.AspNetCore.Testing&version=1.0.9-pre&prerelease
#tool nuget:?package=Superdev.AspNetCore.Testing&version=1.0.9-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.
Security
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();
}
Options
Use writable options
Use writable options when a configuration section should be available through the regular options pipeline and should also be updateable at runtime.
ConfigureWritable<T>:
- binds the configuration section to the standard options infrastructure
- registers
IWritableOptions<T>for the same section - persists updates back to
appsettings.jsonby default
IWritableOptions<T> extends IOptionsSnapshot<T>, so you can still read the current value via Value or Get(name), and you also get write operations such as UpdateAsync(...) and UpdatePropertyAsync(...).
Register writable options:
using Superdev.AspNetCore.Options;
builder.Services.ConfigureWritable<MyFeatureOptions>(
builder.Configuration.GetSection("MyFeature"));
Use a different file if needed:
using Superdev.AspNetCore.Options;
builder.Services.ConfigureWritable<MyFeatureOptions>(
builder.Configuration.GetSection("MyFeature"),
"appsettings.Development.json");
Update options at runtime:
using Microsoft.AspNetCore.Mvc;
using Superdev.AspNetCore.Options;
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();
}
}
Update multiple values in one operation:
await this.options.UpdateAsync(current =>
{
current.Enabled = true;
current.RefreshIntervalInMinutes = 5;
});
Use regular options for read-only scenarios and IWritableOptions<T> only where runtime persistence is actually required.
Writable options modify the configured JSON file on disk. Use this feature intentionally and avoid exposing it through unprotected endpoints.
System Abstractions
Use system abstractions
This package contains lightweight abstractions for system services which make business code easier to test.
Inject IDateTime:
using Superdev.AspNetCore.Services;
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;
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);
}
}
Exception Handling
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.