Initial Development #1

Merged
danieljsummers merged 6 commits from init-dev into main 2021-11-02 23:07:16 +00:00
2 changed files with 77 additions and 4 deletions
Showing only changes of commit 9d97e1c7f2 - Show all commits

View File

@ -13,7 +13,9 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Giraffe" Version="5.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="NSubstitute" Version="4.2.2" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
@ -25,4 +27,8 @@
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Htmx\Giraffe.Htmx.fsproj" />
</ItemGroup>
</Project>

View File

@ -1,8 +1,75 @@
module Tests
module Giraffe.Htmx.Tests
open System
open Giraffe.Htmx
open Microsoft.AspNetCore.Http
open NSubstitute
open Xunit
[<Fact>]
let ``My test`` () =
Assert.True(true)
/// Tests for the IHeaderDictionary extension properties
module IHeaderDictionaryExtensions =
[<Fact>]
let ``HxBoosted succeeds when the header is not present`` () =
let ctx = Substitute.For<HttpContext> ()
ctx.Request.Headers.ReturnsForAnyArgs (HeaderDictionary ()) |> ignore
Option.isNone ctx.Request.Headers.HxBoosted |> Assert.True
[<Fact>]
let ``HxBoosted succeeds when the header is present and true`` () =
let ctx = Substitute.For<HttpContext> ()
let dic = HeaderDictionary ()
dic.Add ("HX-Boosted", "true")
ctx.Request.Headers.ReturnsForAnyArgs dic |> ignore
Option.isSome ctx.Request.Headers.HxBoosted |> Assert.True
Option.get ctx.Request.Headers.HxBoosted |> Assert.True
[<Fact>]
let ``HxBoosted succeeds when the header is present and false`` () =
let ctx = Substitute.For<HttpContext> ()
let dic = HeaderDictionary ()
dic.Add ("HX-Boosted", "false")
ctx.Request.Headers.ReturnsForAnyArgs dic |> ignore
Option.isSome ctx.Request.Headers.HxBoosted |> Assert.True
Option.get ctx.Request.Headers.HxBoosted |> Assert.False
[<Fact>]
let ``HxCurrentUrl succeeds when the header is not present`` () =
let ctx = Substitute.For<HttpContext> ()
ctx.Request.Headers.ReturnsForAnyArgs (HeaderDictionary ()) |> ignore
Option.isNone ctx.Request.Headers.HxCurrentUrl |> Assert.True
[<Fact>]
let ``HxCurrentUrl succeeds when the header is present`` () =
let ctx = Substitute.For<HttpContext> ()
let dic = HeaderDictionary ()
dic.Add ("HX-Current-URL", "http://localhost/test.htm")
ctx.Request.Headers.ReturnsForAnyArgs dic |> ignore
Option.isSome ctx.Request.Headers.HxCurrentUrl |> Assert.True
Assert.Equal (Uri "http://localhost/test.htm", Option.get ctx.Request.Headers.HxCurrentUrl)
[<Fact>]
let ``HxHistoryRestoreRequest succeeds when the header is not present`` () =
let ctx = Substitute.For<HttpContext> ()
ctx.Request.Headers.ReturnsForAnyArgs (HeaderDictionary ()) |> ignore
Option.isNone ctx.Request.Headers.HxHistoryRestoreRequest |> Assert.True
[<Fact>]
let ``HxHistoryRestoreRequest succeeds when the header is present and true`` () =
let ctx = Substitute.For<HttpContext> ()
let dic = HeaderDictionary ()
dic.Add ("HX-History-Restore-Request", "true")
ctx.Request.Headers.ReturnsForAnyArgs dic |> ignore
Option.isSome ctx.Request.Headers.HxHistoryRestoreRequest |> Assert.True
Option.get ctx.Request.Headers.HxHistoryRestoreRequest |> Assert.True
[<Fact>]
let ``HxHistoryRestoreRequest succeeds when the header is present and false`` () =
let ctx = Substitute.For<HttpContext> ()
let dic = HeaderDictionary ()
dic.Add ("HX-History-Restore-Request", "false")
ctx.Request.Headers.ReturnsForAnyArgs dic |> ignore
Option.isSome ctx.Request.Headers.HxHistoryRestoreRequest |> Assert.True
Option.get ctx.Request.Headers.HxHistoryRestoreRequest |> Assert.False