public async Task GetGroupItems_ValidResponse_ValidGroups() { IBoxRequest boxRequest = null; Handler.Setup(h => h.ExecuteAsync <BoxCollection <BoxGroup> >(It.IsAny <IBoxRequest>())) .Returns(() => Task.FromResult <IBoxResponse <BoxCollection <BoxGroup> > >(new BoxResponse <BoxCollection <BoxGroup> >() { Status = ResponseStatus.Success, ContentString = @"{""total_count"": 14, ""entries"": [ {""type"": ""group"", ""id"": ""26477"", ""name"": ""adfasdf"", ""created_at"": ""2011-02-15T14:07:22-08:00"", ""modified_at"": ""2011-10-05T19:04:40-07:00"", ""invitability_level"": ""none""}, {""type"": ""group"", ""id"": ""1263"", ""name"": ""Enterprise Migration"", ""created_at"": ""2009-04-20T19:36:17-07:00"", ""modified_at"": ""2011-10-05T19:05:10-07:00"", ""invitability_level"": ""admins_only""}], ""limit"": 2, ""offset"": 0}" })) .Callback <IBoxRequest>(r => boxRequest = r); /*** Act ***/ BoxCollection <BoxGroup> items = await _groupsManager.GetAllGroupsAsync(filterTerm : "test"); /*** Assert ***/ // Request check Assert.AreEqual("filter_term=test", boxRequest.GetQueryString()); // Response check Assert.AreEqual(items.TotalCount, 14, "Wrong total count"); Assert.AreEqual(items.Entries.Count, 2, "Wrong count of entries"); Assert.AreEqual(items.Entries[0].Type, "group", "Wrong type"); Assert.AreEqual(items.Entries[0].Id, "26477", "Wrong id"); Assert.AreEqual(items.Entries[0].Name, "adfasdf", "Wrong name"); Assert.AreEqual(items.Entries[0].InvitabilityLevel, "none"); Assert.AreEqual(items.Entries[0].CreatedAt, DateTimeOffset.Parse("2011-02-15T14:07:22-08:00"), "Wrong created at"); Assert.AreEqual(items.Entries[0].ModifiedAt, DateTimeOffset.Parse("2011-10-05T19:04:40-07:00"), "Wrong modified at"); Assert.AreEqual(items.Offset, 0, "Wrong offset"); Assert.AreEqual(items.Limit, 2, "Wrong limit"); }
public async Task GetTrashedItems_ValidResponse_ValidFiles() { /*** Arrange ***/ _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\": 49542, \"entries\": [ { \"type\": \"file\", \"id\": \"2701979016\", \"sequence_id\": \"1\", \"etag\": \"1\", \"sha1\": \"9d976863fc849f6061ecf9736710bd9c2bce488c\", \"name\": \"file Tue Jul 24 145436 2012KWPX5S.csv\" }, { \"type\": \"file\", \"id\": \"2698211586\", \"sequence_id\": \"1\", \"etag\": \"1\", \"sha1\": \"09b0e2e9760caf7448c702db34ea001f356f1197\", \"name\": \"file Tue Jul 24 010055 20129Z6GS3.csv\" } ], \"offset\": 0, \"limit\": 2 }" })); /*** Act ***/ BoxCollection <BoxItem> i = await _foldersManager.GetTrashItemsAsync("fakeId", 10); BoxItem i1 = i.Entries.FirstOrDefault(); BoxItem i2 = i.Entries.Skip(1).FirstOrDefault(); /*** Assert ***/ Assert.AreEqual(49542, i.TotalCount); Assert.AreEqual("file", i1.Type); Assert.AreEqual("2701979016", i1.Id); Assert.AreEqual("1", i1.SequenceId); Assert.AreEqual("file Tue Jul 24 145436 2012KWPX5S.csv", i1.Name); Assert.AreEqual("1", i1.ETag); Assert.AreEqual("file", i2.Type); Assert.AreEqual("2698211586", i2.Id); Assert.AreEqual("1", i2.SequenceId); Assert.AreEqual("1", i1.ETag); Assert.AreEqual("file Tue Jul 24 010055 20129Z6GS3.csv", i2.Name); }
public string PageInConsole <T>(Action <T> print, BoxCollection <T> collection) where T : class, new() { print(collection.Entries[0]); collection.Entries.RemoveAt(0); Reporter.WriteInformation("Show next? Enter q to quit. "); return(System.Console.ReadLine().Trim().ToLower()); }
public async Task GetFolderItems_ValidResponse_ValidFolder() { _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\":24,\"entries\":[{\"type\":\"folder\",\"id\":\"192429928\",\"sequence_id\":\"1\",\"etag\":\"1\",\"name\":\"Stephen Curry Three Pointers\"},{\"type\":\"file\",\"id\":\"818853862\",\"sequence_id\":\"0\",\"etag\":\"0\",\"name\":\"Warriors.jpg\"}],\"offset\":0,\"limit\":2,\"order\":[{\"by\":\"type\",\"direction\":\"ASC\"},{\"by\":\"name\",\"direction\":\"ASC\"}]}" })); BoxCollection <BoxItem> items = await _foldersManager.GetFolderItemsAsync("0", 2); Assert.AreEqual(items.TotalCount, 24); Assert.AreEqual(items.Entries.Count, 2); Assert.AreEqual(items.Entries[0].Type, "folder"); Assert.AreEqual(items.Entries[0].Id, "192429928"); Assert.AreEqual(items.Entries[0].SequenceId, "1"); Assert.AreEqual(items.Entries[0].ETag, "1"); Assert.AreEqual(items.Entries[0].Name, "Stephen Curry Three Pointers"); Assert.AreEqual(items.Entries[1].Type, "file"); Assert.AreEqual(items.Entries[1].Id, "818853862"); Assert.AreEqual(items.Entries[1].SequenceId, "0"); Assert.AreEqual(items.Entries[1].ETag, "0"); Assert.AreEqual(items.Entries[1].Name, "Warriors.jpg"); Assert.AreEqual(items.Offset, 0); Assert.AreEqual(items.Limit, 2); //Assert.AreEqual(f.Offset, "0"); // Need to add property //Assert.AreEqual(f.Order[0].By, "type"); // Need to add property //Assert.AreEqual(f.Order[0].Direction, "ASC"); // Need to add property //Assert.AreEqual(f.Order[1].By, "name"); // Need to add property //Assert.AreEqual(f.Order[1].Direction, "ASC"); // Need to add property }
public async Task ViewVersions_ValidResponse_ValidFileVersions() { /*** Arrange ***/ string responseString = "{ \"total_count\": 1, \"entries\": [ { \"type\": \"file_version\", \"id\": \"672259576\", \"sha1\": \"359c6c1ed98081b9a69eb3513b9deced59c957f9\", \"name\": \"Dragons.js\", \"size\": 92556, \"created_at\": \"2012-08-20T10:20:30-07:00\", \"modified_at\": \"2012-11-28T13:14:58-08:00\", \"modified_by\": { \"type\": \"user\", \"id\": \"183732129\", \"name\": \"sean rose\", \"login\": \"[email protected]\" } } ] }"; _handler.Setup(h => h.ExecuteAsync <BoxCollection <BoxFileVersion> >(It.IsAny <IBoxRequest>())) .Returns(Task.FromResult <IBoxResponse <BoxCollection <BoxFileVersion> > >(new BoxResponse <BoxCollection <BoxFileVersion> >() { Status = ResponseStatus.Success, ContentString = responseString })); /*** Act ***/ BoxCollection <BoxFileVersion> c = await _filesManager.ViewVersionsAsync("0"); /*** Assert ***/ Assert.AreEqual(c.TotalCount, 1); Assert.AreEqual(c.Entries.Count, 1); BoxFileVersion f = c.Entries.First(); Assert.AreEqual("file_version", f.Type); Assert.AreEqual("672259576", f.Id); Assert.AreEqual("359c6c1ed98081b9a69eb3513b9deced59c957f9", f.Sha1); Assert.AreEqual("Dragons.js", f.Name); Assert.AreEqual(DateTime.Parse("2012-08-20T10:20:30-07:00"), f.CreatedAt); Assert.AreEqual(DateTime.Parse("2012-11-28T13:14:58-08:00"), f.ModifiedAt); Assert.AreEqual(92556, f.Size); Assert.AreEqual("user", f.ModifiedBy.Type); Assert.AreEqual("183732129", f.ModifiedBy.Id); Assert.AreEqual("sean rose", f.ModifiedBy.Name); Assert.AreEqual("*****@*****.**", f.ModifiedBy.Login); }
public async Task GetMembershipsForUser_ValidResponse_ValidFolder() { IBoxRequest boxRequest = null; /*** Arrange ***/ string responseString = "{\"total_count\":1,\"entries\":[{\"type\":\"group_membership\",\"id\":\"1560354\",\"user\":{\"type\":\"user\",\"id\":\"13130406\",\"name\":\"Alison Wonderland\",\"login\":\"[email protected]\"},\"group\":{\"type\":\"group\",\"id\":\"119720\",\"name\":\"family\"},\"role\":\"member\"}],\"limit\":100,\"offset\":0}"; Handler.Setup(h => h.ExecuteAsync <BoxCollection <BoxGroupMembership> >(It.IsAny <IBoxRequest>())) .Returns(Task.FromResult <IBoxResponse <BoxCollection <BoxGroupMembership> > >(new BoxResponse <BoxCollection <BoxGroupMembership> >() { Status = ResponseStatus.Success, ContentString = responseString })) .Callback <IBoxRequest>(r => boxRequest = r); /*** Act ***/ BoxCollection <BoxGroupMembership> result = await _usersManager.GetMembershipsForUserAsync("13130406"); /*** Assert ***/ // request Assert.IsNotNull(boxRequest); Assert.AreEqual(RequestMethod.Get, boxRequest.Method); Assert.AreEqual(UserUri + "13130406/memberships?offset=0&limit=100", boxRequest.AbsoluteUri.AbsoluteUri); // response Assert.IsNotNull(result); Assert.AreEqual("1560354", result.Entries[0].Id); Assert.AreEqual("13130406", result.Entries[0].User.Id); Assert.AreEqual("119720", result.Entries[0].Group.Id); Assert.AreEqual("member", result.Entries[0].Role); }
private async Task <bool> DoesFileExistInFolder(string folderId, string fileName) { // TODO: Paging BoxCollection <BoxItem> boxCollection = await _client.FoldersManager.GetFolderItemsAsync(folderId, 1000); return(boxCollection.Entries.Any(item => item.Name == fileName)); }
public async Task ViewFileComments_ValidResponse_ValidFile() { /*** Arrange ***/ string responseString = "{ \"total_count\": 1, \"entries\": [ { \"type\": \"comment\", \"id\": \"191969\", \"is_reply_comment\": false, \"message\": \"These tigers are cool!\", \"created_by\": { \"type\": \"user\", \"id\": \"17738362\", \"name\": \"sean rose\", \"login\": \"[email protected]\" }, \"created_at\": \"2012-12-12T11:25:01-08:00\", \"item\": { \"id\": \"5000948880\", \"type\": \"file\" }, \"modified_at\": \"2012-12-12T11:25:01-08:00\" } ] }"; _handler.Setup(h => h.ExecuteAsync <BoxCollection <BoxComment> >(It.IsAny <IBoxRequest>())) .Returns(Task.FromResult <IBoxResponse <BoxCollection <BoxComment> > >(new BoxResponse <BoxCollection <BoxComment> >() { Status = ResponseStatus.Success, ContentString = responseString })); /*** Act ***/ BoxCollection <BoxComment> c = await _filesManager.GetCommentsAsync("0"); BoxComment comment = c.Entries.FirstOrDefault(); /*** Assert ***/ Assert.AreEqual(1, c.TotalCount); Assert.AreEqual("191969", comment.Id); Assert.AreEqual(false, comment.IsReplyComment); Assert.AreEqual("These tigers are cool!", comment.Message); Assert.AreEqual("user", comment.CreatedBy.Type); Assert.AreEqual("17738362", comment.CreatedBy.Id); Assert.AreEqual("sean rose", comment.CreatedBy.Name); Assert.AreEqual("*****@*****.**", comment.CreatedBy.Login); }
public async Task GetFolder_LiveSession_ValidResponse() { BoxFolder f = await _client.FoldersManager.GetItemsAsync("0", 50, 0, new List <string>() { BoxFolder.FieldName, BoxFolder.FieldSize, BoxFolder.FieldModifiedAt, BoxFolder.FieldModifiedBy, BoxFolder.FieldItemCollection, BoxFolder.FieldHasCollaborations, BoxFile.FieldCommentCount }); BoxCollection <BoxItem> c = await _client.FoldersManager.GetFolderItemsAsync("0", 50, 0, new List <string>() { BoxItem.FieldName, BoxItem.FieldSize, BoxItem.FieldModifiedAt, BoxItem.FieldModifiedBy, BoxFolder.FieldItemCollection }); Assert.AreEqual(f.ItemCollection.TotalCount, c.TotalCount); Assert.AreEqual(f.ItemCollection.Entries.Count, c.Entries.Count); for (int i = 0; i < f.ItemCollection.TotalCount; i++) { Assert.AreEqual(f.ItemCollection.Entries[i].Type, c.Entries[i].Type); Assert.AreEqual(f.ItemCollection.Entries[i].Id, c.Entries[i].Id); Assert.AreEqual(f.ItemCollection.Entries[i].Name, c.Entries[i].Name); Assert.AreEqual(f.ItemCollection.Entries[i].Size, c.Entries[i].Size); Assert.AreEqual(f.ItemCollection.Entries[i].ModifiedAt, c.Entries[i].ModifiedAt); Assert.AreEqual(f.ItemCollection.Entries[i].CreatedAt, c.Entries[i].CreatedAt); } }
private async Task <string> GetFileId(string folderId, string fileName) { // TODO: Paging BoxCollection <BoxItem> boxCollection = await _client.FoldersManager.GetFolderItemsAsync(folderId, 1000); return(boxCollection.Entries.FirstOrDefault(item => item.Name == fileName)?.Id); }
static void Main(string[] args) { BoxCollection bxList = new BoxCollection(); bxList.Add(new Box(10, 4, 6)); bxList.Add(new Box(4, 6, 10)); bxList.Add(new Box(6, 10, 4)); bxList.Add(new Box(12, 8, 10)); // Same dimensions. Cannot be added: bxList.Add(new Box(10, 4, 6)); // Test the Remove method. Display(bxList); Console.WriteLine("Removing 6x10x4"); bxList.Remove(new Box(6, 10, 4)); Display(bxList); // Test the Contains method. Box BoxCheck = new Box(8, 12, 10); Console.WriteLine("Contains {0}x{1}x{2} by dimensions: {3}", BoxCheck.Height.ToString(), BoxCheck.Length.ToString(), BoxCheck.Width.ToString(), bxList.Contains(BoxCheck).ToString()); // Test the Contains method overload with a specified equality comparer. Console.WriteLine("Contains {0}x{1}x{2} by volume: {3}", BoxCheck.Height.ToString(), BoxCheck.Length.ToString(), BoxCheck.Width.ToString(), bxList.Contains(BoxCheck, new BoxSameVol()).ToString()); }
public async Task GetFileTasks_ValidResponse_ValidTasks() { /*** Arrange ***/ string responseString = "{\"total_count\": 1, \"entries\": [{\"type\": \"task\", \"id\": \"1786931\",\"item\": {\"type\": \"file\",\"id\": \"7026335894\", \"sequence_id\": \"6\", \"etag\": \"6\", \"sha1\": \"81cc829fb8366fcfc108aa6c5a9bde01a6a10c16\",\"name\": \"API - Persist On-Behalf-Of information.docx\" }, \"due_at\": null } ] }"; _handler.Setup(h => h.ExecuteAsync <BoxCollection <BoxTask> >(It.IsAny <IBoxRequest>())) .Returns(Task.FromResult <IBoxResponse <BoxCollection <BoxTask> > >(new BoxResponse <BoxCollection <BoxTask> >() { Status = ResponseStatus.Success, ContentString = responseString })); /*** Act ***/ BoxCollection <BoxTask> tasks = await _filesManager.GetFileTasks("fakeId"); /*** Assert ***/ BoxTask task = tasks.Entries.FirstOrDefault(); /*** Assert ***/ Assert.AreEqual(1, tasks.TotalCount); Assert.AreEqual("1786931", task.Id); Assert.AreEqual("task", task.Type); Assert.AreEqual("API - Persist On-Behalf-Of information.docx", task.Item.Name); Assert.AreEqual("7026335894", task.Item.Id); }
/// <summary> /// Used to fetch all results using pagination based on limit and offset /// </summary> /// <typeparam name="T">The type of BoxCollection item to expect.</typeparam> /// <param name="request">The pre-configured BoxRequest object.</param> /// <param name="limit">The limit specific to the endpoint.</param> /// <returns></returns> protected async Task <BoxCollection <T> > AutoPaginateLimitOffset <T>(BoxRequest request, int limit) where T : class, new() { var allItemsCollection = new BoxCollection <T>(); allItemsCollection.Entries = new List <T>(); int offset = 0; bool keepGoing; do { var response = await ToResponseAsync <BoxCollection <T> >(request).ConfigureAwait(false); var newItems = response.ResponseObject; allItemsCollection.Entries.AddRange(newItems.Entries); allItemsCollection.Order = newItems.Order; offset += limit; request.Param("offset", offset.ToString()); keepGoing = newItems.Entries.Count >= limit; } while (keepGoing); allItemsCollection.TotalCount = allItemsCollection.Entries.Count; return(allItemsCollection); }
public async Task GetFolderCollaborators_ValidResponse_ValidCollaborators() { /*** Arrange ***/ _handler.Setup(h => h.ExecuteAsync <BoxCollection <BoxCollaboration> >(It.IsAny <IBoxRequest>())) .Returns(() => Task.FromResult <IBoxResponse <BoxCollection <BoxCollaboration> > >(new BoxResponse <BoxCollection <BoxCollaboration> >() { Status = ResponseStatus.Success, ContentString = "{ \"total_count\": 1, \"entries\": [ { \"type\": \"collaboration\", \"id\": \"14176246\", \"created_by\": { \"type\": \"user\", \"id\": \"4276790\", \"name\": \"David Lee\", \"login\": \"[email protected]\" }, \"created_at\": \"2011-11-29T12:56:35-08:00\", \"modified_at\": \"2012-09-11T15:12:32-07:00\", \"expires_at\": null, \"status\": \"accepted\", \"accessible_by\": { \"type\": \"user\", \"id\": \"755492\", \"name\": \"Simon Tan\", \"login\": \"[email protected]\" }, \"role\": \"editor\", \"acknowledged_at\": \"2011-11-29T12:59:40-08:00\", \"item\": null } ] }" })); /*** Act ***/ BoxCollection <BoxCollaboration> c = await _foldersManager.GetCollaborationsAsync("fakeId"); BoxCollaboration collab = c.Entries.FirstOrDefault(); /*** Assert ***/ Assert.AreEqual(1, c.TotalCount); Assert.AreEqual("collaboration", collab.Type); Assert.AreEqual("14176246", collab.Id); Assert.AreEqual("David Lee", collab.CreatedBy.Name); Assert.AreEqual("*****@*****.**", collab.CreatedBy.Login); var user = collab.AccessibleBy as BoxUser; Assert.AreEqual("Simon Tan", user.Name); Assert.AreEqual("*****@*****.**", user.Login); }
public async Task GetFolderCollaborators_ValidResponseWithGroups_ValidCollaborators() { /*** Arrange ***/ _handler.Setup(h => h.ExecuteAsync <BoxCollection <BoxCollaboration> >(It.IsAny <IBoxRequest>())) .Returns(() => Task.FromResult <IBoxResponse <BoxCollection <BoxCollaboration> > >(new BoxResponse <BoxCollection <BoxCollaboration> >() { Status = ResponseStatus.Success, ContentString = "{ \"total_count\": 2, \"entries\": [ { \"type\": \"collaboration\", \"id\": \"14176246\", \"created_by\": { \"type\": \"user\", \"id\": \"4276790\", \"name\": \"David Lee\", \"login\": \"[email protected]\" }, \"created_at\": \"2011-11-29T12:56:35-08:00\", \"modified_at\": \"2012-09-11T15:12:32-07:00\", \"expires_at\": null, \"status\": \"accepted\", \"accessible_by\": { \"type\": \"user\", \"id\": \"755492\", \"name\": \"Simon Tan\", \"login\": \"[email protected]\" }, \"role\": \"editor\", \"acknowledged_at\": \"2011-11-29T12:59:40-08:00\", \"item\": null }, {\"type\": \"collaboration\",\"id\": \"88140750\",\"created_by\": null,\"created_at\": \"2014-12-10T18:58:47-08:00\",\"modified_at\": \"2014-12-10T18:58:47-08:00\",\"expires_at\": null,\"status\": \"accepted\",\"accessible_by\": {\"type\": \"group\",\"id\": \"293514\",\"name\": \"Test Group\"},\"role\": \"editor\",\"acknowledged_at\": \"2014-12-10T18:58:47-08:00\",\"item\": {\"type\": \"folder\",\"id\": \"1055358427\",\"sequence_id\": \"0\",\"etag\": \"0\",\"name\": \"Work\"}} ] }" })); /*** Act ***/ BoxCollection <BoxCollaboration> c = await _foldersManager.GetCollaborationsAsync("fakeId"); var collabs = c.Entries; var collab1 = collabs[0]; var collab2 = collabs[1]; /*** Assert ***/ Assert.AreEqual(2, c.TotalCount); Assert.AreEqual("collaboration", collab1.Type); Assert.AreEqual("14176246", collab1.Id); Assert.AreEqual("David Lee", collab1.CreatedBy.Name); Assert.AreEqual("*****@*****.**", collab1.CreatedBy.Login); var user = collab1.AccessibleBy as BoxUser; Assert.AreEqual("Simon Tan", user.Name); Assert.AreEqual("*****@*****.**", user.Login); Assert.AreEqual("collaboration", collab2.Type); Assert.AreEqual("88140750", collab2.Id); var group = collab2.AccessibleBy as BoxGroup; Assert.AreEqual("293514", group.Id); Assert.AreEqual("Test Group", group.Name); }
public async Task <List <BoxItem> > GetItems(string parentFolderId) { BoxClient client = ClientService.GetClient(); BoxCollection <BoxItem> items = null; if (parentFolderId != null) { CacheKey <BoxItem> key = new CacheKey <BoxItem>(client.Auth.Session.AccessToken, parentFolderId); items = await Cache.GetOrCreateAsync(key, cacheEntry => { Log.LogTrace($"Caching items for folder {parentFolderId}."); cacheEntry.SetAbsoluteExpiration(TimeSpan.FromSeconds(20)); return(client.FoldersManager.GetFolderItemsAsync(parentFolderId, 500, fields: new[] { BoxItem.FieldDescription, BoxItem.FieldName, BoxItem.FieldSize, BoxItem.FieldTags, BoxItem.FieldCreatedAt, BoxItem.FieldModifiedAt, BoxItem.FieldParent, BoxItem.FieldCreatedBy, BoxItem.FieldModifiedBy, BoxItem.FieldOwnedBy })); }).ConfigureAwait(false); } return(items.Entries); }
public async Task EnterpriseUsersInformation_LiveSession_ValidResponse() { BoxCollection <BoxUser> users = await _client.UsersManager.GetEnterpriseUsersAsync("test.user"); Assert.AreEqual(users.TotalCount, 1); Assert.AreEqual(users.Entries.First().Name, "Test User"); Assert.AreEqual(users.Entries.First().Login, "*****@*****.**"); }
public async Task EnterpriseUsersInformation_LiveSession_ValidResponse() { BoxCollection <BoxUser> users = await _client.UsersManager.GetEnterpriseUsersAsync("jhoerr"); Assert.AreEqual(users.TotalCount, 1); Assert.AreEqual(users.Entries.First().Name, "John Hoerr"); Assert.AreEqual(users.Entries.First().Login, "*****@*****.**"); }
public async Task SearchKeyword_LiveSession_EmptyResult() { const string keyword = "NonExistentKeyWord"; BoxCollection <BoxItem> results = await _client.SearchManager.SearchAsync(keyword, 200); Assert.IsNotNull(results, "Search results are null"); Assert.AreEqual(0, results.Entries.Count, "Incorrect number of search results"); }
public async Task SearchKeyword_LiveSession_ValidResponse() { // Test adding a new comment const string keyword = "test"; BoxCollection <BoxItem> results = await _client.SearchManager.SearchAsync(keyword, 10); Assert.IsNotNull(results); }
public async Task SearchAsync_ForNonExistentKeyword_ShouldReturnNoResults() { const string Keyword = "NonExistentKeyWord"; BoxCollection <BoxItem> results = await UserClient.SearchManager.SearchAsync(Keyword, 200); Assert.IsNotNull(results); Assert.AreEqual(0, results.Entries.Count); }
public async Task GetPendingCollaboration_ValidResponse_ValidEntries() { /*** Arrange ***/ string responseString = @"{ ""total_count"": 1, ""entries"": [ { ""type"": ""collaboration"", ""id"": ""27513888"", ""created_by"": { ""type"": ""user"", ""id"": ""11993747"", ""name"": ""sean"", ""login"": ""*****@*****.**"" }, ""created_at"": ""2012-10-17T23:14:42-07:00"", ""modified_at"": ""2012-10-17T23:14:42-07:00"", ""expires_at"": null, ""status"": ""Pending"", ""accessible_by"": { ""type"": ""user"", ""id"": ""181216415"", ""name"": ""sean rose"", ""login"": ""*****@*****.**"" }, ""role"": ""Editor"", ""acknowledged_at"": null, ""invite_email"": ""*****@*****.**"", ""item"": null } ] }"; IBoxRequest boxRequest = null; Handler.Setup(h => h.ExecuteAsync <BoxCollection <BoxCollaboration> >(It.IsAny <IBoxRequest>())) .Returns(Task.FromResult <IBoxResponse <BoxCollection <BoxCollaboration> > >(new BoxResponse <BoxCollection <BoxCollaboration> >() { Status = ResponseStatus.Success, ContentString = responseString })) .Callback <IBoxRequest>(r => boxRequest = r); /*** Act ***/ BoxCollection <BoxCollaboration> collaborations = await _collaborationsManager.GetPendingCollaborationAsync(); /*** Assert ***/ Assert.AreEqual(1, collaborations.TotalCount); Assert.AreEqual("27513888", collaborations.Entries[0].Id); Assert.AreEqual("collaboration", collaborations.Entries[0].Type); Assert.AreEqual("user", collaborations.Entries[0].AccessibleBy.Type); Assert.AreEqual("181216415", collaborations.Entries[0].AccessibleBy.Id); Assert.AreEqual("*****@*****.**", collaborations.Entries[0].InviteEmail); }
public async Task GetAssignments_ValidResponse() { /*** Arrange ***/ var responseString = @"{ ""total_count"": 1, ""entries"": [ { ""type"": ""task_assignment"", ""id"": ""2485961"", ""item"": { ""type"": ""file"", ""id"": ""7287087200"", ""sequence_id"": ""0"", ""etag"": ""0"", ""sha1"": ""0bbd79a105c504f99573e3799756debba4c760cd"", ""name"": ""box-logo.png"" }, ""assigned_to"": { ""type"": ""user"", ""id"": ""193425559"", ""name"": ""Rhaegar Targaryen"", ""login"": ""*****@*****.**"" } } ] }"; IBoxRequest boxRequest = null; var tasksUri = new Uri(Constants.TasksEndpointString); Config.SetupGet(x => x.TasksEndpointUri).Returns(tasksUri); Handler.Setup(h => h.ExecuteAsync <BoxCollection <BoxTaskAssignment> >(It.IsAny <IBoxRequest>())) .Returns(Task.FromResult <IBoxResponse <BoxCollection <BoxTaskAssignment> > >(new BoxResponse <BoxCollection <BoxTaskAssignment> >() { Status = ResponseStatus.Success, ContentString = responseString })) .Callback <IBoxRequest>(r => boxRequest = r); BoxCollection <BoxTaskAssignment> result = await _tasksManager.GetAssignmentsAsync("1839355"); /*** Assert ***/ //Request check Assert.IsNotNull(boxRequest); Assert.AreEqual(RequestMethod.Get, boxRequest.Method); Assert.AreEqual(tasksUri + string.Format(Constants.TaskAssignmentsPathString, "1839355"), boxRequest.AbsoluteUri.AbsoluteUri); //Response check Assert.AreEqual(1, result.TotalCount); Assert.AreEqual("2485961", result.Entries[0].Id); Assert.AreEqual("193425559", result.Entries[0].AssignedTo.Id); Assert.AreEqual("*****@*****.**", result.Entries[0].AssignedTo.Login); Assert.AreEqual("task_assignment", result.Entries[0].Type); Assert.AreEqual("file", result.Entries[0].Item.Type); Assert.AreEqual("7287087200", result.Entries[0].Item.Id); Assert.AreEqual("box-logo.png", result.Entries[0].Item.Name); }
protected virtual void PrintCollaborations(BoxCollection <BoxCollaboration> collabs) { if (collabs == null || collabs.Entries.Count == 0) { Reporter.WriteInformation("This item has no collaborations."); } foreach (var collab in collabs.Entries) { base.PrintCollaboration(collab); } }
protected void PrintAliases(BoxCollection <BoxEmailAlias> aliases) { Reporter.WriteInformation($"User has a total of {aliases.TotalCount} email aliases"); for (int i = 0; i < aliases.TotalCount; i++) { Reporter.WriteInformation($"Email Alias Information"); Reporter.WriteInformation($"Email Alias: {aliases.Entries[i].Email}"); Reporter.WriteInformation($"Aliases Confirmed: {aliases.Entries[i].IsConfirmed}"); Reporter.WriteInformation($"Alias ID: {aliases.Entries[i].Id}"); } }
public async Task GetFolderItemsAsync(string id) { Items.Clear(); BoxCollection <BoxItem> results = await Client.FoldersManager.GetFolderItemsAsync((string)id, 100); foreach (BoxItem item in results.Entries) { Items.Add(item); } }
public static void Main() { int inputLines = int.Parse(Console.ReadLine()); BoxCollection <string> stringBox = new BoxCollection <string>(); for (int i = 0; i < inputLines; i++) { stringBox.Add(Console.ReadLine()); } Console.WriteLine(stringBox); }
//recursive function that pulls all files from all folders public async Task <List <string> > searchFolder(BoxClient client, BoxCollection <BoxItem> items, string BoxURL) { List <string> files = new List <string>(); //stores the file names for future display List <string> tempFiles = new List <string>(); int id = 0; //temp placeholder for id foreach (BoxItem item in items.Entries) //loop through all items in a folder { if (item.Type == "folder") //if the item is a folder dive into it { BoxCollection <BoxItem> folder = await client.FoldersManager.GetFolderItemsAsync(item.Id, 500); //get files from new folder tempFiles = await searchFolder(client, folder, BoxURL); //recursive call foreach (string i in tempFiles) //load file names into list { files.Add(i); } continue; //skip to next item } //converts the box field id from string to int Int32.TryParse(item.Id.Substring(item.Id.Length - 5, 4), out id); //id is actually a long so for our purposes i just grabbed some of it Stream stream = await client.FilesManager.DownloadStreamAsync(item.Id); //grab the actual file docs elasticSearch = new docs(); //build elasticSearch Connection byte[] data; byte[] buffer = new byte[1024 * 64]; using (MemoryStream ms = new MemoryStream()) //grab file stream and pass it into elasticsearch { int count = 0; do { count = stream.Read(buffer, 0, buffer.Length); ms.Write(buffer, 0, count); } while (count > 0); data = ms.ToArray(); FileMeta tempFile = new FileMeta(); tempFile.Path = BoxURL + item.Id; tempFile.File = data; //load metadata for elasticsearch tempFile.Id = id; //load metadata for elasticsearch tempFile.Name = item.Name; //load metadata for elasticsearch tempFile.longID = item.Id; elasticSearch.uploadDirect(tempFile); //upload the file in memory stream to elasticsearch as id of j } files.Add(item.Name); //append the name of the file to the list for future display on results page } return(files); //return a list of all files }
public List <FileSystemEntry> ListEntriesInDirectory(string path) { List <FileSystemEntry> fileSystemEntryList = null; try { string itemType = null; string currFolderId = GetFileOrFolderIDfromPath(path, ref itemType); var folderInfo = boxClient.FoldersManager.GetFolderItemsAsync(currFolderId, 100); folderInfo.Wait(); BoxCollection <BoxItem> collAll = new BoxCollection <BoxItem>(); collAll.Entries = new List <BoxItem>(); collAll.Entries.AddRange(folderInfo.Result.Entries); if (folderInfo.Result.TotalCount > 100) { for (int i = 1; i <= folderInfo.Result.TotalCount / 100 + 1; i++) { var folderItems = boxClient.FoldersManager.GetFolderItemsAsync(currFolderId, i * 100); folderItems.Wait(); if (folderItems.Result.Entries.Count > 0) { collAll.Entries.AddRange(folderItems.Result.Entries); } } } fileSystemEntryList = new List <FileSystemEntry>(); foreach (BoxItem item in collAll.Entries) { fileSystemEntryList.Add(GetEntry(path + "\\" + item.Name)); } } catch (Exception e) { if (e.InnerException != null) { EventLog.WriteEntry("Box SMB", e.Message + " Inner Exception: " + e.InnerException.Message, EventLogEntryType.Error); } else { EventLog.WriteEntry("Box SMB", e.Message, EventLogEntryType.Error); } } return(fileSystemEntryList); }
public async Task SearchKeyword_LiveSession_ValidResponse() { const string keyword = "IMG"; const int numResults = 13; const int numFiles = 12; const int numFolders = 1; BoxCollection <BoxItem> results = await _client.SearchManager.SearchAsync(keyword, 200); Assert.IsNotNull(results, "Search results are null"); Assert.AreEqual(numResults, results.Entries.Count, "Incorrect number of search results"); Assert.IsTrue(results.Entries.Count(item => item is BoxFolder) == numFolders, "Incorrect number of folders in search results"); Assert.IsTrue(results.Entries.Count(item => item is BoxFile) == numFiles, "Incorrect number of files in search results"); }