Example #1
0
        public void Is_in_role()
        {
            using (RepositoryFactory.StartUnitOfWork())
            {
                string username = "******";
                User newUser = new User()
                {
                    Id = Guid.NewGuid(),
                    Name = "test",
                    Email = "*****@*****.**",
                    LastSeen = DateTime.Now,
                    Verified = true,
                    Roles = "admin,superuser"
                };
                using (var tran = RepositoryFactory.StartTransaction())
                {
                    SessionFactory<User>.Store(newUser);
                    tran.Commit();
                }
                WaitForIndexing();

                var authentication = RepositoryFactory.Action<IUserAuthentication>();

                // valid user and roles
                Assert.IsTrue(authentication.IsUserInRole(username, "admin"));
                Assert.IsTrue(authentication.IsUserInRole(username, "superuser"));

                // unknown group should fail
                Assert.IsFalse(authentication.IsUserInRole(username, "helpdesk"));

                // unknown user should fail
                Assert.IsFalse(authentication.IsUserInRole("not_valid_user", "admin"));

            }
        }
Example #2
0
        public void Init()
        {
            IoC.InitializeWith(new WindsorContainer());
            ApplicationInit.InitializeRepositories();
            base.SetUp();
            DBInit.RegisterDocumentStore(Store);
            DBInit.RegisterIndexes(Store);

            using (var tran = RepositoryFactory.StartTransaction())
            {
                _user = new User()
                            {
                                Id = Guid.NewGuid(),
                                Name = "user",
                                Email = "*****@*****.**"
                            };
                _testText = new StaticText
                                {
                                    Id = Guid.NewGuid(),
                                    Title = "text3",
                                    CreatedBy = _user,
                                    CreatedDate = DateTime.Now,
                                    ActualVersion = 0,
                                    PublishDate = DateTime.Now,
                                    Modified = DateTime.Now,
                                    AreCommentAllowed = true,
                                    StaticTextVersions = new List<StaticTextVersion>
                                                             {
                                                                 new StaticTextVersion
                                                                     {
                                                                         CreatedBy = _user,
                                                                         Text = "only one version",
                                                                         Version = 0,
                                                                         CreatedDate = new DateTime(2002, 1, 1)
                                                                     },
                                                             }
                                };
                _testText.Comments = new List<Comment>
                                         {
                                             new Comment
                                                 {
                                                     Id = Guid.NewGuid(),
                                                     Name = "first_comment",
                                                     Content = _testText,
                                                     Owner = _user,
                                                     AnonymousName = null,
                                                     CreatedDate = new DateTime(2002, 1, 1),
                                                     ActualVersion = 0,
                                                     CommentVersions = new List<CommentVersion>()
                                                                           {
                                                                               new CommentVersion
                                                                                   {
                                                                                       CreatedDate =
                                                                                           new DateTime(2002,
                                                                                                        1, 1),
                                                                                       CreatedBy = _user,
                                                                                       ClientIp =
                                                                                           "192.168.1.1",
                                                                                       UserAgent = "mozilla",
                                                                                       Text =
                                                                                           "this is unique commen",
                                                                                       Version = 0
                                                                                   }
                                                                           }
                                                 },
                                             new Comment
                                                 {
                                                     Id = Guid.NewGuid(),
                                                     Name = "second_comment",
                                                     Content = _testText,
                                                     Owner = _user,
                                                     AnonymousName = null,
                                                     CreatedDate = new DateTime(2002, 1, 1).AddMinutes(1),
                                                     ActualVersion = 1,
                                                     CommentVersions = new List<CommentVersion>()
                                                                           {
                                                                               new CommentVersion
                                                                                   {
                                                                                       CreatedDate =
                                                                                           new DateTime(2002,
                                                                                                        1, 1),
                                                                                       CreatedBy = _user,
                                                                                       ClientIp =
                                                                                           "192.168.1.1",
                                                                                       UserAgent = "mozilla",
                                                                                       Text =
                                                                                           "this is unique commen",
                                                                                       Version = 0
                                                                                   },
                                                                               new CommentVersion
                                                                                   {
                                                                                       CreatedDate =
                                                                                           new DateTime(2002,
                                                                                                        2, 1),
                                                                                       CreatedBy = _user,
                                                                                       ClientIp =
                                                                                           "192.168.2.1",
                                                                                       UserAgent = "mozilla",
                                                                                       Text =
                                                                                           "this is unique commen - change",
                                                                                       Version = 1
                                                                                   }
                                                                           }
                                                 }

                                         };

                _testText.Comments[0].TopComment = _testText.Comments[0];
                _testText.Comments[1].TopComment = _testText.Comments[1];
                SessionFactory<User>.Store(_user);
                SessionFactory<StaticText>.Store(_testText);
                foreach (var comment in _testText.Comments)
                {
                    SessionFactory<Comment>.Store(comment);
                }
                tran.Commit();
            }

            WaitForIndexing();
        }
Example #3
0
        public void Init()
        {
            IoC.InitializeWith(new WindsorContainer());
            IoC.InitializeWith(new WindsorContainer());
            ApplicationInit.InitializeRepositories();
            base.SetUp();
            DBInit.RegisterDocumentStore(Store);
            DBInit.RegisterIndexes(Store);

            using (var tran = RepositoryFactory.StartTransaction())
            {
                _user = new User()
                               {
                                   Id = Guid.NewGuid(),
                                   Name = "user",
                                   Email = "*****@*****.**"
                               };
                var statText1 = new StaticText
                                    {
                                        Id = Guid.NewGuid(),
                                        Title = "text1",
                                        FriendlyUrl = "text1",
                                        CreatedBy = _user,
                                        CreatedDate = DateTime.Now,
                                        ActualVersion = 1,
                                        PublishDate = new DateTime(2002, 1, 1),
                                        Modified = new DateTime(2002, 3, 1),
                                        AreCommentAllowed = true,
                                        StaticTextVersions = new List<StaticTextVersion>
                                                                 {
                                                                     new StaticTextVersion
                                                                         {
                                                                             CreatedBy = _user,
                                                                             Text = "version0",
                                                                             Version = 0,
                                                                             CreatedDate = new DateTime(2002, 1, 1)
                                                                         },
                                                                    new StaticTextVersion
                                                                         {
                                                                             CreatedBy = _user,
                                                                             Text = "version1",
                                                                             Version = 1,
                                                                             CreatedDate = new DateTime(2002, 2, 1)
                                                                         }
                                                                 }
                                    };
                 statText1.Comments = new List<Comment>
                                         {
                                             new Comment
                                                 {
                                                     Id = Guid.NewGuid(),
                                                     Name = "first_comment",
                                                     Content = statText1,
                                                     Owner = _user,
                                                     AnonymousName = null,
                                                     CreatedDate = new DateTime(2002, 1, 1),
                                                     ActualVersion = 0,
                                                     CommentVersions = new List<CommentVersion>()
                                                                           {
                                                                               new CommentVersion
                                                                                   {
                                                                                       CreatedDate =
                                                                                           new DateTime(2002,
                                                                                                        1, 1),
                                                                                       CreatedBy = _user,
                                                                                       ClientIp =
                                                                                           "192.168.1.1",
                                                                                       UserAgent = "mozilla",
                                                                                       Text =
                                                                                           "this is unique commen",
                                                                                       Version = 0,
                                                                                   }
                                                                           }
                                                 },
                                             new Comment
                                                 {
                                                     Id = Guid.NewGuid(),
                                                     Name = "first_comment",
                                                     Content = statText1,
                                                     Owner = _user,
                                                     AnonymousName = null,
                                                     CreatedDate = new DateTime(2002, 1, 1),
                                                     ActualVersion = 1,
                                                     CommentVersions = new List<CommentVersion>()
                                                                           {
                                                                               new CommentVersion
                                                                                   {
                                                                                       CreatedDate =
                                                                                           new DateTime(2002,
                                                                                                        1, 1),
                                                                                       CreatedBy = _user,
                                                                                       ClientIp =
                                                                                           "192.168.1.1",
                                                                                       UserAgent = "mozilla",
                                                                                       Text =
                                                                                           "this is unique commen",
                                                                                       Version = 0
                                                                                   },
                                                                               new CommentVersion
                                                                                   {
                                                                                       CreatedDate =
                                                                                           new DateTime(2002,
                                                                                                        2, 1),
                                                                                       CreatedBy = _user,
                                                                                       ClientIp =
                                                                                           "192.168.2.1",
                                                                                       UserAgent = "mozilla",
                                                                                       Text =
                                                                                           "this is unique commen - change",
                                                                                       Version = 1
                                                                                   }
                                                                           }
                                                 }

                                         };
                var statText2 = new StaticText
                {
                    Id = Guid.NewGuid(),
                    Title = "text2",
                    FriendlyUrl = "text2",
                    CreatedBy = _user,
                    CreatedDate = DateTime.Now,
                    ActualVersion = 2,
                    PublishDate = new DateTime(2002, 2, 1),
                    Modified = new DateTime(2002, 3, 1),
                    AreCommentAllowed = true,
                    StaticTextVersions = new List<StaticTextVersion>
                                                                 {
                                                                     new StaticTextVersion
                                                                         {
                                                                             CreatedBy = _user,
                                                                             Text = "version0",
                                                                             Version = 0,
                                                                             CreatedDate = new DateTime(2002, 1, 1)
                                                                         },
                                                                    new StaticTextVersion
                                                                         {
                                                                             CreatedBy = _user,
                                                                             Text = "version1",
                                                                             Version = 1,
                                                                             CreatedDate = new DateTime(2002, 2, 1)
                                                                         },
                                                                    new StaticTextVersion
                                                                         {
                                                                             CreatedBy = _user,
                                                                             Text = "version2",
                                                                             Version = 2,
                                                                             CreatedDate = new DateTime(2002, 3, 1)
                                                                         }
                                                                 }
                };
                var statText3 = new StaticText
                {
                    Id = Guid.NewGuid(),
                    Title = "text3",
                    FriendlyUrl = "text",
                    CreatedBy = _user,
                    CreatedDate = DateTime.Now,
                    ActualVersion = 0,
                    PublishDate = new DateTime(2002, 3, 1),
                    Modified = new DateTime(2002, 3, 1),
                    AreCommentAllowed = true,
                    StaticTextVersions = new List<StaticTextVersion>
                                                                 {
                                                                     new StaticTextVersion
                                                                         {
                                                                             CreatedBy = _user,
                                                                             Text = "only one version",
                                                                             Version = 0,
                                                                             CreatedDate = new DateTime(2002, 1, 1)
                                                                         },
                                                                 }
                };

                SessionFactory<User>.Store(_user);
                SessionFactory<StaticText>.Store(statText1);
                SessionFactory<StaticText>.Store(statText2);
                SessionFactory<StaticText>.Store(statText3);
                foreach (var comment in statText1.Comments)
                {
                    SessionFactory<Comment>.Store(comment);
                }
                _testData = new[] { statText1, statText2, statText3 };
                tran.Commit();
            }

            WaitForIndexing();
        }