BarakoCMS.Testing
4.3.0
dotnet add package BarakoCMS.Testing --version 4.3.0
NuGet\Install-Package BarakoCMS.Testing -Version 4.3.0
<PackageReference Include="BarakoCMS.Testing" Version="4.3.0" />
<PackageVersion Include="BarakoCMS.Testing" Version="4.3.0" />
<PackageReference Include="BarakoCMS.Testing" />
paket add BarakoCMS.Testing --version 4.3.0
#r "nuget: BarakoCMS.Testing, 4.3.0"
#:package BarakoCMS.Testing@4.3.0
#addin nuget:?package=BarakoCMS.Testing&version=4.3.0
#tool nuget:?package=BarakoCMS.Testing&version=4.3.0
<div align="center"> <img src="https://raw.githubusercontent.com/BaryoDev/barakoCMS/master/BarakoCMS.Testing/assets/icon.png" width="96" height="96" alt="BarakoCMS.Testing logo" /> <h1>BarakoCMS.Testing</h1> <p><em>A running barakoCMS for your module's tests.</em></p> </div>
BarakoTestHost starts a PostgreSQL through Testcontainers, builds the real barakoCMS host with
the modules you name, applies the schema, seeds the system roles and the admin, and runs every
module's seeder. Your test then talks to it over HTTP. Nothing is faked, so a module that fails
the contract check or reaches for a document type it does not own fails here the way it would
fail on a deployment.
Use it
dotnet add package BarakoCMS.Testing
Derive a fixture that names your module and its settings, then take it as an xunit class fixture:
public sealed class MyHost : BarakoTestHost
{
public MyHost() : base(o =>
{
o.Modules.Add(new MyModule());
o.Settings["Modules:MyModule:ApiKey"] = "test";
}) { }
}
public class MyModuleTests : IClassFixture<MyHost>
{
private readonly MyHost _host;
public MyModuleTests(MyHost host) => _host = host;
[Fact]
public async Task The_endpoint_answers()
{
var client = await _host.CreateAdminClientAsync();
var response = await client.GetAsync("/api/mymodule/things");
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}
}
BarakoTestHost<MyModule> is the same for a module with a parameterless constructor and no
settings. One container per fixture, shared by every test in the class. Each host validates
tokens with its own key, so several fixtures can run in one test process.
What it gives you
| Member | What it is |
|---|---|
CreateClient() |
An anonymous client |
CreateAdminClientAsync() |
Signed in as the seeded admin (SuperAdmin and Admin) on the default tenant |
CreateAdminClientAsync(slug) |
The same admin on another tenant, with the membership and the X-Tenant header |
CreateClientAsync("Admin") |
A new user holding only the named seeded roles, so a capability your seeder grants is tested on its own |
CreateTenantAsync() |
An active tenant with a random slug |
OpenSession() |
A Marten session for arranging data or reading what an endpoint wrote |
Services |
The host's service provider |
AdminUsername, AdminPassword |
For a test that signs in through POST /api/auth/login |
JwtKey |
The key this host signs and validates with |
Settings you pass override the host's own. The host sets the connection string, a fresh JWT key,
InitialAdmin, Swagger:Enabled=true and Seed:DemoContent=false.
Needs
Docker, for the container. dotnet new barakocms-module (the BarakoCMS.Templates package) produces
a module and a test project already on this package.
Part of barakoCMS
This package belongs to barakoCMS, an open-source headless CMS for .NET 10. MODULES.md is the module contract.
Licensed under MPL-2.0.
| 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
- AspNetCore.HealthChecks.Npgsql (>= 9.0.0)
- AspNetCore.HealthChecks.System (>= 9.0.0)
- AspNetCore.HealthChecks.UI (>= 9.0.0)
- AspNetCore.HealthChecks.UI.Client (>= 9.0.0)
- AspNetCore.HealthChecks.UI.InMemory.Storage (>= 9.0.0)
- BarakoCMS (>= 4.3.0)
- BarakoCMS.Abstractions (>= 4.3.0)
- BCrypt.Net-Next (>= 4.2.0)
- FastEndpoints (>= 8.3.0)
- FastEndpoints.Security (>= 8.3.0)
- FastEndpoints.Swagger (>= 8.3.0)
- IdentityModel (>= 7.0.0)
- JasperFx (>= 2.72.0)
- KubernetesClient (>= 18.0.13)
- Marten (>= 9.37.0)
- Microsoft.AspNetCore.TestHost (>= 10.0.11)
- Microsoft.Extensions.DependencyModel (>= 10.0.11)
- Microsoft.Extensions.Http.Resilience (>= 10.9.0)
- Microsoft.IdentityModel.JsonWebTokens (>= 8.22.0)
- Otp.NET (>= 1.4.1)
- prometheus-net.AspNetCore (>= 8.2.1)
- Serilog.AspNetCore (>= 10.0.0)
- Serilog.Sinks.Console (>= 6.1.1)
- Serilog.Sinks.File (>= 7.0.0)
- SSH.NET (>= 2026.0.0)
- System.IdentityModel.Tokens.Jwt (>= 8.22.0)
- Testcontainers.PostgreSql (>= 4.15.0)
- xunit.v3.extensibility.core (>= 4.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.