예제 #1
0
        public async Task GetRetrievesS3()
        {
            var mock = Substitute.For <IAmazonS3>();

            mock.DoesS3BucketExistAsync("xxx").Returns(true);

            var oms    = new MemoryStream();
            var writer = new StreamWriter(oms);

            var dictionary = new Dictionary <string, object> {
                { "test", "wibble" }
            };

            writer.Write(JsonConvert.SerializeObject(dictionary));
            writer.Flush();
            oms.Seek(0, SeekOrigin.Begin);

            mock
            .GetObjectAsync(string.Empty, string.Empty)
            .ReturnsForAnyArgs(c => new GetObjectResponse
            {
                HttpStatusCode = HttpStatusCode.OK,
                ResponseStream = oms
            });

            var request = DummyRequest();
            var s3      = new S3PersistenceStore("xxx", mock);
            var result  = await s3.Get <string>(request, "test");

            Assert.Equal("wibble", result);
        }
예제 #2
0
        public async Task InvalidBucketThrows()
        {
            var mock        = Substitute.For <IAmazonS3>();
            var bucketCheck = mock.DoesS3BucketExistAsync("xxx").Returns(false);

            var request = DummyRequest();
            var s3      = new S3PersistenceStore("xxx", mock);
            await Assert.ThrowsAsync <InvalidOperationException>(() => s3.Get <string>(request, "test"));
        }
예제 #3
0
        public async Task GetCheckS3CorrectKey()
        {
            var mock        = Substitute.For <IAmazonS3>();
            var bucketCheck = mock.DoesS3BucketExistAsync("xxx").Returns(true);

            var existenceCheck = mock
                                 .GetObjectAsync(string.Empty, string.Empty)
                                 .ReturnsForAnyArgs(c => new GetObjectResponse {
                HttpStatusCode = HttpStatusCode.NotFound
            });

            var request = DummyRequest();
            var s3      = new S3PersistenceStore("xxx", mock);
            var result  = await s3.Get <string>(request, "test");

            Assert.Null(result);

            await mock.Received(1).GetObjectAsync("xxx", "abc123");
        }
예제 #4
0
        public async Task SetPutsValueLocally()
        {
            var mock = Substitute.For <IAmazonS3>();

            mock.DoesS3BucketExistAsync("xxx").Returns(true);

            mock
            .GetObjectAsync(string.Empty, string.Empty)
            .ReturnsForAnyArgs(c => new GetObjectResponse {
                HttpStatusCode = HttpStatusCode.NotFound
            });

            var request = DummyRequest();
            var s3      = new S3PersistenceStore("xxx", mock);
            await s3.Set(request, "test", "wibble");

            var result = await s3.Get <string>(request, "test");

            Assert.Equal("wibble", result);
        }