Using FakeHttpMessageHandler


HTTP calls are one of the most popular ways to do client-to-service or service-to-service communication these days. Most C# developers use HttpClient type to make http calls. Using HttpClient correctly, requires a good understanding on its internals, but for testing, this knowledge is unavoidable.

In this post, I will look into how the Goldlight.HttpClientTestSupport library can be used to help writing unit tests against code with HttpClient.

Why Testing?

Find out more

init-only properties

Init-only properties are a new addition to C# 9. The purpose of this blog post is to look into how it is represented in IL, as well to see how it behaves from IL verification's point of view.

What is an init-only property?

Properties, readonly properties and properties with private setter have been around for a while in C#. One use-case was still missing: setting properties with object initializers that are readonly. Previously these properties had to be read-write or values had to be passed through constructors, which involved writing a good set of constructors. The following code snippet shows an example of an init-only property. State class has a bool 'On' property, which is an init-only property.

var data = new State { On = true };

public class State
  public bool On { get; init; }

Find out more


JsonMergePatch library provides an implementation for json merge patch operations, detailed in RFC7396. The library uses C# source generators to generate the types required for serialization. The Http package provides extension methods for HTTP requests and responses, while the AspNetCore package provides an InputReader implementation.

Resources in REST are typically updated according to the CRUD operations: Create/Update, Read, Delete. JsonMergePatch library enables to use http PATCH method to create and update a resource. Using PATCH operation has several benefits over PUT and POST requests:

  • Patch can be used for both create and update operations.

  • Patch payloads for updates can be significantly smaller if majority of the members remain unchanged

  • Patch solves versioning issues: a new version (V2) of the resource may contain new members. With patch operation V1 clients remain compatible: if a new property is unknown for the client, it will not be sent; on the server side the operation still succeeds, while the new V2 properties are retained. Using PUT operation, the V2 property values would become discarded by a V1 client request.

Getting Started

Find out more

Code Highlight with Blazor

Previously I had a post on adding code highlight to Blazor websites. In this post I will improve the previous solution by using the Monaco Editor instead of the PrismJS library.

Syntax Highlight

Syntax highlight is used colorize the source code based on each word's category. For example, keywords can be one color or type names and variables can use another font color. In Blazor previously I have shown how PrismJS can be used to highlight source code. Another approach is to use Monaco Editor. Monaco Editor is a code editor that powers VS Code. It has tremendous amount of features, way more than required for code highlighting. Using it for code highlight might sound controversial, but it is the same component as used by one of the most used code editors, so it looks and feels familiar.

The Monaco Editor is a JavaScript based component, so it can be used through JavaScript interop within Blazor. Fortunately, there is already an existing Blazor interop version of Monaco Editor, BlazorMonaco. This version is a community based Blazor component, wrapping the Monaco Editor.

Find out more

What is my carbon footprint?


Global warming is an environmental issue ongoing in the past years. It is about the planet Earth heating up. One major cause of the warming is the greenhouse effect. Certain gases, such as CO2, keep the heat within the Earth atmosphere. These gases get into the air by burning fossil fuels such as coal, oil or natural gas. Fossil fuels contain a lot of carbon, which is when burnt, combines with oxygen to form carbon dioxide.

One of the main solutions to avoid global warming is to replace fossil fuel energy sources with renewables, such as wind, solar, hydropower etc. Another carbon free energy source is nuclear energy, which has a different set of challenges to solve.

To learn more about this visit this article by the National Geographic.

Find out more