Example #1
0
        public void UploadBlobFromStream_ForFileUploaded_ReturnsTrus()
        {
            // Create a local file in the ./data/ directory for uploading and downloading
            string _containerName = "testcontainer" + Guid.NewGuid().ToString().ToLower();
            string _localPath     = "../../../data/";
            string _blobName      = "testblob" + Guid.NewGuid().ToString() + ".txt";
            string _localFilePath = Path.Combine(_localPath, _blobName);

            // Write text to the file
            File.WriteAllTextAsync(_localFilePath, "Hello, World!").Wait();
            //Create a container
            var containerClient = Client().GetContainerReference(_containerName);

            containerClient.CreateIfNotExistsAsync().Wait();
            // Get a reference to a blob
            CloudBlockBlob blob = containerClient.GetBlockBlobReference(_blobName);

            // Open the file and upload its data
            using FileStream _uploadFileStream = File.OpenRead(_localFilePath);
            BlobService.Connect(_conString).Container(_containerName).UploadBlob(_blobName).FromStream(_uploadFileStream);
            _uploadFileStream.Close();

            var _blobExists = containerClient.GetBlockBlobReference(_blobName).Exists();

            Assert.True(_blobExists);
        }
        public void DeleteContainer_ForContainerDeleted_ReturnsTrue()
        {
            string _containerName = "todelete";

            Client().GetContainerReference(_containerName).Create();
            BlobService.Connect(_conString).Container(_containerName).DeleteContainer(true);
            var _containerExists = Client().GetContainerReference(_containerName).Exists();

            Assert.False(_containerExists);
        }
        public void CreateContainer_ForContainerCreated_ReturnsTrue()
        {
            string _containerName = "hello";

            BlobService.Connect(_conString).Container(_containerName).CreateContainer();

            var _containerExists = Client().GetContainerReference(_containerName).Exists();

            Assert.True(_containerExists);

            //Clean up
            Client().GetContainerReference(_containerName).DeleteIfExists();
        }
        public void GetAllContainers_ForAllContainers_ReturnsCount()
        {
            this._fixture.ClearStorage();
            string _containerName  = "container";
            int    _noofContainers = 5;

            for (int i = 0; i < _noofContainers; i++)
            {
                Client().GetContainerReference(_containerName + "-" + i).Create();
            }
            var _result = BlobService.Connect(_conString).GetAllContainers().ToList().Count;

            Assert.Equal(_noofContainers, _result);
        }
Example #5
0
        public void GetSharedUri_ForABlob_ReturnsTrue()
        {
            string _containerName = "testcontainer" + Guid.NewGuid().ToString().ToLower();
            string _blobName      = "testfile" + Guid.NewGuid().ToString() + ".txt";;
            var    container      = Client().GetContainerReference(_containerName);

            container.CreateIfNotExistsAsync().Wait();
            CloudBlockBlob blob = container.GetBlockBlobReference(_blobName);

            blob.UploadTextAsync("Hello, World downloaded test file!").Wait();

            var _sharedAccessUri = BlobService.Connect(_conString).Container(_containerName).GetSharedUri("abc.txt", 10);

            Assert.NotNull(_sharedAccessUri);
        }
Example #6
0
        public void DeleteBlob_ForBlobDeleted_ReturnsTure()
        {
            string _containerName = "testcontainer" + Guid.NewGuid().ToString().ToLower();
            string _blobName      = "testfile" + Guid.NewGuid().ToString() + ".txt";;
            var    container      = Client().GetContainerReference(_containerName);

            container.CreateIfNotExistsAsync().Wait();
            CloudBlockBlob blob = container.GetBlockBlobReference(_blobName);

            blob.UploadTextAsync("Hello, World 2!").Wait();

            BlobService.Connect(_conString).Container(_containerName).DeleteBlob(_blobName);

            var _blobExists = container.GetBlockBlobReference(_blobName).Exists();

            Assert.False(_blobExists);
        }
Example #7
0
        public void GetAllBlobItems_ForAllBlobs_ReturnsCount()
        {
            //Create no of blobs
            int    _noOfBlobsToCreate = 7;
            string _containerName     = "testcontainer" + Guid.NewGuid().ToString().ToLower();
            string _blobName          = "testfile" + Guid.NewGuid().ToString() + ".txt";
            var    container          = Client().GetContainerReference(_containerName);

            container.CreateIfNotExistsAsync().Wait();
            for (int i = 0; i < _noOfBlobsToCreate; i++)
            {
                CloudBlockBlob blob = container.GetBlockBlobReference("testfile_" + i + Guid.NewGuid().ToString() + ".txt");
                blob.UploadTextAsync("blob").Wait();
            }
            //Read No of Blob Items
            var _result = BlobService.Connect(_conString).Container(_containerName).GetAllBlobItems();

            Assert.Equal(_noOfBlobsToCreate, _result.ToList().Count());
        }
Example #8
0
        public void DownloadBlobToStream_ForBlobDownloaded_ReturnsTrue()
        {
            string _containerName = "testcontainer" + Guid.NewGuid().ToString().ToLower();
            string _blobName      = "testfile" + Guid.NewGuid().ToString() + ".txt";;
            var    container      = Client().GetContainerReference(_containerName);

            container.CreateIfNotExistsAsync().Wait();
            CloudBlockBlob blob = container.GetBlockBlobReference(_blobName);

            blob.UploadTextAsync("Hello, World downloaded test file!").Wait();

            //Prepare File

            string _localPath = "../../../data/";

            string _localFilePath = Path.Combine(_localPath, _blobName);

            using FileStream _filestream = File.OpenWrite(_localFilePath);
            BlobService.Connect(_conString).Container(_containerName).DownloadBlob(_blobName).ToStream(_filestream);

            Assert.True(File.Exists(_localFilePath));
        }