public async Task GetAll_NonExistingSite()
        {
            var someRandomId = Guid.NewGuid();
            var pageIds      = await PageRepository.GetAll(someRandomId).ConfigureAwait(false);

            Assert.AreEqual(0, pageIds.Count());
        }
        public async Task GetById_RandomIdReturnsNull()
        {
            var pageId    = Guid.NewGuid();
            var retrieved = await PageRepository.GetById <MyPage>(pageId).ConfigureAwait(false);

            Assert.IsNull(retrieved);
        }
        public async Task CreateRevisions_WithRemovalOfOld()
        {
            const int revisionCount = 2;
            var       siteId        = await MakeSite().ConfigureAwait(false);

            using var api = CreateApi();
            MyPage page = await MyPage.CreateAsync(api).ConfigureAwait(false);

            page.SiteId    = siteId;
            page.Title     = "Startpage";
            page.Text      = "Welcome";
            page.IsHidden  = true;
            page.Published = DateTime.Now;
            await PageRepository.Save(page).ConfigureAwait(false);

            var pageId = page.Id;
            await PageRepository.CreateRevision(pageId, revisionCount).ConfigureAwait(false);

            await PageRepository.CreateRevision(pageId, revisionCount).ConfigureAwait(false);

            await PageRepository.CreateRevision(pageId, revisionCount).ConfigureAwait(false);

            using var session = SessionFactory.OpenSession();
            using var txn     = session.BeginTransaction();
            var revisions = session.Query <PageRevisionEntity>().Where(p => p.Page.Id == pageId).ToList();

            Assert.AreEqual(revisionCount, revisions.Count);
            txn.Commit();
        }
        public async Task GetAllPendingComments_RandomId()
        {
            const int pageIndex = 0;
            const int pageSize  = 10;
            var       comments  = await PageRepository.GetAllPendingComments(Guid.NewGuid(), pageIndex, pageSize).ConfigureAwait(false);

            Assert.AreEqual(0, comments.Count());
        }
        public async Task GetAllBlogs()
        {
            var siteId = await MakeSite().ConfigureAwait(false);

            var blogIds = await PageRepository.GetAllBlogs(siteId).ConfigureAwait(false);

            Assert.IsEmpty(blogIds);
        }
        public async Task GetStartPage_EmptySite()
        {
            var siteId = await MakeSite().ConfigureAwait(false);

            var startPage = await PageRepository.GetStartpage <DynamicPage>(siteId).ConfigureAwait(false);

            Assert.IsNull(startPage);
        }
        public async Task GetAll_ExistingSite()
        {
            var siteId = await MakeSite().ConfigureAwait(false);

            var pageIds = await PageRepository.GetAll(siteId).ConfigureAwait(false);

            Assert.AreEqual(0, pageIds.Count());
        }
        public async Task GetAllBlogs_WithOneBlog()
        {
            var siteId = await MakeSite().ConfigureAwait(false);

            var blog = await MakeBlog(siteId).ConfigureAwait(false);

            var blogIds = await PageRepository.GetAllBlogs(siteId).ConfigureAwait(false);

            Assert.AreEqual(1, blogIds.Count());
            Assert.Contains(blog.Id, blogIds.ToList());
        }
        public async Task GetById_PageWithBlocks()
        {
            var siteId = await MakeSite().ConfigureAwait(false);

            MyPage page = await MakePageWithBlocks(siteId).ConfigureAwait(false);

            var pageId    = page.Id;
            var retrieved = await PageRepository.GetById <MyPage>(pageId).ConfigureAwait(false);

            Assert.AreEqual(2, retrieved.Blocks.Count);
        }
        public async Task GetAllComments()
        {
            const int pageIndex = 0;
            const int pageSize  = 10;
            var       siteId    = await MakeSite().ConfigureAwait(false);

            var firstPage = await MakePage(siteId).ConfigureAwait(false);

            var comments = await PageRepository.GetAllComments(firstPage.Id, false, pageIndex, pageSize).ConfigureAwait(false);

            Assert.AreEqual(0, comments.Count());
        }
        private async Task <MyBlogPage> MakeBlog(Guid siteId, int sortOrder = 0)
        {
            using var api = CreateApi();
            MyBlogPage blog = await MyBlogPage.CreateAsync(api).ConfigureAwait(false);

            blog.SiteId    = siteId;
            blog.Title     = "Blog Archive";
            blog.SortOrder = sortOrder;
            await PageRepository.Save(blog).ConfigureAwait(false);

            return(blog);
        }
        public async Task GetBySlug()
        {
            var siteId = await MakeSite().ConfigureAwait(false);

            var firstPage = await MakePage(siteId).ConfigureAwait(false);

            firstPage.Slug = $"slug-{RandomNumber.Next()}";
            await PageRepository.Save(firstPage).ConfigureAwait(false);

            var retrieved = await PageRepository.GetBySlug <MyPage>(firstPage.Slug, siteId).ConfigureAwait(false);

            Assert.AreEqual(firstPage.Id, retrieved.Id);
        }
        public async Task GetAll_WithOnePage()
        {
            var siteId = await MakeSite().ConfigureAwait(false);

            using var api = CreateApi();
            MyPage page = await MakePage(siteId).ConfigureAwait(false);

            var pageId  = page.Id;
            var pageIds = await PageRepository.GetAll(siteId).ConfigureAwait(false);

            Assert.AreEqual(1, pageIds.Count());
            Assert.AreEqual(1, pageIds.Count(id => id == pageId));
        }
        public async Task GetBySlug_RandomSiteId()
        {
            var siteId = await MakeSite().ConfigureAwait(false);

            var firstPage = await MakePage(siteId).ConfigureAwait(false);

            firstPage.Slug = $"slug-{RandomNumber.Next()}";
            await PageRepository.Save(firstPage).ConfigureAwait(false);

            var retrieved = await PageRepository.GetBySlug <MyPage>(firstPage.Slug, Guid.NewGuid()).ConfigureAwait(false);

            Assert.IsNull(retrieved);
        }
        public async Task Delete()
        {
            var siteId = await MakeSite().ConfigureAwait(false);

            MyPage page = await MakePage(siteId).ConfigureAwait(false);

            var pageId = page.Id;
            await PageRepository.Delete(pageId).ConfigureAwait(false);

            var pageIds = await PageRepository.GetAll(siteId).ConfigureAwait(false);

            Assert.AreEqual(0, pageIds.Count());
            // TODO: assert that no orphan comments, blocks, fields, etc. are left.
        }
        private async Task <MyPage> MakePage(Guid siteId)
        {
            using var api = CreateApi();
            MyPage page = await MyPage.CreateAsync(api).ConfigureAwait(false);

            page.SiteId    = siteId;
            page.Title     = "Startpage";
            page.Text      = "Welcome";
            page.IsHidden  = true;
            page.Published = DateTime.Now;
            await PageRepository.Save(page).ConfigureAwait(false);

            return(page);
        }
        public async Task GetStartPage_SinglePage()
        {
            var siteId = await MakeSite().ConfigureAwait(false);

            var aPage = await MakePage(siteId).ConfigureAwait(false);

            aPage.ParentId = null;
            var pageId = aPage.Id;
            await PageRepository.Save(aPage).ConfigureAwait(false);

            var startPage = await PageRepository.GetStartpage <DynamicPage>(siteId).ConfigureAwait(false);

            Assert.AreEqual(pageId, startPage.Id);
        }
        public async Task GetCommentById()
        {
            var siteId = await MakeSite().ConfigureAwait(false);

            var firstPage = await MakePage(siteId).ConfigureAwait(false);

            var firstComment = MakeComment();
            await PageRepository.SaveComment(firstPage.Id, firstComment).ConfigureAwait(false);

            var comment = await PageRepository.GetCommentById(firstComment.Id).ConfigureAwait(false);

            Assert.AreEqual(firstComment.Body, comment.Body);
            Assert.AreEqual(firstComment.Id, comment.Id);
        }
        public async Task DeleteComment()
        {
            var siteId = await MakeSite().ConfigureAwait(false);

            var firstPage = await MakePage(siteId).ConfigureAwait(false);

            var firstComment = MakeComment();
            await PageRepository.SaveComment(firstPage.Id, firstComment).ConfigureAwait(false);

            await PageRepository.DeleteComment(firstComment.Id).ConfigureAwait(false);

            var comment = await PageRepository.GetCommentById(firstComment.Id).ConfigureAwait(false);

            Assert.IsNull(comment);
        }
        public async Task GetById()
        {
            var siteId = await MakeSite().ConfigureAwait(false);

            MyPage page = await MakePage(siteId).ConfigureAwait(false);

            var pageId = page.Id;

            Assert.AreNotEqual(Guid.Empty, pageId);
            var retrieved = await PageRepository.GetById <MyPage>(pageId).ConfigureAwait(false);

            Assert.AreEqual(pageId, retrieved.Id);
            Assert.AreEqual(siteId, retrieved.SiteId);
            Assert.AreEqual("Startpage", retrieved.Title);
            Assert.AreEqual("Welcome", retrieved.Text.Value);
        }
        public async Task Save_AfterChange()
        {
            var siteId = await MakeSite().ConfigureAwait(false);

            MyPage page = await MakePage(siteId).ConfigureAwait(false);

            var    pageId  = page.Id;
            string newText = $"Welcome at {DateTime.Now}";

            page.Text = newText;
            await PageRepository.Save(page).ConfigureAwait(false);

            var retrieved = await PageRepository.GetById <MyPage>(pageId).ConfigureAwait(false);

            Assert.AreEqual(newText, retrieved.Text.Value);
        }
        private async Task <MyPage> MakePageWithBlocks(Guid siteId)
        {
            var page = await MakePage(siteId).ConfigureAwait(false);

            page.Blocks.Add(new Piranha.Extend.Blocks.TextBlock
            {
                Body = Lorem.Sentence(3)
            });
            page.Blocks.Add(new Piranha.Extend.Blocks.TextBlock
            {
                Body = Lorem.Sentence(3)
            });
            await PageRepository.Save(page).ConfigureAwait(false);

            return(page);
        }
Esempio n. 23
0
        private async Task <MyPage> MakePage(Guid siteId)
        {
            var    pageRepository = new PageRepository(SessionFactory, new ContentServiceFactory(_contentFactory), Module.Mapper);
            MyPage page;

            using var api = CreateApi();
            page          = await MyPage.CreateAsync(api).ConfigureAwait(false);

            page.SiteId    = siteId;
            page.Title     = "Startpage";
            page.Text      = "Welcome";
            page.IsHidden  = true;
            page.Published = DateTime.Now;
            await pageRepository.Save(page).ConfigureAwait(false);

            return(page);
        }
        public async Task GetAllBlogs_SortOrder()
        {
            var siteId = await MakeSite().ConfigureAwait(false);

            var blog1 = await MakeBlog(siteId, 1).ConfigureAwait(false);

            var blog2 = await MakeBlog(siteId, 3).ConfigureAwait(false);

            var blog3 = await MakeBlog(siteId, 2).ConfigureAwait(false);

            var blogIds = await PageRepository.GetAllBlogs(siteId).ConfigureAwait(false);

            var array = blogIds.ToArray();

            Assert.AreEqual(3, array.Length);
            Assert.AreEqual(blog1.Id, array[0]);
            Assert.AreEqual(blog3.Id, array[1]);
            Assert.AreEqual(blog2.Id, array[2]);
        }
        public async Task Save_WithPublishDateInPastShouldNotHaveDraft()
        {
            var siteId = await MakeSite().ConfigureAwait(false);

            using var api = CreateApi();
            MyPage page = await MyPage.CreateAsync(api).ConfigureAwait(false);

            page.SiteId    = siteId;
            page.Title     = "Startpage";
            page.Text      = "Welcome";
            page.IsHidden  = true;
            page.Published = DateTime.Now.AddDays(-42);
            await PageRepository.Save(page).ConfigureAwait(false);

            var pageId = page.Id;
            var draft  = await PageRepository.GetDraftById <MyPage>(pageId).ConfigureAwait(false);

            Assert.IsNull(draft);
        }
        public async Task GetAllPendingComments()
        {
            const int pageIndex = 0;
            const int pageSize  = 10;
            var       siteId    = await MakeSite().ConfigureAwait(false);

            var firstPage = await MakePage(siteId).ConfigureAwait(false);

            var firstComment = MakeComment();
            await PageRepository.SaveComment(firstPage.Id, firstComment).ConfigureAwait(false);

            var secondComment = MakeComment();

            secondComment.IsApproved = false;
            await PageRepository.SaveComment(firstPage.Id, secondComment).ConfigureAwait(false);

            var comments = await PageRepository.GetAllPendingComments(firstPage.Id, pageIndex, pageSize).ConfigureAwait(false);

            Assert.AreEqual(1, comments.Count());
        }
        public async Task GetAllComments_WithPaging()
        {
            const int pageSize = 5;
            var       siteId   = await MakeSite().ConfigureAwait(false);

            var firstPage = await MakePage(siteId).ConfigureAwait(false);

            for (var i = 0; i < 10; i++)
            {
                var firstComment = MakeComment();
                await PageRepository.SaveComment(firstPage.Id, firstComment).ConfigureAwait(false);
            }
            var firstPageWithComments = await PageRepository.GetAllComments(firstPage.Id, false, 0, pageSize).ConfigureAwait(false);

            var secondPageWithComments = await PageRepository.GetAllComments(firstPage.Id, false, 1, pageSize).ConfigureAwait(false);

            Assert.AreEqual(5, firstPageWithComments.Count());
            Assert.AreEqual(5, secondPageWithComments.Count());
            Assert.AreEqual(0, firstPageWithComments.Intersect(secondPageWithComments, new CommentComparer()).Count());
        }
Esempio n. 28
0
        public async Task GetSitemap()
        {
            var repository = new SiteRepository(SessionFactory, new ContentServiceFactory(_contentFactory));
            var siteId     = await MakeSite().ConfigureAwait(false);

            _ = await MakePage(siteId).ConfigureAwait(false);

            var anotherPage = await MakePage(siteId).ConfigureAwait(false);

            anotherPage.Published = null;
            var pageRepository = new PageRepository(SessionFactory, new ContentServiceFactory(_contentFactory), Module.Mapper);
            await pageRepository.Save(anotherPage).ConfigureAwait(false);

            var siteMap = await repository.GetSitemap(siteId, true).ConfigureAwait(false);

            Assert.AreEqual(1, siteMap.Count);
            var siteMapIncludingNonPublished = await repository.GetSitemap(siteId, false).ConfigureAwait(false);

            Assert.AreEqual(2, siteMapIncludingNonPublished.Count);
        }
        public async Task GetStartPage_BasedOnSortOrder()
        {
            var siteId = await MakeSite().ConfigureAwait(false);

            var firstPage = await MakePage(siteId).ConfigureAwait(false);

            var secondPage = await MakePage(siteId).ConfigureAwait(false);

            var secondPageId = secondPage.Id;

            firstPage.SortOrder  = 1;
            secondPage.SortOrder = 0;
            await PageRepository.Save(secondPage).ConfigureAwait(false);

            await PageRepository.Save(firstPage).ConfigureAwait(false);

            var retrieved = await PageRepository.GetStartpage <DynamicPage>(siteId).ConfigureAwait(false);

            Assert.AreEqual(secondPageId, retrieved.Id);
        }
        public async Task GetAllComments_ForAllPages()
        {
            const int pageIndex = 0;
            const int pageSize  = int.MaxValue;
            var       siteId    = await MakeSite().ConfigureAwait(false);

            var firstPage = await MakePage(siteId).ConfigureAwait(false);

            var firstComment = MakeComment();
            await PageRepository.SaveComment(firstPage.Id, firstComment).ConfigureAwait(false);

            var secondPage = await MakePage(siteId).ConfigureAwait(false);

            var secondComment = MakeComment();
            await PageRepository.SaveComment(secondPage.Id, secondComment).ConfigureAwait(false);

            var comments = await PageRepository.GetAllComments(null, false, pageIndex, pageSize).ConfigureAwait(false);

            Assert.AreEqual(1, comments.Count(p => p.Author == firstComment.Author), $"Author is '{firstComment.Author}'");
            Assert.AreEqual(1, comments.Count(p => p.Author == secondComment.Author), $"Author is '{secondComment.Author}'");
        }