private async Task ParameterizedTestAsync( Func <UserId, UserId, IReadOnlyList <ChannelId>, IReadOnlyList <QueueId>, DateTime, bool, NonNegativeInt, PositiveInt, IReadOnlyList <NewsfeedPost>, int, Task> parameterizedTest) { var totalLivePosts = SortedLiveNewsfeedPosts.Count; NonNegativeInt noPaginationStart = NonNegativeInt.Parse(0); PositiveInt noPaginationCount = PositiveInt.Parse(int.MaxValue); var wrapper = new ParameterizedTestWrapper(parameterizedTest); parameterizedTest = wrapper.Execute; // No pagination. await parameterizedTest( CreatorId, CreatorId, null, null, Now, false, noPaginationStart, noPaginationCount, SortedLiveNewsfeedPosts, 0); // Paginate from start. await parameterizedTest( CreatorId, CreatorId, null, null, Now, false, NonNegativeInt.Parse(0), PositiveInt.Parse(10), SortedLiveNewsfeedPosts.Take(10).ToList(), 0); // Paginate from middle with different page size and page index. await parameterizedTest( CreatorId, CreatorId, null, null, Now, false, NonNegativeInt.Parse(5), PositiveInt.Parse(10), SortedLiveNewsfeedPosts.Skip(5).Take(10).ToList(), 0); // Paginate from middle with same page size and page index. await parameterizedTest( CreatorId, CreatorId, null, null, Now, false, NonNegativeInt.Parse(10), PositiveInt.Parse(10), SortedLiveNewsfeedPosts.Skip(10).Take(10).ToList(), 0); // Paginate from near end, requesting up to last post. await parameterizedTest( CreatorId, CreatorId, null, null, Now, false, NonNegativeInt.Parse(totalLivePosts - 10), PositiveInt.Parse(10), SortedLiveNewsfeedPosts.Skip(totalLivePosts - 10).Take(10).ToList(), 0); // Paginate from near end, requesting beyond last post. await parameterizedTest( CreatorId, CreatorId, null, null, Now, false, NonNegativeInt.Parse(totalLivePosts - 5), PositiveInt.Parse(10), SortedLiveNewsfeedPosts.Skip(totalLivePosts - 5).Take(10).ToList(), 0); // Paginate from end, requesting beyond last post. await parameterizedTest( CreatorId, CreatorId, null, null, Now, false, NonNegativeInt.Parse(totalLivePosts), PositiveInt.Parse(1), new NewsfeedPost[0], 0); // Paginate from beyond end, requesting beyond last post. await parameterizedTest( CreatorId, CreatorId, null, null, Now, false, NonNegativeInt.Parse(totalLivePosts + 1), PositiveInt.Parse(1), new NewsfeedPost[0], 0); // Unsubscribed. await parameterizedTest( UnsubscribedUserId, CreatorId, null, null, Now, false, noPaginationStart, noPaginationCount, new NewsfeedPost[0], 0); // Subscribed at correct price, fetch from all subscriptions. await parameterizedTest( SubscribedUserId, null, null, null, Now, false, noPaginationStart, noPaginationCount, SortedLiveNewsfeedPosts.Where(v => !v.ChannelId.Equals(ChannelIds[2])).ToList(), 10); // Subscribed at correct price. await parameterizedTest( SubscribedUserId, CreatorId, null, null, Now, false, noPaginationStart, noPaginationCount, SortedLiveNewsfeedPosts.Where(v => !v.ChannelId.Equals(ChannelIds[2])).ToList(), 10); // Subscribed at zero, but on free access list. await parameterizedTest( GuestListUserId, CreatorId, null, null, Now, false, noPaginationStart, noPaginationCount, SortedLiveNewsfeedPosts.Where(v => !v.ChannelId.Equals(ChannelIds[2])).ToList(), 0); // Filter by channel for creator. await parameterizedTest( CreatorId, CreatorId, new[] { ChannelIds[0] }, null, Now, false, noPaginationStart, noPaginationCount, SortedLiveNewsfeedPosts.Where(v => v.ChannelId.Equals(ChannelIds[0])).ToList(), 0); // Filter by channel. await parameterizedTest( SubscribedUserId, null, new[] { ChannelIds[0] }, null, Now, false, noPaginationStart, noPaginationCount, SortedLiveNewsfeedPosts.Where(v => v.ChannelId.Equals(ChannelIds[0])).ToList(), 10); // Filter by channel 2. await parameterizedTest( SubscribedUserId, null, new[] { ChannelIds[1] }, null, Now, false, noPaginationStart, noPaginationCount, SortedLiveNewsfeedPosts.Where(v => v.ChannelId.Equals(ChannelIds[1])).ToList(), 10); // Filter by unsubscribed channel 3. await parameterizedTest( SubscribedUserId, null, new[] { ChannelIds[2] }, null, Now, false, noPaginationStart, noPaginationCount, new NewsfeedPost[0], 10); // Filter by valid channel and creator combination. await parameterizedTest( SubscribedUserId, CreatorId, new[] { ChannelIds[0] }, null, Now, false, noPaginationStart, noPaginationCount, SortedLiveNewsfeedPosts.Where(v => v.ChannelId.Equals(ChannelIds[0])).ToList(), 10); // Filter by invalid channel and creator combination. await parameterizedTest( SubscribedUserId, GuestListUserId, new[] { ChannelIds[0] }, null, Now, false, noPaginationStart, noPaginationCount, new NewsfeedPost[0], 10); // Search forwards from now. await parameterizedTest( CreatorId, CreatorId, null, null, Now, true, noPaginationStart, noPaginationCount, new NewsfeedPost[0], 0); // Search forwards from beginning. await parameterizedTest( CreatorId, CreatorId, null, null, SqlDateTime.MinValue.Value, true, noPaginationStart, noPaginationCount, SortedLiveNewsfeedPosts.Reverse().ToList(), 0); // Paginate forwards from middle with different page size and page index. await parameterizedTest( CreatorId, CreatorId, null, null, SqlDateTime.MinValue.Value, true, NonNegativeInt.Parse(5), PositiveInt.Parse(10), SortedLiveNewsfeedPosts.Reverse().Skip(5).Take(10).ToList(), 0); }
private async Task ParameterizedTestAsync( Func <UserId, UserId, IReadOnlyList <ChannelId>, IReadOnlyList <QueueId>, DateTime, bool, NonNegativeInt, PositiveInt, IReadOnlyList <PreviewNewsfeedPost>, int, Task> parameterizedTest) { var totalLivePosts = SortedLiveNewsfeedPosts.Count; NonNegativeInt noPaginationStart = NonNegativeInt.Parse(0); PositiveInt noPaginationCount = PositiveInt.Parse(int.MaxValue); var wrapper = new ParameterizedTestWrapper(parameterizedTest); parameterizedTest = wrapper.Execute; var visibleSortedLiveNewsfeedPosts = SortedLiveNewsfeedPosts.Where(v => !v.ChannelId.Equals(ChannelIds[3])).ToList(); // No pagination. await parameterizedTest( CreatorId, CreatorId, null, null, Now, false, noPaginationStart, noPaginationCount, visibleSortedLiveNewsfeedPosts.ToList(), 0); // Paginate from start. await parameterizedTest( CreatorId, CreatorId, null, null, Now, false, NonNegativeInt.Parse(0), PositiveInt.Parse(10), visibleSortedLiveNewsfeedPosts.Take(10).ToList(), 0); // Paginate from middle with different page size and page index. await parameterizedTest( CreatorId, CreatorId, null, null, Now, false, NonNegativeInt.Parse(5), PositiveInt.Parse(10), visibleSortedLiveNewsfeedPosts.Skip(5).Take(10).ToList(), 0); // Paginate from middle with same page size and page index. await parameterizedTest( CreatorId, CreatorId, null, null, Now, false, NonNegativeInt.Parse(10), PositiveInt.Parse(10), visibleSortedLiveNewsfeedPosts.Skip(10).Take(10).ToList(), 0); // Paginate from near end, requesting up to last post. await parameterizedTest( CreatorId, CreatorId, null, null, Now, false, NonNegativeInt.Parse(totalLivePosts - 10), PositiveInt.Parse(10), visibleSortedLiveNewsfeedPosts.Skip(totalLivePosts - 10).Take(10).ToList(), 0); // Paginate from near end, requesting beyond last post. await parameterizedTest( CreatorId, CreatorId, null, null, Now, false, NonNegativeInt.Parse(totalLivePosts - 5), PositiveInt.Parse(10), visibleSortedLiveNewsfeedPosts.Skip(totalLivePosts - 5).Take(10).ToList(), 0); // Paginate from end, requesting beyond last post. await parameterizedTest( CreatorId, CreatorId, null, null, Now, false, NonNegativeInt.Parse(totalLivePosts), PositiveInt.Parse(1), new PreviewNewsfeedPost[0], 0); // Paginate from beyond end, requesting beyond last post. await parameterizedTest( CreatorId, CreatorId, null, null, Now, false, NonNegativeInt.Parse(totalLivePosts + 1), PositiveInt.Parse(1), new PreviewNewsfeedPost[0], 0); // Unsubscribed. await parameterizedTest( UnsubscribedUserId, CreatorId, null, null, Now, false, noPaginationStart, noPaginationCount, visibleSortedLiveNewsfeedPosts, 0); // Unsubscribed, fetch from all subscriptions (will ignore non-discoverable channel). await parameterizedTest( UnsubscribedUserId, null, null, null, Now, false, noPaginationStart, noPaginationCount, SortedLiveNewsfeedPosts.Where(v => v.ChannelId.Equals(ChannelIds[0]) || v.ChannelId.Equals(ChannelIds[2])).ToList(), 10); // Logged out. await parameterizedTest( null, CreatorId, null, null, Now, false, noPaginationStart, noPaginationCount, visibleSortedLiveNewsfeedPosts, 0); // Logged out, fetch from all subscriptions (will ignore non-discoverable channel). await parameterizedTest( null, null, null, null, Now, false, noPaginationStart, noPaginationCount, SortedLiveNewsfeedPosts.Where(v => v.ChannelId.Equals(ChannelIds[0]) || v.ChannelId.Equals(ChannelIds[2])).ToList(), 10); // Logged in as creator, filter by channel for creator (will ignore non-discoverable channel). await parameterizedTest( CreatorId, null, null, null, Now, false, noPaginationStart, noPaginationCount, SortedLiveNewsfeedPosts.Where(v => v.ChannelId.Equals(ChannelIds[0]) || v.ChannelId.Equals(ChannelIds[2])).ToList(), 0); // Filter by channel for creator. await parameterizedTest( CreatorId, CreatorId, new[] { ChannelIds[0] }, null, Now, false, noPaginationStart, noPaginationCount, SortedLiveNewsfeedPosts.Where(v => v.ChannelId.Equals(ChannelIds[0])).ToList(), 0); // Filter by channel. await parameterizedTest( UnsubscribedUserId, null, new[] { ChannelIds[0] }, null, Now, false, noPaginationStart, noPaginationCount, SortedLiveNewsfeedPosts.Where(v => v.ChannelId.Equals(ChannelIds[0])).ToList(), 10); // Filter by channel 2. await parameterizedTest( UnsubscribedUserId, null, new[] { ChannelIds[1] }, null, Now, false, noPaginationStart, noPaginationCount, SortedLiveNewsfeedPosts.Where(v => v.ChannelId.Equals(ChannelIds[1])).ToList(), 10); // Filter by valid channel and creator combination. await parameterizedTest( UnsubscribedUserId, CreatorId, new[] { ChannelIds[0] }, null, Now, false, noPaginationStart, noPaginationCount, SortedLiveNewsfeedPosts.Where(v => v.ChannelId.Equals(ChannelIds[0])).ToList(), 10); // Filter by invalid channel and creator combination. await parameterizedTest( UnsubscribedUserId, UserId.Random(), new[] { ChannelIds[0] }, null, Now, false, noPaginationStart, noPaginationCount, new PreviewNewsfeedPost[0], 10); // Search forwards from now. await parameterizedTest( CreatorId, CreatorId, null, null, Now, true, noPaginationStart, noPaginationCount, new PreviewNewsfeedPost[0], 0); // Search forwards from beginning. await parameterizedTest( CreatorId, CreatorId, null, null, SqlDateTime.MinValue.Value, true, noPaginationStart, noPaginationCount, visibleSortedLiveNewsfeedPosts.AsEnumerable().Reverse().ToList(), 0); // Paginate forwards from middle with different page size and page index. await parameterizedTest( CreatorId, CreatorId, null, null, SqlDateTime.MinValue.Value, true, NonNegativeInt.Parse(5), PositiveInt.Parse(10), visibleSortedLiveNewsfeedPosts.AsEnumerable().Reverse().Skip(5).Take(10).ToList(), 0); }