public async Task FolderWorkflow_LiveSession_ValidResponse() { string testName = GetUniqueName(); // Test Create Folder BoxFolderRequest folderReq = new BoxFolderRequest() { Name = testName, Parent = new BoxRequestEntity() { Id = "0" } }; BoxFolder f = await _client.FoldersManager.CreateAsync(folderReq); Assert.AreEqual(testName, f.Name); // Test Get Information BoxFolder fi = await _client.FoldersManager.GetInformationAsync(f.Id); Assert.AreEqual(f.Id, fi.Id); Assert.AreEqual(testName, fi.Name); // Test Create Shared Link BoxSharedLinkRequest sharedLinkReq = new BoxSharedLinkRequest() { Access = BoxSharedLinkAccessType.open }; BoxFolder fsl = await _client.FoldersManager.CreateSharedLinkAsync(f.Id, sharedLinkReq); Assert.AreEqual(BoxSharedLinkAccessType.open, fsl.SharedLink.Access); // Test Update Folder Information string newTestname = GetUniqueName(); BoxFolderRequest updateReq = new BoxFolderRequest() { Id = f.Id, Name = newTestname, SyncState = BoxSyncStateType.not_synced, FolderUploadEmail = new BoxEmailRequest { Access = "open" } }; BoxFolder uf = await _client.FoldersManager.UpdateInformationAsync(updateReq); Assert.AreEqual(newTestname, uf.Name); // Test Copy Folder string copyTestName = GetUniqueName(); BoxFolderRequest copyReq = new BoxFolderRequest() { Id = f.Id, Parent = new BoxRequestEntity() { Id = "0" }, Name = copyTestName }; BoxFolder f2 = await _client.FoldersManager.CopyAsync(copyReq); Assert.AreEqual(copyTestName, f2.Name); // Test Delete Folder await _client.FoldersManager.DeleteAsync(f.Id, true); await _client.FoldersManager.DeleteAsync(f2.Id, true); }
public async Task CopyFolder_ValidResponse_ValidFolder() { /*** Arrange ***/ _handler.Setup(h => h.ExecuteAsync<BoxFolder>(It.IsAny<IBoxRequest>())) .Returns(() => Task.FromResult<IBoxResponse<BoxFolder>>(new BoxResponse<BoxFolder>() { Status = ResponseStatus.Success, ContentString = "{ \"type\": \"folder\", \"id\": \"11446498\", \"sequence_id\": \"1\", \"etag\": \"1\", \"name\": \"Pictures\", \"created_at\": \"2012-12-12T10:53:43-08:00\", \"modified_at\": \"2012-12-12T11:15:04-08:00\", \"description\": \"Some pictures I took\", \"size\": 629644, \"path_collection\": { \"total_count\": 1, \"entries\": [ { \"type\": \"folder\", \"id\": \"0\", \"sequence_id\": null, \"etag\": null, \"name\": \"All Files\" } ] }, \"created_by\": { \"type\": \"user\", \"id\": \"17738362\", \"name\": \"sean rose\", \"login\": \"[email protected]\" }, \"modified_by\": { \"type\": \"user\", \"id\": \"17738362\", \"name\": \"sean rose\", \"login\": \"[email protected]\" }, \"owned_by\": { \"type\": \"user\", \"id\": \"17738362\", \"name\": \"sean rose\", \"login\": \"[email protected]\" }, \"shared_link\": { \"url\": \"https://www.box.com/s/vspke7y05sb214wjokpk\", \"download_url\": \"https://www.box.com/shared/static/vspke7y05sb214wjokpk\", \"vanity_url\": null, \"is_password_enabled\": false, \"unshared_at\": null, \"download_count\": 0, \"preview_count\": 0, \"access\": \"open\", \"permissions\": { \"can_download\": true, \"can_preview\": true } }, \"folder_upload_email\": { \"access\": \"open\", \"email\": \"[email protected]\" }, \"parent\": { \"type\": \"folder\", \"id\": \"0\", \"sequence_id\": null, \"etag\": null, \"name\": \"All Files\" }, \"item_status\": \"active\", \"item_collection\": { \"total_count\": 1, \"entries\": [ { \"type\": \"file\", \"id\": \"5000948880\", \"sequence_id\": \"3\", \"etag\": \"3\", \"sha1\": \"134b65991ed521fcfe4724b7d814ab8ded5185dc\", \"name\": \"tigers.jpeg\" } ], \"offset\": 0, \"limit\": 100 } }" })); /*** Act ***/ BoxFolderRequest folderReq = new BoxFolderRequest() { Id = "fakeId", Parent = new BoxRequestEntity() { Id = "fakeId" } }; BoxFolder f = await _foldersManager.CopyAsync(folderReq); /*** Assert ***/ Assert.AreEqual("folder", f.Type); Assert.AreEqual("11446498", f.Id); Assert.AreEqual("1", f.SequenceId); Assert.AreEqual("1", f.ETag); Assert.AreEqual("Pictures", f.Name); }
private static Task<BoxFolder> CreateNewFolder(BoxClient userClient) { var folderRequest = new BoxFolderRequest { Description = "Test folder", Name = "Misc", Parent = new BoxFolderRequest { Id = "0" } }; return userClient.FoldersManager.CreateAsync(folderRequest); }
/// <summary> /// Used to create a copy of a folder in another folder. The original version of the folder will not be altered. /// </summary> /// <returns></returns> public async Task<BoxFolder> CopyAsync(BoxFolderRequest folderRequest, List<string> fields = null) { folderRequest.ThrowIfNull("folderRequest") .Id.ThrowIfNullOrWhiteSpace("folderRequest.Id"); folderRequest.Parent.ThrowIfNull("folderRequest.Parent") .Id.ThrowIfNullOrWhiteSpace("folderRequest.Parent.Id"); BoxRequest request = new BoxRequest(_config.FoldersEndpointUri, string.Format(Constants.CopyPathString, folderRequest.Id)) .Method(RequestMethod.Post) .Param(ParamFields, fields) .Payload(_converter.Serialize(folderRequest)); IBoxResponse<BoxFolder> response = await ToResponseAsync<BoxFolder>(request); return response.ResponseObject; }
/// <summary> /// Used to create a new empty folder. The new folder will be created inside of the specified parent folder /// </summary> /// <param name="folder"></param> /// <returns></returns> public async Task<BoxFolder> CreateAsync(BoxFolderRequest folderRequest, List<string> fields = null) { folderRequest.ThrowIfNull("folderRequest") .Name.ThrowIfNullOrWhiteSpace("folderRequest.Name"); folderRequest.Parent.ThrowIfNull("folderRequest.Parent") .Id.ThrowIfNullOrWhiteSpace("folderRequest.Parent.Id"); BoxRequest request = new BoxRequest(_config.FoldersEndpointUri) .Method(RequestMethod.Post) .Param(ParamFields, fields) .Payload(_converter.Serialize<BoxFolderRequest>(folderRequest)); IBoxResponse<BoxFolder> response = await ToResponseAsync<BoxFolder>(request).ConfigureAwait(false); return response.ResponseObject; }
public async Task CreateFolder_ValidResponse_ValidFolder() { _handler.Setup(h => h.ExecuteAsync<BoxFolder>(It.IsAny<IBoxRequest>())) .Returns(() => Task.FromResult<IBoxResponse<BoxFolder>>(new BoxResponse<BoxFolder>() { Status = ResponseStatus.Success, ContentString = "{ \"type\": \"folder\", \"id\": \"11446498\", \"sequence_id\": \"1\", \"etag\": \"1\", \"name\": \"Pictures\", \"created_at\": \"2012-12-12T10:53:43-08:00\", \"modified_at\": \"2012-12-12T11:15:04-08:00\", \"description\": \"Some pictures I took\", \"size\": 629644, \"path_collection\": { \"total_count\": 1, \"entries\": [ { \"type\": \"folder\", \"id\": \"0\", \"sequence_id\": null, \"etag\": null, \"name\": \"All Files\" } ] }, \"created_by\": { \"type\": \"user\", \"id\": \"17738362\", \"name\": \"sean rose\", \"login\": \"[email protected]\" }, \"modified_by\": { \"type\": \"user\", \"id\": \"17738362\", \"name\": \"sean rose\", \"login\": \"[email protected]\" }, \"owned_by\": { \"type\": \"user\", \"id\": \"17738362\", \"name\": \"sean rose\", \"login\": \"[email protected]\" }, \"shared_link\": { \"url\": \"https://www.box.com/s/vspke7y05sb214wjokpk\", \"download_url\": \"https://www.box.com/shared/static/vspke7y05sb214wjokpk\", \"vanity_url\": null, \"is_password_enabled\": false, \"unshared_at\": null, \"download_count\": 0, \"preview_count\": 0, \"access\": \"open\", \"permissions\": { \"can_download\": true, \"can_preview\": true } }, \"folder_upload_email\": { \"access\": \"open\", \"email\": \"[email protected]\" }, \"parent\": { \"type\": \"folder\", \"id\": \"0\", \"sequence_id\": null, \"etag\": null, \"name\": \"All Files\" }, \"item_status\": \"active\", \"item_collection\": { \"total_count\": 0, \"entries\": [], \"offset\": 0, \"limit\": 100 } }" })); var folderReq = new BoxFolderRequest() { Name = "test", Parent = new BoxRequestEntity() { Id = "0" } }; BoxFolder f = await _foldersManager.CreateAsync(folderReq); }
/// <summary> /// Used to update information about the folder. To move a folder, update the ID of its parent. To enable an /// email address that can be used to upload files to this folder, update the folder_upload_email attribute. /// An optional If-Match header can be included to ensure that client only updates the folder if it knows /// about the latest version. /// </summary> /// <returns></returns> public async Task<BoxFolder> UpdateInformationAsync(BoxFolderRequest folderRequest, List<string> fields = null) { folderRequest.ThrowIfNull("folderRequest") .Id.ThrowIfNullOrWhiteSpace("folderRequest.Id"); BoxRequest request = new BoxRequest(_config.FoldersEndpointUri, folderRequest.Id) .Param(ParamFields, fields) .Payload(_converter.Serialize(folderRequest)) .Method(RequestMethod.Put); IBoxResponse<BoxFolder> response = await ToResponseAsync<BoxFolder>(request); return response.ResponseObject; }
public async Task RestoreTrashedFolder_ValidResponse_ValidFolder() { /*** Arrange ***/ _handler.Setup(h => h.ExecuteAsync<BoxFolder>(It.IsAny<IBoxRequest>())) .Returns(() => Task.FromResult<IBoxResponse<BoxFolder>>(new BoxResponse<BoxFolder>() { Status = ResponseStatus.Success, ContentString = "{ \"type\": \"folder\", \"id\": \"588970022\", \"sequence_id\": \"2\", \"etag\": \"2\", \"name\": \"heloo world\", \"created_at\": \"2013-01-15T16:15:27-08:00\", \"modified_at\": \"2013-02-07T13:26:00-08:00\", \"description\": \"\", \"size\": 0, \"path_collection\": { \"total_count\": 1, \"entries\": [ { \"type\": \"folder\", \"id\": \"0\", \"sequence_id\": null, \"etag\": null, \"name\": \"All Files\" } ] }, \"created_by\": { \"type\": \"user\", \"id\": \"181757341\", \"name\": \"sean test\", \"login\": \"[email protected]\" }, \"modified_by\": { \"type\": \"user\", \"id\": \"181757341\", \"name\": \"sean test\", \"login\": \"[email protected]\" }, \"trashed_at\": null, \"purged_at\": null, \"content_created_at\": \"2013-01-15T16:15:27-08:00\", \"content_modified_at\": \"2013-02-07T13:26:00-08:00\", \"owned_by\": { \"type\": \"user\", \"id\": \"181757341\", \"name\": \"sean test\", \"login\": \"[email protected]\" }, \"shared_link\": null, \"folder_upload_email\": null, \"parent\": { \"type\": \"folder\", \"id\": \"0\", \"sequence_id\": null, \"etag\": null, \"name\": \"All Files\" }, \"item_status\": \"active\" }" })); /*** Act ***/ BoxFolderRequest folderReq = new BoxFolderRequest() { Id = "fakeId", Parent = new BoxRequestEntity() { Id = "fakeId" } }; BoxFolder f = await _foldersManager.RestoreTrashedFolderAsync(folderReq); /*** Assert ***/ Assert.AreEqual("folder", f.Type); Assert.AreEqual("588970022", f.Id); Assert.AreEqual("2", f.SequenceId); Assert.AreEqual("2", f.ETag); Assert.AreEqual("heloo world", f.Name); }
public async Task CreateFolder_ValidResponse_NameConflict() { _handler.Setup(h => h.ExecuteAsync<BoxFolder>(It.IsAny<IBoxRequest>())) .Returns(() => Task.FromResult<IBoxResponse<BoxFolder>>(new BoxResponse<BoxFolder>() { StatusCode = System.Net.HttpStatusCode.Conflict, Status = ResponseStatus.Error, ContentString = "{\"type\": \"error\", \"status\": 409, \"code\": \"item_name_in_use\", \"context_info\": {\"conflicts\":[{ \"type\": \"folder\", \"id\": \"11446498\", \"sequence_id\": \"1\", \"etag\": \"1\", \"name\": \"Pictures\", \"created_at\": \"2012-12-12T10:53:43-08:00\", \"modified_at\": \"2012-12-12T11:15:04-08:00\", \"description\": \"Some pictures I took\", \"size\": 629644, \"path_collection\": { \"total_count\": 1, \"entries\": [ { \"type\": \"folder\", \"id\": \"0\", \"sequence_id\": null, \"etag\": null, \"name\": \"All Files\" } ] }, \"created_by\": { \"type\": \"user\", \"id\": \"17738362\", \"name\": \"sean rose\", \"login\": \"[email protected]\" }, \"modified_by\": { \"type\": \"user\", \"id\": \"17738362\", \"name\": \"sean rose\", \"login\": \"[email protected]\" }, \"owned_by\": { \"type\": \"user\", \"id\": \"17738362\", \"name\": \"sean rose\", \"login\": \"[email protected]\" }, \"shared_link\": { \"url\": \"https://www.box.com/s/vspke7y05sb214wjokpk\", \"download_url\": \"https://www.box.com/shared/static/vspke7y05sb214wjokpk\", \"vanity_url\": null, \"is_password_enabled\": false, \"unshared_at\": null, \"download_count\": 0, \"preview_count\": 0, \"access\": \"open\", \"permissions\": { \"can_download\": true, \"can_preview\": true } }, \"folder_upload_email\": { \"access\": \"open\", \"email\": \"[email protected]\" }, \"parent\": { \"type\": \"folder\", \"id\": \"0\", \"sequence_id\": null, \"etag\": null, \"name\": \"All Files\" }, \"item_status\": \"active\", \"item_collection\": { \"total_count\": 0, \"entries\": [], \"offset\": 0, \"limit\": 100 } }]},\"help_url\":\"http:\\/\\/developers.box.com\\/docs\\/#errors\",\"message\":\"Item with the same name already exists\",\"request_id\":\"197141966053a1ce8c40d64\"}" })); var folderReq = new BoxFolderRequest() { Name = "test", Parent = new BoxRequestEntity() { Id = "0" } }; try { BoxFolder f = await _foldersManager.CreateAsync(folderReq); throw new BoxException("Invalid error type returned"); } catch (BoxConflictException<BoxFolder> ex) { Assert.AreEqual(Constants.ErrorCodes.Conflict, ex.Error.Code); Assert.IsTrue(ex.Error is BoxConflictError<BoxFolder>); BoxFolder f = ex.ConflictingItems.First(); Assert.AreEqual(f.Type, "folder"); Assert.AreEqual(f.Id, "11446498"); Assert.AreEqual(f.SequenceId, "1"); Assert.AreEqual(f.ETag, "1"); Assert.AreEqual(f.Name, "Pictures"); Assert.AreEqual(f.CreatedAt, DateTime.Parse("2012-12-12T10:53:43-08:00")); Assert.AreEqual(f.ModifiedAt, DateTime.Parse("2012-12-12T11:15:04-08:00")); Assert.AreEqual(f.Description, "Some pictures I took"); Assert.AreEqual(f.Size, 629644); Assert.AreEqual(f.PathCollection.TotalCount, 1); Assert.AreEqual(f.PathCollection.Entries.Count, 1); Assert.AreEqual(f.PathCollection.Entries[0].Id, "0"); Assert.IsNull(f.PathCollection.Entries[0].SequenceId); Assert.IsNull(f.PathCollection.Entries[0].ETag); Assert.AreEqual(f.PathCollection.Entries[0].Name, "All Files"); Assert.AreEqual(f.CreatedBy.Type, "user"); Assert.AreEqual(f.CreatedBy.Id, "17738362"); Assert.AreEqual(f.CreatedBy.Name, "sean rose"); Assert.AreEqual(f.CreatedBy.Login, "*****@*****.**"); Assert.AreEqual(f.ModifiedBy.Type, "user"); Assert.AreEqual(f.ModifiedBy.Id, "17738362"); Assert.AreEqual(f.ModifiedBy.Name, "sean rose"); Assert.AreEqual(f.ModifiedBy.Login, "*****@*****.**"); Assert.AreEqual(f.OwnedBy.Type, "user"); Assert.AreEqual(f.OwnedBy.Id, "17738362"); Assert.AreEqual(f.OwnedBy.Name, "sean rose"); Assert.AreEqual(f.OwnedBy.Login, "*****@*****.**"); Assert.AreEqual(f.SharedLink.Url, "https://www.box.com/s/vspke7y05sb214wjokpk"); Assert.AreEqual(f.SharedLink.DownloadUrl, "https://www.box.com/shared/static/vspke7y05sb214wjokpk"); Assert.AreEqual(f.SharedLink.VanityUrl, null); Assert.IsFalse(f.SharedLink.IsPasswordEnabled); Assert.IsNull(f.SharedLink.UnsharedAt); Assert.AreEqual(f.SharedLink.DownloadCount, 0); Assert.AreEqual(f.SharedLink.PreviewCount, 0); Assert.AreEqual(f.SharedLink.Access, BoxSharedLinkAccessType.open); Assert.IsTrue(f.SharedLink.Permissions.CanDownload); Assert.IsTrue(f.SharedLink.Permissions.CanPreview); Assert.AreEqual(f.FolderUploadEmail.Acesss, "open"); Assert.AreEqual(f.FolderUploadEmail.Address, "*****@*****.**"); Assert.AreEqual(f.Parent.Type, "folder"); Assert.AreEqual(f.Parent.Id, "0"); Assert.IsNull(f.Parent.SequenceId); Assert.IsNull(f.Parent.ETag); Assert.AreEqual(f.Parent.Name, "All Files"); Assert.AreEqual(f.ItemStatus, "active"); Assert.AreEqual(f.ItemCollection.TotalCount, 0); Assert.AreEqual(f.ItemCollection.Entries.Count, 0); } }
public async Task CreateFolder_ValidResponse_ValidFolder() { _handler.Setup(h => h.ExecuteAsync<BoxFolder>(It.IsAny<IBoxRequest>())) .Returns(() => Task.FromResult<IBoxResponse<BoxFolder>>(new BoxResponse<BoxFolder>() { Status = ResponseStatus.Success, ContentString = "{ \"type\": \"folder\", \"id\": \"11446498\", \"sequence_id\": \"1\", \"etag\": \"1\", \"name\": \"Pictures\", \"created_at\": \"2012-12-12T10:53:43-08:00\", \"modified_at\": \"2012-12-12T11:15:04-08:00\", \"description\": \"Some pictures I took\", \"size\": 629644, \"path_collection\": { \"total_count\": 1, \"entries\": [ { \"type\": \"folder\", \"id\": \"0\", \"sequence_id\": null, \"etag\": null, \"name\": \"All Files\" } ] }, \"created_by\": { \"type\": \"user\", \"id\": \"17738362\", \"name\": \"sean rose\", \"login\": \"[email protected]\" }, \"modified_by\": { \"type\": \"user\", \"id\": \"17738362\", \"name\": \"sean rose\", \"login\": \"[email protected]\" }, \"owned_by\": { \"type\": \"user\", \"id\": \"17738362\", \"name\": \"sean rose\", \"login\": \"[email protected]\" }, \"shared_link\": { \"url\": \"https://www.box.com/s/vspke7y05sb214wjokpk\", \"download_url\": \"https://www.box.com/shared/static/vspke7y05sb214wjokpk\", \"vanity_url\": null, \"is_password_enabled\": false, \"unshared_at\": null, \"download_count\": 0, \"preview_count\": 0, \"access\": \"open\", \"permissions\": { \"can_download\": true, \"can_preview\": true } }, \"folder_upload_email\": { \"access\": \"open\", \"email\": \"[email protected]\" }, \"parent\": { \"type\": \"folder\", \"id\": \"0\", \"sequence_id\": null, \"etag\": null, \"name\": \"All Files\" }, \"item_status\": \"active\", \"item_collection\": { \"total_count\": 0, \"entries\": [], \"offset\": 0, \"limit\": 100 } }" })); var folderReq = new BoxFolderRequest() { Name = "test", Parent = new BoxRequestEntity() { Id = "0" } }; BoxFolder f = await _foldersManager.CreateAsync(folderReq); Assert.AreEqual(f.Type, "folder"); Assert.AreEqual(f.Id, "11446498"); Assert.AreEqual(f.SequenceId, "1"); Assert.AreEqual(f.ETag, "1"); Assert.AreEqual(f.Name, "Pictures"); Assert.AreEqual(f.CreatedAt, DateTime.Parse("2012-12-12T10:53:43-08:00")); Assert.AreEqual(f.ModifiedAt, DateTime.Parse("2012-12-12T11:15:04-08:00")); Assert.AreEqual(f.Description, "Some pictures I took"); Assert.AreEqual(f.Size, 629644); Assert.AreEqual(f.PathCollection.TotalCount, 1); Assert.AreEqual(f.PathCollection.Entries.Count, 1); Assert.AreEqual(f.PathCollection.Entries[0].Id, "0"); Assert.IsNull(f.PathCollection.Entries[0].SequenceId); Assert.IsNull(f.PathCollection.Entries[0].ETag); Assert.AreEqual(f.PathCollection.Entries[0].Name, "All Files"); Assert.AreEqual(f.CreatedBy.Type, "user"); Assert.AreEqual(f.CreatedBy.Id, "17738362"); Assert.AreEqual(f.CreatedBy.Name, "sean rose"); Assert.AreEqual(f.CreatedBy.Login, "*****@*****.**"); Assert.AreEqual(f.ModifiedBy.Type, "user"); Assert.AreEqual(f.ModifiedBy.Id, "17738362"); Assert.AreEqual(f.ModifiedBy.Name, "sean rose"); Assert.AreEqual(f.ModifiedBy.Login, "*****@*****.**"); Assert.AreEqual(f.OwnedBy.Type, "user"); Assert.AreEqual(f.OwnedBy.Id, "17738362"); Assert.AreEqual(f.OwnedBy.Name, "sean rose"); Assert.AreEqual(f.OwnedBy.Login, "*****@*****.**"); Assert.AreEqual(f.SharedLink.Url, "https://www.box.com/s/vspke7y05sb214wjokpk"); Assert.AreEqual(f.SharedLink.DownloadUrl, "https://www.box.com/shared/static/vspke7y05sb214wjokpk"); Assert.AreEqual(f.SharedLink.VanityUrl, null); Assert.IsFalse(f.SharedLink.IsPasswordEnabled); Assert.IsNull(f.SharedLink.UnsharedAt); Assert.AreEqual(f.SharedLink.DownloadCount, 0); Assert.AreEqual(f.SharedLink.PreviewCount, 0); Assert.AreEqual(f.SharedLink.Access, BoxSharedLinkAccessType.open); Assert.IsTrue(f.SharedLink.Permissions.CanDownload); Assert.IsTrue(f.SharedLink.Permissions.CanPreview); Assert.AreEqual(f.FolderUploadEmail.Acesss, "open"); Assert.AreEqual(f.FolderUploadEmail.Address, "*****@*****.**"); Assert.AreEqual(f.Parent.Type, "folder"); Assert.AreEqual(f.Parent.Id, "0"); Assert.IsNull(f.Parent.SequenceId); Assert.IsNull(f.Parent.ETag); Assert.AreEqual(f.Parent.Name, "All Files"); Assert.AreEqual(f.ItemStatus, "active"); Assert.AreEqual(f.ItemCollection.TotalCount, 0); Assert.AreEqual(f.ItemCollection.Entries.Count, 0); //Assert.AreEqual(f.Offset, 0); // Need to add property //Assert.AreEqual(f.Limit, 100); // Need to add property }
public async Task<FileSystemInfoContract> MoveItemAsync(RootName root, FileSystemId source, string moveName, DirectoryId destination, Func<FileSystemInfoLocator> locatorResolver) { var context = await RequireContext(root); if (source is DirectoryId) { var request = new BoxFolderRequest() { Id = source.Value, Parent = new BoxRequestEntity() { Id = destination.Value, Type = BoxType.folder }, Name = moveName }; var item = await AsyncFunc.Retry<BoxFolder, BoxException>(async () => await context.Client.FoldersManager.UpdateInformationAsync(request, fields: boxFolderFields), RETRIES); return new DirectoryInfoContract(item.Id, item.Name, item.CreatedAt.Value, item.ModifiedAt.Value); } else { var request = new BoxFileRequest() { Id = source.Value, Parent = new BoxRequestEntity() { Id = destination.Value, Type = BoxType.file }, Name = moveName }; var item = await AsyncFunc.Retry<BoxFile, BoxException>(async () => await context.Client.FilesManager.UpdateInformationAsync(request, fields: boxFileFields), RETRIES); return new FileInfoContract(item.Id, item.Name, item.CreatedAt.Value, item.ModifiedAt.Value, item.Size.Value, item.Sha1.ToLowerInvariant()); } }
/// <summary> /// Restores an item that has been moved to the trash. Default behavior is to restore the item to the folder it was in /// before it was moved to the trash. If that parent folder no longer exists or if there is now an item with the same /// name in that parent folder, the new parent folder and/or new name will need to be included in the request. /// </summary> /// <returns></returns> public async Task<BoxFolder> RestoreTrashedFolderAsync(BoxFolderRequest folderRequest, List<string> fields = null) { folderRequest.ThrowIfNull("folderRequest") .Id.ThrowIfNullOrWhiteSpace("folderRequest.Id"); folderRequest.Parent.ThrowIfNull("folderRequest.Parent") .Id.ThrowIfNullOrWhiteSpace("folderRequest.Parent.Id"); BoxRequest request = new BoxRequest(_config.FoldersEndpointUri, folderRequest.Id) .Method(RequestMethod.Post) .Param(ParamFields, fields) .Payload(_converter.Serialize(folderRequest)) .Authorize(_auth.Session.AccessToken); IBoxResponse<BoxFolder> response = await ToResponseAsync<BoxFolder>(request); return response.ResponseObject; }
/// <summary> /// Restores an item that has been moved to the trash. Default behavior is to restore the item to the folder it was in /// before it was moved to the trash. If that parent folder no longer exists or if there is now an item with the same /// name in that parent folder, the new parent folder and/or new name will need to be included in the request. /// </summary> /// <param name="folderRequest">BoxFolderRequest object (specify Parent.Id if you wish to restore to a different parent)</param> /// <param name="fields">Attribute(s) to include in the response</param> /// <returns>The full item will be returned if success. By default it is restored to the parent folder it was in before it was trashed.</returns> public async Task<BoxFolder> RestoreTrashedFolderAsync(BoxFolderRequest folderRequest, List<string> fields = null) { folderRequest.ThrowIfNull("folderRequest") .Id.ThrowIfNullOrWhiteSpace("folderRequest.Id"); BoxRequest request = new BoxRequest(_config.FoldersEndpointUri, folderRequest.Id) .Method(RequestMethod.Post) .Param(ParamFields, fields); // ID shall not be used in request body it is used only as url attribute string oldId = folderRequest.Id; folderRequest.Id = null; request.Payload(_converter.Serialize(folderRequest)); folderRequest.Id = oldId; IBoxResponse<BoxFolder> response = await ToResponseAsync<BoxFolder>(request).ConfigureAwait(false); return response.ResponseObject; }
public async Task<FileSystemInfoContract> RenameItemAsync(RootName root, FileSystemId target, string newName, Func<FileSystemInfoLocator> locatorResolver) { var context = await RequireContext(root); if (target is DirectoryId) { var request = new BoxFolderRequest() { Id = target.Value, Name = newName }; var item = await AsyncFunc.Retry<BoxFolder, BoxException>(async () => await context.Client.FoldersManager.UpdateInformationAsync(request, fields: boxFolderFields), RETRIES); return new DirectoryInfoContract(item.Id, item.Name, item.CreatedAt.Value, item.ModifiedAt.Value); } else { var request = new BoxFileRequest() { Id = target.Value, Name = newName }; var item = await AsyncFunc.Retry<BoxFile, BoxException>(async () => await context.Client.FilesManager.UpdateInformationAsync(request, fields: boxFileFields), RETRIES); return new FileInfoContract(item.Id, item.Name, item.CreatedAt.Value, item.ModifiedAt.Value, item.Size.Value, item.Sha1.ToLowerInvariant()); } }
public async Task<DirectoryInfoContract> NewDirectoryItemAsync(RootName root, DirectoryId parent, string name) { var context = await RequireContext(root); var request = new BoxFolderRequest() { Name = name, Parent = new BoxRequestEntity() { Id = parent.Value } }; var item = await AsyncFunc.Retry<BoxFolder, BoxException>(async () => await context.Client.FoldersManager.CreateAsync(request, boxFolderFields), RETRIES); return new DirectoryInfoContract(item.Id, item.Name, item.CreatedAt.Value, item.ModifiedAt.Value); }
public async Task FolderSharedLink_CreateAndDelete_ValidResponse() { string testName = GetUniqueName(); // Test Create Folder BoxFolderRequest folderReq = new BoxFolderRequest() { Name = testName, Parent = new BoxRequestEntity() { Id = "0" } }; BoxFolder f = await _client.FoldersManager.CreateAsync(folderReq); Assert.IsNotNull(f, "Folder was not created"); Assert.AreEqual(testName, f.Name, "Folder with incorrect name was created"); BoxSharedLinkRequest sharedLinkReq = new BoxSharedLinkRequest() { Access = BoxSharedLinkAccessType.open, Permissions = new BoxPermissionsRequest { Download = true, } }; BoxFolder sl = await _client.FoldersManager.CreateSharedLinkAsync(f.Id, sharedLinkReq); Assert.AreEqual(sl.Id, f.Id); Assert.IsNotNull(sl.SharedLink); Assert.AreEqual(sl.SharedLink.Access, BoxSharedLinkAccessType.open); Assert.IsNotNull(sl.SharedLink.Permissions); Assert.AreEqual(sl.SharedLink.Permissions.CanDownload, true); sharedLinkReq = new BoxSharedLinkRequest() { Access = null, Permissions = new BoxPermissionsRequest { Download = false, } }; sl = await _client.FoldersManager.CreateSharedLinkAsync(f.Id, sharedLinkReq); Assert.AreEqual(sl.Id, f.Id); Assert.IsNotNull(sl.SharedLink); Assert.AreEqual(sl.SharedLink.Access, BoxSharedLinkAccessType.open); Assert.IsNotNull(sl.SharedLink.Permissions); Assert.AreEqual(sl.SharedLink.Permissions.CanDownload, false); sl = await _client.FoldersManager.DeleteSharedLinkAsync(f.Id); Assert.AreEqual(sl.Id, f.Id); Assert.IsNull(sl.SharedLink); //Clean up - Delete Test Folders await _client.FoldersManager.DeleteAsync(f.Id, true); }
public async Task FolderWorkflow_LiveSession_ValidResponse() { string testName = GetUniqueName(); // Test Create Folder BoxFolderRequest folderReq = new BoxFolderRequest() { Name = testName, Parent = new BoxRequestEntity() { Id = "0" } }; BoxFolder f = await _client.FoldersManager.CreateAsync(folderReq); Assert.IsNotNull(f, "Folder was not created"); Assert.AreEqual(testName, f.Name, "Folder with incorrect name was created"); // Test Get Information BoxFolder fi = await _client.FoldersManager.GetInformationAsync(f.Id); Assert.AreEqual(f.Id, fi.Id, "Folder Ids are not identical"); Assert.AreEqual(testName, fi.Name, "folder name is incorrect"); // Test Create Shared Link BoxSharedLinkRequest sharedLinkReq = new BoxSharedLinkRequest() { Access = BoxSharedLinkAccessType.open }; BoxFolder fsl = await _client.FoldersManager.CreateSharedLinkAsync(f.Id, sharedLinkReq); Assert.AreEqual(BoxSharedLinkAccessType.open, fsl.SharedLink.Access, "Shared link Access is not correct"); // Test Update Folder Information string newTestname = GetUniqueName(); BoxFolderRequest updateReq = new BoxFolderRequest() { Id = f.Id, Name = newTestname, SyncState = BoxSyncStateType.not_synced, FolderUploadEmail = new BoxEmailRequest { Access = "open" } }; BoxFolder uf = await _client.FoldersManager.UpdateInformationAsync(updateReq); Assert.AreEqual(newTestname, uf.Name, "New folder name is not correct"); // Test Copy Folder string copyTestName = GetUniqueName(); BoxFolderRequest copyReq = new BoxFolderRequest() { Id = f.Id, Parent = new BoxRequestEntity() { Id = "0" }, Name = copyTestName }; BoxFolder f2 = await _client.FoldersManager.CopyAsync(copyReq); Assert.AreEqual(copyTestName, f2.Name, "Copied file does not have correct name"); //Clean up - Delete Test Folders await _client.FoldersManager.DeleteAsync(f.Id, true); await _client.FoldersManager.DeleteAsync(f2.Id, true); }
public async Task<FileSystemInfoContract> CopyItemAsync(RootName root, FileSystemId source, string copyName, DirectoryId destination, bool recurse) { var context = await RequireContext(root); if (source is DirectoryId) { var request = new BoxFolderRequest() { Id = source.Value, Name = copyName, Parent = new BoxRequestEntity() { Id = destination.Value } }; var item = await AsyncFunc.Retry<BoxFolder, BoxException>(async () => await context.Client.FoldersManager.CopyAsync(request, boxFolderFields), RETRIES); return new DirectoryInfoContract(item.Id, item.Name, item.CreatedAt.Value, item.ModifiedAt.Value); } else { var request = new BoxFileRequest() { Id = source.Value, Name = copyName, Parent = new BoxRequestEntity() { Id = destination.Value } }; var item = await AsyncFunc.Retry<BoxFile, BoxException>(async () => await context.Client.FilesManager.CopyAsync(request, boxFileFields), RETRIES); return new FileInfoContract(item.Id, item.Name, item.CreatedAt.Value, item.ModifiedAt.Value, item.Size.Value, item.Sha1.ToLowerInvariant()); } }