public void GetWebPartPropertyTest() { 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-SPOWebPartProperty", new CommandParameter("ServerRelativePageUrl", serverRelativeHomePageUrl), new CommandParameter("Identity", wp.Id)); Assert.IsTrue(results.Count > 0); Assert.IsTrue(results[0].BaseObject.GetType() == typeof(Commands.PropertyBagValue)); } else { Assert.Fail("No webparts on page."); } } } }
public void AddWebPartToWikiPageTest() { using (var scope = new PSTestScope(true)) { using (var ctx = TestCommon.CreateClientContext()) { var results = scope.ExecuteCommand("Add-SPOWebPartToWikiPage", 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") { wp.DeleteWebPart(); ctx.ExecuteQueryRetry(); break; } } } } }
public void InvokeWebActionListAction() { using (var scope = new PSTestScope(true)) { List<string> listNames = new List<string>(); Action<List> listAction = list => { listNames.Add(list.Title); }; var results = scope.ExecuteCommand("Invoke-SPOWebAction", new CommandParameter("ListAction", listAction), new CommandParameter("ListProperties", new[] { "Title" }) ); Assert.IsTrue(listNames.Count > 3, "Wrong count on lists"); Assert.IsTrue(listNames.Contains("PnPTestList1"), "PnPTestList1 is missing"); Assert.IsTrue(listNames.Contains("PnPTestList2"), "PnPTestList2 is missing"); Assert.IsTrue(listNames.Contains("PnPTestList3"), "PnPTestList3 is missing"); InvokeWebActionResult result = results.Last().BaseObject as InvokeWebActionResult; AssertInvokeActionResult(result, processedWebCount: 1 ); Assert.IsTrue(result.ProcessedListCount > 3, "Wrong count on proccessed list"); } }
public void DisableFeatureTest() { using (var ctx = TestCommon.CreateClientContext()) { var isActive = ctx.Web.IsFeatureActive(Core.Constants.MINIMALDOWNLOADSTRATEGYFEATUREID); if (!isActive) { ctx.Web.ActivateFeature(Core.Constants.MINIMALDOWNLOADSTRATEGYFEATUREID); } using (var scope = new PSTestScope(true)) { scope.ExecuteCommand("Disable-PnPFeature", new CommandParameter("Identity", Core.Constants.MINIMALDOWNLOADSTRATEGYFEATUREID)); } Assert.IsFalse(ctx.Web.IsFeatureActive(Core.Constants.MINIMALDOWNLOADSTRATEGYFEATUREID)); if (isActive) { ctx.Web.ActivateFeature(Core.Constants.MINIMALDOWNLOADSTRATEGYFEATUREID); } } }
public void GetFeatureTest() { using (var ctx = TestCommon.CreateClientContext()) { var isActive = ctx.Web.IsFeatureActive(Core.Constants.MINIMALDOWNLOADSTRATEGYFEATUREID); if (!isActive) { ctx.Web.ActivateFeature(Core.Constants.MINIMALDOWNLOADSTRATEGYFEATUREID); } using (var scope = new PSTestScope(true)) { var results = scope.ExecuteCommand("Get-PnPFeature", new CommandParameter("Identity", Core.Constants.MINIMALDOWNLOADSTRATEGYFEATUREID)); Assert.IsTrue(results.Any()); } if (!isActive) { ctx.Web.DeactivateFeature(Core.Constants.MINIMALDOWNLOADSTRATEGYFEATUREID); } } }
public void AddFieldFromXmlTest() { var xml = @"<Field Type=""Text"" Name=""PSCmdletTest"" DisplayName=""PSCmdletTest"" ID=""{27d81055-f208-41c9-a976-61c5473eed4a}"" Group=""Test"" Required=""FALSE"" StaticName=""PSCmdletTest"" />"; using (var ctx = TestCommon.CreateClientContext()) { using (var scope = new PSTestScope(true)) { scope.ExecuteCommand("Add-SPOFieldFromXml", new CommandParameter("FieldXml", xml)); } var succeeded = false; try { var field = ctx.Web.Fields.GetByInternalNameOrTitle("PSCmdletTest"); ctx.ExecuteQueryRetry(); succeeded = true; field.DeleteObject(); ctx.ExecuteQueryRetry(); } catch { } Assert.IsTrue(succeeded); } }
public void AddFieldTest() { using (var ctx = TestCommon.CreateClientContext()) { using (var scope = new PSTestScope(true)) { scope.ExecuteCommand("Add-SPOField", new CommandParameter("DisplayName", "PSCmdletTestField"), new CommandParameter("InternalName", "PSCmdletTestField"), new CommandParameter("Type", FieldType.Text), 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); } }
public void GetEventReceiverTest() { 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("Get-PnPEventReceiver"); Assert.IsTrue(results.Any()); Assert.IsTrue(results[0].BaseObject.GetType() == typeof(EventReceiverDefinition)); results = scope.ExecuteCommand("Get-PnPEventReceiver", new CommandParameter("Identity", receiver.ReceiverId)); Assert.IsTrue(results.Any()); using (var ctx = TestCommon.CreateClientContext()) { receiver = ctx.Web.GetEventReceiverByName("TestEventReceiver"); receiver.DeleteObject(); ctx.ExecuteQueryRetry(); } } }
public void AddEventReceiverTest() { using (var scope = new PSTestScope(true)) { scope.ExecuteCommand("Add-PnPEventReceiver", new CommandParameter("Name", "TestEventReceiver"), new CommandParameter("Url", "https://testserver.com/testeventreceiver.svc"), new CommandParameter("EventReceiverType", EventReceiverType.ListAdded), new CommandParameter("Synchronization", EventReceiverSynchronization.Asynchronous)); using (var ctx = TestCommon.CreateClientContext()) { var receiver = ctx.Web.GetEventReceiverByName("TestEventReceiver"); Assert.IsNotNull(receiver); Assert.IsTrue(receiver.ReceiverUrl == "https://testserver.com/testeventreceiver.svc"); Assert.IsTrue(receiver.EventType == EventReceiverType.ListAdded); Assert.IsTrue(receiver.Synchronization == EventReceiverSynchronization.Asynchronous); receiver.DeleteObject(); ctx.ExecuteQueryRetry(); } } }
public void GetTimeZoneIdTest1() { using (var scope = new PSTestScope(false)) { var results = scope.ExecuteCommand("Get-PnPTimeZoneId"); Assert.IsTrue(results.Count > 0); } }
public void GetTenantSiteTest() { using (var scope = new PSTestScope(true)) { var results = scope.ExecuteCommand("Get-PnPTenantSite"); Assert.IsTrue(results.Count > 0); } }
public void GetTimeZoneIdTest2() { using (var scope = new PSTestScope(false)) { var results = scope.ExecuteCommand("Get-PnPTimeZoneId", new CommandParameter("Match", "Stockholm")); Assert.IsTrue(results.Count == 1); } }
public void ApplyPnpTemplateFromFolder() { using (var scope = new PSTestScope(true)) { var results = scope.ExecuteCommand("Apply-PnPProvisioningTemplate", new CommandParameter("Path", @"dummy.pnp") ); } }
public void GetWebTemplatesTest() { using (var scope = new PSTestScope(true)) { var results = scope.ExecuteCommand("Get-PnPWebTemplates", new CommandParameter("Lcid", "1033"), new CommandParameter("CompatibilityLevel", "15")); Assert.IsTrue(results.Count > 0); Assert.IsTrue(results[0].BaseObject.GetType().Equals(typeof(Microsoft.Online.SharePoint.TenantAdministration.SPOTenantWebTemplate))); } }
public void GetWebTemplatesTest() { using (var scope = new PSTestScope(true)) { var results = scope.ExecuteCommand("Get-SPOWebTemplates"); Assert.IsTrue(results.Count > 0); Assert.IsTrue(results[0].BaseObject.GetType().Equals(typeof(Microsoft.Online.SharePoint.TenantAdministration.SPOTenantWebTemplate))); } }
public void ConnectSPOnlineTest3() { using (var scope = new PSTestScope(true)) { var results = scope.ExecuteCommand("Get-SPOContext"); Assert.IsTrue(results.Count == 1); Assert.IsTrue(results[0].BaseObject.GetType() == typeof(Microsoft.SharePoint.Client.ClientContext)); } }
public void ConnectSPOnlineTest3() { using (var scope = new PSTestScope(true)) { var results = scope.ExecuteCommand("Get-PnPContext"); Assert.IsTrue(results.Count == 1); Assert.IsTrue(results[0].BaseObject.GetType() == typeof(OfficeDevPnP.Core.PnPClientContext)); } }
public void CreatePnpTemplateFromFolder() { using (var scope = new PSTestScope(true)) { var results = scope.ExecuteCommand("New-PnPProvisioningTemplateFromFolder", new CommandParameter("Out", @"dummy.pnp"), new CommandParameter("Folder", @".\Dummy"), new CommandParameter("Force") ); } }
public void GetWebPartTest() { using (var scope = new PSTestScope(true)) { // retrieve homepage var results = scope.ExecuteCommand("Get-SPOWebPart", new CommandParameter("ServerRelativePageUrl", serverRelativeHomePageUrl)); Assert.IsTrue(results.Count > 0); Assert.IsTrue(results[0].BaseObject.GetType() == typeof(Microsoft.SharePoint.Client.WebParts.WebPartDefinition)); } }
public void AddContentTypeToListTest() { using (var scope = new PSTestScope(true)) { var results = scope.ExecuteCommand("Add-PnPContentTypeToList", new CommandParameter("ContentType", CTName2), new CommandParameter("List", ListName)); Assert.IsFalse(results.Any()); Assert.IsTrue(ctList.ContentTypeExistsByName(CTName2)); } }
public void AddViewTest() { using (var scope = new PSTestScope(true)) { var results = scope.ExecuteCommand("Add-SPOView", new CommandParameter("List", "PnPTestList"), new CommandParameter("Title", "TestView"), new CommandParameter("Fields", new[] { "Title" })); Assert.IsTrue(results.Any()); Assert.IsTrue(results[0].BaseObject.GetType() == typeof(Microsoft.SharePoint.Client.View)); } }
public void ConnectSPOnlineTest1() { using (var scope = new PSTestScope(false)) { var creds = GetCredentials(ConfigurationManager.AppSettings["SPODevSiteUrl"]); if (creds != null) { var results = scope.ExecuteCommand("Connect-PnPOnline", new CommandParameter("Url", ConfigurationManager.AppSettings["SPODevSiteUrl"])); Assert.IsTrue(results.Count == 0); } else { Assert.Inconclusive("No Credential Manager Credentials present"); } } }
public void GetPropertyTest() { using (var ctx = TestCommon.CreateClientContext()) { using (var scope = new PSTestScope(true)) { var results = scope.ExecuteCommand("Get-PnPProperty", new CommandParameter("ClientObject", ctx.Web), new CommandParameter("Property", "Lists")); Assert.IsTrue(results.Count == 1); Assert.IsTrue(results[0].BaseObject.GetType() == typeof(Microsoft.SharePoint.Client.ListCollection)); } } }
public void AddListItemTest() { using (var scope = new PSTestScope(true)) { var values = new Hashtable(); values.Add("Title", "Test"); var results = scope.ExecuteCommand("Add-SPOListItem", new CommandParameter("List", "PnPTestList"), new CommandParameter("Values", values)); Assert.IsTrue(results.Any()); Assert.IsTrue(results[0].BaseObject.GetType() == typeof(Microsoft.SharePoint.Client.ListItem)); } }
public void AddJavascriptBlockTest() { using (var scope = new PSTestScope(true)) { var results = scope.ExecuteCommand("Add-PnPJavascriptBlock", new CommandParameter("Name", "TestJavascriptBlock"), new CommandParameter("Script", "<script type='text/javascript'>alert('1')</script>")); using (var context = TestCommon.CreateClientContext()) { var actions = context.Web.GetCustomActions().Where(c => c.Location == "ScriptLink" && c.Name == "TestJavascriptBlock"); Assert.IsTrue(actions.Any()); actions.FirstOrDefault().DeleteObject(); context.ExecuteQueryRetry(); } } }
public void AddJavascriptLinkTest() { using (var scope = new PSTestScope(true)) { var results = scope.ExecuteCommand("Add-PnPJavascriptLink", new CommandParameter("Key", "TestJavascriptLink"), new CommandParameter("Url", "https://testserver.com/testtojavascriptlink.js")); using (var context = TestCommon.CreateClientContext()) { var actions = context.Web.GetCustomActions().Where(c => c.Location == "ScriptLink" && c.Name == "TestJavascriptLink"); Assert.IsTrue(actions.Any()); actions.FirstOrDefault().DeleteObject(); context.ExecuteQueryRetry(); } } }
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 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 GetDataRowsFromListWithFields() { using (var scope = new PSTestScope(true)) { //var template = scope.ExecuteCommand("Get-PnPProvisioningTemplate", new CommandParameter("OutputInstance", true)); //Assert.IsTrue(template.Any()); string[] fields = new string[] { "Title" }; var results = scope.ExecuteCommand("Add-PnPDataRowsToProvisioningTemplate", new CommandParameter("Path", @"..\\..\\Resources\\PnPTestList.xml"), new CommandParameter("List", "PnPTestList"), new CommandParameter("Query", "<View></View>"), new CommandParameter("Fields", fields) ); var template = results[0].BaseObject as ProvisioningTemplate; Assert.AreEqual(10, template.Lists[0].DataRows.Count); } }
public void GetFoldersFromListWithIncludeSecurity() { using (var scope = new PSTestScope(true)) { var results = scope.ExecuteCommand("Add-PnPListFoldersToProvisioningTemplate", new CommandParameter("Path", @"..\\..\\Resources\\PnPTestList.xml"), new CommandParameter("List", "PnPTestList"), new CommandParameter("Recursive", false), new CommandParameter("IncludeSecurity", true) ); var template = results[0].BaseObject as ProvisioningTemplate; Assert.AreEqual(10, template.Lists[0].Folders.Count); OfficeDevPnP.Core.Framework.Provisioning.Model.Folder f = template.Lists[0].Folders.Find(fld => fld.Name == "TestFolder0"); Assert.IsTrue(f.Security.RoleAssignments.Count > 0); Assert.AreEqual(0, f.Folders.Count); } }
public void AddContentTypeTest() { using (var scope = new PSTestScope(true)) { var results = scope.ExecuteCommand("Add-SPOContentType", 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(); } } }
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(); } } }
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 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 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); } } }
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 GetDataRowsWithSecurityFromList() { using (var scope = new PSTestScope(true)) { string[] fields = new string[] { "Title" }; var results = scope.ExecuteCommand("Add-PnPDataRowsToProvisioningTemplate", new CommandParameter("Path", @"..\\..\\Resources\\PnPTestList.xml"), new CommandParameter("List", "PnPTestList"), new CommandParameter("Query", "<View></View>"), new CommandParameter("Fields", fields), new CommandParameter("IncludeSecurity", true) ); var template = results[0].BaseObject as ProvisioningTemplate; Assert.AreEqual(10, template.Lists[0].DataRows.Count); DataRow row = template.Lists[0].DataRows[0]; Assert.IsTrue(row.Security.RoleAssignments.Count > 0); Assert.IsTrue(row.Security.ClearSubscopes == true); Assert.IsTrue(row.Security.CopyRoleAssignments == false); } }
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-SPOListItem", new CommandParameter("List", "PnPTestList")); Assert.IsTrue(results.Count > 0); Assert.IsTrue(results[0].BaseObject.GetType() == typeof(Microsoft.SharePoint.Client.ListItem)); } }
public void AddNavigationNodeTest() { using (var scope = new PSTestScope(true)) { var results = scope.ExecuteCommand("Add-SPONavigationNode", 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(); } } }
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-SPOContentType", 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(); } } }
public void SetDefaultContentTypeToListTest() { using (var scope = new PSTestScope(true)) { if (!ctList.ContentTypeExistsByName(CTName2)) { ctList.AddContentTypeToListByName(CTName2, false, true); } var results = scope.ExecuteCommand("Set-SPODefaultContentTypeToList", 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); } }
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(); } } }
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); } } }
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 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-SPOWebAction", 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 ); } }
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); } }
public void SetWebPartPropertyTest() { using (var scope = new PSTestScope(true)) { using (var ctx = TestCommon.CreateClientContext()) { var results = scope.ExecuteCommand("Add-SPOWebPartToWikiPage", 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-SPOWebPartProperty", 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-SPOWebPart", new CommandParameter("ServerRelativePageUrl", serverRelativeHomePageUrl), new CommandParameter("Title", "TESTTESTTEST")); Assert.IsFalse(results.Any()); break; } } } } }
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 Cleanup() { using (var scope = new PSTestScope()) { try { scope.ExecuteCommand("Remove-PnPUnifiedGroup", new CommandParameter("Identity", _groupId)); } catch (Exception) { // Group has already been deleted } try { scope.ExecuteCommand("Remove-PnPDeletedUnifiedGroup", new CommandParameter("Identity", _groupId)); } catch (Exception) { // Group has already been permanently deleted } } }
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(); } } }
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."); } } } }
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); } } }
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-SPOnline -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"); } } }
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); } } }
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(); } } }
public void RemoveWebPartTest() { using (var scope = new PSTestScope(true)) { using (var ctx = TestCommon.CreateClientContext()) { var results = scope.ExecuteCommand("Add-SPOWebPartToWikiPage", 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-SPOWebPart", new CommandParameter("ServerRelativePageUrl", serverRelativeHomePageUrl), new CommandParameter("Title", "Get start with your site")); Assert.IsFalse(results.Any()); } } }
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); } }
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); } } }