Skip to content

Commit 670b1a2

Browse files
Fix assignment of configuration options in unit tests
1 parent 83f0979 commit 670b1a2

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

src/ImageSharp/Formats/DecoderOptions.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ public sealed class DecoderOptions
1515

1616
private uint maxFrames = int.MaxValue;
1717

18+
// Used by the FileProvider in the unit tests to set the configuration on the fly.
19+
#pragma warning disable SA1401 // Fields should be private
20+
internal Configuration BackingConfiguration = Configuration.Default;
21+
#pragma warning restore SA1401 // Fields should be private
22+
1823
/// <summary>
1924
/// Gets the shared default general decoder options instance.
2025
/// Used internally to reduce allocations for default decoding operations.
@@ -24,7 +29,7 @@ public sealed class DecoderOptions
2429
/// <summary>
2530
/// Gets a custom configuration instance to be used by the image processing pipeline.
2631
/// </summary>
27-
public Configuration Configuration { get; init; } = Configuration.Default;
32+
public Configuration Configuration { get => this.BackingConfiguration; init => this.BackingConfiguration = value; }
2833

2934
/// <summary>
3035
/// 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
4651
/// </summary>
4752
public uint MaxFrames { get => this.maxFrames; init => this.maxFrames = Math.Clamp(value, 1, int.MaxValue); }
4853
}
54+
55+
internal static class DecoderOptionsExtensions
56+
{
57+
public static void SetConfiguration(this DecoderOptions options, Configuration configuration)
58+
=> options.BackingConfiguration = configuration;
59+
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ public override async Task<Image<TPixel>> GetImageAsync(IImageDecoder decoder, D
207207
Guard.NotNull(decoder, nameof(decoder));
208208
Guard.NotNull(options, nameof(options));
209209

210-
options.Configuration = this.Configuration;
210+
options.SetConfiguration(this.Configuration);
211211

212212
// Used in small subset of decoder tests, no caching.
213213
// TODO: Check Path here. Why combined?
@@ -244,7 +244,7 @@ public override async Task<Image<TPixel>> GetImageAsync<T>(ISpecializedImageDeco
244244
Guard.NotNull(decoder, nameof(decoder));
245245
Guard.NotNull(options, nameof(options));
246246

247-
options.GeneralOptions.Configuration = this.Configuration;
247+
options.GeneralOptions.SetConfiguration(this.Configuration);
248248

249249
// Used in small subset of decoder tests, no caching.
250250
// TODO: Check Path here. Why combined?
@@ -268,7 +268,7 @@ public override void Serialize(IXunitSerializationInfo info)
268268

269269
private Image<TPixel> DecodeImage(IImageDecoder decoder, DecoderOptions options)
270270
{
271-
options.Configuration = this.Configuration;
271+
options.SetConfiguration(this.Configuration);
272272

273273
var testFile = TestFile.Create(this.FilePath);
274274
using Stream stream = new MemoryStream(testFile.Bytes);
@@ -278,7 +278,7 @@ private Image<TPixel> DecodeImage(IImageDecoder decoder, DecoderOptions options)
278278
private Image<TPixel> DecodeImage<T>(ISpecializedImageDecoder<T> decoder, T options)
279279
where T : class, ISpecializedDecoderOptions, new()
280280
{
281-
options.GeneralOptions.Configuration = this.Configuration;
281+
options.GeneralOptions.SetConfiguration(this.Configuration);
282282

283283
var testFile = TestFile.Create(this.FilePath);
284284
using Stream stream = new MemoryStream(testFile.Bytes);

0 commit comments

Comments
 (0)