Blog
Mert Özen's blog posts on software development, backend, frontend, and DevOps.
Clean Test Code: F.I.R.S.T., Readable Asserts and Test Data Builders
A clean test is fast, independent, repeatable, self-validating and timely (F.I.R.S.T.); the legacy OrderService tests break on Saturdays because of DateTime.Now and depending on run order because of the static Db. With TimeProvider and FakeTimeProvider, a test data builder, test names that read like sentences and asserts that state the reason when they fail, we turn the same rules into clean tests.
Liskov Substitution Principle: Behavioral Subtyping and NotSupportedException in .NET
LSP requires a subtype to satisfy not just the compiler but the base type's contract: preconditions aren't strengthened, postconditions aren't weakened, invariants and the history constraint are preserved. Three real violations in Bookstore's stock module, the NotSupportedException that T[] and ReadOnlyCollection throw from IList<T>.Add, capability queries with Stream.CanSeek, and verifying the contract against every implementation with an abstract xUnit test class.
Unit Testing in C#: xUnit, Theory/InlineData and Testable Code
The hidden dependencies behind a flaky test, an xUnit test project, Fact and Assert, Theory/InlineData/MemberData, taking time from outside with IClock, and pitfalls like decimal InlineData and async void.
Testing with EF Core: SQLite In-Memory and InMemory Provider Pitfalls
With real test output we see how the InMemory provider silently lets unique indexes, foreign keys and raw SQL slip through, and build realistic tests with SQLite in-memory. We cover the false green of asserting on the same context and the debate about abstracting DbContext, using the EF documentation's guidance.
Integration Testing an ASP.NET Core Web API: End-to-End Tests with WebApplicationFactory
We spin up an ASP.NET Core Web API in memory with WebApplicationFactory and test it at the HTTP level: public partial class Program, swapping the database for in-memory SQLite, Location and ProblemDetails tests, and test isolation.
Unit Testing an ASP.NET Core Web API: Service and Controller Tests with xUnit and Moq
Unit testing an ASP.NET Core Web API with xUnit and Moq: the right package versions for net6.0, AAA and naming, Setup and Verify, the Result/Value difference in ActionResult<T> tests, Theory, and a comparison with NSubstitute.