Suwbackkit.Testing
0.3.0
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Suwbackkit.Testing --version 0.3.0
NuGet\Install-Package Suwbackkit.Testing -Version 0.3.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Suwbackkit.Testing" Version="0.3.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Suwbackkit.Testing" Version="0.3.0" />
<PackageReference Include="Suwbackkit.Testing" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Suwbackkit.Testing --version 0.3.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Suwbackkit.Testing, 0.3.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Suwbackkit.Testing@0.3.0
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Suwbackkit.Testing&version=0.3.0
#tool nuget:?package=Suwbackkit.Testing&version=0.3.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Suwbackkit.Testing
Test helpers for the backends of Manomenu's apps, the ones every app's test project carried a copy of. Nothing here knows xUnit: the app's fixture keeps its own skipping and lifetime.
TestDatabases.RecreateAsync(connectionString)drops the database the connection string names (closing every connection to it) and creates it empty;TestDatabases.DropAsync(connectionString)drops it, and is no error when it is gone. Both connect to the server'spostgresdatabase with a 3-second timeout and no pooling.- They refuse any database whose name lacks the word
testbetween underscores or hyphens (myapp_test,myapp_test_<checkout>,myapp_test_knowledge,myapp_seed_testpass;myapp,postgres,latest,myapp_testsdo not), before they connect, with anInvalidOperationExceptionthat names the database and the fix. A connection string pointed at an app's own database by mistake (a strayTEST_CONNECTION_STRING) can never drop it. CapturedLogs, anILoggerProviderthat keeps every entry in memory as aCapturedLog(category, level, message, and theTraceIdof the scope it was written in, the one ASP.NET Core opens per request), so a test can assert that a request's error was logged with the trace id the response carries.
Usage
using Suwbackkit.Postgres;
using Suwbackkit.Testing;
[assembly: AssemblyFixture(typeof(Myapp.Server.Tests.TestDatabase))]
public sealed class TestDatabase : IAsyncLifetime
{
public static readonly string ConnectionString =
Environment.GetEnvironmentVariable("TEST_CONNECTION_STRING")
?? "Host=127.0.0.1;Port=5533;Database=myapp_test;Username=myapp;Password=myapp";
public async ValueTask InitializeAsync()
{
await TestDatabases.RecreateAsync(ConnectionString);
await Migrator.MigrateAsync(ConnectionString, Migrator.DefaultDirectory);
}
public ValueTask DisposeAsync() => ValueTask.CompletedTask;
}
var logs = new CapturedLogs();
builder.Services.AddSingleton<ILoggerProvider>(logs);
// ...
Assert.Contains(logs.Entries, entry => entry.Level == LogLevel.Error && entry.TraceId == traceId);
Source, license and changes: https://github.com/Manomenu/suwbackkit
| 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- Npgsql (>= 10.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.