-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
504 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
28 changes: 28 additions & 0 deletions
28
src/content/DotLiquid/tests/AppNamePlaceholder.Tests/AppNamePlaceholder.Tests.fsproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>netcoreapp2.0</TargetFramework> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.*" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.0.*" /> | ||
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="2.0.*" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="2.0.*" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="2.0.*" /> | ||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.0.*" /> | ||
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.0.*" /> | ||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.0.*" /> | ||
<PackageReference Include="xunit" Version="2.3.*" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.*" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="../../src/AppNamePlaceholder/AppNamePlaceholder.fsproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="Tests.fs" /> | ||
<Compile Include="Program.fs" /> | ||
</ItemGroup> | ||
</Project> |
2 changes: 2 additions & 0 deletions
2
src/content/DotLiquid/tests/AppNamePlaceholder.Tests/Program.fs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module Program | ||
let [<EntryPoint>] main _ = 0 |
87 changes: 87 additions & 0 deletions
87
src/content/DotLiquid/tests/AppNamePlaceholder.Tests/Tests.fs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
module Tests | ||
|
||
open System | ||
open System.IO | ||
open System.Net | ||
open System.Net.Http | ||
open Xunit | ||
open Microsoft.AspNetCore.Builder | ||
open Microsoft.AspNetCore.Hosting | ||
open Microsoft.AspNetCore.TestHost | ||
open Microsoft.Extensions.DependencyInjection | ||
|
||
// --------------------------------- | ||
// Helper functions (extend as you need) | ||
// --------------------------------- | ||
|
||
let createHost() = | ||
WebHostBuilder() | ||
.UseContentRoot(Directory.GetCurrentDirectory()) | ||
.Configure(Action<IApplicationBuilder> AppNamePlaceholder.App.configureApp) | ||
.ConfigureServices(Action<IServiceCollection> AppNamePlaceholder.App.configureServices) | ||
|
||
let runTask task = | ||
task | ||
|> Async.AwaitTask | ||
|> Async.RunSynchronously | ||
|
||
let httpGet (path : string) (client : HttpClient) = | ||
path | ||
|> client.GetAsync | ||
|> runTask | ||
|
||
let isStatus (code : HttpStatusCode) (response : HttpResponseMessage) = | ||
Assert.Equal(code, response.StatusCode) | ||
response | ||
|
||
let ensureSuccess (response : HttpResponseMessage) = | ||
if not response.IsSuccessStatusCode | ||
then response.Content.ReadAsStringAsync() |> runTask |> failwithf "%A" | ||
else response | ||
|
||
let readText (response : HttpResponseMessage) = | ||
response.Content.ReadAsStringAsync() | ||
|> runTask | ||
|
||
let shouldEqual expected actual = | ||
Assert.Equal(expected, actual) | ||
|
||
let shouldContain (expected : string) (actual : string) = | ||
Assert.True(actual.Contains expected) | ||
|
||
// --------------------------------- | ||
// Tests | ||
// --------------------------------- | ||
|
||
[<Fact>] | ||
let ``Route / returns "Hello world, from Giraffe!"`` () = | ||
use server = new TestServer(createHost()) | ||
use client = server.CreateClient() | ||
|
||
client | ||
|> httpGet "/" | ||
|> ensureSuccess | ||
|> readText | ||
|> shouldContain "Hello world, from Giraffe!" | ||
|
||
[<Fact>] | ||
let ``Route /hello/fooBar returns "Hello fooBar, from Giraffe!"`` () = | ||
use server = new TestServer(createHost()) | ||
use client = server.CreateClient() | ||
|
||
client | ||
|> httpGet "/hello/fooBar" | ||
|> ensureSuccess | ||
|> readText | ||
|> shouldContain "Hello fooBar, from Giraffe!" | ||
|
||
[<Fact>] | ||
let ``Route which doesn't exist returns 404 Page not found`` () = | ||
use server = new TestServer(createHost()) | ||
use client = server.CreateClient() | ||
|
||
client | ||
|> httpGet "/route/which/does/not/exist" | ||
|> isStatus HttpStatusCode.NotFound | ||
|> readText | ||
|> shouldEqual "Not Found" |
File renamed without changes.
File renamed without changes.
File renamed without changes.
28 changes: 28 additions & 0 deletions
28
src/content/Giraffe/tests/AppNamePlaceholder.Tests/AppNamePlaceholder.Tests.fsproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>netcoreapp2.0</TargetFramework> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.*" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.0.*" /> | ||
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="2.0.*" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="2.0.*" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="2.0.*" /> | ||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.0.*" /> | ||
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.0.*" /> | ||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.0.*" /> | ||
<PackageReference Include="xunit" Version="2.3.*" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.*" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="../../src/AppNamePlaceholder/AppNamePlaceholder.fsproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="Tests.fs" /> | ||
<Compile Include="Program.fs" /> | ||
</ItemGroup> | ||
</Project> |
2 changes: 2 additions & 0 deletions
2
src/content/Giraffe/tests/AppNamePlaceholder.Tests/Program.fs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module Program | ||
let [<EntryPoint>] main _ = 0 |
Oops, something went wrong.