~ubuntu-branches/ubuntu/utopic/monodevelop/utopic

« back to all changes in this revision

Viewing changes to external/guiunit/src/tests/Syntax/ArbitraryConstraintMatching.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-10-10 14:50:04 UTC
  • mfrom: (10.3.4)
  • Revision ID: package-import@ubuntu.com-20131010145004-80l130sny21b17sb
Tags: 4.0.12+dfsg-1
* [5dcb6e1] Fix debian/watch for new source tarball name format
* [5c68cb5] Refresh list of files removed by get-orig-source to 
  reflect 4.0.12
* [96d60a0] Imported Upstream version 4.0.12+dfsg
* [b989752] Refresh debian/patches/no_appmenu to ensure it applies
* [2a4c351] Ensure every assembly in external/ is cleaned properly
* [92762f7] Add more excluded Mac-specific modulerefs
* [bc698ba] Add symlinks to NUnit assemblies (Closes: #714246)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
// ****************************************************************
 
6
 
 
7
using System;
 
8
using NUnit.Framework.Constraints;
 
9
 
 
10
namespace NUnit.Framework.Syntax
 
11
{
 
12
    [TestFixture]
 
13
    public class ArbitraryConstraintMatching
 
14
    {
 
15
        Constraint custom = new CustomConstraint();
 
16
        Constraint another = new AnotherConstraint();
 
17
 
 
18
        [Test]
 
19
        public void CanMatchCustomConstraint()
 
20
        {
 
21
            IResolveConstraint constraint = new ConstraintExpression().Matches(custom);
 
22
            Assert.That(constraint.Resolve().ToString(), Is.EqualTo("<custom>"));
 
23
        }
 
24
 
 
25
        [Test]
 
26
        public void CanMatchCustomConstraintAfterPrefix()
 
27
        {
 
28
            IResolveConstraint constraint = Is.All.Matches(custom);
 
29
            Assert.That(constraint.Resolve().ToString(), Is.EqualTo("<all <custom>>"));
 
30
        }
 
31
 
 
32
        [Test]
 
33
        public void CanMatchCustomConstraintsUnderAndOperator()
 
34
        {
 
35
            IResolveConstraint constraint = Is.All.Matches(custom).And.Matches(another);
 
36
            Assert.That(constraint.Resolve().ToString(), Is.EqualTo("<all <and <custom> <another>>>"));
 
37
        }
 
38
 
 
39
#if CLR_2_0 || CLR_4_0
 
40
        [Test]
 
41
        public void CanMatchPredicate()
 
42
        {
 
43
            IResolveConstraint constraint = new ConstraintExpression().Matches(new Predicate<int>(IsEven));
 
44
            Assert.That(constraint.Resolve().ToString(), Is.EqualTo("<predicate>"));
 
45
            Assert.That(42, constraint);
 
46
        }
 
47
 
 
48
        bool IsEven(int num)
 
49
        {
 
50
            return (num & 1) == 0;
 
51
        }
 
52
 
 
53
#if !NETCF
 
54
        [Test]
 
55
        public void CanMatchLambda()
 
56
        {
 
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);
 
60
        }
 
61
#endif
 
62
#endif
 
63
 
 
64
        class CustomConstraint : Constraint
 
65
        {
 
66
            public override bool Matches(object actual)
 
67
            {
 
68
                throw new NotImplementedException();
 
69
            }
 
70
 
 
71
            public override void WriteDescriptionTo(MessageWriter writer)
 
72
            {
 
73
                throw new NotImplementedException();
 
74
            }
 
75
        }
 
76
 
 
77
        class AnotherConstraint : CustomConstraint
 
78
        {
 
79
        }
 
80
    }
 
81
}