Beispiel #1
0
        public async Task <ActionResult> Index()
        {
            IDeliveryClient c = DeliveryClientBuilder.WithProjectId("975bf280-fd91-488c-994c-2f04416e5ee3").Build();
            var             i = await c.GetItemAsync("on_roasts");

            return(View());
        }
        public async void GetItemsAsync_SerializeAndDeserialize()
        {
            // Arrange
            string url = $"{_baseUrl}/items";

            _mockHttp
            .When(url)
            .WithQueryString("system.type=article")
            .Respond("application/json",
                     await File.ReadAllTextAsync(Path.Combine(Environment.CurrentDirectory, $"Fixtures{Path.DirectorySeparatorChar}full_articles.json")));

            var client = DeliveryClientBuilder.WithProjectId(_projectId).WithTypeProvider(new CustomTypeProvider()).WithDeliveryHttpClient(new DeliveryHttpClient(_mockHttp.ToHttpClient())).Build();

            // Act
            var response = await client.GetItemsAsync <Article>();

            var serializedResponse   = response.ToBson();
            var deserializedResponse = serializedResponse.FromBson <DeliveryItemListingResponse <Article> >();

            // Assert item equality
            response.Should().BeEquivalentTo(deserializedResponse, o => o.IgnoringCyclicReferences().DateTimesBsonCorrection());

            // Assert the first item - check collections and DateTimes
            var firstItem             = response.Items.FirstOrDefault();
            var firstDeserializedItem = deserializedResponse.Items.FirstOrDefault();

            Assert.NotEmpty(firstDeserializedItem.TeaserImage);
            Assert.NotEmpty(firstDeserializedItem.Personas);
            Assert.Equal(firstItem.PostDate, firstDeserializedItem.PostDate);
        }
Beispiel #3
0
        public void BuildWithOptionalSteps_ReturnsDeliveryClientWithSetInstances()
        {
            var mockModelProvider                         = A.Fake <IModelProvider>();
            var mockRetryPolicyProvider                   = A.Fake <IRetryPolicyProvider>();
            var mockPropertyMapper                        = A.Fake <IPropertyMapper>();
            var mockContentLinkUrlResolver                = A.Fake <IContentLinkUrlResolver>();
            var mockInlineContentItemsProcessor           = A.Fake <IInlineContentItemsProcessor>();
            var mockDefaultInlineContentItemsResolver     = A.Fake <IInlineContentItemsResolver <object> >();
            var mockUnretrievedInlineContentItemsResolver = A.Fake <IInlineContentItemsResolver <UnretrievedContentItem> >();
            var mockAnContentItemsResolver                = A.Fake <IInlineContentItemsResolver <CompleteContentItemModel> >();
            var mockTypeProvider       = A.Fake <ITypeProvider>();
            var mockDeliveryHttpClient = new DeliveryHttpClient(new MockHttpMessageHandler().ToHttpClient());

            var deliveryClient = (Delivery.DeliveryClient)DeliveryClientBuilder
                                 .WithProjectId(ProjectId)
                                 .WithDeliveryHttpClient(mockDeliveryHttpClient)
                                 .WithContentLinkUrlResolver(mockContentLinkUrlResolver)
                                 .WithInlineContentItemsProcessor(mockInlineContentItemsProcessor)
                                 .WithInlineContentItemsResolver(mockDefaultInlineContentItemsResolver)
                                 .WithInlineContentItemsResolver(mockUnretrievedInlineContentItemsResolver)
                                 .WithInlineContentItemsResolver(mockAnContentItemsResolver)
                                 .WithModelProvider(mockModelProvider)
                                 .WithPropertyMapper(mockPropertyMapper)
                                 .WithRetryPolicyProvider(mockRetryPolicyProvider)
                                 .WithTypeProvider(mockTypeProvider)
                                 .Build();

            Assert.Equal(ProjectId, deliveryClient.DeliveryOptions.CurrentValue.ProjectId);
            Assert.Equal(mockModelProvider, deliveryClient.ModelProvider);
            Assert.Equal(mockRetryPolicyProvider, deliveryClient.RetryPolicyProvider);
            Assert.Equal(mockTypeProvider, deliveryClient.TypeProvider);
            Assert.Equal(mockDeliveryHttpClient, deliveryClient.DeliveryHttpClient);
        }
Beispiel #4
0
        public async Task IntegrationTest(bool cmApi)
        {
            var mockHttp = new MockHttpMessageHandler();

            mockHttp.When("https://deliver.kontent.ai/*")
            .Respond("application/json", File.ReadAllText(Path.Combine(AppContext.BaseDirectory, "Fixtures/types.json")));
            var httpClient = mockHttp.ToHttpClient();

            var mockOptions = new Mock <IOptions <CodeGeneratorOptions> >();

            mockOptions.Setup(x => x.Value).Returns(new CodeGeneratorOptions
            {
                Namespace            = "CustomNamespace",
                OutputDir            = TEMP_DIR,
                ContentManagementApi = cmApi
            });

            var client = DeliveryClientBuilder.WithProjectId(PROJECT_ID).WithDeliveryHttpClient(new DeliveryHttpClient(httpClient)).Build();

            var codeGenerator = new CodeGenerator(mockOptions.Object, client);

            await codeGenerator.GenerateContentTypeModels();

            await codeGenerator.GenerateTypeProvider();

            Assert.True(Directory.GetFiles(Path.GetFullPath(TEMP_DIR)).Length > 10);

            foreach (var filepath in Directory.EnumerateFiles(Path.GetFullPath(TEMP_DIR)))
            {
                Assert.DoesNotContain(".Generated.cs", Path.GetFileName(filepath));
            }

            // Cleanup
            Directory.Delete(TEMP_DIR, true);
        }
        public async void InitializeMultipleInlineContentItemsResolvers()
        {
            string       url               = $"{_baseUrl}/items/";
            const string tweetPrefix       = "Tweet resolver: ";
            const string hostedVideoPrefix = "Video resolver: ";

            _mockHttp
            .When($"{url}{"coffee_beverages_explained"}")
            .Respond("application/json", File.ReadAllText(Path.Combine(Environment.CurrentDirectory, $"Fixtures{Path.DirectorySeparatorChar}DeliveryClient{Path.DirectorySeparatorChar}coffee_beverages_explained.json")));

            var deliveryClient = DeliveryClientBuilder
                                 .WithProjectId(_guid)
                                 .WithInlineContentItemsResolver(InlineContentItemsResolverFactory.Instance
                                                                 .ResolveTo <Tweet>(tweet => tweetPrefix + tweet.TweetLink))
                                 .WithInlineContentItemsResolver(InlineContentItemsResolverFactory.Instance
                                                                 .ResolveTo <HostedVideo>(video => hostedVideoPrefix + video.VideoHost.First().Name))
                                 .WithTypeProvider(new CustomTypeProvider())
                                 .WithHttpClient(_mockHttp.ToHttpClient())
                                 .Build();

            var article = await deliveryClient.GetItemAsync <Article>("coffee_beverages_explained");

            Assert.Contains(tweetPrefix, article.Item.BodyCopy);
            Assert.Contains(hostedVideoPrefix, article.Item.BodyCopy);
        }
Beispiel #6
0
        public async Task Index_ReturnsAViewResult_WithAnArticle()
        {
            // Arrange
            var config = new Mock <IConfiguration>();

            MockHttpMessageHandler mockHttp = new MockHttpMessageHandler();

            mockHttp.When($"https://deliver.kontent.ai/975bf280-fd91-488c-994c-2f04416e5ee3/items?elements.url_pattern=on_roasts&depth=1&language={CultureInfo.CurrentCulture}&system.type=article")
            .Respond("application/json", File.ReadAllText(Path.Combine(Environment.CurrentDirectory, $"on_roasts.json")));
            IDeliveryClient client  = DeliveryClientBuilder.WithProjectId("975bf280-fd91-488c-994c-2f04416e5ee3").WithDeliveryHttpClient(new DeliveryHttpClient(mockHttp.ToHttpClient())).WithTypeProvider(new CustomTypeProvider()).Build();
            var             factory = new Mock <IDeliveryClientFactory>();

            factory.Setup(m => m.Get()).Returns(client);

            ArticlesController controller = new ArticlesController(config.Object, factory.Object);

            // Act
            var result = await controller.Show("on_roasts");

            // Assert
            var viewResult = Assert.IsType <ViewResult>(result);
            var viewModel  = Assert.IsType <Article>(viewResult.ViewData.Model);

            Assert.Equal("On Roasts", viewModel.Title);
        }
Beispiel #7
0
        public static async Task <Song> GetSong(string kontentProjectId, int trackNumber)
        {
            IDeliveryClient client = DeliveryClientBuilder.WithProjectId(kontentProjectId).Build();

            DeliveryItemListingResponse <Song> song = await client.GetItemsAsync <Song>(new EqualsFilter("elements.track_number", trackNumber.ToString()));

            return(song.Items[0]);
        }
        public IDeliveryClient GetDeliveryClient()
        {
            if (_deliveryClient == null)
            {
                var projectId = _configuration.GetValue <string>("DeliveryOptions:ProjectId");
                _deliveryClient = DeliveryClientBuilder.WithProjectId(projectId).WithHttpClient(_httpClient).WithTypeProvider(_typeProvider).Build();
            }

            return(_deliveryClient);
        }
Beispiel #9
0
        public void BuildWithOptionalStepsAndCustomProvider_ReturnsDeliveryClientWithSetInstances()
        {
            var modelProvider = new FakeModelProvider();

            var deliveryClient = (Delivery.DeliveryClient)DeliveryClientBuilder
                                 .WithProjectId(ProjectId)
                                 .WithModelProvider(modelProvider)
                                 .Build();

            Assert.Equal(modelProvider, deliveryClient.ModelProvider);
        }
        public static async Task Main(string[] args)
        {
            IDeliveryClient client   = DeliveryClientBuilder.WithProjectId(ProjectId).WithTypeProvider(new CustomTypeProvider()).Build();
            var             articles = await client.GetItemsAsync <Article>();

            foreach (var article in articles.Items)
            {
                Console.WriteLine($"The article '{article.Title}' was posted on {article.PostDate.Value.ToShortDateString()}.");
            }
            Console.ReadLine();
        }
Beispiel #11
0
        public async Task <ViewResult> Index()
        {
            IDeliveryClient client = DeliveryClientBuilder
                                     .WithProjectId("<ProjectID>")
                                     .Build();

            var response = await client.GetItemAsync <Homepage>(
                "employers",
                new DepthParameter(3)
                );

            return(View(response.Item));
        }
Beispiel #12
0
        public async Task IntegrationTest_RunAsync_GeneratePartials_CorrectFiles()
        {
            var mockHttp = new MockHttpMessageHandler();

            mockHttp.When("https://deliver.kontent.ai/*")
            .Respond("application/json", await File.ReadAllTextAsync(Path.Combine(AppContext.BaseDirectory, "Fixtures/delivery_types.json")));
            var httpClient = mockHttp.ToHttpClient();

            const string transformFilename = "Generated";

            var mockOptions = new Mock <IOptions <CodeGeneratorOptions> >();

            mockOptions.Setup(x => x.Value).Returns(new CodeGeneratorOptions
            {
                DeliveryOptions = new DeliveryOptions {
                    ProjectId = ProjectId
                },
                Namespace        = "CustomNamespace",
                OutputDir        = TempDir,
                FileNameSuffix   = transformFilename,
                GeneratePartials = true,
                WithTypeProvider = false,
                StructuredModel  = false,
                ManagementApi    = false
            });

            var deliveryClient = DeliveryClientBuilder.WithProjectId(ProjectId)
                                 .WithDeliveryHttpClient(new DeliveryHttpClient(httpClient)).Build();

            var codeGenerator = new DeliveryCodeGenerator(mockOptions.Object, new FileSystemOutputProvider(mockOptions.Object), deliveryClient);

            await codeGenerator.RunAsync();

            var allFilesCount  = Directory.GetFiles(Path.GetFullPath(TempDir), "*.cs").Length;
            var generatedCount = Directory.GetFiles(Path.GetFullPath(TempDir), $"*.{transformFilename}.cs").Length;

            Assert.Equal(allFilesCount, generatedCount * 2);

            foreach (var filepath in Directory.EnumerateFiles(Path.GetFullPath(TempDir), $"*.{transformFilename}.cs"))
            {
                var customFileExists = File.Exists(filepath.Replace($".{transformFilename}", ""));
                Assert.True(customFileExists);
            }

            // Cleanup
            Directory.Delete(TempDir, true);
        }
Beispiel #13
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req,
            ILogger log, ExecutionContext context)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");
            var config = new ConfigurationBuilder()
                         .SetBasePath(context.FunctionAppDirectory)
                         .AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
                         .AddEnvironmentVariables()
                         .Build();

            IDeliveryClient client = DeliveryClientBuilder.WithProjectId(config["KontentProjectId"]).Build();

            DeliveryItemListingResponse <Song> listingResponse = await client.GetItemsAsync <Song>();

            var songs = listingResponse.Items.Select(x => x.Title).ToArray();

            string API_KEY    = config["NEXMO_API_KEY"];
            string API_SECRET = config["NEXMO_API_SECRET"];

            var nexmoClient = new Client(creds: new Nexmo.Api.Request.Credentials(
                                             nexmoApiKey: API_KEY, nexmoApiSecret: API_SECRET));

            var results = nexmoClient.SMS.Send(new SMS.SMSRequest
            {
                from = req.Query["to"],
                to   = req.Query["msisdn"],
                text = ConvertToNumberedList(songs)
            });


            return(new OkObjectResult(songs));

            string ConvertToNumberedList(IEnumerable <string> songs)
            {
                StringBuilder sb         = new StringBuilder();
                int           songNumber = 1;

                foreach (var s in songs)
                {
                    sb.AppendLine($"{songNumber++} - {s}");
                }
                return(sb.ToString());
            }
        }
Beispiel #14
0
        private static async Task <AbstractResponse> GetAbstractResponseInstance(bool shouldBeStaleContent)
        {
            var itemsResponse = new
            {
                items           = Enumerable.Empty <object>(),
                modular_content = new Dictionary <string, object>()
            };

            var staleContentHeaderValue = shouldBeStaleContent ? "1" : "0";
            var mockHandler             = new MockHttpMessageHandler();
            var responseHeaders         = new[] { new KeyValuePair <string, string>("X-Stale-Content", staleContentHeaderValue) };

            mockHandler.When("*").Respond(responseHeaders, "application/json", JsonConvert.SerializeObject(itemsResponse));
            var httpClient = mockHandler.ToHttpClient();
            var client     = DeliveryClientBuilder.WithProjectId(Guid.NewGuid()).WithHttpClient(httpClient).Build();

            return(await client.GetItemsAsync());
        }
Beispiel #15
0
        public async Task Setup()
        {
            var projectId = Guid.NewGuid();
            var baseUrl   = $"https://deliver.kontent.ai/{projectId}";
            var mockHttp  = new MockHttpMessageHandler();

            mockHttp
            .When($"{baseUrl}/items/on_roasts")
            .Respond("application/json", await File.ReadAllTextAsync(Path.Combine(Environment.CurrentDirectory, $"Fixtures{Path.DirectorySeparatorChar}on_roasts.json")));

            mockHttp
            .When($"{baseUrl}/items")
            .WithQueryString("system.type=article")
            .Respond("application/json",
                     await File.ReadAllTextAsync(Path.Combine(Environment.CurrentDirectory, $"Fixtures{Path.DirectorySeparatorChar}full_articles.json")));

            _client = DeliveryClientBuilder.WithProjectId(projectId).WithTypeProvider(new CustomTypeProvider()).WithDeliveryHttpClient(new DeliveryHttpClient(mockHttp.ToHttpClient())).Build();
        }
Beispiel #16
0
        public async Task IntegrationTestWithGeneratePartials(bool cmApi)
        {
            var mockHttp = new MockHttpMessageHandler();

            mockHttp.When("https://deliver.kontent.ai/*")
            .Respond("application/json", File.ReadAllText(Path.Combine(AppContext.BaseDirectory, "Fixtures/types.json")));
            var httpClient = mockHttp.ToHttpClient();

            const string transformFilename = "Generated";

            var mockOptions = new Mock <IOptions <CodeGeneratorOptions> >();

            mockOptions.Setup(x => x.Value).Returns(new CodeGeneratorOptions
            {
                DeliveryOptions = new DeliveryOptions {
                    ProjectId = PROJECT_ID
                },
                Namespace            = "CustomNamespace",
                OutputDir            = TEMP_DIR,
                FileNameSuffix       = transformFilename,
                GeneratePartials     = true,
                ContentManagementApi = cmApi
            });

            var client = DeliveryClientBuilder.WithProjectId(PROJECT_ID).WithDeliveryHttpClient(new DeliveryHttpClient(httpClient)).Build();

            var codeGenerator = new CodeGenerator(mockOptions.Object, client);

            await codeGenerator.GenerateContentTypeModels();

            var allFilesCount  = Directory.GetFiles(Path.GetFullPath(TEMP_DIR), "*.cs").Length;
            var generatedCount = Directory.GetFiles(Path.GetFullPath(TEMP_DIR), $"*.{transformFilename}.cs").Length;

            Assert.Equal(allFilesCount, generatedCount * 2);

            foreach (var filepath in Directory.EnumerateFiles(Path.GetFullPath(TEMP_DIR), $"*.{transformFilename}.cs"))
            {
                var customFileExists = File.Exists(filepath.Replace($".{transformFilename}", ""));
                Assert.True(customFileExists);
            }

            // Cleanup
            Directory.Delete(TEMP_DIR, true);
        }
Beispiel #17
0
        public void BuildWithoutOptionalSteps_ReturnsDeliveryClientWithDefaultImplementations()
        {
            var expectedResolvableInlineContentItemsTypes = new[]
            {
                typeof(object),
                typeof(UnretrievedContentItem),
                typeof(UnknownContentItem)
            };

            var deliveryClient = (Delivery.DeliveryClient)DeliveryClientBuilder
                                 .WithProjectId(_guid)
                                 .Build();
            var actualResolvableInlineContentItemTypes = GetResolvableInlineContentItemTypes(deliveryClient);

            Assert.NotNull(deliveryClient.ModelProvider);
            Assert.NotNull(deliveryClient.TypeProvider);
            Assert.NotNull(deliveryClient.DeliveryHttpClient);
            Assert.NotNull(deliveryClient.RetryPolicyProvider);
            Assert.Equal(expectedResolvableInlineContentItemsTypes, actualResolvableInlineContentItemTypes);
        }
Beispiel #18
0
        public static async Task <string> GetStringifiedSongList(string kontentProjectId)
        {
            IDeliveryClient client = DeliveryClientBuilder.WithProjectId(kontentProjectId).Build();

            DeliveryItemListingResponse <Song> listingResponse = await client.GetItemsAsync <Song>();

            var songs = listingResponse.Items.OrderBy(x => x.TrackNumber).Select(x => $"{x.TrackNumber} - {x.Title}").ToArray();

            return(ConvertToNumberedList(songs));

            string ConvertToNumberedList(IEnumerable <string> songList)
            {
                StringBuilder sb = new StringBuilder();

                foreach (var s in songList)
                {
                    sb.AppendLine(s);
                }
                return(sb.ToString());
            }
        }
        public void IntegrationTestWithGeneratedSuffix(bool cmApi)
        {
            var mockHttp = new MockHttpMessageHandler();

            mockHttp.When("https://deliver.kontent.ai/*")
            .Respond("application/json", File.ReadAllText(Path.Combine(AppContext.BaseDirectory, "Fixtures/types.json")));
            var httpClient = mockHttp.ToHttpClient();

            const string transformFilename = "Generated";

            var mockOptions = new Mock <IOptions <CodeGeneratorOptions> >();

            mockOptions.Setup(x => x.Value).Returns(new CodeGeneratorOptions
            {
                DeliveryOptions = new DeliveryOptions {
                    ProjectId = PROJECT_ID
                },
                Namespace            = "CustomNamespace",
                OutputDir            = TEMP_DIR,
                FileNameSuffix       = transformFilename,
                ContentManagementApi = cmApi
            });

            var client = DeliveryClientBuilder.WithProjectId(PROJECT_ID).WithHttpClient(httpClient).Build();

            var codeGenerator = new CodeGenerator(mockOptions.Object, client);

            codeGenerator.GenerateContentTypeModels();

            Assert.True(Directory.GetFiles(Path.GetFullPath(TEMP_DIR)).Length > 10);

            foreach (var filepath in Directory.EnumerateFiles(Path.GetFullPath(TEMP_DIR)))
            {
                Assert.EndsWith($".{transformFilename}.cs", Path.GetFileName(filepath));
            }

            // Cleanup
            Directory.Delete(TEMP_DIR, true);
        }
Beispiel #20
0
        public async Task IntegrationTest_RunAsync_CorrectFiles()
        {
            var mockHttp = new MockHttpMessageHandler();

            mockHttp.When("https://deliver.kontent.ai/*")
            .Respond("application/json", await File.ReadAllTextAsync(Path.Combine(AppContext.BaseDirectory, "Fixtures/delivery_types.json")));
            var httpClient = mockHttp.ToHttpClient();

            var mockOptions = new Mock <IOptions <CodeGeneratorOptions> >();

            mockOptions.Setup(x => x.Value).Returns(new CodeGeneratorOptions
            {
                DeliveryOptions = new DeliveryOptions {
                    ProjectId = ProjectId
                },
                Namespace        = "CustomNamespace",
                OutputDir        = TempDir,
                ManagementApi    = false,
                GeneratePartials = false,
                WithTypeProvider = false,
                StructuredModel  = false
            });

            var deliveryClient = DeliveryClientBuilder.WithProjectId(ProjectId).WithDeliveryHttpClient(new DeliveryHttpClient(httpClient)).Build();

            var codeGenerator = new DeliveryCodeGenerator(mockOptions.Object, new FileSystemOutputProvider(mockOptions.Object), deliveryClient);

            await codeGenerator.RunAsync();

            Assert.Equal(NumberOfContentTypes, Directory.GetFiles(Path.GetFullPath(TempDir)).Length);

            Assert.NotEmpty(Directory.EnumerateFiles(Path.GetFullPath(TempDir), "*.Generated.cs"));
            Assert.NotEmpty(Directory.EnumerateFiles(Path.GetFullPath(TempDir)).Where(p => !p.Contains("*.Generated.cs")));
            Assert.Empty(Directory.EnumerateFiles(Path.GetFullPath(TempDir), "*TypeProvider.cs"));

            // Cleanup
            Directory.Delete(TempDir, true);
        }
Beispiel #21
0
        public void BuildWithOptionalStepsWithCustomResolvers_ReturnsDeliveryClientWithSetInstances()
        {
            var mockDefaultInlineContentItemsResolver     = A.Fake <IInlineContentItemsResolver <object> >();
            var mockUnretrievedInlineContentItemsResolver = A.Fake <IInlineContentItemsResolver <UnretrievedContentItem> >();
            var mockCompleteContentItemsResolver          = A.Fake <IInlineContentItemsResolver <CompleteContentItemModel> >();
            var expectedResolvableInlineContentItemsTypes = new[]
            {
                typeof(object),
                typeof(UnretrievedContentItem),
                typeof(CompleteContentItemModel),
                typeof(UnknownContentItem)
            };

            var deliveryClient = (Delivery.DeliveryClient)DeliveryClientBuilder
                                 .WithProjectId(ProjectId)
                                 .WithInlineContentItemsResolver(mockDefaultInlineContentItemsResolver)
                                 .WithInlineContentItemsResolver(mockUnretrievedInlineContentItemsResolver)
                                 .WithInlineContentItemsResolver(mockCompleteContentItemsResolver)
                                 .Build();
            var actualResolvableInlineContentItemTypes = GetResolvableInlineContentItemTypes(deliveryClient);

            Assert.Equal(ProjectId, deliveryClient.DeliveryOptions.ProjectId);
            Assert.Equal(expectedResolvableInlineContentItemsTypes, actualResolvableInlineContentItemTypes);
        }
        public async void GetItemAsync_SerializeAndDeserialize()
        {
            // Arrange
            string url = $"{_baseUrl}/items/brazil_natural_barra_grande";

            _mockHttp
            .When(url)
            .Respond("application/json", await File.ReadAllTextAsync(Path.Combine(Environment.CurrentDirectory, $"Fixtures{Path.DirectorySeparatorChar}brazil_natural_barra_grande.json")));

            var client = DeliveryClientBuilder.WithProjectId(_projectId).WithTypeProvider(new CustomTypeProvider()).WithDeliveryHttpClient(new DeliveryHttpClient(_mockHttp.ToHttpClient())).Build();

            // Act
            var response = await client.GetItemAsync <Coffee>("brazil_natural_barra_grande");

            var serializedResponse   = response.ToBson();
            var deserializedResponse = serializedResponse.FromBson <DeliveryItemResponse <Coffee> >();

            // Assert item equality (apply precision correction for DateTime when deserializing)
            response.Should().BeEquivalentTo(deserializedResponse, o => o.DateTimesBsonCorrection());

            // Check that collections are ok
            Assert.NotEmpty(deserializedResponse.Item.Image);
            Assert.NotEmpty(deserializedResponse.Item.Processing);
        }
Beispiel #23
0
        public KontentHelper(IConfiguration configuration)
        {
            var projectId = configuration["KontentProjectID"];

            this.deliveryClient = DeliveryClientBuilder.WithProjectId(projectId).Build();
        }
Beispiel #24
0
        public void BuildWithProjectId_ReturnsDeliveryClientWithProjectIdSet()
        {
            var deliveryClient = (Delivery.DeliveryClient)DeliveryClientBuilder.WithProjectId(ProjectId).Build();

            Assert.Equal(ProjectId, deliveryClient.DeliveryOptions.ProjectId);
        }
Beispiel #25
0
        public void BuildWithOptionsAndNullPropertyMapper_ThrowsArgumentNullException()
        {
            var builderStep = DeliveryClientBuilder.WithProjectId(_guid);

            Assert.Throws <ArgumentNullException>(() => builderStep.WithPropertyMapper(null));
        }
Beispiel #26
0
        public void BuildWithOptionsAndNullInlineContentItemsProcessor_ThrowsArgumentNullException()
        {
            var builderStep = DeliveryClientBuilder.WithProjectId(_guid);

            Assert.Throws <ArgumentNullException>(() => builderStep.WithInlineContentItemsProcessor(null));
        }
Beispiel #27
0
        public void BuildWithOptionsAndNullContentLinUrlResolver_ThrowsArgumentNullException()
        {
            var builderStep = DeliveryClientBuilder.WithProjectId(_guid);

            Assert.Throws <ArgumentNullException>(() => builderStep.WithContentLinkUrlResolver(null));
        }
Beispiel #28
0
        public void BuildWithOptionsAndNullResiliencePolicyProvider_ThrowsArgumentNullException()
        {
            var builderStep = DeliveryClientBuilder.WithProjectId(_guid);

            Assert.Throws <ArgumentNullException>(() => builderStep.WithRetryPolicyProvider(null));
        }