From the course: Blazor: Getting Started
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Solution: Unit testing authorization - Blazor Tutorial
From the course: Blazor: Getting Started
Solution: Unit testing authorization
(upbeat electronic music) - [Rich] All right, I hope that you paused and took time to try this challenge out. Here's how I solved it. Your solution may be different. I started in the index page and added the NotAuthorized section here. This section has a nav link back to the login page. Let's look at the test. In the test project, I added a test to IndexPagesTests, and I called it IndexShowsSimpleHeaderWhenUnAuthorized. Then I called AddAuthenticationServices. I'll turn on word wrap to see the whole line, and you can see that I passed it a first authorization result of failed. I also added our MockNavigationManager since I have a nav link in the page now. On line 48, I changed Assert.Contains to Assert.DoesNotContain to know that the select a frequency text doesn't appear. Finally, to complete the test, I check that my login link appears on the page. This name doesn't quite match up with the fact that I'm testing for…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
Authentication in a Blazor application11m 4s
-
(Locked)
Authorization in a Blazor application9m 7s
-
(Locked)
Unit test authorization in a Blazor application4m 51s
-
(Locked)
Maintain state in Blazor WebAssembly11m 4s
-
(Locked)
Challenge: Unit testing authorization59s
-
(Locked)
Solution: Unit testing authorization1m 28s
-
-
-
-