public ExecuteCommand ( string cmdletString ) : Collection |
||
cmdletString | string | |
리턴 | Collection |
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 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 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 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 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 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 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 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-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 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 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 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 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 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 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 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 AddCustomActionTest() { using (var scope = new PSTestScope(true)) { var results = scope.ExecuteCommand("Add-PnPCustomAction", new CommandParameter("Name", "TestCustomAction"), new CommandParameter("Title", "TestCustomAction"), new CommandParameter("Description", "Test Custom Action Description"), new CommandParameter("Group", "ActionsMenu"), new CommandParameter("Location", "Microsoft.SharePoint.StandardMenu") ); using (var context = TestCommon.CreateClientContext()) { var actions = context.LoadQuery(context.Web.UserCustomActions.Where(ca => ca.Name == "TestCustomAction")); context.ExecuteQueryRetry(); Assert.IsTrue(actions.Any()); actions.FirstOrDefault().DeleteObject(); context.ExecuteQueryRetry(); } } }
public void InvokeWebActionListActionWithShouldProcess() { using (var scope = new PSTestScope(true)) { List <string> listNames = new List <string>(); Action <List> listAction = list => { listNames.Add(list.Title); }; Func <List, bool> shouldProcessListAction = list => { return(list.Title.Contains("PnPTestList")); }; var results = scope.ExecuteCommand("Invoke-SPOWebAction", new CommandParameter("ListAction", listAction), new CommandParameter("ShouldProcessListAction", shouldProcessListAction), 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, processedListCount: 3 ); } }
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 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); } } }
public void CopyFile_BetweenSiteCollectionsWithAmpersand_Test() { using (var scope = new PSTestScope(site1Url, true)) { var sourceUrl = $"/sites/PNPPS_Test_{site1Id}/Shared%20Documents/{targetFileNameWithAmpersand}"; var destinationFolderUrl = $"/sites/PNPPS_Test_{site2Id}/Shared%20Documents"; string destinationFileUrl = $"/sites/PNPPS_Test_{site2Id}/Shared%20Documents/{targetFileNameWithAmpersand}"; var results = scope.ExecuteCommand("Copy-PnPFile", new CommandParameter("SourceUrl", sourceUrl), new CommandParameter("TargetUrl", destinationFolderUrl), new CommandParameter("Force")); using (var ctx = TestCommon.CreateClientContext(site2Url)) { File initialFile = ctx.Web.GetFileByServerRelativeUrl(destinationFileUrl); ctx.Load(initialFile); ctx.ExecuteQuery(); if (!initialFile.Exists) { Assert.Fail("Copied file cannot be found"); } } } }
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 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-SPOTaxonomyField", 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 InvokeWebActionWithWhatIf() { using (var scope = new PSTestScope(true)) { bool webActionFired = false; bool webPostActionFired = false; bool listActionFired = false; bool listPostActionFired = false; bool listItemActionFired = false; Action <Web> webAction = web => { webActionFired = true; }; Action <Web> webPostAction = web => { webPostActionFired = true; }; Func <List, bool> shouldProcessListAction = list => { return(list.Title.Contains("PnPTestList")); }; Action <List> listAction = list => { listActionFired = true; }; Action <List> listPostAction = list => { listPostActionFired = true; }; Action <ListItem> listItemAction = listItem => { listItemActionFired = true; }; var results = scope.ExecuteCommand("Invoke-SPOWebAction", new CommandParameter("WebAction", webAction), new CommandParameter("PostWebAction", webPostAction), new CommandParameter("ShouldProcessListAction", shouldProcessListAction), new CommandParameter("ListAction", listAction), new CommandParameter("PostListAction", listPostAction), new CommandParameter("ListItemAction", listItemAction), new CommandParameter("WhatIf", true) ); InvokeWebActionResult result = results.Last().BaseObject as InvokeWebActionResult; Assert.AreEqual(1, result.ProcessedWebCount, "Total proccessed web count does not match"); Assert.IsFalse(webActionFired, "web action fired"); Assert.IsFalse(webPostActionFired, "web post action fired"); Assert.IsFalse(listActionFired, "list action fired"); Assert.IsFalse(listPostActionFired, "list post action fired"); Assert.IsFalse(listItemActionFired, "list item action fired"); } }
public void RemoveFieldTest() { using (var ctx = TestCommon.CreateClientContext()) { FieldCreationInformation fieldCI = new FieldCreationInformation(FieldType.Text) { DisplayName = "PnPTestTextField", Group = "PnP", InternalName = "PnPTestTextField", Required = false }; ctx.Web.CreateField(fieldCI); using (var scope = new PSTestScope(true)) { scope.ExecuteCommand("Remove-SPOField", new CommandParameter("Identity", "PnPTestTextField"), new CommandParameter("Force")); } var succeeded = false; try { var field = ctx.Web.Fields.GetByInternalNameOrTitle("PnPTestTextField"); ctx.ExecuteQueryRetry(); } catch { succeeded = true; } Assert.IsTrue(succeeded); } }
public void AddAlert_WithNonDefaultProperties_Test() { using (var ctx = TestCommon.CreateClientContext()) { ctx.Web.EnsureProperties(w => w.CurrentUser.Id, w => w.CurrentUser.LoginName); var currentUser = ctx.Web.CurrentUser; // generate random alert title var randomizer = new Random(); var alertTitle = randomizer.Next(int.MaxValue).ToString(); var list = ctx.Web.DefaultDocumentLibrary(); list.EnsureProperties(l => l.Id); var listId = list.Id; var currentTime = DateTime.Now; // note: SharePoint rounds the milliseconds away, so use a time without milliseconds for testing var alertTime = new DateTime(currentTime.Year, currentTime.Month, currentTime.Day, currentTime.Hour, currentTime.Minute, currentTime.Minute); // Execute cmd-let using (var scope = new PSTestScope(true)) { var results = scope.ExecuteCommand("Add-PnPAlert", new CommandParameter("List", "Shared Documents"), new CommandParameter("Title", alertTitle), new CommandParameter("DeliveryMethod", AlertDeliveryChannel.Email), // cannot use SmS without having Frequency set to "Immediate" new CommandParameter("ChangeType", AlertEventType.DeleteObject), new CommandParameter("Frequency", AlertFrequency.Weekly), new CommandParameter("Time", alertTime), new CommandParameter("Filter", AlertFilter.SomeoneElseChangesAnItem) ); Assert.IsNotNull(results); Assert.IsTrue(results.Count > 0); } // get actual alert and check properties ctx.Web.EnsureProperties(w => w.CurrentUser.Alerts); var newAlerts = currentUser.Alerts.Where(a => a.Title == alertTitle); Assert.AreEqual(1, newAlerts.Count(), "Unexpected number of created alerts"); var newAlert = newAlerts.First(); newAlert.EnsureProperty(a => a.AlertTime); newAlert.EnsureProperty(a => a.Properties); newAlert.User.EnsureProperties(u => u.LoginName); newAlert.List.EnsureProperties(l => l.Id); ctx.ExecuteQueryRetry(); try { Assert.AreEqual(AlertFrequency.Weekly, newAlert.AlertFrequency); Assert.AreEqual(AlertDeliveryChannel.Email, newAlert.DeliveryChannels); Assert.AreEqual(AlertEventType.DeleteObject, newAlert.EventType); Assert.AreEqual(AlertStatus.On, newAlert.Status); Assert.AreEqual(AlertType.List, newAlert.AlertType); Assert.AreEqual(currentUser.LoginName, newAlert.User.LoginName); Assert.AreEqual(listId, newAlert.List.Id); Assert.AreEqual(alertTime, newAlert.AlertTime); Assert.AreEqual(1, newAlert.Properties.Count, "Unexpected number of properties"); Assert.IsTrue(newAlert.Properties.ContainsKey("filterindex")); Assert.AreEqual("1", newAlert.Properties["filterindex"]); } finally { // delete alert currentUser.Alerts.DeleteAlert(newAlert.ID); currentUser.Update(); ctx.ExecuteQueryRetry(); } } }
public void AddGetRemoveAlertTest() { using (var ctx = TestCommon.CreateClientContext()) { ctx.Web.EnsureProperties(w => w.CurrentUser.Id, w => w.CurrentUser.LoginName); var currentUser = ctx.Web.CurrentUser; var randomizer = new Random(); var randomAlertTitle = randomizer.Next(int.MaxValue).ToString(); var list = ctx.Web.GetListByTitle("PnPTestList"); list.EnsureProperties(l => l.Id); var listId = list.Id; Guid alertId; using (var scope = new PSTestScope(true)) { var results = scope.ExecuteCommand("Add-PnPAlert", new CommandParameter("List", listId), new CommandParameter("Title", randomAlertTitle)); Assert.IsNotNull(results); Assert.IsTrue(results.Count > 0); Assert.IsTrue(results[0].BaseObject.GetType() == typeof(AlertCreationInformation)); } using (var scope = new PSTestScope(true)) { var results = scope.ExecuteCommand("Get-PnPAlert", new CommandParameter("List", listId), new CommandParameter("Title", randomAlertTitle)); Assert.IsNotNull(results); Assert.AreEqual(1, results.Count); Assert.IsTrue(results[0].BaseObject.GetType() == typeof(Alert)); var alert = results[0].BaseObject as Alert; Assert.AreEqual(randomAlertTitle, alert.Title); alertId = alert.ID; } using (var scope = new PSTestScope(true)) { var results = scope.ExecuteCommand("Get-PnPAlert", new CommandParameter("Title", randomAlertTitle)); Assert.IsNotNull(results); Assert.AreEqual(1, results.Count); } using (var scope = new PSTestScope(true)) { var results = scope.ExecuteCommand("Get-PnPAlert", new CommandParameter("List", listId)); Assert.IsNotNull(results); Assert.AreEqual(1, results.Count); } using (var scope = new PSTestScope(true)) { var results = scope.ExecuteCommand("Remove-PnPAlert", new CommandParameter("Identity", alertId), new CommandParameter("Force")); } // check that the alert has been deleted ctx.Web.EnsureProperties(w => w.CurrentUser.Alerts); var newAlerts = currentUser.Alerts.Where(a => a.Title == randomAlertTitle); Assert.AreEqual(0, newAlerts.Count(), "Alert is still present"); } }