diff --git a/tests/Unit.Client/Remoting.fs b/tests/Unit.Client/Remoting.fs index a7f67d1c..01e196f7 100644 --- a/tests/Unit.Client/Remoting.fs +++ b/tests/Unit.Client/Remoting.fs @@ -152,14 +152,14 @@ let view model dispatch = cond model.error <| function | None -> empty | Some e -> p [] [textf "%A" e] - comp [ - attr.fragmentWith "Authorized" <| fun (context: AuthenticationState) -> - printfn "Rendering Authorized" - div [] [textf "You're authorized! Welcome %s" context.User.Identity.Name] - attr.fragmentWith "NotAuthorized" <| fun (_: AuthenticationState) -> - printfn "Rendering NotAuthorized" - div [] [text "You're not authorized :("] - ] [] + comp [] [ + comp [ + attr.fragmentWith "Authorized" <| fun (context: AuthenticationState) -> + div [] [textf "You're authorized! Welcome %s" context.User.Identity.Name] + attr.fragmentWith "NotAuthorized" <| fun (_: AuthenticationState) -> + div [] [text "You're not authorized :("] + ] [] + ] ] type Test() = diff --git a/tests/Unit.Client/Startup.fs b/tests/Unit.Client/Startup.fs index 64daafb9..b7215ea8 100644 --- a/tests/Unit.Client/Startup.fs +++ b/tests/Unit.Client/Startup.fs @@ -23,10 +23,21 @@ namespace Bolero.Tests.Client open System open System.Net.Http +open System.Security.Claims +open System.Threading.Tasks open Microsoft.AspNetCore.Components.WebAssembly.Hosting +open Microsoft.AspNetCore.Components.Authorization open Microsoft.Extensions.DependencyInjection open Bolero.Remoting.Client +type DummyAuthProvider() = + inherit AuthenticationStateProvider() + + override _.GetAuthenticationStateAsync() = + let identity = ClaimsIdentity([|Claim(ClaimTypes.Name, "loic")|], "Fake auth type") + let user = ClaimsPrincipal(identity) + Task.FromResult(AuthenticationState(user)) + module Program = [] let Main args = @@ -34,5 +45,7 @@ module Program = builder.RootComponents.Add("#app") builder.Services.AddRemoting() |> ignore builder.Services.AddSingleton(new HttpClient(BaseAddress = Uri(builder.HostEnvironment.BaseAddress))) |> ignore + builder.Services.AddScoped() |> ignore + builder.Services.AddAuthorizationCore() |> ignore builder.Build().RunAsync() |> ignore 0 diff --git a/tests/Unit.Client/paket.references b/tests/Unit.Client/paket.references index b274204a..cc002e98 100644 --- a/tests/Unit.Client/paket.references +++ b/tests/Unit.Client/paket.references @@ -1,4 +1,5 @@ Microsoft.AspNetCore.Components.WebAssembly.Build FSharp.Core Elmish -Microsoft.AspNetCore.Components.Authorization \ No newline at end of file +Microsoft.AspNetCore.Components.Authorization +Microsoft.AspNetCore.Components.WebAssembly.Authentication diff --git a/tests/Unit.Client/wwwroot/index.html b/tests/Unit.Client/wwwroot/index.html index a1871946..43554ca7 100644 --- a/tests/Unit.Client/wwwroot/index.html +++ b/tests/Unit.Client/wwwroot/index.html @@ -12,6 +12,7 @@ element.innerHTML = value; } + diff --git a/tests/Unit/Pages/_Host.cshtml b/tests/Unit/Pages/_Host.cshtml index a9d65e8b..0133b5f2 100644 --- a/tests/Unit/Pages/_Host.cshtml +++ b/tests/Unit/Pages/_Host.cshtml @@ -16,6 +16,7 @@ element.innerHTML = value; } +