public void MemberAccessWithIdentifierReturnsPropertyAccessToken() { var tokenizer = this.GetIdentifierTokenizerWithRealFunctionParser("stuff"); RangeVariableToken rangeVariableToken = new RangeVariableToken(ExpressionConstants.It); QueryToken result = tokenizer.ParseMemberAccess(rangeVariableToken); result.ShouldBeEndPathToken("stuff").And.NextToken.As<RangeVariableToken>().Name.Should().Be(ExpressionConstants.It); }
public void MemberAccessWithStarParsedCorrectly() { var tokenizer = this.GetIdentifierTokenizerWithRealFunctionParser("*"); RangeVariableToken fakeToken = new RangeVariableToken(ExpressionConstants.It); QueryToken result = tokenizer.ParseMemberAccess(fakeToken); result.ShouldBeStarToken().And.NextToken.Should().BeSameAs(fakeToken); }
public void MemberAccessWithIdentifierReturnsPropertyAccessToken() { var tokenizer = this.GetIdentifierTokenizerWithRealFunctionParser("stuff"); RangeVariableToken rangeVariableToken = new RangeVariableToken(ExpressionConstants.It); QueryToken result = tokenizer.ParseMemberAccess(rangeVariableToken); result.ShouldBeEndPathToken("stuff").And.NextToken.As <RangeVariableToken>().Name.Should().Be(ExpressionConstants.It); }
public void CannotCallStarMemberAccessWithANonStarToken() { var tokenizer = this.GetIdentifierTokenizerWithRealFunctionParser("stuff"); RangeVariableToken rangeVariableToken = new RangeVariableToken(ExpressionConstants.It); Action createWithNonStarToken = () => tokenizer.ParseStarMemberAccess(rangeVariableToken); createWithNonStarToken.ShouldThrow <ODataException>(ODataErrorStrings.UriQueryExpressionParser_CannotCreateStarTokenFromNonStar("stuff")); }
public void MemberAccessWithIdentifierReturnsPropertyAccessToken() { var tokenizer = this.GetIdentifierTokenizerWithRealFunctionParser("stuff"); RangeVariableToken rangeVariableToken = new RangeVariableToken(ExpressionConstants.It); QueryToken result = tokenizer.ParseMemberAccess(rangeVariableToken); var rangeToken = Assert.IsType <RangeVariableToken>(result.ShouldBeEndPathToken("stuff").NextToken); Assert.Equal(ExpressionConstants.It, rangeToken.Name); }
public static RangeVariableToken ShouldBeRangeVariableToken(this QueryToken token, string expectedName) { Assert.NotNull(token); RangeVariableToken parameterQueryToken = Assert.IsType <RangeVariableToken>(token); Assert.Equal(QueryTokenKind.RangeVariable, parameterQueryToken.Kind); Assert.Equal(expectedName, parameterQueryToken.Name); return(parameterQueryToken); }
/// <summary> /// Binds a parameter token. /// </summary> /// <param name="rangeVariableToken">The parameter token to bind.</param> /// <param name="state">The state of metadata binding.</param> /// <returns>The bound query node.</returns> internal static SingleValueNode BindRangeVariableToken(RangeVariableToken rangeVariableToken, BindingState state) { ExceptionUtils.CheckArgumentNotNull(rangeVariableToken, "rangeVariableToken"); RangeVariable rangeVariable = state.RangeVariables.SingleOrDefault(p => p.Name == rangeVariableToken.Name); if (rangeVariable == null) { throw new ODataException(ODataErrorStrings.MetadataBinder_ParameterNotInScope(rangeVariableToken.Name)); } return NodeFactory.CreateRangeVariableReferenceNode(rangeVariable); }
/// <summary> /// Binds a parameter token. /// </summary> /// <param name="rangeVariableToken">The parameter token to bind.</param> /// <param name="state">The state of metadata binding.</param> /// <returns>The bound query node.</returns> internal static SingleValueNode BindRangeVariableToken(RangeVariableToken rangeVariableToken, BindingState state) { ExceptionUtils.CheckArgumentNotNull(rangeVariableToken, "rangeVariableToken"); RangeVariable rangeVariable = state.RangeVariables.SingleOrDefault(p => p.Name == rangeVariableToken.Name); if (rangeVariable == null) { throw new ODataException(ODataErrorStrings.MetadataBinder_ParameterNotInScope(rangeVariableToken.Name)); } return(NodeFactory.CreateRangeVariableReferenceNode(rangeVariable)); }
public bool Visit(RangeVariableToken tokenIn) { throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "QueryToken of type '{0}' is not supported.", tokenIn.Kind)); }
/// <summary> /// Visits a RangeVariableToken /// </summary> /// <param name="tokenIn">The RangeVariableToken to bind</param> /// <returns>An Entity or NonEntity RangeVariableReferenceNode bound to this RangeVariableToken</returns> public virtual T Visit(RangeVariableToken tokenIn) { throw new NotImplementedException(); }
public void IntersectArgsMustBeOrderedCorrectly() { //Args can be in any order, but there must be a Point and a Polygon (either geography or geometry) QueryToken parent = new RangeVariableToken(ExpressionConstants.It); //positive tests QueryToken[] geometryPointGeometryPoly = new QueryToken[] { new EndPathToken("GeometryPoint", parent), new EndPathToken("GeometryPolygon", parent) }; QueryToken[] geometryPolyGeometryPoint = new QueryToken[] { new EndPathToken("GeometryPolygon", parent), new EndPathToken("GeometryPoint", parent) }; QueryToken[] geographyPointGeographyPoly = new QueryToken[] { new EndPathToken("GeographyPoint", parent), new EndPathToken("GeographyPolygon", parent) }; QueryToken[] geographyPolyGeographyPoint = new QueryToken[] { new EndPathToken("GeographyPolygon", parent), new EndPathToken("GeographyPoint", parent) }; FunctionCallToken geometryPointGeometryPolyToken = new FunctionCallToken("geo.intersects", geometryPointGeometryPoly); FunctionCallToken geometryPolyGeometryPointToken = new FunctionCallToken("geo.intersects", geometryPolyGeometryPoint); FunctionCallToken geographyPointGeographyPolyToken = new FunctionCallToken("geo.intersects", geographyPointGeographyPoly); FunctionCallToken geographyPolyGeographyPointToken = new FunctionCallToken("geo.intersects", geographyPolyGeographyPoint); SingleValueFunctionCallNode geometryPointGeometryPolyFunction = this.functionCallBinder.BindFunctionCall(geometryPointGeometryPolyToken) as SingleValueFunctionCallNode; SingleValueFunctionCallNode geometryPolyGeometryPointFunction = this.functionCallBinder.BindFunctionCall(geometryPolyGeometryPointToken) as SingleValueFunctionCallNode; SingleValueFunctionCallNode geographyPointGeographyPolyFunction = this.functionCallBinder.BindFunctionCall(geographyPointGeographyPolyToken) as SingleValueFunctionCallNode; SingleValueFunctionCallNode geographyPolyGeographyPointFunction = this.functionCallBinder.BindFunctionCall(geographyPolyGeographyPointToken) as SingleValueFunctionCallNode; geometryPointGeometryPolyFunction.Parameters.Count().Should().Be(2); geometryPointGeometryPolyFunction.Parameters.ElementAt(0).ShouldBeSingleValuePropertyAccessQueryNode(HardCodedTestModel.GetPersonGeometryPointProp()); geometryPointGeometryPolyFunction.Parameters.ElementAt(1).ShouldBeSingleValuePropertyAccessQueryNode(HardCodedTestModel.GetPersonGeometryPolygonProp()); geometryPolyGeometryPointFunction.Parameters.Count().Should().Be(2); geometryPolyGeometryPointFunction.Parameters.ElementAt(0).ShouldBeSingleValuePropertyAccessQueryNode(HardCodedTestModel.GetPersonGeometryPolygonProp()); geometryPolyGeometryPointFunction.Parameters.ElementAt(1).ShouldBeSingleValuePropertyAccessQueryNode(HardCodedTestModel.GetPersonGeometryPointProp()); geographyPointGeographyPolyFunction.Parameters.Count().Should().Be(2); geographyPointGeographyPolyFunction.Parameters.ElementAt(0).ShouldBeSingleValuePropertyAccessQueryNode(HardCodedTestModel.GetPersonGeographyPointProp()); geographyPointGeographyPolyFunction.Parameters.ElementAt(1).ShouldBeSingleValuePropertyAccessQueryNode(HardCodedTestModel.GetPersonGeographyPolygonProp()); geographyPolyGeographyPointFunction.Parameters.Count().Should().Be(2); geographyPolyGeographyPointFunction.Parameters.ElementAt(0).ShouldBeSingleValuePropertyAccessQueryNode(HardCodedTestModel.GetPersonGeographyPolygonProp()); geographyPolyGeographyPointFunction.Parameters.ElementAt(1).ShouldBeSingleValuePropertyAccessQueryNode(HardCodedTestModel.GetPersonGeographyPointProp()); //negative tests QueryToken[] geometryPointNonGeometryPoly = new QueryToken[] { new EndPathToken("GeometryPoint", parent), new LiteralToken("bob") }; QueryToken[] geometryPolyNonGeometryPoint = new QueryToken[] { new EndPathToken("GeometryPolygon", parent), new LiteralToken("bob") }; QueryToken[] geographyPointNonGeograpyPoly = new QueryToken[] { new EndPathToken("GeographyPoint", parent), new LiteralToken("bob") }; QueryToken[] geographyPolyNonGeographyPoint = new QueryToken[] { new EndPathToken("GeographyPolygon", parent), new LiteralToken("bob") }; QueryToken[] garbage = new QueryToken[] { new LiteralToken("tex"), new LiteralToken("slim") }; FunctionCallToken geometryPointNonGeometryPolyToken = new FunctionCallToken("geo.intersects", geometryPointNonGeometryPoly); FunctionCallToken geometryPolyNonGeometryPointToken = new FunctionCallToken("geo.intersects", geometryPolyNonGeometryPoint); FunctionCallToken geographyPointNonGeographyPolyToken = new FunctionCallToken("geo.intersects", geographyPointNonGeograpyPoly); FunctionCallToken geographyPolyNonGeographyPointToken = new FunctionCallToken("geo.intersects", geographyPolyNonGeographyPoint); FunctionCallToken garbageToken = new FunctionCallToken("geo.intersects", garbage); Action createWithGeometryPointNonGeometryPoly = () => this.functionCallBinder.BindFunctionCall(geometryPointNonGeometryPolyToken); Action createWithGeometryPolyNonGeometryPoint = () => this.functionCallBinder.BindFunctionCall(geometryPolyNonGeometryPointToken); Action createWithGeographyPointNonGeographyPoly = () => this.functionCallBinder.BindFunctionCall(geographyPointNonGeographyPolyToken); Action createWithGeographyPolyNonGeographyPoint = () => this.functionCallBinder.BindFunctionCall(geographyPolyNonGeographyPointToken); Action createWithGarbage = () => this.functionCallBinder.BindFunctionCall(garbageToken); FunctionSignatureWithReturnType[] signatures = FunctionCallBinder.GetBuiltInFunctionSignatures(geometryPointNonGeometryPolyToken.Name); createWithGeometryPointNonGeometryPoly.ShouldThrow<ODataException>().WithMessage(ODataErrorStrings.MetadataBinder_NoApplicableFunctionFound( geometryPointNonGeometryPolyToken.Name, BuiltInFunctions.BuildFunctionSignatureListDescription(geometryPointNonGeometryPolyToken.Name, signatures))); signatures = FunctionCallBinder.GetBuiltInFunctionSignatures(geometryPolyNonGeometryPointToken.Name); createWithGeometryPolyNonGeometryPoint.ShouldThrow<ODataException>().WithMessage(ODataErrorStrings.MetadataBinder_NoApplicableFunctionFound( geometryPolyNonGeometryPointToken.Name, BuiltInFunctions.BuildFunctionSignatureListDescription(geometryPolyNonGeometryPointToken.Name, signatures))); signatures = FunctionCallBinder.GetBuiltInFunctionSignatures(geographyPointNonGeographyPolyToken.Name); createWithGeographyPointNonGeographyPoly.ShouldThrow<ODataException>().WithMessage(ODataErrorStrings.MetadataBinder_NoApplicableFunctionFound( geographyPointNonGeographyPolyToken.Name, BuiltInFunctions.BuildFunctionSignatureListDescription(geographyPointNonGeographyPolyToken.Name, signatures))); signatures = FunctionCallBinder.GetBuiltInFunctionSignatures(geographyPolyNonGeographyPointToken.Name); createWithGeographyPolyNonGeographyPoint.ShouldThrow<ODataException>().WithMessage(ODataErrorStrings.MetadataBinder_NoApplicableFunctionFound( geographyPolyNonGeographyPointToken.Name, BuiltInFunctions.BuildFunctionSignatureListDescription(geographyPolyNonGeographyPointToken.Name, signatures))); signatures = FunctionCallBinder.GetBuiltInFunctionSignatures(garbageToken.Name); createWithGarbage.ShouldThrow<ODataException>().WithMessage(ODataErrorStrings.MetadataBinder_NoApplicableFunctionFound( garbageToken.Name, BuiltInFunctions.BuildFunctionSignatureListDescription(garbageToken.Name, signatures))); }
public void IntersectsMustBeCalledWithTwoArgs() { QueryToken parent = new RangeVariableToken(ExpressionConstants.It); QueryToken[] oneArg = new QueryToken[] { new EndPathToken("GeometryLineString", parent), }; QueryToken[] moreThanTwoArgs = new QueryToken[] { new EndPathToken("GeometryLineString", parent), new EndPathToken("GeographyLineString", parent), new EndPathToken("GeometryPolygon", parent) }; FunctionCallToken functionWithOneArg = new FunctionCallToken("geo.intersects", oneArg); FunctionCallToken functionWithMoreThanTwoArgs = new FunctionCallToken("geo.intersects", moreThanTwoArgs); Action createWithOneArg = () => this.functionCallBinder.BindFunctionCall(functionWithOneArg); Action createWithMoreThanTwoArgs = () => this.functionCallBinder.BindFunctionCall(functionWithMoreThanTwoArgs); FunctionSignatureWithReturnType[] signatures = FunctionCallBinder.GetBuiltInFunctionSignatures(functionWithOneArg.Name); createWithOneArg.ShouldThrow<ODataException>().WithMessage(ODataErrorStrings.MetadataBinder_NoApplicableFunctionFound( functionWithOneArg.Name, BuiltInFunctions.BuildFunctionSignatureListDescription(functionWithOneArg.Name, signatures))); signatures = FunctionCallBinder.GetBuiltInFunctionSignatures(functionWithMoreThanTwoArgs.Name); createWithMoreThanTwoArgs.ShouldThrow<ODataException>().WithMessage(ODataErrorStrings.MetadataBinder_NoApplicableFunctionFound( functionWithMoreThanTwoArgs.Name, BuiltInFunctions.BuildFunctionSignatureListDescription(functionWithMoreThanTwoArgs.Name, signatures))); }
public void LengthProducesSingleValueFunctionCallNode() { QueryToken parent = new RangeVariableToken(ExpressionConstants.It); QueryToken[] args = new QueryToken[] { new EndPathToken("GeometryLineString", parent) }; FunctionCallToken function = new FunctionCallToken("geo.length", args); SingleValueFunctionCallNode node = this.functionCallBinder.BindFunctionCall(function) as SingleValueFunctionCallNode; node.Parameters.Count().Should().Be(1); node.Parameters.ElementAt(0).ShouldBeSingleValuePropertyAccessQueryNode(HardCodedTestModel.GetPersonGeometryLineStringProp()); }
public void LengthArgMustBeLineStringType() { QueryToken parent = new RangeVariableToken(ExpressionConstants.It); QueryToken[] args = new QueryToken[] { new EndPathToken("GeometryLinePolygon", parent), new LiteralToken("bob"), }; FunctionCallToken function = new FunctionCallToken("geo.length", args); Action createWithNonLineStringType = () => this.functionCallBinder.BindFunctionCall(function); createWithNonLineStringType.ShouldThrow<ODataException>().WithMessage(ODataErrorStrings.MetadataBinder_PropertyNotDeclared("Fully.Qualified.Namespace.Person", "GeometryLinePolygon")); }
public void LengthWorksWithExactlyOneArgument() { QueryToken parent = new RangeVariableToken(ExpressionConstants.It); QueryToken[] args = new QueryToken[] { new EndPathToken("GeometryLineString", parent), new LiteralToken("bob"), }; FunctionCallToken function = new FunctionCallToken("geo.length", args); Action createWithMoreThanOneArg = () => this.functionCallBinder.BindFunctionCall(function); FunctionSignatureWithReturnType[] signatures = FunctionCallBinder.GetBuiltInFunctionSignatures(function.Name); createWithMoreThanOneArg.ShouldThrow<ODataException>().WithMessage(ODataErrorStrings.MetadataBinder_NoApplicableFunctionFound( function.Name, BuiltInFunctions.BuildFunctionSignatureListDescription(function.Name, signatures))); }
/// <summary> /// Binds a parameter token. /// </summary> /// <param name="rangeVariableToken">The parameter token to bind.</param> /// <returns>The bound query node.</returns> protected virtual SingleValueNode BindRangeVariable(RangeVariableToken rangeVariableToken) { return RangeVariableBinder.BindRangeVariableToken(rangeVariableToken, this.BindingState); }
public void CannotCallStarMemberAccessWithANonStarToken() { var tokenizer = this.GetIdentifierTokenizerWithRealFunctionParser("stuff"); RangeVariableToken rangeVariableToken = new RangeVariableToken(ExpressionConstants.It); Action createWithNonStarToken = () => tokenizer.ParseStarMemberAccess(rangeVariableToken); createWithNonStarToken.ShouldThrow<ODataException>(ODataErrorStrings.UriQueryExpressionParser_CannotCreateStarTokenFromNonStar("stuff")); }
/// <summary> /// Binds a parameter token. /// </summary> /// <param name="rangeVariableToken">The parameter token to bind.</param> /// <returns>The bound query node.</returns> protected virtual SingleValueNode BindRangeVariable(RangeVariableToken rangeVariableToken) { return(RangeVariableBinder.BindRangeVariableToken(rangeVariableToken, this.BindingState)); }
public Expression Visit(RangeVariableToken tokenIn) { throw new NotImplementedException(); }