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

Commit 783429b

Browse files
committed
Added unit tests for Guard,
1 parent dec2c12 commit 783429b

File tree

2 files changed

+122
-0
lines changed

2 files changed

+122
-0
lines changed
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)