diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ScmMethodProviderCollection.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ScmMethodProviderCollection.cs index c85805768e9..fb2ad27ddd8 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ScmMethodProviderCollection.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ScmMethodProviderCollection.cs @@ -804,7 +804,17 @@ private IReadOnlyList GetProtocolMethodArguments(Dictionary [inputClient], inputModels: () => [streamModel]); + + var client = ScmCodeModelGenerator.Instance.TypeFactory.CreateClient(inputClient); + Assert.IsNotNull(client); + + var methodCollection = new ScmMethodProviderCollection(serviceMethod, client!); + var convenienceMethod = methodCollection.FirstOrDefault( + m => m.Signature.Parameters.Any(p => p.Name == "stream") && m.Signature.Name == "Send"); + Assert.IsNotNull(convenienceMethod); + + var methodBody = convenienceMethod!.BodyStatements!.ToDisplayString(); + // Verify that BinaryContent.Create() wraps the property access + Assert.IsTrue(methodBody.Contains("BinaryContent.Create(stream.Body)"), + $"Expected 'BinaryContent.Create(stream.Body)' in method body but got: {methodBody}"); + } + [Test] public async Task MissingOperationParamsResultInNamedArgsForSubsequent() { diff --git a/packages/http-client-csharp/generator/TestProjects/Local/Sample-TypeSpec/src/Generated/SampleTypeSpecClient.cs b/packages/http-client-csharp/generator/TestProjects/Local/Sample-TypeSpec/src/Generated/SampleTypeSpecClient.cs index 659c42158d9..793f3eb27a1 100644 --- a/packages/http-client-csharp/generator/TestProjects/Local/Sample-TypeSpec/src/Generated/SampleTypeSpecClient.cs +++ b/packages/http-client-csharp/generator/TestProjects/Local/Sample-TypeSpec/src/Generated/SampleTypeSpecClient.cs @@ -334,7 +334,7 @@ public virtual ClientResult NoContentType(Wrapper info, Cancella { Argument.AssertNotNull(info, nameof(info)); - ClientResult result = NoContentType(info.P2, info.P1, info.Action, cancellationToken.ToRequestOptions()); + ClientResult result = NoContentType(info.P2, info.P1, BinaryContent.Create(info.Action), cancellationToken.ToRequestOptions()); return ClientResult.FromValue((RoundTripModel)result, result.GetRawResponse()); } @@ -347,7 +347,7 @@ public virtual async Task> NoContentTypeAsync(Wrapp { Argument.AssertNotNull(info, nameof(info)); - ClientResult result = await NoContentTypeAsync(info.P2, info.P1, info.Action, cancellationToken.ToRequestOptions()).ConfigureAwait(false); + ClientResult result = await NoContentTypeAsync(info.P2, info.P1, BinaryContent.Create(info.Action), cancellationToken.ToRequestOptions()).ConfigureAwait(false); return ClientResult.FromValue((RoundTripModel)result, result.GetRawResponse()); }