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"); } } }
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"); }); }); } } }
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()); } } }
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"); } } }