Beispiel #1
0
        public async Task WhenGettingBucketListings_ShouldReturnFileResults(
            [Frozen] Mock <IAmazonS3> client,
            S3StorageManager sut)
        {
            client.Setup(r => r.ListObjectsAsync(It.IsAny <ListObjectsRequest>(), CancellationToken.None))
            .ReturnsAsync(new ListObjectsResponse()
            {
                S3Objects = new List <S3Object>()
                {
                    new S3Object()
                    {
                        BucketName = "TestBucket",
                        Key        = "TestFile"
                    }
                }
            });

            var result = await sut.ListFilesAsync();

            result.ShouldSatisfyAllConditions(() =>
            {
                result.ShouldBeOfType <List <string> >();
                result.Count().ShouldBe(1);
                result.First().ShouldBe("TestFile");
            });
        }
Beispiel #2
0
        internal void DeleteFromStorageTest([Frozen] string bucketName)
        {
            IStorageReference reference = Substitute.For <IStorageReference>();
            var amazonS3 = Substitute.For <IAmazonS3>();
            var deleted  = false;

            amazonS3.When(x => x.DeleteObjectAsync(Arg.Any <DeleteObjectRequest>())).Do(x => { deleted = true; });

            var storageManager = new S3StorageManager(bucketName, amazonS3);

            storageManager.DeleteData(reference);

            Assert.True(deleted);
        }
Beispiel #3
0
        public async Task WhenReadingAnAsyncFile_ShouldReturnStream(
            [Frozen] Mock <IAmazonS3> client,
            S3StorageManager sut)
        {
            client.Setup(r => r.GetObjectAsync(It.IsAny <GetObjectRequest>(), It.IsAny <CancellationToken>())).ReturnsAsync(new GetObjectResponse()
            {
                BucketName     = "Test",
                ResponseStream = new MemoryStream(Encoding.UTF8.GetBytes("I AM A TEST!"))
            });

            var result = await sut.ReadAsync("foo");

            result.ShouldSatisfyAllConditions(() =>
            {
                result.ShouldBeOfType <MemoryStream>();
                result.Length.ShouldBeGreaterThan(0);
                result.ConvertToString().ShouldBe("I AM A TEST!");
            });
        }
Beispiel #4
0
        internal void PutDataToStorageTest([Frozen] string key, [Frozen] string data, [Frozen] string bucketName)
        {
            if (bucketName == null)
            {
                //throw new ArgumentNullException(nameof(bucketName));
            }

            var storeRef = Substitute.For <IStorageReference>();

            storeRef.GetStorageKey().ReturnsForAnyArgs(key);

            var amazon = Substitute.For <IAmazonS3>();

            var storageManager = new S3StorageManager("bucket", amazon);

            var reference = storageManager.PutData(data);

            amazon.Received().PutObjectAsync(Arg.Is <PutObjectRequest>(r => r.ContentBody == data));
        }
Beispiel #5
0
 public async Task WhenWritingAnAsyncFile_ShouldSucceed(
     FileMetaData fileInfo,
     S3StorageManager sut)
 {
     Should.NotThrow(async() => { await sut.WriteAsync(fileInfo); });
 }