I want to test that my method throws argument exception on bad input.

// Here's the method signature:
public void Fobnicate(Foo foo, Bar bar, Baz baz) { ... }

// Validate Foo
[Test, ExpectedException(typeof(ArgumentNullException))]
public void FobnicateThrowsOnNullFoo()
{
    dar.Fobnicate(null, bar, baz);
}

// Validate Bar
[Test, ExpectedException(typeof(ArgumentNullException))]
public void FobnicateThrowsOnNullBar()
{
    dar.Fobnicate(foo, null, baz);
}

// Validate Baz
[Test, ExpectedException(typeof(ArgumentNullException))]
public void FobnicateThrowsOnNullFoo()
{
    dar.Fobnicate(foo, bar, null);
}

Needless to say, that's pretty laborious just to test input. I spotted
MbUnit's [RowTest] attribute, and thought that would help. Then the
unit tests could become just 1 test:

[RowTest]
[Row(null, bar, baz, ExpectedException =
typeof(ArgumentNullException)]
[Row(foo, null, baz, ExpectedException =
typeof(ArgumentNullException)]
[Row(foo, bar, null, ExpectedException =
typeof(ArgumentNullException))]
public void FobnicateValidatesInput(Foo foo, Bar bar, Baz baz)
{
   dar.Fobnicate(foo, bar, baz);
}

That would be brilliant, but it doesn't work because the C# compiler
must know attribute values at compile time. :-(

Is there an elegant way to validate several arguments like this using
MbUnit?


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"MbUnit.User" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/MbUnitUser?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to