public async Task CreateRole() { var ticks = System.DateTime.Now.Ticks; var postRequest = new HttpRequestMessage(HttpMethod.Post, "/Administration/CreateRole"); var formData = new Dictionary <string, string> { { "RoleName", $"Role_{ticks}" } }; postRequest.Content = new FormUrlEncodedContent(formData); // .AspNetCore.Identity.Application var accountController = new AccountControllerShould(this.fixture); var loginCookies = await accountController.LoginApplication(); this.fixture.SetLoginCookies(postRequest, loginCookies); // Post Response HttpResponseMessage postResponse = await this.fixture.HttpClient.SendAsync(postRequest); Assert.Equal(System.Net.HttpStatusCode.Found, postResponse.StatusCode); Assert.NotNull(postResponse.Headers); Assert.Contains("Location: ", postResponse.Headers.ToString()); var listRolesLocation = postResponse.Headers.GetValues("Location").First(); Assert.EndsWith("/Administration/ListRoles", listRolesLocation); // Issue New Get with login cookie to check newly created role var httpRequest = new HttpRequestMessage(HttpMethod.Get, listRolesLocation); this.fixture.SetLoginCookies(httpRequest, loginCookies); var response = await this.fixture.HttpClient.SendAsync(httpRequest); response.EnsureSuccessStatusCode(); var responseString = await response.Content.ReadAsStringAsync(); Assert.Contains($"Role_{ticks}", responseString); }
public async Task CreateNewEmployee() { var ticks = System.DateTime.Now.Ticks; var postRequest = new HttpRequestMessage(HttpMethod.Post, "/Home/Create"); var formData = new Dictionary <string, string> { { "Name", $"Jack_{ticks}" }, { "Email", $"Jack_{ticks}@techjp.in" }, { "Department", "1" } }; postRequest.Content = new FormUrlEncodedContent(formData); var accountController = new AccountControllerShould(this.fixture); var loginCookies = await accountController.LoginApplication(); this.fixture.SetLoginCookies(postRequest, loginCookies); // Post Response HttpResponseMessage postResponse = await this.fixture.HttpClient.SendAsync(postRequest); Assert.Equal(System.Net.HttpStatusCode.Found, postResponse.StatusCode); Assert.NotNull(postResponse.Headers); Assert.Contains("Location: ", postResponse.Headers.ToString()); var newEmployeeLocation = postResponse.Headers.GetValues("Location").First(); // Issue New Get for newly created employee var response = await this.fixture.HttpClient.GetAsync(newEmployeeLocation); response.EnsureSuccessStatusCode(); var responseString = await response.Content.ReadAsStringAsync(); Assert.Contains($"<h1>Jack_{ticks}</h1>", responseString); Assert.Contains($"Email: Jack_{ticks}@techjp.in", responseString); }