Пример #1
0
        private static void CleanupAllTestSiteCollections(ClientContext tenantContext)
        {
            string devSiteUrl = TestCommon.AppSetting("SPODevSiteUrl");

            var tenant = new Tenant(tenantContext);

            try
            {
                using (ClientContext cc = tenantContext.Clone(devSiteUrl))
                {
                    var sites = cc.Web.SiteSearch();

                    foreach (var site in sites)
                    {
                        if (site.Url.ToLower().Contains(sitecollectionNamePrefix.ToLower()))
                        {
                            tenant.DeleteSiteCollection(site.Url);
                        }
                    }
                }
            }
            catch
            { }
        }
Пример #2
0
        public void CrossSiteTransform_SameSite_OverwriteOffTest()
        {
            //Test Requires a test site
            using (var sourceClientContext = TestCommon.CreateClientContext(TestCommon.AppSetting("SPODevTeamSiteUrl")))
            {
                var pageTransformator = new PageTransformator(sourceClientContext);
                pageTransformator.RegisterObserver(new UnitTestLogObserver());

                var pages = sourceClientContext.Web.GetPages("wpp_with"); //Specific page - aim for one file

                foreach (var page in pages)
                {
                    PageTransformationInformation pti = new PageTransformationInformation(page)
                    {
                        // If target page exists, then overwrite it
                        Overwrite = false,

                        // Don't log test runs
                        SkipTelemetry = true,

                        TargetPagePrefix = "Converted_",
                    };

                    pti.MappingProperties["SummaryLinksToQuickLinks"] = "true";
                    pti.MappingProperties["UseCommunityScriptEditor"] = "true";

                    var result = Assert.ThrowsException <ArgumentException>(() =>
                    {
                        var result1 = pageTransformator.Transform(pti);
                        var result2 = pageTransformator.Transform(pti); //Run twice incase target site didnt have the file in the first place
                    });

                    Assert.IsTrue(result.Message.Contains("Not overwriting - there already exists a page with name"));
                }
            }
        }
        public void GetTermSetPathsTest()
        {
            using (var targetClientContext = TestCommon.CreateClientContext(TestCommon.AppSetting("SPOTargetSiteUrl")))
            {
                using (var sourceClientContext = TestCommon.CreateClientContext(TestCommon.AppSetting("SPODevSiteUrl")))
                {
                    TermTransformator termTransformator = new TermTransformator(null, sourceClientContext, targetClientContext);

                    // Target - Katchup - dc2cca62-cf9a-4a61-b672-4aa7d0b6a179
                    // Source - Categories - e757dcf5-f443-42e9-98c6-5842861099cb (site collection term set)
                    termTransformator.CacheTermsFromTermStore(
                        new Guid("e757dcf5-f443-42e9-98c6-5842861099cb"),
                        new Guid("dc2cca62-cf9a-4a61-b672-4aa7d0b6a179"), Guid.Empty, false);

                    var results = TermTransformator.GetAllTermsFromTermSet(new Guid("e757dcf5-f443-42e9-98c6-5842861099cb"), sourceClientContext);
                    foreach (var result in results)
                    {
                        Console.WriteLine($"ID: {result.Key} {result.Value.TermPath}");
                    }

                    Assert.IsTrue(results.Count > 0); //Super simple
                }
            }
        }
        public void CacheTermStoreSiteCollectionByNameTest()
        {
            using (var targetClientContext = TestCommon.CreateClientContext(TestCommon.AppSetting("SPOTargetSiteUrl")))
            {
                using (var sourceClientContext = TestCommon.CreateClientContext(TestCommon.AppSetting("SPODevSiteUrl")))
                {
                    TermTransformator termTransformator = new TermTransformator(null, sourceClientContext, targetClientContext);

                    // Target - Katchup - dc2cca62-cf9a-4a61-b672-4aa7d0b6a179
                    // Source - Categories - e757dcf5-f443-42e9-98c6-5842861099cb (site collection term set)
                    termTransformator.CacheTermsFromTermStore(
                        new Guid("e757dcf5-f443-42e9-98c6-5842861099cb"),
                        new Guid("dc2cca62-cf9a-4a61-b672-4aa7d0b6a179"), Guid.Empty, false);

                    // Need to have the term store populated values
                    var expectedLabel = "Announcements";
                    var result        = Cache.CacheManager.Instance.GetTransformTermCacheTermByName(sourceClientContext, expectedLabel);

                    Assert.IsTrue(result.Count > 0);

                    result.ForEach(o => Console.WriteLine("Cached Term: {0} {1} ", o.TermSetId, o.TermPath, o.TermLabel));
                }
            }
        }
        public void AssetTransfer_CopyAssetToTarget_LargeFileTest()
        {
            //Note: This is more of a system test rather than unit given its dependency on SharePoint

            using (var targetClientContext = TestCommon.CreateClientContext(TestCommon.AppSetting("SPOTargetSiteUrl")))
            {
                using (var sourceClientContext = TestCommon.CreateClientContext(TestCommon.AppSetting("SPODevTeamSiteUrl")))
                {
                    AssetTransfer assetTransfer = new AssetTransfer(sourceClientContext, targetClientContext);

                    // Very crude test - ensure the site is setup for this ahead of the test
                    // Note this file is not included in this project assets due to its licensing. Pls find a > 3MB file to use as a test.
                    var targetWebUrl = targetClientContext.Web.EnsureProperty(o => o.ServerRelativeUrl);
                    var sourceWebUrl = sourceClientContext.Web.EnsureProperty(o => o.ServerRelativeUrl);

                    var sourceFileServerRelativeUrl = $"{sourceWebUrl}/SiteImages/bigstock-Html-Web-Code-57446159.jpg";
                    var targetLocation = $"{targetWebUrl}/Shared%20Documents"; //Shared Documents for example, Site Assets may not exist on vanilla sites

                    assetTransfer.CopyAssetToTargetLocation(sourceFileServerRelativeUrl, targetLocation);
                }
            }

            Assert.Inconclusive(TestCommon.InconclusiveNoAutomatedChecksMessage);
        }
Пример #6
0
        public void CrossSiteBlogTransformTest()
        {
            using (var targetClientContext = TestCommon.CreateClientContext(TestCommon.AppSetting("SPOTargetSiteUrl")))
            {
                using (var sourceClientContext = TestCommon.CreateClientContext("https://bertonline.sharepoint.com/sites/modernizationtestpages/blog"))
                {
                    var pageTransformator = new PageTransformator(sourceClientContext, targetClientContext);
                    pageTransformator.RegisterObserver(new UnitTestLogObserver());

                    var pages = sourceClientContext.Web.GetBlogsFromList(CacheManager.Instance.GetBlogListName(sourceClientContext), "k");

                    foreach (var page in pages)
                    {
                        PageTransformationInformation pti = new PageTransformationInformation(page)
                        {
                            // If target page exists, then overwrite it
                            Overwrite = true,

                            // Don't log test runs
                            SkipTelemetry = true,

                            KeepPageCreationModificationInformation = true,

                            PostAsNews = true,

                            PublishCreatedPage = true,

                            CopyPageMetadata = true,

                            SetAuthorInPageHeader = true,

                            //TargetPageFolder = "Blogs",

                            //SkipUserMapping = true,

                            //AddTableListImageAsImageWebPart = true,

                            // ModernizationCenter options
                            //ModernizationCenterInformation = new ModernizationCenterInformation()
                            //{
                            //    AddPageAcceptBanner = true
                            //},

                            // Migrated page gets the name of the original page
                            //TargetPageTakesSourcePageName = true,

                            // Give the migrated page a specific prefix, default is Migrated_
                            //TargetPagePrefix = "Yes_",

                            // Configure the page header, empty value means ClientSidePageHeaderType.None
                            //PageHeader = new ClientSidePageHeader(cc, ClientSidePageHeaderType.None, null),

                            // If the page is a home page then replace with stock home page
                            //ReplaceHomePageWithDefaultHomePage = true,

                            // Replace embedded images and iframes with a placeholder and add respective images and video web parts at the bottom of the page
                            // HandleWikiImagesAndVideos = false,

                            // Callout to your custom code to allow for title overriding
                            //PageTitleOverride = titleOverride,

                            // Callout to your custom layout handler
                            //LayoutTransformatorOverride = layoutOverride,

                            // Callout to your custom content transformator...in case you fully want replace the model
                            //ContentTransformatorOverride = contentOverride,
                        };

                        pti.MappingProperties["SummaryLinksToQuickLinks"] = "true";
                        pti.MappingProperties["UseCommunityScriptEditor"] = "true";

                        var result = pageTransformator.Transform(pti);
                    }
                }
            }

            //Assert.Inconclusive(TestCommon.InconclusiveNoAutomatedChecksMessage);
        }
Пример #7
0
        public void CrossSiteDelveTransformTest()
        {
            using (var targetClientContext = TestCommon.CreateClientContext(TestCommon.AppSetting("SPOTargetSiteUrl")))
            {
                using (var sourceClientContext = TestCommon.CreateClientContext("https://bertonline.sharepoint.com/portals/personal/bertjansen"))
                {
                    var pageTransformator = new DelvePageTransformator(sourceClientContext, targetClientContext);
                    pageTransformator.RegisterObserver(new UnitTestLogObserver());

                    var pages = sourceClientContext.Web.GetBlogsFromList("Pages", "Delve");

                    foreach (var page in pages)
                    {
                        DelvePageTransformationInformation pti = new DelvePageTransformationInformation(page)
                        {
                            // If target page exists, then overwrite it
                            Overwrite = true,

                            // Don't log test runs
                            SkipTelemetry = true,

                            KeepPageCreationModificationInformation = true,

                            SetAuthorInPageHeader = true,

                            PostAsNews = true,

                            PublishCreatedPage = true,

                            KeepSubTitle = true,

                            //TargetPageFolder = "Blogs",

                            //SkipUserMapping = true,

                            //AddTableListImageAsImageWebPart = true,

                            // Configure the page header, empty value means ClientSidePageHeaderType.None
                            //PageHeader = new ClientSidePageHeader(cc, ClientSidePageHeaderType.None, null),

                            // Replace embedded images and iframes with a placeholder and add respective images and video web parts at the bottom of the page
                            // HandleWikiImagesAndVideos = false,

                            // Callout to your custom code to allow for title overriding
                            //PageTitleOverride = titleOverride,

                            // Callout to your custom layout handler
                            //LayoutTransformatorOverride = layoutOverride,

                            // Callout to your custom content transformator...in case you fully want replace the model
                            //ContentTransformatorOverride = contentOverride,
                        };

                        pti.MappingProperties["SummaryLinksToQuickLinks"] = "true";
                        pti.MappingProperties["UseCommunityScriptEditor"] = "true";

                        var result = pageTransformator.Transform(pti);
                    }
                }
            }

            //Assert.Inconclusive(TestCommon.InconclusiveNoAutomatedChecksMessage);
        }
Пример #8
0
        public void OnPremises_WebExtensions_GetSitePages()
        {
            using (var sourceClientContext = TestCommon.CreateOnPremisesClientContext(TestCommon.AppSetting("SPOnPremTeamSiteUrl")))
            {
                var result = sourceClientContext.Web.GetSitePagesLibrary();

                Assert.IsNotNull(result);
                Assert.AreNotEqual(default(List), result);
            }
        }
Пример #9
0
        /// <summary>
        /// Different page same test conditions
        /// </summary>
        /// <param name="pageName"></param>
        private void PageToTransform(string pageName)
        {
            using (var targetClientContext = TestCommon.CreateClientContext(TestCommon.AppSetting("SPOTargetSiteUrl")))
            {
                using (var sourceClientContext = TestCommon.CreateOnPremisesClientContext(TestCommon.AppSetting("SPOnPremTeamSiteUrl")))
                {
                    var pageTransformator = new PageTransformator(sourceClientContext, targetClientContext);
                    pageTransformator.RegisterObserver(new MarkdownObserver(folder: "c:\\temp", includeVerbose: true));
                    pageTransformator.RegisterObserver(new UnitTestLogObserver());

                    var pages = sourceClientContext.Web.GetPages(pageName);

                    pages.FailTestIfZero();

                    foreach (var page in pages)
                    {
                        PageTransformationInformation pti = new PageTransformationInformation(page)
                        {
                            // If target page exists, then overwrite it
                            Overwrite = true,

                            // Don't log test runs
                            SkipTelemetry = true,

                            //Permissions are unlikely to work given cross domain
                            KeepPageSpecificPermissions = false,
                        };

                        pti.MappingProperties["SummaryLinksToQuickLinks"] = "true";
                        pti.MappingProperties["UseCommunityScriptEditor"] = "true";

                        var result = pageTransformator.Transform(pti);
                    }

                    pageTransformator.FlushObservers();

                    //TODO: Add Target Site Page Creation Checking
                }
            }
        }
Пример #10
0
 /// <summary>
 /// Note: this test will only work if the files are present at the parts of the sharepoint site
 /// and the source site originates from a sub site
 /// </summary>
 /// <param name="url"></param>
 private void AssetTransferOfAsset(string url)
 {
     AssetTransferOfAsset(url, TestCommon.AppSetting("SPODevSiteUrl"));
 }
Пример #11
0
        public void WebServiceFallBackGetChildTermsTest()
        {
            using (var sourceClientContext = TestCommon.CreateOnPremisesClientContext(TestCommon.AppSetting("SPOnPremTeamSiteUrl")))
            {
                var sspId     = "bf53dc87-0092-47bf-8463-ee69cde66b93";
                var termSetId = "5e8a3614-8777-4eb0-9890-e3a6ac466396"; //SP2010
                var termId    = "abeeb936-3ab9-40ce-aba1-a2e236c915d3";
                var path      = "UNIT|TEST";

                // Need to have the term store populated values
                // Announcements
                var results = TermTransformator.CallTaxonomyWebServiceFindChildTerms(sourceClientContext, new Guid(sspId), new Guid(termSetId), new Guid(termId), path);
                foreach (var result in results)
                {
                    Console.WriteLine("{0} - {1}", result.Key, result.Value.TermPath);
                }

                Assert.IsTrue(results != default);
                Assert.IsTrue(results.Count > 0);
            }
        }
Пример #12
0
        private static string CreateTestSiteCollection(Tenant tenant, string sitecollectionName, bool isNoScriptSite = false)
        {
            string devSiteUrl = TestCommon.AppSetting("SPODevSiteUrl");

            string siteOwnerLogin = string.Format("{0}\\{1}", TestCommon.AppSetting("OnPremDomain"), TestCommon.AppSetting("OnPremUserName"));

            if (TestCommon.AppOnlyTesting())
            {
                using (var clientContext = TestCommon.CreateClientContext())
                {
                    List <UserEntity> admins = clientContext.Web.GetAdministrators();
                    siteOwnerLogin = admins[0].LoginName.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries)[1];
                }
            }

            string     siteToCreateUrl = GetTestSiteCollectionName(devSiteUrl, sitecollectionName);
            SiteEntity siteToCreate    = new SiteEntity()
            {
                Url            = siteToCreateUrl,
                Template       = "STS#0",
                Title          = "Test",
                Description    = "Test site collection",
                SiteOwnerLogin = siteOwnerLogin,
                Lcid           = 1033,
            };

            tenant.CreateSiteCollection(siteToCreate);

            // Create the default groups
            using (ClientContext cc = TestCommon.CreateClientContext(siteToCreateUrl))
            {
                var owners   = cc.Web.AddGroup("Test Owners", "", true, false);
                var members  = cc.Web.AddGroup("Test Members", "", true, false);
                var visitors = cc.Web.AddGroup("Test Visitors", "", true, true);

                cc.Web.AssociateDefaultGroups(owners, members, visitors);
            }

            return(siteToCreateUrl);
        }
Пример #13
0
        public void CrossSiteTransformTest()
        {
            using (var targetClientContext = TestCommon.CreateClientContext(TestCommon.AppSetting("SPOTargetSiteUrl")))
            {
                using (var sourceClientContext = TestCommon.CreateClientContext())
                {
                    var pageTransformator = new PageTransformator(sourceClientContext, targetClientContext);

                    var pages = sourceClientContext.Web.GetPages("wp_");

                    foreach (var page in pages)
                    {
                        PageTransformationInformation pti = new PageTransformationInformation(page)
                        {
                            // If target page exists, then overwrite it
                            Overwrite = true,

                            // Don't log test runs
                            SkipTelemetry = true,

                            // ModernizationCenter options
                            //ModernizationCenterInformation = new ModernizationCenterInformation()
                            //{
                            //    AddPageAcceptBanner = true
                            //},

                            // Migrated page gets the name of the original page
                            //TargetPageTakesSourcePageName = true,

                            // Give the migrated page a specific prefix, default is Migrated_
                            //TargetPagePrefix = "Yes_",

                            // Configure the page header, empty value means ClientSidePageHeaderType.None
                            //PageHeader = new ClientSidePageHeader(cc, ClientSidePageHeaderType.None, null),

                            // If the page is a home page then replace with stock home page
                            //ReplaceHomePageWithDefaultHomePage = true,

                            // Replace embedded images and iframes with a placeholder and add respective images and video web parts at the bottom of the page
                            // HandleWikiImagesAndVideos = false,

                            // Callout to your custom code to allow for title overriding
                            //PageTitleOverride = titleOverride,

                            // Callout to your custom layout handler
                            //LayoutTransformatorOverride = layoutOverride,

                            // Callout to your custom content transformator...in case you fully want replace the model
                            //ContentTransformatorOverride = contentOverride,
                        };

                        pti.MappingProperties["SummaryLinksToQuickLinks"] = "true";
                        pti.MappingProperties["UseCommunityScriptEditor"] = "true";

                        var result = pageTransformator.Transform(pti);
                    }
                }
            }

            //Assert.Inconclusive(TestCommon.InconclusiveNoAutomatedChecksMessage);
        }
        public void Initialize()
        {
#if !ONPREMISES
            _userLogin = TestCommon.AppSetting("SPOUserName");
            if (TestCommon.AppOnlyTesting())
            {
                using (var clientContext = TestCommon.CreateClientContext())
                {
                    List <UserEntity> admins = clientContext.Web.GetAdministrators();
                    _userLogin = admins[0].LoginName.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries)[2];
                }
            }
#else
            _userLogin = String.Format(@"{0}\{1}", TestCommon.AppSetting("OnPremDomain"), TestCommon.AppSetting("OnPremUserName"));
            if (TestCommon.AppOnlyTesting())
            {
                using (var clientContext = TestCommon.CreateClientContext())
                {
                    List <UserEntity> admins = clientContext.Web.GetAdministrators();
                    _userLogin = admins[0].LoginName.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries)[1];
                }
            }
#endif

            using (ClientContext clientContext = TestCommon.CreateClientContext())
            {
                clientContext.Web.AddGroup(_testGroupName, "", true, true);
            }
        }
        public void BasicPublishingPageTest()
        {
            using (var targetClientContext = TestCommon.CreateClientContext(TestCommon.AppSetting("SPOTargetSiteUrl")))
            {
                //https://bertonline.sharepoint.com/sites/modernizationtestportal
                using (var sourceClientContext = TestCommon.CreateClientContext("https://bertonline.sharepoint.com/sites/devportal/en-us"))
                {
                    //"C:\github\sp-dev-modernization\Tools\SharePoint.Modernization\PnP.Framework.Modernization.Tests\Transform\Publishing\custompagelayoutmapping.xml"
                    //"C:\temp\mappingtest.xml"
                    //@"C:\github\sp-dev-modernization\Tools\SharePoint.Modernization\PnP.Framework.Modernization.Tests\Transform\Publishing\webpartmapping.xml"
                    //var pageTransformator = new PublishingPageTransformator(sourceClientContext, targetClientContext, @"C:\github\sp-dev-modernization\Tools\SharePoint.Modernization\PnP.Framework.Modernization.Tests\Transform\Publishing\webpartmapping.xml", @"C:\github\sp-dev-modernization\Tools\SharePoint.Modernization\PnP.Framework.Modernization.Tests\Transform\Publishing\custompagelayoutmapping.xml");
                    var pageTransformator = new PublishingPageTransformator(sourceClientContext, targetClientContext, @"D:\github\pnpframework\src\lib\PnP.Framework.Modernization.Test\Transform\Publishing\custompagelayoutmapping.xml");
                    pageTransformator.RegisterObserver(new MarkdownObserver(folder: "d:\\temp", includeVerbose: true));
                    //pageTransformator.RegisterObserver(new MarkdownToSharePointObserver(targetClientContext, includeVerbose: true));

                    var pages = sourceClientContext.Web.GetPagesFromList("Pages", "volvo");
                    //var pages = sourceClientContext.Web.GetPagesFromList("Pages", folder:"News");

                    foreach (var page in pages)
                    {
                        PublishingPageTransformationInformation pti = new PublishingPageTransformationInformation(page)
                        {
                            // If target page exists, then overwrite it
                            Overwrite = true,

                            // Don't log test runs
                            SkipTelemetry = true,

                            KeepPageCreationModificationInformation = true,

                            PostAsNews = true,

                            TermMappingFile = @"D:\github\pnpframework\src\lib\PnP.Framework.Modernization.Test\Transform\Mapping\termmapping_sample2.csv",

                            UrlMappingFile = @"D:\github\pnpframework\src\lib\PnP.Framework.Modernization.Test\Transform\Mapping\urlmapping_sample.csv",

                            UserMappingFile = @"D:\github\pnpframework\src\lib\PnP.Framework.Modernization.Test\Transform\Mapping\usermapping_sample2.csv",

                            DisablePageComments = true,

                            PublishCreatedPage = true,

                            //RemoveEmptySectionsAndColumns = false,

                            // Configure the page header, empty value means ClientSidePageHeaderType.None
                            //PageHeader = new ClientSidePageHeader(cc, ClientSidePageHeaderType.None, null),

                            // Replace embedded images and iframes with a placeholder and add respective images and video web parts at the bottom of the page
                            // HandleWikiImagesAndVideos = false,

                            // Callout to your custom code to allow for title overriding
                            //PageTitleOverride = titleOverride,

                            // Callout to your custom layout handler
                            //LayoutTransformatorOverride = layoutOverride,

                            // Callout to your custom content transformator...in case you fully want replace the model
                            //ContentTransformatorOverride = contentOverride,
                        };

                        pti.MappingProperties["SummaryLinksToQuickLinks"] = "true";
                        pti.MappingProperties["UseCommunityScriptEditor"] = "true";

                        var result = pageTransformator.Transform(pti);
                    }

                    pageTransformator.FlushObservers();
                }
            }
        }
Пример #16
0
        public void BasicOnPremWikiPage_TermMappingPathsOnlyTest()
        {
            using (var targetClientContext = TestCommon.CreateClientContext(TestCommon.AppSetting("SPOTargetSiteUrl")))
            {
                using (var sourceClientContext = TestCommon.CreateOnPremisesClientContext(TestCommon.AppSetting("SPOnPremTeamSiteUrl")))
                {
                    var pageTransformator = new PageTransformator(sourceClientContext, targetClientContext);
                    //pageTransformator.RegisterObserver(new MarkdownObserver(folder: "c:\\temp", includeVerbose: true));
                    pageTransformator.RegisterObserver(new UnitTestLogObserver());

                    //SP2010
                    var pages = sourceClientContext.Web.GetPagesFromList("Site Pages", pageNameStartsWith: "WKP-2010-Quantum");

                    pages.FailTestIfZero();

                    foreach (var page in pages)
                    {
                        PageTransformationInformation pti = new PageTransformationInformation(page)
                        {
                            // If target page exists, then overwrite it
                            Overwrite = true,

                            // Don't log test runs
                            SkipTelemetry = true,

                            //Permissions are unlikely to work given cross domain
                            KeepPageSpecificPermissions = false,

                            // Term store mapping
                            TermMappingFile = @"..\..\Transform\Mapping\term_mapping_paths_sample.csv",

                            //Should process default mapping
                            SkipTermStoreMapping = false,

                            CopyPageMetadata = true
                        };

                        Console.WriteLine("SharePoint Version: {0}", pti.SourceVersion);

                        pti.MappingProperties["SummaryLinksToQuickLinks"] = "true";
                        pti.MappingProperties["UseCommunityScriptEditor"] = "true";

                        var result = pageTransformator.Transform(pti);
                    }

                    pageTransformator.FlushObservers();
                }
            }
        }
        private static string CreateTestSiteCollection(Tenant tenant, string sitecollectionName)
        {
            string devSiteUrl = TestCommon.AppSetting("SPODevSiteUrl");

            string siteOwnerLogin = string.Format("{0}\\{1}", TestCommon.AppSetting("OnPremDomain"), TestCommon.AppSetting("OnPremUserName"));

            if (TestCommon.AppOnlyTesting())
            {
                using (var clientContext = TestCommon.CreateClientContext())
                {
                    List <UserEntity> admins = clientContext.Web.GetAdministrators();
                    siteOwnerLogin = admins[0].LoginName.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries)[1];
                }
            }

            string     siteToCreateUrl = GetTestSiteCollectionName(devSiteUrl, sitecollectionName);
            SiteEntity siteToCreate    = new SiteEntity()
            {
                Url            = siteToCreateUrl,
                Template       = "STS#0",
                Title          = "Test",
                Description    = "Test site collection",
                SiteOwnerLogin = siteOwnerLogin,
            };

            tenant.CreateSiteCollection(siteToCreate);
            return(siteToCreateUrl);
        }
        public void BasicOnPremPublishingPageTest()
        {
            using (var targetClientContext = TestCommon.CreateClientContext(TestCommon.AppSetting("SPOTargetSiteUrl")))
            {
                using (var sourceClientContext = TestCommon.CreateOnPremisesClientContext())
                {
                    //"C:\github\sp-dev-modernization\Tools\SharePoint.Modernization\SharePointPnP.Modernization.Framework.Tests\Transform\Publishing\custompagelayoutmapping.xml"
                    //"C:\temp\onprem-mapping-all-test.xml.xml"
                    var pageTransformator = new PublishingPageTransformator(sourceClientContext, targetClientContext, @"C:\temp\onprem-mapping-all-test.xml");
                    pageTransformator.RegisterObserver(new MarkdownObserver(folder: "c:\\temp", includeVerbose: true));
                    pageTransformator.RegisterObserver(new UnitTestLogObserver());

                    //var pages = sourceClientContext.Web.GetPagesFromList("Pages", "Article-2010-Custom");
                    //var pages = sourceClientContext.Web.GetPagesFromList("Pages", "ArticlePage-2010-Multiple");
                    //var pages = sourceClientContext.Web.GetPagesFromList("Pages", "Article-2010-Custom-Test3");
                    //var pages = sourceClientContext.Web.GetPagesFromList("Pages", folder:"News");
                    //var pages = sourceClientContext.Web.GetPagesFromList("Pages", "Welcome-2013Legacy");
                    var pages = sourceClientContext.Web.GetPagesFromList("Pages", "Welcome-SP2013");

                    pages.FailTestIfZero();

                    foreach (var page in pages)
                    {
                        PublishingPageTransformationInformation pti = new PublishingPageTransformationInformation(page)
                        {
                            // If target page exists, then overwrite it
                            Overwrite = true,

                            // Don't log test runs
                            SkipTelemetry = true,

                            //Permissions are unlikely to work given cross domain
                            KeepPageSpecificPermissions = false,

                            //RemoveEmptySectionsAndColumns = false,

                            // Configure the page header, empty value means ClientSidePageHeaderType.None
                            //PageHeader = new ClientSidePageHeader(cc, ClientSidePageHeaderType.None, null),

                            // Replace embedded images and iframes with a placeholder and add respective images and video web parts at the bottom of the page
                            // HandleWikiImagesAndVideos = false,

                            // Callout to your custom code to allow for title overriding
                            //PageTitleOverride = titleOverride,

                            // Callout to your custom layout handler
                            //LayoutTransformatorOverride = layoutOverride,

                            // Callout to your custom content transformator...in case you fully want replace the model
                            //ContentTransformatorOverride = contentOverride,
                            //SkipUrlRewrite = true
                        };

                        Console.WriteLine("SharePoint Version: {0}", pti.SourceVersion);

                        pti.MappingProperties["SummaryLinksToQuickLinks"] = "true";
                        pti.MappingProperties["UseCommunityScriptEditor"] = "true";

                        var result = pageTransformator.Transform(pti);
                    }

                    pageTransformator.FlushObservers();
                }
            }
        }
        private void DumpTemplate(ClientContext ctx, string template, string subSiteTemplate = "", string saveAsTemplate = "")
        {
            Uri    devSiteUrl = new Uri(TestCommon.AppSetting("SPODevSiteUrl"));
            string baseUrl    = String.Format("{0}://{1}", devSiteUrl.Scheme, devSiteUrl.DnsSafeHost);

            string siteUrl = "";

            if (subSiteTemplate.Length > 0)
            {
                siteUrl = string.Format("{1}/sites/template{0}/template{2}", template.Replace("#", ""), baseUrl, subSiteTemplate.Replace("#", ""));
#if !ONPREMISES
                var siteCollectionUrl = string.Format("{1}/sites/template{0}", template.Replace("#", ""), baseUrl);
                CreateSiteCollection(template, siteCollectionUrl);
                using (var sitecolCtx = ctx.Clone(siteCollectionUrl))
                {
                    sitecolCtx.Web.Webs.Add(new WebCreationInformation()
                    {
                        Title    = string.Format("template{0}", subSiteTemplate),
                        Language = 1033,
                        Url      = string.Format("template{0}", subSiteTemplate.Replace("#", "")),
                        UseSamePermissionsAsParentSite = true
                    });
                    sitecolCtx.ExecuteQueryRetry();
                }
#endif
            }
            else
            {
                siteUrl = string.Format("{1}/sites/template{0}", template.Replace("#", ""), baseUrl);
#if !ONPREMISES
                CreateSiteCollection(template, siteUrl);
#endif
            }

            using (ClientContext cc = ctx.Clone(siteUrl))
            {
                // Specify null as base template since we do want "everything" in this case
                ProvisioningTemplateCreationInformation creationInfo = new ProvisioningTemplateCreationInformation(cc.Web);
                creationInfo.BaseTemplate = null;
                // Do not extract the home page for the base templates
                creationInfo.HandlersToProcess ^= Handlers.PageContents;

                // Override the save name. Case is online site collection provisioned using blankinternetcontainer#0 which returns
                // blankinternet#0 as web template using CSOM/SSOM API
                if (saveAsTemplate.Length > 0)
                {
                    template = saveAsTemplate;
                }

                ProvisioningTemplate p = cc.Web.GetProvisioningTemplate(creationInfo);
                if (subSiteTemplate.Length > 0)
                {
                    p.Id = String.Format("{0}template", subSiteTemplate.Replace("#", ""));
                }
                else
                {
                    p.Id = String.Format("{0}template", template.Replace("#", ""));
                }

                // Cleanup before saving
                p.Security.AdditionalAdministrators.Clear();


                XMLFileSystemTemplateProvider provider = new XMLFileSystemTemplateProvider(".", "");
                if (subSiteTemplate.Length > 0)
                {
                    provider.SaveAs(p, String.Format("{0}Template.xml", subSiteTemplate.Replace("#", "")));
                }
                else
                {
                    provider.SaveAs(p, String.Format("{0}Template.xml", template.Replace("#", "")));
                }

#if !ONPREMISES
                using (var tenantCtx = TestCommon.CreateTenantClientContext())
                {
                    Tenant tenant = new Tenant(tenantCtx);
                    Console.WriteLine("Deleting new site {0}", string.Format("{1}/sites/template{0}", template.Replace("#", ""), baseUrl));
                    tenant.DeleteSiteCollection(siteUrl, false);
                }
#endif
            }
        }