예제 #1
0
        protected override bool DoMatch(NUnitCtr.Constraint ctr)
        {
            IResolveConstraint exp = ctr;
            var multipleConstraint = exp.Resolve();

            return(multipleConstraint.Matches(actual));
        }
예제 #2
0
        protected virtual bool DoMatch(NUnitCtr.Constraint ctr, string caption)
        {
            IResolveConstraint exp = ctr;
            var multipleConstraint = exp.Resolve();

            return(multipleConstraint.Matches(caption));
        }
예제 #3
0
        /// <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();
        }
예제 #4
0
        /// <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);
        }
예제 #5
0
 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");
        }
예제 #7
0
		/// <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 );
		}
예제 #8
0
 protected override bool DoMatch(NUnitCtr.Constraint ctr)
 {
     if (specific == null)
     {
         return(ctr.Matches(actual));
     }
     else
     {
         return(SpecificMatches(actual));
     }
 }
예제 #9
0
        /// <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;
        }
예제 #10
0
파일: TestSuite.cs 프로젝트: jeason0813/NBi
        //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);
            }
        }
예제 #11
0
        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);
        }
예제 #12
0
        /// <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));
        }
예제 #13
0
        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);
        }
예제 #14
0
        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);
        }
예제 #15
0
        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);
        }
예제 #16
0
 /// <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);
예제 #17
0
 public virtual Constraint SetConstraint(Constraint constraint)
 {
     baseConstraint = constraint;
     return this;
 }
예제 #18
0
 /// <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);
예제 #19
0
 /// <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);
 }
예제 #20
0
 /// <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);
예제 #21
0
		/// <summary>
		/// Construct a SomeItemsConstraint on top of an existing constraint
		/// </summary>
		/// <param name="itemConstraint"></param>
		public NoItemConstraint(Constraint itemConstraint)
			: base( itemConstraint ) { }
예제 #22
0
		/// <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;
 }
예제 #24
0
 protected override bool DoMatch(NUnitCtr.Constraint ctr)
 {
     throw new InvalidOperationException();
 }
예제 #25
0
        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)
 {
 }
예제 #27
0
		/// <summary>
		/// Construct a SomeItemsConstraint on top of an existing constraint
		/// </summary>
		/// <param name="itemConstraint"></param>
		public SomeItemsConstraint(Constraint itemConstraint)
			: base( itemConstraint ) 
        {
            this.DisplayName = "some";
        }
예제 #28
0
 /// <summary>
 /// Construct given a base constraint
 /// </summary>
 /// <param name="resolvable"></param>
 protected PrefixConstraint(IResolveConstraint resolvable) : base(resolvable)
 {
     if ( resolvable != null )
         this.baseConstraint = resolvable.Resolve();
 }
예제 #29
0
 public RowCountConstraint(NUnitCtr.Constraint childConstraint)
 {
     child = childConstraint;
 }
예제 #30
0
 protected virtual bool DoMatch(NUnitCtr.Constraint ctr)
 {
     return(ctr.Matches(actual));
 }
예제 #31
0
 public RowCountFilterConstraint(NUnitCtr.Constraint childConstraint, IResultSetFilter filter)
     : base(childConstraint)
 {
     this.filter    = filter;
     filterFunction = filter.Apply;
 }
예제 #32
0
		/// <summary>
		/// Construct given a base constraint
		/// </summary>
		/// <param name="baseConstraint"></param>
		protected PrefixConstraint( Constraint baseConstraint )
		{
			this.baseConstraint = baseConstraint;
		}
예제 #33
0
 public ReusableConstraint(IResolveConstraint c)
 {
     this.constraint = c.Resolve();
 }
예제 #34
0
 /// <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);
 }
예제 #36
0
 /// <summary>
 /// Returns a constraint that wraps its argument
 /// </summary>
 public override Constraint ApplyPrefix(Constraint constraint)
 {
     return constraint;
 }
예제 #37
0
 /// <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);
 }
예제 #38
0
 /// <summary>
 /// Apply the operator to produce an OrConstraint
 /// </summary>
 public override Constraint ApplyOperator(Constraint left, Constraint right)
 {
     return new OrConstraint(left, right);
 }
예제 #39
0
 /// <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;
 }
예제 #41
0
 ///<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)
 {
 }
예제 #42
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) { }
예제 #43
0
 /// <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);
 }
예제 #44
0
		/// <summary>
		/// Construct a SomeItemsConstraint on top of an existing constraint
		/// </summary>
		/// <param name="itemConstraint"></param>
		public NoItemConstraint(Constraint itemConstraint)
			: base( itemConstraint ) 
        {
            this.DisplayName = "none";
        }
예제 #45
0
		/// <summary>
		/// Construct an AllItemsConstraint on top of an existing constraint
		/// </summary>
		/// <param name="itemConstraint"></param>
		public AllItemsConstraint(Constraint itemConstraint)
			: base( itemConstraint ) { }
예제 #46
0
		/// <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 ) { }
예제 #47
0
		/// <summary>
		/// Construct a SomeItemsConstraint on top of an existing constraint
		/// </summary>
		/// <param name="itemConstraint"></param>
		public SomeItemsConstraint(Constraint itemConstraint)
			: base( itemConstraint ) { }
예제 #48
0
        /// <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;
		}
예제 #49
0
 public static void ShouldNot(this object o, Constraint constraint)
 {
     Assert.That(o, new NotOperator().ApplyPrefix(constraint));
 }
예제 #50
0
 /// <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;
 }
예제 #51
0
 public void IsOrderedBy(IEnumerable collection, Constraint constraint)
 {
     Assert.That(collection, constraint);
 }