From 3501a153c8a6f2da1334c87dbd51425ffbe31524 Mon Sep 17 00:00:00 2001 From: Nigel Sampson Date: Fri, 31 May 2019 15:24:18 +1200 Subject: [PATCH 1/2] Add some failing unit tests (#801) --- src/Core/Abstractions.Tests/PathTests.cs | 42 ++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/Core/Abstractions.Tests/PathTests.cs b/src/Core/Abstractions.Tests/PathTests.cs index 0616970fae8..777e9528b58 100644 --- a/src/Core/Abstractions.Tests/PathTests.cs +++ b/src/Core/Abstractions.Tests/PathTests.cs @@ -39,5 +39,47 @@ public void Path_ToCollection() // assert result.MatchSnapshot(); } + + [Fact] + public void Path_Equals_Null() + { + // arrange + Path hero = Path.New("hero"); + Path friends = null; + + // act + var areEqual = hero.Equals(friends); + + // assert + Assert.False(areEqual); + } + + [Fact] + public void Path_Equals_False() + { + // arrange + Path hero = Path.New("hero"); + Path friends = Path.New("hero").Append("friends"); + + // act + var areEqual = hero.Equals(friends); + + // assert + Assert.False(areEqual); + } + + [Fact] + public void Path_Equals_True() + { + // arrange + Path friends1 = Path.New("hero").Append("friends"); + Path friends2 = Path.New("hero").Append("friends"); + + // act + var areEqual = friends1.Equals(friends2); + + // assert + Assert.True(areEqual); + } } } From 121cfae16c88325953264f926589df0d159e32be Mon Sep 17 00:00:00 2001 From: Nigel Sampson Date: Fri, 31 May 2019 15:24:42 +1200 Subject: [PATCH 2/2] Guard against null values (#801) --- src/Core/Abstractions/Path.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Core/Abstractions/Path.cs b/src/Core/Abstractions/Path.cs index 2abfc928b09..4b40692aa96 100644 --- a/src/Core/Abstractions/Path.cs +++ b/src/Core/Abstractions/Path.cs @@ -47,9 +47,14 @@ public bool Equals(Path other) return true; } - return (other.Parent.Equals(Parent) + if (ReferenceEquals(null, other)) + { + return false; + } + + return ((Parent == null && other.Parent == null) || other.Parent.Equals(Parent)) && string.Equals(other.Name, Name, StringComparison.Ordinal) - && other.Index.Equals(Index)); + && other.Index.Equals(Index); } public override bool Equals(object obj)