Architecting an ASP.NET Core MVC Application for Unit Testability

Want to quickly and easily know if your app is working? You'll need automated tests. This course will show you how to architect an ASP.NET Core app so that you can write great automated unit tests.
Course info
Rating
(22)
Level
Advanced
Updated
Dec 31, 2018
Duration
5h 47m
Table of contents
Course Overview
What Should I Test?
Using Abstraction to Test the User Interface
Overthrowing the Tyranny of the Database with Repository and Adapter Patterns
Leveraging the Strategy Pattern to Encapsulate Business Logic
Invoking the Right Logic and Loading the Correct Page
Testing Security: Authorization & Policies
Testing Security: Custom Logic & Middleware
Validating Your Web API Service Code
Description
Course info
Rating
(22)
Level
Advanced
Updated
Dec 31, 2018
Duration
5h 47m
Description

You need unit tests if you want to know if your app is really and truly working. The problem is that it's not always easy to do. In this course, Architecting an ASP.NET Core MVC Application for Unit Testability, you will gain the ability to design your apps for testability. First, you will learn about the architectural design patterns that help make your application easy to test, refactor, and maintain. Next, you will discover how to apply these architectural design patterns in order to implement testable ASP.NET Model-View-Controller code and testable database code using Entity Framework Core. Finally, you will explore how to apply these design patterns to create testable security code, validation code, and Web API code. When you are finished with this course, you will have the skills and knowledge of software architecture and unit testing needed to design your ASP.NET Core apps for testability.

About the author
About the author

Benjamin Day is a consultant and trainer specializing in software development best practices using Microsoft-based technology. He is a Microsoft Visual Studio ALM MVP, a certified Scrum trainer via Scrum.org, and a speaker at conferences such as TechEd, DevTeach, and VSLive. He can be contacted via http://www.benday.com.

More from the author
More courses by Benjamin Day
Section Introduction Transcripts
Section Introduction Transcripts

Course Overview
(Music playing) Hey everyone, my name is Ben Day and welcome to my course, Architecting an ASP.NET Core MVC Application for Unit Testability. I'm a developer, trainer, coach, and I specialize in helping teams and companies get good at software delivery, whether that's helping them with scrum or software testing or software architecture, or just listening to them vent. It's all in the goal of helping them deliver great done working software. Which brings us to the topic of this course, Unit Testing in ASP.NET Core. So if you've watched my other courses on DevOps or Team Foundation Server, you might have noticed that there's kind of a big hole in them. I don't talk a lot about unit testing, although I always say that it's really important. It's essential for the success of projects, the maintenance of software, and for great automated DevOps pipelines. So while I've always said in my courses that unit testing is really important, I've never really showed you how to do it. Well, I'm finally doing it! And you can kind of think of this class as being the missing modules from all my other classes. So, unit tests. What are they? Unit tests are little chunks of code that exercise and validate chunks of code in your application. And while that sounds easy enough, when your application starts getting complicated, it oftentimes gets harder and harder and harder to write unit tests. This course is going to talk about how to design an ASP.NET Core MVC and Web API application for unit testability. Now, if you're not using .NET Core yet, don't despair, almost all the architectural techniques and designs I'm going to show in this course will work in regular .NET, too. Some of the things we're going to talk about, why unit test, and what should a unit test? How do you unit test the user interface? How do you unit test database code? What about unit testing validations and calculations, or testing security logic? We'll cover all that, and through it all, we're going to talk a lot about the design patterns you need in order to architect your application for testability and maintainability. By the end of this course, you'll know more than enough to architect and build a testable app using ASP.NET Core MVC and Web API. So, I hope you'll dive in on this course and learn to write great unit tests for your ASP.NET Core apps with my Architecting in ASP.NET Core MVC Application for Unit Testability course here at Pluralsight.

Using Abstraction to Test the User Interface
Hey everybody! This is the Using Abstraction to Test the User Interface module. Quick overview of this module, we're going to be talking about unit testing in ASP.NET MVC user interface. So, as you can probably guess, we're going to be talking about the Model-View-Controller pattern quite a bit. Towards the end of this module, we're going to dive into some dependency injection stuff, and unit testing using mocks, stubs, and fakes. So, first up, thinking about how to do UI unit testing.

Overthrowing the Tyranny of the Database with Repository and Adapter Patterns
Hey everybody, how's it going? This is the Overthrowing the Tyranny of the Database with the Repository and Adapter Patterns module. Whew! That is kind of a long title! Moving on. In this module, we're going to be talking about unit testing the database. Or, actually, as you're going to come to find out, we're going to be talking about how to find creative ways to not test the database. And we're going to do that by designing data access logic for testability, and we're going to use a repository pattern and the adapter pattern to do that. And eventually we're going to get to how do you do this with Entity Framework Core, because I'm going to assume that most of you are using Entity Framework Core. I'll also talk a little bit about ADO.NET and how to do testability in this repository adapter stuff with that, too. And then finally, I'm going to show you how to use an in-memory fake version of your repository to do some unit testing whenever you've got code that depends on your repositories. Basically, it's yet another way to try to break up your dependency on the database. So, first up, we're going to talk about why the database is 100% pure poison for unit testing, and what does this have to do with the 1986 movie Karate Kid Part II? Stay tuned for all that fun!

Leveraging the Strategy Pattern to Encapsulate Business Logic
Hey everybody, how's it going? This is the Leveraging the Strategy Pattern to Encapsulate Business Logic module. Quick overview of what we're going to talk about in this module. Guess what? We're talking about the strategy pattern. The strategy pattern is going to help us to encapsulate validation logic and calculation logic, so we'll talk about implementing both of those things with strategy. We're going to talk a lot about how ASP.NET Core does validation, and it does that using System.ComponentModel .DataAnnotations. So we'll talk about the stuff that's in that namespace, how to use it, and then also how to write your own validation logic that's custom, that fits in with data annotations. So first up, let's talk about validation in ASP.NET Core.

Invoking the Right Logic and Loading the Correct Page
Hey, everybody. This is the Invoking the Right Logic and loading the Correct Page module. In this module, we're going to talk about ASP.NET MVC routing. So we'll dive into how that works, we'll talk about what the default routes are, we'll talk about how you can create custom routes, and do that using route attributes, and then along the way, we're going to talk about why you would actually want to customize this stuff. This module's going to be a little bit different. We're not going to be talking about unit testing; we're going to be talking about integration testing because, well, we have to integrate with a lot of stuff in ASP.NET, and for this stuff to make sense, you actually have to have an integration test. So first up, let's do an overview of routing in ASP.NET.

Testing Security: Authorization & Policies
Hey everybody, this is the Testing Security: Authorization and Policies module. So this module is a two-part module. So in the first part of this module, we're going to start off with a security overview, talking about authentication versus authorization. We'll take a look a little bit about role- based security and claims-based security, then we'll dive into security in ASP.NET Core. So we'll spend a lot of time talking about the Authorize attribute, your options for role-based security, your options for policy-based security, and then a whole lot of demos. So first up, security overview.

Testing Security: Custom Logic & Middleware
Hey, everybody, this is the second Testing Security module, and this one is Custom Logic and ASP.NET Middleware. Quick overview of what we're going to talk about in this module. This module's going to be very demo heavy. So the first thing I'm going to do is show you how to use the strategy pattern to make and test authorization decisions. And the second thing we're going to do is talk about ASP.NET Core middleware and do some demos on how to use middleware to streamline some things you might want to do with claims-based security. So first up, using the strategy pattern to make authorization decisions.