Example #1
0
 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);
             }
         }
     }
 }
Example #2
0
        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.");
                    }
                }
            }
        }