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

Commit 8448a3b

Browse files
authored
Merge pull request #546 from github/grokys/remove-duplicate-guard
Remove duplicate guard class.
2 parents 2ccc51a + 783429b commit 8448a3b

File tree

12 files changed

+132
-39
lines changed

12 files changed

+132
-39
lines changed

src/GitHub.App/Api/ApiClient.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
using Octokit.Internal;
1919
using System.Collections.Generic;
2020
using GitHub.Models;
21+
using GitHub.Extensions;
2122

2223
namespace GitHub.Api
2324
{

src/GitHub.App/Caches/LoginCache.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Reactive;
55
using System.Reactive.Linq;
66
using Akavache;
7+
using GitHub.Extensions;
78
using GitHub.Primitives;
89
using NLog;
910

src/GitHub.App/Factories/SqlitePersistentBlobCacheFactory.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.ComponentModel.Composition;
77
using System.Reactive.Linq;
88
using System.Threading.Tasks;
9+
using GitHub.Extensions;
910

1011
namespace GitHub.Factories
1112
{

src/GitHub.App/Models/RepositoryHost.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using System.Linq;
1818
using System.Reactive.Threading.Tasks;
1919
using System.Collections.Generic;
20+
using GitHub.Extensions;
2021

2122
namespace GitHub.Models
2223
{

src/GitHub.App/Services/GitClient.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
using System.Linq;
44
using System.Reactive;
55
using System.Reactive.Linq;
6-
using LibGit2Sharp;
6+
using GitHub.Extensions;
77
using GitHub.Primitives;
8+
using LibGit2Sharp;
89

910
namespace GitHub.Services
1011
{

src/GitHub.App/Services/RepositoryCreationService.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Reactive;
44
using System.Reactive.Linq;
55
using GitHub.Api;
6+
using GitHub.Extensions;
67
using GitHub.Extensions.Reactive;
78
using GitHub.Models;
89
using Octokit;

src/GitHub.Exports.Reactive/GitHub.Exports.Reactive.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@
125125
<Link>Key.snk</Link>
126126
</None>
127127
<Compile Include="Helpers\ExceptionHelper.cs" />
128-
<Compile Include="Helpers\Guard.cs" />
129128
<Compile Include="Models\GitIgnoreItem.cs" />
130129
<Compile Include="Models\LicenseItem.cs" />
131130
<Compile Include="Properties\AssemblyInfo.cs" />

src/GitHub.Exports.Reactive/Helpers/Guard.cs

Lines changed: 0 additions & 35 deletions
This file was deleted.

src/GitHub.Extensions/Guard.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ public static void ArgumentNonNegative(int value, string name)
3737
}
3838

3939
/// <summary>
40-
/// Checks a string argument to ensure it isn't null or empty.
40+
/// Checks a string argument to ensure it isn't null or empty.
4141
/// </summary>
4242
/// <param name = "value">The argument value to check.</param>
4343
/// <param name = "name">The name of the argument.</param>
4444
public static void ArgumentNotEmptyString(string value, string name)
4545
{
46-
if (value.Length > 0) return;
46+
if (value?.Length > 0) return;
4747
string message = String.Format(CultureInfo.InvariantCulture, "The value for '{0}' must not be empty", name);
4848
#if DEBUG
4949
if (!InUnitTestRunner())

src/GitHub.UI.Reactive/Validation/ReactiveValidatableObject.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using ReactiveUI;
1111
using NullGuard;
1212
using GitHub.Services;
13+
using GitHub.Extensions;
1314

1415
namespace GitHub.Validation
1516
{
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using GitHub.Extensions;
7+
using Xunit;
8+
9+
namespace UnitTests.GitHub.Extensions
10+
{
11+
public class GuardTests
12+
{
13+
public class TheArgumentNotNullMethod : TestBaseClass
14+
{
15+
[Fact]
16+
public void ShouldNotThrow()
17+
{
18+
Guard.ArgumentNotNull(new object(), "name");
19+
}
20+
21+
[Fact]
22+
public void ShouldThrow()
23+
{
24+
Assert.Throws<ArgumentNullException>(() => Guard.ArgumentNotNull(null, "name"));
25+
}
26+
}
27+
28+
public class TheArgumentNonNegativeMethod : TestBaseClass
29+
{
30+
[Fact]
31+
public void ShouldNotThrowFor0()
32+
{
33+
Guard.ArgumentNonNegative(0, "name");
34+
}
35+
36+
[Fact]
37+
public void ShouldNotThrowFor1()
38+
{
39+
Guard.ArgumentNonNegative(1, "name");
40+
}
41+
42+
[Fact]
43+
public void ShouldThrowForMinus1()
44+
{
45+
Assert.Throws<ArgumentException>(() => Guard.ArgumentNonNegative(-1, "name"));
46+
}
47+
}
48+
49+
public class TheArgumentNotEmptyStringMethod : TestBaseClass
50+
{
51+
[Fact]
52+
public void ShouldNotThrowForString()
53+
{
54+
Guard.ArgumentNotEmptyString("string", "name");
55+
}
56+
57+
[Fact]
58+
public void ShouldThrowForEmptyString()
59+
{
60+
Assert.Throws<ArgumentException>(() => Guard.ArgumentNotEmptyString("", "name"));
61+
}
62+
63+
[Fact]
64+
public void ShouldThrowForNull()
65+
{
66+
Assert.Throws<ArgumentException>(() => Guard.ArgumentNotEmptyString(null, "name"));
67+
}
68+
}
69+
70+
public class TheArgumentInRangeMethod : TestBaseClass
71+
{
72+
[Fact]
73+
public void ShouldNotThrowForGreaterThanMinimum()
74+
{
75+
Guard.ArgumentInRange(12, 10, "name");
76+
}
77+
78+
[Fact]
79+
public void ShouldNotThrowForEqualToMinimumNoMaximum()
80+
{
81+
Guard.ArgumentInRange(10, 10, "name");
82+
}
83+
84+
[Fact]
85+
public void ShouldNotThrowForEqualToMinimumWithMaximum()
86+
{
87+
Guard.ArgumentInRange(10, 10, 20, "name");
88+
}
89+
90+
[Fact]
91+
public void ShouldNotThrowForEqualToMaximum()
92+
{
93+
Guard.ArgumentInRange(20, 10, 20, "name");
94+
}
95+
96+
[Fact]
97+
public void ShouldNotThrowForBetweenMinimumAndMaximum()
98+
{
99+
Guard.ArgumentInRange(12, 10, 20, "name");
100+
}
101+
102+
[Fact]
103+
public void ShouldThrowForLessThanMinimumNoMaximum()
104+
{
105+
Assert.Throws<ArgumentOutOfRangeException>(() => Guard.ArgumentInRange(2, 10, "name"));
106+
}
107+
108+
[Fact]
109+
public void ShouldThrowForLessThanMinimumWithMaximum()
110+
{
111+
Assert.Throws<ArgumentOutOfRangeException>(() => Guard.ArgumentInRange(2, 10, 20, "name"));
112+
}
113+
114+
[Fact]
115+
public void ShouldThrowForGreaterThanMaximum()
116+
{
117+
Assert.Throws<ArgumentOutOfRangeException>(() => Guard.ArgumentInRange(22, 10, 20, "name"));
118+
}
119+
}
120+
}
121+
}

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\GitServiceTests.cs" />
182182
<None Include="GitHub.Exports\VSServicesTests.cs" />
183183
<Compile Include="GitHub.Exports\SimpleRepositoryModelTests.cs" />
184+
<Compile Include="GitHub.Extensions\GuardTests.cs" />
184185
<Compile Include="GitHub.Extensions\UriExtensionTests.cs" />
185186
<Compile Include="GitHub.Primitives\UriStringTests.cs" />
186187
<Compile Include="GitHub.UI\Converters.cs" />

0 commit comments

Comments
 (0)