-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
125 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using Newtonsoft.Json; | ||
namespace ZendeskApi.Client.Models | ||
{ | ||
public class Tag | ||
{ | ||
[JsonProperty("name")] | ||
public string Name { get; set; } | ||
|
||
[JsonProperty("count")] | ||
public int Count { get; set; } | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/ZendeskApi.Client/Resources/Interfaces/ITagsResource.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using ZendeskApi.Client.Models; | ||
using ZendeskApi.Client.Responses; | ||
|
||
namespace ZendeskApi.Client.Resources.Interfaces | ||
{ | ||
public interface ITagsResource | ||
{ | ||
#region List | ||
/// <summary> | ||
/// Lists all tags. This request is paginated. | ||
/// </summary> | ||
Task<ICursorPagination<Tag>> GetAllAsync( | ||
CursorPager cursor, | ||
CancellationToken cancellationToken = default(CancellationToken)); | ||
|
||
#endregion | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Logging; | ||
using ZendeskApi.Client.Models; | ||
using ZendeskApi.Client.Resources.Interfaces; | ||
using ZendeskApi.Client.Responses; | ||
|
||
namespace ZendeskApi.Client.Resources | ||
{ | ||
public class TagsResource : AbstractBaseResource<TagsResource>, ITagsResource | ||
{ | ||
private static string ResourceUri = "/api/v2/tags"; | ||
public TagsResource(IZendeskApiClient apiClient, ILogger logger) : base(apiClient, logger, "tags") | ||
{ | ||
} | ||
|
||
public async Task<ICursorPagination<Tag>> GetAllAsync(CursorPager cursor, CancellationToken cancellationToken = default) | ||
{ | ||
return await GetAsync<TagResponse>( | ||
ResourceUri, | ||
"list-tags", | ||
"ListAsync", | ||
cursor, | ||
cancellationToken: cancellationToken); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System.Collections.Generic; | ||
using Newtonsoft.Json; | ||
using ZendeskApi.Client.Models; | ||
|
||
namespace ZendeskApi.Client.Responses | ||
{ | ||
[JsonObject] | ||
public class TagResponse : CursorPaginationResponse<Tag> | ||
{ | ||
[JsonProperty("tags")] | ||
public IEnumerable<Tag> Tags { get; set; } | ||
|
||
protected override IEnumerable<Tag> Enumerable => Tags; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
test/ZendeskApi.Client.IntegrationTests/Resources/TagsResourceTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
using ZendeskApi.Client.IntegrationTests.Factories; | ||
using ZendeskApi.Client.Models; | ||
|
||
namespace ZendeskApi.Client.IntegrationTests.Resources | ||
{ | ||
public class TagsResourceTest : IClassFixture<ZendeskClientFactory> | ||
{ | ||
private readonly ZendeskClientFactory _clientFactory; | ||
|
||
public TagsResourceTest( | ||
ZendeskClientFactory clientFactory) | ||
{ | ||
_clientFactory = clientFactory; | ||
} | ||
|
||
|
||
[Fact] | ||
public async Task GetAllAsync_WhenCalledWithCursorPagination_ShouldBePaginatable() | ||
{ | ||
var client = _clientFactory.GetClient(); | ||
|
||
var cursorPager = new CursorPager { Size = 5 }; | ||
var tagsPageOne = await client | ||
.Tags.GetAllAsync(cursorPager); | ||
|
||
Assert.NotNull(tagsPageOne); | ||
Assert.Equal(5, tagsPageOne.Count()); | ||
Assert.True(tagsPageOne.Meta.HasMore); | ||
|
||
cursorPager.AfterCursor = tagsPageOne.Meta.AfterCursor; | ||
|
||
var tagsPageTwo = await client.Tags.GetAllAsync(cursorPager); | ||
Assert.NotNull(tagsPageTwo); | ||
Assert.Equal(5, tagsPageTwo.Count()); | ||
|
||
var tagIdsPageOne = tagsPageOne.Select(tag => tag.Name).ToList(); | ||
var tagIdsPageTwo = tagsPageTwo.Select(tag => tag.Name).ToList(); | ||
Assert.NotEqual(tagIdsPageOne, tagIdsPageTwo); | ||
} | ||
} | ||
} |