Exemplo n.º 1
0
        public async Task GetFolderInformation_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\": 1, \"entries\": [ { \"type\": \"file\", \"id\": \"5000948880\", \"sequence_id\": \"3\", \"etag\": \"3\", \"sha1\": \"134b65991ed521fcfe4724b7d814ab8ded5185dc\", \"name\": \"tigers.jpeg\" } ], \"offset\": 0, \"limit\": 100 } }"
            }));

            BoxFolder f = await _foldersManager.GetInformationAsync("fakeId");
        }
        public async Task GetFolderInformation_ValidResponse_ValidFolder()
        {
            IBoxRequest boxRequest = null;

            /*** 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 } }"
            }))
            .Callback <IBoxRequest>(r => boxRequest = r);;

            /*** Act ***/
            BoxFolder f = await _foldersManager.GetInformationAsync("11446498", new List <string>() { "f1", "f2", "f3" });

            /*** Assert ***/
            Assert.IsNotNull(boxRequest);
            Assert.AreEqual(RequestMethod.Get, boxRequest.Method);
            Assert.AreEqual(_FoldersUri + "11446498?fields=f1,f2,f3", boxRequest.AbsoluteUri.AbsoluteUri);

            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].Type, "folder");
            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, 1);
            Assert.AreEqual(f.ItemCollection.Entries.Count, 1);
            Assert.AreEqual(f.ItemCollection.Entries[0].Type, "file");
            Assert.AreEqual(f.ItemCollection.Entries[0].Id, "5000948880");
            Assert.AreEqual(f.ItemCollection.Entries[0].SequenceId, "3");
            Assert.AreEqual(f.ItemCollection.Entries[0].ETag, "3");
            Assert.AreEqual((f.ItemCollection.Entries[0] as BoxFile).Sha1, "134b65991ed521fcfe4724b7d814ab8ded5185dc");
            Assert.AreEqual(f.ItemCollection.Entries[0].Name, "tigers.jpeg");
            Assert.AreEqual(f.ItemCollection.Offset, 0);
            Assert.AreEqual(f.ItemCollection.Limit, 100);
        }