Unforutnately we're limited by the syntax here.
You can use a delegate referring to some other method.
However, you might also try using the [ExpectedException] attribute. I'm a
bit iffy on VB.Net syntax so here's what it would look like in C#.
[ExpectedException(typeof(MyException))]
public void MyTest()
{
// do something that should throw
}
Jeff.
-----Original Message-----
From: [email protected] [mailto:[email protected]] On
Behalf Of [email protected]
Sent: Friday, February 06, 2009 2:35 PM
To: MbUnit.User
Subject: MbUnit Re: Assert.Throws for VB.net
Can't you use a delegate? like, Assert.Throws(AddressOf MyThrowingMethod)?
On Feb 6, 5:48 pm, Dan Lash <[email protected]> wrote:
> Is there a way to use Assert.Throws in VB.net?
>
> All of the overloads for it take an Action (delegate) or lambda. The
> problem with VB is that lambda's
> 1) can only have one expression
> 2) must return a value
>
> So something as simple as:
> Assert.Throws(Of NullReferenceException)(Function() Console.WriteLine
> ("Doesn't Work In VB"))
>
> Gives this compile error:
> Expression does not produce a value.
>
> I guess an acceptable work around is to do the try/catching myself and
> Assert.Fail, but I like the syntax of Assert.Throws.
>
> Thanks,
>
> Dan Lash
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---