public override void DeployModel(object modelHost, DefinitionBase model)
        {
            var siteModelHost    = modelHost.WithAssertAndCast <SiteModelHost>("modelHost", value => value.RequireNotNull());
            var contentTypeModel = model.WithAssertAndCast <ContentTypeDefinition>("model", value => value.RequireNotNull());

            var site = siteModelHost.HostSite;

            var context = site.Context;
            var rootWeb = site.RootWeb;

            var contentTypes = rootWeb.ContentTypes;

            context.Load(rootWeb);
            context.Load(contentTypes);

            context.ExecuteQuery();

            var contentTypeId = contentTypeModel.GetContentTypeId();
            var spObject      = contentTypes.FirstOrDefault(c => c.StringId.ToLower() == contentTypeId.ToLower());

            TraceUtils.WithScope(traceScope =>
            {
                var pair = new ComparePair <ContentTypeDefinition, ContentType>(contentTypeModel, spObject);

                traceScope.WriteLine(string.Format("Validating model:[{0}] field:[{1}]", model, spObject));

                traceScope.WithTraceIndent(trace => pair
                                           .ShouldBeEqual(trace, m => m.Name, o => o.Name)
                                           .ShouldBeEqual(trace, m => m.Description, o => o.Description)
                                           .ShouldBeEqual(trace, m => m.Group, o => o.Group)
                                           .ShouldBeEqual(trace, m => m.GetContentTypeId().ToLowerInvariant(), o => o.Id.ToString().ToLowerInvariant())
                                           .ShouldBeEqual(trace, m => m.Group, o => o.Group));
            });
        }
        protected override void DeployModelInternal(object modelHost, DefinitionBase model)
        {
            var list             = modelHost.WithAssertAndCast <SPList>("modelHost", value => value.RequireNotNull());
            var webpartPageModel = model.WithAssertAndCast <WebPartPageDefinition>("model", value => value.RequireNotNull());

            var spWebPartPage = FindWebPartPage(list, webpartPageModel);

            TraceUtils.WithScope(traceScope =>
            {
                traceScope.WriteLine(string.Format("Validate model:[{0}] web part page:[{1}]", webpartPageModel, spWebPartPage));

                // asserting it exists
                traceScope.WriteLine(string.Format("Validating existance..."));
                Assert.IsNotNull(spWebPartPage);

                traceScope.WriteLine(string.Format("Web part page exists!"));

                // assert base properties
                traceScope.WithTraceIndent(trace =>
                {
                    var originalFileName = GetSafeWebPartPageFileName(webpartPageModel);

                    trace.WriteLine(string.Format("Validate Name: model:[{0}] field:[{1}]", originalFileName, spWebPartPage.Name));
                    Assert.AreEqual(originalFileName, spWebPartPage.Name);
                });
            });
        }
        protected override void DeployModelInternal(object modelHost, DefinitionBase model)
        {
            var siteModelHost   = modelHost.WithAssertAndCast <SiteModelHost>("modelHost", value => value.RequireNotNull());
            var definitionModel = model.WithAssertAndCast <ContentTypeDefinition>("model", value => value.RequireNotNull());

            var site    = siteModelHost.HostSite;
            var rootWeb = site.RootWeb;

            var contentTypes = rootWeb.AvailableContentTypes;

            var spModel = contentTypes[definitionModel.Name];

            TraceUtils.WithScope(traceScope =>
            {
                Trace.WriteLine(string.Format("Validate model: {0} ContentType:{1}", definitionModel, spModel));

                // assert base properties
                traceScope.WithTraceIndent(trace =>
                {
                    trace.WriteLine(string.Format("Validate Name: model:[{0}] ct:[{1}]", definitionModel.Name, spModel.Name));
                    Assert.AreEqual(definitionModel.Name, spModel.Name);

                    trace.WriteLine(string.Format("Validate Description: model:[{0}] ct:[{1}]", definitionModel.Description, spModel.Description));
                    Assert.AreEqual(definitionModel.Description, spModel.Description);

                    trace.WriteLine(string.Format("Validate Id: model:[{0}] ct:[{1}]", definitionModel.GetContentTypeId(), spModel.Id));
                    Assert.AreEqual(new SPContentTypeId(definitionModel.GetContentTypeId()), spModel.Id);

                    trace.WriteLine(string.Format("Validate Group: model:[{0}] ct:[{1}]", definitionModel.Group, spModel.Group));
                    Assert.AreEqual(definitionModel.Group, spModel.Group);
                });
            });
        }
示例#4
0
        protected override void DeployModelInternal(object modelHost, DefinitionBase model)
        {
            var spList = modelHost.WithAssertAndCast <SPList>("modelHost", value => value.RequireNotNull());
            var contentTypeLinkModel = model.WithAssertAndCast <ContentTypeLinkDefinition>("model", value => value.RequireNotNull());

            TraceUtils.WithScope(traceScope =>
            {
                Trace.WriteLine(string.Format("Validate model: {0} ContentTypeLink:{1}", spList, contentTypeLinkModel));

                // assert base properties
                traceScope.WithTraceIndent(trace =>
                {
                    if (spList.ContentTypesEnabled)
                    {
                        var contentTypeId     = new SPContentTypeId(contentTypeLinkModel.ContentTypeId);
                        var targetContentType = spList.ParentWeb.ContentTypes[contentTypeId];

                        var listContentType = spList.ContentTypes[targetContentType.Name];

                        // presence
                        trace.WriteLine(string.Format("Validate list content type presence (not null): model:[{0}] content type link:[{1}]", contentTypeLinkModel.ContentTypeId, listContentType));
                        Assert.IsNotNull(listContentType);

                        // child of
                        trace.WriteLine(string.Format("Validate ChildOf: model:[{0}] content type link:[{1}]", contentTypeLinkModel.ContentTypeId, listContentType));
                        Assert.IsTrue(listContentType.Id.IsChildOf(new SPContentTypeId(contentTypeLinkModel.ContentTypeId)));
                    }
                    else
                    {
                        trace.WriteLine("Skipping content type link check as List.ContentTypesEnabled is false");
                    }
                });
            });
        }
示例#5
0
        public void ExpectUpdateAttributes_ShouldHave_Services()
        {
            var updateAttrTypes = ReflectionUtils.GetTypesFromAssembly <ExpectUpdate>(typeof(ExpectUpdate).Assembly);

            var updateAttrServices = new List <ExpectUpdateValueServiceBase>();

            updateAttrServices.AddRange(ReflectionUtils.GetTypesFromAssembly <ExpectUpdateValueServiceBase>(typeof(ExpectUpdateValueServiceBase).Assembly)
                                        .Select(t => Activator.CreateInstance(t) as ExpectUpdateValueServiceBase));

            TraceUtils.WithScope(trace =>
            {
                foreach (var attr in updateAttrTypes)
                {
                    var targetServices = updateAttrServices.FirstOrDefault(s => s.TargetType == attr);

                    if (targetServices != null)
                    {
                        trace.WriteLine(string.Format("ExpectUpdate: [{0}] has service: [{1}]", attr,
                                                      targetServices.GetType()));
                    }
                    else
                    {
                        trace.WriteLine(string.Format("ExpectUpdate: [{0}] misses  service impl", attr));
                        Assert.Fail();
                    }
                }
            });
        }
        protected override void DeployModelInternal(object modelHost, DefinitionBase model)
        {
            var siteModelHost = modelHost.WithAssertAndCast <SiteModelHost>("modelHost", value => value.RequireNotNull());
            var site          = siteModelHost.HostSite;

            var securityGroupModel = model.WithAssertAndCast <SecurityGroupDefinition>("model", value => value.RequireNotNull());

            var web = site.RootWeb;

            TraceUtils.WithScope(traceScope =>
            {
                var securityGroups = web.SiteGroups;
                var spGroup        = securityGroups[securityGroupModel.Name];

                traceScope.WriteLine(string.Format("Validate model:[{0}] field:[{1}]", securityGroupModel, spGroup));

                // assert base properties
                traceScope.WithTraceIndent(trace =>
                {
                    trace.WriteLine(string.Format("Validate Name: model:[{0}] field:[{1}]", securityGroupModel.Name, spGroup.Name));
                    Assert.AreEqual(securityGroupModel.Name, spGroup.Name);

                    trace.WriteLine(string.Format("Validate Description: model:[{0}] field:[{1}]", securityGroupModel.Description, spGroup.Description));
                    Assert.AreEqual(securityGroupModel.Description, spGroup.Description);
                });
            });
        }
示例#7
0
        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            var list             = modelHost.WithAssertAndCast <List>("modelHost", value => value.RequireNotNull());
            var webPartPageModel = model.WithAssertAndCast <WebPartPageDefinition>("model", value => value.RequireNotNull());

            //if (!string.IsNullOrEmpty(webPartPageModel.FolderUrl))
            //    throw new NotImplementedException("FolderUrl for the web part page model is not supported yet");

            var pageName = GetSafeWebPartPageFileName(webPartPageModel);
            var pageItem = list.QueryAndGetItemByFileName(pageName);

            TraceUtils.WithScope(traceScope =>
            {
                traceScope.WriteLine(string.Format("Validate model:[{0}] web part page:[{1}]", webPartPageModel, pageItem));
                Assert.IsNotNull(pageItem);

                traceScope.WithTraceIndent(trace =>
                {
                    var fileName = pageItem["FileLeafRef"];

                    traceScope.WriteLine(string.Format("Validate FileName model:[{0}] web part page:[{1}]", pageName, fileName));
                    Assert.AreEqual(pageName, fileName);
                });
            });
        }
        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            var modelHostContext = modelHost.WithAssertAndCast <ModelHostContext>("modelHost", value => value.RequireNotNull());
            var fieldlinkModel   = model.WithAssertAndCast <ContentTypeFieldLinkDefinition>("model", value => value.RequireNotNull());

            var site        = modelHostContext.Site;
            var contentType = modelHostContext.ContentType;

            var context = site.Context;

            context.Load(contentType, ct => ct.FieldLinks);
            context.ExecuteQuery();

            var spFieldLink = FindFieldLinkById(contentType.FieldLinks, fieldlinkModel.FieldId);

            TraceUtils.WithScope(traceScope =>
            {
                Trace.WriteLine(string.Format("Validate model: {0} ContentType:{1}", fieldlinkModel, contentType));

                // assert base properties
                traceScope.WithTraceIndent(trace =>
                {
                    trace.WriteLine(string.Format("Validate FieldId: model:[{0}] ct field link:[{1}]", fieldlinkModel.FieldId, spFieldLink.Id));
                    Assert.AreEqual(fieldlinkModel.FieldId, spFieldLink.Id);
                });
            });
        }
        protected override void DeployModelInternal(object modelHost, DefinitionBase model)
        {
            var securableObject        = modelHost.WithAssertAndCast <SPSecurableObject>("modelHost", value => value.RequireNotNull());
            var securityGroupLinkModel = model.WithAssertAndCast <SecurityGroupLinkDefinition>("model", value => value.RequireNotNull());

            var web           = GetWebFromSPSecurableObject(securableObject);
            var securityGroup = web.SiteGroups[securityGroupLinkModel.SecurityGroupName];

            //securableObject.RoleAssignments

            TraceUtils.WithScope(traceScope =>
            {
                traceScope.WriteLine(string.Format("Validate model:[{0}] securableObject:[{1}]", securityGroupLinkModel, securityGroup));

                traceScope.WithTraceIndent(trace =>
                {
                    // asserting it exists
                    trace.WriteLine(string.Format("Validating existance..."));

                    Assert.IsTrue(securableObject
                                  .RoleAssignments
                                  .OfType <SPRoleAssignment>()
                                  .FirstOrDefault(a => a.Member.ID == securityGroup.ID) != null);

                    trace.WriteLine(string.Format("RoleAssignments for security group link [{0}] exists.", securityGroupLinkModel.SecurityGroupName));
                });
            });
        }
示例#10
0
        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            var webModelHost = modelHost.WithAssertAndCast <SiteModelHost>("modelHost", value => value.RequireNotNull());

            var web = webModelHost.HostSite.RootWeb;
            var securityGroupModel = model as SecurityGroupDefinition;

            var context = web.Context;

            // well, this should be pulled up to the site handler and init Load/Exec query
            context.Load(web, tmpWeb => tmpWeb.SiteGroups);
            context.ExecuteQuery();

            var currentGroup = FindSecurityGroupByTitle(web.SiteGroups, securityGroupModel.Name);

            TraceUtils.WithScope(traceScope =>
            {
                traceScope.WriteLine(string.Format("Validate model:[{0}] list view:[{1}]", securityGroupModel, currentGroup));
                Assert.IsNotNull(currentGroup);

                traceScope.WithTraceIndent(trace =>
                {
                    traceScope.WriteLine(string.Format("Validate Title: model:[{0}] list view:[{1}]", securityGroupModel.Name, currentGroup.Title));
                    Assert.AreEqual(securityGroupModel.Name, currentGroup.Title);

                    traceScope.WriteLine(string.Format("Validate Description: model:[{0}] list view:[{1}]", securityGroupModel.Description, currentGroup.Description));
                    Assert.AreEqual(securityGroupModel.Description, currentGroup.Description);
                });
            });
        }
        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            var securableObject        = modelHost.WithAssertAndCast <SecurableObject>("modelHost", value => value.RequireNotNull());
            var securityGroupLinkModel = model.WithAssertAndCast <SecurityGroupLinkDefinition>("model", value => value.RequireNotNull());

            var web = GetWebFromSPSecurableObject(securableObject);

            var context = web.Context;

            context.Load(web, w => w.SiteGroups);
            context.Load(securableObject, s => s.RoleAssignments.Include(r => r.Member));

            context.ExecuteQuery();

            var securityGroup = WebExtensions.FindGroupByName(web.SiteGroups, securityGroupLinkModel.SecurityGroupName);

            TraceUtils.WithScope(traceScope =>
            {
                traceScope.WriteLine(string.Format("Validate model:[{0}] securableObject:[{1}]", securityGroupLinkModel, securityGroup));

                traceScope.WithTraceIndent(trace =>
                {
                    // asserting it exists
                    trace.WriteLine(string.Format("Validating existance..."));

                    var existingRoleAssignments = FindClientRoleRoleAssignment(securableObject.RoleAssignments, securityGroup);

                    Assert.IsNotNull(existingRoleAssignments);

                    trace.WriteLine(string.Format("RoleAssignments for security group link [{0}] exists.", securityGroupLinkModel.SecurityGroupName));
                });
            });
        }
示例#12
0
        protected override void DeployModelInternal(object modelHost, DefinitionBase model)
        {
            var   webModel  = model.WithAssertAndCast <WebDefinition>("model", value => value.RequireNotNull());
            SPWeb parentWeb = null;

            if (modelHost is SiteModelHost)
            {
                parentWeb = (modelHost as SiteModelHost).HostSite.RootWeb;
            }

            if (modelHost is WebModelHost)
            {
                parentWeb = (modelHost as WebModelHost).HostWeb;
            }

            TraceUtils.WithScope(traceScope =>
            {
                var web  = GetWeb(parentWeb, webModel);
                var pair = new ComparePair <WebDefinition, SPWeb>(webModel, web);

                traceScope.WriteLine(string.Format("Validating model:[{0}] web:[{1}]", webModel, web));

                traceScope.WithTraceIndent(trace => pair
                                           .ShouldBeEqual(trace, m => m.Title, w => w.Title)
                                           .ShouldBeEqual(trace, m => m.Description, w => w.Description)
                                           .ShouldBeEqual(trace, m => m.WebTemplate, w => string.Format("{0}#{1}", w.WebTemplate, w.Configuration)));
            });
        }
        private void ValidateFolderProps(Folder folder, FolderDefinition folderModel)
        {
            TraceUtils.WithScope(traceScope =>
            {
                var pair = new ComparePair <FolderDefinition, Folder>(folderModel, folder);

                traceScope.WriteLine(string.Format("Validating model:[{0}] folder:[{1}]", folderModel, folder));

                traceScope.WithTraceIndent(trace => pair
                                           .ShouldBeEqual(trace, m => m.Name, o => o.Name));
            });
        }
        private void ValidateNode(NavigationNode qlNode, QuickLaunchNavigationNodeDefinition quickLaunchModel)
        {
            TraceUtils.WithScope(traceScope =>
            {
                var pair = new ComparePair <QuickLaunchNavigationNodeDefinition, NavigationNode>(quickLaunchModel, qlNode);

                traceScope.WriteLine(string.Format("Validating model:[{0}] node:[{1}]", quickLaunchModel, qlNode));

                traceScope.WithTraceIndent(trace => pair
                                           .ShouldBeEqual(trace, m => m.Title, o => o.Title)
                                           .ShouldBeEqual(trace, m => m.Url, o => o.Url)
                                           .ShouldBeEqual(trace, m => m.IsVisible, o => o.IsVisible)
                                           .ShouldBeEqual(trace, m => m.IsExternal, o => o.IsExternal));
            });
        }
示例#15
0
        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            var webModelHost = modelHost.WithAssertAndCast <SiteModelHost>("modelHost", value => value.RequireNotNull());

            var web = webModelHost.HostSite.RootWeb;
            var securityRoleModel = model.WithAssertAndCast <SecurityRoleDefinition>("model", value => value.RequireNotNull());

            var context = web.Context;

            // well, this should be pulled up to the site handler and init Load/Exec query
            context.Load(web, tmpWeb => tmpWeb.SiteGroups);
            context.ExecuteQuery();

            var currentRole = FindRoleDefinition(web.RoleDefinitions, securityRoleModel.Name);

            TraceUtils.WithScope(traceScope =>
            {
                traceScope.WriteLine(string.Format("Validate model:[{0}] security role:[{1}]", securityRoleModel, currentRole));
                Assert.IsNotNull(currentRole);

                traceScope.WithTraceIndent(trace =>
                {
                    traceScope.WriteLine(string.Format("Validate Name: model:[{0}] list view:[{1}]", securityRoleModel.Name, currentRole.Name));
                    Assert.AreEqual(securityRoleModel.Name, currentRole.Name);

                    traceScope.WriteLine(string.Format("Validate Description: model:[{0}] list view:[{1}]", securityRoleModel.Description, currentRole.Description));
                    Assert.AreEqual(securityRoleModel.Description, currentRole.Description);

                    // validate base permissions
                    trace.WriteLine(string.Format("Validate permissions..."));

                    //
                    context.Load(currentRole, r => r.BasePermissions);
                    context.ExecuteQuery();

                    traceScope.WithTraceIndent(permissionTrace =>
                    {
                        foreach (var permission in securityRoleModel.BasePermissions)
                        {
                            trace.WriteLine(string.Format("Validate permission presence: [{0}]", permission));

                            var spPermission = (PermissionKind)Enum.Parse(typeof(PermissionKind), permission);
                            Assert.IsTrue(currentRole.BasePermissions.Has(spPermission));
                        }
                    });
                });
            });
        }
示例#16
0
        private void Trace(FeatureDefinition featureModel, Feature currentFeature)
        {
            var featureActivated = currentFeature != null;

            TraceUtils.WithScope(traceScope =>
            {
                traceScope.WriteLine(string.Format("Validating model:[{0}] feature:[{1}]", featureModel, currentFeature));

                traceScope.WriteLine(string.Format("Model prop [{0}] on obj prop [{1}]: model:[{2}] obj:[{3}]",
                                                   "Enable",
                                                   "Enable",
                                                   featureModel.Enable,
                                                   featureActivated));

                Assert.AreEqual(featureModel.Enable, featureActivated);
            });
        }
示例#17
0
        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            var list = modelHost.WithAssertAndCast <List>("modelHost", value => value.RequireNotNull());
            var contentTypeLinkModel = model.WithAssertAndCast <ContentTypeLinkDefinition>("model", value => value.RequireNotNull());

            var context = list.Context;

            context.Load(list, l => l.ContentTypesEnabled);
            context.ExecuteQuery();

            TraceUtils.WithScope(traceScope =>
            {
                Trace.WriteLine(string.Format("Validate model: {0} ContentTypeLink:{1}", list, contentTypeLinkModel));

                var web = list.ParentWeb;

                context.Load(list, l => l.ContentTypesEnabled);
                context.ExecuteQuery();

                // assert base properties
                traceScope.WithTraceIndent(trace =>
                {
                    if (list.ContentTypesEnabled)
                    {
                        context.Load(web, w => w.AvailableContentTypes);
                        context.Load(list, l => l.ContentTypes);

                        context.ExecuteQuery();

                        var listContentType = FindListContentType(list, contentTypeLinkModel);

                        // presence
                        trace.WriteLine(string.Format("Validate list content type presence (not null): model:[{0}] content type link:[{1}]", contentTypeLinkModel.ContentTypeId, listContentType));
                        Assert.IsNotNull(listContentType);

                        // child of
                        trace.WriteLine(string.Format("SSkipping checking ChildOf as in CSOM ct is referenced to list by name."));
                    }
                    else
                    {
                        trace.WriteLine("Skipping content type link check as List.ContentTypesEnabled is false");
                    }
                });
            });
        }
示例#18
0
        public void CanSerialize_SiteModelToJSONAndBack()
        {
            var orginalModel = SPMeta2Model.NewSiteModel(site =>
            {
            });

            TraceUtils.WithScope(trace =>
            {
                var modelString = SPMeta2Model.ToJSON(orginalModel);
                Assert.IsFalse(string.IsNullOrEmpty(modelString));

                trace.WriteLine("JSON");
                trace.WriteLine(modelString);

                var deserializedModel = SPMeta2Model.FromJSON(modelString);
                Assert.IsNotNull(deserializedModel);
            });
        }
        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            var list          = modelHost.WithAssertAndCast <List>("modelHost", value => value.RequireNotNull());
            var listViewModel = model.WithAssertAndCast <ListViewDefinition>("model", value => value.RequireNotNull());

            var context = list.Context;

            context.Load(list, l => l.Views);
            context.ExecuteQuery();

            TraceUtils.WithScope(traceScope =>
            {
                var currentView = FindViewByTitle(list.Views, listViewModel.Title);
                traceScope.WriteLine(string.Format("Validate model:[{0}] list view:[{1}]", listViewModel, currentView));

                traceScope.WithTraceIndent(trace =>
                {
                    trace.WriteLine(string.Format("Validate Title: model:[{0}] list view:[{1}]", listViewModel.Title, currentView.Title));
                    Assert.AreEqual(listViewModel.Title, currentView.Title);

                    trace.WriteLine(string.Format("Validate RowLimit: model:[{0}] list view:[{1}]", listViewModel.RowLimit, currentView.RowLimit));
                    Assert.AreEqual((uint)listViewModel.RowLimit, (uint)currentView.RowLimit);

                    trace.WriteLine(string.Format("Validate IsDefault: model:[{0}] list view:[{1}]", listViewModel.IsDefault, currentView.DefaultView));
                    Assert.AreEqual(listViewModel.IsDefault, currentView.DefaultView);

                    trace.WriteLine(string.Format("Validate fields.."));

                    context.Load(currentView, v => v.ViewFields);
                    context.ExecuteQuery();

                    traceScope.WithTraceIndent(fieldTrace =>
                    {
                        foreach (var fieldName in listViewModel.Fields)
                        {
                            trace.WriteLine(string.Format("Validate field presence: [{0}]", fieldName));

                            Assert.IsTrue(DoesFieldExist(currentView.ViewFields, fieldName));
                            trace.WriteLine(string.Format("Field [{0}] exists in view. [OK].", fieldName));
                        }
                    });
                });
            });
        }
示例#20
0
        protected override void DeployModelInternal(object modelHost, DefinitionBase model)
        {
            var webModelHost = modelHost.WithAssertAndCast <WebModelHost>("modelHost", value => value.RequireNotNull());
            var web          = webModelHost.HostWeb;

            var listModel = model.WithAssertAndCast <ListDefinition>("model", value => value.RequireNotNull());

            TraceUtils.WithScope(traceScope =>
            {
                var spList = web.GetList(SPUrlUtility.CombineUrl(web.ServerRelativeUrl, listModel.GetListUrl()));

                traceScope.WriteLine(string.Format("Validate model:[{0}] field:[{1}]", listModel, spList));

                // assert base properties
                traceScope.WithTraceIndent(trace =>
                {
                    trace.WriteLine(string.Format("Validate Title: model:[{0}] list:[{1}]", listModel.Title, spList.Title));
                    Assert.AreEqual(listModel.Title, spList.Title);

                    trace.WriteLine(string.Format("Validate Description: model:[{0}] list:[{1}]", listModel.Description, spList.Description));
                    Assert.AreEqual(listModel.Description, spList.Description);

                    trace.WriteLine(string.Format("Validate ContentTypesEnabled: model:[{0}] list:[{1}]", listModel.ContentTypesEnabled, spList.ContentTypesEnabled));
                    Assert.AreEqual(listModel.ContentTypesEnabled, spList.ContentTypesEnabled);

                    // TODO
                    // template type & template name
                    if (listModel.TemplateType > 0)
                    {
                        trace.WriteLine(string.Format("Validate TemplateType: model:[{0}] list:[{1}]", listModel.TemplateType, spList.BaseTemplate));
                        Assert.AreEqual(listModel.TemplateType, (int)spList.BaseTemplate);
                    }
                    else
                    {
                        trace.WriteLine(string.Format("Skipping TemplateType check. It is 0"));
                    }

                    // TODO
                    // url checking
                    trace.WriteLine(string.Format("Validate Url: model:[{0}] list:[{1}]", listModel.GetListUrl(), spList.RootFolder.ServerRelativeUrl));
                    Assert.IsTrue(spList.RootFolder.ServerRelativeUrl.Contains(listModel.GetListUrl()));
                });
            });
        }
示例#21
0
        protected override void DeployModelInternal(object modelHost, DefinitionBase model)
        {
            var list          = modelHost.WithAssertAndCast <SPList>("modelHost", value => value.RequireNotNull());
            var listViewModel = model.WithAssertAndCast <ListViewDefinition>("model", value => value.RequireNotNull());

            TraceUtils.WithScope(traceScope =>
            {
                var spView = list.Views.FindByName(listViewModel.Title);

                traceScope.WriteLine(string.Format("Validate model:[{0}] view:[{1}]", listViewModel, spView));

                // assert base properties
                traceScope.WithTraceIndent(trace =>
                {
                    trace.WriteLine(string.Format("Validate Title: model:[{0}] view:[{1}]", listViewModel.Title, spView.Title));
                    Assert.AreEqual(listViewModel.Title, spView.Title);

                    trace.WriteLine(string.Format("Validate IsDefault: model:[{0}] view:[{1}]", listViewModel.IsDefault, spView.DefaultView));
                    Assert.AreEqual(listViewModel.IsDefault, spView.DefaultView);

                    trace.WriteLine(string.Format("Validate IsPaged: model:[{0}] view:[{1}]", listViewModel.IsPaged, spView.Paged));
                    Assert.AreEqual(listViewModel.IsPaged, spView.Paged);

                    trace.WriteLine(string.Format("Validate RowLimit: model:[{0}] view:[{1}]", listViewModel.RowLimit, spView.RowLimit));
                    Assert.AreEqual((uint)listViewModel.RowLimit, spView.RowLimit);

                    trace.WriteLine(string.Format("Validate fields.."));

                    traceScope.WithTraceIndent(fieldTrace =>
                    {
                        foreach (var fieldName in listViewModel.Fields)
                        {
                            trace.WriteLine(string.Format("Validate field presence: [{0}]", fieldName));
                            Assert.IsTrue(spView
                                          .ViewFields
                                          .Cast <String>()
                                          .Any(f => System.String.Compare(f, fieldName, System.StringComparison.OrdinalIgnoreCase) == 0));
                            trace.WriteLine(string.Format("Field [{0}] exists in view. [OK].", fieldName));
                        }
                    });
                });
            });
        }
        private void ValidateModel(SiteModelHost siteModelHost, UserCustomActionDefinition customActionModel)
        {
            var customAction = GetCustomAction(siteModelHost, customActionModel);

            TraceUtils.WithScope(traceScope =>
            {
                var pair = new ComparePair <UserCustomActionDefinition, UserCustomAction>(customActionModel, customAction);

                traceScope.WriteLine(string.Format("Validating model:[{0}] custom action:[{1}]", customActionModel, customAction));

                traceScope.WithTraceIndent(trace => pair
                                           .ShouldBeEqual(trace, m => m.Title, o => o.Title)
                                           .ShouldBeEqual(trace, m => m.Description, o => o.Description)
                                           .ShouldBeEqual(trace, m => m.Group, o => o.Group)
                                           .ShouldBeEqual(trace, m => m.Name, o => o.Name)
                                           .ShouldBeEqual(trace, m => m.Sequence, o => o.Sequence)
                                           .ShouldBeEqual(trace, m => m.Location, o => o.Location));
            });
        }
示例#23
0
        protected virtual void WithEventHooks(Action <EventHooks> hooks)
        {
            TraceUtils.WithScope(traceScope =>
            {
                traceScope.WriteLine(string.Format("Validating OnProvisioning/OnProvisioned events."));

                var eventHooks = new EventHooks();

                hooks(eventHooks);

                traceScope.WriteLine(string.Format("Validating OnProvisioning event hit."));
                Assert.AreEqual(true, eventHooks.OnProvisioning);
                traceScope.WriteLine(string.Format("    - done"));

                traceScope.WriteLine(string.Format("Validating OnProvisioned event hit."));
                Assert.AreEqual(true, eventHooks.OnProvisioned);
                traceScope.WriteLine(string.Format("    - done"));
            });
        }
        protected override void DeployModelInternal(object modelHost, DefinitionBase model)
        {
            var spModel        = modelHost.WithAssertAndCast <SPContentType>("modelHost", value => value.RequireNotNull());
            var fieldlinkModel = model.WithAssertAndCast <ContentTypeFieldLinkDefinition>("model", value => value.RequireNotNull());

            var spFieldLink = spModel.FieldLinks[fieldlinkModel.FieldId];

            TraceUtils.WithScope(traceScope =>
            {
                Trace.WriteLine(string.Format("Validate model: {0} ContentType:{1}", fieldlinkModel, spModel));

                // assert base properties
                traceScope.WithTraceIndent(trace =>
                {
                    trace.WriteLine(string.Format("Validate FieldId: model:[{0}] ct field link:[{1}]", fieldlinkModel.FieldId, spFieldLink.Id));
                    Assert.AreEqual(fieldlinkModel.FieldId, spFieldLink.Id);
                });
            });
        }
        public static ValidationPair <TSource> AssertProperty <TSource, TProperty>(
            this ValidationPair <TSource> source,
            ValidationResultType resultType,
            Expression <Func <TSource, TProperty> > exp)
            where TSource : DefinitionBase
        {
            var result = source.ValidationResult;
            var prop   = ReflectionUtils.GetExpressionValue(source.Model, exp);

            TraceUtils.WithScope(s =>
            {
                s.WriteLine(string.Format("Validating property: [{0}]", prop.Name));

                Assert.IsTrue(result.Count(r => r.PropertyName == prop.Name &&
                                           !r.IsValid &&
                                           r.ResultType == resultType) > 0);
            });

            return(source);
        }