diff --git a/DebugProbe.AspNetCore.Tests/Configuration/DebugProbeOptionsTests.cs b/DebugProbe.AspNetCore.Tests/Configuration/DebugProbeOptionsTests.cs index 69f760a..d0f08d4 100644 --- a/DebugProbe.AspNetCore.Tests/Configuration/DebugProbeOptionsTests.cs +++ b/DebugProbe.AspNetCore.Tests/Configuration/DebugProbeOptionsTests.cs @@ -87,4 +87,21 @@ public void MaxEntries_negative_throws_InvalidOperationException() Assert.Contains("MaxEntries", exception.Message); } + + [Fact] + public void MaxBodyCaptureSizeKb_negative_throws_ArgumentOutOfRangeException() + { + var options = new DebugProbeOptions(); + + Assert.Throws(() => options.MaxBodyCaptureSizeKb = -1); + } + + [Fact] + public void MaxBodyCaptureSizeKb_zero_is_valid() + { + var options = new DebugProbeOptions(); + options.MaxBodyCaptureSizeKb = 0; + + Assert.Equal(0, options.MaxBodyCaptureSizeKb); + } } diff --git a/DebugProbe.AspNetCore/Options/DebugProbeOptions.cs b/DebugProbe.AspNetCore/Options/DebugProbeOptions.cs index ba5599f..d6d735e 100644 --- a/DebugProbe.AspNetCore/Options/DebugProbeOptions.cs +++ b/DebugProbe.AspNetCore/Options/DebugProbeOptions.cs @@ -1,4 +1,4 @@ -namespace DebugProbe.AspNetCore.Options; +namespace DebugProbe.AspNetCore.Options; /// /// Configuration options for DebugProbe. @@ -13,7 +13,18 @@ public class DebugProbeOptions /// /// Maximum captured request or response body size in kilobytes. /// - public int MaxBodyCaptureSizeKb { get; set; } = 32; + private int _maxBodyCaptureSizeKb = 32; + public int MaxBodyCaptureSizeKb + { + get => _maxBodyCaptureSizeKb; + set + { + if (value < 0) + throw new ArgumentOutOfRangeException(nameof(MaxBodyCaptureSizeKb), + "MaxBodyCaptureSizeKb must be 0 or greater. Use 0 to disable body capture."); + _maxBodyCaptureSizeKb = value; + } + } internal int MaxBodyCaptureSizeBytes => MaxBodyCaptureSizeKb * 1024;