コード例 #1
0
        public void PageLayoutAnalyse_AspxHeaderAndNameSpaces()
        {
            using (var sourceClientContext = TestCommon.CreateClientContext())
            {
                // Source Context could be a site collection
                ClientContext contextToUse;
                if (sourceClientContext.Web.IsSubSite())
                {
                    string siteCollectionUrl = sourceClientContext.Site.EnsureProperty(o => o.Url);
                    contextToUse = sourceClientContext.Clone(siteCollectionUrl);
                }
                else
                {
                    contextToUse = sourceClientContext;
                }

                var pageLayoutAnalyser = new PageLayoutAnalyser(sourceClientContext);
                pageLayoutAnalyser.RegisterObserver(new UnitTestLogObserver());

                var layout = contextToUse.Web.GetFileByServerRelativeUrl($"{contextToUse.Web.EnsureProperty(o => o.ServerRelativeUrl)}/_catalogs/masterpage/ArticleCustom.aspx");

                var results = new List <Tuple <string, string> >();
                if (layout != null)
                {
                    ListItem item = layout.EnsureProperty(o => o.ListItemAllFields);

                    results.AddRange(pageLayoutAnalyser.ExtractWebPartPrefixesFromNamespaces(item));
                }
                else
                {
                    Assert.Fail("Layout file is missing, upload ArticleCustom.aspx as a page layout and publish the file");
                }

                Assert.IsTrue(results.Count > 0);
            }
        }