diff --git a/eng/testProjects.json b/eng/testProjects.json
index ef671d9400f..9ff944a4f35 100644
--- a/eng/testProjects.json
+++ b/eng/testProjects.json
@@ -36,6 +36,7 @@
"encode/bytes",
"encode/datetime",
"encode/duration",
+ "encode/numeric",
"payload/content-negotiation",
"payload/media-type",
"payload/multipart",
diff --git a/src/AutoRest.CSharp/Properties/launchSettings.json b/src/AutoRest.CSharp/Properties/launchSettings.json
index 6a8ded8c0a8..4276f589ef5 100644
--- a/src/AutoRest.CSharp/Properties/launchSettings.json
+++ b/src/AutoRest.CSharp/Properties/launchSettings.json
@@ -696,6 +696,10 @@
"commandName": "Project",
"commandLineArgs": "--standalone $(SolutionDir)\\test\\CadlRanchProjects\\encode\\duration\\src\\Generated -n"
},
+ "typespec-encode/numeric": {
+ "commandName": "Project",
+ "commandLineArgs": "--standalone $(SolutionDir)\\test\\CadlRanchProjects\\encode\\numeric\\src\\Generated -n"
+ },
"typespec-nonAzure-authentication/api-key": {
"commandName": "Project",
"commandLineArgs": "--standalone $(SolutionDir)\\test\\CadlRanchProjectsNonAzure\\authentication\\api-key\\src\\Generated -n"
diff --git a/test/CadlRanchProjects.Tests/azure-core-basic.cs b/test/CadlRanchProjects.Tests/azure-core-basic.cs
index 2a66ab8d0aa..dfe0092005b 100644
--- a/test/CadlRanchProjects.Tests/azure-core-basic.cs
+++ b/test/CadlRanchProjects.Tests/azure-core-basic.cs
@@ -81,6 +81,17 @@ public Task Azure_Core_Basic_export() => Test(async (host) =>
Assert.AreEqual("Madge", response.Name);
});
+ [Test]
+ public Task Azure_Core_Basic_exoportAllUsers() => Test(async (host) =>
+ {
+ var response = await new BasicClient(host, null).ExportAllUsersAsync("json");
+ Assert.AreEqual(1, response.Value.Users.First().Id);
+ Assert.AreEqual("Madge", response.Value.Users.First().Name);
+ Assert.AreEqual(2, response.Value.Users.Last().Id);
+ Assert.AreEqual("John", response.Value.Users.Last().Name);
+ Assert.AreEqual(2, response.Value.Users.Count());
+ });
+
[Test]
public void Azure_Core_basic_RenameGetMethod()
{
diff --git a/test/CadlRanchProjects.Tests/azure-tcgc-usage.cs b/test/CadlRanchProjects.Tests/azure-tcgc-usage.cs
index 8da0d1cc7fa..f2802a9ce66 100644
--- a/test/CadlRanchProjects.Tests/azure-tcgc-usage.cs
+++ b/test/CadlRanchProjects.Tests/azure-tcgc-usage.cs
@@ -19,11 +19,17 @@ public Task Azure_ClientGenerator_Core_Usage_ModelInOperation() => Test(async (h
var response2 = await new UsageClient(host, null).GetModelInOperationClient().OutputToInputOutputAsync();
Assert.AreEqual("Madge", response2.Value.Name);
+ var response3 = await new UsageClient(host, null).GetModelInOperationClient().ModelInReadOnlyPropertyAsync(new RoundTripModel());
+ Assert.AreEqual("Madge", response3.Value.Result.Name);
+
Assert.IsNotNull(typeof(InputModel).GetMethod("FromResponse", BindingFlags.Static | BindingFlags.NonPublic));
Assert.IsNotNull(typeof(InputModel).GetMethod("ToRequestContent", BindingFlags.Instance | BindingFlags.NonPublic));
Assert.IsNotNull(typeof(OutputModel).GetMethod("FromResponse", BindingFlags.Static | BindingFlags.NonPublic));
Assert.IsNotNull(typeof(OutputModel).GetMethod("ToRequestContent", BindingFlags.Instance | BindingFlags.NonPublic));
+
+ Assert.IsNotNull(typeof(RoundTripModel).GetMethod("FromResponse", BindingFlags.Static | BindingFlags.NonPublic));
+ Assert.IsNotNull(typeof(RoundTripModel).GetMethod("ToRequestContent", BindingFlags.Instance | BindingFlags.NonPublic));
});
}
}
diff --git a/test/CadlRanchProjects.Tests/encode-numeric.cs b/test/CadlRanchProjects.Tests/encode-numeric.cs
new file mode 100644
index 00000000000..eb911315491
--- /dev/null
+++ b/test/CadlRanchProjects.Tests/encode-numeric.cs
@@ -0,0 +1,43 @@
+using System;
+using System.Text.Json;
+using System.Threading.Tasks;
+using AutoRest.TestServer.Tests.Infrastructure;
+using Azure;
+using Azure.Core;
+using Encode.Numeric;
+using Encode.Numeric.Models;
+using NUnit.Framework;
+
+
+namespace CadlRanchProjects.Tests
+{
+ public class encode_numeric : CadlRanchTestBase
+ {
+ [Test]
+ public Task Encode_Numeric_Property_safeintAsString() => Test(async (host) =>
+ {
+ var response = await new NumericClient(host, null).GetPropertyClient().SafeintAsStringAsync(new SafeintAsStringProperty(10000000000));
+ Assert.AreEqual(200, response.GetRawResponse().Status);
+ Assert.AreEqual(10000000000, response.Value.Value);
+ });
+
+ [Test]
+ public Task Encode_Numeric_Property_uint32AsStringOptional() => Test(async (host) =>
+ {
+ var response = await new NumericClient(host, null).GetPropertyClient().Uint32AsStringOptionalAsync(new Uint32AsStringProperty()
+ {
+ Value = "1"
+ });
+ Assert.AreEqual(200, response.GetRawResponse().Status);
+ Assert.AreEqual("1", response.Value.Value);
+ });
+
+ [Test]
+ public Task Encode_Numeric_Property_uint8AsString() => Test(async (host) =>
+ {
+ var response = await new NumericClient(host, null).GetPropertyClient().Uint8AsStringAsync(new Uint8AsStringProperty(255));
+ Assert.AreEqual(200, response.GetRawResponse().Status);
+ Assert.AreEqual(255, response.Value.Value);
+ });
+ }
+}
diff --git a/test/CadlRanchProjects.Tests/resource-manager-models-resources.cs b/test/CadlRanchProjects.Tests/resource-manager-models-resources.cs
index e0b09660385..3b1a4ff5b5f 100644
--- a/test/CadlRanchProjects.Tests/resource-manager-models-resources.cs
+++ b/test/CadlRanchProjects.Tests/resource-manager-models-resources.cs
@@ -32,6 +32,14 @@ public Task Azure_ResourceManager_Models_Resources_TopLevelTrackedResources_get(
Assert.AreEqual(CreatedByType.User, response.Value.Data.SystemData.LastModifiedByType);
});
+ [Test]
+ public Task Azure_ResourceManager_Models_Resources_TopLevelTrackedResources_actionSync() => Test(async (host) =>
+ {
+ var id = TopLevelTrackedResource.CreateResourceIdentifier(Guid.Empty.ToString(), "test-rg", "top");
+ var response = await MgmtTestHelper.CreateArmClientWithMockAuth(host).GetTopLevelTrackedResource(id).ActionSyncAsync(new NotificationDetails("Resource action at top level.", true));
+ Assert.AreEqual(204, response.Status);
+ });
+
[Test]
[Ignore("https://github.com/Azure/autorest.csharp/issues/4876")]
public Task Azure_ResourceManager_Models_Resources_TopLevelTrackedResources_createOrReplace() => Test(async (host) =>
@@ -218,5 +226,69 @@ public Task Azure_ResourceManager_Models_Resources_NestedProxyResources_listByTo
Assert.AreEqual("AzureSDK", response.Value.Data.SystemData.LastModifiedBy);
Assert.AreEqual(CreatedByType.User, response.Value.Data.SystemData.LastModifiedByType);
});
+
+ [Test]
+ [Ignore("https://github.com/Azure/autorest.csharp/issues/4876")]
+ public Task Azure_ResourceManager_Models_Resources_SingletonTrackedResource_createOrUpdate() => Test(async (host) =>
+ {
+ var id = SingletonTrackedResource.CreateResourceIdentifier(Guid.Empty.ToString(), "test-rg");
+ var data = new SingletonTrackedResourceData(AzureLocation.EastUS)
+ {
+ Properties = new SingletonTrackedResourceProperties()
+ {
+ Description = "valid"
+ }
+ };
+ var response = await MgmtTestHelper.CreateArmClientWithMockAuth(host).GetSingletonTrackedResource(id).CreateOrUpdateAsync(WaitUntil.Completed, data);
+ Assert.AreEqual(200, response.GetRawResponse().Status);
+ Assert.AreEqual(true, response.Value.HasData);
+ Assert.AreEqual("Azure.ResourceManager.Models.Resources/singletonTrackedResources", 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);
+ });
+
+ [Test]
+ [Ignore("https://github.com/Azure/autorest.csharp/issues/4876")]
+ public Task Azure_ResourceManager_Models_Resources_SingletonTrackedResource_update() => Test(async (host) =>
+ {
+ var id = SingletonTrackedResource.CreateResourceIdentifier(Guid.Empty.ToString(), "test-rg");
+ var data = new SingletonTrackedResourceData(AzureLocation.EastUS2)
+ {
+ Properties = new SingletonTrackedResourceProperties()
+ {
+ Description = "valid2"
+ }
+ };
+ var response = await MgmtTestHelper.CreateArmClientWithMockAuth(host).GetSingletonTrackedResource(id).UpdateAsync(data);
+ Assert.AreEqual(200, response.GetRawResponse().Status);
+ Assert.AreEqual(true, response.Value.HasData);
+ Assert.AreEqual("Azure.ResourceManager.Models.Resources/singletonTrackedResources", response.Value.Data.ResourceType.ToString());
+ Assert.AreEqual("valid2", 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);
+ });
+
+ [Test]
+ public Task Azure_ResourceManager_Models_Resources_SingletonTrackedResource_getByResourceGroup() => Test(async (host) =>
+ {
+ var id = SingletonTrackedResource.CreateResourceIdentifier(Guid.Empty.ToString(), "test-rg");
+ var response = await MgmtTestHelper.CreateArmClientWithMockAuth(host).GetSingletonTrackedResource(id).GetAsync();
+ Assert.AreEqual(200, response.GetRawResponse().Status);
+ Assert.AreEqual(true, response.Value.HasData);
+ Assert.AreEqual("Azure.ResourceManager.Models.Resources/singletonTrackedResources", 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);
+ });
}
}
diff --git a/test/CadlRanchProjects.Tests/special-headers/conditional-request.cs b/test/CadlRanchProjects.Tests/special-headers/conditional-request.cs
index b793e11dfaf..c082fdc4f4e 100644
--- a/test/CadlRanchProjects.Tests/special-headers/conditional-request.cs
+++ b/test/CadlRanchProjects.Tests/special-headers/conditional-request.cs
@@ -3,6 +3,7 @@
using NUnit.Framework;
using System.Threading.Tasks;
using SpecialHeaders.ConditionalRequest;
+using System;
namespace CadlRanchProjects.Tests
{
@@ -22,5 +23,26 @@ public Task Special_Headers_Conditional_Request_PostIfNoneMatch() => Test(async
Response response = await new ConditionalRequestClient(host, null).PostIfNoneMatchAsync(ifNoneMatch);
Assert.AreEqual(204, response.Status);
});
+
+ [Test]
+ public Task Special_Headers_Conditional_Request_HeadIfModifiedSince() => Test(async (host) =>
+ {
+ DateTimeOffset ifModifiedSince = DateTimeOffset.Parse("Fri, 26 Aug 2022 14:38:00 GMT");
+ Response response = await new ConditionalRequestClient(host, null).HeadIfModifiedSinceAsync(new RequestConditions()
+ {
+ IfModifiedSince = ifModifiedSince
+ });
+ Assert.AreEqual(204, response.Status);
+ });
+ [Test]
+ public Task Special_Headers_Conditional_Request_PostIfUnmodifiedSince() => Test(async (host) =>
+ {
+ DateTimeOffset ifUnmodifiedSince = DateTimeOffset.Parse("Fri, 26 Aug 2022 14:38:00 GMT");
+ Response response = await new ConditionalRequestClient(host, null).PostIfUnmodifiedSinceAsync(new RequestConditions()
+ {
+ IfUnmodifiedSince = ifUnmodifiedSince
+ });
+ Assert.AreEqual(204, response.Status);
+ });
}
}
diff --git a/test/CadlRanchProjects/encode/numeric/Configuration.json b/test/CadlRanchProjects/encode/numeric/Configuration.json
new file mode 100644
index 00000000000..6a085843fd4
--- /dev/null
+++ b/test/CadlRanchProjects/encode/numeric/Configuration.json
@@ -0,0 +1,11 @@
+{
+ "output-folder": ".",
+ "namespace": "Encode.Numeric",
+ "library-name": "Encode.Numeric",
+ "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"
+ ]
+}
diff --git a/test/CadlRanchProjects/encode/numeric/Encode.Numeric.sln b/test/CadlRanchProjects/encode/numeric/Encode.Numeric.sln
new file mode 100644
index 00000000000..1bb8a08401a
--- /dev/null
+++ b/test/CadlRanchProjects/encode/numeric/Encode.Numeric.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}") = "Encode.Numeric", "src\Encode.Numeric.csproj", "{28FF4005-4467-4E36-92E7-DEA27DEB1519}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Encode.Numeric.Tests", "tests\Encode.Numeric.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/encode/numeric/src/Encode.Numeric.csproj b/test/CadlRanchProjects/encode/numeric/src/Encode.Numeric.csproj
new file mode 100644
index 00000000000..8b4ca11f496
--- /dev/null
+++ b/test/CadlRanchProjects/encode/numeric/src/Encode.Numeric.csproj
@@ -0,0 +1,19 @@
+
+
+ This is the Encode.Numeric client library for developing .NET applications with rich experience.
+ Azure SDK Code Generation Encode.Numeric for Azure Data Plane
+ 1.0.0-beta.1
+ Encode.Numeric
+ $(RequiredTargetFrameworks)
+ true
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/CadlRanchProjects/encode/numeric/src/Generated/Docs/Property.xml b/test/CadlRanchProjects/encode/numeric/src/Generated/Docs/Property.xml
new file mode 100644
index 00000000000..375602c189e
--- /dev/null
+++ b/test/CadlRanchProjects/encode/numeric/src/Generated/Docs/Property.xml
@@ -0,0 +1,281 @@
+
+
+
+
+
+This sample shows how to call SafeintAsStringAsync.
+ response = await client.SafeintAsStringAsync(value);
+]]>
+This sample shows how to call SafeintAsStringAsync with all parameters.
+ response = await client.SafeintAsStringAsync(value);
+]]>
+
+
+
+This sample shows how to call SafeintAsString.
+ response = client.SafeintAsString(value);
+]]>
+This sample shows how to call SafeintAsString with all parameters.
+ response = client.SafeintAsString(value);
+]]>
+
+
+
+This sample shows how to call SafeintAsStringAsync and parse the result.
+
+This sample shows how to call SafeintAsStringAsync with all request content and parse the result.
+
+
+
+
+This sample shows how to call SafeintAsString and parse the result.
+
+This sample shows how to call SafeintAsString with all request content and parse the result.
+
+
+
+
+This sample shows how to call Uint32AsStringOptionalAsync.
+ response = await client.Uint32AsStringOptionalAsync(value);
+]]>
+This sample shows how to call Uint32AsStringOptionalAsync with all parameters.
+ response = await client.Uint32AsStringOptionalAsync(value);
+]]>
+
+
+
+This sample shows how to call Uint32AsStringOptional.
+ response = client.Uint32AsStringOptional(value);
+]]>
+This sample shows how to call Uint32AsStringOptional with all parameters.
+ response = client.Uint32AsStringOptional(value);
+]]>
+
+
+
+This sample shows how to call Uint32AsStringOptionalAsync and parse the result.
+
+This sample shows how to call Uint32AsStringOptionalAsync with all request content and parse the result.
+
+
+
+
+This sample shows how to call Uint32AsStringOptional and parse the result.
+
+This sample shows how to call Uint32AsStringOptional with all request content and parse the result.
+
+
+
+
+This sample shows how to call Uint8AsStringAsync.
+ response = await client.Uint8AsStringAsync(value);
+]]>
+This sample shows how to call Uint8AsStringAsync with all parameters.
+ response = await client.Uint8AsStringAsync(value);
+]]>
+
+
+
+This sample shows how to call Uint8AsString.
+ response = client.Uint8AsString(value);
+]]>
+This sample shows how to call Uint8AsString with all parameters.
+ response = client.Uint8AsString(value);
+]]>
+
+
+
+This sample shows how to call Uint8AsStringAsync and parse the result.
+
+This sample shows how to call Uint8AsStringAsync with all request content and parse the result.
+
+
+
+
+This sample shows how to call Uint8AsString and parse the result.
+
+This sample shows how to call Uint8AsString with all request content and parse the result.
+
+
+
+
\ No newline at end of file
diff --git a/test/CadlRanchProjects/encode/numeric/src/Generated/EncodeNumericClientBuilderExtensions.cs b/test/CadlRanchProjects/encode/numeric/src/Generated/EncodeNumericClientBuilderExtensions.cs
new file mode 100644
index 00000000000..87ff240061d
--- /dev/null
+++ b/test/CadlRanchProjects/encode/numeric/src/Generated/EncodeNumericClientBuilderExtensions.cs
@@ -0,0 +1,35 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+//
+
+#nullable disable
+
+using System;
+using Azure.Core.Extensions;
+using Encode.Numeric;
+
+namespace Microsoft.Extensions.Azure
+{
+ /// Extension methods to add to client builder.
+ public static partial class EncodeNumericClientBuilderExtensions
+ {
+ /// Registers a instance.
+ /// The builder to register with.
+ /// The to use.
+ public static IAzureClientBuilder AddNumericClient(this TBuilder builder, Uri endpoint)
+ where TBuilder : IAzureClientFactoryBuilder
+ {
+ return builder.RegisterClientFactory((options) => new NumericClient(endpoint, options));
+ }
+
+ /// Registers a instance.
+ /// The builder to register with.
+ /// The configuration values.
+ public static IAzureClientBuilder AddNumericClient(this TBuilder builder, TConfiguration configuration)
+ where TBuilder : IAzureClientFactoryBuilderWithConfiguration
+ {
+ return builder.RegisterClientFactory(configuration);
+ }
+ }
+}
diff --git a/test/CadlRanchProjects/encode/numeric/src/Generated/Internal/Argument.cs b/test/CadlRanchProjects/encode/numeric/src/Generated/Internal/Argument.cs
new file mode 100644
index 00000000000..e9396659288
--- /dev/null
+++ b/test/CadlRanchProjects/encode/numeric/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 Encode.Numeric
+{
+ 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/encode/numeric/src/Generated/Internal/ChangeTrackingDictionary.cs b/test/CadlRanchProjects/encode/numeric/src/Generated/Internal/ChangeTrackingDictionary.cs
new file mode 100644
index 00000000000..33ca4ac4d35
--- /dev/null
+++ b/test/CadlRanchProjects/encode/numeric/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 Encode.Numeric
+{
+ 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/encode/numeric/src/Generated/Internal/ChangeTrackingList.cs b/test/CadlRanchProjects/encode/numeric/src/Generated/Internal/ChangeTrackingList.cs
new file mode 100644
index 00000000000..71869107e56
--- /dev/null
+++ b/test/CadlRanchProjects/encode/numeric/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 Encode.Numeric
+{
+ 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/encode/numeric/src/Generated/Internal/ModelSerializationExtensions.cs b/test/CadlRanchProjects/encode/numeric/src/Generated/Internal/ModelSerializationExtensions.cs
new file mode 100644
index 00000000000..388b52afb51
--- /dev/null
+++ b/test/CadlRanchProjects/encode/numeric/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 Encode.Numeric
+{
+ 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