BarakoCMS.Testing 4.3.0

dotnet add package BarakoCMS.Testing --version 4.3.0
                    
NuGet\Install-Package BarakoCMS.Testing -Version 4.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="BarakoCMS.Testing" Version="4.3.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="BarakoCMS.Testing" Version="4.3.0" />
                    
Directory.Packages.props
<PackageReference Include="BarakoCMS.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 BarakoCMS.Testing --version 4.3.0
                    
#r "nuget: BarakoCMS.Testing, 4.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 BarakoCMS.Testing@4.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=BarakoCMS.Testing&version=4.3.0
                    
Install as a Cake Addin
#tool nuget:?package=BarakoCMS.Testing&version=4.3.0
                    
Install as a Cake Tool

<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 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
4.3.0 90 9/21/2026
4.0.0 104 9/7/2026