Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2653,6 +2653,37 @@ public void FilterWithInOperationWithEnumsInvalidMemberNames_ThrowsIsNotValidEnu
action.Throws<ODataException>(Error.Format(SRResources.Binder_IsNotValidEnumConstant, expectedExceptionParameter));
}

[Fact]
public void MatchesPatternInFilterWithTheReturnType()
Comment thread
xuzhg marked this conversation as resolved.
{
// Arrange & Act - Filter people whose names match capitalized pattern
var filterClause = ParseFilter("matchesPattern(Name, '^[A-Z][a-z]+$')", HardCodedTestModel.TestModel, HardCodedTestModel.GetPersonType(), HardCodedTestModel.GetPeopleSet());

Comment thread
xuzhg marked this conversation as resolved.
// Assert
var functionCallNode = filterClause.Expression.ShouldBeSingleValueFunctionCallQueryNode("matchesPattern");
Assert.Equal(2, functionCallNode.Parameters.Count());
Assert.True(functionCallNode.TypeReference.IsBoolean());

// Verify first parameter is the Name property
functionCallNode.Parameters.ElementAt(0)
.ShouldBeSingleValuePropertyAccessQueryNode(HardCodedTestModel.GetPersonNameProp());

// Verify second parameter is the regex pattern
functionCallNode.Parameters.ElementAt(1).ShouldBeConstantQueryNode("^[A-Z][a-z]+$");
}

[Fact]
public void MatchesPatternInFilterWithBooleanComparison()
{
// Arrange & Act - Use matchesPattern in boolean expression
var filterClause = ParseFilter("matchesPattern(Name, '[0-9]+') eq true", HardCodedTestModel.TestModel, HardCodedTestModel.GetPersonType(), HardCodedTestModel.GetPeopleSet());

// Assert
var binaryOp = filterClause.Expression.ShouldBeBinaryOperatorNode(BinaryOperatorKind.Equal);
binaryOp.Left.ShouldBeSingleValueFunctionCallQueryNode("matchesPattern");
binaryOp.Right.ShouldBeConstantQueryNode(true);
}

[Fact]
public void FilterWithInOperationWithAny()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1297,6 +1297,32 @@ public void CannotCallFunctionInOpenTypeSpace()
bindOpenFunction.Throws<ODataException>(Error.Format(SRResources.FunctionCallBinder_CallingFunctionOnOpenProperty, "Fully.Qualified.Namespace.FindMyOwner"));
}

[Fact]
public void MatchesPatternFunctionBindsCorrectly()
{
// Arrange
var arguments = new List<QueryToken>()
{
new EndPathToken("Name", new RangeVariableToken(ExpressionConstants.It)),
new LiteralToken(@"^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$")
};
var token = new FunctionCallToken("matchesPattern", arguments);

// Act
var result = functionCallBinder.BindFunctionCall(token);

// Assert
var functionCallNode = result.ShouldBeSingleValueFunctionCallQueryNode("matchesPattern", EdmCoreModel.Instance.GetBoolean(false));
Assert.Equal(2, functionCallNode.Parameters.Count());
Assert.True(functionCallNode.TypeReference.IsBoolean());

// Verify first parameter is the Name property
functionCallNode.Parameters.ElementAt(0).ShouldBeSingleValuePropertyAccessQueryNode(HardCodedTestModel.GetPersonNameProp());

// Verify second parameter is the regex pattern
functionCallNode.Parameters.ElementAt(1).ShouldBeConstantQueryNode(@"^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$");
}

[Fact]
public void GetUriFunction_CombineCustomFunctionsAndBuiltInFunctions()
{
Expand Down