xchain 0.3.1-main.1

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

Xchain

Build NuGet

Xchain extends xUnit with a fluent mechanism to chain tests, pass data, and skip dependent tests if previous ones fail — ideal for integration or system tests with interdependencies.

Features

  • Chained execution: Tests can conditionally run based on previous outcomes.
  • Shared output state: Tests exchange data via TestChainFixture.
  • Skips on failure: Later tests are skipped if earlier ones fail.
  • Custom ordering: Tests are run in a defined sequence using Link.
  • Named tests: Set display name with Name, auto-prepended with # Link.
  • Zero-padded sorting: Use Pad to ensure consistent numeric display alignment.
  • Custom metadata: Add test traits via simple attribute classes.

Example: Chained Execution with Display Names

[TestCaseOrderer("Xchain.ChainOrderer", "Xchain")]
public class ChainTest(TestChainFixture chain) : IClassFixture<TestChainFixture>
{
    [ChainFact(Link = 3, Name = "Throw Exception")]
    public void Test1() => chain.LinkUnless<Exception>((output) =>
    {
        throw new NotImplementedException();
    });

    [ChainFact(Link = 2, Name = "Sleep 2 seconds")]
    public async Task Test2() => await chain.LinkUnlessAsync<NotImplementedException>(async (output, cancellationToken) =>
    {
        var sleep = output.Get<int>("Sleep");
        await Task.Delay(sleep, cancellationToken);
    });

    [ChainFact(Link = 1, Name = "Sleep 1 second", Pad = 2)]
    [ChainTag(Owner = "Kethoneinuo", Category = "Important", Color = "Black")]
    public async Task Test3() => await chain.LinkAsync(async (output, cancellationToken) =>
    {
        const int sleep = 1000;
        output["Sleep"] = sleep * 2;
        await Task.Delay(sleep, cancellationToken);
    }, TimeSpan.FromMilliseconds(100));

    [ChainFact(Link = 4, Name = "Fails again")]
    public void Test4() => chain.LinkUnless<Exception>((output) =>
    {
        throw new NotImplementedException();
    });

    [ChainFact(Link = 5, Name = "Yet another fail")]
    public void Test5() => chain.LinkUnless<Exception>((output) =>
    {
        throw new NotImplementedException();
    });
}

Each test is displayed as:

#01 | Sleep 1 second
#2 | Sleep 2 seconds
#3 | Throw Exception
#4 | Fails again
#5 | Yet another fail

If Pad = 2, it ensures alignment even when Link goes beyond 9 (e.g., #01, #10, #15).

Fluent Chaining Methods

  • Link — executes and captures exceptions
  • LinkUnless<TException> — skips test if exception TException was previously thrown
  • LinkAsync / LinkUnlessAsync<TException> — async equivalents

Sharing Data Across Tests

Xchain uses a TestChainFixture to share both output values and captured exceptions.

[TestCaseOrderer("Xchain.ChainOrderer", "Xchain")]
public class ChainTest(TestChainFixture chain) : IClassFixture<TestChainFixture>
{
    [ChainFact(Link = 1, Name = "Setup")]
    public void Test1() => chain.Output["Sleep"] = 1500;

    [ChainFact(Link = 2, Name = "Sleep using shared value")]
    public void Test2()
    {
        var sleep = (int)chain.Output["Sleep"];
        Thread.Sleep(sleep);
    }
}

Skipping on Previous Failures

[ChainFact(Link = 3, Name = "Failing Root")]
public void Root() => throw new TimeoutException();

[ChainFact(Link = 4, Name = "Skip if Exception")]
public void Dependent() => chain.LinkUnless<Exception>((output) =>
{
    // This test will be skipped
});

Traits with Custom Attributes

You can define custom metadata for filtering and categorization.

[TraitDiscoverer("Xchain.TraitDiscoverer", "Xchain")]
[AttributeUsage(AttributeTargets.Method)]
public class ChainTagAttribute(string? owner = null, string? category = null, string? color = null)
    : Attribute, ITraitAttribute
{
    public string? Owner { get; set; } = owner;
    public string? Category { get; set; } = category;
    public string? Color { get; set; } = color;
}

Usage:

[ChainFact(Link = 1, Name = "Custom Tagged")]
[ChainTag(Owner = "Dev", Category = "Regression", Color = "Red")]
public void TaggedTest() => ...

Test Output Preview

Xchain.Tests.ChainTest: #1 | Sleep 1 second        ✅ Passed
Xchain.Tests.ChainTest: #2 | Sleep 2 seconds       ✅ Passed
Xchain.Tests.ChainTest: #3 | Throw Exception       ❌ Failed
Xchain.Tests.ChainTest: #4 | Fails again           ⚠️ Skipped due to prior failure
Xchain.Tests.ChainTest: #5 | Yet another fail      ⚠️ Skipped due to prior failure

Summary

Feature Description
ChainFact(Link) Defines order and enables chaining
Name Sets test display name (with #Link)
Pad Pads link number (e.g., #01)
LinkUnless<T> Skips if specific exception occurred
Output[...] Share data between tests
ChainTagAttribute Adds test traits dynamically

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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.4.0 449 6/29/2025
0.3.5-try-output.7 120 6/18/2025
0.3.5-try-output.2 121 6/18/2025
0.3.5-main.2 74 6/29/2025
0.3.5-main.1 122 6/18/2025
0.3.5-collection-link.18 69 6/29/2025
0.3.5-collection-link.17 71 6/29/2025
0.3.5-collection-link.12 285 6/19/2025
0.3.5-collection-link.6 119 6/18/2025
0.3.5-collection-link.5 117 6/18/2025
0.3.4 146 6/18/2025
0.3.4-test-output.3 118 6/18/2025
0.3.4-test-output.2 119 6/18/2025
0.3.4-test-output.1 121 6/18/2025
0.3.4-main.1 118 6/18/2025
0.3.3 231 6/16/2025
0.3.3-main.1 121 6/16/2025
0.3.3-chain-linker.7 129 6/16/2025
0.3.2 230 6/13/2025
0.3.2-main.2 194 6/13/2025
0.3.2-flow-fact.3 238 6/13/2025
0.3.2-chain-linker.6 263 6/11/2025
0.3.1 308 5/26/2025
0.3.1-skipped-reason-emoji.1 128 5/26/2025
0.3.1-main.1 126 5/26/2025
0.3.0 153 5/26/2025
0.2.2-main.1 128 5/26/2025
0.2.2-chain-name-and-order.7 80 5/25/2025
0.2.2-chain-name-and-order.5 46 5/24/2025
0.2.1 158 5/22/2025
0.2.1-trait-discoverer.1 120 5/21/2025
0.2.1-main.1 122 5/22/2025
0.2.0 165 5/19/2025
0.1.0 162 5/18/2025
0.1.0-test-chain.3 127 5/18/2025
0.1.0-main.4 122 5/18/2025
0.1.0-main.2 128 5/18/2025
0.1.0-ci.1 125 5/18/2025
0.1.0-chain-orderer.3 123 5/18/2025