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 GetSharedLink_ValidRequest_ValidSharedLink() { string imageFileId1 = "16894947279"; BoxSharedLinkRequest linkReq = new BoxSharedLinkRequest() { Access = BoxSharedLinkAccessType.open }; BoxFile fileLink = await _client.FilesManager.CreateSharedLinkAsync(imageFileId1, linkReq); Assert.AreEqual(BoxSharedLinkAccessType.open, fileLink.SharedLink.Access); }
/// <summary> /// Used to create a shared link for this particular file. Please see here for more information on the permissions available for shared links. /// </summary> /// <param name="id"></param> /// <param name="sharedLinkRequest"></param> /// <returns></returns> public async Task<BoxFile> CreateSharedLinkAsync(string id, BoxSharedLinkRequest sharedLinkRequest, List<string> fields = null) { id.ThrowIfNullOrWhiteSpace("id"); if (!sharedLinkRequest.ThrowIfNull("sharedLinkRequest").Access.HasValue) throw new ArgumentNullException("sharedLink.Access"); BoxRequest request = new BoxRequest(_config.FilesEndpointUri, id) .Method(RequestMethod.Put) .Param(ParamFields, fields) .Payload(_converter.Serialize(new BoxItemRequest() { SharedLink = sharedLinkRequest })); IBoxResponse<BoxFile> response = await ToResponseAsync<BoxFile>(request).ConfigureAwait(false); return response.ResponseObject; }
public async Task FileWorkflow_ValidRequest_ValidResponse() { //file Ids of the two files to download string imageFileId1 = "16894947279"; string imageFileId2 = "16894946307"; // paths to store the two downloaded files var dlPath1 = string.Format(GetSaveFolderPath(), "thumbnail1.png"); var dlPath2 = string.Format(GetSaveFolderPath(), "thumbnail2.png"); //download 2 files using (FileStream fs = new FileStream(dlPath1, FileMode.OpenOrCreate)) { Stream stream = await _client.FilesManager.DownloadStreamAsync(imageFileId1); await stream.CopyToAsync(fs); } using (FileStream fs = new FileStream(dlPath2, FileMode.OpenOrCreate)) { Stream stream = await _client.FilesManager.DownloadStreamAsync(imageFileId2); await stream.CopyToAsync(fs); } // File name to use to upload files string uploadFileName = "testUpload.png"; // Upload file at dlPath1 BoxFile file; using (FileStream fs = new FileStream(dlPath1, FileMode.Open)) { BoxFileRequest req = new BoxFileRequest() { Name = uploadFileName, Parent = new BoxRequestEntity() { Id = "0" } }; file = await _client.FilesManager.UploadAsync(req, fs); } Assert.AreEqual(uploadFileName, file.Name, "Incorrect file name"); Assert.AreEqual("0", file.Parent.Id, "Incorrect destination folder"); // Upload file at dlPath2 as new version of 'file' BoxFile newFileVersion; using (FileStream fs = new FileStream(dlPath2, FileMode.Open)) { newFileVersion = await _client.FilesManager.UploadNewVersionAsync(uploadFileName, file.Id, fs, file.ETag); } Assert.AreEqual(newFileVersion.Name, uploadFileName); Assert.AreEqual(newFileVersion.Parent.Id, "0"); //View file versions (Requires upgraded acct) BoxCollection<BoxFileVersion> fileVersions = await _client.FilesManager.ViewVersionsAsync(newFileVersion.Id); Assert.AreEqual(fileVersions.TotalCount, 1, "Incorrect number of versions"); foreach (var f in fileVersions.Entries) { Assert.AreEqual(uploadFileName, f.Name); } // Update the file name of a file string updateName = GetUniqueName(); BoxFileRequest updateReq = new BoxFileRequest() { Id = file.Id, Name = updateName }; BoxFile fileUpdate = await _client.FilesManager.UpdateInformationAsync(updateReq); Assert.AreEqual(file.Id, fileUpdate.Id, "File Ids are not the same"); Assert.AreEqual(updateName, fileUpdate.Name, "File Names are not the same"); // Test create shared link BoxSharedLinkRequest linkReq = new BoxSharedLinkRequest() { Access = BoxSharedLinkAccessType.open }; BoxFile fileWithLink = await _client.FilesManager.CreateSharedLinkAsync(newFileVersion.Id, linkReq); Assert.AreEqual(BoxSharedLinkAccessType.open, fileWithLink.SharedLink.Access, "Incorrect access for shared link"); // Copy file in same folder string copyName = GetUniqueName(); BoxFileRequest copyReq = new BoxFileRequest() { Id = fileWithLink.Id, Name = copyName, Parent = new BoxRequestEntity() { Id = "0" } }; BoxFile fileCopy = await _client.FilesManager.CopyAsync(copyReq); Assert.AreEqual(fileCopy.Name, copyName, "Incorrect Name for copied file"); Assert.AreEqual(fileCopy.Parent.Id, "0", "Incorrect parent folder for copied file"); // Test get file information BoxFile fileInfo = await _client.FilesManager.GetInformationAsync(fileWithLink.Id); Assert.AreEqual(updateName, fileWithLink.Name, "File name is incorrect"); Assert.AreEqual("0", fileWithLink.Parent.Id, "Parent folder is incorrect"); // Delete both files await _client.FilesManager.DeleteAsync(fileCopy.Id, fileCopy.ETag); await _client.FilesManager.DeleteAsync(fileWithLink.Id, fileWithLink.ETag); }
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 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 CreateFileSharedLink_ValidResponse_ValidFile() { /*** Arrange ***/ string responseString = "{ \"type\": \"file\", \"id\": \"5000948880\", \"sequence_id\": \"3\", \"etag\": \"3\", \"sha1\": \"134b65991ed521fcfe4724b7d814ab8ded5185dc\", \"name\": \"tigers.jpeg\", \"description\": \"a picture of tigers\", \"size\": 629644, \"path_collection\": { \"total_count\": 2, \"entries\": [ { \"type\": \"folder\", \"id\": \"0\", \"sequence_id\": null, \"etag\": null, \"name\": \"All Files\" }, { \"type\": \"folder\", \"id\": \"11446498\", \"sequence_id\": \"1\", \"etag\": \"1\", \"name\": \"Pictures\" } ] }, \"created_at\": \"2012-12-12T10:55:30-08:00\", \"modified_at\": \"2012-12-12T11:04:26-08:00\", \"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/rh935iit6ewrmw0unyul\", \"download_url\": \"https://www.box.com/shared/static/rh935iit6ewrmw0unyul.jpeg\", \"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 } }, \"parent\": { \"type\": \"folder\", \"id\": \"11446498\", \"sequence_id\": \"1\", \"etag\": \"1\", \"name\": \"Pictures\" }, \"item_status\": \"active\" }"; _handler.Setup(h => h.ExecuteAsync<BoxFile>(It.IsAny<IBoxRequest>())) .Returns(Task.FromResult<IBoxResponse<BoxFile>>(new BoxResponse<BoxFile>() { Status = ResponseStatus.Success, ContentString = responseString })); BoxSharedLinkRequest sharedLink = new BoxSharedLinkRequest() { Access = BoxSharedLinkAccessType.collaborators }; /*** Act ***/ BoxFile f = await _filesManager.CreateSharedLinkAsync("0", sharedLink); /*** Assert ***/ Assert.AreEqual("5000948880", f.Id); Assert.AreEqual("3", f.SequenceId); Assert.AreEqual("3", f.ETag); Assert.AreEqual("134b65991ed521fcfe4724b7d814ab8ded5185dc", f.Sha1); Assert.AreEqual("file", f.Type); Assert.AreEqual("sean rose", f.CreatedBy.Name); Assert.AreEqual("*****@*****.**", f.CreatedBy.Login); Assert.AreEqual("user", f.CreatedBy.Type); Assert.AreEqual("17738362", f.CreatedBy.Id); }
public async Task CreateFolderSharedLink_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 ***/ BoxSharedLinkRequest sharedLink = new BoxSharedLinkRequest() { Access = BoxSharedLinkAccessType.collaborators }; BoxFolder f = await _foldersManager.CreateSharedLinkAsync("0", sharedLink); /*** 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); }
/// <summary> /// Used to create a shared link for this particular folder. Please see here for more information on the /// permissions available for shared links. In order to disable a shared link, send this same type of PUT /// request with the value of shared_link set to null, i.e. {"shared_link": null} /// </summary> /// <returns></returns> public async Task<BoxFolder> CreateSharedLinkAsync(string id, BoxSharedLinkRequest sharedLinkRequest, List<string> fields = null) { id.ThrowIfNullOrWhiteSpace("id"); BoxRequest request = new BoxRequest(_config.FoldersEndpointUri, id) .Method(RequestMethod.Put) .Param(ParamFields, fields) .Payload(_converter.Serialize(new BoxItemRequest() { SharedLink = sharedLinkRequest })); IBoxResponse<BoxFolder> response = await ToResponseAsync<BoxFolder>(request).ConfigureAwait(false); return response.ResponseObject; }
public async Task FileWorkflow_ValidRequest_ValidResponse() { string fileName = "reimages.zip"; string saveName = "reimages2.zip"; string filePath = string.Format(savePath, fileName); string dlPath = string.Format(savePath, saveName); // Test upload a file BoxFile file; using (FileStream fs = new FileStream(filePath, FileMode.Open)) { BoxFileRequest req = new BoxFileRequest() { Name = "reimages.zip", Parent = new BoxRequestEntity() { Id = "0" } }; file = await _client.FilesManager.UploadAsync(req, fs); } Assert.AreEqual(fileName, file.Name); Assert.AreEqual("0", file.Parent.Id); // Test upload a new version BoxFile newFile; using (FileStream fs = new FileStream(filePath, FileMode.Open)) { newFile = await _client.FilesManager.UploadNewVersionAsync(fileName, file.Id, fs, file.ETag); } Assert.AreEqual(newFile.Name, fileName); Assert.AreEqual(newFile.Parent.Id, "0"); // Test view file versions (Requires upgraded acct) //BoxCollection<BoxFile> versions = await _client.FilesManager.ViewVersionsAsync(newFile.Id); //Assert.AreEqual(versions.TotalCount, 2); //foreach (var f in versions.Entries) //{ // Assert.AreEqual(fileName, f.Name); // Assert.AreEqual("0", f.Parent.Id); //} // Test update a file string updateName = GetUniqueName(); BoxFileRequest updateReq = new BoxFileRequest() { Id = file.Id, Name = updateName, Description = updateName }; BoxFile fileUpdate = await _client.FilesManager.UpdateInformationAsync(updateReq); Assert.AreEqual(file.Id, fileUpdate.Id); Assert.AreEqual(updateName, fileUpdate.Name); Assert.AreEqual(updateName, fileUpdate.Description); // Test create shared link BoxSharedLinkRequest linkReq = new BoxSharedLinkRequest() { Access = BoxSharedLinkAccessType.open }; BoxFile fileLink = await _client.FilesManager.CreateSharedLinkAsync(newFile.Id, linkReq); Assert.AreEqual(BoxSharedLinkAccessType.open, fileLink.SharedLink.Access); // Test copy a file string copyName = GetUniqueName(); BoxFileRequest copyReq = new BoxFileRequest() { Id = newFile.Id, Name = copyName, Parent = new BoxRequestEntity() { Id = "0" } }; BoxFile fileCopy = await _client.FilesManager.CopyAsync(copyReq); Assert.AreEqual(fileCopy.Name, copyName); Assert.AreEqual(fileCopy.Parent.Id, "0"); // Test download a file using (FileStream fs = new FileStream(dlPath, FileMode.OpenOrCreate)) { Stream stream = await _client.FilesManager.DownloadStreamAsync(file.Id); await stream.CopyToAsync(fs); } // Test get file information BoxFile fileInfo = await _client.FilesManager.GetInformationAsync(file.Id); Assert.AreEqual(updateName, fileInfo.Name); Assert.AreEqual("0", file.Parent.Id); BoxFile newFileInfo = await _client.FilesManager.GetInformationAsync(newFile.Id); Assert.AreEqual(updateName, newFileInfo.Name); Assert.AreEqual("0", newFileInfo.Parent.Id); // Test delete a file await _client.FilesManager.DeleteAsync(fileCopy.Id, fileCopy.ETag); await _client.FilesManager.DeleteAsync(newFile.Id, newFileInfo.ETag); }
public async Task GetSharedLink_ValidRequest_ValidSharedLink() { BoxSharedLinkRequest linkReq = new BoxSharedLinkRequest() { Access = BoxSharedLinkAccessType.open }; BoxFile fileLink = await _client.FilesManager.CreateSharedLinkAsync("11999421592", linkReq); Assert.AreEqual(BoxSharedLinkAccessType.open, fileLink.SharedLink.Access); }