diff --git a/src/SaveEnergy.Specs/Hooks/MockServer.cs b/src/SaveEnergy.Specs/Hooks/MockServer.cs index c4a8e04..8074dc2 100644 --- a/src/SaveEnergy.Specs/Hooks/MockServer.cs +++ b/src/SaveEnergy.Specs/Hooks/MockServer.cs @@ -23,6 +23,12 @@ public void Stop() } public void ConfigureSuccessfulDeviceAuthorization() + { + ConfigureDeviceCodeResponse(); + ConfigureAccesTokenResponse(); + } + + private void ConfigureDeviceCodeResponse() { _mockServer ?.Given(Request.Create().WithPath("/login/device/code").UsingPost()) @@ -42,7 +48,10 @@ public void ConfigureSuccessfulDeviceAuthorization() } ) ); + } + private void ConfigureAccesTokenResponse() + { _mockServer ?.Given(Request.Create().WithPath("/login/oauth/access_token").UsingPost()) .RespondWith( diff --git a/src/SaveEnergy.Tests/Adapters/Outbound/RepositoryQueryTests.cs b/src/SaveEnergy.Tests/Adapters/Outbound/RepositoryQueryTests.cs index dad499a..2fd2a09 100644 --- a/src/SaveEnergy.Tests/Adapters/Outbound/RepositoryQueryTests.cs +++ b/src/SaveEnergy.Tests/Adapters/Outbound/RepositoryQueryTests.cs @@ -250,31 +250,27 @@ CancellationToken cancellationToken var queryString = request.RequestUri?.Query[1..] ?? ""; var queryParameters = queryString.Split(separator); - const string pageParameter = "page="; - var page = int.Parse( - Array - .Find( - queryParameters, - x => x.StartsWith(pageParameter, StringComparison.OrdinalIgnoreCase) - ) - ?.Split('=')[1] ?? "1" - ); + var page = ParseQueryParameter("page=", queryParameters); + var perPage = ParseQueryParameter("per_page=", queryParameters); + + var start = (page - 1) * perPage + 1; + var count = Math.Min(perPage, availableRepositories - start + 1); + count = Math.Max(count, 0); - const string perPageParameter = "per_page="; - var perPage = int.Parse( + return (start, count); + } + + private static int ParseQueryParameter(string parameterName, string[] queryParameters) + { + var page = int.Parse( Array .Find( queryParameters, - x => x.StartsWith(perPageParameter, StringComparison.OrdinalIgnoreCase) + x => x.StartsWith(parameterName, StringComparison.OrdinalIgnoreCase) ) ?.Split('=')[1] ?? "1" ); - - var start = (page - 1) * perPage + 1; - var count = Math.Min(perPage, availableRepositories - start + 1); - count = Math.Max(count, 0); - - return (start, count); + return page; } } }