public void GivenAnExpressionOverLastUpdated_WhenTranslatedToResourceSurrogateId_HasCorrectRanges(BinaryOperator inputOperator, string inputDateTimeOffset, BinaryOperator expectedOperator, string expectedDateTimeOffset)
        {
            var input = new BinaryExpression(inputOperator, FieldName.DateTimeStart, null, DateTimeOffset.Parse(inputDateTimeOffset));

            var output = input.AcceptVisitor(LastUpdatedToResourceSurrogateIdRewriter.Instance, null);

            BinaryExpression binaryOutput = Assert.IsType <BinaryExpression>(output);

            Assert.Equal(SqlFieldName.ResourceSurrogateId, binaryOutput.FieldName);
            Assert.Equal(expectedOperator, binaryOutput.BinaryOperator);
            Assert.Equal(DateTimeOffset.Parse(expectedDateTimeOffset), ResourceSurrogateIdHelper.ResourceSurrogateIdToLastUpdated((long)binaryOutput.Value));
        }
        public void GivenAnExpressionWithIncludes_WhenVisitedByRemoveIncludesRewriter_IncludesAreRemoved()
        {
            IncludeExpression includeExpression = Expression.Include("a", new SearchParameterInfo("p", "Token"), "Patient", false);
            BinaryExpression  fieldExpression   = Expression.Equals(FieldName.Number, null, 1);

            Assert.Null(includeExpression.AcceptVisitor(RemoveIncludesRewriter.Instance));
            Assert.Null(Expression.And(includeExpression, includeExpression).AcceptVisitor(RemoveIncludesRewriter.Instance));

            Assert.Same(fieldExpression, fieldExpression.AcceptVisitor(RemoveIncludesRewriter.Instance));
            var andWithoutIncludes = Expression.And(fieldExpression, fieldExpression);

            Assert.Same(andWithoutIncludes, andWithoutIncludes.AcceptVisitor(RemoveIncludesRewriter.Instance));

            Assert.Same(fieldExpression, Expression.And(includeExpression, fieldExpression).AcceptVisitor(RemoveIncludesRewriter.Instance));
            Assert.Same(fieldExpression, Expression.And(fieldExpression, includeExpression).AcceptVisitor(RemoveIncludesRewriter.Instance));

            Assert.Equal(andWithoutIncludes.ToString(), Expression.And(includeExpression, fieldExpression, fieldExpression).AcceptVisitor(RemoveIncludesRewriter.Instance).ToString());
            Assert.Equal(andWithoutIncludes.ToString(), Expression.And(fieldExpression, includeExpression, fieldExpression).AcceptVisitor(RemoveIncludesRewriter.Instance).ToString());
            Assert.Equal(andWithoutIncludes.ToString(), Expression.And(fieldExpression, fieldExpression, includeExpression).AcceptVisitor(RemoveIncludesRewriter.Instance).ToString());
        }
 public override SearchParameterQueryGeneratorContext VisitBinary(BinaryExpression expression, SearchParameterQueryGeneratorContext context)
 {
     return(expression.AcceptVisitor(_componentHandlers[(int)expression.ComponentIndex], context));
 }