Thursday, October 11, 2007

Debugging in VS2005 using NUnit

As I'm using NUnit more and more (i really started to fall in love with the whole unit-test concept), i find it sometimes useful to be able to debug while running the unit-test. Turns out to be quite easy. This is how it's done:
1) Put your unit-tests into separate project (I do that anyway to keep the NUnit out of "live" references) and compile it (make it either exe or dll, no difference).
2) Start NUnit, browse the compiled dll/exe (from step 1), select "File -> Save as" and save the nunit project. I typically save it in the project's root as "myproject.nunit".
3) Open the project's properties, "Debug" tab.
4) Set "Start Action" to "Start external program:" and browse the "nunit.exe" (e.g. c:\program files\nunit 2.4.1\bin\nunit.exe)
5) Set in the "Start Options" the "Command line arguments" to point to the nunit project you created in step 2. If you did the same as me, i.e. saved it in the project's root, the path should be something like "..\..\myproject.nunit"

And that's it! Just run the debug with F5 as usuall and it'll open NUNIT environment. Set break-points wherever you need in the code and run the appropriate test...

Monday, October 08, 2007

VS 2005 - error while loading form into designer

I get this error quite frequently:
One or more errors encountered while loading the designer. The errors are listed below. Some errors can be fixed by rebuilding your project, while others may require code changes. TypeLoad failure. Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.


Aparently, it's a problem in VS and there's a hotfix available for it. Restarting studio works as well, which is what I do.

Friday, October 05, 2007

Backup data using ROBOCOPY

Need to set up some way of making backups of data from my drive. There's a ROBOCOPY utility in the Win2003 Resource Kit which should do the trick. I found even Robocopy GUI, which generates the script for you. Once you have the CMD file, just put it into scheduler.

Thursday, October 04, 2007

Overriding operators in C#

In one of my projects, i thought i'd love to use operators like ==, !=, > and < style="color: rgb(51, 51, 255);font-size:85%;" > public static bool operator ==(BaseEventVO evt1, BaseEventVO evt2)
{
return (((object)evt1 == (object)evt2) || ((object)evt1 != null) && ((object)evt2 != null) && evt1.IdSeq == evt2.IdSeq && evt1.Year == evt2.Year);
}

public static bool operator !=(BaseEventVO evt1, BaseEventVO evt2)
{
return !(evt1 == evt2);
}

public static bool operator >(BaseEventVO evt1, BaseEventVO evt2)
{
return (evt1.Year > evt2.Year || (evt1.Year == evt2.Year && evt1.Day > evt2.Day));
}

public static bool operator <(BaseEventVO evt1, BaseEventVO evt2)
{
return (evt1.Year < evt2.Year || (evt1.Year == evt2.Year && evt1.Day < evt2.Day));
}


Notice the cast to "(object)evt1 != null" - it is necessary in order to prevent loopback - you can't do "evt1 != null" as it'd use the "!=" overridden operator, hence ending in effective infinite loop (until call-stack blows).

You may also want to override GetHashCode() to produce unique ID of the object - speeds up things very significantly when you do hashtable lookups.