Learn how to apply TDD skills in your everyday .NET projects to produce robust software as well as utilize the power of TDD in C# to implement multiple useful features in your .NET projects
Key Features
- Build a full TDD-based app to help you practice real-world scenarios
- Get up and running with TDD quickly by using specific features of Visual Studio
- Know the challenges of rolling TDD into your organization and build a plan
Book Description
Test-driven development is a manifesto for incrementally adding features to a product but starting with the unit tests first. Today's project templates come with unit tests by default and implementing them has become an expectation. It's no surprise that TDD/unit tests are on most job specifications and are important ingredients of most interviews and coding challenges. Adopting TDD will enforce good design practices and expedite your journey toward becoming a better coding architect.
This book goes beyond the philosophical debates and focuses on familiarizing you with TDD in a real-world setting by using popular frameworks such as ASP.NET and Entity Framework. The book starts with the foundational elements, before showing you how to use Visual Studio 2022 to build a To-Do application. To mimic real-life, you'll be using EF, SQL Server, and Cosmos, and utilize patterns including repository, service, and mediator. As a result of learning from this book, you'll also become familiar with domain-driven design (DDD) and other software best practices including SOLID and FIRSTHAND.
By the end of this TDD book, you'll have become confident in championing a TDD implementation. You'll also be equipped with a business and technical case for rolling out TDD or unit testing to present to your management and colleagues.
What you will learn
- Write unit tests with xUnit and get to grips with dependency injection
- Implement test doubles and mocking with NSubstitute
- Use the TDD style for unit testing in conjunction with DDD and best practices
- Mix TDD with the ASP.NET API, Entity Framework, and databases
- Add the mediator design pattern and understand its effect on unit testing
- Explore continuous integration with GitHub and Azure DevOps
- Get introduced to advanced mocking scenarios and gain familiarity with Moq
Who This Book Is For
This book is for mid to senior-level .NET developers who are looking to utilize the potential of TDD to develop high-quality software. Basic knowledge of OOP and C# programming concepts is assumed but no knowledge of TDD or unit testing is expected. As the book provides in-depth coverage of all the concepts of TDD and unit testing, it acts as an excellent guide for developers who want to build a TDD-based application from scratch or developers planning to introduce unit testing into their organization.
Table of Contents
- Demonstrating TDD with a Hello World App
- Understanding Dependency Injection by Example
- Getting Started with Unit Testing
- Real Unit Testing with Test Doubles
- Test-Driven Development Explained
- The FIRSTHAND Guidelines of TDD
- A Pragmatic View of Domain-Driven Design
- Business Requirements and Infrastructure
- Option 1: Choosing Entity Framework and SQL Server
- Option 2: Choosing Repositories and Cosmos DB
- Cleaner Code with The Mediator Pattern
- Implementing Continuous Integration
- Dealing with Brownfield Projects
- The Intricacies of Rolling TDD Into Your Team
- Appendix: An Intro to Moq and MSTest
- Appendix 2: Advanced Mocking Scenarios - 10 pages