~ubuntu-branches/debian/sid/nunit/sid

« back to all changes in this revision

Viewing changes to src/NUnitFramework/tests/Syntax/ArbitraryConstraintMatching.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2014-09-16 13:43:36 UTC
  • mfrom: (1.1.5)
  • Revision ID: package-import@ubuntu.com-20140916134336-kjxz48tty6lx2ja5
Tags: 2.6.3+dfsg-1
* [c7bd1b5] Imported Upstream version 2.6.3+dfsg
* [bcb4bf8] Move nunit-console-runner to GAC-installed libnunit2.6, 
  don't treat it as a private lib. This lib is signed, and treated 
  as a GAC lib by consumers such as MonoDevelop.
* [7f08e99] Bump version to 2.6.3 as required
* [84535eb] Refreshed patches
* [8479f61] Split package up into per-assembly packages. This makes 
  ABI tracking easier in the future, as we can meaningfully have GAC 
  policy for cases where ABI isn't truly bumped, and no policy for 
  cases where it is. For example, if nunit.framework bumps ABI but 
  nunit.core does not, previously we would need to rebuild everything 
  using NUnit, but under the new split packaging, that rebuild would 
  not be needed for apps only using nunit.core.
* [17a7dc7] Add missing nunit.mocks.dll to nunit.pc

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 CS_3_0 || CS_4_0
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
 
}
 
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 CS_3_0 || CS_4_0 || CS_5_0
 
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
}