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-SPOFeature",
                        new CommandParameter("Identity", Core.Constants.MINIMALDOWNLOADSTRATEGYFEATUREID));
                }

                Assert.IsFalse(ctx.Web.IsFeatureActive(Core.Constants.MINIMALDOWNLOADSTRATEGYFEATUREID));

                if (isActive)
                {
                    ctx.Web.ActivateFeature(Core.Constants.MINIMALDOWNLOADSTRATEGYFEATUREID);
                }
            }
        }
        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(OfficeDevPnP.PowerShell.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 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-SPOFeature",
                        new CommandParameter("Identity", Core.Constants.MINIMALDOWNLOADSTRATEGYFEATUREID));
                    Assert.IsTrue(results.Any());

                }

                if (!isActive)
                {
                    ctx.Web.DeactivateFeature(Core.Constants.MINIMALDOWNLOADSTRATEGYFEATUREID);
                }
            }
        }
        public void AddEventReceiverTest()
        {
            using (var scope = new PSTestScope(true))
            {
                scope.ExecuteCommand("Add-SPOEventReceiver",
                    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 GetWebPartXmlTest()
        {
            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-SPOWebPartXml",
                            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 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 AddCustomActionTest()
        {
            using (var scope = new PSTestScope(true))
            {
                var results = scope.ExecuteCommand("Add-SPOCustomAction",
                    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 AddFieldToContentTypeTest()
        {
            using (var scope = new PSTestScope(true))
            {
                using (var ctx = TestCommon.CreateClientContext())
                {
                    var results = scope.ExecuteCommand("Add-SPOFieldToContentType",
                        new CommandParameter("ContentType", CTName2),
                        new CommandParameter("Field", "Nickname"));

                    Assert.IsFalse(results.Any());

                    var ct = ctx.Web.GetContentTypeByName(CTName2);

                    if (ct != null)
                    {
                        var fields = ct.EnsureProperty(f => f.Fields);
                        Assert.IsNotNull(fields.FirstOrDefault(f => f.Title == "Nickname"));
                    }
                    else
                    {
                        Assert.Fail("Content type not found");
                    }

                }
            }
        }
        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-SPOEventReceiver");

                Assert.IsTrue(results.Any());

                Assert.IsTrue(results[0].BaseObject.GetType() == typeof(EventReceiverDefinition));


                results = scope.ExecuteCommand("Get-SPOEventReceiver",
                    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 GetTimeZoneIdTest1()
 {
     using (var scope = new PSTestScope(false))
     {
         var results = scope.ExecuteCommand("Get-SPOTimeZoneId");
         Assert.IsTrue(results.Count > 0);
     }
 }
Beispiel #13
0
 public void ConnectSPOnlineTest1()
 {
     using (var scope = new PSTestScope(false))
     {
         var results = scope.ExecuteCommand("Connect-SPOnline", new CommandParameter("Url", ConfigurationManager.AppSettings["SPODevSiteUrl"]));
         Assert.IsTrue(results.Count == 0);
     }
 }
        public void GetTenantSiteTest()
        {
            using (var scope = new PSTestScope(true))
            {
                var results = scope.ExecuteCommand("Get-SPOTenantSite");

                Assert.IsTrue(results.Count > 0);
            }
        }
        public void GetTimeZoneIdTest2()
        {
            using (var scope = new PSTestScope(false))
            {
                var results = scope.ExecuteCommand("Get-SPOTimeZoneId", new CommandParameter("Match", "Stockholm"));

                Assert.IsTrue(results.Count == 1);
            }
        }
        public void GetListTest()
        {
            using (var scope = new PSTestScope(true))
            {
                var results = scope.ExecuteCommand("Get-SPOList");

                Assert.IsTrue(results.Count > 0);
                Assert.IsTrue(results[0].BaseObject.GetType() == typeof(Microsoft.SharePoint.Client.List));
            }
        }
        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)));
            }
        }
Beispiel #18
0
        public void ConnectSPOnlineTest2()
        {
            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 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-SPOContentTypeToList",
                    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 GetPropertyTest()
        {
            using (var ctx = TestCommon.CreateClientContext())
            {
                using (var scope = new PSTestScope(true))
                {

                    var results = scope.ExecuteCommand("Get-SPOProperty",
                        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-SPOJavascriptBlock",
                    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-SPOJavascriptLink",
                    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-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();
                }
            }
        }
Beispiel #27
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-SPOListItem",
                                                   new CommandParameter("List", "PnPTestList"));

                Assert.IsTrue(results.Count > 0);
                Assert.IsTrue(results[0].BaseObject.GetType() == typeof(Microsoft.SharePoint.Client.ListItem));
            }
        }
        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 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));
            }
        }
Beispiel #30
0
        public void SetListTest()
        {
            using (var ctx = TestCommon.CreateClientContext())
            {
                ctx.Web.CreateList(ListTemplateType.GenericList, "PnPTestList3", false);

                using (var scope = new PSTestScope(true))
                {
                    scope.ExecuteCommand("Set-SPOList",
                                         new CommandParameter("Identity", "PnPTestList3"),
                                         new CommandParameter("Title", "NewPnPTestList3")
                                         );
                }

                var list = ctx.Web.GetListByTitle("NewPnPTestList3");
                Assert.IsNotNull(list);

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

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

                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 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();
                }
            }
        }
Beispiel #33
0
        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;
                        }
                    }
                }
            }
        }
Beispiel #34
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-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 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 SetMinimalDownloadStrategyTest()
        {
            bool isActive = false;

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

                using (var scope = new PSTestScope(true))
                {
                    if (isActive)
                    {
                        // Deactivate
                        scope.ExecuteCommand("Set-SPOMinimalDownloadStrategy",
                                             new CommandParameter("Off"),
                                             new CommandParameter("Force"));
                    }
                    else
                    {
                        scope.ExecuteCommand("Set-SPOMinimalDownloadStrategy",
                                             new CommandParameter("On"));
                    }
                }
            }
            using (var context = TestCommon.CreateClientContext())
            {
                var featureActive = context.Web.IsFeatureActive(Core.Constants.MINIMALDOWNLOADSTRATEGYFEATUREID);
                if (isActive)
                {
                    Assert.IsFalse(featureActive);
                    context.Web.ActivateFeature(Core.Constants.MINIMALDOWNLOADSTRATEGYFEATUREID);
                }
                else
                {
                    Assert.IsTrue(featureActive);
                    context.Web.DeactivateFeature(Core.Constants.MINIMALDOWNLOADSTRATEGYFEATUREID);
                }
            }
        }
Beispiel #37
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-SPOView",
                                         new CommandParameter("List", "PnPTestList"),
                                         new CommandParameter("Identity", "TestView"),
                                         new CommandParameter("Force")
                                         );
                }

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

                Assert.IsNull(view);
            }
        }
Beispiel #38
0
        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 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-SPOEventReceiver",
                                                   new CommandParameter("Identity", receiver.ReceiverId),
                                                   new CommandParameter("Force"));


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

                    Assert.IsNull(receiver);
                }
            }
        }
        public void RemoveContentTypeTest()
        {
            using (var scope = new PSTestScope(true))
            {
                var results = scope.ExecuteCommand("Add-SPOContentType",
                                                   new CommandParameter("Name", CTName3),
                                                   new CommandParameter("Group", "UnitTestCTGroup"));

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


                results = scope.ExecuteCommand("Remove-SPOContentType",
                                               new CommandParameter("Identity", CTName3),
                                               new CommandParameter("Force"));

                using (var ctx = TestCommon.CreateClientContext())
                {
                    var ct = ctx.Web.GetContentTypeByName(CTName3);

                    Assert.IsNull(ct);
                }
            }
        }
        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-SPOFeature",
                                                       new CommandParameter("Identity", Core.Constants.MINIMALDOWNLOADSTRATEGYFEATUREID));
                    Assert.IsTrue(results.Any());
                }

                if (!isActive)
                {
                    ctx.Web.DeactivateFeature(Core.Constants.MINIMALDOWNLOADSTRATEGYFEATUREID);
                }
            }
        }
        public void RemoveContentTypeTest()
        {
            using (var scope = new PSTestScope(true))
            {
                var results = scope.ExecuteCommand("Add-SPOContentType",
                    new CommandParameter("Name", CTName3),
                    new CommandParameter("Group", "UnitTestCTGroup"));

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

                results = scope.ExecuteCommand("Remove-SPOContentType",
                    new CommandParameter("Identity", CTName3),
                    new CommandParameter("Force"));

                using (var ctx = TestCommon.CreateClientContext())
                {
                    var ct = ctx.Web.GetContentTypeByName(CTName3);

                    Assert.IsNull(ct);
                }

            }
        }
        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);
            }
        }