Skip to content

Commit

Permalink
Allow sort and direction parameter to be passed in when getting trash…
Browse files Browse the repository at this point in the history
…ed items (#754)
  • Loading branch information
antusus authored Oct 8, 2021
1 parent ab1b253 commit 0b4f5b8
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
37 changes: 36 additions & 1 deletion Box.V2.Test/BoxFoldersManagerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,7 @@ public async Task DeleteFolder_ValidResponse_FolderDeleted()
public async Task GetTrashItems_ValidResponse_ValidCountAndEntries()
{
/*** Arrange ***/
IBoxRequest executedRequest = null;
Handler.Setup(h => h.ExecuteAsync<BoxCollection<BoxItem>>(It.IsAny<IBoxRequest>()))
.Returns(() => Task.FromResult<IBoxResponse<BoxCollection<BoxItem>>>(new BoxResponse<BoxCollection<BoxItem>>()
{
Expand Down Expand Up @@ -830,7 +831,11 @@ public async Task GetTrashItems_ValidResponse_ValidCountAndEntries()
""offset"": 0,
""limit"": 2
}"
}));
}))
.Callback<IBoxRequest>((r) =>
{
executedRequest = r;
}) ;

/***Act ***/
BoxCollection<BoxItem> result = await _foldersManager.GetTrashItemsAsync(2, 0);
Expand All @@ -841,6 +846,36 @@ public async Task GetTrashItems_ValidResponse_ValidCountAndEntries()
Assert.AreEqual("file Tue Jul 24 010055 20129Z6GS3.csv", result.Entries[1].Name);
Assert.AreEqual("2701979016", result.Entries[0].Id);
Assert.AreEqual("2698211586", result.Entries[1].Id);
Assert.AreEqual("limit=2&offset=0", executedRequest.GetQueryString());
}

[TestMethod]
[TestCategory("CI-UNIT-TEST")]
public async Task GetTrashItems_SortParamsArePassed()
{
/*** Arrange ***/
IBoxRequest executedRequest = null;
Handler.Setup(h => h.ExecuteAsync<BoxCollection<BoxItem>>(It.IsAny<IBoxRequest>()))
.Returns(() => Task.FromResult<IBoxResponse<BoxCollection<BoxItem>>>(new BoxResponse<BoxCollection<BoxItem>>()
{
Status = ResponseStatus.Success,
ContentString = @"{
""total_count"": 0,
""entries"": [],
""offset"": 0,
""limit"": 2
}"
}))
.Callback<IBoxRequest>((r) =>
{
executedRequest = r;
});

/***Act ***/
BoxCollection<BoxItem> result = await _foldersManager.GetTrashItemsAsync(2, 0, null, false, "name", BoxSortDirection.DESC);

/*** Assert ***/
Assert.AreEqual("limit=2&offset=0&sort=name&direction=DESC", executedRequest.GetQueryString());
}

[TestMethod]
Expand Down
6 changes: 5 additions & 1 deletion Box.V2/Managers/BoxFoldersManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,16 @@ public async Task<BoxCollection<BoxCollaboration>> GetCollaborationsAsync(string
/// <param name="offset">The item at which to begin the response</param>
/// <param name="fields">Attribute(s) to include in the response</param>
/// <param name="autoPaginate">Whether or not to auto-paginate to fetch all items; defaults to false.</param>
/// <param name="sort">The field to sort items on</param>
/// <param name="direction">The direction to sort results in: ascending or descending</param>
/// <returns>A collection of items contained in the trash is returned. An error is thrown if any of the parameters are invalid.</returns>
public async Task<BoxCollection<BoxItem>> GetTrashItemsAsync(int limit, int offset = 0, IEnumerable<string> fields = null, bool autoPaginate=false)
public async Task<BoxCollection<BoxItem>> GetTrashItemsAsync(int limit, int offset = 0, IEnumerable<string> fields = null, bool autoPaginate=false, string sort = null, BoxSortDirection? direction = null)
{
BoxRequest request = new BoxRequest(_config.FoldersEndpointUri, Constants.TrashItemsPathString)
.Param("limit", limit.ToString())
.Param("offset", offset.ToString())
.Param("sort", sort)
.Param("direction", direction.ToString())
.Param(ParamFields, fields);

if (autoPaginate)
Expand Down
4 changes: 3 additions & 1 deletion Box.V2/Managers/IBoxFoldersManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,10 @@ public interface IBoxFoldersManager
/// <param name="offset">The item at which to begin the response</param>
/// <param name="fields">Attribute(s) to include in the response</param>
/// <param name="autoPaginate">Whether or not to auto-paginate to fetch all items; defaults to false.</param>
/// <param name="sort">The field to sort items on</param>
/// <param name="direction">The direction to sort results in: ascending or descending</param>
/// <returns>A collection of items contained in the trash is returned. An error is thrown if any of the parameters are invalid.</returns>
Task<BoxCollection<BoxItem>> GetTrashItemsAsync(int limit, int offset = 0, IEnumerable<string> fields = null, bool autoPaginate=false);
Task<BoxCollection<BoxItem>> GetTrashItemsAsync(int limit, int offset = 0, IEnumerable<string> fields = null, bool autoPaginate=false, string sort = null, BoxSortDirection? direction = null);

/// <summary>
/// Retrieves the files and/or folders that have been moved to the trash. Any attribute in the full files
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Expose tasks from async methods ([#742](https://github.com/box/box-windows-sdk-v2/pull/742))
- Use DateTimeOffset instead of DateTime ([#749](https://github.com/box/box-windows-sdk-v2/pull/749))
- Rework returned exceptions ([#753](https://github.com/box/box-windows-sdk-v2/pull/753))
- Allow sort and direction parameter to be passed in when getting trashed items ([#754](https://github.com/box/box-windows-sdk-v2/pull/754))

**New Features and Enhancements:**
- Add ability to get files under retention for assignment and file versions under retention for assignment ([#734](https://github.com/box/box-windows-sdk-v2/pull/734))
Expand Down

0 comments on commit 0b4f5b8

Please sign in to comment.