public async Task GeoObjectTest() { S3FileStorage fileStorage = new S3FileStorage(options); var stream = await fileStorage.GetStreamAsync("EOzfMJj0RkL3xI4E0rIKsa5bQ8HYe9wy488hHzlmlvrwl0r3dmQqBTrgaN9Rv2mC").ConfigureAwait(false); Assert.True(stream.Position == 0 && stream.CanRead); }
public async Task SearchTest() { S3FileStorage fileStorage = new S3FileStorage(options); var filesInfo = await fileStorage.SearchAsync("EOzfMJj0RkL3xI4E0rIKsa5bQ8HYe9wy488hHzlmlvrwl0r3dmQqBTrgaN9Rv2mC").ConfigureAwait(false); Assert.NotEmpty(filesInfo); }
public async Task Storage_Exists_DelegatesToGetKeys() { var clientMock = new Mock <IAmazonS3>(); string actualPrefix = null; string actualBucket = null; const string bucket = "fooBucket"; const string fileName = "myFile"; clientMock .Setup(c => c.GetAllObjectKeysAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <IDictionary <string, object> >())) .Callback <string, string, IDictionary <string, object> >((buck, pref, _) => { actualBucket = buck; actualPrefix = pref; }) .Returns(Task.FromResult <IList <string> >(new[] { fileName })); var storage = new S3FileStorage(clientMock.Object, bucket); Assert.True(await storage.ExistsAsync(fileName)); Assert.AreEqual(bucket, actualBucket); Assert.AreEqual(fileName, actualPrefix); }
public async Task Storage_ReturnsStoredFile() { var clientMock = new Mock <IAmazonS3>(); Stream stream = null; clientMock .Setup(c => c.PutObjectAsync(It.IsAny <PutObjectRequest>(), It.IsAny <CancellationToken>())) .Callback <PutObjectRequest, CancellationToken>((req, _) => stream = req.InputStream) .Returns(Task.FromResult(new PutObjectResponse())); clientMock .Setup(c => c.GetObjectAsync(It.IsAny <GetObjectRequest>(), It.IsAny <CancellationToken>())) .Returns(() => Task.FromResult(new GetObjectResponse { ResponseStream = stream })); var storage = new S3FileStorage(clientMock.Object, "bucket1"); const string text = "fooBar\nbaz"; const string fileName = "myFile"; await storage.WriteAllTextAsync(fileName, text); var actualText = await storage.ReadAllTextAsync(fileName); Assert.AreEqual(text, actualText); }
public async Task RemoveTest() { S3FileStorage fileStorage = new S3FileStorage(options); string objectId = RandomExtensions.NextString(64); using (MemoryStream memoryStream = new MemoryStream(RandomExtensions.NextBytes(1024))) { await fileStorage.UploadAsync(memoryStream, objectId); } Assert.True(await fileStorage.RemoveAsync(objectId)); }
public async Task UploadTest() { try { string objectId = RandomExtensions.NextString(64); IFileStorage fileStorage = new S3FileStorage(options); using (MemoryStream memoryStream = new MemoryStream(RandomExtensions.NextBytes(1024))) { await fileStorage.UploadAsync(memoryStream, objectId); } } catch (Exception ex) { Console.WriteLine(ex); } }
public void Storage_MissingFile_ThrowsStorageFileNotFoundException() { var clientMock = new Mock <IAmazonS3>(); clientMock .Setup(c => c.GetObjectAsync(It.IsAny <GetObjectRequest>(), It.IsAny <CancellationToken>())) .Returns(Task.FromException <GetObjectResponse>( new AmazonS3Exception("bar", ErrorType.Sender, "NoSuchKey", "1", HttpStatusCode.NotFound))); var storage = new S3FileStorage(clientMock.Object, "bucket1"); var ex = Assert.ThrowsAsync <StorageFileNotFoundException>( async() => await storage.ReadAllTextAsync("foo")); Assert.IsInstanceOf <AmazonS3Exception>(ex.InnerException); Assert.AreEqual("bar", ex.InnerException.Message); }
static void Main(string[] args) { Parser.Default.ParseArguments <S3Options>(args).WithParsed(o => { UploadFileInfo uploadFileInfo = new UploadFileInfo(o.Path); IS3BucketClientFactory s3ClientFactory = new S3BucketClientFactory(); IFileStorage fileStorage = new S3FileStorage(s3ClientFactory, o); ComplexTest test = new ComplexTest(fileStorage, o.Bucket); test.ExpectFileToNotExist(o.Key); test.CanCreateFile(o.Key, uploadFileInfo); test.ExpectFileToExist(o.Key); test.CanReadFile(o.Key, uploadFileInfo); test.CanDeleteFile(o.Key); }); }
public async Task Storage_Delete_DelegatesToS3() { var clientMock = new Mock <IAmazonS3>(); string actualFileName = null; string actualBucket = null; clientMock .Setup(c => c.DeleteObjectAsync(It.IsAny <DeleteObjectRequest>(), It.IsAny <CancellationToken>())) .Callback <DeleteObjectRequest, CancellationToken>((req, _) => { actualFileName = req.Key; actualBucket = req.BucketName; }) .Returns(Task.FromResult(new DeleteObjectResponse())); const string bucket = "fooBucket"; const string fileName = "myFile"; var storage = new S3FileStorage(clientMock.Object, bucket); await storage.DeleteAsync(fileName); Assert.AreEqual(bucket, actualBucket); Assert.AreEqual(fileName, actualFileName); }
public async Task GetBuckets() { S3FileStorage fileStorage = new S3FileStorage(options); await fileStorage.GetBucketsList().ConfigureAwait(false); }