-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #297 from microsoft/andrueastman/kiotaBundle
Adds bundle package
- Loading branch information
Showing
10 changed files
with
212 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// ------------------------------------------------------------------------------ | ||
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information. | ||
// ------------------------------------------------------------------------------ | ||
|
||
using System.Net.Http; | ||
using Microsoft.Kiota.Abstractions; | ||
using Microsoft.Kiota.Abstractions.Authentication; | ||
using Microsoft.Kiota.Abstractions.Serialization; | ||
using Microsoft.Kiota.Http.HttpClientLibrary; | ||
using Microsoft.Kiota.Serialization.Form; | ||
using Microsoft.Kiota.Serialization.Json; | ||
using Microsoft.Kiota.Serialization.Multipart; | ||
using Microsoft.Kiota.Serialization.Text; | ||
|
||
namespace Microsoft.Kiota.Bundle | ||
{ | ||
/// <summary> | ||
/// The <see cref="IRequestAdapter"/> implementation that derived from <see cref="HttpClientRequestAdapter"/> with registrations configured. | ||
/// </summary> | ||
public class DefaultRequestAdapter : HttpClientRequestAdapter | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="DefaultRequestAdapter"/> class. | ||
/// </summary> | ||
/// <param name="authenticationProvider">The authentication provider.</param> | ||
/// <param name="parseNodeFactory">The parse node factory.</param> | ||
/// <param name="serializationWriterFactory">The serialization writer factory.</param> | ||
/// <param name="httpClient">The native HTTP client.</param> | ||
/// <param name="observabilityOptions">The observability options.</param> | ||
public DefaultRequestAdapter(IAuthenticationProvider authenticationProvider, IParseNodeFactory? parseNodeFactory = null, ISerializationWriterFactory? serializationWriterFactory = null, HttpClient? httpClient = null, ObservabilityOptions? observabilityOptions = null) : base(authenticationProvider, parseNodeFactory, serializationWriterFactory, httpClient, observabilityOptions) | ||
{ | ||
SetupDefaults(); | ||
} | ||
|
||
private static void SetupDefaults() | ||
{ | ||
// Setup the default serializers/deserializers | ||
ApiClientBuilder.RegisterDefaultSerializer<JsonSerializationWriterFactory>(); | ||
ApiClientBuilder.RegisterDefaultSerializer<TextSerializationWriterFactory>(); | ||
ApiClientBuilder.RegisterDefaultSerializer<FormSerializationWriterFactory>(); | ||
ApiClientBuilder.RegisterDefaultSerializer<MultipartSerializationWriterFactory>(); | ||
ApiClientBuilder.RegisterDefaultDeserializer<JsonParseNodeFactory>(); | ||
ApiClientBuilder.RegisterDefaultDeserializer<TextParseNodeFactory>(); | ||
ApiClientBuilder.RegisterDefaultDeserializer<FormParseNodeFactory>(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<Sdk Name="Microsoft.DotNet.PackageValidation" Version="1.0.0-preview.7.21379.12" /> | ||
|
||
<PropertyGroup> | ||
<Description>Kiota Bundle package providing default implementations for client setup.</Description> | ||
<AssemblyTitle>Kiota Bundle package for dotnet</AssemblyTitle> | ||
<!-- NET 5 target to be removed on next major version--> | ||
<TargetFrameworks>netstandard2.0;netstandard2.1;net5.0;net6.0;net8.0</TargetFrameworks> | ||
<GenerateDocumentationFile>true</GenerateDocumentationFile> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\abstractions\Microsoft.Kiota.Abstractions.csproj" /> | ||
<ProjectReference Include="..\http\httpClient\Microsoft.Kiota.Http.HttpClientLibrary.csproj" /> | ||
<ProjectReference Include="..\serialization\form\Microsoft.Kiota.Serialization.Form.csproj" /> | ||
<ProjectReference Include="..\serialization\json\Microsoft.Kiota.Serialization.Json.csproj" /> | ||
<ProjectReference Include="..\serialization\multipart\Microsoft.Kiota.Serialization.Multipart.csproj" /> | ||
<ProjectReference Include="..\serialization\text\Microsoft.Kiota.Serialization.Text.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Kiota Bundle Library for dotnet | ||
|
||
The Kiota Bundle Library for dotnet is the dotnet library providing default implementations for client setup. | ||
The package provides a request adapter implementation with defaults serialization libraries setup fo use with a generated Kiota client. | ||
|
||
Read more about Kiota [here](https://github.com/microsoft/kiota/blob/main/README.md). | ||
|
||
## Using the Bundle Library | ||
|
||
```shell | ||
dotnet add package Microsoft.Kiota.Bundle | ||
``` | ||
|
||
## Debugging | ||
|
||
If you are using Visual Studio Code as your IDE, the **launch.json** file already contains the configuration to build and test the library. Otherwise, you can open the **Microsoft.Kiota.Abstractions.sln** with Visual Studio. | ||
|
||
## Contributing | ||
|
||
This project welcomes contributions and suggestions. Most contributions require you to agree to a | ||
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us | ||
the rights to use your contribution. For details, visit [https://cla.opensource.microsoft.com](https://cla.opensource.microsoft.com). | ||
|
||
When you submit a pull request, a CLA bot will automatically determine whether you need to provide | ||
a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions | ||
provided by the bot. You will only need to do this once across all repos using our CLA. | ||
|
||
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). | ||
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or | ||
contact [[email protected]](mailto:[email protected]) with any additional questions or comments. | ||
|
||
## Trademarks | ||
|
||
This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft | ||
trademarks or logos is subject to and must follow | ||
[Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/legal/intellectualproperty/trademarks/usage/general). | ||
Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. | ||
Any use of third-party trademarks or logos are subject to those third-party's policies. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using System; | ||
using Microsoft.Kiota.Abstractions.Authentication; | ||
using Microsoft.Kiota.Abstractions.Serialization; | ||
using Xunit; | ||
|
||
namespace Microsoft.Kiota.Bundle.Tests | ||
{ | ||
public class BundleTests | ||
{ | ||
[Fact] | ||
public void ThrowsArgumentNullExceptionOnNullAuthenticationProvider() | ||
{ | ||
var exception = Assert.Throws<ArgumentNullException>(() => new DefaultRequestAdapter(null!)); | ||
Assert.Equal("authenticationProvider", exception.ParamName); | ||
} | ||
|
||
[Fact] | ||
public void SerializersAreRegisteredAsExpected() | ||
{ | ||
// setup | ||
_ = new DefaultRequestAdapter(new AnonymousAuthenticationProvider()); | ||
|
||
// validate | ||
var serializerCount = SerializationWriterFactoryRegistry.DefaultInstance.ContentTypeAssociatedFactories.Count; | ||
var deserializerCount = ParseNodeFactoryRegistry.DefaultInstance.ContentTypeAssociatedFactories.Count; | ||
|
||
Assert.Equal(4, serializerCount); // four serializers present | ||
Assert.Equal(3, deserializerCount);// three deserializers present | ||
|
||
var serializerKeys = SerializationWriterFactoryRegistry.DefaultInstance.ContentTypeAssociatedFactories.Keys; | ||
var deserializerKeys = ParseNodeFactoryRegistry.DefaultInstance.ContentTypeAssociatedFactories.Keys; | ||
|
||
Assert.Contains("application/json", serializerKeys); | ||
Assert.Contains("application/json", deserializerKeys);// Serializer and deserializer present for application/json | ||
|
||
Assert.Contains("text/plain", serializerKeys); | ||
Assert.Contains("text/plain", deserializerKeys);// Serializer and deserializer present for text/plain | ||
|
||
Assert.Contains("application/x-www-form-urlencoded", serializerKeys); | ||
Assert.Contains("application/x-www-form-urlencoded", deserializerKeys);// Serializer and deserializer present for application/x-www-form-urlencoded | ||
|
||
Assert.Contains("multipart/form-data", serializerKeys);// Serializer present for multipart/form-data | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<IsTestProject>true</IsTestProject> | ||
<TargetFrameworks>net8.0;net462</TargetFrameworks> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="coverlet.msbuild" Version="6.0.2"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" /> | ||
<!-- We need Microsoft.TestPlatform.ObjectModel for net framework execution in linux | ||
environments https://github.com/microsoft/vstest/issues/2469--> | ||
<PackageReference Include="Microsoft.TestPlatform.ObjectModel" Version="17.10.0" /> | ||
<PackageReference Include="Moq" Version="4.20.70" /> | ||
<PackageReference Include="xunit" Version="2.9.0" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="6.0.2"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\bundle\Microsoft.Kiota.Bundle.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |