pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/managedcode/IntegrationTestBaseKit

" rel="stylesheet" href="https://github.githubassets.com/assets/primer-0b53c3bf3393e2ed.css" /> GitHub - managedcode/IntegrationTestBaseKit: Extensions for ASP.NET for managing Docker containers in integration tests.
Skip to content

Extensions for ASP.NET for managing Docker containers in integration tests.

License

Notifications You must be signed in to change notification settings

managedcode/IntegrationTestBaseKit

Repository files navigation

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");
    }
}

About

Extensions for ASP.NET for managing Docker containers in integration tests.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy