Setup Load Testing in Visual Studio

Well most often MS doesn’t setup stuff .So you have to do it for yourself.Like for Load testing in VS test cases,
you have to configure the database “LoadTest2010” and the corresponding tables like LoadTestRun,LoadTestCase,…
Well this is how you can do it in case you stuck at it.

Browse to this folder and execute in command line else you can always run the script in Management Studio.

cd “C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE”

SQLCMD /S localhost\sqlserver -i loadtestresultsrepository.sql

Copying Directory or File in VSTS test cases

Well this one was pretty nasty I must admit.I didn’t know that I would lose some time on this one.And since I did I might as well blog about it.So here goes the problem statement.Have you faced the scenario wherein you had to copy some files under some folder in Unit tests in Visual Studio? This is because the test cases run under a folder called test results and each time you run it creates a new folder for that particular test case. Mind you before I start I must say that I have encountered this on the VS-2010 and not on the nascent versions of Visual Studio viz 2012.So here goes as to what you need to do to achieve the same.

1)First go the TestSettings file in VS 2010 which is directly under solution.
2)Go to Deployment section and check Enable deployment and add the directory that you want to add.

testsettings

3)Now is the trick part you have to edit the Test Settings file in Xml editor and go the tag under Deployment which has the required DeploymentItem and the attribute outputDirectory as follows.

deployment

4)Finally the worst part was now when you run the unit tests you will still now find it added.So to get it in working in VS 2010 you have to select the test list editor under the Test–>Windows menu in Visual Studio IDE.And then select your tests and hit run.Eureka… ooo still not there yet.The directory or file is still not out there!

5)Close your Visual Studio IDE and open it once again.(Age old trick works in the realm of WINDOWS).

So happy testing once again 🙂

XML Diff – Compare XML Tool

Well off late i have been having a torrid affair with XML as the data that flows across into my modules is xml. And so I had to do a series of tests on them to validate the modifications we were doing on the input xml. So hence started my hun t for xml related tool to compare two xmls .After searching for sometime i understood that the overwhelming favourite was XMLDiff.So here goes the simplest of all tools.All you need to do is

1)Download the tool from here.
2)Install the xmldiffpatch.exe
3) Go to $:\Program Files (x86)\XmlDiffPatch\Bin where you will find xmldiffpatch.dll
4)Include in your project as a assembly reference and you are ready to code.

A basic simple one that i used is the following overload of Compare in public bool Compare(XmlNode sourceNode, XmlNode changedNode) for the XmlDiff tool.The code for the same goes as follows.


string original =
@"SHERLOCK HOLMESCONAN DYLEWILEY";
String modified = @" CONAN DYLE WILEY SHERLOCK HOLMES ";
XmlDocument document = new XmlDocument();
document.LoadXml(modified);
XmlNode newNode = ((document).DocumentElement).ParentNode;

XmlDocument document1 = new XmlDocument();
document1.LoadXml(original);
XmlNode originalNode = ((document1).DocumentElement).ParentNode;

XmlDiff xmldiff = new XmlDiff(XmlDiffOptions.IgnoreChildOrder |XmlDiffOptions.IgnoreNamespaces |XmlDiffOptions.IgnorePrefixes);
bool bIdentical = xmldiff.Compare(originalNode, newNode);

As you can notice i have spaces in between tags and the ordering of the child elements is not correct ,but still they will compare and return TRUE.
There is another overload of Compare() method,which takes in two file locations.But i didnt like to pass ,paths of two different files as I thought it was cumbersome,hence i took the overload with XNode as parameters.
There are several other overloads to try out as well as Diffgram, the changes between two XML documents are described in a document called an XDL Diffgram. Yet to try that out but looks like lot of fun with Diffgram.

Run Unit Tests in Visual Studio after locally building your Solution !

Ever felt the need to run unit tests as a part of building your solution locally?Yeah,that sounds like you can do fix/break solution immediately 🙂 Ok,s before we jump to conclusions and go overboard, let us see how we can do this in VS2010.Like you would have already guessed there is an extension called “Continuous Testing for Visual Studio 2010“. Download it from here.Since its free and from Visual Studio Gallery ,I was tempted to install it.So just build it and saw that all my tests were failing as usual! Also in case you are pissed off that your test cases failed and dont want this feature you can always disable it from the Extension Manager from Tools Menu in Visual Studio.Here is the output post building locally,not great though 🙂

unittest

BTW i had read posts that you can execute MSTest.exe from build events using commands,but i was facing some issue with it .So do let me know if you work with that as well.Anyways Continous Testing works great.So let me build and break with more abandon!

DotNet Decompiler dotPeek

Ever since Reflector became paid from free, dotNet developers have been searching for a good alternative.They even said till version 6.0 the Reflector would still work,but for some reason it never used to for me,even if i would never upgrade my reflector.Anyways i found a good one called dotPeek from the JetBrains(yeah the same guys who have that wonder tool called ReSharper).You can download from here.And you can decompile from .NET versions 1 to 4.5 . Good luck reengineering !

Tip for the day!

I was recently working with xmls and xsd’s and came across this wonderful utility called XSD.exe.Using this you can create classes or xmls from schema’s and viceversa as well.Wonderful aint it?
Example
Generate classes from a given xsd

C:\classfiles>xsd “C:\SampleServices\Item\Lookup.xsd” /classes
For more info go to the path where xsd is(mine is C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools or C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\x64.This location is for VS2010 as you would have already presumed) in the command prompt is and hit

$:\xsd /h

And did you know you can even generate schema for a type from a dll or exe.. Cool eh?!

Metro vs Desktop

As i finally persuaded myself to take a shot at the latest OS in town primarily because of the huge discount that MS fished out to me for a win 8 pro upgrade from my all time fav win 7 and i happily took the bait.Here is the link for the same (http://windows.microsoft.com/en-in/windows/buy?ocid=GA8_O_MSCOM_Prog_FPP_Null_Null)

So there i was downloading the ISO at the very instant that i got a chance .Initially it would download the Win8 Upgrade Assistant and once you have finished reviewing it like this.

 

image

The assistant would also do a check whether the programs in the existing OS are compatible or not in the new Win 8 OS.

image

Once you have downloaded the ISO which has a size of approx 2.76 gigs,you are ready to go as you can either burn the it onto a drive or make a bootable Usb and install it .Please ensure that you have taken down the serial key before you move to other things.Obviously they would have mailed you the key as well,but keep it handy and safe.

There is a good article by Tim Fisher on how to clean install Win 8 which will pretty much cover everything you would ever want during installation.Here goes the link once again (http://pcsupport.about.com/od/windows-8/ss/windows-8-clean-install-part-1.htm) .And here is the part where he explains how to do it via USB. (http://pcsupport.about.com/od/windows-8/a/install-windows-8-usb.htm).

Once you land into the Win 8 world you will be taken aback initially by the Metro look but then you will feel back to Win 7 world when you hit Windows Key(this key acts as a switch between the 2 worlds).Never ever i have so often used this key as now.Its almost impossible to keep my hands of it as you would soon realise that nearly all the shortcuts are based on it.

Before we run and install the shortcuts,we will all feel the never ending urge to install all the required softwares and go to each of their sites and install .But do you remember them all?Don’t bother, following is the link from Scott Hanselman who has prepared a list of all the shortcuts in windows 8 here as well as a well written article on win 8 tricks.  (http://www.hanselman.com/blog/Windows8ProductivityWhoMovedMyCheeseOhThereItIs.aspx)

Also here is the list of most used software that we would ever need from Scott !(http://www.hanselman.com/blog/ScottHanselmans2011UltimateDeveloperAndPowerUsersToolListForWindows.aspx)

Finally to just let the whole thing start sinking i would leave you with a video from Scott on YouTube which would make you a lot more comfortable on the new OS.

 

My favorites in Windows 8 are hitting Win + PrintScreen and it goes directly into the picture folder as  a PNG.Also if you a dev guy you will find yourself hitting Win + X key a lot of times over the next few years!For people who hate finding the charms with your mouse hit Win + C.It is next to impossible not to love the new copy-paste mechanism built in .Did i mention the new Task Manager? Its a gem! And hitting del a file no longer asks you for confirmation ,unless you do shift +del.

Finally my two cents is Win 8 will not excite the enterprise market as the new OS is in neither land .Its not tablet nor desktop and this leaves a lot to be desired on a system which is not having touch screens.But then Windows were always like this.They were always the patches and fixes and bugs and SP1/SP2/SP3 guys.So they ended up having a OS which was a mix of everything.God forbid lest it become the next Vista!

Flashing Jelly Bean & ICS on HTC Desire

Ha.. finally I updated my good ‘ol HTC Desire A8181 to Jelly Bean.I don’t know how long it will suffer my testing though and how good the ROM from CyanogenMod 10 is.Anyways it was a very satisfying experience, as I always wanted to update the OS on my mobile as easily as I do on a desktop/laptop. But as I have short term memory loss problem ,let me try to recollect what I did in the first place Smile. Also before you go ahead, let me tell you the following are instructions only for HTC and their ROM’s and in some cases specific to HTC Desire.So others back off unless you want your phone bricked .But I presume most of the others have similar or close to same instructions.

First of all you need to have guts and not a mobile with a shade of pink..ok just kidding. Smile

Following are the prerequisites if you want to go ahead .

1)Creating backups of your existing data and please ensure your phone had enough charge left.

2) Install the HTC drivers for your phone.

3)Uninstall the HTC sync from your computer.

4)Set the enable USB debugging on your device.

5)Need to root your phone.How? Install unrEVOked3 recovery reflash tool from their site unrevoked.com .

.

image

6)Install ROM Manager from Play Store.

7) Select the option ClockwordMod Recovery from the ROM Manager.

8)Copy the ROM from http://d-h.st/Nax to your SD card.

9)Boot into recovery by pressing and holding down the Volume Down and Power buttons.

    Select recovery and select backup and recovery next.Select backup in the next screen.

10) Select wipe data/factory reset and confirm in the next screen.

11)Select install Zip from SD card  post step 10.Choose zip from sd card and select the cyanogenMod 10 ROM file by browsing to that path and select the file.

12) Go back after finishing installation and select reboot system now.

And there you go, you have the all new shiny JB on your device.

Mind you there are loads of tools and sdk’s from which you can explore more.There are sites like androidauthority and forum.xda-developers.com  ,which will help you find loads of ROMs and instructions.I must confess, I spent a few hours reading ’em before taking the plunge Smile.

image                  image                         image

Having installed it, I realised that the performance was not upto the mark, not to mention the various times it just crashed and restarted while opening media .Hence the desire to experiment with my desire, led to the installation of a lower OS, Ice Cream Sandwich.Having heard lots about a ROM called AOKP Milestone 6 (version 2) ,i decided to test drive it.But first, i wanted to check if my previous backup of Froyo was still existent.So I held the volume down and the power button and selected recovery and chose to install from the  previous backup .After some time i was in familiar territory.So I downloaded the new ROM ( http://www.mediafire.com/?5nzio781hub8533) and the corresponding google apps(http://goo.im/gapps/gapps-ics-20120429-signed.zip) and was ready for the next round of installation. All went smooth and I am very pleased with the new OS.Let me test it out further and will let you know in case of any issues.Till then i will enjoy my Ice Cream Sandwich 🙂

The Shift trick!

Though I am really ashamed of this late realization ,but till date I never knew how to run a command prompt to the present directory path. So for lesser mortals like me,this is how you do it. As simple as this.

All you need to do is press SHIFT while right clicking on a empty space in the window. And lo you have it ! You will get the option “Open command window hereSmile.

 

image

TimezoneInfo and DateTime

Until recently what used to be a headache for most of us is finally put out of misery by MS after framework 3.5.Yes there is code to finally get the datetime based on a given timezone and back as even i stumbled upon it a few months back. For eg if you have concerned about the various timezones and their datetimes in US which has several as follows.

//Eastern Standard Time (GMT-05:00) Eastern Time (US & Canada)
//Central Standard Time (GMT-06:00) Central Time (US & Canada)
//Mountain Standard Time (GMT-07:00) Mountain Time (US & Canada)
//Pacific Standard Time  (GMT-08:00) Pacific Time (US & Canada)
//Alaskan Standard Time (GMT-09:00) Alaska
//Hawaiian Standard Time (GMT-10:00) Hawaii
//US Mountain Standard Time (GMT-07:00) Arizona

you can infact convert a DateTime to any other datetime in the world by passing in the timezone they are located in and then you can convert them to UTC or to local and vice versa.Lots of interesting stuff that we can really make our hands dirty.All thanks to the new TimezoneInfo class that has been introduced.You can even get the TimeZoneInfo.BaseUtcOffset of a given location and then find out the difference between that place and local time or UTC for that matter.You can even add datetime offset to the UTC date and get the datetime of a given place.

Let look at an easy example of how we achieve this.

Code Snippet
  1. TimeZoneInfo timeZoneInfo;
  2. DateTime testdate = DateTime.Parse(“3/2/2011 1:00:00 AM”);
  3. DateTimeOffset offset;
  4. DateTime utcdate = testdate.ToUniversalTime();
  5. //Set the time zone information to US Mountain Standard Time -arizona
  6. timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(“US Mountain Standard Time”);
  7. //Get date and time in US Mountain Standard Time
  8. DateTime dateTime = TimeZoneInfo.ConvertTime(testdate, timeZoneInfo);
  9. //Print out the date and time
  10. Console.WriteLine(dateTime.ToString(“yyyy-MM-dd HH-mm-ss t\\M”));
  11. //Mountain Standard Time
  12. timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(“Mountain Standard Time”);
  13. //Get date and time in US Mountain Standard Time
  14. dateTime = TimeZoneInfo.ConvertTime(testdate, timeZoneInfo);
  15. ////Print out the date and time
  16. Console.WriteLine(dateTime.ToString(“yyyy-MM-dd HH-mm-ss t\\M”));
  17. //==============================================================================================
  18. //Set the time zone information to US Mountain Standard Time -est
  19. timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(“Eastern Standard Time”);
  20. //Get date and time in US Mountain Standard Time
  21. dateTime = TimeZoneInfo.ConvertTime(DateTime.Now, timeZoneInfo);
  22. //Print out the date and time
  23. Console.WriteLine(dateTime.ToString(“yyyy-MM-dd HH-mm-ss t\\M”));
  24. //================================================================================================
  25. //Set the time zone information to US Mountain Standard Time -cst
  26. timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(“Central Standard Time”);
  27. //Get date and time in US Mountain Standard Time
  28. dateTime = TimeZoneInfo.ConvertTime(DateTime.Now, timeZoneInfo);
  29. //Print out the date and time
  30. Console.WriteLine(dateTime.ToString(“yyyy-MM-dd HH-mm-ss t\\M”));
  31. //================================================================================================
  32. //Convert it back to UTC
  33. DateTime utcDateTime = dateTime.ToUniversalTime();
  34. //Print out the date and time
  35. Console.WriteLine(utcDateTime.ToString(“yyyy-MM-dd HH-mm-ss t\\M”));
  36. //==============================================================================================================================
  37. Datetime newOffsetDate = testdate.Add(timeZoneInfo.BaseUtcOffset);
  38. Console.WriteLine(utcDateTime.ToString(“yyyy-MM-dd HH-mm-ss t\\M”));

In case if you are wondering if there is support for DST,yes there is!I just made a sample app for you guys to play around and tinker with.(currently it has only US timezones) Click me to Download!

**Note—Always use UTC as the datetime to be stored in DB.