コード例 #1
0
        public async Task AppSettingsFile_GetsLoaded_WhenIncludeAppSettingsProjectOptionIsAdded(bool isToggled)
        {
            // Arrange
            var projectOptions = new WebApiProjectOptions().WithIncludeAppSettings();

            using (var project = WebApiProject.CreateNew(projectOptions, _outputWriter))
            {
                project.AddTypeAsFile <FeatureToggledController>(namespaces: "Controllers");
                project.UpdateFileInProject(
                    "appsettings.json",
                    contents => AddJsonBoolValue(contents, key: FeatureToggle, value: isToggled));

                await project.StartAsync();

                // Act
                using (HttpResponseMessage response = await project.Root.GetAsync(Route))
                {
                    // Assert
                    Assert.NotNull(response);
                    Assert.True(
                        response.IsSuccessStatusCode == isToggled,
                        "Only when the feature toggle in the 'appsettings.json' is activated, should the controller response successful");
                }
            }
        }
コード例 #2
0
        public async Task GetSabotagedEndpoint_TracksFailedResponse_ReturnsFailedResponse()
        {
            // Arrange
            var optionsWithSerilogLogging =
                new WebApiProjectOptions().WithSerilogLogging(ApplicationInsightsConfig.InstrumentationKey);

            using (var project = WebApiProject.CreateNew(Configuration, optionsWithSerilogLogging, Logger))
            {
                project.AddTypeAsFile <SaboteurController>();
                await project.StartAsync();

                // Act
                using (HttpResponseMessage response = await project.Root.GetAsync(SaboteurController.Route))
                {
                    // Assert
                    Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode);
                    await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client =>
                    {
                        EventsResults <EventsRequestResult> results =
                            await client.Events.GetRequestEventsAsync(ApplicationInsightsConfig.ApplicationId, filter: OnlyLastHourFilter);

                        Assert.Contains(results.Value, result =>
                        {
                            return(result.Request.Url.Contains("sabotage") && result.Request.ResultCode == "500");
                        });
                    });
                }
            }
        }
コード例 #3
0
        public async Task GetEnumEndpoint_WithEnumInput_ReturnsOk()
        {
            // Arrange
            using (var project = WebApiProject.CreateNew(_outputWriter))
            {
                project.AddTypeAsFile <EnumController>();
                project.AddTypeAsFile <TestEnum>();
                await project.StartAsync();

                using (var content = new StringContent("\"One\"", Encoding.UTF8, "application/json"))
                    using (HttpResponseMessage response = await project.Root.GetAsync(EnumController.GetRoute, content))
                    {
                        // Assert
                        Assert.True(HttpStatusCode.OK == response.StatusCode, await response.Content.ReadAsStringAsync());
                    }
            }
        }
コード例 #4
0
        public async Task AppSettingsFile_DoesntGetsLoaded_WhenNoIncludeAppSettingsProjectOptionIsAdded()
        {
            // Arrange
            using (var project = WebApiProject.CreateNew(_outputWriter))
            {
                project.AddTypeAsFile <FeatureToggledController>(namespaces: "Controllers");
                await project.StartAsync();

                // Act
                using (HttpResponseMessage response = await project.Root.GetAsync(Route))
                {
                    // Assert
                    Assert.NotNull(response);
                    Assert.False(
                        response.IsSuccessStatusCode,
                        "When no '--include-appsettings' project is added, the feature toggled controller should not response successful");
                }
            }
        }