Esempio n. 1
0
        public static void DownloadAsync_String_String_DependencyThrowsException_DoesNotSwallow()
        {
            var mockSdk = MockSdk
                          .DownloadAsync()
                          .Throws(new InvalidOperationException());

            var storage = new AzureBlobDocumentRepository(mockSdk.BlobContainerClient, new AzureBlobStorageSettings());

            Assert.ThrowsAsync <InvalidOperationException>(() => storage.DownloadAsync("Id", "TheBlob"));
        }
Esempio n. 2
0
        public static async Task DownloadAsync_String_String_ReturnsBlobDownloadInfo()
        {
            const string expectedContentType = "test/content";

            await using var expectedStream = new MemoryStream();

            var mockSdk = MockSdk.DownloadAsync().Returns(expectedStream, expectedContentType);
            var storage = new AzureBlobDocumentRepository(mockSdk.BlobContainerClient, new AzureBlobStorageSettings());

            var result = await storage.DownloadAsync("Id", "TheBlob");

            result.Content.Should().BeSameAs(expectedStream);
            result.ContentType.Should().Be(expectedContentType);
        }
        public async Task DownloadAsync_String_ReturnsBlobDownloadInfo()
        {
            var azureBlobStorageSettings = new AzureBlobStorageSettings {
                DocumentDirectory = "non-solution"
            };
            const string expectedContentType = "test/content";

            using var expectedStream = new MemoryStream();
            var mockSdk = MockSdk.DownloadAsync().Returns(expectedStream, expectedContentType);
            var storage = new AzureBlobDocumentRepository(mockSdk.BlobContainerClient, azureBlobStorageSettings);

            var result = await storage.DownloadAsync("TheBlob");

            result.Content.Should().Be(expectedStream);
            result.ContentType.Should().Be(expectedContentType);
        }
        public void DownloadAsync_String_String_DependencyThrowsRequestFailedException_ThrowsDocumentRepositoryException()
        {
            const string message    = "This is a message.";
            const int    statusCode = 500;

            var mockSdk = MockSdk
                          .DownloadAsync()
                          .Throws(new RequestFailedException(statusCode, message));

            var storage = new AzureBlobDocumentRepository(mockSdk.BlobContainerClient, new AzureBlobStorageSettings());

            var ex = Assert.ThrowsAsync <DocumentRepositoryException>(
                () => storage.DownloadAsync("Id", "TheBlob"));

            ex.HttpStatusCode.Should().Be(statusCode);
            ex.Message.Should().Be(message);
        }