/// <summary> /// Gets the view model. /// </summary> /// <returns></returns> public JobSearchResultsViewModel BuildModel() { var model = new JobSearchResultsViewModel() { JobsLogo = BuildImage("JobsLogo_Content"), HeaderBackgroundImageSmall = BuildImage("HeaderBackgroundImage_Content"), HeaderBackgroundImageMedium = BuildImage("HeaderBackgroundImageMedium_Content"), HeaderBackgroundImageLarge = BuildImage("HeaderBackgroundImageLarge_Content"), JobsHomePage = BuildLinkToPage("JobsHomePage_Content"), JobAdvertPage = BuildLinkToPage("JobDetailPage_Content"), LoginPage = BuildLinkToPage("LoginPage_Content"), LoginUrl = !string.IsNullOrEmpty(UmbracoContent.GetPropertyValue <string>("loginURL")) ? new Uri(UmbracoContent.GetPropertyValue <string>("loginURL"), UriKind.RelativeOrAbsolute) : null, JobsSearchPage = BuildLinkToPage("JobsSearchPage_Content"), JobsPrivacyPage = BuildLinkToPage("JobsPrivacyPage_Content"), JobsSet = ParseJobsSet("PublicOrRedeployment_Content") }; var rss = BuildLinkToPage("JobsRssFeed_Content"); if (rss != null) { model.Metadata.RssFeedTitle = rss.Text; model.Metadata.RssFeedUrl = rss.Url.ToString(); } return(model); }
public virtual IList <ISitemapContent> GetContent() { var content = Initializer.GetContent(); return(Filters.Aggregate(content, (current, contentFilter) => contentFilter.Filter(current)) .Select(c => UmbracoContent.Parse(c)) .ToList <ISitemapContent>()); }
private CmsContentNu GenerateImageNu(UmbracoContent image, string imagePath, string template) { string json = template.Replace("<mediaPath>", imagePath); return(new CmsContentNu { NodeId = image.NodeId, Published = false, Data = json }); }
protected Image BuildImage(string alias) { var imageData = UmbracoContent.GetPropertyValue <IPublishedContent>(alias); if (imageData == null) { return(null); } return(BuildImageFromMediaItem(imageData)); }
protected IList <Image> BuildImages(string alias) { var imagesData = UmbracoContent.GetPropertyValue <IEnumerable <IPublishedContent> >(alias); var images = new List <Image>(); foreach (var imageData in imagesData) { images.Add(BuildImageFromMediaItem(imageData)); } return(images); }
public void To_many_with_match_success() { var cache = Substitute.For<ICache>(); var item1 = new Dictionary<string, string> { {"alias", "testItem"}, {"itemId", "1"}, {"price", "10.00"}, {"onSale", "true"} }; var content1 = new UmbracoContent(item1); var item2 = new Dictionary<string, string> { {"alias", "testItem"}, {"itemId", "2"}, {"price", "20.00"}, {"onSale", "true"} }; var content2 = new UmbracoContent(item2); var item3 = new Dictionary<string, string> { {"alias", "testItem"}, {"itemId", "3"}, {"price", "30.00"}, {"onSale", "true"} }; var content3 = new UmbracoContent(item3); var itemContents = new IContent[] { content1, content2, content3 }; var items = new[] { new TestItem {ItemId = 1, Name = "one"}, new TestItem {ItemId = 2, Name = "two"}, new TestItem {ItemId = 3, Name = "three"}, }; _mapper.To(cache, itemContents, items, x => x.ItemId, "itemId").ToList(); Assert.That(items, Is.Not.Null); Assert.That(items.Count, Is.EqualTo(3)); //load from content Assert.That(items[0].Price, Is.EqualTo(10d)); Assert.That(items[1].Price, Is.EqualTo(20d)); Assert.That(items[2].Price, Is.EqualTo(30d)); //existing value Assert.That(items[0].Name, Is.EqualTo("one")); Assert.That(items[1].Name, Is.EqualTo("two")); Assert.That(items[2].Name, Is.EqualTo("three")); }
public void Get_int_value_empty_returns_default() { var fields = new Dictionary <string, string> { { "Id", "" }, }; var content = new UmbracoContent(fields); var id = content.Get <int>("id"); Assert.That(id, Is.EqualTo(0)); }
public void Get_string_value_whitespace_returns_value() { var fields = new Dictionary <string, string> { { "Name", " " }, }; var content = new UmbracoContent(fields); var id = content.Get <string>("name"); Assert.AreEqual(id, " "); }
public void Get_Underscore() { var fields = new Dictionary <string, string> { { "__flag", "0" }, }; var content = new UmbracoContent(fields); var flag = content.Get <bool>("flag"); Assert.That(!flag); }
protected string BuildJobsSearcherName(string fieldAlias) { var index = umbraco.library.GetPreValueAsString(UmbracoContent.GetPropertyValue <int>(fieldAlias)); if (index == "Redeployment jobs") { return("RedeploymentJobsSearcher"); } else { return("PublicJobsSearcher"); } }
protected JobsSet ParseJobsSet(string fieldAlias) { var index = umbraco.library.GetPreValueAsString(UmbracoContent.GetPropertyValue <int>(fieldAlias)); if (index == "Redeployment jobs") { return(JobsSet.RedeploymentJobs); } else { return(JobsSet.PublicJobs); } }
/// <summary> /// Gets the view model. /// </summary> /// <returns></returns> public JobsSearchViewModel BuildModel() { _model.JobsLogo = BuildImage("JobsLogo_Content"); _model.HeaderBackgroundImageSmall = BuildImage("HeaderBackgroundImage_Content"); _model.HeaderBackgroundImageMedium = BuildImage("HeaderBackgroundImageMedium_Content"); _model.HeaderBackgroundImageLarge = BuildImage("HeaderBackgroundImageLarge_Content"); _model.JobsHomePage = BuildLinkToPage("JobsHomePage_Content"); _model.LoginUrl = !string.IsNullOrEmpty(UmbracoContent.GetPropertyValue <string>("loginURL")) ? new Uri(UmbracoContent.GetPropertyValue <string>("loginURL"), UriKind.RelativeOrAbsolute) : null; _model.SearchResultsPage = BuildLinkToPage("SearchResultsPage_Content"); _model.JobsSet = ParseJobsSet("PublicOrRedeployment_Content"); return(_model); }
public void Get_Raw() { var fields = new Dictionary <string, string> { { "__raw_Id", "10" }, }; var content = new UmbracoContent(fields); var id = content.Get <int>("id"); Assert.That(id, Is.EqualTo(10)); }
public void Get_throw_return_default() { var fields = new Dictionary <string, string> { { "id", "ab" } }; var content = new UmbracoContent(fields); var id = content.Get <int>("id"); Assert.That(id, Is.EqualTo(0)); }
protected HtmlLink BuildLinkToPage(string alias) { var linkedPage = UmbracoContent.GetPropertyValue <IPublishedContent>(alias); if (linkedPage != null) { return(new HtmlLink() { Text = linkedPage.Name, Url = new Uri(linkedPage.UrlAbsolute()) }); } return(null); }
public void Get_nullable_Guid_value() { var guid = Guid.NewGuid(); var fields = new Dictionary <string, string> { { "Key", guid.ToString() }, }; var content = new UmbracoContent(fields); var key = content.Get <Guid?>("key"); Assert.That(key, Is.EqualTo(guid)); }
public void Get_nullable_Guid_returns_default() { var guid = Guid.NewGuid(); var fields = new Dictionary <string, string> { { "Key", guid.ToString().Substring(10) }, }; var content = new UmbracoContent(fields); var key = content.Get <Guid?>("key"); Assert.That(key, Is.EqualTo(Guid.Empty)); }
public void HasChildren() { var urlSet = new UrlSet(); var url1 = new UmbracoContent(); var url2 = new UmbracoContent(); urlSet.Urls.Add(url1); urlSet.Urls.Add(url2); var xml = urlSet.ToXml(); Assert.IsTrue(xml.HasElements, "xml is missing child elements"); Assert.AreEqual(xml.Elements().Count(), 2, "xml has the wrong number of elements."); }
public void TestToXml() { const string testUrl = "http://test.domain.com/something/"; var modified = new DateTimeOffset(new DateTime(2016, 1, 12), _currentMachineOffset).DateTime; var expected = $"<url>\r\n <loc>{testUrl}</loc>\r\n <lastmod>{modified.ToString("yyyy-MM-ddTHH:mm:sszzz")}</lastmod>\r\n <changefreq>weekly</changefreq>\r\n <priority>0.5</priority>\r\n</url>"; var url = new UmbracoContent { Location = testUrl, LastModified = modified }; var xml = url.ToXml(); Assert.AreEqual(expected, xml.ToString()); }
public void Has_success() { var fields = new Dictionary <string, string> { { "Id", "1" }, { "key", "item key" }, { "name", "item name" } }; var content = new UmbracoContent(fields); Assert.That(content.Has("id")); Assert.That(content.Has("key")); Assert.That(content.Has("name")); Assert.That(!content.Has("fake")); }
/// <summary> /// Gets the view model. /// </summary> /// <returns></returns> public JobAdvertViewModel BuildModel() { var model = new JobAdvertViewModel() { JobsLogo = BuildImage("JobsLogo_Content"), HeaderBackgroundImageSmall = BuildImage("HeaderBackgroundImage_Content"), HeaderBackgroundImageMedium = BuildImage("HeaderBackgroundImageMedium_Content"), HeaderBackgroundImageLarge = BuildImage("HeaderBackgroundImageLarge_Content"), JobsHomePage = BuildLinkToPage("JobsHomePage_Content"), LoginPage = BuildLinkToPage("LoginPage_Content"), LoginUrl = !string.IsNullOrEmpty(UmbracoContent.GetPropertyValue <string>("loginURL")) ? new Uri(UmbracoContent.GetPropertyValue <string>("loginURL"), UriKind.RelativeOrAbsolute) : null, SearchResultsPageForClosedJobs = BuildLinkToPage("SearchResultsPage_Content"), JobsSet = ParseJobsSet("PublicOrRedeployment_Content") }; return(model); }
/// <summary> /// Gets the view model. /// </summary> /// <returns></returns> /// <exception cref="System.NotImplementedException"></exception> public JobsComponentViewModel BuildModel() { var model = new JobsComponentViewModel { JobsLogo = BuildImage("JobsLogo_Content"), JobsHomePage = BuildLinkToPage("JobsHomePage_Content"), LoginPage = BuildLinkToPage("LoginPage_Content"), HeaderBackgroundImageSmall = BuildImage("HeaderBackgroundImage_Content"), HeaderBackgroundImageMedium = BuildImage("HeaderBackgroundImageMedium_Content"), HeaderBackgroundImageLarge = BuildImage("HeaderBackgroundImageLarge_Content"), ScriptUrl = new TalentLinkUrl(UmbracoContent.GetPropertyValue <string>("ScriptUrl_Content")), IsForm = UmbracoContent.GetPropertyValue <bool>("IsForm_Content"), ContentBelowComponent = new HtmlString(_mediaUrlTransformer.ParseAndTransformMediaUrlsInHtml(UmbracoContent.GetPropertyValue <string>("ContentBelow_Content"))) }; return(model); }
public async Task ToAsync_single_with_match_success() { var cache = Substitute.For<ICache>(); var fields = new Dictionary<string, string> { {"alias", "test"}, {"id", "1000"}, {"list", "a,b,c"}, {"items", "1,3"} }; var content = new UmbracoContent(fields); var result = new TestEntity { Name = "name" }; await _mapper.ToAsync(cache, content, result).ConfigureAwait(false); Assert.That(result, Is.Not.Null); Assert.That(result.Id, Is.EqualTo(1000)); Assert.That(result.Name, Is.EqualTo("name")); Assert.That(result.Infos.Count, Is.EqualTo(3)); }
public void To_single_success() { var cache = Substitute.For<ICache>(); var fields = new Dictionary<string, string> { {"alias", "test"}, {"id", "1000"}, {"contentName", "test name"}, {"list", "a,b,c"}, {"items", "1,3"} }; var content = new UmbracoContent(fields); var result = _mapper.To<TestEntity>(cache, content); Assert.That(result, Is.Not.Null); Assert.That(result.Id, Is.EqualTo(1000)); Assert.That(result.Name, Is.EqualTo("test name")); Assert.That(result.Infos.Count, Is.EqualTo(3)); }
public void Get_by_alias() { var fields = new Dictionary <string, string> { { "Id", "1" }, { "key", "item key" }, { "name", "item name" } }; var content = new UmbracoContent(fields); var id = content.Get <int>("id"); var key = content.Get <string>("key"); var name = content.Get <string>("name"); Assert.That(id, Is.EqualTo(1)); Assert.That(key, Is.EqualTo("item key")); Assert.That(name, Is.EqualTo("item name")); }
public void Get_bool_value_returns_true() { var fields = new Dictionary <string, string> { { "Yes", "yes" }, { "One", "1" }, { "True", "True" }, }; var content = new UmbracoContent(fields); var yes = content.Get <bool>("yes"); var one = content.Get <bool>("one"); var tru = content.Get <bool>("true"); Assert.That(yes); Assert.That(one); Assert.That(tru); }
public void Get_bool_value_returns_false() { var fields = new Dictionary <string, string> { { "No", "No" }, { "Zero", "0" }, { "false", "false" }, }; var content = new UmbracoContent(fields); var no = content.Get <bool>("no"); var zero = content.Get <bool>("zero"); var fals = content.Get <bool>("false"); Assert.That(!no); Assert.That(!zero); Assert.That(!fals); }
/// <summary> /// Gets the view model. /// </summary> /// <returns></returns> /// <exception cref="System.NotImplementedException"></exception> public JobsHomeViewModel BuildModel() { var model = new JobsHomeViewModel { JobsLogo = BuildImage("JobsLogo_Content"), HeaderBackgroundImageSmall = BuildImage("HeaderBackgroundImage_Content"), HeaderBackgroundImageMedium = BuildImage("HeaderBackgroundImageMedium_Content"), HeaderBackgroundImageLarge = BuildImage("HeaderBackgroundImageLarge_Content"), HeaderBackgroundImageCaption = UmbracoContent.GetPropertyValue <string>("HeaderBackgroundImageCaption_Content"), LoginPage = BuildUri("LoginPage_Content"), LoginUrl = !string.IsNullOrEmpty(UmbracoContent.GetPropertyValue <string>("loginURL")) ? new Uri(UmbracoContent.GetPropertyValue <string>("loginURL"), UriKind.RelativeOrAbsolute) : null, SearchPage = BuildUri("SearchPage_Content"), SearchResultsPageForHeader = BuildUri("SearchResultsPage_Content"), TileNavigation = RelatedLinksService.BuildRelatedLinksViewModelFromUmbracoContent(UmbracoContent, "TileNavigation_Content"), TileImages = BuildImages("TileImages_Content"), CampaignImage = BuildImage("CampaignImage_Content"), CampaignPage = BuildUri("CampaignPage_Content") }; if (model.CampaignPage == null) { var campaignUrl = UmbracoContent.GetPropertyValue <string>("CampaignUrl_Content"); if (!String.IsNullOrEmpty(campaignUrl)) { model.CampaignPage = new HtmlLink() { Url = new Uri(campaignUrl, UriKind.RelativeOrAbsolute) }; } } // Allow a hyphen to indicate that there's no text for the link, just an image foreach (var link in model.TileNavigation) { if (link.Text == "-") { link.Text = String.Empty; } } return(model); }
public HomeController() { #if DEBUG const bool useCache = false; #else const bool useCache = true; #endif // Get root node from mysite.com _externalUmbracoContent = new UmbracoContent("http://mySite.com/", allowCache: useCache); // Add node to ViewBag (for simplicity) ViewBag.ExternalContent = _externalUmbracoContent.GetNode("/"); // Use it in the view as: // <h1>@ViewBag.ExternalContent.Name</h1> // @Html.Raw(ViewBag.ExternalContent.Properties.BodyText) // All custom properties for the node are under (Properties. ) }
public async Task ToAsync_Act_6_augs_Success() { var fields = new Dictionary<string, string> { {"actionid", "1"}, {"name", "test action"}, {"value1", "1"}, {"value2", "2"}, {"value3", "3"}, {"value4", "4"}, {"value5", "5"}, {"value6", "6"} }; var content = new UmbracoContent(fields); var result = await _mapper.ToAsync<TestAction>(null, content).ConfigureAwait(false); Assert.IsNotNull(result); Assert.That(result.ActionId, Is.EqualTo(1)); Assert.That(result.Sum6, Is.EqualTo(21)); }
public void To_Act_mix_Success() { var fields = new Dictionary<string, string> { {"actionid", "1"}, {"name", "test action"}, {"value1", "1"}, {"value2", "2"}, {"value3", "3"}, {"value4", "4"}, {"value5", "5"}, {"value6", "6"} }; var content = new UmbracoContent(fields); var result = _mapper.To<TestAction>(null, content); Assert.IsNotNull(result); Assert.That(result.ActionId, Is.EqualTo(1)); Assert.That(result.Mix, Is.EqualTo(2)); }