private async Task RunLock() { base.CheckForFileId(this._fileId.Value, this._app); var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); var lockRequest = new BoxFileLockRequest(); var boxLock = new BoxFileLock(); if (this._preventDownload.HasValue()) { boxLock.IsDownloadPrevented = true; } if (this._expires.HasValue()) { boxLock.ExpiresAt = GeneralUtilities.GetDateTimeFromString(this._expires.Value()); } lockRequest.Lock = boxLock; var boxLocked = await boxClient.FilesManager.LockAsync(lockRequest, this._fileId.Value); if (base._json.HasValue() || this._home.GetBoxHomeSettings().GetOutputJsonSetting()) { base.OutputJson(boxLocked); return; } base.PrintFileLock(boxLocked); }
public async Task GetLockFile_ValidResponse_Success() { /*** Arrange ***/ 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\": true } } "; _handler.Setup(h => h.ExecuteAsync <BoxFile>(It.IsAny <IBoxRequest>())) .Returns(Task.FromResult <IBoxResponse <BoxFile> >(new BoxResponse <BoxFile>() { Status = ResponseStatus.Success, ContentString = responseString })); /*** Act ***/ BoxFileLock fileLock = await _filesManager.GetLockAsync("0"); /*** Assert ***/ Assert.IsNotNull(fileLock); Assert.AreEqual(true, 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); }
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(new DateTime(2014, 5, 31, 4, 03, 04, DateTimeKind.Utc), fileLock.ExpiresAt); Assert.AreEqual(new DateTime(2014, 5, 30, 3, 03, 04, DateTimeKind.Utc), fileLock.CreatedAt); Assert.IsNotNull(fileLock.CreatedBy); Assert.AreEqual("I don't know gmail", fileLock.CreatedBy.Name); Assert.AreEqual("*****@*****.**", fileLock.CreatedBy.Login); }
protected void PrintFileLock(BoxFileLock fileLock) { Reporter.WriteInformation($"File Lock ID: {fileLock.Id}"); Reporter.WriteInformation($"Is download prevented: {fileLock.IsDownloadPrevented}"); Reporter.WriteInformation($"Expires at: {fileLock.ExpiresAt}"); Reporter.WriteInformation($"Created at: {fileLock.CreatedAt}"); base.PrintMiniUser(fileLock.CreatedBy); }