protected override bool DoMatch(NUnitCtr.Constraint ctr) { IResolveConstraint exp = ctr; var multipleConstraint = exp.Resolve(); return(multipleConstraint.Matches(actual)); }
protected virtual bool DoMatch(NUnitCtr.Constraint ctr, string caption) { IResolveConstraint exp = ctr; var multipleConstraint = exp.Resolve(); return(multipleConstraint.Matches(caption)); }
/// <summary> /// Build a collection of constraint (in fact one by expected item) /// Pay really attention that CollectionContainsConstraint is expecting one unique item! /// So if you cant to check for several items, you need to apply several Constraint (one by expected item) /// </summary> protected virtual void BuildInternalConstraint() { NUnitCtr.Constraint ctr = null; foreach (var item in Expected) { var localCtr = new NUnitCtr.CollectionContainsConstraint(StringComparerHelper.Build(item)); var usingCtr = localCtr.Using(Comparer); if (ctr != null) { ctr = new AndConstraint(ctr, usingCtr); } else { ctr = usingCtr; } } if (ctr == null) { ctr = new NUnitCtr.EmptyCollectionConstraint(); } IResolveConstraint exp = ctr; InternalConstraint = exp.Resolve(); }
/// <summary> /// Test whether the constraint is satisfied by a given value /// </summary> /// <param name="actual">The value to be tested</param> /// <returns>True for if the base constraint fails, false if it succeeds</returns> public override bool Matches(object actual) { this.actual = actual; if ( this.caseInsensitive ) baseConstraint = baseConstraint.IgnoreCase; return !baseConstraint.Matches(actual); }
private void InitializeMatching() { PreInitializeMatching(); internalConstraint = BuildInternalConstraint(); if (internalConstraint != null) { isInitialized = true; } }
/// <summary> /// Constructs an AttributeConstraint for a specified attriute /// Type and base constraint. /// </summary> /// <param name="type"></param> /// <param name="baseConstraint"></param> public AttributeConstraint(Type type, Constraint baseConstraint) : base( baseConstraint ) { this.expectedType = type; if (!typeof(Attribute).IsAssignableFrom(expectedType)) throw new ArgumentException(string.Format( "Type {0} is not an attribute", expectedType), "type"); }
/// <summary> /// Set all modifiers applied to the prefix into /// the base constraint before matching /// </summary> protected void PassModifiersToBase() { if ( this.caseInsensitive ) baseConstraint = baseConstraint.IgnoreCase; if ( this.tolerance != null ) baseConstraint = baseConstraint.Within( tolerance ); if ( this.compareAsCollection ) baseConstraint = baseConstraint.AsCollection; if ( this.compareWith != null ) baseConstraint = baseConstraint.Comparer( compareWith ); }
protected override bool DoMatch(NUnitCtr.Constraint ctr) { if (specific == null) { return(ctr.Matches(actual)); } else { return(SpecificMatches(actual)); } }
/// <summary> /// Apply the item constraint to each item in the collection, /// failing if any item fails. /// </summary> /// <param name="actual"></param> /// <returns></returns> public override bool Matches(object actual) { this.actual = actual; if ( actual == null || !(actual is ICollection) ) return false; if ( this.caseInsensitive ) itemConstraint = itemConstraint.IgnoreCase; foreach(object item in (ICollection)actual) if (!itemConstraint.Matches(item)) return false; return true; }
//public virtual void ExecuteTest(string testSuiteXml) //{ // Trace.WriteLineIf(Extensibility.NBiTraceSwitch.TraceInfo, testSuiteXml); // byte[] byteArray = Encoding.ASCII.GetBytes(testSuiteXml); // var stream = new MemoryStream(byteArray); // var sr = new StreamReader(stream); // TestSuiteManager.Read(sr); // foreach (var test in TestSuiteManager.TestSuite.Tests) // ExecuteTestCases(test); //} /// <summary> /// Handles the standard assertion and if needed rethrow a new AssertionException with a modified stacktrace /// </summary> /// <param name="systemUnderTest"></param> /// <param name="constraint"></param> protected internal void AssertTestCase(Object systemUnderTest, NUnitCtr.Constraint constraint, string stackTrace) { try { Assert.That(systemUnderTest, constraint); } catch (AssertionException ex) { throw new CustomStackTraceAssertionException(ex, stackTrace); } catch (NBiException ex) { throw new CustomStackTraceErrorException(ex, stackTrace); } }
protected virtual NUnitCtr.Constraint BuildInternalConstraint() { NUnitCtr.Constraint ctr = null; if (!string.IsNullOrEmpty(regex)) { if (ctr != null) { ctr = ctr.And.Matches(regex); } else { ctr = new NUnitCtr.RegexConstraint(regex); } } return(ctr); }
/// <summary> /// Create a new instance of a test case /// </summary> /// <param name="sutXml"></param> /// <param name="ctrXml"></param> /// <returns></returns> public TestCase Instantiate(AbstractSystemUnderTestXml sutXml, AbstractConstraintXml ctrXml) { if (sutXml == null) { throw new ArgumentNullException("sutXml"); } if (ctrXml == null) { throw new ArgumentNullException("ctrXml"); } ITestCaseBuilder builder = null; //Look for registration ... var registration = registrations.FirstOrDefault(reg => sutXml.GetType() == reg.SystemUnderTestType && ctrXml.GetType() == reg.ConstraintType); if (registration == null) { throw new ArgumentException(string.Format("'{0}' is not an expected type for a constraint with a system-under-test '{1}'.", ctrXml.GetType().Name, sutXml.GetType().Name)); } //Apply the chooser if needed if (registration.Builder == null) { registration.Chooser.Choose(sutXml, ctrXml); } //Get Builder and initiate it builder = registration.Builder; builder.Setup(sutXml, ctrXml, configuration, variables); //Build builder.Build(); NUnitCtr.Constraint ctr = builder.GetConstraint(); var sut = builder.GetSystemUnderTest(); //Apply negation if needed if (ctrXml.Not) { ctr = new NUnitCtr.NotConstraint(ctr); } return(new TestCase(sut, ctr)); }
protected override NUnitCtr.Constraint BuildInternalConstraint() { NUnitCtr.Constraint ctr = null; foreach (var item in ExpectedItems) { var localCtr = new NUnitCtr.CollectionContainsConstraint(StringComparerHelper.Build(item)); var usingCtr = localCtr.Using(Comparer); if (ctr != null) { ctr = new NUnitCtr.AndConstraint(ctr, usingCtr); } else { ctr = usingCtr; } } return(ctr); }
protected override NUnitCtr.Constraint BuildInternalConstraint() { NUnitCtr.Constraint ctr = null; if (exactly.HasValue) { if (ctr != null) { ctr = ctr.And.EqualTo(exactly.Value); } else { ctr = new NUnitCtr.EqualConstraint(exactly.Value); } } if (moreThan.HasValue) { if (ctr != null) { ctr = ctr.And.GreaterThan(moreThan.Value); } else { ctr = new NUnitCtr.GreaterThanConstraint(moreThan.Value); } } if (lessThan.HasValue) { if (ctr != null) { ctr = ctr.And.LessThan(lessThan.Value); } else { ctr = new NUnitCtr.LessThanConstraint(lessThan.Value); } } return(ctr); }
protected virtual NUnitCtr.Constraint BuildChildConstraint(AbstractComparerXml xml) { NUnitCtr.Constraint ctr = null; if (xml is LessThanXml) { if (((LessThanXml)xml).OrEqual) { ctr = new NUnitCtr.LessThanOrEqualConstraint(xml.Value); } else { ctr = new NUnitCtr.LessThanConstraint(xml.Value); } } else if (xml is MoreThanXml) { if (((MoreThanXml)xml).OrEqual) { ctr = new NUnitCtr.GreaterThanOrEqualConstraint(xml.Value); } else { ctr = new NUnitCtr.GreaterThanConstraint(xml.Value); } } else if (xml is EqualXml) { ctr = new NUnitCtr.EqualConstraint(xml.Value); } if (ctr == null) { throw new ArgumentException(); } return(ctr); }
/// <summary> /// Display Expected and Actual lines for a constraint. This /// is called by MessageWriter's default implementation of /// WriteMessageTo and provides the generic two-line display. /// </summary> /// <param name="constraint">The constraint that failed</param> public abstract void DisplayDifferences(Constraint constraint);
public virtual Constraint SetConstraint(Constraint constraint) { baseConstraint = constraint; return this; }
/// <summary> /// Abstract method that produces a constraint by applying /// the operator to its left and right constraint arguments. /// </summary> public abstract Constraint ApplyOperator(Constraint left, Constraint right);
/// <summary> /// Returns a constraint that will apply the argument /// to the members of a collection, succeeding if /// none of them succeed. /// </summary> public override Constraint ApplyPrefix(Constraint constraint) { return new NoItemConstraint(constraint); }
/// <summary> /// Returns the constraint created by applying this /// prefix to another constraint. /// </summary> /// <param name="constraint"></param> /// <returns></returns> public abstract Constraint ApplyPrefix(Constraint constraint);
/// <summary> /// Construct a SomeItemsConstraint on top of an existing constraint /// </summary> /// <param name="itemConstraint"></param> public NoItemConstraint(Constraint itemConstraint) : base( itemConstraint ) { }
/// <summary> /// Construct an AllItemsConstraint on top of an existing constraint /// </summary> /// <param name="itemConstraint"></param> public AllItemsConstraint(Constraint itemConstraint) : base( itemConstraint ) { this.DisplayName = "all"; }
/// <summary> /// Appends a constraint to the expression and returns that /// constraint, which is associated with the current state /// of the expression being built. /// </summary> public Constraint Append(Constraint constraint) { builder.Append(constraint); return constraint; }
protected override bool DoMatch(NUnitCtr.Constraint ctr) { throw new InvalidOperationException(); }
protected virtual NUnitCtr.Constraint BuildChildConstraint(AbstractComparerXml xml) { var value = xml.Value.Replace(" ", ""); object numericValue; try { if (value.EndsWith("%")) { numericValue = Decimal.Parse(xml.Value.Substring(0, xml.Value.Length - 1)) / new Decimal(100); } else { numericValue = Int32.Parse(xml.Value); } } catch (Exception ex) { var exception = new ArgumentException ( String.Format("The assertion row-count is expecting an integer or percentage value for comparison. The provided value '{0}' is not a integer or percentage value.", value) , ex ); throw exception; } NUnitCtr.Constraint ctr = null; if (xml is LessThanXml) { if (((LessThanXml)xml).OrEqual) { ctr = new NUnitCtr.LessThanOrEqualConstraint(numericValue); } else { ctr = new NUnitCtr.LessThanConstraint(numericValue); } } else if (xml is MoreThanXml) { if (((MoreThanXml)xml).OrEqual) { ctr = new NUnitCtr.GreaterThanOrEqualConstraint(numericValue); } else { ctr = new NUnitCtr.GreaterThanConstraint(numericValue); } } else if (xml is EqualXml) { ctr = new NUnitCtr.EqualConstraint(numericValue); } if (ctr == null) { throw new ArgumentException(); } return(ctr); }
public RowCountFilterPercentageConstraint(NUnitCtr.Constraint childConstraint, IResultSetFilter filter) : base(childConstraint, filter) { }
/// <summary> /// Construct a SomeItemsConstraint on top of an existing constraint /// </summary> /// <param name="itemConstraint"></param> public SomeItemsConstraint(Constraint itemConstraint) : base( itemConstraint ) { this.DisplayName = "some"; }
/// <summary> /// Construct given a base constraint /// </summary> /// <param name="resolvable"></param> protected PrefixConstraint(IResolveConstraint resolvable) : base(resolvable) { if ( resolvable != null ) this.baseConstraint = resolvable.Resolve(); }
public RowCountConstraint(NUnitCtr.Constraint childConstraint) { child = childConstraint; }
protected virtual bool DoMatch(NUnitCtr.Constraint ctr) { return(ctr.Matches(actual)); }
public RowCountFilterConstraint(NUnitCtr.Constraint childConstraint, IResultSetFilter filter) : base(childConstraint) { this.filter = filter; filterFunction = filter.Apply; }
/// <summary> /// Construct given a base constraint /// </summary> /// <param name="baseConstraint"></param> protected PrefixConstraint( Constraint baseConstraint ) { this.baseConstraint = baseConstraint; }
public ReusableConstraint(IResolveConstraint c) { this.constraint = c.Resolve(); }
/// <summary> /// Returns a constraint that will apply the argument /// to the members of a collection, succeeding if /// any of them succeed. /// </summary> public override Constraint ApplyPrefix(Constraint constraint) { return new SomeItemsConstraint(constraint); }
public void IsOrderedBy(IEnumerable collection, Constraint constraint) { Assert.That(collection, constraint); }
/// <summary> /// Returns a constraint that wraps its argument /// </summary> public override Constraint ApplyPrefix(Constraint constraint) { return constraint; }
/// <summary> /// Appends a constraint to the expression and returns that /// constraint, which is associated with the current state /// of the expression being built. Note that the constraint /// is not reduced at this time. For example, if there /// is a NotOperator on the stack we don't reduce and /// return a NotConstraint. The original constraint must /// be returned because it may support modifiers that /// are yet to be applied. /// </summary> public Constraint Append(Constraint constraint) { builder.Append(constraint); return(constraint); }
/// <summary> /// Apply the operator to produce an OrConstraint /// </summary> public override Constraint ApplyOperator(Constraint left, Constraint right) { return new OrConstraint(left, right); }
/// <summary> /// Create an OrConstraint from two other constraints /// </summary> /// <param name="left">The first constraint</param> /// <param name="right">The second constraint</param> public OrConstraint(Constraint left, Constraint right) : base(left, right) { }
private void InitializeMatching() { PreInitializeMatching(); internalConstraint = BuildInternalConstraint(); if (internalConstraint!=null) isInitialized = true; }
///<summary> /// Creates a new DelayedConstraint ///</summary> ///<param name="baseConstraint">The inner constraint two decorate</param> ///<param name="delayInMilliseconds">The time interval after which the match is performed</param> ///<exception cref="InvalidOperationException">If the value of <paramref name="delayInMilliseconds"/> is less than 0</exception> public DelayedConstraint(Constraint baseConstraint, int delayInMilliseconds) : this(baseConstraint, delayInMilliseconds, 0) { }
/// <summary> /// Initializes a new instance of the <see cref="T:ThrowsConstraint"/> class, /// using a constraint to be applied to the exception. /// </summary> /// <param name="baseConstraint">A constraint to apply to the caught exception.</param> public ThrowsConstraint(Constraint baseConstraint) : base(baseConstraint) { }
/// <summary> /// Returns a constraint that will apply the argument /// to the members of a collection, succeeding if /// none of them succeed. /// </summary> public override Constraint ApplyPrefix(Constraint constraint) { return new ExactCountConstraint(expectedCount, constraint); }
/// <summary> /// Construct a SomeItemsConstraint on top of an existing constraint /// </summary> /// <param name="itemConstraint"></param> public NoItemConstraint(Constraint itemConstraint) : base( itemConstraint ) { this.DisplayName = "none"; }
/// <summary> /// Construct an AllItemsConstraint on top of an existing constraint /// </summary> /// <param name="itemConstraint"></param> public AllItemsConstraint(Constraint itemConstraint) : base( itemConstraint ) { }
/// <summary> /// Initializes a new instance of the <see cref="T:NotConstraint"/> class. /// </summary> /// <param name="baseConstraint">The base constraint to be negated.</param> public NotConstraint(Constraint baseConstraint) : base( baseConstraint ) { }
/// <summary> /// Construct a SomeItemsConstraint on top of an existing constraint /// </summary> /// <param name="itemConstraint"></param> public SomeItemsConstraint(Constraint itemConstraint) : base( itemConstraint ) { }
/// <summary> /// Initializes a new instance of the <see cref="T:PropertyConstraint"/> class. /// </summary> /// <param name="name">The name.</param> /// <param name="baseConstraint">The constraint to apply to the property.</param> public PropertyConstraint( string name, Constraint baseConstraint ) : base( baseConstraint ) { this.name = name; }
public static void ShouldNot(this object o, Constraint constraint) { Assert.That(o, new NotOperator().ApplyPrefix(constraint)); }
/// <summary> /// Construct a BinaryOperation from two other constraints /// </summary> /// <param name="left">The first constraint</param> /// <param name="right">The second constraint</param> public BinaryOperation(Constraint left, Constraint right) { this.left = left; this.right = right; }