Create an anonymous delegate that calls the method you want
Create a lambda that does the same
It would be great if some VB experts chimed in here with the syntax!
Charlie
> --
> You received this message because you are subscribed to the Google Groups "NUnit-Discuss" group.
> To post to this group, send email to nunit-...@googlegroups.com.
> To unsubscribe from this group, send email to nunit-discus...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/nunit-discuss?hl=en.
>
>
I've only used Assert.Throws with *functions* that have parameters. If you
can make your sub a function, this may help:
Assert.Throws(Of Exception)(Function()
FunctionWithParameters(parameterValue))
I've only used subs *without* parameters:
Assert.Throws(GetType(Exception), AddressOf SubWithNoParameters)
But if you're using ,NET 4, this should also work:
Assert.Throws(Of Exception)(Sub() SubWithParameters(parameterValue))
Hope that helps even a little bit,
Yann
--------------------------------------------------
From: "authchir" <martin.d...@gmail.com>
Sent: Saturday, July 10, 2010 10:19 AM
To: "NUnit-Discuss" <nunit-...@googlegroups.com>
Subject: [nunit-discuss] Re: Using Assert.throws() in vb.net
The only way I can think of to do this would be to create a private function
in your test code that sets the property. Normally I wouldn't test
getters/setters, but I'm guessing you have some custom code in it.
'in your test method
Assert.Throws(Of Exception)(Function() SetCustomerID(100))
'somewhere in the test fixture
private function SetCustomerID(value as integer) as boolean
custumer.id = value
end function
But what I'd suggest you do is move the verification code out of the setter,
so it becomes testable & call it from the setter instead of having the code
in the setter itself.
Yann
--------------------------------------------------
From: "authchir" <martin.d...@gmail.com>
Sent: Saturday, July 10, 2010 11:52 PM
To: "NUnit-Discuss" <nunit-...@googlegroups.com>
Subject: [nunit-discuss] Re: Using Assert.throws() in vb.net
> Great, it works !!!