Summary description for PropertyConstraint.
Inheritance: NUnit.Framework.Constraints.Constraint
Exemplo n.º 1
0
        /// <summary>
        /// Resolve a constraint that has been recognized by applying
        /// any pending operators and returning the resulting Constraint.
        /// </summary>
        /// <returns>A constraint that incorporates all pending operators</returns>
        private Constraint Resolve(Constraint constraint)
        {
            while (ops.Count > 0)
            {
                switch ((Op)ops.Pop())
                {
                case Op.Not:
                    constraint = new NotConstraint(constraint);
                    break;

                case Op.All:
                    constraint = new AllItemsConstraint(constraint);
                    break;

                case Op.Some:
                    constraint = new SomeItemsConstraint(constraint);
                    break;

                case Op.None:
                    constraint = new NoItemConstraint(constraint);
                    break;

#if NOT_PFX
                case Op.Prop:
                    constraint = new PropertyConstraint((string)opnds.Pop(), constraint);
                    break;
#endif
                }
            }

            return(constraint);
        }
Exemplo n.º 2
0
        public void PropertyEqualToValueWithTolerance()
        {
            Constraint c = new EqualConstraint(105m).Within(0.1m);

            Assert.That(c.Description, Is.EqualTo("105m +/- 0.1m"));

            c = new PropertyConstraint("D", new EqualConstraint(105m).Within(0.1m));
            Assert.That(c.Description, Is.EqualTo("property D equal to 105m +/- 0.1m"));
        }
Exemplo n.º 3
0
        public void PropertyEqualToValueWithTolerance()
        {
            Constraint c = new EqualConstraint(105m).Within(0.1m);
            TextMessageWriter w = new TextMessageWriter();
            c.WriteDescriptionTo(w);
            Assert.That(w.ToString(), Is.EqualTo("105m +/- 0.1m"));

            c = new PropertyConstraint("D", new EqualConstraint(105m).Within(0.1m));
            w = new TextMessageWriter();
            c.WriteDescriptionTo(w);
            Assert.That(w.ToString(), Is.EqualTo("property D equal to 105m +/- 0.1m"));
        }
Exemplo n.º 4
0
        public void PropertyEqualToValueWithTolerance()
        {
            Constraint        c = new EqualConstraint(105m).Within(0.1m);
            TextMessageWriter w = new TextMessageWriter();

            c.WriteDescriptionTo(w);
            Assert.That(w.ToString(), Is.EqualTo("105m +/- 0.1m"));

            c = new PropertyConstraint("D", new EqualConstraint(105m).Within(0.1m));
            w = new TextMessageWriter();
            c.WriteDescriptionTo(w);
            Assert.That(w.ToString(), Is.EqualTo("property D equal to 105m +/- 0.1m"));
        }
Exemplo n.º 5
0
        public void PropertyDefinedInDerivedClass_ShouldExist()
        {
            var sut = new PropertyConstraint(nameof(Derived.SomeProperty), new EqualConstraint(42));

            var instance = (Base) new Derived();
            var actual   = sut.ApplyTo(instance);

            Assert.That(actual, Has.Property(nameof(ConstraintResult.Status)).EqualTo(ConstraintStatus.Success));


            var existSut    = new PropertyExistsConstraint(nameof(Derived.SomeProperty));
            var actualExist = existSut.ApplyTo(instance);

            Assert.That(actualExist.IsSuccess, Is.True);
        }
Exemplo n.º 6
0
 public void BeforeEveryTest()
 {
     _array = new[] { 1, 2, 3 };
     _countPropertyConstraint       = new PropertyConstraint(nameof(IList <object> .Count), new EqualConstraint(_array.Length));
     _countPropertyExistsConstraint = new PropertyExistsConstraint(nameof(IList <object> .Count));
 }
Exemplo n.º 7
0
 public void SetUp()
 {
     theConstraint        = new PropertyConstraint("Length", new EqualConstraint(5));
     expectedDescription  = "property Length equal to 5";
     stringRepresentation = "<property Length <equal 5>>";
 }
Exemplo n.º 8
0
        /// <summary>
        /// Resolve a constraint that has been recognized by applying
        /// any pending operators and returning the resulting Constraint.
        /// </summary>
        /// <returns>A constraint that incorporates all pending operators</returns>
        private Constraint Resolve(Constraint constraint)
        {
            while (ops.Count > 0)
                switch ((Op)ops.Pop())
                {
                    case Op.Not:
                        constraint = new NotConstraint(constraint);
                        break;
                    case Op.All:
                        constraint = new AllItemsConstraint(constraint);
                        break;
					case Op.Some:
						constraint = new SomeItemsConstraint(constraint);
						break;
					case Op.None:
						constraint = new NoItemConstraint(constraint);
						break;
					case Op.Prop:
						constraint = new PropertyConstraint( (string)opnds.Pop(), constraint );
						break;
                }

            return constraint;
        }
Exemplo n.º 9
0
        public void PropertyEqualToValueWithTolerance()
        {
            Constraint c = new EqualConstraint(105m).Within(0.1m);
            Assert.That(c.Description, Is.EqualTo("105m +/- 0.1m"));

            c = new PropertyConstraint("D", new EqualConstraint(105m).Within(0.1m));
            Assert.That(c.Description, Is.EqualTo("property D equal to 105m +/- 0.1m"));
        }
Exemplo n.º 10
0
 public void SetUp()
 {
     theConstraint = new PropertyConstraint("Length", new EqualConstraint(5));
     expectedDescription = "property Length equal to 5";
     stringRepresentation = "<property Length <equal 5>>";
 }
 public MyConstraintBuilder Property(String propertyName, Object propertyValue)
 {
     PropertyConstraint pc = new PropertyConstraint(propertyName, new MyEqualToConstraint(propertyValue));
     constraints.Push(pc);
     return this;
 }