Test-Driven Development with .NET 8+ & Visual Studio 2022
Course Syllabus
Benjamin Day Consulting, Inc.
17 Roberts St #2
Brookline, MA 02445
617-645-0188
https://benday.com
Course Overview
Unit testing enables you and your team to write high-quality software with fewer bugs. It also allows you to say with confidence when something in your code is working and – more importantly – know when it is not working. Test-Driven Development (TDD) is a methodology for writing software that ensures that your application and your application code are testable and tested from the very start.
This course gives students hands-on experience and knowledge for writing and maintaining applications using Test-Driven Development with modern .NET and Visual Studio 2022. Throughout the course we discuss the options, process, and motivations for unit testing and TDD and reemphasize these concepts using hands-on labs.
What You'll Learn
TDD Fundamentals & Methodology
- What is a unit test?
- What is Test-Driven Development (TDD)? Why is TDD important?
- The TDD process: Red-Green-Refactor cycle
- Common (bogus) excuses for NOT doing Unit Testing & TDD
- How do I sell my team on Unit Testing & TDD?
- Best practices for fixing bugs & defects using TDD
Unit Testing Frameworks & Tools
- xUnit.NET - Modern, extensible testing framework (primary focus)
- NUnit - Popular alternative testing framework
- MSTest - Microsoft's built-in testing framework
- Choosing the right framework for your project
- Test runners and Visual Studio 2022 integration
- Test discovery and execution
Creating and Writing Unit Tests
- Test structure: Arrange-Act-Assert pattern
- Naming conventions for tests and test classes
- Test categories and organization
- Parameterized tests and data-driven testing
- Testing edge cases and boundary conditions
- What is Code Coverage and why do I care?
Designing Applications for Testability
- SOLID Principles for testable design
- Single Responsibility Principle (SRP)
- Dependency Inversion Principle (DIP)
- Design Patterns for testability
- Repository pattern (persistence abstraction)
- Adapter pattern (object transformation)
- Strategy pattern (algorithm abstraction)
- Model-View-Controller (MVC) pattern
Testing Different Application Layers
ASP.NET Core Testing
- Testing controllers and Web API endpoints
- Testing views and Razor Pages
- Testing routing and URL generation
- Testing security logic and authorization
- Testing configuration and dependency injection
- Integration testing with
WebApplicationFactory
Database and Persistence Testing
- Testing Entity Framework Core
- Repository pattern implementation and testing
- In-memory databases for testing
- Test data management strategies
- Transaction handling in tests
Business Logic Testing
- Testing validation logic
- Testing calculation logic
- Testing service layer/use case patterns
- Testing domain models and business rules
Mocking and Test Doubles
- Fakes, Mocks, & Stubs - Understanding the differences
- Moq - Popular .NET mocking framework
- Using mocks to avoid "The Huge Integration Test" pitfall
- Dealing with databases and test data in unit tests
- Mocking web services, APIs, and external dependencies
- Mocking Entity Framework and database contexts
- Using mocks to reach hard-to-test scenarios
Advanced Testing Scenarios
- Testing user interfaces and UI logic
- Testing non-public methods (when appropriate)
- Strategies for unit testing legacy code
- Refactoring for testability
- Testing asynchronous code (
async
/await
) - Testing middleware and custom filters
Integration with DevOps
- Where does testing fit with DevOps pipelines?
- Automated testing in CI/CD workflows
- Test reporting and metrics
- Code coverage in build pipelines
- Quality gates and deployment decisions
Additional Testing Types
- Integration testing patterns
- Performance and load testing considerations
- End-to-end testing strategies
- API testing with ASP.NET Core
Lab Exercises
Throughout the course, students will work on hands-on exercises including:
- Writing your first unit tests using TDD
- Refactoring existing code for testability
- Testing ASP.NET Core controllers and services
- Implementing repository pattern with tests
- Creating comprehensive test suites
- Using mocks to isolate dependencies
- Measuring and improving code coverage
Prerequisites
- Basic understanding of C# and .NET development
- Familiarity with Visual Studio 2022
- Some experience with ASP.NET Core helpful but not required
- Basic understanding of object-oriented programming concepts
Course Details
Technologies: .NET 8+, Visual Studio 2022, xUnit.NET, Moq, Entity Framework Core
Programming Languages: Primarily C#
Duration: 2 days, 9am to 5pm
Format: Interactive lectures with extensive hands-on labs
Lab Machine Requirements
Operating System: Windows 10/11 or macOS (latest versions)
Memory: 8GB RAM minimum, 16GB recommended
Required Applications:
- Visual Studio 2022 (Community, Professional, or Enterprise)
- .NET 8+ SDK
- Modern web browser
- SQL Server LocalDB (included with Visual Studio)
Network Requirements: Internet connection for NuGet package restoration
Student Permissions: Administrative rights on laptop helpful for installing packages
Course Outcomes
Upon completion of this course, students will be able to:
- Apply Test-Driven Development methodology effectively
- Choose appropriate testing frameworks for their projects
- Design applications with testability as a primary concern
- Write comprehensive unit test suites
- Use mocking frameworks to isolate dependencies
- Test different layers of .NET applications
- Integrate testing practices into DevOps workflows
- Refactor legacy code for improved testability
- Measure and improve code coverage
Customization Options
This course can be customized for your organization's specific needs:
- Focus on specific testing frameworks (xUnit, NUnit, or MSTest)
- Emphasis on particular application types (Web API, Blazor, etc.)
- Integration with your existing DevOps tools and processes
- Legacy code testing strategies for your codebase
- Shortened format (1-1.5 days) or extended format (3 days)
- Advanced topics (performance testing, security testing)
Course content is regularly updated to reflect the latest .NET and Visual Studio capabilities, testing frameworks, and industry best practices.