/// <summary> /// Binds a collection of <paramref name="segments"/> to metadata, creating a semantic ODataPath object. /// </summary> /// <param name="segments">Collection of path segments.</param> /// <param name="configuration">The configuration to use when binding the path.</param> /// <returns>A semantic <see cref="ODataPath"/> object to describe the path.</returns> internal static ODataPath BindPath(ICollection<string> segments, ODataUriParserConfiguration configuration) { ODataPathParser semanticPathParser = new ODataPathParser(configuration); var intermediateSegments = semanticPathParser.ParsePath(segments); ODataPath path = new ODataPath(intermediateSegments); return path; }
public void CallbackReturnsBatchReferenceSegment() { ODataPathParser pathParser = new ODataPathParser(new ODataUriParserConfiguration(HardCodedTestModel.TestModel) { BatchReferenceCallback = callback }); IList<ODataPathSegment> segments = pathParser.ParsePath(new[] { "$0" }); ODataPathSegment segment = segments.ToList().Single(); segment.Identifier.Should().Be("$0"); segment.TargetEdmNavigationSource.Should().Be(HardCodedTestModel.GetPeopleSet()); segment.TargetEdmType.Should().Be(HardCodedTestModel.GetPersonType()); }
public void KeyAsSegmentWithTemplateShouldWork() { var keyAsSegmentTemplateParser = new ODataPathParser(new ODataUriParserConfiguration(HardCodedTestModel.TestModel) { EnableUriTemplateParsing = true, UrlConventions = ODataUrlConventions.KeyAsSegment }); IList<ODataPathSegment> path = keyAsSegmentTemplateParser.ParsePath(new[] { "Dogs", "{fido}", "MyPeople" }); var keySegment = path[1].As<KeySegment>(); KeyValuePair<string, object> keypair = keySegment.Keys.Single(); keypair.Key.Should().Be("ID"); keypair.Value.As<UriTemplateExpression>().ShouldBeEquivalentTo(new UriTemplateExpression() { LiteralText = "{fido}", ExpectedType = keySegment.EdmType.As<IEdmEntityType>().DeclaredKey.Single().Type }); }