Skip to content

Commit

Permalink
Add some Unit Test coverage of use case to query only Total Count but…
Browse files Browse the repository at this point in the history
… no Results. Improve unit test logging outputs.
  • Loading branch information
cajuncoding committed Feb 1, 2025
1 parent b76690c commit a4ea7e7
Showing 1 changed file with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public async Task TestCursorPagingWithRawSqlWhereClauseAndNullPagingParamValuesA
{
using var sqlConnection = await CreateSqlConnectionAsync().ConfigureAwait(false);

var namePattern = "%Luke%";

ICursorPageResults<CharacterDbModel> page = await sqlConnection.ExecutePagingCursorQueryAsync<CharacterDbModel>(
//TEST Formatted SQL with line breaks, ending semi-colon, etc....
commandText: @"
Expand All @@ -90,16 +92,46 @@ FROM [dbo].[StarWarsCharacters] c
pagingParams: CursorPagingParams.ForCursors(null, null, null, null),
sqlParams: new
{
NamePattern = "%Luke%"
NamePattern = namePattern
}
);

page.Should().NotBeNull();
page.TotalCount.Should().BeNull();
page.CursorResults.Should().HaveCount(1);

TestContext.WriteLine("");
TestContext.WriteLine($"[{page.PageCount}] Page Results:");
TestContext.WriteLine("NO Cursor values provided so ALL results are expected...");
TestContext.WriteLine($"[{namePattern}] WHERE Filter Applied to Limit Primary Result Set...");
TestContext.WriteLine($"[{page.PageCount}] Page Results Returned...");
}

[TestMethod]
public async Task TestCursorPagingWithRawSqlWhereClauseToGetTotalCountButNoResults()
{
using var sqlConnection = await CreateSqlConnectionAsync().ConfigureAwait(false);

ICursorPageResults<CharacterDbModel> page = await sqlConnection.ExecutePagingCursorQueryAsync<CharacterDbModel>(
//TEST Formatted SQL with line breaks, ending semi-colon, etc....
commandText: @"
SELECT *
FROM [dbo].[StarWarsCharacters] c
WHERE c.[Name] LIKE @NamePattern;
",
new[] { OrderField.Descending<CharacterDbModel>(c => c.Id) },
//TEST PASSING IN Empty Paging Params (all values being NULL)....
pagingParams: CursorPagingParams.ForCursors(first: 0, retrieveTotalCount: true),
sqlParams: new
{
NamePattern = "%Luke%"
}
);

page.Should().NotBeNull();
page.TotalCount.Should().Be(1);//TOTAL Count == 1
page.CursorResults.Should().HaveCount(0);//NO RESULTS REQUESTED!

TestContext.WriteLine($"[{page.TotalCount}] Total Results...");
TestContext.WriteLine($"[{page.PageCount}] Page Results Returned...");
}

[TestMethod]
Expand Down

0 comments on commit a4ea7e7

Please sign in to comment.