How to mock HttpClient in your .NET / C# unit tests

You have a class that depends on HttpClient (or IHttpClientFactory for that matter), and want to unit test that. Since you want a unit test and not an integration test, it should not call a real http endpoint. You decide to mock out your dependency on HttpClient, and soon thereafter you got stuck. After googling 'How to mock HttpClient' you landed on this post. So, how would you mock HttpClient for your unit tests?

I give you the short answer right away: Continue reading "How to mock HttpClient in your .NET / C# unit tests"

How to correctly normalize strings and how to compare them (in .NET)

As a developer, you sometimes have to correctly normalize strings. Be it to do quick case-insensitive lookups, or to compare stuff. The question is, what is considered a correct normalization for these use cases? This post uses C# for the sample code, but this topic applies to all languages and environments equally.
Continue reading "How to correctly normalize strings and how to compare them (in .NET)"