public async Task HomeController_Index_ReturnsExpectedContent() { // Arrange var resetResponse = await Client.PostAsync("http://localhost/Home/Reset", content : null); // Guard 1 (start from scratch) AssertRedirectsToHome(resetResponse); var createBillyContent = CreateUserFormContent("Billy", "2000-11-28", 0, "hello"); var createBillyResponse = await Client.PostAsync("http://localhost/Home/Create", createBillyContent); // Guard 2 (ensure user 0 exists) AssertRedirectsToHome(createBillyResponse); var createBobbyContent = CreateUserFormContent("Bobby", "1999-10-27", 1, "howdy"); var createBobbyResponse = await Client.PostAsync("http://localhost/Home/Create", createBobbyContent); // Guard 3 (ensure user 1 exists) AssertRedirectsToHome(createBobbyResponse); var expectedMediaType = MediaTypeHeaderValue.Parse("text/html; charset=utf-8"); var resourceFile = "TagHelperSample.Web.Home.Index.html"; // Act var response = await Client.GetAsync("http://localhost/"); var responseContent = await response.Content.ReadAsStringAsync(); // Assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.Equal(expectedMediaType, response.Content.Headers.ContentType); RazorEmbeddedResource.AssertContent(resourceFile, responseContent); }
public async Task RenderView_ReturnsContents() { // Arrange var resourceFile = "RenderViewToString.html"; var applicationBasePath = TestServices.GetApplicationDirectory( typeof(Program).GetTypeInfo().Assembly.GetName().Name); var serviceScopeFactory = Program.InitializeServices(applicationBasePath); // Act var actual = await Program.RenderViewAsync(serviceScopeFactory); // Assert RazorEmbeddedResource.AssertContent(resourceFile, actual); }
public async Task TagHelperController_ConditionalComment_ReturnsExpectedContent() { // Arrange var expectedMediaType = MediaTypeHeaderValue.Parse("text/html; charset=utf-8"); var resourceFile = "TagHelperSample.Web.TagHelper.ConditionalComment.html"; // Act var response = await Client.GetAsync("http://localhost/TagHelper/ConditionalComment"); var responseContent = await response.Content.ReadAsStringAsync(); // Assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.Equal(expectedMediaType, response.Content.Headers.ContentType); RazorEmbeddedResource.AssertContent(resourceFile, responseContent); }
public async Task RenderView_WorksForMultipleViewsBeingRenderedConcurrently() { // Arrange var resourceFile = "RenderViewToString.html"; var applicationBasePath = TestServices.GetApplicationDirectory( typeof(Program).GetTypeInfo().Assembly.GetName().Name); var serviceScopeFactory = Program.InitializeServices(applicationBasePath); // Act var task1 = Program.RenderViewAsync(serviceScopeFactory); var task2 = Program.RenderViewAsync(serviceScopeFactory); await Task.WhenAll(task1, task2); // Assert RazorEmbeddedResource.AssertContent(resourceFile, task1.Result); RazorEmbeddedResource.AssertContent(resourceFile, task2.Result); }
public async Task HomeController_Index_ReturnsExpectedContent_AfterReset() { // Arrange var resetResponse = await Client.PostAsync("http://localhost/Home/Reset", content : null); // Guard (start from scratch) AssertRedirectsToHome(resetResponse); var expectedMediaType = MediaTypeHeaderValue.Parse("text/html; charset=utf-8"); var resourceFile = "TagHelperSample.Web.Home.Index-Reset.html"; // Act var response = await Client.GetAsync("http://localhost/"); var responseContent = await response.Content.ReadAsStringAsync(); // Assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.Equal(expectedMediaType, response.Content.Headers.ContentType); RazorEmbeddedResource.AssertContent(resourceFile, responseContent); }