diff --git a/test/FunctionalTests/Microsoft.OData.Core.Tests/UriParser/SemanticAst/ODataPathExtensionsTests.cs b/test/FunctionalTests/Microsoft.OData.Core.Tests/UriParser/SemanticAst/ODataPathExtensionsTests.cs index 23d9f8aa68..5384780819 100644 --- a/test/FunctionalTests/Microsoft.OData.Core.Tests/UriParser/SemanticAst/ODataPathExtensionsTests.cs +++ b/test/FunctionalTests/Microsoft.OData.Core.Tests/UriParser/SemanticAst/ODataPathExtensionsTests.cs @@ -251,6 +251,50 @@ public void TestTrimEndingTypeCast() } } + [Fact] + public void TrimEndingTypeAndKeySegments() + { + var testCases = new[] + { + new { + Url = "People", + Trimmed = "People" + }, + new { + Url = "People(1)", + Trimmed = "People" + }, + new { + Url = "People/Fully.Qualified.Namespace.Employee", + Trimmed = "People" + }, + new { + Url = "People(1)/Fully.Qualified.Namespace.Employee", + Trimmed = "People" + }, + new { + Url = "People/Fully.Qualified.Namespace.Employee/1", + Trimmed = "People" + }, + new { + Url = "People/Fully.Qualified.Namespace.Employee/1/MyAddress", + Trimmed = "People/Fully.Qualified.Namespace.Employee/1/MyAddress" + }, + new { + Url = "People(1)/Fully.Qualified.Namespace.Employee/MyAddress", + Trimmed = "People/1/Fully.Qualified.Namespace.Employee/MyAddress" + }, + }; + + foreach (var testCase in testCases) + { + ODataUriParser parser = new ODataUriParser(HardCodedTestModel.TestModel, this.testBaseUri, new Uri(this.testBaseUri, testCase.Url)); + ODataPath path = parser.ParsePath(); + var result = path.TrimEndingTypeAndKeySegments(); + Assert.Equal(testCase.Trimmed, result.ToResourcePathString(ODataUrlKeyDelimiter.Slash)); + } + } + [Fact] public void TestIsIndividualProperty() {