Exemplo n.º 1
0
        public void IfThenClauseNegated()
        {
            // Arrange
            var mockField   = new Mock <IField>().Object;
            var expr        = new FieldExpression(mockField);
            var pred        = new ConstantClause(expr, ComparisonOperator.GTE, DBValue.Create(100));
            var subseq      = new ConstantClause(expr, ComparisonOperator.LTE, DBValue.Create(200));
            var subseqNeg   = new ConstantClause(expr, ComparisonOperator.GT, DBValue.Create(200));
            var clause      = Clause.IfThen(pred, subseq).Negation();
            var mockBuilder = new Mock <IConstraintDeclBuilder>();

            // Sequence
            var sequence = mockBuilder.MakeSequence();

            sequence.Add(builder => builder.StartClause());
            sequence.Add(builder => builder.AddClause(subseqNeg.Matcher()));
            sequence.Add(builder => builder.And());
            sequence.Add(builder => builder.AddClause(pred.Matcher()));
            sequence.Add(builder => builder.EndClause());

            // Act
            var fields = clause.GetDependentFields();

            clause.AddDeclarationTo(mockBuilder.Object);

            // Assert
            fields.Should().BeEquivalentTo(new IField[] { mockField, mockField });
            sequence.VerifyCompleted();
            mockBuilder.VerifyNoOtherCalls();
        }
Exemplo n.º 2
0
        public void ConstantClauseNegated_NE()
        {
            // Arrange
            var mockField = new Mock <IField>();
            var expr      = new FieldExpression(mockField.Object);
            var op        = ComparisonOperator.NE;
            var value     = DBValue.Create(100);

            mockField.Setup(field => field.DataType).Returns(DBType.Int32);
            var clause      = new ConstantClause(expr, op, value);
            var mockBuilder = new Mock <IConstraintDeclBuilder>();

            // Act
            var negation = clause.Negation();

            negation.AddDeclarationTo(mockBuilder.Object);

            // Assert
            var expected = new ConstantClause(expr, ComparisonOperator.EQ, value);

            mockBuilder.Verify(builder => builder.AddClause(expected.Matcher()));
            mockBuilder.VerifyNoOtherCalls();
        }