From 2dec79dadcc28bea232cec833338dc49a9f32be0 Mon Sep 17 00:00:00 2001 From: Ricky Kaare Engelharth Date: Thu, 8 Aug 2024 08:40:41 +0200 Subject: [PATCH 1/3] Add Azure Rest sample using netstandard2.0 --- Cabazure.Client.sln | 24 +++ .../AzureRest.Client/AzureRest.Client.csproj | 15 ++ .../AzureRestClientOptions.cs | 25 +++ .../Endpoints/IGetSubscription.cs | 16 ++ .../Endpoints/IListSubscriptions.cs | 15 ++ .../ServiceCollectionExtensions.cs | 17 ++ .../AzureRest.Contracts.csproj | 11 ++ .../AzureRest.Contracts/CountValue.cs | 9 + .../AzureRest.Contracts/ListResponse.cs | 9 + .../AzureRest.Contracts/ManagedByTenant.cs | 7 + .../JsonSerializerOptionsFactory.cs | 23 +++ .../AzureRest.Contracts/Subscription.cs | 21 +++ .../SubscriptionPolicies.cs | 11 ++ .../AzureRest.TestApp.csproj | 20 +++ .../ConfigureAzureRestClientOptions.cs | 14 ++ .../AzureRest/AzureRest.TestApp/Program.cs | 26 +++ .../ClientEndpointGenerator.cs | 72 ++++---- .../ClientInitializationGenerator.cs | 148 +++++++-------- .../AzureAuthenticationHandler.g.cs | 35 ++-- .../Authentication/BearerTokenProvider.g.cs | 57 +++--- .../Authentication/DateTimeProvider.g.cs | 13 +- .../Authentication/IBearerTokenProvider.g.cs | 13 +- .../Authentication/IDateTimeProvider.g.cs | 9 +- .../EmbeddedSource/BodyAttribute.g.cs | 24 +-- .../Builder/ClientSerializer.g.cs | 27 +-- .../Builder/HttpClientBuilderExtensions.g.cs | 56 +++--- .../Builder/HttpClientExtensions.g.cs | 21 ++- .../Builder/IClientSerializer.g.cs | 11 +- .../Builder/IMessageRequestBuilder.g.cs | 22 +-- .../Builder/IMessageRequestFactory.g.cs | 11 +- .../Builder/IMessageResponseBuilder.g.cs | 28 +-- .../Builder/MessageRequestBuilder.g.cs | 167 ++++++++--------- .../Builder/MessageRequestFactory.g.cs | 25 +-- .../Builder/MessageResponseBuilder.g.cs | 169 +++++++++--------- .../ClientEndpointAttribute.g.cs | 40 +++-- .../EmbeddedSource/DeleteAttribute.g.cs | 36 ++-- .../EmbeddedSource/GetAttribute.g.cs | 36 ++-- .../EmbeddedSource/HeaderAttribute.g.cs | 42 ++--- .../ICabazureAuthClientOptions.g.cs | 29 +-- .../ICabazureClientOptions.g.cs | 25 +-- .../EmbeddedSource/PathAttribute.g.cs | 42 ++--- .../EmbeddedSource/PostAttribute.g.cs | 36 ++-- .../EmbeddedSource/PutAttribute.g.cs | 36 ++-- .../EmbeddedSource/QueryAttribute.g.cs | 42 ++--- 44 files changed, 940 insertions(+), 595 deletions(-) create mode 100644 samples/AzureRest/AzureRest.Client/AzureRest.Client.csproj create mode 100644 samples/AzureRest/AzureRest.Client/AzureRestClientOptions.cs create mode 100644 samples/AzureRest/AzureRest.Client/Endpoints/IGetSubscription.cs create mode 100644 samples/AzureRest/AzureRest.Client/Endpoints/IListSubscriptions.cs create mode 100644 samples/AzureRest/AzureRest.Client/ServiceCollectionExtensions.cs create mode 100644 samples/AzureRest/AzureRest.Contracts/AzureRest.Contracts.csproj create mode 100644 samples/AzureRest/AzureRest.Contracts/CountValue.cs create mode 100644 samples/AzureRest/AzureRest.Contracts/ListResponse.cs create mode 100644 samples/AzureRest/AzureRest.Contracts/ManagedByTenant.cs create mode 100644 samples/AzureRest/AzureRest.Contracts/Serialization/JsonSerializerOptionsFactory.cs create mode 100644 samples/AzureRest/AzureRest.Contracts/Subscription.cs create mode 100644 samples/AzureRest/AzureRest.Contracts/SubscriptionPolicies.cs create mode 100644 samples/AzureRest/AzureRest.TestApp/AzureRest.TestApp.csproj create mode 100644 samples/AzureRest/AzureRest.TestApp/Options/ConfigureAzureRestClientOptions.cs create mode 100644 samples/AzureRest/AzureRest.TestApp/Program.cs diff --git a/Cabazure.Client.sln b/Cabazure.Client.sln index 561d770..3e3b01e 100644 --- a/Cabazure.Client.sln +++ b/Cabazure.Client.sln @@ -27,6 +27,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Graph.TestApp", " EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Graph.Contracts", "samples\Microsoft.Graph\Microsoft.Graph.Contracts\Microsoft.Graph.Contracts.csproj", "{733A2A34-8B64-4A54-B996-EB84F07FE989}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "AzureRest", "AzureRest", "{D2D03799-0BB4-45C1-9D35-60F364C154EE}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AzureRest.Client", "samples\AzureRest\AzureRest.Client\AzureRest.Client.csproj", "{469837C7-D9B8-4867-A1CD-747DBA16213B}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AzureRest.Contracts", "samples\AzureRest\AzureRest.Contracts\AzureRest.Contracts.csproj", "{C19CB361-795D-49FF-8821-E4C739EE5020}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AzureRest.TestApp", "samples\AzureRest\AzureRest.TestApp\AzureRest.TestApp.csproj", "{CF5F841E-FC86-441D-8075-49EA5F280AB8}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -65,6 +73,18 @@ Global {733A2A34-8B64-4A54-B996-EB84F07FE989}.Debug|Any CPU.Build.0 = Debug|Any CPU {733A2A34-8B64-4A54-B996-EB84F07FE989}.Release|Any CPU.ActiveCfg = Release|Any CPU {733A2A34-8B64-4A54-B996-EB84F07FE989}.Release|Any CPU.Build.0 = Release|Any CPU + {469837C7-D9B8-4867-A1CD-747DBA16213B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {469837C7-D9B8-4867-A1CD-747DBA16213B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {469837C7-D9B8-4867-A1CD-747DBA16213B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {469837C7-D9B8-4867-A1CD-747DBA16213B}.Release|Any CPU.Build.0 = Release|Any CPU + {C19CB361-795D-49FF-8821-E4C739EE5020}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C19CB361-795D-49FF-8821-E4C739EE5020}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C19CB361-795D-49FF-8821-E4C739EE5020}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C19CB361-795D-49FF-8821-E4C739EE5020}.Release|Any CPU.Build.0 = Release|Any CPU + {CF5F841E-FC86-441D-8075-49EA5F280AB8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CF5F841E-FC86-441D-8075-49EA5F280AB8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CF5F841E-FC86-441D-8075-49EA5F280AB8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CF5F841E-FC86-441D-8075-49EA5F280AB8}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -79,6 +99,10 @@ Global {3DF0DD77-F029-418F-96B9-5E977F11E8C2} = {3932F1A3-4272-4E08-83F6-E1EB7DCED0FC} {84D328C1-9835-4CDC-865F-8A1FD1D65489} = {3DF0DD77-F029-418F-96B9-5E977F11E8C2} {733A2A34-8B64-4A54-B996-EB84F07FE989} = {3DF0DD77-F029-418F-96B9-5E977F11E8C2} + {D2D03799-0BB4-45C1-9D35-60F364C154EE} = {3932F1A3-4272-4E08-83F6-E1EB7DCED0FC} + {469837C7-D9B8-4867-A1CD-747DBA16213B} = {D2D03799-0BB4-45C1-9D35-60F364C154EE} + {C19CB361-795D-49FF-8821-E4C739EE5020} = {D2D03799-0BB4-45C1-9D35-60F364C154EE} + {CF5F841E-FC86-441D-8075-49EA5F280AB8} = {D2D03799-0BB4-45C1-9D35-60F364C154EE} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {3DD1DF42-FFAB-4F35-B264-B128D2778D40} diff --git a/samples/AzureRest/AzureRest.Client/AzureRest.Client.csproj b/samples/AzureRest/AzureRest.Client/AzureRest.Client.csproj new file mode 100644 index 0000000..2bf9223 --- /dev/null +++ b/samples/AzureRest/AzureRest.Client/AzureRest.Client.csproj @@ -0,0 +1,15 @@ + + + + netstandard2.0 + 9.0 + enable + + + + + + + + + diff --git a/samples/AzureRest/AzureRest.Client/AzureRestClientOptions.cs b/samples/AzureRest/AzureRest.Client/AzureRestClientOptions.cs new file mode 100644 index 0000000..044a334 --- /dev/null +++ b/samples/AzureRest/AzureRest.Client/AzureRestClientOptions.cs @@ -0,0 +1,25 @@ +using System; +using Azure.Core; +using Cabazure.Client; + +namespace AzureRest.Client +{ + public class AzureRestClientOptions : ICabazureAuthClientOptions + { + public TokenCredential? Credential { get; set; } + + Uri ICabazureClientOptions.GetBaseAddress() + // Notice the trailing slash, it's important + // for the client to work correctly with relative paths. + => new("https://management.azure.com/"); + + string ICabazureAuthClientOptions.GetScope() + // The default scope for Microsoft Graph. + => "https://management.azure.com/.default"; + + TokenCredential ICabazureAuthClientOptions.GetCredential() + => Credential + ?? throw new InvalidOperationException( + "No Credential configured for GraphClientOptions"); + } +} diff --git a/samples/AzureRest/AzureRest.Client/Endpoints/IGetSubscription.cs b/samples/AzureRest/AzureRest.Client/Endpoints/IGetSubscription.cs new file mode 100644 index 0000000..9c0ddd5 --- /dev/null +++ b/samples/AzureRest/AzureRest.Client/Endpoints/IGetSubscription.cs @@ -0,0 +1,16 @@ +using System.Threading; +using System.Threading.Tasks; +using AzureRest.Contracts; +using Cabazure.Client; + +namespace AzureRest.Client.Endpoints +{ + [ClientEndpoint("azure-rest-client")] + public interface IGetSubscription + { + [Get("subscriptions/{subscriptionId}?api-version=2022-12-01")] + public Task> ExecuteAsync( + [Path] string subscriptionId, + CancellationToken cancellationToken = default); + } +} diff --git a/samples/AzureRest/AzureRest.Client/Endpoints/IListSubscriptions.cs b/samples/AzureRest/AzureRest.Client/Endpoints/IListSubscriptions.cs new file mode 100644 index 0000000..1847743 --- /dev/null +++ b/samples/AzureRest/AzureRest.Client/Endpoints/IListSubscriptions.cs @@ -0,0 +1,15 @@ +using System.Threading; +using System.Threading.Tasks; +using AzureRest.Contracts; +using Cabazure.Client; + +namespace AzureRest.Client.Endpoints +{ + [ClientEndpoint("azure-rest-client")] + public interface IListSubscriptions + { + [Get("https://management.azure.com/subscriptions?api-version=2022-12-01")] + public Task>> ExecuteAsync( + CancellationToken cancellationToken = default); + } +} diff --git a/samples/AzureRest/AzureRest.Client/ServiceCollectionExtensions.cs b/samples/AzureRest/AzureRest.Client/ServiceCollectionExtensions.cs new file mode 100644 index 0000000..9b619c6 --- /dev/null +++ b/samples/AzureRest/AzureRest.Client/ServiceCollectionExtensions.cs @@ -0,0 +1,17 @@ +using System; +using AzureRest.Client; +using AzureRest.Contracts.Serialization; + +namespace Microsoft.Extensions.DependencyInjection +{ + public static class ServiceCollectionExtensions + { + public static IServiceCollection AddAzureRestClient( + this IServiceCollection services, + Action? clientOptions = null) + => services.AddCabazureClient( + "azure-rest-client", + j => JsonSerializerOptionsFactory.Configure(j), + clientOptions); + } +} diff --git a/samples/AzureRest/AzureRest.Contracts/AzureRest.Contracts.csproj b/samples/AzureRest/AzureRest.Contracts/AzureRest.Contracts.csproj new file mode 100644 index 0000000..33c2f97 --- /dev/null +++ b/samples/AzureRest/AzureRest.Contracts/AzureRest.Contracts.csproj @@ -0,0 +1,11 @@ + + + + netstandard2.0 + + + + + + + diff --git a/samples/AzureRest/AzureRest.Contracts/CountValue.cs b/samples/AzureRest/AzureRest.Contracts/CountValue.cs new file mode 100644 index 0000000..b5db1ca --- /dev/null +++ b/samples/AzureRest/AzureRest.Contracts/CountValue.cs @@ -0,0 +1,9 @@ +namespace AzureRest.Contracts +{ + public class CountValue + { + public string Type { get; set; } + + public int Value { get; set; } + } +} diff --git a/samples/AzureRest/AzureRest.Contracts/ListResponse.cs b/samples/AzureRest/AzureRest.Contracts/ListResponse.cs new file mode 100644 index 0000000..32caa23 --- /dev/null +++ b/samples/AzureRest/AzureRest.Contracts/ListResponse.cs @@ -0,0 +1,9 @@ +namespace AzureRest.Contracts +{ + public class ListResponse + { + public CountValue Count { get; set; } + + public T[] Value { get; set; } + } +} diff --git a/samples/AzureRest/AzureRest.Contracts/ManagedByTenant.cs b/samples/AzureRest/AzureRest.Contracts/ManagedByTenant.cs new file mode 100644 index 0000000..0d741c6 --- /dev/null +++ b/samples/AzureRest/AzureRest.Contracts/ManagedByTenant.cs @@ -0,0 +1,7 @@ +namespace AzureRest.Contracts +{ + public class ManagedByTenant + { + public string TenantId { get; set; } + } +} \ No newline at end of file diff --git a/samples/AzureRest/AzureRest.Contracts/Serialization/JsonSerializerOptionsFactory.cs b/samples/AzureRest/AzureRest.Contracts/Serialization/JsonSerializerOptionsFactory.cs new file mode 100644 index 0000000..c1be644 --- /dev/null +++ b/samples/AzureRest/AzureRest.Contracts/Serialization/JsonSerializerOptionsFactory.cs @@ -0,0 +1,23 @@ +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace AzureRest.Contracts.Serialization +{ + public static class JsonSerializerOptionsFactory + { + public static JsonSerializerOptions Create() + => Configure(new JsonSerializerOptions()); + + public static JsonSerializerOptions Configure( + this JsonSerializerOptions options) + { + options.PropertyNamingPolicy = JsonNamingPolicy.CamelCase; + options.PropertyNameCaseInsensitive = true; + options.Converters.Add( + new JsonStringEnumConverter( + JsonNamingPolicy.CamelCase)); + + return options; + } + } +} diff --git a/samples/AzureRest/AzureRest.Contracts/Subscription.cs b/samples/AzureRest/AzureRest.Contracts/Subscription.cs new file mode 100644 index 0000000..5b2ab63 --- /dev/null +++ b/samples/AzureRest/AzureRest.Contracts/Subscription.cs @@ -0,0 +1,21 @@ +namespace AzureRest.Contracts +{ + public class Subscription + { + public string AuthorizationSource { get; set; } + + public string DisplayName { get; set; } + + public string Id { get; set; } + + public ManagedByTenant[] ManagedByTenants { get; set; } + + public string State { get; set; } + + public string SubscriptionId { get; set; } + + public SubscriptionPolicies SubscriptionPolicies { get; set; } + + public string TenantId { get; set; } + } +} \ No newline at end of file diff --git a/samples/AzureRest/AzureRest.Contracts/SubscriptionPolicies.cs b/samples/AzureRest/AzureRest.Contracts/SubscriptionPolicies.cs new file mode 100644 index 0000000..682ae1a --- /dev/null +++ b/samples/AzureRest/AzureRest.Contracts/SubscriptionPolicies.cs @@ -0,0 +1,11 @@ +namespace AzureRest.Contracts +{ + public class SubscriptionPolicies + { + public string LocationPlacementId { get; set; } + + public string QuotaId { get; set; } + + public string SpendingLimit { get; set; } + } +} \ No newline at end of file diff --git a/samples/AzureRest/AzureRest.TestApp/AzureRest.TestApp.csproj b/samples/AzureRest/AzureRest.TestApp/AzureRest.TestApp.csproj new file mode 100644 index 0000000..cfbf9bd --- /dev/null +++ b/samples/AzureRest/AzureRest.TestApp/AzureRest.TestApp.csproj @@ -0,0 +1,20 @@ + + + + Exe + net8.0 + enable + enable + + + + + + + + + + + + + diff --git a/samples/AzureRest/AzureRest.TestApp/Options/ConfigureAzureRestClientOptions.cs b/samples/AzureRest/AzureRest.TestApp/Options/ConfigureAzureRestClientOptions.cs new file mode 100644 index 0000000..aa78975 --- /dev/null +++ b/samples/AzureRest/AzureRest.TestApp/Options/ConfigureAzureRestClientOptions.cs @@ -0,0 +1,14 @@ +using Azure.Identity; +using AzureRest.Client; +using Microsoft.Extensions.Options; + +namespace AzureRest.TestApp.Options; + +public class ConfigureAzureRestClientOptions + : IConfigureOptions +{ + public void Configure(AzureRestClientOptions options) + { + options.Credential = new DefaultAzureCredential(); + } +} diff --git a/samples/AzureRest/AzureRest.TestApp/Program.cs b/samples/AzureRest/AzureRest.TestApp/Program.cs new file mode 100644 index 0000000..8728616 --- /dev/null +++ b/samples/AzureRest/AzureRest.TestApp/Program.cs @@ -0,0 +1,26 @@ +using AzureRest.Client.Endpoints; +using AzureRest.TestApp.Options; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; + +var builder = Host.CreateApplicationBuilder(args); + +builder.Services.ConfigureOptions(); +builder.Services.AddAzureRestClient(); + +var app = builder.Build(); + +var endpoint = app.Services.GetRequiredService(); + +var result = await endpoint.ExecuteAsync(); +if (result.OkContent is not { } list) +{ + Console.WriteLine(result.StatusCode); + return; +} + +Console.WriteLine($"Found {list.Count.Value} subscriptions ({list.Count.Type}):"); +foreach (var subscription in list.Value) +{ + Console.WriteLine($" - {subscription.DisplayName} ({subscription.SubscriptionId})"); +} \ No newline at end of file diff --git a/src/Cabazure.Client/ClientEndpointGenerator.cs b/src/Cabazure.Client/ClientEndpointGenerator.cs index c606fa9..99c1ca0 100644 --- a/src/Cabazure.Client/ClientEndpointGenerator.cs +++ b/src/Cabazure.Client/ClientEndpointGenerator.cs @@ -39,6 +39,7 @@ private static void ProcessEndpoint( var usingStatements = endpoint .Usings .Append("System.Net") + .Append("System.Net.Http") .Append("Cabazure.Client") .Append("Cabazure.Client.Builder") .Where(us => us != endpoint.Namespace) @@ -57,22 +58,23 @@ private static void ProcessEndpoint( if (endpoint.Namespace != null) { - source.AppendLine($"namespace {endpoint.Namespace};\n"); + source.AppendLine($"namespace {endpoint.Namespace}"); + source.AppendLine($"{{"); } source.AppendLine($$""" - internal partial class {{endpoint.ClassName}} : {{endpoint.InterfaceName}} - { - private readonly IHttpClientFactory factory; - private readonly IMessageRequestFactory requestFactory; - - public {{endpoint.ClassName}}( - IHttpClientFactory factory, - IMessageRequestFactory requestFactory) + internal partial class {{endpoint.ClassName}} : {{endpoint.InterfaceName}} { - this.factory = factory; - this.requestFactory = requestFactory; - } + private readonly IHttpClientFactory factory; + private readonly IMessageRequestFactory requestFactory; + + public {{endpoint.ClassName}}( + IHttpClientFactory factory, + IMessageRequestFactory requestFactory) + { + this.factory = factory; + this.requestFactory = requestFactory; + } """); foreach (var method in endpoint.Methods) @@ -83,7 +85,11 @@ internal partial class {{endpoint.ClassName}} : {{endpoint.InterfaceName}} endpoint.ClientName); } - source.AppendLine("}"); + source.AppendLine(" }"); + if (endpoint.Namespace != null) + { + source.AppendLine($"}}"); + } source.AppendLine("#nullable disable"); context.AddSource( @@ -101,28 +107,28 @@ private static void GenerateEndpointMethod( foreach (var p in method.PathParameters) { - requestOptions.Append($"\n .WithPathParameter(\"{p.Name}\", {GetParameterValue(p)})"); + requestOptions.Append($"\n .WithPathParameter(\"{p.Name}\", {GetParameterValue(p)})"); } foreach (var p in method.QueryParameters) { - requestOptions.Append($"\n .WithQueryParameter(\"{p.Name}\", {GetParameterValue(p)})"); + requestOptions.Append($"\n .WithQueryParameter(\"{p.Name}\", {GetParameterValue(p)})"); } foreach (var p in method.HeaderParameters) { - requestOptions.Append($"\n .WithHeader(\"{p.Name}\", {GetParameterValue(p)})"); + requestOptions.Append($"\n .WithHeader(\"{p.Name}\", {GetParameterValue(p)})"); } if (method.BodyParameter is { } b) { - requestOptions.Append($"\n .WithBody({b})"); + requestOptions.Append($"\n .WithBody({b})"); } if (method.OptionsParameter is { } o) { - clientOptions.Append($"\n .WithRequestOptions({o})"); - requestOptions.Append($"\n .WithRequestOptions({o})"); + clientOptions.Append($"\n .WithRequestOptions({o})"); + requestOptions.Append($"\n .WithRequestOptions({o})"); } var cancellationToken = method.CancellationTokenParameter @@ -136,26 +142,26 @@ private static void GenerateEndpointMethod( var resultConversion = method.ResponseType == null ? null - : $"\n response => new {method.ResponseType}(response),\n "; + : $"\n response => new {method.ResponseType}(response),\n "; source.AppendLine($$""" - {{method.Signature}} - { - var client = factory.CreateClient("{{clientName}}"); + {{method.Signature}} + { + var client = factory.CreateClient("{{clientName}}"); - using var requestMessage = requestFactory - .FromTemplate("{{clientName}}", "{{method.RouteTemplate}}"){{requestOptions}} - .Build(HttpMethod.{{method.HttpMethod}}); + using var requestMessage = requestFactory + .FromTemplate("{{clientName}}", "{{method.RouteTemplate}}"){{requestOptions}} + .Build(HttpMethod.{{method.HttpMethod}}); - using var response = await client{{clientOptions}} - .SendAsync(requestMessage, {{cancellationToken}}); + using var response = await client{{clientOptions}} + .SendAsync(requestMessage, {{cancellationToken}}); - return await requestFactory - .FromResponse("{{clientName}}", response) - .AddSuccessResponse{{resultGeneric}}(HttpStatusCode.OK) - .GetAsync({{resultConversion}}{{cancellationToken}}); - } + return await requestFactory + .FromResponse("{{clientName}}", response) + .AddSuccessResponse{{resultGeneric}}(HttpStatusCode.OK) + .GetAsync({{resultConversion}}{{cancellationToken}}); + } """); } diff --git a/src/Cabazure.Client/ClientInitializationGenerator.cs b/src/Cabazure.Client/ClientInitializationGenerator.cs index 204b002..6880e79 100644 --- a/src/Cabazure.Client/ClientInitializationGenerator.cs +++ b/src/Cabazure.Client/ClientInitializationGenerator.cs @@ -16,75 +16,79 @@ public void Initialize(GeneratorInitializationContext context) """ // #nullable enable + using System; + using System.Collections.Generic; + using System.Net.Http; using System.Text.Json; using Azure.Core; using Cabazure.Client; using Cabazure.Client.Authentication; using Microsoft.Extensions.Options; - namespace Microsoft.Extensions.DependencyInjection; - - internal static partial class ClientInitialization + namespace Microsoft.Extensions.DependencyInjection { - internal static IServiceCollection AddCabazureClient( - this IServiceCollection services, - string clientName, - Action? jsonOptions, - Action? clientOptions, - Action? builder = default) - where TOptions : class, ICabazureClientOptions + internal static partial class ClientInitialization { - if (clientOptions != null) + internal static IServiceCollection AddCabazureClient( + this IServiceCollection services, + string clientName, + Action? jsonOptions, + Action? clientOptions, + Action? builder = default) + where TOptions : class, ICabazureClientOptions { - services - .AddOptions() - .Configure(clientOptions); - } + if (clientOptions != null) + { + services + .AddOptions() + .Configure(clientOptions); + } - void ConfigureHttpClient(IServiceProvider services, HttpClient client) - => client.BaseAddress = services - .GetRequiredService>() - .Value - .GetBaseAddress(); + void ConfigureHttpClient(IServiceProvider services, HttpClient client) + => client.BaseAddress = services + .GetRequiredService>() + .Value + .GetBaseAddress(); - void ConfigureAuthHandler(IList handlers, IServiceProvider services) - { - var options = services - .GetRequiredService>() - .Value; - - if (options is ICabazureAuthClientOptions authOptions) + void ConfigureAuthHandler(IList handlers, IServiceProvider services) { - var scope = authOptions.GetScope(); - var credential = authOptions.GetCredential(); - - var tokenProvider = new BearerTokenProvider( - new TokenRequestContext(new [] { scope }), - credential, - new DateTimeProvider()); + var options = services + .GetRequiredService>() + .Value; + + if (options is ICabazureAuthClientOptions authOptions) + { + var scope = authOptions.GetScope(); + var credential = authOptions.GetCredential(); + + var tokenProvider = new BearerTokenProvider( + new TokenRequestContext(new [] { scope }), + credential, + new DateTimeProvider()); + + handlers.Add(new AzureAuthenticationHandler(tokenProvider)); + } + } - handlers.Add(new AzureAuthenticationHandler(tokenProvider)); + void BuildHttpClient(IHttpClientBuilder b) + { + b.ConfigureHttpClient(ConfigureHttpClient); + b.ConfigureAdditionalHttpMessageHandlers(ConfigureAuthHandler); + builder?.Invoke(b); } - } - void BuildHttpClient(IHttpClientBuilder b) - { - b.ConfigureHttpClient(ConfigureHttpClient); - b.ConfigureAdditionalHttpMessageHandlers(ConfigureAuthHandler); - builder?.Invoke(b); + return services.AddCabazureClient( + clientName, + jsonOptions, + BuildHttpClient); } - return services.AddCabazureClient( - clientName, - jsonOptions, - BuildHttpClient); + internal static partial IServiceCollection AddCabazureClient( + this IServiceCollection services, + string clientName, + Action? jsonOptions, + Action builder); } - - internal static partial IServiceCollection AddCabazureClient( - this IServiceCollection services, - string clientName, - Action? jsonOptions, - Action builder); } #nullable disable """)); @@ -109,6 +113,7 @@ public void Execute(GeneratorExecutionContext context) var usingStatements = receiver.Endpoints .Select(e => e.Namespace) .OfType() + .Append("System") .Append("System.Text.Json") .Append("Cabazure.Client.Builder") .Append("Microsoft.Extensions.DependencyInjection.Extensions") @@ -126,42 +131,43 @@ public void Execute(GeneratorExecutionContext context) } source.AppendLine($$""" - namespace Microsoft.Extensions.DependencyInjection; - - internal static partial class ClientInitialization + namespace Microsoft.Extensions.DependencyInjection { - internal static partial IServiceCollection AddCabazureClient( - this IServiceCollection services, - string clientName, - Action? jsonOptions, - Action builder) + internal static partial class ClientInitialization { - if (jsonOptions != null) + internal static partial IServiceCollection AddCabazureClient( + this IServiceCollection services, + string clientName, + Action? jsonOptions, + Action builder) { - services - .AddOptions(clientName) - .Configure(jsonOptions); - } + if (jsonOptions != null) + { + services + .AddOptions(clientName) + .Configure(jsonOptions); + } - var clientBuilder = services.AddHttpClient(clientName); - builder.Invoke(clientBuilder); + var clientBuilder = services.AddHttpClient(clientName); + builder.Invoke(clientBuilder); - services.TryAddSingleton(); - services.TryAddSingleton(); + services.TryAddSingleton(); + services.TryAddSingleton(); """); foreach (var endpoint in receiver.Endpoints) { source.AppendLine($$""" services.TryAddSingleton<{{endpoint.InterfaceName}}, {{endpoint.ClassName}}>(); - """); + """); } source.AppendLine(""" - return services; - } + return services; + } """); + source.AppendLine(" }"); source.AppendLine("}"); source.AppendLine("#nullable disable"); diff --git a/src/Cabazure.Client/EmbeddedSource/Authentication/AzureAuthenticationHandler.g.cs b/src/Cabazure.Client/EmbeddedSource/Authentication/AzureAuthenticationHandler.g.cs index 0350ef5..89eeafe 100644 --- a/src/Cabazure.Client/EmbeddedSource/Authentication/AzureAuthenticationHandler.g.cs +++ b/src/Cabazure.Client/EmbeddedSource/Authentication/AzureAuthenticationHandler.g.cs @@ -1,25 +1,30 @@ // #nullable enable -namespace Cabazure.Client.Authentication; +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; -internal class AzureAuthenticationHandler - : DelegatingHandler +namespace Cabazure.Client.Authentication { - private readonly IBearerTokenProvider tokenProvider; - - public AzureAuthenticationHandler( - IBearerTokenProvider tokenProvider) + internal class AzureAuthenticationHandler + : DelegatingHandler { - this.tokenProvider = tokenProvider; - } + private readonly IBearerTokenProvider tokenProvider; - protected async override Task SendAsync( - HttpRequestMessage request, - CancellationToken cancellationToken) - { - request.Headers.Authorization = await tokenProvider.GetTokenAsync(cancellationToken); + public AzureAuthenticationHandler( + IBearerTokenProvider tokenProvider) + { + this.tokenProvider = tokenProvider; + } + + protected async override Task SendAsync( + HttpRequestMessage request, + CancellationToken cancellationToken) + { + request.Headers.Authorization = await tokenProvider.GetTokenAsync(cancellationToken); - return await base.SendAsync(request, cancellationToken); + return await base.SendAsync(request, cancellationToken); + } } } #nullable disable \ No newline at end of file diff --git a/src/Cabazure.Client/EmbeddedSource/Authentication/BearerTokenProvider.g.cs b/src/Cabazure.Client/EmbeddedSource/Authentication/BearerTokenProvider.g.cs index 783fdeb..3ac0960 100644 --- a/src/Cabazure.Client/EmbeddedSource/Authentication/BearerTokenProvider.g.cs +++ b/src/Cabazure.Client/EmbeddedSource/Authentication/BearerTokenProvider.g.cs @@ -1,41 +1,44 @@ // #nullable enable using System.Net.Http.Headers; +using System.Threading; +using System.Threading.Tasks; using Azure.Core; -namespace Cabazure.Client.Authentication; - -internal class BearerTokenProvider : IBearerTokenProvider +namespace Cabazure.Client.Authentication { - private readonly TokenRequestContext context; - private readonly TokenCredential credential; - private readonly IDateTimeProvider dateTimeProvider; - private AccessToken accessToken; - - public BearerTokenProvider( - TokenRequestContext context, - TokenCredential credential, - IDateTimeProvider dateTimeProvider) + internal class BearerTokenProvider : IBearerTokenProvider { - this.context = context; - this.credential = credential; - this.dateTimeProvider = dateTimeProvider; - } + private readonly TokenRequestContext context; + private readonly TokenCredential credential; + private readonly IDateTimeProvider dateTimeProvider; + private AccessToken accessToken; - public async Task GetTokenAsync( - CancellationToken cancellationToken) - { - if (TokenIsExpired()) + public BearerTokenProvider( + TokenRequestContext context, + TokenCredential credential, + IDateTimeProvider dateTimeProvider) { - accessToken = await credential.GetTokenAsync(context, cancellationToken); + this.context = context; + this.credential = credential; + this.dateTimeProvider = dateTimeProvider; } - return new AuthenticationHeaderValue( - "Bearer", - accessToken.Token); - } + public async Task GetTokenAsync( + CancellationToken cancellationToken) + { + if (TokenIsExpired()) + { + accessToken = await credential.GetTokenAsync(context, cancellationToken); + } + + return new AuthenticationHeaderValue( + "Bearer", + accessToken.Token); + } - private bool TokenIsExpired() - => dateTimeProvider.GetDateTime().AddMinutes(1) > accessToken.ExpiresOn; + private bool TokenIsExpired() + => dateTimeProvider.GetDateTime().AddMinutes(1) > accessToken.ExpiresOn; + } } #nullable disable \ No newline at end of file diff --git a/src/Cabazure.Client/EmbeddedSource/Authentication/DateTimeProvider.g.cs b/src/Cabazure.Client/EmbeddedSource/Authentication/DateTimeProvider.g.cs index 91fea00..7f01fdd 100644 --- a/src/Cabazure.Client/EmbeddedSource/Authentication/DateTimeProvider.g.cs +++ b/src/Cabazure.Client/EmbeddedSource/Authentication/DateTimeProvider.g.cs @@ -1,11 +1,14 @@ // #nullable enable -namespace Cabazure.Client.Authentication; +using System; -internal class DateTimeProvider - : IDateTimeProvider +namespace Cabazure.Client.Authentication { - public DateTimeOffset GetDateTime() - => DateTimeOffset.UtcNow; + internal class DateTimeProvider + : IDateTimeProvider + { + public DateTimeOffset GetDateTime() + => DateTimeOffset.UtcNow; + } } #nullable disable \ No newline at end of file diff --git a/src/Cabazure.Client/EmbeddedSource/Authentication/IBearerTokenProvider.g.cs b/src/Cabazure.Client/EmbeddedSource/Authentication/IBearerTokenProvider.g.cs index 5678852..a5b0bdd 100644 --- a/src/Cabazure.Client/EmbeddedSource/Authentication/IBearerTokenProvider.g.cs +++ b/src/Cabazure.Client/EmbeddedSource/Authentication/IBearerTokenProvider.g.cs @@ -1,12 +1,15 @@ // #nullable enable using System.Net.Http.Headers; +using System.Threading; +using System.Threading.Tasks; -namespace Cabazure.Client.Authentication; - -internal interface IBearerTokenProvider +namespace Cabazure.Client.Authentication { - Task GetTokenAsync( - CancellationToken cancellationToken); + internal interface IBearerTokenProvider + { + Task GetTokenAsync( + CancellationToken cancellationToken); + } } #nullable disable \ No newline at end of file diff --git a/src/Cabazure.Client/EmbeddedSource/Authentication/IDateTimeProvider.g.cs b/src/Cabazure.Client/EmbeddedSource/Authentication/IDateTimeProvider.g.cs index 5506980..d5fbd4c 100644 --- a/src/Cabazure.Client/EmbeddedSource/Authentication/IDateTimeProvider.g.cs +++ b/src/Cabazure.Client/EmbeddedSource/Authentication/IDateTimeProvider.g.cs @@ -1,9 +1,12 @@ // #nullable enable -namespace Cabazure.Client.Authentication; +using System; -internal interface IDateTimeProvider +namespace Cabazure.Client.Authentication { - DateTimeOffset GetDateTime(); + internal interface IDateTimeProvider + { + DateTimeOffset GetDateTime(); + } } #nullable disable \ No newline at end of file diff --git a/src/Cabazure.Client/EmbeddedSource/BodyAttribute.g.cs b/src/Cabazure.Client/EmbeddedSource/BodyAttribute.g.cs index 8306f10..2285bdd 100644 --- a/src/Cabazure.Client/EmbeddedSource/BodyAttribute.g.cs +++ b/src/Cabazure.Client/EmbeddedSource/BodyAttribute.g.cs @@ -1,18 +1,20 @@ // #nullable enable +using System; using System.Diagnostics.CodeAnalysis; -namespace Cabazure.Client; - -/// -/// Specifies that a parameter should be bound to the request body. -/// -[ExcludeFromCodeCoverage] -[AttributeUsage( - AttributeTargets.Parameter | AttributeTargets.Property, - Inherited = false, - AllowMultiple = false)] -internal sealed class BodyAttribute : Attribute +namespace Cabazure.Client { + /// + /// Specifies that a parameter should be bound to the request body. + /// + [ExcludeFromCodeCoverage] + [AttributeUsage( + AttributeTargets.Parameter | AttributeTargets.Property, + Inherited = false, + AllowMultiple = false)] + internal sealed class BodyAttribute : Attribute + { + } } #nullable disable \ No newline at end of file diff --git a/src/Cabazure.Client/EmbeddedSource/Builder/ClientSerializer.g.cs b/src/Cabazure.Client/EmbeddedSource/Builder/ClientSerializer.g.cs index 12a65a5..9c16edb 100644 --- a/src/Cabazure.Client/EmbeddedSource/Builder/ClientSerializer.g.cs +++ b/src/Cabazure.Client/EmbeddedSource/Builder/ClientSerializer.g.cs @@ -3,22 +3,23 @@ using System.Text.Json; using Microsoft.Extensions.Options; -namespace Cabazure.Client.Builder; - -internal class ClientSerializer : IClientSerializer +namespace Cabazure.Client.Builder { - private readonly IOptionsMonitor options; - - public ClientSerializer( - IOptionsMonitor options) + internal class ClientSerializer : IClientSerializer { - this.options = options; - } + private readonly IOptionsMonitor options; - public string Serialize(string clientName, object value) - => JsonSerializer.Serialize(value, options.Get(clientName)); + public ClientSerializer( + IOptionsMonitor options) + { + this.options = options; + } - public T? Deserialize(string clientName, string json) - => JsonSerializer.Deserialize(json, options.Get(clientName)); + public string Serialize(string clientName, object value) + => JsonSerializer.Serialize(value, options.Get(clientName)); + + public T? Deserialize(string clientName, string json) + => JsonSerializer.Deserialize(json, options.Get(clientName)); + } } #nullable disable \ No newline at end of file diff --git a/src/Cabazure.Client/EmbeddedSource/Builder/HttpClientBuilderExtensions.g.cs b/src/Cabazure.Client/EmbeddedSource/Builder/HttpClientBuilderExtensions.g.cs index 35cfc06..848cee6 100644 --- a/src/Cabazure.Client/EmbeddedSource/Builder/HttpClientBuilderExtensions.g.cs +++ b/src/Cabazure.Client/EmbeddedSource/Builder/HttpClientBuilderExtensions.g.cs @@ -1,39 +1,41 @@ // #nullable enable +using System; using Azure.Core; using Cabazure.Client.Authentication; -namespace Microsoft.Extensions.DependencyInjection; - -internal static class HttpClientBuilderExtensions +namespace Microsoft.Extensions.DependencyInjection { - public static IHttpClientBuilder SetBaseAddress( - this IHttpClientBuilder builder, - Uri baseAddress) - => builder.ConfigureHttpClient(c => c.BaseAddress = baseAddress); + internal static class HttpClientBuilderExtensions + { + public static IHttpClientBuilder SetBaseAddress( + this IHttpClientBuilder builder, + Uri baseAddress) + => builder.ConfigureHttpClient(c => c.BaseAddress = baseAddress); - public static IHttpClientBuilder AddAuthentication( - this IHttpClientBuilder builder, - string scope, - TokenCredential credential) - => AddAuthentication( - builder, - new TokenRequestContext(new[] { scope }), - credential); + public static IHttpClientBuilder AddAuthentication( + this IHttpClientBuilder builder, + string scope, + TokenCredential credential) + => AddAuthentication( + builder, + new TokenRequestContext(new[] { scope }), + credential); - public static IHttpClientBuilder AddAuthentication( - this IHttpClientBuilder builder, - TokenRequestContext context, - TokenCredential credential) - { - var tokenProvider = new BearerTokenProvider( - context, - credential, - new DateTimeProvider()); + public static IHttpClientBuilder AddAuthentication( + this IHttpClientBuilder builder, + TokenRequestContext context, + TokenCredential credential) + { + var tokenProvider = new BearerTokenProvider( + context, + credential, + new DateTimeProvider()); - return builder - .AddHttpMessageHandler( - () => new AzureAuthenticationHandler(tokenProvider)); + return builder + .AddHttpMessageHandler( + () => new AzureAuthenticationHandler(tokenProvider)); + } } } #nullable disable \ No newline at end of file diff --git a/src/Cabazure.Client/EmbeddedSource/Builder/HttpClientExtensions.g.cs b/src/Cabazure.Client/EmbeddedSource/Builder/HttpClientExtensions.g.cs index 28552d9..6b5673a 100644 --- a/src/Cabazure.Client/EmbeddedSource/Builder/HttpClientExtensions.g.cs +++ b/src/Cabazure.Client/EmbeddedSource/Builder/HttpClientExtensions.g.cs @@ -1,19 +1,22 @@ // #nullable enable -namespace Cabazure.Client.Builder; +using System.Net.Http; -internal static class HttpClientExtensions +namespace Cabazure.Client.Builder { - public static HttpClient WithRequestOptions( - this HttpClient httpClient, - IRequestOptions? requestOptions) + internal static class HttpClientExtensions { - if (requestOptions is { Timeout: { Ticks: > 0 } timeout }) + public static HttpClient WithRequestOptions( + this HttpClient httpClient, + IRequestOptions? requestOptions) { - httpClient.Timeout = timeout; - } + if (requestOptions is { Timeout: { Ticks: > 0 } timeout }) + { + httpClient.Timeout = timeout; + } - return httpClient; + return httpClient; + } } } #nullable disable \ No newline at end of file diff --git a/src/Cabazure.Client/EmbeddedSource/Builder/IClientSerializer.g.cs b/src/Cabazure.Client/EmbeddedSource/Builder/IClientSerializer.g.cs index 2a88783..810832d 100644 --- a/src/Cabazure.Client/EmbeddedSource/Builder/IClientSerializer.g.cs +++ b/src/Cabazure.Client/EmbeddedSource/Builder/IClientSerializer.g.cs @@ -1,10 +1,11 @@ // #nullable enable -namespace Cabazure.Client.Builder; - -internal interface IClientSerializer +namespace Cabazure.Client.Builder { - T? Deserialize(string clientName, string json); - string Serialize(string clientName, object value); + internal interface IClientSerializer + { + T? Deserialize(string clientName, string json); + string Serialize(string clientName, object value); + } } #nullable disable \ No newline at end of file diff --git a/src/Cabazure.Client/EmbeddedSource/Builder/IMessageRequestBuilder.g.cs b/src/Cabazure.Client/EmbeddedSource/Builder/IMessageRequestBuilder.g.cs index 61917e2..acb1493 100644 --- a/src/Cabazure.Client/EmbeddedSource/Builder/IMessageRequestBuilder.g.cs +++ b/src/Cabazure.Client/EmbeddedSource/Builder/IMessageRequestBuilder.g.cs @@ -1,22 +1,24 @@ // #nullable enable +using System.Net.Http; using Microsoft.Extensions.Primitives; -namespace Cabazure.Client.Builder; - -internal interface IMessageRequestBuilder +namespace Cabazure.Client.Builder { - IMessageRequestBuilder WithPathParameter(string name, string value); + internal interface IMessageRequestBuilder + { + IMessageRequestBuilder WithPathParameter(string name, string value); - IMessageRequestBuilder WithQueryParameter(string name, string? value); + IMessageRequestBuilder WithQueryParameter(string name, string? value); - IMessageRequestBuilder WithHeader(string name, StringValues value); + IMessageRequestBuilder WithHeader(string name, StringValues value); - IMessageRequestBuilder WithRequestOptions(IRequestOptions? options); + IMessageRequestBuilder WithRequestOptions(IRequestOptions? options); - IMessageRequestBuilder WithBody(TBody body) - where TBody : class; + IMessageRequestBuilder WithBody(TBody body) + where TBody : class; - HttpRequestMessage Build(HttpMethod method); + HttpRequestMessage Build(HttpMethod method); + } } #nullable disable \ No newline at end of file diff --git a/src/Cabazure.Client/EmbeddedSource/Builder/IMessageRequestFactory.g.cs b/src/Cabazure.Client/EmbeddedSource/Builder/IMessageRequestFactory.g.cs index dc364b8..da00b34 100644 --- a/src/Cabazure.Client/EmbeddedSource/Builder/IMessageRequestFactory.g.cs +++ b/src/Cabazure.Client/EmbeddedSource/Builder/IMessageRequestFactory.g.cs @@ -1,11 +1,14 @@ // #nullable enable -namespace Cabazure.Client.Builder; +using System.Net.Http; -internal interface IMessageRequestFactory +namespace Cabazure.Client.Builder { - IMessageRequestBuilder FromTemplate(string clientName, string template); + internal interface IMessageRequestFactory + { + IMessageRequestBuilder FromTemplate(string clientName, string template); - IMessageResponseBuilder FromResponse(string clientName, HttpResponseMessage? response); + IMessageResponseBuilder FromResponse(string clientName, HttpResponseMessage? response); + } } #nullable disable \ No newline at end of file diff --git a/src/Cabazure.Client/EmbeddedSource/Builder/IMessageResponseBuilder.g.cs b/src/Cabazure.Client/EmbeddedSource/Builder/IMessageResponseBuilder.g.cs index b06e1aa..31b964d 100644 --- a/src/Cabazure.Client/EmbeddedSource/Builder/IMessageResponseBuilder.g.cs +++ b/src/Cabazure.Client/EmbeddedSource/Builder/IMessageResponseBuilder.g.cs @@ -1,24 +1,28 @@ // #nullable enable +using System; +using System.Threading; +using System.Threading.Tasks; using System.Net; -namespace Cabazure.Client.Builder; - -internal interface IMessageResponseBuilder +namespace Cabazure.Client.Builder { - IMessageResponseBuilder AddSuccessResponse(HttpStatusCode statusCode); + internal interface IMessageResponseBuilder + { + IMessageResponseBuilder AddSuccessResponse(HttpStatusCode statusCode); - IMessageResponseBuilder AddSuccessResponse(HttpStatusCode statusCode); + IMessageResponseBuilder AddSuccessResponse(HttpStatusCode statusCode); - IMessageResponseBuilder AddErrorResponse(HttpStatusCode statusCode); + IMessageResponseBuilder AddErrorResponse(HttpStatusCode statusCode); - IMessageResponseBuilder AddErrorResponse(HttpStatusCode statusCode); + IMessageResponseBuilder AddErrorResponse(HttpStatusCode statusCode); - Task GetAsync( - Func factory, - CancellationToken cancellationToken); + Task GetAsync( + Func factory, + CancellationToken cancellationToken); - Task GetAsync( - CancellationToken cancellationToken); + Task GetAsync( + CancellationToken cancellationToken); + } } #nullable disable \ No newline at end of file diff --git a/src/Cabazure.Client/EmbeddedSource/Builder/MessageRequestBuilder.g.cs b/src/Cabazure.Client/EmbeddedSource/Builder/MessageRequestBuilder.g.cs index bdbcd6c..f65938d 100644 --- a/src/Cabazure.Client/EmbeddedSource/Builder/MessageRequestBuilder.g.cs +++ b/src/Cabazure.Client/EmbeddedSource/Builder/MessageRequestBuilder.g.cs @@ -1,117 +1,122 @@ // #nullable enable +using System; +using System.Collections.Generic; using System.Globalization; +using System.Linq; +using System.Net.Http; using System.Net.Http.Headers; using System.Text; using Microsoft.Extensions.Primitives; -namespace Cabazure.Client.Builder; - -internal class MessageRequestBuilder : IMessageRequestBuilder +namespace Cabazure.Client.Builder { - private readonly Dictionary pathMapper = new(); - private readonly Dictionary queryMapper = new(); - private readonly Dictionary headerMapper = new(); - private readonly string template; - private readonly IClientSerializer serializer; - private readonly string clientName; - private string content = string.Empty; - - public MessageRequestBuilder( - string template, - IClientSerializer serializer, - string clientName) - { - this.template = template; - this.serializer = serializer; - this.clientName = clientName; - } - - public HttpRequestMessage Build(HttpMethod method) + internal class MessageRequestBuilder : IMessageRequestBuilder { - var message = new HttpRequestMessage(); - - message.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/json")); - message.RequestUri = BuildRequestUri(); - message.Content = new StringContent(content); - message.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json"); - message.Method = method; - message.Version = new Version(2, 0); - - foreach (var header in headerMapper) + private readonly Dictionary pathMapper = new(); + private readonly Dictionary queryMapper = new(); + private readonly Dictionary headerMapper = new(); + private readonly string template; + private readonly IClientSerializer serializer; + private readonly string clientName; + private string content = string.Empty; + + public MessageRequestBuilder( + string template, + IClientSerializer serializer, + string clientName) { - message.Headers.Add(header.Key, header.Value.ToArray()); + this.template = template; + this.serializer = serializer; + this.clientName = clientName; } - return message; - } - - public IMessageRequestBuilder WithHeader(string name, StringValues value) - { - if (!string.IsNullOrWhiteSpace(name) && !string.IsNullOrWhiteSpace(value)) + public HttpRequestMessage Build(HttpMethod method) { - headerMapper[name] = value; - } + var message = new HttpRequestMessage(); - return this; - } + message.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/json")); + message.RequestUri = BuildRequestUri(); + message.Content = new StringContent(content); + message.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json"); + message.Method = method; + message.Version = new Version(2, 0); - public IMessageRequestBuilder WithRequestOptions( - IRequestOptions? options) - { - if (options is { } o) - { - foreach (var header in o.GetHeaders()) + foreach (var header in headerMapper) { - WithHeader(header.Key, header.Value); + message.Headers.Add(header.Key, header.Value.ToArray()); } - } - return this; - } + return message; + } - public IMessageRequestBuilder WithBody(TBody body) - where TBody : class - { - content = serializer.Serialize(clientName, body); + public IMessageRequestBuilder WithHeader(string name, StringValues value) + { + if (!string.IsNullOrWhiteSpace(name) && !string.IsNullOrWhiteSpace(value)) + { + headerMapper[name] = value; + } - return this; - } + return this; + } - public IMessageRequestBuilder WithPathParameter(string name, string value) - { - pathMapper[name] = value; + public IMessageRequestBuilder WithRequestOptions( + IRequestOptions? options) + { + if (options is { } o) + { + foreach (var header in o.GetHeaders()) + { + WithHeader(header.Key, header.Value); + } + } - return this; - } + return this; + } - public IMessageRequestBuilder WithQueryParameter(string name, string? value) - { - if (value is not null) + public IMessageRequestBuilder WithBody(TBody body) + where TBody : class { - queryMapper[name] = value; + content = serializer.Serialize(clientName, body); + + return this; } - return this; - } + public IMessageRequestBuilder WithPathParameter(string name, string value) + { + pathMapper[name] = value; - private Uri BuildRequestUri() - { - var urlBuilder = new StringBuilder(); + return this; + } - urlBuilder.Append(template); - foreach (var parameter in pathMapper) + public IMessageRequestBuilder WithQueryParameter(string name, string? value) { - urlBuilder.Replace($"{{{parameter.Key}}}", Uri.EscapeDataString(parameter.Value)); + if (value is not null) + { + queryMapper[name] = value; + } + + return this; } - if (queryMapper.Count != 0) + private Uri BuildRequestUri() { - urlBuilder.Append(template.Contains('?') ? '&': '?'); - urlBuilder.Append(string.Join("&", queryMapper.Select(q => $"{q.Key}={Uri.EscapeDataString(q.Value)}"))); - } + var urlBuilder = new StringBuilder(); - return new Uri(urlBuilder.ToString(), UriKind.RelativeOrAbsolute); + urlBuilder.Append(template); + foreach (var parameter in pathMapper) + { + urlBuilder.Replace($"{{{parameter.Key}}}", Uri.EscapeDataString(parameter.Value)); + } + + if (queryMapper.Count != 0) + { + urlBuilder.Append(template.Contains('?') ? '&': '?'); + urlBuilder.Append(string.Join("&", queryMapper.Select(q => $"{q.Key}={Uri.EscapeDataString(q.Value)}"))); + } + + return new Uri(urlBuilder.ToString(), UriKind.RelativeOrAbsolute); + } } } #nullable disable \ No newline at end of file diff --git a/src/Cabazure.Client/EmbeddedSource/Builder/MessageRequestFactory.g.cs b/src/Cabazure.Client/EmbeddedSource/Builder/MessageRequestFactory.g.cs index 0bee69c..ec2499a 100644 --- a/src/Cabazure.Client/EmbeddedSource/Builder/MessageRequestFactory.g.cs +++ b/src/Cabazure.Client/EmbeddedSource/Builder/MessageRequestFactory.g.cs @@ -1,20 +1,23 @@ // #nullable enable -namespace Cabazure.Client.Builder; +using System.Net.Http; -internal class MessageRequestFactory : IMessageRequestFactory +namespace Cabazure.Client.Builder { - private readonly IClientSerializer serializer; - - public MessageRequestFactory(IClientSerializer serializer) + internal class MessageRequestFactory : IMessageRequestFactory { - this.serializer = serializer; - } + private readonly IClientSerializer serializer; - public IMessageResponseBuilder FromResponse(string clientName, HttpResponseMessage? response) - => new MessageResponseBuilder(response, serializer, clientName); + public MessageRequestFactory(IClientSerializer serializer) + { + this.serializer = serializer; + } - public IMessageRequestBuilder FromTemplate(string clientName, string template) - => new MessageRequestBuilder(template, serializer, clientName); + public IMessageResponseBuilder FromResponse(string clientName, HttpResponseMessage? response) + => new MessageResponseBuilder(response, serializer, clientName); + + public IMessageRequestBuilder FromTemplate(string clientName, string template) + => new MessageRequestBuilder(template, serializer, clientName); + } } #nullable disable \ No newline at end of file diff --git a/src/Cabazure.Client/EmbeddedSource/Builder/MessageResponseBuilder.g.cs b/src/Cabazure.Client/EmbeddedSource/Builder/MessageResponseBuilder.g.cs index bea3b35..348ff3d 100644 --- a/src/Cabazure.Client/EmbeddedSource/Builder/MessageResponseBuilder.g.cs +++ b/src/Cabazure.Client/EmbeddedSource/Builder/MessageResponseBuilder.g.cs @@ -1,113 +1,120 @@ // #nullable enable +using System; +using System.Collections.Generic; +using System.Net.Http; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; using System.Net; -namespace Cabazure.Client.Builder; - -internal delegate object? ContentSerializerDelegate(string content); - -internal class MessageResponseBuilder : IMessageResponseBuilder +namespace Cabazure.Client.Builder { - private static readonly EndpointResponse EmptyResponse = new( - false, - HttpStatusCode.InternalServerError, - string.Empty, - null, - new Dictionary>()); - - private readonly Dictionary responseSerializers = new(); - private readonly Dictionary responseCodes = new(); - private readonly HttpResponseMessage? response; - private readonly IClientSerializer serializer; - private readonly string clientName; - - public MessageResponseBuilder( - HttpResponseMessage? response, - IClientSerializer serializer, - string clientName) + internal delegate object? ContentSerializerDelegate(string content); + + internal class MessageResponseBuilder : IMessageResponseBuilder { - this.response = response; - this.serializer = serializer; - this.clientName = clientName; - } + private static readonly EndpointResponse EmptyResponse = new( + false, + HttpStatusCode.InternalServerError, + string.Empty, + null, + new Dictionary>()); + + private readonly Dictionary responseSerializers = new(); + private readonly Dictionary responseCodes = new(); + private readonly HttpResponseMessage? response; + private readonly IClientSerializer serializer; + private readonly string clientName; + + public MessageResponseBuilder( + HttpResponseMessage? response, + IClientSerializer serializer, + string clientName) + { + this.response = response; + this.serializer = serializer; + this.clientName = clientName; + } - public IMessageResponseBuilder AddErrorResponse(HttpStatusCode statusCode) - => AddEmptyResponse(statusCode, false); + public IMessageResponseBuilder AddErrorResponse(HttpStatusCode statusCode) + => AddEmptyResponse(statusCode, false); - public IMessageResponseBuilder AddErrorResponse(HttpStatusCode statusCode) - => AddTypedResponse(statusCode, false); + public IMessageResponseBuilder AddErrorResponse(HttpStatusCode statusCode) + => AddTypedResponse(statusCode, false); - public IMessageResponseBuilder AddSuccessResponse(HttpStatusCode statusCode) - => AddEmptyResponse(statusCode, true); + public IMessageResponseBuilder AddSuccessResponse(HttpStatusCode statusCode) + => AddEmptyResponse(statusCode, true); - public IMessageResponseBuilder AddSuccessResponse(HttpStatusCode statusCode) - => AddTypedResponse(statusCode, true); + public IMessageResponseBuilder AddSuccessResponse(HttpStatusCode statusCode) + => AddTypedResponse(statusCode, true); - public Task GetAsync(CancellationToken cancellationToken) - => GetAsync(r => r, cancellationToken); + public Task GetAsync(CancellationToken cancellationToken) + => GetAsync(r => r, cancellationToken); - public async Task GetAsync(Func factory, CancellationToken cancellationToken) - { - if (response is null) + public async Task GetAsync(Func factory, CancellationToken cancellationToken) { - return factory(EmptyResponse); - } + if (response is null) + { + return factory(EmptyResponse); + } #if NETSTANDARD2_0 || NETSTANDARD2_1 || NETCOREAPP2_0 || NETCOREAPP2_1 || NETCOREAPP2_2 || NETCOREAPP3_0 || NETCOREAPP3_1 - var content = await response.Content - .ReadAsStringAsync(); + var content = await response.Content + .ReadAsStringAsync(); #else - var content = await response.Content - .ReadAsStringAsync(cancellationToken); + var content = await response.Content + .ReadAsStringAsync(cancellationToken); #endif - return factory( - new EndpointResponse( - IsSuccessStatus(response), - response.StatusCode, - content, - GetSerializer(response.StatusCode)?.Invoke(content), - GetHeaders(response))); - } + return factory( + new EndpointResponse( + IsSuccessStatus(response), + response.StatusCode, + content, + GetSerializer(response.StatusCode)?.Invoke(content), + GetHeaders(response))); + } - private bool IsSuccessStatus(HttpResponseMessage responseMessage) - => responseCodes.TryGetValue(responseMessage.StatusCode, out var isSuccess) - ? isSuccess - : responseMessage.IsSuccessStatusCode; + private bool IsSuccessStatus(HttpResponseMessage responseMessage) + => responseCodes.TryGetValue(responseMessage.StatusCode, out var isSuccess) + ? isSuccess + : responseMessage.IsSuccessStatusCode; - private ContentSerializerDelegate? GetSerializer(HttpStatusCode statusCode) - => responseSerializers.TryGetValue(statusCode, out var @delegate) - ? @delegate - : null; + private ContentSerializerDelegate? GetSerializer(HttpStatusCode statusCode) + => responseSerializers.TryGetValue(statusCode, out var @delegate) + ? @delegate + : null; - private static Dictionary> GetHeaders(HttpResponseMessage responseMessage) - { - var headers = responseMessage.Headers.ToDictionary(h => h.Key, h => h.Value); - if (responseMessage.Content?.Headers is not null) + private static Dictionary> GetHeaders(HttpResponseMessage responseMessage) { - foreach (var item_ in responseMessage.Content.Headers) + var headers = responseMessage.Headers.ToDictionary(h => h.Key, h => h.Value); + if (responseMessage.Content?.Headers is not null) { - headers[item_.Key] = item_.Value; + foreach (var item_ in responseMessage.Content.Headers) + { + headers[item_.Key] = item_.Value; + } } - } - return headers; - } + return headers; + } - private MessageResponseBuilder AddEmptyResponse(HttpStatusCode statusCode, bool isSuccess) - { - responseSerializers[statusCode] = content => null; - responseCodes[statusCode] = isSuccess; + private MessageResponseBuilder AddEmptyResponse(HttpStatusCode statusCode, bool isSuccess) + { + responseSerializers[statusCode] = content => null; + responseCodes[statusCode] = isSuccess; - return this; - } + return this; + } - private MessageResponseBuilder AddTypedResponse(HttpStatusCode statusCode, bool isSuccess) - { - responseSerializers[statusCode] = content => serializer.Deserialize(clientName, content); - responseCodes[statusCode] = isSuccess; + private MessageResponseBuilder AddTypedResponse(HttpStatusCode statusCode, bool isSuccess) + { + responseSerializers[statusCode] = content => serializer.Deserialize(clientName, content); + responseCodes[statusCode] = isSuccess; - return this; + return this; + } } } #nullable disable \ No newline at end of file diff --git a/src/Cabazure.Client/EmbeddedSource/ClientEndpointAttribute.g.cs b/src/Cabazure.Client/EmbeddedSource/ClientEndpointAttribute.g.cs index 601f6c3..b95bbd5 100644 --- a/src/Cabazure.Client/EmbeddedSource/ClientEndpointAttribute.g.cs +++ b/src/Cabazure.Client/EmbeddedSource/ClientEndpointAttribute.g.cs @@ -1,28 +1,30 @@ // #nullable enable +using System; using System.Diagnostics.CodeAnalysis; -namespace Cabazure.Client; - -/// -/// Indicates that the interface is a specification for a client endpoint. -/// -[ExcludeFromCodeCoverage] -[AttributeUsage( - AttributeTargets.Interface, - Inherited = false, - AllowMultiple = false)] -internal sealed class ClientEndpointAttribute : Attribute +namespace Cabazure.Client { - public string ClientName { get; } - - /// - /// The name of the instance, the endpoint belongs to. - /// - public ClientEndpointAttribute( - string clientName) + /// + /// Indicates that the interface is a specification for a client endpoint. + /// + [ExcludeFromCodeCoverage] + [AttributeUsage( + AttributeTargets.Interface, + Inherited = false, + AllowMultiple = false)] + internal sealed class ClientEndpointAttribute : Attribute { - ClientName = clientName; + public string ClientName { get; } + + /// + /// The name of the instance, the endpoint belongs to. + /// + public ClientEndpointAttribute( + string clientName) + { + ClientName = clientName; + } } } #nullable disable \ No newline at end of file diff --git a/src/Cabazure.Client/EmbeddedSource/DeleteAttribute.g.cs b/src/Cabazure.Client/EmbeddedSource/DeleteAttribute.g.cs index 0afc4cc..7617172 100644 --- a/src/Cabazure.Client/EmbeddedSource/DeleteAttribute.g.cs +++ b/src/Cabazure.Client/EmbeddedSource/DeleteAttribute.g.cs @@ -1,26 +1,28 @@ // #nullable enable +using System; using System.Diagnostics.CodeAnalysis; -namespace Cabazure.Client; - -/// -/// Identifies a HTTP DELETE request call. -/// -[ExcludeFromCodeCoverage] -[AttributeUsage( - AttributeTargets.Method, - Inherited = false, - AllowMultiple = false)] -internal sealed class DeleteAttribute : Attribute +namespace Cabazure.Client { - public string RouteTemplate { get; } - - /// The relative request path which might include placeholders, like: /users/{id}. - public DeleteAttribute( - string routeTemplate) + /// + /// Identifies a HTTP DELETE request call. + /// + [ExcludeFromCodeCoverage] + [AttributeUsage( + AttributeTargets.Method, + Inherited = false, + AllowMultiple = false)] + internal sealed class DeleteAttribute : Attribute { - RouteTemplate = routeTemplate; + public string RouteTemplate { get; } + + /// The relative request path which might include placeholders, like: /users/{id}. + public DeleteAttribute( + string routeTemplate) + { + RouteTemplate = routeTemplate; + } } } #nullable disable \ No newline at end of file diff --git a/src/Cabazure.Client/EmbeddedSource/GetAttribute.g.cs b/src/Cabazure.Client/EmbeddedSource/GetAttribute.g.cs index af3d70b..b8b25bc 100644 --- a/src/Cabazure.Client/EmbeddedSource/GetAttribute.g.cs +++ b/src/Cabazure.Client/EmbeddedSource/GetAttribute.g.cs @@ -1,26 +1,28 @@ // #nullable enable +using System; using System.Diagnostics.CodeAnalysis; -namespace Cabazure.Client; - -/// -/// Identifies a HTTP GET request call. -/// -[ExcludeFromCodeCoverage] -[AttributeUsage( - AttributeTargets.Method, - Inherited = false, - AllowMultiple = false)] -internal sealed class GetAttribute : Attribute +namespace Cabazure.Client { - public string RouteTemplate { get; } - - /// The relative request path which might include placeholders, like: /users/{id}. - public GetAttribute( - string routeTemplate) + /// + /// Identifies a HTTP GET request call. + /// + [ExcludeFromCodeCoverage] + [AttributeUsage( + AttributeTargets.Method, + Inherited = false, + AllowMultiple = false)] + internal sealed class GetAttribute : Attribute { - RouteTemplate = routeTemplate; + public string RouteTemplate { get; } + + /// The relative request path which might include placeholders, like: /users/{id}. + public GetAttribute( + string routeTemplate) + { + RouteTemplate = routeTemplate; + } } } #nullable disable \ No newline at end of file diff --git a/src/Cabazure.Client/EmbeddedSource/HeaderAttribute.g.cs b/src/Cabazure.Client/EmbeddedSource/HeaderAttribute.g.cs index 6e475a1..5cd2327 100644 --- a/src/Cabazure.Client/EmbeddedSource/HeaderAttribute.g.cs +++ b/src/Cabazure.Client/EmbeddedSource/HeaderAttribute.g.cs @@ -1,30 +1,32 @@ // #nullable enable +using System; using System.Diagnostics.CodeAnalysis; -namespace Cabazure.Client; - -/// -/// Specifies that a parameter should be bound to a request header. -/// -[ExcludeFromCodeCoverage] -[AttributeUsage( - AttributeTargets.Parameter | AttributeTargets.Property, - Inherited = false, - AllowMultiple = false)] -internal sealed class HeaderAttribute : Attribute +namespace Cabazure.Client { - public string Name { get; } + /// + /// Specifies that a parameter should be bound to a request header. + /// + [ExcludeFromCodeCoverage] + [AttributeUsage( + AttributeTargets.Parameter | AttributeTargets.Property, + Inherited = false, + AllowMultiple = false)] + internal sealed class HeaderAttribute : Attribute + { + public string Name { get; } - public string? FormatString { get; } + public string? FormatString { get; } - /// The name of the request header. - public HeaderAttribute( - string name, - string? formatString = null) - { - Name = name; - FormatString = formatString; + /// The name of the request header. + public HeaderAttribute( + string name, + string? formatString = null) + { + Name = name; + FormatString = formatString; + } } } #nullable disable \ No newline at end of file diff --git a/src/Cabazure.Client/EmbeddedSource/ICabazureAuthClientOptions.g.cs b/src/Cabazure.Client/EmbeddedSource/ICabazureAuthClientOptions.g.cs index 7c929a6..873f45e 100644 --- a/src/Cabazure.Client/EmbeddedSource/ICabazureAuthClientOptions.g.cs +++ b/src/Cabazure.Client/EmbeddedSource/ICabazureAuthClientOptions.g.cs @@ -2,23 +2,24 @@ #nullable enable using Azure.Core; -namespace Cabazure.Client; - -/// -/// Options for a client that requires authentication. -/// -internal interface ICabazureAuthClientOptions : ICabazureClientOptions +namespace Cabazure.Client { /// - /// The scope to use for authorization token. + /// Options for a client that requires authentication. /// - /// The authorization scope. - string GetScope(); + internal interface ICabazureAuthClientOptions : ICabazureClientOptions + { + /// + /// The scope to use for authorization token. + /// + /// The authorization scope. + string GetScope(); - /// - /// The credential to use for authentication. - /// - /// The credential to use for authentication. - TokenCredential GetCredential(); + /// + /// The credential to use for authentication. + /// + /// The credential to use for authentication. + TokenCredential GetCredential(); + } } #nullable disable \ No newline at end of file diff --git a/src/Cabazure.Client/EmbeddedSource/ICabazureClientOptions.g.cs b/src/Cabazure.Client/EmbeddedSource/ICabazureClientOptions.g.cs index 9623fbb..0f9932c 100644 --- a/src/Cabazure.Client/EmbeddedSource/ICabazureClientOptions.g.cs +++ b/src/Cabazure.Client/EmbeddedSource/ICabazureClientOptions.g.cs @@ -1,19 +1,22 @@ // #nullable enable -namespace Cabazure.Client; +using System; -/// -/// The base options interface used to describe options that can resolve the BaseAddress of the API. -/// -internal interface ICabazureClientOptions +namespace Cabazure.Client { /// - /// The base address of the API. + /// The base options interface used to describe options that can resolve the BaseAddress of the API. /// - /// The base address for the API. - /// - /// If the base address contains path segments, use a trailing slash (/) to separate the base address from the relative path segments. - /// - Uri GetBaseAddress(); + internal interface ICabazureClientOptions + { + /// + /// The base address of the API. + /// + /// The base address for the API. + /// + /// If the base address contains path segments, use a trailing slash (/) to separate the base address from the relative path segments. + /// + Uri GetBaseAddress(); + } } #nullable disable \ No newline at end of file diff --git a/src/Cabazure.Client/EmbeddedSource/PathAttribute.g.cs b/src/Cabazure.Client/EmbeddedSource/PathAttribute.g.cs index b817b78..4e7879a 100644 --- a/src/Cabazure.Client/EmbeddedSource/PathAttribute.g.cs +++ b/src/Cabazure.Client/EmbeddedSource/PathAttribute.g.cs @@ -1,30 +1,32 @@ // #nullable enable +using System; using System.Diagnostics.CodeAnalysis; -namespace Cabazure.Client; - -/// -/// Specifies that a parameter should be added to a placeholder in the request path. -/// -[ExcludeFromCodeCoverage] -[AttributeUsage( - AttributeTargets.Parameter | AttributeTargets.Property, - Inherited = false, - AllowMultiple = false)] -internal sealed class PathAttribute : Attribute +namespace Cabazure.Client { - public string? Name { get; } + /// + /// Specifies that a parameter should be added to a placeholder in the request path. + /// + [ExcludeFromCodeCoverage] + [AttributeUsage( + AttributeTargets.Parameter | AttributeTargets.Property, + Inherited = false, + AllowMultiple = false)] + internal sealed class PathAttribute : Attribute + { + public string? Name { get; } - public string? FormatString { get; } + public string? FormatString { get; } - /// The name of the placeholder in the path. If obmitted, the parameter name will be used. - public PathAttribute( - string? name = null, - string? formatString = null) - { - Name = name; - FormatString = formatString; + /// The name of the placeholder in the path. If obmitted, the parameter name will be used. + public PathAttribute( + string? name = null, + string? formatString = null) + { + Name = name; + FormatString = formatString; + } } } #nullable disable \ No newline at end of file diff --git a/src/Cabazure.Client/EmbeddedSource/PostAttribute.g.cs b/src/Cabazure.Client/EmbeddedSource/PostAttribute.g.cs index 07da635..02ad05c 100644 --- a/src/Cabazure.Client/EmbeddedSource/PostAttribute.g.cs +++ b/src/Cabazure.Client/EmbeddedSource/PostAttribute.g.cs @@ -1,26 +1,28 @@ // #nullable enable +using System; using System.Diagnostics.CodeAnalysis; -namespace Cabazure.Client; - -/// -/// Identifies a HTTP POST request call. -/// -[ExcludeFromCodeCoverage] -[AttributeUsage( - AttributeTargets.Method, - Inherited = false, - AllowMultiple = false)] -internal sealed class PostAttribute : Attribute +namespace Cabazure.Client { - public string RouteTemplate { get; } - - /// The relative request path which might include placeholders, like: /users/{id}. - public PostAttribute( - string routeTemplate) + /// + /// Identifies a HTTP POST request call. + /// + [ExcludeFromCodeCoverage] + [AttributeUsage( + AttributeTargets.Method, + Inherited = false, + AllowMultiple = false)] + internal sealed class PostAttribute : Attribute { - RouteTemplate = routeTemplate; + public string RouteTemplate { get; } + + /// The relative request path which might include placeholders, like: /users/{id}. + public PostAttribute( + string routeTemplate) + { + RouteTemplate = routeTemplate; + } } } #nullable disable \ No newline at end of file diff --git a/src/Cabazure.Client/EmbeddedSource/PutAttribute.g.cs b/src/Cabazure.Client/EmbeddedSource/PutAttribute.g.cs index 1704818..8534892 100644 --- a/src/Cabazure.Client/EmbeddedSource/PutAttribute.g.cs +++ b/src/Cabazure.Client/EmbeddedSource/PutAttribute.g.cs @@ -1,26 +1,28 @@ // #nullable enable +using System; using System.Diagnostics.CodeAnalysis; -namespace Cabazure.Client; - -/// -/// Identifies a HTTP PUT request call. -/// -[ExcludeFromCodeCoverage] -[AttributeUsage( - AttributeTargets.Method, - Inherited = false, - AllowMultiple = false)] -internal sealed class PutAttribute : Attribute +namespace Cabazure.Client { - public string RouteTemplate { get; } - - /// The relative request path which might include placeholders, like: /users/{id}. - public PutAttribute( - string routeTemplate) + /// + /// Identifies a HTTP PUT request call. + /// + [ExcludeFromCodeCoverage] + [AttributeUsage( + AttributeTargets.Method, + Inherited = false, + AllowMultiple = false)] + internal sealed class PutAttribute : Attribute { - RouteTemplate = routeTemplate; + public string RouteTemplate { get; } + + /// The relative request path which might include placeholders, like: /users/{id}. + public PutAttribute( + string routeTemplate) + { + RouteTemplate = routeTemplate; + } } } #nullable disable \ No newline at end of file diff --git a/src/Cabazure.Client/EmbeddedSource/QueryAttribute.g.cs b/src/Cabazure.Client/EmbeddedSource/QueryAttribute.g.cs index 4c96f80..4000452 100644 --- a/src/Cabazure.Client/EmbeddedSource/QueryAttribute.g.cs +++ b/src/Cabazure.Client/EmbeddedSource/QueryAttribute.g.cs @@ -1,30 +1,32 @@ // #nullable enable +using System; using System.Diagnostics.CodeAnalysis; -namespace Cabazure.Client; - -/// -/// Specifies that a parameter should be bound to a request query parameter. -/// -[ExcludeFromCodeCoverage] -[AttributeUsage( - AttributeTargets.Parameter | AttributeTargets.Property, - Inherited = false, - AllowMultiple = false)] -internal sealed class QueryAttribute : Attribute +namespace Cabazure.Client { - public string? Name { get; } + /// + /// Specifies that a parameter should be bound to a request query parameter. + /// + [ExcludeFromCodeCoverage] + [AttributeUsage( + AttributeTargets.Parameter | AttributeTargets.Property, + Inherited = false, + AllowMultiple = false)] + internal sealed class QueryAttribute : Attribute + { + public string? Name { get; } - public string? FormatString { get; } + public string? FormatString { get; } - /// The name of tyhe query parameter. If obmitted, the parameter name will be used. - public QueryAttribute( - string? name = null, - string? formatString = null) - { - Name = name; - FormatString = formatString; + /// The name of tyhe query parameter. If obmitted, the parameter name will be used. + public QueryAttribute( + string? name = null, + string? formatString = null) + { + Name = name; + FormatString = formatString; + } } } #nullable disable \ No newline at end of file From 6e628d9a803c331b05adac8e2268e8f8f360f192 Mon Sep 17 00:00:00 2001 From: Ricky Kaare Engelharth Date: Thu, 8 Aug 2024 08:41:43 +0200 Subject: [PATCH 2/3] Remove Microsoft.Graph sample --- Cabazure.Client.sln | 30 ++-------------- .../Endpoints/IGetUserByEmail.cs | 13 ------- .../GraphClientOptions.cs | 24 ------------- .../Microsoft.Graph.Client.csproj | 15 -------- .../ServiceCollectionExtensions.cs | 15 -------- .../Microsoft.Graph.Contracts.csproj | 9 ----- .../JsonSerializerOptionsFactory.cs | 22 ------------ .../Microsoft.Graph.Contracts/User.cs | 14 -------- .../Microsoft.Graph.TestApp.csproj | 19 ----------- .../Options/ConfigureGraphClientOptions.cs | 14 -------- .../Microsoft.Graph.TestApp/Program.cs | 22 ------------ samples/Microsoft.Graph/Microsoft.Graph.sln | 34 ------------------- 12 files changed, 3 insertions(+), 228 deletions(-) delete mode 100644 samples/Microsoft.Graph/Microsoft.Graph.Client/Endpoints/IGetUserByEmail.cs delete mode 100644 samples/Microsoft.Graph/Microsoft.Graph.Client/GraphClientOptions.cs delete mode 100644 samples/Microsoft.Graph/Microsoft.Graph.Client/Microsoft.Graph.Client.csproj delete mode 100644 samples/Microsoft.Graph/Microsoft.Graph.Client/ServiceCollectionExtensions.cs delete mode 100644 samples/Microsoft.Graph/Microsoft.Graph.Contracts/Microsoft.Graph.Contracts.csproj delete mode 100644 samples/Microsoft.Graph/Microsoft.Graph.Contracts/Serialization/JsonSerializerOptionsFactory.cs delete mode 100644 samples/Microsoft.Graph/Microsoft.Graph.Contracts/User.cs delete mode 100644 samples/Microsoft.Graph/Microsoft.Graph.TestApp/Microsoft.Graph.TestApp.csproj delete mode 100644 samples/Microsoft.Graph/Microsoft.Graph.TestApp/Options/ConfigureGraphClientOptions.cs delete mode 100644 samples/Microsoft.Graph/Microsoft.Graph.TestApp/Program.cs delete mode 100644 samples/Microsoft.Graph/Microsoft.Graph.sln diff --git a/Cabazure.Client.sln b/Cabazure.Client.sln index 3e3b01e..b069e53 100644 --- a/Cabazure.Client.sln +++ b/Cabazure.Client.sln @@ -17,23 +17,15 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{9FD398E9-51D EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{115ACFA6-5271-4A7B-844D-FFEA0A4F6BB7}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Graph.Client", "samples\Microsoft.Graph\Microsoft.Graph.Client\Microsoft.Graph.Client.csproj", "{9D7D550E-15AA-4F2D-869D-53450E345FE7}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{3932F1A3-4272-4E08-83F6-E1EB7DCED0FC}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Microsoft.Graph", "Microsoft.Graph", "{3DF0DD77-F029-418F-96B9-5E977F11E8C2}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Graph.TestApp", "samples\Microsoft.Graph\Microsoft.Graph.TestApp\Microsoft.Graph.TestApp.csproj", "{84D328C1-9835-4CDC-865F-8A1FD1D65489}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Graph.Contracts", "samples\Microsoft.Graph\Microsoft.Graph.Contracts\Microsoft.Graph.Contracts.csproj", "{733A2A34-8B64-4A54-B996-EB84F07FE989}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "AzureRest", "AzureRest", "{D2D03799-0BB4-45C1-9D35-60F364C154EE}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AzureRest.Client", "samples\AzureRest\AzureRest.Client\AzureRest.Client.csproj", "{469837C7-D9B8-4867-A1CD-747DBA16213B}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AzureRest.Client", "samples\AzureRest\AzureRest.Client\AzureRest.Client.csproj", "{469837C7-D9B8-4867-A1CD-747DBA16213B}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AzureRest.Contracts", "samples\AzureRest\AzureRest.Contracts\AzureRest.Contracts.csproj", "{C19CB361-795D-49FF-8821-E4C739EE5020}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AzureRest.Contracts", "samples\AzureRest\AzureRest.Contracts\AzureRest.Contracts.csproj", "{C19CB361-795D-49FF-8821-E4C739EE5020}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AzureRest.TestApp", "samples\AzureRest\AzureRest.TestApp\AzureRest.TestApp.csproj", "{CF5F841E-FC86-441D-8075-49EA5F280AB8}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AzureRest.TestApp", "samples\AzureRest\AzureRest.TestApp\AzureRest.TestApp.csproj", "{CF5F841E-FC86-441D-8075-49EA5F280AB8}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -61,18 +53,6 @@ Global {A5A1DEAD-A6F6-47B5-B6A8-9ED08B5A0FD0}.Debug|Any CPU.Build.0 = Debug|Any CPU {A5A1DEAD-A6F6-47B5-B6A8-9ED08B5A0FD0}.Release|Any CPU.ActiveCfg = Release|Any CPU {A5A1DEAD-A6F6-47B5-B6A8-9ED08B5A0FD0}.Release|Any CPU.Build.0 = Release|Any CPU - {9D7D550E-15AA-4F2D-869D-53450E345FE7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {9D7D550E-15AA-4F2D-869D-53450E345FE7}.Debug|Any CPU.Build.0 = Debug|Any CPU - {9D7D550E-15AA-4F2D-869D-53450E345FE7}.Release|Any CPU.ActiveCfg = Release|Any CPU - {9D7D550E-15AA-4F2D-869D-53450E345FE7}.Release|Any CPU.Build.0 = Release|Any CPU - {84D328C1-9835-4CDC-865F-8A1FD1D65489}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {84D328C1-9835-4CDC-865F-8A1FD1D65489}.Debug|Any CPU.Build.0 = Debug|Any CPU - {84D328C1-9835-4CDC-865F-8A1FD1D65489}.Release|Any CPU.ActiveCfg = Release|Any CPU - {84D328C1-9835-4CDC-865F-8A1FD1D65489}.Release|Any CPU.Build.0 = Release|Any CPU - {733A2A34-8B64-4A54-B996-EB84F07FE989}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {733A2A34-8B64-4A54-B996-EB84F07FE989}.Debug|Any CPU.Build.0 = Debug|Any CPU - {733A2A34-8B64-4A54-B996-EB84F07FE989}.Release|Any CPU.ActiveCfg = Release|Any CPU - {733A2A34-8B64-4A54-B996-EB84F07FE989}.Release|Any CPU.Build.0 = Release|Any CPU {469837C7-D9B8-4867-A1CD-747DBA16213B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {469837C7-D9B8-4867-A1CD-747DBA16213B}.Debug|Any CPU.Build.0 = Debug|Any CPU {469837C7-D9B8-4867-A1CD-747DBA16213B}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -95,10 +75,6 @@ Global {CED809C0-4423-4B2D-BAF8-0C942B52761B} = {115ACFA6-5271-4A7B-844D-FFEA0A4F6BB7} {91529749-D468-43A2-8713-9428234FADFF} = {115ACFA6-5271-4A7B-844D-FFEA0A4F6BB7} {A5A1DEAD-A6F6-47B5-B6A8-9ED08B5A0FD0} = {115ACFA6-5271-4A7B-844D-FFEA0A4F6BB7} - {9D7D550E-15AA-4F2D-869D-53450E345FE7} = {3DF0DD77-F029-418F-96B9-5E977F11E8C2} - {3DF0DD77-F029-418F-96B9-5E977F11E8C2} = {3932F1A3-4272-4E08-83F6-E1EB7DCED0FC} - {84D328C1-9835-4CDC-865F-8A1FD1D65489} = {3DF0DD77-F029-418F-96B9-5E977F11E8C2} - {733A2A34-8B64-4A54-B996-EB84F07FE989} = {3DF0DD77-F029-418F-96B9-5E977F11E8C2} {D2D03799-0BB4-45C1-9D35-60F364C154EE} = {3932F1A3-4272-4E08-83F6-E1EB7DCED0FC} {469837C7-D9B8-4867-A1CD-747DBA16213B} = {D2D03799-0BB4-45C1-9D35-60F364C154EE} {C19CB361-795D-49FF-8821-E4C739EE5020} = {D2D03799-0BB4-45C1-9D35-60F364C154EE} diff --git a/samples/Microsoft.Graph/Microsoft.Graph.Client/Endpoints/IGetUserByEmail.cs b/samples/Microsoft.Graph/Microsoft.Graph.Client/Endpoints/IGetUserByEmail.cs deleted file mode 100644 index de9c16c..0000000 --- a/samples/Microsoft.Graph/Microsoft.Graph.Client/Endpoints/IGetUserByEmail.cs +++ /dev/null @@ -1,13 +0,0 @@ -using Cabazure.Client; -using Microsoft.Graph.Contracts; - -namespace Microsoft.Graph.Client.Endpoints; - -[ClientEndpoint("ms-graph-client")] -public interface IGetUserByEmail -{ - [Get("users/{email}")] - Task> ExecuteAsync( - [Path] string email, - CancellationToken cancellationToken = default); -} diff --git a/samples/Microsoft.Graph/Microsoft.Graph.Client/GraphClientOptions.cs b/samples/Microsoft.Graph/Microsoft.Graph.Client/GraphClientOptions.cs deleted file mode 100644 index 27caff7..0000000 --- a/samples/Microsoft.Graph/Microsoft.Graph.Client/GraphClientOptions.cs +++ /dev/null @@ -1,24 +0,0 @@ -using Azure.Core; -using Cabazure.Client; - -namespace Microsoft.Graph.Client; - -public class GraphClientOptions : ICabazureAuthClientOptions -{ - public TokenCredential? Credential { get; set; } - - Uri ICabazureClientOptions.GetBaseAddress() - // Notice the trailing slash, it's important - // for the client to work correctly with relative paths. - => new("https://graph.microsoft.com/v1.0/"); - - string ICabazureAuthClientOptions.GetScope() - // The default scope for Microsoft Graph. - => "https://graph.microsoft.com/.default"; - - TokenCredential ICabazureAuthClientOptions.GetCredential() - => Credential - ?? throw new InvalidOperationException( - "No Credential configured for GraphClientOptions"); - -} diff --git a/samples/Microsoft.Graph/Microsoft.Graph.Client/Microsoft.Graph.Client.csproj b/samples/Microsoft.Graph/Microsoft.Graph.Client/Microsoft.Graph.Client.csproj deleted file mode 100644 index f3fa2ba..0000000 --- a/samples/Microsoft.Graph/Microsoft.Graph.Client/Microsoft.Graph.Client.csproj +++ /dev/null @@ -1,15 +0,0 @@ - - - - net8.0 - enable - enable - - - - - - - - - diff --git a/samples/Microsoft.Graph/Microsoft.Graph.Client/ServiceCollectionExtensions.cs b/samples/Microsoft.Graph/Microsoft.Graph.Client/ServiceCollectionExtensions.cs deleted file mode 100644 index 57dab3b..0000000 --- a/samples/Microsoft.Graph/Microsoft.Graph.Client/ServiceCollectionExtensions.cs +++ /dev/null @@ -1,15 +0,0 @@ -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Graph.Contracts.Serialization; - -namespace Microsoft.Graph.Client; - -public static class ServiceCollectionExtensions -{ - public static IServiceCollection AddGraphClient( - this IServiceCollection services, - Action? clientOptions = null) - => services.AddCabazureClient( - "ms-graph-client", - j => JsonSerializerOptionsFactory.Configure(j), - clientOptions); -} diff --git a/samples/Microsoft.Graph/Microsoft.Graph.Contracts/Microsoft.Graph.Contracts.csproj b/samples/Microsoft.Graph/Microsoft.Graph.Contracts/Microsoft.Graph.Contracts.csproj deleted file mode 100644 index fa71b7a..0000000 --- a/samples/Microsoft.Graph/Microsoft.Graph.Contracts/Microsoft.Graph.Contracts.csproj +++ /dev/null @@ -1,9 +0,0 @@ - - - - net8.0 - enable - enable - - - diff --git a/samples/Microsoft.Graph/Microsoft.Graph.Contracts/Serialization/JsonSerializerOptionsFactory.cs b/samples/Microsoft.Graph/Microsoft.Graph.Contracts/Serialization/JsonSerializerOptionsFactory.cs deleted file mode 100644 index 6c01113..0000000 --- a/samples/Microsoft.Graph/Microsoft.Graph.Contracts/Serialization/JsonSerializerOptionsFactory.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System.Text.Json; -using System.Text.Json.Serialization; - -namespace Microsoft.Graph.Contracts.Serialization; - -public static class JsonSerializerOptionsFactory -{ - public static JsonSerializerOptions Create() - => Configure(new()); - - public static JsonSerializerOptions Configure( - this JsonSerializerOptions options) - { - options.PropertyNamingPolicy = JsonNamingPolicy.CamelCase; - options.PropertyNameCaseInsensitive = true; - options.Converters.Add( - new JsonStringEnumConverter( - JsonNamingPolicy.CamelCase)); - - return options; - } -} diff --git a/samples/Microsoft.Graph/Microsoft.Graph.Contracts/User.cs b/samples/Microsoft.Graph/Microsoft.Graph.Contracts/User.cs deleted file mode 100644 index af332f0..0000000 --- a/samples/Microsoft.Graph/Microsoft.Graph.Contracts/User.cs +++ /dev/null @@ -1,14 +0,0 @@ -namespace Microsoft.Graph.Contracts; - -public record User( - string? Id, - string? DisplayName, - string? GivenName, - string? Surname, - string? Mail, - string? MobilePhone, - string? OfficeLocation, - string? JobTitle, - string? UserPrincipalName, - string? PreferredLanguage, - IEnumerable? BusinessPhones); \ No newline at end of file diff --git a/samples/Microsoft.Graph/Microsoft.Graph.TestApp/Microsoft.Graph.TestApp.csproj b/samples/Microsoft.Graph/Microsoft.Graph.TestApp/Microsoft.Graph.TestApp.csproj deleted file mode 100644 index c1b73fe..0000000 --- a/samples/Microsoft.Graph/Microsoft.Graph.TestApp/Microsoft.Graph.TestApp.csproj +++ /dev/null @@ -1,19 +0,0 @@ - - - - Exe - net8.0 - enable - enable - - - - - - - - - - - - diff --git a/samples/Microsoft.Graph/Microsoft.Graph.TestApp/Options/ConfigureGraphClientOptions.cs b/samples/Microsoft.Graph/Microsoft.Graph.TestApp/Options/ConfigureGraphClientOptions.cs deleted file mode 100644 index 601cd02..0000000 --- a/samples/Microsoft.Graph/Microsoft.Graph.TestApp/Options/ConfigureGraphClientOptions.cs +++ /dev/null @@ -1,14 +0,0 @@ -using Azure.Identity; -using Microsoft.Extensions.Options; -using Microsoft.Graph.Client; - -namespace Microsoft.Graph.TestApp.Options; - -internal class ConfigureGraphClientOptions - : IConfigureOptions -{ - public void Configure(GraphClientOptions options) - { - options.Credential = new DefaultAzureCredential(); - } -} diff --git a/samples/Microsoft.Graph/Microsoft.Graph.TestApp/Program.cs b/samples/Microsoft.Graph/Microsoft.Graph.TestApp/Program.cs deleted file mode 100644 index 09d79b1..0000000 --- a/samples/Microsoft.Graph/Microsoft.Graph.TestApp/Program.cs +++ /dev/null @@ -1,22 +0,0 @@ -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; -using Microsoft.Graph.Client; -using Microsoft.Graph.Client.Endpoints; -using Microsoft.Graph.TestApp.Options; - -var builder = Host.CreateApplicationBuilder(args); - -builder.Services.ConfigureOptions(); -builder.Services.AddGraphClient(); - -var app = builder.Build(); - -var endpoint = app.Services.GetRequiredService(); - -var result = await endpoint.ExecuteAsync("frannis@contoso.com") switch -{ - { OkContent: { } r } => r.DisplayName, - var r => r.StatusCode.ToString(), -}; - -Console.WriteLine(result); \ No newline at end of file diff --git a/samples/Microsoft.Graph/Microsoft.Graph.sln b/samples/Microsoft.Graph/Microsoft.Graph.sln deleted file mode 100644 index f37b48d..0000000 --- a/samples/Microsoft.Graph/Microsoft.Graph.sln +++ /dev/null @@ -1,34 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.0.31903.59 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Graph.Contracts", "Microsoft.Graph.Contracts\Microsoft.Graph.Contracts.csproj", "{23143289-4D74-49F5-B9DB-5163422479A8}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Graph.Client", "Microsoft.Graph.Client\Microsoft.Graph.Client.csproj", "{D1EA0B5F-9DAE-4E94-8E13-8B26ABA4C1BE}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Graph.TestApp", "Microsoft.Graph.TestApp\Microsoft.Graph.TestApp.csproj", "{9DF4C04D-B409-4DE1-BFE3-24443D236120}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {23143289-4D74-49F5-B9DB-5163422479A8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {23143289-4D74-49F5-B9DB-5163422479A8}.Debug|Any CPU.Build.0 = Debug|Any CPU - {23143289-4D74-49F5-B9DB-5163422479A8}.Release|Any CPU.ActiveCfg = Release|Any CPU - {23143289-4D74-49F5-B9DB-5163422479A8}.Release|Any CPU.Build.0 = Release|Any CPU - {D1EA0B5F-9DAE-4E94-8E13-8B26ABA4C1BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {D1EA0B5F-9DAE-4E94-8E13-8B26ABA4C1BE}.Debug|Any CPU.Build.0 = Debug|Any CPU - {D1EA0B5F-9DAE-4E94-8E13-8B26ABA4C1BE}.Release|Any CPU.ActiveCfg = Release|Any CPU - {D1EA0B5F-9DAE-4E94-8E13-8B26ABA4C1BE}.Release|Any CPU.Build.0 = Release|Any CPU - {9DF4C04D-B409-4DE1-BFE3-24443D236120}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {9DF4C04D-B409-4DE1-BFE3-24443D236120}.Debug|Any CPU.Build.0 = Debug|Any CPU - {9DF4C04D-B409-4DE1-BFE3-24443D236120}.Release|Any CPU.ActiveCfg = Release|Any CPU - {9DF4C04D-B409-4DE1-BFE3-24443D236120}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection -EndGlobal From 173d0a17a6d3e8181df0ee8b85759625492bdea4 Mon Sep 17 00:00:00 2001 From: Ricky Kaare Engelharth Date: Thu, 8 Aug 2024 08:51:09 +0200 Subject: [PATCH 3/3] Update test snapshots --- ...Token_Parameter#TestEndpoint.g.verified.cs | 53 +++--- ...e_From_Constant#TestEndpoint.g.verified.cs | 58 +++--- ...ame_From_NameOf#TestEndpoint.g.verified.cs | 58 +++--- ...tions_Parameter#TestEndpoint.g.verified.cs | 57 +++--- ..._DeleteEndpoint#TestEndpoint.g.verified.cs | 51 +++--- ...ScopedNamespace#TestEndpoint.g.verified.cs | 58 +++--- ...ate_GetEndpoint#TestEndpoint.g.verified.cs | 53 +++--- ...HeaderParameter#TestEndpoint.g.verified.cs | 59 +++--- ...edPathParameter#TestEndpoint.g.verified.cs | 59 +++--- ...dQueryParameter#TestEndpoint.g.verified.cs | 59 +++--- ...erate_Namespace#TestEndpoint.g.verified.cs | 58 +++--- ...rate_NestedType#TestEndpoint.g.verified.cs | 53 +++--- ...tions_Parameter#TestEndpoint.g.verified.cs | 57 +++--- ...nation_Endpoint#TestEndpoint.g.verified.cs | 58 +++--- ...e_PathParameter#TestEndpoint.g.verified.cs | 59 +++--- ...te_PostEndpoint#TestEndpoint.g.verified.cs | 55 +++--- ...ate_PutEndpoint#TestEndpoint.g.verified.cs | 53 +++--- ..._QueryParameter#TestEndpoint.g.verified.cs | 59 +++--- ..._DateTimeOffset#TestEndpoint.g.verified.cs | 59 +++--- ...Generate_Usings#TestEndpoint.g.verified.cs | 57 +++--- ...nitialization.Implementation.g.verified.cs | 40 +++-- ...ization#ClientInitialization.g.verified.cs | 104 +++++------ ...n.AzureAuthenticationHandler.g.verified.cs | 35 ++-- ...tication.BearerTokenProvider.g.verified.cs | 57 +++--- ...hentication.DateTimeProvider.g.verified.cs | 13 +- ...ication.IBearerTokenProvider.g.verified.cs | 13 +- ...entication.IDateTimeProvider.g.verified.cs | 9 +- ...EmbeddedSource#BodyAttribute.g.verified.cs | 24 +-- ...rce#Builder.ClientSerializer.g.verified.cs | 27 +-- ....HttpClientBuilderExtensions.g.verified.cs | 56 +++--- ...Builder.HttpClientExtensions.g.verified.cs | 21 ++- ...ce#Builder.IClientSerializer.g.verified.cs | 11 +- ...ilder.IMessageRequestBuilder.g.verified.cs | 22 +-- ...ilder.IMessageRequestFactory.g.verified.cs | 11 +- ...lder.IMessageResponseBuilder.g.verified.cs | 28 +-- ...uilder.MessageRequestBuilder.g.verified.cs | 167 ++++++++--------- ...uilder.MessageRequestFactory.g.verified.cs | 25 +-- ...ilder.MessageResponseBuilder.g.verified.cs | 169 +++++++++--------- ...urce#ClientEndpointAttribute.g.verified.cs | 40 +++-- ...beddedSource#DeleteAttribute.g.verified.cs | 36 ++-- ..._EmbeddedSource#GetAttribute.g.verified.cs | 36 ++-- ...beddedSource#HeaderAttribute.g.verified.cs | 42 ++--- ...e#ICabazureAuthClientOptions.g.verified.cs | 29 +-- ...ource#ICabazureClientOptions.g.verified.cs | 25 +-- ...EmbeddedSource#PathAttribute.g.verified.cs | 42 ++--- ...EmbeddedSource#PostAttribute.g.verified.cs | 36 ++-- ..._EmbeddedSource#PutAttribute.g.verified.cs | 36 ++-- ...mbeddedSource#QueryAttribute.g.verified.cs | 42 ++--- 48 files changed, 1215 insertions(+), 1114 deletions(-) diff --git a/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_CancellationToken_Parameter#TestEndpoint.g.verified.cs b/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_CancellationToken_Parameter#TestEndpoint.g.verified.cs index 1e3bc12..5f1b1cc 100644 --- a/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_CancellationToken_Parameter#TestEndpoint.g.verified.cs +++ b/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_CancellationToken_Parameter#TestEndpoint.g.verified.cs @@ -2,40 +2,41 @@ // #nullable enable using System.Net; +using System.Net.Http; using Cabazure.Client; using Cabazure.Client.Builder; -internal partial class TestEndpoint : ITestEndpoint -{ - private readonly IHttpClientFactory factory; - private readonly IMessageRequestFactory requestFactory; - - public TestEndpoint( - IHttpClientFactory factory, - IMessageRequestFactory requestFactory) + internal partial class TestEndpoint : ITestEndpoint { - this.factory = factory; - this.requestFactory = requestFactory; - } + private readonly IHttpClientFactory factory; + private readonly IMessageRequestFactory requestFactory; - public async Task> ExecuteAsync( + public TestEndpoint( + IHttpClientFactory factory, + IMessageRequestFactory requestFactory) + { + this.factory = factory; + this.requestFactory = requestFactory; + } + + public async Task> ExecuteAsync( CancellationToken cancellationToken) - { - var client = factory.CreateClient("ClientName"); + { + var client = factory.CreateClient("ClientName"); - using var requestMessage = requestFactory - .FromTemplate("ClientName", "/items") - .Build(HttpMethod.Get); + using var requestMessage = requestFactory + .FromTemplate("ClientName", "/items") + .Build(HttpMethod.Get); - using var response = await client - .SendAsync(requestMessage, cancellationToken); + using var response = await client + .SendAsync(requestMessage, cancellationToken); - return await requestFactory - .FromResponse("ClientName", response) - .AddSuccessResponse(HttpStatusCode.OK) - .GetAsync( - response => new EndpointResponse(response), - cancellationToken); + return await requestFactory + .FromResponse("ClientName", response) + .AddSuccessResponse(HttpStatusCode.OK) + .GetAsync( + response => new EndpointResponse(response), + cancellationToken); + } } -} #nullable disable diff --git a/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_ClientName_From_Constant#TestEndpoint.g.verified.cs b/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_ClientName_From_Constant#TestEndpoint.g.verified.cs index fe68498..9f79788 100644 --- a/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_ClientName_From_Constant#TestEndpoint.g.verified.cs +++ b/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_ClientName_From_Constant#TestEndpoint.g.verified.cs @@ -2,45 +2,47 @@ // #nullable enable using System.Net; +using System.Net.Http; using Cabazure.Client; using Cabazure.Client.Builder; -namespace Test; - -internal partial class TestEndpoint : ITestEndpoint +namespace Test { - private readonly IHttpClientFactory factory; - private readonly IMessageRequestFactory requestFactory; - - public TestEndpoint( - IHttpClientFactory factory, - IMessageRequestFactory requestFactory) + internal partial class TestEndpoint : ITestEndpoint { - this.factory = factory; - this.requestFactory = requestFactory; - } + private readonly IHttpClientFactory factory; + private readonly IMessageRequestFactory requestFactory; - public async Task> ExecuteAsync( + public TestEndpoint( + IHttpClientFactory factory, + IMessageRequestFactory requestFactory) + { + this.factory = factory; + this.requestFactory = requestFactory; + } + + public async Task> ExecuteAsync( ClientRequestOptions options, CancellationToken cancellationToken) - { - var client = factory.CreateClient("ConstantName"); + { + var client = factory.CreateClient("ConstantName"); - using var requestMessage = requestFactory - .FromTemplate("ConstantName", "/routes") - .WithRequestOptions(options) - .Build(HttpMethod.Get); + using var requestMessage = requestFactory + .FromTemplate("ConstantName", "/routes") + .WithRequestOptions(options) + .Build(HttpMethod.Get); - using var response = await client - .WithRequestOptions(options) - .SendAsync(requestMessage, cancellationToken); + using var response = await client + .WithRequestOptions(options) + .SendAsync(requestMessage, cancellationToken); - return await requestFactory - .FromResponse("ConstantName", response) - .AddSuccessResponse(HttpStatusCode.OK) - .GetAsync( - response => new EndpointResponse(response), - cancellationToken); + return await requestFactory + .FromResponse("ConstantName", response) + .AddSuccessResponse(HttpStatusCode.OK) + .GetAsync( + response => new EndpointResponse(response), + cancellationToken); + } } } #nullable disable diff --git a/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_ClientName_From_NameOf#TestEndpoint.g.verified.cs b/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_ClientName_From_NameOf#TestEndpoint.g.verified.cs index afe43bd..3edbc2f 100644 --- a/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_ClientName_From_NameOf#TestEndpoint.g.verified.cs +++ b/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_ClientName_From_NameOf#TestEndpoint.g.verified.cs @@ -2,45 +2,47 @@ // #nullable enable using System.Net; +using System.Net.Http; using Cabazure.Client; using Cabazure.Client.Builder; -namespace Test; - -internal partial class TestEndpoint : ITestEndpoint +namespace Test { - private readonly IHttpClientFactory factory; - private readonly IMessageRequestFactory requestFactory; - - public TestEndpoint( - IHttpClientFactory factory, - IMessageRequestFactory requestFactory) + internal partial class TestEndpoint : ITestEndpoint { - this.factory = factory; - this.requestFactory = requestFactory; - } + private readonly IHttpClientFactory factory; + private readonly IMessageRequestFactory requestFactory; - public async Task> ExecuteAsync( + public TestEndpoint( + IHttpClientFactory factory, + IMessageRequestFactory requestFactory) + { + this.factory = factory; + this.requestFactory = requestFactory; + } + + public async Task> ExecuteAsync( ClientRequestOptions options, CancellationToken cancellationToken) - { - var client = factory.CreateClient("String"); + { + var client = factory.CreateClient("String"); - using var requestMessage = requestFactory - .FromTemplate("String", "/routes") - .WithRequestOptions(options) - .Build(HttpMethod.Get); + using var requestMessage = requestFactory + .FromTemplate("String", "/routes") + .WithRequestOptions(options) + .Build(HttpMethod.Get); - using var response = await client - .WithRequestOptions(options) - .SendAsync(requestMessage, cancellationToken); + using var response = await client + .WithRequestOptions(options) + .SendAsync(requestMessage, cancellationToken); - return await requestFactory - .FromResponse("String", response) - .AddSuccessResponse(HttpStatusCode.OK) - .GetAsync( - response => new EndpointResponse(response), - cancellationToken); + return await requestFactory + .FromResponse("String", response) + .AddSuccessResponse(HttpStatusCode.OK) + .GetAsync( + response => new EndpointResponse(response), + cancellationToken); + } } } #nullable disable diff --git a/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_ClientRequestOptions_Parameter#TestEndpoint.g.verified.cs b/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_ClientRequestOptions_Parameter#TestEndpoint.g.verified.cs index 736f4eb..d705b79 100644 --- a/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_ClientRequestOptions_Parameter#TestEndpoint.g.verified.cs +++ b/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_ClientRequestOptions_Parameter#TestEndpoint.g.verified.cs @@ -2,42 +2,43 @@ // #nullable enable using System.Net; +using System.Net.Http; using Cabazure.Client; using Cabazure.Client.Builder; -internal partial class TestEndpoint : ITestEndpoint -{ - private readonly IHttpClientFactory factory; - private readonly IMessageRequestFactory requestFactory; - - public TestEndpoint( - IHttpClientFactory factory, - IMessageRequestFactory requestFactory) + internal partial class TestEndpoint : ITestEndpoint { - this.factory = factory; - this.requestFactory = requestFactory; - } + private readonly IHttpClientFactory factory; + private readonly IMessageRequestFactory requestFactory; - public async Task> ExecuteAsync( + public TestEndpoint( + IHttpClientFactory factory, + IMessageRequestFactory requestFactory) + { + this.factory = factory; + this.requestFactory = requestFactory; + } + + public async Task> ExecuteAsync( ClientRequestOptions options) - { - var client = factory.CreateClient("ClientName"); + { + var client = factory.CreateClient("ClientName"); - using var requestMessage = requestFactory - .FromTemplate("ClientName", "/items") - .WithRequestOptions(options) - .Build(HttpMethod.Get); + using var requestMessage = requestFactory + .FromTemplate("ClientName", "/items") + .WithRequestOptions(options) + .Build(HttpMethod.Get); - using var response = await client - .WithRequestOptions(options) - .SendAsync(requestMessage, CancellationToken.None); + using var response = await client + .WithRequestOptions(options) + .SendAsync(requestMessage, CancellationToken.None); - return await requestFactory - .FromResponse("ClientName", response) - .AddSuccessResponse(HttpStatusCode.OK) - .GetAsync( - response => new EndpointResponse(response), - CancellationToken.None); + return await requestFactory + .FromResponse("ClientName", response) + .AddSuccessResponse(HttpStatusCode.OK) + .GetAsync( + response => new EndpointResponse(response), + CancellationToken.None); + } } -} #nullable disable diff --git a/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_DeleteEndpoint#TestEndpoint.g.verified.cs b/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_DeleteEndpoint#TestEndpoint.g.verified.cs index c8bee64..a9e97c1 100644 --- a/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_DeleteEndpoint#TestEndpoint.g.verified.cs +++ b/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_DeleteEndpoint#TestEndpoint.g.verified.cs @@ -2,40 +2,41 @@ // #nullable enable using System.Net; +using System.Net.Http; using Cabazure.Client; using Cabazure.Client.Builder; -internal partial class TestEndpoint : ITestEndpoint -{ - private readonly IHttpClientFactory factory; - private readonly IMessageRequestFactory requestFactory; - - public TestEndpoint( - IHttpClientFactory factory, - IMessageRequestFactory requestFactory) + internal partial class TestEndpoint : ITestEndpoint { - this.factory = factory; - this.requestFactory = requestFactory; - } + private readonly IHttpClientFactory factory; + private readonly IMessageRequestFactory requestFactory; - public async Task ExecuteAsync( + public TestEndpoint( + IHttpClientFactory factory, + IMessageRequestFactory requestFactory) + { + this.factory = factory; + this.requestFactory = requestFactory; + } + + public async Task ExecuteAsync( [Path] string id, CancellationToken cancellationToken) - { - var client = factory.CreateClient("ClientName"); + { + var client = factory.CreateClient("ClientName"); - using var requestMessage = requestFactory - .FromTemplate("ClientName", "/items/{id}") - .WithPathParameter("id", id) - .Build(HttpMethod.Delete); + using var requestMessage = requestFactory + .FromTemplate("ClientName", "/items/{id}") + .WithPathParameter("id", id) + .Build(HttpMethod.Delete); - using var response = await client - .SendAsync(requestMessage, cancellationToken); + using var response = await client + .SendAsync(requestMessage, cancellationToken); - return await requestFactory - .FromResponse("ClientName", response) - .AddSuccessResponse(HttpStatusCode.OK) - .GetAsync(cancellationToken); + return await requestFactory + .FromResponse("ClientName", response) + .AddSuccessResponse(HttpStatusCode.OK) + .GetAsync(cancellationToken); + } } -} #nullable disable diff --git a/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_FileScopedNamespace#TestEndpoint.g.verified.cs b/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_FileScopedNamespace#TestEndpoint.g.verified.cs index 8e6138a..8737b74 100644 --- a/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_FileScopedNamespace#TestEndpoint.g.verified.cs +++ b/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_FileScopedNamespace#TestEndpoint.g.verified.cs @@ -2,45 +2,47 @@ // #nullable enable using System.Net; +using System.Net.Http; using Cabazure.Client; using Cabazure.Client.Builder; -namespace Test; - -internal partial class TestEndpoint : ITestEndpoint +namespace Test { - private readonly IHttpClientFactory factory; - private readonly IMessageRequestFactory requestFactory; - - public TestEndpoint( - IHttpClientFactory factory, - IMessageRequestFactory requestFactory) + internal partial class TestEndpoint : ITestEndpoint { - this.factory = factory; - this.requestFactory = requestFactory; - } + private readonly IHttpClientFactory factory; + private readonly IMessageRequestFactory requestFactory; - public async Task> ExecuteAsync( + public TestEndpoint( + IHttpClientFactory factory, + IMessageRequestFactory requestFactory) + { + this.factory = factory; + this.requestFactory = requestFactory; + } + + public async Task> ExecuteAsync( ClientRequestOptions options, CancellationToken cancellationToken) - { - var client = factory.CreateClient("ClientName"); + { + var client = factory.CreateClient("ClientName"); - using var requestMessage = requestFactory - .FromTemplate("ClientName", "/routes") - .WithRequestOptions(options) - .Build(HttpMethod.Get); + using var requestMessage = requestFactory + .FromTemplate("ClientName", "/routes") + .WithRequestOptions(options) + .Build(HttpMethod.Get); - using var response = await client - .WithRequestOptions(options) - .SendAsync(requestMessage, cancellationToken); + using var response = await client + .WithRequestOptions(options) + .SendAsync(requestMessage, cancellationToken); - return await requestFactory - .FromResponse("ClientName", response) - .AddSuccessResponse(HttpStatusCode.OK) - .GetAsync( - response => new EndpointResponse(response), - cancellationToken); + return await requestFactory + .FromResponse("ClientName", response) + .AddSuccessResponse(HttpStatusCode.OK) + .GetAsync( + response => new EndpointResponse(response), + cancellationToken); + } } } #nullable disable diff --git a/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_GetEndpoint#TestEndpoint.g.verified.cs b/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_GetEndpoint#TestEndpoint.g.verified.cs index cb8e95f..ef315fe 100644 --- a/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_GetEndpoint#TestEndpoint.g.verified.cs +++ b/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_GetEndpoint#TestEndpoint.g.verified.cs @@ -2,39 +2,40 @@ // #nullable enable using System.Net; +using System.Net.Http; using Cabazure.Client; using Cabazure.Client.Builder; -internal partial class TestEndpoint : ITestEndpoint -{ - private readonly IHttpClientFactory factory; - private readonly IMessageRequestFactory requestFactory; - - public TestEndpoint( - IHttpClientFactory factory, - IMessageRequestFactory requestFactory) + internal partial class TestEndpoint : ITestEndpoint { - this.factory = factory; - this.requestFactory = requestFactory; - } + private readonly IHttpClientFactory factory; + private readonly IMessageRequestFactory requestFactory; - public async Task> ExecuteAsync() - { - var client = factory.CreateClient("ClientName"); + public TestEndpoint( + IHttpClientFactory factory, + IMessageRequestFactory requestFactory) + { + this.factory = factory; + this.requestFactory = requestFactory; + } + + public async Task> ExecuteAsync() + { + var client = factory.CreateClient("ClientName"); - using var requestMessage = requestFactory - .FromTemplate("ClientName", "/items") - .Build(HttpMethod.Get); + using var requestMessage = requestFactory + .FromTemplate("ClientName", "/items") + .Build(HttpMethod.Get); - using var response = await client - .SendAsync(requestMessage, CancellationToken.None); + using var response = await client + .SendAsync(requestMessage, CancellationToken.None); - return await requestFactory - .FromResponse("ClientName", response) - .AddSuccessResponse(HttpStatusCode.OK) - .GetAsync( - response => new EndpointResponse(response), - CancellationToken.None); + return await requestFactory + .FromResponse("ClientName", response) + .AddSuccessResponse(HttpStatusCode.OK) + .GetAsync( + response => new EndpointResponse(response), + CancellationToken.None); + } } -} #nullable disable diff --git a/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_HeaderParameter#TestEndpoint.g.verified.cs b/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_HeaderParameter#TestEndpoint.g.verified.cs index 2bbc66a..7b5fa5c 100644 --- a/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_HeaderParameter#TestEndpoint.g.verified.cs +++ b/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_HeaderParameter#TestEndpoint.g.verified.cs @@ -2,45 +2,46 @@ // #nullable enable using System.Net; +using System.Net.Http; using Cabazure.Client; using Cabazure.Client.Builder; -internal partial class TestEndpoint : ITestEndpoint -{ - private readonly IHttpClientFactory factory; - private readonly IMessageRequestFactory requestFactory; - - public TestEndpoint( - IHttpClientFactory factory, - IMessageRequestFactory requestFactory) + internal partial class TestEndpoint : ITestEndpoint { - this.factory = factory; - this.requestFactory = requestFactory; - } + private readonly IHttpClientFactory factory; + private readonly IMessageRequestFactory requestFactory; - public async Task> ExecuteAsync( + public TestEndpoint( + IHttpClientFactory factory, + IMessageRequestFactory requestFactory) + { + this.factory = factory; + this.requestFactory = requestFactory; + } + + public async Task> ExecuteAsync( [Header("x-correlation-id")] string correlationId, ClientRequestOptions options, CancellationToken cancellationToken) - { - var client = factory.CreateClient("ClientName"); + { + var client = factory.CreateClient("ClientName"); - using var requestMessage = requestFactory - .FromTemplate("ClientName", "/items") - .WithHeader("x-correlation-id", correlationId) - .WithRequestOptions(options) - .Build(HttpMethod.Get); + using var requestMessage = requestFactory + .FromTemplate("ClientName", "/items") + .WithHeader("x-correlation-id", correlationId) + .WithRequestOptions(options) + .Build(HttpMethod.Get); - using var response = await client - .WithRequestOptions(options) - .SendAsync(requestMessage, cancellationToken); + using var response = await client + .WithRequestOptions(options) + .SendAsync(requestMessage, cancellationToken); - return await requestFactory - .FromResponse("ClientName", response) - .AddSuccessResponse(HttpStatusCode.OK) - .GetAsync( - response => new EndpointResponse(response), - cancellationToken); + return await requestFactory + .FromResponse("ClientName", response) + .AddSuccessResponse(HttpStatusCode.OK) + .GetAsync( + response => new EndpointResponse(response), + cancellationToken); + } } -} #nullable disable diff --git a/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_NamedPathParameter#TestEndpoint.g.verified.cs b/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_NamedPathParameter#TestEndpoint.g.verified.cs index b30ea83..5d52b8c 100644 --- a/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_NamedPathParameter#TestEndpoint.g.verified.cs +++ b/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_NamedPathParameter#TestEndpoint.g.verified.cs @@ -2,45 +2,46 @@ // #nullable enable using System.Net; +using System.Net.Http; using Cabazure.Client; using Cabazure.Client.Builder; -internal partial class TestEndpoint : ITestEndpoint -{ - private readonly IHttpClientFactory factory; - private readonly IMessageRequestFactory requestFactory; - - public TestEndpoint( - IHttpClientFactory factory, - IMessageRequestFactory requestFactory) + internal partial class TestEndpoint : ITestEndpoint { - this.factory = factory; - this.requestFactory = requestFactory; - } + private readonly IHttpClientFactory factory; + private readonly IMessageRequestFactory requestFactory; - public async Task> ExecuteAsync( + public TestEndpoint( + IHttpClientFactory factory, + IMessageRequestFactory requestFactory) + { + this.factory = factory; + this.requestFactory = requestFactory; + } + + public async Task> ExecuteAsync( [Path("id")] string itemId, ClientRequestOptions options, CancellationToken cancellationToken) - { - var client = factory.CreateClient("ClientName"); + { + var client = factory.CreateClient("ClientName"); - using var requestMessage = requestFactory - .FromTemplate("ClientName", "/items/{id}") - .WithPathParameter("id", itemId) - .WithRequestOptions(options) - .Build(HttpMethod.Get); + using var requestMessage = requestFactory + .FromTemplate("ClientName", "/items/{id}") + .WithPathParameter("id", itemId) + .WithRequestOptions(options) + .Build(HttpMethod.Get); - using var response = await client - .WithRequestOptions(options) - .SendAsync(requestMessage, cancellationToken); + using var response = await client + .WithRequestOptions(options) + .SendAsync(requestMessage, cancellationToken); - return await requestFactory - .FromResponse("ClientName", response) - .AddSuccessResponse(HttpStatusCode.OK) - .GetAsync( - response => new EndpointResponse(response), - cancellationToken); + return await requestFactory + .FromResponse("ClientName", response) + .AddSuccessResponse(HttpStatusCode.OK) + .GetAsync( + response => new EndpointResponse(response), + cancellationToken); + } } -} #nullable disable diff --git a/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_NamedQueryParameter#TestEndpoint.g.verified.cs b/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_NamedQueryParameter#TestEndpoint.g.verified.cs index f4a6830..d9301d2 100644 --- a/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_NamedQueryParameter#TestEndpoint.g.verified.cs +++ b/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_NamedQueryParameter#TestEndpoint.g.verified.cs @@ -2,45 +2,46 @@ // #nullable enable using System.Net; +using System.Net.Http; using Cabazure.Client; using Cabazure.Client.Builder; -internal partial class TestEndpoint : ITestEndpoint -{ - private readonly IHttpClientFactory factory; - private readonly IMessageRequestFactory requestFactory; - - public TestEndpoint( - IHttpClientFactory factory, - IMessageRequestFactory requestFactory) + internal partial class TestEndpoint : ITestEndpoint { - this.factory = factory; - this.requestFactory = requestFactory; - } + private readonly IHttpClientFactory factory; + private readonly IMessageRequestFactory requestFactory; - public async Task> ExecuteAsync( + public TestEndpoint( + IHttpClientFactory factory, + IMessageRequestFactory requestFactory) + { + this.factory = factory; + this.requestFactory = requestFactory; + } + + public async Task> ExecuteAsync( [Query("s")] string searchText, ClientRequestOptions options, CancellationToken cancellationToken) - { - var client = factory.CreateClient("ClientName"); + { + var client = factory.CreateClient("ClientName"); - using var requestMessage = requestFactory - .FromTemplate("ClientName", "/items") - .WithQueryParameter("s", searchText) - .WithRequestOptions(options) - .Build(HttpMethod.Get); + using var requestMessage = requestFactory + .FromTemplate("ClientName", "/items") + .WithQueryParameter("s", searchText) + .WithRequestOptions(options) + .Build(HttpMethod.Get); - using var response = await client - .WithRequestOptions(options) - .SendAsync(requestMessage, cancellationToken); + using var response = await client + .WithRequestOptions(options) + .SendAsync(requestMessage, cancellationToken); - return await requestFactory - .FromResponse("ClientName", response) - .AddSuccessResponse(HttpStatusCode.OK) - .GetAsync( - response => new EndpointResponse(response), - cancellationToken); + return await requestFactory + .FromResponse("ClientName", response) + .AddSuccessResponse(HttpStatusCode.OK) + .GetAsync( + response => new EndpointResponse(response), + cancellationToken); + } } -} #nullable disable diff --git a/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_Namespace#TestEndpoint.g.verified.cs b/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_Namespace#TestEndpoint.g.verified.cs index 333fb09..fcd17dd 100644 --- a/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_Namespace#TestEndpoint.g.verified.cs +++ b/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_Namespace#TestEndpoint.g.verified.cs @@ -2,45 +2,47 @@ // #nullable enable using System.Net; +using System.Net.Http; using Cabazure.Client; using Cabazure.Client.Builder; -namespace Test; - -internal partial class TestEndpoint : ITestEndpoint +namespace Test { - private readonly IHttpClientFactory factory; - private readonly IMessageRequestFactory requestFactory; - - public TestEndpoint( - IHttpClientFactory factory, - IMessageRequestFactory requestFactory) + internal partial class TestEndpoint : ITestEndpoint { - this.factory = factory; - this.requestFactory = requestFactory; - } + private readonly IHttpClientFactory factory; + private readonly IMessageRequestFactory requestFactory; - public async Task> ExecuteAsync( + public TestEndpoint( + IHttpClientFactory factory, + IMessageRequestFactory requestFactory) + { + this.factory = factory; + this.requestFactory = requestFactory; + } + + public async Task> ExecuteAsync( ClientRequestOptions options, CancellationToken cancellationToken) - { - var client = factory.CreateClient("ClientName"); + { + var client = factory.CreateClient("ClientName"); - using var requestMessage = requestFactory - .FromTemplate("ClientName", "/routes") - .WithRequestOptions(options) - .Build(HttpMethod.Get); + using var requestMessage = requestFactory + .FromTemplate("ClientName", "/routes") + .WithRequestOptions(options) + .Build(HttpMethod.Get); - using var response = await client - .WithRequestOptions(options) - .SendAsync(requestMessage, cancellationToken); + using var response = await client + .WithRequestOptions(options) + .SendAsync(requestMessage, cancellationToken); - return await requestFactory - .FromResponse("ClientName", response) - .AddSuccessResponse(HttpStatusCode.OK) - .GetAsync( - response => new EndpointResponse(response), - cancellationToken); + return await requestFactory + .FromResponse("ClientName", response) + .AddSuccessResponse(HttpStatusCode.OK) + .GetAsync( + response => new EndpointResponse(response), + cancellationToken); + } } } #nullable disable diff --git a/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_NestedType#TestEndpoint.g.verified.cs b/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_NestedType#TestEndpoint.g.verified.cs index 10c6502..2c69527 100644 --- a/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_NestedType#TestEndpoint.g.verified.cs +++ b/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_NestedType#TestEndpoint.g.verified.cs @@ -2,40 +2,41 @@ // #nullable enable using System.Net; +using System.Net.Http; using Cabazure.Client; using Cabazure.Client.Builder; -internal partial class TestEndpoint : Endpoints.Items.ITestEndpoint -{ - private readonly IHttpClientFactory factory; - private readonly IMessageRequestFactory requestFactory; - - public TestEndpoint( - IHttpClientFactory factory, - IMessageRequestFactory requestFactory) + internal partial class TestEndpoint : Endpoints.Items.ITestEndpoint { - this.factory = factory; - this.requestFactory = requestFactory; - } + private readonly IHttpClientFactory factory; + private readonly IMessageRequestFactory requestFactory; - public async Task> ExecuteAsync( + public TestEndpoint( + IHttpClientFactory factory, + IMessageRequestFactory requestFactory) + { + this.factory = factory; + this.requestFactory = requestFactory; + } + + public async Task> ExecuteAsync( CancellationToken cancellationToken) - { - var client = factory.CreateClient("ClientName"); + { + var client = factory.CreateClient("ClientName"); - using var requestMessage = requestFactory - .FromTemplate("ClientName", "/items") - .Build(HttpMethod.Get); + using var requestMessage = requestFactory + .FromTemplate("ClientName", "/items") + .Build(HttpMethod.Get); - using var response = await client - .SendAsync(requestMessage, cancellationToken); + using var response = await client + .SendAsync(requestMessage, cancellationToken); - return await requestFactory - .FromResponse("ClientName", response) - .AddSuccessResponse(HttpStatusCode.OK) - .GetAsync( - response => new EndpointResponse(response), - cancellationToken); + return await requestFactory + .FromResponse("ClientName", response) + .AddSuccessResponse(HttpStatusCode.OK) + .GetAsync( + response => new EndpointResponse(response), + cancellationToken); + } } -} #nullable disable diff --git a/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_PagedRequestOptions_Parameter#TestEndpoint.g.verified.cs b/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_PagedRequestOptions_Parameter#TestEndpoint.g.verified.cs index 1779092..924b55e 100644 --- a/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_PagedRequestOptions_Parameter#TestEndpoint.g.verified.cs +++ b/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_PagedRequestOptions_Parameter#TestEndpoint.g.verified.cs @@ -2,42 +2,43 @@ // #nullable enable using System.Net; +using System.Net.Http; using Cabazure.Client; using Cabazure.Client.Builder; -internal partial class TestEndpoint : ITestEndpoint -{ - private readonly IHttpClientFactory factory; - private readonly IMessageRequestFactory requestFactory; - - public TestEndpoint( - IHttpClientFactory factory, - IMessageRequestFactory requestFactory) + internal partial class TestEndpoint : ITestEndpoint { - this.factory = factory; - this.requestFactory = requestFactory; - } + private readonly IHttpClientFactory factory; + private readonly IMessageRequestFactory requestFactory; - public async Task> ExecuteAsync( + public TestEndpoint( + IHttpClientFactory factory, + IMessageRequestFactory requestFactory) + { + this.factory = factory; + this.requestFactory = requestFactory; + } + + public async Task> ExecuteAsync( PagedRequestOptions options) - { - var client = factory.CreateClient("ClientName"); + { + var client = factory.CreateClient("ClientName"); - using var requestMessage = requestFactory - .FromTemplate("ClientName", "/items") - .WithRequestOptions(options) - .Build(HttpMethod.Get); + using var requestMessage = requestFactory + .FromTemplate("ClientName", "/items") + .WithRequestOptions(options) + .Build(HttpMethod.Get); - using var response = await client - .WithRequestOptions(options) - .SendAsync(requestMessage, CancellationToken.None); + using var response = await client + .WithRequestOptions(options) + .SendAsync(requestMessage, CancellationToken.None); - return await requestFactory - .FromResponse("ClientName", response) - .AddSuccessResponse(HttpStatusCode.OK) - .GetAsync( - response => new EndpointResponse(response), - CancellationToken.None); + return await requestFactory + .FromResponse("ClientName", response) + .AddSuccessResponse(HttpStatusCode.OK) + .GetAsync( + response => new EndpointResponse(response), + CancellationToken.None); + } } -} #nullable disable diff --git a/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_Pagination_Endpoint#TestEndpoint.g.verified.cs b/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_Pagination_Endpoint#TestEndpoint.g.verified.cs index 6945e91..5c0236a 100644 --- a/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_Pagination_Endpoint#TestEndpoint.g.verified.cs +++ b/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_Pagination_Endpoint#TestEndpoint.g.verified.cs @@ -2,45 +2,47 @@ // #nullable enable using System.Net; +using System.Net.Http; using Cabazure.Client; using Cabazure.Client.Builder; -namespace Test; - -internal partial class TestEndpoint : ITestEndpoint +namespace Test { - private readonly IHttpClientFactory factory; - private readonly IMessageRequestFactory requestFactory; - - public TestEndpoint( - IHttpClientFactory factory, - IMessageRequestFactory requestFactory) + internal partial class TestEndpoint : ITestEndpoint { - this.factory = factory; - this.requestFactory = requestFactory; - } + private readonly IHttpClientFactory factory; + private readonly IMessageRequestFactory requestFactory; - public async Task> ExecuteAsync( + public TestEndpoint( + IHttpClientFactory factory, + IMessageRequestFactory requestFactory) + { + this.factory = factory; + this.requestFactory = requestFactory; + } + + public async Task> ExecuteAsync( PagedRequestOptions options, CancellationToken cancellationToken) - { - var client = factory.CreateClient("ClientName"); + { + var client = factory.CreateClient("ClientName"); - using var requestMessage = requestFactory - .FromTemplate("ClientName", "/routes") - .WithRequestOptions(options) - .Build(HttpMethod.Get); + using var requestMessage = requestFactory + .FromTemplate("ClientName", "/routes") + .WithRequestOptions(options) + .Build(HttpMethod.Get); - using var response = await client - .WithRequestOptions(options) - .SendAsync(requestMessage, cancellationToken); + using var response = await client + .WithRequestOptions(options) + .SendAsync(requestMessage, cancellationToken); - return await requestFactory - .FromResponse("ClientName", response) - .AddSuccessResponse(HttpStatusCode.OK) - .GetAsync( - response => new PagedResponse(response), - cancellationToken); + return await requestFactory + .FromResponse("ClientName", response) + .AddSuccessResponse(HttpStatusCode.OK) + .GetAsync( + response => new PagedResponse(response), + cancellationToken); + } } } #nullable disable diff --git a/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_PathParameter#TestEndpoint.g.verified.cs b/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_PathParameter#TestEndpoint.g.verified.cs index 2a4c084..4eb4463 100644 --- a/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_PathParameter#TestEndpoint.g.verified.cs +++ b/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_PathParameter#TestEndpoint.g.verified.cs @@ -2,45 +2,46 @@ // #nullable enable using System.Net; +using System.Net.Http; using Cabazure.Client; using Cabazure.Client.Builder; -internal partial class TestEndpoint : ITestEndpoint -{ - private readonly IHttpClientFactory factory; - private readonly IMessageRequestFactory requestFactory; - - public TestEndpoint( - IHttpClientFactory factory, - IMessageRequestFactory requestFactory) + internal partial class TestEndpoint : ITestEndpoint { - this.factory = factory; - this.requestFactory = requestFactory; - } + private readonly IHttpClientFactory factory; + private readonly IMessageRequestFactory requestFactory; - public async Task> ExecuteAsync( + public TestEndpoint( + IHttpClientFactory factory, + IMessageRequestFactory requestFactory) + { + this.factory = factory; + this.requestFactory = requestFactory; + } + + public async Task> ExecuteAsync( [Path] string id, ClientRequestOptions options, CancellationToken cancellationToken) - { - var client = factory.CreateClient("ClientName"); + { + var client = factory.CreateClient("ClientName"); - using var requestMessage = requestFactory - .FromTemplate("ClientName", "/items/{id}") - .WithPathParameter("id", id) - .WithRequestOptions(options) - .Build(HttpMethod.Get); + using var requestMessage = requestFactory + .FromTemplate("ClientName", "/items/{id}") + .WithPathParameter("id", id) + .WithRequestOptions(options) + .Build(HttpMethod.Get); - using var response = await client - .WithRequestOptions(options) - .SendAsync(requestMessage, cancellationToken); + using var response = await client + .WithRequestOptions(options) + .SendAsync(requestMessage, cancellationToken); - return await requestFactory - .FromResponse("ClientName", response) - .AddSuccessResponse(HttpStatusCode.OK) - .GetAsync( - response => new EndpointResponse(response), - cancellationToken); + return await requestFactory + .FromResponse("ClientName", response) + .AddSuccessResponse(HttpStatusCode.OK) + .GetAsync( + response => new EndpointResponse(response), + cancellationToken); + } } -} #nullable disable diff --git a/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_PostEndpoint#TestEndpoint.g.verified.cs b/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_PostEndpoint#TestEndpoint.g.verified.cs index be413f1..58c817f 100644 --- a/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_PostEndpoint#TestEndpoint.g.verified.cs +++ b/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_PostEndpoint#TestEndpoint.g.verified.cs @@ -2,43 +2,44 @@ // #nullable enable using System.Net; +using System.Net.Http; using Cabazure.Client; using Cabazure.Client.Builder; -internal partial class TestEndpoint : ITestEndpoint -{ - private readonly IHttpClientFactory factory; - private readonly IMessageRequestFactory requestFactory; - - public TestEndpoint( - IHttpClientFactory factory, - IMessageRequestFactory requestFactory) + internal partial class TestEndpoint : ITestEndpoint { - this.factory = factory; - this.requestFactory = requestFactory; - } + private readonly IHttpClientFactory factory; + private readonly IMessageRequestFactory requestFactory; - public async Task ExecuteAsync( + public TestEndpoint( + IHttpClientFactory factory, + IMessageRequestFactory requestFactory) + { + this.factory = factory; + this.requestFactory = requestFactory; + } + + public async Task ExecuteAsync( [Body] string body, ClientRequestOptions options, CancellationToken cancellationToken) - { - var client = factory.CreateClient("ClientName"); + { + var client = factory.CreateClient("ClientName"); - using var requestMessage = requestFactory - .FromTemplate("ClientName", "/routes") - .WithBody(body) - .WithRequestOptions(options) - .Build(HttpMethod.Post); + using var requestMessage = requestFactory + .FromTemplate("ClientName", "/routes") + .WithBody(body) + .WithRequestOptions(options) + .Build(HttpMethod.Post); - using var response = await client - .WithRequestOptions(options) - .SendAsync(requestMessage, cancellationToken); + using var response = await client + .WithRequestOptions(options) + .SendAsync(requestMessage, cancellationToken); - return await requestFactory - .FromResponse("ClientName", response) - .AddSuccessResponse(HttpStatusCode.OK) - .GetAsync(cancellationToken); + return await requestFactory + .FromResponse("ClientName", response) + .AddSuccessResponse(HttpStatusCode.OK) + .GetAsync(cancellationToken); + } } -} #nullable disable diff --git a/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_PutEndpoint#TestEndpoint.g.verified.cs b/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_PutEndpoint#TestEndpoint.g.verified.cs index 837e0a4..f47138f 100644 --- a/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_PutEndpoint#TestEndpoint.g.verified.cs +++ b/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_PutEndpoint#TestEndpoint.g.verified.cs @@ -2,42 +2,43 @@ // #nullable enable using System.Net; +using System.Net.Http; using Cabazure.Client; using Cabazure.Client.Builder; -internal partial class TestEndpoint : ITestEndpoint -{ - private readonly IHttpClientFactory factory; - private readonly IMessageRequestFactory requestFactory; - - public TestEndpoint( - IHttpClientFactory factory, - IMessageRequestFactory requestFactory) + internal partial class TestEndpoint : ITestEndpoint { - this.factory = factory; - this.requestFactory = requestFactory; - } + private readonly IHttpClientFactory factory; + private readonly IMessageRequestFactory requestFactory; - public async Task ExecuteAsync( + public TestEndpoint( + IHttpClientFactory factory, + IMessageRequestFactory requestFactory) + { + this.factory = factory; + this.requestFactory = requestFactory; + } + + public async Task ExecuteAsync( [Path("id")] string id, [Body] string body, CancellationToken cancellationToken) - { - var client = factory.CreateClient("ClientName"); + { + var client = factory.CreateClient("ClientName"); - using var requestMessage = requestFactory - .FromTemplate("ClientName", "/items/{id}") - .WithPathParameter("id", id) - .WithBody(body) - .Build(HttpMethod.Put); + using var requestMessage = requestFactory + .FromTemplate("ClientName", "/items/{id}") + .WithPathParameter("id", id) + .WithBody(body) + .Build(HttpMethod.Put); - using var response = await client - .SendAsync(requestMessage, cancellationToken); + using var response = await client + .SendAsync(requestMessage, cancellationToken); - return await requestFactory - .FromResponse("ClientName", response) - .AddSuccessResponse(HttpStatusCode.OK) - .GetAsync(cancellationToken); + return await requestFactory + .FromResponse("ClientName", response) + .AddSuccessResponse(HttpStatusCode.OK) + .GetAsync(cancellationToken); + } } -} #nullable disable diff --git a/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_QueryParameter#TestEndpoint.g.verified.cs b/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_QueryParameter#TestEndpoint.g.verified.cs index f5308b4..e4b43c6 100644 --- a/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_QueryParameter#TestEndpoint.g.verified.cs +++ b/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_QueryParameter#TestEndpoint.g.verified.cs @@ -2,45 +2,46 @@ // #nullable enable using System.Net; +using System.Net.Http; using Cabazure.Client; using Cabazure.Client.Builder; -internal partial class TestEndpoint : ITestEndpoint -{ - private readonly IHttpClientFactory factory; - private readonly IMessageRequestFactory requestFactory; - - public TestEndpoint( - IHttpClientFactory factory, - IMessageRequestFactory requestFactory) + internal partial class TestEndpoint : ITestEndpoint { - this.factory = factory; - this.requestFactory = requestFactory; - } + private readonly IHttpClientFactory factory; + private readonly IMessageRequestFactory requestFactory; - public async Task> ExecuteAsync( + public TestEndpoint( + IHttpClientFactory factory, + IMessageRequestFactory requestFactory) + { + this.factory = factory; + this.requestFactory = requestFactory; + } + + public async Task> ExecuteAsync( [Query] string searchText, ClientRequestOptions options, CancellationToken cancellationToken) - { - var client = factory.CreateClient("ClientName"); + { + var client = factory.CreateClient("ClientName"); - using var requestMessage = requestFactory - .FromTemplate("ClientName", "/items") - .WithQueryParameter("searchText", searchText) - .WithRequestOptions(options) - .Build(HttpMethod.Get); + using var requestMessage = requestFactory + .FromTemplate("ClientName", "/items") + .WithQueryParameter("searchText", searchText) + .WithRequestOptions(options) + .Build(HttpMethod.Get); - using var response = await client - .WithRequestOptions(options) - .SendAsync(requestMessage, cancellationToken); + using var response = await client + .WithRequestOptions(options) + .SendAsync(requestMessage, cancellationToken); - return await requestFactory - .FromResponse("ClientName", response) - .AddSuccessResponse(HttpStatusCode.OK) - .GetAsync( - response => new EndpointResponse(response), - cancellationToken); + return await requestFactory + .FromResponse("ClientName", response) + .AddSuccessResponse(HttpStatusCode.OK) + .GetAsync( + response => new EndpointResponse(response), + cancellationToken); + } } -} #nullable disable diff --git a/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_QueryParameter_DateTimeOffset#TestEndpoint.g.verified.cs b/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_QueryParameter_DateTimeOffset#TestEndpoint.g.verified.cs index 62a2f4e..9b60844 100644 --- a/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_QueryParameter_DateTimeOffset#TestEndpoint.g.verified.cs +++ b/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_QueryParameter_DateTimeOffset#TestEndpoint.g.verified.cs @@ -2,45 +2,46 @@ // #nullable enable using System.Net; +using System.Net.Http; using Cabazure.Client; using Cabazure.Client.Builder; -internal partial class TestEndpoint : ITestEndpoint -{ - private readonly IHttpClientFactory factory; - private readonly IMessageRequestFactory requestFactory; - - public TestEndpoint( - IHttpClientFactory factory, - IMessageRequestFactory requestFactory) + internal partial class TestEndpoint : ITestEndpoint { - this.factory = factory; - this.requestFactory = requestFactory; - } + private readonly IHttpClientFactory factory; + private readonly IMessageRequestFactory requestFactory; - public async Task> ExecuteAsync( + public TestEndpoint( + IHttpClientFactory factory, + IMessageRequestFactory requestFactory) + { + this.factory = factory; + this.requestFactory = requestFactory; + } + + public async Task> ExecuteAsync( [Query(formatString: "O", name: "time")] DateTimeOffset? time, ClientRequestOptions options, CancellationToken cancellationToken) - { - var client = factory.CreateClient("ClientName"); + { + var client = factory.CreateClient("ClientName"); - using var requestMessage = requestFactory - .FromTemplate("ClientName", "/items") - .WithQueryParameter("time", time?.ToString("O")) - .WithRequestOptions(options) - .Build(HttpMethod.Get); + using var requestMessage = requestFactory + .FromTemplate("ClientName", "/items") + .WithQueryParameter("time", time?.ToString("O")) + .WithRequestOptions(options) + .Build(HttpMethod.Get); - using var response = await client - .WithRequestOptions(options) - .SendAsync(requestMessage, cancellationToken); + using var response = await client + .WithRequestOptions(options) + .SendAsync(requestMessage, cancellationToken); - return await requestFactory - .FromResponse("ClientName", response) - .AddSuccessResponse(HttpStatusCode.OK) - .GetAsync( - response => new EndpointResponse(response), - cancellationToken); + return await requestFactory + .FromResponse("ClientName", response) + .AddSuccessResponse(HttpStatusCode.OK) + .GetAsync( + response => new EndpointResponse(response), + cancellationToken); + } } -} #nullable disable diff --git a/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_Usings#TestEndpoint.g.verified.cs b/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_Usings#TestEndpoint.g.verified.cs index 52501bf..b25cd39 100644 --- a/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_Usings#TestEndpoint.g.verified.cs +++ b/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_Usings#TestEndpoint.g.verified.cs @@ -2,44 +2,45 @@ // #nullable enable using System.Net; +using System.Net.Http; using System.Text; using Cabazure.Client; using Cabazure.Client.Builder; -internal partial class TestEndpoint : ITestEndpoint -{ - private readonly IHttpClientFactory factory; - private readonly IMessageRequestFactory requestFactory; - - public TestEndpoint( - IHttpClientFactory factory, - IMessageRequestFactory requestFactory) + internal partial class TestEndpoint : ITestEndpoint { - this.factory = factory; - this.requestFactory = requestFactory; - } + private readonly IHttpClientFactory factory; + private readonly IMessageRequestFactory requestFactory; - public async Task> ExecuteAsync( + public TestEndpoint( + IHttpClientFactory factory, + IMessageRequestFactory requestFactory) + { + this.factory = factory; + this.requestFactory = requestFactory; + } + + public async Task> ExecuteAsync( ClientRequestOptions options, CancellationToken cancellationToken) - { - var client = factory.CreateClient("ClientName"); + { + var client = factory.CreateClient("ClientName"); - using var requestMessage = requestFactory - .FromTemplate("ClientName", "/routes") - .WithRequestOptions(options) - .Build(HttpMethod.Get); + using var requestMessage = requestFactory + .FromTemplate("ClientName", "/routes") + .WithRequestOptions(options) + .Build(HttpMethod.Get); - using var response = await client - .WithRequestOptions(options) - .SendAsync(requestMessage, cancellationToken); + using var response = await client + .WithRequestOptions(options) + .SendAsync(requestMessage, cancellationToken); - return await requestFactory - .FromResponse("ClientName", response) - .AddSuccessResponse(HttpStatusCode.OK) - .GetAsync( - response => new EndpointResponse(response), - cancellationToken); + return await requestFactory + .FromResponse("ClientName", response) + .AddSuccessResponse(HttpStatusCode.OK) + .GetAsync( + response => new EndpointResponse(response), + cancellationToken); + } } -} #nullable disable diff --git a/test/Cabazure.Client.Tests/ClientInitializationGeneratorTests.CanGenerate_Initialization#ClientInitialization.Implementation.g.verified.cs b/test/Cabazure.Client.Tests/ClientInitializationGeneratorTests.CanGenerate_Initialization#ClientInitialization.Implementation.g.verified.cs index d5150cf..b257e2c 100644 --- a/test/Cabazure.Client.Tests/ClientInitializationGeneratorTests.CanGenerate_Initialization#ClientInitialization.Implementation.g.verified.cs +++ b/test/Cabazure.Client.Tests/ClientInitializationGeneratorTests.CanGenerate_Initialization#ClientInitialization.Implementation.g.verified.cs @@ -1,34 +1,36 @@ //HintName: ClientInitialization.Implementation.g.cs // #nullable enable +using System; using System.Text.Json; using Cabazure.Client.Builder; using Microsoft.Extensions.DependencyInjection.Extensions; -namespace Microsoft.Extensions.DependencyInjection; - -internal static partial class ClientInitialization +namespace Microsoft.Extensions.DependencyInjection { - internal static partial IServiceCollection AddCabazureClient( - this IServiceCollection services, - string clientName, - Action? jsonOptions, - Action builder) + internal static partial class ClientInitialization { - if (jsonOptions != null) + internal static partial IServiceCollection AddCabazureClient( + this IServiceCollection services, + string clientName, + Action? jsonOptions, + Action builder) { - services - .AddOptions(clientName) - .Configure(jsonOptions); - } + if (jsonOptions != null) + { + services + .AddOptions(clientName) + .Configure(jsonOptions); + } - var clientBuilder = services.AddHttpClient(clientName); - builder.Invoke(clientBuilder); + var clientBuilder = services.AddHttpClient(clientName); + builder.Invoke(clientBuilder); - services.TryAddSingleton(); - services.TryAddSingleton(); - services.TryAddSingleton(); - return services; + services.TryAddSingleton(); + services.TryAddSingleton(); + services.TryAddSingleton(); + return services; + } } } #nullable disable diff --git a/test/Cabazure.Client.Tests/ClientInitializationGeneratorTests.CanGenerate_Initialization#ClientInitialization.g.verified.cs b/test/Cabazure.Client.Tests/ClientInitializationGeneratorTests.CanGenerate_Initialization#ClientInitialization.g.verified.cs index 116f54d..9930cb6 100644 --- a/test/Cabazure.Client.Tests/ClientInitializationGeneratorTests.CanGenerate_Initialization#ClientInitialization.g.verified.cs +++ b/test/Cabazure.Client.Tests/ClientInitializationGeneratorTests.CanGenerate_Initialization#ClientInitialization.g.verified.cs @@ -1,74 +1,78 @@ //HintName: ClientInitialization.g.cs // #nullable enable +using System; +using System.Collections.Generic; +using System.Net.Http; using System.Text.Json; using Azure.Core; using Cabazure.Client; using Cabazure.Client.Authentication; using Microsoft.Extensions.Options; -namespace Microsoft.Extensions.DependencyInjection; - -internal static partial class ClientInitialization +namespace Microsoft.Extensions.DependencyInjection { - internal static IServiceCollection AddCabazureClient( - this IServiceCollection services, - string clientName, - Action? jsonOptions, - Action? clientOptions, - Action? builder = default) - where TOptions : class, ICabazureClientOptions + internal static partial class ClientInitialization { - if (clientOptions != null) + internal static IServiceCollection AddCabazureClient( + this IServiceCollection services, + string clientName, + Action? jsonOptions, + Action? clientOptions, + Action? builder = default) + where TOptions : class, ICabazureClientOptions { - services - .AddOptions() - .Configure(clientOptions); - } - - void ConfigureHttpClient(IServiceProvider services, HttpClient client) - => client.BaseAddress = services - .GetRequiredService>() - .Value - .GetBaseAddress(); + if (clientOptions != null) + { + services + .AddOptions() + .Configure(clientOptions); + } - void ConfigureAuthHandler(IList handlers, IServiceProvider services) - { - var options = services - .GetRequiredService>() - .Value; + void ConfigureHttpClient(IServiceProvider services, HttpClient client) + => client.BaseAddress = services + .GetRequiredService>() + .Value + .GetBaseAddress(); - if (options is ICabazureAuthClientOptions authOptions) + void ConfigureAuthHandler(IList handlers, IServiceProvider services) { - var scope = authOptions.GetScope(); - var credential = authOptions.GetCredential(); + var options = services + .GetRequiredService>() + .Value; + + if (options is ICabazureAuthClientOptions authOptions) + { + var scope = authOptions.GetScope(); + var credential = authOptions.GetCredential(); - var tokenProvider = new BearerTokenProvider( - new TokenRequestContext(new [] { scope }), - credential, - new DateTimeProvider()); + var tokenProvider = new BearerTokenProvider( + new TokenRequestContext(new [] { scope }), + credential, + new DateTimeProvider()); - handlers.Add(new AzureAuthenticationHandler(tokenProvider)); + handlers.Add(new AzureAuthenticationHandler(tokenProvider)); + } } - } - void BuildHttpClient(IHttpClientBuilder b) - { - b.ConfigureHttpClient(ConfigureHttpClient); - b.ConfigureAdditionalHttpMessageHandlers(ConfigureAuthHandler); - builder?.Invoke(b); + void BuildHttpClient(IHttpClientBuilder b) + { + b.ConfigureHttpClient(ConfigureHttpClient); + b.ConfigureAdditionalHttpMessageHandlers(ConfigureAuthHandler); + builder?.Invoke(b); + } + + return services.AddCabazureClient( + clientName, + jsonOptions, + BuildHttpClient); } - return services.AddCabazureClient( - clientName, - jsonOptions, - BuildHttpClient); + internal static partial IServiceCollection AddCabazureClient( + this IServiceCollection services, + string clientName, + Action? jsonOptions, + Action builder); } - - internal static partial IServiceCollection AddCabazureClient( - this IServiceCollection services, - string clientName, - Action? jsonOptions, - Action builder); } #nullable disable \ No newline at end of file diff --git a/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#Authentication.AzureAuthenticationHandler.g.verified.cs b/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#Authentication.AzureAuthenticationHandler.g.verified.cs index 250c45f..9c0ebff 100644 --- a/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#Authentication.AzureAuthenticationHandler.g.verified.cs +++ b/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#Authentication.AzureAuthenticationHandler.g.verified.cs @@ -1,26 +1,31 @@ //HintName: Authentication.AzureAuthenticationHandler.g.cs // #nullable enable -namespace Cabazure.Client.Authentication; +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; -internal class AzureAuthenticationHandler - : DelegatingHandler +namespace Cabazure.Client.Authentication { - private readonly IBearerTokenProvider tokenProvider; - - public AzureAuthenticationHandler( - IBearerTokenProvider tokenProvider) + internal class AzureAuthenticationHandler + : DelegatingHandler { - this.tokenProvider = tokenProvider; - } + private readonly IBearerTokenProvider tokenProvider; - protected async override Task SendAsync( - HttpRequestMessage request, - CancellationToken cancellationToken) - { - request.Headers.Authorization = await tokenProvider.GetTokenAsync(cancellationToken); + public AzureAuthenticationHandler( + IBearerTokenProvider tokenProvider) + { + this.tokenProvider = tokenProvider; + } + + protected async override Task SendAsync( + HttpRequestMessage request, + CancellationToken cancellationToken) + { + request.Headers.Authorization = await tokenProvider.GetTokenAsync(cancellationToken); - return await base.SendAsync(request, cancellationToken); + return await base.SendAsync(request, cancellationToken); + } } } #nullable disable \ No newline at end of file diff --git a/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#Authentication.BearerTokenProvider.g.verified.cs b/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#Authentication.BearerTokenProvider.g.verified.cs index 2c054ab..55d1546 100644 --- a/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#Authentication.BearerTokenProvider.g.verified.cs +++ b/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#Authentication.BearerTokenProvider.g.verified.cs @@ -2,41 +2,44 @@ // #nullable enable using System.Net.Http.Headers; +using System.Threading; +using System.Threading.Tasks; using Azure.Core; -namespace Cabazure.Client.Authentication; - -internal class BearerTokenProvider : IBearerTokenProvider +namespace Cabazure.Client.Authentication { - private readonly TokenRequestContext context; - private readonly TokenCredential credential; - private readonly IDateTimeProvider dateTimeProvider; - private AccessToken accessToken; - - public BearerTokenProvider( - TokenRequestContext context, - TokenCredential credential, - IDateTimeProvider dateTimeProvider) + internal class BearerTokenProvider : IBearerTokenProvider { - this.context = context; - this.credential = credential; - this.dateTimeProvider = dateTimeProvider; - } + private readonly TokenRequestContext context; + private readonly TokenCredential credential; + private readonly IDateTimeProvider dateTimeProvider; + private AccessToken accessToken; - public async Task GetTokenAsync( - CancellationToken cancellationToken) - { - if (TokenIsExpired()) + public BearerTokenProvider( + TokenRequestContext context, + TokenCredential credential, + IDateTimeProvider dateTimeProvider) { - accessToken = await credential.GetTokenAsync(context, cancellationToken); + this.context = context; + this.credential = credential; + this.dateTimeProvider = dateTimeProvider; } - return new AuthenticationHeaderValue( - "Bearer", - accessToken.Token); - } + public async Task GetTokenAsync( + CancellationToken cancellationToken) + { + if (TokenIsExpired()) + { + accessToken = await credential.GetTokenAsync(context, cancellationToken); + } + + return new AuthenticationHeaderValue( + "Bearer", + accessToken.Token); + } - private bool TokenIsExpired() - => dateTimeProvider.GetDateTime().AddMinutes(1) > accessToken.ExpiresOn; + private bool TokenIsExpired() + => dateTimeProvider.GetDateTime().AddMinutes(1) > accessToken.ExpiresOn; + } } #nullable disable \ No newline at end of file diff --git a/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#Authentication.DateTimeProvider.g.verified.cs b/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#Authentication.DateTimeProvider.g.verified.cs index f7b882e..b6944a3 100644 --- a/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#Authentication.DateTimeProvider.g.verified.cs +++ b/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#Authentication.DateTimeProvider.g.verified.cs @@ -1,12 +1,15 @@ //HintName: Authentication.DateTimeProvider.g.cs // #nullable enable -namespace Cabazure.Client.Authentication; +using System; -internal class DateTimeProvider - : IDateTimeProvider +namespace Cabazure.Client.Authentication { - public DateTimeOffset GetDateTime() - => DateTimeOffset.UtcNow; + internal class DateTimeProvider + : IDateTimeProvider + { + public DateTimeOffset GetDateTime() + => DateTimeOffset.UtcNow; + } } #nullable disable \ No newline at end of file diff --git a/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#Authentication.IBearerTokenProvider.g.verified.cs b/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#Authentication.IBearerTokenProvider.g.verified.cs index e5cd3af..583f7ff 100644 --- a/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#Authentication.IBearerTokenProvider.g.verified.cs +++ b/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#Authentication.IBearerTokenProvider.g.verified.cs @@ -2,12 +2,15 @@ // #nullable enable using System.Net.Http.Headers; +using System.Threading; +using System.Threading.Tasks; -namespace Cabazure.Client.Authentication; - -internal interface IBearerTokenProvider +namespace Cabazure.Client.Authentication { - Task GetTokenAsync( - CancellationToken cancellationToken); + internal interface IBearerTokenProvider + { + Task GetTokenAsync( + CancellationToken cancellationToken); + } } #nullable disable \ No newline at end of file diff --git a/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#Authentication.IDateTimeProvider.g.verified.cs b/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#Authentication.IDateTimeProvider.g.verified.cs index 0689fe6..c0586d1 100644 --- a/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#Authentication.IDateTimeProvider.g.verified.cs +++ b/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#Authentication.IDateTimeProvider.g.verified.cs @@ -1,10 +1,13 @@ //HintName: Authentication.IDateTimeProvider.g.cs // #nullable enable -namespace Cabazure.Client.Authentication; +using System; -internal interface IDateTimeProvider +namespace Cabazure.Client.Authentication { - DateTimeOffset GetDateTime(); + internal interface IDateTimeProvider + { + DateTimeOffset GetDateTime(); + } } #nullable disable \ No newline at end of file diff --git a/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#BodyAttribute.g.verified.cs b/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#BodyAttribute.g.verified.cs index 70d428e..8dc91b1 100644 --- a/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#BodyAttribute.g.verified.cs +++ b/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#BodyAttribute.g.verified.cs @@ -1,19 +1,21 @@ //HintName: BodyAttribute.g.cs // #nullable enable +using System; using System.Diagnostics.CodeAnalysis; -namespace Cabazure.Client; - -/// -/// Specifies that a parameter should be bound to the request body. -/// -[ExcludeFromCodeCoverage] -[AttributeUsage( - AttributeTargets.Parameter | AttributeTargets.Property, - Inherited = false, - AllowMultiple = false)] -internal sealed class BodyAttribute : Attribute +namespace Cabazure.Client { + /// + /// Specifies that a parameter should be bound to the request body. + /// + [ExcludeFromCodeCoverage] + [AttributeUsage( + AttributeTargets.Parameter | AttributeTargets.Property, + Inherited = false, + AllowMultiple = false)] + internal sealed class BodyAttribute : Attribute + { + } } #nullable disable \ No newline at end of file diff --git a/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#Builder.ClientSerializer.g.verified.cs b/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#Builder.ClientSerializer.g.verified.cs index 1659a95..d00bbbb 100644 --- a/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#Builder.ClientSerializer.g.verified.cs +++ b/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#Builder.ClientSerializer.g.verified.cs @@ -4,22 +4,23 @@ using System.Text.Json; using Microsoft.Extensions.Options; -namespace Cabazure.Client.Builder; - -internal class ClientSerializer : IClientSerializer +namespace Cabazure.Client.Builder { - private readonly IOptionsMonitor options; - - public ClientSerializer( - IOptionsMonitor options) + internal class ClientSerializer : IClientSerializer { - this.options = options; - } + private readonly IOptionsMonitor options; - public string Serialize(string clientName, object value) - => JsonSerializer.Serialize(value, options.Get(clientName)); + public ClientSerializer( + IOptionsMonitor options) + { + this.options = options; + } - public T? Deserialize(string clientName, string json) - => JsonSerializer.Deserialize(json, options.Get(clientName)); + public string Serialize(string clientName, object value) + => JsonSerializer.Serialize(value, options.Get(clientName)); + + public T? Deserialize(string clientName, string json) + => JsonSerializer.Deserialize(json, options.Get(clientName)); + } } #nullable disable \ No newline at end of file diff --git a/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#Builder.HttpClientBuilderExtensions.g.verified.cs b/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#Builder.HttpClientBuilderExtensions.g.verified.cs index ea1ceb8..e207f73 100644 --- a/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#Builder.HttpClientBuilderExtensions.g.verified.cs +++ b/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#Builder.HttpClientBuilderExtensions.g.verified.cs @@ -1,40 +1,42 @@ //HintName: Builder.HttpClientBuilderExtensions.g.cs // #nullable enable +using System; using Azure.Core; using Cabazure.Client.Authentication; -namespace Microsoft.Extensions.DependencyInjection; - -internal static class HttpClientBuilderExtensions +namespace Microsoft.Extensions.DependencyInjection { - public static IHttpClientBuilder SetBaseAddress( - this IHttpClientBuilder builder, - Uri baseAddress) - => builder.ConfigureHttpClient(c => c.BaseAddress = baseAddress); + internal static class HttpClientBuilderExtensions + { + public static IHttpClientBuilder SetBaseAddress( + this IHttpClientBuilder builder, + Uri baseAddress) + => builder.ConfigureHttpClient(c => c.BaseAddress = baseAddress); - public static IHttpClientBuilder AddAuthentication( - this IHttpClientBuilder builder, - string scope, - TokenCredential credential) - => AddAuthentication( - builder, - new TokenRequestContext(new[] { scope }), - credential); + public static IHttpClientBuilder AddAuthentication( + this IHttpClientBuilder builder, + string scope, + TokenCredential credential) + => AddAuthentication( + builder, + new TokenRequestContext(new[] { scope }), + credential); - public static IHttpClientBuilder AddAuthentication( - this IHttpClientBuilder builder, - TokenRequestContext context, - TokenCredential credential) - { - var tokenProvider = new BearerTokenProvider( - context, - credential, - new DateTimeProvider()); + public static IHttpClientBuilder AddAuthentication( + this IHttpClientBuilder builder, + TokenRequestContext context, + TokenCredential credential) + { + var tokenProvider = new BearerTokenProvider( + context, + credential, + new DateTimeProvider()); - return builder - .AddHttpMessageHandler( - () => new AzureAuthenticationHandler(tokenProvider)); + return builder + .AddHttpMessageHandler( + () => new AzureAuthenticationHandler(tokenProvider)); + } } } #nullable disable \ No newline at end of file diff --git a/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#Builder.HttpClientExtensions.g.verified.cs b/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#Builder.HttpClientExtensions.g.verified.cs index e52380c..2a0b646 100644 --- a/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#Builder.HttpClientExtensions.g.verified.cs +++ b/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#Builder.HttpClientExtensions.g.verified.cs @@ -1,20 +1,23 @@ //HintName: Builder.HttpClientExtensions.g.cs // #nullable enable -namespace Cabazure.Client.Builder; +using System.Net.Http; -internal static class HttpClientExtensions +namespace Cabazure.Client.Builder { - public static HttpClient WithRequestOptions( - this HttpClient httpClient, - IRequestOptions? requestOptions) + internal static class HttpClientExtensions { - if (requestOptions is { Timeout: { Ticks: > 0 } timeout }) + public static HttpClient WithRequestOptions( + this HttpClient httpClient, + IRequestOptions? requestOptions) { - httpClient.Timeout = timeout; - } + if (requestOptions is { Timeout: { Ticks: > 0 } timeout }) + { + httpClient.Timeout = timeout; + } - return httpClient; + return httpClient; + } } } #nullable disable \ No newline at end of file diff --git a/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#Builder.IClientSerializer.g.verified.cs b/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#Builder.IClientSerializer.g.verified.cs index afedd01..6e7454a 100644 --- a/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#Builder.IClientSerializer.g.verified.cs +++ b/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#Builder.IClientSerializer.g.verified.cs @@ -1,11 +1,12 @@ //HintName: Builder.IClientSerializer.g.cs // #nullable enable -namespace Cabazure.Client.Builder; - -internal interface IClientSerializer +namespace Cabazure.Client.Builder { - T? Deserialize(string clientName, string json); - string Serialize(string clientName, object value); + internal interface IClientSerializer + { + T? Deserialize(string clientName, string json); + string Serialize(string clientName, object value); + } } #nullable disable \ No newline at end of file diff --git a/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#Builder.IMessageRequestBuilder.g.verified.cs b/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#Builder.IMessageRequestBuilder.g.verified.cs index a2d45ce..d25f47d 100644 --- a/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#Builder.IMessageRequestBuilder.g.verified.cs +++ b/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#Builder.IMessageRequestBuilder.g.verified.cs @@ -1,23 +1,25 @@ //HintName: Builder.IMessageRequestBuilder.g.cs // #nullable enable +using System.Net.Http; using Microsoft.Extensions.Primitives; -namespace Cabazure.Client.Builder; - -internal interface IMessageRequestBuilder +namespace Cabazure.Client.Builder { - IMessageRequestBuilder WithPathParameter(string name, string value); + internal interface IMessageRequestBuilder + { + IMessageRequestBuilder WithPathParameter(string name, string value); - IMessageRequestBuilder WithQueryParameter(string name, string? value); + IMessageRequestBuilder WithQueryParameter(string name, string? value); - IMessageRequestBuilder WithHeader(string name, StringValues value); + IMessageRequestBuilder WithHeader(string name, StringValues value); - IMessageRequestBuilder WithRequestOptions(IRequestOptions? options); + IMessageRequestBuilder WithRequestOptions(IRequestOptions? options); - IMessageRequestBuilder WithBody(TBody body) - where TBody : class; + IMessageRequestBuilder WithBody(TBody body) + where TBody : class; - HttpRequestMessage Build(HttpMethod method); + HttpRequestMessage Build(HttpMethod method); + } } #nullable disable \ No newline at end of file diff --git a/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#Builder.IMessageRequestFactory.g.verified.cs b/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#Builder.IMessageRequestFactory.g.verified.cs index 6b1b28d..ae920d2 100644 --- a/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#Builder.IMessageRequestFactory.g.verified.cs +++ b/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#Builder.IMessageRequestFactory.g.verified.cs @@ -1,12 +1,15 @@ //HintName: Builder.IMessageRequestFactory.g.cs // #nullable enable -namespace Cabazure.Client.Builder; +using System.Net.Http; -internal interface IMessageRequestFactory +namespace Cabazure.Client.Builder { - IMessageRequestBuilder FromTemplate(string clientName, string template); + internal interface IMessageRequestFactory + { + IMessageRequestBuilder FromTemplate(string clientName, string template); - IMessageResponseBuilder FromResponse(string clientName, HttpResponseMessage? response); + IMessageResponseBuilder FromResponse(string clientName, HttpResponseMessage? response); + } } #nullable disable \ No newline at end of file diff --git a/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#Builder.IMessageResponseBuilder.g.verified.cs b/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#Builder.IMessageResponseBuilder.g.verified.cs index 77aeb44..4550eda 100644 --- a/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#Builder.IMessageResponseBuilder.g.verified.cs +++ b/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#Builder.IMessageResponseBuilder.g.verified.cs @@ -1,25 +1,29 @@ //HintName: Builder.IMessageResponseBuilder.g.cs // #nullable enable +using System; +using System.Threading; +using System.Threading.Tasks; using System.Net; -namespace Cabazure.Client.Builder; - -internal interface IMessageResponseBuilder +namespace Cabazure.Client.Builder { - IMessageResponseBuilder AddSuccessResponse(HttpStatusCode statusCode); + internal interface IMessageResponseBuilder + { + IMessageResponseBuilder AddSuccessResponse(HttpStatusCode statusCode); - IMessageResponseBuilder AddSuccessResponse(HttpStatusCode statusCode); + IMessageResponseBuilder AddSuccessResponse(HttpStatusCode statusCode); - IMessageResponseBuilder AddErrorResponse(HttpStatusCode statusCode); + IMessageResponseBuilder AddErrorResponse(HttpStatusCode statusCode); - IMessageResponseBuilder AddErrorResponse(HttpStatusCode statusCode); + IMessageResponseBuilder AddErrorResponse(HttpStatusCode statusCode); - Task GetAsync( - Func factory, - CancellationToken cancellationToken); + Task GetAsync( + Func factory, + CancellationToken cancellationToken); - Task GetAsync( - CancellationToken cancellationToken); + Task GetAsync( + CancellationToken cancellationToken); + } } #nullable disable \ No newline at end of file diff --git a/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#Builder.MessageRequestBuilder.g.verified.cs b/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#Builder.MessageRequestBuilder.g.verified.cs index 43defdb..00fc64f 100644 --- a/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#Builder.MessageRequestBuilder.g.verified.cs +++ b/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#Builder.MessageRequestBuilder.g.verified.cs @@ -1,118 +1,123 @@ //HintName: Builder.MessageRequestBuilder.g.cs // #nullable enable +using System; +using System.Collections.Generic; using System.Globalization; +using System.Linq; +using System.Net.Http; using System.Net.Http.Headers; using System.Text; using Microsoft.Extensions.Primitives; -namespace Cabazure.Client.Builder; - -internal class MessageRequestBuilder : IMessageRequestBuilder +namespace Cabazure.Client.Builder { - private readonly Dictionary pathMapper = new(); - private readonly Dictionary queryMapper = new(); - private readonly Dictionary headerMapper = new(); - private readonly string template; - private readonly IClientSerializer serializer; - private readonly string clientName; - private string content = string.Empty; - - public MessageRequestBuilder( - string template, - IClientSerializer serializer, - string clientName) - { - this.template = template; - this.serializer = serializer; - this.clientName = clientName; - } - - public HttpRequestMessage Build(HttpMethod method) + internal class MessageRequestBuilder : IMessageRequestBuilder { - var message = new HttpRequestMessage(); - - message.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/json")); - message.RequestUri = BuildRequestUri(); - message.Content = new StringContent(content); - message.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json"); - message.Method = method; - message.Version = new Version(2, 0); - - foreach (var header in headerMapper) + private readonly Dictionary pathMapper = new(); + private readonly Dictionary queryMapper = new(); + private readonly Dictionary headerMapper = new(); + private readonly string template; + private readonly IClientSerializer serializer; + private readonly string clientName; + private string content = string.Empty; + + public MessageRequestBuilder( + string template, + IClientSerializer serializer, + string clientName) { - message.Headers.Add(header.Key, header.Value.ToArray()); + this.template = template; + this.serializer = serializer; + this.clientName = clientName; } - return message; - } - - public IMessageRequestBuilder WithHeader(string name, StringValues value) - { - if (!string.IsNullOrWhiteSpace(name) && !string.IsNullOrWhiteSpace(value)) + public HttpRequestMessage Build(HttpMethod method) { - headerMapper[name] = value; - } + var message = new HttpRequestMessage(); - return this; - } + message.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/json")); + message.RequestUri = BuildRequestUri(); + message.Content = new StringContent(content); + message.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json"); + message.Method = method; + message.Version = new Version(2, 0); - public IMessageRequestBuilder WithRequestOptions( - IRequestOptions? options) - { - if (options is { } o) - { - foreach (var header in o.GetHeaders()) + foreach (var header in headerMapper) { - WithHeader(header.Key, header.Value); + message.Headers.Add(header.Key, header.Value.ToArray()); } - } - return this; - } + return message; + } - public IMessageRequestBuilder WithBody(TBody body) - where TBody : class - { - content = serializer.Serialize(clientName, body); + public IMessageRequestBuilder WithHeader(string name, StringValues value) + { + if (!string.IsNullOrWhiteSpace(name) && !string.IsNullOrWhiteSpace(value)) + { + headerMapper[name] = value; + } - return this; - } + return this; + } - public IMessageRequestBuilder WithPathParameter(string name, string value) - { - pathMapper[name] = value; + public IMessageRequestBuilder WithRequestOptions( + IRequestOptions? options) + { + if (options is { } o) + { + foreach (var header in o.GetHeaders()) + { + WithHeader(header.Key, header.Value); + } + } - return this; - } + return this; + } - public IMessageRequestBuilder WithQueryParameter(string name, string? value) - { - if (value is not null) + public IMessageRequestBuilder WithBody(TBody body) + where TBody : class { - queryMapper[name] = value; + content = serializer.Serialize(clientName, body); + + return this; } - return this; - } + public IMessageRequestBuilder WithPathParameter(string name, string value) + { + pathMapper[name] = value; - private Uri BuildRequestUri() - { - var urlBuilder = new StringBuilder(); + return this; + } - urlBuilder.Append(template); - foreach (var parameter in pathMapper) + public IMessageRequestBuilder WithQueryParameter(string name, string? value) { - urlBuilder.Replace($"{{{parameter.Key}}}", Uri.EscapeDataString(parameter.Value)); + if (value is not null) + { + queryMapper[name] = value; + } + + return this; } - if (queryMapper.Count != 0) + private Uri BuildRequestUri() { - urlBuilder.Append(template.Contains('?') ? '&': '?'); - urlBuilder.Append(string.Join("&", queryMapper.Select(q => $"{q.Key}={Uri.EscapeDataString(q.Value)}"))); - } + var urlBuilder = new StringBuilder(); - return new Uri(urlBuilder.ToString(), UriKind.RelativeOrAbsolute); + urlBuilder.Append(template); + foreach (var parameter in pathMapper) + { + urlBuilder.Replace($"{{{parameter.Key}}}", Uri.EscapeDataString(parameter.Value)); + } + + if (queryMapper.Count != 0) + { + urlBuilder.Append(template.Contains('?') ? '&': '?'); + urlBuilder.Append(string.Join("&", queryMapper.Select(q => $"{q.Key}={Uri.EscapeDataString(q.Value)}"))); + } + + return new Uri(urlBuilder.ToString(), UriKind.RelativeOrAbsolute); + } } } #nullable disable \ No newline at end of file diff --git a/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#Builder.MessageRequestFactory.g.verified.cs b/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#Builder.MessageRequestFactory.g.verified.cs index 0b2f22f..9747564 100644 --- a/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#Builder.MessageRequestFactory.g.verified.cs +++ b/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#Builder.MessageRequestFactory.g.verified.cs @@ -1,21 +1,24 @@ //HintName: Builder.MessageRequestFactory.g.cs // #nullable enable -namespace Cabazure.Client.Builder; +using System.Net.Http; -internal class MessageRequestFactory : IMessageRequestFactory +namespace Cabazure.Client.Builder { - private readonly IClientSerializer serializer; - - public MessageRequestFactory(IClientSerializer serializer) + internal class MessageRequestFactory : IMessageRequestFactory { - this.serializer = serializer; - } + private readonly IClientSerializer serializer; - public IMessageResponseBuilder FromResponse(string clientName, HttpResponseMessage? response) - => new MessageResponseBuilder(response, serializer, clientName); + public MessageRequestFactory(IClientSerializer serializer) + { + this.serializer = serializer; + } - public IMessageRequestBuilder FromTemplate(string clientName, string template) - => new MessageRequestBuilder(template, serializer, clientName); + public IMessageResponseBuilder FromResponse(string clientName, HttpResponseMessage? response) + => new MessageResponseBuilder(response, serializer, clientName); + + public IMessageRequestBuilder FromTemplate(string clientName, string template) + => new MessageRequestBuilder(template, serializer, clientName); + } } #nullable disable \ No newline at end of file diff --git a/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#Builder.MessageResponseBuilder.g.verified.cs b/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#Builder.MessageResponseBuilder.g.verified.cs index 34343be..051bcb2 100644 --- a/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#Builder.MessageResponseBuilder.g.verified.cs +++ b/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#Builder.MessageResponseBuilder.g.verified.cs @@ -1,114 +1,121 @@ //HintName: Builder.MessageResponseBuilder.g.cs // #nullable enable +using System; +using System.Collections.Generic; +using System.Net.Http; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; using System.Net; -namespace Cabazure.Client.Builder; - -internal delegate object? ContentSerializerDelegate(string content); - -internal class MessageResponseBuilder : IMessageResponseBuilder +namespace Cabazure.Client.Builder { - private static readonly EndpointResponse EmptyResponse = new( - false, - HttpStatusCode.InternalServerError, - string.Empty, - null, - new Dictionary>()); - - private readonly Dictionary responseSerializers = new(); - private readonly Dictionary responseCodes = new(); - private readonly HttpResponseMessage? response; - private readonly IClientSerializer serializer; - private readonly string clientName; - - public MessageResponseBuilder( - HttpResponseMessage? response, - IClientSerializer serializer, - string clientName) + internal delegate object? ContentSerializerDelegate(string content); + + internal class MessageResponseBuilder : IMessageResponseBuilder { - this.response = response; - this.serializer = serializer; - this.clientName = clientName; - } + private static readonly EndpointResponse EmptyResponse = new( + false, + HttpStatusCode.InternalServerError, + string.Empty, + null, + new Dictionary>()); + + private readonly Dictionary responseSerializers = new(); + private readonly Dictionary responseCodes = new(); + private readonly HttpResponseMessage? response; + private readonly IClientSerializer serializer; + private readonly string clientName; + + public MessageResponseBuilder( + HttpResponseMessage? response, + IClientSerializer serializer, + string clientName) + { + this.response = response; + this.serializer = serializer; + this.clientName = clientName; + } - public IMessageResponseBuilder AddErrorResponse(HttpStatusCode statusCode) - => AddEmptyResponse(statusCode, false); + public IMessageResponseBuilder AddErrorResponse(HttpStatusCode statusCode) + => AddEmptyResponse(statusCode, false); - public IMessageResponseBuilder AddErrorResponse(HttpStatusCode statusCode) - => AddTypedResponse(statusCode, false); + public IMessageResponseBuilder AddErrorResponse(HttpStatusCode statusCode) + => AddTypedResponse(statusCode, false); - public IMessageResponseBuilder AddSuccessResponse(HttpStatusCode statusCode) - => AddEmptyResponse(statusCode, true); + public IMessageResponseBuilder AddSuccessResponse(HttpStatusCode statusCode) + => AddEmptyResponse(statusCode, true); - public IMessageResponseBuilder AddSuccessResponse(HttpStatusCode statusCode) - => AddTypedResponse(statusCode, true); + public IMessageResponseBuilder AddSuccessResponse(HttpStatusCode statusCode) + => AddTypedResponse(statusCode, true); - public Task GetAsync(CancellationToken cancellationToken) - => GetAsync(r => r, cancellationToken); + public Task GetAsync(CancellationToken cancellationToken) + => GetAsync(r => r, cancellationToken); - public async Task GetAsync(Func factory, CancellationToken cancellationToken) - { - if (response is null) + public async Task GetAsync(Func factory, CancellationToken cancellationToken) { - return factory(EmptyResponse); - } + if (response is null) + { + return factory(EmptyResponse); + } #if NETSTANDARD2_0 || NETSTANDARD2_1 || NETCOREAPP2_0 || NETCOREAPP2_1 || NETCOREAPP2_2 || NETCOREAPP3_0 || NETCOREAPP3_1 - var content = await response.Content - .ReadAsStringAsync(); + var content = await response.Content + .ReadAsStringAsync(); #else - var content = await response.Content - .ReadAsStringAsync(cancellationToken); + var content = await response.Content + .ReadAsStringAsync(cancellationToken); #endif - return factory( - new EndpointResponse( - IsSuccessStatus(response), - response.StatusCode, - content, - GetSerializer(response.StatusCode)?.Invoke(content), - GetHeaders(response))); - } + return factory( + new EndpointResponse( + IsSuccessStatus(response), + response.StatusCode, + content, + GetSerializer(response.StatusCode)?.Invoke(content), + GetHeaders(response))); + } - private bool IsSuccessStatus(HttpResponseMessage responseMessage) - => responseCodes.TryGetValue(responseMessage.StatusCode, out var isSuccess) - ? isSuccess - : responseMessage.IsSuccessStatusCode; + private bool IsSuccessStatus(HttpResponseMessage responseMessage) + => responseCodes.TryGetValue(responseMessage.StatusCode, out var isSuccess) + ? isSuccess + : responseMessage.IsSuccessStatusCode; - private ContentSerializerDelegate? GetSerializer(HttpStatusCode statusCode) - => responseSerializers.TryGetValue(statusCode, out var @delegate) - ? @delegate - : null; + private ContentSerializerDelegate? GetSerializer(HttpStatusCode statusCode) + => responseSerializers.TryGetValue(statusCode, out var @delegate) + ? @delegate + : null; - private static Dictionary> GetHeaders(HttpResponseMessage responseMessage) - { - var headers = responseMessage.Headers.ToDictionary(h => h.Key, h => h.Value); - if (responseMessage.Content?.Headers is not null) + private static Dictionary> GetHeaders(HttpResponseMessage responseMessage) { - foreach (var item_ in responseMessage.Content.Headers) + var headers = responseMessage.Headers.ToDictionary(h => h.Key, h => h.Value); + if (responseMessage.Content?.Headers is not null) { - headers[item_.Key] = item_.Value; + foreach (var item_ in responseMessage.Content.Headers) + { + headers[item_.Key] = item_.Value; + } } - } - return headers; - } + return headers; + } - private MessageResponseBuilder AddEmptyResponse(HttpStatusCode statusCode, bool isSuccess) - { - responseSerializers[statusCode] = content => null; - responseCodes[statusCode] = isSuccess; + private MessageResponseBuilder AddEmptyResponse(HttpStatusCode statusCode, bool isSuccess) + { + responseSerializers[statusCode] = content => null; + responseCodes[statusCode] = isSuccess; - return this; - } + return this; + } - private MessageResponseBuilder AddTypedResponse(HttpStatusCode statusCode, bool isSuccess) - { - responseSerializers[statusCode] = content => serializer.Deserialize(clientName, content); - responseCodes[statusCode] = isSuccess; + private MessageResponseBuilder AddTypedResponse(HttpStatusCode statusCode, bool isSuccess) + { + responseSerializers[statusCode] = content => serializer.Deserialize(clientName, content); + responseCodes[statusCode] = isSuccess; - return this; + return this; + } } } #nullable disable \ No newline at end of file diff --git a/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#ClientEndpointAttribute.g.verified.cs b/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#ClientEndpointAttribute.g.verified.cs index 673b5fe..859a793 100644 --- a/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#ClientEndpointAttribute.g.verified.cs +++ b/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#ClientEndpointAttribute.g.verified.cs @@ -1,29 +1,31 @@ //HintName: ClientEndpointAttribute.g.cs // #nullable enable +using System; using System.Diagnostics.CodeAnalysis; -namespace Cabazure.Client; - -/// -/// Indicates that the interface is a specification for a client endpoint. -/// -[ExcludeFromCodeCoverage] -[AttributeUsage( - AttributeTargets.Interface, - Inherited = false, - AllowMultiple = false)] -internal sealed class ClientEndpointAttribute : Attribute +namespace Cabazure.Client { - public string ClientName { get; } - - /// - /// The name of the instance, the endpoint belongs to. - /// - public ClientEndpointAttribute( - string clientName) + /// + /// Indicates that the interface is a specification for a client endpoint. + /// + [ExcludeFromCodeCoverage] + [AttributeUsage( + AttributeTargets.Interface, + Inherited = false, + AllowMultiple = false)] + internal sealed class ClientEndpointAttribute : Attribute { - ClientName = clientName; + public string ClientName { get; } + + /// + /// The name of the instance, the endpoint belongs to. + /// + public ClientEndpointAttribute( + string clientName) + { + ClientName = clientName; + } } } #nullable disable \ No newline at end of file diff --git a/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#DeleteAttribute.g.verified.cs b/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#DeleteAttribute.g.verified.cs index 19f157d..5e8a61d 100644 --- a/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#DeleteAttribute.g.verified.cs +++ b/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#DeleteAttribute.g.verified.cs @@ -1,27 +1,29 @@ //HintName: DeleteAttribute.g.cs // #nullable enable +using System; using System.Diagnostics.CodeAnalysis; -namespace Cabazure.Client; - -/// -/// Identifies a HTTP DELETE request call. -/// -[ExcludeFromCodeCoverage] -[AttributeUsage( - AttributeTargets.Method, - Inherited = false, - AllowMultiple = false)] -internal sealed class DeleteAttribute : Attribute +namespace Cabazure.Client { - public string RouteTemplate { get; } - - /// The relative request path which might include placeholders, like: /users/{id}. - public DeleteAttribute( - string routeTemplate) + /// + /// Identifies a HTTP DELETE request call. + /// + [ExcludeFromCodeCoverage] + [AttributeUsage( + AttributeTargets.Method, + Inherited = false, + AllowMultiple = false)] + internal sealed class DeleteAttribute : Attribute { - RouteTemplate = routeTemplate; + public string RouteTemplate { get; } + + /// The relative request path which might include placeholders, like: /users/{id}. + public DeleteAttribute( + string routeTemplate) + { + RouteTemplate = routeTemplate; + } } } #nullable disable \ No newline at end of file diff --git a/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#GetAttribute.g.verified.cs b/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#GetAttribute.g.verified.cs index d0562a9..371acaa 100644 --- a/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#GetAttribute.g.verified.cs +++ b/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#GetAttribute.g.verified.cs @@ -1,27 +1,29 @@ //HintName: GetAttribute.g.cs // #nullable enable +using System; using System.Diagnostics.CodeAnalysis; -namespace Cabazure.Client; - -/// -/// Identifies a HTTP GET request call. -/// -[ExcludeFromCodeCoverage] -[AttributeUsage( - AttributeTargets.Method, - Inherited = false, - AllowMultiple = false)] -internal sealed class GetAttribute : Attribute +namespace Cabazure.Client { - public string RouteTemplate { get; } - - /// The relative request path which might include placeholders, like: /users/{id}. - public GetAttribute( - string routeTemplate) + /// + /// Identifies a HTTP GET request call. + /// + [ExcludeFromCodeCoverage] + [AttributeUsage( + AttributeTargets.Method, + Inherited = false, + AllowMultiple = false)] + internal sealed class GetAttribute : Attribute { - RouteTemplate = routeTemplate; + public string RouteTemplate { get; } + + /// The relative request path which might include placeholders, like: /users/{id}. + public GetAttribute( + string routeTemplate) + { + RouteTemplate = routeTemplate; + } } } #nullable disable \ No newline at end of file diff --git a/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#HeaderAttribute.g.verified.cs b/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#HeaderAttribute.g.verified.cs index a6c2efe..2466bec 100644 --- a/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#HeaderAttribute.g.verified.cs +++ b/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#HeaderAttribute.g.verified.cs @@ -1,31 +1,33 @@ //HintName: HeaderAttribute.g.cs // #nullable enable +using System; using System.Diagnostics.CodeAnalysis; -namespace Cabazure.Client; - -/// -/// Specifies that a parameter should be bound to a request header. -/// -[ExcludeFromCodeCoverage] -[AttributeUsage( - AttributeTargets.Parameter | AttributeTargets.Property, - Inherited = false, - AllowMultiple = false)] -internal sealed class HeaderAttribute : Attribute +namespace Cabazure.Client { - public string Name { get; } + /// + /// Specifies that a parameter should be bound to a request header. + /// + [ExcludeFromCodeCoverage] + [AttributeUsage( + AttributeTargets.Parameter | AttributeTargets.Property, + Inherited = false, + AllowMultiple = false)] + internal sealed class HeaderAttribute : Attribute + { + public string Name { get; } - public string? FormatString { get; } + public string? FormatString { get; } - /// The name of the request header. - public HeaderAttribute( - string name, - string? formatString = null) - { - Name = name; - FormatString = formatString; + /// The name of the request header. + public HeaderAttribute( + string name, + string? formatString = null) + { + Name = name; + FormatString = formatString; + } } } #nullable disable \ No newline at end of file diff --git a/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#ICabazureAuthClientOptions.g.verified.cs b/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#ICabazureAuthClientOptions.g.verified.cs index 3894efa..50a3f06 100644 --- a/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#ICabazureAuthClientOptions.g.verified.cs +++ b/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#ICabazureAuthClientOptions.g.verified.cs @@ -3,23 +3,24 @@ #nullable enable using Azure.Core; -namespace Cabazure.Client; - -/// -/// Options for a client that requires authentication. -/// -internal interface ICabazureAuthClientOptions : ICabazureClientOptions +namespace Cabazure.Client { /// - /// The scope to use for authorization token. + /// Options for a client that requires authentication. /// - /// The authorization scope. - string GetScope(); + internal interface ICabazureAuthClientOptions : ICabazureClientOptions + { + /// + /// The scope to use for authorization token. + /// + /// The authorization scope. + string GetScope(); - /// - /// The credential to use for authentication. - /// - /// The credential to use for authentication. - TokenCredential GetCredential(); + /// + /// The credential to use for authentication. + /// + /// The credential to use for authentication. + TokenCredential GetCredential(); + } } #nullable disable \ No newline at end of file diff --git a/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#ICabazureClientOptions.g.verified.cs b/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#ICabazureClientOptions.g.verified.cs index d6f83cf..3d5ce49 100644 --- a/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#ICabazureClientOptions.g.verified.cs +++ b/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#ICabazureClientOptions.g.verified.cs @@ -1,20 +1,23 @@ //HintName: ICabazureClientOptions.g.cs // #nullable enable -namespace Cabazure.Client; +using System; -/// -/// The base options interface used to describe options that can resolve the BaseAddress of the API. -/// -internal interface ICabazureClientOptions +namespace Cabazure.Client { /// - /// The base address of the API. + /// The base options interface used to describe options that can resolve the BaseAddress of the API. /// - /// The base address for the API. - /// - /// If the base address contains path segments, use a trailing slash (/) to separate the base address from the relative path segments. - /// - Uri GetBaseAddress(); + internal interface ICabazureClientOptions + { + /// + /// The base address of the API. + /// + /// The base address for the API. + /// + /// If the base address contains path segments, use a trailing slash (/) to separate the base address from the relative path segments. + /// + Uri GetBaseAddress(); + } } #nullable disable \ No newline at end of file diff --git a/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#PathAttribute.g.verified.cs b/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#PathAttribute.g.verified.cs index fbbf266..4fb8166 100644 --- a/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#PathAttribute.g.verified.cs +++ b/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#PathAttribute.g.verified.cs @@ -1,31 +1,33 @@ //HintName: PathAttribute.g.cs // #nullable enable +using System; using System.Diagnostics.CodeAnalysis; -namespace Cabazure.Client; - -/// -/// Specifies that a parameter should be added to a placeholder in the request path. -/// -[ExcludeFromCodeCoverage] -[AttributeUsage( - AttributeTargets.Parameter | AttributeTargets.Property, - Inherited = false, - AllowMultiple = false)] -internal sealed class PathAttribute : Attribute +namespace Cabazure.Client { - public string? Name { get; } + /// + /// Specifies that a parameter should be added to a placeholder in the request path. + /// + [ExcludeFromCodeCoverage] + [AttributeUsage( + AttributeTargets.Parameter | AttributeTargets.Property, + Inherited = false, + AllowMultiple = false)] + internal sealed class PathAttribute : Attribute + { + public string? Name { get; } - public string? FormatString { get; } + public string? FormatString { get; } - /// The name of the placeholder in the path. If obmitted, the parameter name will be used. - public PathAttribute( - string? name = null, - string? formatString = null) - { - Name = name; - FormatString = formatString; + /// The name of the placeholder in the path. If obmitted, the parameter name will be used. + public PathAttribute( + string? name = null, + string? formatString = null) + { + Name = name; + FormatString = formatString; + } } } #nullable disable \ No newline at end of file diff --git a/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#PostAttribute.g.verified.cs b/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#PostAttribute.g.verified.cs index a64b1dc..548bfe9 100644 --- a/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#PostAttribute.g.verified.cs +++ b/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#PostAttribute.g.verified.cs @@ -1,27 +1,29 @@ //HintName: PostAttribute.g.cs // #nullable enable +using System; using System.Diagnostics.CodeAnalysis; -namespace Cabazure.Client; - -/// -/// Identifies a HTTP POST request call. -/// -[ExcludeFromCodeCoverage] -[AttributeUsage( - AttributeTargets.Method, - Inherited = false, - AllowMultiple = false)] -internal sealed class PostAttribute : Attribute +namespace Cabazure.Client { - public string RouteTemplate { get; } - - /// The relative request path which might include placeholders, like: /users/{id}. - public PostAttribute( - string routeTemplate) + /// + /// Identifies a HTTP POST request call. + /// + [ExcludeFromCodeCoverage] + [AttributeUsage( + AttributeTargets.Method, + Inherited = false, + AllowMultiple = false)] + internal sealed class PostAttribute : Attribute { - RouteTemplate = routeTemplate; + public string RouteTemplate { get; } + + /// The relative request path which might include placeholders, like: /users/{id}. + public PostAttribute( + string routeTemplate) + { + RouteTemplate = routeTemplate; + } } } #nullable disable \ No newline at end of file diff --git a/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#PutAttribute.g.verified.cs b/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#PutAttribute.g.verified.cs index ad3ff1c..c7c6ed1 100644 --- a/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#PutAttribute.g.verified.cs +++ b/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#PutAttribute.g.verified.cs @@ -1,27 +1,29 @@ //HintName: PutAttribute.g.cs // #nullable enable +using System; using System.Diagnostics.CodeAnalysis; -namespace Cabazure.Client; - -/// -/// Identifies a HTTP PUT request call. -/// -[ExcludeFromCodeCoverage] -[AttributeUsage( - AttributeTargets.Method, - Inherited = false, - AllowMultiple = false)] -internal sealed class PutAttribute : Attribute +namespace Cabazure.Client { - public string RouteTemplate { get; } - - /// The relative request path which might include placeholders, like: /users/{id}. - public PutAttribute( - string routeTemplate) + /// + /// Identifies a HTTP PUT request call. + /// + [ExcludeFromCodeCoverage] + [AttributeUsage( + AttributeTargets.Method, + Inherited = false, + AllowMultiple = false)] + internal sealed class PutAttribute : Attribute { - RouteTemplate = routeTemplate; + public string RouteTemplate { get; } + + /// The relative request path which might include placeholders, like: /users/{id}. + public PutAttribute( + string routeTemplate) + { + RouteTemplate = routeTemplate; + } } } #nullable disable \ No newline at end of file diff --git a/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#QueryAttribute.g.verified.cs b/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#QueryAttribute.g.verified.cs index dd13b8f..1da784f 100644 --- a/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#QueryAttribute.g.verified.cs +++ b/test/Cabazure.Client.Tests/EmbeddedSourceGeneratorTests.CanGenerate_EmbeddedSource#QueryAttribute.g.verified.cs @@ -1,31 +1,33 @@ //HintName: QueryAttribute.g.cs // #nullable enable +using System; using System.Diagnostics.CodeAnalysis; -namespace Cabazure.Client; - -/// -/// Specifies that a parameter should be bound to a request query parameter. -/// -[ExcludeFromCodeCoverage] -[AttributeUsage( - AttributeTargets.Parameter | AttributeTargets.Property, - Inherited = false, - AllowMultiple = false)] -internal sealed class QueryAttribute : Attribute +namespace Cabazure.Client { - public string? Name { get; } + /// + /// Specifies that a parameter should be bound to a request query parameter. + /// + [ExcludeFromCodeCoverage] + [AttributeUsage( + AttributeTargets.Parameter | AttributeTargets.Property, + Inherited = false, + AllowMultiple = false)] + internal sealed class QueryAttribute : Attribute + { + public string? Name { get; } - public string? FormatString { get; } + public string? FormatString { get; } - /// The name of tyhe query parameter. If obmitted, the parameter name will be used. - public QueryAttribute( - string? name = null, - string? formatString = null) - { - Name = name; - FormatString = formatString; + /// The name of tyhe query parameter. If obmitted, the parameter name will be used. + public QueryAttribute( + string? name = null, + string? formatString = null) + { + Name = name; + FormatString = formatString; + } } } #nullable disable \ No newline at end of file