示例#1
0
 public void GetAppAccessTokenTest()
 {
     using (var scope = new PSTestScope(true))
     {
         using (var ctx = TestCommon.CreateClientContext())
         {
             var results = scope.ExecuteCommand("Get-PnPAppAuthAccessToken");
             if (TestCommon.AppOnlyTesting())
             {
                 Assert.IsTrue(results.Any());
             }
             else
             {
                 // If not testing in app only, the test passes
                 Assert.IsTrue(true);
             }
         }
     }
 }
        public void AddContentTypeTest()
        {
            using (var scope = new PSTestScope(true))
            {
                var results = scope.ExecuteCommand("Add-PnPContentType",
                                                   new CommandParameter("Name", CTName4),
                                                   new CommandParameter("Group", "UnitTestCTGroup"));

                Assert.IsTrue(results.Any());
                Assert.IsTrue(results[0].BaseObject.GetType() == typeof(Microsoft.SharePoint.Client.ContentType));

                using (var ctx = TestCommon.CreateClientContext())
                {
                    var ct = ctx.Web.GetContentTypeByName(CTName4);
                    ct.DeleteObject();
                    ctx.ExecuteQueryRetry();
                }
            }
        }
示例#3
0
        public void NewListHiddenTest()
        {
            using (var scope = new PSTestScope(true))
            {
                scope.ExecuteCommand("New-PnPList",
                                     new CommandParameter("Title", "PnPTestListHidden1"),
                                     new CommandParameter("Template", ListTemplateType.GenericList),
                                     new CommandParameter("Hidden"));
            }

            using (var ctx = TestCommon.CreateClientContext())
            {
                var list = ctx.Web.GetListByTitle("PnPTestListHidden1");
                Assert.IsTrue(list.Hidden);

                list.DeleteObject();
                ctx.ExecuteQueryRetry();
            }
        }
示例#4
0
        public void InvokeWebActionWebActionWithSubWebs()
        {
            using (var scope = new PSTestScope(true))
            {
                List <Guid>   ids    = new List <Guid>();
                List <string> titles = new List <string>();

                using (var context = TestCommon.CreateClientContext())
                {
                    SetupSubWebs(context.Web, false);
                }

                Action <Web> webAction = web =>
                {
                    ids.Add(web.Id);
                    titles.Add(web.Title);
                };

                var results = scope.ExecuteCommand("Invoke-PnPWebAction",
                                                   new CommandParameter("WebAction", webAction),
                                                   new CommandParameter("WebProperties", new[] { "Id", "Title" }),
                                                   new CommandParameter("SubWebs", true)
                                                   );

                using (var context = TestCommon.CreateClientContext())
                {
                    DeleteSubWebs(context.Web);
                }

                Assert.IsTrue(ids.Count == 8, "Wrong count on ids");

                foreach (var item in ids)
                {
                    Assert.IsTrue(item != Guid.Empty, "Id is empty");
                }

                InvokeWebActionResult result = results.Last().BaseObject as InvokeWebActionResult;

                AssertInvokeActionResult(result,
                                         processedWebCount: 8
                                         );
            }
        }
 public void GetDataRowsFromListNoFields()
 {
     using (var scope = new PSTestScope(true))
     {
         var filePath = CreateUniqueCopyOfTemplateFile(@"Resources\PnPTestList.xml");
         try
         {
             var results = scope.ExecuteCommand("Add-PnPDataRowsToProvisioningTemplate",
                                                new CommandParameter("Path", filePath),
                                                new CommandParameter("List", "PnPTestList"),
                                                new CommandParameter("Query", "<View></View>")
                                                );
             var template = GetTemplateFromXmlFile(filePath);
             Assert.AreEqual(10, template.Lists[0].DataRows.Count);
         } finally
         {
             System.IO.File.Delete(filePath);
         }
     }
 }
        public void SetClientSidePageTest()
        {
            using (var scope = new PSTestScope(true))
            {
                using (var ctx = TestCommon.CreateClientContext())
                {
                    ctx.Web.AddClientSidePage(PageSetTestName, true);


                    var results = scope.ExecuteCommand("Set-PnPClientSidePage",
                                                       new CommandParameter("Identity", PageSetTestName),
                                                       new CommandParameter("LayoutType", ClientSidePageLayoutType.Home),
                                                       new CommandParameter("Name", PageSet2TestName));

                    var page = ClientSidePage.Load(ctx, PageSet2TestName);

                    Assert.IsTrue(page.LayoutType == ClientSidePageLayoutType.Home);
                }
            }
        }
        public void AddClientSidePageSectionTest()
        {
            using (var scope = new PSTestScope(true))
            {
                using (var ctx = TestCommon.CreateClientContext())
                {
                    ctx.Web.AddClientSidePage(PageAddSectionTestName, true);


                    var results = scope.ExecuteCommand("Add-PnPClientSidePageSection",
                                                       new CommandParameter("Page", PageAddSectionTestName),
                                                       new CommandParameter("SectionTemplate", CanvasSectionTemplate.ThreeColumn),
                                                       new CommandParameter("Order", 10));

                    var page = ClientSidePage.Load(ctx, PageAddSectionTestName);

                    Assert.IsTrue(page.Sections[0].Columns.Count == 3);
                }
            }
        }
示例#8
0
        public void GetListItemTest()
        {
            using (var ctx = TestCommon.CreateClientContext())
            {
                var list = ctx.Web.GetListByTitle("PnPTestList");
                var item = list.AddItem(new ListItemCreationInformation());
                item["Title"] = "Test";
                item.Update();

                ctx.ExecuteQueryRetry();
            }
            using (var scope = new PSTestScope(true))
            {
                var results = scope.ExecuteCommand("Get-PnPListItem",
                                                   new CommandParameter("List", "PnPTestList"));

                Assert.IsTrue(results.Count > 0);
                Assert.IsTrue(results[0].BaseObject.GetType() == typeof(Microsoft.SharePoint.Client.ListItem));
            }
        }
        public void SetAllowAllPageLayoutsTest()
        {
            using (var context = TestCommon.CreateClientContext())
            {
                // Arrange

                using (var scope = new PSTestScope(true))
                {
                    // Act
                    var results = scope.ExecuteCommand("Set-PnPAvailablePageLayouts",
                                                       new CommandParameter("AllowAllPageLayouts"));

                    var pageLayouts = context.Web.GetPropertyBagValueString(
                        "__PageLayouts", string.Empty);

                    // Assert
                    Assert.IsTrue(string.IsNullOrWhiteSpace(pageLayouts));
                }
            }
        }
        public void SetDefaultContentTypeToListTest()
        {
            using (var scope = new PSTestScope(true))
            {
                if (!ctList.ContentTypeExistsByName(CTName2))
                {
                    ctList.AddContentTypeToListByName(CTName2, false, true);
                }

                var results = scope.ExecuteCommand("Set-PnPDefaultContentTypeToList",
                                                   new CommandParameter("List", ListName),
                                                   new CommandParameter("ContentType", CTName2));

                ctList.RefreshLoad();
                ctList.Context.Load(ctList, l => l.ContentTypes.Include(c => c.Name));
                ctList.Context.ExecuteQueryRetry();

                var name = ctList.ContentTypes[0].Name;
                Assert.IsTrue(name == CTName2);
            }
        }
示例#11
0
        public void SetListHiddenTest()
        {
            using (var ctx = TestCommon.CreateClientContext())
            {
                ctx.Web.CreateList(ListTemplateType.GenericList, "PnPTestListHidden2", false);

                using (var scope = new PSTestScope(true))
                {
                    scope.ExecuteCommand("Set-PnPList",
                                         new CommandParameter("Identity", "PnPTestListHidden2"),
                                         new CommandParameter("Hidden", true)
                                         );
                }

                var list = ctx.Web.GetListByTitle("PnPTestListHidden2");
                Assert.IsTrue(list.Hidden);

                list.DeleteObject();
                ctx.ExecuteQueryRetry();
            }
        }
        public void GetJavaScriptLinkTest()
        {
            using (var scope = new PSTestScope(true))
            {
                scope.ExecuteCommand("Add-PnPJavascriptLink",
                                     new CommandParameter("Key", "TestJavascriptLink"),
                                     new CommandParameter("Url", "https://testserver.com/testtojavascriptlink.js"));

                var results = scope.ExecuteCommand("Get-PnPJavaScriptLink");

                Assert.IsTrue(results.Any());

                using (var context = TestCommon.CreateClientContext())
                {
                    var actions = context.Web.GetCustomActions().Where(c => c.Location == "ScriptLink" && c.Name == "TestJavascriptLink");

                    actions.FirstOrDefault().DeleteObject();
                    context.ExecuteQueryRetry();
                }
            }
        }
        public void AddContentTypeWithIdTest()
        {
            using (var scope = new PSTestScope(true))
            {
                var results = scope.ExecuteCommand("Add-PnPContentType",
                                                   new CommandParameter("Name", CTName4),
                                                   new CommandParameter("Description", "This is the description of the content type"),
                                                   new CommandParameter("ContentTypeID", "0x01010010AFE1111D664A55B9D45F9712E7B827"),
                                                   new CommandParameter("Group", "UnitTestCTGroup"));

                Assert.IsTrue(results.Any());
                Assert.IsTrue(results[0].BaseObject.GetType() == typeof(Microsoft.SharePoint.Client.ContentType));

                using (var ctx = TestCommon.CreateClientContext())
                {
                    var ct = ctx.Web.GetContentTypeByName(CTName4);
                    ct.DeleteObject();
                    ctx.ExecuteQueryRetry();
                }
            }
        }
示例#14
0
        public void CopyFile_FolderWithFoldersAndEmptyFolderBetweenSiteCollections_Test()
        {
            using (var scope = new PSTestScope(_site1Url, true))
            {
                var sourceUrl      = $"{Site1RelativeFolderUrl}/{SourceFolderWithFolders}";
                var destinationUrl = $"{Site2RelativeFolderUrl}";

                var results = scope.ExecuteCommand("Copy-PnPFile",
                                                   new CommandParameter("SourceUrl", sourceUrl),
                                                   new CommandParameter("TargetUrl", destinationUrl),
                                                   new CommandParameter("Force"));

                using (var ctx = TestCommon.CreateClientContext(_site2Url))
                {
                    List list = ctx.Web.GetListUsingPath(ResourcePath.FromDecodedUrl(destinationUrl));
                    ctx.Load(list);
                    ctx.ExecuteQuery();
                    Assert.AreEqual(5, list.ItemCount);
                }
            }
        }
示例#15
0
        public void SetWebPartPropertyTest()
        {
            using (var scope = new PSTestScope(true))
            {
                using (var ctx = TestCommon.CreateClientContext())
                {
                    var results = scope.ExecuteCommand("Add-PnPWebPartToWikiPage",
                                                       new CommandParameter("ServerRelativePageUrl", serverRelativeHomePageUrl),
                                                       new CommandParameter("Path", "..\\..\\Resources\\webpart.xml"),
                                                       new CommandParameter("Row", 1),
                                                       new CommandParameter("Column", 1));


                    Assert.IsFalse(results.Any());

                    var wps = ctx.Web.GetWebParts(serverRelativeHomePageUrl);

                    foreach (var wp in wps)
                    {
                        if (wp.WebPart.Title == "Get started with your site")
                        {
                            results = scope.ExecuteCommand("Set-PnPWebPartProperty",
                                                           new CommandParameter("ServerRelativePageUrl", serverRelativeHomePageUrl),
                                                           new CommandParameter("Identity", wp.Id),
                                                           new CommandParameter("Key", "Title"),
                                                           new CommandParameter("Value", "TESTTESTTEST"));

                            Assert.IsFalse(results.Any());

                            results = scope.ExecuteCommand("Remove-PnPWebPart",
                                                           new CommandParameter("ServerRelativePageUrl", serverRelativeHomePageUrl),
                                                           new CommandParameter("Title", "TESTTESTTEST"));
                            Assert.IsFalse(results.Any());

                            break;
                        }
                    }
                }
            }
        }
示例#16
0
        public void InvokeWebActionListItemActionWithSkipCounting()
        {
            using (var scope = new PSTestScope(true))
            {
                List <string> listItemTitles = new List <string>();

                Action <ListItem> listItemAction = listItem =>
                {
                    listItemTitles.Add(listItem["Title"]?.ToString());
                };

                Func <List, bool> shouldProcessListAction = list =>
                {
                    return(list.Title.Contains("PnPTestList"));
                };

                var results = scope.ExecuteCommand("Invoke-PnPWebAction",
                                                   new CommandParameter("ListItemAction", listItemAction),
                                                   new CommandParameter("ShouldProcessListAction", shouldProcessListAction),
                                                   new CommandParameter("SkipCounting", true)
                                                   );

                Assert.IsTrue(listItemTitles.Count == 5, "Wrong count on listItems");

                Assert.IsTrue(listItemTitles.Contains("Test1-1"), "Test1-1 is missing");
                Assert.IsTrue(listItemTitles.Contains("Test1-2"), "Test1-2 is missing");

                Assert.IsTrue(listItemTitles.Contains("Test2-1"), "Test2-1 is missing");
                Assert.IsTrue(listItemTitles.Contains("Test2-2"), "Test2-2 is missing");
                Assert.IsTrue(listItemTitles.Contains("Test2-3"), "Test2-3 is missing");

                InvokeWebActionResult result = results.Last().BaseObject as InvokeWebActionResult;

                AssertInvokeActionResult(result,
                                         processedWebCount: 1,
                                         processedListCount: 3,
                                         processedListItemCount: 5
                                         );
            }
        }
示例#17
0
        public void AddTaxonomyField()
        {
            using (var ctx = TestCommon.CreateClientContext())
            {
                // Get the first group
                var taxSession = ctx.Site.GetTaxonomySession();
                var termStore  = taxSession.GetDefaultSiteCollectionTermStore();
                ctx.Load(termStore, ts => ts.Groups);
                ctx.ExecuteQueryRetry();

                var termGroup = termStore.Groups[0];
                ctx.Load(termGroup, tg => tg.TermSets);
                ctx.ExecuteQueryRetry();

                var termSet = termGroup.TermSets[0];
                ctx.Load(termSet, ts => ts.Id);
                ctx.ExecuteQueryRetry();
                using (var scope = new PSTestScope(true))
                {
                    scope.ExecuteCommand("Add-PnPTaxonomyField",
                                         new CommandParameter("DisplayName", "PSCmdletTestField"),
                                         new CommandParameter("InternalName", "PSCmdletTestField"),
                                         new CommandParameter("TaxonomyItemId", termSet.Id),
                                         new CommandParameter("Group", "Test Group"));
                }

                var succeeded = false;
                try
                {
                    var field = ctx.Web.Fields.GetByInternalNameOrTitle("PSCmdletTestField");
                    ctx.ExecuteQueryRetry();
                    succeeded = true;
                    field.DeleteObject();
                    ctx.ExecuteQueryRetry();
                }
                catch { }

                Assert.IsTrue(succeeded);
            }
        }
示例#18
0
 public void Cleanup()
 {
     using (var scope = new PSTestScope())
     {
         try
         {
             scope.ExecuteCommand("Remove-PnPMicrosoft365Group", new CommandParameter("Identity", _groupId));
         }
         catch (Exception)
         {
             // Group has already been deleted
         }
         try
         {
             scope.ExecuteCommand("Remove-PnPDeletedMicrosoft365Group", new CommandParameter("Identity", _groupId));
         }
         catch (Exception)
         {
             // Group has already been permanently deleted
         }
     }
 }
        public void SetMinimalDownloadStrategyTest()
        {
            bool isActive = false;

            using (var context = TestCommon.CreateClientContext())
            {
                isActive = context.Web.IsFeatureActive(OfficeDevPnP.Core.Constants.FeatureId_Web_MinimalDownloadStrategy);

                using (var scope = new PSTestScope(true))
                {
                    if (isActive)
                    {
                        // Deactivate
                        scope.ExecuteCommand("Set-PnPMinimalDownloadStrategy",
                                             new CommandParameter("Off"),
                                             new CommandParameter("Force"));
                    }
                    else
                    {
                        scope.ExecuteCommand("Set-PnPMinimalDownloadStrategy",
                                             new CommandParameter("On"));
                    }
                }
            }
            using (var context = TestCommon.CreateClientContext())
            {
                var featureActive = context.Web.IsFeatureActive(OfficeDevPnP.Core.Constants.FeatureId_Web_MinimalDownloadStrategy);
                if (isActive)
                {
                    Assert.IsFalse(featureActive);
                    context.Web.ActivateFeature(OfficeDevPnP.Core.Constants.FeatureId_Web_MinimalDownloadStrategy);
                }
                else
                {
                    Assert.IsTrue(featureActive);
                    context.Web.DeactivateFeature(OfficeDevPnP.Core.Constants.FeatureId_Web_MinimalDownloadStrategy);
                }
            }
        }
        public void AddNavigationNodeTest()
        {
            using (var scope = new PSTestScope(true))
            {
                var results = scope.ExecuteCommand("Add-PnPNavigationNode",
                                                   new CommandParameter("Location", NavigationType.QuickLaunch),
                                                   new CommandParameter("Title", "Test Navigation Item"),
                                                   new CommandParameter("Url", "https://testserver.com/testtojavascriptlink.js"));


                using (var context = TestCommon.CreateClientContext())
                {
                    var nodes = context.LoadQuery(context.Web.Navigation.QuickLaunch.Where(n => n.Title == "Test Navigation Item"));
                    context.ExecuteQueryRetry();

                    Assert.IsTrue(nodes.Any());

                    nodes.FirstOrDefault().DeleteObject();
                    context.ExecuteQueryRetry();
                }
            }
        }
示例#21
0
        public void GetWebPartXmlTest()
        {
            if (TestCommon.AppOnlyTesting())
            {
                Assert.Inconclusive("Can't currently retrieve web part settings using app-only");
            }

            using (var scope = new PSTestScope(true))
            {
                using (var ctx = TestCommon.CreateClientContext())
                {
                    var wps = ctx.Web.GetWebParts(serverRelativeHomePageUrl);

                    if (wps.Any())
                    {
                        var wp      = wps.FirstOrDefault();
                        var results = scope.ExecuteCommand("Get-PnPWebPartXml",
                                                           new CommandParameter("ServerRelativePageUrl", serverRelativeHomePageUrl),
                                                           new CommandParameter("Identity", wp.Id));

                        Assert.IsTrue(results.Count > 0);
                        Assert.IsTrue(results[0].BaseObject.GetType() == typeof(string));
                        try
                        {
                            var xelement = XElement.Parse(results[0].ToString());
                        }
                        catch
                        {
                            Assert.Fail("Returned data is not valid XML");
                        }
                    }
                    else
                    {
                        Assert.Fail("No webparts on page.");
                    }
                }
            }
        }
示例#22
0
 public void ConnectSPOnlineTest2()
 {
     using (var scope = new PSTestScope(false))
     {
         if (ConfigurationManager.AppSettings["SPOUserName"] != null &&
             ConfigurationManager.AppSettings["SPOPassword"] != null)
         {
             var script = String.Format(@" [ValidateNotNullOrEmpty()] $userPassword = ""{1}""
                                       $userPassword = ConvertTo-SecureString -String {1} -AsPlainText -Force
                                       $cred = New-Object –TypeName System.Management.Automation.PSCredential –ArgumentList {0}, $userPassword
                                       Connect-PnPOnline -Url {2} -Credentials $cred"
                                        , ConfigurationManager.AppSettings["SPOUserName"],
                                        ConfigurationManager.AppSettings["SPOPassword"],
                                        ConfigurationManager.AppSettings["SPODevSiteUrl"]);
             var results = scope.ExecuteScript(script);
             Assert.IsTrue(results.Count == 0);
         }
         else
         {
             Assert.Inconclusive("No credentials specified in app.config");
         }
     }
 }
示例#23
0
        public void RemoveViewTest()
        {
            using (var ctx = TestCommon.CreateClientContext())
            {
                var list = ctx.Web.GetListByTitle("PnPTestList");

                list.CreateView("TestView", ViewType.None, new[] { "Title" }, 30, false);


                using (var scope = new PSTestScope(true))
                {
                    scope.ExecuteCommand("Remove-PnPView",
                                         new CommandParameter("List", "PnPTestList"),
                                         new CommandParameter("Identity", "TestView"),
                                         new CommandParameter("Force")
                                         );
                }

                var view = list.GetViewByName("TestView");

                Assert.IsNull(view);
            }
        }
示例#24
0
        public void AddListWebhookSubscriptionTest()
        {
            using (var scope = new PSTestScope(true))
            {
                using (var ctx = TestCommon.CreateClientContext())
                {
                    // Create the test list
                    List testList = EnsureFreshTestList(ctx);

                    // Test the Add-PnPWebhookSubscription cmdlet on the list
                    scope.ExecuteCommand("Add-PnPWebhookSubscription",
                                         new CommandParameter("List", PnPWebhookTestList),
                                         new CommandParameter("NotificationUrl", TestCommon.WebHookTestUrl));

                    IList <WebhookSubscription> webhookSubscriptions = testList.GetWebhookSubscriptions();
                    Assert.IsTrue(webhookSubscriptions.Count() == 1);

                    // Delete the test list
                    testList.DeleteObject();
                    ctx.ExecuteQueryRetry();
                }
            }
        }
示例#25
0
        public void RemoveWebPartTest()
        {
            using (var scope = new PSTestScope(true))
            {
                using (var ctx = TestCommon.CreateClientContext())
                {
                    var results = scope.ExecuteCommand("Add-PnPWebPartToWikiPage",
                                                       new CommandParameter("ServerRelativePageUrl", serverRelativeHomePageUrl),
                                                       new CommandParameter("Path", "..\\..\\Resources\\webpart.xml"),
                                                       new CommandParameter("Row", 1),
                                                       new CommandParameter("Column", 1));


                    Assert.IsFalse(results.Any());

                    results = scope.ExecuteCommand("Remove-PnPWebPart",
                                                   new CommandParameter("ServerRelativePageUrl", serverRelativeHomePageUrl),
                                                   new CommandParameter("Title", "Get start with your site"));

                    Assert.IsFalse(results.Any());
                }
            }
        }
 public void GetDataRowsFromListWithMultiChoiceField()
 {
     using (var scope = new PSTestScope(true))
     {
         var filePath = CreateUniqueCopyOfTemplateFile(@"Resources\PnPTestList.xml");
         try
         {
             string[] fields  = new string[] { "MultiChoice" };
             var      results = scope.ExecuteCommand("Add-PnPDataRowsToProvisioningTemplate",
                                                     new CommandParameter("Path", filePath),
                                                     new CommandParameter("List", "PnPTestList"),
                                                     new CommandParameter("Query", "<View></View>"),
                                                     new CommandParameter("Fields", fields)
                                                     );
             var template = GetTemplateFromXmlFile(filePath);
             Assert.AreEqual("a;#b;#c", template.Lists[0].DataRows[0].Values["MultiChoice"]);
         }
         finally
         {
             System.IO.File.Delete(filePath);
         }
     }
 }
        public void RemoveEventReceiverTest()
        {
            using (var scope = new PSTestScope(true))
            {
                EventReceiverDefinition receiver = null;
                using (var ctx = TestCommon.CreateClientContext())
                {
                    receiver = ctx.Web.AddRemoteEventReceiver("TestEventReceiver", "https://testserver.com/testeventreceiver.svc", EventReceiverType.ListAdded, EventReceiverSynchronization.Asynchronous, true);
                }

                var results = scope.ExecuteCommand("Remove-PnPEventReceiver",
                                                   new CommandParameter("Identity", receiver.ReceiverId),
                                                   new CommandParameter("Force"));


                using (var ctx = TestCommon.CreateClientContext())
                {
                    receiver = ctx.Web.GetEventReceiverByName("TestEventReceiver");

                    Assert.IsNull(receiver);
                }
            }
        }
示例#28
0
        public void CopyFile_FolderWithSkipSourceFolderNameBetweenSiteCollections_Test()
        {
            using (var scope = new PSTestScope(_site1Url, true))
            {
                var sourceUrl      = $"{Site1RelativeFolderUrl}/{SourceFolderName}";
                var destinationUrl = $"{Site2RelativeFolderUrl}";

                var results = scope.ExecuteCommand("Copy-PnPFile",
                                                   new CommandParameter("SourceUrl", sourceUrl),
                                                   new CommandParameter("TargetUrl", destinationUrl),
                                                   new CommandParameter(name: "SkipSourceFolderName"),
                                                   new CommandParameter("Force"));

                using (var ctx = TestCommon.CreateClientContext(_site2Url))
                {
                    Folder initialFolder = ctx.Web.GetFolderByServerRelativePath(ResourcePath.FromDecodedUrl(destinationUrl));
                    initialFolder.EnsureProperties(f => f.Name, f => f.Exists, f => f.Files);
                    ctx.Load(initialFolder);
                    ctx.ExecuteQuery();
                    Assert.AreEqual(1, initialFolder.Files.Count);
                }
            }
        }
示例#29
0
        public void GetFeatureTest()
        {
            using (var ctx = TestCommon.CreateClientContext())
            {
                var isActive = ctx.Web.IsFeatureActive(Core.Constants.FeatureId_Web_MinimalDownloadStrategy);

                if (!isActive)
                {
                    ctx.Web.ActivateFeature(Core.Constants.FeatureId_Web_MinimalDownloadStrategy);
                }

                using (var scope = new PSTestScope(true))
                {
                    var results = scope.ExecuteCommand("Get-PnPFeature",
                                                       new CommandParameter("Identity", Core.Constants.FeatureId_Web_MinimalDownloadStrategy));
                    Assert.IsTrue(results.Any());
                }

                if (!isActive)
                {
                    ctx.Web.DeactivateFeature(Core.Constants.FeatureId_Web_MinimalDownloadStrategy);
                }
            }
        }
        public void GetFoldersFromList()
        {
            using (var scope = new PSTestScope(true))
            {
                var filePath = CreateUniqueCopyOfTemplateFile(@"Resources\PnPTestList.xml");
                try
                {
                    var results = scope.ExecuteCommand("Add-PnPListFoldersToProvisioningTemplate",
                                                       new CommandParameter("Path", filePath),
                                                       new CommandParameter("List", "PnPTestList"),
                                                       new CommandParameter("Recursive", false)
                                                       );

                    var template = GetTemplateFromXmlFile(filePath);
                    Assert.AreEqual(10, template.Lists[0].Folders.Count);

                    Assert.AreEqual(0, template.Lists[0].Folders[0].Folders.Count);
                }
                finally
                {
                    System.IO.File.Delete(filePath);
                }
            }
        }