Add FSharpWebSite plus simple functional test against it (#6231)

This commit is contained in:
Steve Sanderson 2017-05-05 19:08:36 +01:00 committed by GitHub
parent 64ffcfaa89
commit a80594d706
11 changed files with 150 additions and 0 deletions

View File

@ -4,6 +4,8 @@
<BenchmarkDotNetVersion>0.10.3</BenchmarkDotNetVersion>
<CoreFxVersion>4.3.0</CoreFxVersion>
<DependencyModelVersion>2.0.0-*</DependencyModelVersion>
<FSharpCoreVersion>4.1.0</FSharpCoreVersion>
<FSharpNetSdkVersion>1.0.*</FSharpNetSdkVersion>
<InternalAspNetCoreSdkVersion>2.1.0-*</InternalAspNetCoreSdkVersion>
<JsonNetBsonVersion>1.0.1</JsonNetBsonVersion>
<MoqVersion>4.7.1</MoqVersion>

View File

@ -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<MvcTestFixture<FSharpWebSite.Startup>>
{
public FSharpWebSiteTest(MvcTestFixture<FSharpWebSite.Startup> 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("<h1>Hello from FSharpWebSite</h1>", responseBody);
}
}
}

View File

@ -31,6 +31,7 @@
<ProjectReference Include="..\WebSites\FilesWebSite\FilesWebSite.csproj" />
<ProjectReference Include="..\WebSites\FiltersWebSite\FiltersWebSite.csproj" />
<ProjectReference Include="..\WebSites\FormatterWebSite\FormatterWebSite.csproj" />
<ProjectReference Include="..\WebSites\FSharpWebSite\FSharpWebSite.fsproj" />
<ProjectReference Include="..\WebSites\HtmlGenerationWebSite\HtmlGenerationWebSite.csproj" />
<ProjectReference Include="..\Microsoft.AspNetCore.Mvc.TestCommon\Microsoft.AspNetCore.Mvc.TestCommon.csproj" />
<ProjectReference Include="..\..\samples\MvcSandbox\MvcSandbox.csproj" />
@ -45,6 +46,7 @@
<ProjectReference Include="..\WebSites\WebApiCompatShimWebSite\WebApiCompatShimWebSite.csproj" />
<ProjectReference Include="..\WebSites\XmlFormattersWebSite\XmlFormattersWebSite.csproj" />
<PackageReference Include="FSharp.Core" Version="$(FSharpCoreVersion)" />
<PackageReference Include="Microsoft.AspNetCore.ChunkingCookieManager.Sources" Version="$(AspNetCoreVersion)" PrivateAssets="All" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="$(AspNetCoreVersion)" />
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="$(AspNetCoreVersion)" />

View File

@ -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()

View File

@ -0,0 +1,37 @@
<Project Sdk="FSharp.NET.Sdk; Microsoft.NET.Sdk.Web">
<Import Project="..\..\..\build\dependencies.props" />
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<PropertyGroup>
<!--
Signing is normally configured in common.props, but we can't import that into an F# project
because Internal.AspNetCore.Sdk doesn't support it.
-->
<AssemblyOriginatorKeyFile>..\..\..\build\Key.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
<PublicSign Condition="'$(OS)' != 'Windows_NT'">true</PublicSign>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
</PropertyGroup>
<ItemGroup>
<Compile Include="Controllers\*.fs" />
<Compile Include="Startup.fs" />
<Compile Include="Program.fs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\Microsoft.AspNetCore.Mvc\Microsoft.AspNetCore.Mvc.csproj" />
<PackageReference Include="FSharp.Core" Version="$(FSharpCoreVersion)" />
<PackageReference Include="FSharp.NET.Sdk" Version="$(FSharpNetSdkVersion)" PrivateAssets="All" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="$(AspNetCoreVersion)" />
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="$(AspNetCoreVersion)" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="$(AspNetCoreVersion)" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="$(AspNetCoreVersion)" />
</ItemGroup>
</Project>

View File

@ -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 =
[<EntryPoint>]
let main args =
let host =
WebHostBuilder()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.UseKestrel()
.UseIISIntegration()
.Build()
host.Run()
0

View File

@ -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

View File

@ -0,0 +1,5 @@
@{
ViewData["Title"] = "Home Page";
}
<h1>Hello from FSharpWebSite</h1>

View File

@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<title>@ViewData["Title"] - FSharpWebSite</title>
</head>
<body>
@RenderBody()
</body>
</html>

View File

@ -0,0 +1 @@
@using FSharpWebSite

View File

@ -0,0 +1,3 @@
@{
Layout = "_Layout";
}