private IDeliveryClient GetDeliveryClient(Action mockAction)
        {
            mockAction();
            var deliveryHttpClient = new DeliveryHttpClient(_mockHttp.ToHttpClient());
            var deliveryOptions    = DeliveryOptionsFactory.Create(new DeliveryOptions {
                ProjectId = _guid
            });
            var contentLinkUrlResolver = A.Fake <IContentLinkUrlResolver>();
            var contentItemsProcessor  = A.Fake <IInlineContentItemsProcessor>();
            var contentPropertyMapper  = new PropertyMapper();
            var contentTypeProvider    = new CustomTypeProvider();
            var serializer             = new DeliveryJsonSerializer();
            var modelProvider          = new ModelProvider(contentLinkUrlResolver, contentItemsProcessor, contentTypeProvider, contentPropertyMapper, serializer, new HtmlParser());
            var retryPolicy            = A.Fake <IRetryPolicy>();
            var retryPolicyProvider    = A.Fake <IRetryPolicyProvider>();

            A.CallTo(() => retryPolicyProvider.GetRetryPolicy()).Returns(retryPolicy);
            A.CallTo(() => retryPolicy.ExecuteAsync(A <Func <Task <HttpResponseMessage> > > ._))
            .ReturnsLazily(call => call.GetArgument <Func <Task <HttpResponseMessage> > >(0)());
            var client = new DeliveryClient(
                deliveryOptions,
                modelProvider,
                retryPolicyProvider,
                contentTypeProvider,
                deliveryHttpClient,
                serializer
                );

            return(client);
        }
예제 #2
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);
        }
예제 #3
0
        private DeliveryClient InitializeDeliveryClient(MockHttpMessageHandler mockHttp)
        {
            var deliveryHttpClient     = new DeliveryHttpClient(mockHttp.ToHttpClient());
            var contentLinkUrlResolver = A.Fake <IContentLinkUrlResolver>();
            var deliveryOptions        = DeliveryOptionsFactory.Create(new DeliveryOptions {
                ProjectId = _guid
            });
            var retryPolicy         = A.Fake <IRetryPolicy>();
            var retryPolicyProvider = A.Fake <IRetryPolicyProvider>();

            A.CallTo(() => retryPolicyProvider.GetRetryPolicy()).Returns(retryPolicy);
            A.CallTo(() => retryPolicy.ExecuteAsync(A <Func <Task <HttpResponseMessage> > > ._)).ReturnsLazily(c => c.GetArgument <Func <Task <HttpResponseMessage> > >(0)());
            var modelProvider = new ModelProvider(contentLinkUrlResolver, null, new CustomTypeProvider(), new PropertyMapper(), new DeliveryJsonSerializer(), new HtmlParser());
            var client        = new DeliveryClient(deliveryOptions, modelProvider, retryPolicyProvider, null, deliveryHttpClient);

            return(client);
        }
        public ContentTypeExtractorTests()
        {
            var contentTypeProvider = A.Fake <ITypeProvider>();

            A.CallTo(() => contentTypeProvider.GetCodename(typeof(TypeWithContentTypeCodename))).Returns(TypeWithContentTypeCodename.Codename);
            A.CallTo(() => contentTypeProvider.GetCodename(typeof(TypeWithoutContentTypeCodename))).Returns(null);

            var deliveryOptions = DeliveryOptionsFactory.Create(new DeliveryOptions {
                ProjectId = FAKE_PROJECT_ID
            });
            var modelProvider = new ModelProvider(null, null, contentTypeProvider, null, new DeliveryJsonSerializer(), new HtmlParser());

            _client = new DeliveryClient(
                deliveryOptions,
                modelProvider,
                null,
                contentTypeProvider
                );
        }