Ejemplo n.º 1
0
        public static void GenerateDatabase(ISession session)
        {
            using (var kernel = TestHelper.CreateKernel()) {
                kernel.Get<SchemaManager>().GenerateDatabaseSchema(session);
                HomePage parent = new HomePage { Title = "Parent", UrlSegment = "~" };
                Page child = new Page { Title = "Child", UrlSegment = "child" };
                Page grandchild = new Page { Title = "Grand Child", UrlSegment = "grand-child" };
                parent.AddChildren(child);
                child.AddChildren(grandchild);

                Page child2 = new Page { Title = "Child 2", UrlSegment = "child2" };
                Page grandchild2 = new Page { Title = "Grand Child 2", UrlSegment = "grand-child" };
                parent.AddChildren(child2);
                child2.AddChildren(grandchild2);

                session.Save(parent);
                session.Flush();
            }
        }
Ejemplo n.º 2
0
        public void TestRetrieveByContentItem()
        {
            using (var kernel = TestHelper.CreateKernel()) {
                using (var session = kernel.Get<ISession>()) {
                    DatabaseHelper.GenerateDatabase(session);

                    Page page = new Page { Title = "Page 1", BodyText = "Body 1", UrlSegment = "page-1" };
                    HomePage home = new HomePage { Title = "Home", BodyText = "Home Body", UrlSegment = "~" };
                    home.AddChildren(page);
                    session.Save(home);

                    var contentItems = session.CreateCriteria<ContentItem>().List();
                    Assert.Equal(7, contentItems.Count);
                }
            }
        }
Ejemplo n.º 3
0
        public void NonUniqueUrlThrowsException()
        {
            using (var kernel = TestHelper.CreateKernel()) {
                using (var session = kernel.Get<ISession>()) {
                    DatabaseHelper.GenerateDatabase(session);
                    // Create a duplicate url (parent/child)
                    HomePage home2 = new HomePage() { UrlSegment = "~" };
                    Page child2 = new Page() { UrlSegment = "child" };
                    home2.AddChildren(child2);
                    session.Save(home2);

                    IContentFinder contentFinder = new ContentFinder(session);
                    Assert.Throws<System.Exception>(()=>
                        contentFinder.Find<Page>("~/child")
                    );
                }
            }
        }