diff --git a/Octokit.Tests/Clients/AssigneesClientTests.cs b/Octokit.Tests/Clients/AssigneesClientTests.cs index 84731319e1..738e3eb006 100644 --- a/Octokit.Tests/Clients/AssigneesClientTests.cs +++ b/Octokit.Tests/Clients/AssigneesClientTests.cs @@ -114,11 +114,10 @@ public class TheCheckAssigneeMethod [InlineData(HttpStatusCode.NotFound, false)] public async Task RequestsCorrectValueForStatusCode(HttpStatusCode status, bool expected) { - var response = Task.Factory.StartNew>(() => - new ApiResponse(new Response(status, null, new Dictionary(), "application/json"))); + var responseTask = TestSetup.GetApiResponse(status); var connection = Substitute.For(); connection.Get(Arg.Is(u => u.ToString() == "repos/foo/bar/assignees/cody"), - null, null).Returns(response); + null, null).Returns(responseTask); var apiConnection = Substitute.For(); apiConnection.Connection.Returns(connection); var client = new AssigneesClient(apiConnection); @@ -133,11 +132,12 @@ public async Task RequestsCorrectValueForStatusCode(HttpStatusCode status, bool [InlineData(HttpStatusCode.NotFound, false)] public async Task RequestsCorrectValueForStatusCodeWithRepositoryId(HttpStatusCode status, bool expected) { - var response = Task.Factory.StartNew>(() => - new ApiResponse(new Response(status, null, new Dictionary(), "application/json"))); + var responseTask = TestSetup.GetApiResponse(status); + var connection = Substitute.For(); - connection.Get(Arg.Is(u => u.ToString() == "repositories/1/assignees/cody"), - null, null).Returns(response); + connection.Get(Arg.Is(u => u.ToString() == "repositories/1/assignees/cody"), null, null) + .Returns(responseTask); + var apiConnection = Substitute.For(); apiConnection.Connection.Returns(connection); var client = new AssigneesClient(apiConnection); @@ -150,11 +150,12 @@ public async Task RequestsCorrectValueForStatusCodeWithRepositoryId(HttpStatusCo [Fact] public async Task ThrowsExceptionForInvalidStatusCode() { - var response = Task.Factory.StartNew>(() => - new ApiResponse(new Response(HttpStatusCode.Conflict, null, new Dictionary(), "application/json"))); + var responseTask = TestSetup.GetApiResponse(HttpStatusCode.Conflict); + var connection = Substitute.For(); - connection.Get(Arg.Is(u => u.ToString() == "repos/foo/bar/assignees/cody"), - null, null).Returns(response); + connection.Get(Arg.Is(u => u.ToString() == "repos/foo/bar/assignees/cody"), null, null) + .Returns(responseTask); + var apiConnection = Substitute.For(); apiConnection.Connection.Returns(connection); var client = new AssigneesClient(apiConnection); @@ -165,11 +166,11 @@ public async Task ThrowsExceptionForInvalidStatusCode() [Fact] public async Task ThrowsExceptionForInvalidStatusCodeWithRepositoryId() { - var response = Task.Factory.StartNew>(() => - new ApiResponse(new Response(HttpStatusCode.Conflict, null, new Dictionary(), "application/json"))); + var response = new Response(HttpStatusCode.Conflict, null, new Dictionary(), "application/json"); + var responseTask = Task.FromResult>(new ApiResponse(response)); var connection = Substitute.For(); connection.Get(Arg.Is(u => u.ToString() == "repositories/1/assignees/cody"), - null, null).Returns(response); + null, null).Returns(responseTask); var apiConnection = Substitute.For(); apiConnection.Connection.Returns(connection); var client = new AssigneesClient(apiConnection); diff --git a/Octokit.Tests/Clients/AuthorizationsClientTests.cs b/Octokit.Tests/Clients/AuthorizationsClientTests.cs index f9fe594138..b442c627ec 100644 --- a/Octokit.Tests/Clients/AuthorizationsClientTests.cs +++ b/Octokit.Tests/Clients/AuthorizationsClientTests.cs @@ -173,12 +173,12 @@ public async Task UsesCallbackToRetrieveTwoFactorCode() "secret", Arg.Any(), "two-factor-code") - .Returns(Task.Factory.StartNew(() => new ApplicationAuthorization(0, null, null, null, null, null, null, null, DateTimeOffset.Now, DateTimeOffset.Now, null, "xyz"))); + .Returns(Task.FromResult(new ApplicationAuthorization(0, null, null, null, null, null, null, null, DateTimeOffset.Now, DateTimeOffset.Now, null, "xyz"))); var result = await client.GetOrCreateApplicationAuthentication("clientId", "secret", data, - e => Task.Factory.StartNew(() => twoFactorChallengeResult)); + e => Task.FromResult(twoFactorChallengeResult)); client.Received().GetOrCreateApplicationAuthentication("clientId", "secret", @@ -205,12 +205,12 @@ public async Task RetriesWhenResendRequested() "secret", Arg.Any(), "two-factor-code") - .Returns(Task.Factory.StartNew(() => new ApplicationAuthorization(0, null, null, null, null, null, null, null, DateTimeOffset.Now, DateTimeOffset.Now, null, "OAUTHSECRET"))); + .Returns(Task.FromResult(new ApplicationAuthorization(0, null, null, null, null, null, null, null, DateTimeOffset.Now, DateTimeOffset.Now, null, "OAUTHSECRET"))); var result = await client.GetOrCreateApplicationAuthentication("clientId", "secret", data, - e => Task.Factory.StartNew(() => challengeResults.Dequeue())); + e => Task.FromResult(challengeResults.Dequeue())); client.Received(2).GetOrCreateApplicationAuthentication("clientId", "secret", @@ -245,7 +245,7 @@ public async Task ThrowsTwoFactorChallengeFailedExceptionWhenProvidedCodeIsIncor "clientId", "secret", data, - e => Task.Factory.StartNew(() => challengeResults.Dequeue()))); + e => Task.FromResult(challengeResults.Dequeue()))); Assert.NotNull(exception); client.Received().GetOrCreateApplicationAuthentication("clientId", diff --git a/Octokit.Tests/Clients/FollowersClientTests.cs b/Octokit.Tests/Clients/FollowersClientTests.cs index e279e1e25d..38aaf25f2f 100644 --- a/Octokit.Tests/Clients/FollowersClientTests.cs +++ b/Octokit.Tests/Clients/FollowersClientTests.cs @@ -9,7 +9,7 @@ namespace Octokit.Tests.Clients { /// - /// Client tests mostly just need to make sure they call the IApiConnection with the correct + /// Client tests mostly just need to make sure they call the IApiConnection with the correct /// relative Uri. No need to fake up the response. All *those* tests are in ApiConnectionTests.cs. /// public class FollowersClientTests @@ -204,11 +204,11 @@ public class TheIsFollowingForCurrentMethod [InlineData(HttpStatusCode.NotFound, false)] public async Task RequestsCorrectValueForStatusCode(HttpStatusCode status, bool expected) { - var response = Task.Factory.StartNew>(() => - new ApiResponse(new Response(status, null, new Dictionary(), "application/json"))); + var response = new Response(status, null, new Dictionary(), "application/json"); + var responseTask = Task.FromResult>(new ApiResponse(response)); var connection = Substitute.For(); connection.Get(Arg.Is(u => u.ToString() == "user/following/alfhenrik"), - null, null).Returns(response); + null, null).Returns(responseTask); var apiConnection = Substitute.For(); apiConnection.Connection.Returns(connection); var client = new FollowersClient(apiConnection); @@ -221,11 +221,11 @@ public async Task RequestsCorrectValueForStatusCode(HttpStatusCode status, bool [Fact] public async Task ThrowsExceptionForInvalidStatusCode() { - var response = Task.Factory.StartNew>(() => - new ApiResponse(new Response(HttpStatusCode.Conflict, null, new Dictionary(), "application/json"))); + var response = new Response(HttpStatusCode.Conflict, null, new Dictionary(), "application/json"); + var responseTask = Task.FromResult>(new ApiResponse(response)); var connection = Substitute.For(); connection.Get(Arg.Is(u => u.ToString() == "user/following/alfhenrik"), - null, null).Returns(response); + null, null).Returns(responseTask); var apiConnection = Substitute.For(); apiConnection.Connection.Returns(connection); var client = new FollowersClient(apiConnection); @@ -251,11 +251,11 @@ public class TheIsFollowingMethod [InlineData(HttpStatusCode.NotFound, false)] public async Task RequestsCorrectValueForStatusCode(HttpStatusCode status, bool expected) { - var response = Task.Factory.StartNew>(() => - new ApiResponse(new Response(status, null, new Dictionary(), "application/json"))); + var response = new Response(status, null, new Dictionary(), "application/json"); + var responseTask = Task.FromResult>(new ApiResponse(response)); var connection = Substitute.For(); connection.Get(Arg.Is(u => u.ToString() == "users/alfhenrik/following/alfhenrik-test"), - null, null).Returns(response); + null, null).Returns(responseTask); var apiConnection = Substitute.For(); apiConnection.Connection.Returns(connection); var client = new FollowersClient(apiConnection); @@ -268,11 +268,11 @@ public async Task RequestsCorrectValueForStatusCode(HttpStatusCode status, bool [Fact] public async Task ThrowsExceptionForInvalidStatusCode() { - var response = Task.Factory.StartNew>(() => - new ApiResponse(new Response(HttpStatusCode.Conflict, null, new Dictionary(), "application/json"))); + var response = new Response(HttpStatusCode.Conflict, null, new Dictionary(), "application/json"); + var responseTask = Task.FromResult>(new ApiResponse(response)); var connection = Substitute.For(); connection.Get(Arg.Is(u => u.ToString() == "users/alfhenrik/following/alfhenrik-test"), - null, null).Returns(response); + null, null).Returns(responseTask); var apiConnection = Substitute.For(); apiConnection.Connection.Returns(connection); var client = new FollowersClient(apiConnection); @@ -299,11 +299,13 @@ public class TheFollowMethod [InlineData(HttpStatusCode.NoContent, true)] public async Task RequestsCorrectValueForStatusCode(HttpStatusCode status, bool expected) { - var response = Task.Factory.StartNew>(() => - new ApiResponse(new Response(status, null, new Dictionary(), "application/json"))); + var response = new Response(status, null, new Dictionary(), "application/json"); + var responseTask = Task.FromResult>(new ApiResponse(response)); + var connection = Substitute.For(); - connection.Put(Arg.Is(u => u.ToString() == "user/following/alfhenrik"), - Args.Object).Returns(response); + connection.Put(Arg.Is(u => u.ToString() == "user/following/alfhenrik"), Args.Object) + .Returns(responseTask); + var apiConnection = Substitute.For(); apiConnection.Connection.Returns(connection); var client = new FollowersClient(apiConnection); @@ -316,11 +318,13 @@ public async Task RequestsCorrectValueForStatusCode(HttpStatusCode status, bool [Fact] public async Task ThrowsExceptionForInvalidStatusCode() { - var response = Task.Factory.StartNew>(() => - new ApiResponse(new Response(HttpStatusCode.Conflict, null, new Dictionary(), "application/json"))); + var response = new Response(HttpStatusCode.Conflict, null, new Dictionary(), "application/json"); + var responseTask = Task.FromResult>(new ApiResponse(response)); + var connection = Substitute.For(); - connection.Put(Arg.Is(u => u.ToString() == "user/following/alfhenrik"), - new { }).Returns(response); + connection.Put(Arg.Is(u => u.ToString() == "user/following/alfhenrik"), Args.Object) + .Returns(responseTask); + var apiConnection = Substitute.For(); apiConnection.Connection.Returns(connection); var client = new FollowersClient(apiConnection); diff --git a/Octokit.Tests/Clients/GistsClientTests.cs b/Octokit.Tests/Clients/GistsClientTests.cs index 3dceab8cdb..03920bf4af 100644 --- a/Octokit.Tests/Clients/GistsClientTests.cs +++ b/Octokit.Tests/Clients/GistsClientTests.cs @@ -499,11 +499,13 @@ public void RequestsCorrectUnstarUrl() [InlineData(HttpStatusCode.NotFound, false)] public async Task RequestsCorrectValueForStatusCode(HttpStatusCode status, bool expected) { - var response = Task.Factory.StartNew>(() => - new ApiResponse(new Response(status, null, new Dictionary(), "application/json"))); + var response = new Response(status, null, new Dictionary(), "application/json"); + var responseTask = Task.FromResult>(new ApiResponse(response)); + var connection = Substitute.For(); - connection.Get(Arg.Is(u => u.ToString() == "gists/1/star"), - null, null).Returns(response); + connection.Get(Arg.Is(u => u.ToString() == "gists/1/star"), null, null) + .Returns(responseTask); + var apiConnection = Substitute.For(); apiConnection.Connection.Returns(connection); var client = new GistsClient(apiConnection); @@ -516,11 +518,13 @@ public async Task RequestsCorrectValueForStatusCode(HttpStatusCode status, bool [Fact] public async Task ThrowsExceptionForInvalidStatusCode() { - var response = Task.Factory.StartNew>(() => - new ApiResponse(new Response(HttpStatusCode.Conflict, null, new Dictionary(), "application/json"))); + var response = new Response(HttpStatusCode.Conflict, null, new Dictionary(), "application/json"); + var responseTask = Task.FromResult>(new ApiResponse(response)); + var connection = Substitute.For(); - connection.Get(Arg.Is(u => u.ToString() == "gists/1/star"), - null, null).Returns(response); + connection.Get(Arg.Is(u => u.ToString() == "gists/1/star"), null, null) + .Returns(responseTask); + var apiConnection = Substitute.For(); apiConnection.Connection.Returns(connection); @@ -568,4 +572,4 @@ public void PostsToTheCorrectUrl() connection.Received().Patch(Arg.Is(u => u.ToString() == "gists/1"), Arg.Any()); } } -} \ No newline at end of file +} diff --git a/Octokit.Tests/Clients/OrganizationMembersClientTests.cs b/Octokit.Tests/Clients/OrganizationMembersClientTests.cs index d519c10611..b808c1666d 100644 --- a/Octokit.Tests/Clients/OrganizationMembersClientTests.cs +++ b/Octokit.Tests/Clients/OrganizationMembersClientTests.cs @@ -9,7 +9,7 @@ namespace Octokit.Tests.Clients { /// - /// Client tests mostly just need to make sure they call the IApiConnection with the correct + /// Client tests mostly just need to make sure they call the IApiConnection with the correct /// relative Uri. No need to fake up the response. All *those* tests are in ApiConnectionTests.cs. /// public class OrganizationMembersClientTests @@ -309,11 +309,13 @@ public class TheCheckMemberMethod [InlineData(HttpStatusCode.Found, false)] public async Task RequestsCorrectValueForStatusCode(HttpStatusCode status, bool expected) { - var response = Task.Factory.StartNew>(() => - new ApiResponse(new Response(status, null, new Dictionary(), "application/json"))); + var response = new Response(status, null, new Dictionary(), "application/json"); + var responseTask = Task.FromResult>(new ApiResponse(response)); + var connection = Substitute.For(); - connection.Get(Arg.Is(u => u.ToString() == "orgs/org/members/username"), - null, null).Returns(response); + connection.Get(Arg.Is(u => u.ToString() == "orgs/org/members/username"), null, null) + .Returns(responseTask); + var apiConnection = Substitute.For(); apiConnection.Connection.Returns(connection); var client = new OrganizationMembersClient(apiConnection); @@ -326,11 +328,13 @@ public async Task RequestsCorrectValueForStatusCode(HttpStatusCode status, bool [Fact] public async Task ThrowsExceptionForInvalidStatusCode() { - var response = Task.Factory.StartNew>(() => - new ApiResponse(new Response(HttpStatusCode.Conflict, null, new Dictionary(), "application/json"))); + var response = new Response(HttpStatusCode.Conflict, null, new Dictionary(), "application/json"); + var responseTask = Task.FromResult>(new ApiResponse(response)); + var connection = Substitute.For(); - connection.Get(Arg.Is(u => u.ToString() == "orgs/org/members/username"), - null, null).Returns(response); + connection.Get(Arg.Is(u => u.ToString() == "orgs/org/members/username"), null, null) + .Returns(responseTask); + var apiConnection = Substitute.For(); apiConnection.Connection.Returns(connection); var client = new OrganizationMembersClient(apiConnection); @@ -357,11 +361,13 @@ public class TheCheckMemberPublicMethod [InlineData(HttpStatusCode.NotFound, false)] public async Task RequestsCorrectValueForStatusCode(HttpStatusCode status, bool expected) { - var response = Task.Factory.StartNew>(() => - new ApiResponse(new Response(status, null, new Dictionary(), "application/json"))); + var response = new Response(status, null, new Dictionary(), "application/json"); + var responseTask = Task.FromResult>(new ApiResponse(response)); + var connection = Substitute.For(); - connection.Get(Arg.Is(u => u.ToString() == "orgs/org/public_members/username"), - null, null).Returns(response); + connection.Get(Arg.Is(u => u.ToString() == "orgs/org/public_members/username"), null, null) + .Returns(responseTask); + var apiConnection = Substitute.For(); apiConnection.Connection.Returns(connection); var client = new OrganizationMembersClient(apiConnection); @@ -374,11 +380,13 @@ public async Task RequestsCorrectValueForStatusCode(HttpStatusCode status, bool [Fact] public async Task ThrowsExceptionForInvalidStatusCode() { - var response = Task.Factory.StartNew>(() => - new ApiResponse(new Response(HttpStatusCode.Conflict, null, new Dictionary(), "application/json"))); + var response = new Response(HttpStatusCode.Conflict, null, new Dictionary(), "application/json"); + var responseTask = Task.FromResult>(new ApiResponse(response)); + var connection = Substitute.For(); - connection.Get(Arg.Is(u => u.ToString() == "orgs/org/public_members/username"), - null, null).Returns(response); + connection.Get(Arg.Is(u => u.ToString() == "orgs/org/public_members/username"), null, null) + .Returns(responseTask); + var apiConnection = Substitute.For(); apiConnection.Connection.Returns(connection); var client = new OrganizationMembersClient(apiConnection); @@ -429,11 +437,13 @@ public class ThePublicizeMethod [InlineData(HttpStatusCode.NoContent, true)] public async Task RequestsCorrectValueForStatusCode(HttpStatusCode status, bool expected) { - var response = Task.Factory.StartNew>(() => - new ApiResponse(new Response(status, null, new Dictionary(), "application/json"))); + var response = new Response(status, null, new Dictionary(), "application/json"); + var responseTask = Task.FromResult>(new ApiResponse(response)); + var connection = Substitute.For(); - connection.Put(Arg.Is(u => u.ToString() == "orgs/org/public_members/username"), - Args.Object).Returns(response); + connection.Put(Arg.Is(u => u.ToString() == "orgs/org/public_members/username"), Args.Object) + .Returns(responseTask); + var apiConnection = Substitute.For(); apiConnection.Connection.Returns(connection); var client = new OrganizationMembersClient(apiConnection); @@ -446,11 +456,13 @@ public async Task RequestsCorrectValueForStatusCode(HttpStatusCode status, bool [Fact] public async Task ThrowsExceptionForInvalidStatusCode() { - var response = Task.Factory.StartNew>(() => - new ApiResponse(new Response(HttpStatusCode.Conflict, null, new Dictionary(), "application/json"))); + var response = new Response(HttpStatusCode.Conflict, null, new Dictionary(), "application/json"); + var responseTask = Task.FromResult>(new ApiResponse(response)); + var connection = Substitute.For(); - connection.Put(Arg.Is(u => u.ToString() == "orgs/org/public_members/username"), - new { }).Returns(response); + connection.Put(Arg.Is(u => u.ToString() == "orgs/org/public_members/username"), Args.Object) + .Returns(responseTask); + var apiConnection = Substitute.For(); apiConnection.Connection.Returns(connection); var client = new OrganizationMembersClient(apiConnection); diff --git a/Octokit.Tests/Clients/RepoCollaboratorsClientTests.cs b/Octokit.Tests/Clients/RepoCollaboratorsClientTests.cs index 73f6b35fa4..d0e972c099 100644 --- a/Octokit.Tests/Clients/RepoCollaboratorsClientTests.cs +++ b/Octokit.Tests/Clients/RepoCollaboratorsClientTests.cs @@ -206,11 +206,12 @@ public class TheIsCollaboratorMethod [InlineData(HttpStatusCode.NotFound, false)] public async Task RequestsCorrectValueForStatusCode(HttpStatusCode status, bool expected) { - var response = Task.Factory.StartNew>(() => - new ApiResponse(new Response(status, null, new Dictionary(), "application/json"))); + var responseTask = TestSetup.GetApiResponse(status); + var connection = Substitute.For(); - connection.Get(Arg.Is(u => u.ToString() == "repos/owner/test/collaborators/user1"), - null, null).Returns(response); + connection.Get(Arg.Is(u => u.ToString() == "repos/owner/test/collaborators/user1"), null, null) + .Returns(responseTask); + var apiConnection = Substitute.For(); apiConnection.Connection.Returns(connection); var client = new RepoCollaboratorsClient(apiConnection); @@ -225,11 +226,12 @@ public async Task RequestsCorrectValueForStatusCode(HttpStatusCode status, bool [InlineData(HttpStatusCode.NotFound, false)] public async Task RequestsCorrectValueForStatusCodeWithRepositoryId(HttpStatusCode status, bool expected) { - var response = Task.Factory.StartNew>(() => - new ApiResponse(new Response(status, null, new Dictionary(), "application/json"))); + var responseTask = TestSetup.GetApiResponse(status); + var connection = Substitute.For(); - connection.Get(Arg.Is(u => u.ToString() == "repositories/1/collaborators/user1"), - null, null).Returns(response); + connection.Get(Arg.Is(u => u.ToString() == "repositories/1/collaborators/user1"), null, null) + .Returns(responseTask); + var apiConnection = Substitute.For(); apiConnection.Connection.Returns(connection); var client = new RepoCollaboratorsClient(apiConnection); @@ -242,11 +244,12 @@ public async Task RequestsCorrectValueForStatusCodeWithRepositoryId(HttpStatusCo [Fact] public async Task ThrowsExceptionForInvalidStatusCode() { - var response = Task.Factory.StartNew>(() => - new ApiResponse(new Response(HttpStatusCode.Conflict, null, new Dictionary(), "application/json"))); + var responseTask = TestSetup.GetApiResponse(HttpStatusCode.Conflict); + var connection = Substitute.For(); - connection.Get(Arg.Is(u => u.ToString() == "repos/foo/bar/assignees/cody"), - null, null).Returns(response); + connection.Get(Arg.Is(u => u.ToString() == "repos/foo/bar/assignees/cody"), null, null) + .Returns(responseTask); + var apiConnection = Substitute.For(); apiConnection.Connection.Returns(connection); var client = new RepoCollaboratorsClient(apiConnection); @@ -257,11 +260,12 @@ public async Task ThrowsExceptionForInvalidStatusCode() [Fact] public async Task ThrowsExceptionForInvalidStatusCodeWithRepositoryId() { - var response = Task.Factory.StartNew>(() => - new ApiResponse(new Response(HttpStatusCode.Conflict, null, new Dictionary(), "application/json"))); + var responseTask = TestSetup.GetApiResponse(HttpStatusCode.Conflict); + var connection = Substitute.For(); - connection.Get(Arg.Is(u => u.ToString() == "repositories/1/assignees/cody"), - null, null).Returns(response); + connection.Get(Arg.Is(u => u.ToString() == "repositories/1/assignees/cody"), null, null) + .Returns(responseTask); + var apiConnection = Substitute.For(); apiConnection.Connection.Returns(connection); var client = new RepoCollaboratorsClient(apiConnection); diff --git a/Octokit.Tests/Clients/StarredClientTests.cs b/Octokit.Tests/Clients/StarredClientTests.cs index 2685f61f6e..afae6812bf 100644 --- a/Octokit.Tests/Clients/StarredClientTests.cs +++ b/Octokit.Tests/Clients/StarredClientTests.cs @@ -505,11 +505,12 @@ public class TheCheckStarredMethod [InlineData(HttpStatusCode.NotFound, false)] public async Task ReturnsCorrectResultBasedOnStatus(HttpStatusCode status, bool expected) { - var response = Task.Factory.StartNew>(() => - new ApiResponse(new Response(status, null, new Dictionary(), "application/json"))); + var responseTask = TestSetup.GetApiResponse(status); + var connection = Substitute.For(); connection.Get(Arg.Is(u => u.ToString() == "user/starred/yes/no"), null, null) - .Returns(response); + .Returns(responseTask); + var apiConnection = Substitute.For(); apiConnection.Connection.Returns(connection); @@ -528,12 +529,11 @@ public class TheStarRepoMethod [InlineData(HttpStatusCode.OK, false)] public async Task ReturnsCorrectResultBasedOnStatus(HttpStatusCode status, bool expected) { - var response = Task.Factory.StartNew>(() => - new ApiResponse(new Response(status, null, new Dictionary(), "application/json"))); + var responseTask = TestSetup.GetApiResponse(status); var connection = Substitute.For(); - connection.Put(Arg.Is(u => u.ToString() == "user/starred/yes/no"), - Args.Object, Args.String).Returns(response); + connection.Put(Arg.Is(u => u.ToString() == "user/starred/yes/no"), Args.Object, Args.String) + .Returns(responseTask); var apiConnection = Substitute.For(); apiConnection.Connection.Returns(connection); @@ -553,7 +553,7 @@ public class TheRemoveStarFromRepoMethod [InlineData(HttpStatusCode.OK, false)] public async Task ReturnsCorrectResultBasedOnStatus(HttpStatusCode status, bool expected) { - var response = Task.Factory.StartNew(() => status); + var response = Task.FromResult(status); var connection = Substitute.For(); connection.Delete(Arg.Is(u => u.ToString() == "user/starred/yes/no")) diff --git a/Octokit.Tests/Clients/WatchedClientTests.cs b/Octokit.Tests/Clients/WatchedClientTests.cs index 5d59d9d12a..7bee44c233 100644 --- a/Octokit.Tests/Clients/WatchedClientTests.cs +++ b/Octokit.Tests/Clients/WatchedClientTests.cs @@ -326,7 +326,7 @@ public class TheUnwatchRepoMethod [InlineData(HttpStatusCode.OK, false)] public async Task ReturnsCorrectResultBasedOnStatus(HttpStatusCode status, bool expected) { - var response = Task.Factory.StartNew(() => status); + var response = Task.FromResult(status); var connection = Substitute.For(); connection.Delete(Arg.Is(u => u.ToString() == "repos/yes/no/subscription")) @@ -347,7 +347,7 @@ public async Task ReturnsCorrectResultBasedOnStatus(HttpStatusCode status, bool [InlineData(HttpStatusCode.OK, false)] public async Task ReturnsCorrectResultBasedOnStatusWithRepositoryId(HttpStatusCode status, bool expected) { - var response = Task.Factory.StartNew(() => status); + var response = Task.FromResult(status); var connection = Substitute.For(); connection.Delete(Arg.Is(u => u.ToString() == "repositories/1/subscription")) diff --git a/Octokit.Tests/GitHubClientTests.cs b/Octokit.Tests/GitHubClientTests.cs index 2a02aaa855..bff4f4f091 100644 --- a/Octokit.Tests/GitHubClientTests.cs +++ b/Octokit.Tests/GitHubClientTests.cs @@ -124,7 +124,7 @@ public void WhenSetCreatesInMemoryStoreThatReturnsSpecifiedCredentials() public void IsRetrievedFromCredentialStore() { var credentialStore = Substitute.For(); - credentialStore.GetCredentials().Returns(Task.Factory.StartNew(() => new Credentials("foo", "bar"))); + credentialStore.GetCredentials().Returns(Task.FromResult(new Credentials("foo", "bar"))); var client = new GitHubClient(new ProductHeaderValue("OctokitTests"), credentialStore); Assert.Equal("foo", client.Credentials.Login); diff --git a/Octokit.Tests/Helpers/NSubstituteExtensions.cs b/Octokit.Tests/Helpers/NSubstituteExtensions.cs index 97c1e053f9..24cf22101d 100644 --- a/Octokit.Tests/Helpers/NSubstituteExtensions.cs +++ b/Octokit.Tests/Helpers/NSubstituteExtensions.cs @@ -9,7 +9,7 @@ public static ConfiguredCall ReturnsAsync( this TTask value, Func returnThis, params Func[] returnThese) where TTask : Task { - return value.Returns(callInfo => Task.Factory.StartNew(() => returnThis(callInfo))); + return value.Returns(callInfo => Task.FromResult(returnThis(callInfo))); } public static ConfiguredCall ThrowsAsync(this Task value, Exception exception) diff --git a/Octokit.Tests/Helpers/TaskHelper.cs b/Octokit.Tests/Helpers/TaskHelper.cs new file mode 100644 index 0000000000..9c85c31a01 --- /dev/null +++ b/Octokit.Tests/Helpers/TaskHelper.cs @@ -0,0 +1,16 @@ +using System.Collections.Generic; +using System.Net; +using System.Threading.Tasks; + +namespace Octokit.Internal +{ + public static class TestSetup + { + public static Task> GetApiResponse(HttpStatusCode statusCode) + { + var response = new Response(statusCode, null, new Dictionary(), "application/json"); + return Task.FromResult>(new ApiResponse(response)); + + } + } +} diff --git a/Octokit.Tests/Models/ReadOnlyPagedCollectionTests.cs b/Octokit.Tests/Models/ReadOnlyPagedCollectionTests.cs index 908ff7e74f..87c3cc55df 100644 --- a/Octokit.Tests/Models/ReadOnlyPagedCollectionTests.cs +++ b/Octokit.Tests/Models/ReadOnlyPagedCollectionTests.cs @@ -15,8 +15,9 @@ public class TheGetNextPageMethod public async Task ReturnsTheNextPage() { var nextPageUrl = new Uri("https://example.com/page/2"); - var nextPageResponse = Task.Factory.StartNew>>(() => - new ApiResponse>(new Response(), new List { new object(), new object() })); + var listResponse = new ApiResponse>(new Response(), new List { new object(), new object() }); + var nextPageResponse = Task.FromResult>>(listResponse); + var links = new Dictionary { { "next", nextPageUrl } }; var scopes = new List(); var httpResponse = Substitute.For(); @@ -38,8 +39,8 @@ public async Task ReturnsTheNextPage() public async Task WhenNoInformationSetReturnsNull() { var nextPageUrl = new Uri("https://example.com/page/2"); - var nextPageResponse = Task.Factory.StartNew>>(() => - new ApiResponse>(new Response(), new List { new object(), new object() })); + var listResponse = new ApiResponse>(new Response(), new List { new object(), new object() }); + var nextPageResponse = Task.FromResult>>(listResponse); var links = new Dictionary(); var scopes = new List(); @@ -64,8 +65,8 @@ public async Task WhenNoInformationSetReturnsNull() public async Task WhenInlineFuncKillsPaginationReturnNull() { var nextPageUrl = new Uri("https://example.com/page/2"); - var nextPageResponse = Task.Factory.StartNew>>(() => - new ApiResponse>(new Response(), new List { new object(), new object() })); + var listResponse = new ApiResponse>(new Response(), new List { new object(), new object() }); + var nextPageResponse = Task.FromResult>>(listResponse); var links = new Dictionary { { "next", nextPageUrl } }; var scopes = new List(); diff --git a/Octokit.Tests/Reactive/ObservableIssuesClientTests.cs b/Octokit.Tests/Reactive/ObservableIssuesClientTests.cs index dd5ec4b251..af918574f7 100644 --- a/Octokit.Tests/Reactive/ObservableIssuesClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableIssuesClientTests.cs @@ -301,11 +301,11 @@ public async Task ReturnsEveryPageOfIssues() && d["state"] == "open" && d["sort"] == "created" && d["filter"] == "assigned"), Arg.Any()) - .Returns(Task.Factory.StartNew>>(() => firstPageResponse)); + .Returns(Task.FromResult>>(firstPageResponse)); gitHubClient.Connection.Get>(secondPageUrl, Arg.Any>(), "application/vnd.github.squirrel-girl-preview+json") - .Returns(Task.Factory.StartNew>>(() => secondPageResponse)); + .Returns(Task.FromResult>>(secondPageResponse)); gitHubClient.Connection.Get>(thirdPageUrl, Arg.Any>(), "application/vnd.github.squirrel-girl-preview+json") - .Returns(Task.Factory.StartNew>>(() => lastPageResponse)); + .Returns(Task.FromResult>>(lastPageResponse)); var client = new ObservableIssuesClient(gitHubClient); var results = await client.GetAllForRepository("fake", "repo").ToArray(); @@ -378,11 +378,11 @@ public async Task ReturnsEveryPageOfIssues() && d["sort"] == "created" && d["filter"] == "assigned"), "application/vnd.github.squirrel-girl-preview+json") - .Returns(Task.Factory.StartNew>>(() => firstPageResponse)); + .Returns(Task.FromResult>>(firstPageResponse)); gitHubClient.Connection.Get>(secondPageUrl, Arg.Any>(), "application/vnd.github.squirrel-girl-preview+json") - .Returns(Task.Factory.StartNew>>(() => secondPageResponse)); + .Returns(Task.FromResult>>(secondPageResponse)); gitHubClient.Connection.Get>(thirdPageUrl, Arg.Any>(), "application/vnd.github.squirrel-girl-preview+json") - .Returns(Task.Factory.StartNew>>(() => lastPageResponse)); + .Returns(Task.FromResult>>(lastPageResponse)); var client = new ObservableIssuesClient(gitHubClient); var results = await client.GetAllForOwnedAndMemberRepositories().ToArray(); @@ -464,11 +464,11 @@ public async Task ReturnsEveryPageOfIssues() && d["state"] == "open" && d["sort"] == "created" && d["filter"] == "assigned"), "application/vnd.github.squirrel-girl-preview+json") - .Returns(Task.Factory.StartNew>>(() => firstPageResponse)); + .Returns(Task.FromResult>>(firstPageResponse)); gitHubClient.Connection.Get>(secondPageUrl, Arg.Any>(), "application/vnd.github.squirrel-girl-preview+json") - .Returns(Task.Factory.StartNew>>(() => secondPageResponse)); + .Returns(Task.FromResult>>(secondPageResponse)); gitHubClient.Connection.Get>(thirdPageUrl, Arg.Any>(), "application/vnd.github.squirrel-girl-preview+json") - .Returns(Task.Factory.StartNew>>(() => lastPageResponse)); + .Returns(Task.FromResult>>(lastPageResponse)); var client = new ObservableIssuesClient(gitHubClient); @@ -537,11 +537,11 @@ public async Task ReturnsEveryPageOfIssues() && d["state"] == "open" && d["sort"] == "created" && d["filter"] == "assigned"), "application/vnd.github.squirrel-girl-preview+json") - .Returns(Task.Factory.StartNew>>(() => firstPageResponse)); + .Returns(Task.FromResult>>(firstPageResponse)); gitHubClient.Connection.Get>(secondPageUrl, Arg.Any>(), "application/vnd.github.squirrel-girl-preview+json") - .Returns(Task.Factory.StartNew>>(() => secondPageResponse)); + .Returns(Task.FromResult>>(secondPageResponse)); gitHubClient.Connection.Get>(thirdPageUrl, Arg.Any>(), "application/vnd.github.squirrel-girl-preview+json") - .Returns(Task.Factory.StartNew>>(() => lastPageResponse)); + .Returns(Task.FromResult>>(lastPageResponse)); var client = new ObservableIssuesClient(gitHubClient); var results = await client.GetAllForCurrent().ToArray(); diff --git a/Octokit.Tests/Reactive/ObservableMilestonesClientTests.cs b/Octokit.Tests/Reactive/ObservableMilestonesClientTests.cs index 628575bc68..ea9de926cb 100644 --- a/Octokit.Tests/Reactive/ObservableMilestonesClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableMilestonesClientTests.cs @@ -248,11 +248,11 @@ public async Task ReturnsEveryPageOfMilestones() ); var gitHubClient = Substitute.For(); gitHubClient.Connection.Get>(firstPageUrl, Args.EmptyDictionary, null) - .Returns(Task.Factory.StartNew>>(() => firstPageResponse)); + .Returns(Task.FromResult>>(firstPageResponse)); gitHubClient.Connection.Get>(secondPageUrl, Args.EmptyDictionary, null) - .Returns(Task.Factory.StartNew>>(() => secondPageResponse)); + .Returns(Task.FromResult>>(secondPageResponse)); gitHubClient.Connection.Get>(thirdPageUrl, Args.EmptyDictionary, null) - .Returns(Task.Factory.StartNew>>(() => lastPageResponse)); + .Returns(Task.FromResult>>(lastPageResponse)); var client = new ObservableMilestonesClient(gitHubClient); var results = await client.GetAllForRepository("fake", "repo").ToArray(); @@ -305,17 +305,17 @@ public async Task SendsAppropriateParametersMulti() && d["direction"] == "desc" && d["state"] == "open" && d["sort"] == "due_date"), null) - .Returns(Task.Factory.StartNew>>(() => firstPageResponse)); + .Returns(Task.FromResult>>(firstPageResponse)); gitHubClient.Connection.Get>(secondPageUrl, Arg.Is>(d => d.Count == 3 && d["direction"] == "desc" && d["state"] == "open" && d["sort"] == "due_date"), null) - .Returns(Task.Factory.StartNew>>(() => secondPageResponse)); + .Returns(Task.FromResult>>(secondPageResponse)); gitHubClient.Connection.Get>(thirdPageUrl, Arg.Is>(d => d.Count == 3 && d["direction"] == "desc" && d["state"] == "open" && d["sort"] == "due_date"), null) - .Returns(Task.Factory.StartNew>>(() => lastPageResponse)); + .Returns(Task.FromResult>>(lastPageResponse)); var client = new ObservableMilestonesClient(gitHubClient); diff --git a/Octokit.Tests/Reactive/ObservablePullRequestReviewCommentsClientTests.cs b/Octokit.Tests/Reactive/ObservablePullRequestReviewCommentsClientTests.cs index 600714f4e3..9e4e2b8058 100644 --- a/Octokit.Tests/Reactive/ObservablePullRequestReviewCommentsClientTests.cs +++ b/Octokit.Tests/Reactive/ObservablePullRequestReviewCommentsClientTests.cs @@ -127,11 +127,11 @@ public async Task RequestsCorrectUrlMulti() var gitHubClient = Substitute.For(); var acceptHeader = "application/vnd.github.squirrel-girl-preview+json"; gitHubClient.Connection.Get>(firstPageUrl, Args.EmptyDictionary, acceptHeader) - .Returns(Task.Factory.StartNew>>(() => firstPageResponse)); + .Returns(Task.FromResult>>(firstPageResponse)); gitHubClient.Connection.Get>(secondPageUrl, Args.EmptyDictionary, acceptHeader) - .Returns(Task.Factory.StartNew>>(() => secondPageResponse)); + .Returns(Task.FromResult>>(secondPageResponse)); gitHubClient.Connection.Get>(thirdPageUrl, Args.EmptyDictionary, acceptHeader) - .Returns(Task.Factory.StartNew>>(() => lastPageResponse)); + .Returns(Task.FromResult>>(lastPageResponse)); var client = new ObservablePullRequestReviewCommentsClient(gitHubClient); @@ -181,11 +181,11 @@ public async Task RequestsCorrectUrlMultiWithRepositoryId() var gitHubClient = Substitute.For(); gitHubClient.Connection.Get>(firstPageUrl, Args.EmptyDictionary, null) - .Returns(Task.Factory.StartNew>>(() => firstPageResponse)); + .Returns(Task.FromResult>>(firstPageResponse)); gitHubClient.Connection.Get>(secondPageUrl, Args.EmptyDictionary, null) - .Returns(Task.Factory.StartNew>>(() => secondPageResponse)); + .Returns(Task.FromResult>>(secondPageResponse)); gitHubClient.Connection.Get>(thirdPageUrl, Args.EmptyDictionary, null) - .Returns(Task.Factory.StartNew>>(() => lastPageResponse)); + .Returns(Task.FromResult>>(lastPageResponse)); var client = new ObservablePullRequestReviewCommentsClient(gitHubClient); @@ -351,17 +351,17 @@ public async Task RequestsCorrectUrlMulti() && d["direction"] == "desc" && d["since"] == "2013-11-15T11:43:01Z" && d["sort"] == "updated"), previewAcceptHeader) - .Returns(Task.Factory.StartNew>>(() => firstPageResponse)); + .Returns(Task.FromResult>>(firstPageResponse)); gitHubClient.Connection.Get>(secondPageUrl, Arg.Is>(d => d.Count == 3 && d["direction"] == "desc" && d["since"] == "2013-11-15T11:43:01Z" && d["sort"] == "updated"), previewAcceptHeader) - .Returns(Task.Factory.StartNew>>(() => secondPageResponse)); + .Returns(Task.FromResult>>(secondPageResponse)); gitHubClient.Connection.Get>(thirdPageUrl, Arg.Is>(d => d.Count == 3 && d["direction"] == "desc" && d["since"] == "2013-11-15T11:43:01Z" && d["sort"] == "updated"), previewAcceptHeader) - .Returns(Task.Factory.StartNew>>(() => lastPageResponse)); + .Returns(Task.FromResult>>(lastPageResponse)); var client = new ObservablePullRequestReviewCommentsClient(gitHubClient); @@ -434,17 +434,17 @@ public async Task RequestsCorrectUrlMultiWithRepositoryId() && d["direction"] == "desc" && d["since"] == "2013-11-15T11:43:01Z" && d["sort"] == "updated"), "application/vnd.github.squirrel-girl-preview+json") - .Returns(Task.Factory.StartNew>>(() => firstPageResponse)); + .Returns(Task.FromResult>>(firstPageResponse)); gitHubClient.Connection.Get>(secondPageUrl, Arg.Is>(d => d.Count == 3 && d["direction"] == "desc" && d["since"] == "2013-11-15T11:43:01Z" && d["sort"] == "updated"), "application/vnd.github.squirrel-girl-preview+json") - .Returns(Task.Factory.StartNew>>(() => secondPageResponse)); + .Returns(Task.FromResult>>(secondPageResponse)); gitHubClient.Connection.Get>(thirdPageUrl, Arg.Is>(d => d.Count == 3 && d["direction"] == "desc" && d["since"] == "2013-11-15T11:43:01Z" && d["sort"] == "updated"), "application/vnd.github.squirrel-girl-preview+json") - .Returns(Task.Factory.StartNew>>(() => lastPageResponse)); + .Returns(Task.FromResult>>(lastPageResponse)); var client = new ObservablePullRequestReviewCommentsClient(gitHubClient); @@ -576,15 +576,15 @@ public async Task RequestsCorrectUrlWithoutSelectedSortingArgumentsMulti() Arg.Is>(d => d.Count == 2 && d["direction"] == "asc" && d["sort"] == "created"), previewAcceptHeader) - .Returns(Task.Factory.StartNew>>(() => firstPageResponse)); + .Returns(Task.FromResult>>(firstPageResponse)); gitHubClient.Connection.Get>(secondPageUrl, Arg.Is>(d => d.Count == 2 && d["direction"] == "asc" && d["sort"] == "created"), previewAcceptHeader) - .Returns(Task.Factory.StartNew>>(() => secondPageResponse)); + .Returns(Task.FromResult>>(secondPageResponse)); gitHubClient.Connection.Get>(thirdPageUrl, Arg.Is>(d => d.Count == 2 && d["direction"] == "asc" && d["sort"] == "created"), previewAcceptHeader) - .Returns(Task.Factory.StartNew>>(() => lastPageResponse)); + .Returns(Task.FromResult>>(lastPageResponse)); var client = new ObservablePullRequestReviewCommentsClient(gitHubClient); @@ -646,15 +646,15 @@ public async Task RequestsCorrectUrlWithoutSelectedSortingArgumentsMultiWithRepo Arg.Is>(d => d.Count == 2 && d["direction"] == "asc" && d["sort"] == "created"), "application/vnd.github.squirrel-girl-preview+json") - .Returns(Task.Factory.StartNew>>(() => firstPageResponse)); + .Returns(Task.FromResult>>(firstPageResponse)); gitHubClient.Connection.Get>(secondPageUrl, Arg.Is>(d => d.Count == 2 && d["direction"] == "asc" && d["sort"] == "created"), "application/vnd.github.squirrel-girl-preview+json") - .Returns(Task.Factory.StartNew>>(() => secondPageResponse)); + .Returns(Task.FromResult>>(secondPageResponse)); gitHubClient.Connection.Get>(thirdPageUrl, Arg.Is>(d => d.Count == 2 && d["direction"] == "asc" && d["sort"] == "created"), "application/vnd.github.squirrel-girl-preview+json") - .Returns(Task.Factory.StartNew>>(() => lastPageResponse)); + .Returns(Task.FromResult>>(lastPageResponse)); var client = new ObservablePullRequestReviewCommentsClient(gitHubClient); diff --git a/Octokit.Tests/Reactive/ObservablePullRequestReviewsClientTests.cs b/Octokit.Tests/Reactive/ObservablePullRequestReviewsClientTests.cs index 0b3c7267f5..0ec6a946a5 100644 --- a/Octokit.Tests/Reactive/ObservablePullRequestReviewsClientTests.cs +++ b/Octokit.Tests/Reactive/ObservablePullRequestReviewsClientTests.cs @@ -127,11 +127,11 @@ public async Task RequestsCorrectUrlMulti() var gitHubClient = Substitute.For(); gitHubClient.Connection.Get>(firstPageUrl, Args.EmptyDictionary, null) - .Returns(Task.Factory.StartNew>>(() => firstPageResponse)); + .Returns(Task.FromResult>>(firstPageResponse)); gitHubClient.Connection.Get>(secondPageUrl, Args.EmptyDictionary, null) - .Returns(Task.Factory.StartNew>>(() => secondPageResponse)); + .Returns(Task.FromResult>>(secondPageResponse)); gitHubClient.Connection.Get>(thirdPageUrl, Args.EmptyDictionary, null) - .Returns(Task.Factory.StartNew>>(() => lastPageResponse)); + .Returns(Task.FromResult>>(lastPageResponse)); var client = new ObservablePullRequestReviewsClient(gitHubClient); @@ -182,11 +182,11 @@ public async Task RequestsCorrectUrlMultiWithRepositoryId() var gitHubClient = Substitute.For(); gitHubClient.Connection.Get>(firstPageUrl, Args.EmptyDictionary, null) - .Returns(Task.Factory.StartNew>>(() => firstPageResponse)); + .Returns(Task.FromResult>>(firstPageResponse)); gitHubClient.Connection.Get>(secondPageUrl, Args.EmptyDictionary, null) - .Returns(Task.Factory.StartNew>>(() => secondPageResponse)); + .Returns(Task.FromResult>>(secondPageResponse)); gitHubClient.Connection.Get>(thirdPageUrl, Args.EmptyDictionary, null) - .Returns(Task.Factory.StartNew>>(() => lastPageResponse)); + .Returns(Task.FromResult>>(lastPageResponse)); var client = new ObservablePullRequestReviewsClient(gitHubClient); @@ -522,11 +522,11 @@ public async Task RequestsCorrectUrlMulti() var gitHubClient = Substitute.For(); gitHubClient.Connection.Get>(firstPageUrl, Args.EmptyDictionary, null) - .Returns(Task.Factory.StartNew>>(() => firstPageResponse)); + .Returns(Task.FromResult>>(firstPageResponse)); gitHubClient.Connection.Get>(secondPageUrl, Args.EmptyDictionary, null) - .Returns(Task.Factory.StartNew>>(() => secondPageResponse)); + .Returns(Task.FromResult>>(secondPageResponse)); gitHubClient.Connection.Get>(thirdPageUrl, Args.EmptyDictionary, null) - .Returns(Task.Factory.StartNew>>(() => lastPageResponse)); + .Returns(Task.FromResult>>(lastPageResponse)); var client = new ObservablePullRequestReviewsClient(gitHubClient); @@ -577,11 +577,11 @@ public async Task RequestsCorrectUrlMultiWithRepositoryId() var gitHubClient = Substitute.For(); gitHubClient.Connection.Get>(firstPageUrl, Args.EmptyDictionary, null) - .Returns(Task.Factory.StartNew>>(() => firstPageResponse)); + .Returns(Task.FromResult>>(firstPageResponse)); gitHubClient.Connection.Get>(secondPageUrl, Args.EmptyDictionary, null) - .Returns(Task.Factory.StartNew>>(() => secondPageResponse)); + .Returns(Task.FromResult>>(secondPageResponse)); gitHubClient.Connection.Get>(thirdPageUrl, Args.EmptyDictionary, null) - .Returns(Task.Factory.StartNew>>(() => lastPageResponse)); + .Returns(Task.FromResult>>(lastPageResponse)); var client = new ObservablePullRequestReviewsClient(gitHubClient); diff --git a/Octokit.Tests/Reactive/ObservablePullRequestsClientTests.cs b/Octokit.Tests/Reactive/ObservablePullRequestsClientTests.cs index 4109c2d1ff..2366e4bd2c 100644 --- a/Octokit.Tests/Reactive/ObservablePullRequestsClientTests.cs +++ b/Octokit.Tests/Reactive/ObservablePullRequestsClientTests.cs @@ -210,11 +210,11 @@ public async Task ReturnsEveryPageOfPullRequests() ); var gitHubClient = Substitute.For(); gitHubClient.Connection.Get>(firstPageUrl, Args.EmptyDictionary, "application/vnd.github.shadow-cat-preview+json") - .Returns(Task.Factory.StartNew>>(() => firstPageResponse)); + .Returns(Task.FromResult>>(firstPageResponse)); gitHubClient.Connection.Get>(secondPageUrl, Args.EmptyDictionary, "application/vnd.github.shadow-cat-preview+json") - .Returns(Task.Factory.StartNew>>(() => secondPageResponse)); + .Returns(Task.FromResult>>(secondPageResponse)); gitHubClient.Connection.Get>(thirdPageUrl, Args.EmptyDictionary, "application/vnd.github.shadow-cat-preview+json") - .Returns(Task.Factory.StartNew>>(() => lastPageResponse)); + .Returns(Task.FromResult>>(lastPageResponse)); var client = new ObservablePullRequestsClient(gitHubClient); var results = await client.GetAllForRepository("fake", "repo").ToArray(); @@ -263,11 +263,11 @@ public async Task ReturnsEveryPageOfPullRequestsWithRepositoryId() ); var gitHubClient = Substitute.For(); gitHubClient.Connection.Get>(firstPageUrl, Args.EmptyDictionary, "application/vnd.github.shadow-cat-preview+json") - .Returns(Task.Factory.StartNew>>(() => firstPageResponse)); + .Returns(Task.FromResult>>(firstPageResponse)); gitHubClient.Connection.Get>(secondPageUrl, Args.EmptyDictionary, "application/vnd.github.shadow-cat-preview+json") - .Returns(Task.Factory.StartNew>>(() => secondPageResponse)); + .Returns(Task.FromResult>>(secondPageResponse)); gitHubClient.Connection.Get>(thirdPageUrl, Args.EmptyDictionary, "application/vnd.github.shadow-cat-preview+json") - .Returns(Task.Factory.StartNew>>(() => lastPageResponse)); + .Returns(Task.FromResult>>(lastPageResponse)); var client = new ObservablePullRequestsClient(gitHubClient); var results = await client.GetAllForRepository(1).ToArray(); @@ -322,21 +322,21 @@ public async Task SendsAppropriateParametersMulti() && d["base"] == "fake_base_branch" && d["sort"] == "created" && d["direction"] == "desc"), "application/vnd.github.shadow-cat-preview+json") - .Returns(Task.Factory.StartNew>>(() => firstPageResponse)); + .Returns(Task.FromResult>>(firstPageResponse)); gitHubClient.Connection.Get>(secondPageUrl, Arg.Is>(d => d.Count == 5 && d["head"] == "user:ref-name" && d["state"] == "open" && d["base"] == "fake_base_branch" && d["sort"] == "created" && d["direction"] == "desc"), "application/vnd.github.shadow-cat-preview+json") - .Returns(Task.Factory.StartNew>>(() => secondPageResponse)); + .Returns(Task.FromResult>>(secondPageResponse)); gitHubClient.Connection.Get>(thirdPageUrl, Arg.Is>(d => d.Count == 5 && d["head"] == "user:ref-name" && d["state"] == "open" && d["base"] == "fake_base_branch" && d["sort"] == "created" && d["direction"] == "desc"), "application/vnd.github.shadow-cat-preview+json") - .Returns(Task.Factory.StartNew>>(() => lastPageResponse)); + .Returns(Task.FromResult>>(lastPageResponse)); var client = new ObservablePullRequestsClient(gitHubClient); var results = await client.GetAllForRepository("fake", "repo", new PullRequestRequest { Head = "user:ref-name", Base = "fake_base_branch" }).ToArray(); @@ -391,21 +391,21 @@ public async Task SendsAppropriateParametersMultiWithRepositoryId() && d["base"] == "fake_base_branch" && d["sort"] == "created" && d["direction"] == "desc"), "application/vnd.github.shadow-cat-preview+json") - .Returns(Task.Factory.StartNew>>(() => firstPageResponse)); + .Returns(Task.FromResult>>(firstPageResponse)); gitHubClient.Connection.Get>(secondPageUrl, Arg.Is>(d => d.Count == 5 && d["head"] == "user:ref-name" && d["state"] == "open" && d["base"] == "fake_base_branch" && d["sort"] == "created" && d["direction"] == "desc"), "application/vnd.github.shadow-cat-preview+json") - .Returns(Task.Factory.StartNew>>(() => secondPageResponse)); + .Returns(Task.FromResult>>(secondPageResponse)); gitHubClient.Connection.Get>(thirdPageUrl, Arg.Is>(d => d.Count == 5 && d["head"] == "user:ref-name" && d["state"] == "open" && d["base"] == "fake_base_branch" && d["sort"] == "created" && d["direction"] == "desc"), "application/vnd.github.shadow-cat-preview+json") - .Returns(Task.Factory.StartNew>>(() => lastPageResponse)); + .Returns(Task.FromResult>>(lastPageResponse)); var client = new ObservablePullRequestsClient(gitHubClient); var results = await client.GetAllForRepository(1, new PullRequestRequest { Head = "user:ref-name", Base = "fake_base_branch" }).ToArray(); diff --git a/Octokit.Tests/Reactive/ObservableRepositoriesClientTests.cs b/Octokit.Tests/Reactive/ObservableRepositoriesClientTests.cs index 43251edd24..da93eb3246 100644 --- a/Octokit.Tests/Reactive/ObservableRepositoriesClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableRepositoriesClientTests.cs @@ -153,8 +153,7 @@ public async Task RequestsCorrectUrlWithRepositoryId() public async Task IsALukeWarmObservable() { var repository = new Repository(); - var response = Task.Factory.StartNew>(() => - new ApiResponse(new Response(), repository)); + var response = Task.FromResult>(new ApiResponse(new Response(), repository)); var connection = Substitute.For(); connection.Get(Args.Uri, null, Args.AnyAcceptHeaders).Returns(response); var gitHubClient = new GitHubClient(connection); @@ -179,8 +178,7 @@ public async Task IsALukeWarmObservable() public async Task IsALukeWarmObservableWithRepositoryId() { var repository = new Repository(); - var response = Task.Factory.StartNew>(() => - new ApiResponse(new Response(), repository)); + var response = Task.FromResult>(new ApiResponse(new Response(), repository)); var connection = Substitute.For(); connection.Get(Args.Uri, null, Args.AnyAcceptHeaders).Returns(response); var gitHubClient = new GitHubClient(connection); @@ -248,11 +246,11 @@ public async Task ReturnsEveryPageOfRepositories() var gitHubClient = Substitute.For(); gitHubClient.Connection.Get>(firstPageUrl, Arg.Any>(), Args.AnyAcceptHeaders) - .Returns(Task.Factory.StartNew>>(() => firstPageResponse)); + .Returns(Task.FromResult>>(firstPageResponse)); gitHubClient.Connection.Get>(secondPageUrl, Arg.Any>(), Args.AnyAcceptHeaders) - .Returns(Task.Factory.StartNew>>(() => secondPageResponse)); + .Returns(Task.FromResult>>(secondPageResponse)); gitHubClient.Connection.Get>(thirdPageUrl, Arg.Any>(), Args.AnyAcceptHeaders) - .Returns(Task.Factory.StartNew>>(() => lastPageResponse)); + .Returns(Task.FromResult>>(lastPageResponse)); var repositoriesClient = new ObservableRepositoriesClient(gitHubClient); var results = await repositoriesClient.GetAllForCurrent().ToArray(); @@ -311,13 +309,13 @@ public async Task StopsMakingNewRequestsWhenTakeIsFulfilled() ); var gitHubClient = Substitute.For(); gitHubClient.Connection.GetResponse>(firstPageUrl) - .Returns(Task.Factory.StartNew>>(() => firstPageResponse)); + .Returns(Task.FromResult>>(firstPageResponse)); gitHubClient.Connection.GetResponse>(secondPageUrl) - .Returns(Task.Factory.StartNew>>(() => secondPageResponse)); + .Returns(Task.FromResult>>(secondPageResponse)); gitHubClient.Connection.GetResponse>(thirdPageUrl) - .Returns(Task.Factory.StartNew>>(() => thirdPageResponse)); + .Returns(Task.FromResult>>(thirdPageResponse)); gitHubClient.Connection.GetResponse>(fourthPageUrl) - .Returns(Task.Factory.StartNew>>(() => lastPageResponse)); + .Returns(Task.FromResult>>(lastPageResponse)); var repositoriesClient = new ObservableRepositoriesClient(gitHubClient); var results = await repositoriesClient.GetAllForCurrent().Take(4).ToArray();