Educational project demonstrating unit testing fundamentals in C# using xUnit and Moq. Features a ConsoleCalculator class that depends on an IConsole abstraction rather than calling Console.WriteLine directly, enabling testability through dependency injection. The test project uses Moq with strict behavior to verify both return values and side effects.
Built on .NET Framework 4.6, this project demonstrates the Arrange-Act-Assert pattern, mock setup/verification, and how abstracting dependencies enables isolated unit testing. By injecting an IConsole interface, the calculator's logic can be tested without any console I/O, making the tests fast, deterministic, and reliable.
- .NET Framework 4.6
- Visual Studio
Open the solution in Visual Studio, build, then run tests via Test Explorer or dotnet test.
If you found this useful and you want to learn more about C#, .NET, and software engineering, subscribe to the free Dev Leader Weekly newsletter:
Subscribe to Dev Leader Weekly
- All Links
- Website - Dev Leader
- YouTube - Dev Leader
- YouTube - Dev Leader Path To Tech
- YouTube - Dev Leader Podcast
- YouTube - CodeCommute
- Newsletter - Dev Leader Weekly
- LinkedIn - Nick Cosentino
- GitHub - ncosentino
- Twitter/X - Dev Leader
- Threads - Dev Leader
- Bluesky - Dev Leader
- Mastodon - Dev Leader
- Facebook - Dev Leader
- TikTok - Dev Leader
- Twitch - Dev Leader
- Stack Overflow - Nick Cosentino
Powered by BrandGhost 👻