Tuesday, August 4, 2009

Testing Exceptions in Nunit 4.7

I am getting in TDD a lot, and of course, when thinking in border cases, you'll end up throwing exceptions, And you'd want to see ith they get thrown. With Nunit 4.7 the thing is that If, for example, you're testing that some parameter is null, when you decorate your test with [ExpectedException] it eventually gets thrown, but You'll never know what piece of code actually did it...
So, I created this little R# snippet to test excxeptions in a more granular way:
[Test]
public void $TestName$()
{
try
{
$Code$
}
catch (Exception e)
{
Assert.That(e, Is.TypeOf(typeof($ExpectedException$)));
$END$
}
Assert.Fail("Did Not Throw the Exception.");
}

For example, if you want to test if a parameter is null before you excercise some code, you could have a test like this:

[Test]
public void Intermediary_ParamOneCannotBeNull()
{
try
{
new Intermediary(null, null);
}
catch (Exception e)
{
Assert.That(e, Is.TypeOf(typeof(ArgumentNullException)));
Assert.That(((ArgumentNullException) e).ParamName, Is.EqualTo("paramOne"));
}
Assert.Fail("Did Not Throw the Exception.");
}

this code will not pass:

public Intermediary(IObject paramOne, IObject2 paramTwo
{
if (paramtwo == null)
throw new ArgumentNullException("company");
_one = paramOne
_two = paramTwo;
}

If you'd tested the code with ExpectedException, The code would had passed..

Of course, You could've used Nunit 5.0 ... :-)

Tuesday, June 9, 2009

Alt.NET in Colombia

I recently found @jorgegamba, which has been very active on VAN meetings for hispanic community.

He is also from Colombia and share the same interest on making Alt.Net widespread on Colombia.

He is trying to build a community for Colombian programmers who want to grow as agile .net programmers. I beleive is a very good initiative and I'm planning on supporting his idea any way possible.

Adelante Jorge!

Friday, May 1, 2009

Debugging Sharepoint Applications

When developing sharepoint apps, it becomes a pain in the neck to know what process to lint to (via debug-attach process) because it usually has many w3wp process running, and knowing which is the one you need is usually a trial-and-error thing.

Spence Harbar has a very handy application called Application Pool Manager which lets you do several things:

1. Reset application pools, which is faster than iisreset.
2. Show the list of application pools running
3. Establish which application pool has which process ID associated, and refresh it if someone else recycled them (i.e. VSeWSS)

This way, by just having a look at the tool's menu, you can know for sure what process ID you need to attach to!
There was an error in this gadget