Exemple #1
0
        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 GetRetryPolicy_ReturnsDefaultPolicy()
        {
            var deliveryOptions = Options.Create(new DeliveryOptions
            {
                DefaultRetryPolicyOptions = new DefaultRetryPolicyOptions()
            });
            var provider = new DefaultRetryPolicyProvider(deliveryOptions);

            var retryPolicy = provider.GetRetryPolicy();

            Assert.NotNull(retryPolicy);
            Assert.IsType <DefaultRetryPolicy>(retryPolicy);
        }