-
Notifications
You must be signed in to change notification settings - Fork 475
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleanup ODataIdResolvers and E2E tests (#2693)
- Loading branch information
Showing
17 changed files
with
956 additions
and
769 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
src/Microsoft.AspNet.OData.Shared/Common/ODataPathHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
//----------------------------------------------------------------------------- | ||
// <copyright file="ODataPathHelper.cs" company=".NET Foundation"> | ||
// Copyright (c) .NET Foundation and Contributors. All rights reserved. | ||
// See License.txt in the project root for license information. | ||
// </copyright> | ||
//------------------------------------------------------------------------------ | ||
|
||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Microsoft.OData.UriParser; | ||
|
||
namespace Microsoft.AspNet.OData.Common | ||
{ | ||
/// <summary> | ||
/// Helper methods for <see cref="ODataPath"/>. | ||
/// </summary> | ||
internal static class ODataPathHelper | ||
{ | ||
/// <summary> | ||
/// Get the keys from a <see cref="KeySegment"/>. | ||
/// </summary> | ||
/// <param name="keySegment">The <see cref="KeySegment"/> to extract the keys.</param> | ||
/// <returns>Dictionary of keys.</returns> | ||
public static Dictionary<string, object> KeySegmentAsDictionary(KeySegment keySegment) | ||
{ | ||
if (keySegment == null) | ||
{ | ||
throw Error.ArgumentNull(nameof(keySegment)); | ||
} | ||
|
||
return keySegment.Keys.ToDictionary(d => d.Key, d => d.Value); | ||
} | ||
|
||
/// <summary> | ||
/// Get the position of the next <see cref="KeySegment"/> in a list of <see cref="ODataPathSegment"/>. | ||
/// </summary> | ||
/// <param name="pathSegments">List of <see cref="ODataPathSegment"/>.</param> | ||
/// <param name="currentPosition">Current position in the list of <see cref="ODataPathSegment"/>.</param> | ||
/// <returns>Position of the next <see cref="KeySegment"/> if it exists, or -1 otherwise.</returns> | ||
public static int GetNextKeySegmentPosition(IReadOnlyList<ODataPathSegment> pathSegments, int currentPosition) | ||
{ | ||
if (pathSegments == null) | ||
{ | ||
throw Error.ArgumentNull(nameof(pathSegments)); | ||
} | ||
|
||
if (currentPosition < 0 || currentPosition >= pathSegments.Count) | ||
{ | ||
return -1; | ||
} | ||
|
||
if (pathSegments[currentPosition] is KeySegment) | ||
{ | ||
currentPosition++; | ||
} | ||
|
||
for (int i = currentPosition; i < pathSegments.Count; i++) | ||
{ | ||
ODataPathSegment currentSegment = pathSegments[i]; | ||
|
||
if (currentSegment is KeySegment) | ||
{ | ||
return i; | ||
} | ||
} | ||
|
||
return -1; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.