예제 #1
0
        public void DefaultContentTypeShouldBeRemovedFromProvisionedAssetLibraries()
        {
            using (var ctx = TestCommon.CreateClientContext())
            {
                // Arrange
                var listInstance = new Core.Framework.Provisioning.Model.ListInstance();
                listInstance.Url   = $"lists/{listName}";
                listInstance.Title = listName;
                // An asset must be created by using the
                // template type AND the template feature id
                listInstance.TemplateType      = 851;
                listInstance.TemplateFeatureID = new Guid("4bcccd62-dcaf-46dc-a7d4-e38277ef33f4");
                // Also attachements are not allowed on an asset list
                listInstance.EnableAttachments          = false;
                listInstance.ContentTypesEnabled        = true;
                listInstance.RemoveExistingContentTypes = true;
                listInstance.ContentTypeBindings.Add(new ContentTypeBinding
                {
                    ContentTypeId = BuiltInContentTypeId.DublinCoreName,
                    Default       = true
                });
                var template = new ProvisioningTemplate();
                template.Lists.Add(listInstance);

                // Act
                ctx.Web.ApplyProvisioningTemplate(template);
                var list         = ctx.Web.GetListByUrl(listInstance.Url);
                var contentTypes = list.EnsureProperty(l => l.ContentTypes);
                // Assert
                // Asset list should only have the custom content type we defined
                // and the folder content type
                Assert.AreEqual(contentTypes.Count, 2);
            }
        }
예제 #2
0
        public void CanProvisionObjects()
        {
            var template     = new ProvisioningTemplate();
            var listInstance = new Core.Framework.Provisioning.Model.ListInstance();

            listInstance.Url          = string.Format("lists/{0}", listName);
            listInstance.Title        = listName;
            listInstance.TemplateType = (int)ListTemplateType.GenericList;

            Dictionary <string, string> dataValues = new Dictionary <string, string>();

            dataValues.Add("Title", "Test");
            DataRow dataRow = new DataRow(dataValues);

            listInstance.DataRows.Add(dataRow);

            template.Lists.Add(listInstance);

            using (var ctx = TestCommon.CreateClientContext())
            {
                TokenParser.Initialize(ctx.Web, template);

                new ObjectListInstance().ProvisionObjects(ctx.Web, template);

                var list = ctx.Web.GetListByUrl(listInstance.Url);
                Assert.IsNotNull(list);

                var items = list.GetItems(CamlQuery.CreateAllItemsQuery());
                ctx.Load(items, itms => itms.Include(item => item["Title"]));
                ctx.ExecuteQueryRetry();

                Assert.IsTrue(items.Count == 1);
                Assert.IsTrue(items[0]["Title"].ToString() == "Test");
            }
        }
예제 #3
0
        public void CanProvisionObjects()
        {
            var template = new ProvisioningTemplate();
            var listInstance = new Core.Framework.Provisioning.Model.ListInstance();

            listInstance.Url = string.Format("lists/{0}", listName);
            listInstance.Title = listName;
            listInstance.TemplateType = (int) ListTemplateType.GenericList;

            Dictionary<string, string> dataValues = new Dictionary<string, string>();
            dataValues.Add("Title","Test");
            DataRow dataRow = new DataRow(dataValues);

            listInstance.DataRows.Add(dataRow);

            template.Lists.Add(listInstance);

            using (var ctx = TestCommon.CreateClientContext())
            {
                TokenParser.Initialize(ctx.Web, template);

                new ObjectListInstance().ProvisionObjects(ctx.Web, template);

                var list = ctx.Web.GetListByUrl(listInstance.Url);
                Assert.IsNotNull(list);
                
                var items = list.GetItems(CamlQuery.CreateAllItemsQuery());
                ctx.Load(items, itms => itms.Include(item => item["Title"]));
                ctx.ExecuteQueryRetry();

                Assert.IsTrue(items.Count == 1);
                Assert.IsTrue(items[0]["Title"].ToString() == "Test");
            }
        }
예제 #4
0
        public void CanProvisionObjects()
        {
            var template     = new ProvisioningTemplate();
            var listInstance = new Core.Framework.Provisioning.Model.ListInstance();

            listInstance.Url          = string.Format("lists/{0}", listName);
            listInstance.Title        = listName;
            listInstance.TemplateType = (int)ListTemplateType.GenericList;

            template.Lists.Add(listInstance);

            using (var ctx = TestCommon.CreateClientContext())
            {
                new ObjectListInstance().ProvisionObjects(ctx.Web, template);

                var list = ctx.Web.GetListByUrl(listInstance.Url);
                Assert.IsNotNull(list);
            }
        }
예제 #5
0
        public void CanProvisionObjects()
        {
            var template = new ProvisioningTemplate();
            var listInstance = new Core.Framework.Provisioning.Model.ListInstance();

            listInstance.Url = string.Format("lists/{0}", listName);
            listInstance.Title = listName;
            listInstance.TemplateType = (int) ListTemplateType.GenericList;

            template.Lists.Add(listInstance);

            using (var ctx = TestCommon.CreateClientContext())
            {
                new ObjectListInstance().ProvisionObjects(ctx.Web, template);

                var list = ctx.Web.GetListByUrl(listInstance.Url);
                Assert.IsNotNull(list);
            }
        }
예제 #6
0
        public void UpdatedListTitleShouldBeAvailableAsToken()
        {
            var listUrl = string.Format("lists/{0}", listName);
            var listId  = "";

            // Create the initial list
            using (var ctx = TestCommon.CreateClientContext())
            {
                var list = ctx.Web.Lists.Add(new ListCreationInformation()
                {
                    Title = listName, TemplateType = (int)ListTemplateType.GenericList, Url = listUrl
                });
                list.EnsureProperty(l => l.Id);
                ctx.ExecuteQueryRetry();
                listId = list.Id.ToString();
            }

            // Update list Title using a provisioning template
            // - Using a clean clientcontext to catch all possible "property not loaded" problems
            using (var ctx = TestCommon.CreateClientContext())
            {
                var updatedListTitle = listName + "_edit";
                var template         = new ProvisioningTemplate();
                var listInstance     = new Core.Framework.Provisioning.Model.ListInstance();
                listInstance.Url          = listUrl;
                listInstance.Title        = updatedListTitle;
                listInstance.TemplateType = (int)ListTemplateType.GenericList;
                template.Lists.Add(listInstance);
                var mockProviderType = typeof(MockProviderForListInstanceTests);
                var providerConfig   = "{listid:" + updatedListTitle + "}+{listurl:" + updatedListTitle + "}";
                template.Providers.Add(new Provider()
                {
                    Assembly = mockProviderType.Assembly.FullName, Type = mockProviderType.FullName, Enabled = true, Configuration = providerConfig
                });
                ctx.Web.ApplyProvisioningTemplate(template);
            }

            // Verify that tokens have been replaced
            var expectedConfig = string.Format("{0}+{1}", listId, listUrl).ToLower();

            Assert.AreEqual(expectedConfig, MockProviderForListInstanceTests.ConfigurationData.ToLower(), "Updated list title is not available as a token.");
        }
예제 #7
0
        public void FolderContentTypeShouldNotBeRemovedFromProvisionedDocumentLibraries()
        {
            using (var ctx = TestCommon.CreateClientContext())
            {
                var listInstance = new Core.Framework.Provisioning.Model.ListInstance();
                listInstance.Url                        = listName;
                listInstance.Title                      = listName;
                listInstance.TemplateType               = (int)ListTemplateType.DocumentLibrary;
                listInstance.ContentTypesEnabled        = true;
                listInstance.RemoveExistingContentTypes = true;
                listInstance.ContentTypeBindings.Add(new ContentTypeBinding {
                    ContentTypeId = BuiltInContentTypeId.DublinCoreName, Default = true
                });
                var template = new ProvisioningTemplate();
                template.Lists.Add(listInstance);

                ctx.Web.ApplyProvisioningTemplate(template);

                var list         = ctx.Web.GetListByUrl(listName);
                var contentTypes = list.EnsureProperty(l => l.ContentTypes);
                Assert.IsTrue(contentTypes.Any(ct => ct.StringId.StartsWith(BuiltInContentTypeId.Folder + "00")), "Folder content type should not be removed from a document library.");
            }
        }
        public void FolderContentTypeShouldNotBeRemovedFromProvisionedDocumentLibraries()
        {
            using (var ctx = TestCommon.CreateClientContext())
            {
                var listInstance = new Core.Framework.Provisioning.Model.ListInstance();
                listInstance.Url = listName;
                listInstance.Title = listName;
                listInstance.TemplateType = (int)ListTemplateType.DocumentLibrary;
                listInstance.ContentTypesEnabled = true;
                listInstance.RemoveExistingContentTypes = true;
                listInstance.ContentTypeBindings.Add(new ContentTypeBinding { ContentTypeId = BuiltInContentTypeId.DublinCoreName, Default = true });
                var template = new ProvisioningTemplate();
                template.Lists.Add(listInstance);

                ctx.Web.ApplyProvisioningTemplate(template);

                var list = ctx.Web.GetListByUrl(listName);
                var contentTypes = list.EnsureProperty(l => l.ContentTypes);
                Assert.IsTrue(contentTypes.Any(ct => ct.StringId.StartsWith(BuiltInContentTypeId.Folder + "00")), "Folder content type should not be removed from a document library.");
            }
        }
예제 #9
0
        public void CanRemoveContentTypeWithoutModifyingContentTypeNewButtonVisibility()
        {
            using (var clientContext = TestCommon.CreateClientContext())
            {
                var web = clientContext.Web;

                // create content types
                var documentCtype = web.ContentTypes.GetById(BuiltInContentTypeId.Document);
                var newCtypeInfo1 = new ContentTypeCreationInformation()
                {
                    Name = "Test_ContentType1",
                    ParentContentType = documentCtype,
                    Group             = "Test content types",
                    Description       = "This is a test content type"
                };
                var newCtypeInfo2 = new ContentTypeCreationInformation()
                {
                    Name = "Test_ContentType2",
                    ParentContentType = documentCtype,
                    Group             = "Test content types",
                    Description       = "This is a test content type"
                };
                var newCtypeInfo3 = new ContentTypeCreationInformation()
                {
                    Name = "Test_ContentType3",
                    ParentContentType = documentCtype,
                    Group             = "Test content types",
                    Description       = "This is a test content type"
                };

                var newCtype1 = web.ContentTypes.Add(newCtypeInfo1);
                var newCtype2 = web.ContentTypes.Add(newCtypeInfo2);
                var newCtype3 = web.ContentTypes.Add(newCtypeInfo3);
                clientContext.Load(newCtype1);
                clientContext.Load(newCtype2);
                clientContext.Load(newCtype3);
                clientContext.ExecuteQueryRetry();

                var newList = new ListCreationInformation()
                {
                    TemplateType = (int)ListTemplateType.DocumentLibrary,
                    Title        = listName,
                    Url          = listName
                };

                var doclib = clientContext.Web.Lists.Add(newList);
                doclib.ContentTypesEnabled = true;
                doclib.ContentTypes.AddExistingContentType(newCtype1);
                doclib.ContentTypes.AddExistingContentType(newCtype3);
                doclib.Update();

                clientContext.Load(newCtype1, ct => ct.Id);
                clientContext.Load(newCtype2, ct => ct.Id);
                clientContext.Load(newCtype3, ct => ct.Id);

                clientContext.Load(doclib.ContentTypes);
                clientContext.Load(doclib.RootFolder, rf => rf.ContentTypeOrder);
                clientContext.ExecuteQueryRetry();

                var contentTypeOrder = doclib.RootFolder.ContentTypeOrder;
                //Make a content type hidden in the new button.
                contentTypeOrder.Remove(contentTypeOrder.First(ct => ct.GetParentIdValue().Equals(newCtype3.Id.StringValue, StringComparison.OrdinalIgnoreCase)));

                doclib.RootFolder.UniqueContentTypeOrder = contentTypeOrder;
                Assert.IsTrue(contentTypeOrder.ElementAt(0).GetParentIdValue().Equals(BuiltInContentTypeId.Document, StringComparison.OrdinalIgnoreCase));

                doclib.RootFolder.Update();
                doclib.Update();

                clientContext.ExecuteQueryRetry();

                var template     = new ProvisioningTemplate();
                var listInstance = new Core.Framework.Provisioning.Model.ListInstance();

                listInstance.Url                 = listName;
                listInstance.Title               = listName;
                listInstance.TemplateType        = (int)ListTemplateType.DocumentLibrary;
                listInstance.ContentTypesEnabled = true;
                listInstance.ContentTypeBindings.Add(new ContentTypeBinding()
                {
                    ContentTypeId = newCtype1.Id.StringValue, Default = true
                });
                listInstance.ContentTypeBindings.Add(new ContentTypeBinding()
                {
                    ContentTypeId = newCtype2.Id.StringValue, Hidden = false
                });

                template.Lists.Add(listInstance);

                var parser = new TokenParser(clientContext.Web, template);

                // Update the List with new default content type
                new ObjectListInstance().ProvisionObjects(clientContext.Web, template, parser, new ProvisioningTemplateApplyingInformation());

                var list = clientContext.Web.GetListByUrl(listInstance.Url);
                Assert.IsNotNull(list);

                clientContext.Load(doclib.RootFolder, rf => rf.UniqueContentTypeOrder);
                clientContext.ExecuteQueryRetry();

                var  actualContentTypeOrder           = doclib.RootFolder.UniqueContentTypeOrder;
                bool isHiddenContentTypeStillHidden   = actualContentTypeOrder.FirstOrDefault(ct => ct.GetParentIdValue().Equals(newCtype3.Id.StringValue, StringComparison.OrdinalIgnoreCase)) == null;
                bool isContentType2VisibleInNewButton = actualContentTypeOrder.FirstOrDefault(ct => ct.GetParentIdValue().Equals(newCtype2.Id.StringValue, StringComparison.OrdinalIgnoreCase)) != null;

                Assert.IsTrue(isHiddenContentTypeStillHidden, "Content type has incorrectly been made visible in the new button");
                Assert.IsTrue(isContentType2VisibleInNewButton, "Content type 2 has not been made visible in the new button");
            }
        }
예제 #10
0
        public void CanProvisionObjects()
        {
            if (TestCommon.AppOnlyTesting())
            {
                Assert.Inconclusive("Taxonomy tests are not supported when testing using app-only");
            }

            var template     = new ProvisioningTemplate();
            var listInstance = new Core.Framework.Provisioning.Model.ListInstance();

            listInstance.Url          = string.Format("lists/{0}", listName);
            listInstance.Title        = listName;
            listInstance.TemplateType = (int)ListTemplateType.GenericList;
            listInstance.FieldRefs.Add(new FieldRef()
            {
                Id = new Guid("23f27201-bee3-471e-b2e7-b64fd8b7ca38")
            });

            using (var ctx = TestCommon.CreateClientContext())
            {
                //Create term
                var taxSession = TaxonomySession.GetTaxonomySession(ctx);
                var termStore  = taxSession.GetDefaultSiteCollectionTermStore();

                // Termgroup
                termGroupId = Guid.NewGuid();
                var termGroup = termStore.CreateGroup("Test_Group_" + DateTime.Now.ToFileTime(), termGroupId);
                ctx.Load(termGroup);

                var termSet = termGroup.CreateTermSet("Test_Termset_" + DateTime.Now.ToFileTime(), Guid.NewGuid(), 1033);
                ctx.Load(termSet);

                Guid   termId   = Guid.NewGuid();
                string termName = "Test_Term_" + DateTime.Now.ToFileTime();

                termSet.CreateTerm(termName, 1033, termId);

                Dictionary <string, string> dataValues = new Dictionary <string, string>();
                dataValues.Add("Title", "Test");
                dataValues.Add("TaxKeyword", $"{termName}|{termId.ToString()}");
                DataRow dataRow = new DataRow(dataValues);

                listInstance.DataRows.Add(dataRow);

                template.Lists.Add(listInstance);


                var parser = new TokenParser(ctx.Web, template);

                // Create the List
                parser = new ObjectListInstance().ProvisionObjects(ctx.Web, template, parser, new ProvisioningTemplateApplyingInformation());

                // Load DataRows
                new ObjectListInstanceDataRows().ProvisionObjects(ctx.Web, template, parser, new ProvisioningTemplateApplyingInformation());

                var list = ctx.Web.GetListByUrl(listInstance.Url);
                Assert.IsNotNull(list);

                var items = list.GetItems(CamlQuery.CreateAllItemsQuery());
                ctx.Load(items, itms => itms.Include(item => item["Title"], i => i["TaxKeyword"]));
                ctx.ExecuteQueryRetry();

                Assert.IsTrue(items.Count == 1);
                Assert.IsTrue(items[0]["Title"].ToString() == "Test");

                //Validate taxonomy field data
                var value = items[0]["TaxKeyword"] as TaxonomyFieldValueCollection;
                Assert.IsNotNull(value);
                Assert.IsTrue(value[0].WssId > 0, "Term WSS ID not set correctly");
                Assert.AreEqual(termName, value[0].Label, "Term label not set correctly");
                Assert.AreEqual(termId.ToString(), value[0].TermGuid, "Term GUID not set correctly");
            }
        }
        public void UpdatedListTitleShouldBeAvailableAsToken()
        {
            var listUrl = string.Format("lists/{0}", listName);
            var listId = "";

            // Create the initial list
            using (var ctx = TestCommon.CreateClientContext())
            {
                var list = ctx.Web.Lists.Add(new ListCreationInformation() { Title = listName, TemplateType = (int)ListTemplateType.GenericList, Url = listUrl });
                list.EnsureProperty(l => l.Id);
                ctx.ExecuteQueryRetry();
                listId = list.Id.ToString();
            }

            // Update list Title using a provisioning template 
            // - Using a clean clientcontext to catch all possible "property not loaded" problems
            using (var ctx = TestCommon.CreateClientContext())
            {
                var updatedListTitle = listName + "_edit";
                var template = new ProvisioningTemplate();
                var listInstance = new Core.Framework.Provisioning.Model.ListInstance();
                listInstance.Url = listUrl;
                listInstance.Title = updatedListTitle;
                listInstance.TemplateType = (int)ListTemplateType.GenericList;
                template.Lists.Add(listInstance);
                var mockProviderType = typeof(MockProviderForListInstanceTests);
                var providerConfig = "{listid:" + updatedListTitle + "}+{listurl:" + updatedListTitle + "}";
                template.Providers.Add(new Provider() { Assembly = mockProviderType.Assembly.FullName, Type = mockProviderType.FullName, Enabled = true, Configuration = providerConfig });
                ctx.Web.ApplyProvisioningTemplate(template);
            }

            // Verify that tokens have been replaced
            var expectedConfig = string.Format("{0}+{1}", listId, listUrl).ToLower();
            Assert.AreEqual(expectedConfig, MockProviderForListInstanceTests.ConfigurationData.ToLower(), "Updated list title is not available as a token.");
    }