public void MakePostRequestForStringWithSPContextTest()
        {
            if (string.IsNullOrEmpty(HttpHelperTests.TestAPIUrl))
            {
                Assert.Inconclusive("No value set for HttpHelperFunctionAppUrl property in the config file");
            }

            using (var clientContext = TestCommon.CreatePnPClientContext(5, 1000))
            {
                var web = clientContext.Web;
                web.EnsureProperties(w => w.Url, w => w.Title);

                var requestHeaders = new Dictionary <string, string>
                {
                    { "X-RequestDigest", (clientContext as ClientContext).GetRequestDigest().GetAwaiter().GetResult() }
                };

                var result = HttpHelper.MakePostRequestForString(
                    $"{web.Url}/_api/web",
                    accept: "application/json",
                    requestHeaders: requestHeaders,
                    spContext: clientContext);

                var webJson = JsonConvert.DeserializeAnonymousType(result, new { Title = "" });
                Assert.AreEqual(webJson.Title, web.Title);
            }
        }
        public void TestPnPClientContext()
        {
            using (var clientContext = TestCommon.CreatePnPClientContext(5, 1000))
            {
                var lists = clientContext.Web.Lists;

                clientContext.Load(lists);
                clientContext.ExecuteQueryRetry();


                Assert.IsTrue(lists.Count > 0);
            }
        }
Ejemplo n.º 3
0
        private static void CleanupTemplatesFromSharePointLibrary()
        {
            var context = TestCommon.CreatePnPClientContext();

            var docLib = context.Web.GetListByTitle(testTemplatesDocLib);

            if (docLib != null)
            {
                context.Load(docLib);
                context.ExecuteQueryRetry();
                docLib.DeleteObject();
                context.ExecuteQueryRetry();
            }
        }
        public void TestPnPClientContextClone()
        {
            using (var clientContext = TestCommon.CreatePnPClientContext(5, 1000))
            {
                using (var clonedContext = clientContext.Clone(clientContext.Url))
                {
                    var lists = clonedContext.Web.Lists;
                    clonedContext.Load(lists);
                    clonedContext.ExecuteQueryRetry();

                    Assert.IsTrue(lists.Count > 0);
                    //Assert.AreEqual(clonedContext.Delay, clientContext.Delay);
                    //Assert.AreEqual(clonedContext.RetryCount, clientContext.RetryCount);
                }
            }
        }
Ejemplo n.º 5
0
        public void XMLSharePointGetTemplate1Test()
        {
            var _expectedID      = "SPECIALTEAM";
            var _expectedVersion = 1.0;

            var context = TestCommon.CreatePnPClientContext();

            XMLSharePointTemplateProvider provider =
                new XMLSharePointTemplateProvider(context,
                                                  TestCommon.DevSiteUrl,
                                                  testTemplatesDocLib);

            var result = provider.GetTemplate("ProvisioningTemplate-2016-05-Sample-02.xml");

            Assert.AreEqual(_expectedID, result.Id);
            Assert.AreEqual(_expectedVersion, result.Version);
            Assert.IsTrue(result.Lists.Count == 2);
            Assert.IsTrue(result.SiteFields.Count == 4);
        }
Ejemplo n.º 6
0
        public void MakePostRequestForStringWithSPContextTest()
        {
            using (var clientContext = TestCommon.CreatePnPClientContext(5, 1000))
            {
                var web = clientContext.Web;
                web.EnsureProperties(w => w.Url, w => w.Title);

                var requestHeaders = new Dictionary <string, string>();
                requestHeaders.Add("X-RequestDigest", (clientContext as ClientContext).GetRequestDigest().GetAwaiter().GetResult());

                var result = HttpHelper.MakePostRequestForString(
                    $"{web.Url}/_api/web",
                    accept: "application/json",
                    requestHeaders: requestHeaders,
                    spContext: clientContext);

                var webJson = JsonConvert.DeserializeAnonymousType(result, new { Title = "" });
                Assert.AreEqual(webJson.Title, web.Title);
            }
        }
Ejemplo n.º 7
0
        private static void UploadTemplatesToSharePointLibrary()
        {
            var context = TestCommon.CreatePnPClientContext();

            var docLib = context.Web.CreateDocumentLibrary(testTemplatesDocLib);

            context.Load(docLib, d => d.RootFolder);
            context.ExecuteQueryRetry();

            var templatesToUpload = new string[] {
                "ProvisioningTemplate-2016-05-Sample-02.xml"
            };

            foreach (var tempFile in templatesToUpload)
            {
                // Create or overwrite the "myblob" blob with contents from a local file.
                using (var fileStream = System.IO.File.OpenRead(String.Format(@"{0}\..\..\Resources\Templates\{1}", AppDomain.CurrentDomain.BaseDirectory, tempFile)))
                {
                    docLib.RootFolder.UploadFile(tempFile, fileStream, true);
                    context.ExecuteQueryRetry();
                }
            }
        }