1 // ***********************************************************************
2 // Copyright (c) 2007 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.
24 #define NUNIT_FRAMEWORK
28 namespace NUnit.Framework.Constraints
31 /// OrConstraint succeeds if either member succeeds
33 public class OrConstraint : BinaryConstraint
36 /// Create an OrConstraint from two other constraints
38 /// <param name="left">The first constraint</param>
39 /// <param name="right">The second constraint</param>
40 public OrConstraint(IConstraint left, IConstraint right) : base(left, right) { }
43 /// Gets text describing a constraint
45 public override string Description
47 get { return Left.Description + " or " + Right.Description; }
51 /// Apply the member constraints to an actual value, succeeding
52 /// succeeding as soon as one of them succeeds.
54 /// <param name="actual">The actual value</param>
55 /// <returns>True if either constraint succeeded</returns>
56 public override ConstraintResult ApplyTo<TActual>(TActual actual)
58 bool hasSucceeded = Left.ApplyTo(actual).IsSuccess || Right.ApplyTo(actual).IsSuccess;
59 return new ConstraintResult(this, actual, hasSucceeded);