Suwbackkit.Testing 0.4.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Suwbackkit.Testing --version 0.4.0
                    
NuGet\Install-Package Suwbackkit.Testing -Version 0.4.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.4.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Suwbackkit.Testing" Version="0.4.0" />
                    
Directory.Packages.props
<PackageReference Include="Suwbackkit.Testing" />
                    
Project file
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.4.0
                    
#r "nuget: Suwbackkit.Testing, 0.4.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.4.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.4.0
                    
Install as a Cake Addin
#tool nuget:?package=Suwbackkit.Testing&version=0.4.0
                    
Install as a Cake Tool

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's postgres database with a 3-second timeout and no pooling.
  • They refuse any database whose name lacks the word test between underscores or hyphens (myapp_test, myapp_test_<checkout>, myapp_test_knowledge, myapp_seed_test pass; myapp, postgres, latest, myapp_tests do not), before they connect, with an InvalidOperationException that names the database and the fix. A connection string pointed at an app's own database by mistake (a stray TEST_CONNECTION_STRING) can never drop it.
  • LinkedWorktree.RefuseSharedDatabase(), called first in the fixture, throws when TEST_CONNECTION_STRING is not set and the tests run in a linked git worktree (its .git is a file pointing into the main checkout's worktrees folder): the fixture would otherwise drop and recreate the main checkout's test database under the tests running there. The message says to run them after eval "$(<app>.Web/node_modules/.bin/suwgate dev checkout-env)", which names the checkout's own databases, or to run the gate. RefuseSharedDatabase(testConnectionString, testDirectory) takes both from the caller, for a test of the fixture.
  • CapturedLogs, an ILoggerProvider that keeps every entry in memory as a CapturedLog (category, level, message, and the TraceId of 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()
    {
        LinkedWorktree.RefuseSharedDatabase();
        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 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.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.5.2 69 11/22/2026
0.5.1 61 11/22/2026
0.5.0 80 11/21/2026
0.4.0 76 11/21/2026
0.3.0 68 11/21/2026