diff options
author | Edward Thomson <ethomson@microsoft.com> | 2013-10-22 01:13:04 +0400 |
---|---|---|
committer | Edward Thomson <ethomson@microsoft.com> | 2013-10-22 18:29:51 +0400 |
commit | 7af5c60f22f9bd6064204f84467cfa62bedd1147 (patch) | |
tree | 7dedd6268fac0509949f32f274f76e1e61344440 /LibGit2Sharp.Tests | |
parent | fc78c72fd507b01b1ee65d37525757ce8c35e813 (diff) |
Teach LambdaEqualityHelper to deal with null equality contribution
Diffstat (limited to 'LibGit2Sharp.Tests')
-rw-r--r-- | LibGit2Sharp.Tests/EqualityFixture.cs | 52 | ||||
-rw-r--r-- | LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj | 1 |
2 files changed, 53 insertions, 0 deletions
diff --git a/LibGit2Sharp.Tests/EqualityFixture.cs b/LibGit2Sharp.Tests/EqualityFixture.cs new file mode 100644 index 00000000..168d5fb9 --- /dev/null +++ b/LibGit2Sharp.Tests/EqualityFixture.cs @@ -0,0 +1,52 @@ +using LibGit2Sharp.Tests.TestHelpers; +using Xunit; + +namespace LibGit2Sharp.Tests +{ + public class EqualityFixture : BaseFixture + { + [Fact] + public void EqualityHelperCanTestNullInEquals() + { + var one = new ObjectWithEquality(); + var two = new ObjectWithEquality(); + var three = new ObjectWithEquality(ObjectId.Zero); + var four = new ObjectWithEquality(ObjectId.Zero); + + Assert.True(one.Equals(one)); + Assert.True(two.Equals(two)); + Assert.True(three.Equals(four)); + Assert.True(four.Equals(three)); + Assert.False(one.Equals(three)); + Assert.False(three.Equals(one)); + } + + [Fact] + public void EqualityHelperCanTestNullInHashCode() + { + var one = new ObjectWithEquality(); + var two = new ObjectWithEquality(); + var three = new ObjectWithEquality(ObjectId.Zero); + var four = new ObjectWithEquality(ObjectId.Zero); + + Assert.Equal(one.GetHashCode(), two.GetHashCode()); + Assert.Equal(three.GetHashCode(), four.GetHashCode()); + Assert.NotEqual(one.GetHashCode(), three.GetHashCode()); + } + + private class ObjectWithEquality : GitObject + { + private readonly ObjectId id; + + public ObjectWithEquality(ObjectId id = null) + { + this.id = id; + } + + public override ObjectId Id + { + get { return id; } + } + } + } +} diff --git a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj index 3d84d498..6a356cb8 100644 --- a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj +++ b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj @@ -59,6 +59,7 @@ </ItemGroup> <ItemGroup> <Compile Include="CheckoutFixture.cs" /> + <Compile Include="EqualityFixture.cs" /> <Compile Include="SignatureFixture.cs" /> <Compile Include="FilterBranchFixture.cs" /> <Compile Include="RemoveFixture.cs" /> |