1
// ****************************************************************
2
// Copyright 2012, Charlie Poole
3
// This is free software licensed under the NUnit license. You may
4
// obtain a copy of the license at http://nunit.org
5
// ****************************************************************
8
using NUnit.Framework.Constraints;
10
namespace NUnit.Framework.Syntax
13
public class ArbitraryConstraintMatching
15
Constraint custom = new CustomConstraint();
16
Constraint another = new AnotherConstraint();
19
public void CanMatchCustomConstraint()
21
IResolveConstraint constraint = new ConstraintExpression().Matches(custom);
22
Assert.That(constraint.Resolve().ToString(), Is.EqualTo("<custom>"));
26
public void CanMatchCustomConstraintAfterPrefix()
28
IResolveConstraint constraint = Is.All.Matches(custom);
29
Assert.That(constraint.Resolve().ToString(), Is.EqualTo("<all <custom>>"));
33
public void CanMatchCustomConstraintsUnderAndOperator()
35
IResolveConstraint constraint = Is.All.Matches(custom).And.Matches(another);
36
Assert.That(constraint.Resolve().ToString(), Is.EqualTo("<all <and <custom> <another>>>"));
39
#if CLR_2_0 || CLR_4_0
41
public void CanMatchPredicate()
43
IResolveConstraint constraint = new ConstraintExpression().Matches(new Predicate<int>(IsEven));
44
Assert.That(constraint.Resolve().ToString(), Is.EqualTo("<predicate>"));
45
Assert.That(42, constraint);
50
return (num & 1) == 0;
55
public void CanMatchLambda()
57
IResolveConstraint constraint = new ConstraintExpression().Matches<int>( (x) => (x & 1) == 0);
58
Assert.That(constraint.Resolve().ToString(), Is.EqualTo("<predicate>"));
59
Assert.That(42, constraint);
64
class CustomConstraint : Constraint
66
public override bool Matches(object actual)
68
throw new NotImplementedException();
71
public override void WriteDescriptionTo(MessageWriter writer)
73
throw new NotImplementedException();
77
class AnotherConstraint : CustomConstraint
1
// ****************************************************************
2
// Copyright 2012, Charlie Poole
3
// This is free software licensed under the NUnit license. You may
4
// obtain a copy of the license at http://nunit.org
5
// ****************************************************************
8
using NUnit.Framework.Constraints;
10
namespace NUnit.Framework.Syntax
13
public class ArbitraryConstraintMatching
15
Constraint custom = new CustomConstraint();
16
Constraint another = new AnotherConstraint();
19
public void CanMatchCustomConstraint()
21
IResolveConstraint constraint = new ConstraintExpression().Matches(custom);
22
Assert.That(constraint.Resolve().ToString(), Is.EqualTo("<custom>"));
26
public void CanMatchCustomConstraintAfterPrefix()
28
IResolveConstraint constraint = Is.All.Matches(custom);
29
Assert.That(constraint.Resolve().ToString(), Is.EqualTo("<all <custom>>"));
33
public void CanMatchCustomConstraintsUnderAndOperator()
35
IResolveConstraint constraint = Is.All.Matches(custom).And.Matches(another);
36
Assert.That(constraint.Resolve().ToString(), Is.EqualTo("<all <and <custom> <another>>>"));
39
#if CLR_2_0 || CLR_4_0
41
public void CanMatchPredicate()
43
IResolveConstraint constraint = new ConstraintExpression().Matches(new Predicate<int>(IsEven));
44
Assert.That(constraint.Resolve().ToString(), Is.EqualTo("<predicate>"));
45
Assert.That(42, constraint);
50
return (num & 1) == 0;
53
#if CS_3_0 || CS_4_0 || CS_5_0
55
public void CanMatchLambda()
57
IResolveConstraint constraint = new ConstraintExpression().Matches<int>( (x) => (x & 1) == 0);
58
Assert.That(constraint.Resolve().ToString(), Is.EqualTo("<predicate>"));
59
Assert.That(42, constraint);
64
class CustomConstraint : Constraint
66
public override bool Matches(object actual)
68
throw new NotImplementedException();
71
public override void WriteDescriptionTo(MessageWriter writer)
73
throw new NotImplementedException();
77
class AnotherConstraint : CustomConstraint