Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit f338851

Browse files
authored
Merge pull request #612 from github/fixes/611-hostaddress-equality
Implemented operator== for HostAddress.
2 parents 1eeb954 + 074b659 commit f338851

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

src/GitHub.Exports/Primitives/HostAddress.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,16 @@ public static bool IsGitHubDotComUri(Uri hostUri)
7878
|| hostUri.IsSameHost(gistUri);
7979
}
8080

81+
public static bool operator ==(HostAddress a, HostAddress b)
82+
{
83+
return object.ReferenceEquals(a, null) ? object.ReferenceEquals(b, null) : a.Equals(b);
84+
}
85+
86+
public static bool operator !=(HostAddress a, HostAddress b)
87+
{
88+
return !(a == b);
89+
}
90+
8191
public bool IsGitHubDotCom()
8292
{
8393
return IsGitHubDotComUri(ApiUri);
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System;
2+
using GitHub.Primitives;
3+
using Xunit;
4+
5+
namespace UnitTests.GitHub.Exports
6+
{
7+
public class HostAddressTests
8+
{
9+
[Fact]
10+
public void ShouldBeEqualIfAddressesMatch()
11+
{
12+
var address1 = HostAddress.Create("foo.com");
13+
var address2 = HostAddress.Create("foo.com");
14+
var null1 = default(HostAddress);
15+
var null2 = default(HostAddress);
16+
17+
Assert.True(address1.Equals(address2));
18+
Assert.True(address1 == address2);
19+
Assert.False(address1 != address2);
20+
Assert.True(null1 == null2);
21+
}
22+
23+
[Fact]
24+
public void ShouldBeNotEqualIfAddressesDontMatch()
25+
{
26+
var address1 = HostAddress.Create("foo.com");
27+
var address2 = HostAddress.Create("bar.com");
28+
var null1 = default(HostAddress);
29+
30+
Assert.False(address1.Equals(address2));
31+
Assert.False(address1 == address2);
32+
Assert.True(address1 != address2);
33+
Assert.False(null1 == address1);
34+
Assert.False(address1 == null1);
35+
Assert.True(null1 != address1);
36+
Assert.True(address1 != null1);
37+
}
38+
}
39+
}

src/UnitTests/UnitTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@
181181
<Compile Include="GitHub.Exports.Reactive\Caches\AccountCacheItemTests.cs" />
182182
<Compile Include="GitHub.Exports\GitServiceTests.cs" />
183183
<None Include="GitHub.Exports\VSServicesTests.cs" />
184+
<Compile Include="GitHub.Exports\HostAddressTests.cs" />
184185
<Compile Include="GitHub.Exports\LocalRepositoryModelTests.cs" />
185186
<Compile Include="GitHub.Extensions\GuardTests.cs" />
186187
<Compile Include="GitHub.Extensions\UriExtensionTests.cs" />

0 commit comments

Comments
 (0)