DEV Community

Introduction to ASP.NET Core Integration Testing

Kai Oswald on September 10, 2019

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...
Collapse
 
tomasmuzas profile image
Tomas Mūžas • Edited

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 :)

Collapse
 
kaos profile image
Kai Oswald

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:

CollectionAssert.AreEqual(expectedResponse, actualResponse);
Collapse
 
luridsnk profile image
Filippenko Kirill

Good post. But how would you test authorized endpoints?

Collapse
 
kaos profile image
Kai Oswald

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 the Authorization header on the client.

I'm planning on doing another post going into more detail.

Collapse
 
luridsnk profile image
Filippenko Kirill • Edited

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?

Thread Thread
 
kaos profile image
Kai Oswald