From 8482a04f0e60c3db9826155648bd22a44c9c3969 Mon Sep 17 00:00:00 2001 From: Rosario Pulella Date: Wed, 12 May 2021 12:43:36 -0400 Subject: [PATCH] Paramitize pageSize and page count for unit tests --- .../Test_IncrementalLoadingCollection.cs | 77 ++++++++++--------- 1 file changed, 42 insertions(+), 35 deletions(-) diff --git a/UnitTests/UnitTests.UWP/UI/Collection/Test_IncrementalLoadingCollection.cs b/UnitTests/UnitTests.UWP/UI/Collection/Test_IncrementalLoadingCollection.cs index d845e1d9c7a..f6b213ba1c6 100644 --- a/UnitTests/UnitTests.UWP/UI/Collection/Test_IncrementalLoadingCollection.cs +++ b/UnitTests/UnitTests.UWP/UI/Collection/Test_IncrementalLoadingCollection.cs @@ -15,9 +15,6 @@ namespace UnitTests.UI [TestClass] public class Test_IncrementalLoadingCollection { - private const int PageSize = 20; - private const int Pages = 5; - private static readonly DataSource.PageOperation[] FailPassSequence = new DataSource.PageOperation[] { @@ -28,35 +25,36 @@ private static readonly DataSource.PageOperation[] FailPassSequence DataSource.ThrowException, DataSource.PassThrough, }; - private static readonly int[] AllData - = Enumerable.Range(0, Pages * PageSize).ToArray(); - - [DataRow] - [DataRow(2500, 1000, 1000, 1000, 1000)] [TestMethod] - public async Task Requests(params int[] pageDelays) + [DataRow(20, 5)] + [DataRow(5, 5)] + [DataRow(20, 5, 2500, 1000, 1000, 1000, 1000)] + public async Task Requests(int pageSize, int pages, params int[] pageDelays) { - var source = new DataSource(AllData, pageDelays.Select(DataSource.MakeDelayOp)); - var collection = new IncrementalLoadingCollection, int>(source, PageSize); + var allData = Enumerable.Range(0, pages * pageSize).ToArray(); + var source = new DataSource(allData, pageDelays.Select(DataSource.MakeDelayOp)); + var collection = new IncrementalLoadingCollection, int>(source, pageSize); - for (int pageNum = 1; pageNum <= Pages; pageNum++) + for (var pageNum = 1; pageNum <= pages; pageNum++) { await collection.LoadMoreItemsAsync(0); - CollectionAssert.AreEqual(Enumerable.Range(0, PageSize * pageNum).ToArray(), collection); + CollectionAssert.AreEqual(Enumerable.Range(0, pageSize * pageNum).ToArray(), collection); } } - [DataRow] - [DataRow(2500, 1000, 1000, 1000, 1000)] [TestMethod] - public async Task RequestsAsync(params int[] pageDelays) + [DataRow(20, 5)] + [DataRow(5, 5)] + [DataRow(20, 5, 2500, 1000, 1000, 1000, 1000)] + public async Task RequestsAsync(int pageSize, int pages, params int[] pageDelays) { - var source = new DataSource(AllData, pageDelays.Select(DataSource.MakeDelayOp)); - var collection = new IncrementalLoadingCollection, int>(source, PageSize); + var allData = Enumerable.Range(0, pages * pageSize).ToArray(); + var source = new DataSource(allData, pageDelays.Select(DataSource.MakeDelayOp)); + var collection = new IncrementalLoadingCollection, int>(source, pageSize); var requests = new List(); - for (int pageNum = 1; pageNum <= Pages; pageNum++) + for (var pageNum = 1; pageNum <= pages; pageNum++) { requests.Add(collection.LoadMoreItemsAsync(0).AsTask() .ContinueWith(t => Assert.IsTrue(t.IsCompletedSuccessfully))); @@ -64,14 +62,17 @@ public async Task RequestsAsync(params int[] pageDelays) await Task.WhenAll(requests); - CollectionAssert.AreEqual(AllData, collection); + CollectionAssert.AreEqual(allData, collection); } [TestMethod] - public async Task FirstRequestFails() + [DataRow(5, 5)] + [DataRow(20, 5)] + public async Task FirstRequestFails(int pageSize, int pages) { - var source = new DataSource(AllData, DataSource.ThrowException); - var collection = new IncrementalLoadingCollection, int>(source, PageSize); + var allData = Enumerable.Range(0, pages * pageSize).ToArray(); + var source = new DataSource(allData, DataSource.ThrowException); + var collection = new IncrementalLoadingCollection, int>(source, pageSize); await Assert.ThrowsExceptionAsync(collection.LoadMoreItemsAsync(0).AsTask); @@ -79,7 +80,7 @@ public async Task FirstRequestFails() var requests = new List(); - for (int pageNum = 1; pageNum <= Pages; pageNum++) + for (var pageNum = 1; pageNum <= pages; pageNum++) { requests.Add(collection.LoadMoreItemsAsync(0).AsTask() .ContinueWith(t => Assert.IsTrue(t.IsCompletedSuccessfully))); @@ -87,17 +88,20 @@ public async Task FirstRequestFails() await Task.WhenAll(requests); - CollectionAssert.AreEqual(AllData, collection); + CollectionAssert.AreEqual(allData, collection); } [TestMethod] - public async Task EveryOtherRequestFails() + [DataRow(5, 5)] + [DataRow(20, 5)] + public async Task EveryOtherRequestFails(int pageSize, int pages) { - var source = new DataSource(AllData, FailPassSequence); - var collection = new IncrementalLoadingCollection, int>(source, PageSize); + var allData = Enumerable.Range(0, pages * pageSize).ToArray(); + var source = new DataSource(allData, FailPassSequence); + var collection = new IncrementalLoadingCollection, int>(source, pageSize); var willFail = true; - for (int submitedRequests = 0; submitedRequests < Pages * 2; submitedRequests++) + for (var submitedRequests = 0; submitedRequests < pages * 2; submitedRequests++) { if (willFail) { @@ -111,19 +115,22 @@ public async Task EveryOtherRequestFails() willFail = !willFail; } - CollectionAssert.AreEqual(AllData, collection); + CollectionAssert.AreEqual(allData, collection); } [TestMethod] - public async Task EveryOtherRequestFailsAsync() + [DataRow(5, 5)] + [DataRow(20, 5)] + public async Task EveryOtherRequestFailsAsync(int pageSize, int pages) { - var source = new DataSource(AllData, FailPassSequence); - var collection = new IncrementalLoadingCollection, int>(source, PageSize); + var allData = Enumerable.Range(0, pages * pageSize).ToArray(); + var source = new DataSource(allData, FailPassSequence); + var collection = new IncrementalLoadingCollection, int>(source, pageSize); var requests = new List(); var willFail = true; - for (int submitedRequests = 0; submitedRequests < Pages * 2; submitedRequests++) + for (var submitedRequests = 0; submitedRequests < pages * 2; submitedRequests++) { if (willFail) { @@ -139,7 +146,7 @@ public async Task EveryOtherRequestFailsAsync() await Task.WhenAll(requests); - CollectionAssert.AreEqual(AllData, collection); + CollectionAssert.AreEqual(allData, collection); } } } \ No newline at end of file