Exemplo n.º 1
0
        public void Should_Clone_Page_With_Tags_Options_Contents_AccessRules()
        {
            RunActionInTransaction(session =>
            {
                const string url = "/test-link";
                var uow          = new DefaultUnitOfWork(session);
                var repository   = new DefaultRepository(uow);


                var pageToClone = TestDataProvider.CreateNewPageWithTagsContentsOptionsAndAccessRules(session, 2, 2, 2, 2);

                session.SaveOrUpdate(pageToClone);
                session.Flush();
                session.Clear();

                var pageService = new Mock <IPageService>();
                pageService.Setup(f => f.ValidatePageUrl(It.IsAny <string>(), It.IsAny <Guid?>()));
                pageService.Setup(f => f.CreatePagePermalink(It.IsAny <string>(), It.IsAny <string>())).Returns(url);

                var urlService = new Mock <IUrlService>();
                urlService.Setup(f => f.FixUrl(It.IsAny <string>())).Returns(url);

                var rules = new List <IAccessRule>();
                var rule1 = TestDataProvider.CreateNewAccessRule();
                rules.Add(rule1);
                var rule2 = TestDataProvider.CreateNewAccessRule();
                rules.Add(rule2);

                var command                  = new ClonePageCommand();
                command.Repository           = repository;
                command.UnitOfWork           = uow;
                command.PageService          = pageService.Object;
                command.UrlService           = urlService.Object;
                command.AccessControlService = new Mock <IAccessControlService>().Object;
                command.Context              = new Mock <ICommandContext>().Object;

                var result = command.Execute(new ClonePageViewModel
                {
                    PageId         = pageToClone.Id,
                    PageTitle      = "new cloned page",
                    PageUrl        = url,
                    UserAccessList = pageToClone.AccessRules.Select(u => new UserAccessViewModel(u)).ToList()
                });

                Assert.IsNotNull(result);
                session.Clear();

                var actual = repository.AsQueryable <PageProperties>().Where(f => f.Id == result.PageId).ToList().FirstOrDefault();

                Assert.IsNotNull(actual);
                Assert.AreEqual(2, actual.AccessRules.Count(), "AccessRules");
                Assert.AreEqual(2, actual.PageTags.Count(), "Tags");
                Assert.AreEqual(2, actual.PageContents.Count(), "Contents");
                Assert.AreEqual(2, actual.Options.Count(), "Options");
            });
        }
Exemplo n.º 2
0
        public void Should_Get_File_Access_Control()
        {
            RunActionInTransaction(session =>
            {
                var accessRule = TestDataProvider.CreateNewAccessRule();
                var file       = TestDataProvider.CreateNewMediaFile();
                file.AddRule(accessRule);

                session.SaveOrUpdate(file);
                session.Flush();

                var accessControlService = CreateAccessControlService();

                var level = accessControlService.GetAccessLevel(file, new GenericPrincipal(new GenericIdentity(accessRule.Identity), null));

                Assert.AreEqual(accessRule.AccessLevel, level);
            });
        }
        public void Should_Insert_And_Retrieve_AccessRule_Successfully()
        {
            var content = TestDataProvider.CreateNewAccessRule();

            RunEntityMapTestsInTransaction(content);
        }