-
Notifications
You must be signed in to change notification settings - Fork 162
Unit Test your AuthP app
Jon P Smith edited this page Jan 3, 2023
·
4 revisions
If you want to unit test your application code, and that code relies on the AuthP features you have some options:
- Most services have an interface, so you can stub out the interface with your own code. This is the best way to unit test your application.
- You can use AuthP's
SetupForUnitTestingAsync
extension at the end of the configuration of an AuthP setup. This is much more complex, but you are now testing against the actual AuthP library.
Stubbing is a known approach, but if you really want to against the actual AuthP library, then read the following information.
You would create the same sort of setup as you have in your application, but with these differences:
- I suggest you use an in-memory database, i.e. use the
UsingInMemoryDatabase
extension method. - You might want to seed the AuthP's database with by using the Bulk Loading feature to quickly set up the AuthP parts of the application. Alternatively you could use the admin services after the setup.
- The last method in the setup of the AuthP code should be
SetupForUnitTestingAsync
. This will:- Build the
ServiceProvider
which contains all the AuthP's services (which is returned). - Then it creates the AuthP database using EF Core's
EnsureCreatedAsync
method. - It applied any Bulk Load methods to seed the AuthP's database.
- It returns the built
ServiceProvider
so that can access the services in the AuthP library.
- Build the
Look at the UnitTestExample for an example of using the SetupForUnitTestingAsync
method to set up AuthP for testing.
NOTE: Other unit tests in that folder have more complex unit tests - check them out if you need a deeper look inside your application using AuthP.
- Intro to multi-tenants (ASP.NET video)
- Articles in date order:
- 0. Improved Roles/Permissions
- 1. Setting up the database
- 2. Admin: adding users and tenants
- 3. Versioning your app
- 4. Hierarchical multi-tenant
- 5. Advanced technique with claims
- 6. Sharding multi-tenant setup
- 7. Three ways to add new users
- 8. The design of the sharding data
- 9. Down for maintenance article
- 10: Three ways to refresh claims
- 11. Features of Multilingual service
- 12. Custom databases - Part1
- Videos (old)
- Authentication explained
- Permissions explained
- Roles explained
- AuthUser explained
- Multi tenant explained
- Sharding explained
- How AuthP handles sharding
- How AuthP handles errors
- Languages & cultures explained
- JWT Token refresh explained
- Setup Permissions
- Setup Authentication
- Startup code
- Setup the custom database feature
- JWT Token configuration
- Multi tenant configuration
- Using Permissions
- Using JWT Tokens
- Creating a multi-tenant app
- Supporting multiple languages
- Unit Test your AuthP app