Пример #1
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();
                }
            }
        }
Пример #2
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);
            }
        }
Пример #3
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);
                }
            }
        }
Пример #5
0
        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-PnPWebAction",
                                                   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
                                         );
            }
        }
Пример #6
0
        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");
            }
        }
Пример #7
0
        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.GetListByTitle("PnPTestList");
                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", "PnPTestList"),
                                                       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();
                }
            }
        }
Пример #8
0
        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-PnPWebAction",
                                                   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");
            }
        }