public void GetContentFunctions_WhenContentHasFunction_ShouldReturnLookupWithAnyFunction() { // Arrange var subject = new ContentMap(); var function = new ComposerContentFunction { Guid = Guid.NewGuid() }; var page = new ComposerPage { Guid = Guid.NewGuid(), Language = DefaultLanguage, ContentAreas = { new ComposerContentArea { Name = DefaultAreaName, ContentFunctions ={ function } } } }; subject.AddPage(page); // Act var result = subject.GetContentFunctions(page.Guid, page.Language)[DefaultAreaName]; // Assert Assert.AreEqual(1, result.Count()); Assert.IsTrue(result.Any(b => b.Guid == function.Guid)); }
private SiteMapNode GetParentNode(SiteMapNode node, ContentMap map) { WebsiteNode site; IContentMapEntityUrlProvider urlProvider; using (PerformanceProfiler.Instance.StartMarker(PerformanceMarkerName.SiteMapProvider, PerformanceMarkerArea.Cms, PerformanceMarkerTagName.GetParentNodes)) { if (!TryGetWebsite(map, out site, out urlProvider)) { return(base.GetParentNode(node)); } ADXTrace.Instance.TraceInfo(TraceCategory.Application, string.Format("key={0}", node.Key)); // When searching for parent page, it doesn't matter if we look for root or content page, both will have the same parent page. var languageContext = HttpContext.Current.GetContextLanguageInfo(); var mappingResult = ContentMapUrlMapping.LookupPageByUrlPath(site, node.Url, ContentMapUrlMapping.WebPageLookupOptions.Any, languageContext); // Ignore IsUnique to find any avaiable parent node if (mappingResult.Node == null || mappingResult.Node.Parent == null || mappingResult.Node.Parent.IsReference) { return(null); } return(ReturnNodeIfAccessible(GetNode(map, mappingResult.Node.Parent, urlProvider), () => null)); } }
public void GetContentFunctions_WhenLanguageIsIncorrect_ShouldCheckParentLanguage() { // Arrange var subject = new ContentMap(); var nestedFunction = new ComposerContentFunction { Guid = Guid.NewGuid(), Language = DefaultLanguage }; var layoutFunction = new ComposerContentFunction { Guid = Guid.NewGuid(), Language = DefaultLanguage, ContentAreas = { new ComposerContentArea { Name = DefaultAreaName, ContentFunctions ={ nestedFunction } } } }; var page = new ComposerPage { Guid = Guid.NewGuid(), Language = "sv", ContentAreas = { new ComposerContentArea { Name = DefaultAreaName, ContentFunctions ={ layoutFunction } } } }; subject.AddPage(page); // Act var result = subject.GetContentFunctions(layoutFunction.Guid, DefaultLanguage)[DefaultAreaName]; // Assert Assert.AreEqual(1, result.Count()); Assert.IsTrue(result.Any(b => b.Guid == nestedFunction.Guid)); }
public void GetParent_WhenGuidMatchesShadowGuidAndHasFunctions_ShouldReturnPage() { // Arrange var subject = new ContentMap(); var page = new ComposerPage { Name = "Page name", Guid = Guid.NewGuid(), Language = DefaultLanguage, ShadowGuid = Guid.NewGuid(), ContentAreas = { new ComposerContentArea { Name = DefaultAreaName, ContentFunctions ={ new ComposerContentFunction { Guid = Guid.NewGuid() } } } } }; subject.AddPage(page); // Act var result = subject.GetParentPage(page.ShadowGuid); // Assert Assert.AreSame(page, result); }
private ApplicationPath GetApplicationPathForSiteMarker(ContentMap contentMap, WebsiteNode website, IDictionary cache) { return(GetApplicationPathForSiteMarker(cache, () => { var siteMarkerNode = website.SiteMarkers .FirstOrDefault(e => string.Equals(e.Name, SiteMarker, StringComparison.Ordinal)); if (siteMarkerNode == null || siteMarkerNode.WebPage == null || siteMarkerNode.WebPage.IsReference) { return null; } var urlProvider = PortalCrmConfigurationManager.CreateDependencyProvider(PortalName) .GetDependency <IContentMapEntityUrlProvider>(); try { return urlProvider.GetApplicationPath(contentMap, siteMarkerNode.WebPage); } catch (InvalidOperationException) { return null; } })); }
private bool TryCreateHandler(IPortalContext portal, ContentMap map, out IHttpHandler handler) { switch (portal.Entity.LogicalName) { case "adx_webfile": WebFileNode webfile; if (map.TryGetValue(portal.Entity, out webfile)) { if (CloudBlobRedirectHandler.TryGetCloudBlobHandler(portal.Entity, out handler)) { return(true); } // retrieve the most recently created annotation var note = webfile.Annotations.OrderByDescending(a => a.CreatedOn).FirstOrDefault(); return(TryCreateHandler(note, webfile, portal, out handler)); } break; case "annotation": AnnotationNode annotation; if (map.TryGetValue(portal.Entity, out annotation)) { return(TryCreateHandler(annotation, null, portal, out handler)); } break; } return(base.TryCreateHandler(portal, out handler)); }
protected CrmSiteMapNode GetAccessibleNodeOrAccessDeniedNode(ContentMap map, WebFileNode file, IContentMapEntityUrlProvider provider, bool excludeFromSecurityValidation = false) { if (excludeFromSecurityValidation) { return(GetNode(map, file, provider) ?? GetAccessDeniedNodeInternal()); } return(ReturnNodeIfAccessible(GetNode(map, file, provider), GetAccessDeniedNodeInternal)); }
public virtual ApplicationPath GetApplicationPath(ContentMap map, EntityNode node) { var link = node as WebLinkNode; if (link != null) { if (!string.IsNullOrWhiteSpace(link.ExternalUrl)) { return(ApplicationPath.FromExternalUrl(link.ExternalUrl)); } ApplicationPath path = null; // Check .IsReference incase the linked-to root WebPage is deactivated. if (link.WebPage != null && !link.WebPage.IsReference) { // If language content page exists, replace web link page with the content page var langInfo = HttpContext.Current.GetContextLanguageInfo(); var linkWebPage = langInfo.FindLanguageSpecificWebPageNode(link.WebPage, false); // If web page doesn't exist for current language, return null path if (linkWebPage != null) { path = GetApplicationPath(linkWebPage); } } return(path); } var page = node as WebPageNode; if (page != null) { var path = GetApplicationPath(page); return(path); } var file = node as WebFileNode; if (file != null) { var path = GetApplicationPath(file); return(path); } var shortcut = node as ShortcutNode; if (shortcut != null) { var path = GetApplicationPath(shortcut); return(path); } return(null); }
private void RefreshIntersect(ContentMap map, Relationship relationship) { // invalidate any cached intersect queries ManyRelationshipDefinition mrd; if (map.Solution.ManyRelationships != null && map.Solution.ManyRelationships.TryGetValue(relationship.SchemaName, out mrd)) { base.Remove(mrd.IntersectEntityname, null); } }
private ApplicationPath GetApplicationPath(ContentMap map, Entity entity) { EntityNode node; if (map.TryGetValue(entity, out node)) { return(GetApplicationPath(map, node)); } return(null); }
public virtual string GetUrl(ContentMap map, EntityNode node) { var applicationPath = GetApplicationPath(map, node); if (applicationPath != null) { return(applicationPath.ExternalUrl ?? applicationPath.AbsolutePath); } return(null); }
private T Using <T>(ContentMap contentMap, Func <IFileSystemContext, T> action) { var root = GetRoot(contentMap); if (root == null) { throw new InvalidOperationException("Unable to retrieve the root directory."); } return(action(new ContentMapFileSystemContext(this, contentMap, root, new WebPageNodeDirectory(this, contentMap, root)))); }
internal static string GetPortalContextPath(this RouteCollection routes, ContentMap contentMap, WebsiteNode website, string path) { ADXTrace.Instance.TraceInfo(TraceCategory.Application, string.Format("Start: {0}", path)); var match = routes.OfTypeWithLock <IPortalContextRoute>() .Select(portalContextRoute => portalContextRoute.GetPortalContextPath(contentMap, website, path)) .FirstOrDefault(contextPath => contextPath != null); ADXTrace.Instance.TraceInfo(TraceCategory.Application, string.Format("End: {0}", path)); return(match); }
public string GetPortalContextPath(ContentMap contentMap, WebsiteNode website, string path) { if (contentMap == null || website == null || path == null) { return(null); } var pathCache = HttpContext.Current != null ? HttpContext.Current.Items : null; var applicationPath = GetApplicationPathForSiteMarker(contentMap, website, pathCache); return(GetPortalContextPath(path, applicationPath)); }
public void ExpandVisitorGroupReference_WhenReferenceIsNotFound_ShouldNotSetVisitorGroups() { // Arrange var subject = new ContentMap(); var function = new ComposerContentFunction { VisitorGroupContainerID = Guid.NewGuid() }; // Act subject.ExpandVisitorGroupReference(function); // Assert Assert.IsFalse(function.VisitorGroups.Any()); }
protected virtual CrmSiteMapNode GetNode(ContentMap map, WebPageNode webPageNode, HttpStatusCode statusCode, IContentMapEntityUrlProvider provider, bool includeReturnUrl = false) { var contextLanguageInfo = HttpContext.Current.GetContextLanguageInfo(); WebPageNode GetLanguageNode() { ADXTrace.Instance.TraceInfo(TraceCategory.Monitoring, string.Format("SiteMapProvider.GetNode Lang:{0} ", webPageNode.IsRoot != false ? "root" : webPageNode.WebPageLanguage.PortalLanguage.Code)); var languageNode = webPageNode.LanguageContentPages.FirstOrDefault(p => p.WebPageLanguage.PortalLanguage.Code == contextLanguageInfo.ContextLanguage.Code); return(languageNode ?? webPageNode); } var page = contextLanguageInfo.IsCrmMultiLanguageEnabled ? GetLanguageNode() : webPageNode; var template = page.PageTemplate; if (template == null) { ADXTrace.Instance.TraceInfo(TraceCategory.Application, string.Format("Web Page with id '{0}' does not have the required Page Template.", page.Id)); return(null); } var returnUrl = includeReturnUrl && HttpContext.Current != null ? "&ReturnUrl={0}".FormatWith(System.Web.Security.AntiXss.AntiXssEncoder.UrlEncode(HttpContext.Current.Request.Url.PathAndQuery)) : string.Empty; var rewriteUrl = template.Type == (int)PageTemplateNode.TemplateType.WebTemplate && template.WebTemplateId != null ? template.UseWebsiteHeaderAndFooter.GetValueOrDefault(true) ? "~/Pages/WebTemplate.aspx" : "~/Pages/WebTemplateNoMaster.aspx" : template.RewriteUrl; var entity = page.ToEntity(GetEntityType("adx_webpage")); var url = provider.GetUrl(map, page); var node = new CrmSiteMapNode( this, url, url, !string.IsNullOrWhiteSpace(page.Title) ? page.Title : page.Name, page.Summary, "{0}?pageid={1}{2}".FormatWith(rewriteUrl, page.Id, returnUrl), page.ModifiedOn.GetValueOrDefault(DateTime.UtcNow), entity, statusCode); if (template.WebTemplateId != null) { node["adx_webtemplateid"] = template.WebTemplateId.Id.ToString(); } return(node); }
protected virtual void IntializeContainerForImport(IContainer container, DataImporter dataImporter) { // Temporarily inject the current context (dataImporter) into the container var context = new DataImporterPackageReaderContext(dataImporter); container.Inject <IPackageReaderContext>(context); container.Inject <IContentTransferContext>(dataImporter); // Create a ContentMap object that will live over the current thread/request IContentMap contentMap = new ContentMap(); container.Inject <IContentMap>(contentMap); }
public void AddPage_ShouldAddPageToMap() { // Arrange var subject = new ContentMap(); var page = new ComposerPage { Guid = Guid.NewGuid(), Language = DefaultLanguage }; // Act subject.AddPage(page); // Assert var result = subject.GetPage(page.Guid, page.Language); Assert.AreSame(page, result); }
public void ExpandVisitorGroupReference_WhenReferenceIsNotFound_ShouldNotSetVisitorGroups() { // Arrange var subject = new ContentMap(); var function = new ComposerContentFunction { VisitorGroupContainerID = Guid.NewGuid() }; // Act subject.ExpandVisitorGroupReference(function); // Assert Assert.IsFalse(function.VisitorGroups.Any()); }
private static IEnumerable <string> GetRolesForGrouping(ContentMap map, Entity rule, EntityReference websiteReference) { IDictionary <EntityReference, EntityNode> intersectNodes; if (map.TryGetValue("adx_communityforumaccesspermission_webrole", out intersectNodes)) { var ruleGroupingRoles = intersectNodes.Values.Cast <ForumAccessPermissionsToWebRoleNode>() .Where(i => i.ForumAccessPermission.Id == rule.Id && BelongsToWebsite(websiteReference, i.WebRole)) .Select(r => r.WebRole.Name); return(ruleGroupingRoles); } return(Enumerable.Empty <string>()); }
protected virtual CrmSiteMapNode GetNode(ContentMap map, WebFileNode file, HttpStatusCode statusCode, IContentMapEntityUrlProvider provider) { var entity = file.ToEntity(GetEntityType("adx_webfile")); var url = provider.GetUrl(map, file); return(new CrmSiteMapNode( this, url, url, file.Name, file.Summary, string.Empty, file.ModifiedOn.GetValueOrDefault(DateTime.UtcNow), entity, statusCode)); }
public void GetContentFunctions_WhenContentDoesntHaveAnyFunctions_ShouldReturnEmptyLookup() { // Arrange var subject = new ContentMap(); var composerPage = new ComposerPage { Guid = Guid.NewGuid(), Language = DefaultLanguage }; subject.AddPage(composerPage); // Act var result = subject.GetContentFunctions(composerPage.Guid, composerPage.Language); // Assert Assert.IsFalse(result.Any()); }
public void AddPage_ShouldAddPageToMap() { // Arrange var subject = new ContentMap(); var page = new ComposerPage { Guid = Guid.NewGuid(), Language = DefaultLanguage }; // Act subject.AddPage(page); // Assert var result = subject.GetPage(page.Guid, page.Language); Assert.AreSame(page, result); }
public WebPageNodeDirectory(ContentMapFileSystem fileSystem, ContentMap contentMap, WebPageNode node) : base(fileSystem) { if (contentMap == null) { throw new ArgumentNullException("contentMap"); } if (node == null) { throw new ArgumentNullException("node"); } ContentMapFileSystem = fileSystem; ContentMap = contentMap; Node = node; ContentMapUrlProvider = fileSystem.ContentMapUrlProvider; }
public void ExpandVisitorGroupReference_WhenReferenceHasBeenRegistered_ShouldSetVisitorGroups() { // Arrange var subject = new ContentMap(); var reference = Guid.NewGuid(); var visitorGroups = new[] { Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid() }; var function = new ComposerContentFunction { VisitorGroupContainerID = reference }; subject.AddVisitorGroupMap(reference, visitorGroups); // Act subject.ExpandVisitorGroupReference(function); // Assert Assert.AreEqual(3, function.VisitorGroups.Count()); Assert.IsTrue(function.VisitorGroups.SequenceEqual(visitorGroups)); }
private async Task <ContentMap> InitializeContentDirectoryAsync(Context context, MemoryContentDirectoryHeader header, AbsolutePath path, bool isLoadingBackup) { var operationContext = new OperationContext(context); var result = await operationContext.PerformOperationAsync <Result <ContentMap> >( Tracer, async() => { // Making this method asynchronous to initialize _initializeContentDirectory field as fast as possible // even if the initialization is synchronous. // This will enforce the invariant that ContentDirectory property is not null. await Task.Yield(); bool canLoadContentDirectory = path != null && header.Version == BinaryFormatVersion; var loadedContentDirectory = canLoadContentDirectory ? await DeserializeBodyAsync(context, header, path, isLoadingBackup) : new ContentMap(); if (!isLoadingBackup && loadedContentDirectory.Count != 0) { // Successfully loaded primary content directory return(loadedContentDirectory); } // Primary content directory is empty, missing, or failed to load // Reconstruct to ensure content is populated. ContentMap contentDirectory = new ContentMap(); var backupContentDirectory = loadedContentDirectory; if (_host != null) { var hashInfoPairs = _host.Reconstruct(context); await AddBulkAsync( contentDirectory: contentDirectory, backupContentDirectory: backupContentDirectory, hashInfoPairs: hashInfoPairs); } else { // Host may be null in tests. Warn? } return(contentDirectory); }, _counters[MemoryContentDirectoryCounters.InitializeContentDirectory]).ThrowIfFailure(); return(result.Value); }
protected CrmSiteMapNode GetNotFoundNode(ContentMap map, WebsiteNode site, IContentMapEntityUrlProvider urlProvider) { var notFoundPage = site.SiteMarkers.FirstOrDefault(sm => sm.Name == NotFoundPageSiteMarkerName); if (notFoundPage == null || notFoundPage.WebPage == null || notFoundPage.WebPage.IsReference) { return(null); } var languageInfo = HttpContext.Current.GetContextLanguageInfo(); var path = HttpContext.Current.Request.Path; var notFoundNode = languageInfo.FindLanguageSpecificWebPageNode(notFoundPage.WebPage, true); var isLanguageEnabled = languageInfo.IsCrmMultiLanguageEnabled; if (isLanguageEnabled) { var isPublished = languageInfo.ContextLanguage.IsPublished; var language = languageInfo.ContextLanguage.WebsiteLanguageNode.Name; if (isPublished && notFoundNode == null) { var root = this.RootNode as CrmSiteMapNode; if (null != root) { ADXTrace.Instance.TraceWarning(TraceCategory.Application, "Cannot find language specific web page for url"); var id = root.Entity.GetAttributeValue("adx_webpageid"); throw new HttpException((int)HttpStatusCode.NotFound, "Error ID - {0}. The Webpage you are looking for at {1} is not found in the {2} language. To display Page Not Found page localize it in {2} language.".FormatWith(id, path, language)); } } else if (!isPublished && notFoundNode != null) { ADXTrace.Instance.TraceInfo(TraceCategory.Application, string.Format("Language not available for: {0}", language)); var id = notFoundNode.Id; throw new HttpException((int)HttpStatusCode.NotFound, "Error ID – {0} . {1} language is not available. Please ensure it is in published status.".FormatWith(id, language)); } else if (!isPublished) { throw new HttpException((int)HttpStatusCode.NotFound, "Not Found."); } } return(GetNode(map, notFoundNode, HttpStatusCode.NotFound, urlProvider)); }
public void CreateContentMap() { contentMap = new ContentMap(); askContentMap = new ContentMap(); contentMap.Add("N/A", (int)ReplyContent.NA); contentMap.Add("None", (int)ReplyContent.None); askContentMap.Add("None", (int)ReplyContent.None); contentMap.Add("Self", (int)ReplyContent.Self); contentMap.Add("Bot", (int)ReplyContent.Bot); askContentMap.Add("Bot", (int)ReplyContent.Bot); contentMap.Add("Other", (int)ReplyContent.Other); contentMap.Add("Greeting", (int)ReplyContent.Greeting); contentMap.Add("Name", (int)ReplyContent.Name); askContentMap.Add("Name", (int)ReplyContent.Name); contentMap.Add("Mood", (int)ReplyContent.Mood); askContentMap.Add("Mood", (int)ReplyContent.Mood); contentMap.Add("Person", (int)ReplyContent.Person); contentMap.Add("Place", (int)ReplyContent.Place); askContentMap.Add("Place", (int)ReplyContent.Place); contentMap.Add("Object", (int)ReplyContent.Object); askContentMap.Add("Object", (int)ReplyContent.Object); contentCount = contentMap.Count; replyContent = new int[contentCount]; }
private ApplicationPath GetApplicationPath(ContentMap map, Entity entity, string partialUrlAttribute, string parentReferenceAttribute, bool trailingSlash = false, bool prependLangCode = false) { var partialUrl = entity.GetAttributeValue <string>(partialUrlAttribute); if (string.IsNullOrEmpty(partialUrl)) { return(null); } var parentReference = entity.GetAttributeValue <EntityReference>(parentReferenceAttribute); if (parentReference == null) { return(null); } EntityNode parentNode; if (!map.TryGetValue(parentReference, out parentNode)) { return(null); } var parentPath = GetApplicationPath(map, parentNode); if (parentPath == null || parentPath.PartialPath == null) { return(null); } partialUrl = trailingSlash && !partialUrl.EndsWith("/") ? partialUrl + "/" : partialUrl; var parentPartialPath = parentPath.PartialPath.EndsWith("/") ? parentPath.PartialPath : parentPath.PartialPath + "/"; var resultAppPath = ApplicationPath.FromPartialPath(parentPartialPath + partialUrl); if (ContextLanguageInfo.DisplayLanguageCodeInUrl && ContextLanguageInfo.IsCrmMultiLanguageEnabledInWebsite(PortalContext.Current.Website) && prependLangCode) { resultAppPath = ContextLanguageInfo.PrependLanguageCode(resultAppPath); } return(resultAppPath); }
private T Using <T>(ContentMap contentMap, DirectoryContentHash cwd, Func <IFileSystemContext, T> action) { var root = GetRoot(contentMap); if (root == null) { throw new InvalidOperationException("Unable to retrieve the root directory."); } var current = GetDirectory(contentMap, cwd); if (current == null || !current.Exists) { throw new InvalidOperationException("Unable to retrieve the target directory"); } return(action(new ContentMapFileSystemContext(this, contentMap, root, current))); }
public void ExpandVisitorGroupReference_WhenReferenceHasBeenRegistered_ShouldSetVisitorGroups() { // Arrange var subject = new ContentMap(); var reference = Guid.NewGuid(); var visitorGroups = new[] { Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid() }; var function = new ComposerContentFunction { VisitorGroupContainerID = reference }; subject.AddVisitorGroupMap(reference, visitorGroups); // Act subject.ExpandVisitorGroupReference(function); // Assert Assert.AreEqual(3, function.VisitorGroups.Count()); Assert.IsTrue(function.VisitorGroups.SequenceEqual(visitorGroups)); }
private static Task AddBulkAsync(ContentMap contentDirectory, ContentMap backupContentDirectory, ContentDirectorySnapshot <ContentFileInfo> hashInfoPairs) { return(hashInfoPairs.ParallelAddToConcurrentDictionaryAsync( contentDirectory, hashInfoPair => hashInfoPair.Hash, hashInfoPair => { var info = hashInfoPair.Payload; if (backupContentDirectory.TryGetValue(hashInfoPair.Hash, out var backupInfo)) { // Recover the last access time from the backup. This has the affect that // content mentioned in the backup will be older than newly discovered content return new ContentFileInfo( info.FileSize, backupInfo.LastAccessedFileTimeUtc, info.ReplicaCount); } return info; })); }
public void RestructurePersonalization_ShouldSetTheSamePersonalizationGroupOnAllFunctions() { // Arrange var subject = new ContentMap(); var sourceFunctions = new[] { Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid() }; var containerGuid = Guid.NewGuid(); var page = CreatePersonalizedComposerPage(containerGuid, sourceFunctions); subject.AddPage(page); subject.AddPersonalisationContainer(containerGuid); // Act subject.RestructurePersonalization(); // Assert var restructuredFunctions = subject.GetContentFunctions(page.Guid, DefaultLanguage).Single().ToArray(); Assert.IsTrue(restructuredFunctions.Skip(1).All(b => b.PersonalizationGroup == restructuredFunctions[0].PersonalizationGroup)); }
public void GetContentFunctions_WhenLanguageIsIncorrect_ShouldCheckParentLanguage() { // Arrange var subject = new ContentMap(); var nestedFunction = new ComposerContentFunction { Guid = Guid.NewGuid(), Language = DefaultLanguage }; var layoutFunction = new ComposerContentFunction { Guid = Guid.NewGuid(), Language = DefaultLanguage, ContentAreas = { new ComposerContentArea { Name = DefaultAreaName, ContentFunctions = { nestedFunction } } } }; var page = new ComposerPage { Guid = Guid.NewGuid(), Language = "sv", ContentAreas = { new ComposerContentArea { Name = DefaultAreaName, ContentFunctions = { layoutFunction } } } }; subject.AddPage(page); // Act var result = subject.GetContentFunctions(layoutFunction.Guid, DefaultLanguage)[DefaultAreaName]; // Assert Assert.AreEqual(1, result.Count()); Assert.IsTrue(result.Any(b => b.Guid == nestedFunction.Guid)); }
public void GetParent_WhenGuidMatchesShadowGuidAndHasFunctions_ShouldReturnPage() { // Arrange var subject = new ContentMap(); var page = new ComposerPage { Name = "Page name", Guid = Guid.NewGuid(), Language = DefaultLanguage, ShadowGuid = Guid.NewGuid(), ContentAreas = { new ComposerContentArea { Name = DefaultAreaName, ContentFunctions = { new ComposerContentFunction { Guid = Guid.NewGuid() } } } } }; subject.AddPage(page); // Act var result = subject.GetParentPage(page.ShadowGuid); // Assert Assert.AreSame(page, result); }
public void GetParent_WhenGuidMatchesShadowGuidButPageHasNoFunctions_ShouldReturnNull() { // Arrange var subject = new ContentMap(); var page = new ComposerPage { Name = "Page name", Guid = Guid.NewGuid(), Language = DefaultLanguage, ShadowGuid = Guid.NewGuid() }; subject.AddPage(page); // Act var result = subject.GetParentPage(page.ShadowGuid); // Assert Assert.IsNull(result); }
public void GetParent_WhenGuidMatchPage_ShouldReturnNull() { // Arrange var subject = new ContentMap(); var function = new ComposerContentFunction { Guid = Guid.NewGuid(), Language = DefaultLanguage }; var page = new ComposerPage { Guid = Guid.NewGuid(), Language = DefaultLanguage, ContentAreas = { new ComposerContentArea { Name = DefaultAreaName, ContentFunctions = { function } } } }; subject.AddPage(page); // Act var result = subject.GetParentPage(page.Guid); // Assert Assert.IsNull(result); }
public void GetParent_WhenShadowGuidOfAddedPageIsEmpty_ShouldReturnNull() { // Arrange var subject = new ContentMap(); var page = new ComposerPage { Guid = Guid.NewGuid(), ShadowGuid = Guid.Empty, Language = DefaultLanguage, }; subject.AddPage(page); // Act var result = subject.GetParentPage(page.ShadowGuid); // Assert Assert.IsNull(result); }
public void RestructurePersonalization_ShouldMovePersonalizedFunctionsToContainerParent() { // Arrange var subject = new ContentMap(); var sourceFunctions = new[] { Guid.NewGuid(), Guid.NewGuid() }; var containerGuid = Guid.NewGuid(); var page = CreatePersonalizedComposerPage(containerGuid, sourceFunctions); subject.AddPage(page); subject.AddPersonalisationContainer(containerGuid); // Act subject.RestructurePersonalization(); // Assert var restructuredFunctions = subject.GetContentFunctions(page.Guid, DefaultLanguage).Single().ToList(); Assert.AreEqual(2, restructuredFunctions.Count()); Assert.AreEqual(sourceFunctions[0], restructuredFunctions[0].Guid); Assert.AreEqual(sourceFunctions[1], restructuredFunctions[1].Guid); }
public void RestructurePersonalization_ShouldSetTheSamePersonalizationGroupOnAllFunctions() { // Arrange var subject = new ContentMap(); var sourceFunctions = new[] { Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid() }; var containerGuid = Guid.NewGuid(); var page = CreatePersonalizedComposerPage(containerGuid, sourceFunctions); subject.AddPage(page); subject.AddPersonalisationContainer(containerGuid); // Act subject.RestructurePersonalization(); // Assert var restructuredFunctions = subject.GetContentFunctions(page.Guid, DefaultLanguage).Single().ToArray(); Assert.IsTrue(restructuredFunctions.Skip(1).All(b => b.PersonalizationGroup == restructuredFunctions[0].PersonalizationGroup)); }
public void GetContentFunctions_WhenContentAreaDoesNotExist_ShouldReturnLookupWithoutFunctions() { // Arrange var subject = new ContentMap(); var areaName = "Area54"; var page = new ComposerPage { Guid = Guid.NewGuid(), Language = DefaultLanguage, ContentAreas = { new ComposerContentArea { Name = DefaultAreaName } } }; subject.AddPage(page); // Act var result = subject.GetContentFunctions(page.Guid, page.Language)[areaName]; // Assert Assert.IsFalse(result.Any()); }
public void GetContentFunctions_WhenContentHasFunction_ShouldReturnLookupWithAnyFunction() { // Arrange var subject = new ContentMap(); var function = new ComposerContentFunction { Guid = Guid.NewGuid() }; var page = new ComposerPage { Guid = Guid.NewGuid(), Language = DefaultLanguage, ContentAreas = { new ComposerContentArea { Name = DefaultAreaName, ContentFunctions = { function } } } }; subject.AddPage(page); // Act var result = subject.GetContentFunctions(page.Guid, page.Language)[DefaultAreaName]; // Assert Assert.AreEqual(1, result.Count()); Assert.IsTrue(result.Any(b => b.Guid == function.Guid)); }
protected virtual void IntializeContainerForImport(IContainer container, DataImporter dataImporter) { // Temporarily inject the current context (dataImporter) into the container var context = new DataImporterPackageReaderContext(dataImporter); container.Inject<IPackageReaderContext>(context); container.Inject<IContentTransferContext>(dataImporter); // Create a ContentMap object that will live over the current thread/request IContentMap contentMap = new ContentMap(); container.Inject<IContentMap>(contentMap); }
public void GetContentFunctions_WhenContentDoesntHaveAnyFunctions_ShouldReturnEmptyLookup() { // Arrange var subject = new ContentMap(); var composerPage = new ComposerPage { Guid = Guid.NewGuid(), Language = DefaultLanguage }; subject.AddPage(composerPage); // Act var result = subject.GetContentFunctions(composerPage.Guid, composerPage.Language); // Assert Assert.IsFalse(result.Any()); }