diff --git a/packages/http-client-csharp/eng/scripts/Generate.ps1 b/packages/http-client-csharp/eng/scripts/Generate.ps1 index 901a4dd4be7..dfbb2eaa9c3 100644 --- a/packages/http-client-csharp/eng/scripts/Generate.ps1 +++ b/packages/http-client-csharp/eng/scripts/Generate.ps1 @@ -73,7 +73,6 @@ $failingSpecs = @( Join-Path 'http' 'special-headers' 'conditional-request' Join-Path 'http' 'special-headers' 'repeatability' Join-Path 'http' 'type' 'dictionary' - Join-Path 'http' 'type' 'enum' 'fixed' Join-Path 'http' 'type' 'model' 'empty' Join-Path 'http' 'type' 'model' 'flatten' Join-Path 'http' 'type' 'model' 'usage' diff --git a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/Properties/launchSettings.json b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/Properties/launchSettings.json index 4b4ca7ddbda..71185eecdef 100644 --- a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/Properties/launchSettings.json +++ b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/Properties/launchSettings.json @@ -65,6 +65,11 @@ "commandName": "Executable", "executablePath": "$(SolutionDir)/../dist/generator/Microsoft.Generator.CSharp.exe" }, + "http-type-enum-fixed": { + "commandLineArgs": "$(SolutionDir)/TestProjects/CadlRanch/http/type/enum/fixed -p StubLibraryPlugin", + "commandName": "Executable", + "executablePath": "$(SolutionDir)/../dist/generator/Microsoft.Generator.CSharp.exe" + }, "http-type-scalar": { "commandLineArgs": "$(SolutionDir)/TestProjects/CadlRanch/http/type/scalar -p StubLibraryPlugin", "commandName": "Executable", diff --git a/packages/http-client-csharp/generator/TestProjects/CadlRanch.Tests/Http/_Type/_Enum/Fixed/FixedTests.cs b/packages/http-client-csharp/generator/TestProjects/CadlRanch.Tests/Http/_Type/_Enum/Fixed/FixedTests.cs new file mode 100644 index 00000000000..86005657356 --- /dev/null +++ b/packages/http-client-csharp/generator/TestProjects/CadlRanch.Tests/Http/_Type/_Enum/Fixed/FixedTests.cs @@ -0,0 +1,38 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.ClientModel; +using System.Threading.Tasks; +using _Type._Enum.Fixed; +using _Type._Enum.Fixed.Models; +using NUnit.Framework; + +namespace TestProjects.CadlRanch.Tests.Http._Type._Enum.Fixed +{ + internal class FixedTests : CadlRanchTestBase + { + [CadlRanchTest] + public Task Type_Enum_Fixed_String_getKnownValue() => Test(async (host) => + { + var response = await new FixedClient(host, null).GetStringClient().GetKnownValueAsync(); + Assert.AreEqual(DaysOfWeekEnum.Monday, response.Value); + }); + + [CadlRanchTest] + public Task Type_Enum_Fixed_String_putKnownValue() => Test(async (host) => + { + var response = await new FixedClient(host, null).GetStringClient().PutKnownValueAsync(DaysOfWeekEnum.Monday); + Assert.AreEqual(204, response.GetRawResponse().Status); + }); + + [CadlRanchTest] + public Task Type_Enum_Fixed_String_putUnknownValue() => Test((host) => + { + var exception = Assert.ThrowsAsync(() => new FixedClient(host, null).GetStringClient().PutUnknownValueAsync(BinaryContent.Create(BinaryData.FromObjectAsJson("Weekend")), null)); + Assert.IsNotNull(exception?.GetRawResponse()); + Assert.AreEqual(500, exception?.GetRawResponse()?.Status); + return Task.CompletedTask; + }); + } +} diff --git a/packages/http-client-csharp/generator/TestProjects/CadlRanch/http/type/enum/fixed/Configuration.json b/packages/http-client-csharp/generator/TestProjects/CadlRanch/http/type/enum/fixed/Configuration.json new file mode 100644 index 00000000000..ee1c7d3cc3b --- /dev/null +++ b/packages/http-client-csharp/generator/TestProjects/CadlRanch/http/type/enum/fixed/Configuration.json @@ -0,0 +1,6 @@ +{ + "output-folder": ".", + "namespace": "Type.Enum.Fixed", + "library-name": "Type.Enum.Fixed", + "use-model-reader-writer": true +} diff --git a/packages/http-client-csharp/generator/TestProjects/CadlRanch/http/type/enum/fixed/_Type._Enum.Fixed.sln b/packages/http-client-csharp/generator/TestProjects/CadlRanch/http/type/enum/fixed/_Type._Enum.Fixed.sln new file mode 100644 index 00000000000..f112adf2f50 --- /dev/null +++ b/packages/http-client-csharp/generator/TestProjects/CadlRanch/http/type/enum/fixed/_Type._Enum.Fixed.sln @@ -0,0 +1,48 @@ +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}") = "_Type._Enum.Fixed", "src\_Type._Enum.Fixed.csproj", "{28FF4005-4467-4E36-92E7-DEA27DEB1519}" +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/packages/http-client-csharp/generator/TestProjects/CadlRanch/http/type/enum/fixed/src/Generated/FixedClient.cs b/packages/http-client-csharp/generator/TestProjects/CadlRanch/http/type/enum/fixed/src/Generated/FixedClient.cs new file mode 100644 index 00000000000..3c72b867393 --- /dev/null +++ b/packages/http-client-csharp/generator/TestProjects/CadlRanch/http/type/enum/fixed/src/Generated/FixedClient.cs @@ -0,0 +1,20 @@ +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; + +namespace _Type._Enum.Fixed +{ + public partial class FixedClient + { + public FixedClient() : this(new Uri("http://localhost:3000"), new FixedClientOptions()) => throw null; + + public FixedClient(Uri endpoint, FixedClientOptions options) => throw null; + + public ClientPipeline Pipeline => throw null; + + public virtual String GetStringClient() => throw null; + } +} diff --git a/packages/http-client-csharp/generator/TestProjects/CadlRanch/http/type/enum/fixed/src/Generated/FixedClientOptions.cs b/packages/http-client-csharp/generator/TestProjects/CadlRanch/http/type/enum/fixed/src/Generated/FixedClientOptions.cs new file mode 100644 index 00000000000..b3e1ebf26c3 --- /dev/null +++ b/packages/http-client-csharp/generator/TestProjects/CadlRanch/http/type/enum/fixed/src/Generated/FixedClientOptions.cs @@ -0,0 +1,12 @@ +// + +#nullable disable + +using System.ClientModel.Primitives; + +namespace _Type._Enum.Fixed +{ + public partial class FixedClientOptions : ClientPipelineOptions + { + } +} diff --git a/packages/http-client-csharp/generator/TestProjects/CadlRanch/http/type/enum/fixed/src/Generated/Models/DaysOfWeekEnum.cs b/packages/http-client-csharp/generator/TestProjects/CadlRanch/http/type/enum/fixed/src/Generated/Models/DaysOfWeekEnum.cs new file mode 100644 index 00000000000..5dc2116849e --- /dev/null +++ b/packages/http-client-csharp/generator/TestProjects/CadlRanch/http/type/enum/fixed/src/Generated/Models/DaysOfWeekEnum.cs @@ -0,0 +1,24 @@ +// + +#nullable disable + +namespace _Type._Enum.Fixed.Models +{ + public enum DaysOfWeekEnum + { + /// Monday. + Monday, + /// Tuesday. + Tuesday, + /// Wednesday. + Wednesday, + /// Thursday. + Thursday, + /// Friday. + Friday, + /// Saturday. + Saturday, + /// Sunday. + Sunday + } +} diff --git a/packages/http-client-csharp/generator/TestProjects/CadlRanch/http/type/enum/fixed/src/Generated/String.cs b/packages/http-client-csharp/generator/TestProjects/CadlRanch/http/type/enum/fixed/src/Generated/String.cs new file mode 100644 index 00000000000..a0def7c7752 --- /dev/null +++ b/packages/http-client-csharp/generator/TestProjects/CadlRanch/http/type/enum/fixed/src/Generated/String.cs @@ -0,0 +1,42 @@ +// + +#nullable disable + +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Threading.Tasks; +using _Type._Enum.Fixed.Models; + +namespace _Type._Enum.Fixed +{ + public partial class String + { + protected String() => throw null; + + public ClientPipeline Pipeline => throw null; + + public virtual ClientResult GetKnownValue(RequestOptions options) => throw null; + + public virtual Task GetKnownValueAsync(RequestOptions options) => throw null; + + public virtual ClientResult GetKnownValue() => throw null; + + public virtual Task> GetKnownValueAsync() => throw null; + + public virtual ClientResult PutKnownValue(BinaryContent content, RequestOptions options) => throw null; + + public virtual Task PutKnownValueAsync(BinaryContent content, RequestOptions options) => throw null; + + public virtual ClientResult PutKnownValue(DaysOfWeekEnum body) => throw null; + + public virtual Task PutKnownValueAsync(DaysOfWeekEnum body) => throw null; + + public virtual ClientResult PutUnknownValue(BinaryContent content, RequestOptions options) => throw null; + + public virtual Task PutUnknownValueAsync(BinaryContent content, RequestOptions options) => throw null; + + public virtual ClientResult PutUnknownValue(DaysOfWeekEnum body) => throw null; + + public virtual Task PutUnknownValueAsync(DaysOfWeekEnum body) => throw null; + } +} diff --git a/packages/http-client-csharp/generator/TestProjects/CadlRanch/http/type/enum/fixed/src/_Type._Enum.Fixed.csproj b/packages/http-client-csharp/generator/TestProjects/CadlRanch/http/type/enum/fixed/src/_Type._Enum.Fixed.csproj new file mode 100644 index 00000000000..fb8bf6dc5d7 --- /dev/null +++ b/packages/http-client-csharp/generator/TestProjects/CadlRanch/http/type/enum/fixed/src/_Type._Enum.Fixed.csproj @@ -0,0 +1,16 @@ + + + This is the _Type._Enum.Fixed client library for developing .NET applications with rich experience. + SDK Code Generation _Type._Enum.Fixed + 1.0.0-beta.1 + _Type._Enum.Fixed + netstandard2.0 + latest + true + + + + + + + diff --git a/packages/http-client-csharp/generator/TestProjects/CadlRanch/http/type/enum/fixed/tspCodeModel.json b/packages/http-client-csharp/generator/TestProjects/CadlRanch/http/type/enum/fixed/tspCodeModel.json new file mode 100644 index 00000000000..179be9f36c2 --- /dev/null +++ b/packages/http-client-csharp/generator/TestProjects/CadlRanch/http/type/enum/fixed/tspCodeModel.json @@ -0,0 +1,384 @@ +{ + "$id": "1", + "Name": "Type.Enum.Fixed", + "ApiVersions": [], + "Enums": [ + { + "$id": "2", + "Kind": "enum", + "Name": "DaysOfWeekEnum", + "CrossLanguageDefinitionId": "Type.Enum.Fixed.DaysOfWeekEnum", + "ValueType": { + "$id": "3", + "Kind": "string", + "Name": "string", + "CrossLanguageDefinitionId": "TypeSpec.string", + "Decorators": [] + }, + "Values": [ + { + "$id": "4", + "Name": "Monday", + "Value": "Monday", + "Description": "Monday.", + "Decorators": [] + }, + { + "$id": "5", + "Name": "Tuesday", + "Value": "Tuesday", + "Description": "Tuesday.", + "Decorators": [] + }, + { + "$id": "6", + "Name": "Wednesday", + "Value": "Wednesday", + "Description": "Wednesday.", + "Decorators": [] + }, + { + "$id": "7", + "Name": "Thursday", + "Value": "Thursday", + "Description": "Thursday.", + "Decorators": [] + }, + { + "$id": "8", + "Name": "Friday", + "Value": "Friday", + "Description": "Friday.", + "Decorators": [] + }, + { + "$id": "9", + "Name": "Saturday", + "Value": "Saturday", + "Description": "Saturday.", + "Decorators": [] + }, + { + "$id": "10", + "Name": "Sunday", + "Value": "Sunday", + "Description": "Sunday.", + "Decorators": [] + } + ], + "Description": "Days of the week", + "IsExtensible": false, + "Usage": "Input,Output,Json", + "Decorators": [] + } + ], + "Models": [], + "Clients": [ + { + "$id": "11", + "Name": "FixedClient", + "Operations": [], + "Protocol": { + "$id": "12" + }, + "Parameters": [ + { + "$id": "13", + "Name": "endpoint", + "NameInRequest": "endpoint", + "Type": { + "$id": "14", + "Kind": "url", + "Name": "url", + "CrossLanguageDefinitionId": "TypeSpec.url" + }, + "Location": "Uri", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsRequired": true, + "IsEndpoint": true, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Client", + "DefaultValue": { + "$id": "15", + "Type": { + "$id": "16", + "Kind": "string", + "Name": "string", + "CrossLanguageDefinitionId": "TypeSpec.string" + }, + "Value": "http://localhost:3000" + } + } + ], + "Decorators": [] + }, + { + "$id": "17", + "Name": "String", + "Operations": [ + { + "$id": "18", + "Name": "getKnownValue", + "ResourceName": "String", + "Description": "getKnownValue", + "Accessibility": "public", + "Parameters": [ + { + "$id": "19", + "Name": "endpoint", + "NameInRequest": "endpoint", + "Type": { + "$id": "20", + "Kind": "url", + "Name": "url", + "CrossLanguageDefinitionId": "TypeSpec.url" + }, + "Location": "Uri", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsRequired": true, + "IsEndpoint": true, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Client", + "DefaultValue": { + "$id": "21", + "Type": { + "$id": "22", + "Kind": "string", + "Name": "string", + "CrossLanguageDefinitionId": "TypeSpec.string" + }, + "Value": "http://localhost:3000" + } + }, + { + "$id": "23", + "Name": "accept", + "NameInRequest": "Accept", + "Type": { + "$id": "24", + "Kind": "constant", + "ValueType": { + "$id": "25", + "Kind": "string", + "Name": "string", + "CrossLanguageDefinitionId": "TypeSpec.string", + "Decorators": [] + }, + "Value": "application/json", + "Decorators": [] + }, + "Location": "Header", + "IsApiVersion": false, + "IsContentType": false, + "IsEndpoint": false, + "Explode": false, + "IsRequired": true, + "Kind": "Constant", + "Decorators": [] + } + ], + "Responses": [ + { + "$id": "26", + "StatusCodes": [ + 200 + ], + "BodyType": { + "$ref": "2" + }, + "BodyMediaType": "Json", + "Headers": [], + "IsErrorResponse": false, + "ContentTypes": [ + "application/json" + ] + } + ], + "HttpMethod": "GET", + "RequestBodyMediaType": "None", + "Uri": "{endpoint}", + "Path": "/type/enum/fixed/string/known-value", + "BufferResponse": true, + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true, + "CrossLanguageDefinitionId": "Type.Enum.Fixed.String.getKnownValue", + "Decorators": [] + }, + { + "$id": "27", + "Name": "putKnownValue", + "ResourceName": "String", + "Description": "putKnownValue", + "Accessibility": "public", + "Parameters": [ + { + "$ref": "19" + }, + { + "$id": "28", + "Name": "contentType", + "NameInRequest": "Content-Type", + "Description": "Body parameter's content type. Known values are application/json", + "Type": { + "$id": "29", + "Kind": "constant", + "ValueType": { + "$id": "30", + "Kind": "string", + "Name": "string", + "CrossLanguageDefinitionId": "TypeSpec.string", + "Decorators": [] + }, + "Value": "application/json", + "Decorators": [] + }, + "Location": "Header", + "IsApiVersion": false, + "IsContentType": true, + "IsEndpoint": false, + "Explode": false, + "IsRequired": true, + "Kind": "Constant", + "Decorators": [] + }, + { + "$id": "31", + "Name": "body", + "NameInRequest": "body", + "Description": "_", + "Type": { + "$ref": "2" + }, + "Location": "Body", + "IsApiVersion": false, + "IsContentType": false, + "IsEndpoint": false, + "Explode": false, + "IsRequired": true, + "Kind": "Method", + "Decorators": [] + } + ], + "Responses": [ + { + "$id": "32", + "StatusCodes": [ + 204 + ], + "BodyMediaType": "Json", + "Headers": [], + "IsErrorResponse": false + } + ], + "HttpMethod": "PUT", + "RequestBodyMediaType": "None", + "Uri": "{endpoint}", + "Path": "/type/enum/fixed/string/known-value", + "RequestMediaTypes": [ + "application/json" + ], + "BufferResponse": true, + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true, + "CrossLanguageDefinitionId": "Type.Enum.Fixed.String.putKnownValue", + "Decorators": [] + }, + { + "$id": "33", + "Name": "putUnknownValue", + "ResourceName": "String", + "Description": "putUnknownValue", + "Accessibility": "public", + "Parameters": [ + { + "$ref": "19" + }, + { + "$id": "34", + "Name": "contentType", + "NameInRequest": "Content-Type", + "Description": "Body parameter's content type. Known values are application/json", + "Type": { + "$id": "35", + "Kind": "constant", + "ValueType": { + "$id": "36", + "Kind": "string", + "Name": "string", + "CrossLanguageDefinitionId": "TypeSpec.string", + "Decorators": [] + }, + "Value": "application/json", + "Decorators": [] + }, + "Location": "Header", + "IsApiVersion": false, + "IsContentType": true, + "IsEndpoint": false, + "Explode": false, + "IsRequired": true, + "Kind": "Constant", + "Decorators": [] + }, + { + "$id": "37", + "Name": "body", + "NameInRequest": "body", + "Description": "_", + "Type": { + "$ref": "2" + }, + "Location": "Body", + "IsApiVersion": false, + "IsContentType": false, + "IsEndpoint": false, + "Explode": false, + "IsRequired": true, + "Kind": "Method", + "Decorators": [] + } + ], + "Responses": [ + { + "$id": "38", + "StatusCodes": [ + 204 + ], + "BodyMediaType": "Json", + "Headers": [], + "IsErrorResponse": false + } + ], + "HttpMethod": "PUT", + "RequestBodyMediaType": "None", + "Uri": "{endpoint}", + "Path": "/type/enum/fixed/string/unknown-value", + "RequestMediaTypes": [ + "application/json" + ], + "BufferResponse": true, + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true, + "CrossLanguageDefinitionId": "Type.Enum.Fixed.String.putUnknownValue", + "Decorators": [] + } + ], + "Protocol": { + "$id": "39" + }, + "Parent": "FixedClient", + "Parameters": [ + { + "$ref": "19" + } + ], + "Decorators": [] + } + ] +}