ASP.NET Core – How to unit test an ApiController

The key to unit testing an ApiController class is to mock out all of its dependencies, including the controller’s HttpContext property, like this: If the controller method you’re testing uses anything from the HttpContext, then you’ll want to swap in your own value. Otherwise HttpContext will be null and you’ll get a NullReferenceException. Fortunately Microsoft … Read more

Adding your own feature flags in ASP.NET

In ASP.NET, you can add your own feature flags by using the feature management functionality. In this article, I’ll show how to configure and use feature management in ASP.NET and how to use this to feature gate an endpoint using your own feature flag. Configure feature management You need to do a few configuration steps … Read more