Skip to content

Commit

Permalink
Remove use of .Wait() from tests
Browse files Browse the repository at this point in the history
  • Loading branch information
haacked committed Nov 6, 2013
1 parent 920b911 commit 3c3feba
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ public async Task ReturnsSpecifiedMilestone()
}

[IntegrationTest]
public void ReturnsAllMilestones()
public async Task ReturnsAllMilestones()
{
var github = new GitHubClient(new ProductHeaderValue("OctokitTests"))
{
Credentials = Helper.Credentials
};
var client = new ObservableMilestonesClient(github);
var milestones = client.GetForRepository("libgit2", "libgit2sharp", new MilestoneRequest { State = ItemState.Closed }).ToList().Wait();
var milestones = await client.GetForRepository("libgit2", "libgit2sharp", new MilestoneRequest { State = ItemState.Closed }).ToList();

Assert.NotEmpty(milestones);
Assert.True(milestones.All(m => m.State == ItemState.Closed));
Expand Down
26 changes: 12 additions & 14 deletions Octokit.Tests/Reactive/ObservableIssuesClientTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NSubstitute;
using Octokit;
using Octokit.Internal;
using Octokit.Reactive;
using Octokit.Tests.Helpers;
Expand All @@ -8,8 +9,6 @@
using System.Threading.Tasks;
using Xunit;

namespace Octokit.Tests.Reactive
{
public class ObservableIssuesClientTests
{
public class TheGetMethod
Expand Down Expand Up @@ -40,7 +39,7 @@ public async Task EnsuresNonNullArguments()
public class TheGetForRepositoryMethod
{
[Fact]
public void ReturnsEveryPageOfIssues()
public async Task ReturnsEveryPageOfIssues()
{
var firstPageUrl = new Uri("repos/fake/repo/issues", UriKind.Relative);
var secondPageUrl = new Uri("https://example.com/page/2");
Expand Down Expand Up @@ -89,7 +88,7 @@ public void ReturnsEveryPageOfIssues()
.Returns(Task.Factory.StartNew<IResponse<List<Issue>>>(() => lastPageResponse));
var client = new ObservableIssuesClient(gitHubClient);

var results = client.GetForRepository("fake", "repo").ToArray().Wait();
var results = await client.GetForRepository("fake", "repo").ToArray();

Assert.Equal(7, results.Length);
Assert.Equal(firstPageResponse.BodyAsObject[0].Number, results[0].Number);
Expand All @@ -101,7 +100,7 @@ public void ReturnsEveryPageOfIssues()
public class TheGetAllForOwnedAndMemberRepositoriesMethod
{
[Fact]
public void ReturnsEveryPageOfIssues()
public async Task ReturnsEveryPageOfIssues()
{
var firstPageUrl = new Uri("user/issues", UriKind.Relative);
var secondPageUrl = new Uri("https://example.com/page/2");
Expand Down Expand Up @@ -150,7 +149,7 @@ public void ReturnsEveryPageOfIssues()
.Returns(Task.Factory.StartNew<IResponse<List<Issue>>>(() => lastPageResponse));
var client = new ObservableIssuesClient(gitHubClient);

var results = client.GetAllForOwnedAndMemberRepositories().ToArray().Wait();
var results = await client.GetAllForOwnedAndMemberRepositories().ToArray();

Assert.Equal(7, results.Length);
Assert.Equal(firstPageResponse.BodyAsObject[0].Number, results[0].Number);
Expand All @@ -162,7 +161,7 @@ public void ReturnsEveryPageOfIssues()
public class TheGetAllForOrganizationMethod
{
[Fact]
public void ReturnsEveryPageOfIssues()
public async Task ReturnsEveryPageOfIssues()
{
var firstPageUrl = new Uri("orgs/test/issues", UriKind.Relative);
var secondPageUrl = new Uri("https://example.com/page/2");
Expand Down Expand Up @@ -211,7 +210,7 @@ public void ReturnsEveryPageOfIssues()
.Returns(Task.Factory.StartNew<IResponse<List<Issue>>>(() => lastPageResponse));
var client = new ObservableIssuesClient(gitHubClient);

var results = client.GetAllForOrganization("test").ToArray().Wait();
var results = await client.GetAllForOrganization("test").ToArray();

Assert.Equal(7, results.Length);
Assert.Equal(firstPageResponse.BodyAsObject[0].Number, results[0].Number);
Expand All @@ -223,7 +222,7 @@ public void ReturnsEveryPageOfIssues()
public class TheGetAllForCurrentMethod
{
[Fact]
public void ReturnsEveryPageOfIssues()
public async Task ReturnsEveryPageOfIssues()
{
var firstPageUrl = new Uri("issues", UriKind.Relative);
var secondPageUrl = new Uri("https://example.com/page/2");
Expand Down Expand Up @@ -272,7 +271,7 @@ public void ReturnsEveryPageOfIssues()
.Returns(Task.Factory.StartNew<IResponse<List<Issue>>>(() => lastPageResponse));
var client = new ObservableIssuesClient(gitHubClient);

var results = client.GetAllForCurrent().ToArray().Wait();
var results = await client.GetAllForCurrent().ToArray();

Assert.Equal(7, results.Length);
Assert.Equal(firstPageResponse.BodyAsObject[0].Number, results[0].Number);
Expand Down Expand Up @@ -319,13 +318,13 @@ public class TheUpdateMethod
[Fact]
public void UpdatesClientIssueIssue()
{
var IssueUpdate = new IssueUpdate();
var issueUpdate = new IssueUpdate();
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableIssuesClient(gitHubClient);

client.Update("fake", "repo", 42, IssueUpdate);
client.Update("fake", "repo", 42, issueUpdate);

gitHubClient.Issue.Received().Update("fake", "repo", 42, IssueUpdate);
gitHubClient.Issue.Received().Update("fake", "repo", 42, issueUpdate);
}

[Fact]
Expand Down Expand Up @@ -361,4 +360,3 @@ static ApiInfo CreateApiInfo(IDictionary<string, Uri> links)
return new ApiInfo(links, new List<string>(), new List<string>(), "etag", new RateLimit(new Dictionary<string, string>()));
}
}
}
8 changes: 4 additions & 4 deletions Octokit.Tests/Reactive/ObservableMilestonesClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public async Task EnsuresNonNullArguments()
public class TheGetForRepositoryMethod
{
[Fact]
public void ReturnsEveryPageOfMilestones()
public async Task ReturnsEveryPageOfMilestones()
{
var firstPageUrl = new Uri("repos/fake/repo/milestones", UriKind.Relative);
var secondPageUrl = new Uri("https://example.com/page/2");
Expand Down Expand Up @@ -85,7 +85,7 @@ public void ReturnsEveryPageOfMilestones()
.Returns(Task.Factory.StartNew<IResponse<List<Milestone>>>(() => lastPageResponse));
var client = new ObservableMilestonesClient(gitHubClient);

var results = client.GetForRepository("fake", "repo").ToArray().Wait();
var results = await client.GetForRepository("fake", "repo").ToArray();

Assert.Equal(7, results.Length);
Assert.Equal(firstPageResponse.BodyAsObject[0].Number, results[0].Number);
Expand All @@ -94,7 +94,7 @@ public void ReturnsEveryPageOfMilestones()
}

[Fact]
public void SendsAppropriateParameters()
public async Task SendsAppropriateParameters()
{
var firstPageUrl = new Uri("repos/fake/repo/milestones", UriKind.Relative);
var secondPageUrl = new Uri("https://example.com/page/2");
Expand Down Expand Up @@ -142,7 +142,7 @@ public void SendsAppropriateParameters()
.Returns(Task.Factory.StartNew<IResponse<List<Milestone>>>(() => lastPageResponse));
var client = new ObservableMilestonesClient(gitHubClient);

var results = client.GetForRepository("fake", "repo", new MilestoneRequest { SortDirection = SortDirection.Descending }).ToArray().Wait();
var results = await client.GetForRepository("fake", "repo", new MilestoneRequest { SortDirection = SortDirection.Descending }).ToArray();

Assert.Equal(7, results.Length);
Assert.Equal(firstPageResponse.BodyAsObject[0].Number, results[0].Number);
Expand Down
8 changes: 4 additions & 4 deletions Octokit.Tests/Reactive/ObservableRepositoriesClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public async Task IsALukeWarmObservable()
public class TheGetAllForCurrentMethod
{
[Fact]
public void ReturnsEveryPageOfRepositories()
public async Task ReturnsEveryPageOfRepositories()
{
var firstPageUrl = new Uri("user/repos", UriKind.Relative);
var secondPageUrl = new Uri("https://example.com/page/2");
Expand Down Expand Up @@ -87,7 +87,7 @@ public void ReturnsEveryPageOfRepositories()
.Returns(Task.Factory.StartNew<IResponse<List<Repository>>>(() => lastPageResponse));
var repositoriesClient = new ObservableRepositoriesClient(gitHubClient);

var results = repositoriesClient.GetAllForCurrent().ToArray().Wait();
var results = await repositoriesClient.GetAllForCurrent().ToArray();

Assert.Equal(7, results.Length);
gitHubClient.Connection.Received(1).GetAsync<List<Repository>>(firstPageUrl, null, null);
Expand All @@ -96,7 +96,7 @@ public void ReturnsEveryPageOfRepositories()
}

[Fact]
public void StopsMakingNewRequestsWhenTakeIsFulfilled()
public async Task StopsMakingNewRequestsWhenTakeIsFulfilled()
{
var firstPageUrl = new Uri("user/repos", UriKind.Relative);
var secondPageUrl = new Uri("https://example.com/page/2");
Expand Down Expand Up @@ -152,7 +152,7 @@ public void StopsMakingNewRequestsWhenTakeIsFulfilled()
.Returns(Task.Factory.StartNew<IResponse<List<Repository>>>(() => lastPageResponse));
var repositoriesClient = new ObservableRepositoriesClient(gitHubClient);

var results = repositoriesClient.GetAllForCurrent().Take(4).ToArray().Wait();
var results = await repositoriesClient.GetAllForCurrent().Take(4).ToArray();

Assert.Equal(4, results.Length);
gitHubClient.Connection.Received(1).GetAsync<List<Repository>>(firstPageUrl, null, null);
Expand Down

0 comments on commit 3c3feba

Please sign in to comment.