From a80594d706681b4c339ca536d20bb4752e6590d2 Mon Sep 17 00:00:00 2001 From: Steve Sanderson Date: Fri, 5 May 2017 19:08:36 +0100 Subject: [PATCH] Add FSharpWebSite plus simple functional test against it (#6231) --- build/dependencies.props | 2 + .../FSharpWebSiteTest.cs | 32 ++++++++++++++++ ...soft.AspNetCore.Mvc.FunctionalTests.csproj | 2 + .../Controllers/HomeController.fs | 16 ++++++++ .../FSharpWebSite/FSharpWebSite.fsproj | 37 +++++++++++++++++++ test/WebSites/FSharpWebSite/Program.fs | 24 ++++++++++++ test/WebSites/FSharpWebSite/Startup.fs | 19 ++++++++++ .../FSharpWebSite/Views/Home/Index.cshtml | 5 +++ .../FSharpWebSite/Views/Shared/_Layout.cshtml | 9 +++++ .../FSharpWebSite/Views/_ViewImports.cshtml | 1 + .../FSharpWebSite/Views/_ViewStart.cshtml | 3 ++ 11 files changed, 150 insertions(+) create mode 100644 test/Microsoft.AspNetCore.Mvc.FunctionalTests/FSharpWebSiteTest.cs create mode 100644 test/WebSites/FSharpWebSite/Controllers/HomeController.fs create mode 100644 test/WebSites/FSharpWebSite/FSharpWebSite.fsproj create mode 100644 test/WebSites/FSharpWebSite/Program.fs create mode 100644 test/WebSites/FSharpWebSite/Startup.fs create mode 100644 test/WebSites/FSharpWebSite/Views/Home/Index.cshtml create mode 100644 test/WebSites/FSharpWebSite/Views/Shared/_Layout.cshtml create mode 100644 test/WebSites/FSharpWebSite/Views/_ViewImports.cshtml create mode 100644 test/WebSites/FSharpWebSite/Views/_ViewStart.cshtml diff --git a/build/dependencies.props b/build/dependencies.props index 4017a7fed6..44cb4ea1a6 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -4,6 +4,8 @@ 0.10.3 4.3.0 2.0.0-* + 4.1.0 + 1.0.* 2.1.0-* 1.0.1 4.7.1 diff --git a/test/Microsoft.AspNetCore.Mvc.FunctionalTests/FSharpWebSiteTest.cs b/test/Microsoft.AspNetCore.Mvc.FunctionalTests/FSharpWebSiteTest.cs new file mode 100644 index 0000000000..3cd7c14409 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.FunctionalTests/FSharpWebSiteTest.cs @@ -0,0 +1,32 @@ +// 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.Net; +using System.Net.Http; +using System.Threading.Tasks; +using Xunit; + +namespace Microsoft.AspNetCore.Mvc.FunctionalTests +{ + public class FSharpWebSiteTest : IClassFixture> + { + public FSharpWebSiteTest(MvcTestFixture fixture) + { + Client = fixture.Client; + } + + public HttpClient Client { get; } + + [Fact] + public async Task HomeIndex_ReturnsHtml() + { + // Act + var response = await Client.GetAsync("http://localhost/"); + var responseBody = await response.Content.ReadAsStringAsync(); + + // Assert + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + Assert.Contains("

Hello from FSharpWebSite

", responseBody); + } + } +} diff --git a/test/Microsoft.AspNetCore.Mvc.FunctionalTests/Microsoft.AspNetCore.Mvc.FunctionalTests.csproj b/test/Microsoft.AspNetCore.Mvc.FunctionalTests/Microsoft.AspNetCore.Mvc.FunctionalTests.csproj index efcd7976f9..31fed2fb6e 100644 --- a/test/Microsoft.AspNetCore.Mvc.FunctionalTests/Microsoft.AspNetCore.Mvc.FunctionalTests.csproj +++ b/test/Microsoft.AspNetCore.Mvc.FunctionalTests/Microsoft.AspNetCore.Mvc.FunctionalTests.csproj @@ -31,6 +31,7 @@ + @@ -45,6 +46,7 @@ + diff --git a/test/WebSites/FSharpWebSite/Controllers/HomeController.fs b/test/WebSites/FSharpWebSite/Controllers/HomeController.fs new file mode 100644 index 0000000000..8658155e31 --- /dev/null +++ b/test/WebSites/FSharpWebSite/Controllers/HomeController.fs @@ -0,0 +1,16 @@ +// 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. + +namespace FSharpWebSite.Controllers + +open System +open System.Collections.Generic +open System.Linq +open System.Threading.Tasks +open Microsoft.AspNetCore.Mvc + +type HomeController () = + inherit Controller() + + member this.Index () = + this.View() diff --git a/test/WebSites/FSharpWebSite/FSharpWebSite.fsproj b/test/WebSites/FSharpWebSite/FSharpWebSite.fsproj new file mode 100644 index 0000000000..5b250bab5f --- /dev/null +++ b/test/WebSites/FSharpWebSite/FSharpWebSite.fsproj @@ -0,0 +1,37 @@ + + + + + netcoreapp2.0 + + + + + ..\..\..\build\Key.snk + true + true + false + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/WebSites/FSharpWebSite/Program.fs b/test/WebSites/FSharpWebSite/Program.fs new file mode 100644 index 0000000000..9def47bebc --- /dev/null +++ b/test/WebSites/FSharpWebSite/Program.fs @@ -0,0 +1,24 @@ +// 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. + +namespace FSharpWebSite + +open System.IO +open Microsoft.AspNetCore.Hosting + + +module Program = + + [] + let main args = + let host = + WebHostBuilder() + .UseContentRoot(Directory.GetCurrentDirectory()) + .UseStartup() + .UseKestrel() + .UseIISIntegration() + .Build() + + host.Run() + + 0 diff --git a/test/WebSites/FSharpWebSite/Startup.fs b/test/WebSites/FSharpWebSite/Startup.fs new file mode 100644 index 0000000000..09b0db7737 --- /dev/null +++ b/test/WebSites/FSharpWebSite/Startup.fs @@ -0,0 +1,19 @@ +// 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. + +namespace FSharpWebSite + +open Microsoft.AspNetCore.Builder +open Microsoft.AspNetCore.Hosting +open Microsoft.Extensions.DependencyInjection + + +type Startup () = + + member this.ConfigureServices(services: IServiceCollection) = + services.AddMvc() |> ignore + + member this.Configure(app: IApplicationBuilder) = + app.UseDeveloperExceptionPage() |> ignore + app.UseStaticFiles() |> ignore + app.UseMvcWithDefaultRoute() |> ignore diff --git a/test/WebSites/FSharpWebSite/Views/Home/Index.cshtml b/test/WebSites/FSharpWebSite/Views/Home/Index.cshtml new file mode 100644 index 0000000000..f2fd366901 --- /dev/null +++ b/test/WebSites/FSharpWebSite/Views/Home/Index.cshtml @@ -0,0 +1,5 @@ +@{ + ViewData["Title"] = "Home Page"; +} + +

Hello from FSharpWebSite

diff --git a/test/WebSites/FSharpWebSite/Views/Shared/_Layout.cshtml b/test/WebSites/FSharpWebSite/Views/Shared/_Layout.cshtml new file mode 100644 index 0000000000..5523878ce3 --- /dev/null +++ b/test/WebSites/FSharpWebSite/Views/Shared/_Layout.cshtml @@ -0,0 +1,9 @@ + + + + @ViewData["Title"] - FSharpWebSite + + + @RenderBody() + + diff --git a/test/WebSites/FSharpWebSite/Views/_ViewImports.cshtml b/test/WebSites/FSharpWebSite/Views/_ViewImports.cshtml new file mode 100644 index 0000000000..4694316f4b --- /dev/null +++ b/test/WebSites/FSharpWebSite/Views/_ViewImports.cshtml @@ -0,0 +1 @@ +@using FSharpWebSite diff --git a/test/WebSites/FSharpWebSite/Views/_ViewStart.cshtml b/test/WebSites/FSharpWebSite/Views/_ViewStart.cshtml new file mode 100644 index 0000000000..a5f10045db --- /dev/null +++ b/test/WebSites/FSharpWebSite/Views/_ViewStart.cshtml @@ -0,0 +1,3 @@ +@{ + Layout = "_Layout"; +}