Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/Microsoft.OData.Core/UriParser/SemanticAst/ODataPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,16 @@ internal bool Equals(ODataPath other)
return false;
}

return !this.segments.Where((t, i) => !t.Equals(other.segments[i])).Any();
int segmentsCount = this.segments.Count;
for (int index = 0; index < segmentsCount; index++)
{
if (!this.segments[index].Equals(other.segments[index]))
{
return false;
}
}

return true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,58 @@ public void PathsWithEqualivalentSegmentsAreEqual()
Assert.True(new ODataPath(new DynamicPathSegment("foo")).Equals(new ODataPath(new DynamicPathSegment("foo"))));
}

[Fact]
public void EmptyPathsAreEqual()
{
Assert.True(new ODataPath().Equals(new ODataPath()));
}

[Fact]
public void EqualsThrowsForNullPath()
{
ODataPath path = new ODataPath(MetadataSegment.Instance);

Assert.Throws<ArgumentNullException>("other", () => path.Equals((ODataPath)null));
}

[Fact]
public void PathsWithMultipleEquivalentSegmentsAreEqual()
{
ODataPath first = new ODataPath(
new DynamicPathSegment("first"),
new DynamicPathSegment("middle"),
new DynamicPathSegment("last"));
ODataPath second = new ODataPath(
new DynamicPathSegment("first"),
new DynamicPathSegment("middle"),
new DynamicPathSegment("last"));

Assert.True(first.Equals(second));
}

[Theory]
[InlineData(0)]
[InlineData(1)]
[InlineData(2)]
public void PathsWithMismatchAtAnyPositionAreNotEqual(int mismatchIndex)
{
ODataPathSegment[] firstSegments =
{
new DynamicPathSegment("first"),
new DynamicPathSegment("middle"),
new DynamicPathSegment("last")
};
ODataPathSegment[] secondSegments =
{
new DynamicPathSegment("first"),
new DynamicPathSegment("middle"),
new DynamicPathSegment("last")
};
secondSegments[mismatchIndex] = new DynamicPathSegment("different");

Assert.False(new ODataPath(firstSegments).Equals(new ODataPath(secondSegments)));
}

[Fact]
public void PathsShouldNotAllowSegmentsToBeNull()
{
Expand Down