public void BindApplyWithAggregateAndFilterShouldReturnApplyClause() { IEnumerable <QueryToken> tokens = _parser.ParseApply("aggregate(StockQuantity with sum as TotalPrice)/filter(TotalPrice eq 100)"); MetadataBinder metadataBiner = new MetadataBinder(_bindingState); ApplyBinder binder = new ApplyBinder(metadataBiner.Bind, _bindingState); ApplyClause actual = binder.BindApply(tokens); actual.Should().NotBeNull(); actual.Transformations.Should().HaveCount(2); List <TransformationNode> transformations = actual.Transformations.ToList(); FilterTransformationNode filter = transformations[1] as FilterTransformationNode; filter.Should().NotBeNull(); filter.Kind.Should().Be(TransformationNodeKind.Filter); FilterClause filterClause = filter.FilterClause; filterClause.Expression.Should().NotBeNull(); BinaryOperatorNode binaryOperation = filterClause.Expression as BinaryOperatorNode; binaryOperation.Should().NotBeNull(); ConvertNode propertyConvertNode = binaryOperation.Left as ConvertNode; propertyConvertNode.Should().NotBeNull(); SingleValueOpenPropertyAccessNode propertyAccess = propertyConvertNode.Source as SingleValueOpenPropertyAccessNode; propertyAccess.Should().NotBeNull(); propertyAccess.Name.Should().Be("TotalPrice"); }
public void BuildRelativeUri_FilterSegmentWithAliasInFilterOption_AliasAsBoolean() { Uri relativeUri = new Uri("People/$filter(ID%20eq%201)?$filter=%40p1&@p1=true", UriKind.Relative); ODataUriParser odataUriParser = new ODataUriParser(HardCodedTestModel.TestModel, serviceRoot, relativeUri); SetODataUriParserSettingsTo(this.settings, odataUriParser.Settings); odataUriParser.UrlKeyDelimiter = ODataUrlKeyDelimiter.Parentheses; ODataUri odataUri = odataUriParser.ParseUri(); List <FilterSegment> filterSegments = odataUri.Path.OfType <FilterSegment>().ToList(); filterSegments.Count.Should().Be(1); filterSegments[0].TargetEdmType.ToString().ShouldBeEquivalentTo(HardCodedTestModel.GetPersonType().ToString()); filterSegments[0].SingleResult.Should().BeFalse(); BinaryOperatorNode binaryOperatorNode = filterSegments[0].Expression as BinaryOperatorNode; binaryOperatorNode.Should().NotBeNull(); binaryOperatorNode.OperatorKind.Should().Be(BinaryOperatorKind.Equal); binaryOperatorNode.Left.ShouldBeSingleValuePropertyAccessQueryNode(HardCodedTestModel.GetPersonIdProp()); binaryOperatorNode.Right.ShouldBeConstantQueryNode(1); odataUri.Filter.Expression.ShouldBeParameterAliasNode("@p1", EdmCoreModel.Instance.GetBoolean(false)); odataUri.ParameterAliasNodes["@p1"].ShouldBeConstantQueryNode(true); Uri expectedUri = new Uri("http://gobbledygook/People/$filter(ID%20eq%201)?$filter=%40p1&@p1=true"); Uri actualUri = odataUri.BuildUri(ODataUrlKeyDelimiter.Parentheses); Assert.Equal(expectedUri, actualUri); actualUri = odataUri.BuildUri(ODataUrlKeyDelimiter.Slash); Assert.Equal(expectedUri, actualUri); }