public async void ResolveLinksInStronglyTypedModel() { var mockHttp = new MockHttpMessageHandler(); string guid = Guid.NewGuid().ToString(); string url = $"https://deliver.kontent.ai/{guid}/items/coffee_processing_techniques"; mockHttp.When(url). Respond("application/json", await File.ReadAllTextAsync(Path.Combine(Environment.CurrentDirectory, $"Fixtures{Path.DirectorySeparatorChar}ContentLinkResolver{Path.DirectorySeparatorChar}coffee_processing_techniques.json"))); var deliveryOptions = DeliveryOptionsFactory.Create(new DeliveryOptions { ProjectId = guid }); var options = DeliveryOptionsFactory.Create(new DeliveryOptions { ProjectId = guid }); var deliveryHttpClient = new DeliveryHttpClient(mockHttp.ToHttpClient()); var resiliencePolicyProvider = new DefaultRetryPolicyProvider(options); var contentLinkUrlResolver = new CustomContentLinkUrlResolver(); var contentItemsProcessor = InlineContentItemsProcessorFactory.Create(); var modelProvider = new ModelProvider(contentLinkUrlResolver, contentItemsProcessor, new CustomTypeProvider(), new PropertyMapper(), new DeliveryJsonSerializer(), new HtmlParser()); var client = new DeliveryClient( deliveryOptions, modelProvider, resiliencePolicyProvider, null, deliveryHttpClient ); string expected = "Check out our <a data-item-id=\"0c9a11bb-6fc3-409c-b3cb-f0b797e15489\" href=\"http://example.org/brazil-natural-barra-grande\">Brazil Natural Barra Grande</a> coffee for a tasty example."; var item = await client.GetItemAsync <Article>("coffee_processing_techniques"); Assert.Contains(expected, item.Item.BodyCopy); }
public void ContentLinkAttributesAreParsed() { var linkUrlResolver = new CustomContentLinkUrlResolver { GetLinkUrl = link => $"http://example.org/{link.ContentTypeCodename}/{link.Codename}/{link.Id}-{link.UrlSlug}" }; var result = ResolveContentLinks("Learn <a href=\"\" data-item-id=\"CID\">more</a>.", linkUrlResolver); Assert.Equal("Learn <a href=\"http://example.org/article/about_us/CID-about-us\" data-item-id=\"CID\">more</a>.", result); }
public void BrokenUrlLinkIsEncoded() { var linkUrlResolver = new CustomContentLinkUrlResolver { GetBrokenLinkUrl = () => "http://example.org/<broken>" }; var result = ResolveContentLinks("Learn <a href=\"\" data-item-id=\"OTHER\">more</a>.", linkUrlResolver); Assert.Equal("Learn <a href=\"http://example.org/<broken>\" data-item-id=\"OTHER\">more</a>.", result); }
public void UrlLinkIsEncoded() { var linkUrlResolver = new CustomContentLinkUrlResolver { GetLinkUrl = link => "http://example.org?q=bits&bolts" }; var result = ResolveContentLinks("Learn <a href=\"\" data-item-id=\"CID\">more</a>.", linkUrlResolver); Assert.Equal("Learn <a href=\"http://example.org?q=bits&bolts\" data-item-id=\"CID\">more</a>.", result); }
public void ResolveBrokenLinkUrlIsOptional() { var linkUrlResolver = new CustomContentLinkUrlResolver { GetBrokenLinkUrl = () => null }; var result = ResolveContentLinks("Learn <a href=\"\" data-item-id=\"OTHER\">more</a>.", linkUrlResolver); Assert.Equal("Learn <a href=\"\" data-item-id=\"OTHER\">more</a>.", result); }
public async Task BrokenUrlLinkIsEncoded() { var linkUrlResolver = new CustomContentLinkUrlResolver { GetBrokenLinkUrl = () => "http://example.org/<broken>" }; var result = await ResolveContentLinks($"Learn <a href=\"\" data-item-id=\"{ContentItemIdB}\">more</a>.", linkUrlResolver); Assert.Equal($"Learn <a href=\"http://example.org/<broken>\" data-item-id=\"{ContentItemIdB}\">more</a>.", result); }
public async Task UrlLinkIsEncoded() { var linkUrlResolver = new CustomContentLinkUrlResolver { GetLinkUrl = link => "http://example.org?q=bits&bolts" }; var result = await ResolveContentLinks($"Learn <a href=\"\" data-item-id=\"{ContentItemIdA}\">more</a>.", linkUrlResolver); Assert.Equal($"Learn <a href=\"http://example.org?q=bits&bolts\" data-item-id=\"{ContentItemIdA}\">more</a>.", result); }
public async Task ResolveBrokenLinkUrlIsOptional() { var linkUrlResolver = new CustomContentLinkUrlResolver { GetBrokenLinkUrl = () => null }; var result = await ResolveContentLinks($"Learn <a href=\"\" data-item-id=\"{ContentItemIdB}\">more</a>.", linkUrlResolver); Assert.Equal($"Learn <a href=\"\" data-item-id=\"{ContentItemIdB}\">more</a>.", result); }
public async Task ContentLinkAttributesAreParsed() { var linkUrlResolver = new CustomContentLinkUrlResolver { GetLinkUrl = link => $"http://example.org/{link.ContentTypeCodename}/{link.Codename}/{link.Id}-{link.UrlSlug}" }; var result = await ResolveContentLinks($"Learn <a href=\"\" data-item-id=\"{ContentItemIdA}\">more</a>.", linkUrlResolver); Assert.Equal($"Learn <a href=\"http://example.org/article/about_us/{ContentItemIdA}-about-us\" data-item-id=\"{ContentItemIdA}\">more</a>.", result); }
private string ResolveContentLinks(string text, CustomContentLinkUrlResolver linkUrlResolver) { var linkResolver = new ContentLinkResolver(linkUrlResolver); var links = JObject.FromObject(new { CID = new { codename = "about_us", type = "article", url_slug = "about-us" } }); return(linkResolver.ResolveContentLinks(text, links)); }
private async Task <string> ResolveContentLinks(string text, CustomContentLinkUrlResolver linkUrlResolver) { var linkResolver = new ContentLinkResolver(linkUrlResolver); IContentLink link = new ContentLink() { ContentTypeCodename = "article", UrlSlug = "about-us", Codename = "about_us" }; link.Id = ContentItemIdA; var links = new Dictionary <Guid, IContentLink> { { ContentItemIdA, link } }; return(await linkResolver.ResolveContentLinksAsync(text, links)); }
private string ResolveContentLinks(string text) { var linkUrlResolver = new CustomContentLinkUrlResolver(); return(ResolveContentLinks(text, linkUrlResolver)); }
private async Task <string> ResolveContentLinks(string text) { var linkUrlResolver = new CustomContentLinkUrlResolver(); return(await ResolveContentLinks(text, linkUrlResolver)); }