Skip to content

Commit

Permalink
Fix test for fragment attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
Tarmil committed May 19, 2020
1 parent 8fe003e commit cf7af92
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 9 deletions.
16 changes: 8 additions & 8 deletions tests/Unit.Client/Remoting.fs
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,14 @@ let view model dispatch =
cond model.error <| function
| None -> empty
| Some e -> p [] [textf "%A" e]
comp<AuthorizeView> [
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<CascadingAuthenticationState> [] [
comp<AuthorizeView> [
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() =
Expand Down
13 changes: 13 additions & 0 deletions tests/Unit.Client/Startup.fs
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,29 @@ 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 =
[<EntryPoint>]
let Main args =
let builder = WebAssemblyHostBuilder.CreateDefault(args)
builder.RootComponents.Add<Tests>("#app")
builder.Services.AddRemoting() |> ignore
builder.Services.AddSingleton(new HttpClient(BaseAddress = Uri(builder.HostEnvironment.BaseAddress))) |> ignore
builder.Services.AddScoped<AuthenticationStateProvider, DummyAuthProvider>() |> ignore
builder.Services.AddAuthorizationCore() |> ignore
builder.Build().RunAsync() |> ignore
0
3 changes: 2 additions & 1 deletion tests/Unit.Client/paket.references
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Microsoft.AspNetCore.Components.WebAssembly.Build
FSharp.Core
Elmish
Microsoft.AspNetCore.Components.Authorization
Microsoft.AspNetCore.Components.Authorization
Microsoft.AspNetCore.Components.WebAssembly.Authentication
1 change: 1 addition & 0 deletions tests/Unit.Client/wwwroot/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
element.innerHTML = value;
}
</script>
<script src="_content/Microsoft.AspNetCore.Components.WebAssembly.Authentication/AuthenticationService.js"></script>
<script src="_framework/blazor.webassembly.js"></script>
</body>
</html>
1 change: 1 addition & 0 deletions tests/Unit/Pages/_Host.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
element.innerHTML = value;
}
</script>
<script src="_content/Microsoft.AspNetCore.Components.WebAssembly.Authentication/AuthenticationService.js"></script>
<script src="_framework/blazor.server.js"></script>
</body>
</html>

0 comments on commit cf7af92

Please sign in to comment.