From 0af94f4ab51df4da2a789ccdb748eaeca6f81f56 Mon Sep 17 00:00:00 2001 From: Fabio Vilela Date: Wed, 13 Dec 2023 16:15:13 +1100 Subject: [PATCH] address comments and add new factory to the tests --- .../CursorPaginatedIterator.cs | 3 +-- .../CursorPaginatedIteratorFactory.cs | 2 -- .../ZendeskApi.Client.csproj | 10 ++------- .../CBPSupport/CBPSupportTests.cs | 18 +++++++++------- .../CursorPaginatedIteratorFactory.cs | 21 +++++++++++++++++++ .../Resources/JobStatusResourceTests.cs | 18 +++++++--------- .../Resources/RequestsResourceTests.cs | 5 +++-- 7 files changed, 45 insertions(+), 32 deletions(-) rename src/ZendeskApi.Client/{Models => Pagination}/CursorPaginatedIterator.cs (97%) create mode 100644 test/ZendeskApi.Client.IntegrationTests/Factories/CursorPaginatedIteratorFactory.cs diff --git a/src/ZendeskApi.Client/Models/CursorPaginatedIterator.cs b/src/ZendeskApi.Client/Pagination/CursorPaginatedIterator.cs similarity index 97% rename from src/ZendeskApi.Client/Models/CursorPaginatedIterator.cs rename to src/ZendeskApi.Client/Pagination/CursorPaginatedIterator.cs index d6a3f67c..6fa075d5 100644 --- a/src/ZendeskApi.Client/Models/CursorPaginatedIterator.cs +++ b/src/ZendeskApi.Client/Pagination/CursorPaginatedIterator.cs @@ -1,12 +1,11 @@ using System; using System.Collections; using System.Collections.Generic; -using System.Linq; using System.Threading.Tasks; using Newtonsoft.Json; -using ZendeskApi.Client; using ZendeskApi.Client.Responses; +namespace ZendeskApi.Client.Pagination; public class CursorPaginatedIterator : IEnumerable { diff --git a/src/ZendeskApi.Client/Pagination/CursorPaginatedIteratorFactory.cs b/src/ZendeskApi.Client/Pagination/CursorPaginatedIteratorFactory.cs index fcffa3d9..53a5723c 100644 --- a/src/ZendeskApi.Client/Pagination/CursorPaginatedIteratorFactory.cs +++ b/src/ZendeskApi.Client/Pagination/CursorPaginatedIteratorFactory.cs @@ -1,5 +1,3 @@ -using System; -using Microsoft.Extensions.DependencyInjection; using ZendeskApi.Client.Responses; namespace ZendeskApi.Client.Pagination diff --git a/src/ZendeskApi.Client/ZendeskApi.Client.csproj b/src/ZendeskApi.Client/ZendeskApi.Client.csproj index 47554757..4818fc22 100644 --- a/src/ZendeskApi.Client/ZendeskApi.Client.csproj +++ b/src/ZendeskApi.Client/ZendeskApi.Client.csproj @@ -1,7 +1,7 @@ - + - + netstandard2.0;net6.0 A Zendesk Api Client for use with the ZendeskApi v2 @@ -17,10 +17,4 @@ - - - - - - diff --git a/test/ZendeskApi.Client.IntegrationTests/CBPSupport/CBPSupportTests.cs b/test/ZendeskApi.Client.IntegrationTests/CBPSupport/CBPSupportTests.cs index 8aa42adc..bca9ff07 100644 --- a/test/ZendeskApi.Client.IntegrationTests/CBPSupport/CBPSupportTests.cs +++ b/test/ZendeskApi.Client.IntegrationTests/CBPSupport/CBPSupportTests.cs @@ -3,23 +3,26 @@ using Xunit; using ZendeskApi.Client.IntegrationTests.Factories; using ZendeskApi.Client.Models; +using CursorPaginatedIteratorFactory = ZendeskApi.Client.IntegrationTests.Factories.CursorPaginatedIteratorFactory; namespace ZendeskApi.Client.IntegrationTests.CBPSupport { public class CBPSupportTests : IClassFixture { - private readonly ZendeskClientFactory _clientFactory; + private readonly ZendeskClientFactory clientFactory; + private readonly CursorPaginatedIteratorFactory cursorPaginatedIteratorFactory; public CBPSupportTests( - ZendeskClientFactory clientFactory) + ZendeskClientFactory _clientFactory) { - _clientFactory = clientFactory; + clientFactory = _clientFactory; + cursorPaginatedIteratorFactory = new Factories.CursorPaginatedIteratorFactory(clientFactory); } [Fact] public async Task GetAllAsync_WhenCalledWithCursorPagination_ShouldBePaginatableByReplacingTheCursor() { - var client = _clientFactory.GetClient(); + var client = clientFactory.GetClient(); var cursorPager = new CursorPager { Size = 5 }; var ticketsPageOne = await client @@ -43,14 +46,13 @@ public async Task GetAllAsync_WhenCalledWithCursorPagination_ShouldBePaginatable [Fact] public async Task CursorPaginatedIterator_ShouldBePaginatableByCallingNextPage() { - var client = _clientFactory.GetClient(); - var apiClient = _clientFactory.GetApiClient(); - + var client = clientFactory.GetClient(); + var cursorPager = new CursorPager { Size = 2 }; var ticketsResponse = await client .Tickets.GetAllAsync(cursorPager); - var iterator = new CursorPaginatedIterator(ticketsResponse, apiClient); + var iterator = cursorPaginatedIteratorFactory.Create(ticketsResponse); Assert.True(iterator.HasMore()); Assert.Equal(2, iterator.Count()); var ticketIdsPageOne = iterator.Select(ticket => ticket.Id).ToList(); diff --git a/test/ZendeskApi.Client.IntegrationTests/Factories/CursorPaginatedIteratorFactory.cs b/test/ZendeskApi.Client.IntegrationTests/Factories/CursorPaginatedIteratorFactory.cs new file mode 100644 index 00000000..bc1684ed --- /dev/null +++ b/test/ZendeskApi.Client.IntegrationTests/Factories/CursorPaginatedIteratorFactory.cs @@ -0,0 +1,21 @@ +using System; +using ZendeskApi.Client.Pagination; +using ZendeskApi.Client.Responses; + +namespace ZendeskApi.Client.IntegrationTests.Factories +{ + public class CursorPaginatedIteratorFactory + { + private readonly ZendeskClientFactory zendeskClientFactory; + public CursorPaginatedIteratorFactory(ZendeskClientFactory _zendeskClientFactory) + { + zendeskClientFactory = _zendeskClientFactory; + } + + public CursorPaginatedIterator Create(ICursorPagination response) + { + return new CursorPaginatedIterator(response, zendeskClientFactory.GetApiClient()); + } + } +} + diff --git a/test/ZendeskApi.Client.IntegrationTests/Resources/JobStatusResourceTests.cs b/test/ZendeskApi.Client.IntegrationTests/Resources/JobStatusResourceTests.cs index 67a322aa..df8f1f08 100644 --- a/test/ZendeskApi.Client.IntegrationTests/Resources/JobStatusResourceTests.cs +++ b/test/ZendeskApi.Client.IntegrationTests/Resources/JobStatusResourceTests.cs @@ -1,36 +1,34 @@ -using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Xunit; using ZendeskApi.Client.IntegrationTests.Factories; using ZendeskApi.Client.Models; -using ZendeskApi.Client.Responses; namespace ZendeskApi.Client.IntegrationTests.Resources { public class JobStatusResourceTests : IClassFixture { - private readonly ZendeskClientFactory _clientFactory; - + private readonly ZendeskClientFactory clientFactory; + private readonly CursorPaginatedIteratorFactory cursorPaginatedIteratorFactory; public JobStatusResourceTests( - ZendeskClientFactory clientFactory) + ZendeskClientFactory _clientFactory) { - _clientFactory = clientFactory; + clientFactory = _clientFactory; + cursorPaginatedIteratorFactory = new CursorPaginatedIteratorFactory(clientFactory); } [Fact] public async Task GetAllAsync_WhenCalledWithCursorPagination_ShouldBePaginatable() { - var client = _clientFactory.GetClient(); - var apiClient = _clientFactory.GetApiClient(); + var client = clientFactory.GetClient(); var results = await client .JobStatuses.GetAllAsync(new CursorPager() { Size = 2 }); - var iterator = new CursorPaginatedIterator(results, apiClient); + var iterator = cursorPaginatedIteratorFactory.Create(results); Assert.NotNull(results); Assert.Equal(2, iterator.Count()); @@ -40,4 +38,4 @@ public async Task GetAllAsync_WhenCalledWithCursorPagination_ShouldBePaginatable } } -} \ No newline at end of file +} diff --git a/test/ZendeskApi.Client.IntegrationTests/Resources/RequestsResourceTests.cs b/test/ZendeskApi.Client.IntegrationTests/Resources/RequestsResourceTests.cs index 51e55237..ba025307 100644 --- a/test/ZendeskApi.Client.IntegrationTests/Resources/RequestsResourceTests.cs +++ b/test/ZendeskApi.Client.IntegrationTests/Resources/RequestsResourceTests.cs @@ -12,6 +12,7 @@ public class RequestsResourceTests : IClassFixture { private readonly ITestOutputHelper _output; private readonly ZendeskClientFactory _clientFactory; + private readonly CursorPaginatedIteratorFactory cursorPaginatedIteratorFactory; public RequestsResourceTests( ITestOutputHelper output, @@ -19,6 +20,7 @@ public RequestsResourceTests( { _output = output; _clientFactory = clientFactory; + cursorPaginatedIteratorFactory = new CursorPaginatedIteratorFactory(clientFactory); } [Fact] @@ -249,11 +251,10 @@ public async Task UpdateAsync_WhenCalled_ShouldUpdateRequest() public async Task GetAllAsync_And_GetAllComments_ShouldBePaginatable() { var client = _clientFactory.GetClient(); - var apiClient = _clientFactory.GetApiClient(); var cursor = new CursorPager { Size = 1 }; var requestsResponse = await client.Requests.GetAllAsync(cursor); - var requestsIterator = new CursorPaginatedIterator(requestsResponse, apiClient); + var requestsIterator = cursorPaginatedIteratorFactory.Create(requestsResponse); Assert.Equal(1, requestsIterator.Count()); var commentsResponse = await client.Requests.GetAllComments((long)requestsIterator.First().Id, cursor);