Skip to content

Commit

Permalink
address comments and add new factory to the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fbvilela committed Dec 13, 2023
1 parent ab87126 commit 0af94f4
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -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<T> : IEnumerable<T>
{

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System;
using Microsoft.Extensions.DependencyInjection;
using ZendeskApi.Client.Responses;

namespace ZendeskApi.Client.Pagination
Expand Down
10 changes: 2 additions & 8 deletions src/ZendeskApi.Client/ZendeskApi.Client.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<Import Project=".\..\ZendeskApi.Build\ZendeskApi.Commons.props" />

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>
<Description>A Zendesk Api Client for use with the ZendeskApi v2</Description>
Expand All @@ -17,10 +17,4 @@
<PackageReference Include="System.Reflection.Extensions" Version="4.3.0" />
</ItemGroup>

<ItemGroup>
<None Remove="Pagination\" />
</ItemGroup>
<ItemGroup>
<Folder Include="Pagination\" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -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<ZendeskClientFactory>
{
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
Expand All @@ -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<Ticket>(ticketsResponse, apiClient);
var iterator = cursorPaginatedIteratorFactory.Create<Ticket>(ticketsResponse);
Assert.True(iterator.HasMore());
Assert.Equal(2, iterator.Count());
var ticketIdsPageOne = iterator.Select(ticket => ticket.Id).ToList();
Expand Down
Original file line number Diff line number Diff line change
@@ -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<T> Create<T>(ICursorPagination<T> response)
{
return new CursorPaginatedIterator<T>(response, zendeskClientFactory.GetApiClient());
}
}
}

Original file line number Diff line number Diff line change
@@ -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<ZendeskClientFactory>
{
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<JobStatusResponse>(results, apiClient);
var iterator = cursorPaginatedIteratorFactory.Create<JobStatusResponse>(results);

Assert.NotNull(results);
Assert.Equal(2, iterator.Count());
Expand All @@ -40,4 +38,4 @@ public async Task GetAllAsync_WhenCalledWithCursorPagination_ShouldBePaginatable
}

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ public class RequestsResourceTests : IClassFixture<ZendeskClientFactory>
{
private readonly ITestOutputHelper _output;
private readonly ZendeskClientFactory _clientFactory;
private readonly CursorPaginatedIteratorFactory cursorPaginatedIteratorFactory;

public RequestsResourceTests(
ITestOutputHelper output,
ZendeskClientFactory clientFactory)
{
_output = output;
_clientFactory = clientFactory;
cursorPaginatedIteratorFactory = new CursorPaginatedIteratorFactory(clientFactory);
}

[Fact]
Expand Down Expand Up @@ -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<Request>(requestsResponse, apiClient);
var requestsIterator = cursorPaginatedIteratorFactory.Create<Request>(requestsResponse);
Assert.Equal(1, requestsIterator.Count());

var commentsResponse = await client.Requests.GetAllComments((long)requestsIterator.First().Id, cursor);
Expand Down

0 comments on commit 0af94f4

Please sign in to comment.