From 8513f93539b4b65d3164dd2c0b7271732da3279c Mon Sep 17 00:00:00 2001
From: mcgallan <88413158+mcgallan@users.noreply.github.com>
Date: Mon, 11 Nov 2024 11:22:51 +0800
Subject: [PATCH] Add Client Example Test And Fix ResourceManager Resource Test
(#5153)
* generate
* regen
* update
* Update resource-manager-resources.cs
* update
---
eng/testProjects.json | 1 +
.../Properties/launchSettings.json | 4 +
.../azure-example-client-basic.cs | 38 +
.../resource-manager-resources.cs | 55 +-
.../azure/example/basic/Configuration.json | 12 +
.../basic/_Specs_.Azure.Example.Basic.sln | 50 ++
.../basic/src/Generated/AzureExampleClient.cs | 208 +++++
.../Generated/AzureExampleClientOptions.cs | 37 +
.../src/Generated/Docs/AzureExampleClient.xml | 111 +++
.../basic/src/Generated/Internal/Argument.cs | 129 ++++
.../Internal/ChangeTrackingDictionary.cs | 167 ++++
.../Generated/Internal/ChangeTrackingList.cs | 153 ++++
.../Internal/ModelSerializationExtensions.cs | 398 ++++++++++
.../basic/src/Generated/Internal/Optional.cs | 51 ++
.../Internal/Utf8JsonRequestContent.cs | 55 ++
.../Models/ActionRequest.Serialization.cs | 202 +++++
.../src/Generated/Models/ActionRequest.cs | 89 +++
.../Models/ActionResponse.Serialization.cs | 202 +++++
.../src/Generated/Models/ActionResponse.cs | 89 +++
.../basic/src/Generated/Models/Enum.cs | 48 ++
.../Generated/Models/Model.Serialization.cs | 173 +++++
.../basic/src/Generated/Models/Model.cs | 73 ++
...zureExampleBasicClientBuilderExtensions.cs | 35 +
.../SpecsAzureExampleBasicModelFactory.cs | 44 ++
.../basic/src/Properties/AssemblyInfo.cs | 6 +
.../src/_Specs_.Azure.Example.Basic.csproj | 19 +
.../Samples/Samples_AzureExampleClient.cs | 127 +++
.../_Specs_.Azure.Example.Basic.Tests.csproj | 19 +
.../azure/example/basic/tspCodeModel.json | 731 ++++++++++++++++++
.../azure/example/basic/tspconfig.yaml | 4 +
30 files changed, 3308 insertions(+), 22 deletions(-)
create mode 100644 test/CadlRanchProjects.Tests/azure-example-client-basic.cs
create mode 100644 test/CadlRanchProjects/azure/example/basic/Configuration.json
create mode 100644 test/CadlRanchProjects/azure/example/basic/_Specs_.Azure.Example.Basic.sln
create mode 100644 test/CadlRanchProjects/azure/example/basic/src/Generated/AzureExampleClient.cs
create mode 100644 test/CadlRanchProjects/azure/example/basic/src/Generated/AzureExampleClientOptions.cs
create mode 100644 test/CadlRanchProjects/azure/example/basic/src/Generated/Docs/AzureExampleClient.xml
create mode 100644 test/CadlRanchProjects/azure/example/basic/src/Generated/Internal/Argument.cs
create mode 100644 test/CadlRanchProjects/azure/example/basic/src/Generated/Internal/ChangeTrackingDictionary.cs
create mode 100644 test/CadlRanchProjects/azure/example/basic/src/Generated/Internal/ChangeTrackingList.cs
create mode 100644 test/CadlRanchProjects/azure/example/basic/src/Generated/Internal/ModelSerializationExtensions.cs
create mode 100644 test/CadlRanchProjects/azure/example/basic/src/Generated/Internal/Optional.cs
create mode 100644 test/CadlRanchProjects/azure/example/basic/src/Generated/Internal/Utf8JsonRequestContent.cs
create mode 100644 test/CadlRanchProjects/azure/example/basic/src/Generated/Models/ActionRequest.Serialization.cs
create mode 100644 test/CadlRanchProjects/azure/example/basic/src/Generated/Models/ActionRequest.cs
create mode 100644 test/CadlRanchProjects/azure/example/basic/src/Generated/Models/ActionResponse.Serialization.cs
create mode 100644 test/CadlRanchProjects/azure/example/basic/src/Generated/Models/ActionResponse.cs
create mode 100644 test/CadlRanchProjects/azure/example/basic/src/Generated/Models/Enum.cs
create mode 100644 test/CadlRanchProjects/azure/example/basic/src/Generated/Models/Model.Serialization.cs
create mode 100644 test/CadlRanchProjects/azure/example/basic/src/Generated/Models/Model.cs
create mode 100644 test/CadlRanchProjects/azure/example/basic/src/Generated/SpecsAzureExampleBasicClientBuilderExtensions.cs
create mode 100644 test/CadlRanchProjects/azure/example/basic/src/Generated/SpecsAzureExampleBasicModelFactory.cs
create mode 100644 test/CadlRanchProjects/azure/example/basic/src/Properties/AssemblyInfo.cs
create mode 100644 test/CadlRanchProjects/azure/example/basic/src/_Specs_.Azure.Example.Basic.csproj
create mode 100644 test/CadlRanchProjects/azure/example/basic/tests/Generated/Samples/Samples_AzureExampleClient.cs
create mode 100644 test/CadlRanchProjects/azure/example/basic/tests/_Specs_.Azure.Example.Basic.Tests.csproj
create mode 100644 test/CadlRanchProjects/azure/example/basic/tspCodeModel.json
create mode 100644 test/CadlRanchProjects/azure/example/basic/tspconfig.yaml
diff --git a/eng/testProjects.json b/eng/testProjects.json
index 5211fcc1b5c..1af0e56bcb9 100644
--- a/eng/testProjects.json
+++ b/eng/testProjects.json
@@ -32,6 +32,7 @@
"azure/client-generator-core/access",
"azure/client-generator-core/flatten-property",
"azure/client-generator-core/usage",
+ "azure/example/basic",
"azure/resource-manager/common-properties",
"azure/special-headers/client-request-id",
"encode/bytes",
diff --git a/src/AutoRest.CSharp/Properties/launchSettings.json b/src/AutoRest.CSharp/Properties/launchSettings.json
index 3d483bbe1fc..e4686c415e6 100644
--- a/src/AutoRest.CSharp/Properties/launchSettings.json
+++ b/src/AutoRest.CSharp/Properties/launchSettings.json
@@ -652,6 +652,10 @@
"commandName": "Project",
"commandLineArgs": "--standalone $(SolutionDir)\\test\\CadlRanchProjects\\azure\\core\\traits\\src\\Generated -n"
},
+ "typespec-azure/example/basic": {
+ "commandName": "Project",
+ "commandLineArgs": "--standalone $(SolutionDir)\\test\\CadlRanchProjects\\azure\\example\\basic\\src\\Generated -n"
+ },
"typespec-azure/resource-manager/common-properties": {
"commandName": "Project",
"commandLineArgs": "--standalone $(SolutionDir)\\test\\CadlRanchProjects\\azure\\resource-manager\\common-properties\\src\\Generated -n"
diff --git a/test/CadlRanchProjects.Tests/azure-example-client-basic.cs b/test/CadlRanchProjects.Tests/azure-example-client-basic.cs
new file mode 100644
index 00000000000..f872bc7f22f
--- /dev/null
+++ b/test/CadlRanchProjects.Tests/azure-example-client-basic.cs
@@ -0,0 +1,38 @@
+using System;
+using System.Threading.Tasks;
+using _Specs_.Azure.Core.Page;
+using _Specs_.Azure.Example.Basic;
+using _Specs_.Azure.Example.Basic.Models;
+using AutoRest.TestServer.Tests.Infrastructure;
+using NUnit.Framework;
+
+namespace CadlRanchProjects.Tests
+{
+ public class azure_example_client_basic : CadlRanchTestBase
+ {
+ [Test]
+ public Task Azure_Example_Client_BasicAction() => Test(async (host) =>
+ {
+ var request = new ActionRequest("text")
+ {
+ ModelProperty = new Model()
+ {
+ EnumProperty = _Specs_.Azure.Example.Basic.Models.Enum.EnumValue1,
+ Int32Property = 1,
+ Float32Property = 1.5f,
+ },
+ ArrayProperty =
+ {
+ "item"
+ },
+ RecordProperty =
+ {
+ { "record", "value" }
+ }
+ };
+ var response = await new AzureExampleClient(host, null).BasicActionAsync("query", "header", request);
+ Assert.AreEqual(200, response.GetRawResponse().Status);
+ Assert.AreEqual("text", response.Value.StringProperty);
+ });
+ }
+}
diff --git a/test/CadlRanchProjects.Tests/resource-manager-resources.cs b/test/CadlRanchProjects.Tests/resource-manager-resources.cs
index 68d37582708..d8b55fb1e97 100644
--- a/test/CadlRanchProjects.Tests/resource-manager-resources.cs
+++ b/test/CadlRanchProjects.Tests/resource-manager-resources.cs
@@ -102,18 +102,24 @@ public Task Azure_ResourceManager_Resources_TopLevelTrackedResources_delete() =>
public Task Azure_ResourceManager_Resources_TopLevelTrackedResources_listByResourceGroup() => Test(async (host) =>
{
var id = ResourceGroupResource.CreateResourceIdentifier(Guid.Empty.ToString(), "test-rg");
- var response = await MgmtTestHelper.CreateArmClientWithMockAuth(host).GetResourceGroupResource(id).GetTopLevelTrackedResourceAsync("top");
- Assert.AreEqual(200, response.GetRawResponse().Status);
- Assert.AreEqual(true, response.Value.HasData);
- Assert.AreEqual("top", response.Value.Data.Name);
- Assert.AreEqual("Azure.ResourceManager.Resources/topLevelTrackedResources", response.Value.Data.ResourceType.ToString());
- Assert.AreEqual(AzureLocation.EastUS, response.Value.Data.Location);
- Assert.AreEqual("valid", response.Value.Data.Properties.Description);
- Assert.AreEqual(ProvisioningState.Succeeded, response.Value.Data.Properties.ProvisioningState);
- Assert.AreEqual("AzureSDK", response.Value.Data.SystemData.CreatedBy);
- Assert.AreEqual(CreatedByType.User, response.Value.Data.SystemData.CreatedByType);
- Assert.AreEqual("AzureSDK", response.Value.Data.SystemData.LastModifiedBy);
- Assert.AreEqual(CreatedByType.User, response.Value.Data.SystemData.LastModifiedByType);
+ var resourceGroup = MgmtTestHelper.CreateArmClientWithMockAuth(host).GetResourceGroupResource(id);
+ var collection = resourceGroup.GetTopLevelTrackedResources();
+ int count = 0;
+ await foreach (var resource in collection.GetAllAsync())
+ {
+ count++;
+ Assert.AreEqual(true, resource.HasData);
+ Assert.AreEqual("top", resource.Data.Name);
+ Assert.AreEqual("Azure.ResourceManager.Resources/topLevelTrackedResources", resource.Data.ResourceType.ToString());
+ Assert.AreEqual(AzureLocation.EastUS, resource.Data.Location);
+ Assert.AreEqual("valid", resource.Data.Properties.Description);
+ Assert.AreEqual(ProvisioningState.Succeeded, resource.Data.Properties.ProvisioningState);
+ Assert.AreEqual("AzureSDK", resource.Data.SystemData.CreatedBy);
+ Assert.AreEqual(CreatedByType.User, resource.Data.SystemData.CreatedByType);
+ Assert.AreEqual("AzureSDK", resource.Data.SystemData.LastModifiedBy);
+ Assert.AreEqual(CreatedByType.User, resource.Data.SystemData.LastModifiedByType);
+ }
+ Assert.AreEqual(1, count);
});
[Test]
@@ -213,16 +219,21 @@ public Task Azure_ResourceManager_Resources_NestedProxyResources_delete() => Tes
public Task Azure_ResourceManager_Resources_NestedProxyResources_listByTopLevelTrackedResource() => Test(async (host) =>
{
var id = TopLevelTrackedResource.CreateResourceIdentifier(Guid.Empty.ToString(), "test-rg", "top");
- var response = await MgmtTestHelper.CreateArmClientWithMockAuth(host).GetTopLevelTrackedResource(id).GetNestedProxyResourceAsync("nested");
- Assert.AreEqual(200, response.GetRawResponse().Status);
- Assert.AreEqual(true, response.Value.HasData);
- Assert.AreEqual("Azure.ResourceManager.Resources/topLevelTrackedResources/top/nestedProxyResources", response.Value.Data.ResourceType.ToString());
- Assert.AreEqual("valid", response.Value.Data.Properties.Description);
- Assert.AreEqual(ProvisioningState.Succeeded, response.Value.Data.Properties.ProvisioningState);
- Assert.AreEqual("AzureSDK", response.Value.Data.SystemData.CreatedBy);
- Assert.AreEqual(CreatedByType.User, response.Value.Data.SystemData.CreatedByType);
- Assert.AreEqual("AzureSDK", response.Value.Data.SystemData.LastModifiedBy);
- Assert.AreEqual(CreatedByType.User, response.Value.Data.SystemData.LastModifiedByType);
+ var collection = MgmtTestHelper.CreateArmClientWithMockAuth(host).GetTopLevelTrackedResource(id).GetNestedProxyResources();
+ int count = 0;
+ await foreach (var resource in collection.GetAllAsync())
+ {
+ count++;
+ Assert.AreEqual(true, resource.HasData);
+ Assert.AreEqual("Azure.ResourceManager.Resources/topLevelTrackedResources/top/nestedProxyResources", resource.Data.ResourceType.ToString());
+ Assert.AreEqual("valid", resource.Data.Properties.Description);
+ Assert.AreEqual(ProvisioningState.Succeeded, resource.Data.Properties.ProvisioningState);
+ Assert.AreEqual("AzureSDK", resource.Data.SystemData.CreatedBy);
+ Assert.AreEqual(CreatedByType.User, resource.Data.SystemData.CreatedByType);
+ Assert.AreEqual("AzureSDK", resource.Data.SystemData.LastModifiedBy);
+ Assert.AreEqual(CreatedByType.User, resource.Data.SystemData.LastModifiedByType);
+ }
+ Assert.AreEqual(1, count);
});
[Test]
diff --git a/test/CadlRanchProjects/azure/example/basic/Configuration.json b/test/CadlRanchProjects/azure/example/basic/Configuration.json
new file mode 100644
index 00000000000..21f5769da04
--- /dev/null
+++ b/test/CadlRanchProjects/azure/example/basic/Configuration.json
@@ -0,0 +1,12 @@
+{
+ "output-folder": ".",
+ "namespace": "_Specs_.Azure.Example.Basic",
+ "library-name": "_Specs_.Azure.Example.Basic",
+ "flavor": "azure",
+ "use-model-reader-writer": true,
+ "shared-source-folders": [
+ "../../../../../../../artifacts/bin/AutoRest.CSharp/Debug/net8.0/Generator.Shared",
+ "../../../../../../../artifacts/bin/AutoRest.CSharp/Debug/net8.0/Azure.Core.Shared"
+ ],
+ "examples-dir": "..\\..\\..\\..\\..\\node_modules\\@azure-tools\\cadl-ranch-specs\\http\\azure\\example\\basic\\examples"
+}
diff --git a/test/CadlRanchProjects/azure/example/basic/_Specs_.Azure.Example.Basic.sln b/test/CadlRanchProjects/azure/example/basic/_Specs_.Azure.Example.Basic.sln
new file mode 100644
index 00000000000..162c8af0f75
--- /dev/null
+++ b/test/CadlRanchProjects/azure/example/basic/_Specs_.Azure.Example.Basic.sln
@@ -0,0 +1,50 @@
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 16
+VisualStudioVersion = 16.0.29709.97
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "_Specs_.Azure.Example.Basic", "src\_Specs_.Azure.Example.Basic.csproj", "{28FF4005-4467-4E36-92E7-DEA27DEB1519}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "_Specs_.Azure.Example.Basic.Tests", "tests\_Specs_.Azure.Example.Basic.Tests.csproj", "{1F1CD1D4-9932-4B73-99D8-C252A67D4B46}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {B0C276D1-2930-4887-B29A-D1A33E7009A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {B0C276D1-2930-4887-B29A-D1A33E7009A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {B0C276D1-2930-4887-B29A-D1A33E7009A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {B0C276D1-2930-4887-B29A-D1A33E7009A2}.Release|Any CPU.Build.0 = Release|Any CPU
+ {8E9A77AC-792A-4432-8320-ACFD46730401}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {8E9A77AC-792A-4432-8320-ACFD46730401}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {8E9A77AC-792A-4432-8320-ACFD46730401}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {8E9A77AC-792A-4432-8320-ACFD46730401}.Release|Any CPU.Build.0 = Release|Any CPU
+ {A4241C1F-A53D-474C-9E4E-075054407E74}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {A4241C1F-A53D-474C-9E4E-075054407E74}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {A4241C1F-A53D-474C-9E4E-075054407E74}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {A4241C1F-A53D-474C-9E4E-075054407E74}.Release|Any CPU.Build.0 = Release|Any CPU
+ {FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Release|Any CPU.Build.0 = Release|Any CPU
+ {85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Release|Any CPU.Build.0 = Release|Any CPU
+ {28FF4005-4467-4E36-92E7-DEA27DEB1519}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {28FF4005-4467-4E36-92E7-DEA27DEB1519}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {28FF4005-4467-4E36-92E7-DEA27DEB1519}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {28FF4005-4467-4E36-92E7-DEA27DEB1519}.Release|Any CPU.Build.0 = Release|Any CPU
+ {1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {A97F4B90-2591-4689-B1F8-5F21FE6D6CAE}
+ EndGlobalSection
+EndGlobal
diff --git a/test/CadlRanchProjects/azure/example/basic/src/Generated/AzureExampleClient.cs b/test/CadlRanchProjects/azure/example/basic/src/Generated/AzureExampleClient.cs
new file mode 100644
index 00000000000..c7660ef8d0c
--- /dev/null
+++ b/test/CadlRanchProjects/azure/example/basic/src/Generated/AzureExampleClient.cs
@@ -0,0 +1,208 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+//
+
+#nullable disable
+
+using System;
+using System.Threading;
+using System.Threading.Tasks;
+using Azure;
+using Azure.Core;
+using Azure.Core.Pipeline;
+using _Specs_.Azure.Example.Basic.Models;
+
+namespace _Specs_.Azure.Example.Basic
+{
+ // Data plane generated client.
+ /// The AzureExample service client.
+ public partial class AzureExampleClient
+ {
+ private readonly HttpPipeline _pipeline;
+ private readonly Uri _endpoint;
+ private readonly string _apiVersion;
+
+ /// The ClientDiagnostics is used to provide tracing support for the client library.
+ internal ClientDiagnostics ClientDiagnostics { get; }
+
+ /// The HTTP pipeline for sending and receiving REST requests and responses.
+ public virtual HttpPipeline Pipeline => _pipeline;
+
+ /// Initializes a new instance of AzureExampleClient.
+ public AzureExampleClient() : this(new Uri("http://localhost:3000"), new AzureExampleClientOptions())
+ {
+ }
+
+ /// Initializes a new instance of AzureExampleClient.
+ /// Service host.
+ /// The options for configuring the client.
+ /// is null.
+ public AzureExampleClient(Uri endpoint, AzureExampleClientOptions options)
+ {
+ Argument.AssertNotNull(endpoint, nameof(endpoint));
+ options ??= new AzureExampleClientOptions();
+
+ ClientDiagnostics = new ClientDiagnostics(options, true);
+ _pipeline = HttpPipelineBuilder.Build(options, Array.Empty(), Array.Empty(), new ResponseClassifier());
+ _endpoint = endpoint;
+ _apiVersion = options.Version;
+ }
+
+ /// Basic action.
+ /// The to use.
+ /// The to use.
+ /// The to use.
+ /// The cancellation token to use.
+ /// , or is null.
+ ///
+ public virtual async Task> BasicActionAsync(string queryParam, string headerParam, ActionRequest body, CancellationToken cancellationToken = default)
+ {
+ Argument.AssertNotNull(queryParam, nameof(queryParam));
+ Argument.AssertNotNull(headerParam, nameof(headerParam));
+ Argument.AssertNotNull(body, nameof(body));
+
+ using RequestContent content = body.ToRequestContent();
+ RequestContext context = FromCancellationToken(cancellationToken);
+ Response response = await BasicActionAsync(queryParam, headerParam, content, context).ConfigureAwait(false);
+ return Response.FromValue(ActionResponse.FromResponse(response), response);
+ }
+
+ /// Basic action.
+ /// The to use.
+ /// The to use.
+ /// The to use.
+ /// The cancellation token to use.
+ /// , or is null.
+ ///
+ public virtual Response BasicAction(string queryParam, string headerParam, ActionRequest body, CancellationToken cancellationToken = default)
+ {
+ Argument.AssertNotNull(queryParam, nameof(queryParam));
+ Argument.AssertNotNull(headerParam, nameof(headerParam));
+ Argument.AssertNotNull(body, nameof(body));
+
+ using RequestContent content = body.ToRequestContent();
+ RequestContext context = FromCancellationToken(cancellationToken);
+ Response response = BasicAction(queryParam, headerParam, content, context);
+ return Response.FromValue(ActionResponse.FromResponse(response), response);
+ }
+
+ ///
+ /// [Protocol Method] Basic action.
+ ///
+ /// -
+ ///
+ /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
+ ///
+ ///
+ /// -
+ ///
+ /// Please try the simpler convenience overload with strongly typed models first.
+ ///
+ ///
+ ///
+ ///
+ /// The to use.
+ /// The to use.
+ /// The content to send as the body of the request.
+ /// The request context, which can override default behaviors of the client pipeline on a per-call basis.
+ /// , or is null.
+ /// Service returned a non-success status code.
+ /// The response returned from the service.
+ ///
+ public virtual async Task BasicActionAsync(string queryParam, string headerParam, RequestContent content, RequestContext context = null)
+ {
+ Argument.AssertNotNull(queryParam, nameof(queryParam));
+ Argument.AssertNotNull(headerParam, nameof(headerParam));
+ Argument.AssertNotNull(content, nameof(content));
+
+ using var scope = ClientDiagnostics.CreateScope("AzureExampleClient.BasicAction");
+ scope.Start();
+ try
+ {
+ using HttpMessage message = CreateBasicActionRequest(queryParam, headerParam, content, context);
+ return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false);
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ ///
+ /// [Protocol Method] Basic action.
+ ///
+ /// -
+ ///
+ /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
+ ///
+ ///
+ /// -
+ ///
+ /// Please try the simpler convenience overload with strongly typed models first.
+ ///
+ ///
+ ///
+ ///
+ /// The to use.
+ /// The to use.
+ /// The content to send as the body of the request.
+ /// The request context, which can override default behaviors of the client pipeline on a per-call basis.
+ /// , or is null.
+ /// Service returned a non-success status code.
+ /// The response returned from the service.
+ ///
+ public virtual Response BasicAction(string queryParam, string headerParam, RequestContent content, RequestContext context = null)
+ {
+ Argument.AssertNotNull(queryParam, nameof(queryParam));
+ Argument.AssertNotNull(headerParam, nameof(headerParam));
+ Argument.AssertNotNull(content, nameof(content));
+
+ using var scope = ClientDiagnostics.CreateScope("AzureExampleClient.BasicAction");
+ scope.Start();
+ try
+ {
+ using HttpMessage message = CreateBasicActionRequest(queryParam, headerParam, content, context);
+ return _pipeline.ProcessMessage(message, context);
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ internal HttpMessage CreateBasicActionRequest(string queryParam, string headerParam, RequestContent content, RequestContext context)
+ {
+ var message = _pipeline.CreateMessage(context, ResponseClassifier200);
+ var request = message.Request;
+ request.Method = RequestMethod.Post;
+ var uri = new RawRequestUriBuilder();
+ uri.Reset(_endpoint);
+ uri.AppendPath("/azure/example/basic/basic", false);
+ uri.AppendQuery("query-param", queryParam, true);
+ uri.AppendQuery("api-version", _apiVersion, true);
+ request.Uri = uri;
+ request.Headers.Add("header-param", headerParam);
+ request.Headers.Add("Accept", "application/json");
+ request.Headers.Add("Content-Type", "application/json");
+ request.Content = content;
+ return message;
+ }
+
+ private static RequestContext DefaultRequestContext = new RequestContext();
+ internal static RequestContext FromCancellationToken(CancellationToken cancellationToken = default)
+ {
+ if (!cancellationToken.CanBeCanceled)
+ {
+ return DefaultRequestContext;
+ }
+
+ return new RequestContext() { CancellationToken = cancellationToken };
+ }
+
+ private static ResponseClassifier _responseClassifier200;
+ private static ResponseClassifier ResponseClassifier200 => _responseClassifier200 ??= new StatusCodeClassifier(stackalloc ushort[] { 200 });
+ }
+}
diff --git a/test/CadlRanchProjects/azure/example/basic/src/Generated/AzureExampleClientOptions.cs b/test/CadlRanchProjects/azure/example/basic/src/Generated/AzureExampleClientOptions.cs
new file mode 100644
index 00000000000..457942e8443
--- /dev/null
+++ b/test/CadlRanchProjects/azure/example/basic/src/Generated/AzureExampleClientOptions.cs
@@ -0,0 +1,37 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+//
+
+#nullable disable
+
+using System;
+using Azure.Core;
+
+namespace _Specs_.Azure.Example.Basic
+{
+ /// Client options for AzureExampleClient.
+ public partial class AzureExampleClientOptions : ClientOptions
+ {
+ private const ServiceVersion LatestVersion = ServiceVersion.V2022_12_01_Preview;
+
+ /// The version of the service to use.
+ public enum ServiceVersion
+ {
+ /// Service version "2022-12-01-preview".
+ V2022_12_01_Preview = 1,
+ }
+
+ internal string Version { get; }
+
+ /// Initializes new instance of AzureExampleClientOptions.
+ public AzureExampleClientOptions(ServiceVersion version = LatestVersion)
+ {
+ Version = version switch
+ {
+ ServiceVersion.V2022_12_01_Preview => "2022-12-01-preview",
+ _ => throw new NotSupportedException()
+ };
+ }
+ }
+}
diff --git a/test/CadlRanchProjects/azure/example/basic/src/Generated/Docs/AzureExampleClient.xml b/test/CadlRanchProjects/azure/example/basic/src/Generated/Docs/AzureExampleClient.xml
new file mode 100644
index 00000000000..da751c75dee
--- /dev/null
+++ b/test/CadlRanchProjects/azure/example/basic/src/Generated/Docs/AzureExampleClient.xml
@@ -0,0 +1,111 @@
+
+
+
+
+
+This sample shows how to call BasicActionAsync.
+ response = await client.BasicActionAsync("query", "header", body);
+]]>
+
+
+
+This sample shows how to call BasicAction.
+ response = client.BasicAction("query", "header", body);
+]]>
+
+
+
+This sample shows how to call BasicActionAsync and parse the result.
+
+
+
+
+This sample shows how to call BasicAction and parse the result.
+
+
+
+
\ No newline at end of file
diff --git a/test/CadlRanchProjects/azure/example/basic/src/Generated/Internal/Argument.cs b/test/CadlRanchProjects/azure/example/basic/src/Generated/Internal/Argument.cs
new file mode 100644
index 00000000000..01a4c8fce3e
--- /dev/null
+++ b/test/CadlRanchProjects/azure/example/basic/src/Generated/Internal/Argument.cs
@@ -0,0 +1,129 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+//
+
+#nullable disable
+
+using System;
+using System.Collections;
+using System.Collections.Generic;
+
+namespace _Specs_.Azure.Example.Basic
+{
+ internal static class Argument
+ {
+ public static void AssertNotNull(T value, string name)
+ {
+ if (value is null)
+ {
+ throw new ArgumentNullException(name);
+ }
+ }
+
+ public static void AssertNotNull(T? value, string name)
+ where T : struct
+ {
+ if (!value.HasValue)
+ {
+ throw new ArgumentNullException(name);
+ }
+ }
+
+ public static void AssertNotNullOrEmpty(IEnumerable value, string name)
+ {
+ if (value is null)
+ {
+ throw new ArgumentNullException(name);
+ }
+ if (value is ICollection collectionOfT && collectionOfT.Count == 0)
+ {
+ throw new ArgumentException("Value cannot be an empty collection.", name);
+ }
+ if (value is ICollection collection && collection.Count == 0)
+ {
+ throw new ArgumentException("Value cannot be an empty collection.", name);
+ }
+ using IEnumerator e = value.GetEnumerator();
+ if (!e.MoveNext())
+ {
+ throw new ArgumentException("Value cannot be an empty collection.", name);
+ }
+ }
+
+ public static void AssertNotNullOrEmpty(string value, string name)
+ {
+ if (value is null)
+ {
+ throw new ArgumentNullException(name);
+ }
+ if (value.Length == 0)
+ {
+ throw new ArgumentException("Value cannot be an empty string.", name);
+ }
+ }
+
+ public static void AssertNotNullOrWhiteSpace(string value, string name)
+ {
+ if (value is null)
+ {
+ throw new ArgumentNullException(name);
+ }
+ if (string.IsNullOrWhiteSpace(value))
+ {
+ throw new ArgumentException("Value cannot be empty or contain only white-space characters.", name);
+ }
+ }
+
+ public static void AssertNotDefault(ref T value, string name)
+ where T : struct, IEquatable
+ {
+ if (value.Equals(default))
+ {
+ throw new ArgumentException("Value cannot be empty.", name);
+ }
+ }
+
+ public static void AssertInRange(T value, T minimum, T maximum, string name)
+ where T : notnull, IComparable
+ {
+ if (minimum.CompareTo(value) > 0)
+ {
+ throw new ArgumentOutOfRangeException(name, "Value is less than the minimum allowed.");
+ }
+ if (maximum.CompareTo(value) < 0)
+ {
+ throw new ArgumentOutOfRangeException(name, "Value is greater than the maximum allowed.");
+ }
+ }
+
+ public static void AssertEnumDefined(Type enumType, object value, string name)
+ {
+ if (!Enum.IsDefined(enumType, value))
+ {
+ throw new ArgumentException($"Value not defined for {enumType.FullName}.", name);
+ }
+ }
+
+ public static T CheckNotNull(T value, string name)
+ where T : class
+ {
+ AssertNotNull(value, name);
+ return value;
+ }
+
+ public static string CheckNotNullOrEmpty(string value, string name)
+ {
+ AssertNotNullOrEmpty(value, name);
+ return value;
+ }
+
+ public static void AssertNull(T value, string name, string message = null)
+ {
+ if (value != null)
+ {
+ throw new ArgumentException(message ?? "Value must be null.", name);
+ }
+ }
+ }
+}
diff --git a/test/CadlRanchProjects/azure/example/basic/src/Generated/Internal/ChangeTrackingDictionary.cs b/test/CadlRanchProjects/azure/example/basic/src/Generated/Internal/ChangeTrackingDictionary.cs
new file mode 100644
index 00000000000..f66f9cd0389
--- /dev/null
+++ b/test/CadlRanchProjects/azure/example/basic/src/Generated/Internal/ChangeTrackingDictionary.cs
@@ -0,0 +1,167 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+//
+
+#nullable disable
+
+using System;
+using System.Collections;
+using System.Collections.Generic;
+
+namespace _Specs_.Azure.Example.Basic
+{
+ internal class ChangeTrackingDictionary : IDictionary, IReadOnlyDictionary where TKey : notnull
+ {
+ private IDictionary _innerDictionary;
+
+ public ChangeTrackingDictionary()
+ {
+ }
+
+ public ChangeTrackingDictionary(IDictionary dictionary)
+ {
+ if (dictionary == null)
+ {
+ return;
+ }
+ _innerDictionary = new Dictionary(dictionary);
+ }
+
+ public ChangeTrackingDictionary(IReadOnlyDictionary dictionary)
+ {
+ if (dictionary == null)
+ {
+ return;
+ }
+ _innerDictionary = new Dictionary();
+ foreach (var pair in dictionary)
+ {
+ _innerDictionary.Add(pair);
+ }
+ }
+
+ public bool IsUndefined => _innerDictionary == null;
+
+ public int Count => IsUndefined ? 0 : EnsureDictionary().Count;
+
+ public bool IsReadOnly => IsUndefined ? false : EnsureDictionary().IsReadOnly;
+
+ public ICollection Keys => IsUndefined ? Array.Empty() : EnsureDictionary().Keys;
+
+ public ICollection Values => IsUndefined ? Array.Empty() : EnsureDictionary().Values;
+
+ public TValue this[TKey key]
+ {
+ get
+ {
+ if (IsUndefined)
+ {
+ throw new KeyNotFoundException(nameof(key));
+ }
+ return EnsureDictionary()[key];
+ }
+ set
+ {
+ EnsureDictionary()[key] = value;
+ }
+ }
+
+ IEnumerable IReadOnlyDictionary.Keys => Keys;
+
+ IEnumerable IReadOnlyDictionary.Values => Values;
+
+ public IEnumerator> GetEnumerator()
+ {
+ if (IsUndefined)
+ {
+ IEnumerator> enumerateEmpty()
+ {
+ yield break;
+ }
+ return enumerateEmpty();
+ }
+ return EnsureDictionary().GetEnumerator();
+ }
+
+ IEnumerator IEnumerable.GetEnumerator()
+ {
+ return GetEnumerator();
+ }
+
+ public void Add(KeyValuePair item)
+ {
+ EnsureDictionary().Add(item);
+ }
+
+ public void Clear()
+ {
+ EnsureDictionary().Clear();
+ }
+
+ public bool Contains(KeyValuePair item)
+ {
+ if (IsUndefined)
+ {
+ return false;
+ }
+ return EnsureDictionary().Contains(item);
+ }
+
+ public void CopyTo(KeyValuePair[] array, int index)
+ {
+ if (IsUndefined)
+ {
+ return;
+ }
+ EnsureDictionary().CopyTo(array, index);
+ }
+
+ public bool Remove(KeyValuePair item)
+ {
+ if (IsUndefined)
+ {
+ return false;
+ }
+ return EnsureDictionary().Remove(item);
+ }
+
+ public void Add(TKey key, TValue value)
+ {
+ EnsureDictionary().Add(key, value);
+ }
+
+ public bool ContainsKey(TKey key)
+ {
+ if (IsUndefined)
+ {
+ return false;
+ }
+ return EnsureDictionary().ContainsKey(key);
+ }
+
+ public bool Remove(TKey key)
+ {
+ if (IsUndefined)
+ {
+ return false;
+ }
+ return EnsureDictionary().Remove(key);
+ }
+
+ public bool TryGetValue(TKey key, out TValue value)
+ {
+ if (IsUndefined)
+ {
+ value = default;
+ return false;
+ }
+ return EnsureDictionary().TryGetValue(key, out value);
+ }
+
+ public IDictionary EnsureDictionary()
+ {
+ return _innerDictionary ??= new Dictionary();
+ }
+ }
+}
diff --git a/test/CadlRanchProjects/azure/example/basic/src/Generated/Internal/ChangeTrackingList.cs b/test/CadlRanchProjects/azure/example/basic/src/Generated/Internal/ChangeTrackingList.cs
new file mode 100644
index 00000000000..7f0a3bc417f
--- /dev/null
+++ b/test/CadlRanchProjects/azure/example/basic/src/Generated/Internal/ChangeTrackingList.cs
@@ -0,0 +1,153 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+//
+
+#nullable disable
+
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+
+namespace _Specs_.Azure.Example.Basic
+{
+ internal class ChangeTrackingList : IList, IReadOnlyList
+ {
+ private IList _innerList;
+
+ public ChangeTrackingList()
+ {
+ }
+
+ public ChangeTrackingList(IList innerList)
+ {
+ if (innerList != null)
+ {
+ _innerList = innerList;
+ }
+ }
+
+ public ChangeTrackingList(IReadOnlyList innerList)
+ {
+ if (innerList != null)
+ {
+ _innerList = innerList.ToList();
+ }
+ }
+
+ public bool IsUndefined => _innerList == null;
+
+ public int Count => IsUndefined ? 0 : EnsureList().Count;
+
+ public bool IsReadOnly => IsUndefined ? false : EnsureList().IsReadOnly;
+
+ public T this[int index]
+ {
+ get
+ {
+ if (IsUndefined)
+ {
+ throw new ArgumentOutOfRangeException(nameof(index));
+ }
+ return EnsureList()[index];
+ }
+ set
+ {
+ if (IsUndefined)
+ {
+ throw new ArgumentOutOfRangeException(nameof(index));
+ }
+ EnsureList()[index] = value;
+ }
+ }
+
+ public void Reset()
+ {
+ _innerList = null;
+ }
+
+ public IEnumerator GetEnumerator()
+ {
+ if (IsUndefined)
+ {
+ IEnumerator enumerateEmpty()
+ {
+ yield break;
+ }
+ return enumerateEmpty();
+ }
+ return EnsureList().GetEnumerator();
+ }
+
+ IEnumerator IEnumerable.GetEnumerator()
+ {
+ return GetEnumerator();
+ }
+
+ public void Add(T item)
+ {
+ EnsureList().Add(item);
+ }
+
+ public void Clear()
+ {
+ EnsureList().Clear();
+ }
+
+ public bool Contains(T item)
+ {
+ if (IsUndefined)
+ {
+ return false;
+ }
+ return EnsureList().Contains(item);
+ }
+
+ public void CopyTo(T[] array, int arrayIndex)
+ {
+ if (IsUndefined)
+ {
+ return;
+ }
+ EnsureList().CopyTo(array, arrayIndex);
+ }
+
+ public bool Remove(T item)
+ {
+ if (IsUndefined)
+ {
+ return false;
+ }
+ return EnsureList().Remove(item);
+ }
+
+ public int IndexOf(T item)
+ {
+ if (IsUndefined)
+ {
+ return -1;
+ }
+ return EnsureList().IndexOf(item);
+ }
+
+ public void Insert(int index, T item)
+ {
+ EnsureList().Insert(index, item);
+ }
+
+ public void RemoveAt(int index)
+ {
+ if (IsUndefined)
+ {
+ throw new ArgumentOutOfRangeException(nameof(index));
+ }
+ EnsureList().RemoveAt(index);
+ }
+
+ public IList EnsureList()
+ {
+ return _innerList ??= new List();
+ }
+ }
+}
diff --git a/test/CadlRanchProjects/azure/example/basic/src/Generated/Internal/ModelSerializationExtensions.cs b/test/CadlRanchProjects/azure/example/basic/src/Generated/Internal/ModelSerializationExtensions.cs
new file mode 100644
index 00000000000..2dcf0fa2691
--- /dev/null
+++ b/test/CadlRanchProjects/azure/example/basic/src/Generated/Internal/ModelSerializationExtensions.cs
@@ -0,0 +1,398 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+//
+
+#nullable disable
+
+using System;
+using System.ClientModel.Primitives;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Globalization;
+using System.Text.Json;
+using System.Xml;
+using Azure.Core;
+
+namespace _Specs_.Azure.Example.Basic
+{
+ internal static class ModelSerializationExtensions
+ {
+ internal static readonly ModelReaderWriterOptions WireOptions = new ModelReaderWriterOptions("W");
+
+ public static object GetObject(this JsonElement element)
+ {
+ switch (element.ValueKind)
+ {
+ case JsonValueKind.String:
+ return element.GetString();
+ case JsonValueKind.Number:
+ if (element.TryGetInt32(out int intValue))
+ {
+ return intValue;
+ }
+ if (element.TryGetInt64(out long longValue))
+ {
+ return longValue;
+ }
+ return element.GetDouble();
+ case JsonValueKind.True:
+ return true;
+ case JsonValueKind.False:
+ return false;
+ case JsonValueKind.Undefined:
+ case JsonValueKind.Null:
+ return null;
+ case JsonValueKind.Object:
+ var dictionary = new Dictionary();
+ foreach (var jsonProperty in element.EnumerateObject())
+ {
+ dictionary.Add(jsonProperty.Name, jsonProperty.Value.GetObject());
+ }
+ return dictionary;
+ case JsonValueKind.Array:
+ var list = new List