Exemplo n.º 1
0
        public void Saving_New_Entity_With_Predefined_Empty_Id_Should_Not_Change_Id()
        {
            RunActionInTransaction(session =>
            {
                var layout = TestDataProvider.CreateNewLayout();
                var region = TestDataProvider.CreateNewRegion();

                layout.LayoutRegions = new List <LayoutRegion>
                {
                    TestDataProvider.CreateNewLayoutRegion(layout, region),
                };

                var page = TestDataProvider.CreateNewPageProperties(layout);

                var pageId = page.Id = Guid.NewGuid();

                Assert.AreEqual(page.Id, pageId);

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

                Assert.AreEqual(page.Id, pageId);
            });
        }
Exemplo n.º 2
0
        public void Should_Return_Page_With_PageContents_Successfully()
        {
            string virtualPath = "/test/" + Guid.NewGuid().ToString().Replace("-", string.Empty) + "/";
            var    layout      = TestDataProvider.CreateNewLayout();
            var    regionA     = TestDataProvider.CreateNewRegion();
            var    regionB     = TestDataProvider.CreateNewRegion();

            var htmlContent         = TestDataProvider.CreateNewHtmlContent();
            var serverWidgetContent = TestDataProvider.CreateNewServerControlWidget();
            var htmlContentWidget   = TestDataProvider.CreateNewHtmlContentWidget();

            layout.LayoutRegions = new List <LayoutRegion>
            {
                TestDataProvider.CreateNewLayoutRegion(layout, regionA),
                TestDataProvider.CreateNewLayoutRegion(layout, regionB)
            };

            var page = TestDataProvider.CreateNewPageProperties(layout);

            page.PageContents = new List <PageContent>
            {
                TestDataProvider.CreateNewPageContent(htmlContent, page, regionA),
                TestDataProvider.CreateNewPageContent(serverWidgetContent, page, regionB),
                TestDataProvider.CreateNewPageContent(htmlContentWidget, page, regionB)
            };
            page.PageUrl = virtualPath;

            RunDatabaseActionAndAssertionsInTransaction(
                page,
                session =>
            {
                session.Save(page);
                session.Flush();
            },
                (result, session) =>
            {
                Page pageAlias     = null;
                Layout layoutAlias = null;

                var entity = session.QueryOver(() => pageAlias)
                             .Inner.JoinAlias(() => pageAlias.Layout, () => layoutAlias)
                             .Where(f => f.PageUrl == virtualPath.ToLowerInvariant())
                             .Fetch(f => f.Layout).Eager
                             .Fetch(f => f.Layout.LayoutRegions).Eager
                             .Fetch(f => f.PageContents).Eager
                             .Fetch(f => f.PageContents[0].Content).Eager
                             .SingleOrDefault();

                Assert.IsNotNull(entity);
                Assert.AreEqual(page.PageContents.Count(), entity.PageContents.Distinct().Count());
                Assert.AreEqual(page.Layout.LayoutRegions.Count(), entity.Layout.LayoutRegions.Distinct().Count());
            });
        }
Exemplo n.º 3
0
        public void Should_Insert_And_Retrieve_Layout_LayoutRegions_Successfully()
        {
            var layout        = TestDataProvider.CreateNewLayout();
            var layoutRegions = new[]
            {
                TestDataProvider.CreateNewLayoutRegion(layout),
                TestDataProvider.CreateNewLayoutRegion(layout),
                TestDataProvider.CreateNewLayoutRegion(layout)
            };

            layout.LayoutRegions = layoutRegions;

            SaveEntityAndRunAssertionsInTransaction(
                layout,
                result =>
            {
                Assert.AreEqual(layout, result);
                Assert.AreEqual(layoutRegions.OrderBy(f => f.Id), result.LayoutRegions.OrderBy(f => f.Id));
            });
        }
Exemplo n.º 4
0
        public void Saving_Entity_With_Duplicated_Id_Should_Fail2()
        {
            RunActionInTransaction(
                session =>
            {
                var layout = TestDataProvider.CreateNewLayout();
                var region = TestDataProvider.CreateNewRegion();

                layout.LayoutRegions = new List <LayoutRegion> {
                    TestDataProvider.CreateNewLayoutRegion(layout, region),
                };

                var page = TestDataProvider.CreateNewPageProperties(layout);

                var pageId = page.Id;
                Assert.AreNotEqual(pageId, Guid.Empty);

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

                Assert.AreEqual(page.Id, pageId);

                var originalPage = session.Get <Page>(pageId);
                Assert.AreEqual(page, originalPage);

                var page2 = TestDataProvider.CreateNewPageProperties(layout);
                page2.Id  = pageId;

                session.Clear();
                Assert.Throws <NHibernate.Exceptions.GenericADOException>(
                    () =>
                {
                    session.SaveOrUpdate(page2);
                    session.Flush();
                });
            });
        }
Exemplo n.º 5
0
        public void Changing_Saved_Entity_Id_Should_Fail()
        {
            RunActionInTransaction(
                session =>
            {
                var layout = TestDataProvider.CreateNewLayout();
                var region = TestDataProvider.CreateNewRegion();

                layout.LayoutRegions = new List <LayoutRegion> {
                    TestDataProvider.CreateNewLayoutRegion(layout, region),
                };

                var page = TestDataProvider.CreateNewPageProperties(layout);

                var pageId = page.Id;
                Assert.AreNotEqual(pageId, Guid.Empty);

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

                Assert.AreEqual(page.Id, pageId);

                var originalPage = session.Get <Page>(pageId);
                Assert.AreEqual(page, originalPage);

                var newId       = Guid.NewGuid();
                originalPage.Id = newId;

                Assert.Throws <NHibernate.HibernateException>(
                    () =>
                {
                    session.SaveOrUpdate(originalPage);
                    session.Flush();
                });
            });
        }
Exemplo n.º 6
0
        public void Should_Insert_And_Retrieve_LayoutRegion_Successfully()
        {
            var entity = TestDataProvider.CreateNewLayoutRegion();

            RunEntityMapTestsInTransaction(entity);
        }
Exemplo n.º 7
0
        public void Should_Sort_Page_Content_Successfully()
        {
            RunActionInTransaction(session =>
            {
                var layout = TestDataProvider.CreateNewLayout();
                var region = TestDataProvider.CreateNewRegion();

                layout.LayoutRegions = new List <LayoutRegion>
                {
                    TestDataProvider.CreateNewLayoutRegion(layout, region),
                };

                var page          = TestDataProvider.CreateNewPageProperties(layout);
                page.PageContents = new[]
                {
                    TestDataProvider.CreateNewPageContent(TestDataProvider.CreateNewHtmlContent(), page, region),
                    TestDataProvider.CreateNewPageContent(TestDataProvider.CreateNewHtmlContent(), page, region),
                    TestDataProvider.CreateNewPageContent(TestDataProvider.CreateNewHtmlContent(), page, region)
                };

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

                IUnitOfWork unitOfWork = new DefaultUnitOfWork(session);

                SortPageContentCommand command = new SortPageContentCommand();
                command.UnitOfWork             = unitOfWork;
                command.Repository             = new DefaultRepository(unitOfWork);

                var request = new PageContentSortViewModel
                {
                    PageId       = page.Id,
                    RegionId     = region.Id,
                    PageContents =
                        new List <ContentSortViewModel>
                    {
                        new ContentSortViewModel {
                            Id = page.PageContents[2].Id, Version = page.PageContents[2].Version
                        },
                        new ContentSortViewModel {
                            Id = page.PageContents[1].Id, Version = page.PageContents[1].Version
                        },
                        new ContentSortViewModel {
                            Id = page.PageContents[0].Id, Version = page.PageContents[0].Version
                        },
                    }
                };
                var response = command.Execute(request);

                Assert.AreEqual(2, response.UpdatedPageContents.Count);

                session.Flush();
                session.Clear();

                var updatedPage = command.Repository.AsQueryable <PageContent>(f => f.Page.Id == page.Id).ToList();

                Assert.AreEqual(2, updatedPage.FirstOrDefault(f => f.Id == page.PageContents[0].Id).Order);
                Assert.AreEqual(1, updatedPage.FirstOrDefault(f => f.Id == page.PageContents[1].Id).Order);
                Assert.AreEqual(0, updatedPage.FirstOrDefault(f => f.Id == page.PageContents[2].Id).Order);
            });
        }
Exemplo n.º 8
0
        public void Should_Sort_Page_Content_Successfully()
        {
            RunActionInTransaction(session =>
            {
                var layout = TestDataProvider.CreateNewLayout();
                var region = TestDataProvider.CreateNewRegion();

                layout.LayoutRegions = new List <LayoutRegion>
                {
                    TestDataProvider.CreateNewLayoutRegion(layout, region),
                };

                var page          = TestDataProvider.CreateNewPageProperties(layout);
                page.PageContents = new[]
                {
                    TestDataProvider.CreateNewPageContent(TestDataProvider.CreateNewHtmlContent(), page, region),
                    TestDataProvider.CreateNewPageContent(TestDataProvider.CreateNewHtmlContent(), page, region),
                    TestDataProvider.CreateNewPageContent(TestDataProvider.CreateNewHtmlContent(), page, region)
                };

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

                IUnitOfWork unitOfWork = new DefaultUnitOfWork(session);

                var configuration = Container.Resolve <ICmsConfiguration>();
                SortPageContentCommand command = new SortPageContentCommand(configuration);
                command.UnitOfWork             = unitOfWork;
                command.Repository             = new DefaultRepository(unitOfWork);
                command.Context = new Mock <ICommandContext>().Object;

                var accessControlService = new Mock <IAccessControlService>();
                accessControlService.Setup(s => s.DemandAccess(It.IsAny <IPrincipal>(), It.IsAny <string>()));
                command.AccessControlService = accessControlService.Object;

                var request = new PageContentSortViewModel
                {
                    PageId       = page.Id,
                    PageContents =
                        new List <ContentSortViewModel>
                    {
                        new ContentSortViewModel {
                            RegionId = region.Id, PageContentId = page.PageContents[2].Id, Version = page.PageContents[2].Version
                        },
                        new ContentSortViewModel {
                            RegionId = region.Id, PageContentId = page.PageContents[1].Id, Version = page.PageContents[1].Version
                        },
                        new ContentSortViewModel {
                            RegionId = region.Id, PageContentId = page.PageContents[0].Id, Version = page.PageContents[0].Version
                        },
                    }
                };
                var response = command.Execute(request);

                Assert.IsTrue(response);

                session.Flush();
                session.Clear();

                var updatedPage = command.Repository.AsQueryable <PageContent>(f => f.Page.Id == page.Id).ToList();

                Assert.AreEqual(2, updatedPage.FirstOrDefault(f => f.Id == page.PageContents[0].Id).Order);
                Assert.AreEqual(1, updatedPage.FirstOrDefault(f => f.Id == page.PageContents[1].Id).Order);
                Assert.AreEqual(0, updatedPage.FirstOrDefault(f => f.Id == page.PageContents[2].Id).Order);
            });
        }