Beispiel #1
0
 internal DeleteFieldLinkRequest(IContentType contentType, IFieldLink fieldLink, bool updateContentTypeChildren = true)
 {
     ContentType       = contentType;
     FieldLink         = fieldLink;
     UpdateContentType = updateContentTypeChildren;
     VerifyField(fieldLink);
 }
Beispiel #2
0
        public async Task AddSiteContentTypeFieldLinkAsyncTest()
        {
            // The FieldLinkCollection Add REST endpoint has many limitations
            // https://docs.microsoft.com/en-us/previous-versions/office/sharepoint-visio/jj245869%28v%3doffice.15%29#rest-resource-endpoint
            // It ONLY works with Site Columns already present in the parent content content type or  with list columns if they are already added to the list
            // TODO: Probably worthy to recommend not using this endpoint for adding fieldlinks... What alternative ?

            //TestCommon.Instance.Mocking = false;
            using (var context = await TestCommon.Instance.GetContextAsync(TestCommon.TestSite))
            {
                // Create a new test content type
                IContentType newContentType = await context.Web.ContentTypes.AddAsync("0x0100302EF0D1F1DB4C4EBF58251BCCF5968A", "TEST ADD ASYNC", "TESTING", "TESTING");

                Assert.IsNotNull(newContentType);

                // Add a new field link between newContentType and Title
                IFieldLink newFieldLink = await newContentType.FieldLinks.AddAsync("Title", "My Title");

                Assert.IsNotNull(newFieldLink);
                Assert.AreEqual("Title", newFieldLink.Name);
                Assert.AreEqual("My Title", newFieldLink.DisplayName);
                Assert.AreEqual(new Guid("fa564e0f-0c70-4ab9-b863-0177e6ddd247"), newFieldLink.Id);

                await newContentType.DeleteAsync();
            }
        }
Beispiel #3
0
        public async Task AddSiteContentTypeFieldLinkSpecificBatchTest()
        {
            //TestCommon.Instance.Mocking = false;
            using (var context = await TestCommon.Instance.GetContextAsync(TestCommon.TestSite))
            {
                var newBatch = context.NewBatch();

                // Create a new test content type
                IContentType newContentType = context.Web.ContentTypes.AddBatch(newBatch, "0x0100302EF0D1F1DB4C4EBF58251BCCF5967F", "TEST ADD SPEC BATCH", "TESTING", "TESTING");
                Assert.IsNotNull(newContentType);

                await context.ExecuteAsync(newBatch); // You cannot create and refer to the resource in the same batch. Execute seperately.

                var newBatch2 = context.NewBatch();

                // Add a new field link between newContentType and Title
                IFieldLink newFieldLink = newContentType.FieldLinks.AddBatch(newBatch2, "Title", "My Title");

                await context.ExecuteAsync(newBatch2);

                Assert.IsNotNull(newFieldLink);
                Assert.AreEqual("Title", newFieldLink.Name);
                Assert.AreEqual("My Title", newFieldLink.DisplayName);
                Assert.AreEqual(new Guid("fa564e0f-0c70-4ab9-b863-0177e6ddd247"), newFieldLink.Id);

                await newContentType.DeleteAsync();
            }
        }
Beispiel #4
0
 private void VerifyField(IFieldLink field)
 {
     if (field.Parent.Parent.Parent.Parent is IList parentList)
     {
         IsListField = true;
         List        = parentList;
     }
 }
Beispiel #5
0
        public async Task AddSiteContentTypeFieldLinkAsyncExceptionTest()
        {
            //TestCommon.Instance.Mocking = false;
            using (var context = await TestCommon.Instance.GetContextAsync(TestCommon.TestSite))
            {
                // Create a new test content type
                IContentType newContentType = await context.Web.ContentTypes.AddAsync("0x0100302EF0D1F1DB4C4EBF58251BCCF5968A", "TEST ADD ASYNC", "TESTING", "TESTING");

                Assert.IsNotNull(newContentType);

                await Assert.ThrowsExceptionAsync <ArgumentNullException>(async() =>
                {
                    // Add a new field link between newContentType and Title
                    IFieldLink newFieldLink = await newContentType.FieldLinks.AddAsync(null, "My Title");
                });

                await newContentType.DeleteAsync();
            }
        }
Beispiel #6
0
        public async Task AddSiteContentTypeFieldLinkTest()
        {
            //TestCommon.Instance.Mocking = false;
            using (var context = await TestCommon.Instance.GetContextAsync(TestCommon.TestSite))
            {
                // Create a new test content type
                IContentType newContentType = context.Web.ContentTypes.Add("0x0100302EF0D1F1DB4C4EBF58251BCCF5968B", "TEST ADD", "TESTING", "TESTING");
                Assert.IsNotNull(newContentType);

                // Add a new field link between newContentType and Title
                IFieldLink newFieldLink = newContentType.FieldLinks.Add("Title", "My Title");

                Assert.IsNotNull(newFieldLink);
                Assert.AreEqual("Title", newFieldLink.Name);
                Assert.AreEqual("My Title", newFieldLink.DisplayName);
                Assert.AreEqual(new Guid("fa564e0f-0c70-4ab9-b863-0177e6ddd247"), newFieldLink.Id);

                await newContentType.DeleteAsync();
            }
        }
Beispiel #7
0
        public async Task AddSiteContentTypeFieldLinkSpecificBatchExeceptionAsyncTest()
        {
            //TestCommon.Instance.Mocking = false;
            using (var context = await TestCommon.Instance.GetContextAsync(TestCommon.TestSite))
            {
                await Assert.ThrowsExceptionAsync <ClientException>(async() =>
                {
                    var newBatch = context.NewBatch();

                    // Create a new test content type
                    IContentType newContentType = await context.Web.ContentTypes.AddBatchAsync(newBatch, "0x0100302EF0D1F1DB4C4EBF58251BCCF5968E", "TEST ADD SPEC BATCH ASYNC", "TESTING", "TESTING");
                    Assert.IsNotNull(newContentType);

                    // Add a new field link between newContentType and Title
                    IFieldLink newFieldLink = await newContentType.FieldLinks.AddBatchAsync(newBatch, "Title", "My Title");
                    await context.ExecuteAsync(newBatch);

                    newBatch.Requests.Clear();
                }, "You cannot do a batch add of a model to a modelcollection that was not yet requested. Common reasons are adding an item and using that same item in a single batch");
            }
        }
Beispiel #8
0
        public async Task GetSiteContentTypeFieldLinksTest()
        {
            //TestCommon.Instance.Mocking = false;
            using (var context = await TestCommon.Instance.GetContextAsync(TestCommon.TestSite))
            {
                // Get existing content type
                IContentType contentType = (from ct in context.Web.ContentTypes
                                            where ct.Name == "Document"
                                            select ct)
                                           .QueryProperties(ct => ct.FieldLinks)
                                           .FirstOrDefault();

                Assert.IsTrue(contentType.FieldLinks.Length > 0);
                Assert.IsNotNull(contentType);

                IFieldLink titleFieldLink = contentType.FieldLinks.AsRequested().FirstOrDefault(fl => fl.Name == "Title");

                Assert.IsNotNull(titleFieldLink);
                Assert.AreEqual("Title", titleFieldLink.Name);
                Assert.AreEqual(new Guid("fa564e0f-0c70-4ab9-b863-0177e6ddd247"), titleFieldLink.Id);
            }
        }