public IActionResult GetFileMetadata(string fileName, string bucketName) { try { ICloudFileMetadata remoteFile = _fileService.GetFileMetadata(fileName, bucketName); return(Ok(remoteFile)); } catch (ArgumentException aex) when(aex.Message.StartsWith("Not Found")) { return(NotFound()); } }
public void GetFileMetadataTest(string bucketName, string remoteLocation, string fileName) { string remotePath = $"{remoteLocation}/{fileName}".TrimStart(Path.AltDirectorySeparatorChar); var client = _serviceProvider.GetService <ICloudFileService>(); ICloudFileMetadata actual = null; try { actual = client.GetFileMetadata(remotePath, bucketName); bool retrieveSuccess = actual?.LastModified != null; if (!retrieveSuccess) { throw new Exception("File or date is `null`, something is not correct"); } } catch (ArgumentException ae) when(ae.Message.StartsWith("Not found")) { Assert.Fail("File not found"); } catch (Exception ex) { Assert.Fail(ex.Message); } bool actualDateExist = actual.LastModified != null; bool actualSizeExist = actual.Size > 0; string expectedSignedUrl = actual.SignedUrl.StartsWith(@"C:\") ? actual.SignedUrl : string.Empty; string expectedBucket = bucketName; string expectedName = remotePath; Assert.AreEqual(expectedSignedUrl, actual.SignedUrl); Assert.AreEqual(expectedBucket, actual.Bucket); Assert.AreEqual(expectedName, actual.Name); Assert.IsTrue(actualDateExist); Assert.IsTrue(actualSizeExist); }
public void UploadFileTest(string bucketName, string remoteLocation, string fileName) { string localPath = Path.Combine(Directory.GetCurrentDirectory(), fileName); string remotePath = $"{remoteLocation}/{fileName}".TrimStart(Path.AltDirectorySeparatorChar); var client = _serviceProvider.GetService <ICloudFileService>(); try { ICloudFileMetadata uploadedFile = client.UploadFile(localPath, remotePath, bucketName); bool uploadSuccess = uploadedFile.LastModified != null; Assert.IsTrue(uploadSuccess); } catch (ArgumentException ae) when(ae.Message.EndsWith("valid file extension")) { Assert.Fail(ae.Message); } catch (Exception ex) { Assert.Fail(ex.Message); } }