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);
            }
        }
        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();
            }
        }
Beispiel #4
0
        public void GetBlobSetEventsByBlobSet()
        {
            using (TransactionScope ts = new TransactionScope())
            {
                var context      = BlobShareDataStoreEntities.CreateInstance();
                var eventService = new EventService(context);
                var user         = this.GetTestUser(context);
                var blobSet      = this.GetTestBlobSet(context);

                eventService.CreateEventUserViewBlobSet(user.NameIdentifier, user.IdentityProvider, blobSet);

                var reportService = new ReportService(context);
                int totalPages;

                var events = reportService.GetBlobSetEventsByBlobSet(
                    DateTime.UtcNow.AddSeconds(-5),
                    DateTime.UtcNow.AddSeconds(1),
                    EventType.View,
                    blobSet.BlobSetId,
                    100,
                    1,
                    out totalPages);

                Assert.AreEqual(1, totalPages);
                Assert.AreEqual(1, events.Count());
                var e = events.First();
                Assert.AreEqual(blobSet.BlobSetId, e.BlobSet.BlobSetId);
                Assert.AreEqual(blobSet.Name, e.BlobSet.Name);
                Assert.AreEqual((int)EventType.View, e.EventType);
                Assert.AreEqual(user.UserId, e.User.UserId);
            }
        }
Beispiel #5
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);
            }
        }
        public void RetrieveBlobs()
        {
            BlobShareDataStoreEntities context = BlobShareDataStoreEntities.CreateInstance();

            foreach (var item in context.Blobs)
            {
                Assert.IsNotNull(item);
            }
        }
Beispiel #7
0
        private BlobSet GetTestBlobSet(BlobShareDataStoreEntities context)
        {
            BlobSet set = new BlobSet()
            {
                BlobSetId = Guid.NewGuid(),
                Name      = "Test Resource Set"
            };

            context.BlobSets.AddObject(set);

            return(set);
        }
Beispiel #8
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);
        }
Beispiel #9
0
 public void CreateEventUserLogin()
 {
     using (TransactionScope ts = new TransactionScope())
     {
         BlobShareDataStoreEntities context = BlobShareDataStoreEntities.CreateInstance();
         EventService service = new EventService(context);
         User         user    = this.GetTestUser(context);
         service.CreateEventUserLogin(user);
         Assert.AreEqual(2, user.UserEvents.Count);
         Assert.AreEqual((int)UserEventType.Login, user.UserEvents.Skip(1).First().EventType);
     }
 }
Beispiel #10
0
 public void CreateEventUserDownloadBlob()
 {
     using (TransactionScope ts = new TransactionScope())
     {
         BlobShareDataStoreEntities context = BlobShareDataStoreEntities.CreateInstance();
         EventService service = new EventService(context);
         User         user    = this.GetTestUser(context);
         Blob         blob    = this.GetTestBlob(context);
         service.CreateEventUserDownloadBlob(user.NameIdentifier, user.IdentityProvider, blob);
         Assert.AreEqual(1, user.BlobEvents.Count);
         Assert.AreEqual((int)EventType.Download, user.BlobEvents.First().EventType);
     }
 }
        internal static Role CreateRoleForTest(string name, BlobShareDataStoreEntities context)
        {
            Role role = new Role()
            {
                RoleName    = name,
                Description = name
            };

            context.Roles.AddObject(role);
            context.SaveChanges();

            return(role);
        }
Beispiel #12
0
        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));
            }
        }
Beispiel #13
0
 public InvitationService(BlobShareDataStoreEntities context)
     : this(
         context,
         new PermissionService(context),
         new SmtpNotificationService(
             ConfigReader.GetConfigValue("SmtpHost"),
             int.Parse(ConfigReader.GetConfigValue("SmtpPort"), CultureInfo.InvariantCulture),
             ConfigReader.GetConfigValue("SmtpUser"),
             ConfigReader.GetConfigValue("SmtpPassword"),
             ConfigReader.GetConfigValue("SmtpSenderName"),
             ConfigReader.GetConfigValue("SmtpSenderAddress")))
 {
 }
Beispiel #14
0
        private User GetTestUser(BlobShareDataStoreEntities context)
        {
            UserService userService = new UserService(context);
            User        user        = new User()
            {
                Name             = "Test User",
                Email            = "*****@*****.**",
                IdentityProvider = "identityProvider",
                NameIdentifier   = "nameIdentifier"
            };

            userService.CreateUser(user);
            return(user);
        }
Beispiel #15
0
        private Blob GetTestBlob(BlobShareDataStoreEntities context)
        {
            Blob blob = new Blob()
            {
                BlobId           = Guid.NewGuid(),
                Name             = "Test Blob Resource",
                OriginalFileName = "originalfile.txt",
                UploadDateTime   = DateTime.UtcNow
            };

            context.Blobs.AddObject(blob);

            return(blob);
        }
        internal static User CreateUserForTest(string name, BlobShareDataStoreEntities context)
        {
            User user = new User()
            {
                UserId           = Guid.NewGuid(),
                Name             = name,
                Email            = name,
                NameIdentifier   = name,
                IdentityProvider = name,
            };

            context.Users.AddObject(user);
            context.SaveChanges();

            return(user);
        }
        public void InviteUser()
        {
            using (TransactionScope ts = new TransactionScope())
            {
                BlobShareDataStoreEntities context = BlobShareDataStoreEntities.CreateInstance();
                InvitationService          service = new InvitationService(context);
                User user = this.GetTestUser(context);
                var  link = "http://test/";

                var invitation = service.InviteUser(user, link, DateTime.UtcNow.AddDays(5), "Test invitation", false);

                Assert.IsNotNull(invitation);
                Assert.AreEqual(user.Email, invitation.Email);
                Assert.AreEqual(user, invitation.User);
            }
        }
Beispiel #18
0
        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);
        }
Beispiel #19
0
        public void GetTopItemsByUser()
        {
            using (TransactionScope ts = new TransactionScope())
            {
                var context      = BlobShareDataStoreEntities.CreateInstance();
                var eventService = new EventService(context);
                var user         = this.GetTestUser(context);
                var blob         = this.GetTestBlob(context);

                eventService.CreateEventUserViewBlob(user.NameIdentifier, user.IdentityProvider, blob);

                var reportService = new ReportService(context);
                var events        = reportService.GetTopItemsByUser(user, 3);

                Assert.AreEqual(1, events.Count());
                var e = events.First();
                Assert.AreEqual(1, e.Total);
                Assert.IsFalse(e.IsBlobSet);
                Assert.AreEqual(blob.Name, e.Name);
            }
        }
        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();
            }
        }
Beispiel #21
0
        public void GetUserEventsByUser()
        {
            using (TransactionScope ts = new TransactionScope())
            {
                var context      = BlobShareDataStoreEntities.CreateInstance();
                var eventService = new EventService(context);
                var user         = this.GetTestUser(context);
                var blob         = this.GetTestBlob(context);

                eventService.CreateEventUserViewBlob(user.NameIdentifier, user.IdentityProvider, blob);

                var reportService = new ReportService(context);
                int totalPages;
                var events = reportService.GetUserEventsByUser(
                    DateTime.UtcNow.AddSeconds(-5),
                    DateTime.UtcNow.AddSeconds(1),
                    new List <int> {
                    (int)EventType.View
                },                                         // userEventTypes
                    new List <int> {
                    (int)EventType.View
                },                                         // setEventTypes
                    new List <int> {
                    (int)EventType.View
                },                                         // resourceEventTypes
                    user.UserId,
                    100,
                    1,
                    out totalPages);

                Assert.AreEqual(1, totalPages);
                Assert.AreEqual(2, events.Count());
                var ev = events.First(e => !e.IsUserEvent);
                Assert.AreEqual(blob.BlobId, ev.Blob.BlobId);
                Assert.AreEqual(blob.Name, ev.Blob.Name);
                Assert.AreEqual((int)EventType.View, ev.EventType);
                Assert.AreEqual(user.UserId, ev.User.UserId);
            }
        }
Beispiel #22
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);
            }
        }
        public void AddRoleToBlob()
        {
            using (TransactionScope ts = new TransactionScope())
            {
                BlobShareDataStoreEntities context = BlobShareDataStoreEntities.CreateInstance();
                Blob blob = BlobServicesTests.CreateBlobForTest("Test Resource", context);

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

                Assert.IsNotNull(permission);
                Assert.AreEqual(role, permission.Roles.First());
                Assert.AreEqual(blob, permission.Blob);
                Assert.AreEqual((int)Privilege.Read, permission.Privilege);

                IEnumerable <Blob> resources = service.GetBlobsByRole(role);

                Assert.IsNotNull(resources);
                Assert.AreEqual(1, resources.Count());
                Assert.AreEqual(blob.BlobId, resources.First().BlobId);
            }
        }
Beispiel #24
0
        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();
            }
        }
Beispiel #25
0
 public ControllerBase()
 {
     this.Context = BlobShareDataStoreEntities.CreateInstance();
 }
Beispiel #26
0
 public InvitationService(BlobShareDataStoreEntities context, IPermissionService permissionService, INotificationService notificationService)
 {
     this.context             = context;
     this.permissionService   = permissionService;
     this.notificationService = notificationService;
 }
Beispiel #27
0
 public InvitationService()
     : this(BlobShareDataStoreEntities.CreateInstance())
 {
 }
Beispiel #28
0
 public EventService(BlobShareDataStoreEntities context, IUserService userService)
 {
     this.context     = context;
     this.userService = userService;
 }
Beispiel #29
0
 public EventService(BlobShareDataStoreEntities context)
     : this(context, new UserService(context))
 {
 }
Beispiel #30
0
 public EventService()
     : this(BlobShareDataStoreEntities.CreateInstance())
 {
 }