コード例 #1
0
        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            // base validation
            base.DeployModel(modelHost, model);

            // content editor specific validation

            var host       = modelHost.WithAssertAndCast <WebpartPageModelHost>("modelHost", value => value.RequireNotNull());
            var definition = model.WithAssertAndCast <RefinementScriptWebPartDefinition>("model", value => value.RequireNotNull());

            var item = host.PageListItem;

            WebPartExtensions.WithExistingWebPart(item, definition, (spWebPartManager, spObject) =>
            {
                var typedWebPart = spObject as RefinementScriptWebPart;

                var assert = ServiceFactory.AssertService
                             .NewAssert(definition, typedWebPart)
                             .ShouldNotBeNull(typedWebPart);
            });
        }
コード例 #2
0
        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            // base validation
            base.DeployModel(modelHost, model);

            // web specific validation
            var host       = modelHost.WithAssertAndCast <WebpartPageModelHost>("modelHost", value => value.RequireNotNull());
            var definition = model.WithAssertAndCast <PageViewerWebPartDefinition>("model", value => value.RequireNotNull());

            var item = host.PageListItem;

            WebPartExtensions.WithExistingWebPart(item, definition, (spWebPartManager, spObject) =>
            {
                var web         = spWebPartManager.Web;
                var typedObject = spObject as PageViewerWebPart;

                var assert = ServiceFactory.AssertService
                             .NewAssert(definition, typedObject)
                             .ShouldNotBeNull(typedObject);

                if (!string.IsNullOrEmpty(definition.ContentLink))
                {
                    assert.ShouldBeEqual(m => m.ContentLink, o => o.ContentLink);
                }
                else
                {
                    assert.SkipProperty(m => m.ContentLink);
                }

                if (!string.IsNullOrEmpty(definition.SourceType))
                {
                    assert.ShouldBeEqual(m => m.SourceType, o => o.GetSourceType());
                }
                else
                {
                    assert.SkipProperty(m => m.SourceType);
                }
            });
        }
コード例 #3
0
        protected override void DeployModelInternal(object modelHost, DefinitionBase model)
        {
            var host             = modelHost.WithAssertAndCast <WebpartPageModelHost>("modelHost", value => value.RequireNotNull());
            var webpartPageModel = model.WithAssertAndCast <WebPartDefinition>("model", value => value.RequireNotNull());

            InvokeOnModelEvent <FieldDefinition, SPField>(null, ModelEventType.OnUpdating);
            WebPartExtensions.DeployWebPartsToPage(host.SPLimitedWebPartManager, new[] { webpartPageModel },
                                                   onUpdatingWebpartInstnce =>
            {
                InvokeOnModelEvent(this, new ModelEventArgs
                {
                    CurrentModelNode = null,
                    Model            = null,
                    EventType        = ModelEventType.OnProvisioning,
                    Object           = onUpdatingWebpartInstnce,
                    ObjectType       = typeof(System.Web.UI.WebControls.WebParts.WebPart),
                    ObjectDefinition = model,
                    ModelHost        = modelHost
                });

                InvokeOnModelEvent <WebPartDefinition, WebPart>(onUpdatingWebpartInstnce, ModelEventType.OnUpdating);
            },
                                                   onUpdatedWebpartInstnce =>
            {
                InvokeOnModelEvent(this, new ModelEventArgs
                {
                    CurrentModelNode = null,
                    Model            = null,
                    EventType        = ModelEventType.OnProvisioned,
                    Object           = onUpdatedWebpartInstnce,
                    ObjectType       = typeof(System.Web.UI.WebControls.WebParts.WebPart),
                    ObjectDefinition = model,
                    ModelHost        = modelHost
                });

                InvokeOnModelEvent <WebPartDefinition, WebPart>(onUpdatedWebpartInstnce, ModelEventType.OnUpdated);
            });
        }
コード例 #4
0
        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            // base validation
            base.DeployModel(modelHost, model);


            // web specific validation
            var host       = modelHost.WithAssertAndCast <WebpartPageModelHost>("modelHost", value => value.RequireNotNull());
            var definition = model.WithAssertAndCast <XsltListViewWebPartDefinition>("model", value => value.RequireNotNull());

            //var item = host.PageListItem;

            WebPartExtensions.WithExistingWebPart(host.HostFile, definition, (spWebPartManager, spObject) =>
            {
                var web         = spWebPartManager.Web;
                var typedObject = spObject as XsltListViewWebPart;

                var assert = ServiceFactory.AssertService
                             .NewAssert(definition, typedObject)
                             .ShouldNotBeNull(typedObject);

                var typedDefinition = definition;
                var targetWeb       = web;

                // web url
                if (!string.IsNullOrEmpty(typedDefinition.WebUrl))
                {
                    var lookupFieldModelHandler = new LookupFieldModelHandler();
                    targetWeb = lookupFieldModelHandler.GetTargetWeb(web.Site,
                                                                     definition.WebUrl, definition.WebId);

                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var srcProp = s.GetExpressionValue(m => m.WebUrl);

                        var isValid = d.WebId == targetWeb.ID;

                        return(new PropertyValidationResult
                        {
                            Tag = p.Tag,
                            Src = srcProp,
                            Dst = null,
                            IsValid = isValid
                        });
                    });
                }
                else
                {
                    assert.SkipProperty(m => m.WebUrl, "WebUrl is NULL. Skipping.");
                }

                if (typedDefinition.WebId.HasGuidValue())
                {
                    var lookupFieldModelHandler = new LookupFieldModelHandler();
                    targetWeb = lookupFieldModelHandler.GetTargetWeb(web.Site,
                                                                     definition.WebUrl, definition.WebId);

                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var srcProp = s.GetExpressionValue(m => m.WebId);

                        var isValid = d.WebId == targetWeb.ID;

                        return(new PropertyValidationResult
                        {
                            Tag = p.Tag,
                            Src = srcProp,
                            Dst = null,
                            IsValid = isValid
                        });
                    });
                }
                else
                {
                    assert.SkipProperty(m => m.WebId, "WebId is NULL. Skipping.");
                }

                var targetList = web.Lists[typedObject.ListId];

                var hasList = !string.IsNullOrEmpty(definition.ListTitle) ||
                              !string.IsNullOrEmpty(definition.ListUrl) ||
                              definition.ListId.HasValue;
                var hasView = !string.IsNullOrEmpty(definition.ViewName) ||
                              definition.ViewId.HasValue;;

                if (definition.CacheXslStorage.HasValue)
                {
                    assert.ShouldBeEqual(m => m.CacheXslStorage, o => o.CacheXslStorage);
                }
                else
                {
                    assert.SkipProperty(m => m.CacheXslStorage, "CacheXslStorage is null or empty.");
                }

                if (definition.CacheXslTimeOut.HasValue)
                {
                    assert.ShouldBeEqual(m => m.CacheXslTimeOut, o => o.CacheXslTimeOut);
                }
                else
                {
                    assert.SkipProperty(m => m.CacheXslTimeOut, "CacheXslTimeOut is null or empty.");
                }

                if (definition.ShowTimelineIfAvailable.HasValue)
                {
                    assert.ShouldBeEqual(m => m.ShowTimelineIfAvailable, o => o.ShowTimelineIfAvailable);
                }
                else
                {
                    assert.SkipProperty(m => m.ShowTimelineIfAvailable, "ShowTimelineIfAvailable is null or empty.");
                }

                // list
                if (!string.IsNullOrEmpty(definition.ListTitle))
                {
                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var srcProp = s.GetExpressionValue(m => m.ListTitle);
                        var dstProp = d.GetExpressionValue(o => o.ListId);

                        return(new PropertyValidationResult
                        {
                            Tag = p.Tag,
                            Src = srcProp,
                            Dst = null,
                            IsValid = targetList.ID == (Guid)dstProp.Value
                        });
                    });
                }
                else
                {
                    assert.SkipProperty(m => m.ListTitle, "ListTitle is null or empty. Skipping.");
                }

                if (!string.IsNullOrEmpty(definition.ListUrl))
                {
                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var srcProp = s.GetExpressionValue(m => m.ListUrl);
                        var dstProp = d.GetExpressionValue(o => o.ListId);

                        return(new PropertyValidationResult
                        {
                            Tag = p.Tag,
                            Src = srcProp,
                            Dst = null,
                            IsValid = targetList.ID == (Guid)dstProp.Value
                        });
                    });
                }
                else
                {
                    assert.SkipProperty(m => m.ListUrl, "ListUrl is null or empty. Skipping.");
                }

                if (definition.ListId.HasValue && definition.ListId != default(Guid))
                {
                    assert.ShouldBeEqual(m => m.ListId, o => o.ListId);
                }
                else
                {
                    assert.SkipProperty(m => m.ListId, "ListId is null or empty. Skipping.");
                }

                // view
                if (definition.ViewId.HasValue)
                {
                    // web part gonna have hidden view
                    // so validation is a bit tricky, done by other properties

                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var srcView = targetList.Views[s.ViewId.Value];
                        var dstView = typedObject.View;

                        var srcProp = s.GetExpressionValue(m => m.ViewId);
                        var dstProp = d.GetExpressionValue(o => o.View);

                        var isValid = srcView.ViewFields.Count == dstView.ViewFields.Count &&
                                      srcView.Query == dstView.Query;

                        return(new PropertyValidationResult
                        {
                            Tag = p.Tag,
                            Src = srcProp,
                            Dst = null,
                            IsValid = isValid
                        });
                    });
                }
                else
                {
                    assert.SkipProperty(m => m.ViewId, "ViewId is null or empty. Skipping.");
                }

                if (!string.IsNullOrEmpty(definition.ViewName))
                {
                    // web part gonna have hidden view
                    // so validation is a bit tricky, done by other properties

                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var srcView = targetList.Views[s.ViewName];
                        var dstView = typedObject.View;

                        var srcProp = s.GetExpressionValue(m => m.ViewName);
                        var dstProp = d.GetExpressionValue(o => o.View);

                        var isValid = srcView.ViewFields.Count == dstView.ViewFields.Count &&
                                      srcView.Query == dstView.Query;

                        return(new PropertyValidationResult
                        {
                            Tag = p.Tag,
                            Src = srcProp,
                            Dst = null,
                            IsValid = isValid
                        });
                    });
                }
                else
                {
                    assert.SkipProperty(m => m.ViewName, "ViewName is null or empty. Skipping.");
                }

                // JSLink
                if (!string.IsNullOrEmpty(definition.JSLink))
                {
                    assert.ShouldBeEqual(m => m.JSLink, o => o.JSLink);
                }
                else
                {
                    assert.SkipProperty(m => m.JSLink);
                }

                if (definition.InplaceSearchEnabled.HasValue)
                {
                    assert.ShouldBeEqual(m => m.InplaceSearchEnabled, o => o.InplaceSearchEnabled);
                }
                else
                {
                    assert.SkipProperty(m => m.InplaceSearchEnabled, "InplaceSearchEnabled is null or empty.");
                }

                if (definition.DisableSaveAsNewViewButton.HasValue)
                {
                    assert.ShouldBeEqual(m => m.DisableSaveAsNewViewButton, o => o.DisableSaveAsNewViewButton);
                }
                else
                {
                    assert.SkipProperty(m => m.DisableSaveAsNewViewButton, "DisableSaveAsNewViewButton is null or empty.");
                }

                if (definition.DisableColumnFiltering.HasValue)
                {
                    assert.ShouldBeEqual(m => m.DisableColumnFiltering, o => o.DisableColumnFiltering);
                }
                else
                {
                    assert.SkipProperty(m => m.DisableColumnFiltering, "DisableColumnFiltering is null or empty.");
                }

                if (definition.DisableViewSelectorMenu.HasValue)
                {
                    assert.ShouldBeEqual(m => m.DisableViewSelectorMenu, o => o.DisableViewSelectorMenu);
                }
                else
                {
                    assert.SkipProperty(m => m.DisableViewSelectorMenu, "DisableViewSelectorMenu is null or empty.");
                }

                // title link
                if (string.IsNullOrEmpty(definition.TitleUrl))
                {
                    // list?
                    if (hasView)
                    {
                        assert.ShouldBeEqual((p, s, d) =>
                        {
                            var srcProp = s.GetExpressionValue(m => m.TitleUrl);
                            var srcView = string.IsNullOrEmpty(s.ViewName) ?
                                          targetList.Views[s.ViewId.Value] :
                                          targetList.Views[s.ViewName];

                            return(new PropertyValidationResult
                            {
                                Tag = p.Tag,
                                Src = srcProp,
                                Dst = null,
                                IsValid = srcView.ServerRelativeUrl.StartsWith(typedObject.TitleUrl)
                            });
                        });
                    }
                    else if (hasList)
                    {
                        assert.ShouldBeEqual((p, s, d) =>
                        {
                            var srcProp = s.GetExpressionValue(m => m.TitleUrl);

                            return(new PropertyValidationResult
                            {
                                Tag = p.Tag,
                                Src = srcProp,
                                Dst = null,
                                IsValid = targetList.DefaultViewUrl.StartsWith(typedObject.TitleUrl)
                            });
                        });
                    }
                }
                else
                {
                    assert.ShouldBeEqual(m => m.TitleUrl, o => o.TitleUrl);
                }

                if (!string.IsNullOrEmpty(definition.XslLink))
                {
                    assert.ShouldBeEqual(m => m.XslLink, o => o.XslLink);
                }
                else
                {
                    assert.SkipProperty(m => m.XslLink);
                }

                if (!string.IsNullOrEmpty(definition.XmlDefinitionLink))
                {
                    assert.ShouldBeEqual(m => m.XmlDefinitionLink, o => o.XmlDefinitionLink);
                }
                else
                {
                    assert.SkipProperty(m => m.XmlDefinitionLink);
                }

                if (!string.IsNullOrEmpty(definition.GhostedXslLink))
                {
                    assert.ShouldBeEqual(m => m.GhostedXslLink, o => o.GhostedXslLink);
                }
                else
                {
                    assert.SkipProperty(m => m.GhostedXslLink);
                }

                if (!string.IsNullOrEmpty(definition.BaseXsltHashKey))
                {
                    assert.ShouldBeEqual(m => m.BaseXsltHashKey, o => o.BaseXsltHashKey);
                }
                else
                {
                    assert.SkipProperty(m => m.BaseXsltHashKey);
                }


                if (!string.IsNullOrEmpty(definition.XmlDefinition))
                {
                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var value        = ConvertUtils.ToString(d.XmlDefinition);
                        var destXmlAttrs = XDocument.Parse(value).Root.Attributes();

                        var srcProp = s.GetExpressionValue(m => m.XmlDefinition);
                        var isValid = true;

                        var srcXmlAttrs = XDocument.Parse(definition.XmlDefinition).Root.Attributes();

                        foreach (var srcAttr in srcXmlAttrs)
                        {
                            var attrName  = srcAttr.Name;
                            var attrValue = srcAttr.Value;

                            isValid = destXmlAttrs.FirstOrDefault(a => a.Name == attrName)
                                      .Value == attrValue;

                            if (!isValid)
                            {
                                break;
                            }
                        }

                        return(new PropertyValidationResult
                        {
                            Tag = p.Tag,
                            Src = srcProp,
                            Dst = null,
                            IsValid = isValid
                        });
                    });
                }
                else
                {
                    assert.SkipProperty(m => m.XmlDefinition);
                }

                if (!string.IsNullOrEmpty(definition.Xsl))
                {
                    assert.ShouldBeEqual(m => m.Xsl, o => o.Xsl);
                }
                else
                {
                    assert.SkipProperty(m => m.Xsl);
                }

                // skip it, it will be part of the .Toolbar validation
                assert.SkipProperty(m => m.ToolbarShowAlways, "");

                if (!string.IsNullOrEmpty(definition.Toolbar))
                {
                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var targetView    = (spObject as XsltListViewWebPart).View;
                        var htmlSchemaXml = XDocument.Parse(targetView.HtmlSchemaXml);

                        var useShowAlwaysValue =
                            (typedDefinition.Toolbar.ToUpper() == BuiltInToolbarType.Standard.ToUpper()) &&
                            typedDefinition.ToolbarShowAlways.HasValue &&
                            typedDefinition.ToolbarShowAlways.Value;

                        var toolbarNode = htmlSchemaXml.Root
                                          .Descendants("Toolbar")
                                          .FirstOrDefault();

                        // NONE? the node might not be there
                        if ((typedDefinition.Toolbar.ToUpper() == BuiltInToolbarType.None.ToUpper()) &&
                            (toolbarNode == null))
                        {
                            var srcProp = s.GetExpressionValue(m => m.Toolbar);

                            return(new PropertyValidationResult
                            {
                                Tag = p.Tag,
                                Src = srcProp,
                                Dst = null,
                                IsValid = true
                            });
                        }
                        else
                        {
                            var toolBarValue = toolbarNode.GetAttributeValue("Type");

                            var srcProp = s.GetExpressionValue(m => m.Toolbar);
                            var isValid = toolBarValue.ToUpper() == definition.Toolbar.ToUpper();

                            if (useShowAlwaysValue)
                            {
                                var showAlwaysValue = toolbarNode.GetAttributeValue("ShowAlways");
                                isValid             = isValid && (showAlwaysValue.ToUpper() == "TRUE");
                            }

                            return(new PropertyValidationResult
                            {
                                Tag = p.Tag,
                                Src = srcProp,
                                Dst = null,
                                IsValid = isValid
                            });
                        }
                    });
                }
                else
                {
                    assert.SkipProperty(m => m.Toolbar);
                }
            });
        }
コード例 #5
0
        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            // base validation
            base.DeployModel(modelHost, model);


            // web specific validation
            var host       = modelHost.WithAssertAndCast <WebpartPageModelHost>("modelHost", value => value.RequireNotNull());
            var definition = model.WithAssertAndCast <ListViewWebPartDefinition>("model", value => value.RequireNotNull());

            var item = host.PageListItem;

            WebPartExtensions.WithExistingWebPart(item, definition, (spWebPartManager, spObject) =>
            {
                var web         = spWebPartManager.Web;
                var typedObject = spObject as ListViewWebPart;

                var assert = ServiceFactory.AssertService
                             .NewAssert(definition, typedObject)
                             .ShouldNotBeNull(typedObject);

                var targetList = web.Lists[typedObject.ListId];

                var hasList = !string.IsNullOrEmpty(definition.ListTitle) ||
                              !string.IsNullOrEmpty(definition.ListUrl) ||
                              definition.ListId.HasValue;
                var hasView = !string.IsNullOrEmpty(definition.ViewName) ||
                              definition.ViewId.HasValue;;

                // list
                if (!string.IsNullOrEmpty(definition.ListTitle))
                {
                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var srcProp = s.GetExpressionValue(m => m.ListTitle);
                        var dstProp = d.GetExpressionValue(o => o.ListId);

                        return(new PropertyValidationResult
                        {
                            Tag = p.Tag,
                            Src = srcProp,
                            Dst = null,
                            IsValid = targetList.ID == (Guid)dstProp.Value
                        });
                    });
                }
                else
                {
                    assert.SkipProperty(m => m.ListTitle, "ListTitle is null or empty. Skipping.");
                }

                if (!string.IsNullOrEmpty(definition.ListUrl))
                {
                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var srcProp = s.GetExpressionValue(m => m.ListUrl);
                        var dstProp = d.GetExpressionValue(o => o.ListId);

                        return(new PropertyValidationResult
                        {
                            Tag = p.Tag,
                            Src = srcProp,
                            Dst = null,
                            IsValid = targetList.ID == (Guid)dstProp.Value
                        });
                    });
                }
                else
                {
                    assert.SkipProperty(m => m.ListUrl, "ListUrl is null or empty. Skipping.");
                }

                if (definition.ListId.HasValue && definition.ListId != default(Guid))
                {
                    assert.ShouldBeEqual(m => m.ListId, o => o.ListId);
                }
                else
                {
                    assert.SkipProperty(m => m.ListId, "ListId is null or empty. Skipping.");
                }

                // view
                if (definition.ViewId.HasValue)
                {
                    // web part gonna have hidden view
                    // so validation is a bit tricky, done by other properties

                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var srcView = targetList.Views[s.ViewId.Value];
                        var dstView = targetList.Views[new Guid(typedObject.ViewGuid)];

                        var srcProp = s.GetExpressionValue(m => m.ViewId);
                        var dstProp = d.GetExpressionValue(o => o.ViewGuid);

                        var isValid = srcView.ViewFields.Count == dstView.ViewFields.Count &&
                                      srcView.Query == dstView.Query;

                        return(new PropertyValidationResult
                        {
                            Tag = p.Tag,
                            Src = srcProp,
                            Dst = null,
                            IsValid = isValid
                        });
                    });
                }
                else
                {
                    assert.SkipProperty(m => m.ViewId, "ViewId is null or empty. Skipping.");
                }

                if (!string.IsNullOrEmpty(definition.ViewName))
                {
                    // web part gonna have hidden view
                    // so validation is a bit tricky, done by other properties

                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var srcView = targetList.Views[s.ViewName];
                        var dstView = targetList.Views[new Guid(typedObject.ViewGuid)];

                        var srcProp = s.GetExpressionValue(m => m.ViewName);
                        var dstProp = d.GetExpressionValue(o => o.ViewGuid);

                        var isValid = srcView.ViewFields.Count == dstView.ViewFields.Count &&
                                      srcView.Query == dstView.Query;

                        return(new PropertyValidationResult
                        {
                            Tag = p.Tag,
                            Src = srcProp,
                            Dst = null,
                            IsValid = isValid
                        });
                    });
                }
                else
                {
                    assert.SkipProperty(m => m.ViewName, "ViewName is null or empty. Skipping.");
                }

                //  title link
                if (string.IsNullOrEmpty(definition.TitleUrl))
                {
                    // list?
                    if (hasView)
                    {
                        assert.ShouldBeEqual((p, s, d) =>
                        {
                            var srcProp = s.GetExpressionValue(m => m.TitleUrl);
                            var srcView = string.IsNullOrEmpty(s.ViewName) ?
                                          targetList.Views[s.ViewId.Value] :
                                          targetList.Views[s.ViewName];

                            return(new PropertyValidationResult
                            {
                                Tag = p.Tag,
                                Src = srcProp,
                                Dst = null,
                                IsValid = srcView.ServerRelativeUrl.StartsWith(typedObject.TitleUrl)
                            });
                        });
                    }
                    else if (hasList)
                    {
                        assert.ShouldBeEqual((p, s, d) =>
                        {
                            var srcProp = s.GetExpressionValue(m => m.TitleUrl);

                            return(new PropertyValidationResult
                            {
                                Tag = p.Tag,
                                Src = srcProp,
                                Dst = null,
                                IsValid = targetList.DefaultViewUrl.StartsWith(typedObject.TitleUrl)
                            });
                        });
                    }
                }
                else
                {
                    assert.ShouldBeEqual(m => m.TitleUrl, o => o.TitleUrl);
                }
            });
        }
コード例 #6
0
        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            var host       = modelHost.WithAssertAndCast <WebpartPageModelHost>("modelHost", value => value.RequireNotNull());
            var definition = model.WithAssertAndCast <WebPartDefinition>("model", value => value.RequireNotNull());

            var item = host.PageListItem;

            WebPartExtensions.WithExistingWebPart(item, definition, (spWebPartManager, spObject) =>
            {
                //[FALSE] - [Title]
                //                        [FALSE] - [Id]
                //                        [FALSE] - [ZoneId]
                //                        [FALSE] - [ZoneIndex]
                //                        [FALSE] - [WebpartFileName]
                //                        [FALSE] - [WebpartType]
                //                        [FALSE] - [WebpartXmlTemplate]

                var assert = ServiceFactory.AssertService
                             .NewAssert(definition, spObject)
                             .ShouldNotBeNull(spObject);

                if (!string.IsNullOrEmpty(definition.ChromeState))
                {
                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var srcProp  = s.GetExpressionValue(m => m.ChromeState);
                        var srcValue = (PartChromeState)Enum.Parse(typeof(PartChromeState), s.ChromeState);
                        var isValid  = srcValue == d.ChromeState;

                        return(new PropertyValidationResult
                        {
                            Tag = p.Tag,
                            Src = srcProp,
                            Dst = null,
                            IsValid = isValid
                        });
                    });
                }
                else
                {
                    assert.SkipProperty(m => m.ChromeState, "ChromeType is null or empty. Skipping.");
                }

                if (!string.IsNullOrEmpty(definition.ChromeType))
                {
                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var srcProp    = s.GetExpressionValue(m => m.ChromeType);
                        var chromeType = WebPartChromeTypesConvertService.NormilizeValueToPartChromeTypes(s.ChromeType);

                        var srcValue = (PartChromeType)Enum.Parse(typeof(PartChromeType), chromeType);
                        var isValid  = srcValue == d.ChromeType;

                        return(new PropertyValidationResult
                        {
                            Tag = p.Tag,
                            Src = srcProp,
                            Dst = null,
                            IsValid = isValid
                        });
                    });
                }
                else
                {
                    assert.SkipProperty(m => m.ChromeType, "ChromeType is null or empty. Skipping.");
                }

                if (!string.IsNullOrEmpty(definition.Description))
                {
                    assert.ShouldBeEqual(m => m.Description, o => o.Description);
                }
                else
                {
                    assert.SkipProperty(m => m.Description, "Description is null or empty. Skipping.");
                }

                if (definition.Height.HasValue)
                {
                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var srcProp = s.GetExpressionValue(m => m.Height);
                        var isValid = d.Height == new Unit(s.Height.Value);

                        return(new PropertyValidationResult
                        {
                            Tag = p.Tag,
                            Src = srcProp,
                            Dst = null,
                            IsValid = isValid
                        });
                    });
                }
                else
                {
                    assert.SkipProperty(m => m.Height, "Height is null or empty. Skipping.");
                }

                if (definition.Width.HasValue)
                {
                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var srcProp = s.GetExpressionValue(m => m.Width);
                        var isValid = d.Width == new Unit(s.Width.Value);

                        return(new PropertyValidationResult
                        {
                            Tag = p.Tag,
                            Src = srcProp,
                            Dst = null,
                            IsValid = isValid
                        });
                    });
                }
                else
                {
                    assert.SkipProperty(m => m.Width, "Width is null or empty. Skipping.");
                }

                if (!string.IsNullOrEmpty(definition.ImportErrorMessage))
                {
                    assert.ShouldBeEqual(m => m.ImportErrorMessage, o => o.ImportErrorMessage);
                }
                else
                {
                    assert.SkipProperty(m => m.ImportErrorMessage, "ImportErrorMessage is null or empty. Skipping.");
                }

                if (!DisableTitleUrlValidation)
                {
                    if (!string.IsNullOrEmpty(definition.TitleUrl))
                    {
                        assert.ShouldBeEndOf(m => m.TitleUrl, o => o.TitleUrl);
                    }
                    else
                    {
                        assert.SkipProperty(m => m.TitleUrl, "TitleUrl is null or empty. Skipping.");
                    }
                }

                if (!string.IsNullOrEmpty(definition.TitleIconImageUrl))
                {
                    assert.ShouldBeEndOf(m => m.TitleIconImageUrl, o => o.TitleIconImageUrl);
                }
                else
                {
                    assert.SkipProperty(m => m.TitleIconImageUrl, "TitleIconImageUrl is null or empty. Skipping.");
                }

                if (!string.IsNullOrEmpty(definition.ExportMode))
                {
                    assert.ShouldBeEqual(m => m.ExportMode, o => o.GetExportMode());
                }
                else
                {
                    assert.SkipProperty(m => m.ExportMode, "ExportMode is null or empty. Skipping.");
                }


                if (!string.IsNullOrEmpty(definition.Id))
                {
                    assert.ShouldBeEqual(m => m.Id, o => o.ID);
                }
                else
                {
                    assert.SkipProperty(m => m.Id, "Id is null or empty. Skipping.");
                }

                if (!string.IsNullOrEmpty(definition.Title))
                {
                    assert.ShouldBeEqual(m => m.Title, o => o.Title);
                }
                else
                {
                    assert.SkipProperty(m => m.Title, "Title is null or empty. Skipping.");
                }

                if (!string.IsNullOrEmpty(definition.ZoneId))
                {
                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var srcProp = s.GetExpressionValue(m => m.ZoneId);
                        //var dstProp = d.GetExpressionValue(ct => ct.GetId());

                        return(new PropertyValidationResult
                        {
                            Tag = p.Tag,
                            Src = srcProp,
                            Dst = null,
                            IsValid = object.Equals(s.ZoneId, spWebPartManager.GetZoneID(d))
                        });
                    });
                }

                else
                {
                    assert.SkipProperty(m => m.ZoneId, "ZoneId is null or empty. Skipping.");
                }

                //if (definition.ZoneIndex > 0)
                //    assert.ShouldBeEqual(m => m.ZoneIndex, o => o.ZoneIndex);
                //else
                //    assert.SkipProperty(m => m.ZoneIndex, "ZoneIndex == 0. Skipping.");

                assert.SkipProperty(m => m.ZoneIndex, "Skipping.");

                if (!string.IsNullOrEmpty(definition.WebpartFileName))
                {
                    var site = host.PageListItem.Web.Site;

                    var webPartManager = host.SPLimitedWebPartManager;

                    var webpartFileName = definition.WebpartFileName;
                    var rootWeb         = site.RootWeb;

                    // load definition from WP catalog
                    var webpartCatalog = rootWeb.GetCatalog(SPListTemplateType.WebPartCatalog);
                    var webpartItem    = webpartCatalog.Items.OfType <SPListItem>().FirstOrDefault(
                        i => string.Compare(i.Name, webpartFileName, true) == 0);

                    if (webpartItem == null)
                    {
                        throw new ArgumentException(string.Format("webpartItem. Can't find web part file with name: {0}", webpartFileName));
                    }

                    using (var streamReader = new MemoryStream(webpartItem.File.OpenBinary()))
                    {
                        using (var xmlReader = XmlReader.Create(streamReader))
                        {
                            var errMessage          = string.Empty;
                            var webpartInstance     = webPartManager.ImportWebPart(xmlReader, out errMessage);
                            var webPartInstanceType = webpartInstance.GetType();

                            assert.ShouldBeEqual((p, s, d) =>
                            {
                                var srcProp = s.GetExpressionValue(m => m.WebpartFileName);
                                //var dstProp = d.GetExpressionValue(ct => ct.GetId());

                                return(new PropertyValidationResult
                                {
                                    Tag = p.Tag,
                                    Src = srcProp,
                                    Dst = null,
                                    IsValid = webPartInstanceType == d.GetType()
                                });
                            });
                        }
                    }
                }
                else
                {
                    assert.SkipProperty(m => m.WebpartFileName, "ZoneIndex == 0. Skipping.");
                }

                if (!string.IsNullOrEmpty(definition.WebpartType))
                {
                    var webPartInstance     = WebPartExtensions.ResolveWebPartInstance(host.PageListItem.Web.Site, host.SPLimitedWebPartManager, definition);
                    var webPartInstanceType = webPartInstance.GetType();

                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var srcProp = s.GetExpressionValue(m => m.WebpartType);
                        //var dstProp = d.GetExpressionValue(ct => ct.GetId());

                        return(new PropertyValidationResult
                        {
                            Tag = p.Tag,
                            Src = srcProp,
                            Dst = null,
                            IsValid = webPartInstanceType == d.GetType()
                        });
                    });
                }
                else
                {
                    assert.SkipProperty(m => m.WebpartType, "WebpartType is empty. Skipping.");
                }

                if (!string.IsNullOrEmpty(definition.WebpartXmlTemplate))
                {
                    assert.SkipProperty(m => m.WebpartXmlTemplate, "WebpartXmlTemplate is not empty, but no validation is required with SSOM. Skipping.");
                }
                else
                {
                    assert.SkipProperty(m => m.WebpartXmlTemplate, "WebpartXmlTemplate is empty. Skipping.");
                }

                if (definition.ParameterBindings.Count == 0)
                {
                    assert.SkipProperty(m => m.ParameterBindings, "ParameterBindings is null or empty. Skipping.");
                }
                else
                {
                    // TODO
                }
            });
        }
コード例 #7
0
        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            // base validation
            base.DeployModel(modelHost, model);

            var host       = modelHost.WithAssertAndCast <WebpartPageModelHost>("modelHost", value => value.RequireNotNull());
            var definition = model.WithAssertAndCast <ResultScriptWebPartDefinition>("model", value => value.RequireNotNull());

            //var item = host.PageListItem;

            WebPartExtensions.WithExistingWebPart(host.HostFile, definition, (spWebPartManager, spObject) =>
            {
                var typedWebPart = spObject as ResultScriptWebPart;

                var assert = ServiceFactory.AssertService
                             .NewAssert(definition, typedWebPart)
                             .ShouldNotBeNull(typedWebPart);

                if (!string.IsNullOrEmpty(definition.DataProviderJSON))
                {
                    throw new NotImplementedException();
                }
                else
                {
                    assert.SkipProperty(m => m.DataProviderJSON, "DataProviderJSON is null or empty, skipping.");
                }

                if (!string.IsNullOrEmpty(definition.EmptyMessage))
                {
                    assert.ShouldBeEqual(m => m.EmptyMessage, o => o.EmptyMessage);
                }
                else
                {
                    assert.SkipProperty(m => m.EmptyMessage, "EmptyMessage is null or empty, skipping.");
                }

                if (definition.ResultsPerPage.HasValue)
                {
                    assert.ShouldBeEqual(m => m.ResultsPerPage.Value, o => o.ResultsPerPage);
                }
                else
                {
                    assert.SkipProperty(m => m.ResultsPerPage, "ResultsPerPage is null or empty, skipping.");
                }

                if (definition.ShowResultCount.HasValue)
                {
                    assert.ShouldBeEqual(m => m.ShowResultCount.Value, o => o.ShowResultCount);
                }
                else
                {
                    assert.SkipProperty(m => m.ShowResultCount, "ShowResultCount is null or empty, skipping.");
                }

                if (definition.ShowLanguageOptions.HasValue)
                {
                    assert.ShouldBeEqual(m => m.ShowLanguageOptions.Value, o => o.ShowLanguageOptions);
                }
                else
                {
                    assert.SkipProperty(m => m.ShowLanguageOptions, "ShowLanguageOptions is null or empty, skipping.");
                }

                if (definition.MaxPagesBeforeCurrent.HasValue)
                {
                    assert.ShouldBeEqual(m => m.MaxPagesBeforeCurrent.Value, o => o.MaxPagesBeforeCurrent);
                }
                else
                {
                    assert.SkipProperty(m => m.MaxPagesBeforeCurrent, "MaxPagesBeforeCurrent is null or empty, skipping.");
                }

                if (definition.ShowBestBets.HasValue)
                {
                    assert.ShouldBeEqual(m => m.ShowBestBets.Value, o => o.ShowBestBets);
                }
                else
                {
                    assert.SkipProperty(m => m.ShowBestBets, "ShowBestBets is null or empty, skipping.");
                }

                if (!string.IsNullOrEmpty(definition.AdvancedSearchPageAddress))
                {
                    assert.ShouldBeEqual(m => m.AdvancedSearchPageAddress, o => o.AdvancedSearchPageAddress);
                }
                else
                {
                    assert.SkipProperty(m => m.AdvancedSearchPageAddress, "AdvancedSearchPageAddress is null or empty, skipping.");
                }

                if (definition.UseSharedDataProvider.HasValue)
                {
                    assert.ShouldBeEqual(m => m.UseSharedDataProvider.Value, o => o.UseSharedDataProvider);
                }
                else
                {
                    assert.SkipProperty(m => m.UseSharedDataProvider, "UseSharedDataProvider is null or empty, skipping.");
                }

                if (definition.ShowPreferencesLink.HasValue)
                {
                    assert.ShouldBeEqual(m => m.ShowPreferencesLink.Value, o => o.ShowPreferencesLink);
                }
                else
                {
                    assert.SkipProperty(m => m.ShowPreferencesLink, "ShowPreferencesLink is null or empty, skipping.");
                }

                if (definition.ShowViewDuplicates.HasValue)
                {
                    assert.ShouldBeEqual(m => m.ShowViewDuplicates.Value, o => o.ShowViewDuplicates);
                }
                else
                {
                    assert.SkipProperty(m => m.ShowViewDuplicates, "ShowViewDuplicates is null or empty, skipping.");
                }

                if (definition.RepositionLanguageDropDown.HasValue)
                {
                    assert.ShouldBeEqual(m => m.RepositionLanguageDropDown.Value, o => o.RepositionLanguageDropDown);
                }
                else
                {
                    assert.SkipProperty(m => m.RepositionLanguageDropDown, "RepositionLanguageDropDown is null or empty, skipping.");
                }

                if (!string.IsNullOrEmpty(definition.PreloadedItemTemplateIdsJson))
                {
                    throw new NotImplementedException();
                }
                else
                {
                    assert.SkipProperty(m => m.PreloadedItemTemplateIdsJson, "PreloadedItemTemplateIdsJson is null or empty, skipping.");
                }

                if (definition.ShowPaging.HasValue)
                {
                    assert.ShouldBeEqual(m => m.ShowPaging.Value, o => o.ShowPaging);
                }
                else
                {
                    assert.SkipProperty(m => m.ShowPaging, "ShowPaging is null or empty, skipping.");
                }

                if (!string.IsNullOrEmpty(definition.ResultTypeId))
                {
                    assert.ShouldBeEqual(m => m.ResultTypeId, o => o.ResultTypeId);
                }
                else
                {
                    assert.SkipProperty(m => m.ResultTypeId, "ResultTypeId is null or empty, skipping.");
                }

                if (definition.ShowResults.HasValue)
                {
                    assert.ShouldBeEqual(m => m.ShowResults.Value, o => o.ShowResults);
                }
                else
                {
                    assert.SkipProperty(m => m.ShowResults, "ShowResults is null or empty, skipping.");
                }

                if (!string.IsNullOrEmpty(definition.ItemTemplateId))
                {
                    assert.ShouldBeEqual(m => m.ItemTemplateId, o => o.ItemTemplateId);
                }
                else
                {
                    assert.SkipProperty(m => m.ItemTemplateId, "ItemTemplateId is null or empty, skipping.");
                }

                if (!string.IsNullOrEmpty(definition.ItemBodyTemplateId))
                {
                    assert.ShouldBeEqual(m => m.ItemBodyTemplateId, o => o.ItemBodyTemplateId);
                }
                else
                {
                    assert.SkipProperty(m => m.ItemBodyTemplateId, "ItemBodyTemplateId is null or empty, skipping.");
                }

                if (!string.IsNullOrEmpty(definition.HitHighlightedPropertiesJson))
                {
                    throw new NotImplementedException();
                }
                else
                {
                    assert.SkipProperty(m => m.HitHighlightedPropertiesJson, "HitHighlightedPropertiesJson is null or empty, skipping.");
                }

                if (!string.IsNullOrEmpty(definition.AvailableSortsJson))
                {
                    throw new NotImplementedException();
                }
                else
                {
                    assert.SkipProperty(m => m.AvailableSortsJson, "AvailableSortsJson is null or empty, skipping.");
                }

                if (!string.IsNullOrEmpty(definition.RenderTemplateId))
                {
                    assert.ShouldBeEqual(m => m.RenderTemplateId, o => o.RenderTemplateId);
                }
                else
                {
                    assert.SkipProperty(m => m.RenderTemplateId, "RenderTemplateId is null or empty, skipping.");
                }

                if (definition.ShowPersonalFavorites.HasValue)
                {
                    assert.ShouldBeEqual(m => m.ShowPersonalFavorites.Value, o => o.ShowPersonalFavorites);
                }
                else
                {
                    assert.SkipProperty(m => m.ShowPersonalFavorites, "ShowPersonalFavorites is null or empty, skipping.");
                }

                if (definition.ShowSortOptions.HasValue)
                {
                    assert.ShouldBeEqual(m => m.ShowSortOptions.Value, o => o.ShowSortOptions);
                }
                else
                {
                    assert.SkipProperty(m => m.ShowSortOptions, "ShowSortOptions is null or empty, skipping.");
                }

                if (definition.ShowAlertMe.HasValue)
                {
                    assert.ShouldBeEqual(m => m.ShowAlertMe.Value, o => o.ShowAlertMe);
                }
                else
                {
                    assert.SkipProperty(m => m.ShowAlertMe, "ShowAlertMe is null or empty, skipping.");
                }

                if (definition.ShowDidYouMean.HasValue)
                {
                    assert.ShouldBeEqual(m => m.ShowDidYouMean.Value, o => o.ShowDidYouMean);
                }
                else
                {
                    assert.SkipProperty(m => m.ShowDidYouMean, "ShowDidYouMean is null or empty, skipping.");
                }

                if (!string.IsNullOrEmpty(definition.QueryGroupName))
                {
                    assert.ShouldBeEqual(m => m.QueryGroupName, o => o.QueryGroupName);
                }
                else
                {
                    assert.SkipProperty(m => m.QueryGroupName, "QueryGroupName is null or empty, skipping.");
                }

                if (definition.ShowAdvancedLink.HasValue)
                {
                    assert.ShouldBeEqual(m => m.ShowAdvancedLink.Value, o => o.ShowAdvancedLink);
                }
                else
                {
                    assert.SkipProperty(m => m.ShowAdvancedLink, "ShowAdvancedLink is null or empty, skipping.");
                }

                if (definition.BypassResultTypes.HasValue)
                {
                    assert.ShouldBeEqual(m => m.BypassResultTypes.Value, o => o.BypassResultTypes);
                }
                else
                {
                    assert.SkipProperty(m => m.BypassResultTypes, "BypassResultTypes is null or empty, skipping.");
                }

                if (!string.IsNullOrEmpty(definition.GroupTemplateId))
                {
                    assert.ShouldBeEqual(m => m.GroupTemplateId, o => o.GroupTemplateId);
                }
                else
                {
                    assert.SkipProperty(m => m.GroupTemplateId, "GroupTemplateId is null or empty, skipping.");
                }
            });
        }
コード例 #8
0
        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            var host       = modelHost.WithAssertAndCast <WebpartPageModelHost>("modelHost", value => value.RequireNotNull());
            var definition = model.WithAssertAndCast <WebPartDefinition>("model", value => value.RequireNotNull());

            var item = host.PageListItem;

            WebPartExtensions.WithExistingWebPart(item, definition, (spWebPartManager, spObject) =>
            {
                //[FALSE] - [Title]
                //                        [FALSE] - [Id]
                //                        [FALSE] - [ZoneId]
                //                        [FALSE] - [ZoneIndex]
                //                        [FALSE] - [WebpartFileName]
                //                        [FALSE] - [WebpartType]
                //                        [FALSE] - [WebpartXmlTemplate]

                var assert = ServiceFactory.AssertService
                             .NewAssert(definition, spObject)
                             .ShouldNotBeNull(spObject);

                if (!string.IsNullOrEmpty(definition.Id))
                {
                    assert.ShouldBeEqual(m => m.Id, o => o.ID);
                }
                else
                {
                    assert.SkipProperty(m => m.Id, "Id is null or empty. Skipping.");
                }

                if (!string.IsNullOrEmpty(definition.Title))
                {
                    assert.ShouldBeEqual(m => m.Title, o => o.Title);
                }
                else
                {
                    assert.SkipProperty(m => m.Title, "Title is null or empty. Skipping.");
                }

                if (!string.IsNullOrEmpty(definition.ZoneId))
                {
                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var srcProp = s.GetExpressionValue(m => m.ZoneId);
                        //var dstProp = d.GetExpressionValue(ct => ct.GetId());

                        return(new PropertyValidationResult
                        {
                            Tag = p.Tag,
                            Src = srcProp,
                            Dst = null,
                            IsValid = object.Equals(s.ZoneId, spWebPartManager.GetZoneID(d))
                        });
                    });
                }

                else
                {
                    assert.SkipProperty(m => m.ZoneId, "ZoneId is null or empty. Skipping.");
                }

                //if (definition.ZoneIndex > 0)
                //    assert.ShouldBeEqual(m => m.ZoneIndex, o => o.ZoneIndex);
                //else
                //    assert.SkipProperty(m => m.ZoneIndex, "ZoneIndex == 0. Skipping.");

                assert.SkipProperty(m => m.ZoneIndex, "Skipping.");

                if (!string.IsNullOrEmpty(definition.WebpartFileName))
                {
                    var site = host.PageListItem.Web.Site;

                    var webPartManager = host.SPLimitedWebPartManager;

                    var webpartFileName = definition.WebpartFileName;
                    var rootWeb         = site.RootWeb;

                    // load definition from WP catalog
                    var webpartCatalog = rootWeb.GetCatalog(SPListTemplateType.WebPartCatalog);
                    var webpartItem    = webpartCatalog.Items.OfType <SPListItem>().FirstOrDefault(
                        i => string.Compare(i.Name, webpartFileName, true) == 0);

                    if (webpartItem == null)
                    {
                        throw new ArgumentException(string.Format("webpartItem. Can't find web part file with name: {0}", webpartFileName));
                    }

                    using (var streamReader = new MemoryStream(webpartItem.File.OpenBinary()))
                    {
                        using (var xmlReader = XmlReader.Create(streamReader))
                        {
                            var errMessage          = string.Empty;
                            var webpartInstance     = webPartManager.ImportWebPart(xmlReader, out errMessage);
                            var webPartInstanceType = webpartInstance.GetType();

                            assert.ShouldBeEqual((p, s, d) =>
                            {
                                var srcProp = s.GetExpressionValue(m => m.WebpartFileName);
                                //var dstProp = d.GetExpressionValue(ct => ct.GetId());

                                return(new PropertyValidationResult
                                {
                                    Tag = p.Tag,
                                    Src = srcProp,
                                    Dst = null,
                                    IsValid = webPartInstanceType == d.GetType()
                                });
                            });
                        }
                    }
                }
                else
                {
                    assert.SkipProperty(m => m.WebpartFileName, "ZoneIndex == 0. Skipping.");
                }

                if (!string.IsNullOrEmpty(definition.WebpartType))
                {
                    var webPartInstance     = WebPartExtensions.ResolveWebPartInstance(host.PageListItem.Web.Site, host.SPLimitedWebPartManager, definition);
                    var webPartInstanceType = webPartInstance.GetType();

                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var srcProp = s.GetExpressionValue(m => m.WebpartType);
                        //var dstProp = d.GetExpressionValue(ct => ct.GetId());

                        return(new PropertyValidationResult
                        {
                            Tag = p.Tag,
                            Src = srcProp,
                            Dst = null,
                            IsValid = webPartInstanceType == d.GetType()
                        });
                    });
                }
                else
                {
                    assert.SkipProperty(m => m.WebpartType, "WebpartType is empty. Skipping.");
                }

                if (!string.IsNullOrEmpty(definition.WebpartXmlTemplate))
                {
                    throw new SPMeta2NotImplementedException("WebpartXmlTemplate validation is not supported yet.");
                }
                else
                {
                    assert.SkipProperty(m => m.WebpartXmlTemplate, "WebpartXmlTemplate is empty. Skipping.");
                }
            });
        }
コード例 #9
0
        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            // base validation
            base.DeployModel(modelHost, model);

            // content editor specific validation

            var host       = modelHost.WithAssertAndCast <WebpartPageModelHost>("modelHost", value => value.RequireNotNull());
            var typedModel = model.WithAssertAndCast <ContentByQueryWebPartDefinition>("model", value => value.RequireNotNull());

            var item = host.PageListItem;

            WebPartExtensions.WithExistingWebPart(item, typedModel, (spWebPartManager, spObject) =>
            {
                var typedWebPart = spObject as ContentByQueryWebPart;

                var assert = ServiceFactory.AssertService
                             .NewAssert(typedModel, typedWebPart)
                             .ShouldNotBeNull(typedWebPart);

                if (!string.IsNullOrEmpty(typedModel.ContentTypeBeginsWithId))
                {
                    assert.ShouldBeEqual(m => m.ContentTypeBeginsWithId, o => o.ContentTypeBeginsWithId);
                }
                else
                {
                    assert.SkipProperty(m => m.ContentTypeBeginsWithId, "ContentTypeBeginsWithId is null or empty, skipping.");
                }

                if (!string.IsNullOrEmpty(typedModel.DataMappings))
                {
                    assert.ShouldBeEqual(m => m.DataMappings, o => o.DataMappings);
                }
                else
                {
                    assert.SkipProperty(m => m.DataMappings, "DataMappings is null or empty, skipping.");
                }

                if (!string.IsNullOrEmpty(typedModel.DataMappingViewFields))
                {
                    assert.ShouldBeEqual(m => m.DataMappingViewFields, o => o.DataMappingViewFields);
                }
                else
                {
                    assert.SkipProperty(m => m.DataMappingViewFields, "DataMappingViewFields is null or empty, skipping.");
                }

                // filter display value 1-2-3
                if (!string.IsNullOrEmpty(typedModel.FilterDisplayValue1))
                {
                    assert.ShouldBeEqual(m => m.FilterDisplayValue1, o => o.FilterDisplayValue1);
                }
                else
                {
                    assert.SkipProperty(m => m.FilterDisplayValue1, "FilterDisplayValue1 is null or empty, skipping.");
                }

                if (!string.IsNullOrEmpty(typedModel.FilterDisplayValue2))
                {
                    assert.ShouldBeEqual(m => m.FilterDisplayValue2, o => o.FilterDisplayValue2);
                }
                else
                {
                    assert.SkipProperty(m => m.FilterDisplayValue2, "FilterDisplayValue2 is null or empty, skipping.");
                }

                if (!string.IsNullOrEmpty(typedModel.FilterDisplayValue3))
                {
                    assert.ShouldBeEqual(m => m.FilterDisplayValue3, o => o.FilterDisplayValue3);
                }
                else
                {
                    assert.SkipProperty(m => m.FilterDisplayValue3, "FilterDisplayValue3 is null or empty, skipping.");
                }

                // operators 1-2-3
                if (!string.IsNullOrEmpty(typedModel.FilterOperator1))
                {
                }
                else
                {
                    assert.SkipProperty(m => m.FilterOperator1, "FilterOperator1 is null or empty, skipping.");
                }

                if (!string.IsNullOrEmpty(typedModel.FilterOperator2))
                {
                }
                else
                {
                    assert.SkipProperty(m => m.FilterOperator2, "FilterOperator2 is null or empty, skipping.");
                }

                if (!string.IsNullOrEmpty(typedModel.FilterOperator3))
                {
                }
                else
                {
                    assert.SkipProperty(m => m.FilterOperator3, "FilterOperator3 is null or empty, skipping.");
                }

                // type 1-2-3
                if (!string.IsNullOrEmpty(typedModel.FilterType1))
                {
                    assert.ShouldBeEqual(m => m.FilterType1, o => o.FilterType1);
                }
                else
                {
                    assert.SkipProperty(m => m.FilterType1, "FilterType1 is null or empty, skipping.");
                }

                if (!string.IsNullOrEmpty(typedModel.FilterType2))
                {
                    assert.ShouldBeEqual(m => m.FilterType2, o => o.FilterType2);
                }
                else
                {
                    assert.SkipProperty(m => m.FilterType2, "FilterType2 is null or empty, skipping.");
                }

                if (!string.IsNullOrEmpty(typedModel.FilterType3))
                {
                    assert.ShouldBeEqual(m => m.FilterType3, o => o.FilterType3);
                }
                else
                {
                    assert.SkipProperty(m => m.FilterType3, "FilterType3 is null or empty, skipping.");
                }

                // filter values 1-2-3
                if (!string.IsNullOrEmpty(typedModel.FilterValue1))
                {
                    assert.ShouldBeEqual(m => m.FilterValue1, o => o.FilterValue1);
                }
                else
                {
                    assert.SkipProperty(m => m.FilterValue1, "FilterValue1 is null or empty, skipping.");
                }

                if (!string.IsNullOrEmpty(typedModel.FilterValue2))
                {
                    assert.ShouldBeEqual(m => m.FilterValue2, o => o.FilterValue2);
                }
                else
                {
                    assert.SkipProperty(m => m.FilterValue2, "FilterValue2 is null or empty, skipping.");
                }

                if (!string.IsNullOrEmpty(typedModel.FilterValue3))
                {
                    assert.ShouldBeEqual(m => m.FilterValue3, o => o.FilterValue3);
                }
                else
                {
                    assert.SkipProperty(m => m.FilterValue3, "FilterValue3 is null or empty, skipping.");
                }

                // sorting

                if (!string.IsNullOrEmpty(typedModel.SortBy))
                {
                    assert.ShouldBeEqual(m => m.SortBy, o => o.SortBy);
                }
                else
                {
                    assert.SkipProperty(m => m.SortBy, "SortBy is null or empty, skipping.");
                }

                if (!string.IsNullOrEmpty(typedModel.SortByFieldType))
                {
                    assert.ShouldBeEqual(m => m.SortByFieldType, o => o.SortByFieldType);
                }
                else
                {
                    assert.SkipProperty(m => m.SortByFieldType, "SortByFieldType is null or empty, skipping.");
                }

                if (!string.IsNullOrEmpty(typedModel.SortByDirection))
                {
                    // TODO
                }
                else
                {
                    assert.SkipProperty(m => m.SortByDirection, "SortByDirection is null or empty, skipping.");
                }

                // xslt
                if (!string.IsNullOrEmpty(typedModel.GroupStyle))
                {
                    assert.ShouldBeEqual(m => m.GroupStyle, o => o.GroupStyle);
                }
                else
                {
                    assert.SkipProperty(m => m.GroupStyle, "GroupStyle is null or empty, skipping.");
                }

                if (!string.IsNullOrEmpty(typedModel.ItemStyle))
                {
                    assert.ShouldBeEqual(m => m.ItemStyle, o => o.ItemStyle);
                }
                else
                {
                    assert.SkipProperty(m => m.ItemStyle, "ItemStyle is null or empty, skipping.");
                }

                if (!string.IsNullOrEmpty(typedModel.ItemXslLink))
                {
                    // TODO
                }
                else
                {
                    assert.SkipProperty(m => m.ItemXslLink, "ItemXslLink is null or empty, skipping.");
                }

                if (!string.IsNullOrEmpty(typedModel.MainXslLink))
                {
                    // TODO
                }
                else
                {
                    assert.SkipProperty(m => m.MainXslLink, "MainXslLink is null or empty, skipping.");
                }


                // list name/url/id
                if (!string.IsNullOrEmpty(typedModel.ListName))
                {
                    // TODO
                }
                else
                {
                    assert.SkipProperty(m => m.ListName, "ListName is null or empty, skipping.");
                }

                if (!string.IsNullOrEmpty(typedModel.ListUrl))
                {
                    // TODO
                }
                else
                {
                    assert.SkipProperty(m => m.ListUrl, "ListUrl is null or empty, skipping.");
                }

                if (typedModel.ListGuid.HasValue)
                {
                    // TODO
                }
                else
                {
                    assert.SkipProperty(m => m.ListGuid, "ListGuid is null or empty, skipping.");
                }

                if (!string.IsNullOrEmpty(typedModel.WebUrl))
                {
                    // TODO
                }
                else
                {
                    assert.SkipProperty(m => m.WebUrl, "WebUrl is null or empty, skipping.");
                }

                // misc

                if (typedModel.ItemLimit.HasValue)
                {
                    // TODO
                }
                else
                {
                    assert.SkipProperty(m => m.ItemLimit, "ItemLimit is null or empty, skipping.");
                }

                if (typedModel.PlayMediaInBrowser.HasValue)
                {
                    // TODO
                }
                else
                {
                    assert.SkipProperty(m => m.PlayMediaInBrowser, "PlayMediaInBrowser is null or empty, skipping.");
                }

                if (typedModel.ShowUntargetedItems.HasValue)
                {
                    // TODO
                }
                else
                {
                    assert.SkipProperty(m => m.ShowUntargetedItems, "ShowUntargetedItems is null or empty, skipping.");
                }

                if (typedModel.UseCopyUtil.HasValue)
                {
                    // TODO
                }
                else
                {
                    assert.SkipProperty(m => m.UseCopyUtil, "UseCopyUtil is null or empty, skipping.");
                }

                if (typedModel.ServerTemplate.HasValue)
                {
                    // TODO
                }
                else
                {
                    assert.SkipProperty(m => m.ServerTemplate, "ServerTemplate is null or empty, skipping.");
                }
            });
        }
コード例 #10
0
        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            // base validation
            base.DeployModel(modelHost, model);


            // web specific validation
            var host       = modelHost.WithAssertAndCast <WebpartPageModelHost>("modelHost", value => value.RequireNotNull());
            var definition = model.WithAssertAndCast <XsltListViewWebPartDefinition>("model", value => value.RequireNotNull());

            var item = host.PageListItem;

            WebPartExtensions.WithExistingWebPart(item, definition, (spWebPartManager, spObject) =>
            {
                var web         = spWebPartManager.Web;
                var typedObject = spObject as XsltListViewWebPart;

                var assert = ServiceFactory.AssertService
                             .NewAssert(definition, typedObject)
                             .ShouldNotBeNull(typedObject);

                var targetList = web.Lists[typedObject.ListId];

                var hasList = !string.IsNullOrEmpty(definition.ListTitle) ||
                              !string.IsNullOrEmpty(definition.ListUrl) ||
                              definition.ListId.HasValue;
                var hasView = !string.IsNullOrEmpty(definition.ViewName) ||
                              definition.ViewId.HasValue;;

                if (definition.CacheXslStorage.HasValue)
                {
                    assert.ShouldBeEqual(m => m.CacheXslStorage, o => o.CacheXslStorage);
                }
                else
                {
                    assert.SkipProperty(m => m.CacheXslStorage, "CacheXslStorage is null or empty.");
                }

                if (definition.CacheXslTimeOut.HasValue)
                {
                    assert.ShouldBeEqual(m => m.CacheXslTimeOut, o => o.CacheXslTimeOut);
                }
                else
                {
                    assert.SkipProperty(m => m.CacheXslTimeOut, "CacheXslTimeOut is null or empty.");
                }

                if (definition.ShowTimelineIfAvailable.HasValue)
                {
                    assert.ShouldBeEqual(m => m.ShowTimelineIfAvailable, o => o.ShowTimelineIfAvailable);
                }
                else
                {
                    assert.SkipProperty(m => m.ShowTimelineIfAvailable, "ShowTimelineIfAvailable is null or empty.");
                }

                // list
                if (!string.IsNullOrEmpty(definition.ListTitle))
                {
                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var srcProp = s.GetExpressionValue(m => m.ListTitle);
                        var dstProp = d.GetExpressionValue(o => o.ListId);

                        return(new PropertyValidationResult
                        {
                            Tag = p.Tag,
                            Src = srcProp,
                            Dst = null,
                            IsValid = targetList.ID == (Guid)dstProp.Value
                        });
                    });
                }
                else
                {
                    assert.SkipProperty(m => m.ListTitle, "ListTitle is null or empty. Skipping.");
                }

                if (!string.IsNullOrEmpty(definition.ListUrl))
                {
                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var srcProp = s.GetExpressionValue(m => m.ListUrl);
                        var dstProp = d.GetExpressionValue(o => o.ListId);

                        return(new PropertyValidationResult
                        {
                            Tag = p.Tag,
                            Src = srcProp,
                            Dst = null,
                            IsValid = targetList.ID == (Guid)dstProp.Value
                        });
                    });
                }
                else
                {
                    assert.SkipProperty(m => m.ListUrl, "ListUrl is null or empty. Skipping.");
                }

                if (definition.ListId.HasValue && definition.ListId != default(Guid))
                {
                    assert.ShouldBeEqual(m => m.ListId, o => o.ListId);
                }
                else
                {
                    assert.SkipProperty(m => m.ListId, "ListId is null or empty. Skipping.");
                }

                // view
                if (definition.ViewId.HasValue)
                {
                    // web part gonna have hidden view
                    // so validation is a bit tricky, done by other properties

                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var srcView = targetList.Views[s.ViewId.Value];
                        var dstView = typedObject.View;

                        var srcProp = s.GetExpressionValue(m => m.ViewId);
                        var dstProp = d.GetExpressionValue(o => o.View);

                        var isValid = srcView.ViewFields.Count == dstView.ViewFields.Count &&
                                      srcView.Query == dstView.Query;

                        return(new PropertyValidationResult
                        {
                            Tag = p.Tag,
                            Src = srcProp,
                            Dst = null,
                            IsValid = isValid
                        });
                    });
                }
                else
                {
                    assert.SkipProperty(m => m.ViewId, "ViewId is null or empty. Skipping.");
                }

                if (!string.IsNullOrEmpty(definition.ViewName))
                {
                    // web part gonna have hidden view
                    // so validation is a bit tricky, done by other properties

                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var srcView = targetList.Views[s.ViewName];
                        var dstView = typedObject.View;

                        var srcProp = s.GetExpressionValue(m => m.ViewName);
                        var dstProp = d.GetExpressionValue(o => o.View);

                        var isValid = srcView.ViewFields.Count == dstView.ViewFields.Count &&
                                      srcView.Query == dstView.Query;

                        return(new PropertyValidationResult
                        {
                            Tag = p.Tag,
                            Src = srcProp,
                            Dst = null,
                            IsValid = isValid
                        });
                    });
                }
                else
                {
                    assert.SkipProperty(m => m.ViewName, "ViewName is null or empty. Skipping.");
                }

                // JSLink
                assert.ShouldBeEqual(m => m.JSLink, o => o.JSLink);

                if (definition.InplaceSearchEnabled.HasValue)
                {
                    assert.ShouldBeEqual(m => m.InplaceSearchEnabled, o => o.InplaceSearchEnabled);
                }
                else
                {
                    assert.SkipProperty(m => m.InplaceSearchEnabled, "InplaceSearchEnabled is null or empty.");
                }

                if (definition.DisableSaveAsNewViewButton.HasValue)
                {
                    assert.ShouldBeEqual(m => m.DisableSaveAsNewViewButton, o => o.DisableSaveAsNewViewButton);
                }
                else
                {
                    assert.SkipProperty(m => m.DisableSaveAsNewViewButton, "DisableSaveAsNewViewButton is null or empty.");
                }

                if (definition.DisableColumnFiltering.HasValue)
                {
                    assert.ShouldBeEqual(m => m.DisableColumnFiltering, o => o.DisableColumnFiltering);
                }
                else
                {
                    assert.SkipProperty(m => m.DisableColumnFiltering, "DisableColumnFiltering is null or empty.");
                }

                if (definition.DisableViewSelectorMenu.HasValue)
                {
                    assert.ShouldBeEqual(m => m.DisableViewSelectorMenu, o => o.DisableViewSelectorMenu);
                }
                else
                {
                    assert.SkipProperty(m => m.DisableViewSelectorMenu, "DisableViewSelectorMenu is null or empty.");
                }

                // title link
                if (string.IsNullOrEmpty(definition.TitleUrl))
                {
                    // list?
                    if (hasView)
                    {
                        assert.ShouldBeEqual((p, s, d) =>
                        {
                            var srcProp = s.GetExpressionValue(m => m.TitleUrl);
                            var srcView = string.IsNullOrEmpty(s.ViewName) ?
                                          targetList.Views[s.ViewId.Value] :
                                          targetList.Views[s.ViewName];

                            return(new PropertyValidationResult
                            {
                                Tag = p.Tag,
                                Src = srcProp,
                                Dst = null,
                                IsValid = srcView.ServerRelativeUrl.StartsWith(typedObject.TitleUrl)
                            });
                        });
                    }
                    else if (hasList)
                    {
                        assert.ShouldBeEqual((p, s, d) =>
                        {
                            var srcProp = s.GetExpressionValue(m => m.TitleUrl);

                            return(new PropertyValidationResult
                            {
                                Tag = p.Tag,
                                Src = srcProp,
                                Dst = null,
                                IsValid = targetList.DefaultViewUrl.StartsWith(typedObject.TitleUrl)
                            });
                        });
                    }
                }
                else
                {
                    assert.ShouldBeEqual(m => m.TitleUrl, o => o.TitleUrl);
                }

                if (!string.IsNullOrEmpty(definition.XslLink))
                {
                    assert.ShouldBeEqual(m => m.XslLink, o => o.XslLink);
                }
                else
                {
                    assert.SkipProperty(m => m.XslLink);
                }

                if (!string.IsNullOrEmpty(definition.XmlDefinitionLink))
                {
                    assert.ShouldBeEqual(m => m.XmlDefinitionLink, o => o.XmlDefinitionLink);
                }
                else
                {
                    assert.SkipProperty(m => m.XmlDefinitionLink);
                }

                if (!string.IsNullOrEmpty(definition.GhostedXslLink))
                {
                    assert.ShouldBeEqual(m => m.GhostedXslLink, o => o.GhostedXslLink);
                }
                else
                {
                    assert.SkipProperty(m => m.GhostedXslLink);
                }

                if (!string.IsNullOrEmpty(definition.BaseXsltHashKey))
                {
                    assert.ShouldBeEqual(m => m.BaseXsltHashKey, o => o.BaseXsltHashKey);
                }
                else
                {
                    assert.SkipProperty(m => m.BaseXsltHashKey);
                }


                if (!string.IsNullOrEmpty(definition.XmlDefinition))
                {
                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var srcProp = s.GetExpressionValue(m => m.XmlDefinition);

                        return(new PropertyValidationResult
                        {
                            Tag = p.Tag,
                            Src = srcProp,
                            Dst = null,
                            IsValid = d.XmlDefinition.Contains("BaseViewID=\"2\"")
                        });
                    });
                }
                else
                {
                    assert.SkipProperty(m => m.XmlDefinition);
                }

                if (!string.IsNullOrEmpty(definition.Xsl))
                {
                    assert.ShouldBeEqual(m => m.Xsl, o => o.Xsl);
                }
                else
                {
                    assert.SkipProperty(m => m.Xsl);
                }
            });
        }
コード例 #11
0
        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            var host       = modelHost.WithAssertAndCast <WebpartPageModelHost>("modelHost", value => value.RequireNotNull());
            var definition = model.WithAssertAndCast <WebPartDefinition>("model", value => value.RequireNotNull());

            var file = host.HostFile;
            var web  = host.HostFile.Web;

            WebPartExtensions.WithExistingWebPart(file, definition, (spWebPartManager, spObject) =>
            {
                //[FALSE] - [Title]
                //                        [FALSE] - [Id]
                //                        [FALSE] - [ZoneId]
                //                        [FALSE] - [ZoneIndex]
                //                        [FALSE] - [WebpartFileName]
                //                        [FALSE] - [WebpartType]
                //                        [FALSE] - [WebpartXmlTemplate]

                var assert = ServiceFactory.AssertService
                             .NewAssert(definition, spObject)
                             .ShouldNotBeNull(spObject);

                var currentType      = spObject.GetType().AssemblyQualifiedName;
                var currentClassName = currentType.Split(',').First().Trim();

                var expectedTypeAttr = (definition.GetType().GetCustomAttributes(typeof(ExpectWebpartType))
                                        .FirstOrDefault() as ExpectWebpartType);

                // NULL for the generic web part
                // should not be tested here
                if (expectedTypeAttr != null)
                {
                    var expectedType = expectedTypeAttr.WebPartType;

                    var expectedClassName = expectedType.Split(',').First().Trim();

                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var isValid = true;

                        isValid = currentClassName.ToUpper() == expectedClassName.ToUpper();

                        return(new PropertyValidationResult
                        {
                            Tag = p.Tag,
                            Src = null,
                            Dst = null,
                            IsValid = isValid
                        });
                    });
                }
                // props

                if (definition.Properties.Count > 0)
                {
                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var isValid = true;

                        foreach (var prop in definition.Properties)
                        {
                            // returns correct one depending on the V2/V3
                            var value = ReflectionUtils.GetPropertyValue(d, prop.Name);

                            // that True / true issue give a pain
                            // toLower for the time being
                            isValid = value.ToString().ToLower() == prop.Value.ToLower();

                            if (!isValid)
                            {
                                break;
                            }
                        }

                        var srcProp = s.GetExpressionValue(m => m.Properties);

                        return(new PropertyValidationResult
                        {
                            Tag = p.Tag,
                            Src = srcProp,
                            Dst = null,
                            IsValid = isValid
                        });
                    });
                }
                else
                {
                    assert.SkipProperty(m => m.Properties, "Properties are empty. Skipping.");
                }

                if (!string.IsNullOrEmpty(definition.ChromeState))
                {
                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var srcProp  = s.GetExpressionValue(m => m.ChromeState);
                        var srcValue = (PartChromeState)Enum.Parse(typeof(PartChromeState), s.ChromeState);
                        var isValid  = srcValue == d.ChromeState;

                        return(new PropertyValidationResult
                        {
                            Tag = p.Tag,
                            Src = srcProp,
                            Dst = null,
                            IsValid = isValid
                        });
                    });
                }
                else
                {
                    assert.SkipProperty(m => m.ChromeState, "ChromeType is null or empty. Skipping.");
                }

                if (!string.IsNullOrEmpty(definition.ChromeType))
                {
                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var srcProp    = s.GetExpressionValue(m => m.ChromeType);
                        var chromeType = WebPartChromeTypesConvertService.NormilizeValueToPartChromeTypes(s.ChromeType);

                        var srcValue = (PartChromeType)Enum.Parse(typeof(PartChromeType), chromeType);
                        var isValid  = srcValue == d.ChromeType;

                        return(new PropertyValidationResult
                        {
                            Tag = p.Tag,
                            Src = srcProp,
                            Dst = null,
                            IsValid = isValid
                        });
                    });
                }
                else
                {
                    assert.SkipProperty(m => m.ChromeType, "ChromeType is null or empty. Skipping.");
                }

                if (!string.IsNullOrEmpty(definition.Description))
                {
                    assert.ShouldBeEqual(m => m.Description, o => o.Description);
                }
                else
                {
                    assert.SkipProperty(m => m.Description, "Description is null or empty. Skipping.");
                }

                if (definition.Height.HasValue)
                {
                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var srcProp = s.GetExpressionValue(m => m.Height);
                        var isValid = d.Height == new Unit(s.Height.Value);

                        return(new PropertyValidationResult
                        {
                            Tag = p.Tag,
                            Src = srcProp,
                            Dst = null,
                            IsValid = isValid
                        });
                    });
                }
                else
                {
                    assert.SkipProperty(m => m.Height, "Height is null or empty. Skipping.");
                }

                if (definition.Width.HasValue)
                {
                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var srcProp = s.GetExpressionValue(m => m.Width);
                        var isValid = d.Width == new Unit(s.Width.Value);

                        return(new PropertyValidationResult
                        {
                            Tag = p.Tag,
                            Src = srcProp,
                            Dst = null,
                            IsValid = isValid
                        });
                    });
                }
                else
                {
                    assert.SkipProperty(m => m.Width, "Width is null or empty. Skipping.");
                }

                if (!string.IsNullOrEmpty(definition.ImportErrorMessage))
                {
                    assert.ShouldBeEqual(m => m.ImportErrorMessage, o => o.ImportErrorMessage);
                }
                else
                {
                    assert.SkipProperty(m => m.ImportErrorMessage, "ImportErrorMessage is null or empty. Skipping.");
                }

                if (!DisableTitleUrlValidation)
                {
                    if (!string.IsNullOrEmpty(definition.TitleUrl))
                    {
                        assert.ShouldBeEqual((p, s, d) =>
                        {
                            var srcProp = s.GetExpressionValue(m => m.TitleUrl);
                            var dstProp = d.GetExpressionValue(o => o.TitleUrl);

                            var srcUrl = srcProp.Value as string;
                            var dstUrl = dstProp.Value as string;

                            var isValid = false;

                            if (definition.TitleUrl.Contains("~sitecollection"))
                            {
                                var siteCollectionUrl = web.Site.ServerRelativeUrl == "/" ? string.Empty : web.Site.ServerRelativeUrl;

                                isValid = srcUrl.Replace("~sitecollection", siteCollectionUrl) == dstUrl;
                            }
                            else if (definition.TitleUrl.Contains("~site"))
                            {
                                var siteCollectionUrl = web.ServerRelativeUrl == "/" ? string.Empty : web.ServerRelativeUrl;

                                isValid = srcUrl.Replace("~site", siteCollectionUrl) == dstUrl;
                            }
                            else
                            {
                                isValid = srcUrl == dstUrl;
                            }

                            return(new PropertyValidationResult
                            {
                                Tag = p.Tag,
                                Src = srcProp,
                                Dst = dstProp,
                                IsValid = isValid
                            });
                        });
                    }
                    else
                    {
                        assert.SkipProperty(m => m.TitleUrl, "TitleUrl is null or empty. Skipping.");
                    }
                }

                if (!string.IsNullOrEmpty(definition.TitleIconImageUrl))
                {
                    assert.ShouldBeEndOf(m => m.TitleIconImageUrl, o => o.TitleIconImageUrl);
                }
                else
                {
                    assert.SkipProperty(m => m.TitleIconImageUrl, "TitleIconImageUrl is null or empty. Skipping.");
                }

                if (!string.IsNullOrEmpty(definition.ExportMode))
                {
                    assert.ShouldBeEqual(m => m.ExportMode, o => o.GetExportMode());
                }
                else
                {
                    assert.SkipProperty(m => m.ExportMode, "ExportMode is null or empty. Skipping.");
                }


                if (!string.IsNullOrEmpty(definition.Id))
                {
                    assert.ShouldBeEqual(m => m.Id, o => o.ID);
                }
                else
                {
                    assert.SkipProperty(m => m.Id, "Id is null or empty. Skipping.");
                }

                if (!string.IsNullOrEmpty(definition.Title))
                {
                    assert.ShouldBeEqual(m => m.Title, o => o.Title);
                }
                else
                {
                    assert.SkipProperty(m => m.Title, "Title is null or empty. Skipping.");
                }

                if (!string.IsNullOrEmpty(definition.ZoneId))
                {
                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var srcProp = s.GetExpressionValue(m => m.ZoneId);
                        //var dstProp = d.GetExpressionValue(ct => ct.GetId());

                        return(new PropertyValidationResult
                        {
                            Tag = p.Tag,
                            Src = srcProp,
                            Dst = null,
                            IsValid = object.Equals(s.ZoneId, spWebPartManager.GetZoneID(d))
                        });
                    });
                }

                else
                {
                    assert.SkipProperty(m => m.ZoneId, "ZoneId is null or empty. Skipping.");
                }

                //if (definition.ZoneIndex > 0)
                //    assert.ShouldBeEqual(m => m.ZoneIndex, o => o.ZoneIndex);
                //else
                //    assert.SkipProperty(m => m.ZoneIndex, "ZoneIndex == 0. Skipping.");

                assert.SkipProperty(m => m.ZoneIndex, "Skipping.");

                if (!string.IsNullOrEmpty(definition.WebpartFileName))
                {
                    var site = host.HostFile.Web.Site;

                    var webPartManager = host.SPLimitedWebPartManager;

                    var webpartFileName = definition.WebpartFileName;
                    var rootWeb         = site.RootWeb;

                    // load definition from WP catalog
                    var webpartCatalog = rootWeb.GetCatalog(SPListTemplateType.WebPartCatalog);
                    var webpartItem    = webpartCatalog.Items.OfType <SPListItem>().FirstOrDefault(
                        i => string.Compare(i.Name, webpartFileName, true) == 0);

                    if (webpartItem == null)
                    {
                        throw new ArgumentException(string.Format("webpartItem. Can't find web part file with name: {0}", webpartFileName));
                    }

                    using (var streamReader = new MemoryStream(webpartItem.File.OpenBinary()))
                    {
                        using (var xmlReader = XmlReader.Create(streamReader))
                        {
                            var errMessage          = string.Empty;
                            var webpartInstance     = webPartManager.ImportWebPart(xmlReader, out errMessage);
                            var webPartInstanceType = webpartInstance.GetType();

                            assert.ShouldBeEqual((p, s, d) =>
                            {
                                var srcProp = s.GetExpressionValue(m => m.WebpartFileName);
                                //var dstProp = d.GetExpressionValue(ct => ct.GetId());

                                return(new PropertyValidationResult
                                {
                                    Tag = p.Tag,
                                    Src = srcProp,
                                    Dst = null,
                                    IsValid = webPartInstanceType == d.GetType()
                                });
                            });
                        }
                    }
                }
                else
                {
                    assert.SkipProperty(m => m.WebpartFileName, "ZoneIndex == 0. Skipping.");
                }

                if (!string.IsNullOrEmpty(definition.WebpartType))
                {
                    var webPartInstance     = WebPartExtensions.ResolveWebPartInstance(host.HostFile.Web.Site, host.SPLimitedWebPartManager, definition);
                    var webPartInstanceType = webPartInstance.GetType();

                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var srcProp = s.GetExpressionValue(m => m.WebpartType);
                        //var dstProp = d.GetExpressionValue(ct => ct.GetId());

                        return(new PropertyValidationResult
                        {
                            Tag = p.Tag,
                            Src = srcProp,
                            Dst = null,
                            IsValid = webPartInstanceType == d.GetType()
                        });
                    });
                }
                else
                {
                    assert.SkipProperty(m => m.WebpartType, "WebpartType is empty. Skipping.");
                }

                if (!string.IsNullOrEmpty(definition.WebpartXmlTemplate))
                {
                    assert.SkipProperty(m => m.WebpartXmlTemplate, "WebpartXmlTemplate is not empty, but no validation is required with SSOM. Skipping.");
                }
                else
                {
                    assert.SkipProperty(m => m.WebpartXmlTemplate, "WebpartXmlTemplate is empty. Skipping.");
                }

                if (definition.ParameterBindings.Count == 0)
                {
                    assert.SkipProperty(m => m.ParameterBindings, "ParameterBindings is null or empty. Skipping.");
                }
                else
                {
                    // TODO
                }
            });
        }
コード例 #12
0
        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            // base validation
            base.DeployModel(modelHost, model);

            // content editor specific validation

            var host       = modelHost.WithAssertAndCast <WebpartPageModelHost>("modelHost", value => value.RequireNotNull());
            var definition = model.WithAssertAndCast <ContentBySearchWebPartDefinition>("model", value => value.RequireNotNull());

            var item = host.PageListItem;

            WebPartExtensions.WithExistingWebPart(item, definition, (spWebPartManager, spObject) =>
            {
                var typedWebPart = spObject as ContentBySearchWebPart;

                var assert = ServiceFactory.AssertService
                             .NewAssert(definition, typedWebPart)
                             .ShouldNotBeNull(typedWebPart);

                if (!string.IsNullOrEmpty(definition.PropertyMappings))
                {
                    throw new NotImplementedException();
                }
                else
                {
                    assert.SkipProperty(m => m.PropertyMappings, "PropertyMappings is null or empty, skipping.");
                }

                if (definition.OverwriteResultPath.HasValue)
                {
                    throw new NotImplementedException();
                }
                else
                {
                    assert.SkipProperty(m => m.OverwriteResultPath, "OverwriteResultPath is null or empty, skipping.");
                }

                if (definition.ShouldHideControlWhenEmpty.HasValue)
                {
                    throw new NotImplementedException();
                }
                else
                {
                    assert.SkipProperty(m => m.ShouldHideControlWhenEmpty, "ShouldHideControlWhenEmpty is null or empty, skipping.");
                }

                if (definition.LogAnalyticsViewEvent.HasValue)
                {
                    throw new NotImplementedException();
                }
                else
                {
                    assert.SkipProperty(m => m.LogAnalyticsViewEvent, "LogAnalyticsViewEvent is null or empty, skipping.");
                }

                if (definition.AddSEOPropertiesFromSearch.HasValue)
                {
                    throw new NotImplementedException();
                }
                else
                {
                    assert.SkipProperty(m => m.AddSEOPropertiesFromSearch, "AddSEOPropertiesFromSearch is null or empty, skipping.");
                }

                if (definition.StartingItemIndex.HasValue)
                {
                    throw new NotImplementedException();
                }
                else
                {
                    assert.SkipProperty(m => m.StartingItemIndex, "StartingItemIndex is null or empty, skipping.");
                }

                //

                if (!string.IsNullOrEmpty(definition.GroupTemplateId))
                {
                    throw new NotImplementedException();
                }
                else
                {
                    assert.SkipProperty(m => m.GroupTemplateId, "GroupTemplateId is null or empty, skipping.");
                }

                if (!string.IsNullOrEmpty(definition.ItemTemplateId))
                {
                    throw new NotImplementedException();
                }
                else
                {
                    assert.SkipProperty(m => m.ItemTemplateId, "ItemTemplateId is null or empty, skipping.");
                }

                if (!string.IsNullOrEmpty(definition.RenderTemplateId))
                {
                    throw new NotImplementedException();
                }
                else
                {
                    assert.SkipProperty(m => m.RenderTemplateId, "RenderTemplateId is null or empty, skipping.");
                }

                if (!string.IsNullOrEmpty(definition.DataProviderJSON))
                {
                    throw new NotImplementedException();
                }
                else
                {
                    assert.SkipProperty(m => m.DataProviderJSON, "DataProviderJSON is null or empty, skipping.");
                }

                if (definition.NumberOfItems.HasValue)
                {
                    throw new NotImplementedException();
                }
                else
                {
                    assert.SkipProperty(m => m.NumberOfItems, "NumberOfItems is null or empty, skipping.");
                }

                if (definition.ResultsPerPage.HasValue)
                {
                    throw new NotImplementedException();
                }
                else
                {
                    assert.SkipProperty(m => m.ResultsPerPage, "ResultsPerPage is null or empty, skipping.");
                }
            });
        }
コード例 #13
0
        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            // base validation
            base.DeployModel(modelHost, model);


            // web specific validation
            var host       = modelHost.WithAssertAndCast <WebpartPageModelHost>("modelHost", value => value.RequireNotNull());
            var definition = model.WithAssertAndCast <ListViewWebPartDefinition>("model", value => value.RequireNotNull());

            WebPartExtensions.WithExistingWebPart(host.HostFile, definition, (spWebPartManager, spObject) =>
            {
                var web         = spWebPartManager.Web;
                var typedObject = spObject as ListViewWebPart;

                var assert = ServiceFactory.AssertService
                             .NewAssert(definition, typedObject)
                             .ShouldNotBeNull(typedObject);

                var typedDefinition = definition;
                var targetWeb       = web;

                // web url
                if (!string.IsNullOrEmpty(typedDefinition.WebUrl))
                {
                    var lookupFieldModelHandler = new LookupFieldModelHandler();
                    targetWeb = lookupFieldModelHandler.GetTargetWeb(web.Site,
                                                                     definition.WebUrl, definition.WebId);

                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var srcProp = s.GetExpressionValue(m => m.WebUrl);

                        var isValid = d.WebId == targetWeb.ID;

                        return(new PropertyValidationResult
                        {
                            Tag = p.Tag,
                            Src = srcProp,
                            Dst = null,
                            IsValid = isValid
                        });
                    });
                }
                else
                {
                    assert.SkipProperty(m => m.WebUrl, "WebUrl is NULL. Skipping.");
                }

                if (typedDefinition.WebId.HasGuidValue())
                {
                    var lookupFieldModelHandler = new LookupFieldModelHandler();
                    targetWeb = lookupFieldModelHandler.GetTargetWeb(web.Site,
                                                                     definition.WebUrl, definition.WebId);

                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var srcProp = s.GetExpressionValue(m => m.WebId);

                        var isValid = d.WebId == targetWeb.ID;

                        return(new PropertyValidationResult
                        {
                            Tag = p.Tag,
                            Src = srcProp,
                            Dst = null,
                            IsValid = isValid
                        });
                    });
                }
                else
                {
                    assert.SkipProperty(m => m.WebId, "WebId is NULL. Skipping.");
                }


                var targetList = web.Lists[typedObject.ListId];

                var hasList = !string.IsNullOrEmpty(definition.ListTitle) ||
                              !string.IsNullOrEmpty(definition.ListUrl) ||
                              definition.ListId.HasValue;
                var hasView = !string.IsNullOrEmpty(definition.ViewName) ||
                              definition.ViewId.HasValue;;

                // list
                if (!string.IsNullOrEmpty(definition.ListTitle))
                {
                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var srcProp = s.GetExpressionValue(m => m.ListTitle);
                        var dstProp = d.GetExpressionValue(o => o.ListId);

                        return(new PropertyValidationResult
                        {
                            Tag = p.Tag,
                            Src = srcProp,
                            Dst = null,
                            IsValid = targetList.ID == (Guid)dstProp.Value
                        });
                    });
                }
                else
                {
                    assert.SkipProperty(m => m.ListTitle, "ListTitle is null or empty. Skipping.");
                }

                if (!string.IsNullOrEmpty(definition.ListUrl))
                {
                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var srcProp = s.GetExpressionValue(m => m.ListUrl);
                        var dstProp = d.GetExpressionValue(o => o.ListId);

                        return(new PropertyValidationResult
                        {
                            Tag = p.Tag,
                            Src = srcProp,
                            Dst = null,
                            IsValid = targetList.ID == (Guid)dstProp.Value
                        });
                    });
                }
                else
                {
                    assert.SkipProperty(m => m.ListUrl, "ListUrl is null or empty. Skipping.");
                }

                if (definition.ListId.HasValue && definition.ListId != default(Guid))
                {
                    assert.ShouldBeEqual(m => m.ListId, o => o.ListId);
                }
                else
                {
                    assert.SkipProperty(m => m.ListId, "ListId is null or empty. Skipping.");
                }

                // view
                if (definition.ViewId.HasValue)
                {
                    // web part gonna have hidden view
                    // so validation is a bit tricky, done by other properties

                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var srcView = targetList.Views[s.ViewId.Value];
                        var dstView = targetList.Views[new Guid(typedObject.ViewGuid)];

                        var srcProp = s.GetExpressionValue(m => m.ViewId);
                        var dstProp = d.GetExpressionValue(o => o.ViewGuid);

                        var isValid = srcView.ViewFields.Count == dstView.ViewFields.Count &&
                                      srcView.Query == dstView.Query;

                        return(new PropertyValidationResult
                        {
                            Tag = p.Tag,
                            Src = srcProp,
                            Dst = null,
                            IsValid = isValid
                        });
                    });
                }
                else
                {
                    assert.SkipProperty(m => m.ViewId, "ViewId is null or empty. Skipping.");
                }

                if (!string.IsNullOrEmpty(definition.ViewName))
                {
                    // web part gonna have hidden view
                    // so validation is a bit tricky, done by other properties

                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var srcView = targetList.Views[s.ViewName];
                        var dstView = targetList.Views[new Guid(typedObject.ViewGuid)];

                        var srcProp = s.GetExpressionValue(m => m.ViewName);
                        var dstProp = d.GetExpressionValue(o => o.ViewGuid);

                        var isValid = srcView.ViewFields.Count == dstView.ViewFields.Count &&
                                      srcView.Query == dstView.Query;

                        return(new PropertyValidationResult
                        {
                            Tag = p.Tag,
                            Src = srcProp,
                            Dst = null,
                            IsValid = isValid
                        });
                    });
                }
                else
                {
                    assert.SkipProperty(m => m.ViewName, "ViewName is null or empty. Skipping.");
                }

                //  title link
                if (string.IsNullOrEmpty(definition.TitleUrl))
                {
                    // list?
                    if (hasView)
                    {
                        assert.ShouldBeEqual((p, s, d) =>
                        {
                            var srcProp = s.GetExpressionValue(m => m.TitleUrl);
                            var srcView = string.IsNullOrEmpty(s.ViewName) ?
                                          targetList.Views[s.ViewId.Value] :
                                          targetList.Views[s.ViewName];

                            return(new PropertyValidationResult
                            {
                                Tag = p.Tag,
                                Src = srcProp,
                                Dst = null,
                                IsValid = srcView.ServerRelativeUrl.StartsWith(typedObject.TitleUrl)
                            });
                        });
                    }
                    else if (hasList)
                    {
                        assert.ShouldBeEqual((p, s, d) =>
                        {
                            var srcProp = s.GetExpressionValue(m => m.TitleUrl);

                            return(new PropertyValidationResult
                            {
                                Tag = p.Tag,
                                Src = srcProp,
                                Dst = null,
                                IsValid = targetList.DefaultViewUrl.StartsWith(typedObject.TitleUrl)
                            });
                        });
                    }
                }
                else
                {
                    assert.ShouldBeEqual(m => m.TitleUrl, o => o.TitleUrl);
                }


                // skip it, it will be part of the .Toolbar validation
                assert.SkipProperty(m => m.ToolbarShowAlways, "");

                if (!string.IsNullOrEmpty(definition.Toolbar))
                {
                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var list = XsltListViewWebPartModelHandler.GetTargetList(targetWeb,
                                                                                 typedDefinition.ListTitle,
                                                                                 typedDefinition.ListUrl,
                                                                                 typedDefinition.ListId);

                        var targetView    = list.Views[Guid.Parse((spObject as ListViewWebPart).ViewGuid)];
                        var htmlSchemaXml = XDocument.Parse(targetView.HtmlSchemaXml);

                        var useShowAlwaysValue =
                            (typedDefinition.Toolbar.ToUpper() == BuiltInToolbarType.Standard.ToUpper()) &&
                            typedDefinition.ToolbarShowAlways.HasValue &&
                            typedDefinition.ToolbarShowAlways.Value;

                        var toolbarNode = htmlSchemaXml.Root
                                          .Descendants("Toolbar")
                                          .FirstOrDefault();

                        // NONE? the node might not be there
                        if ((typedDefinition.Toolbar.ToUpper() == BuiltInToolbarType.None.ToUpper()) &&
                            (toolbarNode == null))
                        {
                            var srcProp = s.GetExpressionValue(m => m.Toolbar);

                            return(new PropertyValidationResult
                            {
                                Tag = p.Tag,
                                Src = srcProp,
                                Dst = null,
                                IsValid = true
                            });
                        }
                        else
                        {
                            var toolBarValue = toolbarNode.GetAttributeValue("Type");

                            var srcProp = s.GetExpressionValue(m => m.Toolbar);
                            var isValid = toolBarValue.ToUpper() == definition.Toolbar.ToUpper();

                            if (useShowAlwaysValue)
                            {
                                var showAlwaysValue = toolbarNode.GetAttributeValue("ShowAlways");
                                isValid             = isValid && (showAlwaysValue.ToUpper() == "TRUE");
                            }

                            return(new PropertyValidationResult
                            {
                                Tag = p.Tag,
                                Src = srcProp,
                                Dst = null,
                                IsValid = isValid
                            });
                        }
                    });
                }
                else
                {
                    assert.SkipProperty(m => m.Toolbar);
                }
            });
        }
コード例 #14
0
        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            // base validation
            base.DeployModel(modelHost, model);

            // web specific validation
            var host       = modelHost.WithAssertAndCast <WebpartPageModelHost>("modelHost", value => value.RequireNotNull());
            var definition = model.WithAssertAndCast <ContentEditorWebPartDefinition>("model", value => value.RequireNotNull());

            var item = host.PageListItem;

            WebPartExtensions.WithExistingWebPart(item, definition, (spWebPartManager, spObject) =>
            {
                var web         = spWebPartManager.Web;
                var typedObject = spObject as ContentEditorWebPart;

                var assert = ServiceFactory.AssertService
                             .NewAssert(definition, typedObject)
                             .ShouldNotBeNull(typedObject);

                if (!string.IsNullOrEmpty(definition.ContentLink))
                {
                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var srcProp = s.GetExpressionValue(m => m.ContentLink);
                        var dstProp = d.GetExpressionValue(o => o.ContentLink);

                        var srcUrl = srcProp.Value as string;
                        var dstUrl = dstProp.Value as string;

                        var isValid = false;

                        if (definition.ContentLink.Contains("~sitecollection"))
                        {
                            var siteCollectionUrl = web.Site.ServerRelativeUrl == "/" ? string.Empty : web.Site.ServerRelativeUrl;

                            isValid = srcUrl.Replace("~sitecollection", siteCollectionUrl) == dstUrl;
                        }
                        else if (definition.ContentLink.Contains("~site"))
                        {
                            var siteCollectionUrl = web.ServerRelativeUrl == "/" ? string.Empty : web.ServerRelativeUrl;

                            isValid = srcUrl.Replace("~site", siteCollectionUrl) == dstUrl;
                        }
                        else
                        {
                            isValid = srcUrl == dstUrl;
                        }

                        return(new PropertyValidationResult
                        {
                            Tag = p.Tag,
                            Src = srcProp,
                            Dst = dstProp,
                            IsValid = isValid
                        });
                    });
                }
                else
                {
                    assert.SkipProperty(m => m.ContentLink, "ContentLink is null or empty. Skipping.");
                }

                if (!string.IsNullOrEmpty(definition.Content))
                {
                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var srcProp = s.GetExpressionValue(m => m.Content);
                        var dstProp = d.GetExpressionValue(o => o.Content);

                        var srcUrl = srcProp.Value as string;
                        var dstUrl = dstProp.Value as XmlElement;

                        var isValid = dstUrl.InnerText == srcUrl;

                        return(new PropertyValidationResult
                        {
                            Tag = p.Tag,
                            Src = srcProp,
                            Dst = dstProp,
                            IsValid = isValid
                        });
                    });
                }
                else
                {
                    assert.SkipProperty(m => m.Content, "Content is null or empty. Skipping.");
                }
            });

            // content editor specific validation
        }
コード例 #15
0
        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            // base validation
            base.DeployModel(modelHost, model);

            // content editor specific validation

            var host            = modelHost.WithAssertAndCast <WebpartPageModelHost>("modelHost", value => value.RequireNotNull());
            var typedDefinition = model.WithAssertAndCast <ContentByQueryWebPartDefinition>("model", value => value.RequireNotNull());

            CurrentHost = host;

            //var item = host.PageListItem;

            WebPartExtensions.WithExistingWebPart(host.HostFile, typedDefinition, (spWebPartManager, spObject) =>
            {
                var typedWebPart = spObject as ContentByQueryWebPart;

                var assert = ServiceFactory.AssertService
                             .NewAssert(typedDefinition, typedWebPart)
                             .ShouldNotBeNull(typedWebPart);

                if (!string.IsNullOrEmpty(typedDefinition.ContentTypeBeginsWithId))
                {
                    assert.ShouldBeEqual(m => m.ContentTypeBeginsWithId, o => o.ContentTypeBeginsWithId);
                }
                else
                {
                    assert.SkipProperty(m => m.ContentTypeBeginsWithId, "ContentTypeBeginsWithId is null or empty, skipping.");
                }

                if (!string.IsNullOrEmpty(typedDefinition.DataMappings))
                {
                    assert.ShouldBeEqual(m => m.DataMappings, o => o.DataMappings);
                }
                else
                {
                    assert.SkipProperty(m => m.DataMappings, "DataMappings is null or empty, skipping.");
                }

                if (!string.IsNullOrEmpty(typedDefinition.DataMappingViewFields))
                {
                    assert.ShouldBeEqual(m => m.DataMappingViewFields, o => o.DataMappingViewFields);
                }
                else
                {
                    assert.SkipProperty(m => m.DataMappingViewFields, "DataMappingViewFields is null or empty, skipping.");
                }

                // filter display value 1-2-3
                if (!string.IsNullOrEmpty(typedDefinition.FilterDisplayValue1))
                {
                    assert.ShouldBeEqual(m => m.FilterDisplayValue1, o => o.FilterDisplayValue1);
                }
                else
                {
                    assert.SkipProperty(m => m.FilterDisplayValue1, "FilterDisplayValue1 is null or empty, skipping.");
                }

                if (!string.IsNullOrEmpty(typedDefinition.FilterDisplayValue2))
                {
                    assert.ShouldBeEqual(m => m.FilterDisplayValue2, o => o.FilterDisplayValue2);
                }
                else
                {
                    assert.SkipProperty(m => m.FilterDisplayValue2, "FilterDisplayValue2 is null or empty, skipping.");
                }

                if (!string.IsNullOrEmpty(typedDefinition.FilterDisplayValue3))
                {
                    assert.ShouldBeEqual(m => m.FilterDisplayValue3, o => o.FilterDisplayValue3);
                }
                else
                {
                    assert.SkipProperty(m => m.FilterDisplayValue3, "FilterDisplayValue3 is null or empty, skipping.");
                }

                // operators 1-2-3
                if (!string.IsNullOrEmpty(typedDefinition.FilterOperator1))
                {
                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var srcProp = s.GetExpressionValue(m => m.FilterOperator1);
                        var isValid = false;

                        isValid = s.FilterOperator1.ToLower() == d.FilterOperator1.ToString().ToLower();

                        return(new PropertyValidationResult
                        {
                            Tag = p.Tag,
                            Src = srcProp,
                            Dst = null,
                            IsValid = isValid
                        });
                    });
                }
                else
                {
                    assert.SkipProperty(m => m.FilterOperator1, "FilterOperator1 is null or empty, skipping.");
                }

                if (!string.IsNullOrEmpty(typedDefinition.FilterOperator2))
                {
                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var srcProp = s.GetExpressionValue(m => m.FilterOperator2);
                        var isValid = false;

                        isValid = s.FilterOperator2.ToLower() == d.FilterOperator2.ToString().ToLower();

                        return(new PropertyValidationResult
                        {
                            Tag = p.Tag,
                            Src = srcProp,
                            Dst = null,
                            IsValid = isValid
                        });
                    });
                }
                else
                {
                    assert.SkipProperty(m => m.FilterOperator2, "FilterOperator2 is null or empty, skipping.");
                }

                if (!string.IsNullOrEmpty(typedDefinition.FilterOperator3))
                {
                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var srcProp = s.GetExpressionValue(m => m.FilterOperator3);
                        var isValid = false;

                        isValid = s.FilterOperator3.ToLower() == d.FilterOperator3.ToString().ToLower();

                        return(new PropertyValidationResult
                        {
                            Tag = p.Tag,
                            Src = srcProp,
                            Dst = null,
                            IsValid = isValid
                        });
                    });
                }
                else
                {
                    assert.SkipProperty(m => m.FilterOperator3, "FilterOperator3 is null or empty, skipping.");
                }

                // type 1-2-3
                if (!string.IsNullOrEmpty(typedDefinition.FilterType1))
                {
                    assert.ShouldBeEqual(m => m.FilterType1, o => o.FilterType1);
                }
                else
                {
                    assert.SkipProperty(m => m.FilterType1, "FilterType1 is null or empty, skipping.");
                }

                if (!string.IsNullOrEmpty(typedDefinition.FilterType2))
                {
                    assert.ShouldBeEqual(m => m.FilterType2, o => o.FilterType2);
                }
                else
                {
                    assert.SkipProperty(m => m.FilterType2, "FilterType2 is null or empty, skipping.");
                }

                if (!string.IsNullOrEmpty(typedDefinition.FilterType3))
                {
                    assert.ShouldBeEqual(m => m.FilterType3, o => o.FilterType3);
                }
                else
                {
                    assert.SkipProperty(m => m.FilterType3, "FilterType3 is null or empty, skipping.");
                }

                // filter values 1-2-3
                if (!string.IsNullOrEmpty(typedDefinition.FilterValue1))
                {
                    assert.ShouldBeEqual(m => m.FilterValue1, o => o.FilterValue1);
                }
                else
                {
                    assert.SkipProperty(m => m.FilterValue1, "FilterValue1 is null or empty, skipping.");
                }

                if (!string.IsNullOrEmpty(typedDefinition.FilterValue2))
                {
                    assert.ShouldBeEqual(m => m.FilterValue2, o => o.FilterValue2);
                }
                else
                {
                    assert.SkipProperty(m => m.FilterValue2, "FilterValue2 is null or empty, skipping.");
                }

                if (!string.IsNullOrEmpty(typedDefinition.FilterValue3))
                {
                    assert.ShouldBeEqual(m => m.FilterValue3, o => o.FilterValue3);
                }
                else
                {
                    assert.SkipProperty(m => m.FilterValue3, "FilterValue3 is null or empty, skipping.");
                }

                // sorting

                if (!string.IsNullOrEmpty(typedDefinition.SortBy))
                {
                    assert.ShouldBeEqual(m => m.SortBy, o => o.SortBy);
                }
                else
                {
                    assert.SkipProperty(m => m.SortBy, "SortBy is null or empty, skipping.");
                }

                if (!string.IsNullOrEmpty(typedDefinition.SortByFieldType))
                {
                    assert.ShouldBeEqual(m => m.SortByFieldType, o => o.SortByFieldType);
                }
                else
                {
                    assert.SkipProperty(m => m.SortByFieldType, "SortByFieldType is null or empty, skipping.");
                }

                if (!string.IsNullOrEmpty(typedDefinition.SortByDirection))
                {
                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var srcProp = s.GetExpressionValue(m => m.SortByDirection);
                        var isValid = false;

                        isValid = s.SortByDirection.ToLower() == d.SortByDirection.ToString().ToLower();

                        return(new PropertyValidationResult
                        {
                            Tag = p.Tag,
                            Src = srcProp,
                            Dst = null,
                            IsValid = isValid
                        });
                    });
                }
                else
                {
                    assert.SkipProperty(m => m.SortByDirection, "SortByDirection is null or empty, skipping.");
                }

                // xslt
                if (!string.IsNullOrEmpty(typedDefinition.GroupStyle))
                {
                    assert.ShouldBeEqual(m => m.GroupStyle, o => o.GroupStyle);
                }
                else
                {
                    assert.SkipProperty(m => m.GroupStyle, "GroupStyle is null or empty, skipping.");
                }

                if (!string.IsNullOrEmpty(typedDefinition.ItemStyle))
                {
                    assert.ShouldBeEqual(m => m.ItemStyle, o => o.ItemStyle);
                }
                else
                {
                    assert.SkipProperty(m => m.ItemStyle, "ItemStyle is null or empty, skipping.");
                }

                if (!string.IsNullOrEmpty(typedDefinition.ItemXslLink))
                {
                    // TODO
                }
                else
                {
                    assert.SkipProperty(m => m.ItemXslLink, "ItemXslLink is null or empty, skipping.");
                }

                if (!string.IsNullOrEmpty(typedDefinition.MainXslLink))
                {
                    // TODO
                }
                else
                {
                    assert.SkipProperty(m => m.MainXslLink, "MainXslLink is null or empty, skipping.");
                }


                // list name/url/id
                if (!string.IsNullOrEmpty(typedDefinition.ListName))
                {
                    // TODO
                }
                else
                {
                    assert.SkipProperty(m => m.ListName, "ListName is null or empty, skipping.");
                }

                if (!string.IsNullOrEmpty(typedDefinition.ListUrl))
                {
                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var srcProp = s.GetExpressionValue(m => m.ListUrl);
                        var isValid = false;

                        // resolve web / url by list URL
                        // check ListId

                        var webLookup = new LookupFieldModelHandler();

                        using (var targetWeb = webLookup.GetTargetWeb(CurrentHost.HostFile.Web.Site,
                                                                      typedDefinition.WebUrl,
                                                                      typedDefinition.WebId))
                        {
                            var listUrl = SPUrlUtility.CombineUrl(targetWeb.ServerRelativeUrl, typedDefinition.ListUrl);
                            var list    = targetWeb.GetList(listUrl);

                            isValid = typedWebPart.ListGuid == list.ID.ToString("D");
                        }

                        return(new PropertyValidationResult
                        {
                            Tag = p.Tag,
                            Src = srcProp,
                            Dst = null,
                            IsValid = isValid
                        });
                    });
                }
                else
                {
                    assert.SkipProperty(m => m.ListUrl, "ListUrl is null or empty, skipping.");
                }

                if (typedDefinition.ListGuid.HasValue)
                {
                    // TODO
                }
                else
                {
                    assert.SkipProperty(m => m.ListGuid, "ListGuid is null or empty, skipping.");
                }

                if (!string.IsNullOrEmpty(typedDefinition.WebUrl))
                {
                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var srcProp = s.GetExpressionValue(m => m.WebUrl);
                        var isValid = false;

                        isValid = s.WebUrl == d.WebUrl;

                        return(new PropertyValidationResult
                        {
                            Tag = p.Tag,
                            Src = srcProp,
                            Dst = null,
                            IsValid = isValid
                        });
                    });
                }
                else
                {
                    assert.SkipProperty(m => m.WebUrl, "WebUrl is null or empty, skipping.");
                }

                if (typedDefinition.WebId.HasValue)
                {
                    // TODO
                }
                else
                {
                    assert.SkipProperty(m => m.WebId, "WebId is null or empty, skipping.");
                }

                // misc

                if (typedDefinition.ItemLimit.HasValue)
                {
                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var srcProp = s.GetExpressionValue(m => m.ItemLimit);
                        var isValid = false;

                        isValid = s.ItemLimit == d.ItemLimit;

                        return(new PropertyValidationResult
                        {
                            Tag = p.Tag,
                            Src = srcProp,
                            Dst = null,
                            IsValid = isValid
                        });
                    });
                }
                else
                {
                    assert.SkipProperty(m => m.ItemLimit, "ItemLimit is null or empty, skipping.");
                }

                if (typedDefinition.PlayMediaInBrowser.HasValue)
                {
                    assert.ShouldBeEqual(m => m.PlayMediaInBrowser, o => o.PlayMediaInBrowser);
                }
                else
                {
                    assert.SkipProperty(m => m.PlayMediaInBrowser, "PlayMediaInBrowser is null or empty, skipping.");
                }

                if (typedDefinition.ShowUntargetedItems.HasValue)
                {
                    assert.ShouldBeEqual(m => m.ShowUntargetedItems, o => o.ShowUntargetedItems);
                }
                else
                {
                    assert.SkipProperty(m => m.ShowUntargetedItems, "ShowUntargetedItems is null or empty, skipping.");
                }

                if (typedDefinition.UseCopyUtil.HasValue)
                {
                    assert.ShouldBeEqual(m => m.UseCopyUtil, o => o.UseCopyUtil);
                }
                else
                {
                    assert.SkipProperty(m => m.UseCopyUtil, "UseCopyUtil is null or empty, skipping.");
                }

                if (typedDefinition.ServerTemplate.HasValue)
                {
                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var srcProp = s.GetExpressionValue(m => m.ServerTemplate);
                        var isValid = false;

                        isValid = s.ServerTemplate == ConvertUtils.ToInt(d.ServerTemplate);

                        return(new PropertyValidationResult
                        {
                            Tag = p.Tag,
                            Src = srcProp,
                            Dst = null,
                            IsValid = isValid
                        });
                    });
                }
                else
                {
                    assert.SkipProperty(m => m.ServerTemplate, "ServerTemplate is null or empty, skipping.");
                }

                if (!string.IsNullOrEmpty(typedDefinition.GroupBy))
                {
                    assert.ShouldBeEqual(m => m.GroupBy, o => o.GroupBy);
                }
                else
                {
                    assert.SkipProperty(m => m.GroupBy, "GroupBy is null or empty, skipping.");
                }

                if (typedDefinition.DisplayColumns.HasValue)
                {
                    assert.ShouldBeEqual(m => m.DisplayColumns, o => o.DisplayColumns);
                }
                else
                {
                    assert.SkipProperty(m => m.DisplayColumns, "DisplayColumns is null or empty, skipping.");
                }
            });
        }
コード例 #16
0
        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            // base validation
            base.DeployModel(modelHost, model);

            // content editor specific validation

            var host       = modelHost.WithAssertAndCast <WebpartPageModelHost>("modelHost", value => value.RequireNotNull());
            var typedModel = model.WithAssertAndCast <AdvancedSearchBoxDefinition>("model", value => value.RequireNotNull());

            //var item = host.PageListItem;

            WebPartExtensions.WithExistingWebPart(host.HostFile, typedModel, (spWebPartManager, spObject) =>
            {
                var typedWebPart = spObject as AdvancedSearchBox;

                var assert = ServiceFactory.AssertService
                             .NewAssert(typedModel, typedWebPart)
                             .ShouldNotBeNull(typedWebPart);


                if (!string.IsNullOrEmpty(typedModel.AndQueryTextBoxLabelText))
                {
                    assert.ShouldBeEqual(m => m.AndQueryTextBoxLabelText, o => o.AndQueryTextBoxLabelText);
                }
                else
                {
                    assert.SkipProperty(m => m.AndQueryTextBoxLabelText);
                }

                if (!string.IsNullOrEmpty(typedModel.DisplayGroup))
                {
                    assert.ShouldBeEqual(m => m.DisplayGroup, o => o.DisplayGroup);
                }
                else
                {
                    assert.SkipProperty(m => m.DisplayGroup);
                }

                if (!string.IsNullOrEmpty(typedModel.LanguagesLabelText))
                {
                    assert.ShouldBeEqual(m => m.LanguagesLabelText, o => o.LanguagesLabelText);
                }
                else
                {
                    assert.SkipProperty(m => m.LanguagesLabelText);
                }

                if (!string.IsNullOrEmpty(typedModel.NotQueryTextBoxLabelText))
                {
                    assert.ShouldBeEqual(m => m.NotQueryTextBoxLabelText, o => o.NotQueryTextBoxLabelText);
                }
                else
                {
                    assert.SkipProperty(m => m.NotQueryTextBoxLabelText);
                }

                if (!string.IsNullOrEmpty(typedModel.OrQueryTextBoxLabelText))
                {
                    assert.ShouldBeEqual(m => m.OrQueryTextBoxLabelText, o => o.OrQueryTextBoxLabelText);
                }
                else
                {
                    assert.SkipProperty(m => m.OrQueryTextBoxLabelText);
                }

                if (!string.IsNullOrEmpty(typedModel.PhraseQueryTextBoxLabelText))
                {
                    assert.ShouldBeEqual(m => m.PhraseQueryTextBoxLabelText, o => o.PhraseQueryTextBoxLabelText);
                }
                else
                {
                    assert.SkipProperty(m => m.PhraseQueryTextBoxLabelText);
                }

                if (!string.IsNullOrEmpty(typedModel.AdvancedSearchBoxProperties))
                {
                    assert.ShouldBeEqual(m => m.AdvancedSearchBoxProperties, o => o.Properties);
                }
                else
                {
                    assert.SkipProperty(m => m.AdvancedSearchBoxProperties);
                }

                if (!string.IsNullOrEmpty(typedModel.PropertiesSectionLabelText))
                {
                    assert.ShouldBeEqual(m => m.PropertiesSectionLabelText, o => o.PropertiesSectionLabelText);
                }
                else
                {
                    assert.SkipProperty(m => m.PropertiesSectionLabelText);
                }

                if (!string.IsNullOrEmpty(typedModel.ResultTypeLabelText))
                {
                    assert.ShouldBeEqual(m => m.ResultTypeLabelText, o => o.ResultTypeLabelText);
                }
                else
                {
                    assert.SkipProperty(m => m.ResultTypeLabelText);
                }

                if (!string.IsNullOrEmpty(typedModel.ScopeLabelText))
                {
                    assert.ShouldBeEqual(m => m.ScopeLabelText, o => o.ScopeLabelText);
                }
                else
                {
                    assert.SkipProperty(m => m.ScopeLabelText);
                }

                if (!string.IsNullOrEmpty(typedModel.ScopeSectionLabelText))
                {
                    assert.ShouldBeEqual(m => m.ScopeSectionLabelText, o => o.ScopeSectionLabelText);
                }
                else
                {
                    assert.SkipProperty(m => m.ScopeSectionLabelText);
                }

                if (!string.IsNullOrEmpty(typedModel.SearchResultPageURL))
                {
                    assert.ShouldBeEqual(m => m.SearchResultPageURL, o => o.SearchResultPageURL);
                }
                else
                {
                    assert.SkipProperty(m => m.SearchResultPageURL);
                }

                if (typedModel.ShowAndQueryTextBox.HasValue)
                {
                    assert.ShouldBeEqual(m => m.ShowAndQueryTextBox, o => o.ShowAndQueryTextBox);
                }
                else
                {
                    assert.SkipProperty(m => m.ShowAndQueryTextBox);
                }

                if (typedModel.ShowLanguageOptions.HasValue)
                {
                    assert.ShouldBeEqual(m => m.ShowLanguageOptions, o => o.ShowLanguageOptions);
                }
                else
                {
                    assert.SkipProperty(m => m.ShowLanguageOptions);
                }

                if (typedModel.ShowNotQueryTextBox.HasValue)
                {
                    assert.ShouldBeEqual(m => m.ShowNotQueryTextBox, o => o.ShowNotQueryTextBox);
                }
                else
                {
                    assert.SkipProperty(m => m.ShowNotQueryTextBox);
                }

                if (typedModel.ShowOrQueryTextBox.HasValue)
                {
                    assert.ShouldBeEqual(m => m.ShowOrQueryTextBox, o => o.ShowOrQueryTextBox);
                }
                else
                {
                    assert.SkipProperty(m => m.ShowOrQueryTextBox);
                }

                if (typedModel.ShowPhraseQueryTextBox.HasValue)
                {
                    assert.ShouldBeEqual(m => m.ShowPhraseQueryTextBox, o => o.ShowPhraseQueryTextBox);
                }
                else
                {
                    assert.SkipProperty(m => m.ShowPhraseQueryTextBox);
                }

                if (typedModel.ShowPropertiesSection.HasValue)
                {
                    assert.ShouldBeEqual(m => m.ShowPropertiesSection, o => o.ShowPropertiesSection);
                }
                else
                {
                    assert.SkipProperty(m => m.ShowPropertiesSection);
                }

                if (typedModel.ShowResultTypePicker.HasValue)
                {
                    assert.ShouldBeEqual(m => m.ShowResultTypePicker, o => o.ShowResultTypePicker);
                }
                else
                {
                    assert.SkipProperty(m => m.ShowResultTypePicker);
                }

                if (typedModel.ShowScopes.HasValue)
                {
                    assert.ShouldBeEqual(m => m.ShowScopes, o => o.ShowScopes);
                }
                else
                {
                    assert.SkipProperty(m => m.ShowScopes);
                }

                if (!string.IsNullOrEmpty(typedModel.TextQuerySectionLabelText))
                {
                    assert.ShouldBeEqual(m => m.TextQuerySectionLabelText, o => o.TextQuerySectionLabelText);
                }
                else
                {
                    assert.SkipProperty(m => m.TextQuerySectionLabelText);
                }
            });
        }