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

Exception Handling in Web API (Part 1): Exception Filter

The Web World, especially Web Services is fast moving towards the more abstract simpler Web API. This article is not focused on comparing Web Service and Web API, but rather it focuses on Exception Handling in Web API. By default,  the most common exception that an API Controller raises are translated into an HTTP Status … Continue reading Exception Handling in Web API (Part 1): Exception Filter

Hello World in Ext JS and ASP.Net MVC4

Javascript based frameworks has been evolving of late and one of the prominent among them is External Javascript, better known as Ext JS. Unlike some of its competitors like Angular JS, Ext JS distinguishes itself with a rich suite of UI components. It is cross browser compatible. I am delving more into details of Ext … Continue reading Hello World in Ext JS and ASP.Net MVC4