public void InvokeWebActionPostWebAction()
        {
            using (var scope = new PSTestScope(true))
            {
                Guid id = Guid.Empty;

                Action <Web> webPostAction = web =>
                {
                    id = web.Id;
                };

                var results = scope.ExecuteCommand("Invoke-SPOWebAction",
                                                   new CommandParameter("PostWebAction", webPostAction),
                                                   new CommandParameter("WebProperties", new[] { "Id" })
                                                   );

                Assert.IsTrue(id != Guid.Empty, "Id is empty");

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

                AssertInvokeActionResult(result,
                                         processedPostWebCount: 1
                                         );
            }
        }
Пример #2
0
        private void AssertInvokeActionResult(InvokeWebActionResult result,
            int? processedWebCount = null,
            int? processedPostWebCount = null,
            int? processedListCount = null,
            int? processedPostListCount = null,
            int? processedListItemCount = null,
            int? processedPostListItemCount = null)
        {
            Assert.IsNotNull(result, "InvokeActionResult is null");

            if (processedWebCount.HasValue)
            {
                Assert.AreEqual(processedWebCount.Value, result.ProcessedWebCount, "Total proccessed web count does not match");

                if(result.AverageWebTime.HasValue)
                    Assert.IsTrue(result.AverageWebTime > 0, "Average web time is 0");
            }

            if (processedPostWebCount.HasValue)
            {
                Assert.AreEqual(processedPostWebCount.Value, result.ProcessedPostWebCount, "Total proccessed web count does not match");

                if (result.AveragePostWebTime.HasValue)
                    Assert.IsTrue(result.AveragePostWebTime > 0, "Average web time is 0");
            }

            if (processedListCount.HasValue)
            {
                Assert.AreEqual(processedListCount.Value, result.ProcessedListCount, "Total proccessed list count does not match");

                if (result.AverageListTime.HasValue)
                    Assert.IsTrue(result.AverageListTime > 0, "Average list time is 0");
            }

            if (processedPostListCount.HasValue)
            {
                Assert.AreEqual(processedPostListCount.Value, result.ProcessedPostListCount, "Total proccessed list count does not match");

                if (result.AveragePostListTime.HasValue)
                    Assert.IsTrue(result.AveragePostListTime > 0, "Average list time is 0");
            }

            if (processedListItemCount.HasValue)
            {
                Assert.AreEqual(processedListItemCount.Value, result.ProcessedListItemCount, "Total proccessed list item count does not match");

                if (result.AverageListItemTime.HasValue)
                    Assert.IsTrue(result.AverageListItemTime > 0, "Average list item time is 0");
            }

            Assert.IsTrue(result.StartDate >= DateTime.Today, "Incorrect start date");
            Assert.IsTrue(result.EndDate >= DateTime.Today, "Incorrect end date");
            Assert.IsTrue(result.EndDate > result.StartDate, "End date is not greater than start date");
        }
        public void InvokeWebActionWebActionWithMultipleWebs()
        {
            using (var scope = new PSTestScope(true))
            {
                List <ClientContext> clientContexts = new List <ClientContext>()
                {
                    TestCommon.CreateClientContext(),
                                     TestCommon.CreateClientContext(),
                                     TestCommon.CreateClientContext()
                };

                Web[] webs = clientContexts.Select(item => item.Web).ToArray();

                List <Guid>   ids    = new List <Guid>();
                List <string> titles = new List <string>();

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

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

                foreach (var clientContext in clientContexts)
                {
                    clientContext.Dispose();
                }

                Assert.IsTrue(ids.Count == webs.Length, "Id counts does not match web count");

                for (int i = 0; i < webs.Length; i++)
                {
                    Assert.IsTrue(ids[i] != Guid.Empty, "id is Empty");
                    Assert.IsTrue(ids[i] == webs[i].Id, "ids are not in correct order");
                }

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

                AssertInvokeActionResult(result,
                                         processedWebCount: webs.Count()
                                         );
            }
        }
        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-SPOWebAction",
                                                   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
                                         );
            }
        }
Пример #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
                                         );
            }
        }