Judah,
I don't see a way that I particularly like. How about we make a new way?
[TestFixture]
public class ExampleTest
{
[ParameterProvider("ThisIsAKey")]
public Parameters[] MyParameters()
{
List<Parameters> ParametersList = new List<Parameters>();
ParametersList.Add(typeof(ArgumentNullException), null, bar, baz)
ParametersList.Add(typeof(ArgumentNullException), foo, null, baz)
ParametersList.Add(typeof(ArgumentNullException), foo, bar, null)
return ParametersList.ToArray();
}
[ParameterizedTest("ThisIsAKey")]
public void MyTest(Foo foo, Bar bar, Baz baz)
dar.Fobnicate(foo, bar, baz);
}
I am not very happy with the key part. What do you think?
Smiles,
Jay
On 5/8/07, Judah Himango <[EMAIL PROTECTED]> wrote:
>
>
> 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?
>
>
> >
>
--
Jay Flowers
----------------------------------------------------------------------
http://jayflowers.com
---------------------------------------------------------------------
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---