예제 #1
0
        public void DeleteAsync_NullUri()
        {
            var storage = new AzureBlobStorage(Configuration);

            storage
            .Awaiting(s => s.DeleteAsync(null))
            .Should().Throw <ArgumentNullException>();
        }
예제 #2
0
        public void PutAsync_NullStream()
        {
            var storage = new AzureBlobStorage(Configuration);

            storage
            .Awaiting(s => s.PutAsync(null, ".dat"))
            .Should().Throw <ArgumentNullException>();
        }
예제 #3
0
        public void DeleteAsync_NotMyUri()
        {
            var storage = new AzureBlobStorage(Configuration);
            var uri     = new Uri("some://other/base/file.txt");

            storage
            .Awaiting(s => s.DeleteAsync(uri))
            .Should().Throw <ArgumentException>();
        }
예제 #4
0
        public void DeleteAsync_RelativeUri()
        {
            var storage = new AzureBlobStorage(Configuration);
            var uri     = new Uri("relative/file.txt", UriKind.Relative);

            storage
            .Awaiting(s => s.DeleteAsync(uri))
            .Should().Throw <ArgumentException>();
        }
예제 #5
0
        public async Task DeleteAsync_DoesNotExist()
        {
            var storage = new AzureBlobStorage(Configuration);
            var uri     = new Uri(storage.BaseUri, "a/b/file.txt");

            var result = await storage.DeleteAsync(uri);

            result.Should().BeFalse();
        }
예제 #6
0
        public void PutAsync_UnreadableStream()
        {
            var storage = new AzureBlobStorage(Configuration);
            var stream  = Mock.Of <Stream>(s => s.CanRead == false);

            storage
            .Awaiting(s => s.PutAsync(stream, ".dat"))
            .Should().Throw <ArgumentException>();
        }
예제 #7
0
        public void GetAsync_NotFound()
        {
            var storage = new AzureBlobStorage(Configuration);
            var uri     = new Uri(storage.BaseUri, "does/not/exist.txt");

            async Task <string> GetAsync()
            => await ReadUtf8Async(await storage.GetAsync(uri));

            Awaiting(GetAsync).Should()
            .Throw <RequestFailedException>()
            .Which.Status.Should().Be(404);
        }
예제 #8
0
        public async Task GetAsync()
        {
            var storage = new AzureBlobStorage(Configuration);
            var uri     = new Uri(storage.BaseUri, "a/file.txt");

            await WriteBlobAsync("a/file.txt");

            using var stream = await storage.GetAsync(uri);

            var text = await ReadUtf8Async(stream);

            text.Should().Be(TestText);
        }
예제 #9
0
        public async Task DeleteAsync_Exists()
        {
            var storage = new AzureBlobStorage(Configuration);
            var uri     = new Uri(storage.BaseUri, "a/b/file.txt");

            await WriteBlobAsync("a/b/file.txt");
            await WriteBlobAsync("a/other.txt");

            (await BlobExistsAsync("a/b/file.txt"))
            .Should().BeTrue("blob should exist prior to deletion");

            var result = await storage.DeleteAsync(uri);

            result.Should().BeTrue();

            (await BlobExistsAsync("a/b/file.txt"))
            .Should().BeFalse("blob should have been deleted");

            (await BlobExistsAsync("a/other.txt"))
            .Should().BeTrue("other blob should NOT have been deleted");
        }
예제 #10
0
        public async Task PutAsync(string extension)
        {
            var storage = new AzureBlobStorage(Configuration);

            Uri uri;

            using (var stream = new MemoryStream(TestBytes))
                uri = await storage.PutAsync(stream, extension);

            uri.Should().NotBeNull();
            uri.Should().Match <Uri>(u => storage.BaseUri.IsBaseOf(u));

            uri.AbsolutePath.Should().MatchRegex(
                @"^/[0-9]{4}/[0-9]{4}/[0-9]{8}_[0-9]{6}_[0-9a-fA-F]{8}\.txt$"
                );

            var name = GetBlobName(uri, storage);
            var text = await ReadBlobAsync(name);

            text.Should().Be(TestText);
        }
예제 #11
0
 private static string GetBlobName(Uri uri, AzureBlobStorage storage)
 {
     return(uri.ToRelative(storage.BaseUri).ToString());
 }