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

Solution: Unit testing authorization - Blazor Tutorial

From the course: Blazor: Getting Started

Start my 1-month free trial

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…

Contents