AutoFixture – Make your tests slim and maintainable

Autofixture is an excellent library that can generate your tests data so as a developer you spent more time on what to test rather than how to setup data for tests. As you write less code to create the object you going to test so the code become more maintainable. For the example codes I am using following libraries:
1. XUnit – As unit testing framework
2. AutoFixture – A framework to generate test data
3. NSubstitute – A mocking library
4. Shouldly – A fluent assertion library.
Continue reading


Multilevel Caching using Bolt.Cache – InMemory and Redis

Caching is a very important part of scaling your website. In this blog post I am trying to show how you can implement a two level caching. One Redis for distributed caching and the other one is inmemory caching. So the idea is first you look whether data exists in memory. If not then check whether the data exists in Redis. If not then load from your Sql Data source. And then save this in memory and Redis. So for next request we can serve the data from memory, if not from Redis. Continue reading

Yet another validation library : Bolt.Validation

Validation is most common requirement for almost all applications. Asp.Net mvc and Web api using default attribute based model validation. Which is fine for most of the cases. But while developing web api I found that providing error code for each error is very useful for consumer. So the application that consuming my api, can change the workflow of UI based on type of error. Continue reading

End to End Testing of Web API 2 using OWIN and Specflow

One of the problem of end to end testing of Web API is that we need to deploy the API first and then run the tests. That means we are deploying without checking whether we did break something or not and find out the issue after deployment. To solve this problem a common practice is to setup the CI server (TeamCity / Jenkins etc) in a way so that the process deploy the API in an intermediate test server and then deploy to target server once tests passed in test server. Continue reading

Backendless development with AngularJs

Have you ever been in a situation where you start doing some front-end work but stuck because the webapi you need to finish this story is not ready yet. Lets see how you can continue front-end development without backend api. Suppose you start building front-end of an application where you need to display currently available books list. So you need an webapi that will return list of books and you then display them in html page using angularjs. The idea here is use $httpBackend to mock your $http / $resource request and return mock data. When the webapi is ready you just remove $httpBackend and all your code will work as it is. You sit with the developer who working on the api and decided the endpoint will be “/api/v1/books” and return type will be collection books. Lets start developing this. Continue reading

How to use Redis to build recently viewed items functionality

Its a very common feature, specially in eCommerce site to display a list of recently viewed items. The idea is the application keep track of a certain number of items user viewed and display them. This helps user to quickly view any items that he/she previously viewed without searching the store again.

Lets say we have to store maximum 5 recent items. So anytime user view details of an item then we need to save that item against user id and when we display the list of recently viewed items, that item should be at top. If a user view an item that he/she viewed before than instead of adding that item we need move the item to top. After adding an item we also need to check how many items added. If the maximum items per user reached then we need to remove the item that has been viewed by user least recently. You most probably don’t want to store those recent items forever. At the same time you don’t want  to expire them at any specific future time. The lifespan of users recent items needs to slide as the user browse. Continue reading