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

Commit 8ca54d7

Browse files
authored
Merge pull request #1418 from github/task/convert-unit-tests-to-nunit
Move Unit.Tests to nunit
2 parents cf66e90 + 7dedb6a commit 8ca54d7

File tree

60 files changed

+1154
-1620
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1154
-1620
lines changed

scripts/Run-XUnit.ps1

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

scripts/test.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ if (!$?) {
4747
}
4848

4949
Write-Output "Running UnitTests..."
50-
Run-XUnit test UnitTests $TimeoutDuration $config -AppVeyor:$AppVeyor
50+
Run-NUnit test UnitTests $TimeoutDuration $config -AppVeyor:$AppVeyor
5151
if (!$?) {
5252
$exitcode = 3
5353
}

test/UnitTests/GitHub.Api/LoginManagerTests.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using GitHub.Primitives;
66
using NSubstitute;
77
using Octokit;
8-
using Xunit;
8+
using NUnit.Framework;
99

1010
public class LoginManagerTests
1111
{
@@ -14,7 +14,7 @@ public class LoginManagerTests
1414

1515
public class TheLoginMethod
1616
{
17-
[Fact]
17+
[Test]
1818
public async Task LoginTokenIsSavedToCache()
1919
{
2020
var client = Substitute.For<IGitHubClient>();
@@ -30,7 +30,7 @@ public async Task LoginTokenIsSavedToCache()
3030
await keychain.Received().Save("foo", "123abc", host);
3131
}
3232

33-
[Fact]
33+
[Test]
3434
public async Task LoggedInUserIsReturned()
3535
{
3636
var client = Substitute.For<IGitHubClient>();
@@ -45,10 +45,10 @@ public async Task LoggedInUserIsReturned()
4545
var target = new LoginManager(keychain, tfa, "id", "secret");
4646
var result = await target.Login(host, client, "foo", "bar");
4747

48-
Assert.Same(user, result);
48+
Assert.That(user, Is.SameAs(result));
4949
}
5050

51-
[Fact]
51+
[Test]
5252
public async Task DeletesExistingAuthenticationIfNullTokenReturned()
5353
{
5454
// If GetOrCreateApplicationAuthentication is called and a matching token already exists,
@@ -73,7 +73,7 @@ public async Task DeletesExistingAuthenticationIfNullTokenReturned()
7373
await keychain.Received().Save("foo", "123abc", host);
7474
}
7575

76-
[Fact]
76+
[Test]
7777
public async Task TwoFactorExceptionIsPassedToHandler()
7878
{
7979
var client = Substitute.For<IGitHubClient>();
@@ -98,7 +98,7 @@ await client.Authorization.Received().GetOrCreateApplicationAuthentication(
9898
"123456");
9999
}
100100

101-
[Fact]
101+
[Test]
102102
public async Task Failed2FACodeResultsInRetry()
103103
{
104104
var client = Substitute.For<IGitHubClient>();
@@ -132,7 +132,7 @@ await client.Authorization.Received(1).GetOrCreateApplicationAuthentication(
132132
"123456");
133133
}
134134

135-
[Fact]
135+
[Test]
136136
public async Task HandlerNotifiedOfExceptionIn2FAChallengeResponse()
137137
{
138138
var client = Substitute.For<IGitHubClient>();
@@ -163,7 +163,7 @@ await client.Authorization.Received(1).GetOrCreateApplicationAuthentication(
163163
tfa.Value.Received(1).ChallengeFailed(loginAttemptsException);
164164
}
165165

166-
[Fact]
166+
[Test]
167167
public async Task RequestResendCodeResultsInRetryingLogin()
168168
{
169169
var client = Substitute.For<IGitHubClient>();
@@ -188,7 +188,7 @@ public async Task RequestResendCodeResultsInRetryingLogin()
188188
await client.Authorization.Received(2).GetOrCreateApplicationAuthentication("id", "secret", Arg.Any<NewAuthorization>());
189189
}
190190

191-
[Fact]
191+
[Test]
192192
public async Task UsesUsernameAndPasswordInsteadOfAuthorizationTokenWhenEnterpriseAndAPIReturns404()
193193
{
194194
var client = Substitute.For<IGitHubClient>();
@@ -210,7 +210,7 @@ public async Task UsesUsernameAndPasswordInsteadOfAuthorizationTokenWhenEnterpri
210210
await keychain.Received().Save("foo", "bar", enterprise);
211211
}
212212

213-
[Fact]
213+
[Test]
214214
public async Task ErasesLoginWhenUnauthorized()
215215
{
216216
var client = Substitute.For<IGitHubClient>();
@@ -223,12 +223,12 @@ public async Task ErasesLoginWhenUnauthorized()
223223
var tfa = new Lazy<ITwoFactorChallengeHandler>(() => Substitute.For<ITwoFactorChallengeHandler>());
224224

225225
var target = new LoginManager(keychain, tfa, "id", "secret");
226-
await Assert.ThrowsAsync<AuthorizationException>(async () => await target.Login(enterprise, client, "foo", "bar"));
226+
Assert.ThrowsAsync<AuthorizationException>(async () => await target.Login(enterprise, client, "foo", "bar"));
227227

228228
await keychain.Received().Delete(enterprise);
229229
}
230230

231-
[Fact]
231+
[Test]
232232
public async Task ErasesLoginWhenNonOctokitExceptionThrown()
233233
{
234234
var client = Substitute.For<IGitHubClient>();
@@ -241,12 +241,12 @@ public async Task ErasesLoginWhenNonOctokitExceptionThrown()
241241
var tfa = new Lazy<ITwoFactorChallengeHandler>(() => Substitute.For<ITwoFactorChallengeHandler>());
242242

243243
var target = new LoginManager(keychain, tfa, "id", "secret");
244-
await Assert.ThrowsAsync<InvalidOperationException>(async () => await target.Login(host, client, "foo", "bar"));
244+
Assert.ThrowsAsync<InvalidOperationException>(async () => await target.Login(host, client, "foo", "bar"));
245245

246246
await keychain.Received().Delete(host);
247247
}
248248

249-
[Fact]
249+
[Test]
250250
public async Task ErasesLoginWhenNonOctokitExceptionThrownIn2FA()
251251
{
252252
var client = Substitute.For<IGitHubClient>();
@@ -264,7 +264,7 @@ public async Task ErasesLoginWhenNonOctokitExceptionThrownIn2FA()
264264
tfa.Value.HandleTwoFactorException(exception).Returns(new TwoFactorChallengeResult("123456"));
265265

266266
var target = new LoginManager(keychain, tfa, "id", "secret");
267-
await Assert.ThrowsAsync<InvalidOperationException>(async () => await target.Login(host, client, "foo", "bar"));
267+
Assert.ThrowsAsync<InvalidOperationException>(async() => await target.Login(host, client, "foo", "bar"));
268268

269269
await keychain.Received().Delete(host);
270270
}

test/UnitTests/GitHub.Api/SimpleApiClientFactoryTests.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
using GitHub.Services;
66
using GitHub.VisualStudio;
77
using NSubstitute;
8-
using Xunit;
8+
using NUnit.Framework;
99

1010
public class SimpleApiClientFactoryTests
1111
{
1212
public class TheCreateMethod
1313
{
14-
[Fact]
14+
[Test]
1515
public async Task CreatesNewInstanceOfSimpleApiClient()
1616
{
1717
const string url = "https://github.com/github/CreatesNewInstanceOfSimpleApiClient";
@@ -27,15 +27,15 @@ public async Task CreatesNewInstanceOfSimpleApiClient()
2727

2828
var client = await factory.Create(url);
2929

30-
Assert.Equal(url, client.OriginalUrl);
31-
Assert.Equal(HostAddress.GitHubDotComHostAddress, client.HostAddress);
32-
Assert.Same(client, await factory.Create(url)); // Tests caching.
30+
Assert.That(url, Is.EqualTo(client.OriginalUrl));
31+
Assert.That(HostAddress.GitHubDotComHostAddress, Is.EqualTo(client.HostAddress));
32+
Assert.That(client,Is.SameAs(await factory.Create(url))); // Tests caching.
3333
}
3434
}
3535

3636
public class TheClearFromCacheMethod
3737
{
38-
[Fact]
38+
[Test]
3939
public async Task RemovesClientFromCache()
4040
{
4141
const string url = "https://github.com/github/RemovesClientFromCache";
@@ -51,7 +51,7 @@ public async Task RemovesClientFromCache()
5151
var client = await factory.Create(url);
5252
factory.ClearFromCache(client);
5353

54-
Assert.NotSame(client, factory.Create(url));
54+
Assert.That(client, Is.Not.SameAs(factory.Create(url)));
5555
}
5656
}
5757

test/UnitTests/GitHub.Api/SimpleApiClientTests.cs

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using GitHub.Services;
66
using NSubstitute;
77
using Octokit;
8-
using Xunit;
8+
using NUnit.Framework;
99
using EnterpriseProbeResult = GitHub.Services.EnterpriseProbeResult;
1010

1111
public class SimpleApiClientTests
@@ -21,7 +21,7 @@ public void Throws()
2121

2222
public class TheGetRepositoryMethod
2323
{
24-
[Fact]
24+
[Test]
2525
public async Task RetrievesRepositoryFromWeb()
2626
{
2727
var gitHubHost = HostAddress.GitHubDotComHostAddress;
@@ -38,10 +38,10 @@ public async Task RetrievesRepositoryFromWeb()
3838

3939
var result = await client.GetRepository();
4040

41-
Assert.Equal(42, result.Id);
41+
Assert.That(42, Is.EqualTo(result.Id));
4242
}
4343

44-
[Fact]
44+
[Test]
4545
public async Task RetrievesCachedRepositoryForSubsequentCalls()
4646
{
4747
var gitHubHost = HostAddress.GitHubDotComHostAddress;
@@ -60,16 +60,15 @@ public async Task RetrievesCachedRepositoryForSubsequentCalls()
6060

6161
var result = await client.GetRepository();
6262

63-
Assert.Equal(42, result.Id);
63+
Assert.That(42, Is.EqualTo(result.Id));
6464
}
6565
}
6666

6767
public class TheHasWikiMethod
6868
{
69-
[Theory]
70-
[InlineData(WikiProbeResult.Ok, true)]
71-
[InlineData(WikiProbeResult.Failed, false)]
72-
[InlineData(WikiProbeResult.NotFound, false)]
69+
[TestCase(WikiProbeResult.Ok, true)]
70+
[TestCase(WikiProbeResult.Failed, false)]
71+
[TestCase(WikiProbeResult.NotFound, false)]
7372
public async Task ReturnsTrueWhenWikiProbeReturnsOk(WikiProbeResult probeResult, bool expected)
7473
{
7574
var gitHubHost = HostAddress.GitHubDotComHostAddress;
@@ -89,11 +88,11 @@ public async Task ReturnsTrueWhenWikiProbeReturnsOk(WikiProbeResult probeResult,
8988

9089
var result = client.HasWiki();
9190

92-
Assert.Equal(expected, result);
93-
Assert.Equal(expected, client.HasWiki());
91+
Assert.That(expected, Is.EqualTo(result));
92+
Assert.That(expected, Is.EqualTo(client.HasWiki()));
9493
}
9594

96-
[Fact]
95+
[Test]
9796
public void ReturnsFalseWhenWeHaveNotRequestedRepository()
9897
{
9998
var gitHubHost = HostAddress.GitHubDotComHostAddress;
@@ -114,10 +113,9 @@ public void ReturnsFalseWhenWeHaveNotRequestedRepository()
114113

115114
public class TheIsEnterpriseMethod
116115
{
117-
[Theory]
118-
[InlineData(EnterpriseProbeResult.Ok, true)]
119-
[InlineData(EnterpriseProbeResult.Failed, false)]
120-
[InlineData(EnterpriseProbeResult.NotFound, false)]
116+
[TestCase(EnterpriseProbeResult.Ok, true)]
117+
[TestCase(EnterpriseProbeResult.Failed, false)]
118+
[TestCase(EnterpriseProbeResult.NotFound, false)]
121119
public async Task ReturnsTrueWhenEnterpriseProbeReturnsOk(EnterpriseProbeResult probeResult, bool expected)
122120
{
123121
var gitHubHost = HostAddress.GitHubDotComHostAddress;
@@ -137,11 +135,11 @@ public async Task ReturnsTrueWhenEnterpriseProbeReturnsOk(EnterpriseProbeResult
137135

138136
var result = client.IsEnterprise();
139137

140-
Assert.Equal(expected, result);
141-
Assert.Equal(expected, client.IsEnterprise());
138+
Assert.That(expected, Is.EqualTo(result));
139+
Assert.That(expected, Is.EqualTo(client.IsEnterprise()));
142140
}
143141

144-
[Fact]
142+
[Test]
145143
public void ReturnsFalseWhenWeHaveNotRequestedRepository()
146144
{
147145
var gitHubHost = HostAddress.GitHubDotComHostAddress;
@@ -162,7 +160,7 @@ public void ReturnsFalseWhenWeHaveNotRequestedRepository()
162160

163161
public class TheIsIsAuthenticatedMethod
164162
{
165-
[Fact]
163+
[Test]
166164
public void ReturnsFalseWhenCredentialsNotSet()
167165
{
168166
var gitHubClient = Substitute.For<IGitHubClient>();
@@ -178,7 +176,7 @@ public void ReturnsFalseWhenCredentialsNotSet()
178176
Assert.False(result);
179177
}
180178

181-
[Fact]
179+
[Test]
182180
public void ReturnsFalseWhenAuthenicationTypeIsAnonymous()
183181
{
184182
var connection = Substitute.For<IConnection>();
@@ -197,7 +195,7 @@ public void ReturnsFalseWhenAuthenicationTypeIsAnonymous()
197195
Assert.False(result);
198196
}
199197

200-
[Fact]
198+
[Test]
201199
public void ReturnsTrueWhenLoginIsSetToBasicAuth()
202200
{
203201
var connection = Substitute.For<IConnection>();
@@ -216,7 +214,7 @@ public void ReturnsTrueWhenLoginIsSetToBasicAuth()
216214
Assert.True(result);
217215
}
218216

219-
[Fact]
217+
[Test]
220218
public void ReturnsTrueWhenLoginIsSetToOAuth()
221219
{
222220
var connection = Substitute.For<IConnection>();

0 commit comments

Comments
 (0)