Exemplo n.º 1
0
        public void CanDeploy_SecurityGroupLink_OnModuleFile()
        {
            var securityGroup = ModelGeneratorService.GetRandomDefinition <SecurityGroupDefinition>();

            var listDef = ModelGeneratorService.GetRandomDefinition <ListDefinition>(def =>
            {
                def.TemplateType = BuiltInListTemplateTypeId.DocumentLibrary;
            });

            var siteModel = SPMeta2Model
                            .NewSiteModel(site =>
            {
                site.AddSecurityGroup(securityGroup);
            });

            var webModel = SPMeta2Model
                           .NewWebModel(web =>
            {
                web.AddRandomWeb(rndWeb =>
                {
                    rndWeb.AddList(listDef, rndList =>
                    {
                        rndList.AddRandomModuleFile(rndModuleFile =>
                        {
                            rndModuleFile.OnProvisioning <object>(context =>
                            {
                                TurnOffValidation(rndModuleFile);
                            });

                            AddSecurityGroupLinkWithRoleLinks(rndModuleFile, securityGroup);
                        });
                    });
                });
            });

            TestModels(new ModelNode[] { siteModel, webModel });
        }
        public void ShouldFail_On_Invalid_ContentTypeId()
        {
            var isValid = false;

            var model = SPMeta2Model.NewSiteModel(site =>
            {
                site.AddRandomContentType(ct =>
                {
                    (ct.Value as ContentTypeDefinition).ParentContentTypeId = Guid.NewGuid().ToString();
                });
            });

            try
            {
                Service.DeployModel(null, model);
            }
            catch (Exception e)
            {
                isValid = e is SPMeta2ModelDeploymentException &&
                          e.InnerException is SPMeta2ModelValidationException;
            }

            Assert.IsTrue(isValid);
        }
Exemplo n.º 3
0
        public void Incremental_Update_NonSingleton_ModelNodes_Two_Level_Model()
        {
            var contentTypeCounts = Rnd.Int(3) + 3;
            var fieldLinksCount   = Rnd.Int(3) + 3;

            var model = SPMeta2Model.NewSiteModel(site =>
            {
                for (var ctIndex = 0; ctIndex < contentTypeCounts; ctIndex++)
                {
                    site.AddRandomContentType(contentType =>
                    {
                        for (var flIndex = 0; flIndex < fieldLinksCount; flIndex++)
                        {
                            contentType.AddContentTypeFieldLink(new ContentTypeFieldLinkDefinition
                            {
                                FieldId = Rnd.Guid()
                            });
                        }
                    });
                }
            });

            Internal_Incremental_Update_NonSingleton_ModelNodes_SameModels(model);
        }
Exemplo n.º 4
0
        public void CanDeploy_ContentTypeEventReceiver()
        {
            WithExcpectedExceptions(new[] { typeof(SPMeta2UnsupportedModelHostException) }, () =>
            {
                var eventReceiver = ModelGeneratorService.GetRandomDefinition <EventReceiverDefinition>();

                eventReceiver.Assembly = "Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c";
                eventReceiver.Class    = "Microsoft.SharePoint.Help.HelpLibraryEventReceiver";

                eventReceiver.Synchronization = BuiltInEventReceiverSynchronization.Synchronous;
                eventReceiver.Type            = BuiltInEventReceiverType.ItemAdded;

                var model = SPMeta2Model
                            .NewSiteModel(site =>
                {
                    site.AddRandomContentType(contentType =>
                    {
                        contentType.AddEventReceiver(eventReceiver);
                    });
                });

                TestModel(model);
            });
        }
        public void CanDeploy_ContentTypeFieldLink_OnWebContentType()
        {
            var siteFieldOne = ModelGeneratorService.GetRandomDefinition <FieldDefinition>();
            var siteFieldTwo = ModelGeneratorService.GetRandomDefinition <FieldDefinition>();

            var webFieldOne = ModelGeneratorService.GetRandomDefinition <FieldDefinition>();
            var webFieldTwo = ModelGeneratorService.GetRandomDefinition <FieldDefinition>();

            var webContentType = ModelGeneratorService.GetRandomDefinition <ContentTypeDefinition>();

            var siteModel = SPMeta2Model.NewSiteModel(site =>
            {
                site.AddField(siteFieldOne);
                site.AddField(siteFieldTwo);
            });

            var webModel = SPMeta2Model.NewWebModel(web =>
            {
                web.AddRandomWeb(subWeb =>
                {
                    subWeb.AddField(webFieldOne);
                    subWeb.AddField(webFieldTwo);

                    subWeb.AddContentType(webContentType, contentType =>
                    {
                        contentType
                        .AddContentTypeFieldLink(siteFieldOne)
                        .AddContentTypeFieldLink(siteFieldTwo)
                        .AddContentTypeFieldLink(webFieldOne)
                        .AddContentTypeFieldLink(webFieldTwo);
                    });
                });
            });

            TestModels(new[] { siteModel, webModel });
        }
Exemplo n.º 6
0
        //[SampleMetadataTag(Name = BuiltInTagNames.SampleHidden)]
        public void CanDeploySimplePublishingPageLayoutDefinition()
        {
            var publishingPageContentType = new ContentTypeDefinition
            {
                Name  = "M2 Article",
                Id    = new Guid("664CFB31-AFF3-433E-9F3F-D8812199B0BC"),
                Group = "SPMeta2.Samples",
                ParentContentTypeId = BuiltInPublishingContentTypeId.ArticlePage
            };

            var publshingPageLayout = new PublishingPageLayoutDefinition
            {
                Title    = "M2 Article Left Layout",
                FileName = "m2-article-left.aspx",
                // replace with your publishing page layout content
                Content = DefaultPublishingPageLayoutTemplates.ArticleLeft,
                AssociatedContentTypeId = publishingPageContentType.GetContentTypeId(),
                NeedOverride            = true
            };

            var siteModel = SPMeta2Model.NewSiteModel(site =>
            {
                site.AddContentType(publishingPageContentType);
            });

            var rootWebModel = SPMeta2Model.NewWebModel(web =>
            {
                web.AddHostList(BuiltInListDefinitions.Catalogs.MasterPage, list =>
                {
                    list.AddPublishingPageLayout(publshingPageLayout);
                });
            });

            DeployModel(siteModel);
            DeployModel(rootWebModel);
        }
Exemplo n.º 7
0
        public void ShouldFail_On_InternalName_MoreThan_32()
        {
            var isValid = false;

            var model = SPMeta2Model.NewSiteModel(site =>
            {
                site.AddRandomField(ct =>
                {
                    (ct.Value as FieldDefinition).InternalName = Rnd.String(33);
                });
            });

            try
            {
                Service.DeployModel(null, model);
            }
            catch (Exception e)
            {
                isValid = e is SPMeta2ModelDeploymentException &&
                          e.InnerException is SPMeta2ModelValidationException;
            }

            Assert.IsTrue(isValid);
        }
Exemplo n.º 8
0
        public void CanDeploy_WebpartTo_PublishingPageWebPartZone()
        {
            var siteModel = SPMeta2Model.NewSiteModel(site =>
            {
                site.AddSiteFeature(RegSiteFeatures.Publishing);
            });

            TestModel(siteModel);

            var webModel = SPMeta2Model.NewWebModel(web =>
            {
                web.AddWebFeature(BuiltInWebFeatures.SharePointServerPublishing.Inherit(def =>
                {
                    def.Enable = true;
                }));

                web.AddHostList(BuiltInListDefinitions.Pages, list =>
                {
                    list
                    .AddRandomPublishingPage(page =>
                    {
                        page
                        .AddRandomWebpart()
                        .AddRandomWebpart();
                    })
                    .AddRandomPublishingPage(page =>
                    {
                        page
                        .AddRandomWebpart()
                        .AddRandomWebpart();
                    });
                });
            });

            TestModel(webModel);
        }
        public void CanDeploy_SecurityGroup_Under_SecurityGroup()
        {
            var activeDirectoryOrGlobalO365Groups = RunnerEnvironmentUtils.GetEnvironmentVariable(EnvironmentConsts.DefaultTestADGroups)
                                                    .Split(',');

            var randomNestedGroup = Rnd.RandomFromArray(activeDirectoryOrGlobalO365Groups);

            var spGroup     = ModelGeneratorService.GetRandomDefinition <SecurityGroupDefinition>();
            var domainGroup = ModelGeneratorService.GetRandomDefinition <SecurityGroupDefinition>(def =>
            {
                def.Name = randomNestedGroup;
            });

            var siteModel = SPMeta2Model
                            .NewSiteModel(site =>
            {
                site.AddSecurityGroup(spGroup, group =>
                {
                    group.AddSecurityGroup(domainGroup);
                });
            });

            TestModels(new ModelNode[] { siteModel });
        }
Exemplo n.º 10
0
        public void CanDeploy_Webpart_With_AuthorizationFilter()
        {
            var securityGroupDef = ModelGeneratorService.GetRandomDefinition <SecurityGroupDefinition>(def =>
            {
                def.DefaultUser = string.Empty;
                def.Owner       = string.Empty;
            });

            var siteModel = SPMeta2Model.NewSiteModel(site =>
            {
                site.AddSecurityGroup(securityGroupDef);
            });


            var webModel = SPMeta2Model.NewWebModel(web =>
            {
                web.AddWebFeature(BuiltInWebFeatures.WikiPageHomePage.Inherit(def =>
                {
                    def.Enable = true;
                }));

                web.AddHostList(BuiltInListDefinitions.SitePages, list =>
                {
                    list.AddRandomWebPartPage(page =>
                    {
                        page.AddRandomWebpart(webPart =>
                        {
                            var wpDef = webPart.Value as WebPartDefinition;
                            wpDef.AuthorizationFilter = string.Format(";;;;{0}", securityGroupDef.Name);
                        });
                    });
                });
            });

            TestModel(siteModel, webModel);
        }
Exemplo n.º 11
0
        public void ABigPictureSample(ClientContext clientContext)
        {
            // Step 1, create 'definitions' - a bunch of CSharp POCO objects
            var clientDescriptionField = new FieldDefinition
            {
                Title        = "Client Description",
                InternalName = "dcs_ClientDescription",
                Group        = DocConsts.DefaulFieldsGroup,
                Id           = new Guid("06975b67-01f5-47d7-9e2e-2702dfb8c217"),
                FieldType    = BuiltInFieldTypes.Note,
            };

            var customerAccountContentType = new ContentTypeDefinition
            {
                Name = "Customer Account",
                Id   = new Guid("ddc46a66-19a0-460b-a723-c84d7f60a342"),
                ParentContentTypeId = BuiltInContentTypeId.Item,
                Group = DocConsts.DefaultContentTypeGroup
            };

            // step 2, define relationships between definitions
            // we need to build a logical 'model tree'

            // fields and content types live under site
            // so use SiteModel and add fields/content types under site
            var siteModel = SPMeta2Model.NewSiteModel(site =>
            {
                site.AddField(clientDescriptionField);
                site.AddContentType(customerAccountContentType);
            });

            // step 3, deploy site model via CSOM
            var csomProvisionService = new CSOMProvisionService();

            csomProvisionService.DeploySiteModel(clientContext, siteModel);
        }
Exemplo n.º 12
0
        public void CanDeploy_UserField_BindedBySecurityGroupId()
        {
            var securityGroup = ModelGeneratorService.GetRandomDefinition <SecurityGroupDefinition>();
            var userField     = ModelGeneratorService.GetRandomDefinition <UserFieldDefinition>(def =>
            {
                def.SelectionGroup     = null;
                def.SelectionGroupName = string.Empty;
            });

            var siteModel = SPMeta2Model.NewSiteModel(site =>
            {
                site
                .AddSecurityGroup(securityGroup, group =>
                {
                    group.OnProvisioned <object>(context =>
                    {
                        userField.SelectionGroup = ExtractGroupId(context);
                    });
                })
                .AddUserField(userField);
            });

            TestModel(siteModel);
        }
Exemplo n.º 13
0
        public void CanDeploy_WebpartToPublishingPageWebPartZone()
        {
            var siteModel = SPMeta2Model
                            .NewSiteModel(site =>
            {
                site
                .AddSiteFeature(RegSiteFeatures.Publishing);
            });

            TestModel(siteModel);

            var webModel = SPMeta2Model
                           .NewWebModel(web =>
            {
                web
                .AddFeature(RegWebFeatures.Publishing)
                .AddHostList(BuiltInListDefinitions.Pages, list =>
                {
                    list
                    .AddRandomPublishingPage(page =>
                    {
                        page
                        .AddRandomWebpart()
                        .AddRandomWebpart();
                    })
                    .AddRandomPublishingPage(page =>
                    {
                        page
                        .AddRandomWebpart()
                        .AddRandomWebpart();
                    });
                });
            });

            TestModel(webModel);
        }
Exemplo n.º 14
0
        public void CanDeploy_TaxonomyTermByName()
        {
            var term = ModelGeneratorService.GetRandomDefinition <TaxonomyTermDefinition>(def =>
            {
            });

            var model = SPMeta2Model
                        .NewSiteModel(site =>
            {
                site
                .AddRandomTermStore(store =>
                {
                    store.AddRandomTermGroup(group =>
                    {
                        group.AddRandomTermSet(termSet =>
                        {
                            termSet.AddTaxonomyTerm(term);
                        });
                    });
                });
            });

            TestModel(model);
        }
Exemplo n.º 15
0
        //[SampleMetadataTag(Name = BuiltInTagNames.SampleHidden)]
        public void CanProvisionRootWebLists()
        {
            var rootWeb = new RootWebDefinition
            {
            };

            var model = SPMeta2Model.NewSiteModel(site =>
            {
                site.AddRootWeb(rootWeb, web =>
                {
                    web
                    .AddHostList(BuiltInListDefinitions.StyleLibrary, list =>
                    {
                        // do stuff with 'Style Library'
                    })
                    .AddHostList(BuiltInListDefinitions.Catalogs.MasterPage, list =>
                    {
                        // do stuff with 'Master Page Library'
                    });
                });
            });

            DeployModel(model);
        }
Exemplo n.º 16
0
        public void CanDeploy_Default_PublishingPage_WithRequiredFields()
        {
            var siteFeature = BuiltInSiteFeatures.SharePointServerPublishingInfrastructure.Inherit(f => f.Enable());
            var webFeature  = BuiltInWebFeatures.SharePointServerPublishing.Inherit(f => f.Enable());

            var publishingPageLayoutContentType = ModelGeneratorService.GetRandomDefinition <ContentTypeDefinition>(def =>
            {
                def.Name   = string.Format("Required - {0}", Environment.TickCount);
                def.Hidden = false;
                def.ParentContentTypeId = BuiltInPublishingContentTypeId.ArticlePage;
            });

            var requiredText = ModelGeneratorService.GetRandomDefinition <TextFieldDefinition>(def =>
            {
                def.ShowInDisplayForm    = true;
                def.ShowInEditForm       = true;
                def.ShowInListSettings   = true;
                def.ShowInNewForm        = true;
                def.ShowInVersionHistory = true;
                def.ShowInViewForms      = true;

                def.ValidationFormula = null;
                def.ValidationMessage = null;

                def.Hidden = false;

                def.DefaultValue = string.Empty;
                def.Required     = true;
            });

            var publishingPageLayout = ModelGeneratorService.GetRandomDefinition <PublishingPageLayoutDefinition>(def =>
            {
                def.AssociatedContentTypeId = publishingPageLayoutContentType.GetContentTypeId();
            });

            var page = ModelGeneratorService.GetRandomDefinition <PublishingPageDefinition>(def =>
            {
                def.PageLayoutFileName = publishingPageLayout.FileName;

                def.DefaultValues.Add(new FieldValue()
                {
                    FieldName = requiredText.InternalName,
                    Value     = Rnd.String()
                });
            });

            var siteModel = SPMeta2Model.NewSiteModel(site =>
            {
                site.AddSiteFeature(siteFeature);

                site.AddField(requiredText);

                site.AddContentType(publishingPageLayoutContentType, contentType =>
                {
                    contentType.AddContentTypeFieldLink(requiredText);
                });
            });

            var webModel = SPMeta2Model.NewWebModel(web =>
            {
                web.AddWebFeature(webFeature);

                web.AddHostList(BuiltInListDefinitions.Catalogs.MasterPage, list =>
                {
                    list.AddPublishingPageLayout(publishingPageLayout);
                });

                web.AddHostList(BuiltInListDefinitions.Pages, list =>
                {
                    list.AddContentTypeLink(publishingPageLayoutContentType);

                    list.AddPublishingPage(page);
                });
            });

            TestModels(new  ModelNode[] { siteModel, webModel });
        }
        public void CanDeploySimpleBreakRoleInheritance_OnList()
        {
            var privateListDef = new ListDefinition
            {
                Title        = "Private records",
                TemplateType = BuiltInListTemplateTypeId.GenericList,
                CustomUrl    = "lists/private-records",
            };

            var privateProjectWebBreakRoleInheritance = new BreakRoleInheritanceDefinition
            {
                CopyRoleAssignments = false
            };

            var privateSecurityGroupMembers = new SecurityGroupDefinition
            {
                Name = "Private Project Group Members"
            };

            var privateSecurityGroupViewers = new SecurityGroupDefinition
            {
                Name = "Private Project Group Viewers"
            };

            // site model with the groups
            var siteModel = SPMeta2Model.NewSiteModel(site =>
            {
                site.AddSecurityGroup(privateSecurityGroupMembers);
                site.AddSecurityGroup(privateSecurityGroupViewers);
            });

            // web model
            var webModel = SPMeta2Model.NewWebModel(web =>
            {
                web.AddList(privateListDef, publicProjectWeb =>
                {
                    publicProjectWeb.AddBreakRoleInheritance(privateProjectWebBreakRoleInheritance, privateResetList =>
                    {
                        // privateResetList is your list but after breaking role inheritance

                        // link group with roles by SecurityRoleType / SecurityRoleName
                        // use BuiltInSecurityRoleTypes or BuiltInSecurityRoleNames

                        // add group with contributor permission
                        privateResetList.AddSecurityGroupLink(privateSecurityGroupMembers, group =>
                        {
                            group.AddSecurityRoleLink(new SecurityRoleLinkDefinition
                            {
                                SecurityRoleType = BuiltInSecurityRoleTypes.Contributor
                            });
                        });

                        // add group with reader permission
                        privateResetList.AddSecurityGroupLink(privateSecurityGroupViewers, group =>
                        {
                            group.AddSecurityRoleLink(new SecurityRoleLinkDefinition
                            {
                                SecurityRoleType = BuiltInSecurityRoleTypes.Reader
                            });
                        });
                    });
                });
            });

            // deploy site model with groups, and then web model with the rest
            DeployModel(siteModel);
            DeployModel(webModel);
        }
        public void Can_Find_ListView_WithInList()
        {
            // Problem with webpart deployment to display form #891
            // https://github.com/SubPointSolutions/spmeta2/issues/891

            var hasHit      = false;
            var listViewDef = ModelGeneratorService.GetRandomDefinition <ListViewDefinition>();

            // once model is deployed with the XsltLIstViewWebPart pointing to StyleLibrary
            // we expect to have the following views on the collection:

            //  targetList.RootFolder.Url   "Lists/TestList3"   string
            //  targetList.Views[0].ServerRelativeUrl   "/Lists/TestList3/AllItems.aspx"    string
            //  targetList.Views[1].ServerRelativeUrl   "/Lists/TestList1/DispForm.aspx"    string
            //  targetList.Views[2].ServerRelativeUrl   "/Lists/TestList3/AllItems3.aspx"   string

            // so that the issue is that DispForm.aspx does not belong to the TestList3!
            // listv view lookup service must not find that view!

            var webDef = ModelGeneratorService.GetRandomDefinition <WebDefinition>();

            var contentTypesModel = SPMeta2Model
                                    .NewSiteModel(site =>
            {
                site
                .AddContentType(ContentTypes.MyType1)
                .AddContentType(ContentTypes.MyType2)
                .AddContentType(ContentTypes.MyType3);
            });

            var listsModel = SPMeta2Model.NewWebModel(rootWeb =>
            {
                rootWeb.AddWeb(webDef, web =>
                {
                    web
                    .AddList(Lists.TestList1)
                    .AddList(Lists.TestList2)
                    .AddList(Lists.TestList3);
                });
            });

            var webModel = SPMeta2Model.NewWebModel(rootWeb =>
            {
                rootWeb.AddWeb(webDef, web =>
                {
                    web
                    .AddList(Lists.TestList1, list =>
                    {
                        list
                        .AddHideContentTypeLinks(new HideContentTypeLinksDefinition
                        {
                            ContentTypes = { new ContentTypeLinkValue()
                                             {
                                                 ContentTypeName = "Item"
                                             }, new ContentTypeLinkValue()
                                             {
                                                 ContentTypeName = "Элемент"
                                             } }
                        })
                        .AddContentTypeLink(ContentTypes.MyType1)
                        .AddListView(Views.View1)
                        .AddHostListView(BuiltInListViewDefinitions.Lists.DispForm, view =>
                        {
                            view.AddWebPart(WebParts.TestWebPart3);
                        });
                    })
                    .AddList(Lists.TestList2, list =>
                    {
                        list
                        .AddHideContentTypeLinks(new HideContentTypeLinksDefinition
                        {
                            ContentTypes = { new ContentTypeLinkValue()
                                             {
                                                 ContentTypeName = "Item"
                                             }, new ContentTypeLinkValue()
                                             {
                                                 ContentTypeName = "Элемент"
                                             } }
                        })
                        .AddContentTypeLink(ContentTypes.MyType2)
                        .AddListView(Views.View2)
                        .AddHostListView(BuiltInListViewDefinitions.Lists.AllItems, view =>
                        {
                            view.AddWebPart(WebParts.TestWebPart1);
                        });
                    })
                    .AddList(Lists.TestList3, list =>
                    {
                        list
                        .AddHideContentTypeLinks(new HideContentTypeLinksDefinition
                        {
                            ContentTypes = { new ContentTypeLinkValue()
                                             {
                                                 ContentTypeName = "Item"
                                             }, new ContentTypeLinkValue()
                                             {
                                                 ContentTypeName = "Элемент"
                                             } }
                        })
                        .AddContentTypeLink(ContentTypes.MyType3)
                        .AddListView(Views.View3)
                        .AddHostListView(BuiltInListViewDefinitions.Lists.DispForm, view =>
                        {
                            view.AddWebPart(WebParts.TestWebPart2);
                        });
                    });
                });
            });

            ProvisionRunner.DeploySiteModel(contentTypesModel);
            ProvisionRunner.DeployWebModel(listsModel);

            ProvisionRunner.DeployWebModel(webModel);
            ProvisionRunner.DeployWebModel(webModel);

            ProvisionRunner.WithSSOMSiteAndWebContext((site, rootWeb) =>
            {
                using (var web = site.OpenWeb(webDef.Url))
                {
                    hasHit = true;

                    //  targetList.RootFolder.Url   "Lists/TestList3"   string
                    //  targetList.Views[0].ServerRelativeUrl   "/Lists/TestList3/AllItems.aspx"    string
                    //  targetList.Views[1].ServerRelativeUrl   "/Lists/TestList1/DispForm.aspx"    string
                    //  targetList.Views[2].ServerRelativeUrl   "/Lists/TestList3/AllItems3.aspx"   string

                    var listTitle = Lists.TestList3.Title;

                    var currentList    = web.Lists[listTitle];
                    var currentListUrl = currentList.RootFolder.Url;

                    var ownViews = currentList.Views.OfType <SPView>()
                                   .Where(v => v.Url.ToUpper().StartsWith(currentListUrl.ToUpper()));

                    var alienViews = currentList.Views.OfType <SPView>()
                                     .Where(v => !(v.Url.ToUpper().StartsWith(currentListUrl.ToUpper())));

                    // there must be a few correct views and the other one from the othe list (by URL)
                    Assert.IsTrue(ownViews.Count() > 0);
                    Assert.IsTrue(alienViews.Count() > 0);

                    // lookup service must not find the DispForm.aspx view
                    // it does not belong to a list
                    var view = Service.FindView(currentList, BuiltInListViewDefinitions.Lists.DispForm);

                    Assert.IsNull(view);
                }
            });

            Assert.IsTrue(hasHit);
        }
Exemplo n.º 19
0
        private void InternalDeploySiteFieldWithPushChangesToLists(bool pushChangesToLists)
        {
            var oldFieldTitle = Rnd.String();
            var newFieldTitle = Rnd.String();

            var oldSharePointFieldTitle = string.Empty;
            var newSharePointFieldTitle = string.Empty;

            // defs
            var oldFieldDef = ModelGeneratorService.GetRandomDefinition <TextFieldDefinition>(def =>
            {
                def.DefaultFormula    = string.Empty;
                def.ValidationFormula = string.Empty;

                def.Title = oldFieldTitle;
            });

            var newFieldDef = oldFieldDef.Inherit(def =>
            {
                def.DefaultFormula    = string.Empty;
                def.ValidationFormula = string.Empty;

                def.Title = newFieldTitle;

                def.PushChangesToLists = pushChangesToLists;
            });

            var oldListDef = ModelGeneratorService.GetRandomDefinition <ListDefinition>(def =>
            {
            });

            var newListDef = oldListDef.Inherit(def =>
            {
            });

            var oldListFielLink = new ListFieldLinkDefinition
            {
                FieldId = oldFieldDef.Id
            };

            var newListFielLink = new ListFieldLinkDefinition
            {
                FieldId = oldFieldDef.Id
            };

            var oldSiteModel = SPMeta2Model.NewSiteModel(site =>
            {
                site.AddField(oldFieldDef);
            });

            var oldWebModel = SPMeta2Model.NewWebModel(web =>
            {
                web.AddList(oldListDef, list =>
                {
                    list.AddListFieldLink(oldListFielLink);
                });
            });

            var newWebModel = SPMeta2Model.NewWebModel(web =>
            {
                web.AddList(newListDef, list =>
                {
                    list.AddListFieldLink(newListFielLink);
                });
            });

            var newSiteModel = SPMeta2Model.NewSiteModel(site =>
            {
                site.AddField(newFieldDef);
            });

            // passing Reg_Title as definition PropertyBag
            // later, validation handlers foe ListFieldLink will use Reg_Title instead of title
            // bit if a hack
            if (pushChangesToLists)
            {
                newListFielLink.PropertyBag.Add(new PropertyBagValue
                {
                    Name  = "_Reg_DisplayName",
                    Value = newFieldTitle
                });
            }
            else
            {
                newListFielLink.PropertyBag.Add(new PropertyBagValue
                {
                    Name  = "_Reg_DisplayName",
                    Value = oldFieldTitle
                });
            }

            // deploy initial field and list
            TestModel(oldSiteModel);
            TestModel(oldWebModel);

            // deploy 'new' field model
            TestModel(newSiteModel);
            TestModel(newWebModel);
        }
Exemplo n.º 20
0
        public void CanDeploy_SiteModel()
        {
            var model = SPMeta2Model.NewSiteModel(m => { });

            TestModel(model);
        }
Exemplo n.º 21
0
        public ModelNode GenerateModelTreeForDefinition(Type definitionType, SPObjectModelType objectModelType)
        {
            ModelNode result = null;

            var rootHostType   = GetRootHostType(definitionType, objectModelType);
            var parentHostType = GetParentHostType(definitionType, objectModelType);

            var currentDefinition       = GetRandomDefinition(definitionType);
            var expectManyInstancesAttr = definitionType.GetCustomAttribute <ExpectManyInstances>(false);

            var manyInstances = new List <DefinitionBase>();

            if (expectManyInstancesAttr != null)
            {
                var maxCount = expectManyInstancesAttr.MinInstancesCount +
                               Rnd.Int(expectManyInstancesAttr.MaxInstancesCount -
                                       expectManyInstancesAttr.MinInstancesCount);

                for (int i = 0; i < maxCount; i++)
                {
                    manyInstances.Add(GetRandomDefinition(definitionType));
                }
            }

            CurrentDefinitions.Clear();

            CurrentDefinitions.Add(currentDefinition);
            CurrentDefinitions.AddRange(manyInstances);

            //CurrentDefinition = currentDefinition;

            var defs = new List <GeneratedNodes>();

            LookupModelTree(rootHostType, definitionType, defs, objectModelType);

            if (defs.Count > 0)
            {
                defs.Reverse();

                var rootHost = defs[0].ModelNode;
                parentHostType = rootHost.Value.GetType();

                defs.RemoveAt(0);

                ModelNode model = null;

                if (parentHostType == typeof(FarmDefinition))
                {
                    model = SPMeta2Model.NewFarmModel();
                }

                if (parentHostType == typeof(WebApplicationDefinition))
                {
                    model = SPMeta2Model.NewWebApplicationModel();
                }

                if (parentHostType == typeof(SiteDefinition))
                {
                    model = SPMeta2Model.NewSiteModel();
                }

                if (parentHostType == typeof(WebDefinition))
                {
                    model = SPMeta2Model.NewWebModel();
                }

                var _m = model;

                foreach (var def in defs)
                {
                    _m.ChildModels.Add(def.ModelNode);
                    _m = def.ModelNode;
                }

                _m.AddDefinitionNode(currentDefinition);

                foreach (var manyDef in manyInstances)
                {
                    _m.AddDefinitionNode(manyDef);
                }

                result = model;
            }
            else
            {
                ModelNode resultModel = null;

                if (currentDefinition.GetType() == typeof(FarmDefinition))
                {
                    resultModel = SPMeta2Model.NewFarmModel();
                }

                if (currentDefinition.GetType() == typeof(WebApplicationDefinition))
                {
                    resultModel = SPMeta2Model.NewWebApplicationModel();
                }

                if (currentDefinition.GetType() == typeof(SiteDefinition))
                {
                    resultModel = SPMeta2Model.NewSiteModel();
                }

                if (currentDefinition.GetType() == typeof(WebDefinition))
                {
                    resultModel = SPMeta2Model.NewWebModel();
                }

                if (resultModel == null)
                {
                    throw new SPMeta2NotImplementedException(string.Format("Cannot find host model for type:[{0}]. Ensure correct RootHostAttribute/ParentHostAttribute/SPObjectTypeAttribute attributes.", definitionType.AssemblyQualifiedName));
                }

                resultModel.Value = currentDefinition;
                result            = resultModel;
            }

            // ProcessAdditionalArtifacts(result, defs);

            return(result);
        }
Exemplo n.º 22
0
        public void CanPassTypedSyntax_SiteLevel()
        {
            var model = SPMeta2Model.NewSiteModel(site =>
            {
                site.AddSharePointDesignerSettings(new SharePointDesignerSettingsDefinition());

                site.AddRootWeb(new RootWebDefinition {
                }, rootWeb =>
                {
                    rootWeb.AddTopNavigationNode(new TopNavigationNodeDefinition());
                });

                site.AddCoreProperty(new CorePropertyDefinition())
                .AddCoreProperty(new CorePropertyDefinition(), property =>
                {
                    property.AddProfileTypeProperty(new ProfileTypePropertyDefinition());
                });


                site.AddAuditSettings(new AuditSettingsDefinition());
                site.AddImageRendition(new ImageRenditionDefinition());

                site.AddRootWeb(new RootWebDefinition());

                site.AddEventReceiver(new EventReceiverDefinition());

                site
                .AddProperty(new PropertyDefinition())
                .AddProperty(new PropertyDefinition());

                site.AddFeature(new FeatureDefinition());
                site.AddSiteFeature(new FeatureDefinition());

                site.AddSecurityGroup(new SecurityGroupDefinition(), group =>
                {
                    group
                    .AddUser(new UserDefinition())
                    .AddUser(new UserDefinition());

                    // TODO

                    // .AddSecurityRoleLink() is missed on SecurityGroup #601
                    // https://github.com/SubPointSolutions/spmeta2/issues/601
                    group.AddSecurityRoleLink(new SecurityRoleLinkDefinition());
                    group.AddSecurityRoleLink(new SecurityRoleLinkDefinition());
                });

                site.AddSecurityRole(new SecurityRoleDefinition());

                site.AddWeb(new WebDefinition());

                site.AddField(new FieldDefinition());
                site.AddContentType(new ContentTypeDefinition(), contentType =>
                {
                    contentType
                    .AddContentTypeFieldLink(new ContentTypeFieldLinkDefinition())
                    .AddModuleFile(new ModuleFileDefinition())

                    .AddUniqueContentTypeFieldsOrder(new UniqueContentTypeFieldsOrderDefinition())
                    .AddHideContentTypeFieldLinks(new HideContentTypeFieldLinksDefinition())
                    .AddRemoveContentTypeFieldLinks(new RemoveContentTypeFieldLinksDefinition());
                });

                site.AddSandboxSolution(new SandboxSolutionDefinition());

                site.AddTaxonomyTermStore(new TaxonomyTermStoreDefinition(), store =>
                {
                    store.AddTaxonomyTermGroup(new TaxonomyTermGroupDefinition(), group =>
                    {
                        group.AddTaxonomyTermSet(new TaxonomyTermSetDefinition(), termSet =>
                        {
                            termSet.AddTaxonomyTerm(new TaxonomyTermDefinition(), term =>
                            {
                                term.AddTaxonomyTerm(new TaxonomyTermDefinition());

                                // .AddTaxonomyTermLabel() is missed on TaxonomyTermDefinition #602
                                // https://github.com/SubPointSolutions/spmeta2/issues/602
                                term.AddTaxonomyTermLabel(new TaxonomyTermLabelDefinition());
                            });
                        });
                    });
                });

                site.AddRootWeb(new RootWebDefinition());
                site.AddWeb(new WebDefinition());

                site.AddUserCustomAction(new UserCustomActionDefinition());
            });
        }
Exemplo n.º 23
0
        private ContentTypeEnvironment GetContentTypeLinksSandbox(
            Action <SiteModelNode, ContentTypeEnvironment> siteModelConfig,
            Action <WebModelNode, ContentTypeEnvironment> webModelConfig,
            Action <ListModelNode, ContentTypeEnvironment> listModelConfig)
        {
            var result = new ContentTypeEnvironment();

            // site model

            ContentTypeDefinition ctFirst  = null;
            ContentTypeDefinition ctSecond = null;
            ContentTypeDefinition ctThird  = null;

            var siteModel = SPMeta2Model
                            .NewSiteModel(site =>
            {
                site
                .AddRandomContentType(ct => { ctFirst = ct.Value as ContentTypeDefinition; })
                .AddRandomContentType(ct => { ctSecond = ct.Value as ContentTypeDefinition; })
                .AddRandomContentType(ct => { ctThird = ct.Value as ContentTypeDefinition; });
            });

            ctFirst.Name  = "first_" + ctFirst.Name;
            ctSecond.Name = "second_" + ctSecond.Name;
            ctThird.Name  = "third_" + ctThird.Name;

            result.First  = ctFirst;
            result.Second = ctSecond;
            result.Third  = ctThird;

            result.SiteModel = siteModel;

            if (siteModelConfig != null)
            {
                siteModelConfig(result.SiteModel, result);
            }

            // web model
            var webModel = SPMeta2Model
                           .NewWebModel(web =>
            {
                web
                .AddRandomList(list =>
                {
                    list
                    .AddContentTypeLink(ctFirst, link =>
                    {
                        result.FirstLink = link;
                        //link.Options.RequireSelfProcessing = link.Value.RequireSelfProcessing = true;
                        link.Options.RequireSelfProcessing = true;
                    })
                    .AddContentTypeLink(ctSecond, link =>
                    {
                        result.SecondLink = link;
                        //link.Options.RequireSelfProcessing = link.Value.RequireSelfProcessing = true;
                        link.Options.RequireSelfProcessing = true;
                    })
                    .AddContentTypeLink(ctThird, link =>
                    {
                        result.ThirdLink = link;
                        //link.Options.RequireSelfProcessing = link.Value.RequireSelfProcessing = true;
                        link.Options.RequireSelfProcessing = true;
                    });

                    result.List = list.Value as ListDefinition;

                    if (listModelConfig != null)
                    {
                        listModelConfig(list, result);
                    }
                });
            });

            result.WebModel = webModel;

            if (webModelConfig != null)
            {
                webModelConfig(result.WebModel, result);
            }

            return(result);
        }
        public void CanDeploy_ModuleFile_With_RequiredFieldValues()
        {
            var requiredText = RItemValues.GetRequiredTextField(ModelGeneratorService);

            var text1 = RItemValues.GetRandomTextField(ModelGeneratorService);
            var text2 = RItemValues.GetRandomTextField(ModelGeneratorService);

            var contentTypeDef = ModelGeneratorService.GetRandomDefinition <ContentTypeDefinition>(def =>
            {
                def.ParentContentTypeId = BuiltInContentTypeId.Item;
            });

            var itemDef = ModelGeneratorService.GetRandomDefinition <ModuleFileDefinition>(def =>
            {
                def.Title           = Rnd.String();
                def.ContentTypeName = contentTypeDef.Name;

                def.DefaultValues.Add(new FieldValue()
                {
                    FieldName = requiredText.InternalName,
                    Value     = Rnd.String()
                });

                def.Values.Add(new FieldValue()
                {
                    FieldName = text1.InternalName,
                    Value     = Rnd.String()
                });

                def.Values.Add(new FieldValue()
                {
                    FieldName = text2.InternalName,
                    Value     = Rnd.String()
                });
            });

            var listDef = ModelGeneratorService.GetRandomDefinition <ListDefinition>(def =>
            {
                def.ContentTypesEnabled = true;
                def.TemplateType        = BuiltInListTemplateTypeId.DocumentLibrary;
            });

            var siteModel = SPMeta2Model.NewSiteModel(site =>
            {
                site.AddField(requiredText);
                site.AddField(text1);
                site.AddField(text2);

                site.AddContentType(contentTypeDef, contentType =>
                {
                    contentType.AddContentTypeFieldLink(requiredText);
                    contentType.AddContentTypeFieldLink(text1);
                    contentType.AddContentTypeFieldLink(text2);
                });
            });

            var webModel = SPMeta2Model.NewWebModel(web =>
            {
                web.AddList(listDef, list =>
                {
                    list.AddContentTypeLink(contentTypeDef);
                    list.AddModuleFile(itemDef);
                });
            });

            TestModel(siteModel, webModel);
        }
Exemplo n.º 25
0
        protected LookupFieldEnvironment GetLookupFieldEnvironment(Action <LookupFieldEnvironment> action)
        {
            var result = new LookupFieldEnvironment();

            var dataList = ModelGeneratorService.GetRandomDefinition <ListDefinition>(def =>
            {
                def.TemplateType = BuiltInListTemplateTypeId.GenericList;
            });

            var masterList = ModelGeneratorService.GetRandomDefinition <ListDefinition>(def =>
            {
                def.TemplateType = BuiltInListTemplateTypeId.GenericList;
            });

            var lookupField = GetSingleSelectLookupDefinition(def =>
            {
                def.Indexed = false;
                //def.LookupListTitle = dataList.Title;
            });

            ModelNode childListNode = null;

            var siteModel = SPMeta2Model.NewSiteModel(site =>
            {
                site.AddField(lookupField);
            });

            var childWebModel = SPMeta2Model.NewWebModel(web =>
            {
                web.AddList(dataList, list =>
                {
                    childListNode = list;

                    list
                    .AddRandomListItem()
                    .AddRandomListItem()
                    .AddRandomListItem();
                });
            });

            var masterWebModel = SPMeta2Model.NewWebModel(web =>
            {
                web
                .AddList(masterList, list =>
                {
                    list.AddListFieldLink(lookupField);
                });
            });

            result.LookupField = lookupField;

            result.ChildList      = dataList;
            result.ChildListNode  = childListNode;
            result.ChildListModel = childWebModel;


            result.MasterList      = masterList;
            result.MasterListModel = masterWebModel;

            result.SiteModel = siteModel;

            if (action != null)
            {
                action(result);
            }

            return(result);
        }
Exemplo n.º 26
0
        public void CanDeploy_TaxonomyTerms_WithCustomProperties()
        {
            var term = ModelGeneratorService.GetRandomDefinition <TaxonomyTermDefinition>(def =>
            {
                def.CustomProperties.Add(new TaxonomyTermCustomProperty
                {
                    Name  = Rnd.String(),
                    Value = Rnd.String()
                });

                def.CustomProperties.Add(new TaxonomyTermCustomProperty
                {
                    Name  = Rnd.String(),
                    Value = Rnd.HttpUrl()
                });

                def.CustomProperties.Add(new TaxonomyTermCustomProperty
                {
                    Name  = Rnd.Int().ToString(),
                    Value = Rnd.Int().ToString()
                });
            });

            var subTerm = ModelGeneratorService.GetRandomDefinition <TaxonomyTermDefinition>(def =>
            {
                def.CustomProperties.Add(new TaxonomyTermCustomProperty
                {
                    Name  = Rnd.String(),
                    Value = Rnd.String()
                });

                def.CustomProperties.Add(new TaxonomyTermCustomProperty
                {
                    Name  = Rnd.String(),
                    Value = Rnd.HttpUrl()
                });

                def.CustomProperties.Add(new TaxonomyTermCustomProperty
                {
                    Name  = Rnd.Int().ToString(),
                    Value = Rnd.Int().ToString()
                });
            });

            var model = SPMeta2Model
                        .NewSiteModel(site =>
            {
                site
                .AddRandomTermStore(store =>
                {
                    store.AddRandomTermGroup(group =>
                    {
                        group.AddRandomTermSet(termSet =>
                        {
                            termSet.AddTaxonomyTerm(term, t =>
                            {
                                t.AddTaxonomyTerm(subTerm);
                            });
                        });
                    });
                });
            });

            TestModel(model);
        }
Exemplo n.º 27
0
        public void CanDeploy_WebNavigationSettings_As_TaxonomyProvider()
        {
            var globalTerm   = Rnd.String();
            var currentlTerm = Rnd.String();

            var currentNavigationGroup = new TaxonomyTermGroupDefinition
            {
                Name = string.Format("{0}", globalTerm)
            };

            var currentNavigationTermSet = new TaxonomyTermSetDefinition
            {
                Name = string.Format("{0}", globalTerm)
            };

            var globalNavigationGroup = new TaxonomyTermGroupDefinition
            {
                Name = string.Format("{0}", currentlTerm)
            };

            var globalNavigationTermSet = new TaxonomyTermSetDefinition
            {
                Name = string.Format("{0}", currentlTerm)
            };

            var taxWeb = ModelGeneratorService.GetRandomDefinition <WebDefinition>(def =>
            {
            });

            var siteModel = SPMeta2Model.NewSiteModel(site =>
            {
                site.AddSiteFeature(BuiltInSiteFeatures.SharePointServerPublishingInfrastructure.Inherit(def =>
                {
                    def.Enable = true;
                }));

                site.AddTaxonomyTermStore(new TaxonomyTermStoreDefinition
                {
                    UseDefaultSiteCollectionTermStore = true
                },
                                          store =>
                {
                    store.AddTaxonomyTermGroup(currentNavigationGroup, group =>
                    {
                        group.AddTaxonomyTermSet(currentNavigationTermSet, termSet =>
                        {
                            termSet.AddRandomTerm();
                            termSet.AddRandomTerm();
                            termSet.AddRandomTerm();
                        });
                    });

                    store.AddTaxonomyTermGroup(globalNavigationGroup, group =>
                    {
                        group.AddTaxonomyTermSet(globalNavigationTermSet, termSet =>
                        {
                            termSet.AddRandomTerm();
                            termSet.AddRandomTerm();
                            termSet.AddRandomTerm();
                        });
                    });
                });
            });

            var webModel = SPMeta2Model.NewWebModel(web =>
            {
                web.AddWeb(taxWeb, subWeb =>
                {
                    subWeb.AddSiteFeature(BuiltInWebFeatures.SharePointServerPublishing.Inherit(def =>
                    {
                        def.Enable = true;
                    }));

                    subWeb.AddWebNavigationSettings(new WebNavigationSettingsDefinition()
                    {
                        CurrentNavigationSource = BuiltInStandardNavigationSources.TaxonomyProvider,

                        CurrentNavigationUseDefaultSiteCollectionTermStore = true,
                        CurrentNavigationTermSetName = currentNavigationGroup.Name,

                        GlobalNavigationSource = BuiltInStandardNavigationSources.TaxonomyProvider,

                        GlobalNavigationUseDefaultSiteCollectionTermStore = true,
                        GlobalNavigationTermSetName = globalNavigationGroup.Name,

                        DisplayShowHideRibbonAction = true
                    });
                });
            });

            TestModel(siteModel, webModel);
        }
        public void CanDeploySimpleBreakRoleInheritance_OnWeb()
        {
            var privateProjectWebDef = new WebDefinition
            {
                Title       = "Private project",
                Url         = "private-project",
                WebTemplate = BuiltInWebTemplates.Collaboration.TeamSite
            };

            var privateProjectWebBreakRoleInheritance = new BreakRoleInheritanceDefinition
            {
                CopyRoleAssignments = false
            };

            var privateSecurityGroupMembers = new SecurityGroupDefinition
            {
                Name = "Private Project Group Members"
            };

            var privateSecurityGroupViewers = new SecurityGroupDefinition
            {
                Name = "Private Project Group Viewers"
            };

            // site model with the groups
            var siteModel = SPMeta2Model.NewSiteModel(site =>
            {
                site.AddSecurityGroup(privateSecurityGroupMembers);
                site.AddSecurityGroup(privateSecurityGroupViewers);
            });

            // web model
            var webModel = SPMeta2Model.NewWebModel(web =>
            {
                web.AddWeb(privateProjectWebDef, publicProjectWeb =>
                {
                    publicProjectWeb.AddBreakRoleInheritance(privateProjectWebBreakRoleInheritance, privateProjectResetWeb =>
                    {
                        // privateProjectResetWeb is your web but after breaking role inheritance

                        // link group with roles by SecurityRoleType / SecurityRoleName
                        // use BuiltInSecurityRoleTypes or BuiltInSecurityRoleNames

                        // add group with contributor permission
                        privateProjectResetWeb.AddSecurityGroupLink(privateSecurityGroupMembers, group =>
                        {
                            group.AddSecurityRoleLink(new SecurityRoleLinkDefinition
                            {
                                SecurityRoleType = BuiltInSecurityRoleTypes.Contributor
                            });
                        });

                        // add group with reader permission
                        privateProjectResetWeb.AddSecurityGroupLink(privateSecurityGroupViewers, group =>
                        {
                            group.AddSecurityRoleLink(new SecurityRoleLinkDefinition
                            {
                                SecurityRoleType = BuiltInSecurityRoleTypes.Reader
                            });
                        });
                    });
                });
            });

            // deploy site model with groups, and then web model with the rest
            DeployModel(siteModel);
            DeployModel(webModel);
        }
Exemplo n.º 29
0
        protected virtual SolutionPackageBase CreateNewSolutionPackage(
            NuGetSolutionPackageService service,
            Action <SolutionPackageBase> action,
            RegressinModelLevel modelLevel)
        {
            var knownPackageType = false;

            SolutionPackageBase solutionPackage = null;

            if (service is SPMeta2SolutionPackageService)
            {
                var m2package = new SolutionPackageBase();

                m2package.Name  = "SPMeta2 CI Package Name";
                m2package.Title = "SPMeta2 CI Package Title";

                m2package.Description = "SPMeta2 CI Package description";
                m2package.Id          = "MetaPack.SPMeta2.CI";
                m2package.Authors     = "SubPoint Solutions Authors";
                m2package.Company     = "SubPoint Solutions Company";
                m2package.Version     = "1.0.0.0";
                m2package.Owners      = "SubPoint Solutions Owners";

                m2package.ReleaseNotes = "ReleaseNotes";
                m2package.Summary      = "Summary";
                m2package.ProjectUrl   = "https://github.com/SubPointSolutions/metapack";
                m2package.IconUrl      = "https://github.com/SubPointSolutions/metapack/metapack.png";
                m2package.LicenseUrl   = "https://opensource.org/licenses/MIT";

                m2package.Copyright = "Some copyright here";
                m2package.Tags      = "CI SPMeta2 MetaPack Tags";

                var models = new List <ModelNode>();

                switch (modelLevel)
                {
                case RegressinModelLevel.Farm:
                    models.Add(SPMeta2Model.NewFarmModel(farm => { }));
                    break;

                case RegressinModelLevel.WebApplication:
                    models.Add(SPMeta2Model.NewWebApplicationModel(webApp => { }));
                    break;

                case RegressinModelLevel.Site:
                    models.Add(SPMeta2Model.NewSiteModel(site => { }));
                    models.Add(SPMeta2Model.NewWebModel(web => { }));
                    break;

                case RegressinModelLevel.Web:
                    models.Add(SPMeta2Model.NewWebModel(web => { }));
                    break;

                case RegressinModelLevel.Subweb:
                    models.Add(SPMeta2Model.NewWebModel(web => { }));
                    break;

                default:
                    throw new NotImplementedException(string.Format(
                                                          "Unsupported model level:[{0}] for model genaration",
                                                          modelLevel));
                }

                var index = 0;

                foreach (var model in models)
                {
                    index++;

                    var xmlContext = SPMeta2Model.ToXML(model);

                    var modelContainer = new ModelContainerBase
                    {
                        Model = Encoding.UTF8.GetBytes(xmlContext),
                    };

                    modelContainer.AdditionalOptions.Add(new OptionValue
                    {
                        Name  = DefaultOptions.Model.Order.Id,
                        Value = index.ToString()
                    });

                    m2package.AddModel(modelContainer);
                }

                m2package.AdditionalOptions.Add(new OptionValue
                {
                    Name  = DefaultOptions.SolutionToolPackage.PackageId.Id,
                    Value = "MetaPack.SPMeta2"
                });

                solutionPackage = m2package;
            }

            if (service is SharePointPnPSolutionPackageService)
            {
                var pnpPackage = new SolutionPackageBase();

                pnpPackage.Name  = "SharePointPnP CI Package Name";
                pnpPackage.Title = "SharePointPnP Package Title";

                pnpPackage.Description = "SPMeta2 CI Package description";
                pnpPackage.Id          = "MetaPack.SharePointPnP.CI";
                pnpPackage.Authors     = "SubPoint Solutions Authors";
                pnpPackage.Company     = "SubPoint Solutions Company";
                pnpPackage.Version     = "1.0.0.0";
                pnpPackage.Owners      = "SubPoint Solutions Owners";

                pnpPackage.ReleaseNotes = "ReleaseNotes";
                pnpPackage.Summary      = "Summary";
                pnpPackage.ProjectUrl   = "https://github.com/SubPointSolutions/metapack";
                pnpPackage.IconUrl      = "https://github.com/SubPointSolutions/metapack/metapack.png";
                pnpPackage.LicenseUrl   = "https://opensource.org/licenses/MIT";

                pnpPackage.Copyright = "Some copyright here";
                pnpPackage.Tags      = "CI SPMeta2 MetaPack Tags";


                // TODO
                // Zip up and set the model type
                var asmFolder = Path.GetDirectoryName(GetType().Assembly.Location);

                var foldersPath       = Path.Combine(asmFolder, @"Data/PnPTemplates/Folders");
                var openXmlFolderPath = Path.Combine(asmFolder, @"Data/PnPTemplates/OpenXML");

                foreach (var templateFolder in Directory.GetDirectories(foldersPath))
                {
                    // package up into zip
                    var templateFolderZipFile = GetTempZipFilePath();
                    ZipFile.CreateFromDirectory(templateFolder, templateFolderZipFile);

                    var modelContainer = new ModelContainerBase
                    {
                        Model = System.IO.File.ReadAllBytes(templateFolderZipFile),
                    };

                    modelContainer.AdditionalOptions.Add(new OptionValue
                    {
                        Name  = DefaultOptions.Model.Type.Id,
                        Value = "SharePointPnP.FolderZip"
                    });

                    pnpPackage.AddModel(modelContainer);
                }



                var openXmlPackages = Directory.GetFiles(openXmlFolderPath, "*.pnp");

                foreach (var file in openXmlPackages)
                {
                    var modelContainer = new ModelContainerBase
                    {
                        Model = System.IO.File.ReadAllBytes(file),
                    };

                    modelContainer.AdditionalOptions.Add(new OptionValue
                    {
                        Name  = DefaultOptions.Model.Type.Id,
                        Value = "SharePointPnP.OpenXml"
                    });

                    pnpPackage.AddModel(modelContainer);
                }

                pnpPackage.AdditionalOptions.Add(new OptionValue
                {
                    Name  = DefaultOptions.SolutionToolPackage.PackageId.Id,
                    Value = "MetaPack.SharePointPnP"
                });

                solutionPackage = pnpPackage;
            }

            if (solutionPackage == null)
            {
                throw new NotImplementedException(string.Format(
                                                      "Unknown service type:[{0}]", service.GetType()));
            }

            if (action != null)
            {
                action(solutionPackage);
            }

            return(solutionPackage);
        }
        public void Can_Reverse_UniqueContentTypeOrder()
        {
            // only root web
            var options = ReverseOptions.Default
                          .AddDepthOption <WebDefinition>(0);

            var ct1 = Def <ContentTypeDefinition>();
            var ct2 = Def <ContentTypeDefinition>();
            var ct3 = Def <ContentTypeDefinition>();
            var ct4 = Def <ContentTypeDefinition>();

            var siteModel = SPMeta2Model.NewSiteModel(site =>
            {
                site.RegExcludeFromValidation();

                site.AddContentType(ct1, c => c.RegExcludeFromValidation());
                site.AddContentType(ct2, c => c.RegExcludeFromValidation());
                site.AddContentType(ct3, c => c.RegExcludeFromValidation());
                site.AddContentType(ct4, c => c.RegExcludeFromValidation());
            });

            var listDef = Def <ListDefinition>(def =>
            {
                def.TemplateType        = BuiltInListTemplateTypeId.DocumentLibrary;
                def.Url                 = null;
                def.CustomUrl           = Rnd.String();
                def.ContentTypesEnabled = true;
            });

            var model1 = SPMeta2Model.NewWebModel(web =>
            {
                web.AddList(listDef, list =>
                {
                    list.AddContentTypeLink(ct1);
                    list.AddContentTypeLink(ct2);
                    list.AddContentTypeLink(ct3);
                    list.AddContentTypeLink(ct4);

                    list.AddUniqueContentTypeOrder(new UniqueContentTypeOrderDefinition
                    {
                        ContentTypes = new List <ContentTypeLinkValue>
                        {
                            new ContentTypeLinkValue {
                                ContentTypeName = ct2.Name
                            },
                            new ContentTypeLinkValue {
                                ContentTypeName = ct3.Name
                            },
                        }
                    });
                });
            });

            // only giving list, improve the test performance
            var listDefs = GetAllDefinitionOfType <ListDefinition>(model1);

            foreach (var listDefinition in listDefs)
            {
                options.AddFilterOption <ListDefinition>(l => l.Title == listDefinition.Title);
            }

            DeployReverseAndTestModel(new ModelNode[] { siteModel, model1 }, options);
        }