Ejemplo n.º 1
0
        public async Task SavePushesToS3()
        {
            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");

            mock.When(a => a.PutObjectAsync(Arg.Any <PutObjectRequest>())).Do(call =>
            {
                var put = call.Arg <PutObjectRequest>();
                Assert.Equal("xxx", put.BucketName);
                Assert.Equal("abc123", put.Key);
                Assert.NotNull(put.InputStream);
                using (var reader = new StreamReader(put.InputStream))
                {
                    var content = reader.ReadToEnd();
                    var data    = JsonConvert.DeserializeObject <JObject>(content);
                    Assert.Equal("wibble", data.Value <string>("test"));
                }
            });

            await s3.Save(request);
        }
Ejemplo n.º 2
0
        public async Task SetTwiceDoesSingleCheck()
        {
            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");

            await s3.Set(request, "test2", "wibble2");

            await mock.Received(1).DoesS3BucketExistAsync("xxx");

            await mock.Received(1).GetObjectAsync("xxx", "abc123");
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        public async Task RemoveWorksWithNoKeys()
        {
            var mock = Substitute.For <IAmazonS3>();

            mock.DoesS3BucketExistAsync("xxx").Returns(true);
            mock
            .GetObjectAsync(string.Empty, string.Empty)
            .ReturnsForAnyArgs(c => new GetObjectResponse {
                HttpStatusCode = HttpStatusCode.NotFound
            });

            var store = new S3PersistenceStore("xxx", mock);
            await store.Set(DummyRequest(), "test", "value");

            var result1 = store.Remove(DummyRequest());
            var result2 = store.Remove(DummyRequest());

            Assert.True(result1);
            Assert.True(result2);
        }