예제 #1
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);
        }