xunit

xUnit 2.9.3 is the testing framework for all 30 test projects in Sorcha. Tests use FluentAssertions for readable assertions and Moq for mocking. All tests follow strict MethodName_Scenario_ExpectedBehavior naming.

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "xunit" with this command: npx skills add stuartf303/sorcha/stuartf303-sorcha-xunit

xUnit Skill

xUnit 2.9.3 is the testing framework for all 30 test projects in Sorcha. Tests use FluentAssertions for readable assertions and Moq for mocking. All tests follow strict MethodName_Scenario_ExpectedBehavior naming.

Quick Start

Unit Test Structure

// SPDX-License-Identifier: MIT // Copyright (c) 2026 Sorcha Contributors

public class WalletManagerTests { private readonly Mock<IRepository<Wallet>> _mockRepository; private readonly WalletManager _sut;

public WalletManagerTests()
{
    _mockRepository = new Mock&#x3C;IRepository&#x3C;Wallet>>();
    _sut = new WalletManager(_mockRepository.Object);
}

[Fact]
public async Task CreateAsync_ValidWallet_ReturnsSuccess()
{
    // Arrange
    var wallet = new Wallet { Name = "Test" };
    _mockRepository.Setup(r => r.AddAsync(wallet)).ReturnsAsync(wallet);

    // Act
    var result = await _sut.CreateAsync(wallet);

    // Assert
    result.IsSuccess.Should().BeTrue();
    result.Value.Should().Be(wallet);
}

}

Theory with InlineData

[Theory] [InlineData(12)] [InlineData(15)] [InlineData(18)] [InlineData(21)] [InlineData(24)] public void GenerateMnemonic_ValidWordCount_ReturnsCorrectLength(int wordCount) { var result = _keyManager.GenerateMnemonic(wordCount);

result.IsSuccess.Should().BeTrue();
result.Value!.Split(' ').Should().HaveCount(wordCount);

}

Key Concepts

Concept Usage Example

[Fact]

Single test case [Fact] public void Method_Test() {}

[Theory]

Parameterized tests [Theory] [InlineData(1)] public void Method(int x) {}

IClassFixture<T>

Per-class shared state class Tests : IClassFixture<DbFixture>

ICollectionFixture<T>

Cross-class shared state [Collection("Db")] class Tests

IAsyncLifetime

Async setup/teardown Task InitializeAsync() , Task DisposeAsync()

Common Patterns

Exception Testing

[Fact] public void Constructor_NullRepository_ThrowsArgumentNullException() { var act = () => new WalletManager(null!);

act.Should().Throw&#x3C;ArgumentNullException>()
    .WithParameterName("repository");

}

[Fact] public async Task ProcessAsync_InvalidData_ThrowsWithMessage() { var exception = await Assert.ThrowsAsync<InvalidOperationException>( () => _processor.ProcessAsync(invalidContext));

exception.Message.Should().Contain("validation failed");

}

Async Test Pattern

[Fact] public async Task ExecuteAsync_ValidBlueprint_CompletesSuccessfully() { // Arrange var blueprint = CreateTestBlueprint();

// Act
var result = await _engine.ExecuteAsync(blueprint);

// Assert
result.Success.Should().BeTrue();
result.ProcessedData.Should().ContainKey("output");

}

See Also

  • patterns - Test patterns and anti-patterns

  • workflows - Test workflows and fixtures

Related Skills

  • See the fluent-assertions skill for assertion patterns

  • See the moq skill for mocking dependencies

  • See the entity-framework skill for database testing with InMemory provider

  • See the postgresql skill for Testcontainers integration tests

Documentation Resources

Fetch latest xUnit documentation with Context7.

How to use Context7:

  • Use mcp__context7__resolve-library-id to search for "xunit"

  • Query with mcp__context7__query-docs using the resolved library ID

Library ID: /xunit/xunit.net (875 code snippets, High reputation)

Recommended Queries:

  • "xUnit Theory InlineData patterns"

  • "IClassFixture ICollectionFixture shared context"

  • "IAsyncLifetime async setup teardown"

  • "xUnit parallel test execution configuration"

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

General

entity-framework

No summary provided by upstream source.

Repository SourceNeeds Review
General

signalr

No summary provided by upstream source.

Repository SourceNeeds Review
General

scalar

No summary provided by upstream source.

Repository SourceNeeds Review
General

grpc

No summary provided by upstream source.

Repository SourceNeeds Review