Exemplo n.º 1
0
        public void CreateNotification()
        {
            IScopeProvider provider = ScopeProvider;

            using (IScope scope = provider.CreateScope())
            {
                var repo = new NotificationsRepository((IScopeAccessor)provider);

                var node = new NodeDto // create bogus item so we can add a notification
                {
                    CreateDate     = DateTime.Now,
                    Level          = 1,
                    NodeObjectType = Constants.ObjectTypes.ContentItem,
                    ParentId       = -1,
                    Path           = "-1,123",
                    SortOrder      = 1,
                    Text           = "hello",
                    Trashed        = false,
                    UniqueId       = Guid.NewGuid(),
                    UserId         = Constants.Security.SuperUserId
                };
                object  result = ScopeAccessor.AmbientScope.Database.Insert(node);
                IEntity entity = Mock.Of <IEntity>(e => e.Id == node.NodeId);
                IUser   user   = Mock.Of <IUser>(e => e.Id == node.UserId);

                Notification notification = repo.CreateNotification(user, entity, "A");

                Assert.AreEqual("A", notification.Action);
                Assert.AreEqual(node.NodeId, notification.EntityId);
                Assert.AreEqual(node.NodeObjectType, notification.EntityType);
                Assert.AreEqual(node.UserId, notification.UserId);
            }
        }
Exemplo n.º 2
0
        public void GetEntityNotifications()
        {
            IScopeProvider provider = ScopeProvider;

            using (IScope scope = provider.CreateScope())
            {
                var repo = new NotificationsRepository((IScopeAccessor)provider);

                var node1 = new NodeDto {
                    CreateDate = DateTime.Now, Level = 1, NodeObjectType = Constants.ObjectTypes.ContentItem, ParentId = -1, Path = "-1,1", SortOrder = 1, Text = "hello1", Trashed = false, UniqueId = Guid.NewGuid(), UserId = -1
                };
                ScopeAccessor.AmbientScope.Database.Insert(node1);
                IEntity entity1 = Mock.Of <IEntity>(e => e.Id == node1.NodeId);
                var     node2   = new NodeDto {
                    CreateDate = DateTime.Now, Level = 1, NodeObjectType = Constants.ObjectTypes.ContentItem, ParentId = -1, Path = "-1,2", SortOrder = 1, Text = "hello2", Trashed = false, UniqueId = Guid.NewGuid(), UserId = -1
                };
                ScopeAccessor.AmbientScope.Database.Insert(node2);
                IEntity entity2 = Mock.Of <IEntity>(e => e.Id == node2.NodeId);

                for (int i = 0; i < 10; i++)
                {
                    var userDto = new UserDto {
                        Email = "test" + i, Login = "******" + i, Password = "******", UserName = "******" + i, UserLanguage = "en", CreateDate = DateTime.Now, UpdateDate = DateTime.Now
                    };
                    ScopeAccessor.AmbientScope.Database.Insert(userDto);
                    IUser        userNew      = Mock.Of <IUser>(e => e.Id == userDto.Id);
                    Notification notification = repo.CreateNotification(userNew, (i % 2 == 0) ? entity1 : entity2, i.ToString(CultureInfo.InvariantCulture));
                }

                IEnumerable <Notification> notifications = repo.GetEntityNotifications(entity1);

                Assert.AreEqual(5, notifications.Count());
            }
        }
Exemplo n.º 3
0
        public void Delete_By_User()
        {
            IScopeProvider provider = ScopeProvider;

            using (IScope scope = provider.CreateScope())
            {
                var repo = new NotificationsRepository((IScopeAccessor)provider);

                var userDto = new UserDto {
                    Email = "test", Login = "******", Password = "******", UserName = "******", UserLanguage = "en", CreateDate = DateTime.Now, UpdateDate = DateTime.Now
                };
                ScopeAccessor.AmbientScope.Database.Insert(userDto);

                IUser userNew   = Mock.Of <IUser>(e => e.Id == userDto.Id);
                IUser userAdmin = Mock.Of <IUser>(e => e.Id == Constants.Security.SuperUserId);

                for (int i = 0; i < 10; i++)
                {
                    var node = new NodeDto {
                        CreateDate = DateTime.Now, Level = 1, NodeObjectType = Constants.ObjectTypes.ContentItem, ParentId = -1, Path = "-1," + i, SortOrder = 1, Text = "hello" + i, Trashed = false, UniqueId = Guid.NewGuid(), UserId = -1
                    };
                    object       result       = ScopeAccessor.AmbientScope.Database.Insert(node);
                    IEntity      entity       = Mock.Of <IEntity>(e => e.Id == node.NodeId);
                    Notification notification = repo.CreateNotification((i % 2 == 0) ? userAdmin : userNew, entity, i.ToString(CultureInfo.InvariantCulture));
                }

                int delCount = repo.DeleteNotifications(userAdmin);

                Assert.AreEqual(5, delCount);
            }
        }
        public void GetEntityNotifications()
        {
            var provider   = new PetaPocoUnitOfWorkProvider(Logger);
            var unitOfWork = provider.GetUnitOfWork();

            using (var repo = new NotificationsRepository(unitOfWork))
            {
                var node1 = new NodeDto {
                    CreateDate = DateTime.Now, Level = 1, NodeObjectType = Guid.Parse(Constants.ObjectTypes.ContentItem), ParentId = -1, Path = "-1,1", SortOrder = 1, Text = "hello1", Trashed = false, UniqueId = Guid.NewGuid(), UserId = 0
                };
                unitOfWork.Database.Insert(node1);
                var entity1 = Mock.Of <IEntity>(e => e.Id == node1.NodeId);
                var node2   = new NodeDto {
                    CreateDate = DateTime.Now, Level = 1, NodeObjectType = Guid.Parse(Constants.ObjectTypes.ContentItem), ParentId = -1, Path = "-1,2", SortOrder = 1, Text = "hello2", Trashed = false, UniqueId = Guid.NewGuid(), UserId = 0
                };
                unitOfWork.Database.Insert(node2);
                var entity2 = Mock.Of <IEntity>(e => e.Id == node2.NodeId);

                for (var i = 0; i < 10; i++)
                {
                    var userDto = new UserDto {
                        ContentStartId = -1, Email = "test" + i, Login = "******" + i, MediaStartId = -1, Password = "******", Type = 1, UserName = "******" + i, UserLanguage = "en"
                    };
                    unitOfWork.Database.Insert(userDto);
                    var userNew      = Mock.Of <IUser>(e => e.Id == userDto.Id);
                    var notification = repo.CreateNotification(userNew, (i % 2 == 0) ? entity1 : entity2, i.ToString(CultureInfo.InvariantCulture));
                }

                var notifications = repo.GetEntityNotifications(entity1);

                Assert.AreEqual(5, notifications.Count());
            }
        }
        public void Delete_By_User()
        {
            var provider   = new PetaPocoUnitOfWorkProvider(Logger);
            var unitOfWork = provider.GetUnitOfWork();

            using (var repo = new NotificationsRepository(unitOfWork))
            {
                var userDto = new UserDto {
                    ContentStartId = -1, Email = "test", Login = "******", MediaStartId = -1, Password = "******", Type = 1, UserName = "******", UserLanguage = "en"
                };
                unitOfWork.Database.Insert(userDto);

                var userNew   = Mock.Of <IUser>(e => e.Id == userDto.Id);
                var userAdmin = Mock.Of <IUser>(e => e.Id == 0);

                for (var i = 0; i < 10; i++)
                {
                    var node = new NodeDto {
                        CreateDate = DateTime.Now, Level = 1, NodeObjectType = Guid.Parse(Constants.ObjectTypes.ContentItem), ParentId = -1, Path = "-1," + i, SortOrder = 1, Text = "hello" + i, Trashed = false, UniqueId = Guid.NewGuid(), UserId = 0
                    };
                    var result       = unitOfWork.Database.Insert(node);
                    var entity       = Mock.Of <IEntity>(e => e.Id == node.NodeId);
                    var notification = repo.CreateNotification((i % 2 == 0) ? userAdmin : userNew, entity, i.ToString(CultureInfo.InvariantCulture));
                }

                var delCount = repo.DeleteNotifications(userAdmin);

                Assert.AreEqual(5, delCount);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Creates a new notification
        /// </summary>
        /// <param name="user"></param>
        /// <param name="entity"></param>
        /// <param name="action">The action letter - note: this is a string for future compatibility</param>
        /// <returns></returns>
        public Notification CreateNotification(IUser user, IEntity entity, string action)
        {
            var uow        = _uowProvider.GetUnitOfWork();
            var repository = new NotificationsRepository(uow);

            return(repository.CreateNotification(user, entity, action));
        }
        public void CreateNotification()
        {
            var provider   = new PetaPocoUnitOfWorkProvider(Logger);
            var unitOfWork = provider.GetUnitOfWork();
            var repo       = new NotificationsRepository(unitOfWork);

            var node = new NodeDto {
                CreateDate = DateTime.Now, Level = 1, NodeObjectType = Guid.Parse(Constants.ObjectTypes.ContentItem), ParentId = -1, Path = "-1,123", SortOrder = 1, Text = "hello", Trashed = false, UniqueId = Guid.NewGuid(), UserId = 0
            };
            var result = unitOfWork.Database.Insert(node);
            var entity = Mock.Of <IEntity>(e => e.Id == node.NodeId);
            var user   = Mock.Of <IUser>(e => e.Id == node.UserId);

            var notification = repo.CreateNotification(user, entity, "A");

            Assert.AreEqual("A", notification.Action);
            Assert.AreEqual(node.NodeId, notification.EntityId);
            Assert.AreEqual(node.NodeObjectType, notification.EntityType);
            Assert.AreEqual(node.UserId, notification.UserId);
        }