Evil Code #12: Tuple Parameter – Overloads and Overrides

Tuples is an interesting subject to go back to due to certain peculiar qualities it possess. In this section, we would address some of them. To begin with, however, we will address how to tuples behave during method overloads - a pattern it share with rest of .Net. Consider the following code. public class Foo … Continue reading Evil Code #12: Tuple Parameter – Overloads and Overrides

A2Z.Net : A – Anonymous Types

This article marks the beginning of a new series of posts, which aims to dig deeper into 26 different features of .Net. For the first article, or the A - I have selected Anonymous Types. I would have chosen asynchronous programming, but I have whole dedicated series on asynchronous programming which could followed in this link. Introduced … Continue reading A2Z.Net : A – Anonymous Types

MemoryCache – AddOrGetExisting Method

MemoryCache provides an easy to use method AddOrGetExisting which provides an easy way to retrive or add data to cache. While it is extremely convenient, it comes off at a cost. Let's explore it a bit along with alternative. Note : For the sake of example, let us ignore multi-threading scenarios for the moment. public class MemoryCacheRunner { … Continue reading MemoryCache – AddOrGetExisting Method

Private Routes using VueJs

Quite often in your application, you could come across when certain pages/routes could be accessed by only authenticated users. And then there are other pages, which could be access be any one. I tend to call them by private routes and public routes. Private Routes requires a certain condition to be met, for example, the user needs to be authenticated. … Continue reading Private Routes using VueJs

Getting started with DocFx

I have been lately pretty impressed with the DocFx, Microsoft's static documentation generator. In this blog post, I thought I would outline how easy it is to configure the DocFx for generating documentation for your project. Assumption : Project already has Xml documentations enabled and the code have the necessary comments. Step 1 : Install … Continue reading Getting started with DocFx

Mocking User.Identity.Name

One of the other issue you might encounter while unit testing your Controller is when you dealing with Identity. Consider the following action method. public async Task<BarResponse> Foo(BarRequest user) { if (ModelState.IsValid) { try { var userName = User.Identity.Name; // Do Task return new BarResponse{ }; } catch (Exception ex) { return new BarResponse { … Continue reading Mocking User.Identity.Name

Writing Unit Test for Model Validation

It is a pretty common pattern to validate your Web Action model using ModelState.IsValid method. For example, public async Task<UpdateUserProfileResponse> UpdateUser(UpdateUserProfileRequest user) { if (ModelState.IsValid) { // Valid Model, do your job } else { // Send response indicating invalid model } } A pretty useful pattern, as it makes use of the DataAnnotations to validate and provide meaning … Continue reading Writing Unit Test for Model Validation

Github Actions : Building your first workflow

Github Actions allows to create custom workflows to automate our development processes. In this series, we will walkthrough the creation of a workflow of a Web API which was build using .Net Core. Do note that Github supports the developers using Custom templates, but since we are attempting to learng more on the Actions, let … Continue reading Github Actions : Building your first workflow