Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin-framework/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
daveaglick committed Dec 20, 2022
2 parents 5c311e4 + f6b50b3 commit 79e6f43
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/core/Statiq.Core/Modules/Control/ExecuteIf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ protected override async Task<IEnumerable<IDocument>> ExecuteContextAsync(IExecu
}
}
}
else
else if (!hasExecuted)
{
if (await condition.Predicate.GetValueAsync(null, context))
{
Expand Down
12 changes: 12 additions & 0 deletions src/extensions/Statiq.Images/MutateImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,18 @@ public MutateImage OutputAsBmp()
return this;
}

/// <summary>
/// Outputs the image as WebP. This will override the default
/// behavior of outputting the image as the same format.
/// </summary>
/// <returns>The current module instance.</returns>
public MutateImage OutputAsWebp()
{
_operations.Peek().OutputActions.Add(
new OutputAction((i, s) => i.SaveAsWebp(s), x => x.ChangeExtension(".webp")));
return this;
}

/// <summary>
/// Allows you to specify an alternate output format for the image.
/// For example, you might use this if you want to full specify the encoder and it's properties.
Expand Down
2 changes: 1 addition & 1 deletion src/extensions/Statiq.Images/Statiq.Images.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<PackageTags>Statiq Static StaticContent StaticSite Blog BlogEngine Images ImageProcessor</PackageTags>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.4" />
<PackageReference Include="SixLabors.ImageSharp" Version="2.1.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\core\Statiq.Common\Statiq.Common.csproj" />
Expand Down
120 changes: 120 additions & 0 deletions tests/core/Statiq.Core.Tests/Modules/Control/ExecuteIfFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,126 @@ public async Task FalseIfWithContextResultsInCorrectCounts()
c.OutputCount.ShouldBe(12);
}

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

[Test]
public async Task FalseIfWithFollowingElseIfWithContextResultsInCorrectCounts()
{
// 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(_ => false), b)
.ElseIf(Config.FromContext(_ => true), c));

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

[Test]
public async Task TrueIfWithFollowingElseWithContextResultsInCorrectCounts()
{
// 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)
.Else(c));

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

[Test]
public async Task FalseIfWithFollowingElseWithContextResultsInCorrectCounts()
{
// 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(_ => false), b)
.Else(c));

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

[Test]
public async Task UnmatchedDocumentsAreAddedToResults()
{
Expand Down

0 comments on commit 79e6f43

Please sign in to comment.