Exemplo n.º 1
0
        public void UploadBlob()
        {
            using (TransactionScope ts = new TransactionScope())
            {
                var service = new BlobService(CloudStorageAccount.DevelopmentStorageAccount, TestContainerName);

                var blob = new Blob()
                {
                    Name = "Test Resource",
                    OriginalFileName = "logo-dpe.png",
                    Description = "Test Resource",
                    UploadDateTime = DateTime.Now
                };

                Stream stream = new FileStream("logo-dpe.png", FileMode.Open, FileAccess.Read);

                service.UploadBlob(blob, stream);

                Assert.IsNotNull(blob.BlobId);
                Assert.AreNotEqual(Guid.Empty, blob.BlobId);

                Blob newBlob = service.GetBlobById(blob.BlobId);

                Assert.IsNotNull(newBlob);
                Assert.AreEqual(blob.BlobId, newBlob.BlobId);
                Assert.AreEqual(blob.Description, newBlob.Description);
                Assert.AreEqual(blob.OriginalFileName, newBlob.OriginalFileName);
                Assert.AreEqual(blob.UploadDateTime.ToString(), newBlob.UploadDateTime.ToString());

                var resources = service.GetBlobs();

                Assert.IsNotNull(resources);
                Assert.IsTrue(resources.Count() >= 1);
                Assert.IsNotNull(resources.Where(r => r.BlobId == newBlob.BlobId).FirstOrDefault());

                CloudBlob cloudBlob = service.GetBlob(newBlob);
                cloudBlob.Delete();
            }
        }