.NET Testing Best Practices
summary
Adds unit tests to an ASP.NET Core sample using xUnit, Moq (with auto-mocking) and FluentAssertions, refactors a static singleton into constructor-injected ILightSwitcher and extracts ITimePeriodHelper so tests can control time-of-day. Implements parameterized theories, debugs failing cases, fixes a bug caused by string time names by introducing a TimePeriod enum, gets 13 passing tests locally, and emits JUnit XML from dotnet test for GitHub Actions test reporting.
AI-written summary · about
chapters (24)
- 0:00Welcome to .NET testing
- 1:11Demo environment setup
- 2:32New xUnit test project
- 4:18First unit test with Fluent
- 7:52Arrange-act-assert pattern
- 8:14Motion detection testing
- 10:49xUnit theories for tests
- 12:36First test case
- 16:17Auto-run tests after build
- 18:02Debug failing tests
- 22:26Light switcher with mocks
- 25:39Extract time period logic
- 27:01Adding dependency injection to production code
- 29:16DI in tests with AutoFixture
- 34:39Debug tests for behavior
- 38:00Fixing bugs discovered through testing
- 39:26Refactor string enums
- 42:46Time edge case testing
- 43:28Time period tests
- 47:18Tests in DevOps pipeline
- 50:09GitHub Actions workflow
- 51:12Test reports generation
- 52:35CI pipeline results
- 53:40Add tests to projects








