Codementor Events

Unit Tests In ASP.NET Core Controllers - Matheus Rodrigues

Published Jun 18, 2018
Unit Tests In ASP.NET Core Controllers - Matheus Rodrigues

In this new series of posts, I want to show different aspects of testing an ASP.NET core application.

I will start in this post showing how to create unit tests for controllers. Then I am going to talk integration test in the controller and explore ASP.NET core new feature, Test Host. After that, let’s see how we can test our application business logic.

Moving to the database realm. I’m going to show how we can create unit tests for code that deals with DbContext, using Entity Framework Core In-memory database feature. And them, how to do integration tests with a real database, with strategies to maintain a database for integration tests.

Let’s jump right into it!

Project

The samples I’m going to show throughout this series are from a small project I create to experimenting with the new ASP.NET core features.

It is a to do list, where you can create many lists and create tasks in those lists.

Technologies / Frameworks In The Project

  • Visual Studio 2017 Community
  • ASP.NET Core 2.0
  • Entity Framework Core 2.0
  • LocalDB
  • xUnit
  • FluentAssertions
  • FakeItEasy

In this post, I’m not going to show every implementation detail, feel free to download/clone the repository.

You can download or clone the git repository here.

Continue Reading...

Discover and read more posts from Matheus Rodrigues
get started