Ejemplo n.º 1
0
 public void CloneChildren()
 {
     var children = new List<Page> { new Page() };
     var parent = new Page { Pages = children };
     var result = parent.Clone() as Page;
     Assert.NotEmpty( result.Pages );
 }
Ejemplo n.º 2
0
 public void ClonePageContexts()
 {
     var page = new Page { PageContexts = new List<PageContext>() };
     page.PageContexts.Add( new PageContext() );
     var result = page.Clone() as Page;
     Assert.NotNull( result.PageContexts );
     Assert.NotEmpty( result.PageContexts );
 }
Ejemplo n.º 3
0
 public void CloneBlocks()
 {
     var page = new Page { Blocks = new List<Block>() };
     page.Blocks.Add( new Block() );
     var result = page.Clone() as Page;
     Assert.NotNull( result.Blocks );
     Assert.NotEmpty( result.Blocks );
 }
Ejemplo n.º 4
0
 public void ClonePageRoutes()
 {
     var page = new Page { PageRoutes = new List<PageRoute>() };
     page.PageRoutes.Add( new PageRoute() );
     var result = page.Clone() as Page;
     Assert.NotNull( result.PageRoutes );
     Assert.NotEmpty( result.PageRoutes );
 }
Ejemplo n.º 5
0
 public void CloneChildrenRecursively()
 {
     var parent = new Page();
     var child = new Page();
     var grandchild = new Page();
     parent.Pages = new List<Page> { child };
     child.Pages = new List<Page> { grandchild };
     var result = parent.Clone() as Page;
     Assert.NotEmpty( result.Pages );
     Assert.NotEmpty( result.Pages.FirstOrDefault().Pages );
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Determines whether the specified page can be deleted.
        /// Performs some additional checks that are missing from the
        /// auto-generated PageService.CanDelete().
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="errorMessage">The error message.</param>
        /// <param name="includeSecondLvl">If set to true, verifies that the item is not referenced by any second level relationships.</param>
        /// <returns>
        ///   <c>true</c> if this instance can delete the specified item; otherwise, <c>false</c>.
        /// </returns>
        public bool CanDelete( Page item, out string errorMessage, bool includeSecondLvl )
        {
            errorMessage = string.Empty;

            bool canDelete = CanDelete( item, out errorMessage );

            var site = new Service<Site>( this.Context ).Queryable().Where( s => ( s.DefaultPageId == item.Id || s.LoginPageId == item.Id
                || s.RegistrationPageId == item.Id || s.PageNotFoundPageId == item.Id ) ).FirstOrDefault();
            if ( canDelete && includeSecondLvl && site != null )
            {
                errorMessage = string.Format( "This {0} is used by a special page on the {1} {2}.", Page.FriendlyTypeName, site.Name, Site.FriendlyTypeName );
                canDelete = false;
            }

            return canDelete;
        }
Ejemplo n.º 7
0
 public void ToJson()
 {
     var page = new Page();
     var result = page.ToJson();
     Assert.NotEmpty( result );
 }
Ejemplo n.º 8
0
 public void ShallowClone()
 {
     var page = new Page { InternalName = "SomePage" };
     var result = page.Clone( false );
     Assert.Equal( result.InternalName, page.InternalName );
 }
Ejemplo n.º 9
0
        public void ExportJson()
        {
            var page = new Page
            {
                PageTitle = "FooPage"
            };

            var result = page.ToJson();
            const string key = "\"PageTitle\": \"FooPage\"";
            Assert.NotEqual( result.IndexOf( key ), -1 );
        }
Ejemplo n.º 10
0
        private string ParentStructure( Page page, List<int> parentIds = null )
        {
            if ( page == null )
            {
                return string.Empty;
            }

            // Create or add this node to the history stack for this tree walk.
            if ( parentIds == null )
            {
                parentIds = new List<int>();
            }
            else
            {
                // If we have encountered this node before during this tree walk, we have found an infinite recursion in the tree.
                // Truncate the path with an error message and exit.
                if ( parentIds.Contains( page.Id ) )
                {
                    return "#Invalid-Parent-Reference#";
                }
            }

            parentIds.Add( page.Id );

            string prefix = ParentStructure( page.ParentPage, parentIds );

            if ( !string.IsNullOrWhiteSpace( prefix ) )
            {
                prefix += " <i class='fa fa-angle-right'></i> ";
            }

            string pageUrl = RockPage.ResolveUrl( "~/Page/" );

            return string.Format( "{0}<a href='{1}{2}'>{3}</a>", prefix, pageUrl, page.Id, page.PageTitle );
        }
Ejemplo n.º 11
0
        public void ImportJsonRecursively()
        {
            const string PAGE_NAME = "Child Page";

            var childPage = new Page { InternalName = PAGE_NAME };
            var parentPage = new Page { InternalName = "Parent Page" };
            var grandparentPage = new Page { InternalName = "Grandparent Page" };

            parentPage.Pages.Add( childPage );
            grandparentPage.Pages.Add( parentPage );

            var json = grandparentPage.ToJson();
            var page = Page.FromJson( json );
            var childPages = page.Pages.First().Pages;
            Assert.NotNull( childPages );
            Assert.NotEmpty( childPages );
            Assert.Equal( childPages.First().InternalName, PAGE_NAME );
        }
Ejemplo n.º 12
0
        public void ImportJson()
        {
            var obj = new Page { InternalName = "Parent" };
            obj.Pages.Add( new Page { InternalName = "Child" } );

            var json = obj.ToJson();
            var page = Page.FromJson( json );
            Assert.NotNull( page.Pages );
            Assert.NotEmpty( page.Pages );
            Assert.Equal( page.Pages.First().InternalName, obj.Pages.First().InternalName );
        }
Ejemplo n.º 13
0
 public void ImportBlocks()
 {
     var obj = new Page { InternalName = "Some Page" };
     obj.Blocks.Add( new Block { Name = "Some Block" } );
     var json = obj.ToJson();
     var page = Page.FromJson( json );
     Assert.NotNull( page.Blocks );
     Assert.NotEmpty( page.Blocks );
     Assert.Equal( page.Blocks.First().Name, obj.Blocks.First().Name );
 }
Ejemplo n.º 14
0
        public void ImportAttributeValues()
        {
            var obj = new Page
            {
                InternalName = "Some Page",
                AttributeValues = new Dictionary<string, AttributeValueCache>()
                {
                    { "foobar",  new AttributeValueCache( new AttributeValue { Value = "baz" } ) }
                }
            };

            var json = obj.ToJson();
            var page = Page.FromJson( json );
            Assert.NotNull( page.AttributeValues );
            Assert.NotEmpty( page.AttributeValues );
            Assert.Equal( page.AttributeValues.First().Value.Value, "baz" );
        }
Ejemplo n.º 15
0
        public void ImportAttributes()
        {
            var obj = new Page
            {
                InternalName = "Some Page",
                Attributes = new Dictionary<string, AttributeCache> { { "foobar", null } }
            };

            // the AttributeCacheJsonConverter won't convert null to AttributeCache
            var json = obj.ToJson().Replace( "\"foobar\": null", "\"foobar\": {}" );

            var page = Page.FromJson( json );
            Assert.NotNull( page.Attributes );
            Assert.NotEmpty( page.Attributes );
        }
Ejemplo n.º 16
0
        public void FromJson()
        {
            var obj = new Page
            {
                InternalName = "Foo Page",
                IsSystem = true,
            };

            string json = obj.ToJson();
            var page = Page.FromJson( json );
            Assert.Equal( obj.InternalName, page.InternalName );
            Assert.Equal( obj.IsSystem, page.IsSystem );
        }
Ejemplo n.º 17
0
        public void ExportChildPages()
        {
            var page = new Page
            {
                PageTitle = "FooPage",
                Pages = new List<Page> { new Page { PageTitle = "BarPage" } }
            };

            var result = page.ToJson();
            result = result.Substring( result.IndexOf( "\"Pages\":" ) + 7 );
            const string key = "\"PageTitle\": \"BarPage\"";
            Assert.NotEqual( result.IndexOf( key ), -1 );
        }
Ejemplo n.º 18
0
 public void ImportPageContexts()
 {
     Random random = new Random();
     var id = random.Next();
     var obj = new Page { InternalName = "Some Page" };
     obj.PageContexts.Add( new PageContext { PageId = id } );
     var json = obj.ToJson();
     var page = Page.FromJson( json );
     Assert.NotNull( page.PageContexts );
     Assert.NotEmpty( page.PageContexts );
     Assert.Equal( page.PageContexts.First().PageId, id );
 }
Ejemplo n.º 19
0
 public void ImportPageRoutes()
 {
     var obj = new Page { InternalName = "Some Page" };
     obj.PageRoutes.Add( new PageRoute { Route = "/some/route" } );
     var json = obj.ToJson();
     var page = Page.FromJson( json );
     Assert.NotNull( page.PageRoutes );
     Assert.NotEmpty( page.PageRoutes );
     Assert.Equal( page.PageRoutes.First().Route, obj.PageRoutes.First().Route );
 }
Ejemplo n.º 20
0
 public void ExportChildPagesRecursively()
 {
     var parent = new Page { PageTitle = "Parent" };
     var child = new Page { PageTitle = "Child" };
     var grandchild = new Page { PageTitle = "Grandchild" };
     parent.Pages = new List<Page> { child };
     child.Pages = new List<Page> { grandchild };
     var result = parent.ToJson();
     const string parentKey = "\"PageTitle\": \"Parent\"";
     const string childKey = "\"PageTitle\": \"Child\"";
     const string grandChildKey = "\"PageTitle\": \"Grandchild\"";
     Assert.NotEqual( result.IndexOf( parentKey ), -1 );
     Assert.NotEqual( result.IndexOf( childKey ), -1 );
     Assert.NotEqual( result.IndexOf( grandChildKey ), -1 );
 }