In this post I'll give you a quick introduction into how you can test your ASP.NET Core Controllers.
Please note that the term "Integration Testin...
For further actions, you may consider blocking this person and/or reporting abuse
Hey, nice post! Just my two cents, but I believe you can use
Assert.Equal
on collections as well, cleaning up quite a lot of code :)It doesn't, but there's a neat utility class for Collections called
CollectionAssert
which I just found that does that!So the code could be cut to:
Good post. But how would you test authorized endpoints?
This depends on the authorization methods used to protect those endpoints.
For example if you use JWT you could generate your token in the
TestInitialize
and set theAuthorization
header on the client.I'm planning on doing another post going into more detail.
Good point.
But if you're ought to create and API for SPA, you'd probably consider not only 'header' implementation.
For those reasons I personally prefer to send JWT in HttpOnly cookie. Could you please cover this case as well?
Just published the second post covering Cookie and JWT authentication!
ASP.NET Core Integration Testing: Protected endpoints
Kai Oswald ・ Oct 7 ・ 4 min read