.NET Testing Best Practices
summary
Sample ASP.NET Core IoT code gets unit tests added with XUnit and FluentAssertions and mocks supplied via Moq / NSubstitute and AutoMocker. Tests verify actuateLights scenarios (motion, time period, last‑motion) and lead to concrete changes: extract ITimePeriodHelper, replace singleton with constructor injection, introduce TimePeriod enum to turn a runtime magic‑string bug into a compile‑time error. CI runs dotnet test, publishes JUnit results via GitHub Actions, and the example suite ends up green.
AI-written summary · about
chapters (23)
- 0:00.NET testing intro
- 1:06Demo code access
- 2:30Speaker & community
- 3:14Light controller app
- 4:19New xUnit project
- 5:58Basic test with Fluent Assertions
- 9:32Run tests after build
- 9:52Light actuator tests
- 12:28Light control scenarios
- 15:40Arrange Act Assert pattern
- 18:10Making code testable
- 21:04Fixing Singleton for testing
- 23:55Mocking with Moq
- 25:45Motion detection tests
- 26:06Injecting time dependency
- 28:11DI in console app
- 30:18AutoMock for dependencies
- 32:07Mocking time & light switcher
- 35:20Light turn-off tests
- 37:11Debugging test failures
- 39:04Magic strings to enums
- 41:13GitHub Actions setup
- 42:19Publishing test results








