From 8906d8e5f7f33714b85b477b65faa66dd92adfd6 Mon Sep 17 00:00:00 2001 From: Kiran Challa Date: Fri, 1 Jun 2018 11:18:47 -0700 Subject: [PATCH] Added functional tests for Dispatcher sample --- .../DispatcherSampleTest.cs | 70 +++++++++++++++++++ ....AspNetCore.Routing.FunctionalTests.csproj | 1 + 2 files changed, 71 insertions(+) create mode 100644 test/Microsoft.AspNetCore.Routing.FunctionalTests/DispatcherSampleTest.cs diff --git a/test/Microsoft.AspNetCore.Routing.FunctionalTests/DispatcherSampleTest.cs b/test/Microsoft.AspNetCore.Routing.FunctionalTests/DispatcherSampleTest.cs new file mode 100644 index 0000000000..ff26a0e250 --- /dev/null +++ b/test/Microsoft.AspNetCore.Routing.FunctionalTests/DispatcherSampleTest.cs @@ -0,0 +1,70 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Net; +using System.Net.Http; +using System.Threading.Tasks; +using Microsoft.AspNetCore.TestHost; +using Xunit; + +namespace Microsoft.AspNetCore.Routing.FunctionalTests +{ + public class DispatcherSampleTest : IDisposable + { + private readonly HttpClient _client; + private readonly TestServer _testServer; + + public DispatcherSampleTest() + { + var webHostBuilder = DispatcherSample.Web.Program.GetWebHostBuilder(); + _testServer = new TestServer(webHostBuilder); + _client = _testServer.CreateClient(); + _client.BaseAddress = new Uri("http://localhost"); + } + + [Fact] + public async Task MatchesRootPath_AndReturnsPlaintext() + { + // Arrange + var expectedContentType = "text/plain"; + var expectedContent = "Dispatcher sample endpoints:" + Environment.NewLine + "/plaintext"; + + // Act + var response = await _client.GetAsync("/"); + + // Assert + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + Assert.NotNull(response.Content); + Assert.NotNull(response.Content.Headers.ContentType); + Assert.Equal(expectedContentType, response.Content.Headers.ContentType.MediaType); + var actualContent = await response.Content.ReadAsStringAsync(); + Assert.Equal(expectedContent, actualContent); + } + + [Fact] + public async Task MatchesStaticRouteTemplate_AndReturnsPlaintext() + { + // Arrange + var expectedContentType = "text/plain"; + var expectedContent = "Hello, World!"; + + // Act + var response = await _client.GetAsync("/plaintext"); + + // Assert + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + Assert.NotNull(response.Content); + Assert.NotNull(response.Content.Headers.ContentType); + Assert.Equal(expectedContentType, response.Content.Headers.ContentType.MediaType); + var actualContent = await response.Content.ReadAsStringAsync(); + Assert.Equal(expectedContent, actualContent); + } + + public void Dispose() + { + _testServer.Dispose(); + _client.Dispose(); + } + } +} diff --git a/test/Microsoft.AspNetCore.Routing.FunctionalTests/Microsoft.AspNetCore.Routing.FunctionalTests.csproj b/test/Microsoft.AspNetCore.Routing.FunctionalTests/Microsoft.AspNetCore.Routing.FunctionalTests.csproj index 9520c32ff5..cbbb6f11e1 100644 --- a/test/Microsoft.AspNetCore.Routing.FunctionalTests/Microsoft.AspNetCore.Routing.FunctionalTests.csproj +++ b/test/Microsoft.AspNetCore.Routing.FunctionalTests/Microsoft.AspNetCore.Routing.FunctionalTests.csproj @@ -7,6 +7,7 @@ +