public void AddAnExistingResourceToAnExistingList() { using (TransactionScope ts = new TransactionScope()) { BlobShareDataStoreEntities context = BlobShareDataStoreEntities.CreateInstance(); BlobSet set = CreateBlobSetForTest("Test List", context); Blob blob = BlobServicesTests.CreateBlobForTest("Test Resource", context); BlobSetService service = new BlobSetService(context); service.AddBlobToSet(set.Name, blob.BlobId); BlobSet newSet = service.GetBlobSetById(set.BlobSetId); Assert.IsNotNull(newSet); Assert.AreEqual(1, newSet.Blobs.Count); BlobService bservices = new BlobService(context, CloudStorageAccount.DevelopmentStorageAccount, TestContainerName); Blob newResource = bservices.GetBlobById(blob.BlobId); Assert.IsNotNull(newResource); Assert.AreEqual(1, newResource.BlobSets.Count); Assert.AreEqual(newResource.BlobSets.First().BlobSetId, set.BlobSetId); Assert.AreEqual(newSet.Blobs.First().BlobId, blob.BlobId); } }
public void DeleteBlob() { using (TransactionScope ts = new TransactionScope()) { BlobShareDataStoreEntities context = BlobShareDataStoreEntities.CreateInstance(); Blob blob = CreateBlobForTest("Test Resource", context); BlobService service = new BlobService(context, CloudStorageAccount.DevelopmentStorageAccount, TestContainerName); service.DeleteBlobById(blob.BlobId); Assert.IsNull(service.GetBlobById(blob.BlobId)); } }
public void GetContentTypes() { BlobService service = new BlobService(CloudStorageAccount.DevelopmentStorageAccount, TestContainerName); Blob blob = new Blob(); blob.OriginalFileName = "image.jpg"; Assert.AreEqual("image/jpeg", service.GetContentType(blob)); blob.OriginalFileName = "image.gif"; Assert.AreEqual("image/gif", service.GetContentType(blob)); blob.OriginalFileName = "video.wmv"; Assert.AreEqual("video/x-ms-wmv", service.GetContentType(blob)); blob.OriginalFileName = "video.avi"; Assert.AreEqual("video/avi", service.GetContentType(blob)); blob.OriginalFileName = "sound.wav"; Assert.AreEqual("audio/wav", service.GetContentType(blob)); ////These two Asserts will fail if they are executed on a PC without office ////blob.OriginalFileName = "doc.docx"; ////Assert.AreEqual("application/vnd.openxmlformats-officedocument.wordprocessingml.document", service.GetContentType(blob)); ////blob.OriginalFileName = "plan.xlsx"; ////Assert.AreEqual("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", service.GetContentType(blob)); }
private void FileUploadFileUploadCompleted(object sender, FileUploadCompletedEventArgs e) { var dataStore = BlobShareDataStoreEntities.CreateInstance(); try { var blobService = new BlobService( dataStore, CloudStorageAccount.Parse(ConfigReader.GetConfigValue("DataConnectionString")), ConfigReader.GetConfigValue("MainBlobContanier")); try { if (!string.IsNullOrEmpty(e.FileName)) { e.DistributedUpload.Commit(); var resource = new Blob(); resource.BlobId = Guid.Parse(this.ctx.Request.QueryString["id"]); resource.Name = Path.GetFileNameWithoutExtension(e.FileName); resource.Description = string.Empty; resource.OriginalFileName = e.FileName; resource.UploadDateTime = DateTime.UtcNow; blobService.CreateBlob(resource); } } catch (Exception ex) { this.ctx.Response.StatusCode = (int)System.Net.HttpStatusCode.InternalServerError; this.ctx.Response.StatusDescription = ex.Message; return; } } finally { dataStore.Dispose(); } }
public void UpdateDescription() { using (TransactionScope ts = new TransactionScope()) { BlobShareDataStoreEntities context = BlobShareDataStoreEntities.CreateInstance(); Blob blob = CreateBlobForTest("Resource For Test", context); BlobService service = new BlobService(context, CloudStorageAccount.DevelopmentStorageAccount, TestContainerName); service.UpdateDescription(blob.BlobId, "New Name", "New Description"); Blob newResource = service.GetBlobById(blob.BlobId); Assert.IsNotNull(newResource); Assert.AreEqual(0, newResource.BlobSets.Count); Assert.AreEqual(blob.BlobId, newResource.BlobId); Assert.AreEqual("New Name", newResource.Name); Assert.AreEqual("New Description", newResource.Description); Assert.AreEqual(blob.OriginalFileName, newResource.OriginalFileName); Assert.AreEqual(blob.UploadDateTime.ToString(), newResource.UploadDateTime.ToString()); CloudBlob cloudBlob = service.GetBlob(newResource); cloudBlob.Delete(); } }
public void AddUserToBlob() { using (TransactionScope ts = new TransactionScope()) { BlobShareDataStoreEntities context = BlobShareDataStoreEntities.CreateInstance(); Blob blob = BlobServicesTests.CreateBlobForTest("Test Resource", context); User user = CreateUserForTest("testuser1", context); PermissionService service = new PermissionService(context); Permission permission = service.GrantPermissionToUserBlob(Privilege.Read, user, blob, DateTime.UtcNow.AddDays(1)); Assert.IsNotNull(permission); Assert.AreEqual(user, permission.Users.First()); Assert.AreEqual(blob, permission.Blob); Assert.AreEqual((int)Privilege.Read, permission.Privilege); IEnumerable<Blob> resources = service.GetBlobsByUser(user); Assert.IsNotNull(resources); Assert.AreEqual(1, resources.Count()); Assert.AreEqual(blob.BlobId, resources.First().BlobId); Assert.IsTrue(service.CheckPermissionToBlob(user.NameIdentifier, user.IdentityProvider, blob.BlobId)); BlobService blobService = new BlobService(context, CloudStorageAccount.DevelopmentStorageAccount, TestContainerName); CloudBlob cloudBlob = blobService.GetBlob(blob); cloudBlob.Delete(); } }
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(); } }
internal static Blob CreateBlobForTest(string name, BlobShareDataStoreEntities context) { BlobService service = new BlobService(context, CloudStorageAccount.DevelopmentStorageAccount, TestContainerName); Blob 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); stream.Close(); return blob; }