From the course: Building and Securing RESTful APIs in ASP.NET Core

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Add a test user

Add a test user - ASP.NET Core Tutorial

From the course: Building and Securing RESTful APIs in ASP.NET Core

Start my 1-month free trial

Add a test user

- [Narrator] The C data class adds some test data to the in-memory database each time the application starts up. We can use this same approach to add some test users to the database. I'll add the new method at the bottom of the C data class. This'll be private static async task add test users. And this will accept a role manager, which we need to get from the identity name space. This takes user role entity. Call this role manager. And we'll also get a user manager. (typing) Now, as a first check, let's make sure that there isn't any data in the database. If there is then we aren't working with the in-memory database and something has changed. So let's say data exists equals role manager dot roles dot any, or user manager dot users any. If there is data for some reason, we're just gonna bail. If not, we'll do two things: we'll add a test role and a test user. (typing) Role manager dot create async, we'll create a role. We'll say new user role entity, call this role admin. Then we'll…

Contents