|
From: <joe...@us...> - 2003-01-21 17:36:04
|
Update of /cvsroot/nmock/nmock/test/NMock/Constraints
In directory sc8-pr-cvs1:/tmp/cvs-serv30252/test/NMock/Constraints
Modified Files:
ConstraintsTest.cs
Log Message:
Added PropertyIs decorator for constraints to allow a constraint to test the value of a property rather than the object itself.
Index: ConstraintsTest.cs
===================================================================
RCS file: /cvsroot/nmock/nmock/test/NMock/Constraints/ConstraintsTest.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** ConstraintsTest.cs 31 Dec 2002 21:36:40 -0000 1.2
--- ConstraintsTest.cs 21 Jan 2003 17:36:00 -0000 1.3
***************
*** 235,238 ****
--- 235,270 ----
[Test]
+ public void PropertyIs()
+ {
+ ThingWithProps t = new ThingWithProps();
+
+ // test property equals a value
+ Assertion.Assert(new PropertyIs("MyProp", "hello").Eval(t));
+ Assertion.Assert(!new PropertyIs("MyProp", "bye").Eval(t));
+
+ // test property using another constraint
+ Assertion.Assert(new PropertyIs("MyProp", new IsMatch("ell")).Eval(t));
+ Assertion.Assert(!new PropertyIs("MyProp", new IsMatch("sfsl")).Eval(t));
+
+ Assertion.AssertEquals(
+ "Property MyProp: <x>",
+ new PropertyIs("MyProp", new IsEqual("x")).Message);
+ }
+
+ [Test]
+ public void PropertyIsWithNullValue()
+ {
+ Assertion.Assert(!new PropertyIs("Blah", new IsAnything()).Eval(null));
+ }
+
+ class ThingWithProps
+ {
+ public string MyProp
+ {
+ get { return "hello"; }
+ }
+ }
+
+ [Test]
public void CollectingConstraint()
{
|