Skip to content

Commit

Permalink
Float estimates (#19)
Browse files Browse the repository at this point in the history
* Add overload that takes a double as the estimate value for an issue.Issue

Refactor the code that sets the estimate to allow both int and double to be passed in.
Added test for the double estimate
Update package versions to later versions.

* Add ConfigureAwait(false) in 2 places that were previously missed.
  • Loading branch information
AlexGhiondea committed May 22, 2020
1 parent 57b4387 commit d51d3ea
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Pipeline/ThrowOnErrorResponsePolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public override void Process(HttpMessage message, ReadOnlyMemory<HttpPipelinePol

public override async ValueTask ProcessAsync(HttpMessage message, ReadOnlyMemory<HttpPipelinePolicy> pipeline)
{
await ProcessNextAsync(message, pipeline);
await ProcessNextAsync(message, pipeline).ConfigureAwait(false);
if (message.ResponseClassifier.IsErrorResponse(message))
{
throw new RequestFailedException(message.Response.Status, message.ToString());
Expand Down
2 changes: 1 addition & 1 deletion src/Pipeline/ZenHubAuthenticationPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public override async ValueTask ProcessAsync(HttpMessage message, ReadOnlyMemory
#pragma warning disable CA1062 // Validate arguments of public methods
message.Request.Headers.Add("X-Authentication-Token", _authToken);
#pragma warning restore CA1062 // Validate arguments of public methods
await ProcessNextAsync(message, pipeline);
await ProcessNextAsync(message, pipeline).ConfigureAwait(false);
}
}
}
10 changes: 5 additions & 5 deletions src/ZenHub.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<LangVersion>preview</LangVersion>
<VersionPrefix>1.1.0</VersionPrefix>
<VersionPrefix>1.2.0</VersionPrefix>
</PropertyGroup>

<PropertyGroup>
Expand All @@ -21,13 +21,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Core" Version="1.0.0" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.6">
<PackageReference Include="Azure.Core" Version="1.2.1" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Octokit" Version="0.36.0" />
<PackageReference Include="System.Text.Json" Version="4.6.0" />
<PackageReference Include="Octokit" Version="0.47.0" />
<PackageReference Include="System.Text.Json" Version="4.7.2" />
</ItemGroup>

</Project>
16 changes: 16 additions & 0 deletions src/ZenHubIssueClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,22 @@ public async Task<Response<IssueDetails>> GetDetailsAsync(CancellationToken canc
/// </summary>
/// <param name="estimate">The value of the estimate</param>
public async Task<Response> SetEstimateAsync(int estimate, CancellationToken cancellationToken = default)
{
return await SetEstimateInternalAsync(estimate, cancellationToken)
.ConfigureAwait(false);
}

/// <summary>
/// Set the estimate on the issue
/// </summary>
/// <param name="estimate">The value of the estimate</param>
public async Task<Response> SetEstimateAsync(double estimate, CancellationToken cancellationToken = default)
{
return await SetEstimateInternalAsync(estimate, cancellationToken)
.ConfigureAwait(false);
}

private async Task<Response> SetEstimateInternalAsync<T>(T estimate, CancellationToken cancellationToken = default)
{
var contentBody = new
{
Expand Down
10 changes: 10 additions & 0 deletions tests/ZenHubClient.Mock.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,16 @@ public void SetIssueEstimate1()
Assert.AreEqual(200, response.Status);
}

[Test]
public void SetIssueEstimate2()
{
long repoId = MockServer.repositoryId;
int issueNumber = MockServer.issueNumber;

var response = _zenhubClient.GetIssueClient(repoId, issueNumber).SetEstimateAsync(1.5).GetAwaiter().GetResult();
Assert.AreEqual(200, response.Status);
}

[Test]
public void AddIssueToReleaseReport1()
{
Expand Down
28 changes: 28 additions & 0 deletions tests/testData/PutIssueEstimate_floating.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"Request": {
"Path": {
"Matchers": [
{
"Name": "ExactMatcher",
"Pattern": "/p1/repositories/1/issues/2/estimate"
}
]
},
"Methods": [
"put"
],
"Body": {
"Matcher": {
"Name": "ExactMatcher",
"Pattern": "{\"estimate\":1.5}"
}
}
},
"Response": {
"StatusCode": 200,
"BodyAsJson": { "estimate": 1.5 },
"Headers": {
"Content-Type": "application/json"
}
}
}

0 comments on commit d51d3ea

Please sign in to comment.