예제 #1
0
 public async Task RetrieveContainerByName_NonExistingContainer()
 {
     var       data          = BlobServiceClientBuilder.GenerateSeedData();
     var       client        = BlobServiceClientBuilder.GetBlobServiceClientMock(data);
     var       containerName = "VeryFakeName";
     Exception ex            = await Assert.ThrowsAsync <ContainerNotFoundException>(
         async() => await client.GetContainerReferenceAsync(containerName));
 }
예제 #2
0
        public async Task ListContainers()
        {
            var data       = BlobServiceClientBuilder.GenerateSeedData();
            var client     = BlobServiceClientBuilder.GetBlobServiceClientMock(data);
            var containers = await client.ListContainersAsync();

            Assert.Equal(containers.Count(), data.Containers.Count);
        }
예제 #3
0
        public async Task RetrieveContainerByName()
        {
            var data          = BlobServiceClientBuilder.GenerateSeedData();
            var client        = BlobServiceClientBuilder.GetBlobServiceClientMock(data);
            var containerName = data.Containers[0].Name;
            var container     = await client.GetContainerReferenceAsync(containerName);

            Assert.Equal(container.Name, containerName);
        }
예제 #4
0
        public async Task CreateContainer()
        {
            var data          = BlobServiceClientBuilder.GenerateSeedData();
            var client        = BlobServiceClientBuilder.GetBlobServiceClientMock(data);
            var containerName = "NewContainer";

            BlobContainer newContainer = await client.CreateContainerAsync(containerName);

            Assert.NotEqual(newContainer.Id, string.Empty);
        }
        public async Task UpdateContainer()
        {
            var data   = BlobServiceClientBuilder.GenerateSeedData();
            var client = BlobServiceClientBuilder.GetBlobServiceClientMock(data);
            var targetContainerName = "TestCont#2";
            var container           = await client.GetContainerReferenceAsync(targetContainerName);

            await container.RenameAsync(targetContainerName + "_New");

            Assert.Equal(container.Name, targetContainerName + "_New");
        }
        public async Task ListBlobs()
        {
            var data   = BlobServiceClientBuilder.GenerateSeedData();
            var client = BlobServiceClientBuilder.GetBlobServiceClientMock(data);
            var targetContainerName = "TestCont#2";
            var container           = await client.GetContainerReferenceAsync(targetContainerName);

            var blobs = await container.ListBlobsAsync();

            Assert.Single(blobs);
        }
예제 #7
0
        public async Task GetBlobReferenceAsync()
        {
            var data          = BlobServiceClientBuilder.GenerateSeedData();
            var client        = BlobServiceClientBuilder.GetBlobServiceClientMock(data);
            var targetBlob    = data.Blobs.First();
            var blobId        = targetBlob.Id;
            var containerName = data.Containers.Where(c => c.Id == targetBlob.ContainerId).First().Name;
            var blob          = await client.GetBlobReferenceAsync(containerName, blobId);

            Assert.Equal(targetBlob.OrigFileName, blob.FileName);
        }
예제 #8
0
        public async Task CreateContainer_ShouldReturnArgumentExceptionAsync()
        {
            var    data          = BlobServiceClientBuilder.GenerateSeedData();
            var    client        = BlobServiceClientBuilder.GetBlobServiceClientMock(data);
            string containerName = string.Empty;

            BlobContainer newContainer = null;

            Exception ex = await Assert.ThrowsAsync <ArgumentException>(
                async() => newContainer = await client.CreateContainerAsync(containerName));
        }
        public async Task DeleteContainer()
        {
            var    data          = BlobServiceClientBuilder.GenerateSeedData();
            var    client        = BlobServiceClientBuilder.GetBlobServiceClientMock(data);
            string containerName = data.Containers[0].Name;

            BlobContainer container = await client.GetContainerReferenceAsync(containerName);

            await container.DeleteAsync();

            Assert.DoesNotContain(data.Containers, c => c.Name == container.Name);
        }
        public async Task UploadBlob()
        {
            var data   = BlobServiceClientBuilder.GenerateSeedData();
            var client = BlobServiceClientBuilder.GetBlobServiceClientMock(data);
            var targetContainerName = data.Containers.First().Name;
            var container           = await client.GetContainerReferenceAsync(targetContainerName);

            using (var test_Stream = new MemoryStream(Encoding.UTF8.GetBytes("whatever")))
            {
                var blob = await container.UploadBlobAsync(test_Stream, "IloveAramMCP.png");

                Assert.NotNull(blob);
            }
        }
예제 #11
0
        public async Task DeleteBlobAsync_ShouldSuccess()
        {
            var data   = BlobServiceClientBuilder.GenerateSeedData();
            var client = BlobServiceClientBuilder.GetBlobServiceClientMock(data);

            var targetBlob    = data.Blobs.First();
            var blobId        = targetBlob.Id;
            var containerName = data.Containers.Where(c => c.Id == targetBlob.ContainerId).First().Name;
            var blob          = await client.GetBlobReferenceAsync(containerName, blobId);

            await blob.DeleteAsync();

            Assert.DoesNotContain(data.Blobs, b => b.Id == blobId);
        }
        public async Task DeleteContainer_ShouldReturnServerError()
        {
            var data           = BlobServiceClientBuilder.GenerateSeedData();
            var apiMockOptiosn = new ApiMockOptions()
            {
                ThrowInternalServerError = true
            };

            var client = BlobServiceClientBuilder.GetBlobServiceClientMock(data, apiMockOptiosn);

            string containerName = data.Containers[data.Containers.Count - 1].Name;

            BlobContainer container = await client.GetContainerReferenceAsync(containerName);

            Exception ex = await Assert.ThrowsAsync <BlobServiceException>(
                async() => await container.DeleteAsync());
        }
예제 #13
0
        public async Task ReadBlob_ShouldSuccess()
        {
            var data   = BlobServiceClientBuilder.GenerateSeedData();
            var client = BlobServiceClientBuilder.GetBlobServiceClientMock(data);

            var targetBlob    = data.Blobs.First();
            var blobId        = targetBlob.Id;
            var containerName = data.Containers.Where(c => c.Id == targetBlob.ContainerId).First().Name;
            var blob          = await client.GetBlobReferenceAsync(containerName, blobId);

            using (var rawBlob = await blob.OpenReadAsync())
            {
                using (var test_Stream = new MemoryStream(Encoding.UTF8.GetBytes("whatever")))
                {
                    Assert.Equal(test_Stream.Length, rawBlob.Length);
                }
            }
        }
예제 #14
0
        public async Task DownloadToStreamAsync_ShouldSuccess()
        {
            var data   = BlobServiceClientBuilder.GenerateSeedData();
            var client = BlobServiceClientBuilder.GetBlobServiceClientMock(data);

            var targetBlob    = data.Blobs.First();
            var blobId        = targetBlob.Id;
            var containerName = data.Containers.Where(c => c.Id == targetBlob.ContainerId).First().Name;
            var blob          = await client.GetBlobReferenceAsync(containerName, blobId);

            var blobOriginalStream = await blob.OpenReadAsync();

            var targetStream = new MemoryStream();

            await blob.DownloadToStreamAsync(targetStream);

            targetStream.Position       = 0;
            blobOriginalStream.Position = 0;
            Assert.True(TestHelper.FileStreamEquals(targetStream, blobOriginalStream));
        }
예제 #15
0
        public async Task UpdateBlobData_ShouldSuccess()
        {
            var data   = BlobServiceClientBuilder.GenerateSeedData();
            var client = BlobServiceClientBuilder.GetBlobServiceClientMock(data);

            var targetBlob    = data.Blobs.First();
            var blobId        = targetBlob.Id;
            var containerName = data.Containers.Where(c => c.Id == targetBlob.ContainerId).First().Name;
            var blob          = await client.GetBlobReferenceAsync(containerName, blobId);

            using (var newStream = new MemoryStream(Encoding.UTF8.GetBytes("whatever+whatever=love")))
            {
                var newFilename    = "newFile.png";
                var newContentType = MIMETypeMapper.GetMimeMapping(newFilename);
                await blob.UpdateBlobAsync(newStream, newFilename, newContentType);

                Assert.Equal(blob.SizeInBytes, newStream.Length);
                Assert.Equal(blob.MimeType, newContentType);
                Assert.Equal(blob.FileName, newFilename);
            }
        }