Cant create seed data for integrational tests
Hello evereybody. I've recently updated my projects with authentification. Before that, i managed users as simple database resource with simple CRUD operations. Now my AppUser inherits from IdentityUser. I also added a new endpoint for user registration. But now i need to update my integrational tests and im having problems with inserting seed data into test database. How to fix my WebApplicationFactory and Utilites classes to add/delete seede users to database?
9 Replies
Do you get an error? What's not working for you?
For example my test with get all users enpoint always returns 0 users while 3 is the expected result. I'm 100% sure the problem is that users seed data in not in the database when it' created (it returns users when i test it in swagger). So i cant really understand how to insert these example users in my test database. It works for projects and tasks (other resources), but my user model inherits from IdentityUser. Project link: https://github.com/skmkqw/ProjectManagementAPI/tree/Authentification
GitHub
GitHub - skmkqw/ProjectManagementAPI at Authentification
Contribute to skmkqw/ProjectManagementAPI development by creating an account on GitHub.
I can also pin test results if you want to
I don't quite remember it, but do you have to make a new migration for this?
Yes, i did one. Api is working good in practice
I'm not sure where the problem is: in configuring test database or in seeding data
hmm all I can think of now is that
Utilities.InitializeDatabase(dbContext, userManager);
is called inside the ConfigureTestServices
. Maybe you would want to do it after
not sure if the in memory db gets recreated or soim quite sure it's in the right place. At least all the other resources are working well
https://github.com/search?q=repo%3Adotnet%2FAspNetCore.Docs.Samples%20InitializeDbForTests&type=code you could check out this repo, they don't do seeding in the configure method
GitHub
Build software better, together
GitHub is where people build software. More than 100 million people use GitHub to discover, fork, and contribute to over 420 million projects.
I found the problem. The devil was in details) The is thing is by default Identity refuses to register users who dont have at least 1 uppercase letter in password. Changing "password123!" to "Password123!" made it work.