public void AddUserToBlobSet()
        {
            using (TransactionScope ts = new TransactionScope())
            {
                BlobShareDataStoreEntities context    = BlobShareDataStoreEntities.CreateInstance();
                BlobSetService             setService = new BlobSetService(context);
                BlobSet set = new BlobSet()
                {
                    Name        = "Resource Set Test",
                    Description = "Resource Set Test"
                };
                setService.CreateBlobSet(set);

                User user = CreateUserForTest("testuser1", context);
                PermissionService service    = new PermissionService(context);
                Permission        permission = service.GrantPermissionToUserBlobSet(Privilege.Read, user, set, DateTime.UtcNow.AddDays(1));

                Assert.IsNotNull(permission);
                Assert.AreEqual(user, permission.Users.First());
                Assert.AreEqual(set, permission.BlobSet);
                Assert.AreEqual((int)Privilege.Read, permission.Privilege);

                IEnumerable <BlobSet> sets = service.GetBlobSetsByUser(user);

                Assert.IsNotNull(sets);
                Assert.AreEqual(1, sets.Count());
                Assert.AreEqual(set.BlobSetId, sets.First().BlobSetId);

                Assert.IsTrue(service.CheckPermissionToBlobSet(user.NameIdentifier, user.IdentityProvider, set.BlobSetId));
            }
        }
        public void AddRoleToBlobSet()
        {
            using (TransactionScope ts = new TransactionScope())
            {
                BlobShareDataStoreEntities context    = BlobShareDataStoreEntities.CreateInstance();
                BlobSetService             setService = new BlobSetService(context);
                BlobSet set = new BlobSet()
                {
                    Name        = "Resource Set Test",
                    Description = "Resource Set Test"
                };
                setService.CreateBlobSet(set);

                Role role = CreateRoleForTest("testrole1", context);
                PermissionService service    = new PermissionService(context);
                Permission        permission = service.GrantPermissionToRoleBlobSet(Privilege.Read, role, set, DateTime.UtcNow.AddDays(1));

                Assert.IsNotNull(permission);
                Assert.AreEqual(role, permission.Roles.First());
                Assert.AreEqual(set, permission.BlobSet);
                Assert.AreEqual((int)Privilege.Read, permission.Privilege);

                IEnumerable <BlobSet> sets = service.GetBlobSetsByRole(role);

                Assert.IsNotNull(sets);
                Assert.AreEqual(1, sets.Count());
                Assert.AreEqual(set.BlobSetId, sets.First().BlobSetId);
            }
        }
示例#3
0
        public void RemoveSet()
        {
            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.BlobSetId, blob.BlobId);
                BlobSet newList = service.GetBlobSetById(set.BlobSetId);

                Assert.IsNotNull(newList);
                Assert.AreEqual(1, newList.Blobs.Count);

                service.DeleteBlobSet(set.BlobSetId);

                BlobSet deletedList = service.GetBlobSetById(set.BlobSetId);

                Assert.IsNull(deletedList);

                BlobService bservices   = new BlobService(context, CloudStorageAccount.DevelopmentStorageAccount, TestContainerName);
                Blob        newResource = bservices.GetBlobById(blob.BlobId);

                Assert.IsNotNull(newResource);
                Assert.AreEqual(0, newResource.BlobSets.Count);
            }
        }
示例#4
0
        private static BlobSet CreateBlobSetForTest(string name, BlobShareDataStoreEntities context)
        {
            var     service = new BlobSetService(context);
            BlobSet entity  = new BlobSet()
            {
                Name = name
            };

            service.CreateBlobSet(entity);

            return(entity);
        }
示例#5
0
        public void UpdateExistingList()
        {
            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);

                set.Name        = "updated test list";
                set.Description = "updated test description";
                service.UpdateBlobSet(set);

                BlobSet newSet = service.GetBlobSetById(set.BlobSetId);

                Assert.IsNotNull(newSet);
                Assert.AreEqual(1, newSet.Blobs.Count);
                Assert.AreEqual(set.Name, newSet.Name);
                Assert.AreEqual(set.Description, newSet.Description);
            }
        }