statiqdev / Statiq.Framework

A flexible and extensible static content generation framework for .NET.
https://statiq.dev/framework
MIT License
425 stars 74 forks source link

Possible bug in `ElseIf` when `Predicate.RequiresDocument` is `false` #255

Closed nils-a closed 1 year ago

nils-a commented 1 year ago

Maybe I'm holding it wrong, but I feel I've found a bug.

I've added a failing unit test like this:

[Test]
public async Task TrueIfWithFollowingElseIfWithContextResultsInCorrectCounts()
{
    // Given
    CountModule a = new CountModule("A")
    {
        AdditionalOutputs = 2,
        EnsureInputDocument = true
    };
    CountModule b = new CountModule("B")
    {
        AdditionalOutputs = 2
    };
    CountModule c = new CountModule("C")
    {
        AdditionalOutputs = 3
    };

    // When
    await ExecuteAsync(
        a,
        new ExecuteIf(Config.FromContext(_ => true), b)
            .ElseIf(Config.FromContext(_ => true), c));

    // Then
    a.ExecuteCount.ShouldBe(1);
    b.ExecuteCount.ShouldBe(1);
    c.ExecuteCount.ShouldBe(0);
}