Browse Source

Fix assignment of configuration options in unit tests

pull/2357/head
James Jackson-South 3 years ago
parent
commit
670b1a27bb
  1. 13
      src/ImageSharp/Formats/DecoderOptions.cs
  2. 8
      tests/ImageSharp.Tests/TestUtilities/ImageProviders/FileProvider.cs

13
src/ImageSharp/Formats/DecoderOptions.cs

@ -15,6 +15,11 @@ public sealed class DecoderOptions
private uint maxFrames = int.MaxValue;
// Used by the FileProvider in the unit tests to set the configuration on the fly.
#pragma warning disable SA1401 // Fields should be private
internal Configuration BackingConfiguration = Configuration.Default;
#pragma warning restore SA1401 // Fields should be private
/// <summary>
/// Gets the shared default general decoder options instance.
/// Used internally to reduce allocations for default decoding operations.
@ -24,7 +29,7 @@ public sealed class DecoderOptions
/// <summary>
/// Gets a custom configuration instance to be used by the image processing pipeline.
/// </summary>
public Configuration Configuration { get; init; } = Configuration.Default;
public Configuration Configuration { get => this.BackingConfiguration; init => this.BackingConfiguration = value; }
/// <summary>
/// Gets the target size to decode the image into. Scaling should use an operation equivalent to <see cref="ResizeMode.Max"/>.
@ -46,3 +51,9 @@ public sealed class DecoderOptions
/// </summary>
public uint MaxFrames { get => this.maxFrames; init => this.maxFrames = Math.Clamp(value, 1, int.MaxValue); }
}
internal static class DecoderOptionsExtensions
{
public static void SetConfiguration(this DecoderOptions options, Configuration configuration)
=> options.BackingConfiguration = configuration;
}

8
tests/ImageSharp.Tests/TestUtilities/ImageProviders/FileProvider.cs

@ -207,7 +207,7 @@ public abstract partial class TestImageProvider<TPixel> : IXunitSerializable
Guard.NotNull(decoder, nameof(decoder));
Guard.NotNull(options, nameof(options));
options.Configuration = this.Configuration;
options.SetConfiguration(this.Configuration);
// Used in small subset of decoder tests, no caching.
// TODO: Check Path here. Why combined?
@ -244,7 +244,7 @@ public abstract partial class TestImageProvider<TPixel> : IXunitSerializable
Guard.NotNull(decoder, nameof(decoder));
Guard.NotNull(options, nameof(options));
options.GeneralOptions.Configuration = this.Configuration;
options.GeneralOptions.SetConfiguration(this.Configuration);
// Used in small subset of decoder tests, no caching.
// TODO: Check Path here. Why combined?
@ -268,7 +268,7 @@ public abstract partial class TestImageProvider<TPixel> : IXunitSerializable
private Image<TPixel> DecodeImage(IImageDecoder decoder, DecoderOptions options)
{
options.Configuration = this.Configuration;
options.SetConfiguration(this.Configuration);
var testFile = TestFile.Create(this.FilePath);
using Stream stream = new MemoryStream(testFile.Bytes);
@ -278,7 +278,7 @@ public abstract partial class TestImageProvider<TPixel> : IXunitSerializable
private Image<TPixel> DecodeImage<T>(ISpecializedImageDecoder<T> decoder, T options)
where T : class, ISpecializedDecoderOptions, new()
{
options.GeneralOptions.Configuration = this.Configuration;
options.GeneralOptions.SetConfiguration(this.Configuration);
var testFile = TestFile.Create(this.FilePath);
using Stream stream = new MemoryStream(testFile.Bytes);

Loading…
Cancel
Save