1
// ***********************************************************************
2
// Copyright (c) 2009 Charlie Poole
4
// Permission is hereby granted, free of charge, to any person obtaining
5
// a copy of this software and associated documentation files (the
6
// "Software"), to deal in the Software without restriction, including
7
// without limitation the rights to use, copy, modify, merge, publish,
8
// distribute, sublicense, and/or sell copies of the Software, and to
9
// permit persons to whom the Software is furnished to do so, subject to
10
// the following conditions:
12
// The above copyright notice and this permission notice shall be
13
// included in all copies or substantial portions of the Software.
15
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
// ***********************************************************************
25
using NUnit.Framework.Constraints;
27
namespace NUnit.Framework.Syntax
29
public class NotOperatorOverride : SyntaxTest
34
parseTree = "<not <null>>";
35
staticSyntax = !Is.Null;
36
inheritedSyntax = !Helper().Null;
37
builderSyntax = !Builder().Null;
41
public void NotOperatorCanApplyToResolvableConstraintExpression()
43
Assert.That(GetType(), !Has.Attribute(typeof(DescriptionAttribute)));
47
[TestFixture, Description("Test")]
48
public class AndOperatorOverride : SyntaxTest
53
parseTree = "<and <greaterthan 5> <lessthan 10>>";
54
staticSyntax = Is.GreaterThan(5) & Is.LessThan(10);
55
inheritedSyntax = Helper().GreaterThan(5) & Is.LessThan(10);
56
builderSyntax = Builder().GreaterThan(5) & Builder().LessThan(10);
60
public void AndOperatorCanCombineTwoResolvableConstraintExpressions()
62
Assert.That(GetType(), Has.Attribute(typeof(TestFixtureAttribute)) & Has.Attribute(typeof(DescriptionAttribute)));
66
public void AndOperatorCanCombineConstraintAndResolvableConstraintExpression()
68
Assert.That(GetType(), Is.EqualTo(typeof(AndOperatorOverride)) & Has.Attribute(typeof(DescriptionAttribute)));
72
public void AndOperatorCanCombineResolvableConstraintExpressionAndConstraint()
74
Assert.That(GetType(), Has.Attribute(typeof(DescriptionAttribute)) & Is.EqualTo(typeof(AndOperatorOverride)));
79
public class OrOperatorOverride : SyntaxTest
84
parseTree = "<or <lessthan 5> <greaterthan 10>>";
85
staticSyntax = Is.LessThan(5) | Is.GreaterThan(10);
86
inheritedSyntax = Helper().LessThan(5) | Is.GreaterThan(10);
87
builderSyntax = Builder().LessThan(5) | Is.GreaterThan(10);
91
public void OrOperatorCanCombineTwoResolvableConstraintExpressions()
93
Assert.That(GetType(), Has.Attribute(typeof(TestFixtureAttribute)) | Has.Attribute(typeof(TestCaseAttribute)));
97
public void OrOperatorCanCombineResolvableConstraintExpressionAndConstraint()
99
Assert.That(GetType(), Has.Attribute(typeof(TestFixtureAttribute)) | Is.EqualTo(7));
103
public void OrOperatorCanCombineConstraintAndResolvableConstraintExpression()
105
Assert.That(GetType(), Is.EqualTo(7) | Has.Attribute(typeof(TestFixtureAttribute)));
109
public class MixedOperatorOverrides
112
public void ComplexTests()
114
string expected = "<and <and <not <null>> <not <lessthan 5>>> <not <greaterthan 10>>>";
117
Is.Not.Null & Is.Not.LessThan(5) & Is.Not.GreaterThan(10);
118
Assert.That(c.ToString(), Is.EqualTo(expected).NoClip);
120
c = !Is.Null & !Is.LessThan(5) & !Is.GreaterThan(10);
121
Assert.That(c.ToString(), Is.EqualTo(expected).NoClip);
124
c = !x & !Is.LessThan(5) & !Is.GreaterThan(10);
125
Assert.That(c.ToString(), Is.EqualTo(expected).NoClip);