From 3c3febaf7749f257ef7104ca20373a0cc6f0d66d Mon Sep 17 00:00:00 2001 From: Haacked Date: Tue, 5 Nov 2013 16:02:33 -0800 Subject: [PATCH] Remove use of .Wait() from tests --- .../ObservableMilestonesClientTests.cs | 4 +-- .../Reactive/ObservableIssuesClientTests.cs | 26 +++++++++---------- .../ObservableMilestonesClientTests.cs | 8 +++--- .../ObservableRepositoriesClientTests.cs | 8 +++--- 4 files changed, 22 insertions(+), 24 deletions(-) diff --git a/Octokit.Tests.Integration/Reactive/ObservableMilestonesClientTests.cs b/Octokit.Tests.Integration/Reactive/ObservableMilestonesClientTests.cs index 2b28cd6fdc..ab7f232dbc 100644 --- a/Octokit.Tests.Integration/Reactive/ObservableMilestonesClientTests.cs +++ b/Octokit.Tests.Integration/Reactive/ObservableMilestonesClientTests.cs @@ -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)); diff --git a/Octokit.Tests/Reactive/ObservableIssuesClientTests.cs b/Octokit.Tests/Reactive/ObservableIssuesClientTests.cs index 0814934d59..8e2fef8379 100644 --- a/Octokit.Tests/Reactive/ObservableIssuesClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableIssuesClientTests.cs @@ -1,4 +1,5 @@ using NSubstitute; +using Octokit; using Octokit.Internal; using Octokit.Reactive; using Octokit.Tests.Helpers; @@ -8,8 +9,6 @@ using System.Threading.Tasks; using Xunit; -namespace Octokit.Tests.Reactive -{ public class ObservableIssuesClientTests { public class TheGetMethod @@ -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"); @@ -89,7 +88,7 @@ public void ReturnsEveryPageOfIssues() .Returns(Task.Factory.StartNew>>(() => 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); @@ -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"); @@ -150,7 +149,7 @@ public void ReturnsEveryPageOfIssues() .Returns(Task.Factory.StartNew>>(() => 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); @@ -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"); @@ -211,7 +210,7 @@ public void ReturnsEveryPageOfIssues() .Returns(Task.Factory.StartNew>>(() => 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); @@ -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"); @@ -272,7 +271,7 @@ public void ReturnsEveryPageOfIssues() .Returns(Task.Factory.StartNew>>(() => 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); @@ -319,13 +318,13 @@ public class TheUpdateMethod [Fact] public void UpdatesClientIssueIssue() { - var IssueUpdate = new IssueUpdate(); + var issueUpdate = new IssueUpdate(); var gitHubClient = Substitute.For(); 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] @@ -361,4 +360,3 @@ static ApiInfo CreateApiInfo(IDictionary links) return new ApiInfo(links, new List(), new List(), "etag", new RateLimit(new Dictionary())); } } -} diff --git a/Octokit.Tests/Reactive/ObservableMilestonesClientTests.cs b/Octokit.Tests/Reactive/ObservableMilestonesClientTests.cs index baa18f3098..d0216d85e0 100644 --- a/Octokit.Tests/Reactive/ObservableMilestonesClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableMilestonesClientTests.cs @@ -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"); @@ -85,7 +85,7 @@ public void ReturnsEveryPageOfMilestones() .Returns(Task.Factory.StartNew>>(() => 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); @@ -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"); @@ -142,7 +142,7 @@ public void SendsAppropriateParameters() .Returns(Task.Factory.StartNew>>(() => 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); diff --git a/Octokit.Tests/Reactive/ObservableRepositoriesClientTests.cs b/Octokit.Tests/Reactive/ObservableRepositoriesClientTests.cs index dbbe60bfc0..c48ceb0eea 100644 --- a/Octokit.Tests/Reactive/ObservableRepositoriesClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableRepositoriesClientTests.cs @@ -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"); @@ -87,7 +87,7 @@ public void ReturnsEveryPageOfRepositories() .Returns(Task.Factory.StartNew>>(() => 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>(firstPageUrl, null, null); @@ -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"); @@ -152,7 +152,7 @@ public void StopsMakingNewRequestsWhenTakeIsFulfilled() .Returns(Task.Factory.StartNew>>(() => 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>(firstPageUrl, null, null);