public void CanDeploy_SandboxWebFeature() { var sandboxSolution = new SandboxSolutionDefinition() { FileName = string.Format("{0}.wsp", Rnd.String()), Activate = true, SolutionId = new Guid("e9a61998-07f2-45e9-ae43-9e93fa6b11bb"), Content = ModuleFileUtils.FromResource(GetType().Assembly, "SPMeta2.Regression.Tests.Templates.SandboxSolutions.SPMeta2.Containers.SandboxSolutionContainer.wsp") }; var siteModel = SPMeta2Model.NewSiteModel(site => { site.AddSandboxSolution(sandboxSolution); }); var model = SPMeta2Model .NewWebModel(web => { web.AddFeature(new FeatureDefinition { Enable = true, ForceActivate = true, Id = new Guid("b997a462-8efb-44cf-92c0-457e75c81798"), Scope = FeatureDefinitionScope.Web }); }); TestModel(siteModel, model); }
public override ModelNode ReverseSingleHost(object reverseHost, ReverseOptions options) { var item = (reverseHost as WebPartPageReverseHost).HostWebPartPageFile; var context = (reverseHost as WebPartPageReverseHost).HostClientContext; var def = new WebPartPageDefinition(); def.FileName = item.Name; def.Title = item.Title; // always reverse to CustomPageLayout // we don't know what is the content of the web part page using (var stream = File.OpenBinaryDirect( context, item.ServerRelativeUrl).Stream) { def.CustomPageLayout = Encoding.UTF8.GetString(ModuleFileUtils.ReadFully(stream)); } def.NeedOverride = true; return(new WebPartPageModelNode { Options = { RequireSelfProcessing = true }, Value = def }); }
public void CanDeploy_SandboxSiteFeature() { var sandboxSolution = new SandboxSolutionDefinition() { FileName = string.Format("{0}.wsp", Rnd.String()), Activate = true, SolutionId = new Guid("e9a61998-07f2-45e9-ae43-9e93fa6b11bb"), Content = ModuleFileUtils.FromResource(GetType().Assembly, "SPMeta2.Regression.Tests.Templates.SandboxSolutions.SPMeta2.Containers.SandboxSolutionContainer.wsp") }; var model = SPMeta2Model .NewSiteModel(site => { site.AddSandboxSolution(sandboxSolution); site.AddFeature(new FeatureDefinition { Enable = true, ForceActivate = true, Id = new Guid("32dc6bed-0298-4fca-a72f-e9b9c0d6f09a"), Scope = FeatureDefinitionScope.Site }); }); TestModel(model); }
public void CanDeploy_SandboxSiteFeature() { var sandboxSolution = new SandboxSolutionDefinition() { FileName = string.Format("{0}.wsp", Rnd.String()), Activate = true, SolutionId = new Guid("9f581901-7ed8-4293-9d48-c526ad5a3d7d"), Content = ModuleFileUtils.FromResource(GetType().Assembly, "SPMeta2.Regression.Tests.Templates.SandboxSolutions.SPMeta2.ScenarioTest.SandboxApp.wsp") }; var model = SPMeta2Model .NewSiteModel(site => { site.AddSandboxSolution(sandboxSolution); site.AddFeature(new FeatureDefinition { Enable = true, ForceActivate = true, Id = new Guid("167dc650-68d2-4784-bd5b-9c6709db4ac6"), Scope = FeatureDefinitionScope.Site }); }); TestModel(model); }
public override ModelNode ReverseSingleHost(object reverseHost, ReverseOptions options) { var item = (reverseHost as SandboxSolutionReverseHost).HostSandboxSolutionFile; var context = (reverseHost as SandboxSolutionReverseHost).HostClientContext; var def = new SandboxSolutionDefinition(); def.FileName = item.Name; def.SolutionId = ConvertUtils.ToGuid(item.ListItemAllFields["SolutionId"]).Value; def.Activate = true; using (var stream = File.OpenBinaryDirect( context, item.ServerRelativeUrl).Stream) { def.Content = ModuleFileUtils.ReadFully(stream); } return(new SandboxSolutionModelNode { Options = { RequireSelfProcessing = true }, Value = def }); }
public void CanDeploy_SandboxWebFeature() { var sandboxSolution = new SandboxSolutionDefinition() { FileName = string.Format("{0}.wsp", Rnd.String()), Activate = true, SolutionId = new Guid("9f581901-7ed8-4293-9d48-c526ad5a3d7d"), Content = ModuleFileUtils.FromResource(GetType().Assembly, "SPMeta2.Regression.Tests.Templates.SandboxSolutions.SPMeta2.ScenarioTest.SandboxApp.wsp") }; var siteModel = SPMeta2Model.NewSiteModel(site => { site.AddSandboxSolution(sandboxSolution); }); var model = SPMeta2Model .NewWebModel(web => { web.AddFeature(new FeatureDefinition { Enable = true, ForceActivate = true, Id = new Guid("e4a8e1de-6688-493b-ad7a-d35c0268550c"), Scope = FeatureDefinitionScope.Web }); }); TestModel(siteModel, model); }
public static ModelNode GetModel() { var model = SPMeta2Model.NewWebModel(web => { web .AddWebFeature(GoogleMapsFeatures.DisableMinimalDownloadStrategy) .AddField(GoogleMapsFields.LocationPoint) .AddField(GoogleMapsFields.LocationArea) .AddList(GoogleMapsLists.Locations, list => { list .AddField(GoogleMapsFields.LocationPoint) .AddField(GoogleMapsFields.LocationArea) .AddListView(GoogleMapsListViews.AllItems); }) .AddHostList(BuiltInListDefinitions.SiteAssets, list => { if (Directory.Exists(GoogleMapsConsts.SiteAssetsPath)) { ModuleFileUtils.LoadModuleFilesFromLocalFolder(list, GoogleMapsConsts.SiteAssetsPath); } }); }); return(model); }
//[SampleMetadataTag(Name = BuiltInTagNames.SampleHidden)] public void CanDeployUserCustomActionWithJquery() { var jQueryFile = new ModuleFileDefinition { FileName = "jquery-1.11.2.min.js", Content = ModuleFileUtils.FromResource(GetType().Assembly, "SPMeta2.Docs.Modules.jquery-1.11.2.min.js"), Overwrite = true }; var appScriptsFolder = new FolderDefinition { Name = "M2 App Scripts" }; var jQueryCustomAction = new UserCustomActionDefinition { Name = "m2jQuery", Location = "ScriptLink", ScriptSrc = UrlUtility.CombineUrl(new string[] { "~sitecollection", BuiltInListDefinitions.StyleLibrary.GetListUrl(), appScriptsFolder.Name, jQueryFile.FileName }), Sequence = 1500 }; var jQuerySiteLogger = new UserCustomActionDefinition { Name = "m2jQuerySiteLogger", Location = "ScriptLink", ScriptBlock = "jQuery(document).ready( function() { console.log('jQuery site logger on site:' + _spPageContextInfo.siteAbsoluteUrl); } );", Sequence = 1600 }; var siteModel = SPMeta2Model.NewSiteModel(site => { site .AddUserCustomAction(jQueryCustomAction) .AddUserCustomAction(jQuerySiteLogger); }); var webModel = SPMeta2Model.NewWebModel(web => { web.AddHostList(BuiltInListDefinitions.StyleLibrary, list => { list.AddFolder(appScriptsFolder, folder => { folder.AddModuleFile(jQueryFile); }); }); }); DeployModel(siteModel); DeployModel(webModel); }
public static byte[] GetContent(this SPFile file) { byte[] result = null; using (var stream = file.OpenBinaryStream()) result = ModuleFileUtils.ReadFully(stream); return(result); }
public override void DeployModel(object modelHost, DefinitionBase model) { var folderModelHost = modelHost.WithAssertAndCast <FolderModelHost>("modelHost", value => value.RequireNotNull()); var folder = folderModelHost.CurrentLibraryFolder; var definition = model.WithAssertAndCast <PublishingPageLayoutDefinition>("model", value => value.RequireNotNull()); var spObject = FindPublishingPage(folderModelHost.CurrentList, folder, definition); var spFile = spObject.File; var context = spObject.Context; context.Load(spObject); context.Load(spObject, o => o.DisplayName); context.Load(spFile, f => f.ServerRelativeUrl); context.ExecuteQuery(); var assert = ServiceFactory.AssertService .NewAssert(definition, spObject) .ShouldNotBeNull(spObject) .ShouldBeEqual(m => m.FileName, o => o.GetFileName()) .ShouldBeEqual(m => m.Description, o => o.GetPublishingPageLayoutDescription()) .ShouldBeEndOf(m => m.AssociatedContentTypeId, o => o.GetPublishingPageLayoutAssociatedContentTypeId()) .ShouldBeEqual(m => m.Title, o => o.GetTitle()); assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(m => m.Content); //var dstProp = d.GetExpressionValue(ct => ct.GetId()); var isContentValid = false; byte[] dstContent = null; using (var stream = File.OpenBinaryDirect(folderModelHost.HostClientContext, spFile.ServerRelativeUrl).Stream) dstContent = ModuleFileUtils.ReadFully(stream); var srcStringContent = s.Content; var dstStringContent = Encoding.UTF8.GetString(dstContent); srcStringContent = srcStringContent .Replace("meta:webpartpageexpansion=\"full\" ", string.Empty); isContentValid = dstStringContent.Contains(srcStringContent); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, // Dst = dstProp, IsValid = isContentValid }); }); }
public override DefinitionBase GenerateRandomDefinition(Action <DefinitionBase> action) { return(WithEmptyDefinition(def => { def.FileName = string.Format("{0}.wsp", Rnd.String()); def.SolutionId = new Guid("9591a597-da94-47b4-a3c6-2f8703d4de2b"); def.Content = ModuleFileUtils.FromResource(GetType().Assembly, "SPMeta2.Containers.Templates.Apps.SPMeta2.Sandbox.TestFarmApp.wsp"); })); }
public void CanDeploy_List_From_CustomTemplate() { var sandboxSolution = new SandboxSolutionDefinition() { FileName = string.Format("{0}.wsp", Rnd.String()), Activate = true, SolutionId = new Guid("e9a61998-07f2-45e9-ae43-9e93fa6b11bb"), Content = ModuleFileUtils.FromResource(GetType().Assembly, "SPMeta2.Regression.Tests.Templates.SandboxSolutions.SPMeta2.Containers.SandboxSolutionContainer.wsp") }; var customListDef = ModelGeneratorService.GetRandomDefinition <ListDefinition>(def => { def.TemplateType = BuiltInListTemplateTypeId.GenericList; def.ForceCheckout = false; #pragma warning disable 618 def.Url = Rnd.String(); #pragma warning restore 618 def.CustomUrl = string.Empty; // would give invalid list template exception //def.TemplateType = 10500; // works well, just reset TemplateType as GetRandomDefinition<> generated random TemplateType def.TemplateType = 0; def.TemplateName = "CustomerList"; }); var siteModel = SPMeta2Model .NewSiteModel(site => { site.AddSandboxSolution(sandboxSolution); }); var webModel = SPMeta2Model .NewWebModel(web => { web.AddRandomWeb(subWeb => { subWeb.AddWebFeature(new FeatureDefinition { Id = new Guid("b997a462-8efb-44cf-92c0-457e75c81798"), Scope = FeatureDefinitionScope.Web, Enable = true, ForceActivate = true }); subWeb.AddList(customListDef); }); }); TestModel(siteModel, webModel); }
public override DefinitionBase GenerateRandomDefinition(Action <DefinitionBase> action) { return(WithEmptyDefinition(def => { def.FileName = string.Format("{0}.wsp", Rnd.String()); def.Activate = Rnd.Bool(); def.SolutionId = new Guid("e34d1ce3-62da-4a73-a382-a49af8e5dde0"); def.Content = ModuleFileUtils.FromResource(GetType().Assembly, "SPMeta2.Containers.Templates.Apps.SPMeta2.Sandbox.TestSandboxApp.wsp"); })); }
public override DefinitionBase GenerateRandomDefinition(Action <DefinitionBase> action) { return(WithEmptyDefinition(def => { def.FileName = string.Format("{0}.wsp", Rnd.String()); def.Activate = true; def.SolutionId = new Guid("e9a61998-07f2-45e9-ae43-9e93fa6b11bb"); def.Content = ModuleFileUtils.FromResource(GetType().Assembly, "SPMeta2.Containers.Templates.Apps.SPMeta2.Containers.SandboxSolutionContainer.wsp"); })); }
public override void DeployModel(object modelHost, DefinitionBase model) { var folderModelHost = modelHost.WithAssertAndCast <FolderModelHost>("modelHost", value => value.RequireNotNull()); var folder = folderModelHost.CurrentLibraryFolder; var definition = model.WithAssertAndCast <TemplateDefinitionBase>("model", value => value.RequireNotNull()); var spFile = GetItemFile(folderModelHost.CurrentList, folder, definition.FileName); var spObject = spFile.ListItemAllFields; var context = spObject.Context; context.Load(spObject); context.Load(spFile, f => f.ServerRelativeUrl); context.ExecuteQuery(); var assert = ServiceFactory.AssertService .NewAssert(definition, spObject) .ShouldNotBeNull(spObject) .ShouldBeEqual(m => m.Title, o => o.GetTitle()) .ShouldBeEqual(m => m.FileName, o => o.GetFileName()) //.ShouldBeEqual(m => m.CrawlerXSLFile, o => o.GetCrawlerXSLFile()) .ShouldBeEqual(m => m.HiddenTemplate, o => o.GetHiddenTemplate()) .ShouldBeEqual(m => m.Description, o => o.GetMasterPageDescription()) ; assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(m => m.Content); //var dstProp = d.GetExpressionValue(ct => ct.GetId()); var isContentValid = false; byte[] dstContent = null; using (var stream = File.OpenBinaryDirect(folderModelHost.HostClientContext, spFile.ServerRelativeUrl).Stream) dstContent = ModuleFileUtils.ReadFully(stream); var srcStringContent = Encoding.UTF8.GetString(s.Content); var dstStringContent = Encoding.UTF8.GetString(dstContent); isContentValid = dstStringContent.Contains(srcStringContent); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, // Dst = dstProp, IsValid = isContentValid }); }); }
public void CanDeploy_List_From_STPListTemplate() { var stpTemplateContent = ModuleFileUtils.FromResource( GetType().Assembly, "SPMeta2.Regression.Tests.Templates.STP.M2Template.stp"); var stpTemplateFeatureId = new Guid("{00BFEA71-DE22-43B2-A848-C05709900100}"); // upload stp to list templates var stpModel = SPMeta2Model .NewWebModel(web => { web.AddHostList(BuiltInListDefinitions.Catalogs.ListTemplates, list => { list.AddModuleFile(new ModuleFileDefinition { FileName = "M2Template.stp", Content = stpTemplateContent }); }); }); var customListDef = ModelGeneratorService.GetRandomDefinition <ListDefinition>(def => { def.TemplateType = BuiltInListTemplateTypeId.GenericList; def.ForceCheckout = false; #pragma warning disable 618 def.Url = Rnd.String(); #pragma warning restore 618 def.CustomUrl = string.Empty; def.TemplateType = 0; def.TemplateName = "M2Template"; }); // deploy template to both current and sub web var webModel = SPMeta2Model.NewWebModel(web => { web.AddList(customListDef.Inherit <ListDefinition>()); web.AddRandomWeb(subWeb => { subWeb.AddList(customListDef.Inherit <ListDefinition>()); }); }); TestModel(stpModel, webModel); }
public void CanPassTypedSyntax_Extensions() { var model = SPMeta2Model.NewWebModel(web => { web.AddRandomList(list => { ModuleFileUtils.LoadModuleFilesFromLocalFolder(list, Directory.GetCurrentDirectory()); list.AddRandomFolder(folder => { ModuleFileUtils.LoadModuleFilesFromLocalFolder(folder, Directory.GetCurrentDirectory()); }); }); }); }
public override void DeployModel(object modelHost, DefinitionBase model) { var folderHost = modelHost.WithAssertAndCast <FolderModelHost>("modelHost", value => value.RequireNotNull()); var definition = model.WithAssertAndCast <ModuleFileDefinition>("model", value => value.RequireNotNull()); var folder = folderHost.CurrentLibraryFolder; var spObject = GetFile(folderHost, definition); if (!spObject.IsObjectPropertyInstantiated("Name")) { spObject.Context.Load(spObject, o => o.Name); } if (!spObject.IsObjectPropertyInstantiated("ServerRelativeUrl")) { spObject.Context.Load(spObject, o => o.ServerRelativeUrl); } spObject.Context.ExecuteQuery(); var assert = ServiceFactory.AssertService .NewAssert(definition, spObject) .ShouldNotBeNull(spObject) .ShouldBeEqual(m => m.FileName, o => o.Name); assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(m => m.Content); //var dstProp = d.GetExpressionValue(ct => ct.GetId()); var isContentValid = false; byte[] dstContent = null; using (var stream = File.OpenBinaryDirect(folderHost.HostClientContext, spObject.ServerRelativeUrl).Stream) dstContent = ModuleFileUtils.ReadFully(stream); isContentValid = dstContent.SequenceEqual(definition.Content); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, // Dst = dstProp, IsValid = isContentValid }); }); }
public static SiteModelNode DeployModel() { return(SPMeta2Model.NewSiteModel(site => { site .AddField(ArtFields.SpfWebUrl()) .AddContentType(ArtContentTypes.CustomAutoTitleCT(), contentType => { contentType .AddContentTypeFieldLink(ArtFields.SpfWebUrl()) ; }) .AddRootWeb(new RootWebDefinition(), RootWeb => { RootWeb .AddList(ArtLists.CustomAutoTitleList(), SpfList => { SpfList .AddContentTypeLink(ArtContentTypes.CustomAutoTitleCT()) .AddUniqueContentTypeOrder(new UniqueContentTypeOrderDefinition { ContentTypes = new List <ContentTypeLinkValue> { new ContentTypeLinkValue { ContentTypeName = ArtContentTypes.CustomAutoTitleCT().Name } } }) .AddListView(ArtViews.SettingsView()); }) .AddHostList(BuiltInListDefinitions.Catalogs.MasterPage, list => { var FolderPath = Path.Combine(ArtConsts.SystemPath, ArtConsts.Assets); if (Directory.Exists(FolderPath)) { Extentions.FillApplytoFile(); ModuleFileUtils.LoadModuleFilesFromLocalFolder(list, FolderPath); } }) ; }) .AddUserCustomAction(ArtActions.ListSettings()) .AddUserCustomAction(ArtActions.FolderSettings()) ; })); }
public static SiteModelNode DeployModel(string assetFolder) { // keep model clean, parametrised if (!Directory.Exists(assetFolder)) { throw new Exception(string.Format("Cannot find folder:[{0}]", assetFolder)); } return(SPMeta2Model.NewSiteModel(site => { site.AddRootWeb(new RootWebDefinition(), rootWeb => { rootWeb.AddHostList(BuiltInListDefinitions.Catalogs.MasterPage, list => { ModuleFileUtils.LoadModuleFilesFromLocalFolder(list, assetFolder); }); }); })); }
public static SiteModelNode DeployModel() { return(SPMeta2Model.NewSiteModel(site => { site .AddRootWeb(new RootWebDefinition(), RootWeb => { RootWeb .AddHostList(BuiltInListDefinitions.Catalogs.MasterPage, list => { var FolderPath = Path.Combine(SystemPath, Assets); if (Directory.Exists(FolderPath)) { ModuleFileUtils.LoadModuleFilesFromLocalFolder(list, FolderPath); } }); }) ; })); }
public override IEnumerable <DefinitionBase> GetAdditionalArtifacts() { var sandboxSolution = new SandboxSolutionDefinition { FileName = string.Format("{0}.wsp", Rnd.String()), Activate = true, SolutionId = new Guid("e9a61998-07f2-45e9-ae43-9e93fa6b11bb"), Content = ModuleFileUtils.FromResource(GetType().Assembly, "SPMeta2.Containers.Templates.Apps.SPMeta2.Containers.SandboxSolutionContainer.wsp") }; var webpartFeature = new FeatureDefinition { Scope = FeatureDefinitionScope.Site, Id = new Guid("9acf0f59-3cdc-412b-a647-4185dd4cd9bc"), Enable = true }; return(new DefinitionBase[] { sandboxSolution, webpartFeature }); }
public void CanPassTypedSyntax_Extensions() { var tmpDir = Path.Combine( Path.GetTempPath(), string.Format("m2_regression_test_CanPassTypedSyntax_Extensions_{0}", Guid.NewGuid().ToString("N"))); Directory.CreateDirectory(tmpDir); var model = SPMeta2Model.NewWebModel(web => { web.AddRandomList(list => { ModuleFileUtils.LoadModuleFilesFromLocalFolder(list, tmpDir); list.AddRandomFolder(folder => { ModuleFileUtils.LoadModuleFilesFromLocalFolder(folder, tmpDir); }); }); }); }
/** * * SPSite model assembly example * */ public static SiteModelNode SiteDemoModel() { return(SPMeta2Model.NewSiteModel(site => { site .AddUserCustomAction(ActionsInfo.M2ArtefactsAction()) .AddRootWeb(new RootWebDefinition(), RootWeb => { RootWeb .AddHostList(BuiltInListDefinitions.Catalogs.MasterPage, list => { var FolderPath = Path.Combine(ConstsInfo.SystemPath, ConstsInfo.DynamicAssets); if (Directory.Exists(FolderPath)) { JSInfo.FillApplytoFile(); ModuleFileUtils.LoadModuleFilesFromLocalFolder(list, FolderPath); } }) ; }); })); }
public override ModelNode ReverseSingleHost(object reverseHost, ReverseOptions options) { var item = (reverseHost as ModuleFileReverseHost).HostFile; var context = (reverseHost as ModuleFileReverseHost).HostClientContext; var def = new ModuleFileDefinition(); def.FileName = item.Name; using (var stream = File.OpenBinaryDirect( context, item.ServerRelativeUrl).Stream) { def.Content = ModuleFileUtils.ReadFully(stream); } return(new ModuleFileModelNode { Options = { RequireSelfProcessing = true }, Value = def }); }
public ModelNode GetStyleLibraryModel() { var webModel = SPMeta2Model.NewWebModel(rootWeb => { // AddHostList() to indicate that we don't provision list, but just look it up rootWeb.AddHostList(BuiltInListDefinitions.StyleLibrary, list => { //LoadModuleFilesFromLocalFolder() helper gets everything from the local folder //and creates a new M2 model full of folders/module files //everything you have in M2ProjectPrefixConsts.DefaultStyleLibraryPath //will be pushed to 'Style Library' back to back if (Directory.Exists(M2ProjectPrefixConsts.DefaultStyleLibraryPath)) { ModuleFileUtils.LoadModuleFilesFromLocalFolder(list, M2ProjectPrefixConsts.DefaultStyleLibraryPath); } }); }); return(webModel); }
//[SampleMetadataTag(Name = BuiltInTagNames.SampleHidden)] public void CanDeploySimpleSandboxSolutionDefinition() { // FileName could be different to the original solution name // FileName must not have "." to avoid fails (DesignPackage API limitations) // Content is a byte array, so get ot from whatever source you want // SolutionId is used to lookup existing sandbox package // get SolutionId from the VS project or XML inside WSP package // Activate must be always true for CSOM (DesignPackage API limitations) var myBranding = new SandboxSolutionDefinition { FileName = "MyBranding.wsp", Content = File.ReadAllBytes("MySandboxBranding.wsp"), SolutionId = new Guid("0CDCC076-A472-4DD9-9A1F-0E1E761ED61D"), Activate = true, }; var myTasks = new SandboxSolutionDefinition { FileName = "MyTasks.wsp", Content = ModuleFileUtils.FromResource(GetType().Assembly, "MyIntranet.Resources.MyTasks.wsp"), SolutionId = new Guid("3D279748-92FC-49F9-A6C5-A10FBCD2DB24"), Activate = true, }; var model = SPMeta2Model.NewSiteModel(site => { site .AddSandboxSolution(myBranding) .AddSandboxSolution(myTasks); }); DeployModel(model); }
public override void DeployModel(object modelHost, DefinitionBase model) { var folderModelHost = modelHost.WithAssertAndCast <FolderModelHost>("modelHost", value => value.RequireNotNull()); var folder = folderModelHost.CurrentListFolder; var definition = model.WithAssertAndCast <WebPartGalleryFileDefinition>("model", value => value.RequireNotNull()); var file = GetItemFile(folderModelHost.CurrentList, folder, definition.FileName); var spObject = file.ListItemAllFields; var context = spObject.Context; context.Load(file, f => f.ServerRelativeUrl); context.Load(spObject); context.ExecuteQueryWithTrace(); var assert = ServiceFactory.AssertService .NewAssert(definition, spObject) .ShouldNotBeNull(spObject) .ShouldBeEqual(m => m.Title, o => o.GetTitle()) .ShouldBeEqual(m => m.FileName, o => o.GetName()) .ShouldBeEqual(m => m.Description, o => o.GetWebPartGalleryFileDescription()) .ShouldBeEqual(m => m.Group, o => o.GetWebPartGalleryFileGroup()) ; assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(m => m.Content); //var dstProp = d.GetExpressionValue(ct => ct.GetId()); var isContentValid = true; byte[] dstContent = null; using (var stream = File.OpenBinaryDirect(folderModelHost.HostClientContext, file.ServerRelativeUrl).Stream) dstContent = ModuleFileUtils.ReadFully(stream); var srcStringContent = Encoding.UTF8.GetString(s.Content); var dstStringContent = Encoding.UTF8.GetString(dstContent); srcStringContent = WebpartXmlExtensions .LoadWebpartXmlDocument(srcStringContent) .SetTitle(s.Title) .SetOrUpdateProperty("Description", s.Description) .ToString(); dstStringContent = WebpartXmlExtensions.LoadWebpartXmlDocument(dstStringContent).ToString(); isContentValid = dstStringContent.Contains(srcStringContent); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, // Dst = dstProp, IsValid = isContentValid }); }); if (definition.RecommendationSettings.Count > 0) { assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(m => m.RecommendationSettings); var isValid = true; // TODO //var targetControlTypeValue = d.GetWebPartGalleryFileRecommendationSettings(); //var targetControlTypeValues = new List<string>(); //for (var i = 0; i < targetControlTypeValue.Count; i++) // targetControlTypeValues.Add(targetControlTypeValue[i].ToUpper()); //foreach (var v in s.RecommendationSettings) //{ // if (!targetControlTypeValues.Contains(v.ToUpper())) // isValid = false; //} return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.RecommendationSettings, "RecommendationSettings is empty. Skipping."); } }
public override void DeployModel(object modelHost, DefinitionBase model) { var folderModelHost = modelHost.WithAssertAndCast <FolderModelHost>("modelHost", value => value.RequireNotNull()); var definition = model.WithAssertAndCast <WebPartPageDefinition>("model", value => value.RequireNotNull()); var folder = folderModelHost.CurrentListFolder; var context = folder.Context; var pageName = GetSafeWebPartPageFileName(definition); var pageFile = GetCurrentWebPartPageFile(folderModelHost.CurrentList, folder, pageName); var spObject = pageFile.ListItemAllFields; context.Load(spObject); context.Load(spObject, s => s.File); context.ExecuteQueryWithTrace(); var assert = ServiceFactory.AssertService .NewAssert(definition, spObject) .ShouldNotBeNull(spObject) .ShouldBeEqual(m => m.FileName, o => o.GetName()); assert.SkipProperty(m => m.Title, "Web part pages don't have title. Skipping."); if (!string.IsNullOrEmpty(definition.CustomPageLayout)) { var custmPageContent = Encoding.UTF8.GetBytes(definition.CustomPageLayout); var pageTemplateContent = definition.GetWebPartPageTemplateContent(); byte[] dstContent = null; using (var stream = File.OpenBinaryDirect(folderModelHost.HostClientContext, spObject.File.ServerRelativeUrl).Stream) dstContent = ModuleFileUtils.ReadFully(stream); assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(m => m.PageLayoutTemplate); var isValidPageLayoutTemplate = custmPageContent.SequenceEqual(dstContent); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, //Dst = dstProp, IsValid = isValidPageLayoutTemplate }); }); assert.SkipProperty(m => m.PageLayoutTemplate, "PageLayoutTemplate validated with GetWebPartPageTemplateContent() call before."); assert.SkipProperty(m => m.CustomPageLayout, "CustomPageLayout validated with GetCustomnPageContent() call before."); } else { assert.SkipProperty(m => m.CustomPageLayout, "CustomPageLayout is null or empty. Skipping."); } if (definition.PageLayoutTemplate > 0) { var pageTemplateContent = definition.GetWebPartPageTemplateContent(); byte[] dstContent = null; using (var stream = File.OpenBinaryDirect(folderModelHost.HostClientContext, spObject.File.ServerRelativeUrl).Stream) dstContent = ModuleFileUtils.ReadFully(stream); assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(m => m.PageLayoutTemplate); var isValidPageLayoutTemplate = pageTemplateContent.SequenceEqual(dstContent); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, //Dst = dstProp, IsValid = isValidPageLayoutTemplate }); }); assert.SkipProperty(m => m.PageLayoutTemplate, "PageLayoutTemplate validated with GetWebPartPageTemplateContent() call before."); } else { assert.SkipProperty(m => m.CustomPageLayout, "PageLayoutTemplate is o or less. Skipping."); } }
public override void DeployModel(object modelHost, DefinitionBase model) { var folderHost = modelHost.WithAssertAndCast <FolderModelHost>("modelHost", value => value.RequireNotNull()); var definition = model.WithAssertAndCast <ModuleFileDefinition>("model", value => value.RequireNotNull()); var stringCustomContentType = string.Empty; if (!string.IsNullOrEmpty(definition.ContentTypeName) || !string.IsNullOrEmpty(definition.ContentTypeId)) { stringCustomContentType = ResolveContentTypeId(folderHost, definition); } var folder = folderHost.CurrentListFolder; var spObject = GetFile(folderHost, definition); if (folderHost.CurrentList != null) { if (!spObject.IsObjectPropertyInstantiated("ListItemAllFields")) { spObject.Context.Load(spObject, o => o.ListItemAllFields); } } if (!spObject.IsObjectPropertyInstantiated("Name")) { spObject.Context.Load(spObject, o => o.Name); } if (!spObject.IsObjectPropertyInstantiated("ServerRelativeUrl")) { spObject.Context.Load(spObject, o => o.ServerRelativeUrl); } spObject.Context.ExecuteQueryWithTrace(); var assert = ServiceFactory.AssertService .NewAssert(definition, spObject) .ShouldNotBeNull(spObject) .ShouldBeEqual(m => m.FileName, o => o.Name); if (!string.IsNullOrEmpty(definition.ContentTypeId)) { } else { assert.SkipProperty(m => m.ContentTypeId, "ContentTypeId is null or empty. Skipping."); } if (!string.IsNullOrEmpty(definition.ContentTypeName)) { assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(def => def.ContentTypeName); var currentContentTypeName = d.ListItemAllFields["ContentTypeId"].ToString(); var isValis = stringCustomContentType == currentContentTypeName; return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = isValis }); }); } else { assert.SkipProperty(m => m.ContentTypeName, "ContentTypeName is null or empty. Skipping."); } if (definition.DefaultValues.Count > 0) { assert.ShouldBeEqual((p, s, d) => { var isValid = true; foreach (var srcValue in s.DefaultValues) { // big TODO here for == != if (!string.IsNullOrEmpty(srcValue.FieldName)) { if (d.ListItemAllFields[srcValue.FieldName].ToString() != srcValue.Value.ToString()) { isValid = false; } } if (!isValid) { break; } } var srcProp = s.GetExpressionValue(def => def.DefaultValues); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.DefaultValues, "DefaultValues.Count == 0. Skipping."); } // skip all templates if (definition.FileName.ToUpper().EndsWith("DOTX")) { assert.SkipProperty(m => m.Content, "DOTX file is detected. Skipping."); } else { assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(m => m.Content); //var dstProp = d.GetExpressionValue(ct => ct.GetId()); var isContentValid = false; byte[] dstContent = null; using (var stream = File.OpenBinaryDirect(folderHost.HostClientContext, spObject.ServerRelativeUrl).Stream) dstContent = ModuleFileUtils.ReadFully(stream); isContentValid = dstContent.SequenceEqual(definition.Content); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, // Dst = dstProp, IsValid = isContentValid }); }); } }