Re: Writing custom constraints

"Charlie Poole" <[email protected]> Wed, 20 Aug 2008 11:15:20 -0700
Newsgroups gmane.comp.windows.dotnet.nunit.user
Message-ID <003601c902f0$b7310720$6401a8c0@ferrari>
See http://nunit.org/index.php?p=customConstraints&r=2.4.8

It's very basic but intellisense and experimentation should
give you the rest.

Note that this allows writing a custom constraint only. You
could use it like
  Assert.That(x, new MyCustomConstraint());

Providing a fluent syntax layer on top of it is a different
matter. I wasn't even thinking of the syntax when I put in
the constraint model - although people tend to confuse them.

If you wanted to extend the syntax layer, here are a few
options: 
   
1. If you work exclusively in C# 3.0 use extension methods.

2. Create a static class that works like Is or Has, possibly
   inheriting from one of them as a base. In fact, by using
   your own namespace and fooling around with aliasing you
   can even give it the same name.

3. Use a base class and then you won't have to bother with
   extension methods. If you like it, you can inherit from
   AssertionHelper.

Whichever approach you take, the above will make your syntax
work on a standalone basis, but it won't work with NUnit's
prefixes like Not, All, Some. If you want those to work,
you need to extend ConstraintBuilder, but it may be more
work than you want to do to get NUnit to use your extension
rather than it's own ConstraintBuilder.

For 2.5, I'm working to make the syntax layer extensible
just like the constraints.

Charlie

> -----Original Message-----
> From: [email protected] 
> [mailto:[email protected]] On Behalf 
> Of Brad Stiles
> Sent: Wednesday, August 20, 2008 10:29 AM
> To: [email protected]
> Subject: [Nunit-users] Writing custom constraints
> 
> Charlie,
> 
> Are there any guidelines and examples for writing custom 
> constraints anywhere, or am I better off just looking at the 
> source code?
> 
> Brad 
> 
> 
> --------------------------------------------------------------
> -----------
> This SF.Net email is sponsored by the Moblin Your Move 
> Developer's challenge Build the coolest Linux based 
> applications with Moblin SDK & win great prizes Grand prize 
> is a trip for two to an Open Source event anywhere in the 
> world http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> Nunit-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/nunit-users
> 



-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/