public CsdlSemanticsPathExpression(CsdlPathExpression expression, IEdmEntityType bindingContext, CsdlSemanticsSchema schema) : base(schema, expression) { this.Expression = expression; this.BindingContext = bindingContext; }
public CsdlSemanticsPropertyPathExpression(CsdlPathExpression expression, IEdmEntityType bindingContext, CsdlSemanticsSchema schema) : base(expression, bindingContext, schema) { }
public void ParseCsdlOutOfLineAnnotationWithMembersWorksAsExpected() { string json = @"""$Annotations"": { ""self.Person"": { ""@Core.Description#Tablet"": ""Dummy"", ""@UI.DisplayName#MyTablet"": { ""$Path"": ""FirstName"" } }, ""self.MyEntityType"": { ""@self.Dummy"": true, ""@UI.Threshold#Example73"": { ""$Type"": ""Edm.Decimal"", ""$Cast"": { ""$Path"": ""Average"" } } } }"; IList <CsdlAnnotations> annotations = ParseCsdlSchemaElement(json, SchemaJsonParser.ParseCsdlOutOfLineAnnotations); Assert.NotNull(annotations); Assert.Equal(2, annotations.Count); // #1 CsdlAnnotations csdlAnnotations = annotations.First(c => c.Target == "self.Person"); Assert.Null(csdlAnnotations.Qualifier); Assert.Equal(2, csdlAnnotations.Annotations.Count()); // #1.1 CsdlAnnotation csdlAnnotation = csdlAnnotations.Annotations.First(c => c.Term == "Core.Description"); Assert.Equal("Tablet", csdlAnnotation.Qualifier); CsdlConstantExpression constExp = Assert.IsType <CsdlConstantExpression>(csdlAnnotation.Expression); Assert.Equal("Dummy", constExp.Value); Assert.Equal(EdmValueKind.String, constExp.ValueKind); // #1.2 csdlAnnotation = csdlAnnotations.Annotations.First(c => c.Term == "UI.DisplayName"); Assert.Equal("MyTablet", csdlAnnotation.Qualifier); CsdlPathExpression pathExp = Assert.IsType <CsdlPathExpression>(csdlAnnotation.Expression); Assert.Equal("FirstName", pathExp.Path); // #2 csdlAnnotations = annotations.First(c => c.Target == "self.MyEntityType"); Assert.Null(csdlAnnotations.Qualifier); Assert.Equal(2, csdlAnnotations.Annotations.Count()); // #2.1 csdlAnnotation = csdlAnnotations.Annotations.First(c => c.Term == "self.Dummy"); Assert.Null(csdlAnnotation.Qualifier); constExp = Assert.IsType <CsdlConstantExpression>(csdlAnnotation.Expression); Assert.Equal("true", constExp.Value); Assert.Equal(EdmValueKind.Boolean, constExp.ValueKind); // #2.2 csdlAnnotation = csdlAnnotations.Annotations.First(c => c.Term == "UI.Threshold"); Assert.Equal("Example73", csdlAnnotation.Qualifier); CsdlCastExpression castExp = Assert.IsType <CsdlCastExpression>(csdlAnnotation.Expression); Assert.IsType <CsdlDecimalTypeReference>(castExp.Type); pathExp = Assert.IsType <CsdlPathExpression>(castExp.Operand); Assert.Equal("Average", pathExp.Path); }
/// <summary> /// Parse an instance path with a Value path. /// An instance path is on object with a "$Path" member. /// "@UI.DisplayName#second": { /// "$Path": "@vCard.Address#work/FullName" /// } /// </summary> /// <param name="element">The input JSON element.</param> /// <param name="context">The parser context.</param> /// <param name="pathExp">The built path expression.</param> /// <returns>true/false.</returns> private static bool TryParseValuePathExpression(JsonElement element, JsonParserContext context, out CsdlPathExpression pathExp) { Debug.Assert(context != null); pathExp = null; // Path expressions are represented as an object with a single member $Path JsonElement propertyValue; if (element.ValueKind != JsonValueKind.Object || !element.TryGetProperty("$Path", out propertyValue)) { return(false); } // whose value is a string containing a path. string pathStr = propertyValue.ProcessProperty("$Path", context, (v, p) => v.ParseAsString(p)); pathExp = new CsdlPathExpression(pathStr, context.Location()); return(true); }
public CsdlSemanticsPathExpression(CsdlPathExpression expression, IEdmEntityType bindingContext, CsdlSemanticsSchema schema) : base(schema, expression) { this.pathCache = new Cache <CsdlSemanticsPathExpression, IEnumerable <string> >(); this.expression = expression; this.bindingContext = bindingContext; }
public void ParseApplyExpressionWorksAsExpected() { string json = @" { ""$Apply"": [ ""Product: "", { ""$Path"": ""ProductName"" }, ""("", { ""$Path"": ""Available/Quantity"" }, "" "", { ""$Path"": ""Available /Unit"" }, "" available)"" ], ""$Function"": ""odata.concat"" }"; CsdlExpressionBase expressionBase = ParseExpression(json); Assert.NotNull(expressionBase); CsdlApplyExpression applyExp = Assert.IsType <CsdlApplyExpression>(expressionBase); Assert.NotNull(applyExp.Function); Assert.Equal("odata.concat", applyExp.Function); Assert.NotNull(applyExp.Arguments); Assert.Equal(7, applyExp.Arguments.Count()); // 0 CsdlConstantExpression constantArgument = Assert.IsType <CsdlConstantExpression>(applyExp.Arguments.ElementAt(0)); Assert.Equal("Product: ", constantArgument.Value); // 1 CsdlPathExpression pathArgument = Assert.IsType <CsdlPathExpression>(applyExp.Arguments.ElementAt(1)); Assert.Equal("ProductName", pathArgument.Path); // 2 constantArgument = Assert.IsType <CsdlConstantExpression>(applyExp.Arguments.ElementAt(2)); Assert.Equal("(", constantArgument.Value); // 3 pathArgument = Assert.IsType <CsdlPathExpression>(applyExp.Arguments.ElementAt(3)); Assert.Equal("Available/Quantity", pathArgument.Path); // 4 constantArgument = Assert.IsType <CsdlConstantExpression>(applyExp.Arguments.ElementAt(4)); Assert.Equal(" ", constantArgument.Value); // 5 pathArgument = Assert.IsType <CsdlPathExpression>(applyExp.Arguments.ElementAt(5)); Assert.Equal("Available /Unit", pathArgument.Path); // 6 constantArgument = Assert.IsType <CsdlConstantExpression>(applyExp.Arguments.ElementAt(6)); Assert.Equal(" available)", constantArgument.Value); }