Unit Testing of File uploading in MVC

Ways to write unit test code for File upload on Controllers:

For file upload related testing we need to Mock HTTPContext, HTTPContext.Server and HttpPostedFileBase. These classes handle the file uploading and saving.

We have to add a nugget package named Moq (https://www.nuget.org/packages/moq/) which will help us mocking the above classes. Moq source in Git: https://github.com/moq/moq4Read More »

Recursion with Common Table Expression in T-SQL

Generally for recursion we use Cursor in T-SQL. But Cursor is a kind of for loop which execute expression one by one until the end of the dataset or table or vew for which Cursor is defined. T-SQL is providing a different and unique technique called “Common Table Expression” or CTE which can do recursion by referencing itself.  As CTE can recurrently call itself with select statement depending on the type of join operation, it is a bulk operation for recursion which can make your select query operation incredibly faster.

Read More »

Create ASP.net control for Image resizer and cropper keeping aspect ratio

Published in CodeProject as well.

Overview

We had a long term problem about image resizing and cropping. Our problem was if we resize in server side, the image quality demolished and we can’t cropped according to aspect ratio as uploading image can be in any size and any dimension. For a B2B type of project , we faced it a lot as user of the website need to upload image, they are not resizing by themselves and uploading big images for their post which was making the site slow to load.
Finally, I make a control which forcefully resize the uploaded image into my required size keeping the correct ratio of the original image and it’s quality. After that, user has option to choose their cropping portion.

Read More »