Saturday, September 19, 2015

Unit Testing with NDBUnit and Identity Column

NDBUnit offers a great way to test your database related functionalities. While performing automated unit testing with databases, libraries like NDBUnit are very handy and they do an amazing job.

If you would like to learn more about them and get started, do visit their GitHub page here -

In this article, I am specifically talking about a common use case where we need to test the database functionality for a table having identity set to true. In that case, you will need to turn it on in your setup method like this

INDbUnitTest dbUnitTest = new NDbUnit.Core.SqlClient.SqlDbUnitTest(connectionString);
In my case, even after doing this, it wasn't inserting identity and was always inserting -1 in the primary key column. After doing a lot of research, I realized that I had to explicitly set it up once again in the XSD as well. If you open your XSD in visual studio, locate the particular table and hit F4 (i.e. go to properties window), you should see all of the properties of that field. We are mainly interested in AutoIncrementSeed And AutoIncrementStep properties which should be set to same value as that of your database (typically 1). Ideally this value should get set automatically when you generate XSD, but it appears that in one of my table that wasn't happening which caused me to spend some time to get around this and finally found the solution as mentioned above.

Monday, April 22, 2013

ASP.Net MVC 3 jQuery Remote Validation - Some Gotchas

If you have a requirement where you need to validate few fields on the fly , like creating a unique username, you might find remote validation concept quite handy.

There is a good explanation (with example) here

There are several small issues you might run into when using Remote Validation concept in ASP.Net MVC3
1. Validator called twice
This generally happens if you have the script maintained at the page level and master (layout) page, then there is a chance that validation would be called twice. Remove the script reference from either of the places.
2. Validation happening on every keypress, but you would like to have it on blur (lost focus i.e.)
This can be handled by disabling the keyup for validator globally as shown below

$(document).ready(function () {
    $.validator.setDefaults({onkeyup: false})


Wednesday, July 11, 2012

Using Fiddler with soapUI

As developers, Fiddler is one tool which helps a lot when it comes to tricky requests, response. Similarly soapUI is an excellent tool which helps you work with service calls interactively. Recently I was facing an issue within a particular service call from soapUI and when I tried to findout the response from Fiddler, I was surprise that it was not captured at all (despite of being remote service).

The reason why it happens is that Fiddler by default listens port 8888 on (You can verify this using  Tools > Fiddler Options > Connections). When the requests are being made from browsers etc, then this gets used correctly. In case of soapUI this needs to be explicitly configured.

To configure it in soapUI, goto File Menu in soapUI and select Preferences. Then select "Proxy Settings" tab and on the right side, enter values as

PORT: 8888

And do select the "Enable proxy" checkbox. Apply and now re-run the request. Now onwards all requests from soapUI would be tracked appropriately in Fiddler as well.

Wednesday, March 2, 2011

Crystal Reports with Visual Studio

Recently I was trying to work with Crystal Reports for learning purpose and I have ran through couple of issues. Solutions to these issues were trivial but took good amount of time in research.

It goes without saying that you should have a valid installation of Visual Studio with crystal report basic and valid license on the server for running crystal reports.

Issue No. 1 - Can't see images for Crystal report viewer, or not able to use the export, print functionalities when deployed to another web server.

Solution : This happens because crystal repots viewer assumes a very specific directory structure for the images and scripts. If you are running IIS on your development machine, you can find the structure here "C:\inetpub\wwwroot\aspnet_client\System_Web\2_0_50727\CrystalReportWebFormViewer4"

Now all you have to do is that copy the content of this whole structure, right from aspnet_client to your webserver and create a virtual directory to point to this path. Even if you dont want to create a virtual directory or dont have access to do so, you can simply copy the full structure to the root of your webapp and that should do the magic.

If you are not using IIS and using a inbuilt webserver with Visual studio (cassini i.e.), still you will have this structure , only thing that in this case it would be available at C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\ASP.NETClientFiles