/// <summary> /// Used to create a lock on the file. /// </summary> /// <param name="lockFileRequest">Request contains Lock object for setting of lock properties such as ExpiresAt - the time the lock expires, IsDownloadPrevented - whether or not the file can be downloaded while locked. </param> /// <param name="id">Id of the file.</param> /// <returns>Returns information about locked file</returns> public async Task<BoxFileLock> LockAsync(BoxFileLockRequest lockFileRequest, string id) { return await UpdateLockAsync(lockFileRequest, id); }
/// <summary> /// Used to update the lock information on the file /// </summary> /// <param name="fileRequest"></param> /// <returns></returns> public async Task<BoxFileLock> UpdateLockAsync(BoxFileLockRequest lockFileRequest, string Id) { BoxRequest request = new BoxRequest(_config.FilesEndpointUri, Id) .Method(RequestMethod.Put) .Param(ParamFields, "lock"); request.Payload = _converter.Serialize(lockFileRequest); IBoxResponse<BoxFile> response = await ToResponseAsync<BoxFile>(request).ConfigureAwait(false); return response.ResponseObject.Lock; }
/// <summary> /// Used to update the lock information on the file (for example, ExpiresAt or IsDownloadPrevented. /// </summary> /// <param name="lockFileRequest">BoxFileLockRequest object.</param> /// <param name="id">Id of the file.</param> /// <returns>BoxFileLock object.</returns> public async Task<BoxFileLock> UpdateLockAsync(BoxFileLockRequest lockFileRequest, string id) { lockFileRequest.ThrowIfNull("lockFileRequest"); id.ThrowIfNullOrWhiteSpace("id"); BoxRequest request = new BoxRequest(_config.FilesEndpointUri, id) .Method(RequestMethod.Put) .Param(ParamFields, BoxFile.FieldLock); request.Payload = _converter.Serialize(lockFileRequest); IBoxResponse<BoxFile> response = await ToResponseAsync<BoxFile>(request).ConfigureAwait(false); return response.ResponseObject.Lock; }
public async Task UpdateFileLock_ValidResponse_ValidFile() { string responseString = "{ \"type\": \"file\", \"id\": \"7435988481\", \"etag\": \"1\", \"lock\": { \"type\": \"lock\", \"id\": \"14516545\", \"created_by\": { \"type\": \"user\", \"id\": \"13130406\", \"name\": \"I don't know gmail\", \"login\": \"[email protected]\" }, \"created_at\": \"2014-05-29T18:03:04-07:00\", \"expires_at\": \"2014-05-30T19:03:04-07:00\", \"is_download_prevented\": false } } "; _handler.Setup(h => h.ExecuteAsync<BoxFile>(It.IsAny<IBoxRequest>())) .Returns(Task.FromResult<IBoxResponse<BoxFile>>(new BoxResponse<BoxFile>() { Status = ResponseStatus.Success, ContentString = responseString })); /*** Act ***/ BoxFileLockRequest request = new BoxFileLockRequest(); request.Lock = new BoxFileLock(); request.Lock.IsDownloadPrevented = false; BoxFileLock fileLock = await _filesManager.UpdateLockAsync(request, "0"); /*** Assert ***/ Assert.IsNotNull(fileLock); Assert.AreEqual(false, fileLock.IsDownloadPrevented); Assert.AreEqual(DateTime.Parse("2014-05-30T19:03:04-07:00"), fileLock.ExpiresAt); Assert.AreEqual(DateTime.Parse("2014-05-29T18:03:04-07:00"), fileLock.CreatedAt); Assert.IsNotNull(fileLock.CreatedBy); Assert.AreEqual("I don't know gmail", fileLock.CreatedBy.Name); Assert.AreEqual("*****@*****.**", fileLock.CreatedBy.Login); }