ManagedCode.IntegrationTestBaseKit.XUnit 0.0.2

Prefix Reserved
dotnet add package ManagedCode.IntegrationTestBaseKit.XUnit --version 0.0.2                
NuGet\Install-Package ManagedCode.IntegrationTestBaseKit.XUnit -Version 0.0.2                
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="ManagedCode.IntegrationTestBaseKit.XUnit" Version="0.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ManagedCode.IntegrationTestBaseKit.XUnit --version 0.0.2                
#r "nuget: ManagedCode.IntegrationTestBaseKit.XUnit, 0.0.2"                
#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.
// Install ManagedCode.IntegrationTestBaseKit.XUnit as a Cake Addin
#addin nuget:?package=ManagedCode.IntegrationTestBaseKit.XUnit&version=0.0.2

// Install ManagedCode.IntegrationTestBaseKit.XUnit as a Cake Tool
#tool nuget:?package=ManagedCode.IntegrationTestBaseKit.XUnit&version=0.0.2                

IntegrationTestBaseKit

Overview

IntegrationTestBaseKit is a library designed to facilitate the creation and management of Docker containers for integration testing purposes. It provides a set of tools to start, stop, and check the readiness of Docker containers in a thread-safe manner.

Features

  • Start and stop Docker containers asynchronously.
  • Check container readiness using customizable wait strategies.
  • Event-driven notifications for container lifecycle events (starting, started, stopping, stopped).

Installation

To install the library, use the following command:

dotnet add package ManagedCode.IntegrationTestBaseKit

for xUnit integration use the following command:

dotnet add package ManagedCode.ManagedCode.IntegrationTestBaseKit.XUnit

Usage

Creating a Test Application Define a TestApp class that inherits from BaseXUnitTestApp<TestBlazorApp.Program>, add ICollectionFixture<TestApp>

using DotNet.Testcontainers.Containers;
using Testcontainers.Azurite;
using Testcontainers.PostgreSql;
using Xunit;

namespace ManagedCode.IntegrationTestBaseKit.Tests
{
    [CollectionDefinition(nameof(TestApp))]
    public class TestApp : BaseXUnitTestApp<TestBlazorApp.Program>, ICollectionFixture<TestApp>
    {
        protected override async Task ConfigureTestContainers()
        {
            AddContainer(new AzuriteBuilder().Build());
            AddContainer("postgree", new PostgreSqlBuilder().Build());
        }
    }
}

Writing Tests

Use the TestApp class in your tests to manage Docker containers.

using DotNet.Testcontainers.Containers;
using FluentAssertions;
using Testcontainers.Azurite;
using Testcontainers.PostgreSql;
using Xunit.Abstractions;

namespace ManagedCode.IntegrationTestBaseKit.Tests;

[Collection(nameof(TestApp))]
public class HealthTests(ITestOutputHelper log, TestApp testApplication)
{
    [Fact]
    public async Task HealthTest()
    {
        var client = testApplication.CreateHttpClient();
        var response = await client.GetAsync("/health");
        response.EnsureSuccessStatusCode();
    }

    [Fact]
    public async Task BrowserHealthTest()
    {
        var page = await testApplication.OpenNewPage("/health");
        var content = await page.ContentAsync();
        content.Contains("Healthy")
            .Should()
            .BeTrue();
    }
    
    [Fact]
    public async Task HealthTest()
    {
        var client = testApplication.CreateSignalRClient("/healthHub");
        await client.StartAsync();

        client.State
            .Should()
            .Be(HubConnectionState.Connected);

        var result = await client.InvokeAsync<string>("Health");
        result.Should()
            .Be("Healthy");
    }
}
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.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.0.2 348 9/9/2024
0.0.1 97 8/24/2024