Skip to content
This repository has been archived by the owner on Jul 9, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into options-in-factory
Browse files Browse the repository at this point in the history
  • Loading branch information
baywet authored May 21, 2024
2 parents 54fe68a + 3464453 commit 7b234ee
Show file tree
Hide file tree
Showing 11 changed files with 128 additions and 84 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/auto-merge-dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
steps:
- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v2.0.0
uses: dependabot/fetch-metadata@v2.1.0
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"

Expand Down
17 changes: 3 additions & 14 deletions .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,28 +53,17 @@ jobs:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache SonarCloud scanner
id: cache-sonar-scanner
uses: actions/cache@v4
with:
path: ./.sonar/scanner
key: ${{ runner.os }}-sonar-scanner
restore-keys: ${{ runner.os }}-sonar-scanner
- name: Install SonarCloud scanner
if: steps.cache-sonar-scanner.outputs.cache-hit != 'true'
shell: pwsh
run: |
New-Item -Path ./.sonar/scanner -ItemType Directory
dotnet tool update dotnet-sonarscanner --tool-path ./.sonar/scanner
run: dotnet tool install dotnet-sonarscanner --create-manifest-if-needed
- name: Build and analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
CollectCoverage: true
CoverletOutputFormat: 'opencover' # https://github.com/microsoft/vstest/issues/4014#issuecomment-1307913682
shell: pwsh
run: |
./.sonar/scanner/dotnet-sonarscanner begin /k:"microsoft_kiota-http-dotnet" /o:"microsoft" /d:sonar.login="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.opencover.reportsPaths="Microsoft.Kiota.Http.HttpClientLibrary.Tests/coverage.net8.0.opencover.xml"
dotnet tool run dotnet-sonarscanner begin /k:"microsoft_kiota-http-dotnet" /o:"microsoft" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.opencover.reportsPaths="Microsoft.Kiota.Http.HttpClientLibrary.Tests/coverage.net8.0.opencover.xml"
dotnet workload restore
dotnet build
dotnet test Microsoft.Kiota.Http.HttpClientLibrary.sln --no-build --verbosity normal /p:CollectCoverage=true /p:CoverletOutputFormat=opencover --framework net8.0
./.sonar/scanner/dotnet-sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}"
dotnet tool run dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"
26 changes: 13 additions & 13 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"recommendations": [
"formulahendry.dotnet-test-explorer",
"ms-azure-devops.azure-pipelines",
"streetsidesoftware.code-spell-checker",
"editorconfig.editorconfig",
"donjayamanne.githistory",
"cschleiden.vscode-github-actions",
"github.copilot",
"github.vscode-pull-request-github",
"ms-vsliveshare.vsliveshare",
"esbenp.prettier-vscode"
]
}
"recommendations": [
"ms-azure-devops.azure-pipelines",
"streetsidesoftware.code-spell-checker",
"editorconfig.editorconfig",
"donjayamanne.githistory",
"cschleiden.vscode-github-actions",
"github.copilot",
"github.vscode-pull-request-github",
"ms-vsliveshare.vsliveshare",
"esbenp.prettier-vscode",
"ms-dotnettools.vscodeintellicode-csharp"
]
}
22 changes: 16 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.4.0]

## Added

- KiotaClientFactory `create()` overload that accepts a list of handlers.

### Added

- `GetDefaultHandlerTypes` added to `KiotaClientFactory` if you're creating your own `HttpClient` and still want to use the default handlers.

## [1.4.1] - 2024-05-07

## Changed

- Use `SocketsHttpHandler` with `EnableMultipleHttp2Connections` as default HTTP message handler.

## [1.4.0]

## Added

- KiotaClientFactory `create()` overload that accepts a list of handlers.

## [1.3.12] - 2024-04-22

- UriReplacementHandler improvements to be added to middleware pipeline by default and respects options set in the HttpRequestMessage (https://github.com/microsoft/kiota-http-dotnet/issues/242)
Expand Down
19 changes: 10 additions & 9 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Microsoft Open Source Code of Conduct

This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).

Resources:

- [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/)
- [Microsoft Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/)
- Contact [[email protected]](mailto:[email protected]) with questions or concerns
# Microsoft Open Source Code of Conduct

This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).

Resources:

- [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/)
- [Microsoft Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/)
- Contact [[email protected]](mailto:[email protected]) with questions or concerns
- Employees can reach out at [aka.ms/opensource/moderation-support](https://aka.ms/opensource/moderation-support)
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,22 @@ public void ChainHandlersCollectionAndGetFirstLinkWithMultipleHandlersSetsFinalH
Assert.IsType<HttpClientHandler>(innerHandler.InnerHandler);
}

[Fact]
public void GetDefaultHttpMessageHandlerEnablesMultipleHttp2Connections()
{
// Act
var defaultHandler = KiotaClientFactory.GetDefaultHttpMessageHandler();
// Assert
Assert.NotNull(defaultHandler);
#if NETFRAMEWORK
Assert.IsType<WinHttpHandler>(defaultHandler);
Assert.True(((WinHttpHandler)defaultHandler).EnableMultipleHttp2Connections);
#else
Assert.IsType<SocketsHttpHandler>(defaultHandler);
Assert.True(((SocketsHttpHandler)defaultHandler).EnableMultipleHttp2Connections);
#endif
}

[Fact]
public void GetDefaultHttpMessageHandlerSetsUpProxy()
{
Expand All @@ -83,10 +99,9 @@ public void GetDefaultHttpMessageHandlerSetsUpProxy()
Assert.IsType<WinHttpHandler>(defaultHandler);
Assert.Equal(proxy, ((WinHttpHandler)defaultHandler).Proxy);
#else
Assert.IsType<HttpClientHandler>(defaultHandler);
Assert.Equal(proxy, ((HttpClientHandler)defaultHandler).Proxy);
Assert.IsType<SocketsHttpHandler>(defaultHandler);
Assert.Equal(proxy, ((SocketsHttpHandler)defaultHandler).Proxy);
#endif

}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="Microsoft.TestPlatform.ObjectModel" Version="17.9.0" />
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="xunit" Version="2.7.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.8">
<PackageReference Include="xunit" Version="2.8.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
34 changes: 17 additions & 17 deletions Microsoft.Kiota.Http.HttpClientLibrary.Tests/RequestAdapterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public async Task GetRequestMessageFromRequestInformationSetsContentHeaders()
}

[Fact]
public async void SendMethodDoesNotThrowWithoutUrlTemplate()
public async Task SendMethodDoesNotThrowWithoutUrlTemplate()
{
var mockHandler = new Mock<HttpMessageHandler>();
var client = new HttpClient(mockHandler.Object);
Expand Down Expand Up @@ -206,7 +206,7 @@ public async void SendMethodDoesNotThrowWithoutUrlTemplate()
[InlineData(HttpStatusCode.NonAuthoritativeInformation)]
[InlineData(HttpStatusCode.PartialContent)]
[Theory]
public async void SendStreamReturnsUsableStream(HttpStatusCode statusCode)
public async Task SendStreamReturnsUsableStream(HttpStatusCode statusCode)
{
var mockHandler = new Mock<HttpMessageHandler>();
var client = new HttpClient(mockHandler.Object);
Expand Down Expand Up @@ -238,7 +238,7 @@ public async void SendStreamReturnsUsableStream(HttpStatusCode statusCode)
[InlineData(HttpStatusCode.NonAuthoritativeInformation)]
[InlineData(HttpStatusCode.NoContent)]
[Theory]
public async void SendStreamReturnsNullForNoContent(HttpStatusCode statusCode)
public async Task SendStreamReturnsNullForNoContent(HttpStatusCode statusCode)
{
var mockHandler = new Mock<HttpMessageHandler>();
var client = new HttpClient(mockHandler.Object);
Expand Down Expand Up @@ -266,7 +266,7 @@ public async void SendStreamReturnsNullForNoContent(HttpStatusCode statusCode)
[InlineData(HttpStatusCode.NoContent)]
[InlineData(HttpStatusCode.PartialContent)]
[Theory]
public async void SendSNoContentDoesntFailOnOtherStatusCodes(HttpStatusCode statusCode)
public async Task SendSNoContentDoesntFailOnOtherStatusCodes(HttpStatusCode statusCode)
{
var mockHandler = new Mock<HttpMessageHandler>();
var client = new HttpClient(mockHandler.Object);
Expand All @@ -292,7 +292,7 @@ public async void SendSNoContentDoesntFailOnOtherStatusCodes(HttpStatusCode stat
[InlineData(HttpStatusCode.NoContent)]
[InlineData(HttpStatusCode.ResetContent)]
[Theory]
public async void SendReturnsNullOnNoContent(HttpStatusCode statusCode)
public async Task SendReturnsNullOnNoContent(HttpStatusCode statusCode)
{
var mockHandler = new Mock<HttpMessageHandler>();
var client = new HttpClient(mockHandler.Object);
Expand Down Expand Up @@ -321,7 +321,7 @@ public async void SendReturnsNullOnNoContent(HttpStatusCode statusCode)
[InlineData(HttpStatusCode.NoContent)]
[InlineData(HttpStatusCode.ResetContent)]
[Theory]
public async void SendReturnsNullOnNoContentWithContentHeaderPresent(HttpStatusCode statusCode)
public async Task SendReturnsNullOnNoContentWithContentHeaderPresent(HttpStatusCode statusCode)
{
var mockHandler = new Mock<HttpMessageHandler>();
var client = new HttpClient(mockHandler.Object);
Expand All @@ -348,7 +348,7 @@ public async void SendReturnsNullOnNoContentWithContentHeaderPresent(HttpStatusC
[InlineData(HttpStatusCode.Accepted)]
[InlineData(HttpStatusCode.NonAuthoritativeInformation)]
[Theory]
public async void SendReturnsObjectOnContent(HttpStatusCode statusCode)
public async Task SendReturnsObjectOnContent(HttpStatusCode statusCode)
{
var mockHandler = new Mock<HttpMessageHandler>();
var client = new HttpClient(mockHandler.Object);
Expand Down Expand Up @@ -379,7 +379,7 @@ public async void SendReturnsObjectOnContent(HttpStatusCode statusCode)
Assert.NotNull(response);
}
[Fact]
public async void RetriesOnCAEResponse()
public async Task RetriesOnCAEResponse()
{
var mockHandler = new Mock<HttpMessageHandler>();
var client = new HttpClient(mockHandler.Object);
Expand All @@ -393,7 +393,7 @@ public async void RetriesOnCAEResponse()
StatusCode = methodCalled ? HttpStatusCode.OK : HttpStatusCode.Unauthorized,
Content = new StreamContent(new MemoryStream(Encoding.UTF8.GetBytes("Test")))
};
if(!methodCalled)
if (!methodCalled)
response.Headers.WwwAuthenticate.Add(new("Bearer", "realm=\"\", authorization_uri=\"https://login.microsoftonline.com/common/oauth2/authorize\", client_id=\"00000003-0000-0000-c000-000000000000\", error=\"insufficient_claims\", claims=\"eyJhY2Nlc3NfdG9rZW4iOnsibmJmIjp7ImVzc2VudGlhbCI6dHJ1ZSwgInZhbHVlIjoiMTY1MjgxMzUwOCJ9fX0=\""));
methodCalled = true;
return Task.FromResult(response);
Expand All @@ -414,7 +414,7 @@ public async void RetriesOnCAEResponse()
[InlineData(HttpStatusCode.NotFound)]
[InlineData(HttpStatusCode.BadGateway)]
[Theory]
public async void SetsTheApiExceptionStatusCode(HttpStatusCode statusCode)
public async Task SetsTheApiExceptionStatusCode(HttpStatusCode statusCode)
{
var mockHandler = new Mock<HttpMessageHandler>();
var client = new HttpClient(mockHandler.Object);
Expand All @@ -440,7 +440,7 @@ public async void SetsTheApiExceptionStatusCode(HttpStatusCode statusCode)
var response = await adapter.SendPrimitiveAsync<Stream>(requestInfo);
Assert.Fail("Expected an ApiException to be thrown");
}
catch(ApiException e)
catch (ApiException e)
{
Assert.Equal((int)statusCode, e.ResponseStatusCode);
Assert.True(e.ResponseHeaders.ContainsKey("request-id"));
Expand All @@ -449,7 +449,7 @@ public async void SetsTheApiExceptionStatusCode(HttpStatusCode statusCode)
[InlineData(HttpStatusCode.NotFound)]// 4XX
[InlineData(HttpStatusCode.BadGateway)]// 5XX
[Theory]
public async void SelectsTheXXXErrorMappingClassCorrectly(HttpStatusCode statusCode)
public async Task SelectsTheXXXErrorMappingClassCorrectly(HttpStatusCode statusCode)
{
var mockHandler = new Mock<HttpMessageHandler>();
var client = new HttpClient(mockHandler.Object);
Expand All @@ -460,7 +460,7 @@ public async void SelectsTheXXXErrorMappingClassCorrectly(HttpStatusCode statusC
var responseMessage = new HttpResponseMessage
{
StatusCode = statusCode,
Content = new StringContent("{}",Encoding.UTF8,"application/json")
Content = new StringContent("{}", Encoding.UTF8, "application/json")
};
return responseMessage;
});
Expand All @@ -485,15 +485,15 @@ public async void SelectsTheXXXErrorMappingClassCorrectly(HttpStatusCode statusC
var response = await adapter.SendPrimitiveAsync<Stream>(requestInfo, errorMapping);
Assert.Fail("Expected an ApiException to be thrown");
}
catch(MockError mockError)
catch (MockError mockError)
{
Assert.Equal((int)statusCode, mockError.ResponseStatusCode);
Assert.Equal("A general error occured", mockError.Message);
}
}
[InlineData(HttpStatusCode.BadGateway)]// 5XX
[Theory]
public async void ThrowsApiExceptionOnMissingMapping(HttpStatusCode statusCode)
public async Task ThrowsApiExceptionOnMissingMapping(HttpStatusCode statusCode)
{
var mockHandler = new Mock<HttpMessageHandler>();
var client = new HttpClient(mockHandler.Object);
Expand All @@ -510,7 +510,7 @@ public async void ThrowsApiExceptionOnMissingMapping(HttpStatusCode statusCode)
});
var mockParseNode = new Mock<IParseNode>();
mockParseNode.Setup<IParsable>(x => x.GetObjectValue(It.IsAny<ParsableFactory<IParsable>>()))
.Returns(new MockError("A general error occured: "+ statusCode.ToString()));
.Returns(new MockError("A general error occured: " + statusCode.ToString()));
var mockParseNodeFactory = new Mock<IParseNodeFactory>();
mockParseNodeFactory.Setup<IParseNode>(x => x.GetRootParseNode(It.IsAny<string>(), It.IsAny<Stream>()))
.Returns(mockParseNode.Object);
Expand All @@ -529,7 +529,7 @@ public async void ThrowsApiExceptionOnMissingMapping(HttpStatusCode statusCode)
var response = await adapter.SendPrimitiveAsync<Stream>(requestInfo, errorMapping);
Assert.Fail("Expected an ApiException to be thrown");
}
catch(ApiException apiException)
catch (ApiException apiException)
{
Assert.Equal((int)statusCode, apiException.ResponseStatusCode);
Assert.Contains("The server returned an unexpected status code and no error factory is registered for this code", apiException.Message);
Expand Down
Loading

0 comments on commit 7b234ee

Please sign in to comment.