Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/Tests/PageSelectionTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[TestFixture]
public class PageSelectionTests
{
[Test]
public void SinglePageRejectsNegativeIndex()
{
// A negative index would render nothing and produce a confusing downstream error; reject it
// at the call site instead. Zero (the first page) remains valid.
var settings = new VerifySettings();
Assert.Throws<ArgumentOutOfRangeException>(() => settings.SinglePage(-1));
}

[Test]
public void PagesToIncludeRejectsNonPositiveCount()
{
// Zero or fewer pages leaves nothing to verify and drives a negative page range into the
// pdf subset; require at least one page.
var settings = new VerifySettings();
Assert.Throws<ArgumentOutOfRangeException>(() => settings.PagesToInclude(0));
Assert.Throws<ArgumentOutOfRangeException>(() => settings.PagesToInclude(-1));
}

[Test]
public void AcceptsBoundaryValues()
{
// The lowest valid values must pass: page index 0 and a count of 1.
var settings = new VerifySettings();
Assert.DoesNotThrow(() => settings.SinglePage(0));
Assert.DoesNotThrow(() => settings.PagesToInclude(1));
}
}
20 changes: 17 additions & 3 deletions src/Verify.DocNet/VerifyDocNet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,15 @@ public static void Initialize()
VerifierSettings.RegisterFileConverter<IDocReader>((target, context) => Convert(null, target, context));
}

public static void PagesToInclude(this VerifySettings settings, int count) =>
public static void PagesToInclude(this VerifySettings settings, int count)
{
if (count < 1)
{
throw new ArgumentOutOfRangeException(nameof(count), count, "PagesToInclude count must be greater than or equal to 1.");
}

settings.Context["VerifyDocNetPagesToInclude"] = count;
}

public static SettingsTask PagesToInclude(this SettingsTask settings, int count)
{
Expand All @@ -37,8 +44,15 @@ static int GetPagesToInclude(this IReadOnlyDictionary<string, object> settings,
return count;
}

public static void SinglePage(this VerifySettings settings, int index) =>
settings.Context["VerifyDocNetSinglePage"] = index;
public static void SinglePage(this VerifySettings settings, int index)
{
if (index < 0)
{
throw new ArgumentOutOfRangeException(nameof(index), index, "SinglePage index must be greater than or equal to 0.");
}

settings.Context["VerifyDocNetSinglePage"] = index;
}

/// <summary>
/// Zero based index of single page to include (overrules PagesToInclude when in range)
Expand Down
Loading