public async Task Then_NotFound_is_not_returned() { var client = new WebApplicationFactory <Startup>().CreateClient(); var response = await client.GetAsync("/Account/Logout"); response.StatusCode.Should().NotBe(HttpStatusCode.NotFound); }
public async Task Then_404_NotFound_is_not_returned() { var client = new WebApplicationFactory <Startup>().CreateClient(); var response = await client.GetAsync("/Invitations/SignUpComplete/" + Guid.NewGuid()); response.StatusCode.Should().NotBe(HttpStatusCode.NotFound); }
public async Task GetSingleUserShouldContainHelicopter() { var client = new WebApplicationFactory <Startup>().CreateClient(); var response = await client.GetAsync("/user/1"); var body = await response.Content.ReadAsStringAsync(); Assert.Contains("Helicopter", body); }
public async Task GetSingleUserShouldReturn200StatusCode() { var client = new WebApplicationFactory <Startup>().CreateClient(); var response = await client.GetAsync("/user/1"); var status = response.StatusCode; Assert.Equal(HttpStatusCode.OK, status); }
public async Task Then_404_is_not_received() { var client = new WebApplicationFactory <Startup>().CreateClient(new WebApplicationFactoryClientOptions() { AllowAutoRedirect = false }); var response = await client.GetAsync("/connect/authorize?client_id=apply&redirect_uri=https%3A%2F%2Flocalhost%3A6016%2Fsignin-oidc&response_type=id_token&scope=openid&response_mode=form_post&nonce=636870306741009302.OGQ0NzNiNGMtYTI0NC00MWYyLTkwN2EtYTZjYWYzMWEzZDlmYjk3NzYzOGEtMTQyZC00NmVjLTkxNzEtMzcyMzI2MDY0OGRl&state=CfDJ8LFoUd-yaHtCvaoVlhv1Wfqc67BTxjkNx_lTq5KspA_63Dunb1MzY5ns9cm0Q6EzZNRESvUudLno7ONZKTmCrPHfC9RxRuUOUtH9zhLWvwNI8T7jB3oljq4cZK0JVTxvBP1Tjd2cuGrEH1i1sDsbxVPKBSktOVv2H3pow-OPVT-DEOtN2pCGG8IeyqgM_QEpaTdNDIaBHJ0ZdfDL2CQ8VmMAowJxtA2IbEcJ7nIAC_1kmodGjaumlQl8EaDWolr6m-D5E9OAtgM-pby1SnZKXR4lnBp65fc3uLY8TtrLsVpz_lSyb2Gw7oxuNUI4hyIbbw&x-client-SKU=ID_NETSTANDARD1_4&x-client-ver=5.2.0.0"); response.StatusCode.Should().NotBe(HttpStatusCode.NotFound); }
public async Task Index_WhenHostingEnvironmentIsDevelopment_ReturnView() { // Arrange var client = new WebApplicationFactory <Startup>().CreateClient(); // Act var response = await client.GetAsync("/"); // Assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.Equal("text/html; charset=utf-8", response.Content.Headers.ContentType.ToString()); }
public async Task GetMovieShouldReturnBadRequestWhenClientThrowsException() { var client = new WebApplicationFactory <Startup>() .WithWebHostBuilder(builder => { builder.ConfigureServices(services => { services.AddSingleton <IClient, ArgumentExceptionClient>(); }); }).CreateClient(); var res = await client.GetAsync("/movie?Title=title"); Assert.Equal(HttpStatusCode.BadRequest, res.StatusCode); }
public async Task GetMovieWithTestClientShouldReturnNotFound(string url) { var client = new WebApplicationFactory <Startup>() .WithWebHostBuilder(builder => { builder.ConfigureServices(services => { services.AddSingleton <IClient, NotFoundClient>(); }); }).CreateClient(); var res = await client.GetAsync(url); Assert.Equal(HttpStatusCode.NotFound, res.StatusCode); }
public async Task SortEndpointIsConfiguredAndReturnsCorrectJsonResponseForRecommended() { // Arrange var httpClient = new WebApplicationFactory <ProductCatalog.Api.Startup>().Server.CreateClient(); // Act var httpResponseMessage = await httpClient.GetAsync("/sort?sortOption=Recommended"); // Assert httpResponseMessage.StatusCode.Should().Be(StatusCodes.Status200OK); var readAsStringAsync = await httpResponseMessage.Content.ReadAsStringAsync(); var products = JsonConvert.DeserializeObject <Product[]>(readAsStringAsync); products.Should().Equal(ListOfProduct.SortedBasedOnRecommended); }
public async Task UserEndpointIsConfiguredAndReturnsCorrectJsonResponse() { // Arrange var httpClient = new WebApplicationFactory <ProductCatalog.Api.Startup>().Server.CreateClient(); // Act var httpResponseMessage = await httpClient.GetAsync("/user"); // Assert httpResponseMessage.StatusCode.Should().Be(StatusCodes.Status200OK); var readAsStringAsync = await httpResponseMessage.Content.ReadAsStringAsync(); var userResponseModel = JsonConvert.DeserializeObject <UserResponseModel>(readAsStringAsync); userResponseModel.Name.Should().Be("Wael Emara"); userResponseModel.Token.Should().Be("25a4f06f-8fd5-49b3-a711-c013c156f8c8"); }
public async Task Return_List_Of_Albums() { // Arrange var httpClient = new WebApplicationFactory <Startup>().CreateClient(); httpClient.DefaultRequestHeaders.TryAddWithoutValidation("User-Id", UserId); // Act var response = await httpClient.GetAsync("/albums"); response.EnsureSuccessStatusCode(); var result = await response.Content.ReadAsAsync <List <AlbumResponse> >(); // Assert Assert.AreEqual(expected: 10, actual: result.Count); result.ForEach((album) => { Assert.AreEqual(expected: UserId, actual: album.UserId); }); }
public async Task Return_Welcome_Message() { // Arrange var apiName = Startup.ApiName; var apiDescription = Startup.ApiDescription; var apiVersion = Startup.ApiVersion; var docsUrl = "https://localhost/docs"; var httpClient = new WebApplicationFactory <Startup>().CreateClient(); // Act var response = await httpClient.GetAsync("/"); response.EnsureSuccessStatusCode(); var result = await response.Content.ReadAsAsync <JObject>(); // Assert Assert.AreEqual(expected: apiName, actual: result["message"].ToString()); Assert.AreEqual(expected: apiDescription, actual: result["details"].ToString()); Assert.AreEqual(expected: apiVersion, actual: result["version"].ToString()); Assert.AreEqual(expected: docsUrl, actual: result["docs"].ToString()); }