diff --git a/SPMeta2/SPMeta2.CSOM.Standard/Config/MetadataNavigationHierarchyConfig.cs b/SPMeta2/SPMeta2.CSOM.Standard/Config/MetadataNavigationHierarchyConfig.cs index f6b0369eb..973ff5930 100644 --- a/SPMeta2/SPMeta2.CSOM.Standard/Config/MetadataNavigationHierarchyConfig.cs +++ b/SPMeta2/SPMeta2.CSOM.Standard/Config/MetadataNavigationHierarchyConfig.cs @@ -1,18 +1,25 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - - -namespace SPMeta2.CSOM.Standard.Config -{ - public class MetadataNavigationHierarchyConfig - { - public MetadataNavigationHierarchyConfig(Guid fieldId) - { - this.FieldId = fieldId; - } - - public Guid FieldId { get; set; } - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + + +namespace SPMeta2.CSOM.Standard.Config +{ + public class MetadataNavigationHierarchyConfig + { + #region constructors + public MetadataNavigationHierarchyConfig() + { + + } + #endregion + + #region properties + public Guid FieldId { get; set; } + public string FieldType { get; set; } + public string CachedName { get; set; } + public string CachedDisplayName { get; set; } + #endregion + } +} diff --git a/SPMeta2/SPMeta2.CSOM.Standard/Config/MetadataNavigationKeyFilterConfig.cs b/SPMeta2/SPMeta2.CSOM.Standard/Config/MetadataNavigationKeyFilterConfig.cs index 83ec88df1..37d34444a 100644 --- a/SPMeta2/SPMeta2.CSOM.Standard/Config/MetadataNavigationKeyFilterConfig.cs +++ b/SPMeta2/SPMeta2.CSOM.Standard/Config/MetadataNavigationKeyFilterConfig.cs @@ -8,11 +8,18 @@ namespace SPMeta2.CSOM.Standard.Config { public class MetadataNavigationKeyFilterConfig { - public MetadataNavigationKeyFilterConfig(Guid fieldId) - { - this.FieldId = fieldId; - } - - public Guid FieldId { get; set; } + #region constructors + public MetadataNavigationKeyFilterConfig() + { + + } + #endregion + + #region properties + public Guid FieldId { get; set; } + public string FieldType { get; set; } + public string CachedName { get; set; } + public string CachedDisplayName { get; set; } + #endregion } } diff --git a/SPMeta2/SPMeta2.CSOM.Standard/Config/MetadataNavigationSettingsConfig.cs b/SPMeta2/SPMeta2.CSOM.Standard/Config/MetadataNavigationSettingsConfig.cs index e37ce8354..1b8353f8d 100644 --- a/SPMeta2/SPMeta2.CSOM.Standard/Config/MetadataNavigationSettingsConfig.cs +++ b/SPMeta2/SPMeta2.CSOM.Standard/Config/MetadataNavigationSettingsConfig.cs @@ -2,43 +2,212 @@ using System.Collections.Generic; using System.Linq; using System.Text; - +using System.Xml.Linq; using Microsoft.SharePoint.Client; +using SPMeta2.CSOM.Extensions; using SPMeta2.Enumerations; using SPMeta2.Exceptions; +using SPMeta2.Utils; namespace SPMeta2.CSOM.Standard.Config { public class MetadataNavigationSettingsConfig { + #region constructors + + public MetadataNavigationSettingsConfig() + { + SettingDocument = new XDocument(new XElement("MetadataNavigationSettings")); + + SettingDocument.Root.SetAttribute("SchemaVersion", "1"); + SettingDocument.Root.SetAttribute("IsEnabled", "True"); + SettingDocument.Root.SetAttribute("AutoIndex", "True"); + } + + #endregion + + #region properties + + protected XDocument SettingDocument { get; set; } + + + #endregion + + #region static + public static MetadataNavigationSettingsConfig GetMetadataNavigationSettings(List list) { - throw new SPMeta2NotImplementedException("MetadataNavigationSettings provision for CSOM isnot yet implemented by M2 - https://github.com/SubPointSolutions/spmeta2/issues/738"); + var result = new MetadataNavigationSettingsConfig(); + + var context = list.Context; + + context.Load(list, l => l.RootFolder); + context.ExecuteQueryWithTrace(); + +#if NET35 + throw new SPMeta2NotImplementedException("Not implemented for SP2010 and NET35"); +#endif + +#if !NET35 + var props = list.RootFolder.Properties; + + if (props.FieldValues.ContainsKey("client_MOSS_MetadataNavigationSettings")) + { + var value = ConvertUtils.ToString(props["client_MOSS_MetadataNavigationSettings"]); + + if (!string.IsNullOrEmpty(value)) + { + result.SettingDocument = XDocument.Parse(value); + } + } + +#endif + + return result; } - public void AddConfiguredHierarchy(MetadataNavigationHierarchyConfig metadataNavigationHierarchy) + #endregion + + #region methods + + public void AddConfiguredHierarchy(MetadataNavigationHierarchyConfig item) { - throw new SPMeta2NotImplementedException("MetadataNavigationSettings provision for CSOM isnot yet implemented by M2 - https://github.com/SubPointSolutions/spmeta2/issues/738"); + var currentKey = FindConfiguredKeyFilter(item.FieldId); + + if (currentKey == null) + { + var root = SettingDocument.Root; + + var parentNode = root.Descendants("NavigationHierarchies").FirstOrDefault(); + + if (parentNode == null) + { + parentNode = new XElement("NavigationHierarchies"); + root.Add(parentNode); + + var folderHierarchyNode = new XElement("FolderHierarchy"); + + folderHierarchyNode.SetAttribute("HideFoldersNode", "False"); + parentNode.Add(folderHierarchyNode); + } + + var newNode = new XElement("MetadataField"); + + newNode.SetAttributeValue("FieldID", item.FieldId.ToString("D")); + newNode.SetAttributeValue("FieldType", item.FieldType); + + newNode.SetAttributeValue("CachedName", item.CachedName); + newNode.SetAttributeValue("CachedDisplayName", item.CachedDisplayName); + + parentNode.Add(newNode); + } } - public void AddConfiguredKeyFilter(MetadataNavigationKeyFilterConfig metadataNavigationKeyFilterConfig) + public void AddConfiguredKeyFilter(MetadataNavigationKeyFilterConfig item) { - throw new SPMeta2NotImplementedException("MetadataNavigationSettings provision for CSOM isnot yet implemented by M2 - https://github.com/SubPointSolutions/spmeta2/issues/738"); + var currentKey = FindConfiguredKeyFilter(item.FieldId); + + if (currentKey == null) + { + var root = SettingDocument.Root; + + var parentNode = root.Descendants("KeyFilters").FirstOrDefault(); + + if (parentNode == null) + { + parentNode = new XElement("KeyFilters"); + root.Add(parentNode); + } + + var newNode = new XElement("MetadataField"); + + newNode.SetAttributeValue("FieldID", item.FieldId.ToString("D")); + newNode.SetAttributeValue("FieldType", item.FieldType); + + newNode.SetAttributeValue("CachedName", item.CachedName); + newNode.SetAttributeValue("CachedDisplayName", item.CachedDisplayName); + + parentNode.Add(newNode); + } } public static void SetMetadataNavigationSettings(List list, MetadataNavigationSettingsConfig settings) { - throw new SPMeta2NotImplementedException("MetadataNavigationSettings provision for CSOM isnot yet implemented by M2 - https://github.com/SubPointSolutions/spmeta2/issues/738"); + var xmlValue = settings.SettingDocument.Root.ToString(); + + var context = list.Context; + + context.Load(list, l => l.RootFolder); + context.ExecuteQueryWithTrace(); + +#if NET35 + throw new SPMeta2NotImplementedException("Not implemented for SP2010 and NET35"); +#endif + +#if !NET35 + + list.RootFolder.Properties["client_MOSS_MetadataNavigationSettings"] = xmlValue; + list.RootFolder.Update(); + list.Update(); + + context.ExecuteQueryWithTrace(); +#endif } public MetadataNavigationHierarchyConfig FindConfiguredHierarchy(Guid guid) { - throw new SPMeta2NotImplementedException("MetadataNavigationSettings provision for CSOM isnot yet implemented by M2 - https://github.com/SubPointSolutions/spmeta2/issues/738"); + var root = SettingDocument.Root; + var parentNode = root.Descendants("NavigationHierarchies").FirstOrDefault(); + + if (parentNode == null) + return null; + + var nodes = parentNode.Descendants("MetadataField"); + var targetNode = nodes.FirstOrDefault(n => n.GetAttributeValue("FieldID") == guid.ToString("D")); + + if (targetNode != null) + { + var result = new MetadataNavigationHierarchyConfig(); + + result.FieldId = ConvertUtils.ToGuid(targetNode.GetAttributeValue("FieldID")).Value; + + result.FieldType = ConvertUtils.ToString(targetNode.GetAttributeValue("FieldType")); + result.CachedDisplayName = ConvertUtils.ToString(targetNode.GetAttributeValue("CachedDisplayName")); + result.CachedName = ConvertUtils.ToString(targetNode.GetAttributeValue("CachedName")); + + return result; + } + + return null; } public MetadataNavigationKeyFilterConfig FindConfiguredKeyFilter(Guid guid) { - throw new SPMeta2NotImplementedException("MetadataNavigationSettings provision for CSOM isnot yet implemented by M2 - https://github.com/SubPointSolutions/spmeta2/issues/738"); + var root = SettingDocument.Root; + var parentNode = root.Descendants("KeyFilters").FirstOrDefault(); + + if (parentNode == null) + return null; + + var nodes = parentNode.Descendants("MetadataField"); + var targetNode = nodes.FirstOrDefault(n => n.GetAttributeValue("FieldID") == guid.ToString("D")); + + if (targetNode != null) + { + var result = new MetadataNavigationKeyFilterConfig(); + + result.FieldId = ConvertUtils.ToGuid(targetNode.GetAttributeValue("FieldID")).Value; + + result.FieldType = ConvertUtils.ToString(targetNode.GetAttributeValue("FieldType")); + result.CachedDisplayName = ConvertUtils.ToString(targetNode.GetAttributeValue("CachedDisplayName")); + result.CachedName = ConvertUtils.ToString(targetNode.GetAttributeValue("CachedName")); + + return result; + } + + return null; } + + #endregion } } diff --git a/SPMeta2/SPMeta2.CSOM.Standard/ModelHandlers/DesignPackageModelHandler.cs b/SPMeta2/SPMeta2.CSOM.Standard/ModelHandlers/DesignPackageModelHandler.cs index be3bc7c8e..deb4b003a 100644 --- a/SPMeta2/SPMeta2.CSOM.Standard/ModelHandlers/DesignPackageModelHandler.cs +++ b/SPMeta2/SPMeta2.CSOM.Standard/ModelHandlers/DesignPackageModelHandler.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using Microsoft.SharePoint.Client.Publishing; using SPMeta2.Common; @@ -13,10 +14,11 @@ using Microsoft.SharePoint.Client.DocumentSet; using Microsoft.SharePoint.Client; using SPMeta2.Exceptions; +using File = Microsoft.SharePoint.Client.File; namespace SPMeta2.CSOM.Standard.ModelHandlers { - public class DesignPackageModelHandler : CSOMModelHandlerBase + public class DesignPackageModelHandler : SandboxSolutionModelHandler { #region properties @@ -31,40 +33,171 @@ public override Type TargetType public override void DeployModel(object modelHost, DefinitionBase model) { - var siteModelHost = modelHost.WithAssertAndCast("modelHost", value => value.RequireNotNull()); + var siteModelHost = modelHost.WithAssertAndCast("modelHost", value => value.RequireNotNull()); var definition = model.WithAssertAndCast("model", value => value.RequireNotNull()); DeployArtifact(siteModelHost, definition); } - private void DeployArtifact(SiteModelHandler modelHost, DesignPackageDefinition definition) + private void DeployArtifact(SiteModelHost modelHost, DesignPackageDefinition definition) { - // TODO, implementation - // Add DesignPackage provision support #166 - // https://github.com/SubPointSolutions/spmeta2/issues/166 + var site = modelHost.HostSite; + var context = site.Context; - DesignPackageInfo currentArtifact = null; + //var existingSolutionFile = FindExistingSolutionFile(siteModelHost, definition); + var existingSolution = FindExistingSolutionById(modelHost, definition.SolutionId); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioning, - Object = currentArtifact, - ObjectType = typeof(DesignPackageInfo), + Object = existingSolution, + ObjectType = typeof(File), ObjectDefinition = definition, ModelHost = modelHost }); - // TODO + // uninstalling existing one + if (existingSolution != null && definition.Install) + { + TraceService.Information((int)LogEventId.ModelProvisionProcessingExistingObject, + "Processing existing sandbox solution"); + + var fileItem = existingSolution.ListItemAllFields; + context.Load(fileItem); + context.ExecuteQueryWithTrace(); + + var currentFileName = fileItem["FileLeafRef"].ToString(); + + //if (!currentFileName.Contains(definition.FileName)) + // currentFileName = currentFileName.Replace(string.Format("-v{0}.{1}.wsp", 1, 0), string.Empty); + //else + // currentFileName = definition.FileName; + + var packageFileName = Path.GetFileNameWithoutExtension(currentFileName); + var packageFileNameParts = packageFileName.Split('-'); + + var packageName = packageFileNameParts[0]; + + var versionParts = packageFileNameParts[1].Replace("v", string.Empty) + .Split('.'); + + var packageMajorVersion = int.Parse(versionParts[0]); + var packageMinorVersion = int.Parse(versionParts[1]); + + var info = new DesignPackageInfo + { + PackageGuid = definition.SolutionId, + MajorVersion = packageMajorVersion, + MinorVersion = packageMinorVersion, + PackageName = packageName, + + }; + + // cleaning up AppliedDesignGuid at root web to enable 'force' uninstall + var rootWeb = site.RootWeb; + rootWeb.AllProperties["AppliedDesignGuid"] = null; + rootWeb.Update(); + + context.ExecuteQueryWithTrace(); + + // deactivate and remove + TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, + "Deleting existing sandbox solution via DesignPackage.UnInstall()"); + DesignPackage.UnInstall(context, site, info); + + try + { + context.ExecuteQueryWithTrace(); + } + catch (Exception uninstallException) + { + // pass this one + // bug in SharePoint's DesignPackage.UnInstall method + if (!uninstallException.ToString().Contains("33e33eca-7712-4f3d-ab83-6848789fc9b6")) + { + throw; + } + } + } + + // installing new + if (definition.Install) + { + var folder = site.RootWeb.RootFolder; + + context.Load(folder); + context.ExecuteQueryWithTrace(); + + var fileCreatingInfo = new FileCreationInformation + { + Url = definition.FileName, + Overwrite = true + }; + + if (definition.Content.Length < 1024 * 1024 * 1.5) + { + fileCreatingInfo.Content = definition.Content; + } + else + { + fileCreatingInfo.ContentStream = new MemoryStream(definition.Content); + } + + + var newFile = folder.Files.Add(fileCreatingInfo); + + context.Load(newFile); + context.Load(newFile, f => f.ServerRelativeUrl); + + TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Uploading new sandbox solution to root site folder"); + context.ExecuteQueryWithTrace(); + + var info = new DesignPackageInfo + { + PackageGuid = definition.SolutionId, + MajorVersion = definition.MajorVersion, + MinorVersion = definition.MinorVersion, + PackageName = Path.GetFileNameWithoutExtension(definition.FileName) + }; + + // activate and remove + TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "DesignPackage.Install()"); + DesignPackage.Install(context, site, info, newFile.ServerRelativeUrl); + context.ExecuteQueryWithTrace(); + + // clean up the file + TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Deleting sandbox file from root site folder"); + newFile.DeleteObject(); + context.ExecuteQueryWithTrace(); + + existingSolution = FindExistingSolutionById(modelHost, definition.SolutionId); + } + + if (definition.Apply) + { + var info = new DesignPackageInfo + { + PackageGuid = definition.SolutionId, + MajorVersion = definition.MajorVersion, + MinorVersion = definition.MinorVersion, + PackageName = Path.GetFileNameWithoutExtension(definition.FileName) + }; + + // apply + TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "DesignPackage.Apply()"); + DesignPackage.Apply(context, site, info); + context.ExecuteQueryWithTrace(); + } InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioned, - Object = currentArtifact, - ObjectType = typeof(DesignPackageInfo), + Object = existingSolution, + ObjectType = typeof(File), ObjectDefinition = definition, ModelHost = modelHost }); diff --git a/SPMeta2/SPMeta2.CSOM.Standard/ModelHandlers/MetadataNavigationSettingsModelHandler.cs b/SPMeta2/SPMeta2.CSOM.Standard/ModelHandlers/MetadataNavigationSettingsModelHandler.cs index a7582065a..dec81f893 100644 --- a/SPMeta2/SPMeta2.CSOM.Standard/ModelHandlers/MetadataNavigationSettingsModelHandler.cs +++ b/SPMeta2/SPMeta2.CSOM.Standard/ModelHandlers/MetadataNavigationSettingsModelHandler.cs @@ -1,110 +1,129 @@ -using System; -using System.Linq; -using Microsoft.SharePoint.Client; -using SPMeta2.Common; -using SPMeta2.CSOM.ModelHandlers; -using SPMeta2.CSOM.ModelHosts; -using SPMeta2.CSOM.Standard.Config; -using SPMeta2.Definitions; -using SPMeta2.Standard.Definitions; -using SPMeta2.Utils; - -namespace SPMeta2.CSOM.Standard.ModelHandlers -{ - public class MetadataNavigationSettingsModelHandler : CSOMModelHandlerBase - { - #region properties - - public override Type TargetType - { - get { return typeof(MetadataNavigationSettingsDefinition); } - } - - #endregion - - #region methods - - public override void DeployModel(object modelHost, DefinitionBase model) - { - var listHost = modelHost.WithAssertAndCast("model", value => value.RequireNotNull()); - var typedDefinition = model.WithAssertAndCast("model", value => value.RequireNotNull()); - - DeploySettings(modelHost, listHost, typedDefinition); - } - - protected MetadataNavigationSettingsConfig GetCurrentSettings(List list) - { - return MetadataNavigationSettingsConfig.GetMetadataNavigationSettings(list); - } - - private void DeploySettings(object modelHost, ListModelHost listHost, MetadataNavigationSettingsDefinition definition) - { - var list = listHost.HostList; - - InvokeOnModelEvent(this, new ModelEventArgs - { - CurrentModelNode = null, - Model = null, - EventType = ModelEventType.OnProvisioning, - Object = list, - ObjectType = typeof(List), - ObjectDefinition = definition, - ModelHost = modelHost - }); - - var needUpdate = false; - - // deploy - var settings = GetCurrentSettings(list); - - if (definition.Hierarchies.Count() > 0) - { - foreach (var h in definition.Hierarchies) - { - if (h.FieldId.HasGuidValue()) - { - var targetField = list.Fields.GetById(h.FieldId.Value); - - settings.AddConfiguredHierarchy(new MetadataNavigationHierarchyConfig(targetField.Id)); - } - } - - needUpdate = true; - } - - if (definition.KeyFilters.Count() > 0) - { - foreach (var h in definition.KeyFilters) - { - if (h.FieldId.HasGuidValue()) - { - var targetField = list.Fields.GetById(h.FieldId.Value); - - settings.AddConfiguredKeyFilter(new MetadataNavigationKeyFilterConfig(targetField.Id)); - } - } - - needUpdate = true; - } - - InvokeOnModelEvent(this, new ModelEventArgs - { - CurrentModelNode = null, - Model = null, - EventType = ModelEventType.OnProvisioned, - Object = list, - ObjectType = typeof(List), - ObjectDefinition = definition, - ModelHost = modelHost - }); - - - if (needUpdate) - { - MetadataNavigationSettingsConfig.SetMetadataNavigationSettings(list, settings); - } - } - - #endregion - } -} +using System; +using System.Linq; +using Microsoft.SharePoint.Client; +using SPMeta2.Common; +using SPMeta2.CSOM.Extensions; +using SPMeta2.CSOM.ModelHandlers; +using SPMeta2.CSOM.ModelHosts; +using SPMeta2.CSOM.Standard.Config; +using SPMeta2.Definitions; +using SPMeta2.Standard.Definitions; +using SPMeta2.Utils; + +namespace SPMeta2.CSOM.Standard.ModelHandlers +{ + public class MetadataNavigationSettingsModelHandler : CSOMModelHandlerBase + { + #region properties + + public override Type TargetType + { + get { return typeof(MetadataNavigationSettingsDefinition); } + } + + #endregion + + #region methods + + public override void DeployModel(object modelHost, DefinitionBase model) + { + var listHost = modelHost.WithAssertAndCast("model", value => value.RequireNotNull()); + var typedDefinition = model.WithAssertAndCast("model", value => value.RequireNotNull()); + + DeploySettings(modelHost, listHost, typedDefinition); + } + + protected MetadataNavigationSettingsConfig GetCurrentSettings(List list) + { + return MetadataNavigationSettingsConfig.GetMetadataNavigationSettings(list); + } + + private void DeploySettings(object modelHost, ListModelHost listHost, MetadataNavigationSettingsDefinition definition) + { + var list = listHost.HostList; + var context = list.Context; + + InvokeOnModelEvent(this, new ModelEventArgs + { + CurrentModelNode = null, + Model = null, + EventType = ModelEventType.OnProvisioning, + Object = list, + ObjectType = typeof(List), + ObjectDefinition = definition, + ModelHost = modelHost + }); + + var needUpdate = false; + + // deploy + var settings = GetCurrentSettings(list); + + if (definition.Hierarchies.Count() > 0) + { + foreach (var h in definition.Hierarchies) + { + if (h.FieldId.HasGuidValue()) + { + var targetField = list.Fields.GetById(h.FieldId.Value); + + context.Load(targetField); + context.ExecuteQueryWithTrace(); + + settings.AddConfiguredHierarchy(new MetadataNavigationHierarchyConfig + { + FieldId = targetField.Id, + FieldType = targetField.TypeAsString, + CachedDisplayName = targetField.Title, + CachedName = targetField.InternalName + }); + } + } + + needUpdate = true; + } + + if (definition.KeyFilters.Count() > 0) + { + foreach (var h in definition.KeyFilters) + { + if (h.FieldId.HasGuidValue()) + { + var targetField = list.Fields.GetById(h.FieldId.Value); + + context.Load(targetField); + context.ExecuteQueryWithTrace(); + + settings.AddConfiguredKeyFilter(new MetadataNavigationKeyFilterConfig + { + FieldId = targetField.Id, + FieldType = targetField.TypeAsString, + CachedDisplayName = targetField.Title, + CachedName = targetField.InternalName + }); + } + } + + needUpdate = true; + } + + InvokeOnModelEvent(this, new ModelEventArgs + { + CurrentModelNode = null, + Model = null, + EventType = ModelEventType.OnProvisioned, + Object = list, + ObjectType = typeof(List), + ObjectDefinition = definition, + ModelHost = modelHost + }); + + if (needUpdate) + { + MetadataNavigationSettingsConfig.SetMetadataNavigationSettings(list, settings); + } + } + + #endregion + } +} diff --git a/SPMeta2/SPMeta2.CSOM.Standard/ModelHandlers/SandboxSolutionModelHandler.cs b/SPMeta2/SPMeta2.CSOM.Standard/ModelHandlers/SandboxSolutionModelHandler.cs index 8d7bd3106..95e35e2d8 100644 --- a/SPMeta2/SPMeta2.CSOM.Standard/ModelHandlers/SandboxSolutionModelHandler.cs +++ b/SPMeta2/SPMeta2.CSOM.Standard/ModelHandlers/SandboxSolutionModelHandler.cs @@ -1,210 +1,223 @@ -using System; -using System.IO; -using System.Linq; -using Microsoft.SharePoint.Client; -using Microsoft.SharePoint.Client.Publishing; -using SPMeta2.Common; -using SPMeta2.CSOM.Extensions; -using SPMeta2.CSOM.ModelHandlers; -using SPMeta2.CSOM.ModelHosts; -using SPMeta2.Definitions; -using SPMeta2.Exceptions; -using SPMeta2.Services; -using SPMeta2.Utils; -using File = Microsoft.SharePoint.Client.File; - -namespace SPMeta2.CSOM.Standard.ModelHandlers -{ - public class SandboxSolutionModelHandler : CSOMModelHandlerBase - { - #region properties - - public override Type TargetType - { - get { return typeof(SandboxSolutionDefinition); } - } - - #endregion - - #region methods - - public override void DeployModel(object modelHost, DefinitionBase model) - { - var sandboxSolutionDefinition = model.WithAssertAndCast("model", value => value.RequireNotNull()); - - ValidateDefinition(sandboxSolutionDefinition); - - var siteModelHost = modelHost.WithAssertAndCast("modelHost", value => value.RequireNotNull()); - - DeploySandboxSolution(modelHost, siteModelHost, sandboxSolutionDefinition); - } - - private void ValidateDefinition(SandboxSolutionDefinition sandboxSolutionDefinition) - { - if (!sandboxSolutionDefinition.Activate) - throw new SPMeta2NotSupportedException("SandboxSolutionDefinition.Activate must be true. (DesignPackage API requires it)."); - - if (sandboxSolutionDefinition.SolutionId == default(Guid)) - throw new SPMeta2NotSupportedException("SandboxSolutionDefinition.SolutionId must be defined for CSOM based provision (DesignPackage API requires it)."); - - var fileName = Path.GetFileNameWithoutExtension(sandboxSolutionDefinition.FileName); - - if (fileName.Contains(".")) - throw new SPMeta2NotSupportedException("SandboxSolutionDefinition.FileName must not contain dots. (DesignPackage API requires it)."); - } - - private void DeploySandboxSolution(object modelHost, SiteModelHost siteModelHost, SandboxSolutionDefinition sandboxSolutionDefinition) - { - var site = siteModelHost.HostSite; - var context = site.Context; - - var existingSolutionFile = FindExistingSolutionFile(siteModelHost, sandboxSolutionDefinition); - var existingSolution = FindExistingSolution(siteModelHost, sandboxSolutionDefinition); - - InvokeOnModelEvent(this, new ModelEventArgs - { - CurrentModelNode = null, - Model = null, - EventType = ModelEventType.OnProvisioning, - Object = existingSolutionFile, - ObjectType = typeof(File), - ObjectDefinition = sandboxSolutionDefinition, - ModelHost = modelHost - }); - - if (existingSolution != null) - { - TraceService.Information((int)LogEventId.ModelProvisionProcessingExistingObject, "Processing existing sandbox solution"); - - var fileItem = existingSolution.ListItemAllFields; - context.Load(fileItem); - context.ExecuteQueryWithTrace(); - - var currentFileName = fileItem["FileLeafRef"].ToString(); - - if (!currentFileName.Contains(sandboxSolutionDefinition.FileName)) - { - currentFileName = currentFileName.Replace(string.Format("-v{0}.{1}.wsp", 1, 0), string.Empty); - } - else - { - currentFileName = sandboxSolutionDefinition.FileName; - } - - var info = new DesignPackageInfo - { - PackageGuid = sandboxSolutionDefinition.SolutionId, - MajorVersion = 1, - MinorVersion = 0, - PackageName = Path.GetFileNameWithoutExtension(currentFileName) - }; - - // deactivate and remove - TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Deleting existing sandbox solution via DesignPackage.UnInstall()"); - DesignPackage.UnInstall(context, site, info); - - context.ExecuteQueryWithTrace(); - } - - //var solutionGallery = site.RootWeb.Lists.GetByTitle("Site Assets"); - //var folder = solutionGallery.RootFolder; - var folder = site.RootWeb.RootFolder; - - context.Load(folder); - context.ExecuteQueryWithTrace(); - - var fileCreatingInfo = new FileCreationInformation - { - Url = sandboxSolutionDefinition.FileName, - Overwrite = true - }; - - if (sandboxSolutionDefinition.Content.Length < 1024 * 1024 * 1.5) - { - fileCreatingInfo.Content = sandboxSolutionDefinition.Content; - } - else - { - fileCreatingInfo.ContentStream = new System.IO.MemoryStream(sandboxSolutionDefinition.Content); - } - - - var newFile = folder.Files.Add(fileCreatingInfo); - - context.Load(newFile); - context.Load(newFile, f => f.ServerRelativeUrl); - - TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Uploading new sandbox solution to root site folder"); - context.ExecuteQueryWithTrace(); - - if (sandboxSolutionDefinition.Activate) - { - var info = new DesignPackageInfo - { - PackageGuid = sandboxSolutionDefinition.SolutionId, - MajorVersion = 1, - MinorVersion = 0, - PackageName = Path.GetFileNameWithoutExtension(sandboxSolutionDefinition.FileName) - }; - - // activate and remove - TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Activating sandbox solution via DesignPackage.Install()"); - DesignPackage.Install(context, site, info, newFile.ServerRelativeUrl); - context.ExecuteQueryWithTrace(); - - // clean up the file - TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Deleting sandbox file from root site folder"); - newFile.DeleteObject(); - context.ExecuteQueryWithTrace(); - } - - InvokeOnModelEvent(this, new ModelEventArgs - { - CurrentModelNode = null, - Model = null, - EventType = ModelEventType.OnProvisioned, - Object = newFile, - ObjectType = typeof(File), - ObjectDefinition = sandboxSolutionDefinition, - ModelHost = modelHost - }); - } - - protected File FindExistingSolution(SiteModelHost siteModelHost, SandboxSolutionDefinition sandboxSolutionDefinition) - { - TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Resolving sandbox solution by SolutionId: [{0}]", sandboxSolutionDefinition.SolutionId); - - var site = siteModelHost.HostSite; - var context = site.Context; - - var solutionGallery = site.GetCatalog((int)ListTemplateType.SolutionCatalog); - var files = solutionGallery.GetItems(CamlQuery.CreateAllItemsQuery()); - - context.Load(files); - context.ExecuteQueryWithTrace(); - - var fileItem = files.ToList().FirstOrDefault(f => new Guid(f["SolutionId"].ToString()) == sandboxSolutionDefinition.SolutionId); - return fileItem != null ? fileItem.File : null; - } - - protected File FindExistingSolutionFile(SiteModelHost siteModelHost, SandboxSolutionDefinition sandboxSolutionDefinition) - { - TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Resolving sandbox solution by FileName: [{0}]", sandboxSolutionDefinition.FileName); - - var site = siteModelHost.HostSite; - var context = site.Context; - - var solutionGallery = site.GetCatalog((int)ListTemplateType.SolutionCatalog); - var files = solutionGallery.GetItems(CamlQuery.CreateAllItemsQuery()); - - context.Load(files); - context.ExecuteQueryWithTrace(); - - var fileItem = files.ToList().FirstOrDefault(f => f["FileLeafRef"].ToString() == sandboxSolutionDefinition.FileName); - - return fileItem != null ? fileItem.File : null; - } - - #endregion - } -} +using System; +using System.IO; +using System.Linq; +using Microsoft.SharePoint.Client; +using Microsoft.SharePoint.Client.Publishing; +using SPMeta2.Common; +using SPMeta2.CSOM.Extensions; +using SPMeta2.CSOM.ModelHandlers; +using SPMeta2.CSOM.ModelHosts; +using SPMeta2.Definitions; +using SPMeta2.Exceptions; +using SPMeta2.Services; +using SPMeta2.Utils; +using File = Microsoft.SharePoint.Client.File; + +namespace SPMeta2.CSOM.Standard.ModelHandlers +{ + public class SandboxSolutionModelHandler : CSOMModelHandlerBase + { + #region properties + + public override Type TargetType + { + get { return typeof(SandboxSolutionDefinition); } + } + + #endregion + + #region methods + + public override void DeployModel(object modelHost, DefinitionBase model) + { + var sandboxSolutionDefinition = model.WithAssertAndCast("model", value => value.RequireNotNull()); + + ValidateDefinition(sandboxSolutionDefinition); + + var siteModelHost = modelHost.WithAssertAndCast("modelHost", value => value.RequireNotNull()); + + DeploySandboxSolution(modelHost, siteModelHost, sandboxSolutionDefinition); + } + + private void ValidateDefinition(SandboxSolutionDefinition sandboxSolutionDefinition) + { + if (!sandboxSolutionDefinition.Activate) + throw new SPMeta2NotSupportedException("SandboxSolutionDefinition.Activate must be true. (DesignPackage API requires it)."); + + if (sandboxSolutionDefinition.SolutionId == default(Guid)) + throw new SPMeta2NotSupportedException("SandboxSolutionDefinition.SolutionId must be defined for CSOM based provision (DesignPackage API requires it)."); + + var fileName = Path.GetFileNameWithoutExtension(sandboxSolutionDefinition.FileName); + + if (fileName.Contains(".")) + throw new SPMeta2NotSupportedException("SandboxSolutionDefinition.FileName must not contain dots. (DesignPackage API requires it)."); + } + + private void DeploySandboxSolution(object modelHost, SiteModelHost siteModelHost, SandboxSolutionDefinition sandboxSolutionDefinition) + { + var site = siteModelHost.HostSite; + var context = site.Context; + + var existingSolutionFile = FindExistingSolutionFile(siteModelHost, sandboxSolutionDefinition); + var existingSolution = FindExistingSolution(siteModelHost, sandboxSolutionDefinition); + + InvokeOnModelEvent(this, new ModelEventArgs + { + CurrentModelNode = null, + Model = null, + EventType = ModelEventType.OnProvisioning, + Object = existingSolutionFile, + ObjectType = typeof(File), + ObjectDefinition = sandboxSolutionDefinition, + ModelHost = modelHost + }); + + if (existingSolution != null) + { + TraceService.Information((int)LogEventId.ModelProvisionProcessingExistingObject, "Processing existing sandbox solution"); + + var fileItem = existingSolution.ListItemAllFields; + context.Load(fileItem); + context.ExecuteQueryWithTrace(); + + var currentFileName = fileItem["FileLeafRef"].ToString(); + + if (!currentFileName.Contains(sandboxSolutionDefinition.FileName)) + { + currentFileName = currentFileName.Replace(string.Format("-v{0}.{1}.wsp", 1, 0), string.Empty); + } + else + { + currentFileName = sandboxSolutionDefinition.FileName; + } + + var info = new DesignPackageInfo + { + PackageGuid = sandboxSolutionDefinition.SolutionId, + MajorVersion = 1, + MinorVersion = 0, + PackageName = Path.GetFileNameWithoutExtension(currentFileName) + }; + + // deactivate and remove + TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Deleting existing sandbox solution via DesignPackage.UnInstall()"); + DesignPackage.UnInstall(context, site, info); + + context.ExecuteQueryWithTrace(); + } + + //var solutionGallery = site.RootWeb.Lists.GetByTitle("Site Assets"); + //var folder = solutionGallery.RootFolder; + var folder = site.RootWeb.RootFolder; + + context.Load(folder); + context.ExecuteQueryWithTrace(); + + var fileCreatingInfo = new FileCreationInformation + { + Url = sandboxSolutionDefinition.FileName, + Overwrite = true + }; + + if (sandboxSolutionDefinition.Content.Length < 1024 * 1024 * 1.5) + { + fileCreatingInfo.Content = sandboxSolutionDefinition.Content; + } + else + { + fileCreatingInfo.ContentStream = new System.IO.MemoryStream(sandboxSolutionDefinition.Content); + } + + + var newFile = folder.Files.Add(fileCreatingInfo); + + context.Load(newFile); + context.Load(newFile, f => f.ServerRelativeUrl); + + TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Uploading new sandbox solution to root site folder"); + context.ExecuteQueryWithTrace(); + + if (sandboxSolutionDefinition.Activate) + { + var info = new DesignPackageInfo + { + PackageGuid = sandboxSolutionDefinition.SolutionId, + MajorVersion = 1, + MinorVersion = 0, + PackageName = Path.GetFileNameWithoutExtension(sandboxSolutionDefinition.FileName) + }; + + // activate and remove + TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Activating sandbox solution via DesignPackage.Install()"); + DesignPackage.Install(context, site, info, newFile.ServerRelativeUrl); + context.ExecuteQueryWithTrace(); + + // clean up the file + TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Deleting sandbox file from root site folder"); + newFile.DeleteObject(); + context.ExecuteQueryWithTrace(); + } + + InvokeOnModelEvent(this, new ModelEventArgs + { + CurrentModelNode = null, + Model = null, + EventType = ModelEventType.OnProvisioned, + Object = newFile, + ObjectType = typeof(File), + ObjectDefinition = sandboxSolutionDefinition, + ModelHost = modelHost + }); + } + + protected File FindExistingSolution(SiteModelHost siteModelHost, + SandboxSolutionDefinition sandboxSolutionDefinition) + { + return FindExistingSolutionById(siteModelHost, sandboxSolutionDefinition.SolutionId); + } + + protected File FindExistingSolutionById(SiteModelHost siteModelHost, Guid solutionId) + { + TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Resolving sandbox solution by SolutionId: [{0}]", solutionId); + + var site = siteModelHost.HostSite; + var context = site.Context; + + var solutionGallery = site.GetCatalog((int)ListTemplateType.SolutionCatalog); + var files = solutionGallery.GetItems(CamlQuery.CreateAllItemsQuery()); + + context.Load(files); + context.ExecuteQueryWithTrace(); + + var fileItem = files.ToList().FirstOrDefault(f => new Guid(f["SolutionId"].ToString()) == solutionId); + return fileItem != null ? fileItem.File : null; + } + + + protected File FindExistingSolutionFile(SiteModelHost siteModelHost, + SandboxSolutionDefinition sandboxSolutionDefinition) + { + return FindExistingSolutionFileByName(siteModelHost, sandboxSolutionDefinition.FileName); + } + + protected File FindExistingSolutionFileByName(SiteModelHost siteModelHost, string fileName) + { + TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Resolving sandbox solution by FileName: [{0}]", fileName); + + var site = siteModelHost.HostSite; + var context = site.Context; + + var solutionGallery = site.GetCatalog((int)ListTemplateType.SolutionCatalog); + var files = solutionGallery.GetItems(CamlQuery.CreateAllItemsQuery()); + + context.Load(files); + context.ExecuteQueryWithTrace(); + + var fileItem = files.ToList().FirstOrDefault(f => f["FileLeafRef"].ToString() == fileName); + + return fileItem != null ? fileItem.File : null; + } + + #endregion + } +} diff --git a/SPMeta2/SPMeta2.CSOM.Standard/Properties/AssemblyInfo.cs b/SPMeta2/SPMeta2.CSOM.Standard/Properties/AssemblyInfo.cs index 2ae40049e..a15e9911d 100644 --- a/SPMeta2/SPMeta2.CSOM.Standard/Properties/AssemblyInfo.cs +++ b/SPMeta2/SPMeta2.CSOM.Standard/Properties/AssemblyInfo.cs @@ -32,4 +32,4 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.2.16298.0736")] +[assembly: AssemblyFileVersion("1.2.16305.1232")] diff --git a/SPMeta2/SPMeta2.CSOM/ModelHandlers/FieldModelHandler.cs b/SPMeta2/SPMeta2.CSOM/ModelHandlers/FieldModelHandler.cs index 181908d1f..f68242070 100644 --- a/SPMeta2/SPMeta2.CSOM/ModelHandlers/FieldModelHandler.cs +++ b/SPMeta2/SPMeta2.CSOM/ModelHandlers/FieldModelHandler.cs @@ -16,7 +16,7 @@ namespace SPMeta2.CSOM.ModelHandlers { public class FieldModelHandler : CSOMModelHandlerBase { - #region construactors + #region constructors static FieldModelHandler() { @@ -52,10 +52,6 @@ protected static XElement GetNewMinimalSPFieldTemplate() new XAttribute(BuiltInFieldAttributes.CanToggleHidden, "TRUE")); } - #endregion - - #region methods - protected virtual bool PreloadProperties(Field field) { return false; @@ -196,8 +192,19 @@ public override void DeployModel(object modelHost, DefinitionBase model) ModelHost = modelHost }); - TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "UpdateAndPushChanges(true)"); - currentField.UpdateAndPushChanges(true); + if (fieldModel.PushChangesToLists.HasValue) + { + TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, + string.Format("UpdateAndPushChanges({0})", fieldModel.PushChangesToLists)); + + currentField.UpdateAndPushChanges(fieldModel.PushChangesToLists.Value); + } + else + { + TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "UpdateAndPushChanges(true)"); + // Why does SSOM handler distinguish between list and web/site fields and csom doesn't? + currentField.UpdateAndPushChanges(true); + } TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "ExecuteQuery()"); context.ExecuteQueryWithTrace(); diff --git a/SPMeta2/SPMeta2.CSOM/ModelHandlers/FolderModelHandler.cs b/SPMeta2/SPMeta2.CSOM/ModelHandlers/FolderModelHandler.cs index b66ad17c4..438d11eaf 100644 --- a/SPMeta2/SPMeta2.CSOM/ModelHandlers/FolderModelHandler.cs +++ b/SPMeta2/SPMeta2.CSOM/ModelHandlers/FolderModelHandler.cs @@ -356,10 +356,16 @@ private Folder EnsureLibraryFolder(FolderModelHost folderModelHost, FolderDefini var currentFolderItem = currentFolder.ListItemAllFields; - MapProperties(currentFolderItem, folderModel); + // could be NULL, in the /Forms or other hidden folders + if (currentFolderItem != null + && currentFolderItem.ServerObjectIsNull != null + && !currentFolderItem.ServerObjectIsNull.Value) + { + MapProperties(currentFolderItem, folderModel); - currentFolderItem.Update(); - context.ExecuteQueryWithTrace(); + currentFolderItem.Update(); + context.ExecuteQueryWithTrace(); + } #endif } else @@ -376,10 +382,16 @@ private Folder EnsureLibraryFolder(FolderModelHost folderModelHost, FolderDefini var currentFolderItem = currentFolder.ListItemAllFields; - MapProperties(currentFolderItem, folderModel); + // could be NULL, in the /Forms or other hidden folders + if (currentFolderItem != null + && currentFolderItem.ServerObjectIsNull != null + && !currentFolderItem.ServerObjectIsNull.Value) + { + MapProperties(currentFolderItem, folderModel); - currentFolderItem.Update(); - context.ExecuteQueryWithTrace(); + currentFolderItem.Update(); + context.ExecuteQueryWithTrace(); + } #endif } diff --git a/SPMeta2/SPMeta2.CSOM/Properties/AssemblyInfo.cs b/SPMeta2/SPMeta2.CSOM/Properties/AssemblyInfo.cs index d8d2f270d..9501c1fe1 100644 --- a/SPMeta2/SPMeta2.CSOM/Properties/AssemblyInfo.cs +++ b/SPMeta2/SPMeta2.CSOM/Properties/AssemblyInfo.cs @@ -33,4 +33,4 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.2.16298.0736")] +[assembly: AssemblyFileVersion("1.2.16305.1232")] diff --git a/SPMeta2/SPMeta2.Containers.CSOM/Properties/AssemblyInfo.cs b/SPMeta2/SPMeta2.Containers.CSOM/Properties/AssemblyInfo.cs index 36798c040..108e7ff1f 100644 --- a/SPMeta2/SPMeta2.Containers.CSOM/Properties/AssemblyInfo.cs +++ b/SPMeta2/SPMeta2.Containers.CSOM/Properties/AssemblyInfo.cs @@ -33,4 +33,4 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.2.16298.0736")] \ No newline at end of file +[assembly: AssemblyFileVersion("1.2.16305.1232")] \ No newline at end of file diff --git a/SPMeta2/SPMeta2.Containers.O365/Properties/AssemblyInfo.cs b/SPMeta2/SPMeta2.Containers.O365/Properties/AssemblyInfo.cs index 442b9cf49..706c6dc09 100644 --- a/SPMeta2/SPMeta2.Containers.O365/Properties/AssemblyInfo.cs +++ b/SPMeta2/SPMeta2.Containers.O365/Properties/AssemblyInfo.cs @@ -33,4 +33,4 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.2.16298.0736")] +[assembly: AssemblyFileVersion("1.2.16305.1232")] diff --git a/SPMeta2/SPMeta2.Containers.O365v16/Properties/AssemblyInfo.cs b/SPMeta2/SPMeta2.Containers.O365v16/Properties/AssemblyInfo.cs index a2d193f07..1bac1ea68 100644 --- a/SPMeta2/SPMeta2.Containers.O365v16/Properties/AssemblyInfo.cs +++ b/SPMeta2/SPMeta2.Containers.O365v16/Properties/AssemblyInfo.cs @@ -33,4 +33,4 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.2.16298.0736")] \ No newline at end of file +[assembly: AssemblyFileVersion("1.2.16305.1232")] \ No newline at end of file diff --git a/SPMeta2/SPMeta2.Containers.SSOM/Properties/AssemblyInfo.cs b/SPMeta2/SPMeta2.Containers.SSOM/Properties/AssemblyInfo.cs index a7684bfec..4f5b0f14b 100644 --- a/SPMeta2/SPMeta2.Containers.SSOM/Properties/AssemblyInfo.cs +++ b/SPMeta2/SPMeta2.Containers.SSOM/Properties/AssemblyInfo.cs @@ -33,4 +33,4 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.2.16298.0736")] +[assembly: AssemblyFileVersion("1.2.16305.1232")] diff --git a/SPMeta2/SPMeta2.Containers.SSOM/SSOMProvisionRunner.cs b/SPMeta2/SPMeta2.Containers.SSOM/SSOMProvisionRunner.cs index a1c726aea..505ae73d6 100644 --- a/SPMeta2/SPMeta2.Containers.SSOM/SSOMProvisionRunner.cs +++ b/SPMeta2/SPMeta2.Containers.SSOM/SSOMProvisionRunner.cs @@ -4,6 +4,7 @@ using System.IO; using System.IO.MemoryMappedFiles; using System.Linq; +using System.Reflection; using Microsoft.Office.SecureStoreService.Server; using Microsoft.Office.Server.Audience; using Microsoft.Office.Server.Search.Portability; @@ -102,6 +103,17 @@ private void InitServices() args.CurrentNode.Value })); }; + + foreach (var modelHandler in _provisionService.ModelHandlers.Values) + { + var isQA = modelHandler.GetType() + .GetProperty("IsQARun", BindingFlags.NonPublic | BindingFlags.Instance); + + if (isQA != null) + { + isQA.SetValue(modelHandler, true); ; + } + } } private void LoadEnvironmentConfig() diff --git a/SPMeta2/SPMeta2.Containers.Standard/DefinitionGenerators/DesignPackageDefinitionGenerator.cs b/SPMeta2/SPMeta2.Containers.Standard/DefinitionGenerators/DesignPackageDefinitionGenerator.cs index f70d92460..6d65cf649 100644 --- a/SPMeta2/SPMeta2.Containers.Standard/DefinitionGenerators/DesignPackageDefinitionGenerator.cs +++ b/SPMeta2/SPMeta2.Containers.Standard/DefinitionGenerators/DesignPackageDefinitionGenerator.cs @@ -1,11 +1,13 @@ using System; using System.Collections.Generic; +using SPMeta2.Containers.Consts; using SPMeta2.Containers.Services.Base; using SPMeta2.Definitions; using SPMeta2.Definitions.Base; using SPMeta2.Enumerations; using SPMeta2.Standard.Definitions; using SPMeta2.Syntax.Default; +using System.IO; namespace SPMeta2.Containers.Standard.DefinitionGenerators { @@ -15,7 +17,13 @@ public override DefinitionBase GenerateRandomDefinition(Action a { return WithEmptyDefinition(def => { - // TODO + def.FileName = string.Format("{0}.wsp", Rnd.String()); + + def.Install = true; + def.Apply = false; + + def.SolutionId = DefaultContainers.DesignPackage.SolutionId; + def.Content = File.ReadAllBytes(DefaultContainers.DesignPackage.Package_v10_FilePath); }); } } diff --git a/SPMeta2/SPMeta2.Containers.Standard/Properties/AssemblyInfo.cs b/SPMeta2/SPMeta2.Containers.Standard/Properties/AssemblyInfo.cs index 38fa3b5fd..477738e72 100644 --- a/SPMeta2/SPMeta2.Containers.Standard/Properties/AssemblyInfo.cs +++ b/SPMeta2/SPMeta2.Containers.Standard/Properties/AssemblyInfo.cs @@ -33,4 +33,4 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.2.16298.0736")] +[assembly: AssemblyFileVersion("1.2.16305.1232")] diff --git a/SPMeta2/SPMeta2.Containers/Consts/DefaultContainers.cs b/SPMeta2/SPMeta2.Containers/Consts/DefaultContainers.cs index 1406f8c84..724827d8a 100644 --- a/SPMeta2/SPMeta2.Containers/Consts/DefaultContainers.cs +++ b/SPMeta2/SPMeta2.Containers/Consts/DefaultContainers.cs @@ -1,21 +1,21 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - - -namespace SPMeta2.Containers.Consts -{ - public static class DefaultContainers - { - public static class WebTemplates - { - public static class M2CustomTeamSite - { - public static Guid SolutionId = new Guid("{52b034ae-13e4-4147-b8f1-469f2b21f2d7}"); - public static string FilePath = @"Containers\WebTemplates\M2CustomTeamSite.wsp"; - - public static string WebTemplateName = "{7DA6B762-9AB9-4D81-870A-E93B586B7534}#M2CustomTeamSite"; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + + +namespace SPMeta2.Containers.Consts +{ + public static class DefaultContainers + { + public static class WebTemplates + { + public static class M2CustomTeamSite + { + public static Guid SolutionId = new Guid("{52b034ae-13e4-4147-b8f1-469f2b21f2d7}"); + public static string FilePath = @"Containers\WebTemplates\M2CustomTeamSite.wsp"; + + public static string WebTemplateName = "{7DA6B762-9AB9-4D81-870A-E93B586B7534}#M2CustomTeamSite"; } public static class M2CustomWebAsTemplate @@ -24,54 +24,66 @@ public static class M2CustomWebAsTemplate public static string FilePath = @"Containers\WebTemplates\M2CustomWebAsTemplate.wsp"; public static string WebTemplateName = "M2CustomWebAsTemplate"; - } - } - - public static class Sandbox - { - public static string FilePath = @"Containers\Sandbox\SPMeta2.Containers.SandboxSolutionContainer.wsp"; - public static Guid SolutionId = new Guid("e9a61998-07f2-45e9-ae43-9e93fa6b11bb"); - - public static Guid SiteFeatureId = new Guid("32dc6bed-0298-4fca-a72f-e9b9c0d6f09a"); - public static Guid WebFeatureId = new Guid("b997a462-8efb-44cf-92c0-457e75c81798"); - public static Guid WebPartFeatureId = new Guid("9acf0f59-3cdc-412b-a647-4185dd4cd9bc"); - } - - public static class FarmSolution - { - public static string FilePath = @"Containers\Farm\SPMeta2.Containers.FarmSolutionContainer.wsp"; - public static Guid SolutionId = new Guid("a4a2146d-57d1-48bd-a02e-ba97b371903d"); - } - - public static class Apps - { - public static Guid ProductId = new Guid("{e81b6820-5d57-4d17-a098-5f4317f6c400}"); - public static Guid FeatureId = new Guid("{e81b6820-5d57-4d17-a098-5f4317f6c401}"); - - public static string M2ClientWebPart1Name = "M2ClientWebPart1"; - public static string M2ClientWebPart2Name = "M2ClientWebPart2"; - - public static string GenericVersionableAppFilePath = @"Containers\Apps\{0}\SPMeta2.Containers.AppContainer.app"; - - public static class v0 - { - public static string FilePath = @"Containers\Apps\1.0.0.0\SPMeta2.Containers.AppContainer.app"; - } - - public static class v1 - { - public static string FilePath = @"Containers\Apps\1.0.0.1\SPMeta2.Containers.AppContainer.app"; - } - - public static class v2 - { - public static string FilePath = @"Containers\Apps\1.0.0.2\SPMeta2.Containers.AppContainer.app"; - } - - public static class v3 - { - public static string FilePath = @"Containers\Apps\1.0.0.3\SPMeta2.Containers.AppContainer.app"; - } - } - } -} + } + } + + public static class DesignPackage + { + public static Guid SolutionId = new Guid("9083433c-2c01-4ce2-974d-dda6f70acc9f"); + + public static string Package_v10_FilePath = @"Containers\DesignPackages\ci-1-1.0.wsp"; + public static string Package_v11_FilePath = @"Containers\DesignPackages\ci-1-1.1.wsp"; + public static string Package_v12_FilePath = @"Containers\DesignPackages\ci-1-1.2.wsp"; + public static string Package_v13_FilePath = @"Containers\DesignPackages\ci-1-1.3.wsp"; + public static string Package_v14_FilePath = @"Containers\DesignPackages\ci-1-1.4.wsp"; + public static string Package_v15_FilePath = @"Containers\DesignPackages\ci-1-1.5.wsp"; + } + + public static class Sandbox + { + public static string FilePath = @"Containers\Sandbox\SPMeta2.Containers.SandboxSolutionContainer.wsp"; + public static Guid SolutionId = new Guid("e9a61998-07f2-45e9-ae43-9e93fa6b11bb"); + + public static Guid SiteFeatureId = new Guid("32dc6bed-0298-4fca-a72f-e9b9c0d6f09a"); + public static Guid WebFeatureId = new Guid("b997a462-8efb-44cf-92c0-457e75c81798"); + public static Guid WebPartFeatureId = new Guid("9acf0f59-3cdc-412b-a647-4185dd4cd9bc"); + } + + public static class FarmSolution + { + public static string FilePath = @"Containers\Farm\SPMeta2.Containers.FarmSolutionContainer.wsp"; + public static Guid SolutionId = new Guid("a4a2146d-57d1-48bd-a02e-ba97b371903d"); + } + + public static class Apps + { + public static Guid ProductId = new Guid("{e81b6820-5d57-4d17-a098-5f4317f6c400}"); + public static Guid FeatureId = new Guid("{e81b6820-5d57-4d17-a098-5f4317f6c401}"); + + public static string M2ClientWebPart1Name = "M2ClientWebPart1"; + public static string M2ClientWebPart2Name = "M2ClientWebPart2"; + + public static string GenericVersionableAppFilePath = @"Containers\Apps\{0}\SPMeta2.Containers.AppContainer.app"; + + public static class v0 + { + public static string FilePath = @"Containers\Apps\1.0.0.0\SPMeta2.Containers.AppContainer.app"; + } + + public static class v1 + { + public static string FilePath = @"Containers\Apps\1.0.0.1\SPMeta2.Containers.AppContainer.app"; + } + + public static class v2 + { + public static string FilePath = @"Containers\Apps\1.0.0.2\SPMeta2.Containers.AppContainer.app"; + } + + public static class v3 + { + public static string FilePath = @"Containers\Apps\1.0.0.3\SPMeta2.Containers.AppContainer.app"; + } + } + } +} diff --git a/SPMeta2/SPMeta2.Containers/Containers/DesignPackages/ci-1-1.0.wsp b/SPMeta2/SPMeta2.Containers/Containers/DesignPackages/ci-1-1.0.wsp new file mode 100644 index 000000000..32b5e4c71 Binary files /dev/null and b/SPMeta2/SPMeta2.Containers/Containers/DesignPackages/ci-1-1.0.wsp differ diff --git a/SPMeta2/SPMeta2.Containers/Containers/DesignPackages/ci-1-1.1.wsp b/SPMeta2/SPMeta2.Containers/Containers/DesignPackages/ci-1-1.1.wsp new file mode 100644 index 000000000..4e6f1be09 Binary files /dev/null and b/SPMeta2/SPMeta2.Containers/Containers/DesignPackages/ci-1-1.1.wsp differ diff --git a/SPMeta2/SPMeta2.Containers/Containers/DesignPackages/ci-1-1.2.wsp b/SPMeta2/SPMeta2.Containers/Containers/DesignPackages/ci-1-1.2.wsp new file mode 100644 index 000000000..4e2167eab Binary files /dev/null and b/SPMeta2/SPMeta2.Containers/Containers/DesignPackages/ci-1-1.2.wsp differ diff --git a/SPMeta2/SPMeta2.Containers/Containers/DesignPackages/ci-1-1.3.wsp b/SPMeta2/SPMeta2.Containers/Containers/DesignPackages/ci-1-1.3.wsp new file mode 100644 index 000000000..6ab25886c Binary files /dev/null and b/SPMeta2/SPMeta2.Containers/Containers/DesignPackages/ci-1-1.3.wsp differ diff --git a/SPMeta2/SPMeta2.Containers/Containers/DesignPackages/ci-1-1.4.wsp b/SPMeta2/SPMeta2.Containers/Containers/DesignPackages/ci-1-1.4.wsp new file mode 100644 index 000000000..936fc4938 Binary files /dev/null and b/SPMeta2/SPMeta2.Containers/Containers/DesignPackages/ci-1-1.4.wsp differ diff --git a/SPMeta2/SPMeta2.Containers/Containers/DesignPackages/ci-1-1.5.wsp b/SPMeta2/SPMeta2.Containers/Containers/DesignPackages/ci-1-1.5.wsp new file mode 100644 index 000000000..b89b9d44a Binary files /dev/null and b/SPMeta2/SPMeta2.Containers/Containers/DesignPackages/ci-1-1.5.wsp differ diff --git a/SPMeta2/SPMeta2.Containers/Properties/AssemblyInfo.cs b/SPMeta2/SPMeta2.Containers/Properties/AssemblyInfo.cs index 98ac0b3d7..fbbc0bc97 100644 --- a/SPMeta2/SPMeta2.Containers/Properties/AssemblyInfo.cs +++ b/SPMeta2/SPMeta2.Containers/Properties/AssemblyInfo.cs @@ -33,4 +33,4 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.2.16298.0736")] +[assembly: AssemblyFileVersion("1.2.16305.1232")] diff --git a/SPMeta2/SPMeta2.Containers/SPMeta2.Containers.csproj b/SPMeta2/SPMeta2.Containers/SPMeta2.Containers.csproj index 0ace4553f..8598ce27e 100644 --- a/SPMeta2/SPMeta2.Containers/SPMeta2.Containers.csproj +++ b/SPMeta2/SPMeta2.Containers/SPMeta2.Containers.csproj @@ -321,6 +321,24 @@ Always + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + Always diff --git a/SPMeta2/SPMeta2.Containers/Services/RegressionTestService.cs b/SPMeta2/SPMeta2.Containers/Services/RegressionTestService.cs index 3ec108bcf..e1e254520 100644 --- a/SPMeta2/SPMeta2.Containers/Services/RegressionTestService.cs +++ b/SPMeta2/SPMeta2.Containers/Services/RegressionTestService.cs @@ -370,12 +370,26 @@ protected virtual Action> Create hook.OnProvisioned = true; - AssertService.IsNotNull(context.Object); - AssertService.IsNotNull(context.ObjectDefinition); + var farmDef = context.ObjectDefinition as FarmSolutionDefinition; - AssertService.IsNotNull(context.ModelHost); + if (farmDef != null && farmDef.ShouldDelete == true) + { + // by passing checking the object within onb provisioed event + // farm solution is expected to be deleted + } + else + { + if (context.Object == null) + { + Console.WriteLine(""); + } - AssertService.IsInstanceOfType(context.Object, typeof(TObjectType)); + AssertService.IsNotNull(context.Object); + AssertService.IsNotNull(context.ObjectDefinition); + + AssertService.IsNotNull(context.ModelHost); + AssertService.IsInstanceOfType(context.Object, typeof(TObjectType)); + } }); } diff --git a/SPMeta2/SPMeta2.O365/Properties/AssemblyInfo.cs b/SPMeta2/SPMeta2.O365/Properties/AssemblyInfo.cs index e4b025af2..e4884e2eb 100644 --- a/SPMeta2/SPMeta2.O365/Properties/AssemblyInfo.cs +++ b/SPMeta2/SPMeta2.O365/Properties/AssemblyInfo.cs @@ -33,4 +33,4 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.2.16298.0736")] +[assembly: AssemblyFileVersion("1.2.16305.1232")] diff --git a/SPMeta2/SPMeta2.Regression.CSOM.Standard/Properties/AssemblyInfo.cs b/SPMeta2/SPMeta2.Regression.CSOM.Standard/Properties/AssemblyInfo.cs index 3318c3c11..7b28a3cdf 100644 --- a/SPMeta2/SPMeta2.Regression.CSOM.Standard/Properties/AssemblyInfo.cs +++ b/SPMeta2/SPMeta2.Regression.CSOM.Standard/Properties/AssemblyInfo.cs @@ -33,4 +33,4 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.2.16298.0736")] +[assembly: AssemblyFileVersion("1.2.16305.1232")] diff --git a/SPMeta2/SPMeta2.Regression.CSOM.Standard/Validation/DesignPackageDefinitionValidator.cs b/SPMeta2/SPMeta2.Regression.CSOM.Standard/Validation/DesignPackageDefinitionValidator.cs index 3f6b861ac..bc5ad6896 100644 --- a/SPMeta2/SPMeta2.Regression.CSOM.Standard/Validation/DesignPackageDefinitionValidator.cs +++ b/SPMeta2/SPMeta2.Regression.CSOM.Standard/Validation/DesignPackageDefinitionValidator.cs @@ -1,9 +1,11 @@ using Microsoft.SharePoint.Client; using Microsoft.SharePoint.Client.Publishing; +using SPMeta2.Containers.Assertion; using SPMeta2.CSOM.Extensions; using SPMeta2.CSOM.ModelHosts; using SPMeta2.CSOM.Standard.ModelHandlers; using SPMeta2.Definitions; +using SPMeta2.Regression.CSOM.Standard.Extensions; using SPMeta2.Standard.Definitions; using SPMeta2.Utils; @@ -18,14 +20,79 @@ public override void DeployModel(object modelHost, DefinitionBase model) var siteModelHost = modelHost.WithAssertAndCast("modelHost", value => value.RequireNotNull()); var definition = model.WithAssertAndCast("model", value => value.RequireNotNull()); - // TODO - var context = siteModelHost.HostSite.Context; + var spObject = this.FindExistingSolutionById(siteModelHost, definition.SolutionId); + var context = spObject.Context; - DesignPackageInfo spObject = null; + var site = siteModelHost.HostSite; + var rootWeb = site.RootWeb; - var assert = ServiceFactory.AssertService - .NewAssert(definition, spObject) - .ShouldNotBeNull(spObject); + var fileItem = spObject.ListItemAllFields; + + context.Load(fileItem); + context.Load(rootWeb, w => w.AllProperties); + + context.ExecuteQueryWithTrace(); + + var assert = ServiceFactory.AssertService.NewAssert(definition, fileItem); + + assert + .ShouldNotBeNull(fileItem) + + //.ShouldBeEqual(d => d, o => o.GetSolutionActivationStatus()) + .ShouldBeEqual(d => d.SolutionId, o => o.GetSolutionId()) + + .SkipProperty(d => d.Content, "Content is fine.") + .SkipProperty(d => d.FileName, "Randomly generated by CSOM activation."); + + if (definition.Apply) + { + assert.ShouldBeEqual((p, s, d) => + { + // once applied, design package sets AppliedDesignGuid property in the root web + // checking is all good + var installedPackageId = ConvertUtils.ToGuid(rootWeb.AllProperties["AppliedDesignGuid"]); + + var srcProp = s.GetExpressionValue(m => m.Apply); + var isValid = spObject != null + && installedPackageId == definition.SolutionId; + + return new PropertyValidationResult + { + Tag = p.Tag, + Src = srcProp, + Dst = null, + IsValid = isValid + }; + }); + } + else + { + assert.SkipProperty(m => m.Apply, "Apply is false"); + } + + if (definition.Install) + { + assert.ShouldBeEqual((p, s, d) => + { + var srcProp = s.GetExpressionValue(m => m.Install); + var isValid = spObject != null; + + return new PropertyValidationResult + { + Tag = p.Tag, + Src = srcProp, + Dst = null, + IsValid = isValid + }; + }); + } + else + { + assert.SkipProperty(d => d.Install, "Install is false"); + } + + assert.SkipProperty(m => m.MajorVersion, string.Empty); + assert.SkipProperty(m => m.MinorVersion, string.Empty); } #endregion diff --git a/SPMeta2/SPMeta2.Regression.CSOM/Properties/AssemblyInfo.cs b/SPMeta2/SPMeta2.Regression.CSOM/Properties/AssemblyInfo.cs index 118918056..6afa87f11 100644 --- a/SPMeta2/SPMeta2.Regression.CSOM/Properties/AssemblyInfo.cs +++ b/SPMeta2/SPMeta2.Regression.CSOM/Properties/AssemblyInfo.cs @@ -33,4 +33,4 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.2.16298.0736")] +[assembly: AssemblyFileVersion("1.2.16305.1232")] diff --git a/SPMeta2/SPMeta2.Regression.CSOM/Validation/ClientFieldDefinitionValidator.cs b/SPMeta2/SPMeta2.Regression.CSOM/Validation/ClientFieldDefinitionValidator.cs index ec1b72058..06f20e63c 100644 --- a/SPMeta2/SPMeta2.Regression.CSOM/Validation/ClientFieldDefinitionValidator.cs +++ b/SPMeta2/SPMeta2.Regression.CSOM/Validation/ClientFieldDefinitionValidator.cs @@ -361,6 +361,9 @@ protected void ValidateField(AssertPair assert, Field sp assert.SkipProperty(m => m.TitleResource, "TitleResource is null or empty. Skipping."); assert.SkipProperty(m => m.DescriptionResource, "DescriptionResource is null or empty. Skipping."); } + + assert.SkipProperty(m => m.PushChangesToLists, + "Covered by 'Regression.Scenarios.Fields.PushChangesToLists' test category"); } } } diff --git a/SPMeta2/SPMeta2.Regression.CSOM/Validation/ClientListFieldLinkDefinitionValidator.cs b/SPMeta2/SPMeta2.Regression.CSOM/Validation/ClientListFieldLinkDefinitionValidator.cs index d0e902b24..bf671391e 100644 --- a/SPMeta2/SPMeta2.Regression.CSOM/Validation/ClientListFieldLinkDefinitionValidator.cs +++ b/SPMeta2/SPMeta2.Regression.CSOM/Validation/ClientListFieldLinkDefinitionValidator.cs @@ -31,11 +31,44 @@ public override void DeployModel(object modelHost, DefinitionBase model) .ShouldNotBeNull(spObject) .ShouldBeEqualIfNotNullOrEmpty(m => m.FieldInternalName, o => o.InternalName) - .ShouldBeEqualIfNotNullOrEmpty(m => m.DisplayName, o => o.Title) .ShouldBeEqualIfHasValue(m => m.FieldId, o => o.Id) .ShouldBeEqualIfHasValue(m => m.Required, o => o.Required) - .ShouldBeEqualIfHasValue(m => m.Hidden, o => o.Hidden); + .ShouldBeEqualIfHasValue(m => m.Hidden, o => o.Hidden); + + if (!string.IsNullOrEmpty(definition.DisplayName)) + assert.ShouldBeEqual(m => m.DisplayName, o => o.Title); + else + { + + var regDisplayTitleProp = definition.PropertyBag.FirstOrDefault(p => p.Name == "_Reg_DisplayName"); + + if (regDisplayTitleProp != null) + { + // Enhance FieldDefinition with 'pushChangesToLists' option #922 + // https://github.com/SubPointSolutions/spmeta2/issues/922 + + assert.ShouldBeEqual((p, s, d) => + { + var srcProp = s.GetExpressionValue(m => m.DisplayName); + var dstProp = d.GetExpressionValue(m => m.Title); + + var isValid = regDisplayTitleProp.Value == d.Title; + + return new PropertyValidationResult + { + Tag = p.Tag, + Src = srcProp, + Dst = null, + IsValid = isValid + }; + }); + } + else + { + assert.SkipProperty(m => m.DisplayName, "DisplayName is null or empty. Skipping"); + } + } if (definition.AddFieldOptions.HasFlag(BuiltInAddFieldOptions.DefaultValue)) { diff --git a/SPMeta2/SPMeta2.Regression.CSOM/Validation/ClientRegionalSettingsDefinitionValidator.cs b/SPMeta2/SPMeta2.Regression.CSOM/Validation/ClientRegionalSettingsDefinitionValidator.cs index 1ac0fd59e..d32891f40 100644 --- a/SPMeta2/SPMeta2.Regression.CSOM/Validation/ClientRegionalSettingsDefinitionValidator.cs +++ b/SPMeta2/SPMeta2.Regression.CSOM/Validation/ClientRegionalSettingsDefinitionValidator.cs @@ -50,21 +50,95 @@ public override void DeployModel(object modelHost, DefinitionBase model) } else { + if (definition.CalendarType.HasValue) + assert.ShouldBeEqual(m => m.CalendarType, o => o.CalendarType); + else + assert.SkipProperty(m => m.CalendarType, "CalendarType is null or empty"); - assert - .ShouldBeEqual(m => m.AdjustHijriDays, o => o.AdjustHijriDays) - .ShouldBeEqual(m => m.AlternateCalendarType, o => o.AlternateCalendarType) - .ShouldBeEqual(m => m.CalendarType, o => o.CalendarType) - .ShouldBeEqual(m => m.Collation, o => o.Collation) - .ShouldBeEqual(m => m.FirstDayOfWeek, o => o.FirstDayOfWeek) - .ShouldBeEqual(m => m.FirstWeekOfYear, o => o.FirstWeekOfYear) - .ShouldBeEqual(m => m.LocaleId, o => o.LocaleId) - // weird stuff with these props - //.ShouldBeEqual(m => m.WorkDayEndHour, o => o.WorkDayEndHour) - //.ShouldBeEqual(m => m.WorkDayStartHour, o => o.WorkDayStartHour) - .ShouldBeEqual(m => m.WorkDays, o => o.WorkDays) - .ShouldBeEqual(m => m.ShowWeeks, o => o.ShowWeeks) - .ShouldBeEqual(m => m.Time24, o => o.Time24); + if (definition.AlternateCalendarType.HasValue) + assert.ShouldBeEqual(m => m.AlternateCalendarType, o => o.AlternateCalendarType); + else + assert.SkipProperty(m => m.AlternateCalendarType, "AlternateCalendarType is null or empty"); + + if (definition.AdjustHijriDays.HasValue) + assert.ShouldBeEqual(m => m.AdjustHijriDays, o => o.AdjustHijriDays); + else + assert.SkipProperty(m => m.AdjustHijriDays, "AdjustHijriDays is null or empty"); + + if (definition.Collation.HasValue) + assert.ShouldBeEqual(m => m.Collation, o => o.Collation); + else + assert.SkipProperty(m => m.Collation, "Collation is null or empty"); + + if (definition.WorkDayStartHour.HasValue) + { + assert.ShouldBeEqual((p, s, d) => + { + var srcProp = s.GetExpressionValue(m => m.WorkDayStartHour); + // WHAT?? why minutes?? + var isValid = s.WorkDayStartHour == d.WorkDayStartHour / 60; + + return new PropertyValidationResult + { + Tag = p.Tag, + Src = srcProp, + Dst = null, + IsValid = isValid + }; + }); + } + else + assert.SkipProperty(m => m.WorkDayStartHour, "WorkDayStartHour is null or empty"); + + if (definition.WorkDayEndHour.HasValue) + { + assert.ShouldBeEqual((p, s, d) => + { + var srcProp = s.GetExpressionValue(m => m.WorkDayEndHour); + // WHAT?? why minutes?? + var isValid = s.WorkDayEndHour == d.WorkDayEndHour / 60; + + return new PropertyValidationResult + { + Tag = p.Tag, + Src = srcProp, + Dst = null, + IsValid = isValid + }; + }); + } + else + assert.SkipProperty(m => m.WorkDayEndHour, "WorkDayEndHour is null or empty"); + + if (definition.WorkDays.HasValue) + assert.ShouldBeEqual(m => m.WorkDays, o => o.WorkDays); + else + assert.SkipProperty(m => m.WorkDays, "WorkDays is null or empty"); + + if (definition.Time24.HasValue) + assert.ShouldBeEqual(m => m.Time24, o => o.Time24); + else + assert.SkipProperty(m => m.Time24, "Time24 is null or empty"); + + if (definition.ShowWeeks.HasValue) + assert.ShouldBeEqual(m => m.ShowWeeks, o => o.ShowWeeks); + else + assert.SkipProperty(m => m.ShowWeeks, "ShowWeeks is null or empty"); + + if (definition.FirstDayOfWeek.HasValue) + assert.ShouldBeEqual(m => m.FirstWeekOfYear, o => o.FirstWeekOfYear); + else + assert.SkipProperty(m => m.FirstWeekOfYear, "FirstWeekOfYear is null or empty"); + + if (definition.FirstDayOfWeek.HasValue) + assert.ShouldBeEqual(m => m.FirstDayOfWeek, o => o.FirstDayOfWeek); + else + assert.SkipProperty(m => m.FirstDayOfWeek, "FirstDayOfWeek is null or empty"); + + if (definition.LocaleId.HasValue) + assert.ShouldBeEqual(m => m.LocaleId, o => o.LocaleId); + else + assert.SkipProperty(m => m.LocaleId, "LocaleId is null or empty"); if (definition.TimeZoneId.HasValue) { diff --git a/SPMeta2/SPMeta2.Regression.CSOM/Validation/WebPartDefinitionValidator.cs b/SPMeta2/SPMeta2.Regression.CSOM/Validation/WebPartDefinitionValidator.cs index 02ed01ba6..9183764de 100644 --- a/SPMeta2/SPMeta2.Regression.CSOM/Validation/WebPartDefinitionValidator.cs +++ b/SPMeta2/SPMeta2.Regression.CSOM/Validation/WebPartDefinitionValidator.cs @@ -1,369 +1,398 @@ -using System.Net; -using Microsoft.SharePoint.Client; -using SPMeta2.Containers.Assertion; -using SPMeta2.CSOM.ModelHandlers; -using SPMeta2.CSOM.ModelHosts; -using SPMeta2.Definitions; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using System.Text; -using System.Xml.Linq; -using SPMeta2.Attributes.Regression; -using SPMeta2.CSOM.Extensions; -using SPMeta2.Definitions.Base; -using SPMeta2.Enumerations; -using SPMeta2.Utils; -using SPMeta2.Services; - -namespace SPMeta2.Regression.CSOM.Validation -{ - public class WebPartDefinitionValidator : WebPartModelHandler - { - protected XDocument CurrentWebPartXml { get; set; } - - public override void DeployModel(object modelHost, DefinitionBase model) - { - var listItemModelHost = modelHost.WithAssertAndCast("modelHost", value => value.RequireNotNull()); - var definition = model.WithAssertAndCast("model", value => value.RequireNotNull()); - - var pageFile = listItemModelHost.HostFile; - var context = pageFile.Context; - - context.Load(pageFile); - context.ExecuteQueryWithTrace(); - - var siteServerUrl = listItemModelHost.HostSite.ServerRelativeUrl; - var webUrl = listItemModelHost.HostWeb.Url; - - var serverUrl = context.Url; - - if (siteServerUrl != "/") - serverUrl = context.Url.Split(new string[] { siteServerUrl }, StringSplitOptions.RemoveEmptyEntries)[0]; - - var absItemUrl = UrlUtility.CombineUrl(serverUrl, pageFile.ServerRelativeUrl); - - WithExistingWebPart(pageFile, definition, (spObject, spObjectDefintion) => - { +using System.Net; +using Microsoft.SharePoint.Client; +using SPMeta2.Containers.Assertion; +using SPMeta2.CSOM.ModelHandlers; +using SPMeta2.CSOM.ModelHosts; +using SPMeta2.Definitions; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Xml.Linq; +using SPMeta2.Attributes.Regression; +using SPMeta2.CSOM.Extensions; +using SPMeta2.Definitions.Base; +using SPMeta2.Enumerations; +using SPMeta2.Utils; +using SPMeta2.Services; + +namespace SPMeta2.Regression.CSOM.Validation +{ + public class WebPartDefinitionValidator : WebPartModelHandler + { + protected XDocument CurrentWebPartXml { get; set; } + + public override void DeployModel(object modelHost, DefinitionBase model) + { + var listItemModelHost = modelHost.WithAssertAndCast("modelHost", value => value.RequireNotNull()); + var definition = model.WithAssertAndCast("model", value => value.RequireNotNull()); + + var pageFile = listItemModelHost.HostFile; + var context = pageFile.Context; + + context.Load(pageFile); + context.ExecuteQueryWithTrace(); + + var siteServerUrl = listItemModelHost.HostSite.ServerRelativeUrl; + var webUrl = listItemModelHost.HostWeb.Url; + + var serverUrl = context.Url; + + if (siteServerUrl != "/") + serverUrl = context.Url.Split(new string[] { siteServerUrl }, StringSplitOptions.RemoveEmptyEntries)[0]; + + var absItemUrl = UrlUtility.CombineUrl(serverUrl, pageFile.ServerRelativeUrl); + + WithExistingWebPart(pageFile, definition, (spObject, spObjectDefintion) => + { var webpartExportUrl = UrlUtility.CombineUrl(new[]{ webUrl, "_vti_bin/exportwp.aspx?pageurl=" + absItemUrl + "&" + "guidstring=" + spObjectDefintion.Id.ToString() - }); - - var assert = ServiceFactory.AssertService - .NewAssert(model, definition, spObject) - .ShouldNotBeNull(spObject); - - var webClient = new WebClient(); - - if (context.Credentials != null) - { - webClient.Credentials = context.Credentials; - webClient.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f"); - } - else - webClient.UseDefaultCredentials = true; - - var webPartXmlString = webClient.DownloadString(webpartExportUrl); - CurrentWebPartXml = WebpartXmlExtensions.LoadWebpartXmlDocument(webPartXmlString); - - - assert.ShouldBeEqual(m => m.Title, o => o.Title); - - // checking the web part type, shoul be as expected - // Add regression on 'expected' web part type #690 - - var currentType = CurrentWebPartXml.GetWebPartAssemblyQualifiedName(); - var currentClassName = currentType.Split(',').First().Trim(); - - var expectedTypeAttr = (definition.GetType().GetCustomAttributes(typeof(ExpectWebpartType)) - .FirstOrDefault() as ExpectWebpartType); - - // NULL can be on generic web part - // test should not care about that case, there other tests to enfore that attr usage - 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 = CurrentWebPartXml.GetProperty(prop.Name); - - // that True / true issue give a pain - // toLower for the time being - isValid = value.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.ExportMode)) - { - var value = CurrentWebPartXml.GetExportMode(); - - assert.ShouldBeEqual((p, s, d) => - { - var srcProp = s.GetExpressionValue(m => m.ExportMode); - var isValid = definition.ExportMode == value; - - return new PropertyValidationResult - { - Tag = p.Tag, - Src = srcProp, - Dst = null, - IsValid = isValid - }; - }); - } - else - assert.SkipProperty(m => m.ExportMode, "ExportMode is null or empty. Skipping."); - - if (!string.IsNullOrEmpty(definition.ChromeState)) - { - var value = CurrentWebPartXml.GetChromeState(); - - assert.ShouldBeEqual((p, s, d) => - { - var srcProp = s.GetExpressionValue(m => m.ChromeState); - var isValid = definition.ChromeState == value; - - return new PropertyValidationResult - { - Tag = p.Tag, - Src = srcProp, - Dst = null, - IsValid = isValid - }; - }); - } - else - assert.SkipProperty(m => m.ChromeState, "ChromeState is null or empty. Skipping."); - - if (!string.IsNullOrEmpty(definition.ChromeType)) - { - // returns correct one depending on the V2/V3 - var value = CurrentWebPartXml.GetChromeType(); - - var chromeType = string.Empty; - - if (CurrentWebPartXml.IsV3version()) - chromeType = WebPartChromeTypesConvertService.NormilizeValueToPartChromeTypes(definition.ChromeType); - else if (CurrentWebPartXml.IsV2version()) - chromeType = WebPartChromeTypesConvertService.NormilizeValueToFrameTypes(definition.ChromeType); - - assert.ShouldBeEqual((p, s, d) => - { - var srcProp = s.GetExpressionValue(m => m.ChromeType); - var isValid = chromeType == value; - - 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)) - { - var value = CurrentWebPartXml.GetProperty("Description"); - - assert.ShouldBeEqual((p, s, d) => - { - var srcProp = s.GetExpressionValue(m => m.Description); - var isValid = (srcProp.Value as string) == value; - - return new PropertyValidationResult - { - Tag = p.Tag, - Src = srcProp, - Dst = null, - IsValid = isValid - }; - }); - } - else - { - assert.SkipProperty(m => m.Description, "Description is null or empty. Skipping."); - } - - if (definition.Height.HasValue) - { - var value = ConvertUtils.ToInt(CurrentWebPartXml.GetProperty("Height").Replace("px", string.Empty)); - - assert.ShouldBeEqual((p, s, d) => - { - var srcProp = s.GetExpressionValue(m => m.Height); - var isValid = definition.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) - { - var value = ConvertUtils.ToInt(CurrentWebPartXml.GetProperty("Width").Replace("px", string.Empty)); - - assert.ShouldBeEqual((p, s, d) => - { - var srcProp = s.GetExpressionValue(m => m.Width); - var isValid = definition.Width == value; - - return new PropertyValidationResult - { - Tag = p.Tag, - Src = srcProp, - Dst = null, - IsValid = isValid - }; - }); - } - else - { - assert.SkipProperty(m => m.Width, "Width is NULL, skipping"); - } - - if (!string.IsNullOrEmpty(definition.ImportErrorMessage)) - { - var value = CurrentWebPartXml.GetImportErrorMessage(); - - assert.ShouldBeEqual((p, s, d) => - { - var srcProp = s.GetExpressionValue(m => m.ImportErrorMessage); - var isValid = definition.ImportErrorMessage == value; - - return new PropertyValidationResult - { - Tag = p.Tag, - Src = srcProp, - Dst = null, - IsValid = isValid - }; - }); - } - else - assert.SkipProperty(m => m.ImportErrorMessage, "ImportErrorMessage is null or empty. Skipping."); - - if (!string.IsNullOrEmpty(definition.TitleIconImageUrl)) - { - var value = CurrentWebPartXml.GetTitleIconImageUrl(); - - assert.ShouldBeEqual((p, s, d) => - { - var srcProp = s.GetExpressionValue(m => m.TitleIconImageUrl); - var isValid = definition.TitleIconImageUrl == value; - - return new PropertyValidationResult - { - Tag = p.Tag, - Src = srcProp, - Dst = null, - IsValid = isValid - }; - }); - } - else - assert.SkipProperty(m => m.TitleIconImageUrl, "TitleIconImageUrl is null or empty. Skipping."); - - if (!string.IsNullOrEmpty(definition.TitleUrl)) - { - var value = CurrentWebPartXml.GetTitleUrl(); - var defValue = TokenReplacementService.ReplaceTokens(new TokenReplacementContext - { - Context = listItemModelHost, - Value = value - }).Value; - - var isValid = defValue.ToUpper() == value.ToUpper(); - - assert.ShouldBeEqual((p, s, d) => - { - var srcProp = s.GetExpressionValue(m => m.TitleUrl); - - return new PropertyValidationResult - { - Tag = p.Tag, - Src = srcProp, - Dst = null, - IsValid = isValid - }; - }); - } - else - assert.SkipProperty(m => m.TitleUrl, "TitleUrl is null or empty. Skipping."); - - - assert.SkipProperty(m => m.WebpartFileName, "WebpartFileName is null or empty. Skipping."); - assert.SkipProperty(m => m.WebpartType, "WebpartType is null or empty. Skipping."); - assert.SkipProperty(m => m.WebpartXmlTemplate, "WebpartXmlTemplate is null or empty. Skipping."); - - assert.SkipProperty(m => m.ZoneId, "ZoneId is null or empty. Skipping."); - assert.SkipProperty(m => m.ZoneIndex, "ZoneIndex is null or empty. Skipping."); - - assert.SkipProperty(m => m.Id, "Id is null or empty. Skipping."); - - if (definition.ParameterBindings.Count == 0) - { - assert.SkipProperty(m => m.ParameterBindings, "ParameterBindings is null or empty. Skipping."); - } - else - { - // TODO + }); + + var assert = ServiceFactory.AssertService + .NewAssert(model, definition, spObject) + .ShouldNotBeNull(spObject); + + var webClient = new WebClient(); + + if (context.Credentials != null) + { + webClient.Credentials = context.Credentials; + webClient.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f"); + } + else + webClient.UseDefaultCredentials = true; + + var webPartXmlString = webClient.DownloadString(webpartExportUrl); + CurrentWebPartXml = WebpartXmlExtensions.LoadWebpartXmlDocument(webPartXmlString); + + + assert.ShouldBeEqual(m => m.Title, o => o.Title); + + // checking the web part type, shoul be as expected + // Add regression on 'expected' web part type #690 + + var currentType = CurrentWebPartXml.GetWebPartAssemblyQualifiedName(); + var currentClassName = currentType.Split(',').First().Trim(); + + var expectedTypeAttr = (definition.GetType().GetCustomAttributes(typeof(ExpectWebpartType)) + .FirstOrDefault() as ExpectWebpartType); + + // NULL can be on generic web part + // test should not care about that case, there other tests to enfore that attr usage + 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 = CurrentWebPartXml.GetProperty(prop.Name); + + // that True / true issue give a pain + // toLower for the time being + isValid = value.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.ExportMode)) + { + var value = CurrentWebPartXml.GetExportMode(); + + assert.ShouldBeEqual((p, s, d) => + { + var srcProp = s.GetExpressionValue(m => m.ExportMode); + var isValid = definition.ExportMode == value; + + return new PropertyValidationResult + { + Tag = p.Tag, + Src = srcProp, + Dst = null, + IsValid = isValid + }; + }); + } + else + assert.SkipProperty(m => m.ExportMode, "ExportMode is null or empty. Skipping."); + + if (!string.IsNullOrEmpty(definition.ChromeState)) + { + var value = CurrentWebPartXml.GetChromeState(); + + assert.ShouldBeEqual((p, s, d) => + { + var srcProp = s.GetExpressionValue(m => m.ChromeState); + var isValid = definition.ChromeState == value; + + return new PropertyValidationResult + { + Tag = p.Tag, + Src = srcProp, + Dst = null, + IsValid = isValid + }; + }); + } + else + assert.SkipProperty(m => m.ChromeState, "ChromeState is null or empty. Skipping."); + + if (!string.IsNullOrEmpty(definition.ChromeType)) + { + // returns correct one depending on the V2/V3 + var value = CurrentWebPartXml.GetChromeType(); + + var chromeType = string.Empty; + + if (CurrentWebPartXml.IsV3version()) + chromeType = WebPartChromeTypesConvertService.NormilizeValueToPartChromeTypes(definition.ChromeType); + else if (CurrentWebPartXml.IsV2version()) + chromeType = WebPartChromeTypesConvertService.NormilizeValueToFrameTypes(definition.ChromeType); + + assert.ShouldBeEqual((p, s, d) => + { + var srcProp = s.GetExpressionValue(m => m.ChromeType); + var isValid = chromeType == value; + + 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)) + { + var value = CurrentWebPartXml.GetProperty("Description"); + + assert.ShouldBeEqual((p, s, d) => + { + var srcProp = s.GetExpressionValue(m => m.Description); + var isValid = (srcProp.Value as string) == value; + + return new PropertyValidationResult + { + Tag = p.Tag, + Src = srcProp, + Dst = null, + IsValid = isValid + }; + }); + } + else + { + assert.SkipProperty(m => m.Description, "Description is null or empty. Skipping."); + } + + if (definition.Height.HasValue) + { + var value = ConvertUtils.ToInt(CurrentWebPartXml.GetProperty("Height").Replace("px", string.Empty)); + + assert.ShouldBeEqual((p, s, d) => + { + var srcProp = s.GetExpressionValue(m => m.Height); + var isValid = definition.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) + { + var value = ConvertUtils.ToInt(CurrentWebPartXml.GetProperty("Width").Replace("px", string.Empty)); + + assert.ShouldBeEqual((p, s, d) => + { + var srcProp = s.GetExpressionValue(m => m.Width); + var isValid = definition.Width == value; + + return new PropertyValidationResult + { + Tag = p.Tag, + Src = srcProp, + Dst = null, + IsValid = isValid + }; + }); + } + else + { + assert.SkipProperty(m => m.Width, "Width is NULL, skipping"); + } + + if (!string.IsNullOrEmpty(definition.ImportErrorMessage)) + { + var value = CurrentWebPartXml.GetImportErrorMessage(); + + assert.ShouldBeEqual((p, s, d) => + { + var srcProp = s.GetExpressionValue(m => m.ImportErrorMessage); + var isValid = definition.ImportErrorMessage == value; + + return new PropertyValidationResult + { + Tag = p.Tag, + Src = srcProp, + Dst = null, + IsValid = isValid + }; + }); + } + else + assert.SkipProperty(m => m.ImportErrorMessage, "ImportErrorMessage is null or empty. Skipping."); + + if (!string.IsNullOrEmpty(definition.TitleIconImageUrl)) + { + var value = CurrentWebPartXml.GetTitleIconImageUrl(); + + assert.ShouldBeEqual((p, s, d) => + { + var srcProp = s.GetExpressionValue(m => m.TitleIconImageUrl); + var isValid = definition.TitleIconImageUrl == value; + + return new PropertyValidationResult + { + Tag = p.Tag, + Src = srcProp, + Dst = null, + IsValid = isValid + }; + }); + } + else + assert.SkipProperty(m => m.TitleIconImageUrl, "TitleIconImageUrl is null or empty. Skipping."); + + if (!string.IsNullOrEmpty(definition.TitleUrl)) + { + var value = CurrentWebPartXml.GetTitleUrl(); + var defValue = TokenReplacementService.ReplaceTokens(new TokenReplacementContext + { + Context = listItemModelHost, + Value = value + }).Value; + + var isValid = defValue.ToUpper() == value.ToUpper(); + + assert.ShouldBeEqual((p, s, d) => + { + var srcProp = s.GetExpressionValue(m => m.TitleUrl); + + return new PropertyValidationResult + { + Tag = p.Tag, + Src = srcProp, + Dst = null, + IsValid = isValid + }; + }); + } + else + assert.SkipProperty(m => m.TitleUrl, "TitleUrl is null or empty. Skipping."); + + + assert.SkipProperty(m => m.WebpartFileName, "WebpartFileName is null or empty. Skipping."); + assert.SkipProperty(m => m.WebpartType, "WebpartType is null or empty. Skipping."); + assert.SkipProperty(m => m.WebpartXmlTemplate, "WebpartXmlTemplate is null or empty. Skipping."); + + assert.SkipProperty(m => m.ZoneId, "ZoneId is null or empty. Skipping."); + assert.SkipProperty(m => m.ZoneIndex, "ZoneIndex is null or empty. Skipping."); + + assert.SkipProperty(m => m.Id, "Id is null or empty. Skipping."); + + if (definition.ParameterBindings.Count == 0) + { + assert.SkipProperty(m => m.ParameterBindings, "ParameterBindings is null or empty. Skipping."); + } + else + { + assert.ShouldBeEqual((p, s, d) => + { + // that's a fast hack + // hope we eoudn't have other web part with ParameterBindings :) + var webPartBindings = CurrentWebPartXml.GetProperty("ParameterBindings"); + var isValid = true; + + var srcProp = s.GetExpressionValue(m => m.ParameterBindings); + + // one more hack, fix up later + // just checking presense of the strings + foreach (var srcBinding in s.ParameterBindings) + { + var hasName = webPartBindings.Contains(srcBinding.Name); + var hasValue = webPartBindings.Contains(srcBinding.Location); + + if (!hasName || !hasValue) + { + isValid = false; + } + } + + return new PropertyValidationResult + { + Tag = p.Tag, + Src = srcProp, + Dst = null, + IsValid = isValid + }; + }); } if (!string.IsNullOrEmpty(definition.AuthorizationFilter)) @@ -387,9 +416,9 @@ public override void DeployModel(object modelHost, DefinitionBase model) else { assert.SkipProperty(m => m.AuthorizationFilter, "AuthorizationFilter is null or empty. Skipping."); - } - - }); - } - } -} + } + + }); + } + } +} diff --git a/SPMeta2/SPMeta2.Regression.Impl.Tests/Properties/AssemblyInfo.cs b/SPMeta2/SPMeta2.Regression.Impl.Tests/Properties/AssemblyInfo.cs index 3f3c34d62..2b02549d0 100644 --- a/SPMeta2/SPMeta2.Regression.Impl.Tests/Properties/AssemblyInfo.cs +++ b/SPMeta2/SPMeta2.Regression.Impl.Tests/Properties/AssemblyInfo.cs @@ -33,4 +33,4 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.2.16298.0736")] +[assembly: AssemblyFileVersion("1.2.16305.1232")] diff --git a/SPMeta2/SPMeta2.Regression.SSOM.Standard/Properties/AssemblyInfo.cs b/SPMeta2/SPMeta2.Regression.SSOM.Standard/Properties/AssemblyInfo.cs index 7493d05a0..4a4342246 100644 --- a/SPMeta2/SPMeta2.Regression.SSOM.Standard/Properties/AssemblyInfo.cs +++ b/SPMeta2/SPMeta2.Regression.SSOM.Standard/Properties/AssemblyInfo.cs @@ -33,4 +33,4 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.2.16298.0736")] +[assembly: AssemblyFileVersion("1.2.16305.1232")] diff --git a/SPMeta2/SPMeta2.Regression.SSOM.Standard/Validation/DesignPackageDefinitionValidator.cs b/SPMeta2/SPMeta2.Regression.SSOM.Standard/Validation/DesignPackageDefinitionValidator.cs index d89f6b665..87001ad13 100644 --- a/SPMeta2/SPMeta2.Regression.SSOM.Standard/Validation/DesignPackageDefinitionValidator.cs +++ b/SPMeta2/SPMeta2.Regression.SSOM.Standard/Validation/DesignPackageDefinitionValidator.cs @@ -3,10 +3,13 @@ using Microsoft.SharePoint.Publishing; using SPMeta2.Common; using SPMeta2.Definitions; +using SPMeta2.Regression.SSOM.Extensions; +using SPMeta2.Regression.SSOM.Validation; using SPMeta2.SSOM.ModelHosts; using SPMeta2.SSOM.Standard.ModelHandlers; using SPMeta2.Standard.Definitions; using SPMeta2.Utils; +using SPMeta2.Containers.Assertion; namespace SPMeta2.Regression.SSOM.Standard.Validation { @@ -19,13 +22,66 @@ public override void DeployModel(object modelHost, DefinitionBase model) var siteModelHost = modelHost.WithAssertAndCast("modelHost", value => value.RequireNotNull()); var definition = model.WithAssertAndCast("model", value => value.RequireNotNull()); - // TODO + var site = siteModelHost.HostSite; + var rootWeb = site.RootWeb; - DesignPackageInfo spObject = null; + var spObject = FindExistingSolutionById(siteModelHost, definition.SolutionId); - var assert = ServiceFactory.AssertService - .NewAssert(definition, spObject) - .ShouldNotBeNull(spObject); + var assert = ServiceFactory.AssertService.NewAssert(definition, definition, spObject) + .ShouldNotBeNull(spObject) + .ShouldBeEqual(m => m.SolutionId, o => o.SolutionId) + .SkipProperty(m => m.FileName, "Solution should be deployed fine.") + .SkipProperty(m => m.Content, "Solution should be deployed fine."); + + if (definition.Apply) + { + assert.ShouldBeEqual((p, s, d) => + { + // once applied, design package sets AppliedDesignGuid property in the root web + // checking is all good + var installedPackageId = ConvertUtils.ToGuid(rootWeb.AllProperties["AppliedDesignGuid"]); + + var srcProp = s.GetExpressionValue(m => m.Apply); + var isValid = spObject != null + && installedPackageId == definition.SolutionId; + + return new PropertyValidationResult + { + Tag = p.Tag, + Src = srcProp, + Dst = null, + IsValid = isValid + }; + }); + } + else + { + assert.SkipProperty(m => m.Apply, "Apply is false"); + } + + if (definition.Install) + { + assert.ShouldBeEqual((p, s, d) => + { + var srcProp = s.GetExpressionValue(m => m.Install); + var isValid = spObject != null; + + return new PropertyValidationResult + { + Tag = p.Tag, + Src = srcProp, + Dst = null, + IsValid = isValid + }; + }); + } + else + { + assert.SkipProperty(m => m.Install, "Install is false"); + } + + assert.SkipProperty(m => m.MajorVersion, string.Empty); + assert.SkipProperty(m => m.MinorVersion, string.Empty); } #endregion diff --git a/SPMeta2/SPMeta2.Regression.SSOM/Extensions/SPUserSolutionExtensions.cs b/SPMeta2/SPMeta2.Regression.SSOM/Extensions/SPUserSolutionExtensions.cs index b4e45e72a..1cee5065d 100644 --- a/SPMeta2/SPMeta2.Regression.SSOM/Extensions/SPUserSolutionExtensions.cs +++ b/SPMeta2/SPMeta2.Regression.SSOM/Extensions/SPUserSolutionExtensions.cs @@ -1,17 +1,17 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -using Microsoft.SharePoint; - -namespace SPMeta2.Regression.SSOM.Extensions -{ - internal static class SPUserSolutionExtensions - { - public static bool IsActivated(this SPUserSolution solution) - { - return solution.Status == SPUserSolutionStatus.Activated; - } - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +using Microsoft.SharePoint; + +namespace SPMeta2.Regression.SSOM.Extensions +{ + public static class SPUserSolutionExtensions + { + public static bool IsActivated(this SPUserSolution solution) + { + return solution.Status == SPUserSolutionStatus.Activated; + } + } +} diff --git a/SPMeta2/SPMeta2.Regression.SSOM/Properties/AssemblyInfo.cs b/SPMeta2/SPMeta2.Regression.SSOM/Properties/AssemblyInfo.cs index a5ee5c712..775aefb01 100644 --- a/SPMeta2/SPMeta2.Regression.SSOM/Properties/AssemblyInfo.cs +++ b/SPMeta2/SPMeta2.Regression.SSOM/Properties/AssemblyInfo.cs @@ -33,4 +33,4 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.2.16298.0736")] +[assembly: AssemblyFileVersion("1.2.16305.1232")] diff --git a/SPMeta2/SPMeta2.Regression.SSOM/Validation/FarmSolutionDefinitionValidator.cs b/SPMeta2/SPMeta2.Regression.SSOM/Validation/FarmSolutionDefinitionValidator.cs index 24b3242a7..582525a2c 100644 --- a/SPMeta2/SPMeta2.Regression.SSOM/Validation/FarmSolutionDefinitionValidator.cs +++ b/SPMeta2/SPMeta2.Regression.SSOM/Validation/FarmSolutionDefinitionValidator.cs @@ -1,26 +1,230 @@ -using SPMeta2.Definitions; -using SPMeta2.SSOM.ModelHandlers; - -using SPMeta2.Utils; -using SPMeta2.SSOM.ModelHosts; - -namespace SPMeta2.Regression.SSOM.Validation -{ - public class FarmSolutionDefinitionValidator : FarmSolutionModelHandler - { - public override void DeployModel(object modelHost, DefinitionBase model) - { - var definition = model.WithAssertAndCast("model", value => value.RequireNotNull()); - var farmModelHost = modelHost.WithAssertAndCast("modelHost", value => value.RequireNotNull()); - - var solution = FindExistingSolution(farmModelHost, definition); - - ServiceFactory.AssertService - .NewAssert(definition, definition, solution) - .ShouldNotBeNull(solution) - .SkipProperty(m => m.FileName, "Skipping FileName property.") - .ShouldBeEqual(m => m.SolutionId, o => o.SolutionId) - .SkipProperty(m => m.Content, "Skipping Content property."); - } - } -} +using SPMeta2.Definitions; +using SPMeta2.SSOM.ModelHandlers; + +using SPMeta2.Utils; +using SPMeta2.SSOM.ModelHosts; +using SPMeta2.Containers.Assertion; +using SPMeta2.Extensions; + +namespace SPMeta2.Regression.SSOM.Validation +{ + public class FarmSolutionDefinitionValidator : FarmSolutionModelHandler + { + #region constructors + public FarmSolutionDefinitionValidator() + { + + } + + #endregion + + #region methods + public override void DeployModel(object modelHost, DefinitionBase model) + { + var definition = model.WithAssertAndCast("model", value => value.RequireNotNull()); + var farmModelHost = modelHost.WithAssertAndCast("modelHost", value => value.RequireNotNull()); + + var solution = FindExistingSolution(farmModelHost, definition); + + var assert = ServiceFactory.AssertService + .NewAssert(definition, definition, solution); + + if (definition.ShouldDelete == true + && !definition.ShouldDeploy.HasValue) + { + // DELETE OPERATION + + // solution has to be NULL + assert.ShouldBeNull(solution); + + assert.SkipProperty(m => m.UpgradeDate, "ShouldDelete = true"); + assert.SkipProperty(m => m.DeploymentDate, "ShouldDelete = true"); + + assert.SkipProperty(m => m.DeploymentForce, "ShouldDelete = true"); + assert.SkipProperty(m => m.DeploymentGlobalInstallWPPackDlls, "ShouldDelete = true"); + assert.SkipProperty(m => m.LCID, "ShouldDelete = true"); + + assert.SkipProperty(m => m.Content, "ShouldDelete = true"); + assert.SkipProperty(m => m.FileName, "ShouldDelete = true"); + assert.SkipProperty(m => m.SolutionId, "ShouldDelete = true"); + + assert.SkipProperty(m => m.ShouldAdd, "ShouldDelete = true"); + assert.SkipProperty(m => m.ShouldDelete, "ShouldDelete = true"); + assert.SkipProperty(m => m.ShouldDeploy, "ShouldDelete = true"); + assert.SkipProperty(m => m.ShouldRetract, "ShouldDelete = true"); + assert.SkipProperty(m => m.ShouldUpgrade, "ShouldDelete = true"); + + return; + } + + if (definition.ShouldRetract == true) + { + // RETRACT OPERATION + assert.ShouldNotBeNull(solution); + + assert.SkipProperty(m => m.UpgradeDate, "ShouldDelete = true"); + assert.SkipProperty(m => m.DeploymentDate, "ShouldDelete = true"); + + assert.SkipProperty(m => m.DeploymentForce, "ShouldDelete = true"); + assert.SkipProperty(m => m.DeploymentGlobalInstallWPPackDlls, "ShouldDelete = true"); + assert.SkipProperty(m => m.LCID, "ShouldDelete = true"); + + assert.SkipProperty(m => m.Content, "ShouldDelete = true"); + assert.SkipProperty(m => m.FileName, "ShouldDelete = true"); + assert.SkipProperty(m => m.SolutionId, "ShouldDelete = true"); + + assert.SkipProperty(m => m.ShouldAdd, "ShouldDelete = true"); + assert.SkipProperty(m => m.ShouldDelete, "ShouldDelete = true"); + assert.SkipProperty(m => m.ShouldDeploy, "ShouldDelete = true"); + //assert.SkipProperty(m => m.ShouldRetract, "ShouldDelete = true"); + assert.SkipProperty(m => m.ShouldUpgrade, "ShouldDelete = true"); + + // should be deployed state + assert.ShouldBeEqual((p, s, d) => + { + var srcProp = s.GetExpressionValue(def => def.ShouldRetract); + + var isValid = d.Deployed == false + && definition.HasPropertyBagValue("HadRetractHit"); + + return new PropertyValidationResult + { + Tag = p.Tag, + Src = srcProp, + Dst = null, + IsValid = isValid + }; + }); + + return; + } + + if (definition.ShouldUpgrade == true) + { + // UPGRADE OPERATION + assert.ShouldNotBeNull(solution); + + assert.SkipProperty(m => m.UpgradeDate, "ShouldDelete = true"); + assert.SkipProperty(m => m.DeploymentDate, "ShouldDelete = true"); + + assert.SkipProperty(m => m.DeploymentForce, "ShouldDelete = true"); + assert.SkipProperty(m => m.DeploymentGlobalInstallWPPackDlls, "ShouldDelete = true"); + assert.SkipProperty(m => m.LCID, "ShouldDelete = true"); + + assert.SkipProperty(m => m.Content, "ShouldDelete = true"); + assert.SkipProperty(m => m.FileName, "ShouldDelete = true"); + assert.SkipProperty(m => m.SolutionId, "ShouldDelete = true"); + + assert.SkipProperty(m => m.ShouldAdd, "ShouldDelete = true"); + assert.SkipProperty(m => m.ShouldDelete, "ShouldDelete = true"); + assert.SkipProperty(m => m.ShouldDeploy, "ShouldDelete = true"); + assert.SkipProperty(m => m.ShouldRetract, "ShouldDelete = true"); + //assert.SkipProperty(m => m.ShouldUpgrade, "ShouldDelete = true"); + + // should be deployed state + assert.ShouldBeEqual((p, s, d) => + { + var srcProp = s.GetExpressionValue(def => def.ShouldUpgrade); + + var isValid = definition.HasPropertyBagValue("HadUpgradetHit"); + + return new PropertyValidationResult + { + Tag = p.Tag, + Src = srcProp, + Dst = null, + IsValid = isValid + }; + }); + + return; + } + + if (definition.ShouldDeploy == true) + { + // DEPLOY OPERATION + assert.ShouldNotBeNull(solution); + + assert.SkipProperty(m => m.UpgradeDate, "ShouldDelete = true"); + assert.SkipProperty(m => m.DeploymentDate, "ShouldDelete = true"); + + assert.SkipProperty(m => m.DeploymentForce, "ShouldDelete = true"); + assert.SkipProperty(m => m.DeploymentGlobalInstallWPPackDlls, "ShouldDelete = true"); + assert.SkipProperty(m => m.LCID, "ShouldDelete = true"); + + assert.SkipProperty(m => m.Content, "ShouldDelete = true"); + assert.SkipProperty(m => m.FileName, "ShouldDelete = true"); + assert.SkipProperty(m => m.SolutionId, "ShouldDelete = true"); + + assert.SkipProperty(m => m.ShouldAdd, "ShouldDelete = true"); + assert.SkipProperty(m => m.ShouldDelete, "ShouldDelete = true"); + //assert.SkipProperty(m => m.ShouldDeploy, "ShouldDelete = true"); + assert.SkipProperty(m => m.ShouldRetract, "ShouldDelete = true"); + assert.SkipProperty(m => m.ShouldUpgrade, "ShouldDelete = true"); + + // should be deployed state + assert.ShouldBeEqual((p, s, d) => + { + var srcProp = s.GetExpressionValue(def => def.ShouldDeploy); + + var isValid = d.Deployed + && definition.HasPropertyBagValue("HadDeploymentHit"); + + return new PropertyValidationResult + { + Tag = p.Tag, + Src = srcProp, + Dst = null, + IsValid = isValid + }; + }); + + return; + } + + assert.ShouldNotBeNull(solution) + //.ShouldBeEqual(m => m.FileName, o => o.Name) + .SkipProperty(m => m.FileName, "Skipping Name props. It might be different as the same SolutionId could be deployment in the farm.") + .ShouldBeEqual(m => m.SolutionId, o => o.SolutionId) + .SkipProperty(m => m.Content, "Skipping Content property."); + + assert.SkipProperty(m => m.ShouldAdd, "ShouldAdd"); + assert.SkipProperty(m => m.ShouldDelete, "ShouldDelete"); + assert.SkipProperty(m => m.ShouldDeploy, "ShouldDeploy"); + assert.SkipProperty(m => m.ShouldRetract, "ShouldRetract"); + assert.SkipProperty(m => m.ShouldUpgrade, "ShouldUpgrade"); + + assert.SkipProperty(m => m.DeploymentForce); + assert.SkipProperty(m => m.DeploymentGlobalInstallWPPackDlls); + + if (definition.LCID.HasValue) + { + // TODO + } + else + { + assert.SkipProperty(m => m.LCID, "LCID is NULL"); + } + + + if (definition.DeploymentDate.HasValue) + { + // TODO + } + else + { + assert.SkipProperty(m => m.DeploymentDate, "DeploymentDate is NULL"); + } + + if (definition.UpgradeDate.HasValue) + { + // TODO + } + else + { + assert.SkipProperty(m => m.UpgradeDate, "UpgradeDate is NULL"); + } + } + #endregion + } +} diff --git a/SPMeta2/SPMeta2.Regression.SSOM/Validation/FieldDefinitionValidator.cs b/SPMeta2/SPMeta2.Regression.SSOM/Validation/FieldDefinitionValidator.cs index 5b2383cc2..a547cf45c 100644 --- a/SPMeta2/SPMeta2.Regression.SSOM/Validation/FieldDefinitionValidator.cs +++ b/SPMeta2/SPMeta2.Regression.SSOM/Validation/FieldDefinitionValidator.cs @@ -339,6 +339,9 @@ protected void ValidateField(AssertPair assert, SPFiel { assert.SkipProperty(m => m.DescriptionResource, "DescriptionResource is NULL or empty. Skipping."); } + + assert.SkipProperty(m => m.PushChangesToLists, + "Covered by 'Regression.Scenarios.Fields.PushChangesToLists' test category"); } } } diff --git a/SPMeta2/SPMeta2.Regression.SSOM/Validation/ListFieldLinkDefinitionValidator.cs b/SPMeta2/SPMeta2.Regression.SSOM/Validation/ListFieldLinkDefinitionValidator.cs index ddac097ef..d096ba246 100644 --- a/SPMeta2/SPMeta2.Regression.SSOM/Validation/ListFieldLinkDefinitionValidator.cs +++ b/SPMeta2/SPMeta2.Regression.SSOM/Validation/ListFieldLinkDefinitionValidator.cs @@ -1,138 +1,167 @@ -using Microsoft.SharePoint; -using Microsoft.SharePoint.Utilities; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using SPMeta2.Containers.Assertion; -using SPMeta2.Definitions; -using SPMeta2.SSOM.DefaultSyntax; -using SPMeta2.SSOM.ModelHandlers; -using SPMeta2.SSOM.ModelHosts; -using SPMeta2.Utils; -using System.Linq; -using SPMeta2.Enumerations; - -namespace SPMeta2.Regression.SSOM.Validation -{ - public class ListFieldLinkDefinitionValidator : ListFieldLinkModelHandler - { - public override void DeployModel(object modelHost, DefinitionBase model) - { - var listModelHost = modelHost.WithAssertAndCast("modelHost", value => value.RequireNotNull()); - var definition = model.WithAssertAndCast("model", value => value.RequireNotNull()); - - var list = listModelHost.HostList; - var spObject = FindExistingListField(list, definition); - - var assert = ServiceFactory.AssertService - .NewAssert(definition, spObject) - .ShouldNotBeNull(spObject); - - if (!string.IsNullOrEmpty(definition.FieldInternalName)) - assert.ShouldBeEqual(m => m.FieldInternalName, o => o.InternalName); - else - assert.SkipProperty(m => m.FieldInternalName, "FieldInternalName is null or empty. Skipping"); - - if (definition.FieldId.HasGuidValue()) - assert.ShouldBeEqual(m => m.FieldId, o => o.Id); - else - assert.SkipProperty(m => m.FieldId, "FieldId is null or empty. Skipping"); - - if (!string.IsNullOrEmpty(definition.DisplayName)) - assert.ShouldBeEqual(m => m.DisplayName, o => o.Title); - else - assert.SkipProperty(m => m.DisplayName, "DisplayName is null or empty. Skipping"); - - if (definition.Required.HasValue) - assert.ShouldBeEqual(m => m.Required, o => o.Required); - else - assert.SkipProperty(m => m.Required, "Required is null or empty. Skipping"); - - if (definition.Hidden.HasValue) - assert.ShouldBeEqual(m => m.Hidden, o => o.Hidden); - else - assert.SkipProperty(m => m.Hidden, "Hidden is null or empty. Skipping"); - - if (definition.AddFieldOptions.HasFlag(BuiltInAddFieldOptions.DefaultValue)) - { - assert.SkipProperty(m => m.AddFieldOptions, "BuiltInAddFieldOptions.DefaultValue. Skipping."); - } - - if (definition.AddFieldOptions.HasFlag(BuiltInAddFieldOptions.AddToAllContentTypes)) - { - assert.ShouldBeEqual((p, s, d) => - { - var srcProp = s.GetExpressionValue(m => m.AddFieldOptions); - var isValid = true; - - var listContentTypes = list.ContentTypes; - - foreach (SPContentType ct in listContentTypes) - { - // TODO! - if (ct.Name == "Folder") - { - // skip folder content type - continue; - } - - isValid = ct.FieldLinks.OfType().Count(l => l.Name == spObject.InternalName) > 0; - - if (!isValid) - break; - } - - return new PropertyValidationResult - { - Tag = p.Tag, - Src = srcProp, - Dst = null, - IsValid = isValid - }; - }); - } - - if (definition.AddFieldOptions.HasFlag(BuiltInAddFieldOptions.AddFieldToDefaultView)) - { - assert.ShouldBeEqual((p, s, d) => - { - var srcProp = s.GetExpressionValue(m => m.AddFieldOptions); - var isValid = false; - - return new PropertyValidationResult - { - Tag = p.Tag, - Src = srcProp, - Dst = null, - IsValid = isValid - }; - }); - } - - if (definition.AddToDefaultView) - { - assert.ShouldBeEqual((p, s, d) => - { - var srcProp = s.GetExpressionValue(m => m.AddToDefaultView); - var field = FindExistingListField(list, definition); - - var isValid = list.DefaultView - .ViewFields - .ToStringCollection() - .Contains(field.InternalName); - - return new PropertyValidationResult - { - Tag = p.Tag, - Src = srcProp, - Dst = null, - IsValid = isValid - }; - }); - } - else - { - assert.SkipProperty(m => m.AddToDefaultView, "AddToDefaultView is false. Skipping."); - } - - } - } -} +using Microsoft.SharePoint; +using Microsoft.SharePoint.Utilities; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using SPMeta2.Containers.Assertion; +using SPMeta2.Definitions; +using SPMeta2.SSOM.DefaultSyntax; +using SPMeta2.SSOM.ModelHandlers; +using SPMeta2.SSOM.ModelHosts; +using SPMeta2.Utils; +using System.Linq; +using SPMeta2.Enumerations; + +namespace SPMeta2.Regression.SSOM.Validation +{ + public class ListFieldLinkDefinitionValidator : ListFieldLinkModelHandler + { + public override void DeployModel(object modelHost, DefinitionBase model) + { + var listModelHost = modelHost.WithAssertAndCast("modelHost", value => value.RequireNotNull()); + var definition = model.WithAssertAndCast("model", value => value.RequireNotNull()); + + var list = listModelHost.HostList; + var spObject = FindExistingListField(list, definition); + + var assert = ServiceFactory.AssertService + .NewAssert(definition, spObject) + .ShouldNotBeNull(spObject); + + if (!string.IsNullOrEmpty(definition.FieldInternalName)) + assert.ShouldBeEqual(m => m.FieldInternalName, o => o.InternalName); + else + assert.SkipProperty(m => m.FieldInternalName, "FieldInternalName is null or empty. Skipping"); + + if (definition.FieldId.HasGuidValue()) + assert.ShouldBeEqual(m => m.FieldId, o => o.Id); + else + assert.SkipProperty(m => m.FieldId, "FieldId is null or empty. Skipping"); + + if (!string.IsNullOrEmpty(definition.DisplayName)) + assert.ShouldBeEqual(m => m.DisplayName, o => o.Title); + else + { + + var regDisplayTitleProp = definition.PropertyBag.FirstOrDefault(p => p.Name == "_Reg_DisplayName"); + + if (regDisplayTitleProp != null) + { + // Enhance FieldDefinition with 'pushChangesToLists' option #922 + // https://github.com/SubPointSolutions/spmeta2/issues/922 + + assert.ShouldBeEqual((p, s, d) => + { + var srcProp = s.GetExpressionValue(m => m.DisplayName); + var dstProp = d.GetExpressionValue(m => m.Title); + + var isValid = regDisplayTitleProp.Value == d.Title; + + return new PropertyValidationResult + { + Tag = p.Tag, + Src = srcProp, + Dst = null, + IsValid = isValid + }; + }); + } + else + { + assert.SkipProperty(m => m.DisplayName, "DisplayName is null or empty. Skipping"); + } + } + + if (definition.Required.HasValue) + assert.ShouldBeEqual(m => m.Required, o => o.Required); + else + assert.SkipProperty(m => m.Required, "Required is null or empty. Skipping"); + + if (definition.Hidden.HasValue) + assert.ShouldBeEqual(m => m.Hidden, o => o.Hidden); + else + assert.SkipProperty(m => m.Hidden, "Hidden is null or empty. Skipping"); + + if (definition.AddFieldOptions.HasFlag(BuiltInAddFieldOptions.DefaultValue)) + { + assert.SkipProperty(m => m.AddFieldOptions, "BuiltInAddFieldOptions.DefaultValue. Skipping."); + } + + if (definition.AddFieldOptions.HasFlag(BuiltInAddFieldOptions.AddToAllContentTypes)) + { + assert.ShouldBeEqual((p, s, d) => + { + var srcProp = s.GetExpressionValue(m => m.AddFieldOptions); + var isValid = true; + + var listContentTypes = list.ContentTypes; + + foreach (SPContentType ct in listContentTypes) + { + // TODO! + if (ct.Name == "Folder") + { + // skip folder content type + continue; + } + + isValid = ct.FieldLinks.OfType().Count(l => l.Name == spObject.InternalName) > 0; + + if (!isValid) + break; + } + + return new PropertyValidationResult + { + Tag = p.Tag, + Src = srcProp, + Dst = null, + IsValid = isValid + }; + }); + } + + if (definition.AddFieldOptions.HasFlag(BuiltInAddFieldOptions.AddFieldToDefaultView)) + { + assert.ShouldBeEqual((p, s, d) => + { + var srcProp = s.GetExpressionValue(m => m.AddFieldOptions); + var isValid = false; + + return new PropertyValidationResult + { + Tag = p.Tag, + Src = srcProp, + Dst = null, + IsValid = isValid + }; + }); + } + + if (definition.AddToDefaultView) + { + assert.ShouldBeEqual((p, s, d) => + { + var srcProp = s.GetExpressionValue(m => m.AddToDefaultView); + var field = FindExistingListField(list, definition); + + var isValid = list.DefaultView + .ViewFields + .ToStringCollection() + .Contains(field.InternalName); + + return new PropertyValidationResult + { + Tag = p.Tag, + Src = srcProp, + Dst = null, + IsValid = isValid + }; + }); + } + else + { + assert.SkipProperty(m => m.AddToDefaultView, "AddToDefaultView is false. Skipping."); + } + + } + } +} diff --git a/SPMeta2/SPMeta2.Regression.SSOM/Validation/RegionalSettingsDefinitionValidator.cs b/SPMeta2/SPMeta2.Regression.SSOM/Validation/RegionalSettingsDefinitionValidator.cs index 23cf7b957..1c4d0cf7a 100644 --- a/SPMeta2/SPMeta2.Regression.SSOM/Validation/RegionalSettingsDefinitionValidator.cs +++ b/SPMeta2/SPMeta2.Regression.SSOM/Validation/RegionalSettingsDefinitionValidator.cs @@ -25,19 +25,67 @@ public override void DeployModel(object modelHost, DefinitionBase model) var assert = ServiceFactory.AssertService .NewAssert(definition, spObject) - .ShouldNotBeNull(spObject) - .ShouldBeEqual(m => m.AdjustHijriDays, o => o.AdjustHijriDays) - .ShouldBeEqual(m => m.AlternateCalendarType, o => o.AlternateCalendarType) - .ShouldBeEqual(m => m.CalendarType, o => o.CalendarType) - .ShouldBeEqual(m => m.Collation, o => o.Collation) - .ShouldBeEqual(m => m.FirstDayOfWeek, o => o.FirstDayOfWeek) - .ShouldBeEqual(m => m.FirstWeekOfYear, o => o.FirstWeekOfYear) - //.ShouldBeEqual(m => m.LocaleId, o => o.LocaleId) - .ShouldBeEqual(m => m.WorkDayEndHour, o => o.WorkDayEndHour) - .ShouldBeEqual(m => m.WorkDayStartHour, o => o.WorkDayStartHour) - .ShouldBeEqual(m => m.WorkDays, o => o.WorkDays) - .ShouldBeEqual(m => m.ShowWeeks, o => o.ShowWeeks) - .ShouldBeEqual(m => m.Time24, o => o.Time24); + .ShouldNotBeNull(spObject); + + if (definition.CalendarType.HasValue) + assert.ShouldBeEqual(m => m.CalendarType, o => o.CalendarType); + else + assert.SkipProperty(m => m.CalendarType, "CalendarType is null or empty"); + + if (definition.AlternateCalendarType.HasValue) + assert.ShouldBeEqual(m => m.AlternateCalendarType, o => o.AlternateCalendarType); + else + assert.SkipProperty(m => m.AlternateCalendarType, "AlternateCalendarType is null or empty"); + + if (definition.AdjustHijriDays.HasValue) + assert.ShouldBeEqual(m => m.AdjustHijriDays, o => o.AdjustHijriDays); + else + assert.SkipProperty(m => m.AdjustHijriDays, "AdjustHijriDays is null or empty"); + + if (definition.Collation.HasValue) + assert.ShouldBeEqual(m => m.Collation, o => o.Collation); + else + assert.SkipProperty(m => m.Collation, "Collation is null or empty"); + + if (definition.WorkDayStartHour.HasValue) + assert.ShouldBeEqual(m => m.WorkDayStartHour, o => o.WorkDayStartHour); + else + assert.SkipProperty(m => m.WorkDayStartHour, "WorkDayStartHour is null or empty"); + + if (definition.WorkDayEndHour.HasValue) + assert.ShouldBeEqual(m => m.WorkDayEndHour, o => o.WorkDayEndHour); + else + assert.SkipProperty(m => m.WorkDayEndHour, "WorkDayEndHour is null or empty"); + + if (definition.WorkDays.HasValue) + assert.ShouldBeEqual(m => m.WorkDays, o => o.WorkDays); + else + assert.SkipProperty(m => m.WorkDays, "WorkDays is null or empty"); + + if (definition.Time24.HasValue) + assert.ShouldBeEqual(m => m.Time24, o => o.Time24); + else + assert.SkipProperty(m => m.Time24, "Time24 is null or empty"); + + if (definition.ShowWeeks.HasValue) + assert.ShouldBeEqual(m => m.ShowWeeks, o => o.ShowWeeks); + else + assert.SkipProperty(m => m.ShowWeeks, "ShowWeeks is null or empty"); + + if (definition.FirstDayOfWeek.HasValue) + assert.ShouldBeEqual(m => m.FirstWeekOfYear, o => o.FirstWeekOfYear); + else + assert.SkipProperty(m => m.FirstWeekOfYear, "FirstWeekOfYear is null or empty"); + + if (definition.FirstDayOfWeek.HasValue) + assert.ShouldBeEqual(m => m.FirstDayOfWeek, o => o.FirstDayOfWeek); + else + assert.SkipProperty(m => m.FirstDayOfWeek, "FirstDayOfWeek is null or empty"); + + if (definition.LocaleId.HasValue) + assert.ShouldBeEqual(m => m.LocaleId, o => o.LocaleId); + else + assert.SkipProperty(m => m.LocaleId, "LocaleId is null or empty"); if (definition.TimeZoneId.HasValue) { diff --git a/SPMeta2/SPMeta2.Regression.SSOM/Validation/WebPartDefinitionValidator.cs b/SPMeta2/SPMeta2.Regression.SSOM/Validation/WebPartDefinitionValidator.cs index 6902cbf2d..92524a852 100644 --- a/SPMeta2/SPMeta2.Regression.SSOM/Validation/WebPartDefinitionValidator.cs +++ b/SPMeta2/SPMeta2.Regression.SSOM/Validation/WebPartDefinitionValidator.cs @@ -19,7 +19,9 @@ using System.IO; using System.Reflection; using System.Xml; +using Microsoft.SharePoint.WebPartPages; using SPMeta2.Attributes.Regression; +using WebPart = System.Web.UI.WebControls.WebParts.WebPart; namespace SPMeta2.Regression.SSOM.Validation { @@ -376,7 +378,38 @@ public override void DeployModel(object modelHost, DefinitionBase model) } else { - // TODO + + + assert.ShouldBeEqual((p, s, d) => + { + // that's a fast hack + // hope we eoudn't have other web part with ParameterBindings :) + var webPart = d as DataFormWebPart; + var isValid = true; + + var srcProp = s.GetExpressionValue(m => m.ParameterBindings); + + // one more hack, fix up later + // just checking presense of the strings + foreach (var srcBinding in s.ParameterBindings) + { + var hasName = webPart.ParameterBindings.Contains(srcBinding.Name); + var hasValue = webPart.ParameterBindings.Contains(srcBinding.Location); + + if (!hasName || !hasValue) + { + isValid = false; + } + } + + return new PropertyValidationResult + { + Tag = p.Tag, + Src = srcProp, + Dst = null, + IsValid = isValid + }; + }); } if (!string.IsNullOrEmpty(definition.AuthorizationFilter)) diff --git a/SPMeta2/SPMeta2.Regression.Tests/Impl/Random/RandomDefinitionTest.cs b/SPMeta2/SPMeta2.Regression.Tests/Impl/Random/RandomDefinitionTest.cs index 6c00fe94d..a02867410 100644 --- a/SPMeta2/SPMeta2.Regression.Tests/Impl/Random/RandomDefinitionTest.cs +++ b/SPMeta2/SPMeta2.Regression.Tests/Impl/Random/RandomDefinitionTest.cs @@ -693,7 +693,11 @@ public void CanDeployRandom_TreeViewSettingsDefinition() [TestCategory("Regression.Rnd.Web")] public void CanDeployRandom_RegionalSettingsDefinition() { - TestRandomDefinition(); + // disable validation on the web as regional setting would toggle LCID + WithDisabledValidationOnTypes(typeof(WebDefinition), () => + { + TestRandomDefinition(); + }); } [TestMethod] diff --git a/SPMeta2/SPMeta2.Regression.Tests/Impl/Scenarios/ContentTypeScenariosTest.cs b/SPMeta2/SPMeta2.Regression.Tests/Impl/Scenarios/ContentTypeScenariosTest.cs index b0272b4e8..d224c4580 100644 --- a/SPMeta2/SPMeta2.Regression.Tests/Impl/Scenarios/ContentTypeScenariosTest.cs +++ b/SPMeta2/SPMeta2.Regression.Tests/Impl/Scenarios/ContentTypeScenariosTest.cs @@ -1,597 +1,597 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using SPMeta2.Containers; -using SPMeta2.Definitions; -using SPMeta2.Definitions.ContentTypes; -using SPMeta2.Enumerations; -using SPMeta2.Models; -using SPMeta2.Regression.Tests.Base; -using SPMeta2.Regression.Tests.Impl.Scenarios.Base; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using SPMeta2.Containers.Extensions; -using SPMeta2.Containers.Services; -using SPMeta2.Syntax.Default; -using SPMeta2.Syntax.Default.Modern; -using SPMeta2.Utils; -using SPMeta2.Containers.Templates.Documents; -using SPMeta2.Standard.Enumerations; - -namespace SPMeta2.Regression.Tests.Impl.Scenarios -{ - [TestClass] - public class ContentTypeScenariosTest : SPMeta2RegresionScenarioTestBase - { - #region internal - - [ClassInitializeAttribute] - public static void Init(TestContext context) - { - InternalInit(); - } - - [ClassCleanupAttribute] - public static void Cleanup() - { - InternalCleanup(); - } - - #endregion - - #region scopes - - [TestMethod] - [TestCategory("Regression.Scenarios.ContentTypes.Scopes")] - public void CanDeploy_SiteScoped_ContentType() - { - var contentType = ModelGeneratorService.GetRandomDefinition(); - - var model = SPMeta2Model - .NewSiteModel(site => - { - site.AddContentType(contentType); - }); - - TestModel(model); - } - - [TestMethod] - [TestCategory("Regression.Scenarios.ContentTypes.Scopes")] - public void CanDeploy_WebScoped_ContentType() - { - var contentType = ModelGeneratorService.GetRandomDefinition(); - - var model = SPMeta2Model - .NewWebModel(web => - { - web.AddRandomWeb(subWeb => - { - subWeb.AddContentType(contentType); - }); - }); - - TestModel(model); - } - - - #endregion - - #region default - - [TestMethod] - [TestCategory("Regression.Scenarios.ContentTypes")] - public void CanDeploy_CustomListItemContentType() - { - TestRandomDefinition(def => - { - def.ParentContentTypeId = BuiltInContentTypeId.Item; - }); - } - - [TestMethod] - [TestCategory("Regression.Scenarios.ContentTypes")] - public void CanDeploy_CustomListItemContentType_ByParentName() - { - TestRandomDefinition(def => - { - def.ParentContentTypeId = string.Empty; - def.ParentContentTypeName = BuiltInContentTypeNames.Item; - }); - } - - [TestMethod] - [TestCategory("Regression.Scenarios.ContentTypes")] - public void CanDeploy_CustomDocumentContentType() - { - TestRandomDefinition(def => - { - def.ParentContentTypeId = BuiltInContentTypeId.Document; - }); - } - - [TestMethod] - [TestCategory("Regression.Scenarios.ContentTypes")] - public void CanDeploy_CustomDocumentContentType_ByParentName() - { - TestRandomDefinition(def => - { - def.ParentContentTypeId = string.Empty; - def.ParentContentTypeName = BuiltInContentTypeNames.Document; - }); - } - - protected List GetHierarchicalContentTypes() - { - var root = ModelGeneratorService.GetRandomDefinition(def => - { - def.ParentContentTypeId = BuiltInContentTypeId.Item; - }); - - var levelOne = ModelGeneratorService.GetRandomDefinition(def => - { - def.ParentContentTypeId = root.GetContentTypeId(); - }); - - var levelTwo = ModelGeneratorService.GetRandomDefinition(def => - { - def.ParentContentTypeId = levelOne.GetContentTypeId(); - }); - +using Microsoft.VisualStudio.TestTools.UnitTesting; +using SPMeta2.Containers; +using SPMeta2.Definitions; +using SPMeta2.Definitions.ContentTypes; +using SPMeta2.Enumerations; +using SPMeta2.Models; +using SPMeta2.Regression.Tests.Base; +using SPMeta2.Regression.Tests.Impl.Scenarios.Base; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using SPMeta2.Containers.Extensions; +using SPMeta2.Containers.Services; +using SPMeta2.Syntax.Default; +using SPMeta2.Syntax.Default.Modern; +using SPMeta2.Utils; +using SPMeta2.Containers.Templates.Documents; +using SPMeta2.Standard.Enumerations; + +namespace SPMeta2.Regression.Tests.Impl.Scenarios +{ + [TestClass] + public class ContentTypeScenariosTest : SPMeta2RegresionScenarioTestBase + { + #region internal + + [ClassInitializeAttribute] + public static void Init(TestContext context) + { + InternalInit(); + } + + [ClassCleanupAttribute] + public static void Cleanup() + { + InternalCleanup(); + } + + #endregion + + #region scopes + + [TestMethod] + [TestCategory("Regression.Scenarios.ContentTypes.Scopes")] + public void CanDeploy_SiteScoped_ContentType() + { + var contentType = ModelGeneratorService.GetRandomDefinition(); + + var model = SPMeta2Model + .NewSiteModel(site => + { + site.AddContentType(contentType); + }); + + TestModel(model); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.ContentTypes.Scopes")] + public void CanDeploy_WebScoped_ContentType() + { + var contentType = ModelGeneratorService.GetRandomDefinition(); + + var model = SPMeta2Model + .NewWebModel(web => + { + web.AddRandomWeb(subWeb => + { + subWeb.AddContentType(contentType); + }); + }); + + TestModel(model); + } + + + #endregion + + #region default + + [TestMethod] + [TestCategory("Regression.Scenarios.ContentTypes")] + public void CanDeploy_CustomListItemContentType() + { + TestRandomDefinition(def => + { + def.ParentContentTypeId = BuiltInContentTypeId.Item; + }); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.ContentTypes")] + public void CanDeploy_CustomListItemContentType_ByParentName() + { + TestRandomDefinition(def => + { + def.ParentContentTypeId = string.Empty; + def.ParentContentTypeName = BuiltInContentTypeNames.Item; + }); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.ContentTypes")] + public void CanDeploy_CustomDocumentContentType() + { + TestRandomDefinition(def => + { + def.ParentContentTypeId = BuiltInContentTypeId.Document; + }); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.ContentTypes")] + public void CanDeploy_CustomDocumentContentType_ByParentName() + { + TestRandomDefinition(def => + { + def.ParentContentTypeId = string.Empty; + def.ParentContentTypeName = BuiltInContentTypeNames.Document; + }); + } + + protected List GetHierarchicalContentTypes() + { + var root = ModelGeneratorService.GetRandomDefinition(def => + { + def.ParentContentTypeId = BuiltInContentTypeId.Item; + }); + + var levelOne = ModelGeneratorService.GetRandomDefinition(def => + { + def.ParentContentTypeId = root.GetContentTypeId(); + }); + + var levelTwo = ModelGeneratorService.GetRandomDefinition(def => + { + def.ParentContentTypeId = levelOne.GetContentTypeId(); + }); + return new List(new ContentTypeDefinition[] { root, levelOne, levelTwo - }); - } - - [TestMethod] - [TestCategory("Regression.Scenarios.ContentTypes.ParentChild")] - public void CanDeploy_HierarchicalContentTypesOrderByIdAcs() - { - var contentTypes = GetHierarchicalContentTypes(); - - contentTypes.Sort(delegate(ContentTypeDefinition c1, ContentTypeDefinition c2) - { - return c1.IsChildOf(c2) ? -1 : 1; - }); - - var siteModel = SPMeta2Model - .NewSiteModel(site => - { - site.AddContentTypes(contentTypes); - }); - - TestModel(siteModel); - } - - [TestMethod] - [TestCategory("Regression.Scenarios.ContentTypes.ParentChild")] - public void CanDeploy_HierarchicalContentTypesOrderByIdDesc() - { - var contentTypes = GetHierarchicalContentTypes(); - contentTypes = contentTypes.OrderByDescending(c => c.Id).ToList(); - - contentTypes.Sort(delegate(ContentTypeDefinition c1, ContentTypeDefinition c2) - { - return c1.IsChildOf(c2) ? 1 : -1; - }); - - var siteModel = SPMeta2Model - .NewSiteModel(site => - { - site.AddContentTypes(contentTypes); - }); - - TestModel(siteModel); - } - - #endregion - - #region utils - - protected class ContentTypeEnvironment - { - public FieldDefinition First { get; set; } - public FieldDefinition Second { get; set; } - public FieldDefinition Third { get; set; } - - public ModelNode FirstLink { get; set; } - public ModelNode SecondLink { get; set; } - public ModelNode ThirdLink { get; set; } - - public ContentTypeDefinition ContentType { get; set; } - - public SiteModelNode SiteModel { get; set; } - } - - private ContentTypeEnvironment GetContentTypeSandbox( - Action siteModelConfig, - Action contentTypeModelConfig) - { - var result = new ContentTypeEnvironment(); - - // site model - - FieldDefinition fldFirst = null; - FieldDefinition fldSecond = null; - FieldDefinition fldThird = null; - - var siteModel = SPMeta2Model - .NewSiteModel(site => - { - site - .AddRandomField(ct => { fldFirst = ct.Value as FieldDefinition; }) - .AddRandomField(ct => { fldSecond = ct.Value as FieldDefinition; }) - .AddRandomField(ct => { fldThird = ct.Value as FieldDefinition; }) - .AddRandomContentType(contentType => - { - fldFirst.Title = "first_" + fldFirst.Title; - fldSecond.Title = "second_" + fldSecond.Title; - fldThird.Title = "third_" + fldThird.Title; - - result.First = fldFirst; - result.Second = fldSecond; - result.Third = fldThird; - - result.ContentType = contentType.Value as ContentTypeDefinition; - - contentType - .AddContentTypeFieldLink(fldFirst, link => - { - result.FirstLink = link; - //link.Options.RequireSelfProcessing = link.Value.RequireSelfProcessing = true; - link.Options.RequireSelfProcessing = true; - }) - .AddContentTypeFieldLink(fldSecond, link => - { - result.SecondLink = link; - //link.Options.RequireSelfProcessing = link.Value.RequireSelfProcessing = true; - link.Options.RequireSelfProcessing = true; - }) - .AddContentTypeFieldLink(fldThird, link => - { - result.ThirdLink = link; - //link.Options.RequireSelfProcessing = link.Value.RequireSelfProcessing = true; - link.Options.RequireSelfProcessing = true; - }); - - if (contentTypeModelConfig != null) - contentTypeModelConfig(contentType, result); - }); - }); - - result.SiteModel = siteModel; - - if (siteModelConfig != null) - siteModelConfig(result.SiteModel, result); - - return result; - } - - #endregion - - #region content type fields links - - [TestMethod] - [TestCategory("Regression.Scenarios.ContentTypes.FieldLinks")] - public void CanDeploy_CanHideContentTypeFieldLinks() - { - var env = GetContentTypeSandbox( - (siteModel, e) => - { - - }, - (contentTypeModel, e) => - { - contentTypeModel - .AddHideContentTypeFieldLinks(new HideContentTypeFieldLinksDefinition - { + }); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.ContentTypes.ParentChild")] + public void CanDeploy_HierarchicalContentTypesOrderByIdAcs() + { + var contentTypes = GetHierarchicalContentTypes(); + + contentTypes.Sort(delegate(ContentTypeDefinition c1, ContentTypeDefinition c2) + { + return c1.IsChildOf(c2) ? -1 : 1; + }); + + var siteModel = SPMeta2Model + .NewSiteModel(site => + { + site.AddContentTypes(contentTypes); + }); + + TestModel(siteModel); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.ContentTypes.ParentChild")] + public void CanDeploy_HierarchicalContentTypesOrderByIdDesc() + { + var contentTypes = GetHierarchicalContentTypes(); + contentTypes = contentTypes.OrderByDescending(c => c.Id).ToList(); + + contentTypes.Sort(delegate(ContentTypeDefinition c1, ContentTypeDefinition c2) + { + return c1.IsChildOf(c2) ? 1 : -1; + }); + + var siteModel = SPMeta2Model + .NewSiteModel(site => + { + site.AddContentTypes(contentTypes); + }); + + TestModel(siteModel); + } + + #endregion + + #region utils + + protected class ContentTypeEnvironment + { + public FieldDefinition First { get; set; } + public FieldDefinition Second { get; set; } + public FieldDefinition Third { get; set; } + + public ModelNode FirstLink { get; set; } + public ModelNode SecondLink { get; set; } + public ModelNode ThirdLink { get; set; } + + public ContentTypeDefinition ContentType { get; set; } + + public SiteModelNode SiteModel { get; set; } + } + + private ContentTypeEnvironment GetContentTypeSandbox( + Action siteModelConfig, + Action contentTypeModelConfig) + { + var result = new ContentTypeEnvironment(); + + // site model + + FieldDefinition fldFirst = null; + FieldDefinition fldSecond = null; + FieldDefinition fldThird = null; + + var siteModel = SPMeta2Model + .NewSiteModel(site => + { + site + .AddRandomField(ct => { fldFirst = ct.Value as FieldDefinition; }) + .AddRandomField(ct => { fldSecond = ct.Value as FieldDefinition; }) + .AddRandomField(ct => { fldThird = ct.Value as FieldDefinition; }) + .AddRandomContentType(contentType => + { + fldFirst.Title = "first_" + fldFirst.Title; + fldSecond.Title = "second_" + fldSecond.Title; + fldThird.Title = "third_" + fldThird.Title; + + result.First = fldFirst; + result.Second = fldSecond; + result.Third = fldThird; + + result.ContentType = contentType.Value as ContentTypeDefinition; + + contentType + .AddContentTypeFieldLink(fldFirst, link => + { + result.FirstLink = link; + //link.Options.RequireSelfProcessing = link.Value.RequireSelfProcessing = true; + link.Options.RequireSelfProcessing = true; + }) + .AddContentTypeFieldLink(fldSecond, link => + { + result.SecondLink = link; + //link.Options.RequireSelfProcessing = link.Value.RequireSelfProcessing = true; + link.Options.RequireSelfProcessing = true; + }) + .AddContentTypeFieldLink(fldThird, link => + { + result.ThirdLink = link; + //link.Options.RequireSelfProcessing = link.Value.RequireSelfProcessing = true; + link.Options.RequireSelfProcessing = true; + }); + + if (contentTypeModelConfig != null) + contentTypeModelConfig(contentType, result); + }); + }); + + result.SiteModel = siteModel; + + if (siteModelConfig != null) + siteModelConfig(result.SiteModel, result); + + return result; + } + + #endregion + + #region content type fields links + + [TestMethod] + [TestCategory("Regression.Scenarios.ContentTypes.FieldLinks")] + public void CanDeploy_CanHideContentTypeFieldLinks() + { + var env = GetContentTypeSandbox( + (siteModel, e) => + { + + }, + (contentTypeModel, e) => + { + contentTypeModel + .AddHideContentTypeFieldLinks(new HideContentTypeFieldLinksDefinition + { Fields = new List { new FieldLinkValue { InternalName = e.Second.InternalName }, new FieldLinkValue { InternalName = e.First.InternalName }, - } - }); - }); - - TestModel(env.SiteModel); - } - - [TestMethod] - [TestCategory("Regression.Scenarios.ContentTypes.FieldLinks")] - public void CanDeploy_CanRemoveContentTypeFieldLinks() - { - var env = GetContentTypeSandbox( - (siteModel, e) => - { - - }, - (contentTypeModel, e) => - { - contentTypeModel - .AddRemoveContentTypeFieldLinks(new RemoveContentTypeFieldLinksDefinition - { + } + }); + }); + + TestModel(env.SiteModel); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.ContentTypes.FieldLinks")] + public void CanDeploy_CanRemoveContentTypeFieldLinks() + { + var env = GetContentTypeSandbox( + (siteModel, e) => + { + + }, + (contentTypeModel, e) => + { + contentTypeModel + .AddRemoveContentTypeFieldLinks(new RemoveContentTypeFieldLinksDefinition + { Fields = new List { new FieldLinkValue { InternalName = e.Second.InternalName }, new FieldLinkValue { InternalName = e.First.InternalName }, - } - }, m => - { - m.OnProvisioned(ctx => - { - // disable validation on content type field links as they would be deleted by 'RemoveContentTypeFieldLinksDefinition' - - //e.FirstLink.Options.RequireSelfProcessing = e.FirstLink.Value.RequireSelfProcessing = false; - //e.SecondLink.Options.RequireSelfProcessing = e.SecondLink.Value.RequireSelfProcessing = false; - //e.ThirdLink.Options.RequireSelfProcessing = e.ThirdLink.Value.RequireSelfProcessing = false; - - e.FirstLink.Options.RequireSelfProcessing = false; - e.SecondLink.Options.RequireSelfProcessing = false; - e.ThirdLink.Options.RequireSelfProcessing = false; - }); - }); - }); - - TestModel(env.SiteModel); - } - - [TestMethod] - [TestCategory("Regression.Scenarios.ContentTypes.FieldLinks")] - public void CanDeploy_CanSetupUniqueContentTypeFieldsOrder() - { - var env = GetContentTypeSandbox( - (siteModel, e) => - { - - }, - (contentTypeModel, e) => - { - contentTypeModel - .AddUniqueContentTypeFieldsOrder(new UniqueContentTypeFieldsOrderDefinition - { - + } + }, m => + { + m.OnProvisioned(ctx => + { + // disable validation on content type field links as they would be deleted by 'RemoveContentTypeFieldLinksDefinition' + + //e.FirstLink.Options.RequireSelfProcessing = e.FirstLink.Value.RequireSelfProcessing = false; + //e.SecondLink.Options.RequireSelfProcessing = e.SecondLink.Value.RequireSelfProcessing = false; + //e.ThirdLink.Options.RequireSelfProcessing = e.ThirdLink.Value.RequireSelfProcessing = false; + + e.FirstLink.Options.RequireSelfProcessing = false; + e.SecondLink.Options.RequireSelfProcessing = false; + e.ThirdLink.Options.RequireSelfProcessing = false; + }); + }); + }); + + TestModel(env.SiteModel); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.ContentTypes.FieldLinks")] + public void CanDeploy_CanSetupUniqueContentTypeFieldsOrder() + { + var env = GetContentTypeSandbox( + (siteModel, e) => + { + + }, + (contentTypeModel, e) => + { + contentTypeModel + .AddUniqueContentTypeFieldsOrder(new UniqueContentTypeFieldsOrderDefinition + { + Fields = new List { new FieldLinkValue { InternalName = e.Second.InternalName }, new FieldLinkValue { InternalName = e.First.InternalName }, - } - }); - }); - - TestModel(env.SiteModel); - } - - [TestMethod] - [TestCategory("Regression.Scenarios.ContentTypes.FieldLinks")] - public void CanDeploy_CanSetupUniqueContentTypeFieldsOrder_At_OOTB_List_Scope() - { - var fieldDef = ModelGeneratorService.GetRandomDefinition(def => - { - def.Hidden = false; - - def.ShowInDisplayForm = true; - def.ShowInEditForm = true; - def.ShowInListSettings = true; - def.ShowInNewForm = true; - def.ShowInViewForms = true; - - def.AddFieldOptions = BuiltInAddFieldOptions.AddToAllContentTypes - | BuiltInAddFieldOptions.AddFieldInternalNameHint; - }); - - var listDef = ModelGeneratorService.GetRandomDefinition(def => - { - def.ContentTypesEnabled = false; - def.TemplateType = BuiltInListTemplateTypeId.GenericList; - }); - - var contentTypeLinkDef = new ContentTypeLinkDefinition - { - ContentTypeName = BuiltInContentTypeNames.Item, - ContentTypeId = BuiltInContentTypeId.Item - }; - - var webModel = SPMeta2Model.NewWebModel(web => - { - // adding field first - web.AddList(listDef, list => - { - list.AddField(fieldDef, field => - { - - }); - }); - - // then working with the content type - web.AddList(listDef.Inherit(), list => - { - list.AddContentTypeLink(contentTypeLinkDef, contenTypeLink => - { - contenTypeLink.RegExcludeFromEventsValidation(); - - contenTypeLink.AddUniqueContentTypeFieldsOrder(new UniqueContentTypeFieldsOrderDefinition - { - + } + }); + }); + + TestModel(env.SiteModel); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.ContentTypes.FieldLinks")] + public void CanDeploy_CanSetupUniqueContentTypeFieldsOrder_At_OOTB_List_Scope() + { + var fieldDef = ModelGeneratorService.GetRandomDefinition(def => + { + def.Hidden = false; + + def.ShowInDisplayForm = true; + def.ShowInEditForm = true; + def.ShowInListSettings = true; + def.ShowInNewForm = true; + def.ShowInViewForms = true; + + def.AddFieldOptions = BuiltInAddFieldOptions.AddToAllContentTypes + | BuiltInAddFieldOptions.AddFieldInternalNameHint; + }); + + var listDef = ModelGeneratorService.GetRandomDefinition(def => + { + def.ContentTypesEnabled = false; + def.TemplateType = BuiltInListTemplateTypeId.GenericList; + }); + + var contentTypeLinkDef = new ContentTypeLinkDefinition + { + ContentTypeName = BuiltInContentTypeNames.Item, + ContentTypeId = BuiltInContentTypeId.Item + }; + + var webModel = SPMeta2Model.NewWebModel(web => + { + // adding field first + web.AddList(listDef, list => + { + list.AddField(fieldDef, field => + { + + }); + }); + + // then working with the content type + web.AddList(listDef.Inherit(), list => + { + list.AddContentTypeLink(contentTypeLinkDef, contenTypeLink => + { + contenTypeLink.RegExcludeFromEventsValidation(); + + contenTypeLink.AddUniqueContentTypeFieldsOrder(new UniqueContentTypeFieldsOrderDefinition + { + Fields = new List { new FieldLinkValue {InternalName = fieldDef.InternalName}, new FieldLinkValue {InternalName = "Title"}, - } - }); - }); - }); - }); - - TestModel(webModel); - } - - [TestMethod] - [TestCategory("Regression.Scenarios.ContentTypes.FieldLinks")] - public void CanDeploy_CanSetupUniqueContentTypeFieldsOrder_At_List_Scope() - { - // Support 'UniqueContentTypeFieldsOrderDefinition' at list level content types #742 - // https://github.com/SubPointSolutions/spmeta2/issues/742 - - WithDisabledPropertyUpdateValidation(() => - { - var first = string.Empty; - var second = string.Empty; - - var env = GetContentTypeSandbox( - (siteModel, e) => - { - - }, - (contentTypeModel, e) => - { - first = e.First.InternalName; - second = e.Second.InternalName; - - contentTypeModel - .AddUniqueContentTypeFieldsOrder(new UniqueContentTypeFieldsOrderDefinition - { + } + }); + }); + }); + }); + + TestModel(webModel); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.ContentTypes.FieldLinks")] + public void CanDeploy_CanSetupUniqueContentTypeFieldsOrder_At_List_Scope() + { + // Support 'UniqueContentTypeFieldsOrderDefinition' at list level content types #742 + // https://github.com/SubPointSolutions/spmeta2/issues/742 + + WithDisabledPropertyUpdateValidation(() => + { + var first = string.Empty; + var second = string.Empty; + + var env = GetContentTypeSandbox( + (siteModel, e) => + { + + }, + (contentTypeModel, e) => + { + first = e.First.InternalName; + second = e.Second.InternalName; + + contentTypeModel + .AddUniqueContentTypeFieldsOrder(new UniqueContentTypeFieldsOrderDefinition + { Fields = new List { new FieldLinkValue {InternalName = e.Second.InternalName}, new FieldLinkValue {InternalName = e.First.InternalName}, - } - }); - }); - - var webModel = SPMeta2Model.NewWebModel(web => - { - web.AddRandomList(list => - { - (list.Value as ListDefinition).ContentTypesEnabled = true; - - list.AddContentTypeLink(env.ContentType, contenTypeLink => - { - contenTypeLink.AddUniqueContentTypeFieldsOrder(new UniqueContentTypeFieldsOrderDefinition - { - + } + }); + }); + + var webModel = SPMeta2Model.NewWebModel(web => + { + web.AddRandomList(list => + { + (list.Value as ListDefinition).ContentTypesEnabled = true; + + list.AddContentTypeLink(env.ContentType, contenTypeLink => + { + contenTypeLink.AddUniqueContentTypeFieldsOrder(new UniqueContentTypeFieldsOrderDefinition + { + Fields = new List { new FieldLinkValue {InternalName = first}, new FieldLinkValue {InternalName = second}, - } - }); - }); - }); - }); - - TestModel(env.SiteModel, webModel); - }); - } - - #endregion - - #region doc templates - - [TestMethod] - [TestCategory("Regression.Scenarios.ContentTypes.DocumentTemplate")] - public void CanDeploy_ContentType_WithDocTemplate_In_ResourceFolder() - { - var siteContentType = ModelGeneratorService.GetRandomDefinition(); - var documentTemplate = ModelGeneratorService.GetRandomDefinition(def => - { - def.Content = DocumentTemplates.SPMeta2_MSWord_Template; - def.FileName = Rnd.String() + ".dotx"; - }); - - - siteContentType.DocumentTemplate = documentTemplate.FileName; - - var siteModel = SPMeta2Model.NewSiteModel(site => - { - site.AddContentType(siteContentType, contentType => - { - contentType.AddModuleFile(documentTemplate); - }); - }); - - var contentModel = SPMeta2Model.NewWebModel(web => - { - web.AddRandomDocumentLibrary(list => - { - list.AddContentTypeLink(siteContentType); - }); - }); - - TestModels(new ModelNode[] { siteModel, contentModel }); - } - - - [TestMethod] - [TestCategory("Regression.Scenarios.ContentTypes.DocumentTemplate")] - public void CanDeploy_ContentType_WithDocTemplate_In_RootWeb_DocumentLibrary() - { - var siteContentType = ModelGeneratorService.GetRandomDefinition(); - - var documentTemplate = ModelGeneratorService.GetRandomDefinition(def => - { - def.Content = DocumentTemplates.SPMeta2_MSWord_Template; - def.FileName = Rnd.String() + ".dotx"; - }); - - var documentTemplateLibrary = ModelGeneratorService.GetRandomDefinition(def => - { - def.TemplateType = BuiltInListTemplateTypeId.DocumentLibrary; - }); - + } + }); + }); + }); + }); + + TestModel(env.SiteModel, webModel); + }); + } + + #endregion + + #region doc templates + + [TestMethod] + [TestCategory("Regression.Scenarios.ContentTypes.DocumentTemplate")] + public void CanDeploy_ContentType_WithDocTemplate_In_ResourceFolder() + { + var siteContentType = ModelGeneratorService.GetRandomDefinition(); + var documentTemplate = ModelGeneratorService.GetRandomDefinition(def => + { + def.Content = DocumentTemplates.SPMeta2_MSWord_Template; + def.FileName = Rnd.String() + ".dotx"; + }); + + + siteContentType.DocumentTemplate = documentTemplate.FileName; + + var siteModel = SPMeta2Model.NewSiteModel(site => + { + site.AddContentType(siteContentType, contentType => + { + contentType.AddModuleFile(documentTemplate); + }); + }); + + var contentModel = SPMeta2Model.NewWebModel(web => + { + web.AddRandomDocumentLibrary(list => + { + list.AddContentTypeLink(siteContentType); + }); + }); + + TestModels(new ModelNode[] { siteModel, contentModel }); + } + + + [TestMethod] + [TestCategory("Regression.Scenarios.ContentTypes.DocumentTemplate")] + public void CanDeploy_ContentType_WithDocTemplate_In_RootWeb_DocumentLibrary() + { + var siteContentType = ModelGeneratorService.GetRandomDefinition(); + + var documentTemplate = ModelGeneratorService.GetRandomDefinition(def => + { + def.Content = DocumentTemplates.SPMeta2_MSWord_Template; + def.FileName = Rnd.String() + ".dotx"; + }); + + var documentTemplateLibrary = ModelGeneratorService.GetRandomDefinition(def => + { + def.TemplateType = BuiltInListTemplateTypeId.DocumentLibrary; + }); + siteContentType.DocumentTemplate = UrlUtility.CombineUrl(new[]{ "~sitecollection", #pragma warning disable 618 documentTemplateLibrary.Url, #pragma warning restore 618 documentTemplate.FileName - }); - - var siteModel = SPMeta2Model.NewSiteModel(site => - { - site.AddContentType(siteContentType); - }); - - var webModel = SPMeta2Model.NewWebModel(web => - { - web.AddList(documentTemplateLibrary, list => - { - list.AddModuleFile(documentTemplate); - }); - }); - - var contentModel = SPMeta2Model.NewWebModel(web => - { - web.AddRandomDocumentLibrary(list => - { - list.AddContentTypeLink(siteContentType); - }); - }); - - TestModels(new ModelNode[] { webModel, siteModel, contentModel }); - } - - [TestMethod] - [TestCategory("Regression.Scenarios.ContentTypes.DocumentTemplate")] - public void CanDeploy_ContentType_WithDocTemplate_In_SubWeb_DocumentLibrary() - { - var siteContentType = ModelGeneratorService.GetRandomDefinition(); - - var documentTemplate = ModelGeneratorService.GetRandomDefinition(def => - { - def.Content = DocumentTemplates.SPMeta2_MSWord_Template; - def.FileName = Rnd.String() + ".dotx"; - }); - - var documentTemplateLibrary = ModelGeneratorService.GetRandomDefinition(def => - { - def.TemplateType = BuiltInListTemplateTypeId.DocumentLibrary; - }); - - var subWebDef = ModelGeneratorService.GetRandomDefinition(); - + }); + + var siteModel = SPMeta2Model.NewSiteModel(site => + { + site.AddContentType(siteContentType); + }); + + var webModel = SPMeta2Model.NewWebModel(web => + { + web.AddList(documentTemplateLibrary, list => + { + list.AddModuleFile(documentTemplate); + }); + }); + + var contentModel = SPMeta2Model.NewWebModel(web => + { + web.AddRandomDocumentLibrary(list => + { + list.AddContentTypeLink(siteContentType); + }); + }); + + TestModels(new ModelNode[] { webModel, siteModel, contentModel }); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.ContentTypes.DocumentTemplate")] + public void CanDeploy_ContentType_WithDocTemplate_In_SubWeb_DocumentLibrary() + { + var siteContentType = ModelGeneratorService.GetRandomDefinition(); + + var documentTemplate = ModelGeneratorService.GetRandomDefinition(def => + { + def.Content = DocumentTemplates.SPMeta2_MSWord_Template; + def.FileName = Rnd.String() + ".dotx"; + }); + + var documentTemplateLibrary = ModelGeneratorService.GetRandomDefinition(def => + { + def.TemplateType = BuiltInListTemplateTypeId.DocumentLibrary; + }); + + var subWebDef = ModelGeneratorService.GetRandomDefinition(); + siteContentType.DocumentTemplate = UrlUtility.CombineUrl(new[]{ "~sitecollection", subWebDef.Url, @@ -599,102 +599,185 @@ public void CanDeploy_ContentType_WithDocTemplate_In_SubWeb_DocumentLibrary() documentTemplateLibrary.Url, #pragma warning restore 618 documentTemplate.FileName - }); - - var siteModel = SPMeta2Model.NewSiteModel(site => - { - site.AddContentType(siteContentType); - }); - - var webModel = SPMeta2Model.NewWebModel(web => - { - web.AddWeb(subWebDef, subWeb => - { - subWeb.AddList(documentTemplateLibrary, list => - { - list.AddModuleFile(documentTemplate); - }); - }); - - - }); - - var contentModel = SPMeta2Model.NewWebModel(web => - { - web.AddRandomDocumentLibrary(list => - { - list.AddContentTypeLink(siteContentType); - }); - }); - - TestModels(new ModelNode[] { webModel, siteModel, contentModel }); - } - - #endregion - - #region localization - - [TestMethod] - [TestCategory("Regression.Scenarios.ContentTypes.Localization")] - public void CanDeploy_Localized_Site_ContentType() - { - var definition = GetLocalizedDefinition(); - - var model = SPMeta2Model.NewSiteModel(site => - { - site.AddContentType(definition); - }); - - TestModel(model); - } - - [TestMethod] - [TestCategory("Regression.Scenarios.ContentTypes.Localization")] - public void CanDeploy_Localized_Web_ContentType() - { - var contentType = GetLocalizedDefinition(); - var subWebContentType = GetLocalizedDefinition(); - - var model = SPMeta2Model.NewWebModel(web => - { - web.AddContentType(contentType); - - web.AddRandomWeb(subWeb => - { - subWeb.AddContentType(subWebContentType); - }); - }); - - TestModel(model); - } - - #endregion - - #region utils - - protected ContentTypeDefinition GetLocalizedDefinition() - { - var definition = ModelGeneratorService.GetRandomDefinition(); - var localeIds = Rnd.LocaleIds(); - - foreach (var localeId in localeIds) - { - definition.NameResource.Add(new ValueForUICulture - { - CultureId = localeId, - Value = string.Format("LocalizedName_{0}", localeId) - }); - - definition.DescriptionResource.Add(new ValueForUICulture - { - CultureId = localeId, - Value = string.Format("LocalizedDescription_{0}", localeId) - }); - } - - return definition; - } - - #endregion - } -} + }); + + var siteModel = SPMeta2Model.NewSiteModel(site => + { + site.AddContentType(siteContentType); + }); + + var webModel = SPMeta2Model.NewWebModel(web => + { + web.AddWeb(subWebDef, subWeb => + { + subWeb.AddList(documentTemplateLibrary, list => + { + list.AddModuleFile(documentTemplate); + }); + }); + + + }); + + var contentModel = SPMeta2Model.NewWebModel(web => + { + web.AddRandomDocumentLibrary(list => + { + list.AddContentTypeLink(siteContentType); + }); + }); + + TestModels(new ModelNode[] { webModel, siteModel, contentModel }); + } + + #endregion + + #region localization + + [TestMethod] + [TestCategory("Regression.Scenarios.ContentTypes.Localization")] + public void CanDeploy_Localized_Site_ContentType() + { + var definition = GetLocalizedDefinition(); + + var model = SPMeta2Model.NewSiteModel(site => + { + site.AddContentType(definition); + }); + + TestModel(model); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.ContentTypes.Localization")] + public void CanDeploy_Localized_Web_ContentType() + { + var contentType = GetLocalizedDefinition(); + var subWebContentType = GetLocalizedDefinition(); + + var model = SPMeta2Model.NewWebModel(web => + { + web.AddContentType(contentType); + + web.AddRandomWeb(subWeb => + { + subWeb.AddContentType(subWebContentType); + }); + }); + + TestModel(model); + } + + #endregion + + #region renaming + + [TestMethod] + [TestCategory("Regression.Scenarios.ContentTypes.Renaming")] + public void CanDeploy_ContentType_And_Rename() + { + // Enhance ContentTypeDefinition - support Name renaming #924 + // https://github.com/SubPointSolutions/spmeta2/issues/924 + + // we should be able to deploy and then rename content types + // 3 waves of deployment: original, and two renames + // all should work, including model validations with the new Names + + // we need to add content type field links to ensure two paths: + // 1) model handler provisions content types + // 2) model handler resolves content type to pass further to the provision flow + + var originalContentTypes = new List(); + + originalContentTypes.Add(ModelGeneratorService.GetRandomDefinition()); + originalContentTypes.Add(ModelGeneratorService.GetRandomDefinition()); + + var firstRenames = originalContentTypes.Select(d => + { + return d.Inherit(def => + { + def.Name = Rnd.String(); + }); + }); + + var secondRenames = originalContentTypes.Select(d => + { + return d.Inherit(def => + { + def.Name = Rnd.String(); + }); + }); + + // deploy and test original content types + var originalModel = SPMeta2Model.NewSiteModel(site => + { + foreach (var ct in originalContentTypes) + { + site.AddContentType(ct, contentType => + { + contentType.AddContentTypeFieldLink(BuiltInFieldId.Title); + }); + } + }); + + TestModel(originalModel); + + // deploy and test first renames + var firstRenamesModel = SPMeta2Model.NewSiteModel(site => + { + foreach (var ct in firstRenames) + { + site.AddContentType(ct, contentType => + { + contentType.AddContentTypeFieldLink(BuiltInFieldId.Title); + }); + } + }); + + TestModel(firstRenamesModel); + + // deploy and test first renames + var secondRenamesModel = SPMeta2Model.NewSiteModel(site => + { + foreach (var ct in secondRenames) + { + site.AddContentType(ct, contentType => + { + contentType.AddContentTypeFieldLink(BuiltInFieldId.Title); + }); + } + }); + + TestModel(secondRenamesModel); + } + + #endregion + + #region utils + + protected ContentTypeDefinition GetLocalizedDefinition() + { + var definition = ModelGeneratorService.GetRandomDefinition(); + var localeIds = Rnd.LocaleIds(); + + foreach (var localeId in localeIds) + { + definition.NameResource.Add(new ValueForUICulture + { + CultureId = localeId, + Value = string.Format("LocalizedName_{0}", localeId) + }); + + definition.DescriptionResource.Add(new ValueForUICulture + { + CultureId = localeId, + Value = string.Format("LocalizedDescription_{0}", localeId) + }); + } + + return definition; + } + + #endregion + } +} diff --git a/SPMeta2/SPMeta2.Regression.Tests/Impl/Scenarios/DesignPackageScenariosTest.cs b/SPMeta2/SPMeta2.Regression.Tests/Impl/Scenarios/DesignPackageScenariosTest.cs new file mode 100644 index 000000000..9005159d7 --- /dev/null +++ b/SPMeta2/SPMeta2.Regression.Tests/Impl/Scenarios/DesignPackageScenariosTest.cs @@ -0,0 +1,110 @@ +using System.Diagnostics; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using SPMeta2.Containers; +using SPMeta2.Containers.Services; +using SPMeta2.Definitions; +using SPMeta2.Exceptions; +using SPMeta2.Regression.Tests.Base; +using SPMeta2.Regression.Tests.Impl.Scenarios.Base; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +using SPMeta2.Syntax.Default; +using System.IO; +using SPMeta2.Enumerations; +using SPMeta2.Models; +using SPMeta2.Standard.Definitions; +using SPMeta2.Standard.Syntax; + +namespace SPMeta2.Regression.Tests.Impl.Scenarios +{ + [TestClass] + public class DesignPackageScenariosTest : SPMeta2RegresionScenarioTestBase + { + public DesignPackageScenariosTest() + { + RegressionService.ProvisionGenerationCount = 2; + } + + #region internal + + [ClassInitializeAttribute] + public static void Init(TestContext context) + { + InternalInit(); + } + + [ClassCleanupAttribute] + public static void Cleanup() + { + InternalCleanup(); + } + + #endregion + + #region default + + [TestMethod] + [TestCategory("Regression.Scenarios.DesignPackage")] + public void CanDeploy_Simple_DesignPackage() + { + var siteFeature = BuiltInSiteFeatures.SharePointServerPublishingInfrastructure.Inherit(f => f.Enable()); + + var webFeature = BuiltInWebFeatures.SharePointServerPublishing.Inherit(f => f.Enable()); + + var designPackageDef = ModelGeneratorService.GetRandomDefinition(def => + { + + }); + + var siteModel = SPMeta2Model.NewSiteModel(site => site.AddSiteFeature(siteFeature)); + var rootWebModel = SPMeta2Model.NewWebModel(web => + { + web.AddWebFeature(webFeature); + }); + + var designPackageModel = SPMeta2Model.NewSiteModel(site => site.AddDesignPackage(designPackageDef)); + + TestModels(new ModelNode[] + { + siteModel, + rootWebModel, + designPackageModel + }); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.DesignPackage")] + public void CanDeploy_Simple_DesignPackage_As_Apply() + { + var siteFeature = BuiltInSiteFeatures.SharePointServerPublishingInfrastructure.Inherit(f => f.Enable()); + + var webFeature = BuiltInWebFeatures.SharePointServerPublishing.Inherit(f => f.Enable()); + + var designPackageDef = ModelGeneratorService.GetRandomDefinition(def => + { + def.Apply = true; + }); + + var siteModel = SPMeta2Model.NewSiteModel(site => site.AddSiteFeature(siteFeature)); + var rootWebModel = SPMeta2Model.NewWebModel(web => + { + web.AddWebFeature(webFeature); + }); + + var designPackageModel = SPMeta2Model.NewSiteModel(site => site.AddDesignPackage(designPackageDef)); + + TestModels(new ModelNode[] + { + siteModel, + rootWebModel, + designPackageModel + }); + } + + + #endregion + } +} diff --git a/SPMeta2/SPMeta2.Regression.Tests/Impl/Scenarios/FarmSolutionScenariosTest.cs b/SPMeta2/SPMeta2.Regression.Tests/Impl/Scenarios/FarmSolutionScenariosTest.cs new file mode 100644 index 000000000..a8ef17614 --- /dev/null +++ b/SPMeta2/SPMeta2.Regression.Tests/Impl/Scenarios/FarmSolutionScenariosTest.cs @@ -0,0 +1,522 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +using Microsoft.VisualStudio.TestTools.UnitTesting; +using SPMeta2.BuiltInDefinitions; +using SPMeta2.Containers; +using SPMeta2.Containers.Standard; +using SPMeta2.Definitions; +using SPMeta2.Enumerations; +using SPMeta2.Models; +using SPMeta2.Regression.Tests.Definitions; +using SPMeta2.Regression.Tests.Impl.Scenarios.Base; +using SPMeta2.Standard.Definitions; +using SPMeta2.Syntax.Default; +using SPMeta2.Validation.Validators.Relationships; + +namespace SPMeta2.Regression.Tests.Impl.Scenarios +{ + [TestClass] + public class FarmSolutionScenariosTest : SPMeta2RegresionScenarioTestBase + { + #region constructors + + public FarmSolutionScenariosTest() + { + RegressionService.ProvisionGenerationCount = 1; + RegressionService.ShowOnlyFalseResults = false; + } + + #endregion + + #region internal + + [ClassInitializeAttribute] + public static void Init(TestContext context) + { + InternalInit(); + } + + [ClassCleanupAttribute] + public static void Cleanup() + { + InternalCleanup(); + } + + #endregion + + #region default + + [TestMethod] + [TestCategory("Regression.Scenarios.FarmSolution.Default")] + public void CanDeploy_FarmSolution_As_Default() + { + WithExpectedUnsupportedCSOMnO365RunnerExceptions(() => + { + var solutionDef = ModelGeneratorService.GetRandomDefinition(def => + { + + }); + + TestFarmSolutionModel(solutionDef); + }); + } + + #endregion + + #region add operations + + [TestMethod] + [TestCategory("Regression.Scenarios.FarmSolution.Add")] + public void CanDeploy_FarmSolution_As_Add_FromDeleted_State() + { + WithExpectedUnsupportedCSOMnO365RunnerExceptions(() => + { + var solutionDef = ModelGeneratorService.GetRandomDefinition(def => + { + + }); + + PrepareDeletedState(solutionDef); + + TestFarmSolutionModel(solutionDef); + }); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.FarmSolution.Add")] + public void CanDeploy_FarmSolution_As_Add_FromRetracted_State() + { + WithExpectedUnsupportedCSOMnO365RunnerExceptions(() => + { + var solutionDef = ModelGeneratorService.GetRandomDefinition(def => + { + + }); + + PrepareRetractedState(solutionDef); + TestFarmSolutionModel(solutionDef); + }); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.FarmSolution.Add")] + public void CanDeploy_FarmSolution_As_Add_FromAdded_State() + { + WithExpectedUnsupportedCSOMnO365RunnerExceptions(() => + { + var solutionDef = ModelGeneratorService.GetRandomDefinition(def => + { + + }); + + PrepareAddedState(solutionDef); + TestFarmSolutionModel(solutionDef); + }); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.FarmSolution.Add")] + public void CanDeploy_FarmSolution_As_Add_FromDeployed_State() + { + WithExpectedUnsupportedCSOMnO365RunnerExceptions(() => + { + var solutionDef = ModelGeneratorService.GetRandomDefinition(def => + { + + }); + + PrepareDeployedState(solutionDef); + TestFarmSolutionModel(solutionDef); + }); + } + + #endregion + + #region delete operations + + [TestMethod] + [TestCategory("Regression.Scenarios.FarmSolution.Delete")] + public void CanDeploy_FarmSolution_As_Delete_FromDeleted_State() + { + WithExpectedUnsupportedCSOMnO365RunnerExceptions(() => + { + var solutionDef = ModelGeneratorService.GetRandomDefinition(def => + { + def.ShouldDelete = true; + def.ShouldAdd = false; + }); + + PrepareDeletedState(solutionDef); + + TestFarmSolutionModel(solutionDef); + }); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.FarmSolution.Delete")] + public void CanDeploy_FarmSolution_As_Delete_FromRetracted_State() + { + WithExpectedUnsupportedCSOMnO365RunnerExceptions(() => + { + var solutionDef = ModelGeneratorService.GetRandomDefinition(def => + { + def.ShouldDelete = true; + def.ShouldAdd = false; + }); + + PrepareRetractedState(solutionDef); + TestFarmSolutionModel(solutionDef); + }); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.FarmSolution.Delete")] + public void CanDeploy_FarmSolution_As_Delete_FromAdded_State() + { + WithExpectedUnsupportedCSOMnO365RunnerExceptions(() => + { + var solutionDef = ModelGeneratorService.GetRandomDefinition(def => + { + def.ShouldDelete = true; + def.ShouldAdd = false; + }); + + PrepareAddedState(solutionDef); + TestFarmSolutionModel(solutionDef); + }); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.FarmSolution.Delete")] + public void CanDeploy_FarmSolution_As_Delete_FromDeployed_State() + { + WithExpectedUnsupportedCSOMnO365RunnerExceptions(() => + { + var solutionDef = ModelGeneratorService.GetRandomDefinition(def => + { + def.ShouldDelete = true; + def.ShouldAdd = false; + }); + + PrepareDeployedState(solutionDef); + TestFarmSolutionModel(solutionDef); + }); + } + + #endregion + + #region retract operations + + [TestMethod] + [TestCategory("Regression.Scenarios.FarmSolution.Retract")] + public void CanDeploy_FarmSolution_As_Retract_FromDeleted_State() + { + WithExpectedUnsupportedCSOMnO365RunnerExceptions(() => + { + var solutionDef = ModelGeneratorService.GetRandomDefinition(def => + { + def.ShouldRetract = true; + }); + + PrepareDeletedState(solutionDef); + + TestFarmSolutionModel(solutionDef); + }); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.FarmSolution.Retract")] + public void CanDeploy_FarmSolution_As_Retract_FromRetracted_State() + { + WithExpectedUnsupportedCSOMnO365RunnerExceptions(() => + { + var solutionDef = ModelGeneratorService.GetRandomDefinition(def => + { + def.ShouldRetract = true; + }); + + PrepareRetractedState(solutionDef); + TestFarmSolutionModel(solutionDef); + }); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.FarmSolution.Retract")] + public void CanDeploy_FarmSolution_As_Retract_FromAdded_State() + { + WithExpectedUnsupportedCSOMnO365RunnerExceptions(() => + { + var solutionDef = ModelGeneratorService.GetRandomDefinition(def => + { + def.ShouldRetract = true; + }); + + PrepareAddedState(solutionDef); + TestFarmSolutionModel(solutionDef); + }); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.FarmSolution.Retract")] + public void CanDeploy_FarmSolution_As_Retract_FromDeployed_State() + { + WithExpectedUnsupportedCSOMnO365RunnerExceptions(() => + { + var solutionDef = ModelGeneratorService.GetRandomDefinition(def => + { + def.ShouldRetract = true; + }); + + PrepareDeployedState(solutionDef); + TestFarmSolutionModel(solutionDef); + }); + } + + #endregion + + + #region deploy operations + + [TestMethod] + [TestCategory("Regression.Scenarios.FarmSolution.Deploy")] + public void CanDeploy_FarmSolution_As_Deploy_FromDeleted_State() + { + WithExpectedUnsupportedCSOMnO365RunnerExceptions(() => + { + var solutionDef = ModelGeneratorService.GetRandomDefinition(def => + { + def.ShouldDeploy = true; + }); + + PrepareDeletedState(solutionDef); + TestFarmSolutionModel(solutionDef); + }); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.FarmSolution.Deploy")] + public void CanDeploy_FarmSolution_As_Deploy_FromRetracted_State() + { + WithExpectedUnsupportedCSOMnO365RunnerExceptions(() => + { + var solutionDef = ModelGeneratorService.GetRandomDefinition(def => + { + def.ShouldDeploy = true; + }); + + PrepareRetractedState(solutionDef); + TestFarmSolutionModel(solutionDef); + }); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.FarmSolution.Deploy")] + public void CanDeploy_FarmSolution_As_Deploy_FromAdded_State() + { + WithExpectedUnsupportedCSOMnO365RunnerExceptions(() => + { + var solutionDef = ModelGeneratorService.GetRandomDefinition(def => + { + def.ShouldDeploy = true; + }); + + PrepareAddedState(solutionDef); + TestFarmSolutionModel(solutionDef); + }); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.FarmSolution.Deploy")] + public void CanDeploy_FarmSolution_As_Deploy_FromDeployed_State() + { + WithExpectedUnsupportedCSOMnO365RunnerExceptions(() => + { + var solutionDef = ModelGeneratorService.GetRandomDefinition(def => + { + def.ShouldDeploy = true; + }); + + PrepareDeployedState(solutionDef); + TestFarmSolutionModel(solutionDef); + }); + } + + #endregion + + #region upgrade operations + + [TestMethod] + [TestCategory("Regression.Scenarios.FarmSolution.Upgrade")] + public void CanDeploy_FarmSolution_As_Upgrade_FromDeleted_State() + { + WithExpectedUnsupportedCSOMnO365RunnerExceptions(() => + { + var solutionDef = ModelGeneratorService.GetRandomDefinition(def => + { + def.ShouldUpgrade = true; + }); + + PrepareDeletedState(solutionDef); + TestFarmSolutionModel(solutionDef); + }); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.FarmSolution.Upgrade")] + public void CanDeploy_FarmSolution_As_Upgrade_FromRetracted_State() + { + WithExpectedUnsupportedCSOMnO365RunnerExceptions(() => + { + var solutionDef = ModelGeneratorService.GetRandomDefinition(def => + { + def.ShouldUpgrade = true; + }); + + PrepareRetractedState(solutionDef); + TestFarmSolutionModel(solutionDef); + }); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.FarmSolution.Upgrade")] + public void CanDeploy_FarmSolution_As_Upgrade_FromAdded_State() + { + WithExpectedUnsupportedCSOMnO365RunnerExceptions(() => + { + var solutionDef = ModelGeneratorService.GetRandomDefinition(def => + { + def.ShouldUpgrade = true; + }); + + PrepareAddedState(solutionDef); + //TestFarmSolutionModel(solutionDef); + }); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.FarmSolution.Upgrade")] + public void CanDeploy_FarmSolution_As_Upgrade_FromDeployed_State() + { + WithExpectedUnsupportedCSOMnO365RunnerExceptions(() => + { + var solutionDef = ModelGeneratorService.GetRandomDefinition(def => + { + def.ShouldUpgrade = true; + }); + + PrepareDeployedState(solutionDef); + TestFarmSolutionModel(solutionDef); + }); + } + + #endregion + + #region utils + + private void PrepareDeployedState(FarmSolutionDefinition solutionDef) + { + var deployDef = solutionDef.Inherit(def => + { + def.ShouldDelete = null; + def.ShouldRetract = null; + def.ShouldUpgrade = null; + + def.ShouldAdd = true; + def.ShouldDeploy = true; + }); + + TestFarmSolutionModel(deployDef); + } + + private void PrepareAddedState(FarmSolutionDefinition solutionDef) + { + var addDef = solutionDef.Inherit(def => + { + def.ShouldDelete = null; + def.ShouldDeploy = null; + def.ShouldUpgrade = null; + + def.ShouldAdd = true; + def.ShouldRetract = null; + }); + + TestFarmSolutionModel(addDef); + + var retractDef = solutionDef.Inherit(def => + { + def.ShouldDelete = null; + def.ShouldDeploy = null; + def.ShouldUpgrade = null; + + def.ShouldAdd = true; + def.ShouldRetract = true; + }); + + TestFarmSolutionModel(retractDef); + } + + private void PrepareRetractedState(FarmSolutionDefinition solutionDef) + { + var deployDef = solutionDef.Inherit(def => + { + def.ShouldDelete = null; + def.ShouldRetract = null; + def.ShouldUpgrade = null; + + def.ShouldAdd = true; + def.ShouldDeploy = true; + }); + + var retractDef = solutionDef.Inherit(def => + { + def.ShouldDelete = null; + def.ShouldDeploy = null; + def.ShouldUpgrade = null; + + def.ShouldAdd = true; + def.ShouldRetract = true; + }); + + TestFarmSolutionModel(deployDef); + TestFarmSolutionModel(retractDef); + } + + private void PrepareDeletedState(FarmSolutionDefinition solutionDef) + { + var deletedDef = solutionDef.Inherit(def => + { + def.ShouldDeploy = null; + def.ShouldRetract = true; + def.ShouldUpgrade = null; + + def.ShouldAdd = false; + def.ShouldDelete = true; + }); + + TestFarmSolutionModel(deletedDef); + } + + protected virtual void TestFarmSolutionModel(FarmSolutionDefinition solutionDef) + { + var newSolutiondef = solutionDef.Inherit(); + + var originalModel = SPMeta2Model.NewFarmModel(farm => + { + farm.AddFarmSolution(solutionDef); + }); + + var newModel = SPMeta2Model.NewFarmModel(farm => + { + farm.AddFarmSolution(newSolutiondef); + }); + + TestModel(originalModel); + TestModel(newModel); + } + + #endregion + } +} diff --git a/SPMeta2/SPMeta2.Regression.Tests/Impl/Scenarios/FieldScenariosTest.cs b/SPMeta2/SPMeta2.Regression.Tests/Impl/Scenarios/FieldScenariosTest.cs index 09c21f1ec..1275dac27 100644 --- a/SPMeta2/SPMeta2.Regression.Tests/Impl/Scenarios/FieldScenariosTest.cs +++ b/SPMeta2/SPMeta2.Regression.Tests/Impl/Scenarios/FieldScenariosTest.cs @@ -7,6 +7,7 @@ using SPMeta2.Regression.Tests.Impl.Scenarios.Base; using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Text; using SPMeta2.Containers.Services; @@ -19,9 +20,64 @@ using SPMeta2.Attributes.Regression; using SPMeta2.Containers.Extensions; +using SPMeta2.Exceptions; +using SPMeta2.Models; + +using SPMeta2.Regression.Tests.Utils; +using ReflectionUtils = SPMeta2.Utils.ReflectionUtils; namespace SPMeta2.Regression.Tests.Impl.Scenarios { + [TestClass] + public class FieldScenariosSelfTest + { + #region default values + + [TestMethod] + [TestCategory("Regression.Scenarios.Fields.DefaultValues")] + [TestCategory("CI.Core")] + public void SelfDiagnostic_AllFields_Should_Have_DefaultValue_Tests() + { + // check if FieldScenariosTest class has all testsfor field default values + // should not inherit SPMeta2RegresionScenarioTestBase as it will force to use (init) provisioners under CI + // that's why it is separated + + var isValid = true; + + var methods = typeof(FieldScenariosTest).GetMethods(); + var targetTypes = new List(); + + var assemblies = new[] + { + typeof(FieldDefinition).Assembly, + typeof(TaxonomyFieldDefinition).Assembly + }; + + targetTypes.AddRange(ReflectionUtils.GetTypesFromAssemblies(assemblies)); + + Trace.WriteLine(string.Format("Found [{0}] fied types.", targetTypes.Count)); + + foreach (var fieldType in targetTypes.OrderBy(m => m.Name)) + { + var fullDefName = fieldType.Name; + var shortDefName = fieldType.Name.Replace("Definition", string.Empty); + + var testName = string.Format("CanDeploy_{0}_DefaultValue", shortDefName); + + var testExists = methods.Any(m => m.Name == testName); + + if (!testExists) + isValid = false; + + Trace.WriteLine(string.Format("[{0}] def: {1} test method: {2}", + testExists, fullDefName, testName)); + } + + Assert.IsTrue(isValid); + } + #endregion + } + [TestClass] public class FieldScenariosTest : SPMeta2RegresionScenarioTestBase { @@ -405,7 +461,7 @@ protected List GetAllRandomFields() var spMetaAssembly = typeof(FieldDefinition).Assembly; var spMetaStandardAssembly = typeof(TaxonomyFieldDefinition).Assembly; - var types = ReflectionUtils.GetTypesFromAssemblies(new[] + var types = SPMeta2.Utils.ReflectionUtils.GetTypesFromAssemblies(new[] { spMetaAssembly, spMetaStandardAssembly @@ -760,6 +816,367 @@ public void CanDeploy_Field_To_O365_RootSiteCollection() #endregion + #region default values + + + + [TestMethod] + [TestCategory("Regression.Scenarios.Fields.DefaultValues")] + public void CanDeploy_BooleanField_DefaultValue() + { + // Cover FieldDefinition.DefaultValue with regression tests #595 + // https://github.com/SubPointSolutions/spmeta2/issues/595 + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.Fields.DefaultValues")] + public void CanDeploy_BusinessDataField_DefaultValue() + { + // Cover FieldDefinition.DefaultValue with regression tests #595 + // https://github.com/SubPointSolutions/spmeta2/issues/595 + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.Fields.DefaultValues")] + public void CanDeploy_CalculatedField_DefaultValue() + { + // Cover FieldDefinition.DefaultValue with regression tests #595 + // https://github.com/SubPointSolutions/spmeta2/issues/595 + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.Fields.DefaultValues")] + public void CanDeploy_ChoiceField_DefaultValue() + { + // Cover FieldDefinition.DefaultValue with regression tests #595 + // https://github.com/SubPointSolutions/spmeta2/issues/595 + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.Fields.DefaultValues")] + public void CanDeploy_ComputedField_DefaultValue() + { + // Cover FieldDefinition.DefaultValue with regression tests #595 + // https://github.com/SubPointSolutions/spmeta2/issues/595 + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.Fields.DefaultValues")] + public void CanDeploy_CurrencyField_DefaultValue() + { + // Cover FieldDefinition.DefaultValue with regression tests #595 + // https://github.com/SubPointSolutions/spmeta2/issues/595 + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.Fields.DefaultValues")] + public void CanDeploy_DateTimeField_DefaultValue() + { + // Cover FieldDefinition.DefaultValue with regression tests #595 + // https://github.com/SubPointSolutions/spmeta2/issues/595 + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.Fields.DefaultValues")] + public void CanDeploy_DependentLookupField_DefaultValue() + { + // Cover FieldDefinition.DefaultValue with regression tests #595 + // https://github.com/SubPointSolutions/spmeta2/issues/595 + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.Fields.DefaultValues")] + public void CanDeploy_Field_DefaultValue() + { + // Cover FieldDefinition.DefaultValue with regression tests #595 + // https://github.com/SubPointSolutions/spmeta2/issues/595 + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.Fields.DefaultValues")] + public void CanDeploy_GeolocationField_DefaultValue() + { + // Cover FieldDefinition.DefaultValue with regression tests #595 + // https://github.com/SubPointSolutions/spmeta2/issues/595 + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.Fields.DefaultValues")] + public void CanDeploy_GuidField_DefaultValue() + { + // Cover FieldDefinition.DefaultValue with regression tests #595 + // https://github.com/SubPointSolutions/spmeta2/issues/595 + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.Fields.DefaultValues")] + public void CanDeploy_HTMLField_DefaultValue() + { + // Cover FieldDefinition.DefaultValue with regression tests #595 + // https://github.com/SubPointSolutions/spmeta2/issues/595 + throw new NotImplementedException(); + } + + + [TestMethod] + [TestCategory("Regression.Scenarios.Fields.DefaultValues")] + public void CanDeploy_ImageField_DefaultValue() + { + // Cover FieldDefinition.DefaultValue with regression tests #595 + // https://github.com/SubPointSolutions/spmeta2/issues/595 + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.Fields.DefaultValues")] + public void CanDeploy_LinkField_DefaultValue() + { + // Cover FieldDefinition.DefaultValue with regression tests #595 + // https://github.com/SubPointSolutions/spmeta2/issues/595 + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.Fields.DefaultValues")] + public void CanDeploy_LookupField_DefaultValue() + { + // Cover FieldDefinition.DefaultValue with regression tests #595 + // https://github.com/SubPointSolutions/spmeta2/issues/595 + throw new NotImplementedException(); + } + + + [TestMethod] + [TestCategory("Regression.Scenarios.Fields.DefaultValues")] + public void CanDeploy_MediaField_DefaultValue() + { + // Cover FieldDefinition.DefaultValue with regression tests #595 + // https://github.com/SubPointSolutions/spmeta2/issues/595 + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.Fields.DefaultValues")] + public void CanDeploy_MultiChoiceField_DefaultValue() + { + // Cover FieldDefinition.DefaultValue with regression tests #595 + // https://github.com/SubPointSolutions/spmeta2/issues/595 + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.Fields.DefaultValues")] + public void CanDeploy_NoteField_DefaultValue() + { + // Cover FieldDefinition.DefaultValue with regression tests #595 + // https://github.com/SubPointSolutions/spmeta2/issues/595 + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.Fields.DefaultValues")] + public void CanDeploy_NumberField_DefaultValue() + { + // Cover FieldDefinition.DefaultValue with regression tests #595 + // https://github.com/SubPointSolutions/spmeta2/issues/595 + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.Fields.DefaultValues")] + public void CanDeploy_OutcomeChoiceField_DefaultValue() + { + // Cover FieldDefinition.DefaultValue with regression tests #595 + // https://github.com/SubPointSolutions/spmeta2/issues/595 + throw new NotImplementedException(); + } + + + [TestMethod] + [TestCategory("Regression.Scenarios.Fields.DefaultValues")] + public void CanDeploy_SummaryLinkField_DefaultValue() + { + // Cover FieldDefinition.DefaultValue with regression tests #595 + // https://github.com/SubPointSolutions/spmeta2/issues/595 + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.Fields.DefaultValues")] + public void CanDeploy_TaxonomyField_DefaultValue() + { + // Cover FieldDefinition.DefaultValue with regression tests #595 + // https://github.com/SubPointSolutions/spmeta2/issues/595 + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.Fields.DefaultValues")] + public void CanDeploy_TextField_DefaultValue() + { + // Cover FieldDefinition.DefaultValue with regression tests #595 + // https://github.com/SubPointSolutions/spmeta2/issues/595 + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.Fields.DefaultValues")] + public void CanDeploy_URLField_DefaultValue() + { + // Cover FieldDefinition.DefaultValue with regression tests #595 + // https://github.com/SubPointSolutions/spmeta2/issues/595 + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.Fields.DefaultValues")] + public void CanDeploy_UserField_DefaultValue() + { + // Cover FieldDefinition.DefaultValue with regression tests #595 + // https://github.com/SubPointSolutions/spmeta2/issues/595 + throw new NotImplementedException(); + } + + #endregion + + #region PushChangesToLists tests + + [TestMethod] + [TestCategory("Regression.Scenarios.Fields.PushChangesToLists")] + public void CanDeploy_Field_Without_PushChangesToLists_OnSite() + { + InternalDeploySiteFieldWithPushChangesToLists(false); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.Fields.PushChangesToLists")] + public void CanDeploy_Field_With_PushChangesToLists_OnSite() + { + InternalDeploySiteFieldWithPushChangesToLists(true); + } + + private void InternalDeploySiteFieldWithPushChangesToLists(bool pushChangesToLists) + { + var oldFieldTitle = Rnd.String(); + var newFieldTitle = Rnd.String(); + + var oldSharePointFieldTitle = string.Empty; + var newSharePointFieldTitle = string.Empty; + + // defs + var oldFieldDef = ModelGeneratorService.GetRandomDefinition(def => + { + def.DefaultFormula = string.Empty; + def.ValidationFormula = string.Empty; + + def.Title = oldFieldTitle; + }); + + var newFieldDef = oldFieldDef.Inherit(def => + { + def.DefaultFormula = string.Empty; + def.ValidationFormula = string.Empty; + + def.Title = newFieldTitle; + + def.PushChangesToLists = pushChangesToLists; + }); + + var oldListDef = ModelGeneratorService.GetRandomDefinition(def => + { + + }); + + var newListDef = oldListDef.Inherit(def => + { + + }); + + var oldListFielLink = new ListFieldLinkDefinition + { + FieldId = oldFieldDef.Id + }; + + var newListFielLink = new ListFieldLinkDefinition + { + FieldId = oldFieldDef.Id + }; + + var oldSiteModel = SPMeta2Model.NewSiteModel(site => + { + site.AddField(oldFieldDef); + }); + + var oldWebModel = SPMeta2Model.NewWebModel(web => + { + web.AddList(oldListDef, list => + { + list.AddListFieldLink(oldListFielLink); + }); + }); + + var newWebModel = SPMeta2Model.NewWebModel(web => + { + web.AddList(newListDef, list => + { + list.AddListFieldLink(newListFielLink); + }); + }); + + var newSiteModel = SPMeta2Model.NewSiteModel(site => + { + site.AddField(newFieldDef); + }); + + // passing Reg_Title as definition PropertyBag + // later, validation handlers foe ListFieldLink will use Reg_Title instead of title + // bit if a hack + if (pushChangesToLists) + { + newListFielLink.PropertyBag.Add(new PropertyBagValue + { + Name = "_Reg_DisplayName", + Value = newFieldTitle + }); + } + else + { + newListFielLink.PropertyBag.Add(new PropertyBagValue + { + Name = "_Reg_DisplayName", + Value = oldFieldTitle + }); + } + + // deploy initial field and list + TestModel(oldSiteModel); + TestModel(oldWebModel); + + // deploy 'new' field model + TestModel(newSiteModel); + TestModel(newWebModel); + } + + private string ExtractFieldTitleFromObject(OnCreatingContext context) + { + var obj = context.Object; + + return obj.GetPropertyValue("Title") as string; + } + + #endregion + #region utils protected FieldDefinition GetLocalizedFieldDefinition() diff --git a/SPMeta2/SPMeta2.Regression.Tests/Impl/Scenarios/ListItemScenariousTest.cs b/SPMeta2/SPMeta2.Regression.Tests/Impl/Scenarios/ListItemScenariousTest.cs index 677b9ea6d..6217ddf47 100644 --- a/SPMeta2/SPMeta2.Regression.Tests/Impl/Scenarios/ListItemScenariousTest.cs +++ b/SPMeta2/SPMeta2.Regression.Tests/Impl/Scenarios/ListItemScenariousTest.cs @@ -1,234 +1,802 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using SPMeta2.Containers; -using SPMeta2.Definitions; -using SPMeta2.Enumerations; -using SPMeta2.Regression.Tests.Base; -using SPMeta2.Regression.Tests.Impl.Scenarios.Base; -using SPMeta2.Syntax.Default; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using SPMeta2.Definitions.Fields; -using SPMeta2.Regression.Tests.Prototypes; - - -namespace SPMeta2.Regression.Tests.Impl.Scenarios -{ - [TestClass] - public class ListItemScenariousTest : SPMeta2RegresionScenarioTestBase - { - #region internal - - [ClassInitializeAttribute] - public static void Init(TestContext context) - { - InternalInit(); - } - - [ClassCleanupAttribute] - public static void Cleanup() - { - InternalCleanup(); - } - - #endregion - - #region field values - - - [TestMethod] - [TestCategory("Regression.Scenarios.ListItems.Values")] - public void CanDeploy_ListItem_With_RequiredFieldValues() - { - var requiredText = RItemValues.GetRequiredTextField(ModelGeneratorService); - - var text1 = RItemValues.GetRandomTextField(ModelGeneratorService); - var text2 = RItemValues.GetRandomTextField(ModelGeneratorService); - - var contentTypeDef = ModelGeneratorService.GetRandomDefinition(def => - { - def.ParentContentTypeId = BuiltInContentTypeId.Item; - }); - - var itemDef = ModelGeneratorService.GetRandomDefinition(def => - { - def.ContentTypeName = contentTypeDef.Name; - - def.DefaultValues.Add(new FieldValue() - { - FieldName = requiredText.InternalName, - Value = Rnd.String() - }); - - def.Values.Add(new FieldValue() - { - FieldName = text1.InternalName, - Value = Rnd.String() - }); - - def.Values.Add(new FieldValue() - { - FieldName = text2.InternalName, - Value = Rnd.String() - }); - - }); - - var listDef = ModelGeneratorService.GetRandomDefinition(def => - { - def.ContentTypesEnabled = true; - def.TemplateType = BuiltInListTemplateTypeId.GenericList; - }); - - var siteModel = SPMeta2Model.NewSiteModel(site => - { - site.AddField(requiredText); - site.AddField(text1); - site.AddField(text2); - - site.AddContentType(contentTypeDef, contentType => - { - contentType.AddContentTypeFieldLink(requiredText); - contentType.AddContentTypeFieldLink(text1); - contentType.AddContentTypeFieldLink(text2); - }); - - }); - - var webModel = SPMeta2Model.NewWebModel(web => - { - web.AddList(listDef, list => - { - list.AddContentTypeLink(contentTypeDef); - list.AddListItem(itemDef); - }); - }); - - TestModel(siteModel, webModel); - } - - - [TestMethod] - [TestCategory("Regression.Scenarios.ListItems.Values")] - public void CanDeploy_ListItem_With_ContentType_ByName() - { - var contentTypeDef = ModelGeneratorService.GetRandomDefinition(def => - { - def.ParentContentTypeId = BuiltInContentTypeId.Item; - }); - - var itemDef = ModelGeneratorService.GetRandomDefinition(def => - { - def.ContentTypeName = contentTypeDef.Name; - }); - - var listDef = ModelGeneratorService.GetRandomDefinition(def => - { - def.ContentTypesEnabled = true; - def.TemplateType = BuiltInListTemplateTypeId.GenericList; - }); - - var siteModel = SPMeta2Model.NewSiteModel(site => - { - site.AddContentType(contentTypeDef); - }); - - var webModel = SPMeta2Model.NewWebModel(web => - { - web.AddList(listDef, list => - { - list.AddContentTypeLink(contentTypeDef); - list.AddListItem(itemDef); - }); - }); - - TestModel(siteModel, webModel); - } - - #endregion - - #region default list - - [TestMethod] - [TestCategory("Regression.Scenarios.ListItems")] - public void CanDeploy_ListItem_ToList() - { - var list = ModelGeneratorService.GetRandomDefinition(def => - { - def.EnableMinorVersions = false; - def.TemplateType = BuiltInListTemplateTypeId.GenericList; - }); - - var model = SPMeta2Model - .NewWebModel(web => - { - web.AddList(list, rndList => - { - rndList.AddRandomListItem(); - }); - - }); - - TestModel(model); - } - - - [TestMethod] - [TestCategory("Regression.Scenarios.ListItems")] - public void CanDeploy_ListItem_ToListFolder() - { - var list = ModelGeneratorService.GetRandomDefinition(def => - { - def.TemplateType = BuiltInListTemplateTypeId.GenericList; - }); - - var model = SPMeta2Model - .NewWebModel(web => - { - web.AddList(list, rndList => - { - rndList.AddRandomFolder(rndFolder => - { - rndFolder.AddRandomListItem(); - }); - }); - - }); - - TestModel(model); - } - - [TestMethod] - [TestCategory("Regression.Scenarios.ListItems")] - public void CanDeploy_ListItem_ToListSubFolder() - { - var list = ModelGeneratorService.GetRandomDefinition(def => - { - def.EnableMinorVersions = false; - def.TemplateType = BuiltInListTemplateTypeId.GenericList; - }); - - var model = SPMeta2Model - .NewWebModel(web => - { - web.AddList(list, rndList => - { - rndList.AddRandomFolder(rndFolder => - { - rndFolder.AddRandomFolder(rndSubFolder => - { - rndSubFolder.AddRandomListItem(); - }); - - }); - }); - - }); - - TestModel(model); - } - - #endregion - } -} +using Microsoft.VisualStudio.TestTools.UnitTesting; +using SPMeta2.Containers; +using SPMeta2.Definitions; +using SPMeta2.Enumerations; +using SPMeta2.Regression.Tests.Base; +using SPMeta2.Regression.Tests.Impl.Scenarios.Base; +using SPMeta2.Syntax.Default; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using SPMeta2.Definitions.Fields; +using SPMeta2.Regression.Tests.Prototypes; +using SPMeta2.Standard.Definitions.Fields; +using SPMeta2.Utils; + + +namespace SPMeta2.Regression.Tests.Impl.Scenarios +{ + [TestClass] + public class ListItemScenariousSelfTest + { + #region default values + + [TestMethod] + [TestCategory("Regression.Scenarios.ListItems.Values")] + [TestCategory("CI.Core")] + public void SelfDiagnostic_AllFields_Should_Have_Value_Tests() + { + var isValid = true; + + var methods = typeof(ListItemScenariousTest).GetMethods(); + var targetTypes = new List(); + + var assemblies = new[] + { + typeof(FieldDefinition).Assembly, + typeof(TaxonomyFieldDefinition).Assembly + }; + + targetTypes.AddRange(ReflectionUtils.GetTypesFromAssemblies(assemblies)); + + Trace.WriteLine(string.Format("Found [{0}] fied types.", targetTypes.Count)); + + foreach (var fieldType in targetTypes.OrderBy(m => m.Name)) + { + var fullDefName = fieldType.Name; + var shortDefName = fieldType.Name.Replace("Definition", string.Empty); + + var testName1 = string.Format("CanDeploy_{0}_Value", shortDefName); + var testName2 = string.Format("CanDeploy_{0}_Values", shortDefName); + + var testExists1 = methods.Any(m => m.Name == testName1); + var testExists2 = methods.Any(m => m.Name == testName2); + + + if (!testExists1) + isValid = false; + + if (!testExists2) + isValid = false; + + Trace.WriteLine(string.Format("[{0}] def: {1} one value test method: {2}", + testExists1, fullDefName, testName1)); + + Trace.WriteLine(string.Format("[{0}] def: {1} multiple values test method: {2}", + testExists2, fullDefName, testName2)); + + Trace.WriteLine(string.Empty); + } + + Assert.IsTrue(isValid); + } + #endregion + } + + [TestClass] + public class ListItemScenariousTest : SPMeta2RegresionScenarioTestBase + { + #region internal + + [ClassInitializeAttribute] + public static void Init(TestContext context) + { + InternalInit(); + } + + [ClassCleanupAttribute] + public static void Cleanup() + { + InternalCleanup(); + } + + #endregion + + #region field values + + [TestMethod] + [TestCategory("Regression.Scenarios.ListItems.Values")] + public void CanDeploy_ListItem_With_RequiredFieldValues() + { + var requiredText = RItemValues.GetRequiredTextField(ModelGeneratorService); + + var text1 = RItemValues.GetRandomTextField(ModelGeneratorService); + var text2 = RItemValues.GetRandomTextField(ModelGeneratorService); + + var contentTypeDef = ModelGeneratorService.GetRandomDefinition(def => + { + def.ParentContentTypeId = BuiltInContentTypeId.Item; + }); + + var itemDef = ModelGeneratorService.GetRandomDefinition(def => + { + def.ContentTypeName = contentTypeDef.Name; + + def.DefaultValues.Add(new FieldValue() + { + FieldName = requiredText.InternalName, + Value = Rnd.String() + }); + + def.Values.Add(new FieldValue() + { + FieldName = text1.InternalName, + Value = Rnd.String() + }); + + def.Values.Add(new FieldValue() + { + FieldName = text2.InternalName, + Value = Rnd.String() + }); + + }); + + var listDef = ModelGeneratorService.GetRandomDefinition(def => + { + def.ContentTypesEnabled = true; + def.TemplateType = BuiltInListTemplateTypeId.GenericList; + }); + + var siteModel = SPMeta2Model.NewSiteModel(site => + { + site.AddField(requiredText); + site.AddField(text1); + site.AddField(text2); + + site.AddContentType(contentTypeDef, contentType => + { + contentType.AddContentTypeFieldLink(requiredText); + contentType.AddContentTypeFieldLink(text1); + contentType.AddContentTypeFieldLink(text2); + }); + + }); + + var webModel = SPMeta2Model.NewWebModel(web => + { + web.AddList(listDef, list => + { + list.AddContentTypeLink(contentTypeDef); + list.AddListItem(itemDef); + }); + }); + + TestModel(siteModel, webModel); + } + + + [TestMethod] + [TestCategory("Regression.Scenarios.ListItems.Values")] + public void CanDeploy_ListItem_With_ContentType_ByName() + { + var contentTypeDef = ModelGeneratorService.GetRandomDefinition(def => + { + def.ParentContentTypeId = BuiltInContentTypeId.Item; + }); + + var itemDef = ModelGeneratorService.GetRandomDefinition(def => + { + def.ContentTypeName = contentTypeDef.Name; + }); + + var listDef = ModelGeneratorService.GetRandomDefinition(def => + { + def.ContentTypesEnabled = true; + def.TemplateType = BuiltInListTemplateTypeId.GenericList; + }); + + var siteModel = SPMeta2Model.NewSiteModel(site => + { + site.AddContentType(contentTypeDef); + }); + + var webModel = SPMeta2Model.NewWebModel(web => + { + web.AddList(listDef, list => + { + list.AddContentTypeLink(contentTypeDef); + list.AddListItem(itemDef); + }); + }); + + TestModel(siteModel, webModel); + } + + #endregion + + #region default list + + [TestMethod] + [TestCategory("Regression.Scenarios.ListItems")] + public void CanDeploy_ListItem_ToList() + { + var list = ModelGeneratorService.GetRandomDefinition(def => + { + def.EnableMinorVersions = false; + def.TemplateType = BuiltInListTemplateTypeId.GenericList; + }); + + var model = SPMeta2Model + .NewWebModel(web => + { + web.AddList(list, rndList => + { + rndList.AddRandomListItem(); + }); + + }); + + TestModel(model); + } + + + [TestMethod] + [TestCategory("Regression.Scenarios.ListItems")] + public void CanDeploy_ListItem_ToListFolder() + { + var list = ModelGeneratorService.GetRandomDefinition(def => + { + def.TemplateType = BuiltInListTemplateTypeId.GenericList; + }); + + var model = SPMeta2Model + .NewWebModel(web => + { + web.AddList(list, rndList => + { + rndList.AddRandomFolder(rndFolder => + { + rndFolder.AddRandomListItem(); + }); + }); + + }); + + TestModel(model); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.ListItems")] + public void CanDeploy_ListItem_ToListSubFolder() + { + var list = ModelGeneratorService.GetRandomDefinition(def => + { + def.EnableMinorVersions = false; + def.TemplateType = BuiltInListTemplateTypeId.GenericList; + }); + + var model = SPMeta2Model + .NewWebModel(web => + { + web.AddList(list, rndList => + { + rndList.AddRandomFolder(rndFolder => + { + rndFolder.AddRandomFolder(rndSubFolder => + { + rndSubFolder.AddRandomListItem(); + }); + + }); + }); + + }); + + TestModel(model); + } + + #endregion + + #region field values + + + [TestMethod] + [TestCategory("Regression.Scenarios.ListItems.Values")] + public void CanDeploy_BooleanField_Value() + { + // Cover ListItemFieldValueDefinition/ListItemFieldValuesDefinition with regression test #533 + // https://github.com/SubPointSolutions/spmeta2/issues/533 + + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.ListItems.Values")] + public void CanDeploy_BooleanField_Values() + { + // Cover ListItemFieldValueDefinition/ListItemFieldValuesDefinition with regression test #533 + // https://github.com/SubPointSolutions/spmeta2/issues/533 + + throw new NotImplementedException(); + } + + + [TestMethod] + [TestCategory("Regression.Scenarios.ListItems.Values")] + public void CanDeploy_BusinessDataField_Value() + { + // Cover ListItemFieldValueDefinition/ListItemFieldValuesDefinition with regression test #533 + // https://github.com/SubPointSolutions/spmeta2/issues/533 + + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.ListItems.Values")] + public void CanDeploy_BusinessDataField_Values() + { + // Cover ListItemFieldValueDefinition/ListItemFieldValuesDefinition with regression test #533 + // https://github.com/SubPointSolutions/spmeta2/issues/533 + + throw new NotImplementedException(); + } + + + [TestMethod] + [TestCategory("Regression.Scenarios.ListItems.Values")] + public void CanDeploy_CalculatedField_Value() + { + // Cover ListItemFieldValueDefinition/ListItemFieldValuesDefinition with regression test #533 + // https://github.com/SubPointSolutions/spmeta2/issues/533 + + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.ListItems.Values")] + public void CanDeploy_CalculatedField_Values() + { + // Cover ListItemFieldValueDefinition/ListItemFieldValuesDefinition with regression test #533 + // https://github.com/SubPointSolutions/spmeta2/issues/533 + + throw new NotImplementedException(); + } + + + [TestMethod] + [TestCategory("Regression.Scenarios.ListItems.Values")] + public void CanDeploy_ChoiceField_Value() + { + // Cover ListItemFieldValueDefinition/ListItemFieldValuesDefinition with regression test #533 + // https://github.com/SubPointSolutions/spmeta2/issues/533 + + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.ListItems.Values")] + public void CanDeploy_ChoiceField_Values() + { + // Cover ListItemFieldValueDefinition/ListItemFieldValuesDefinition with regression test #533 + // https://github.com/SubPointSolutions/spmeta2/issues/533 + + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.ListItems.Values")] + public void CanDeploy_ComputedField_Value() + { + // Cover ListItemFieldValueDefinition/ListItemFieldValuesDefinition with regression test #533 + // https://github.com/SubPointSolutions/spmeta2/issues/533 + + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.ListItems.Values")] + public void CanDeploy_ComputedField_Values() + { + // Cover ListItemFieldValueDefinition/ListItemFieldValuesDefinition with regression test #533 + // https://github.com/SubPointSolutions/spmeta2/issues/533 + + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.ListItems.Values")] + public void CanDeploy_CurrencyField_Value() + { + // Cover ListItemFieldValueDefinition/ListItemFieldValuesDefinition with regression test #533 + // https://github.com/SubPointSolutions/spmeta2/issues/533 + + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.ListItems.Values")] + public void CanDeploy_CurrencyField_Values() + { + // Cover ListItemFieldValueDefinition/ListItemFieldValuesDefinition with regression test #533 + // https://github.com/SubPointSolutions/spmeta2/issues/533 + + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.ListItems.Values")] + public void CanDeploy_DateTimeField_Value() + { + // Cover ListItemFieldValueDefinition/ListItemFieldValuesDefinition with regression test #533 + // https://github.com/SubPointSolutions/spmeta2/issues/533 + + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.ListItems.Values")] + public void CanDeploy_DateTimeField_Values() + { + // Cover ListItemFieldValueDefinition/ListItemFieldValuesDefinition with regression test #533 + // https://github.com/SubPointSolutions/spmeta2/issues/533 + + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.ListItems.Values")] + public void CanDeploy_DependentLookupField_Value() + { + // Cover ListItemFieldValueDefinition/ListItemFieldValuesDefinition with regression test #533 + // https://github.com/SubPointSolutions/spmeta2/issues/533 + + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.ListItems.Values")] + public void CanDeploy_DependentLookupField_Values() + { + // Cover ListItemFieldValueDefinition/ListItemFieldValuesDefinition with regression test #533 + // https://github.com/SubPointSolutions/spmeta2/issues/533 + + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.ListItems.Values")] + public void CanDeploy_Field_Value() + { + // Cover ListItemFieldValueDefinition/ListItemFieldValuesDefinition with regression test #533 + // https://github.com/SubPointSolutions/spmeta2/issues/533 + + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.ListItems.Values")] + public void CanDeploy_Field_Values() + { + // Cover ListItemFieldValueDefinition/ListItemFieldValuesDefinition with regression test #533 + // https://github.com/SubPointSolutions/spmeta2/issues/533 + + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.ListItems.Values")] + public void CanDeploy_GeolocationField_Value() + { + // Cover ListItemFieldValueDefinition/ListItemFieldValuesDefinition with regression test #533 + // https://github.com/SubPointSolutions/spmeta2/issues/533 + + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.ListItems.Values")] + public void CanDeploy_GeolocationField_Values() + { + // Cover ListItemFieldValueDefinition/ListItemFieldValuesDefinition with regression test #533 + // https://github.com/SubPointSolutions/spmeta2/issues/533 + + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.ListItems.Values")] + public void CanDeploy_GuidField_Value() + { + // Cover ListItemFieldValueDefinition/ListItemFieldValuesDefinition with regression test #533 + // https://github.com/SubPointSolutions/spmeta2/issues/533 + + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.ListItems.Values")] + public void CanDeploy_GuidField_Values() + { + // Cover ListItemFieldValueDefinition/ListItemFieldValuesDefinition with regression test #533 + // https://github.com/SubPointSolutions/spmeta2/issues/533 + + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.ListItems.Values")] + public void CanDeploy_HTMLField_Value() + { + // Cover ListItemFieldValueDefinition/ListItemFieldValuesDefinition with regression test #533 + // https://github.com/SubPointSolutions/spmeta2/issues/533 + + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.ListItems.Values")] + public void CanDeploy_HTMLField_Values() + { + // Cover ListItemFieldValueDefinition/ListItemFieldValuesDefinition with regression test #533 + // https://github.com/SubPointSolutions/spmeta2/issues/533 + + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.ListItems.Values")] + public void CanDeploy_ImageField_Value() + { + // Cover ListItemFieldValueDefinition/ListItemFieldValuesDefinition with regression test #533 + // https://github.com/SubPointSolutions/spmeta2/issues/533 + + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.ListItems.Values")] + public void CanDeploy_ImageField_Values() + { + // Cover ListItemFieldValueDefinition/ListItemFieldValuesDefinition with regression test #533 + // https://github.com/SubPointSolutions/spmeta2/issues/533 + + throw new NotImplementedException(); + } + + + [TestMethod] + [TestCategory("Regression.Scenarios.ListItems.Values")] + public void CanDeploy_LinkField_Value() + { + // Cover ListItemFieldValueDefinition/ListItemFieldValuesDefinition with regression test #533 + // https://github.com/SubPointSolutions/spmeta2/issues/533 + + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.ListItems.Values")] + public void CanDeploy_LinkField_Values() + { + // Cover ListItemFieldValueDefinition/ListItemFieldValuesDefinition with regression test #533 + // https://github.com/SubPointSolutions/spmeta2/issues/533 + + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.ListItems.Values")] + public void CanDeploy_LookupField_Value() + { + // Cover ListItemFieldValueDefinition/ListItemFieldValuesDefinition with regression test #533 + // https://github.com/SubPointSolutions/spmeta2/issues/533 + + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.ListItems.Values")] + public void CanDeploy_LookupField_Values() + { + // Cover ListItemFieldValueDefinition/ListItemFieldValuesDefinition with regression test #533 + // https://github.com/SubPointSolutions/spmeta2/issues/533 + + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.ListItems.Values")] + public void CanDeploy_MediaField_Value() + { + // Cover ListItemFieldValueDefinition/ListItemFieldValuesDefinition with regression test #533 + // https://github.com/SubPointSolutions/spmeta2/issues/533 + + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.ListItems.Values")] + public void CanDeploy_MediaField_Values() + { + // Cover ListItemFieldValueDefinition/ListItemFieldValuesDefinition with regression test #533 + // https://github.com/SubPointSolutions/spmeta2/issues/533 + + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.ListItems.Values")] + public void CanDeploy_MultiChoiceField_Value() + { + // Cover ListItemFieldValueDefinition/ListItemFieldValuesDefinition with regression test #533 + // https://github.com/SubPointSolutions/spmeta2/issues/533 + + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.ListItems.Values")] + public void CanDeploy_MultiChoiceField_Values() + { + // Cover ListItemFieldValueDefinition/ListItemFieldValuesDefinition with regression test #533 + // https://github.com/SubPointSolutions/spmeta2/issues/533 + + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.ListItems.Values")] + public void CanDeploy_NoteField_Value() + { + // Cover ListItemFieldValueDefinition/ListItemFieldValuesDefinition with regression test #533 + // https://github.com/SubPointSolutions/spmeta2/issues/533 + + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.ListItems.Values")] + public void CanDeploy_NoteField_Values() + { + // Cover ListItemFieldValueDefinition/ListItemFieldValuesDefinition with regression test #533 + // https://github.com/SubPointSolutions/spmeta2/issues/533 + + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.ListItems.Values")] + public void CanDeploy_NumberField_Value() + { + // Cover ListItemFieldValueDefinition/ListItemFieldValuesDefinition with regression test #533 + // https://github.com/SubPointSolutions/spmeta2/issues/533 + + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.ListItems.Values")] + public void CanDeploy_NumberField_Values() + { + // Cover ListItemFieldValueDefinition/ListItemFieldValuesDefinition with regression test #533 + // https://github.com/SubPointSolutions/spmeta2/issues/533 + + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.ListItems.Values")] + public void CanDeploy_OutcomeChoiceField_Value() + { + // Cover ListItemFieldValueDefinition/ListItemFieldValuesDefinition with regression test #533 + // https://github.com/SubPointSolutions/spmeta2/issues/533 + + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.ListItems.Values")] + public void CanDeploy_OutcomeChoiceField_Values() + { + // Cover ListItemFieldValueDefinition/ListItemFieldValuesDefinition with regression test #533 + // https://github.com/SubPointSolutions/spmeta2/issues/533 + + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.ListItems.Values")] + public void CanDeploy_SummaryLinkField_Value() + { + // Cover ListItemFieldValueDefinition/ListItemFieldValuesDefinition with regression test #533 + // https://github.com/SubPointSolutions/spmeta2/issues/533 + + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.ListItems.Values")] + public void CanDeploy_SummaryLinkField_Values() + { + // Cover ListItemFieldValueDefinition/ListItemFieldValuesDefinition with regression test #533 + // https://github.com/SubPointSolutions/spmeta2/issues/533 + + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.ListItems.Values")] + public void CanDeploy_TaxonomyField_Value() + { + // Cover ListItemFieldValueDefinition/ListItemFieldValuesDefinition with regression test #533 + // https://github.com/SubPointSolutions/spmeta2/issues/533 + + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.ListItems.Values")] + public void CanDeploy_TaxonomyField_Values() + { + // Cover ListItemFieldValueDefinition/ListItemFieldValuesDefinition with regression test #533 + // https://github.com/SubPointSolutions/spmeta2/issues/533 + + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.ListItems.Values")] + public void CanDeploy_TextField_Value() + { + // Cover ListItemFieldValueDefinition/ListItemFieldValuesDefinition with regression test #533 + // https://github.com/SubPointSolutions/spmeta2/issues/533 + + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.ListItems.Values")] + public void CanDeploy_TextField_Values() + { + // Cover ListItemFieldValueDefinition/ListItemFieldValuesDefinition with regression test #533 + // https://github.com/SubPointSolutions/spmeta2/issues/533 + + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.ListItems.Values")] + public void CanDeploy_URLField_Value() + { + // Cover ListItemFieldValueDefinition/ListItemFieldValuesDefinition with regression test #533 + // https://github.com/SubPointSolutions/spmeta2/issues/533 + + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.ListItems.Values")] + public void CanDeploy_URLField_Values() + { + // Cover ListItemFieldValueDefinition/ListItemFieldValuesDefinition with regression test #533 + // https://github.com/SubPointSolutions/spmeta2/issues/533 + + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.ListItems.Values")] + public void CanDeploy_UserField_Value() + { + // Cover ListItemFieldValueDefinition/ListItemFieldValuesDefinition with regression test #533 + // https://github.com/SubPointSolutions/spmeta2/issues/533 + + throw new NotImplementedException(); + } + + [TestMethod] + [TestCategory("Regression.Scenarios.ListItems.Values")] + public void CanDeploy_UserField_Values() + { + // Cover ListItemFieldValueDefinition/ListItemFieldValuesDefinition with regression test #533 + // https://github.com/SubPointSolutions/spmeta2/issues/533 + + throw new NotImplementedException(); + } + + #endregion + } +} diff --git a/SPMeta2/SPMeta2.Regression.Tests/Impl/Scenarios/MetadataNavigationSettingsScenarios.cs b/SPMeta2/SPMeta2.Regression.Tests/Impl/Scenarios/MetadataNavigationSettingsScenarios.cs index 0b59398ec..6b81457fe 100644 --- a/SPMeta2/SPMeta2.Regression.Tests/Impl/Scenarios/MetadataNavigationSettingsScenarios.cs +++ b/SPMeta2/SPMeta2.Regression.Tests/Impl/Scenarios/MetadataNavigationSettingsScenarios.cs @@ -39,21 +39,21 @@ public static void Cleanup() [TestCategory("Regression.Scenarios.MetadataNavigationSettings")] public void CanDeploy_MetadataNavigationSettings_With_Hierary() { - WithExcpectedException(typeof(SPMeta2NotImplementedException), () => - { - var managedNavSettings = ModelGeneratorService.GetRandomDefinition( - def => - { - def.Hierarchies.Clear(); - def.KeyFilters.Clear(); + var managedNavSettings = ModelGeneratorService.GetRandomDefinition( + def => + { + def.Hierarchies.Clear(); + def.KeyFilters.Clear(); - def.Hierarchies.Add(new MetadataNavigationHierarchy - { - FieldId = BuiltInFieldId.ContentTypeId - }); + def.Hierarchies.Add(new MetadataNavigationHierarchy + { + FieldId = BuiltInFieldId.ContentTypeId }); + }); - var model = SPMeta2Model.NewWebModel(web => + var model = SPMeta2Model.NewWebModel(rootWeb => + { + rootWeb.AddRandomWeb(web => { web.AddWebFeature(BuiltInWebFeatures.MetadataNavigationAndFiltering.Inherit(f => { @@ -64,37 +64,37 @@ public void CanDeploy_MetadataNavigationSettings_With_Hierary() { list.AddMetadataNavigationSettings(managedNavSettings); }); - }); - TestModel(model); }); + + TestModel(model); } [TestMethod] [TestCategory("Regression.Scenarios.MetadataNavigationSettings")] public void CanDeploy_MetadataNavigationSettings_With_KeyFilters() { - WithExcpectedException(typeof(SPMeta2NotImplementedException), () => - { - var managedNavSettings = ModelGeneratorService.GetRandomDefinition( - def => + var managedNavSettings = ModelGeneratorService.GetRandomDefinition( + def => + { + def.Hierarchies.Clear(); + def.KeyFilters.Clear(); + + def.KeyFilters.Add(new MetadataNavigationKeyFilter { - def.Hierarchies.Clear(); - def.KeyFilters.Clear(); - - def.KeyFilters.Add(new MetadataNavigationKeyFilter - { - FieldId = BuiltInFieldId.Created - }); - - def.KeyFilters.Add(new MetadataNavigationKeyFilter - { - FieldId = BuiltInFieldId.Modified - }); + FieldId = BuiltInFieldId.Created }); - var model = SPMeta2Model.NewWebModel(web => + def.KeyFilters.Add(new MetadataNavigationKeyFilter + { + FieldId = BuiltInFieldId.Modified + }); + }); + + var model = SPMeta2Model.NewWebModel(rootWeb => + { + rootWeb.AddRandomWeb(web => { web.AddWebFeature(BuiltInWebFeatures.MetadataNavigationAndFiltering.Inherit(f => { @@ -105,59 +105,58 @@ public void CanDeploy_MetadataNavigationSettings_With_KeyFilters() { list.AddMetadataNavigationSettings(managedNavSettings); }); - }); - TestModel(model); }); + + TestModel(model); } [TestMethod] [TestCategory("Regression.Scenarios.MetadataNavigationSettings")] public void CanDeploy_MetadataNavigationSettings_With_Hierarchies_And_KeyFilters() { - WithExcpectedException(typeof(SPMeta2NotImplementedException), - () => + + var managedNavSettings = ModelGeneratorService.GetRandomDefinition( + def => { + def.Hierarchies.Clear(); + def.KeyFilters.Clear(); - var managedNavSettings = ModelGeneratorService.GetRandomDefinition( - def => - { - def.Hierarchies.Clear(); - def.KeyFilters.Clear(); - - def.Hierarchies.Add(new MetadataNavigationHierarchy - { - FieldId = BuiltInFieldId.ContentTypeId - }); - - def.KeyFilters.Add(new MetadataNavigationKeyFilter - { - FieldId = BuiltInFieldId.Created - }); - - def.KeyFilters.Add(new MetadataNavigationKeyFilter - { - FieldId = BuiltInFieldId.Modified - }); - }); - - var model = SPMeta2Model.NewWebModel(web => + def.Hierarchies.Add(new MetadataNavigationHierarchy { - web.AddWebFeature(BuiltInWebFeatures.MetadataNavigationAndFiltering.Inherit(f => - { - f.Enable = true; - })); + FieldId = BuiltInFieldId.ContentTypeId + }); - web.AddRandomDocumentLibrary(list => - { - list.AddMetadataNavigationSettings(managedNavSettings); - }); + def.KeyFilters.Add(new MetadataNavigationKeyFilter + { + FieldId = BuiltInFieldId.Created + }); + def.KeyFilters.Add(new MetadataNavigationKeyFilter + { + FieldId = BuiltInFieldId.Modified }); + }); - TestModel(model); + var model = SPMeta2Model.NewWebModel(rootWeb => + { + rootWeb.AddRandomWeb(web => + { + web.AddWebFeature(BuiltInWebFeatures.MetadataNavigationAndFiltering.Inherit(f => + { + f.Enable = true; + })); + + web.AddRandomDocumentLibrary(list => + { + list.AddMetadataNavigationSettings(managedNavSettings); + }); }); + + }); + + TestModel(model); } #endregion diff --git a/SPMeta2/SPMeta2.Regression.Tests/Impl/Scenarios/Webparts/XsltListViewWebPartScenariosTest.cs b/SPMeta2/SPMeta2.Regression.Tests/Impl/Scenarios/Webparts/XsltListViewWebPartScenariosTest.cs index 4b1341576..14e3f61a5 100644 --- a/SPMeta2/SPMeta2.Regression.Tests/Impl/Scenarios/Webparts/XsltListViewWebPartScenariosTest.cs +++ b/SPMeta2/SPMeta2.Regression.Tests/Impl/Scenarios/Webparts/XsltListViewWebPartScenariosTest.cs @@ -1063,5 +1063,77 @@ public void CanDeploy_XsltListViewWebPart_At_SubWeb_FromRootWeb() } #endregion + + #region parameter bindings + + [TestMethod] + [TestCategory("Regression.Scenarios.Webparts.XsltListViewWebPart.ParameterBindings")] + public void CanDeploy_XsltListViewWebPart_With_ParameterBindings_ID_Filtering() + { + var dstList = ModelGeneratorService.GetRandomDefinition(def => + { + def.TemplateType = BuiltInListTemplateTypeId.GenericList; + }); + + var sourceList = ModelGeneratorService.GetRandomDefinition(def => + { + def.TemplateType = BuiltInListTemplateTypeId.GenericList; + }); + + var sourceListView = ModelGeneratorService.GetRandomDefinition(def => + { + def.Query = "{ID}"; + def.Hidden = true; + }); + + // this web part would be binded to list view + // it will also be performing 'filtering' via query string - ID + var xsltListViewWebpart = ModelGeneratorService.GetRandomDefinition(def => + { + def.ListId = Guid.Empty; + def.ListTitle = sourceList.Title; + def.ListUrl = string.Empty; + + def.ViewName = sourceListView.Title; + def.ViewId = null; + + def.JSLink = string.Empty; + + def.ParameterBindings.Add(new ParameterBindingValue + { + Name = "ID", + Location = "QueryString(ID)" + }); + }); + + var model = SPMeta2Model.NewWebModel(web => + { + web + .AddList(sourceList, list => + { + list.AddListView(sourceListView); + + list + .AddRandomListItem() + .AddRandomListItem() + .AddRandomListItem(); + }) + .AddList(dstList, list => + { + list + .AddRandomListItem() + .AddRandomListItem(); + + list.AddHostListView(BuiltInListViewDefinitions.Lists.EditForm, view => + { + view.AddXsltListViewWebPart(xsltListViewWebpart); + }); + }); + }); + + TestModel(model); + } + + #endregion } } diff --git a/SPMeta2/SPMeta2.Regression.Tests/Impl/Utils/ConvertUtilsTests.cs b/SPMeta2/SPMeta2.Regression.Tests/Impl/Utils/ConvertUtilsTests.cs index 47d4d26c2..688558847 100644 --- a/SPMeta2/SPMeta2.Regression.Tests/Impl/Utils/ConvertUtilsTests.cs +++ b/SPMeta2/SPMeta2.Regression.Tests/Impl/Utils/ConvertUtilsTests.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; -using System.Threading.Tasks; + namespace SPMeta2.Regression.Tests.Impl.Utils { diff --git a/SPMeta2/SPMeta2.Regression.Tests/Properties/AssemblyInfo.cs b/SPMeta2/SPMeta2.Regression.Tests/Properties/AssemblyInfo.cs index b70aa270c..bc387ee0e 100644 --- a/SPMeta2/SPMeta2.Regression.Tests/Properties/AssemblyInfo.cs +++ b/SPMeta2/SPMeta2.Regression.Tests/Properties/AssemblyInfo.cs @@ -33,4 +33,4 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.2.16298.0736")] +[assembly: AssemblyFileVersion("1.2.16305.1232")] diff --git a/SPMeta2/SPMeta2.Regression.Tests/SPMeta2.Regression.Tests.csproj b/SPMeta2/SPMeta2.Regression.Tests/SPMeta2.Regression.Tests.csproj index 8218eb09b..cd8ce74bc 100644 --- a/SPMeta2/SPMeta2.Regression.Tests/SPMeta2.Regression.Tests.csproj +++ b/SPMeta2/SPMeta2.Regression.Tests/SPMeta2.Regression.Tests.csproj @@ -162,6 +162,8 @@ + + diff --git a/SPMeta2/SPMeta2.Regression.Tests/Services/ExpectUpdateServices/ExpectUpdateAsIntRangeService.cs b/SPMeta2/SPMeta2.Regression.Tests/Services/ExpectUpdateServices/ExpectUpdateAsIntRangeService.cs index ebaf8c9c2..565912fba 100644 --- a/SPMeta2/SPMeta2.Regression.Tests/Services/ExpectUpdateServices/ExpectUpdateAsIntRangeService.cs +++ b/SPMeta2/SPMeta2.Regression.Tests/Services/ExpectUpdateServices/ExpectUpdateAsIntRangeService.cs @@ -30,6 +30,16 @@ public override object GetNewPropValue(ExpectUpdate attr, object obj, PropertyIn { newValue = Convert.ToUInt16(tmpValue); } + else if (prop.PropertyType == typeof(Int16?) || + prop.PropertyType == typeof(Int16)) + { + newValue = Convert.ToInt16(tmpValue); + } + else if (prop.PropertyType == typeof(UInt32?) || + prop.PropertyType == typeof(UInt32)) + { + newValue = Convert.ToUInt32(tmpValue); + } else { // TODO, as per case diff --git a/SPMeta2/SPMeta2.Regression.Tests/Utils/X509Utils.cs b/SPMeta2/SPMeta2.Regression.Tests/Utils/X509Utils.cs index 05d7f7685..b26ded650 100644 --- a/SPMeta2/SPMeta2.Regression.Tests/Utils/X509Utils.cs +++ b/SPMeta2/SPMeta2.Regression.Tests/Utils/X509Utils.cs @@ -3,7 +3,7 @@ using System.Linq; using System.Security.Cryptography.X509Certificates; using System.Text; -using System.Threading.Tasks; + namespace SPMeta2.Regression.Tests.Utils { diff --git a/SPMeta2/SPMeta2.Regression/Properties/AssemblyInfo.cs b/SPMeta2/SPMeta2.Regression/Properties/AssemblyInfo.cs index 62248c274..0c996cf6e 100644 --- a/SPMeta2/SPMeta2.Regression/Properties/AssemblyInfo.cs +++ b/SPMeta2/SPMeta2.Regression/Properties/AssemblyInfo.cs @@ -33,4 +33,4 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.16298.0736")] +[assembly: AssemblyFileVersion("1.0.16305.1232")] diff --git a/SPMeta2/SPMeta2.SSOM.Standard/ModelHandlers/DesignPackageModelHandler.cs b/SPMeta2/SPMeta2.SSOM.Standard/ModelHandlers/DesignPackageModelHandler.cs index 54c0c8960..159103a89 100644 --- a/SPMeta2/SPMeta2.SSOM.Standard/ModelHandlers/DesignPackageModelHandler.cs +++ b/SPMeta2/SPMeta2.SSOM.Standard/ModelHandlers/DesignPackageModelHandler.cs @@ -13,10 +13,11 @@ using SPMeta2.Standard.Definitions; using SPMeta2.Utils; using Microsoft.Office.Server.UserProfiles; +using SPMeta2.Services; namespace SPMeta2.SSOM.Standard.ModelHandlers { - public class DesignPackageModelHandler : SSOMModelHandlerBase + public class DesignPackageModelHandler : SandboxSolutionModelHandler { #region properties @@ -34,42 +35,140 @@ public override void DeployModel(object modelHost, DefinitionBase model) var siteModelHost = modelHost.WithAssertAndCast("modelHost", value => value.RequireNotNull()); var definition = model.WithAssertAndCast("model", value => value.RequireNotNull()); - DeployDefinition(modelHost, siteModelHost, definition); + DeployDesignPackage(modelHost, siteModelHost, definition); } - private void DeployDefinition(object modelHost, SiteModelHost siteModelHost, DesignPackageDefinition definition) + private void DeployDesignPackage(object modelHost, SiteModelHost siteModelHost, DesignPackageDefinition definition) { var site = siteModelHost.HostSite; - - // TODO, implementation - // Add DesignPackage provision support #166 - // https://github.com/SubPointSolutions/spmeta2/issues/166 - - DesignPackageDefinition currrentArtifact = null; + var sandboxSolution = FindExistingSolutionById(siteModelHost, definition.SolutionId); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioning, - Object = currrentArtifact, - ObjectType = typeof(DesignPackageDefinition), + Object = sandboxSolution, + ObjectType = typeof(SPUserSolution), ObjectDefinition = definition, ModelHost = modelHost }); - // TODO, implementation + if (sandboxSolution != null) + { + TraceService.Information((int)LogEventId.ModelProvisionProcessingExistingObject, + "Processing existing design package"); + } + else + { + TraceService.Information((int)LogEventId.ModelProvisionProcessingExistingObject, + "Processing new design package"); + } - InvokeOnModelEvent(this, new ModelEventArgs + var designPackageInfo = new DesignPackageInfo(definition.FileName, + definition.SolutionId, + definition.MajorVersion, + definition.MinorVersion); + + if (definition.Install) { - CurrentModelNode = null, - Model = null, - EventType = ModelEventType.OnProvisioned, - Object = currrentArtifact, - ObjectType = typeof(DesignPackageDefinition), - ObjectDefinition = definition, - ModelHost = modelHost - }); + // removing first + if (sandboxSolution != null) + { + TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Deleting existing sandbox solution"); + siteModelHost.HostSite.Solutions.Remove(sandboxSolution); + + var catalog = siteModelHost.HostSite.RootWeb.GetCatalog(SPListTemplateType.SolutionCatalog); + + try + { + var solutionFile = catalog.RootFolder.Files[sandboxSolution.Name]; + + if (solutionFile.Exists) + solutionFile.Delete(); + } + catch + { + TraceService.Information((int)LogEventId.ModelProvisionProcessingExistingObject, + "Error while deleting design package"); + } + } + + TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Deploying design package file to the root folder of the root web"); + + var rootFolder = site.RootWeb.RootFolder; + var tmpDesignPackageFile = rootFolder.Files.Add(definition.FileName, definition.Content, true); + + TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, + string.Format("Installing design package from URL:[{0}]", tmpDesignPackageFile.ServerRelativeUrl)); + + DesignPackage.Install(site, designPackageInfo, tmpDesignPackageFile.ServerRelativeUrl); + sandboxSolution = FindExistingSolutionById(siteModelHost, definition.SolutionId); + + if (definition.Apply) + { + TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Applying design package"); + DesignPackage.Apply(site, designPackageInfo); + } + else + { + TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Apply == false. Skipping design package activation"); + } + + // cleanup + if (tmpDesignPackageFile.Exists) + { + tmpDesignPackageFile.Delete(); + } + + InvokeOnModelEvent(this, new ModelEventArgs + { + CurrentModelNode = null, + Model = null, + EventType = ModelEventType.OnProvisioned, + Object = sandboxSolution, + ObjectType = typeof(SPUserSolution), + ObjectDefinition = definition, + ModelHost = modelHost + }); + } + else + { + TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Activate = false. Continue provision"); + + if (sandboxSolution != null) + { + TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Solution is NOT NULL. Checking Apply status"); + + if (definition.Apply) + { + TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Applying design package"); + DesignPackage.Apply(site, designPackageInfo); + } + else + { + TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, + "Apply == false. Skipping design package activation"); + } + } + else + { + TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Solution is NULL. Skipping Apply status"); + } + + sandboxSolution = FindExistingSolutionById(siteModelHost, definition.SolutionId); + + InvokeOnModelEvent(this, new ModelEventArgs + { + CurrentModelNode = null, + Model = null, + EventType = ModelEventType.OnProvisioned, + Object = sandboxSolution, + ObjectType = typeof(SPUserSolution), + ObjectDefinition = definition, + ModelHost = modelHost + }); + } } #endregion diff --git a/SPMeta2/SPMeta2.SSOM.Standard/Properties/AssemblyInfo.cs b/SPMeta2/SPMeta2.SSOM.Standard/Properties/AssemblyInfo.cs index 5c6399771..a0b4cc49f 100644 --- a/SPMeta2/SPMeta2.SSOM.Standard/Properties/AssemblyInfo.cs +++ b/SPMeta2/SPMeta2.SSOM.Standard/Properties/AssemblyInfo.cs @@ -33,4 +33,4 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.2.16298.0736")] +[assembly: AssemblyFileVersion("1.2.16305.1232")] diff --git a/SPMeta2/SPMeta2.SSOM/ModelHandlers/ContentTypeModelHandler.cs b/SPMeta2/SPMeta2.SSOM/ModelHandlers/ContentTypeModelHandler.cs index d24fa320c..3b54023c4 100644 --- a/SPMeta2/SPMeta2.SSOM/ModelHandlers/ContentTypeModelHandler.cs +++ b/SPMeta2/SPMeta2.SSOM/ModelHandlers/ContentTypeModelHandler.cs @@ -105,6 +105,7 @@ public override void DeployModel(object modelHost, DefinitionBase model) // by ID, by Name var targetContentType = tmpWeb.ContentTypes[contentTypeId]; + // fallback to name if (targetContentType == null) { targetContentType = tmpWeb.ContentTypes diff --git a/SPMeta2/SPMeta2.SSOM/ModelHandlers/FarmSolutionModelHandler.cs b/SPMeta2/SPMeta2.SSOM/ModelHandlers/FarmSolutionModelHandler.cs index 06fbe72aa..fbed68775 100644 --- a/SPMeta2/SPMeta2.SSOM/ModelHandlers/FarmSolutionModelHandler.cs +++ b/SPMeta2/SPMeta2.SSOM/ModelHandlers/FarmSolutionModelHandler.cs @@ -1,114 +1,415 @@ -using System.IO; -using Microsoft.SharePoint; -using Microsoft.SharePoint.Administration; -using SPMeta2.Common; -using SPMeta2.Definitions; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -using SPMeta2.Definitions.Base; -using SPMeta2.Services; -using SPMeta2.SSOM.ModelHosts; -using SPMeta2.Utils; - -namespace SPMeta2.SSOM.ModelHandlers -{ - public class FarmSolutionModelHandler : SSOMModelHandlerBase - { - #region properties - - public override Type TargetType - { - get { return typeof(FarmSolutionDefinition); } - } - - #endregion - - #region methods - - public override void DeployModel(object modelHost, DefinitionBase model) - { - var farmModelHost = modelHost.WithAssertAndCast("modelHost", value => value.RequireNotNull()); - var solutionModel = model.WithAssertAndCast("model", value => value.RequireNotNull()); - - DeploySolution(farmModelHost, solutionModel); - } - - protected SPSolution FindExistingSolution(FarmModelHost modelHost, FarmSolutionDefinition definition) - { - TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, - "Resolving farm solution by SolutionId: [{0}] and Name: [{1}]", +using System.IO; +using Microsoft.SharePoint; +using Microsoft.SharePoint.Administration; +using SPMeta2.Common; +using SPMeta2.Definitions; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +using SPMeta2.Definitions.Base; +using SPMeta2.Services; +using SPMeta2.SSOM.ModelHosts; +using SPMeta2.Utils; +using System.Threading; +using SPMeta2.Extensions; + +namespace SPMeta2.SSOM.ModelHandlers +{ + public class FarmSolutionModelHandler : SSOMModelHandlerBase + { + #region constructors + + public FarmSolutionModelHandler() + { + + } + + #endregion + + #region static + + static FarmSolutionModelHandler() + { + SolutionDeploymentTimeoutInMillisecond = 1000; + } + + #endregion + + #region properties + + public static int SolutionDeploymentTimeoutInMillisecond { get; set; } + protected bool IsQARun { get; set; } + + public override Type TargetType + { + get { return typeof(FarmSolutionDefinition); } + } + + #endregion + + #region methods + + public override void DeployModel(object modelHost, DefinitionBase model) + { + var farmModelHost = modelHost.WithAssertAndCast("modelHost", value => value.RequireNotNull()); + var solutionModel = model.WithAssertAndCast("model", value => value.RequireNotNull()); + + DeploySolutionDefinition(farmModelHost, solutionModel); + } + + protected SPSolution FindExistingSolution(FarmModelHost modelHost, FarmSolutionDefinition definition) + { + TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, + "Resolving farm solution by SolutionId: [{0}] and Name: [{1}]", new object[] { definition.SolutionId, definition.FileName - }); - - var farm = modelHost.HostFarm; - - return farm.Solutions.FirstOrDefault(s => - s.Name.ToUpper() == definition.FileName.ToUpper() || - definition.SolutionId != Guid.Empty && s.SolutionId == definition.SolutionId); - } - - private void DeploySolution(FarmModelHost modelHost, FarmSolutionDefinition definition) - { - var farm = modelHost.HostFarm; - var existringSolution = FindExistingSolution(modelHost, definition); - - InvokeOnModelEvent(this, new ModelEventArgs - { - CurrentModelNode = null, - Model = null, - EventType = ModelEventType.OnProvisioning, - Object = existringSolution, - ObjectType = typeof(SPSolution), - ObjectDefinition = definition, - ModelHost = modelHost - }); - - var tmpWspDirectory = string.Format("{0}_{1}", Path.GetFileNameWithoutExtension(definition.FileName), Guid.NewGuid().ToString("N")); - var tmpWspDirectoryPath = Path.Combine(Path.GetTempPath(), tmpWspDirectory); - - Directory.CreateDirectory(tmpWspDirectoryPath); - - var tmpWspFilPath = Path.Combine(tmpWspDirectoryPath, definition.FileName); - File.WriteAllBytes(tmpWspFilPath, definition.Content); - - if (existringSolution == null) - { - TraceService.Information((int)LogEventId.ModelProvisionProcessingNewObject, "Processing new farm solution"); - existringSolution = farm.Solutions.Add(tmpWspFilPath, (uint)definition.LCID); - } - else - { - TraceService.Information((int)LogEventId.ModelProvisionProcessingExistingObject, "Upgrading existing farm solution"); - - if (existringSolution.Deployed) - { - existringSolution.Upgrade(tmpWspFilPath); - } - else - { - // TODO - // https://github.com/SubPointSolutions/spmeta2/issues/324 - } - } - - InvokeOnModelEvent(this, new ModelEventArgs - { - CurrentModelNode = null, - Model = null, - EventType = ModelEventType.OnProvisioned, - Object = existringSolution, - ObjectType = typeof(SPSolution), - ObjectDefinition = definition, - ModelHost = modelHost - }); - } - - #endregion - } -} + }); + + var farm = modelHost.HostFarm; + + // always get anew instance of the farm + // that would refresh the .Solution colleciton with the right state of the solutions + farm = SPFarm.Local; + + return farm.Solutions.FirstOrDefault(s => + s.Name.ToUpper() == definition.FileName.ToUpper() || + definition.SolutionId != Guid.Empty && s.SolutionId == definition.SolutionId); + } + + private void DeploySolutionDefinition(FarmModelHost modelHost, FarmSolutionDefinition definition) + { + var farm = modelHost.HostFarm; + var existingSolution = FindExistingSolution(modelHost, definition); + + InvokeOnModelEvent(this, new ModelEventArgs + { + CurrentModelNode = null, + Model = null, + EventType = ModelEventType.OnProvisioning, + Object = existingSolution, + ObjectType = typeof(SPSolution), + ObjectDefinition = definition, + ModelHost = modelHost + }); + + // should retract? + if (existingSolution != null && definition.ShouldRetract == true) + { + RetractSolution(modelHost, definition, existingSolution); + existingSolution = FindExistingSolution(modelHost, definition); + } + else if (existingSolution == null && definition.ShouldRetract == true) + { + // set up flag for nn existing solution + if (IsQARun) + definition.SetPropertyBagValue("HadRetractHit"); + } + + + // should delete? + if (existingSolution != null && definition.ShouldDelete == true) + { + DeleteSolution(modelHost, definition, existingSolution); + existingSolution = FindExistingSolution(modelHost, definition); + } + + // should add? + if (definition.ShouldAdd == true) + { + // add solution to the farm + existingSolution = AddSolution(modelHost, definition); + } + + if (existingSolution != null && definition.ShouldUpgrade == true) + { + // should upgrade? + UpgradeSolution(modelHost, definition, existingSolution); + } + else if (existingSolution != null && definition.ShouldDeploy == true) + { + // should deploy? + DeploySolution(modelHost, definition, existingSolution); + } + + InvokeOnModelEvent(this, new ModelEventArgs + { + CurrentModelNode = null, + Model = null, + EventType = ModelEventType.OnProvisioned, + Object = existingSolution, + ObjectType = typeof(SPSolution), + ObjectDefinition = definition, + ModelHost = modelHost + }); + } + + protected virtual void DeploySolution(FarmModelHost modelHost, FarmSolutionDefinition definition, SPSolution existingSolution) + { + definition.SetPropertyBagValue("HadDeploymentHit"); + + if (!existingSolution.Deployed) + { + TraceService.Information((int)LogEventId.CoreCalls, string.Format("Deploying farm solution:[{0}]", existingSolution.Name)); + + var isNowDeployment = false; + + if (definition.DeploymentDate.HasValue) + { + TraceService.Information((int)LogEventId.CoreCalls, string.Format("Deploying solution on date [{0}]", definition.DeploymentDate.Value)); + + existingSolution.Deploy(definition.DeploymentDate.Value, + definition.DeploymentGlobalInstallWPPackDlls, + definition.DeploymentForce); + } + else + { + TraceService.Information((int)LogEventId.CoreCalls, string.Format("Deploying solution NOW.")); + + existingSolution.Deploy(DateTime.Now, + definition.DeploymentGlobalInstallWPPackDlls, + definition.DeploymentForce); + + isNowDeployment = true; + } + + var deployed = existingSolution.DeploymentState != SPSolutionDeploymentState.NotDeployed; + + if (isNowDeployment) + { + TraceService.Information((int)LogEventId.CoreCalls, string.Format("Checking .Deployed status to be true")); + + while (!deployed) + { + TraceService.Information((int)LogEventId.CoreCalls, + string.Format("Sleeping [{0}] milliseconds...", SolutionDeploymentTimeoutInMillisecond)); + Thread.Sleep(SolutionDeploymentTimeoutInMillisecond); + + TraceService.Information((int)LogEventId.CoreCalls, + string.Format("Checkin .Deployed for solution [{0}] in [{1}] milliseconds...", + existingSolution.Name, SolutionDeploymentTimeoutInMillisecond)); + + existingSolution = FindExistingSolution(modelHost, definition); + deployed = existingSolution.DeploymentState != SPSolutionDeploymentState.NotDeployed; + } + + TraceService.Information((int)LogEventId.CoreCalls, string.Format("Checking .Deployed status to be false")); + var jobExists = existingSolution.JobExists; + + while (jobExists) + { + TraceService.Information((int)LogEventId.CoreCalls, + string.Format("Sleeping [{0}] milliseconds...", SolutionDeploymentTimeoutInMillisecond)); + Thread.Sleep(SolutionDeploymentTimeoutInMillisecond); + + + TraceService.Information((int)LogEventId.CoreCalls, + string.Format("Checkin .JobExists for solution [{0}] in [{1}] milliseconds...", + existingSolution.Name, SolutionDeploymentTimeoutInMillisecond)); + + existingSolution = FindExistingSolution(modelHost, definition); + jobExists = existingSolution.JobExists; + } + + TraceService.Information((int)LogEventId.CoreCalls, string.Format(".Deployed is true AND .JobExists is false")); + } + else + { + TraceService.Information((int)LogEventId.CoreCalls, string.Format("Future deployment. Passing wait.")); + } + } + else + { + TraceService.Information((int)LogEventId.CoreCalls, string.Format("Farm solution:[{0}] was already deployed.", existingSolution.Name)); + } + } + + protected virtual void UpgradeSolution(FarmModelHost modelHost, FarmSolutionDefinition definition, SPSolution existingSolution) + { + definition.SetPropertyBagValue("HadUpgradetHit"); + + // ensure deployment state first + TraceService.Information((int)LogEventId.CoreCalls, string.Format("Ensuring deployment state. Solution must be deployed before upgrading.")); + DeploySolution(modelHost, definition, existingSolution); + + // upgrade + var tmpWspDirectory = string.Format("{0}_{1}", Path.GetFileNameWithoutExtension(definition.FileName), Guid.NewGuid().ToString("N")); + var tmpWspDirectoryPath = Path.Combine(Path.GetTempPath(), tmpWspDirectory); + + Directory.CreateDirectory(tmpWspDirectoryPath); + + var tmpWspFilPath = Path.Combine(tmpWspDirectoryPath, definition.FileName); + File.WriteAllBytes(tmpWspFilPath, definition.Content); + + var isNowDeployment = false; + + if (definition.UpgradeDate.HasValue) + { + existingSolution.Upgrade(tmpWspFilPath, definition.UpgradeDate.Value); + } + else + { + existingSolution.Upgrade(tmpWspFilPath, DateTime.Now); + isNowDeployment = true; + } + + var deployed = existingSolution.Deployed; + + if (isNowDeployment) + { + TraceService.Information((int)LogEventId.CoreCalls, string.Format("Checking .Deployed status to be true")); + + while (!deployed) + { + TraceService.Information((int)LogEventId.CoreCalls, + string.Format("Sleeping [{0}] milliseconds...", SolutionDeploymentTimeoutInMillisecond)); + Thread.Sleep(SolutionDeploymentTimeoutInMillisecond); + + TraceService.Information((int)LogEventId.CoreCalls, + string.Format("Checkin .Deployed for solution [{0}] in [{1}] milliseconds...", + existingSolution.Name, SolutionDeploymentTimeoutInMillisecond)); + + existingSolution = FindExistingSolution(modelHost, definition); + deployed = existingSolution.DeploymentState != SPSolutionDeploymentState.NotDeployed; + } + + existingSolution = FindExistingSolution(modelHost, definition); + TraceService.Information((int)LogEventId.CoreCalls, string.Format("Checking .Deployed status to be false")); + var jobExists = existingSolution.JobExists; + + while (jobExists) + { + TraceService.Information((int)LogEventId.CoreCalls, + string.Format("Sleeping [{0}] milliseconds...", SolutionDeploymentTimeoutInMillisecond)); + Thread.Sleep(SolutionDeploymentTimeoutInMillisecond); + + + TraceService.Information((int)LogEventId.CoreCalls, + string.Format("Checkin .JobExists for solution [{0}] in [{1}] milliseconds...", + existingSolution.Name, SolutionDeploymentTimeoutInMillisecond)); + + existingSolution = FindExistingSolution(modelHost, definition); + jobExists = existingSolution.JobExists; + } + + TraceService.Information((int)LogEventId.CoreCalls, string.Format(".Deployed is true AND .JobExists is false")); + } + else + { + TraceService.Information((int)LogEventId.CoreCalls, string.Format("Future upgrade. Passing wait.")); + } + } + + protected virtual void DeleteSolution(FarmModelHost modelHost, FarmSolutionDefinition definition, SPSolution existingSolution) + { + if (IsQARun) + definition.SetPropertyBagValue("HadDeleteHit"); + + TraceService.Information((int)LogEventId.CoreCalls, string.Format("Deleting solution [{0}]", existingSolution.Name)); + existingSolution.Delete(); + } + + protected virtual void RetractSolution(FarmModelHost modelHost, FarmSolutionDefinition definition, SPSolution existingSolution) + { + if (IsQARun) + definition.SetPropertyBagValue("HadRetractHit"); + + TraceService.Information((int)LogEventId.CoreCalls, string.Format("Retracting solution [{0}]", existingSolution.Name)); + + if (existingSolution.Deployed) + { + var retracted = existingSolution.DeploymentState == SPSolutionDeploymentState.NotDeployed; + existingSolution.Retract(DateTime.Now); + + TraceService.Information((int)LogEventId.CoreCalls, string.Format("Checking .Deployed status to be false")); + + while (!retracted) + { + TraceService.Information((int)LogEventId.CoreCalls, + string.Format("Sleeping [{0}] milliseconds...", SolutionDeploymentTimeoutInMillisecond)); + Thread.Sleep(SolutionDeploymentTimeoutInMillisecond); + + TraceService.Information((int)LogEventId.CoreCalls, + string.Format("Checkin .Deployed for solution [{0}] in [{1}] milliseconds...", + existingSolution.Name, SolutionDeploymentTimeoutInMillisecond)); + + existingSolution = FindExistingSolution(modelHost, definition); + retracted = existingSolution.DeploymentState == SPSolutionDeploymentState.NotDeployed; + } + + existingSolution = FindExistingSolution(modelHost, definition); + + TraceService.Information((int)LogEventId.CoreCalls, string.Format("Checking .JobExists status to be false")); + var jobExists = existingSolution.JobExists; + + while (jobExists) + { + TraceService.Information((int)LogEventId.CoreCalls, + string.Format("Sleeping [{0}] milliseconds...", SolutionDeploymentTimeoutInMillisecond)); + Thread.Sleep(SolutionDeploymentTimeoutInMillisecond); + + + TraceService.Information((int)LogEventId.CoreCalls, + string.Format("Checkin .JobExists for solution [{0}] in [{1}] milliseconds...", + existingSolution.Name, SolutionDeploymentTimeoutInMillisecond)); + + existingSolution = FindExistingSolution(modelHost, definition); + jobExists = existingSolution.JobExists; + } + + existingSolution = FindExistingSolution(modelHost, definition); + + TraceService.Information((int)LogEventId.CoreCalls, string.Format(".Deployed and .JobExists are false")); + } + else + { + TraceService.Information((int)LogEventId.CoreCalls, string.Format("Solution was already retracted.")); + } + } + + protected virtual SPSolution AddSolution(FarmModelHost modelHost, FarmSolutionDefinition definition) + { + if (IsQARun) + definition.SetPropertyBagValue("HadAddHit"); + + TraceService.Information((int)LogEventId.CoreCalls, string.Format("Adding solution [{0}]", definition.FileName)); + + var farm = modelHost.HostFarm; + + var existringSolution = FindExistingSolution(modelHost, definition); + + var tmpWspDirectory = string.Format("{0}_{1}", Path.GetFileNameWithoutExtension(definition.FileName), Guid.NewGuid().ToString("N")); + var tmpWspDirectoryPath = Path.Combine(Path.GetTempPath(), tmpWspDirectory); + + Directory.CreateDirectory(tmpWspDirectoryPath); + + var tmpWspFilPath = Path.Combine(tmpWspDirectoryPath, definition.FileName); + File.WriteAllBytes(tmpWspFilPath, definition.Content); + + if (existringSolution == null) + { + TraceService.Information((int)LogEventId.ModelProvisionProcessingNewObject, "Processing new farm solution"); + + if (definition.LCID.HasValue) + { + existringSolution = farm.Solutions.Add(tmpWspFilPath, (uint)definition.LCID); + } + else + { + existringSolution = farm.Solutions.Add(tmpWspFilPath); + } + } + else + { + TraceService.Information((int)LogEventId.ModelProvisionProcessingExistingObject, "Farm solution exists. No need to add."); + } + + return existringSolution; + } + + #endregion + } +} diff --git a/SPMeta2/SPMeta2.SSOM/ModelHandlers/FieldModelHandler.cs b/SPMeta2/SPMeta2.SSOM/ModelHandlers/FieldModelHandler.cs index cbf661c2a..7bd709c23 100644 --- a/SPMeta2/SPMeta2.SSOM/ModelHandlers/FieldModelHandler.cs +++ b/SPMeta2/SPMeta2.SSOM/ModelHandlers/FieldModelHandler.cs @@ -1,24 +1,22 @@ using System; using System.Linq; using System.Xml.Linq; + using Microsoft.SharePoint; + using SPMeta2.Common; using SPMeta2.Definitions; -using SPMeta2.Definitions.Base; using SPMeta2.Enumerations; -using SPMeta2.ModelHandlers; +using SPMeta2.Exceptions; using SPMeta2.Services; using SPMeta2.SSOM.ModelHosts; using SPMeta2.Utils; -using System.Globalization; -using SPMeta2.Exceptions; -using System.Diagnostics; namespace SPMeta2.SSOM.ModelHandlers { public class FieldModelHandler : SSOMModelHandlerBase { - #region construactors + #region constructors static FieldModelHandler() { @@ -90,7 +88,7 @@ public override void DeployModel(object modelHost, DefinitionBase model) var fieldModel = model.WithAssertAndCast("model", value => value.RequireNotNull()); - SPField field = null; + SPField field; var isListField = false; @@ -130,11 +128,26 @@ public override void DeployModel(object modelHost, DefinitionBase model) // no promotion for the list field, and force push for the site fields if (isListField) { + TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Update() for list field"); field.Update(); } else { - field.Update(true); + + if (fieldModel.PushChangesToLists.HasValue) + { + TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, + string.Format("UpdateAndPushChanges({0})", fieldModel.PushChangesToLists)); + + field.Update(fieldModel.PushChangesToLists.Value); + } + else + { + TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Update(true)"); + field.Update(true); + } + + } } diff --git a/SPMeta2/SPMeta2.SSOM/ModelHandlers/FolderModelHandler.cs b/SPMeta2/SPMeta2.SSOM/ModelHandlers/FolderModelHandler.cs index d4b92db1a..194d5d000 100644 --- a/SPMeta2/SPMeta2.SSOM/ModelHandlers/FolderModelHandler.cs +++ b/SPMeta2/SPMeta2.SSOM/ModelHandlers/FolderModelHandler.cs @@ -41,7 +41,7 @@ public override void WithResolvingModelHost(ModelHostResolveContext modelHostCon if (folderModelHost.CurrentLibrary != null) { - var currentFolder = EnsureLibraryFolder(folderModelHost, folderModel); + var currentFolder = FindCurrentLibraryFolder(folderModelHost, folderModel); var newContext = new FolderModelHost { @@ -55,7 +55,7 @@ public override void WithResolvingModelHost(ModelHostResolveContext modelHostCon } else if (folderModelHost.CurrentList != null) { - var currentListItem = EnsureListFolder(folderModelHost, folderModel); + var currentListItem = FindCurrentListFolder(folderModelHost, folderModel); var newContext = new FolderModelHost { @@ -136,6 +136,16 @@ protected SPFolder GetLibraryFolder(FolderModelHost folderModelHost, FolderDefin return folder; } + private SPListItem FindCurrentListFolder(FolderModelHost folderModelHost, FolderDefinition folderModel) + { + TraceService.Information((int)LogEventId.ModelProvisionCoreCall, "FindCurrentListFolder()"); + + var list = folderModelHost.CurrentList; + var currentFolder = GetListFolder(folderModelHost, folderModel); + + return currentFolder.Item; + } + private SPListItem EnsureListFolder(FolderModelHost folderModelHost, FolderDefinition folderModel) { TraceService.Information((int)LogEventId.ModelProvisionProcessingNewObject, "EnsureListFolder()"); @@ -210,7 +220,14 @@ private SPListItem EnsureListFolder(FolderModelHost folderModelHost, FolderDefin return currentFolderItem; } + private SPFolder FindCurrentLibraryFolder(FolderModelHost folderModelHost, FolderDefinition folderModel) + { + TraceService.Information((int)LogEventId.ModelProvisionCoreCall, "FindCurrentLibraryFolder()"); + + var currentFolder = GetLibraryFolder(folderModelHost, folderModel); + return currentFolder; + } private SPFolder EnsureLibraryFolder(FolderModelHost folderModelHost, FolderDefinition folderModel) { @@ -234,13 +251,18 @@ private SPFolder EnsureLibraryFolder(FolderModelHost folderModelHost, FolderDefi if (currentFolder == null || !currentFolder.Exists) { - TraceService.Information((int)LogEventId.ModelProvisionProcessingNewObject, "Processing new library folder"); + TraceService.Information((int)LogEventId.ModelProvisionProcessingNewObject, + "Processing new library folder"); currentFolder = parentFolder.SubFolders.Add(folderModel.Name); currentFolder.Update(); - MapFolderProperties(currentFolder.Item, folderModel); - currentFolder.Item.Update(); + // if NULL - that's /Forms or other 'hidden folder' within the library + if (currentFolder.Item != null) + { + MapFolderProperties(currentFolder.Item, folderModel); + currentFolder.Item.Update(); + } InvokeOnModelEvent(this, new ModelEventArgs { @@ -255,7 +277,8 @@ private SPFolder EnsureLibraryFolder(FolderModelHost folderModelHost, FolderDefi } else { - TraceService.Information((int)LogEventId.ModelProvisionProcessingExistingObject, "Processing existing library folder"); + TraceService.Information((int)LogEventId.ModelProvisionProcessingExistingObject, + "Processing existing library folder"); InvokeOnModelEvent(this, new ModelEventArgs { @@ -267,11 +290,15 @@ private SPFolder EnsureLibraryFolder(FolderModelHost folderModelHost, FolderDefi ObjectDefinition = folderModel, ModelHost = folderModelHost }); - - currentFolder.Update(); - MapFolderProperties(currentFolder.Item, folderModel); - currentFolder.Item.Update(); + //currentFolder.Update(); + + // if NULL - that's /Forms or other 'hidden folder' within the library + if (currentFolder.Item != null) + { + MapFolderProperties(currentFolder.Item, folderModel); + currentFolder.Item.Update(); + } } return currentFolder; diff --git a/SPMeta2/SPMeta2.SSOM/ModelHandlers/SandboxSolutionModelHandler.cs b/SPMeta2/SPMeta2.SSOM/ModelHandlers/SandboxSolutionModelHandler.cs index a87b00c5d..c8581eca8 100644 --- a/SPMeta2/SPMeta2.SSOM/ModelHandlers/SandboxSolutionModelHandler.cs +++ b/SPMeta2/SPMeta2.SSOM/ModelHandlers/SandboxSolutionModelHandler.cs @@ -1,123 +1,134 @@ -using SPMeta2.Common; -using SPMeta2.Definitions; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -using SPMeta2.Services; -using SPMeta2.Utils; -using SPMeta2.SSOM.ModelHosts; -using Microsoft.SharePoint; - -namespace SPMeta2.SSOM.ModelHandlers -{ - public class SandboxSolutionModelHandler : SSOMModelHandlerBase - { - #region properties - - public override Type TargetType - { - get { return typeof(SandboxSolutionDefinition); } - } - - #endregion - - #region methods - - public override void DeployModel(object modelHost, DefinitionBase model) - { - var siteModelHost = modelHost.WithAssertAndCast("modelHost", value => value.RequireNotNull()); - var sandboxSolutionDefinition = model.WithAssertAndCast("model", value => value.RequireNotNull()); - - DeploySandboxSolution(modelHost, siteModelHost, sandboxSolutionDefinition); - } - - private void DeploySandboxSolution(object modelHost, SiteModelHost siteModelHost, SandboxSolutionDefinition sandboxSolutionDefinition) - { - var existingSolutions = FindExistingSolutionFile(siteModelHost, sandboxSolutionDefinition); - var sandboxSolution = FindExistingSolution(siteModelHost, sandboxSolutionDefinition); - - InvokeOnModelEvent(this, new ModelEventArgs - { - CurrentModelNode = null, - Model = null, - EventType = ModelEventType.OnProvisioning, - Object = sandboxSolution, - ObjectType = typeof(SPUserSolution), - ObjectDefinition = sandboxSolutionDefinition, - ModelHost = modelHost - }); - - if (sandboxSolution != null) - TraceService.Information((int)LogEventId.ModelProvisionProcessingExistingObject, "Processing existing sandbox solution"); - - if (sandboxSolution != null && sandboxSolution.Status == SPUserSolutionStatus.Activated) - { - TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Deleting existing sandbox solution"); - siteModelHost.HostSite.Solutions.Remove(sandboxSolution); - } - - var solutionGallery = (SPDocumentLibrary)siteModelHost.HostSite.GetCatalog(SPListTemplateType.SolutionCatalog); - var file = solutionGallery.RootFolder.Files.Add(sandboxSolutionDefinition.FileName, sandboxSolutionDefinition.Content, true); - - if (sandboxSolutionDefinition.Activate) - { - TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Activating sandbox solution"); - - var userSolution = siteModelHost.HostSite.Solutions.Add(file.Item.ID); - - InvokeOnModelEvent(this, new ModelEventArgs - { - CurrentModelNode = null, - Model = null, - EventType = ModelEventType.OnProvisioned, - Object = userSolution, - ObjectType = typeof(SPUserSolution), - ObjectDefinition = sandboxSolutionDefinition, - ModelHost = modelHost - }); - } - else - { - TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Activate = false. Continue provision"); - - InvokeOnModelEvent(this, new ModelEventArgs - { - CurrentModelNode = null, - Model = null, - EventType = ModelEventType.OnProvisioned, - Object = sandboxSolution, - ObjectType = typeof(SPUserSolution), - ObjectDefinition = sandboxSolutionDefinition, - ModelHost = modelHost - }); - } - } - - protected SPUserSolution FindExistingSolution(SiteModelHost siteModelHost, - SandboxSolutionDefinition sandboxSolutionDefinition) - { - TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Resolving sandbox solution by SolutionId: [{0}]", sandboxSolutionDefinition.SolutionId); - - return siteModelHost.HostSite.Solutions.OfType() - .FirstOrDefault(f => f.SolutionId == sandboxSolutionDefinition.SolutionId); - } - - protected SPFile FindExistingSolutionFile(SiteModelHost siteModelHost, SandboxSolutionDefinition sandboxSolutionDefinition) - { - TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Resolving sandbox solution by FileName: [{0}]", sandboxSolutionDefinition.FileName); - - - var site = siteModelHost.HostSite; - var solutionGallery = (SPDocumentLibrary)site.GetCatalog(SPListTemplateType.SolutionCatalog); - - return solutionGallery.RootFolder - .Files - .OfType() - .FirstOrDefault(f => f.Name.ToUpper() == sandboxSolutionDefinition.FileName.ToUpper()); - } - - #endregion - } -} +using SPMeta2.Common; +using SPMeta2.Definitions; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +using SPMeta2.Services; +using SPMeta2.Utils; +using SPMeta2.SSOM.ModelHosts; +using Microsoft.SharePoint; + +namespace SPMeta2.SSOM.ModelHandlers +{ + public class SandboxSolutionModelHandler : SSOMModelHandlerBase + { + #region properties + + public override Type TargetType + { + get { return typeof(SandboxSolutionDefinition); } + } + + #endregion + + #region methods + + public override void DeployModel(object modelHost, DefinitionBase model) + { + var siteModelHost = modelHost.WithAssertAndCast("modelHost", value => value.RequireNotNull()); + var sandboxSolutionDefinition = model.WithAssertAndCast("model", value => value.RequireNotNull()); + + DeploySandboxSolution(modelHost, siteModelHost, sandboxSolutionDefinition); + } + + private void DeploySandboxSolution(object modelHost, SiteModelHost siteModelHost, SandboxSolutionDefinition sandboxSolutionDefinition) + { + var existingSolutions = FindExistingSolutionFile(siteModelHost, sandboxSolutionDefinition); + var sandboxSolution = FindExistingSolution(siteModelHost, sandboxSolutionDefinition); + + InvokeOnModelEvent(this, new ModelEventArgs + { + CurrentModelNode = null, + Model = null, + EventType = ModelEventType.OnProvisioning, + Object = sandboxSolution, + ObjectType = typeof(SPUserSolution), + ObjectDefinition = sandboxSolutionDefinition, + ModelHost = modelHost + }); + + if (sandboxSolution != null) + TraceService.Information((int)LogEventId.ModelProvisionProcessingExistingObject, "Processing existing sandbox solution"); + + if (sandboxSolution != null && sandboxSolution.Status == SPUserSolutionStatus.Activated) + { + TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Deleting existing sandbox solution"); + siteModelHost.HostSite.Solutions.Remove(sandboxSolution); + } + + var solutionGallery = (SPDocumentLibrary)siteModelHost.HostSite.GetCatalog(SPListTemplateType.SolutionCatalog); + var file = solutionGallery.RootFolder.Files.Add(sandboxSolutionDefinition.FileName, sandboxSolutionDefinition.Content, true); + + if (sandboxSolutionDefinition.Activate) + { + TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Activating sandbox solution"); + + var userSolution = siteModelHost.HostSite.Solutions.Add(file.Item.ID); + + InvokeOnModelEvent(this, new ModelEventArgs + { + CurrentModelNode = null, + Model = null, + EventType = ModelEventType.OnProvisioned, + Object = userSolution, + ObjectType = typeof(SPUserSolution), + ObjectDefinition = sandboxSolutionDefinition, + ModelHost = modelHost + }); + } + else + { + TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Activate = false. Continue provision"); + + InvokeOnModelEvent(this, new ModelEventArgs + { + CurrentModelNode = null, + Model = null, + EventType = ModelEventType.OnProvisioned, + Object = sandboxSolution, + ObjectType = typeof(SPUserSolution), + ObjectDefinition = sandboxSolutionDefinition, + ModelHost = modelHost + }); + } + } + + protected virtual SPUserSolution FindExistingSolution(SiteModelHost siteModelHost, + SandboxSolutionDefinition sandboxSolutionDefinition) + { + return FindExistingSolutionById(siteModelHost, sandboxSolutionDefinition.SolutionId); + } + + protected virtual SPUserSolution FindExistingSolutionById(SiteModelHost siteModelHost, + Guid solutionId) + { + TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Resolving sandbox solution by SolutionId: [{0}]", solutionId); + + // cler m_SiteSolutions flat to get always a fresh colletion + // m_SiteSolutions + var site = siteModelHost.HostSite; + ReflectionUtils.SetNonPublicFieldValue(site, "m_SiteSolutions", null); + + return siteModelHost.HostSite.Solutions.OfType() + .FirstOrDefault(f => f.SolutionId == solutionId); + } + + protected virtual SPFile FindExistingSolutionFile(SiteModelHost siteModelHost, SandboxSolutionDefinition sandboxSolutionDefinition) + { + TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Resolving sandbox solution by FileName: [{0}]", sandboxSolutionDefinition.FileName); + + + var site = siteModelHost.HostSite; + var solutionGallery = (SPDocumentLibrary)site.GetCatalog(SPListTemplateType.SolutionCatalog); + + return solutionGallery.RootFolder + .Files + .OfType() + .FirstOrDefault(f => f.Name.ToUpper() == sandboxSolutionDefinition.FileName.ToUpper()); + } + + #endregion + } +} diff --git a/SPMeta2/SPMeta2.SSOM/Properties/AssemblyInfo.cs b/SPMeta2/SPMeta2.SSOM/Properties/AssemblyInfo.cs index 24660227c..dcbd7f71e 100644 --- a/SPMeta2/SPMeta2.SSOM/Properties/AssemblyInfo.cs +++ b/SPMeta2/SPMeta2.SSOM/Properties/AssemblyInfo.cs @@ -33,4 +33,4 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.2.16298.0736")] +[assembly: AssemblyFileVersion("1.2.16305.1232")] diff --git a/SPMeta2/SPMeta2.Standard/Definitions/DesignPackageDefinition.cs b/SPMeta2/SPMeta2.Standard/Definitions/DesignPackageDefinition.cs index 233333663..f8cc8021b 100644 --- a/SPMeta2/SPMeta2.Standard/Definitions/DesignPackageDefinition.cs +++ b/SPMeta2/SPMeta2.Standard/Definitions/DesignPackageDefinition.cs @@ -10,14 +10,15 @@ using SPMeta2.Utils; using System.Runtime.Serialization; using SPMeta2.Attributes.Capabilities; +using SPMeta2.Definitions.Base; namespace SPMeta2.Standard.Definitions { /// /// Allows to define and deploy SharePoint design package. /// - [SPObjectType(SPObjectModelType.SSOM, "Microsoft.SharePoint.Publishing.DesignPackageInfo", "Microsoft.SharePoint.Publishing")] - [SPObjectType(SPObjectModelType.CSOM, "Microsoft.SharePoint.Client.Publishing.DesignPackageInfo", "Microsoft.SharePoint.Client.Publishing")] + [SPObjectType(SPObjectModelType.SSOM, "Microsoft.SharePoint.SPUserSolution", "Microsoft.SharePoint")] + [SPObjectType(SPObjectModelType.CSOM, "Microsoft.SharePoint.Client.File", "Microsoft.SharePoint.Client")] [DefaultParentHost(typeof(SiteDefinition))] [DefaultRootHost(typeof(SiteDefinition))] @@ -31,27 +32,45 @@ namespace SPMeta2.Standard.Definitions [ExpectManyInstances] - public class DesignPackageDefinition : DefinitionBase + public class DesignPackageDefinition : SolutionDefinitionBase { + #region ccontructors + + public DesignPackageDefinition() + { + Content = new byte[0]; + + Install = true; + Apply = false; + } + + #endregion + #region properties - [ExpectRequired] + [ExpectValidation] [DataMember] - [IdentityKey] - public string PackageName { get; set; } + public int MajorVersion { get; set; } - [ExpectRequired] - [DataMember] [ExpectValidation] - public Guid PackageGuid { get; set; } + [DataMember] + public int MinorVersion { get; set; } + /// + /// Represents DesignPackage.Install() call + /// True by default. + /// [ExpectValidation] [DataMember] - public int? MajorVersion { get; set; } + public bool Install { get; set; } + /// + /// Represents DesignPackage.Apply() call + /// False by default. + /// [ExpectValidation] [DataMember] - public int? MinorVersion { get; set; } + public bool Apply { get; set; } #endregion @@ -60,7 +79,10 @@ public class DesignPackageDefinition : DefinitionBase public override string ToString() { return new ToStringResult(this) - .AddPropertyValue(p => p.PackageName) + .AddPropertyValue(p => p.FileName) + .AddPropertyValue(p => p.SolutionId) + .AddPropertyValue(p => p.Install) + .AddPropertyValue(p => p.Apply) .ToString(); } diff --git a/SPMeta2/SPMeta2.Standard/Properties/AssemblyInfo.cs b/SPMeta2/SPMeta2.Standard/Properties/AssemblyInfo.cs index ec1e24334..57f95567c 100644 --- a/SPMeta2/SPMeta2.Standard/Properties/AssemblyInfo.cs +++ b/SPMeta2/SPMeta2.Standard/Properties/AssemblyInfo.cs @@ -33,4 +33,4 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.2.16298.0736")] +[assembly: AssemblyFileVersion("1.2.16305.1232")] diff --git a/SPMeta2/SPMeta2/Definitions/Base/SolutionDefinitionBase.cs b/SPMeta2/SPMeta2/Definitions/Base/SolutionDefinitionBase.cs index 1ba3869c9..0f218b8e7 100644 --- a/SPMeta2/SPMeta2/Definitions/Base/SolutionDefinitionBase.cs +++ b/SPMeta2/SPMeta2/Definitions/Base/SolutionDefinitionBase.cs @@ -1,44 +1,45 @@ -using System; -using System.Runtime.Serialization; -using SPMeta2.Attributes.Identity; -using SPMeta2.Attributes.Regression; - -namespace SPMeta2.Definitions.Base -{ - - /// - /// Base definition for farm and sandbox solution definitions. - /// - [DataContract] - public abstract class SolutionDefinitionBase : DefinitionBase - { - #region properties - - /// - /// Target solutions file name. - /// - /// - [ExpectValidation] - [ExpectRequired] - [DataMember] - public string FileName { get; set; } - - /// - /// Target sandbox solution content. - /// - [ExpectValidation] - [ExpectRequired] - [DataMember] - public byte[] Content { get; set; } - - /// - /// Target ID of the solution. - /// - [ExpectValidation] - [DataMember] - [IdentityKey] - public Guid SolutionId { get; set; } - - #endregion - } -} +using System; +using System.Runtime.Serialization; +using SPMeta2.Attributes.Identity; +using SPMeta2.Attributes.Regression; + +namespace SPMeta2.Definitions.Base +{ + + /// + /// Base definition for farm and sandbox solution definitions. + /// + [DataContract] + public abstract class SolutionDefinitionBase : DefinitionBase + { + #region properties + + /// + /// Target solutions file name. + /// + /// + [ExpectValidation] + [ExpectRequired] + [DataMember] + public string FileName { get; set; } + + /// + /// Target sandbox solution content. + /// + [ExpectValidation] + [ExpectRequired] + [DataMember] + public byte[] Content { get; set; } + + /// + /// Target ID of the solution. + /// + [ExpectValidation] + [DataMember] + [IdentityKey] + [ExpectRequired] + public Guid SolutionId { get; set; } + + #endregion + } +} diff --git a/SPMeta2/SPMeta2/Definitions/FarmSolutionDefinition.cs b/SPMeta2/SPMeta2/Definitions/FarmSolutionDefinition.cs index a63011256..1f144f965 100644 --- a/SPMeta2/SPMeta2/Definitions/FarmSolutionDefinition.cs +++ b/SPMeta2/SPMeta2/Definitions/FarmSolutionDefinition.cs @@ -1,63 +1,139 @@ -using System; -using System.Runtime.Serialization; -using SPMeta2.Attributes; -using SPMeta2.Attributes.Capabilities; -using SPMeta2.Attributes.Regression; -using SPMeta2.Definitions.Base; -using SPMeta2.Utils; - -namespace SPMeta2.Definitions -{ - /// - /// Allows to define and deploy SharePoint farm solution. - /// - /// - - [SPObjectType(SPObjectModelType.SSOM, "Microsoft.SharePoint.Administration.SPSolution", "Microsoft.SharePoint")] - - [DefaultParentHost(typeof(FarmDefinition))] - [DefaultRootHost(typeof(FarmDefinition))] - - [Serializable] - [DataContract] - [ExpectWithExtensionMethod] - - [ParentHostCapability(typeof(FarmDefinition))] - [ExpectManyInstances] - public class FarmSolutionDefinition : SolutionDefinitionBase - { - #region constructors - - public FarmSolutionDefinition() - { - LCID = 1033; - Content = new byte[0]; - } - - #endregion - - #region properties - - /// - /// Locale for the current solution. - /// - /// - [DataMember] - public int LCID { get; set; } - - #endregion - - #region methods - - public override string ToString() - { - return new ToStringResult(this) - .AddPropertyValue(p => p.FileName) - .AddPropertyValue(p => p.SolutionId) - .AddPropertyValue(p => p.LCID) - .ToString(); - } - - #endregion - } -} +using System; +using System.Runtime.Serialization; +using SPMeta2.Attributes; +using SPMeta2.Attributes.Capabilities; +using SPMeta2.Attributes.Regression; +using SPMeta2.Definitions.Base; +using SPMeta2.Utils; + +namespace SPMeta2.Definitions +{ + /// + /// Allows to define and deploy SharePoint farm solution + /// + /// Supports Retract, Delete, Add, Deploy/Update workflows with the ShouldXXX properties + /// By default always ShouldAdd always true. + /// + + [SPObjectType(SPObjectModelType.SSOM, "Microsoft.SharePoint.Administration.SPSolution", "Microsoft.SharePoint")] + + [DefaultParentHost(typeof(FarmDefinition))] + [DefaultRootHost(typeof(FarmDefinition))] + + [Serializable] + [DataContract] + [ExpectWithExtensionMethod] + + [ParentHostCapability(typeof(FarmDefinition))] + [ExpectManyInstances] + public class FarmSolutionDefinition : SolutionDefinitionBase + { + #region constructors + + public FarmSolutionDefinition() + { + // changed to int? + // no locale by default + //LCID = 1033; + + Content = new byte[0]; + + DeploymentGlobalInstallWPPackDlls = true; + DeploymentForce = true; + + ShouldAdd = true; + } + + #endregion + + #region properties + + /// + /// Locale for the current solution. + /// + /// + [DataMember] + [ExpectValidation] + public int? LCID { get; set; } + + /// + /// Indicates if solution has to be retracted + /// + [DataMember] + [ExpectValidation] + public bool? ShouldRetract { get; set; } + + /// + /// Indicates if solution has to be added + /// + [DataMember] + [ExpectValidation] + public bool? ShouldAdd { get; set; } + + /// + /// Indicates if solution has to be deleted + /// + [DataMember] + [ExpectValidation] + public bool? ShouldDelete { get; set; } + + /// + /// Indicates if solution has to be deployed + /// + [DataMember] + [ExpectValidation] + public bool? ShouldDeploy { get; set; } + + /// + /// Indicates if solution has to be upgraded + /// + [DataMember] + [ExpectValidation] + public bool? ShouldUpgrade { get; set; } + + /// + /// Deployment date. NULL for 'right now' + /// + [DataMember] + [ExpectValidation] + public DateTime? DeploymentDate { get; set; } + + /// + /// Upgrade date. NULL for 'right now' + /// + [DataMember] + [ExpectValidation] + public DateTime? UpgradeDate { get; set; } + + /// + /// Passed to SPSolution.Deploy() method. + /// TRUE by default + /// + [DataMember] + [ExpectValidation] + public bool DeploymentGlobalInstallWPPackDlls { get; set; } + + /// + /// Passed to SPSolution.Deploy() method. + /// TRUE by default + /// + [DataMember] + [ExpectValidation] + public bool DeploymentForce { get; set; } + + #endregion + + #region methods + + public override string ToString() + { + return new ToStringResult(this) + .AddPropertyValue(p => p.FileName) + .AddPropertyValue(p => p.SolutionId) + .AddPropertyValue(p => p.LCID) + .ToString(); + } + + #endregion + } +} diff --git a/SPMeta2/SPMeta2/Definitions/FieldDefinition.cs b/SPMeta2/SPMeta2/Definitions/FieldDefinition.cs index 26084d5ea..e8d6d144e 100644 --- a/SPMeta2/SPMeta2/Definitions/FieldDefinition.cs +++ b/SPMeta2/SPMeta2/Definitions/FieldDefinition.cs @@ -281,6 +281,10 @@ public FieldDefinition() [DataMember] public bool? EnforceUniqueValues { get; set; } + [ExpectValidation] + [DataMember] + public bool? PushChangesToLists { get; set; } + [ExpectValidation] [ExpectUpdate] [DataMember] diff --git a/SPMeta2/SPMeta2/Definitions/RegionalSettingsDefinition.cs b/SPMeta2/SPMeta2/Definitions/RegionalSettingsDefinition.cs index 4afdd4870..4d484ec5d 100644 --- a/SPMeta2/SPMeta2/Definitions/RegionalSettingsDefinition.cs +++ b/SPMeta2/SPMeta2/Definitions/RegionalSettingsDefinition.cs @@ -28,50 +28,74 @@ public class RegionalSettingsDefinition : DefinitionBase [ExpectValidation] [DataMember] + [ExpectUpdateAsIntRange(MinValue = 1, MaxValue = 5)] + [ExpectNullable] public short? AdjustHijriDays { get; set; } [ExpectValidation] [DataMember] + [ExpectUpdateAsIntRange(MinValue = 0, MaxValue = 16)] + [ExpectNullable] public short? AlternateCalendarType { get; set; } [ExpectValidation] [DataMember] + [ExpectUpdateAsIntRange(MinValue = 0, MaxValue = 16)] + [ExpectNullable] public short? CalendarType { get; set; } [ExpectValidation] [DataMember] + [ExpectUpdateAsIntRange(MinValue = 0, MaxValue = 38)] + [ExpectNullable] public short? Collation { get; set; } [ExpectValidation] [DataMember] + [ExpectNullable] + [ExpectUpdateAsIntRange(MinValue = 1, MaxValue = 4)] public uint? FirstDayOfWeek { get; set; } [ExpectValidation] [DataMember] + [ExpectUpdateAsIntRange(MinValue = 0, MaxValue = 2)] + [ExpectNullable] public short? FirstWeekOfYear { get; set; } - //[ExpectValidation] + [ExpectValidation] [DataMember] + [ExpectUpdateAsLCID] + [ExpectNullable] public uint? LocaleId { get; set; } [ExpectValidation] [DataMember] + [ExpectUpdate] + [ExpectNullable] public bool? ShowWeeks { get; set; } [ExpectValidation] [DataMember] + [ExpectUpdate] + [ExpectNullable] public bool? Time24 { get; set; } - //[ExpectValidation] + [ExpectValidation] [DataMember] + [ExpectUpdateAsIntRange(MinValue = 5, MaxValue = 8)] + [ExpectNullable] public short? WorkDayEndHour { get; set; } [ExpectValidation] [DataMember] + [ExpectUpdateAsIntRange(MinValue = 1, MaxValue = 5)] + [ExpectNullable] public short? WorkDays { get; set; } - //[ExpectValidation] + [ExpectValidation] [DataMember] + [ExpectUpdateAsIntRange(MinValue = 1, MaxValue = 4)] + [ExpectNullable] public short? WorkDayStartHour { get; set; } [ExpectValidation] diff --git a/SPMeta2/SPMeta2/Extensions/DefinitionBaseExtensions.cs b/SPMeta2/SPMeta2/Extensions/DefinitionBaseExtensions.cs new file mode 100644 index 000000000..d79be0a0c --- /dev/null +++ b/SPMeta2/SPMeta2/Extensions/DefinitionBaseExtensions.cs @@ -0,0 +1,67 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +using SPMeta2.Definitions; +using SPMeta2.Models; + +namespace SPMeta2.Extensions +{ + public static class DefinitionBaseExtensions + { + #region property bag + + public static DefinitionBase SetPropertyBagValue(this DefinitionBase definition, string name) + { + return SetPropertyBagValue(definition, name, true); + } + + public static DefinitionBase SetPropertyBagValue(this DefinitionBase definition, string name, object value) + { + return SetPropertyBagValue(definition, name, value != null ? definition.ToString() : string.Empty); + } + + public static DefinitionBase SetPropertyBagValue(this DefinitionBase definition, string name, string value) + { + var prop = FindPropertyBagValue(definition, name); + + if (prop == null) + { + prop = new PropertyBagValue + { + Name = name, + Value = value + }; + + definition.PropertyBag.Add(prop); + } + + prop.Value = value; + + return definition; + } + + public static string GetPropertyBagValue(this DefinitionBase definition, string name, string value) + { + var prop = FindPropertyBagValue(definition, name); + + if (prop != null) + return prop.Value; + + return null; + } + + public static PropertyBagValue FindPropertyBagValue(this DefinitionBase definition, string name) + { + return definition.PropertyBag.FirstOrDefault(p => p.Name.ToUpper() == name.ToUpper()); + } + + public static bool HasPropertyBagValue(this DefinitionBase definition, string name) + { + return FindPropertyBagValue(definition, name) != null; + } + + #endregion + } +} diff --git a/SPMeta2/SPMeta2/Properties/AssemblyInfo.cs b/SPMeta2/SPMeta2/Properties/AssemblyInfo.cs index ea94cd1f8..0eb33d088 100644 --- a/SPMeta2/SPMeta2/Properties/AssemblyInfo.cs +++ b/SPMeta2/SPMeta2/Properties/AssemblyInfo.cs @@ -32,4 +32,4 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.2.16298.0736")] +[assembly: AssemblyFileVersion("1.2.16305.1232")] diff --git a/SPMeta2/SPMeta2/SPMeta2.csproj b/SPMeta2/SPMeta2/SPMeta2.csproj index 8ee08216f..b4494e356 100644 --- a/SPMeta2/SPMeta2/SPMeta2.csproj +++ b/SPMeta2/SPMeta2/SPMeta2.csproj @@ -343,6 +343,7 @@ + diff --git a/SPMeta2/SPMeta2/Utils/ReflectionUtils.cs b/SPMeta2/SPMeta2/Utils/ReflectionUtils.cs index 26af33e1a..fbdc7e247 100644 --- a/SPMeta2/SPMeta2/Utils/ReflectionUtils.cs +++ b/SPMeta2/SPMeta2/Utils/ReflectionUtils.cs @@ -23,6 +23,18 @@ public static class ReflectionUtils { #region methods + #region set helpers + + public static void SetNonPublicFieldValue(object obj, string fieldName, object value) + { + var prop = obj.GetType().GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Instance); + + if (prop != null) + prop.SetValue(obj, value); + } + + #endregion + #region get prop methods public static IEnumerable GetPropertiesWithCustomAttribute(object obj) diff --git a/SPMeta2/SubPointSolutions.Docs/Properties/AssemblyInfo.cs b/SPMeta2/SubPointSolutions.Docs/Properties/AssemblyInfo.cs index aecad8bb7..2d66eb0e5 100644 --- a/SPMeta2/SubPointSolutions.Docs/Properties/AssemblyInfo.cs +++ b/SPMeta2/SubPointSolutions.Docs/Properties/AssemblyInfo.cs @@ -33,4 +33,4 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.16298.0736")] +[assembly: AssemblyFileVersion("1.0.16305.1232")]