public SurveyControllerTests(IntegrationTestWebApplicationFactory <Startup> factory) { _authenticatedClient = factory.WithWebHostBuilder(builder => { builder.ConfigureTestServices(services => { services.AddAuthentication("Test") .AddScheme <AuthenticationSchemeOptions, TestAuthHandler>( "Test", options => { }); }); }).CreateDefaultClient(new UnwrappingResponseHandler()); _unauthenticatedClient = factory.CreateClient(); }
public async Task Unauthenticated_Call_To_Post_Survey_Should_Return_Unauthorized_Response() { var client = _factory.CreateClient(); var createSurveyCommand = new CreateSurveyCommand("How unauthorized is this?", 400, "Unauthorized users", new List <SurveyOptionDto> { new SurveyOptionDto { OptionText = "Very unauthorized" }, new SurveyOptionDto { OptionText = "Completely Unauthorized" } }); var response = await client.PostAsync("/api/survey", new StringContent(JsonConvert.SerializeObject(createSurveyCommand), Encoding.UTF8, MediaTypeNames.Application.Json)); Assert.Equal(StatusCodes.Status401Unauthorized, (int)response.StatusCode); }
public AdminControllerTests(IntegrationTestWebApplicationFactory <Startup> factory) { _client = factory.CreateClient(); }