Initial Development #1
|
@ -13,7 +13,9 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Giraffe" Version="5.0.0" />
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.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" Version="2.4.1" />
|
||||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
@ -25,4 +27,8 @@
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Htmx\Giraffe.Htmx.fsproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
@ -1,8 +1,75 @@
|
||||||
module Tests
|
module Giraffe.Htmx.Tests
|
||||||
|
|
||||||
open System
|
open System
|
||||||
|
open Giraffe.Htmx
|
||||||
|
open Microsoft.AspNetCore.Http
|
||||||
|
open NSubstitute
|
||||||
open Xunit
|
open Xunit
|
||||||
|
|
||||||
[<Fact>]
|
/// Tests for the IHeaderDictionary extension properties
|
||||||
let ``My test`` () =
|
module IHeaderDictionaryExtensions =
|
||||||
Assert.True(true)
|
|
||||||
|
[<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
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user