From 84992c347d5cc149f34bae008d3c1c843e840d6e Mon Sep 17 00:00:00 2001 From: Wei Hu Date: Thu, 31 Oct 2024 12:24:33 +0800 Subject: [PATCH] Update ClientPipelineApi, HttpMessageApi abstraction (#4816) - Remove unused `ClientPipelineApi.CreateMessage` - Add `HttpRequestOptionsApi` to `ClientPipelineApi.Send(Async)` - Replace `HttpMessageApi.ResponseClassifier` with `HttpMessageApi.ApplyResponseClassifier` - Make abstraction more generic This fix is needed for below issues of Azure plugin: https://github.com/Azure/azure-sdk-for-net/issues/46899 https://github.com/Azure/azure-sdk-for-net/issues/46900 https://github.com/Azure/azure-sdk-for-net/issues/46901 https://github.com/Azure/azure-sdk-for-net/issues/46902 --- .../Abstractions/ClientPipelineApi.cs | 8 +-- .../Providers/Abstractions/HttpMessageApi.cs | 4 +- .../Providers/Abstractions/HttpRequestApi.cs | 7 +-- .../Abstractions/ValueExpressionExtensions.cs | 51 +++++++++++++++++++ .../ClientPipelineExtensionsDefinition.cs | 12 ++--- .../src/Providers/ClientPipelineProvider.cs | 14 +++-- .../src/Providers/PipelineMessageProvider.cs | 7 +-- .../src/Providers/PipelineRequestProvider.cs | 13 ++--- .../src/Providers/RestClientProvider.cs | 16 +++--- .../Abstractions/ClientPipelineApiTests.cs | 13 ++--- .../Abstractions/HttpMessageApiTests.cs | 9 ++-- ...teBodyOfRestClientOperationIsOverridden.cs | 2 +- 12 files changed, 102 insertions(+), 54 deletions(-) diff --git a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/Providers/Abstractions/ClientPipelineApi.cs b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/Providers/Abstractions/ClientPipelineApi.cs index b32cd0976c..9c18555bf2 100644 --- a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/Providers/Abstractions/ClientPipelineApi.cs +++ b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/Providers/Abstractions/ClientPipelineApi.cs @@ -4,7 +4,9 @@ using System; using Microsoft.Generator.CSharp.Expressions; using Microsoft.Generator.CSharp.Primitives; +using Microsoft.Generator.CSharp.Providers; using Microsoft.Generator.CSharp.Snippets; +using Microsoft.Generator.CSharp.Statements; namespace Microsoft.Generator.CSharp.ClientModel.Providers { @@ -18,13 +20,11 @@ protected ClientPipelineApi(Type type, ValueExpression original) : base(type, or { } - public abstract HttpMessageApi CreateMessage(); - public abstract ValueExpression CreateMessage(HttpRequestOptionsApi requestOptions, ValueExpression responseClassifier); - public abstract InvokeMethodExpression Send(HttpMessageApi message); + public abstract MethodBodyStatement Send(HttpMessageApi message, HttpRequestOptionsApi options); - public abstract InvokeMethodExpression SendAsync(HttpMessageApi message); + public abstract MethodBodyStatement SendAsync(HttpMessageApi message, HttpRequestOptionsApi options); public abstract ValueExpression Create(ValueExpression options, ValueExpression perRetryPolicies); diff --git a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/Providers/Abstractions/HttpMessageApi.cs b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/Providers/Abstractions/HttpMessageApi.cs index a955d07367..1ae33e935d 100644 --- a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/Providers/Abstractions/HttpMessageApi.cs +++ b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/Providers/Abstractions/HttpMessageApi.cs @@ -21,9 +21,9 @@ protected HttpMessageApi(Type type, ValueExpression original) : base(type, origi public abstract ValueExpression BufferResponse(); - public abstract ValueExpression ResponseClassifier(); + public abstract MethodBodyStatement ApplyResponseClassifier(StatusCodeClassifierApi statusCodeClassifier); - public abstract MethodBodyStatement Apply(ValueExpression options); + public abstract MethodBodyStatement ApplyRequestOptions(HttpRequestOptionsApi options); public abstract MethodBodyStatement[] ExtractResponse(); diff --git a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/Providers/Abstractions/HttpRequestApi.cs b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/Providers/Abstractions/HttpRequestApi.cs index 910355647a..5428986201 100644 --- a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/Providers/Abstractions/HttpRequestApi.cs +++ b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/Providers/Abstractions/HttpRequestApi.cs @@ -6,6 +6,7 @@ using Microsoft.Generator.CSharp.Expressions; using Microsoft.Generator.CSharp.Primitives; using Microsoft.Generator.CSharp.Snippets; +using Microsoft.Generator.CSharp.Statements; namespace Microsoft.Generator.CSharp.ClientModel.Providers { @@ -15,11 +16,11 @@ protected HttpRequestApi(CSharpType type, ValueExpression original) : base(type, { } - public abstract AssignmentExpression SetMethod(string httpMethod); + public abstract MethodBodyStatement SetMethod(string httpMethod); - public abstract AssignmentExpression SetUri(ValueExpression uri); + public abstract MethodBodyStatement SetUri(ValueExpression uri); - public abstract InvokeMethodExpression SetHeaders(IReadOnlyList arguments); + public abstract MethodBodyStatement SetHeaders(IReadOnlyList arguments); public abstract ValueExpression Content(); public abstract HttpRequestApi FromExpression(ValueExpression original); diff --git a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/Providers/Abstractions/ValueExpressionExtensions.cs b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/Providers/Abstractions/ValueExpressionExtensions.cs index 044708c6b8..e4bc7219a8 100644 --- a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/Providers/Abstractions/ValueExpressionExtensions.cs +++ b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/Providers/Abstractions/ValueExpressionExtensions.cs @@ -3,6 +3,7 @@ using System; using Microsoft.Generator.CSharp.Expressions; +using Microsoft.Generator.CSharp.Providers; using Microsoft.Generator.CSharp.Snippets; namespace Microsoft.Generator.CSharp.ClientModel.Providers @@ -33,5 +34,55 @@ public static T ToApi(this ValueExpression valueExpression) where T : ScopedA throw new InvalidOperationException($"Invalid type {typeof(T)}"); } } + + public static T ToApi(this ParameterProvider valueExpression) where T : ScopedApi + { + switch (typeof(T).Name) + { + case nameof(ClientResponseApi): + return (T)(object)ClientModelPlugin.Instance.TypeFactory.ClientResponseApi.FromExpression(valueExpression); + case nameof(HttpResponseApi): + return (T)(object)ClientModelPlugin.Instance.TypeFactory.HttpResponseApi.FromExpression(valueExpression); + case nameof(HttpRequestOptionsApi): + return (T)(object)ClientModelPlugin.Instance.TypeFactory.HttpRequestOptionsApi.FromExpression(valueExpression); + case nameof(HttpMessageApi): + return (T)(object)ClientModelPlugin.Instance.TypeFactory.HttpMessageApi.FromExpression(valueExpression); + case nameof(HttpRequestApi): + return (T)(object)ClientModelPlugin.Instance.TypeFactory.HttpRequestApi.FromExpression(valueExpression); + case nameof(ClientPipelineApi): + return (T)(object)ClientModelPlugin.Instance.TypeFactory.ClientPipelineApi.FromExpression(valueExpression); + case nameof(StatusCodeClassifierApi): + return (T)(object)ClientModelPlugin.Instance.TypeFactory.StatusCodeClassifierApi.FromExpression(valueExpression); + case nameof(RequestContentApi): + return (T)(object)ClientModelPlugin.Instance.TypeFactory.RequestContentApi.FromExpression(valueExpression); + default: + throw new InvalidOperationException($"Invalid type {typeof(T)}"); + } + } + + public static T ToApi(this PropertyProvider valueExpression) where T : ScopedApi + { + switch (typeof(T).Name) + { + case nameof(ClientResponseApi): + return (T)(object)ClientModelPlugin.Instance.TypeFactory.ClientResponseApi.FromExpression(valueExpression); + case nameof(HttpResponseApi): + return (T)(object)ClientModelPlugin.Instance.TypeFactory.HttpResponseApi.FromExpression(valueExpression); + case nameof(HttpRequestOptionsApi): + return (T)(object)ClientModelPlugin.Instance.TypeFactory.HttpRequestOptionsApi.FromExpression(valueExpression); + case nameof(HttpMessageApi): + return (T)(object)ClientModelPlugin.Instance.TypeFactory.HttpMessageApi.FromExpression(valueExpression); + case nameof(HttpRequestApi): + return (T)(object)ClientModelPlugin.Instance.TypeFactory.HttpRequestApi.FromExpression(valueExpression); + case nameof(ClientPipelineApi): + return (T)(object)ClientModelPlugin.Instance.TypeFactory.ClientPipelineApi.FromExpression(valueExpression); + case nameof(StatusCodeClassifierApi): + return (T)(object)ClientModelPlugin.Instance.TypeFactory.StatusCodeClassifierApi.FromExpression(valueExpression); + case nameof(RequestContentApi): + return (T)(object)ClientModelPlugin.Instance.TypeFactory.RequestContentApi.FromExpression(valueExpression); + default: + throw new InvalidOperationException($"Invalid type {typeof(T)}"); + } + } } } diff --git a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/Providers/ClientPipelineExtensionsDefinition.cs b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/Providers/ClientPipelineExtensionsDefinition.cs index 0ecac00ae2..0dbf23902e 100644 --- a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/Providers/ClientPipelineExtensionsDefinition.cs +++ b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/Providers/ClientPipelineExtensionsDefinition.cs @@ -27,10 +27,10 @@ public ClientPipelineExtensionsDefinition() { _pipelineParam = new ParameterProvider("pipeline", FormattableStringHelpers.Empty, ClientModelPlugin.Instance.TypeFactory.ClientPipelineApi.ClientPipelineType); _messageParam = new ParameterProvider("message", FormattableStringHelpers.Empty, ClientModelPlugin.Instance.TypeFactory.HttpMessageApi.HttpMessageType); - _requestOptionsParam = new ParameterProvider("options", FormattableStringHelpers.Empty, ClientModelPlugin.Instance.TypeFactory.HttpRequestOptionsApi.HttpRequestOptionsType); - _pipeline = _pipelineParam.AsExpression.ToApi(); - _message = _messageParam.AsExpression.ToApi(); - _options = _requestOptionsParam.AsExpression.ToApi(); + _requestOptionsParam = new ParameterProvider(ClientModelPlugin.Instance.TypeFactory.HttpRequestOptionsApi.ParameterName, FormattableStringHelpers.Empty, ClientModelPlugin.Instance.TypeFactory.HttpRequestOptionsApi.HttpRequestOptionsType); + _pipeline = _pipelineParam.ToApi(); + _message = _messageParam.ToApi(); + _options = _requestOptionsParam.ToApi(); } protected override TypeSignatureModifiers GetDeclarationModifiers() @@ -124,7 +124,7 @@ private MethodProvider BuildProcessMessage() var clientErrorNoThrow = _options.NoThrow(); return new MethodProvider(signature, new MethodBodyStatement[] { - _pipeline.Send(_message).Terminate(), + _pipeline.Send(_message, _options), MethodBodyStatement.EmptyLine, new IfStatement(_message.Response().IsError().And(new BinaryOperatorExpression("&", _options.NullConditional().Property("ErrorOptions"), clientErrorNoThrow).NotEqual(clientErrorNoThrow))) { @@ -167,7 +167,7 @@ private MethodProvider BuildProcessMessageAsync() var clientErrorNoThrow = _options.NoThrow(); return new MethodProvider(signature, new MethodBodyStatement[] { - _pipeline.SendAsync(_message).Terminate(), + _pipeline.SendAsync(_message, _options), MethodBodyStatement.EmptyLine, new IfStatement(_message.Response().IsError().And(new BinaryOperatorExpression("&", _options.NullConditional().Property("ErrorOptions"), clientErrorNoThrow).NotEqual(clientErrorNoThrow))) { diff --git a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/Providers/ClientPipelineProvider.cs b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/Providers/ClientPipelineProvider.cs index 404fb05181..22c0307808 100644 --- a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/Providers/ClientPipelineProvider.cs +++ b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/Providers/ClientPipelineProvider.cs @@ -4,6 +4,7 @@ using System.ClientModel.Primitives; using Microsoft.Generator.CSharp.Expressions; using Microsoft.Generator.CSharp.Primitives; +using Microsoft.Generator.CSharp.Statements; using static Microsoft.Generator.CSharp.Snippets.Snippet; namespace Microsoft.Generator.CSharp.ClientModel.Providers @@ -26,11 +27,8 @@ public ClientPipelineProvider(ValueExpression original) : base(typeof(ClientPipe public override ValueExpression Create(ValueExpression options, ValueExpression perRetryPolicies) => Static().Invoke(nameof(ClientPipeline.Create), [options, New.Array(ClientModelPlugin.Instance.TypeFactory.ClientPipelineApi.PipelinePolicyType), perRetryPolicies, New.Array(ClientModelPlugin.Instance.TypeFactory.ClientPipelineApi.PipelinePolicyType)]).As(); - public override HttpMessageApi CreateMessage() - => new PipelineMessageProvider(Original.Invoke(nameof(ClientPipeline.CreateMessage))); - public override ValueExpression CreateMessage(HttpRequestOptionsApi requestOptions, ValueExpression responseClassifier) - => Original.Invoke(nameof(ClientPipeline.CreateMessage), requestOptions, responseClassifier).As(); + => new PipelineMessageProvider(Original.Invoke(nameof(ClientPipeline.CreateMessage))); public override ClientPipelineApi FromExpression(ValueExpression expression) => new ClientPipelineProvider(expression); @@ -38,11 +36,11 @@ public override ClientPipelineApi FromExpression(ValueExpression expression) public override ValueExpression PerRetryPolicy(params ValueExpression[] arguments) => Static().Invoke(nameof(ApiKeyAuthenticationPolicy.CreateHeaderApiKeyPolicy), arguments).As(); - public override InvokeMethodExpression Send(HttpMessageApi message) - => Original.Invoke(nameof(ClientPipeline.Send), [message]); + public override MethodBodyStatement Send(HttpMessageApi message, HttpRequestOptionsApi options) + => Original.Invoke(nameof(ClientPipeline.Send), [message]).Terminate(); - public override InvokeMethodExpression SendAsync(HttpMessageApi message) - => Original.Invoke(nameof(ClientPipeline.SendAsync), [message], true); + public override MethodBodyStatement SendAsync(HttpMessageApi message, HttpRequestOptionsApi options) + => Original.Invoke(nameof(ClientPipeline.SendAsync), [message], true).Terminate(); public override ClientPipelineApi ToExpression() => this; } diff --git a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/Providers/PipelineMessageProvider.cs b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/Providers/PipelineMessageProvider.cs index 25467d7cf1..255acaebc4 100644 --- a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/Providers/PipelineMessageProvider.cs +++ b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/Providers/PipelineMessageProvider.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System.ClientModel.Primitives; +using Microsoft.CodeAnalysis.Classification; using Microsoft.Generator.CSharp.Expressions; using Microsoft.Generator.CSharp.Primitives; using Microsoft.Generator.CSharp.Statements; @@ -27,10 +28,10 @@ public override ValueExpression BufferResponse() public override HttpResponseApi Response() => new PipelineResponseProvider(Original.Property(nameof(PipelineMessage.Response))); - public override ValueExpression ResponseClassifier() - => Original.Property(nameof(PipelineMessage.ResponseClassifier)); + public override MethodBodyStatement ApplyResponseClassifier(StatusCodeClassifierApi statusCodeClassifier) + => Original.Property(nameof(PipelineMessage.ResponseClassifier)).Assign(statusCodeClassifier).Terminate(); - public override MethodBodyStatement Apply(ValueExpression options) + public override MethodBodyStatement ApplyRequestOptions(HttpRequestOptionsApi options) => Original.Invoke(nameof(PipelineMessage.Apply), options).Terminate(); public override MethodBodyStatement[] ExtractResponse() diff --git a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/Providers/PipelineRequestProvider.cs b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/Providers/PipelineRequestProvider.cs index 202d196655..a8d36d45be 100644 --- a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/Providers/PipelineRequestProvider.cs +++ b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/Providers/PipelineRequestProvider.cs @@ -6,6 +6,7 @@ using Microsoft.Generator.CSharp.Expressions; using Microsoft.Generator.CSharp.ClientModel.Snippets; using static Microsoft.Generator.CSharp.Snippets.Snippet; +using Microsoft.Generator.CSharp.Statements; namespace Microsoft.Generator.CSharp.ClientModel.Providers { @@ -24,14 +25,14 @@ public override ValueExpression Content() public override HttpRequestApi FromExpression(ValueExpression original) => new PipelineRequestProvider(original); - public override InvokeMethodExpression SetHeaders(IReadOnlyList arguments) - => Original.Property(nameof(PipelineRequest.Headers)).Invoke(nameof(PipelineRequestHeaders.Set), arguments); + public override MethodBodyStatement SetHeaders(IReadOnlyList arguments) + => Original.Property(nameof(PipelineRequest.Headers)).Invoke(nameof(PipelineRequestHeaders.Set), arguments).Terminate(); - public override AssignmentExpression SetMethod(string httpMethod) - => Original.Property(nameof(PipelineRequest.Method)).Assign(Literal(httpMethod)); + public override MethodBodyStatement SetMethod(string httpMethod) + => Original.Property(nameof(PipelineRequest.Method)).Assign(Literal(httpMethod)).Terminate(); - public override AssignmentExpression SetUri(ValueExpression value) - => Original.Property("Uri").Assign(value.As().ToUri()); + public override MethodBodyStatement SetUri(ValueExpression value) + => Original.Property("Uri").Assign(value.As().ToUri()).Terminate(); public override HttpRequestApi ToExpression() => this; } diff --git a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/Providers/RestClientProvider.cs b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/Providers/RestClientProvider.cs index 8d26b7ba08..99dafe5aa3 100644 --- a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/Providers/RestClientProvider.cs +++ b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/Providers/RestClientProvider.cs @@ -131,7 +131,7 @@ private bool IsCreateRequest(MethodProvider method) private MethodProvider BuildCreateRequestMethod(InputOperation operation) { - var pipelineField = ((MemberExpression)ClientProvider.PipelineProperty).ToApi(); + var pipelineField = ClientProvider.PipelineProperty.ToApi(); var options = ScmKnownParameters.RequestOptions; var signature = new MethodSignature( @@ -165,18 +165,18 @@ private MethodProvider BuildCreateRequestMethod(InputOperation operation) signature, new MethodBodyStatements( [ - Declare("message", pipelineField.CreateMessage().ToApi(), out HttpMessageApi message), - message.ResponseClassifier().Assign(classifier).Terminate(), - Declare("request", message.Request().ToApi(), out HttpRequestApi request), // ScopedApi - request.SetMethod(operation.HttpMethod).Terminate(), + Declare("message", pipelineField.CreateMessage(options.ToApi(), classifier).ToApi(), out HttpMessageApi message), + message.ApplyResponseClassifier(classifier.ToApi()), + Declare("request", message.Request().ToApi(), out HttpRequestApi request), + request.SetMethod(operation.HttpMethod), Declare("uri", New.Instance(), out ScopedApi uri), uri.Reset(ClientProvider.EndpointField).Terminate(), .. AppendPathParameters(uri, operation, paramMap), .. AppendQueryParameters(uri, operation, paramMap), - request.SetUri(uri).Terminate(), + request.SetUri(uri), .. AppendHeaderParameters(request, operation, paramMap), .. GetSetContent(request, signature.Parameters), - message.Apply(options), + message.ApplyRequestOptions(options.ToApi()), Return(message) ]), this); @@ -231,7 +231,7 @@ private IEnumerable AppendHeaderParameters(HttpRequestApi r } else { - statement = request.SetHeaders([Literal(inputParameter.NameInRequest), toStringExpression.As()]).Terminate(); + statement = request.SetHeaders([Literal(inputParameter.NameInRequest), toStringExpression.As()]); } statements.Add(statement); } diff --git a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/test/Providers/Abstractions/ClientPipelineApiTests.cs b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/test/Providers/Abstractions/ClientPipelineApiTests.cs index 2ea76f42bd..fb5c2538b4 100644 --- a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/test/Providers/Abstractions/ClientPipelineApiTests.cs +++ b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/test/Providers/Abstractions/ClientPipelineApiTests.cs @@ -2,6 +2,7 @@ using Microsoft.Generator.CSharp.ClientModel.Providers; using Microsoft.Generator.CSharp.Expressions; using Microsoft.Generator.CSharp.Primitives; +using Microsoft.Generator.CSharp.Statements; using Microsoft.Generator.CSharp.Tests.Common; using NUnit.Framework; @@ -28,7 +29,6 @@ public void ValidateBodyOfRestClientOperationIsOverridden() Assert.NotNull(method); Assert.NotNull(method!.BodyStatements); - var test = method?.BodyStatements?.ToDisplayString(); Assert.AreEqual(Helpers.GetExpectedFromFile(), method!.BodyStatements!.ToDisplayString()); } @@ -58,9 +58,6 @@ public TestClientPipelineApi(ValueExpression original) : base(typeof(string), or public override ValueExpression Create(ValueExpression options, ValueExpression perRetryPolicies) => Original.Invoke("GetFakeCreate", [options, perRetryPolicies]); - public override HttpMessageApi CreateMessage() - => Original.Invoke("GetFakeCreateMessage").ToApi(); - public override ValueExpression CreateMessage(HttpRequestOptionsApi requestOptions, ValueExpression responseClassifier) => Original.Invoke("GetFakeCreateMessage", [requestOptions, responseClassifier]); @@ -70,11 +67,11 @@ public override ClientPipelineApi FromExpression(ValueExpression expression) public override ValueExpression PerRetryPolicy(params ValueExpression[] arguments) => Original.Invoke("GetFakePerRetryPolicy", arguments); - public override InvokeMethodExpression Send(HttpMessageApi message) - => Original.Invoke("GetFakeSend", message); + public override MethodBodyStatement Send(HttpMessageApi message, HttpRequestOptionsApi options) + => Original.Invoke("GetFakeSend", [message, options]).Terminate(); - public override InvokeMethodExpression SendAsync(HttpMessageApi message) - => Original.Invoke("GetFakeSendAsync", message); + public override MethodBodyStatement SendAsync(HttpMessageApi message, HttpRequestOptionsApi options) + => Original.Invoke("GetFakeSendAsync", [message, options]).Terminate(); public override ClientPipelineApi ToExpression() => this; } diff --git a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/test/Providers/Abstractions/HttpMessageApiTests.cs b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/test/Providers/Abstractions/HttpMessageApiTests.cs index f9ceabb91e..2bd282029a 100644 --- a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/test/Providers/Abstractions/HttpMessageApiTests.cs +++ b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/test/Providers/Abstractions/HttpMessageApiTests.cs @@ -32,7 +32,6 @@ public void ValidateBodyOfProcessMessageIsOverridden() Assert.IsNotNull(method); Assert.IsNotNull(method!.BodyStatements); - var test = method!.BodyStatements!.ToDisplayString(); Assert.AreEqual(Helpers.GetExpectedFromFile(), method!.BodyStatements!.ToDisplayString()); } @@ -55,8 +54,8 @@ public TestHttpMessageApi(ValueExpression original) : base(typeof(string), origi public override CSharpType HttpMessageType => typeof(string); - public override MethodBodyStatement Apply(ValueExpression options) - => Original.Invoke("GetFakeApply", [options]).Terminate(); + public override MethodBodyStatement ApplyRequestOptions(HttpRequestOptionsApi options) + => Original.Invoke("GetFakeSetRequestContext", [options]).Terminate(); public override ValueExpression BufferResponse() => Original.Invoke("GetFakeBufferResponse"); @@ -73,8 +72,8 @@ public override HttpRequestApi Request() public override HttpResponseApi Response() => Original.Invoke("GetFakeResponse").ToApi(); - public override ValueExpression ResponseClassifier() - => Original.Invoke("GetFakeResponseClassifier"); + public override MethodBodyStatement ApplyResponseClassifier(StatusCodeClassifierApi statusCodeClassifier) + => Original.Invoke("GetFakeAssignResponseClassifier", [statusCodeClassifier]).Terminate(); public override HttpMessageApi ToExpression() => this; } diff --git a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/test/Providers/Abstractions/TestData/ClientPipelineApiTests/ValidateBodyOfRestClientOperationIsOverridden.cs b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/test/Providers/Abstractions/TestData/ClientPipelineApiTests/ValidateBodyOfRestClientOperationIsOverridden.cs index 82fcb29c6c..b835fb8067 100644 --- a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/test/Providers/Abstractions/TestData/ClientPipelineApiTests/ValidateBodyOfRestClientOperationIsOverridden.cs +++ b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/test/Providers/Abstractions/TestData/ClientPipelineApiTests/ValidateBodyOfRestClientOperationIsOverridden.cs @@ -1,4 +1,4 @@ -global::System.ClientModel.Primitives.PipelineMessage message = Pipeline.GetFakeCreateMessage(); +global::System.ClientModel.Primitives.PipelineMessage message = Pipeline.GetFakeCreateMessage(options, PipelineMessageClassifier200); message.ResponseClassifier = PipelineMessageClassifier200; global::System.ClientModel.Primitives.PipelineRequest request = message.Request; request.Method = "GET";