Browse Source

Throw, don't adjust.

pull/1286/head
James Jackson-South 6 years ago
parent
commit
10b57fdb7a
  1. 9
      src/ImageSharp/Configuration.cs
  2. 8
      tests/ImageSharp.Tests/ConfigurationTests.cs

9
src/ImageSharp/Configuration.cs

@ -25,8 +25,6 @@ namespace SixLabors.ImageSharp
/// A lazily initialized configuration default instance. /// A lazily initialized configuration default instance.
/// </summary> /// </summary>
private static readonly Lazy<Configuration> Lazy = new Lazy<Configuration>(CreateDefaultInstance); private static readonly Lazy<Configuration> Lazy = new Lazy<Configuration>(CreateDefaultInstance);
private const int MinStreamProcessingBufferSize = 128;
private const int DefaultStreamProcessingBufferSize = 8096; private const int DefaultStreamProcessingBufferSize = 8096;
private int streamProcessingBufferSize = DefaultStreamProcessingBufferSize; private int streamProcessingBufferSize = DefaultStreamProcessingBufferSize;
private int maxDegreeOfParallelism = Environment.ProcessorCount; private int maxDegreeOfParallelism = Environment.ProcessorCount;
@ -79,17 +77,16 @@ namespace SixLabors.ImageSharp
/// <summary> /// <summary>
/// Gets or sets the size of the buffer to use when working with streams. /// Gets or sets the size of the buffer to use when working with streams.
/// Intitialized with <see cref="DefaultStreamProcessingBufferSize"/> by default /// Intitialized with <see cref="DefaultStreamProcessingBufferSize"/> by default.
/// and can accept a minimum value of <see cref="MinStreamProcessingBufferSize"/>.
/// </summary> /// </summary>
public int StreamProcessingBufferSize public int StreamProcessingBufferSize
{ {
get => this.streamProcessingBufferSize; get => this.streamProcessingBufferSize;
set set
{ {
if (value < MinStreamProcessingBufferSize) if (value <= 0)
{ {
value = MinStreamProcessingBufferSize; throw new ArgumentOutOfRangeException(nameof(this.StreamProcessingBufferSize));
} }
this.streamProcessingBufferSize = value; this.streamProcessingBufferSize = value;

8
tests/ImageSharp.Tests/ConfigurationTests.cs

@ -141,12 +141,10 @@ namespace SixLabors.ImageSharp.Tests
[Fact] [Fact]
public void StreamBufferSize_CannotGoBelowMinimum() public void StreamBufferSize_CannotGoBelowMinimum()
{ {
var config = new Configuration var config = new Configuration();
{
StreamProcessingBufferSize = 0
};
Assert.Equal(128, config.StreamProcessingBufferSize); Assert.Throws<ArgumentOutOfRangeException>(
() => config.StreamProcessingBufferSize = 0);
} }
} }
} }

Loading…
Cancel
Save