/// <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); }
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")); }
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")); }
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); }
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)); }
public void SetUp() { theConstraint = new PropertyConstraint("Length", new EqualConstraint(5)); expectedDescription = "property Length equal to 5"; stringRepresentation = "<property Length <equal 5>>"; }
/// <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; }
public MyConstraintBuilder Property(String propertyName, Object propertyValue) { PropertyConstraint pc = new PropertyConstraint(propertyName, new MyEqualToConstraint(propertyValue)); constraints.Push(pc); return this; }