Re: Operator overloads for constraints

"Charlie Poole" <[email protected]> Tue, 10 Jun 2008 17:08:04 +0100
Newsgroups gmane.comp.windows.dotnet.nunit.devel
Message-ID <000501c8cb14$2eeb82f0$1400000a@ferrari>
Hi Stephen, 

I've experimented a bit with this sort of thing but without the
use of operator overloading. If you'd like to work on it, I'm 
all for it.

I think I would prefer not to put the method that creates a
value wrapper on Is, since all other methods of that class
create Constraints.

A further point would be that you can't return a Constraint
from the overloaded == operator. A Constraint represents
a test and it's associated parameters but not the actual
value to which it is applied. So you would be returning 
some object like ConstraintAppliedToActual - but hopefully
with a better name!

Charlie

Charlie
> -----Original Message-----
> From: [email protected] 
> [mailto:[email protected]] On 
> Behalf Of Stephen Boissiere
> Sent: Monday, June 09, 2008 5:19 PM
> To: [email protected]
> Subject: [nunit-developer] Operator overloads for constraints
> 
> Hi, I have a proposal for a possible improvement to nunit's 
> usage. I could implement this if there was a demand for it, 
> but wanted to know a) is it already there and b) is it worth it?
> 
> Basically if you have heard of LLBLGen Pro I was 'inspired' 
> by an idea from their code. It is a good ORM and I recommend 
> it. Anyway, the point is they allow you to build a query 
> using operator overloads e.g.
> 
> table.Fill ( MyTable.MyField == 23 );
> 
> this would fill a table with all rows where MyField == 23. 
> This is done by overloading operator == to return an object 
> instead of a bool. The new object describes the comparison.
> 
> For nunit I propose an optional syntax like:
> 
> Assert.That(Is.Value(2 + 2) == 4);
> 
> 'Value' is a proposed new static method. It would return a 
> new class (e.g. ValueWrapper) with overloaded operator == 
> which returns an 'EqualConstraint'. Something like:
> 
> class ValueWrapper
> {
>     ...
>     public static EqualConstraint operator == ( ValueWrapper 
> lhs, object rhs )
>     {
>         return new EqualConstraint ( lhs.InnerValue, rhs );
>     }
>     ...
> }
> 
> So - am I too late, or is it just not that good an idea?
> 
> Thanks,
> Stephen Boissiere
> 
> --------------------------------------------------------------
> -----------
> Check out the new SourceForge.net Marketplace.
> It's the best place to buy or sell services for just about 
> anything Open Source.
> http://sourceforge.net/services/buy/index.php
> _______________________________________________
> nunit-developer mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/nunit-developer
> 



-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php