private void MapProperties(SPList targetList, SPView currentView, ListViewDefinition listViewModel) { // if any fields specified, overwrite if (listViewModel.Fields.Any()) { currentView.ViewFields.DeleteAll(); foreach (var viewField in listViewModel.Fields) { currentView.ViewFields.Add(viewField); } } if (!string.IsNullOrEmpty(listViewModel.ViewData)) { currentView.ViewData = listViewModel.ViewData; } if (!string.IsNullOrEmpty(listViewModel.Scope)) { var scopeValue = ListViewScopeTypesConvertService.NormilizeValueToSSOMType(listViewModel.Scope); currentView.Scope = (SPViewScope)Enum.Parse( typeof(SPViewScope), scopeValue); } // There is no value in setting Aggregations if AggregationsStatus is not to "On" if (!string.IsNullOrEmpty(listViewModel.AggregationsStatus) && listViewModel.AggregationsStatus == "On") { currentView.AggregationsStatus = listViewModel.AggregationsStatus; if (!string.IsNullOrEmpty(listViewModel.Aggregations)) { currentView.Aggregations = listViewModel.Aggregations; } } currentView.Hidden = listViewModel.Hidden; if (listViewModel.InlineEdit.HasValue) { currentView.InlineEdit = listViewModel.InlineEdit.Value.ToString(CultureInfo.InvariantCulture); } currentView.Title = listViewModel.Title; currentView.RowLimit = (uint)listViewModel.RowLimit; currentView.DefaultView = listViewModel.IsDefault; currentView.Paged = listViewModel.IsPaged; if (listViewModel.IncludeRootFolder.HasValue) { currentView.IncludeRootFolder = listViewModel.IncludeRootFolder.Value; } #if !NET35 if (!string.IsNullOrEmpty(listViewModel.JSLink)) { currentView.JSLink = listViewModel.JSLink; } #endif if (!string.IsNullOrEmpty(listViewModel.Query)) { currentView.Query = listViewModel.Query; } if (listViewModel.DefaultViewForContentType.HasValue) { currentView.DefaultViewForContentType = listViewModel.DefaultViewForContentType.Value; } if (!string.IsNullOrEmpty(listViewModel.ContentTypeName)) { currentView.ContentTypeId = LookupListContentTypeByName(targetList, listViewModel.ContentTypeName); } if (!string.IsNullOrEmpty(listViewModel.ContentTypeId)) { currentView.ContentTypeId = LookupListContentTypeById(targetList, listViewModel.ContentTypeId); } if (listViewModel.ViewStyleId.HasValue) { var viewStyle = targetList.ParentWeb.ViewStyles.StyleByID(listViewModel.ViewStyleId.Value); currentView.ApplyStyle(viewStyle); } if (listViewModel.TabularView.HasValue) { currentView.TabularView = listViewModel.TabularView.Value; } }
public override void DeployModel(object modelHost, DefinitionBase model) { var listModelHost = modelHost.WithAssertAndCast <ListModelHost>("modelHost", value => value.RequireNotNull()); var definition = model.WithAssertAndCast <ListViewDefinition>("model", value => value.RequireNotNull()); var list = listModelHost.HostList; var context = list.Context; context.Load(list, l => l.Fields); context.Load(list, l => l.Views.Include( v => v.ViewFields, v => v.Title, v => v.DefaultView, v => v.ViewQuery, v => v.RowLimit, v => v.Paged, v => v.Scope, v => v.Hidden, v => v.JSLink, v => v.ServerRelativeUrl, v => v.DefaultViewForContentType, v => v.ContentTypeId, v => v.AggregationsStatus, v => v.Aggregations, v => v.ViewType, v => v.IncludeRootFolder, v => v.HtmlSchemaXml, v => v.ViewData)); context.ExecuteQueryWithTrace(); var spObject = FindViewByTitle(list.Views, definition.Title); var assert = ServiceFactory.AssertService .NewAssert(definition, spObject); assert .ShouldNotBeNull(spObject) .ShouldBeEqual(m => m.Title, o => o.Title) .ShouldBeEqual(m => m.IsDefault, o => o.DefaultView) .ShouldBeEqual(m => m.Hidden, o => o.Hidden) .ShouldBeEqual(m => m.RowLimit, o => (int)o.RowLimit) .ShouldBeEqual(m => m.IsPaged, o => o.Paged); if (!string.IsNullOrEmpty(definition.Scope)) { assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(def => def.Scope); var dstProp = d.GetExpressionValue(o => o.Scope); var scopeValue = ListViewScopeTypesConvertService.NormilizeValueToCSOMType(definition.Scope); var isValid = scopeValue == d.Scope.ToString(); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = dstProp, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.Scope); } if (!string.IsNullOrEmpty(definition.ViewData)) { assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(def => def.ViewData); var dstProp = d.GetExpressionValue(o => o.ViewData); var srcViewDate = assert.Src.ViewData.Replace(System.Environment.NewLine, string.Empty).Replace(" /", "/"); var dstViewDate = assert.Dst.ViewData.Replace(System.Environment.NewLine, string.Empty).Replace(" /", "/"); // replacing all new lines srcViewDate = Regex.Replace(srcViewDate, @"\r\n?|\n", string.Empty); dstViewDate = Regex.Replace(dstViewDate, @"\r\n?|\n", string.Empty); var isValid = srcViewDate.ToUpper() == dstViewDate.ToUpper(); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = dstProp, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.ViewData); } if (definition.Types.Count() == 0) { assert.SkipProperty(m => m.Types, "Types.Count == 0"); if (!string.IsNullOrEmpty(definition.Type)) { assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(def => def.Type); var dstProp = d.GetExpressionValue(o => o.ViewType); var isValid = srcProp.Value.ToString().ToUpper() == dstProp.Value.ToString().ToUpper(); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = dstProp, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.Type); } } else { assert.SkipProperty(m => m.Type, "Types.Count != 0"); assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(def => def.Types); //var dstProp = d.GetExpressionValue(o => o.Type); var isValid = false; ViewType?srcType = null; foreach (var type in s.Types) { var tmpViewType = (ViewType)Enum.Parse(typeof(ViewType), type); if (srcType == null) { srcType = tmpViewType; } else { srcType = srcType | tmpViewType; } } var srcTypeValue = (int)srcType; var dstTypeValue = (int)0; // checking if only reccurence set // test designed that way only if (((int)srcTypeValue & (int)(ViewType.Recurrence)) == (int)ViewType.Recurrence) { // nah, whatever, it works and does the job isValid = d.HtmlSchemaXml.Contains("RecurrenceRowset=\"TRUE\""); } return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = isValid }); }); } assert.SkipProperty(m => m.ViewStyleId, "ViewStyleId unsupported by SP CSOM API yet. Skipping."); assert.SkipProperty(m => m.TabularView, "TabularView unsupported by SP CSOM API yet. Skipping."); assert.SkipProperty(m => m.InlineEdit, "InlineEdit unsupported by SP CSOM API yet. Skipping."); assert.ShouldBeEqualIfNotNullOrEmpty(m => m.JSLink, o => o.JSLink); if (definition.IncludeRootFolder.HasValue) { assert.ShouldBeEqual(m => m.IncludeRootFolder, o => o.IncludeRootFolder); } else { assert.SkipProperty(m => m.IncludeRootFolder, "IncludeRootFolder is null or empty. Skipping."); } if (!string.IsNullOrEmpty(definition.Query)) { assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(def => def.Query); var dstProp = d.GetExpressionValue(o => o.ViewQuery); var srcViewDate = assert.Src.Query.Replace(System.Environment.NewLine, string.Empty).Replace(" /", "/"); var dstViewDate = assert.Dst.ViewQuery.Replace(System.Environment.NewLine, string.Empty).Replace(" /", "/"); // replacing all new lines srcViewDate = Regex.Replace(srcViewDate, @"\r\n?|\n", string.Empty); dstViewDate = Regex.Replace(dstViewDate, @"\r\n?|\n", string.Empty); var isValid = srcViewDate.ToUpper() == dstViewDate.ToUpper(); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = dstProp, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.Query, "Query is null or empty. Skipping."); } assert.ShouldBeEqualIfHasValue(m => m.DefaultViewForContentType, o => o.DefaultViewForContentType); if (string.IsNullOrEmpty(definition.ContentTypeName)) { assert.SkipProperty(m => m.ContentTypeName, "ContentTypeName is null or empty. Skipping."); } else { var contentTypeId = LookupListContentTypeByName(list, definition.ContentTypeName); assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(def => def.ContentTypeName); var dstProp = d.GetExpressionValue(ct => ct.ContentTypeId); var isValis = contentTypeId.StringValue == d.ContentTypeId.StringValue; return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = dstProp, IsValid = isValis }); }); } if (string.IsNullOrEmpty(definition.ContentTypeId)) { assert.SkipProperty(m => m.ContentTypeId, "ContentTypeId is null or empty. Skipping."); } else { var contentTypeId = LookupListContentTypeById(list, definition.ContentTypeId); assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(def => def.ContentTypeId); var dstProp = d.GetExpressionValue(ct => ct.ContentTypeId); var isValis = contentTypeId.StringValue == d.ContentTypeId.StringValue; return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = dstProp, IsValid = isValis }); }); } if (string.IsNullOrEmpty(definition.AggregationsStatus)) { assert.SkipProperty(m => m.AggregationsStatus, "Aggregationsstatus is null or empty. Skipping."); } else { assert.ShouldBeEqual(m => m.AggregationsStatus, o => o.AggregationsStatus); } if (string.IsNullOrEmpty(definition.Aggregations)) { assert.SkipProperty(m => m.Aggregations, "Aggregations is null or empty. Skipping."); } else { assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(def => def.Aggregations); var dstProp = d.GetExpressionValue(ct => ct.Aggregations); var isValid = s.Aggregations .Replace("'", string.Empty) .Replace(" ", string.Empty) .Replace("\"", string.Empty) == d.Aggregations .Replace("'", string.Empty) .Replace(" ", string.Empty) .Replace("\"", string.Empty); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = dstProp, IsValid = isValid }); }); } assert.ShouldBePartOfIfNotNullOrEmpty(m => m.Url, o => o.ServerRelativeUrl); assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(def => def.Fields); var dstProp = d.GetExpressionValue(ct => ct.ViewFields); var hasAllFields = true; foreach (var srcField in s.Fields) { var listField = list.Fields.ToList().FirstOrDefault(f => f.StaticName == srcField); // if list-scoped field we need to check by internal name // internal name is changed for list scoped-fields // that's why to check by BOTH, definition AND real internal name if (!d.ViewFields.ToList().Contains(srcField) && !d.ViewFields.ToList().Contains(listField.InternalName)) { hasAllFields = false; } } return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = dstProp, IsValid = hasAllFields }); }); var supportsLocalization = ReflectionUtils.HasProperties(spObject, new[] { "TitleResource" }); if (supportsLocalization) { if (definition.TitleResource.Any()) { assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(def => def.TitleResource); var isValid = true; foreach (var userResource in s.TitleResource) { var culture = LocalizationService.GetUserResourceCultureInfo(userResource); var resourceObject = ReflectionUtils.GetPropertyValue(spObject, "TitleResource"); var value = ReflectionUtils.GetMethod(resourceObject, "GetValueForUICulture") .Invoke(resourceObject, new[] { culture.Name }) as ClientResult <string>; context.ExecuteQuery(); isValid = userResource.Value == value.Value; if (!isValid) { break; } } return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.TitleResource, "TitleResource is NULL or empty. Skipping."); } } else { TraceService.Critical((int)LogEventId.ModelProvisionCoreCall, "CSOM runtime doesn't have Web.TitleResource and Web.DescriptionResource() methods support. Skipping validation."); assert.SkipProperty(m => m.TitleResource, "TitleResource is null or empty. Skipping."); } }
private void MapProperties(SPList targetList, SPView currentView, ListViewDefinition listViewModel) { // if any fields specified, overwrite if (listViewModel.Fields.Any()) { currentView.ViewFields.DeleteAll(); foreach (var viewField in listViewModel.Fields) { currentView.ViewFields.Add(viewField); } } if (!string.IsNullOrEmpty(listViewModel.ViewData)) { currentView.ViewData = listViewModel.ViewData; } if (!string.IsNullOrEmpty(listViewModel.Scope)) { var scopeValue = ListViewScopeTypesConvertService.NormilizeValueToSSOMType(listViewModel.Scope); currentView.Scope = (SPViewScope)Enum.Parse( typeof(SPViewScope), scopeValue); } currentView.Hidden = listViewModel.Hidden; currentView.Title = listViewModel.Title; currentView.RowLimit = (uint)listViewModel.RowLimit; currentView.DefaultView = listViewModel.IsDefault; currentView.Paged = listViewModel.IsPaged; #if !NET35 if (!string.IsNullOrEmpty(listViewModel.JSLink)) { currentView.JSLink = listViewModel.JSLink; } #endif if (!string.IsNullOrEmpty(listViewModel.Query)) { currentView.Query = listViewModel.Query; } if (listViewModel.DefaultViewForContentType.HasValue) { currentView.DefaultViewForContentType = listViewModel.DefaultViewForContentType.Value; } if (!string.IsNullOrEmpty(listViewModel.ContentTypeName)) { currentView.ContentTypeId = LookupListContentTypeByName(targetList, listViewModel.ContentTypeName); } if (!string.IsNullOrEmpty(listViewModel.ContentTypeId)) { currentView.ContentTypeId = LookupListContentTypeById(targetList, listViewModel.ContentTypeId); } if (listViewModel.ViewStyleId.HasValue) { var viewStyle = targetList.ParentWeb.ViewStyles.StyleByID(listViewModel.ViewStyleId.Value); currentView.ApplyStyle(viewStyle); } }
public override void DeployModel(object modelHost, DefinitionBase model) { var listModelHost = modelHost.WithAssertAndCast <ListModelHost>("modelHost", value => value.RequireNotNull()); var definition = model.WithAssertAndCast <ListViewDefinition>("model", value => value.RequireNotNull()); var list = listModelHost.HostList; var spObject = list.Views.FindByName(definition.Title); var assert = ServiceFactory.AssertService .NewAssert(definition, spObject) .ShouldBeEqual(m => m.Title, o => o.Title) .ShouldBeEqual(m => m.IsDefault, o => o.IsDefaul()) .ShouldBeEqual(m => m.Hidden, o => o.Hidden) .ShouldBeEqual(m => m.RowLimit, o => (int)o.RowLimit) .ShouldBeEqual(m => m.IsPaged, o => o.Paged); if (definition.InlineEdit.HasValue) { assert.ShouldBeEqual(m => m.InlineEdit.ToString().ToLower(), o => o.InlineEdit.ToLower()); } else { assert.SkipProperty(m => m.InlineEdit); } if (!string.IsNullOrEmpty(definition.Scope)) { assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(def => def.Scope); var dstProp = d.GetExpressionValue(o => o.Scope); var scopeValue = ListViewScopeTypesConvertService.NormilizeValueToSSOMType(definition.Scope); var isValid = scopeValue == d.Scope.ToString(); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = dstProp, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.Scope); } if (!string.IsNullOrEmpty(definition.Query)) { assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(def => def.Query); var dstProp = d.GetExpressionValue(o => o.Query); var srcViewDate = assert.Src.Query.Replace(System.Environment.NewLine, string.Empty).Replace(" /", "/"); var dstViewDate = assert.Dst.Query.Replace(System.Environment.NewLine, string.Empty).Replace(" /", "/"); var isValid = srcViewDate.ToUpper() == dstViewDate.ToUpper(); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = dstProp, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.Query); } if (!string.IsNullOrEmpty(definition.ViewData)) { assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(def => def.ViewData); var dstProp = d.GetExpressionValue(o => o.ViewData); var srcViewDate = assert.Src.ViewData.Replace(System.Environment.NewLine, string.Empty).Replace(" /", "/"); var dstViewDate = assert.Dst.ViewData.Replace(System.Environment.NewLine, string.Empty).Replace(" /", "/"); var isValid = srcViewDate.ToUpper() == dstViewDate.ToUpper(); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = dstProp, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.ViewData); } if (!string.IsNullOrEmpty(definition.Type)) { assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(def => def.Type); var dstProp = d.GetExpressionValue(o => o.Type); var isValid = srcProp.Value.ToString().ToUpper() == dstProp.Value.ToString().ToUpper(); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = dstProp, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.Type); } if (definition.ViewStyleId.HasValue) { assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(def => def.ViewStyleId); var isValid = false; var srcViewId = s.ViewStyleId; var destViewId = 0; var doc = XDocument.Parse(d.SchemaXml); destViewId = ConvertUtils.ToInt(doc.Descendants("ViewStyle") .First() .GetAttributeValue("ID") ).Value; isValid = srcViewId == destViewId; return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.ViewStyleId, "ViewStyleId is null"); } if (!string.IsNullOrEmpty(definition.JSLink)) { assert.ShouldBeEqual(m => m.JSLink, o => o.JSLink); } else { assert.SkipProperty(m => m.JSLink); } if (definition.DefaultViewForContentType.HasValue) { assert.ShouldBeEqual(m => m.DefaultViewForContentType, o => o.DefaultViewForContentType); } else { assert.SkipProperty(m => m.DefaultViewForContentType, "DefaultViewForContentType is null or empty. Skipping."); } if (definition.TabularView.HasValue) { assert.ShouldBeEqual(m => m.TabularView, o => o.TabularView); } else { assert.SkipProperty(m => m.TabularView, "TabularView is null or empty. Skipping."); } if (string.IsNullOrEmpty(definition.ContentTypeName)) { assert.SkipProperty(m => m.ContentTypeName, "ContentTypeName is null or empty. Skipping."); } else { var contentTypeId = LookupListContentTypeByName(list, definition.ContentTypeName); assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(def => def.ContentTypeName); var dstProp = d.GetExpressionValue(ct => ct.ContentTypeId); var isValis = contentTypeId == d.ContentTypeId; return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = dstProp, IsValid = isValis }); }); } if (string.IsNullOrEmpty(definition.ContentTypeId)) { assert.SkipProperty(m => m.ContentTypeId, "ContentTypeId is null or empty. Skipping."); } else { var contentTypeId = LookupListContentTypeById(list, definition.ContentTypeId); assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(def => def.ContentTypeId); var dstProp = d.GetExpressionValue(ct => ct.ContentTypeId); var isValis = contentTypeId == d.ContentTypeId; return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = dstProp, IsValid = isValis }); }); } if (string.IsNullOrEmpty(definition.AggregationsStatus)) { assert.SkipProperty(m => m.AggregationsStatus, "Aggregationsstatus is null or empty. Skipping."); } else { assert.ShouldBeEqual(m => m.AggregationsStatus, o => o.AggregationsStatus); } if (string.IsNullOrEmpty(definition.Aggregations)) { assert.SkipProperty(m => m.Aggregations, "Aggregations is null or empty. Skipping."); } else { assert.ShouldBeEqual(m => m.Aggregations, o => o.Aggregations); } if (string.IsNullOrEmpty(definition.Url)) { assert.SkipProperty(m => m.Url, "Url is null or empty. Skipping."); } else { assert.ShouldBePartOf(m => m.Url, o => o.ServerRelativeUrl); } assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(def => def.Fields); var dstProp = d.GetExpressionValue(ct => ct.ViewFields); var hasAllFields = true; foreach (var srcField in s.Fields) { var listField = d.ParentList.Fields.OfType <SPField>().FirstOrDefault(f => f.StaticName == srcField); // if list-scoped field we need to check by internal name // internal name is changed for list scoped-fields // that's why to check by BOTH, definition AND real internal name if (!d.ViewFields.ToStringCollection().Contains(srcField) && !d.ViewFields.ToStringCollection().Contains(listField.InternalName)) { hasAllFields = false; } } return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = dstProp, IsValid = hasAllFields }); }); /// localization if (definition.TitleResource.Any()) { assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(def => def.TitleResource); var isValid = true; foreach (var userResource in s.TitleResource) { var culture = LocalizationService.GetUserResourceCultureInfo(userResource); var value = d.TitleResource.GetValueForUICulture(culture); isValid = userResource.Value == value; if (!isValid) { break; } } return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.TitleResource, "TitleResource is NULL or empty. Skipping."); } }
public override void DeployModel(object modelHost, DefinitionBase model) { var listModelHost = modelHost.WithAssertAndCast <ListModelHost>("modelHost", value => value.RequireNotNull()); var definition = model.WithAssertAndCast <ListViewDefinition>("model", value => value.RequireNotNull()); var list = listModelHost.HostList; var context = list.Context; context.Load(list, l => l.Fields); context.Load(list, l => l.Views.Include( o => o.ViewFields, o => o.Title, o => o.DefaultView, o => o.ViewQuery, o => o.RowLimit, o => o.Paged, o => o.Scope, o => o.Hidden, o => o.JSLink, o => o.ServerRelativeUrl, o => o.DefaultViewForContentType, o => o.ContentTypeId, o => o.ViewType, o => o.ViewData, v => v.Title)); context.ExecuteQueryWithTrace(); var spObject = FindViewByTitle(list.Views, definition.Title); var assert = ServiceFactory.AssertService .NewAssert(definition, spObject); assert .ShouldNotBeNull(spObject) .ShouldBeEqual(m => m.Title, o => o.Title) .ShouldBeEqual(m => m.IsDefault, o => o.DefaultView) .ShouldBeEqual(m => m.Hidden, o => o.Hidden) .ShouldBeEqual(m => m.RowLimit, o => (int)o.RowLimit) .ShouldBeEqual(m => m.IsPaged, o => o.Paged); if (!string.IsNullOrEmpty(definition.Scope)) { assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(def => def.Scope); var dstProp = d.GetExpressionValue(o => o.Scope); var scopeValue = ListViewScopeTypesConvertService.NormilizeValueToCSOMType(definition.Scope); var isValid = scopeValue == d.Scope.ToString(); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = dstProp, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.Scope); } if (!string.IsNullOrEmpty(definition.ViewData)) { assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(def => def.ViewData); var dstProp = d.GetExpressionValue(o => o.ViewData); var srcViewDate = assert.Src.ViewData.Replace(System.Environment.NewLine, string.Empty).Replace(" /", "/"); var dstViewDate = assert.Dst.ViewData.Replace(System.Environment.NewLine, string.Empty).Replace(" /", "/"); var isValid = srcViewDate.ToUpper() == dstViewDate.ToUpper(); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = dstProp, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.ViewData); } if (!string.IsNullOrEmpty(definition.Type)) { assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(def => def.Type); var dstProp = d.GetExpressionValue(o => o.ViewType); var isValid = srcProp.Value.ToString().ToUpper() == dstProp.Value.ToString().ToUpper(); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = dstProp, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.Type); } assert.SkipProperty(m => m.ViewStyleId, "ViewStyleId unsupported by SP CSOM API yet. Skipping."); assert.ShouldBeEqualIfNotNullOrEmpty(m => m.JSLink, o => o.JSLink); if (!string.IsNullOrEmpty(definition.Query)) { assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(def => def.Query); var dstProp = d.GetExpressionValue(o => o.ViewQuery); var srcViewDate = assert.Src.Query.Replace(System.Environment.NewLine, string.Empty).Replace(" /", "/"); var dstViewDate = assert.Dst.ViewQuery.Replace(System.Environment.NewLine, string.Empty).Replace(" /", "/"); var isValid = srcViewDate.ToUpper() == dstViewDate.ToUpper(); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = dstProp, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.Query, "Query is null or empty. Skipping."); } assert.ShouldBeEqualIfHasValue(m => m.DefaultViewForContentType, o => o.DefaultViewForContentType); if (string.IsNullOrEmpty(definition.ContentTypeName)) { assert.SkipProperty(m => m.ContentTypeName, "ContentTypeName is null or empty. Skipping."); } else { var contentTypeId = LookupListContentTypeByName(list, definition.ContentTypeName); assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(def => def.ContentTypeName); var dstProp = d.GetExpressionValue(ct => ct.ContentTypeId); var isValis = contentTypeId.StringValue == d.ContentTypeId.StringValue; return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = dstProp, IsValid = isValis }); }); } if (string.IsNullOrEmpty(definition.ContentTypeId)) { assert.SkipProperty(m => m.ContentTypeId, "ContentTypeId is null or empty. Skipping."); } else { var contentTypeId = LookupListContentTypeById(list, definition.ContentTypeId); assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(def => def.ContentTypeId); var dstProp = d.GetExpressionValue(ct => ct.ContentTypeId); var isValis = contentTypeId.StringValue == d.ContentTypeId.StringValue; return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = dstProp, IsValid = isValis }); }); } assert.ShouldBePartOfIfNotNullOrEmpty(m => m.Url, o => o.ServerRelativeUrl); assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(def => def.Fields); var dstProp = d.GetExpressionValue(ct => ct.ViewFields); var hasAllFields = true; foreach (var srcField in s.Fields) { var listField = list.Fields.ToList().FirstOrDefault(f => f.StaticName == srcField); // if list-scoped field we need to check by internal name // internal name is changed for list scoped-fields // that's why to check by BOTH, definition AND real internal name if (!d.ViewFields.ToList().Contains(srcField) && !d.ViewFields.ToList().Contains(listField.InternalName)) { hasAllFields = false; } } return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = dstProp, IsValid = hasAllFields }); }); var supportsLocalization = ReflectionUtils.HasProperties(spObject, new[] { "TitleResource" }); if (supportsLocalization) { if (definition.TitleResource.Any()) { assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(def => def.TitleResource); var isValid = true; foreach (var userResource in s.TitleResource) { var culture = LocalizationService.GetUserResourceCultureInfo(userResource); var resourceObject = ReflectionUtils.GetPropertyValue(spObject, "TitleResource"); var value = ReflectionUtils.GetMethod(resourceObject, "GetValueForUICulture") .Invoke(resourceObject, new[] { culture.Name }) as ClientResult <string>; context.ExecuteQuery(); isValid = userResource.Value == value.Value; if (!isValid) { break; } } return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.TitleResource, "TitleResource is NULL or empty. Skipping."); } } else { TraceService.Critical((int)LogEventId.ModelProvisionCoreCall, "CSOM runtime doesn't have Web.TitleResource and Web.DescriptionResource() methods support. Skipping validation."); assert.SkipProperty(m => m.TitleResource, "TitleResource is null or empty. Skipping."); } }