public void ShareFolderLinkAsync()
        {
            Folder actual = null;
            var folderName = TestItemName();
            var folder = Client.CreateFolder(RootId, folderName, null);
            var sharedLink = new SharedLink(Access.Open, DateTime.UtcNow.AddDays(3), new Permissions {CanPreview = true, CanDownload = true});

            Client.ShareFolderLink(copiedFolder => actual = copiedFolder, AbortOnFailure, folder.Id, sharedLink, null);

            AssertActionComplete(ref actual);
            Client.Delete(folder, true);
            AssertFolderConstraints(actual, folderName, RootId);
            AssertSharedLink(actual.SharedLink, sharedLink);
        }
        public void UpdateEverythingAsync()
        {
            // Arrange
            Folder actual = null;
            const string newDescription = "new description";
            var folder = Client.CreateFolder(RootId, TestItemName(), null);
            var newParent = Client.CreateFolder(RootId, TestItemName(), null);
            var sharedLink = new SharedLink(Access.Open, DateTime.UtcNow.AddDays(3), new Permissions {CanDownload = true, CanPreview = true});
            var newName = TestItemName();

            // Act
            folder.Name = newName;
            folder.Description = newDescription;
            folder.Parent.Id = newParent.Id;
            folder.SharedLink = sharedLink;
            Client.Update(updatedFolder => actual = updatedFolder, AbortOnFailure, folder, null);

            AssertActionComplete(ref actual);
            Client.Delete(folder, true);
            Client.Delete(newParent, true);
            AssertFolderConstraints(actual, newName, newParent.Id, folder.Id);
            AssertSharedLink(sharedLink, actual.SharedLink);
            Assert.That(actual.Description, Is.EqualTo(newDescription));
        }
 /// <summary>
 ///     Creates a shared link to the specified file
 /// </summary>
 /// <param name="file">The file for which to create a shared link</param>
 /// <param name="sharedLink">The properties of the shared link</param>
 /// <param name="fields">The properties that should be set on the returned File object.  Type and Id are always set.  If left null, all properties will be set, which can increase response time.</param>
 /// <param name="etag">Include the item's etag to prevent the completion of this operation if you don't have the must current version of the item.  A BoxItemModifiedException will be thrown if the item is stale.</param>
 /// <returns>A file object populated with the shared link</returns>
 /// <remarks>In order for File.SharedLink to be populated, you must either include Field.SharedLink in the fields list, or leave the list null</remarks>
 public File ShareLink(File file, SharedLink sharedLink, IEnumerable<FileField> fields = null, string etag = null)
 {
     GuardFromNull(file, "file");
     return ShareFileLink(file.Id, sharedLink, fields, etag);
 }
 /// <summary>
 ///     Creates a shared link to the specified file
 /// </summary>
 /// <param name="onSuccess">Action to perform with the linked file</param>
 /// <param name="onFailure">Action to perform following a failed File operation</param>
 /// <param name="file">The file for which to create a shared link</param>
 /// <param name="sharedLink">The properties of the shared link</param>
 /// <param name="fields">The properties that should be set on the returned File object.  Type and Id are always set.  If left null, all properties will be set, which can increase response time.</param>
 /// <param name="etag">Include the item's etag to prevent the completion of this operation if you don't have the must current version of the item.  A BoxItemModifiedException will be thrown if the item is stale.</param>
 /// <remarks>In order for File.SharedLink to be populated, you must either include Field.SharedLink in the fields list, or leave the list null</remarks>
 public void ShareLink(Action<File> onSuccess, Action<Error> onFailure, File file, SharedLink sharedLink, IEnumerable<FileField> fields = null, string etag = null)
 {
     GuardFromNull(file, "file");
     ShareFileLink(onSuccess, onFailure, file.Id, sharedLink, fields, etag);
 }
 public void ShareLink()
 {
     string fileName = TestItemName();
     File file = Client.CreateFile(RootId, fileName);
     // Act
     var expectedLink = new SharedLink(Access.Open, DateTime.UtcNow.AddDays(3), new Permissions {CanDownload = true, CanPreview = true});
     File linkedFile = Client.ShareLink(file, expectedLink);
     Client.Delete(linkedFile);
     // Assert
     AssertFileConstraints(linkedFile, file.Name, RootId, file.Id);
     AssertSharedLink(linkedFile.SharedLink, expectedLink);
 }
        public void UpdateAsync()
        {
            // Arrange
            File actual = null;
            File file = Client.CreateFile(RootId, TestItemName());
            const string newDescription = "new description";
            Folder folder = Client.CreateFolder(RootId, TestItemName(), null);
            var sharedLink = new SharedLink(Access.Open, DateTime.UtcNow.AddDays(3), new Permissions {CanDownload = true, CanPreview = true});
            string newName = TestItemName();

            // Act
            file.Name = newName;
            file.Description = newDescription;
            file.Parent.Id = folder.Id;
            file.SharedLink = sharedLink;
            Client.Update(updatedFile => { actual = updatedFile; }, AbortOnFailure, file, null);

            AssertActionComplete(ref actual);
            Client.Delete(folder, recursive: true);
            AssertFileConstraints(actual, newName, folder.Id, file.Id);
            AssertSharedLink(sharedLink, actual.SharedLink);
            Assert.That(actual.Description, Is.EqualTo(newDescription));
        }
        public void ShareFolderLinkAsync()
        {
            var callbackHit = false;
            var folderName = TestItemName();
            var folder = Client.CreateFolder(RootId, folderName, null);
            var sharedLink = new SharedLink(Access.Open, DateTime.UtcNow.AddDays(3), new Permissions {CanPreview = true, CanDownload = true});

            Client.ShareFolderLink(copiedFolder =>
                {
                    callbackHit = true;
                    AssertFolderConstraints(folder, folderName, RootId);
                    AssertSharedLink(folder.SharedLink, sharedLink);
                    Client.DeleteFolder(folder.Id, true);
                }, AbortOnFailure, folder.Id, sharedLink, null);

            do
            {
                Thread.Sleep(1000);
            } while (!callbackHit && --MaxWaitInSeconds > 0);

            if (MaxWaitInSeconds.Equals(0))
            {
                Assert.Fail("Async operation did not complete in alloted time.");
            }
        }
 public void ShareLinkAccessOnly()
 {
     string fileName = TestItemName();
     File file = Client.CreateFile(RootId, fileName);
     // Act
     var expectedLink = new SharedLink(Access.Open);
     File linkedFile = Client.ShareLink(file, expectedLink);
     Client.Delete(linkedFile);
     // Assert
     AssertFileConstraints(linkedFile, file.Name, RootId, file.Id);
     AssertSharedLink(linkedFile.SharedLink, expectedLink);
 }
 protected static void AssertSharedLink(SharedLink actual, SharedLink sharedLink)
 {
     Assert.That(actual, Is.Not.Null);
         Assert.That(actual.Access, Is.EqualTo(sharedLink.Access));
         Assert.That(actual.UnsharedAt, Is.GreaterThan(DateTime.MinValue));
         Assert.That(actual.UnsharedAt, Is.LessThan(DateTime.MaxValue));
         Assert.That(actual.Permissions.CanDownload, Is.True);
         Assert.That(actual.Permissions.CanPreview, Is.True);
 }
 public void DisableSharedLink()
 {
     var folderName = TestItemName();
     var folder = Client.CreateFolder(RootId, folderName, null);
     Folder actual = null;
     try
     {
         var sharedLink = new SharedLink(Access.Open, DateTime.UtcNow.AddDays(3), new Permissions { CanPreview = true, CanDownload = true });
         var update = Client.ShareLink(folder, sharedLink);
         AssertSharedLink(update.SharedLink, sharedLink);
         actual = Client.DisableSharedLink(update);
         AssertSharedLink(actual.SharedLink, null);
     }
     finally
     {
         if (actual != null)
         {
             Client.Delete(actual, true);
         }
     }
 }
 /// <summary>
 ///     Creates a shared link to the specified folder
 /// </summary>
 /// <param name="onSuccess">Action to perform with the linked folder</param>
 /// <param name="onFailure">Action to perform following a failed operation</param>
 /// <param name="folder">The folder for which to create a shared link</param>
 /// <param name="sharedLink">The properties of the shared link</param>
 /// <param name="fields">The properties that should be set on the returned Folder object.  Type and Id are always set.  If left null, all properties will be set, which can increase response time.</param>
 /// <param name="etag">Include the item's etag to prevent the completion of this operation if you don't have the must current version of the item.  A BoxItemModifiedException will be thrown if the item is stale.</param>
 /// <remarks>In order for Folder.SharedLink to be populated, you must either include Field.SharedLink in the fields list, or leave the list null</remarks>
 public void ShareLink(Action<Folder> onSuccess, Action<Error> onFailure, Folder folder, SharedLink sharedLink, IEnumerable<FolderField> fields = null, string etag = null)
 {
     GuardFromNull(folder, "folder");
     ShareFolderLink(onSuccess, onFailure, folder.Id, sharedLink, fields, etag);
 }
 /// <summary>
 ///     Creates a shared link to the specified folder
 /// </summary>
 /// <param name="folder">The folder for which to create a shared link</param>
 /// <param name="sharedLink">The properties of the shared link</param>
 /// <param name="fields">The properties that should be set on the returned Folder object.  Type and Id are always set.  If left null, all properties will be set, which can increase response time.</param>
 /// <param name="etag">Include the item's etag to prevent the completion of this operation if you don't have the must current version of the item.  A BoxItemModifiedException will be thrown if the item is stale.</param>
 /// <returns>An object populated with the shared link</returns>
 /// <remarks>In order for Folder.SharedLink to be populated, you must either include Field.SharedLink in the fields list, or leave the list null</remarks>
 public Folder ShareLink(Folder folder, SharedLink sharedLink, IEnumerable<FolderField> fields = null, string etag = null)
 {
     GuardFromNull(folder, "folder");
     return ShareFolderLink(folder.Id, sharedLink, fields, etag);
 }
        public void ShareFileLinkAsync()
        {
            // Arrange
            File actual = null;
            File file = Client.CreateFile(RootId, TestItemName());
            var expectedLink = new SharedLink(Access.Open, DateTime.UtcNow.AddDays(3), new Permissions {CanDownload = true, CanPreview = true});

            // Act
            Client.ShareLink(sharedFile => { actual = sharedFile; }, AbortOnFailure, file, expectedLink, null);

            AssertActionComplete(ref actual);
            Client.Delete(actual);
            AssertFileConstraints(actual, file.Name, RootId, file.Id);
            AssertSharedLink(actual.SharedLink, expectedLink);
        }
 public void CreateSharedLink()
 {
     var folderName = TestItemName();
     var folder = Client.CreateFolder(RootId, folderName, null);
     var sharedLink = new SharedLink(Access.Open, DateTime.UtcNow.AddDays(3), new Permissions {CanPreview = true, CanDownload = true});
     var update = Client.ShareLink(folder, sharedLink);
     AssertFolderConstraints(update, folderName, RootId, folder.Id);
     AssertSharedLink(update.SharedLink, sharedLink);
     Client.Delete(update, true);
 }
        public void UpdateEverythingAsync()
        {
            // Arrange
            var callbackHit = false;
            var fileName = TestItemName();
            var folder = Client.CreateFolder(RootId, fileName, null);
            var newDescription = "new description";
            var newFolder = TestItemName();
            var newParent = Client.CreateFolder(RootId, newFolder, null);
            var sharedLink = new SharedLink(Access.Open, DateTime.UtcNow.AddDays(3), new Permissions {CanDownload = true, CanPreview = true});
            var newName = TestItemName();

            // Act
            folder.Name = newName;
            folder.Description = newDescription;
            folder.Parent.Id = newParent.Id;
            folder.SharedLink = sharedLink;
            Client.Update(updatedFolder =>
                {
                    // Assert
                    Client.Delete(updatedFolder, true);
                    AssertFolderConstraints(updatedFolder, newName, newParent.Id, folder.Id);
                    AssertSharedLink(sharedLink, updatedFolder.SharedLink);
                    Assert.That(updatedFolder.Description, Is.EqualTo(newDescription));
                    callbackHit = true;
                }, AbortOnFailure, folder, null);

            do
            {
                Thread.Sleep(1000);
            } while (!callbackHit && --MaxWaitInSeconds > 0);

            // Cleanup

            if (MaxWaitInSeconds.Equals(0))
            {
                Assert.Fail("Async operation did not complete in alloted time.");
            }
        }
 public void UpdateEverything()
 {
     var folder = Client.CreateFolder(RootId, TestItemName(), null);
     var newDescription = "new description";
     var newParent = Client.CreateFolder(RootId, TestItemName(), null);
     var sharedLink = new SharedLink(Access.Open, DateTime.UtcNow.AddDays(3), new Permissions {CanDownload = true, CanPreview = true});
     var newName = TestItemName();
     // Act
     try
     {
         folder.Parent.Id = newParent.Id;
         folder.Description = newDescription;
         folder.Name = newName;
         folder.SharedLink = sharedLink;
         var updatedFolder = Client.Update(folder);
         // Assert
         AssertFolderConstraints(updatedFolder, newName, newParent.Id, folder.Id);
         AssertSharedLink(sharedLink, folder.SharedLink);
         Assert.That(updatedFolder.Description, Is.EqualTo(newDescription));
     }
     finally
     {
         Client.Delete(newParent, true);
     }
 }
 /// <summary>
 ///     Creates a shared link to the specified file
 /// </summary>
 /// <param name="id">The ID of the file for which to create a shared link</param>
 /// <param name="sharedLink">The properties of the shared link</param>
 /// <param name="fields">The properties that should be set on the returned File object.  Type and Id are always set.  If left null, all properties will be set, which can increase response time.</param>
 /// <param name="etag">Include the item's etag to prevent the completion of this operation if you don't have the must current version of the item.  A BoxItemModifiedException will be thrown if the item is stale.</param>
 /// <returns>A file object populated with the shared link</returns>
 /// <remarks>In order for File.SharedLink to be populated, you must either include Field.SharedLink in the fields list, or leave the list null</remarks>
 public File ShareFileLink(string id, SharedLink sharedLink, IEnumerable<FileField> fields = null, string etag = null)
 {
     GuardFromNull(id, "id");
     GuardFromNull(sharedLink, "sharedLink");
     IRestRequest request = _requestHelper.Update(ResourceType.File, id, etag, fields, sharedLink: sharedLink);
     return _restClient.ExecuteAndDeserialize<File>(request);
 }
 public void ShareLinkMustHaveSomePermissions()
 {
     string fileName = TestItemName();
     File file = Client.CreateFile(RootId, fileName);
     // Act
     var expectedLink = new SharedLink(Access.Open, permissions:new Permissions(){CanDownload = false, CanPreview = false});
     File linkedFile = Client.ShareLink(file, expectedLink);
     Client.Delete(linkedFile);
     // Assert
     AssertFileConstraints(linkedFile, file.Name, RootId, file.Id);
     AssertSharedLink(linkedFile.SharedLink, expectedLink);
 }
 /// <summary>
 ///     Creates a shared link to the specified file
 /// </summary>
 /// <param name="onSuccess">Action to perform with the linked file</param>
 /// <param name="onFailure">Action to perform following a failed File operation</param>
 /// <param name="id">The ID of the file for which to create a shared link</param>
 /// <param name="sharedLink">The properties of the shared link</param>
 /// <param name="fields">The properties that should be set on the returned File object.  Type and Id are always set.  If left null, all properties will be set, which can increase response time.</param>
 /// <param name="etag">Include the item's etag to prevent the completion of this operation if you don't have the must current version of the item.  A BoxItemModifiedException will be thrown if the item is stale.</param>
 /// <remarks>In order for File.SharedLink to be populated, you must either include Field.SharedLink in the fields list, or leave the list null</remarks>
 public void ShareFileLink(Action<File> onSuccess, Action<Error> onFailure, string id, SharedLink sharedLink, IEnumerable<FileField> fields = null, string etag = null)
 {
     GuardFromNull(id, "id");
     GuardFromNull(sharedLink, "sharedLink");
     GuardFromNullCallbacks(onSuccess, onFailure);
     IRestRequest request = _requestHelper.Update(ResourceType.File, id, etag, fields, sharedLink: sharedLink);
     _restClient.ExecuteAsync(request, onSuccess, onFailure);
 }
 public void UpdateEverything()
 {
     string fileName = TestItemName();
     File file = Client.CreateFile(RootId, fileName);
     string newDescription = "new description";
     string newFolder = TestItemName();
     Folder folder = Client.CreateFolder(RootId, newFolder, null);
     var sharedLink = new SharedLink(Access.Open, DateTime.UtcNow.AddDays(3), new Permissions {CanDownload = true, CanPreview = true});
     string newName = TestItemName();
     // Act
     try
     {
         file.Parent.Id = folder.Id;
         file.Description = newDescription;
         file.Name = newName;
         file.SharedLink = sharedLink;
         File updatedFile = Client.Update(file);
         // Assert
         AssertFileConstraints(updatedFile, newName, folder.Id, file.Id);
         AssertSharedLink(sharedLink, file.SharedLink);
         Assert.That(updatedFile.Description, Is.EqualTo(newDescription));
     }
     finally
     {
         Client.Delete(folder, true);
     }
 }
        public void ShareFileLinkAsync()
        {
            // Arrange
            var callbackHit = false;
            var testItemName = TestItemName();
            var file = Client.CreateFile(RootId, testItemName);
            var expectedLink = new SharedLink(Access.Open, DateTime.UtcNow.AddDays(3), new Permissions {CanDownload = true, CanPreview = true});

            // Act
            Client.ShareLink(sharedFile =>
                {
                    // Assert
                    Client.Delete(sharedFile);
                    AssertFileConstraints(sharedFile, file.Name, RootId, file.Id);
                    AssertSharedLink(sharedFile.SharedLink, expectedLink);
                    callbackHit = true;
                }, AbortOnFailure, file, expectedLink, null);

            do
            {
                Thread.Sleep(1000);
            } while (!callbackHit && --MaxWaitInSeconds > 0);

            // Cleanup

            if (MaxWaitInSeconds.Equals(0))
            {
                Assert.Fail("Async operation did not complete in alloted time.");
            }
        }