Skip to content

Commit

Permalink
Add and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
clemvnt committed Jun 20, 2024
1 parent eefa4ca commit 791c259
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,7 @@ protected Expression GetFlattenedPropertyExpression(string propertyPath, QueryBi
}
#endregion

internal string GetFullPropertyPath(SingleValueNode node)
internal static string GetFullPropertyPath(SingleValueNode node)
{
string path = null;
SingleValueNode parent = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ public static ODataModelBuilder Add_Address_ComplexType(this ODataModelBuilder b
address.Property(a => a.Street);
address.Property(a => a.City);
address.Property(a => a.State);
address.HasDynamicProperties(a => a.DynamicProperties);
return builder;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,161 @@ public void GetPropertyExpression_Works_ForAggregateOrNonAggregate(bool isAggreg
Assert.NotNull(expression);
Assert.Equal(expected, expression.ToString());
}

[Fact]
public void GetFullPropertyPath_WithSingleComplexNode()
{
// Arrange
Mock<IEdmStructuredTypeReference> structuredType = new Mock<IEdmStructuredTypeReference>();
Mock<IEdmNavigationSource> navigationSource = new Mock<IEdmNavigationSource>();
ResourceRangeVariable rangeVariable = new ResourceRangeVariable("$it", structuredType.Object, navigationSource.Object);
ResourceRangeVariableReferenceNode source = new ResourceRangeVariableReferenceNode("$it", rangeVariable);

Mock<IEdmComplexTypeReference> type = new Mock<IEdmComplexTypeReference>();

Mock<IEdmProperty> property = new Mock<IEdmProperty>();
property.Setup(p => p.Name).Returns("Address");
property.Setup(p => p.PropertyKind).Returns(EdmPropertyKind.Structural);
property.Setup(p => p.Type).Returns(type.Object);

SingleComplexNode node = new SingleComplexNode(source, property.Object);

// Act
string fullPropertyPath = QueryBinder.GetFullPropertyPath(node);

// Assert
Assert.Equal("Address", fullPropertyPath);
}

[Fact]
public void GetFullPropertyPath_WithSingleValuePropertyAccessNode()
{
// Arrange
Mock<IEdmStructuredTypeReference> structuredType = new Mock<IEdmStructuredTypeReference>();
Mock<IEdmNavigationSource> navigationSource = new Mock<IEdmNavigationSource>();
ResourceRangeVariable rangeVariable = new ResourceRangeVariable("$it", structuredType.Object, navigationSource.Object);
ResourceRangeVariableReferenceNode source = new ResourceRangeVariableReferenceNode("$it", rangeVariable);

Mock<IEdmTypeReference> type = new Mock<IEdmTypeReference>();

Mock<IEdmProperty> property = new Mock<IEdmProperty>();
property.Setup(p => p.Name).Returns("ZipCode");
property.Setup(p => p.PropertyKind).Returns(EdmPropertyKind.Structural);
property.Setup(p => p.Type).Returns(type.Object);

SingleValuePropertyAccessNode node = new SingleValuePropertyAccessNode(source, property.Object);

// Act
string fullPropertyPath = QueryBinder.GetFullPropertyPath(node);

// Assert
Assert.Equal("ZipCode", fullPropertyPath);
}

[Fact]
public void GetFullPropertyPath_WithSingleNavigationNode()
{
// Arrange
Mock<IEdmStructuredTypeReference> structuredType = new Mock<IEdmStructuredTypeReference>();
Mock<IEdmNavigationSource> navigationSource = new Mock<IEdmNavigationSource>();
ResourceRangeVariable rangeVariable = new ResourceRangeVariable("$it", structuredType.Object, navigationSource.Object);
ResourceRangeVariableReferenceNode source = new ResourceRangeVariableReferenceNode("$it", rangeVariable);

Mock<IEdmEntityTypeReference> type = new Mock<IEdmEntityTypeReference>();

Mock<IEdmNavigationProperty> property = new Mock<IEdmNavigationProperty>();
property.Setup(p => p.Name).Returns("Address");
property.Setup(p => p.Type).Returns(type.Object);

Mock<IEdmPathExpression> bindingPath = new Mock<IEdmPathExpression>();

SingleNavigationNode node = new SingleNavigationNode(source, property.Object, bindingPath.Object);

// Act
string fullPropertyPath = QueryBinder.GetFullPropertyPath(node);

// Assert
Assert.Equal("Address", fullPropertyPath);
}

[Fact]
public void GetFullPropertyPath_WithSingleValueOpenPropertyAccess()
{
// Arrange
Mock<IEdmStructuredTypeReference> structuredType = new Mock<IEdmStructuredTypeReference>();
Mock<IEdmNavigationSource> navigationSource = new Mock<IEdmNavigationSource>();
ResourceRangeVariable rangeVariable = new ResourceRangeVariable("$it", structuredType.Object, navigationSource.Object);
ResourceRangeVariableReferenceNode source = new ResourceRangeVariableReferenceNode("$it", rangeVariable);

SingleValueOpenPropertyAccessNode node = new SingleValueOpenPropertyAccessNode(source, "ZipCode");

// Act
string fullPropertyPath = QueryBinder.GetFullPropertyPath(node);

// Assert
Assert.Equal("ZipCode", fullPropertyPath);
}

[Fact]
public void GetFullPropertyPath_WithSingleValuePropertyAccessNodeInSingleComplexNode()
{
// Arrange
Mock<IEdmStructuredTypeReference> structuredType = new Mock<IEdmStructuredTypeReference>();
Mock<IEdmNavigationSource> navigationSource = new Mock<IEdmNavigationSource>();
ResourceRangeVariable rangeVariable = new ResourceRangeVariable("$it", structuredType.Object, navigationSource.Object);
ResourceRangeVariableReferenceNode source = new ResourceRangeVariableReferenceNode("$it", rangeVariable);

Mock<IEdmComplexTypeReference> complexType = new Mock<IEdmComplexTypeReference>();

Mock<IEdmProperty> complexProperty = new Mock<IEdmProperty>();
complexProperty.Setup(p => p.Name).Returns("Address");
complexProperty.Setup(p => p.PropertyKind).Returns(EdmPropertyKind.Structural);
complexProperty.Setup(p => p.Type).Returns(complexType.Object);

SingleComplexNode complexNode = new SingleComplexNode(source, complexProperty.Object);

Mock<IEdmTypeReference> type = new Mock<IEdmTypeReference>();

Mock<IEdmProperty> property = new Mock<IEdmProperty>();
property.Setup(p => p.Name).Returns("ZipCode");
property.Setup(p => p.PropertyKind).Returns(EdmPropertyKind.Structural);
property.Setup(p => p.Type).Returns(type.Object);

SingleValuePropertyAccessNode node = new SingleValuePropertyAccessNode(complexNode, property.Object);

// Act
string fullPropertyPath = QueryBinder.GetFullPropertyPath(node);

// Assert
Assert.Equal("Address\\ZipCode", fullPropertyPath);
}

[Fact]
public void GetFullPropertyPath_WithSingleValueOpenPropertyAccessNodeInSingleComplexNode()
{
// Arrange
Mock<IEdmStructuredTypeReference> structuredType = new Mock<IEdmStructuredTypeReference>();
Mock<IEdmNavigationSource> navigationSource = new Mock<IEdmNavigationSource>();
ResourceRangeVariable rangeVariable = new ResourceRangeVariable("$it", structuredType.Object, navigationSource.Object);
ResourceRangeVariableReferenceNode source = new ResourceRangeVariableReferenceNode("$it", rangeVariable);

Mock<IEdmComplexTypeReference> complexType = new Mock<IEdmComplexTypeReference>();

Mock<IEdmProperty> complexProperty = new Mock<IEdmProperty>();
complexProperty.Setup(p => p.Name).Returns("Address");
complexProperty.Setup(p => p.PropertyKind).Returns(EdmPropertyKind.Structural);
complexProperty.Setup(p => p.Type).Returns(complexType.Object);

SingleComplexNode complexNode = new SingleComplexNode(source, complexProperty.Object);

SingleValueOpenPropertyAccessNode node = new SingleValueOpenPropertyAccessNode(complexNode, "ZipCode");

// Act
string fullPropertyPath = QueryBinder.GetFullPropertyPath(node);

// Assert
Assert.Equal("Address\\ZipCode", fullPropertyPath);
}
}

public class MyQueryBinder : QueryBinder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1303,9 +1303,15 @@ public void ApplyTo_Returns_Correct_Queryable(string filter, List<Dictionary<str
public void SortOnNestedDynamicPropertyWorks()
{
// Arrange
var model = new ODataModelBuilder()
.Add_Customer_EntityType_With_Address()
.GetEdmModel();
var modelBuilder = new ODataModelBuilder();

var addressType = modelBuilder.ComplexType<Address>();
addressType.HasDynamicProperties(a => a.DynamicProperties);

var customerType = modelBuilder.EntityType<Customer>();
customerType.ComplexProperty(c => c.Address);

var model = modelBuilder.GetEdmModel();

var context = new ODataQueryContext(model, typeof(Customer));

Expand Down

0 comments on commit 791c259

Please sign in to comment.