From 7e754d11397d5b43ffc80fed6c65407b6f80eb21 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Tue, 10 Dec 2019 16:54:11 -0800 Subject: [PATCH 1/5] Add extensible-enums-swagger with tests (#331) --- eng/Generate.ps1 | 2 +- .../ExtensibleEnumTests.cs | 103 ++++++++++++++++++ .../Infrastructure/TestServerTestBase.cs | 11 +- .../Models/DaysOfWeekExtensibleEnum.cs | 45 ++++++++ .../Generated/Models/IntEnum.cs | 37 +++++++ .../Generated/Models/Pet.Serialization.cs | 51 +++++++++ .../Generated/Models/Pet.cs | 12 ++ .../Generated/Operations/PetOperations.cs | 79 ++++++++++++++ .../extensible-enums-swagger.csproj | 15 +++ 9 files changed, 352 insertions(+), 3 deletions(-) create mode 100644 test/AutoRest.TestServer.Tests/ExtensibleEnumTests.cs create mode 100644 test/TestServerProjects/extensible-enums-swagger/Generated/Models/DaysOfWeekExtensibleEnum.cs create mode 100644 test/TestServerProjects/extensible-enums-swagger/Generated/Models/IntEnum.cs create mode 100644 test/TestServerProjects/extensible-enums-swagger/Generated/Models/Pet.Serialization.cs create mode 100644 test/TestServerProjects/extensible-enums-swagger/Generated/Models/Pet.cs create mode 100644 test/TestServerProjects/extensible-enums-swagger/Generated/Operations/PetOperations.cs create mode 100644 test/TestServerProjects/extensible-enums-swagger/extensible-enums-swagger.csproj diff --git a/eng/Generate.ps1 b/eng/Generate.ps1 index bfd87029..16ed4106 100644 --- a/eng/Generate.ps1 +++ b/eng/Generate.ps1 @@ -36,7 +36,7 @@ $debugFlags = if (-not $noDebug) { '--debug', '--verbose' } $testServerDirectory = Join-Path $repoRoot 'test' 'TestServerProjects' $configurationPath = Join-Path $testServerDirectory 'readme.tests.md' $testServerSwaggerPath = Join-Path $repoRoot 'node_modules' '@microsoft.azure' 'autorest.testserver' 'swagger' -$testNames = if ($name) { $name } else { 'url-multi-collectionFormat', 'url', 'body-string', 'body-complex', 'custom-baseUrl', 'custom-baseUrl-more-options', 'header' } +$testNames = if ($name) { $name } else { 'extensible-enums-swagger', 'url-multi-collectionFormat', 'url', 'body-string', 'body-complex', 'custom-baseUrl', 'custom-baseUrl-more-options', 'header' } if (!$NoReset) { diff --git a/test/AutoRest.TestServer.Tests/ExtensibleEnumTests.cs b/test/AutoRest.TestServer.Tests/ExtensibleEnumTests.cs new file mode 100644 index 00000000..c999d70a --- /dev/null +++ b/test/AutoRest.TestServer.Tests/ExtensibleEnumTests.cs @@ -0,0 +1,103 @@ +using System.Threading.Tasks; +using AutoRest.TestServer.Tests.Infrastructure; +using extensible_enums_swagger; +using extensible_enums_swagger.Models.V20160707; +using NUnit.Framework; + +namespace AutoRest.TestServer.Tests +{ + public class ExtensibleEnumTests : TestServerTestBase + { + public ExtensibleEnumTests(TestServerVersion version) : base(version, "extensibleenums") { } + + [Test] + [IgnoreOnTestServer(TestServerVersion.V2, "Dynamic")] + public Task RoundTripEnum() => TestStatus(async (host, pipeline) => + { + var response = await PetOperations.AddPetAsync(ClientDiagnostics, pipeline, new Pet() + { + Name = "Retriever", + IntEnum = IntEnum._2, + DaysOfWeek = DaysOfWeekExtensibleEnum.Friday + }, host: host); + + Assert.AreEqual("Retriever", response.Value.Name); + Assert.AreEqual(IntEnum._2, response.Value.IntEnum); + Assert.AreEqual(DaysOfWeekExtensibleEnum.Friday, response.Value.DaysOfWeek); + + return response.GetRawResponse(); + }); + + [Test] + [IgnoreOnTestServer(TestServerVersion.V2, "Dynamic")] + public Task RoundTripEnum_Custom() => TestStatus(async (host, pipeline) => + { + var response = await PetOperations.AddPetAsync(ClientDiagnostics, pipeline, new Pet() + { + Name = "Retriever", + IntEnum = "77", + DaysOfWeek = "WED" + }, host: host); + + Assert.AreEqual("Retriever", response.Value.Name); + Assert.AreEqual("77", response.Value.IntEnum.ToString()); + Assert.AreEqual("WED", response.Value.DaysOfWeek.Value.ToString()); + + return response.GetRawResponse(); + }); + + [Test] + [IgnoreOnTestServer(TestServerVersion.V2, "Dynamic")] + public Task RoundTripEnum_Null() => TestStatus(async (host, pipeline) => + { + var response = await PetOperations.AddPetAsync(ClientDiagnostics, pipeline, new Pet() + { + Name = "Retriever", + IntEnum = "77", + DaysOfWeek = null + }, host: host); + + Assert.AreEqual("Retriever", response.Value.Name); + Assert.AreEqual("77", response.Value.IntEnum.ToString()); + Assert.Null(response.Value.DaysOfWeek); + + return response.GetRawResponse(); + }); + + [Test] + public Task AllowedValueEnum() => TestStatus(async (host, pipeline) => + { + var response = await PetOperations.GetByPetIdAsync(ClientDiagnostics, pipeline, "scooby", host: host); + + Assert.AreEqual("Scooby Scarface", response.Value.Name); + Assert.AreEqual("2.1", response.Value.IntEnum.ToString()); + Assert.AreEqual(DaysOfWeekExtensibleEnum.Thursday, response.Value.DaysOfWeek); + + return response.GetRawResponse(); + }); + + [Test] + public Task ExpectedEnum() => TestStatus(async (host, pipeline) => + { + var response = await PetOperations.GetByPetIdAsync(ClientDiagnostics, pipeline, "tommy", host: host); + + Assert.AreEqual("Tommy Tomson", response.Value.Name); + Assert.AreEqual(IntEnum._1, response.Value.IntEnum); + Assert.AreEqual(DaysOfWeekExtensibleEnum.Monday, response.Value.DaysOfWeek); + + return response.GetRawResponse(); + }); + + [Test] + public Task UnexpectedEnum() => TestStatus(async (host, pipeline) => + { + var response = await PetOperations.GetByPetIdAsync(ClientDiagnostics, pipeline, "casper", host: host); + + Assert.AreEqual("Casper Ghosty", response.Value.Name); + Assert.AreEqual(IntEnum._2, response.Value.IntEnum); + Assert.AreEqual("Weekend", response.Value.DaysOfWeek.Value.ToString()); + + return response.GetRawResponse(); + }); + } +} diff --git a/test/AutoRest.TestServer.Tests/Infrastructure/TestServerTestBase.cs b/test/AutoRest.TestServer.Tests/Infrastructure/TestServerTestBase.cs index 8cc27062..1a8b5bd1 100644 --- a/test/AutoRest.TestServer.Tests/Infrastructure/TestServerTestBase.cs +++ b/test/AutoRest.TestServer.Tests/Infrastructure/TestServerTestBase.cs @@ -62,7 +62,7 @@ namespace AutoRest.TestServer.Tests.Infrastructure public Task TestStatus(Func> test) { - return TestStatus(TestContext.CurrentContext.Test.Name, test); + return TestStatus(GetScenarioName(), test); } private Task TestStatus(string scenario, Func> test) => Test(scenario, async (host, pipeline) => @@ -73,7 +73,7 @@ namespace AutoRest.TestServer.Tests.Infrastructure public Task Test(Func test, bool ignoreScenario = false) { - return Test(TestContext.CurrentContext.Test.Name, test, ignoreScenario); + return Test(GetScenarioName(), test, ignoreScenario); } private async Task Test(string scenario, Func test, bool ignoreScenario = false) @@ -102,5 +102,12 @@ namespace AutoRest.TestServer.Tests.Infrastructure await server.DisposeAsync(); } + + private static string GetScenarioName() + { + var testName = TestContext.CurrentContext.Test.Name; + var indexOfUnderscore = testName.IndexOf('_'); + return indexOfUnderscore == -1 ? testName : testName.Substring(0, indexOfUnderscore); + } } } diff --git a/test/TestServerProjects/extensible-enums-swagger/Generated/Models/DaysOfWeekExtensibleEnum.cs b/test/TestServerProjects/extensible-enums-swagger/Generated/Models/DaysOfWeekExtensibleEnum.cs new file mode 100644 index 00000000..79cf8f05 --- /dev/null +++ b/test/TestServerProjects/extensible-enums-swagger/Generated/Models/DaysOfWeekExtensibleEnum.cs @@ -0,0 +1,45 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.ComponentModel; + +namespace extensible_enums_swagger.Models.V20160707 +{ + public readonly partial struct DaysOfWeekExtensibleEnum : IEquatable + { + private readonly string? _value; + + public DaysOfWeekExtensibleEnum(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string MondayValue = "Monday"; + private const string TuesdayValue = "Tuesday"; + private const string WednesdayValue = "Wednesday"; + private const string ThursdayValue = "Thursday"; + private const string FridayValue = "Friday"; + private const string SaturdayValue = "Saturday"; + private const string SundayValue = "Sunday"; + + public static DaysOfWeekExtensibleEnum Monday { get; } = new DaysOfWeekExtensibleEnum(MondayValue); + public static DaysOfWeekExtensibleEnum Tuesday { get; } = new DaysOfWeekExtensibleEnum(TuesdayValue); + public static DaysOfWeekExtensibleEnum Wednesday { get; } = new DaysOfWeekExtensibleEnum(WednesdayValue); + public static DaysOfWeekExtensibleEnum Thursday { get; } = new DaysOfWeekExtensibleEnum(ThursdayValue); + public static DaysOfWeekExtensibleEnum Friday { get; } = new DaysOfWeekExtensibleEnum(FridayValue); + public static DaysOfWeekExtensibleEnum Saturday { get; } = new DaysOfWeekExtensibleEnum(SaturdayValue); + public static DaysOfWeekExtensibleEnum Sunday { get; } = new DaysOfWeekExtensibleEnum(SundayValue); + public static bool operator ==(DaysOfWeekExtensibleEnum left, DaysOfWeekExtensibleEnum right) => left.Equals(right); + public static bool operator !=(DaysOfWeekExtensibleEnum left, DaysOfWeekExtensibleEnum right) => !left.Equals(right); + public static implicit operator DaysOfWeekExtensibleEnum(string value) => new DaysOfWeekExtensibleEnum(value); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object? obj) => obj is DaysOfWeekExtensibleEnum other && Equals(other); + public bool Equals(DaysOfWeekExtensibleEnum other) => string.Equals(_value, other._value, StringComparison.Ordinal); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value?.GetHashCode() ?? 0; + public override string? ToString() => _value; + } +} diff --git a/test/TestServerProjects/extensible-enums-swagger/Generated/Models/IntEnum.cs b/test/TestServerProjects/extensible-enums-swagger/Generated/Models/IntEnum.cs new file mode 100644 index 00000000..0c5b0b09 --- /dev/null +++ b/test/TestServerProjects/extensible-enums-swagger/Generated/Models/IntEnum.cs @@ -0,0 +1,37 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.ComponentModel; + +namespace extensible_enums_swagger.Models.V20160707 +{ + public readonly partial struct IntEnum : IEquatable + { + private readonly string? _value; + + public IntEnum(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string _1Value = "1"; + private const string _2Value = "2"; + private const string _3Value = "3"; + + public static IntEnum _1 { get; } = new IntEnum(_1Value); + public static IntEnum _2 { get; } = new IntEnum(_2Value); + public static IntEnum _3 { get; } = new IntEnum(_3Value); + public static bool operator ==(IntEnum left, IntEnum right) => left.Equals(right); + public static bool operator !=(IntEnum left, IntEnum right) => !left.Equals(right); + public static implicit operator IntEnum(string value) => new IntEnum(value); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object? obj) => obj is IntEnum other && Equals(other); + public bool Equals(IntEnum other) => string.Equals(_value, other._value, StringComparison.Ordinal); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value?.GetHashCode() ?? 0; + public override string? ToString() => _value; + } +} diff --git a/test/TestServerProjects/extensible-enums-swagger/Generated/Models/Pet.Serialization.cs b/test/TestServerProjects/extensible-enums-swagger/Generated/Models/Pet.Serialization.cs new file mode 100644 index 00000000..124d7ed7 --- /dev/null +++ b/test/TestServerProjects/extensible-enums-swagger/Generated/Models/Pet.Serialization.cs @@ -0,0 +1,51 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System.Text.Json; + +namespace extensible_enums_swagger.Models.V20160707 +{ + public partial class Pet + { + internal void Serialize(Utf8JsonWriter writer) + { + writer.WriteStartObject(); + if (Name != null) + { + writer.WritePropertyName("name"); + writer.WriteStringValue(Name); + } + if (DaysOfWeek != null) + { + writer.WritePropertyName("DaysOfWeek"); + writer.WriteStringValue(DaysOfWeek.ToString()); + } + writer.WritePropertyName("IntEnum"); + writer.WriteStringValue(IntEnum.ToString()); + writer.WriteEndObject(); + } + internal static Pet Deserialize(JsonElement element) + { + var result = new Pet(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("name")) + { + result.Name = property.Value.GetString(); + continue; + } + if (property.NameEquals("DaysOfWeek")) + { + result.DaysOfWeek = new DaysOfWeekExtensibleEnum(property.Value.GetString()); + continue; + } + if (property.NameEquals("IntEnum")) + { + result.IntEnum = new IntEnum(property.Value.GetString()); + continue; + } + } + return result; + } + } +} diff --git a/test/TestServerProjects/extensible-enums-swagger/Generated/Models/Pet.cs b/test/TestServerProjects/extensible-enums-swagger/Generated/Models/Pet.cs new file mode 100644 index 00000000..5d890a94 --- /dev/null +++ b/test/TestServerProjects/extensible-enums-swagger/Generated/Models/Pet.cs @@ -0,0 +1,12 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace extensible_enums_swagger.Models.V20160707 +{ + public partial class Pet + { + public string? Name { get; set; } + public DaysOfWeekExtensibleEnum? DaysOfWeek { get; set; } + public IntEnum IntEnum { get; set; } + } +} diff --git a/test/TestServerProjects/extensible-enums-swagger/Generated/Operations/PetOperations.cs b/test/TestServerProjects/extensible-enums-swagger/Generated/Operations/PetOperations.cs new file mode 100644 index 00000000..46cdde4b --- /dev/null +++ b/test/TestServerProjects/extensible-enums-swagger/Generated/Operations/PetOperations.cs @@ -0,0 +1,79 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Text.Json; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; +using extensible_enums_swagger.Models.V20160707; + +namespace extensible_enums_swagger +{ + internal static class PetOperations + { + public static async ValueTask> GetByPetIdAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string petId, string host = "http://localhost:3000", CancellationToken cancellationToken = default) + { + using var scope = clientDiagnostics.CreateScope("extensible_enums_swagger.GetByPetId"); + scope.Start(); + try + { + var request = pipeline.CreateRequest(); + request.Method = RequestMethod.Get; + request.Uri.Reset(new Uri($"{host}")); + request.Uri.AppendPath("/extensibleenums/pet/", false); + request.Uri.AppendPath(petId, true); + var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); + cancellationToken.ThrowIfCancellationRequested(); + using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); + switch (response.Status) + { + case 200: + return Response.FromValue(Pet.Deserialize(document.RootElement), response); + default: + throw new Exception(); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + public static async ValueTask> AddPetAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Pet? petParam, string host = "http://localhost:3000", CancellationToken cancellationToken = default) + { + using var scope = clientDiagnostics.CreateScope("extensible_enums_swagger.AddPet"); + scope.Start(); + try + { + var request = pipeline.CreateRequest(); + request.Method = RequestMethod.Post; + request.Uri.Reset(new Uri($"{host}")); + request.Uri.AppendPath("/extensibleenums/pet/addPet", false); + request.Headers.Add("Content-Type", "application/json"); + var buffer = new ArrayBufferWriter(); + await using var writer = new Utf8JsonWriter(buffer); + petParam?.Serialize(writer); + writer.Flush(); + request.Content = RequestContent.Create(buffer.WrittenMemory); + var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); + cancellationToken.ThrowIfCancellationRequested(); + using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); + switch (response.Status) + { + case 200: + return Response.FromValue(Pet.Deserialize(document.RootElement), response); + default: + throw new Exception(); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + } +} diff --git a/test/TestServerProjects/extensible-enums-swagger/extensible-enums-swagger.csproj b/test/TestServerProjects/extensible-enums-swagger/extensible-enums-swagger.csproj new file mode 100644 index 00000000..409c8953 --- /dev/null +++ b/test/TestServerProjects/extensible-enums-swagger/extensible-enums-swagger.csproj @@ -0,0 +1,15 @@ + + + + netstandard2.0 + true + annotations + + + + + + + + + From 65e415e70581126b0754e8754c745eaaada0aa3e Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Wed, 11 Dec 2019 11:19:47 -0800 Subject: [PATCH 2/5] Add nullchecks for nullable required parameters (#332) * Add nullchecks for nullable required parameters * LOGIC * use if --- .../ServiceClientMethodParameter.cs | 4 +- .../CodeGen/ClientWriter.cs | 27 +- src/AutoRest.CSharp.V3/CodeGen/CodeWriter.cs | 10 + src/AutoRest.CSharp.V3/Pipeline/Extensions.cs | 6 +- src/AutoRest.CSharp.V3/Plugins/Modeler.cs | 6 +- test/AutoRest.TestServer.Tests/url.cs | 7 +- .../Generated/Operations/ArrayOperations.cs | 33 +++ .../Generated/Operations/BasicOperations.cs | 34 +++ .../Operations/DictionaryOperations.cs | 38 +++ .../Operations/FlattencomplexOperations.cs | 5 + .../Operations/InheritanceOperations.cs | 14 + .../PolymorphicrecursiveOperations.cs | 14 + .../Operations/PolymorphismOperations.cs | 61 +++++ .../Operations/PrimitiveOperations.cs | 154 +++++++++++ .../Operations/ReadonlypropertyOperations.cs | 14 + .../Generated/Operations/EnumOperations.cs | 34 +++ .../Generated/Operations/StringOperations.cs | 69 +++++ .../Generated/Operations/PathsOperations.cs | 21 ++ .../Generated/Operations/PathsOperations.cs | 9 + .../Generated/Operations/PetOperations.cs | 14 + .../Generated/Operations/HeaderOperations.cs | 253 ++++++++++++++++++ .../Generated/Operations/QueriesOperations.cs | 15 ++ .../Operations/PathItemsOperations.cs | 68 +++++ .../Generated/Operations/PathsOperations.cs | 150 +++++++++++ .../Generated/Operations/QueriesOperations.cs | 170 ++++++++++++ 25 files changed, 1217 insertions(+), 13 deletions(-) diff --git a/src/AutoRest.CSharp.V3/ClientModels/ServiceClientMethodParameter.cs b/src/AutoRest.CSharp.V3/ClientModels/ServiceClientMethodParameter.cs index 01dd2edf..44987be9 100644 --- a/src/AutoRest.CSharp.V3/ClientModels/ServiceClientMethodParameter.cs +++ b/src/AutoRest.CSharp.V3/ClientModels/ServiceClientMethodParameter.cs @@ -5,15 +5,17 @@ namespace AutoRest.CSharp.V3.ClientModels { internal class ServiceClientMethodParameter { - public ServiceClientMethodParameter(string name, ClientTypeReference type, ClientConstant? defaultValue) + public ServiceClientMethodParameter(string name, ClientTypeReference type, ClientConstant? defaultValue, bool isRequired) { Name = name; Type = type; DefaultValue = defaultValue; + IsRequired = isRequired; } public ClientTypeReference Type { get; } public string Name { get; } public ClientConstant? DefaultValue { get; } + public bool IsRequired { get; } } } diff --git a/src/AutoRest.CSharp.V3/CodeGen/ClientWriter.cs b/src/AutoRest.CSharp.V3/CodeGen/ClientWriter.cs index 43b7aed4..8eabfff4 100644 --- a/src/AutoRest.CSharp.V3/CodeGen/ClientWriter.cs +++ b/src/AutoRest.CSharp.V3/CodeGen/ClientWriter.cs @@ -45,7 +45,7 @@ namespace AutoRest.CSharp.V3.CodeGen return true; } - private void WriteOperation(CodeWriter writer, ClientMethod operation, CSharpNamespace? @namespace) + private void WriteOperation(CodeWriter writer, ClientMethod operation, CSharpNamespace @namespace) { //TODO: Handle multiple responses var schemaResponse = operation.ResponseType; @@ -70,7 +70,9 @@ namespace AutoRest.CSharp.V3.CodeGen var methodName = operation.Name; using (writer.Method("public static async", writer.Type(returnType), $"{methodName}Async", parametersText)) { - writer.Line($"using var scope = clientDiagnostics.CreateScope(\"{@namespace?.FullName ?? "[NO NAMESPACE]"}.{methodName}\");"); + WriteParameterNullChecks(writer, operation); + + writer.Line($"using var scope = clientDiagnostics.CreateScope(\"{@namespace.FullName}.{methodName}\");"); //TODO: Implement attribute logic //writer.Line("scope.AddAttribute(\"key\", name);"); writer.Line("scope.Start();"); @@ -140,6 +142,23 @@ namespace AutoRest.CSharp.V3.CodeGen } } + private void WriteParameterNullChecks(CodeWriter writer, ClientMethod operation) + { + foreach (ServiceClientMethodParameter parameter in operation.Parameters) + { + var cs = _typeFactory.CreateType(parameter.Type); + if (parameter.IsRequired && (cs.IsNullable || !cs.IsValueType)) + { + using (writer.If($"{parameter.Name} == null")) + { + writer.Append("throw new ").AppendType(typeof(ArgumentNullException)).Append("(nameof(").Append(parameter.Name).Append("));"); + writer.Line(); + } + } + } + writer.Line(); + } + private void WriteConstant(CodeWriter writer, ClientConstant constant) { if (constant.Value == null) @@ -155,7 +174,7 @@ namespace AutoRest.CSharp.V3.CodeGen dateTimeValue = dateTimeValue.ToUniversalTime(); writer.Append("new "); - writer.Append(writer.Type(typeof(DateTimeOffset))); + writer.AppendType(typeof(DateTimeOffset)); writer.Append("("); writer.Literal(dateTimeValue.Year); writer.Comma(); @@ -171,7 +190,7 @@ namespace AutoRest.CSharp.V3.CodeGen writer.Comma(); writer.Literal(dateTimeValue.Millisecond); writer.Comma(); - writer.Append(writer.Type(typeof(TimeSpan))); + writer.AppendType(typeof(TimeSpan)); writer.Append("."); writer.Append(nameof(TimeSpan.Zero)); writer.Append(")"); diff --git a/src/AutoRest.CSharp.V3/CodeGen/CodeWriter.cs b/src/AutoRest.CSharp.V3/CodeGen/CodeWriter.cs index 552443f5..f0d77dac 100644 --- a/src/AutoRest.CSharp.V3/CodeGen/CodeWriter.cs +++ b/src/AutoRest.CSharp.V3/CodeGen/CodeWriter.cs @@ -135,6 +135,16 @@ namespace AutoRest.CSharp.V3.CodeGen return name; } + public CodeWriter AppendType(CSharpType type) + { + return Append(Type(type)); + } + + public CodeWriter AppendType(Type type, bool isNullable = false) + { + return Append(Type(type, isNullable)); + } + public string Type(Type type, bool isNullable = false) => Type(new CSharpType(type, isNullable)); public string AttributeType(Type type) => Type(type).Replace("Attribute", String.Empty); diff --git a/src/AutoRest.CSharp.V3/Pipeline/Extensions.cs b/src/AutoRest.CSharp.V3/Pipeline/Extensions.cs index 9d11555a..6dc2614c 100644 --- a/src/AutoRest.CSharp.V3/Pipeline/Extensions.cs +++ b/src/AutoRest.CSharp.V3/Pipeline/Extensions.cs @@ -179,7 +179,7 @@ namespace AutoRest.CSharp.V3.Pipeline private static void WriteDeserializeClientObject(CodeWriter writer, CSharpType cSharpType, string name) { - writer.Append(writer.Type(cSharpType)); + writer.AppendType(cSharpType); writer.Append(".Deserialize("); writer.Append(name); writer.Append(")"); @@ -190,7 +190,7 @@ namespace AutoRest.CSharp.V3.Pipeline if (isStringBased) { writer.Append("new "); - writer.Append(writer.Type(cSharpType)); + writer.AppendType(cSharpType); writer.Append("("); writer.Append(name); writer.Append(".GetString())"); @@ -199,7 +199,7 @@ namespace AutoRest.CSharp.V3.Pipeline writer.Append(name); writer.Append(".GetString().To"); - writer.Append(writer.Type(cSharpType)); + writer.AppendType(cSharpType); writer.Append("()"); } diff --git a/src/AutoRest.CSharp.V3/Plugins/Modeler.cs b/src/AutoRest.CSharp.V3/Plugins/Modeler.cs index aef31d37..b383ce12 100644 --- a/src/AutoRest.CSharp.V3/Plugins/Modeler.cs +++ b/src/AutoRest.CSharp.V3/Plugins/Modeler.cs @@ -107,18 +107,18 @@ namespace AutoRest.CSharp.V3.Plugins case ArraySchema arraySchema when arraySchema.ElementType is ConstantSchema constantInnerType: constantOrParameter = new ServiceClientMethodParameter(requestParameter.CSharpName(), new CollectionTypeReference(CreateType(constantInnerType.ValueType, false), false), - CreateDefaultValueConstant(requestParameter)); + CreateDefaultValueConstant(requestParameter), false); break; //TODO: Workaround for https://github.com/Azure/autorest.csharp/pull/275 case DictionarySchema dictionarySchema when dictionarySchema.ElementType is ConstantSchema constantInnerType: constantOrParameter = new ServiceClientMethodParameter(requestParameter.CSharpName(), new CollectionTypeReference(CreateType(constantInnerType.ValueType, false), false), - CreateDefaultValueConstant(requestParameter)); + CreateDefaultValueConstant(requestParameter), false); break; default: constantOrParameter = new ServiceClientMethodParameter(requestParameter.CSharpName(), CreateType(requestParameter.Schema, requestParameter.IsNullable()), - CreateDefaultValueConstant(requestParameter)); + CreateDefaultValueConstant(requestParameter), requestParameter.Required == true); break; } diff --git a/test/AutoRest.TestServer.Tests/url.cs b/test/AutoRest.TestServer.Tests/url.cs index 8ac4c783..8a0cc90e 100644 --- a/test/AutoRest.TestServer.Tests/url.cs +++ b/test/AutoRest.TestServer.Tests/url.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Text; using System.Threading.Tasks; using AutoRest.TestServer.Tests.Infrastructure; +using Azure.Core.Pipeline; using NUnit.Framework; using url; using url.Models.V100; @@ -47,8 +48,10 @@ namespace AutoRest.TestServer.Tests public Task UrlPathsByteMultiByte() => TestStatus(async (host, pipeline) => await PathsOperations.ByteMultiByteAsync(ClientDiagnostics, pipeline, TestConstants.ByteArray, host)); [Test] - [Ignore("Don't have null-checks yet")] - public Task UrlByteNullAsync() => TestStatus(async (host, pipeline) => await PathsOperations.ByteNullAsync(ClientDiagnostics, pipeline, null, host)); + public void UrlByteNullAsync() + { + Assert.ThrowsAsync(async () => await PathsOperations.ByteNullAsync(ClientDiagnostics, null, null, host: string.Empty)); + } [Test] [Ignore("Might not apply")] diff --git a/test/TestServerProjects/body-complex/Generated/Operations/ArrayOperations.cs b/test/TestServerProjects/body-complex/Generated/Operations/ArrayOperations.cs index ee2b2768..10a6cfe1 100644 --- a/test/TestServerProjects/body-complex/Generated/Operations/ArrayOperations.cs +++ b/test/TestServerProjects/body-complex/Generated/Operations/ArrayOperations.cs @@ -16,6 +16,11 @@ namespace body_complex { public static async ValueTask> GetValidAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("body_complex.GetValid"); scope.Start(); try @@ -43,6 +48,15 @@ namespace body_complex } public static async ValueTask PutValidAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, ArrayWrapper complexBody, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (complexBody == null) + { + throw new ArgumentNullException(nameof(complexBody)); + } + using var scope = clientDiagnostics.CreateScope("body_complex.PutValid"); scope.Start(); try @@ -69,6 +83,11 @@ namespace body_complex } public static async ValueTask> GetEmptyAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("body_complex.GetEmpty"); scope.Start(); try @@ -96,6 +115,15 @@ namespace body_complex } public static async ValueTask PutEmptyAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, ArrayWrapper complexBody, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (complexBody == null) + { + throw new ArgumentNullException(nameof(complexBody)); + } + using var scope = clientDiagnostics.CreateScope("body_complex.PutEmpty"); scope.Start(); try @@ -122,6 +150,11 @@ namespace body_complex } public static async ValueTask> GetNotProvidedAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("body_complex.GetNotProvided"); scope.Start(); try diff --git a/test/TestServerProjects/body-complex/Generated/Operations/BasicOperations.cs b/test/TestServerProjects/body-complex/Generated/Operations/BasicOperations.cs index 63df69d4..20c84813 100644 --- a/test/TestServerProjects/body-complex/Generated/Operations/BasicOperations.cs +++ b/test/TestServerProjects/body-complex/Generated/Operations/BasicOperations.cs @@ -16,6 +16,11 @@ namespace body_complex { public static async ValueTask> GetValidAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("body_complex.GetValid"); scope.Start(); try @@ -43,6 +48,15 @@ namespace body_complex } public static async ValueTask PutValidAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Basic complexBody, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (complexBody == null) + { + throw new ArgumentNullException(nameof(complexBody)); + } + using var scope = clientDiagnostics.CreateScope("body_complex.PutValid"); scope.Start(); try @@ -70,6 +84,11 @@ namespace body_complex } public static async ValueTask> GetInvalidAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("body_complex.GetInvalid"); scope.Start(); try @@ -97,6 +116,11 @@ namespace body_complex } public static async ValueTask> GetEmptyAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("body_complex.GetEmpty"); scope.Start(); try @@ -124,6 +148,11 @@ namespace body_complex } public static async ValueTask> GetNullAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("body_complex.GetNull"); scope.Start(); try @@ -151,6 +180,11 @@ namespace body_complex } public static async ValueTask> GetNotProvidedAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("body_complex.GetNotProvided"); scope.Start(); try diff --git a/test/TestServerProjects/body-complex/Generated/Operations/DictionaryOperations.cs b/test/TestServerProjects/body-complex/Generated/Operations/DictionaryOperations.cs index d6425660..d0254888 100644 --- a/test/TestServerProjects/body-complex/Generated/Operations/DictionaryOperations.cs +++ b/test/TestServerProjects/body-complex/Generated/Operations/DictionaryOperations.cs @@ -16,6 +16,11 @@ namespace body_complex { public static async ValueTask> GetValidAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("body_complex.GetValid"); scope.Start(); try @@ -43,6 +48,15 @@ namespace body_complex } public static async ValueTask PutValidAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, DictionaryWrapper complexBody, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (complexBody == null) + { + throw new ArgumentNullException(nameof(complexBody)); + } + using var scope = clientDiagnostics.CreateScope("body_complex.PutValid"); scope.Start(); try @@ -69,6 +83,11 @@ namespace body_complex } public static async ValueTask> GetEmptyAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("body_complex.GetEmpty"); scope.Start(); try @@ -96,6 +115,15 @@ namespace body_complex } public static async ValueTask PutEmptyAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, DictionaryWrapper complexBody, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (complexBody == null) + { + throw new ArgumentNullException(nameof(complexBody)); + } + using var scope = clientDiagnostics.CreateScope("body_complex.PutEmpty"); scope.Start(); try @@ -122,6 +150,11 @@ namespace body_complex } public static async ValueTask> GetNullAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("body_complex.GetNull"); scope.Start(); try @@ -149,6 +182,11 @@ namespace body_complex } public static async ValueTask> GetNotProvidedAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("body_complex.GetNotProvided"); scope.Start(); try diff --git a/test/TestServerProjects/body-complex/Generated/Operations/FlattencomplexOperations.cs b/test/TestServerProjects/body-complex/Generated/Operations/FlattencomplexOperations.cs index 55d51208..3457c636 100644 --- a/test/TestServerProjects/body-complex/Generated/Operations/FlattencomplexOperations.cs +++ b/test/TestServerProjects/body-complex/Generated/Operations/FlattencomplexOperations.cs @@ -16,6 +16,11 @@ namespace body_complex { public static async ValueTask> GetValidAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("body_complex.GetValid"); scope.Start(); try diff --git a/test/TestServerProjects/body-complex/Generated/Operations/InheritanceOperations.cs b/test/TestServerProjects/body-complex/Generated/Operations/InheritanceOperations.cs index b063bc7b..9b72dabe 100644 --- a/test/TestServerProjects/body-complex/Generated/Operations/InheritanceOperations.cs +++ b/test/TestServerProjects/body-complex/Generated/Operations/InheritanceOperations.cs @@ -16,6 +16,11 @@ namespace body_complex { public static async ValueTask> GetValidAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("body_complex.GetValid"); scope.Start(); try @@ -43,6 +48,15 @@ namespace body_complex } public static async ValueTask PutValidAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Siamese complexBody, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (complexBody == null) + { + throw new ArgumentNullException(nameof(complexBody)); + } + using var scope = clientDiagnostics.CreateScope("body_complex.PutValid"); scope.Start(); try diff --git a/test/TestServerProjects/body-complex/Generated/Operations/PolymorphicrecursiveOperations.cs b/test/TestServerProjects/body-complex/Generated/Operations/PolymorphicrecursiveOperations.cs index 44f99b50..49dad085 100644 --- a/test/TestServerProjects/body-complex/Generated/Operations/PolymorphicrecursiveOperations.cs +++ b/test/TestServerProjects/body-complex/Generated/Operations/PolymorphicrecursiveOperations.cs @@ -16,6 +16,11 @@ namespace body_complex { public static async ValueTask> GetValidAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("body_complex.GetValid"); scope.Start(); try @@ -43,6 +48,15 @@ namespace body_complex } public static async ValueTask PutValidAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Fish complexBody, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (complexBody == null) + { + throw new ArgumentNullException(nameof(complexBody)); + } + using var scope = clientDiagnostics.CreateScope("body_complex.PutValid"); scope.Start(); try diff --git a/test/TestServerProjects/body-complex/Generated/Operations/PolymorphismOperations.cs b/test/TestServerProjects/body-complex/Generated/Operations/PolymorphismOperations.cs index 8d1548cb..da687b58 100644 --- a/test/TestServerProjects/body-complex/Generated/Operations/PolymorphismOperations.cs +++ b/test/TestServerProjects/body-complex/Generated/Operations/PolymorphismOperations.cs @@ -16,6 +16,11 @@ namespace body_complex { public static async ValueTask> GetValidAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("body_complex.GetValid"); scope.Start(); try @@ -43,6 +48,15 @@ namespace body_complex } public static async ValueTask PutValidAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Fish complexBody, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (complexBody == null) + { + throw new ArgumentNullException(nameof(complexBody)); + } + using var scope = clientDiagnostics.CreateScope("body_complex.PutValid"); scope.Start(); try @@ -69,6 +83,11 @@ namespace body_complex } public static async ValueTask> GetDotSyntaxAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("body_complex.GetDotSyntax"); scope.Start(); try @@ -96,6 +115,11 @@ namespace body_complex } public static async ValueTask> GetComposedWithDiscriminatorAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("body_complex.GetComposedWithDiscriminator"); scope.Start(); try @@ -123,6 +147,11 @@ namespace body_complex } public static async ValueTask> GetComposedWithoutDiscriminatorAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("body_complex.GetComposedWithoutDiscriminator"); scope.Start(); try @@ -150,6 +179,11 @@ namespace body_complex } public static async ValueTask> GetComplicatedAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("body_complex.GetComplicated"); scope.Start(); try @@ -177,6 +211,15 @@ namespace body_complex } public static async ValueTask PutComplicatedAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Salmon complexBody, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (complexBody == null) + { + throw new ArgumentNullException(nameof(complexBody)); + } + using var scope = clientDiagnostics.CreateScope("body_complex.PutComplicated"); scope.Start(); try @@ -203,6 +246,15 @@ namespace body_complex } public static async ValueTask> PutMissingDiscriminatorAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Salmon complexBody, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (complexBody == null) + { + throw new ArgumentNullException(nameof(complexBody)); + } + using var scope = clientDiagnostics.CreateScope("body_complex.PutMissingDiscriminator"); scope.Start(); try @@ -236,6 +288,15 @@ namespace body_complex } public static async ValueTask PutValidMissingRequiredAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Fish complexBody, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (complexBody == null) + { + throw new ArgumentNullException(nameof(complexBody)); + } + using var scope = clientDiagnostics.CreateScope("body_complex.PutValidMissingRequired"); scope.Start(); try diff --git a/test/TestServerProjects/body-complex/Generated/Operations/PrimitiveOperations.cs b/test/TestServerProjects/body-complex/Generated/Operations/PrimitiveOperations.cs index 1996f01b..a1f5d269 100644 --- a/test/TestServerProjects/body-complex/Generated/Operations/PrimitiveOperations.cs +++ b/test/TestServerProjects/body-complex/Generated/Operations/PrimitiveOperations.cs @@ -16,6 +16,11 @@ namespace body_complex { public static async ValueTask> GetIntAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("body_complex.GetInt"); scope.Start(); try @@ -43,6 +48,15 @@ namespace body_complex } public static async ValueTask PutIntAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, IntWrapper complexBody, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (complexBody == null) + { + throw new ArgumentNullException(nameof(complexBody)); + } + using var scope = clientDiagnostics.CreateScope("body_complex.PutInt"); scope.Start(); try @@ -69,6 +83,11 @@ namespace body_complex } public static async ValueTask> GetLongAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("body_complex.GetLong"); scope.Start(); try @@ -96,6 +115,15 @@ namespace body_complex } public static async ValueTask PutLongAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, LongWrapper complexBody, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (complexBody == null) + { + throw new ArgumentNullException(nameof(complexBody)); + } + using var scope = clientDiagnostics.CreateScope("body_complex.PutLong"); scope.Start(); try @@ -122,6 +150,11 @@ namespace body_complex } public static async ValueTask> GetFloatAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("body_complex.GetFloat"); scope.Start(); try @@ -149,6 +182,15 @@ namespace body_complex } public static async ValueTask PutFloatAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, FloatWrapper complexBody, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (complexBody == null) + { + throw new ArgumentNullException(nameof(complexBody)); + } + using var scope = clientDiagnostics.CreateScope("body_complex.PutFloat"); scope.Start(); try @@ -175,6 +217,11 @@ namespace body_complex } public static async ValueTask> GetDoubleAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("body_complex.GetDouble"); scope.Start(); try @@ -202,6 +249,15 @@ namespace body_complex } public static async ValueTask PutDoubleAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, DoubleWrapper complexBody, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (complexBody == null) + { + throw new ArgumentNullException(nameof(complexBody)); + } + using var scope = clientDiagnostics.CreateScope("body_complex.PutDouble"); scope.Start(); try @@ -228,6 +284,11 @@ namespace body_complex } public static async ValueTask> GetBoolAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("body_complex.GetBool"); scope.Start(); try @@ -255,6 +316,15 @@ namespace body_complex } public static async ValueTask PutBoolAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, BooleanWrapper complexBody, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (complexBody == null) + { + throw new ArgumentNullException(nameof(complexBody)); + } + using var scope = clientDiagnostics.CreateScope("body_complex.PutBool"); scope.Start(); try @@ -281,6 +351,11 @@ namespace body_complex } public static async ValueTask> GetStringAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("body_complex.GetString"); scope.Start(); try @@ -308,6 +383,15 @@ namespace body_complex } public static async ValueTask PutStringAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, StringWrapper complexBody, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (complexBody == null) + { + throw new ArgumentNullException(nameof(complexBody)); + } + using var scope = clientDiagnostics.CreateScope("body_complex.PutString"); scope.Start(); try @@ -334,6 +418,11 @@ namespace body_complex } public static async ValueTask> GetDateAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("body_complex.GetDate"); scope.Start(); try @@ -361,6 +450,15 @@ namespace body_complex } public static async ValueTask PutDateAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, DateWrapper complexBody, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (complexBody == null) + { + throw new ArgumentNullException(nameof(complexBody)); + } + using var scope = clientDiagnostics.CreateScope("body_complex.PutDate"); scope.Start(); try @@ -387,6 +485,11 @@ namespace body_complex } public static async ValueTask> GetDateTimeAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("body_complex.GetDateTime"); scope.Start(); try @@ -414,6 +517,15 @@ namespace body_complex } public static async ValueTask PutDateTimeAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, DatetimeWrapper complexBody, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (complexBody == null) + { + throw new ArgumentNullException(nameof(complexBody)); + } + using var scope = clientDiagnostics.CreateScope("body_complex.PutDateTime"); scope.Start(); try @@ -440,6 +552,11 @@ namespace body_complex } public static async ValueTask> GetDateTimeRfc1123Async(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("body_complex.GetDateTimeRfc1123"); scope.Start(); try @@ -467,6 +584,15 @@ namespace body_complex } public static async ValueTask PutDateTimeRfc1123Async(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Datetimerfc1123Wrapper complexBody, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (complexBody == null) + { + throw new ArgumentNullException(nameof(complexBody)); + } + using var scope = clientDiagnostics.CreateScope("body_complex.PutDateTimeRfc1123"); scope.Start(); try @@ -493,6 +619,11 @@ namespace body_complex } public static async ValueTask> GetDurationAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("body_complex.GetDuration"); scope.Start(); try @@ -520,6 +651,15 @@ namespace body_complex } public static async ValueTask PutDurationAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, DurationWrapper complexBody, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (complexBody == null) + { + throw new ArgumentNullException(nameof(complexBody)); + } + using var scope = clientDiagnostics.CreateScope("body_complex.PutDuration"); scope.Start(); try @@ -546,6 +686,11 @@ namespace body_complex } public static async ValueTask> GetByteAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("body_complex.GetByte"); scope.Start(); try @@ -573,6 +718,15 @@ namespace body_complex } public static async ValueTask PutByteAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, ByteWrapper complexBody, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (complexBody == null) + { + throw new ArgumentNullException(nameof(complexBody)); + } + using var scope = clientDiagnostics.CreateScope("body_complex.PutByte"); scope.Start(); try diff --git a/test/TestServerProjects/body-complex/Generated/Operations/ReadonlypropertyOperations.cs b/test/TestServerProjects/body-complex/Generated/Operations/ReadonlypropertyOperations.cs index fa24ea55..3f28666c 100644 --- a/test/TestServerProjects/body-complex/Generated/Operations/ReadonlypropertyOperations.cs +++ b/test/TestServerProjects/body-complex/Generated/Operations/ReadonlypropertyOperations.cs @@ -16,6 +16,11 @@ namespace body_complex { public static async ValueTask> GetValidAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("body_complex.GetValid"); scope.Start(); try @@ -43,6 +48,15 @@ namespace body_complex } public static async ValueTask PutValidAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, ReadonlyObj complexBody, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (complexBody == null) + { + throw new ArgumentNullException(nameof(complexBody)); + } + using var scope = clientDiagnostics.CreateScope("body_complex.PutValid"); scope.Start(); try diff --git a/test/TestServerProjects/body-string/Generated/Operations/EnumOperations.cs b/test/TestServerProjects/body-string/Generated/Operations/EnumOperations.cs index afaf0141..63004e26 100644 --- a/test/TestServerProjects/body-string/Generated/Operations/EnumOperations.cs +++ b/test/TestServerProjects/body-string/Generated/Operations/EnumOperations.cs @@ -16,6 +16,11 @@ namespace body_string { public static async ValueTask> GetNotExpandableAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("body_string.GetNotExpandable"); scope.Start(); try @@ -43,6 +48,11 @@ namespace body_string } public static async ValueTask PutNotExpandableAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Colors stringBody, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("body_string.PutNotExpandable"); scope.Start(); try @@ -69,6 +79,11 @@ namespace body_string } public static async ValueTask> GetReferencedAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("body_string.GetReferenced"); scope.Start(); try @@ -96,6 +111,11 @@ namespace body_string } public static async ValueTask PutReferencedAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Colors enumStringBody, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("body_string.PutReferenced"); scope.Start(); try @@ -122,6 +142,11 @@ namespace body_string } public static async ValueTask> GetReferencedConstantAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("body_string.GetReferencedConstant"); scope.Start(); try @@ -149,6 +174,15 @@ namespace body_string } public static async ValueTask PutReferencedConstantAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, RefColorConstant enumStringBody, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (enumStringBody == null) + { + throw new ArgumentNullException(nameof(enumStringBody)); + } + using var scope = clientDiagnostics.CreateScope("body_string.PutReferencedConstant"); scope.Start(); try diff --git a/test/TestServerProjects/body-string/Generated/Operations/StringOperations.cs b/test/TestServerProjects/body-string/Generated/Operations/StringOperations.cs index 3c4db2f5..64507e3f 100644 --- a/test/TestServerProjects/body-string/Generated/Operations/StringOperations.cs +++ b/test/TestServerProjects/body-string/Generated/Operations/StringOperations.cs @@ -15,6 +15,11 @@ namespace body_string { public static async ValueTask> GetNullAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("body_string.GetNull"); scope.Start(); try @@ -42,6 +47,11 @@ namespace body_string } public static async ValueTask PutNullAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("body_string.PutNull"); scope.Start(); try @@ -68,6 +78,11 @@ namespace body_string } public static async ValueTask> GetEmptyAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("body_string.GetEmpty"); scope.Start(); try @@ -95,6 +110,11 @@ namespace body_string } public static async ValueTask PutEmptyAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("body_string.PutEmpty"); scope.Start(); try @@ -121,6 +141,11 @@ namespace body_string } public static async ValueTask> GetMbcsAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("body_string.GetMbcs"); scope.Start(); try @@ -148,6 +173,11 @@ namespace body_string } public static async ValueTask PutMbcsAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("body_string.PutMbcs"); scope.Start(); try @@ -174,6 +204,11 @@ namespace body_string } public static async ValueTask> GetWhitespaceAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("body_string.GetWhitespace"); scope.Start(); try @@ -201,6 +236,11 @@ namespace body_string } public static async ValueTask PutWhitespaceAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("body_string.PutWhitespace"); scope.Start(); try @@ -227,6 +267,11 @@ namespace body_string } public static async ValueTask> GetNotProvidedAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("body_string.GetNotProvided"); scope.Start(); try @@ -254,6 +299,11 @@ namespace body_string } public static async ValueTask> GetBase64EncodedAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("body_string.GetBase64Encoded"); scope.Start(); try @@ -281,6 +331,11 @@ namespace body_string } public static async ValueTask> GetBase64UrlEncodedAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("body_string.GetBase64UrlEncoded"); scope.Start(); try @@ -308,6 +363,15 @@ namespace body_string } public static async ValueTask PutBase64UrlEncodedAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Byte[] stringBody, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (stringBody == null) + { + throw new ArgumentNullException(nameof(stringBody)); + } + using var scope = clientDiagnostics.CreateScope("body_string.PutBase64UrlEncoded"); scope.Start(); try @@ -334,6 +398,11 @@ namespace body_string } public static async ValueTask> GetNullBase64UrlEncodedAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("body_string.GetNullBase64UrlEncoded"); scope.Start(); try diff --git a/test/TestServerProjects/custom-baseUrl-more-options/Generated/Operations/PathsOperations.cs b/test/TestServerProjects/custom-baseUrl-more-options/Generated/Operations/PathsOperations.cs index 9118e2ca..aaf6732d 100644 --- a/test/TestServerProjects/custom-baseUrl-more-options/Generated/Operations/PathsOperations.cs +++ b/test/TestServerProjects/custom-baseUrl-more-options/Generated/Operations/PathsOperations.cs @@ -14,6 +14,27 @@ namespace custom_baseUrl_more_options { public static async ValueTask GetEmptyAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string vault, string secret, string keyName, string subscriptionId, string? keyVersion, string dnsSuffix = "host", CancellationToken cancellationToken = default) { + if (vault == null) + { + throw new ArgumentNullException(nameof(vault)); + } + if (secret == null) + { + throw new ArgumentNullException(nameof(secret)); + } + if (dnsSuffix == null) + { + throw new ArgumentNullException(nameof(dnsSuffix)); + } + if (keyName == null) + { + throw new ArgumentNullException(nameof(keyName)); + } + if (subscriptionId == null) + { + throw new ArgumentNullException(nameof(subscriptionId)); + } + using var scope = clientDiagnostics.CreateScope("custom_baseUrl_more_options.GetEmpty"); scope.Start(); try diff --git a/test/TestServerProjects/custom-baseUrl/Generated/Operations/PathsOperations.cs b/test/TestServerProjects/custom-baseUrl/Generated/Operations/PathsOperations.cs index 7e2f9810..d0973ed1 100644 --- a/test/TestServerProjects/custom-baseUrl/Generated/Operations/PathsOperations.cs +++ b/test/TestServerProjects/custom-baseUrl/Generated/Operations/PathsOperations.cs @@ -14,6 +14,15 @@ namespace custom_baseUrl { public static async ValueTask GetEmptyAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string accountName, string host = "host", CancellationToken cancellationToken = default) { + if (accountName == null) + { + throw new ArgumentNullException(nameof(accountName)); + } + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("custom_baseUrl.GetEmpty"); scope.Start(); try diff --git a/test/TestServerProjects/extensible-enums-swagger/Generated/Operations/PetOperations.cs b/test/TestServerProjects/extensible-enums-swagger/Generated/Operations/PetOperations.cs index 46cdde4b..a33f82b5 100644 --- a/test/TestServerProjects/extensible-enums-swagger/Generated/Operations/PetOperations.cs +++ b/test/TestServerProjects/extensible-enums-swagger/Generated/Operations/PetOperations.cs @@ -16,6 +16,15 @@ namespace extensible_enums_swagger { public static async ValueTask> GetByPetIdAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string petId, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (petId == null) + { + throw new ArgumentNullException(nameof(petId)); + } + using var scope = clientDiagnostics.CreateScope("extensible_enums_swagger.GetByPetId"); scope.Start(); try @@ -44,6 +53,11 @@ namespace extensible_enums_swagger } public static async ValueTask> AddPetAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Pet? petParam, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("extensible_enums_swagger.AddPet"); scope.Start(); try diff --git a/test/TestServerProjects/header/Generated/Operations/HeaderOperations.cs b/test/TestServerProjects/header/Generated/Operations/HeaderOperations.cs index d001b842..a79cfe4c 100644 --- a/test/TestServerProjects/header/Generated/Operations/HeaderOperations.cs +++ b/test/TestServerProjects/header/Generated/Operations/HeaderOperations.cs @@ -15,6 +15,15 @@ namespace header { public static async ValueTask ParamExistingKeyAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string userAgent, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (userAgent == null) + { + throw new ArgumentNullException(nameof(userAgent)); + } + using var scope = clientDiagnostics.CreateScope("header.ParamExistingKey"); scope.Start(); try @@ -36,6 +45,11 @@ namespace header } public static async ValueTask ResponseExistingKeyAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("header.ResponseExistingKey"); scope.Start(); try @@ -56,6 +70,15 @@ namespace header } public static async ValueTask ParamProtectedKeyAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string contentType, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (contentType == null) + { + throw new ArgumentNullException(nameof(contentType)); + } + using var scope = clientDiagnostics.CreateScope("header.ParamProtectedKey"); scope.Start(); try @@ -77,6 +100,11 @@ namespace header } public static async ValueTask ResponseProtectedKeyAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("header.ResponseProtectedKey"); scope.Start(); try @@ -97,6 +125,15 @@ namespace header } public static async ValueTask ParamIntegerAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string scenario, int value, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (scenario == null) + { + throw new ArgumentNullException(nameof(scenario)); + } + using var scope = clientDiagnostics.CreateScope("header.ParamInteger"); scope.Start(); try @@ -119,6 +156,15 @@ namespace header } public static async ValueTask ResponseIntegerAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string scenario, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (scenario == null) + { + throw new ArgumentNullException(nameof(scenario)); + } + using var scope = clientDiagnostics.CreateScope("header.ResponseInteger"); scope.Start(); try @@ -140,6 +186,15 @@ namespace header } public static async ValueTask ParamLongAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string scenario, long value, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (scenario == null) + { + throw new ArgumentNullException(nameof(scenario)); + } + using var scope = clientDiagnostics.CreateScope("header.ParamLong"); scope.Start(); try @@ -162,6 +217,15 @@ namespace header } public static async ValueTask ResponseLongAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string scenario, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (scenario == null) + { + throw new ArgumentNullException(nameof(scenario)); + } + using var scope = clientDiagnostics.CreateScope("header.ResponseLong"); scope.Start(); try @@ -183,6 +247,15 @@ namespace header } public static async ValueTask ParamFloatAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string scenario, float value, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (scenario == null) + { + throw new ArgumentNullException(nameof(scenario)); + } + using var scope = clientDiagnostics.CreateScope("header.ParamFloat"); scope.Start(); try @@ -205,6 +278,15 @@ namespace header } public static async ValueTask ResponseFloatAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string scenario, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (scenario == null) + { + throw new ArgumentNullException(nameof(scenario)); + } + using var scope = clientDiagnostics.CreateScope("header.ResponseFloat"); scope.Start(); try @@ -226,6 +308,15 @@ namespace header } public static async ValueTask ParamDoubleAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string scenario, double value, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (scenario == null) + { + throw new ArgumentNullException(nameof(scenario)); + } + using var scope = clientDiagnostics.CreateScope("header.ParamDouble"); scope.Start(); try @@ -248,6 +339,15 @@ namespace header } public static async ValueTask ResponseDoubleAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string scenario, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (scenario == null) + { + throw new ArgumentNullException(nameof(scenario)); + } + using var scope = clientDiagnostics.CreateScope("header.ResponseDouble"); scope.Start(); try @@ -269,6 +369,15 @@ namespace header } public static async ValueTask ParamBoolAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string scenario, bool value, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (scenario == null) + { + throw new ArgumentNullException(nameof(scenario)); + } + using var scope = clientDiagnostics.CreateScope("header.ParamBool"); scope.Start(); try @@ -291,6 +400,15 @@ namespace header } public static async ValueTask ResponseBoolAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string scenario, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (scenario == null) + { + throw new ArgumentNullException(nameof(scenario)); + } + using var scope = clientDiagnostics.CreateScope("header.ResponseBool"); scope.Start(); try @@ -312,6 +430,15 @@ namespace header } public static async ValueTask ParamStringAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string scenario, string? value, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (scenario == null) + { + throw new ArgumentNullException(nameof(scenario)); + } + using var scope = clientDiagnostics.CreateScope("header.ParamString"); scope.Start(); try @@ -337,6 +464,15 @@ namespace header } public static async ValueTask ResponseStringAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string scenario, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (scenario == null) + { + throw new ArgumentNullException(nameof(scenario)); + } + using var scope = clientDiagnostics.CreateScope("header.ResponseString"); scope.Start(); try @@ -358,6 +494,15 @@ namespace header } public static async ValueTask ParamDateAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string scenario, DateTimeOffset value, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (scenario == null) + { + throw new ArgumentNullException(nameof(scenario)); + } + using var scope = clientDiagnostics.CreateScope("header.ParamDate"); scope.Start(); try @@ -380,6 +525,15 @@ namespace header } public static async ValueTask ResponseDateAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string scenario, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (scenario == null) + { + throw new ArgumentNullException(nameof(scenario)); + } + using var scope = clientDiagnostics.CreateScope("header.ResponseDate"); scope.Start(); try @@ -401,6 +555,15 @@ namespace header } public static async ValueTask ParamDatetimeAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string scenario, DateTimeOffset value, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (scenario == null) + { + throw new ArgumentNullException(nameof(scenario)); + } + using var scope = clientDiagnostics.CreateScope("header.ParamDatetime"); scope.Start(); try @@ -423,6 +586,15 @@ namespace header } public static async ValueTask ResponseDatetimeAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string scenario, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (scenario == null) + { + throw new ArgumentNullException(nameof(scenario)); + } + using var scope = clientDiagnostics.CreateScope("header.ResponseDatetime"); scope.Start(); try @@ -444,6 +616,15 @@ namespace header } public static async ValueTask ParamDatetimeRfc1123Async(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string scenario, DateTimeOffset? value, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (scenario == null) + { + throw new ArgumentNullException(nameof(scenario)); + } + using var scope = clientDiagnostics.CreateScope("header.ParamDatetimeRfc1123"); scope.Start(); try @@ -469,6 +650,15 @@ namespace header } public static async ValueTask ResponseDatetimeRfc1123Async(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string scenario, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (scenario == null) + { + throw new ArgumentNullException(nameof(scenario)); + } + using var scope = clientDiagnostics.CreateScope("header.ResponseDatetimeRfc1123"); scope.Start(); try @@ -490,6 +680,15 @@ namespace header } public static async ValueTask ParamDurationAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string scenario, TimeSpan value, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (scenario == null) + { + throw new ArgumentNullException(nameof(scenario)); + } + using var scope = clientDiagnostics.CreateScope("header.ParamDuration"); scope.Start(); try @@ -512,6 +711,15 @@ namespace header } public static async ValueTask ResponseDurationAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string scenario, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (scenario == null) + { + throw new ArgumentNullException(nameof(scenario)); + } + using var scope = clientDiagnostics.CreateScope("header.ResponseDuration"); scope.Start(); try @@ -533,6 +741,19 @@ namespace header } public static async ValueTask ParamByteAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string scenario, Byte[] value, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (scenario == null) + { + throw new ArgumentNullException(nameof(scenario)); + } + if (value == null) + { + throw new ArgumentNullException(nameof(value)); + } + using var scope = clientDiagnostics.CreateScope("header.ParamByte"); scope.Start(); try @@ -555,6 +776,15 @@ namespace header } public static async ValueTask ResponseByteAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string scenario, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (scenario == null) + { + throw new ArgumentNullException(nameof(scenario)); + } + using var scope = clientDiagnostics.CreateScope("header.ResponseByte"); scope.Start(); try @@ -576,6 +806,15 @@ namespace header } public static async ValueTask ParamEnumAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string scenario, GreyscaleColors? value, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (scenario == null) + { + throw new ArgumentNullException(nameof(scenario)); + } + using var scope = clientDiagnostics.CreateScope("header.ParamEnum"); scope.Start(); try @@ -601,6 +840,15 @@ namespace header } public static async ValueTask ResponseEnumAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string scenario, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (scenario == null) + { + throw new ArgumentNullException(nameof(scenario)); + } + using var scope = clientDiagnostics.CreateScope("header.ResponseEnum"); scope.Start(); try @@ -622,6 +870,11 @@ namespace header } public static async ValueTask CustomRequestIdAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("header.CustomRequestId"); scope.Start(); try diff --git a/test/TestServerProjects/url-multi-collectionFormat/Generated/Operations/QueriesOperations.cs b/test/TestServerProjects/url-multi-collectionFormat/Generated/Operations/QueriesOperations.cs index 5e2cf0d4..12998787 100644 --- a/test/TestServerProjects/url-multi-collectionFormat/Generated/Operations/QueriesOperations.cs +++ b/test/TestServerProjects/url-multi-collectionFormat/Generated/Operations/QueriesOperations.cs @@ -15,6 +15,11 @@ namespace url_multi_collectionFormat { public static async ValueTask ArrayStringMultiNullAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, IEnumerable arrayQuery, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("url_multi_collectionFormat.ArrayStringMultiNull"); scope.Start(); try @@ -39,6 +44,11 @@ namespace url_multi_collectionFormat } public static async ValueTask ArrayStringMultiEmptyAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, IEnumerable arrayQuery, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("url_multi_collectionFormat.ArrayStringMultiEmpty"); scope.Start(); try @@ -63,6 +73,11 @@ namespace url_multi_collectionFormat } public static async ValueTask ArrayStringMultiValidAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, IEnumerable arrayQuery, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("url_multi_collectionFormat.ArrayStringMultiValid"); scope.Start(); try diff --git a/test/TestServerProjects/url/Generated/Operations/PathItemsOperations.cs b/test/TestServerProjects/url/Generated/Operations/PathItemsOperations.cs index 70b0bfb5..a3ae1478 100644 --- a/test/TestServerProjects/url/Generated/Operations/PathItemsOperations.cs +++ b/test/TestServerProjects/url/Generated/Operations/PathItemsOperations.cs @@ -14,6 +14,23 @@ namespace url { public static async ValueTask GetAllWithValuesAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string pathItemStringPath, string? pathItemStringQuery, string globalStringPath, string? globalStringQuery, string localStringPath, string? localStringQuery, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (pathItemStringPath == null) + { + throw new ArgumentNullException(nameof(pathItemStringPath)); + } + if (globalStringPath == null) + { + throw new ArgumentNullException(nameof(globalStringPath)); + } + if (localStringPath == null) + { + throw new ArgumentNullException(nameof(localStringPath)); + } + using var scope = clientDiagnostics.CreateScope("url.GetAllWithValues"); scope.Start(); try @@ -52,6 +69,23 @@ namespace url } public static async ValueTask GetGlobalQueryNullAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string pathItemStringPath, string? pathItemStringQuery, string globalStringPath, string? globalStringQuery, string localStringPath, string? localStringQuery, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (pathItemStringPath == null) + { + throw new ArgumentNullException(nameof(pathItemStringPath)); + } + if (globalStringPath == null) + { + throw new ArgumentNullException(nameof(globalStringPath)); + } + if (localStringPath == null) + { + throw new ArgumentNullException(nameof(localStringPath)); + } + using var scope = clientDiagnostics.CreateScope("url.GetGlobalQueryNull"); scope.Start(); try @@ -90,6 +124,23 @@ namespace url } public static async ValueTask GetGlobalAndLocalQueryNullAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string pathItemStringPath, string? pathItemStringQuery, string globalStringPath, string? globalStringQuery, string localStringPath, string? localStringQuery, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (pathItemStringPath == null) + { + throw new ArgumentNullException(nameof(pathItemStringPath)); + } + if (globalStringPath == null) + { + throw new ArgumentNullException(nameof(globalStringPath)); + } + if (localStringPath == null) + { + throw new ArgumentNullException(nameof(localStringPath)); + } + using var scope = clientDiagnostics.CreateScope("url.GetGlobalAndLocalQueryNull"); scope.Start(); try @@ -128,6 +179,23 @@ namespace url } public static async ValueTask GetLocalPathItemQueryNullAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string pathItemStringPath, string? pathItemStringQuery, string globalStringPath, string? globalStringQuery, string localStringPath, string? localStringQuery, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (pathItemStringPath == null) + { + throw new ArgumentNullException(nameof(pathItemStringPath)); + } + if (globalStringPath == null) + { + throw new ArgumentNullException(nameof(globalStringPath)); + } + if (localStringPath == null) + { + throw new ArgumentNullException(nameof(localStringPath)); + } + using var scope = clientDiagnostics.CreateScope("url.GetLocalPathItemQueryNull"); scope.Start(); try diff --git a/test/TestServerProjects/url/Generated/Operations/PathsOperations.cs b/test/TestServerProjects/url/Generated/Operations/PathsOperations.cs index 59f3f24d..ed2fc95b 100644 --- a/test/TestServerProjects/url/Generated/Operations/PathsOperations.cs +++ b/test/TestServerProjects/url/Generated/Operations/PathsOperations.cs @@ -16,6 +16,11 @@ namespace url { public static async ValueTask GetBooleanTrueAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("url.GetBooleanTrue"); scope.Start(); try @@ -37,6 +42,11 @@ namespace url } public static async ValueTask GetBooleanFalseAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("url.GetBooleanFalse"); scope.Start(); try @@ -58,6 +68,11 @@ namespace url } public static async ValueTask GetIntOneMillionAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("url.GetIntOneMillion"); scope.Start(); try @@ -79,6 +94,11 @@ namespace url } public static async ValueTask GetIntNegativeOneMillionAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("url.GetIntNegativeOneMillion"); scope.Start(); try @@ -100,6 +120,11 @@ namespace url } public static async ValueTask GetTenBillionAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("url.GetTenBillion"); scope.Start(); try @@ -121,6 +146,11 @@ namespace url } public static async ValueTask GetNegativeTenBillionAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("url.GetNegativeTenBillion"); scope.Start(); try @@ -142,6 +172,11 @@ namespace url } public static async ValueTask FloatScientificPositiveAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("url.FloatScientificPositive"); scope.Start(); try @@ -163,6 +198,11 @@ namespace url } public static async ValueTask FloatScientificNegativeAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("url.FloatScientificNegative"); scope.Start(); try @@ -184,6 +224,11 @@ namespace url } public static async ValueTask DoubleDecimalPositiveAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("url.DoubleDecimalPositive"); scope.Start(); try @@ -205,6 +250,11 @@ namespace url } public static async ValueTask DoubleDecimalNegativeAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("url.DoubleDecimalNegative"); scope.Start(); try @@ -226,6 +276,11 @@ namespace url } public static async ValueTask StringUnicodeAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("url.StringUnicode"); scope.Start(); try @@ -247,6 +302,11 @@ namespace url } public static async ValueTask StringUrlEncodedAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("url.StringUrlEncoded"); scope.Start(); try @@ -268,6 +328,11 @@ namespace url } public static async ValueTask StringEmptyAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("url.StringEmpty"); scope.Start(); try @@ -289,6 +354,15 @@ namespace url } public static async ValueTask StringNullAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string stringPath, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (stringPath == null) + { + throw new ArgumentNullException(nameof(stringPath)); + } + using var scope = clientDiagnostics.CreateScope("url.StringNull"); scope.Start(); try @@ -310,6 +384,11 @@ namespace url } public static async ValueTask EnumValidAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, UriColor enumPath, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("url.EnumValid"); scope.Start(); try @@ -331,6 +410,11 @@ namespace url } public static async ValueTask EnumNullAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, UriColor enumPath, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("url.EnumNull"); scope.Start(); try @@ -352,6 +436,15 @@ namespace url } public static async ValueTask ByteMultiByteAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Byte[] bytePath, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (bytePath == null) + { + throw new ArgumentNullException(nameof(bytePath)); + } + using var scope = clientDiagnostics.CreateScope("url.ByteMultiByte"); scope.Start(); try @@ -373,6 +466,11 @@ namespace url } public static async ValueTask ByteEmptyAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("url.ByteEmpty"); scope.Start(); try @@ -394,6 +492,15 @@ namespace url } public static async ValueTask ByteNullAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Byte[] bytePath, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (bytePath == null) + { + throw new ArgumentNullException(nameof(bytePath)); + } + using var scope = clientDiagnostics.CreateScope("url.ByteNull"); scope.Start(); try @@ -415,6 +522,11 @@ namespace url } public static async ValueTask DateValidAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("url.DateValid"); scope.Start(); try @@ -436,6 +548,11 @@ namespace url } public static async ValueTask DateNullAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, DateTimeOffset datePath, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("url.DateNull"); scope.Start(); try @@ -457,6 +574,11 @@ namespace url } public static async ValueTask DateTimeValidAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("url.DateTimeValid"); scope.Start(); try @@ -478,6 +600,11 @@ namespace url } public static async ValueTask DateTimeNullAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, DateTimeOffset dateTimePath, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("url.DateTimeNull"); scope.Start(); try @@ -499,6 +626,15 @@ namespace url } public static async ValueTask Base64UrlAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Byte[] base64UrlPath, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (base64UrlPath == null) + { + throw new ArgumentNullException(nameof(base64UrlPath)); + } + using var scope = clientDiagnostics.CreateScope("url.Base64Url"); scope.Start(); try @@ -520,6 +656,15 @@ namespace url } public static async ValueTask ArrayCsvInPathAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, IEnumerable arrayPath, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (arrayPath == null) + { + throw new ArgumentNullException(nameof(arrayPath)); + } + using var scope = clientDiagnostics.CreateScope("url.ArrayCsvInPath"); scope.Start(); try @@ -541,6 +686,11 @@ namespace url } public static async ValueTask UnixTimeUrlAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, DateTimeOffset unixTimeUrlPath, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("url.UnixTimeUrl"); scope.Start(); try diff --git a/test/TestServerProjects/url/Generated/Operations/QueriesOperations.cs b/test/TestServerProjects/url/Generated/Operations/QueriesOperations.cs index 8b8b6e5f..fc70a5e0 100644 --- a/test/TestServerProjects/url/Generated/Operations/QueriesOperations.cs +++ b/test/TestServerProjects/url/Generated/Operations/QueriesOperations.cs @@ -16,6 +16,11 @@ namespace url { public static async ValueTask GetBooleanTrueAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("url.GetBooleanTrue"); scope.Start(); try @@ -37,6 +42,11 @@ namespace url } public static async ValueTask GetBooleanFalseAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("url.GetBooleanFalse"); scope.Start(); try @@ -58,6 +68,11 @@ namespace url } public static async ValueTask GetBooleanNullAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, bool? boolQuery, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("url.GetBooleanNull"); scope.Start(); try @@ -82,6 +97,11 @@ namespace url } public static async ValueTask GetIntOneMillionAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("url.GetIntOneMillion"); scope.Start(); try @@ -103,6 +123,11 @@ namespace url } public static async ValueTask GetIntNegativeOneMillionAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("url.GetIntNegativeOneMillion"); scope.Start(); try @@ -124,6 +149,11 @@ namespace url } public static async ValueTask GetIntNullAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, int? intQuery, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("url.GetIntNull"); scope.Start(); try @@ -148,6 +178,11 @@ namespace url } public static async ValueTask GetTenBillionAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("url.GetTenBillion"); scope.Start(); try @@ -169,6 +204,11 @@ namespace url } public static async ValueTask GetNegativeTenBillionAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("url.GetNegativeTenBillion"); scope.Start(); try @@ -190,6 +230,11 @@ namespace url } public static async ValueTask GetLongNullAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, long? longQuery, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("url.GetLongNull"); scope.Start(); try @@ -214,6 +259,11 @@ namespace url } public static async ValueTask FloatScientificPositiveAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("url.FloatScientificPositive"); scope.Start(); try @@ -235,6 +285,11 @@ namespace url } public static async ValueTask FloatScientificNegativeAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("url.FloatScientificNegative"); scope.Start(); try @@ -256,6 +311,11 @@ namespace url } public static async ValueTask FloatNullAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, float? floatQuery, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("url.FloatNull"); scope.Start(); try @@ -280,6 +340,11 @@ namespace url } public static async ValueTask DoubleDecimalPositiveAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("url.DoubleDecimalPositive"); scope.Start(); try @@ -301,6 +366,11 @@ namespace url } public static async ValueTask DoubleDecimalNegativeAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("url.DoubleDecimalNegative"); scope.Start(); try @@ -322,6 +392,11 @@ namespace url } public static async ValueTask DoubleNullAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, double? doubleQuery, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("url.DoubleNull"); scope.Start(); try @@ -346,6 +421,11 @@ namespace url } public static async ValueTask StringUnicodeAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("url.StringUnicode"); scope.Start(); try @@ -367,6 +447,11 @@ namespace url } public static async ValueTask StringUrlEncodedAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("url.StringUrlEncoded"); scope.Start(); try @@ -388,6 +473,11 @@ namespace url } public static async ValueTask StringEmptyAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("url.StringEmpty"); scope.Start(); try @@ -409,6 +499,11 @@ namespace url } public static async ValueTask StringNullAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string? stringQuery, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("url.StringNull"); scope.Start(); try @@ -433,6 +528,11 @@ namespace url } public static async ValueTask EnumValidAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, UriColor? enumQuery, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("url.EnumValid"); scope.Start(); try @@ -457,6 +557,11 @@ namespace url } public static async ValueTask EnumNullAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, UriColor? enumQuery, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("url.EnumNull"); scope.Start(); try @@ -481,6 +586,11 @@ namespace url } public static async ValueTask ByteMultiByteAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Byte[]? byteQuery, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("url.ByteMultiByte"); scope.Start(); try @@ -505,6 +615,11 @@ namespace url } public static async ValueTask ByteEmptyAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("url.ByteEmpty"); scope.Start(); try @@ -526,6 +641,11 @@ namespace url } public static async ValueTask ByteNullAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Byte[]? byteQuery, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("url.ByteNull"); scope.Start(); try @@ -550,6 +670,11 @@ namespace url } public static async ValueTask DateValidAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("url.DateValid"); scope.Start(); try @@ -571,6 +696,11 @@ namespace url } public static async ValueTask DateNullAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, DateTimeOffset? dateQuery, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("url.DateNull"); scope.Start(); try @@ -595,6 +725,11 @@ namespace url } public static async ValueTask DateTimeValidAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("url.DateTimeValid"); scope.Start(); try @@ -616,6 +751,11 @@ namespace url } public static async ValueTask DateTimeNullAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, DateTimeOffset? dateTimeQuery, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("url.DateTimeNull"); scope.Start(); try @@ -640,6 +780,11 @@ namespace url } public static async ValueTask ArrayStringCsvValidAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, IEnumerable arrayQuery, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("url.ArrayStringCsvValid"); scope.Start(); try @@ -664,6 +809,11 @@ namespace url } public static async ValueTask ArrayStringCsvNullAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, IEnumerable arrayQuery, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("url.ArrayStringCsvNull"); scope.Start(); try @@ -688,6 +838,11 @@ namespace url } public static async ValueTask ArrayStringCsvEmptyAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, IEnumerable arrayQuery, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("url.ArrayStringCsvEmpty"); scope.Start(); try @@ -712,6 +867,11 @@ namespace url } public static async ValueTask ArrayStringSsvValidAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, IEnumerable arrayQuery, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("url.ArrayStringSsvValid"); scope.Start(); try @@ -736,6 +896,11 @@ namespace url } public static async ValueTask ArrayStringTsvValidAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, IEnumerable arrayQuery, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("url.ArrayStringTsvValid"); scope.Start(); try @@ -760,6 +925,11 @@ namespace url } public static async ValueTask ArrayStringPipesValidAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, IEnumerable arrayQuery, string host = "http://localhost:3000", CancellationToken cancellationToken = default) { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + using var scope = clientDiagnostics.CreateScope("url.ArrayStringPipesValid"); scope.Start(); try From ca6e9482619f048decfb902f73fbbbf222e04e52 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Wed, 11 Dec 2019 12:49:00 -0800 Subject: [PATCH 3/5] Simplify JSON request body writing (#333) * Simplify JSON request body writing * Generated * Additional files --- .../CodeGen/ClientWriter.cs | 10 +- .../Utf8JsonRequestContent.cs | 47 +++++++++ .../Generated/Operations/ArrayOperations.cs | 19 ++-- .../Generated/Operations/BasicOperations.cs | 13 +-- .../Operations/DictionaryOperations.cs | 20 ++-- .../Operations/FlattencomplexOperations.cs | 1 - .../Operations/InheritanceOperations.cs | 9 +- .../PolymorphicrecursiveOperations.cs | 9 +- .../Operations/PolymorphismOperations.cs | 37 +++---- .../Operations/PrimitiveOperations.cs | 99 +++++++------------ .../Operations/ReadonlypropertyOperations.cs | 9 +- .../Generated/Operations/EnumOperations.cs | 27 ++--- .../Generated/Operations/StringOperations.cs | 48 +++------ .../Generated/Operations/PathsOperations.cs | 1 - .../Generated/Operations/PathsOperations.cs | 1 - .../Generated/Operations/PetOperations.cs | 9 +- .../Generated/Operations/HeaderOperations.cs | 29 ------ .../Generated/Operations/QueriesOperations.cs | 3 - .../Operations/PathItemsOperations.cs | 4 - .../Generated/Operations/PathsOperations.cs | 26 ----- .../Generated/Operations/QueriesOperations.cs | 34 ------- 21 files changed, 146 insertions(+), 309 deletions(-) create mode 100644 src/assets/Azure.Core.Shared/Utf8JsonRequestContent.cs diff --git a/src/AutoRest.CSharp.V3/CodeGen/ClientWriter.cs b/src/AutoRest.CSharp.V3/CodeGen/ClientWriter.cs index 8eabfff4..4e6821c5 100644 --- a/src/AutoRest.CSharp.V3/CodeGen/ClientWriter.cs +++ b/src/AutoRest.CSharp.V3/CodeGen/ClientWriter.cs @@ -107,21 +107,17 @@ namespace AutoRest.CSharp.V3.CodeGen if (operation.Request.Body is ConstantOrParameter body) { - var bufferWriter = new CSharpType(typeof(ArrayBufferWriter<>), new CSharpType(typeof(byte))); - - writer.Line($"var buffer = new {writer.Type(bufferWriter)}();"); - writer.Line($"await using var writer = new {writer.Type(typeof(Utf8JsonWriter))}(buffer);"); + writer.Line($"using var content = new {writer.Type(typeof(Utf8JsonRequestContent))}();"); + writer.Line($"var writer = content.{nameof(Utf8JsonRequestContent.JsonWriter)};"); var type = body.IsConstant ? body.Constant.Type : body.Parameter.Type; var name = body.IsConstant ? body.Constant.ToValueString() : body.Parameter.Name; writer.ToSerializeCall(type, _typeFactory, name, string.Empty, false); - writer.Line("writer.Flush();"); - writer.Line("request.Content = RequestContent.Create(buffer.WrittenMemory);"); + writer.Line("request.Content = content;"); } writer.Line("var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);"); - writer.Line("cancellationToken.ThrowIfCancellationRequested();"); if (schemaResponse != null && responseType != null) { diff --git a/src/assets/Azure.Core.Shared/Utf8JsonRequestContent.cs b/src/assets/Azure.Core.Shared/Utf8JsonRequestContent.cs new file mode 100644 index 00000000..7664164d --- /dev/null +++ b/src/assets/Azure.Core.Shared/Utf8JsonRequestContent.cs @@ -0,0 +1,47 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System.IO; +using System.Text.Json; +using System.Threading; +using System.Threading.Tasks; + +namespace Azure.Core +{ + internal class Utf8JsonRequestContent: RequestContent + { + private readonly ArrayBufferWriter _writer; + + public Utf8JsonRequestContent() + { + _writer = new ArrayBufferWriter(); + JsonWriter = new Utf8JsonWriter(_writer); + } + + public Utf8JsonWriter JsonWriter { get; } + + public override async Task WriteToAsync(Stream stream, CancellationToken cancellation) + { + await JsonWriter.FlushAsync(cancellation); + using var content = Create(_writer.WrittenMemory); + await content.WriteToAsync(stream, cancellation); + } + + public override void WriteTo(Stream stream, CancellationToken cancellation) + { + JsonWriter.Flush(); + using var content = Create(_writer.WrittenMemory); + content.WriteTo(stream, cancellation); + } + + public override bool TryComputeLength(out long length) + { + length = JsonWriter.BytesCommitted + JsonWriter.BytesPending; + return true; + } + + public override void Dispose() + { + } + } +} diff --git a/test/TestServerProjects/body-complex/Generated/Operations/ArrayOperations.cs b/test/TestServerProjects/body-complex/Generated/Operations/ArrayOperations.cs index 10a6cfe1..657d1133 100644 --- a/test/TestServerProjects/body-complex/Generated/Operations/ArrayOperations.cs +++ b/test/TestServerProjects/body-complex/Generated/Operations/ArrayOperations.cs @@ -30,7 +30,6 @@ namespace body_complex request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/complex/array/valid", false); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); switch (response.Status) { @@ -66,13 +65,11 @@ namespace body_complex request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/complex/array/valid", false); request.Headers.Add("Content-Type", "application/json"); - var buffer = new ArrayBufferWriter(); - await using var writer = new Utf8JsonWriter(buffer); + using var content = new Utf8JsonRequestContent(); + var writer = content.JsonWriter; complexBody.Serialize(writer); - writer.Flush(); - request.Content = RequestContent.Create(buffer.WrittenMemory); + request.Content = content; var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -97,7 +94,6 @@ namespace body_complex request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/complex/array/empty", false); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); switch (response.Status) { @@ -133,13 +129,11 @@ namespace body_complex request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/complex/array/empty", false); request.Headers.Add("Content-Type", "application/json"); - var buffer = new ArrayBufferWriter(); - await using var writer = new Utf8JsonWriter(buffer); + using var content = new Utf8JsonRequestContent(); + var writer = content.JsonWriter; complexBody.Serialize(writer); - writer.Flush(); - request.Content = RequestContent.Create(buffer.WrittenMemory); + request.Content = content; var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -164,7 +158,6 @@ namespace body_complex request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/complex/array/notprovided", false); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); switch (response.Status) { diff --git a/test/TestServerProjects/body-complex/Generated/Operations/BasicOperations.cs b/test/TestServerProjects/body-complex/Generated/Operations/BasicOperations.cs index 20c84813..8776900c 100644 --- a/test/TestServerProjects/body-complex/Generated/Operations/BasicOperations.cs +++ b/test/TestServerProjects/body-complex/Generated/Operations/BasicOperations.cs @@ -30,7 +30,6 @@ namespace body_complex request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/complex/basic/valid", false); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); switch (response.Status) { @@ -67,13 +66,11 @@ namespace body_complex request.Uri.AppendPath("/complex/basic/valid", false); request.Headers.Add("Content-Type", "application/json"); request.Uri.AppendQuery("api-version", "2016-02-29", true); - var buffer = new ArrayBufferWriter(); - await using var writer = new Utf8JsonWriter(buffer); + using var content = new Utf8JsonRequestContent(); + var writer = content.JsonWriter; complexBody.Serialize(writer); - writer.Flush(); - request.Content = RequestContent.Create(buffer.WrittenMemory); + request.Content = content; var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -98,7 +95,6 @@ namespace body_complex request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/complex/basic/invalid", false); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); switch (response.Status) { @@ -130,7 +126,6 @@ namespace body_complex request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/complex/basic/empty", false); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); switch (response.Status) { @@ -162,7 +157,6 @@ namespace body_complex request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/complex/basic/null", false); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); switch (response.Status) { @@ -194,7 +188,6 @@ namespace body_complex request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/complex/basic/notprovided", false); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); switch (response.Status) { diff --git a/test/TestServerProjects/body-complex/Generated/Operations/DictionaryOperations.cs b/test/TestServerProjects/body-complex/Generated/Operations/DictionaryOperations.cs index d0254888..4d9f895e 100644 --- a/test/TestServerProjects/body-complex/Generated/Operations/DictionaryOperations.cs +++ b/test/TestServerProjects/body-complex/Generated/Operations/DictionaryOperations.cs @@ -30,7 +30,6 @@ namespace body_complex request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/complex/dictionary/typed/valid", false); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); switch (response.Status) { @@ -66,13 +65,11 @@ namespace body_complex request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/complex/dictionary/typed/valid", false); request.Headers.Add("Content-Type", "application/json"); - var buffer = new ArrayBufferWriter(); - await using var writer = new Utf8JsonWriter(buffer); + using var content = new Utf8JsonRequestContent(); + var writer = content.JsonWriter; complexBody.Serialize(writer); - writer.Flush(); - request.Content = RequestContent.Create(buffer.WrittenMemory); + request.Content = content; var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -97,7 +94,6 @@ namespace body_complex request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/complex/dictionary/typed/empty", false); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); switch (response.Status) { @@ -133,13 +129,11 @@ namespace body_complex request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/complex/dictionary/typed/empty", false); request.Headers.Add("Content-Type", "application/json"); - var buffer = new ArrayBufferWriter(); - await using var writer = new Utf8JsonWriter(buffer); + using var content = new Utf8JsonRequestContent(); + var writer = content.JsonWriter; complexBody.Serialize(writer); - writer.Flush(); - request.Content = RequestContent.Create(buffer.WrittenMemory); + request.Content = content; var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -164,7 +158,6 @@ namespace body_complex request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/complex/dictionary/typed/null", false); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); switch (response.Status) { @@ -196,7 +189,6 @@ namespace body_complex request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/complex/dictionary/typed/notprovided", false); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); switch (response.Status) { diff --git a/test/TestServerProjects/body-complex/Generated/Operations/FlattencomplexOperations.cs b/test/TestServerProjects/body-complex/Generated/Operations/FlattencomplexOperations.cs index 3457c636..bc3aa62e 100644 --- a/test/TestServerProjects/body-complex/Generated/Operations/FlattencomplexOperations.cs +++ b/test/TestServerProjects/body-complex/Generated/Operations/FlattencomplexOperations.cs @@ -30,7 +30,6 @@ namespace body_complex request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/complex/flatten/valid", false); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); switch (response.Status) { diff --git a/test/TestServerProjects/body-complex/Generated/Operations/InheritanceOperations.cs b/test/TestServerProjects/body-complex/Generated/Operations/InheritanceOperations.cs index 9b72dabe..af848797 100644 --- a/test/TestServerProjects/body-complex/Generated/Operations/InheritanceOperations.cs +++ b/test/TestServerProjects/body-complex/Generated/Operations/InheritanceOperations.cs @@ -30,7 +30,6 @@ namespace body_complex request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/complex/inheritance/valid", false); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); switch (response.Status) { @@ -66,13 +65,11 @@ namespace body_complex request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/complex/inheritance/valid", false); request.Headers.Add("Content-Type", "application/json"); - var buffer = new ArrayBufferWriter(); - await using var writer = new Utf8JsonWriter(buffer); + using var content = new Utf8JsonRequestContent(); + var writer = content.JsonWriter; complexBody.Serialize(writer); - writer.Flush(); - request.Content = RequestContent.Create(buffer.WrittenMemory); + request.Content = content; var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) diff --git a/test/TestServerProjects/body-complex/Generated/Operations/PolymorphicrecursiveOperations.cs b/test/TestServerProjects/body-complex/Generated/Operations/PolymorphicrecursiveOperations.cs index 49dad085..46046298 100644 --- a/test/TestServerProjects/body-complex/Generated/Operations/PolymorphicrecursiveOperations.cs +++ b/test/TestServerProjects/body-complex/Generated/Operations/PolymorphicrecursiveOperations.cs @@ -30,7 +30,6 @@ namespace body_complex request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/complex/polymorphicrecursive/valid", false); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); switch (response.Status) { @@ -66,13 +65,11 @@ namespace body_complex request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/complex/polymorphicrecursive/valid", false); request.Headers.Add("Content-Type", "application/json"); - var buffer = new ArrayBufferWriter(); - await using var writer = new Utf8JsonWriter(buffer); + using var content = new Utf8JsonRequestContent(); + var writer = content.JsonWriter; complexBody.Serialize(writer); - writer.Flush(); - request.Content = RequestContent.Create(buffer.WrittenMemory); + request.Content = content; var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) diff --git a/test/TestServerProjects/body-complex/Generated/Operations/PolymorphismOperations.cs b/test/TestServerProjects/body-complex/Generated/Operations/PolymorphismOperations.cs index da687b58..618618b6 100644 --- a/test/TestServerProjects/body-complex/Generated/Operations/PolymorphismOperations.cs +++ b/test/TestServerProjects/body-complex/Generated/Operations/PolymorphismOperations.cs @@ -30,7 +30,6 @@ namespace body_complex request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/complex/polymorphism/valid", false); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); switch (response.Status) { @@ -66,13 +65,11 @@ namespace body_complex request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/complex/polymorphism/valid", false); request.Headers.Add("Content-Type", "application/json"); - var buffer = new ArrayBufferWriter(); - await using var writer = new Utf8JsonWriter(buffer); + using var content = new Utf8JsonRequestContent(); + var writer = content.JsonWriter; complexBody.Serialize(writer); - writer.Flush(); - request.Content = RequestContent.Create(buffer.WrittenMemory); + request.Content = content; var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -97,7 +94,6 @@ namespace body_complex request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/complex/polymorphism/dotsyntax", false); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); switch (response.Status) { @@ -129,7 +125,6 @@ namespace body_complex request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/complex/polymorphism/composedWithDiscriminator", false); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); switch (response.Status) { @@ -161,7 +156,6 @@ namespace body_complex request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/complex/polymorphism/composedWithoutDiscriminator", false); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); switch (response.Status) { @@ -193,7 +187,6 @@ namespace body_complex request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/complex/polymorphism/complicated", false); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); switch (response.Status) { @@ -229,13 +222,11 @@ namespace body_complex request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/complex/polymorphism/complicated", false); request.Headers.Add("Content-Type", "application/json"); - var buffer = new ArrayBufferWriter(); - await using var writer = new Utf8JsonWriter(buffer); + using var content = new Utf8JsonRequestContent(); + var writer = content.JsonWriter; complexBody.Serialize(writer); - writer.Flush(); - request.Content = RequestContent.Create(buffer.WrittenMemory); + request.Content = content; var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -264,13 +255,11 @@ namespace body_complex request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/complex/polymorphism/missingdiscriminator", false); request.Headers.Add("Content-Type", "application/json"); - var buffer = new ArrayBufferWriter(); - await using var writer = new Utf8JsonWriter(buffer); + using var content = new Utf8JsonRequestContent(); + var writer = content.JsonWriter; complexBody.Serialize(writer); - writer.Flush(); - request.Content = RequestContent.Create(buffer.WrittenMemory); + request.Content = content; var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); switch (response.Status) { @@ -306,13 +295,11 @@ namespace body_complex request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/complex/polymorphism/missingrequired/invalid", false); request.Headers.Add("Content-Type", "application/json"); - var buffer = new ArrayBufferWriter(); - await using var writer = new Utf8JsonWriter(buffer); + using var content = new Utf8JsonRequestContent(); + var writer = content.JsonWriter; complexBody.Serialize(writer); - writer.Flush(); - request.Content = RequestContent.Create(buffer.WrittenMemory); + request.Content = content; var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) diff --git a/test/TestServerProjects/body-complex/Generated/Operations/PrimitiveOperations.cs b/test/TestServerProjects/body-complex/Generated/Operations/PrimitiveOperations.cs index a1f5d269..28cbd4c3 100644 --- a/test/TestServerProjects/body-complex/Generated/Operations/PrimitiveOperations.cs +++ b/test/TestServerProjects/body-complex/Generated/Operations/PrimitiveOperations.cs @@ -30,7 +30,6 @@ namespace body_complex request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/complex/primitive/integer", false); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); switch (response.Status) { @@ -66,13 +65,11 @@ namespace body_complex request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/complex/primitive/integer", false); request.Headers.Add("Content-Type", "application/json"); - var buffer = new ArrayBufferWriter(); - await using var writer = new Utf8JsonWriter(buffer); + using var content = new Utf8JsonRequestContent(); + var writer = content.JsonWriter; complexBody.Serialize(writer); - writer.Flush(); - request.Content = RequestContent.Create(buffer.WrittenMemory); + request.Content = content; var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -97,7 +94,6 @@ namespace body_complex request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/complex/primitive/long", false); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); switch (response.Status) { @@ -133,13 +129,11 @@ namespace body_complex request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/complex/primitive/long", false); request.Headers.Add("Content-Type", "application/json"); - var buffer = new ArrayBufferWriter(); - await using var writer = new Utf8JsonWriter(buffer); + using var content = new Utf8JsonRequestContent(); + var writer = content.JsonWriter; complexBody.Serialize(writer); - writer.Flush(); - request.Content = RequestContent.Create(buffer.WrittenMemory); + request.Content = content; var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -164,7 +158,6 @@ namespace body_complex request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/complex/primitive/float", false); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); switch (response.Status) { @@ -200,13 +193,11 @@ namespace body_complex request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/complex/primitive/float", false); request.Headers.Add("Content-Type", "application/json"); - var buffer = new ArrayBufferWriter(); - await using var writer = new Utf8JsonWriter(buffer); + using var content = new Utf8JsonRequestContent(); + var writer = content.JsonWriter; complexBody.Serialize(writer); - writer.Flush(); - request.Content = RequestContent.Create(buffer.WrittenMemory); + request.Content = content; var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -231,7 +222,6 @@ namespace body_complex request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/complex/primitive/double", false); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); switch (response.Status) { @@ -267,13 +257,11 @@ namespace body_complex request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/complex/primitive/double", false); request.Headers.Add("Content-Type", "application/json"); - var buffer = new ArrayBufferWriter(); - await using var writer = new Utf8JsonWriter(buffer); + using var content = new Utf8JsonRequestContent(); + var writer = content.JsonWriter; complexBody.Serialize(writer); - writer.Flush(); - request.Content = RequestContent.Create(buffer.WrittenMemory); + request.Content = content; var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -298,7 +286,6 @@ namespace body_complex request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/complex/primitive/bool", false); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); switch (response.Status) { @@ -334,13 +321,11 @@ namespace body_complex request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/complex/primitive/bool", false); request.Headers.Add("Content-Type", "application/json"); - var buffer = new ArrayBufferWriter(); - await using var writer = new Utf8JsonWriter(buffer); + using var content = new Utf8JsonRequestContent(); + var writer = content.JsonWriter; complexBody.Serialize(writer); - writer.Flush(); - request.Content = RequestContent.Create(buffer.WrittenMemory); + request.Content = content; var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -365,7 +350,6 @@ namespace body_complex request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/complex/primitive/string", false); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); switch (response.Status) { @@ -401,13 +385,11 @@ namespace body_complex request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/complex/primitive/string", false); request.Headers.Add("Content-Type", "application/json"); - var buffer = new ArrayBufferWriter(); - await using var writer = new Utf8JsonWriter(buffer); + using var content = new Utf8JsonRequestContent(); + var writer = content.JsonWriter; complexBody.Serialize(writer); - writer.Flush(); - request.Content = RequestContent.Create(buffer.WrittenMemory); + request.Content = content; var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -432,7 +414,6 @@ namespace body_complex request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/complex/primitive/date", false); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); switch (response.Status) { @@ -468,13 +449,11 @@ namespace body_complex request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/complex/primitive/date", false); request.Headers.Add("Content-Type", "application/json"); - var buffer = new ArrayBufferWriter(); - await using var writer = new Utf8JsonWriter(buffer); + using var content = new Utf8JsonRequestContent(); + var writer = content.JsonWriter; complexBody.Serialize(writer); - writer.Flush(); - request.Content = RequestContent.Create(buffer.WrittenMemory); + request.Content = content; var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -499,7 +478,6 @@ namespace body_complex request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/complex/primitive/datetime", false); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); switch (response.Status) { @@ -535,13 +513,11 @@ namespace body_complex request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/complex/primitive/datetime", false); request.Headers.Add("Content-Type", "application/json"); - var buffer = new ArrayBufferWriter(); - await using var writer = new Utf8JsonWriter(buffer); + using var content = new Utf8JsonRequestContent(); + var writer = content.JsonWriter; complexBody.Serialize(writer); - writer.Flush(); - request.Content = RequestContent.Create(buffer.WrittenMemory); + request.Content = content; var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -566,7 +542,6 @@ namespace body_complex request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/complex/primitive/datetimerfc1123", false); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); switch (response.Status) { @@ -602,13 +577,11 @@ namespace body_complex request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/complex/primitive/datetimerfc1123", false); request.Headers.Add("Content-Type", "application/json"); - var buffer = new ArrayBufferWriter(); - await using var writer = new Utf8JsonWriter(buffer); + using var content = new Utf8JsonRequestContent(); + var writer = content.JsonWriter; complexBody.Serialize(writer); - writer.Flush(); - request.Content = RequestContent.Create(buffer.WrittenMemory); + request.Content = content; var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -633,7 +606,6 @@ namespace body_complex request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/complex/primitive/duration", false); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); switch (response.Status) { @@ -669,13 +641,11 @@ namespace body_complex request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/complex/primitive/duration", false); request.Headers.Add("Content-Type", "application/json"); - var buffer = new ArrayBufferWriter(); - await using var writer = new Utf8JsonWriter(buffer); + using var content = new Utf8JsonRequestContent(); + var writer = content.JsonWriter; complexBody.Serialize(writer); - writer.Flush(); - request.Content = RequestContent.Create(buffer.WrittenMemory); + request.Content = content; var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -700,7 +670,6 @@ namespace body_complex request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/complex/primitive/byte", false); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); switch (response.Status) { @@ -736,13 +705,11 @@ namespace body_complex request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/complex/primitive/byte", false); request.Headers.Add("Content-Type", "application/json"); - var buffer = new ArrayBufferWriter(); - await using var writer = new Utf8JsonWriter(buffer); + using var content = new Utf8JsonRequestContent(); + var writer = content.JsonWriter; complexBody.Serialize(writer); - writer.Flush(); - request.Content = RequestContent.Create(buffer.WrittenMemory); + request.Content = content; var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) diff --git a/test/TestServerProjects/body-complex/Generated/Operations/ReadonlypropertyOperations.cs b/test/TestServerProjects/body-complex/Generated/Operations/ReadonlypropertyOperations.cs index 3f28666c..ef23dcae 100644 --- a/test/TestServerProjects/body-complex/Generated/Operations/ReadonlypropertyOperations.cs +++ b/test/TestServerProjects/body-complex/Generated/Operations/ReadonlypropertyOperations.cs @@ -30,7 +30,6 @@ namespace body_complex request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/complex/readonlyproperty/valid", false); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); switch (response.Status) { @@ -66,13 +65,11 @@ namespace body_complex request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/complex/readonlyproperty/valid", false); request.Headers.Add("Content-Type", "application/json"); - var buffer = new ArrayBufferWriter(); - await using var writer = new Utf8JsonWriter(buffer); + using var content = new Utf8JsonRequestContent(); + var writer = content.JsonWriter; complexBody.Serialize(writer); - writer.Flush(); - request.Content = RequestContent.Create(buffer.WrittenMemory); + request.Content = content; var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) diff --git a/test/TestServerProjects/body-string/Generated/Operations/EnumOperations.cs b/test/TestServerProjects/body-string/Generated/Operations/EnumOperations.cs index 63004e26..549981f2 100644 --- a/test/TestServerProjects/body-string/Generated/Operations/EnumOperations.cs +++ b/test/TestServerProjects/body-string/Generated/Operations/EnumOperations.cs @@ -30,7 +30,6 @@ namespace body_string request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/string/enum/notExpandable", false); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); switch (response.Status) { @@ -62,13 +61,11 @@ namespace body_string request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/string/enum/notExpandable", false); request.Headers.Add("Content-Type", "application/json"); - var buffer = new ArrayBufferWriter(); - await using var writer = new Utf8JsonWriter(buffer); + using var content = new Utf8JsonRequestContent(); + var writer = content.JsonWriter; writer.WriteStringValue(stringBody.ToSerialString()); - writer.Flush(); - request.Content = RequestContent.Create(buffer.WrittenMemory); + request.Content = content; var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -93,7 +90,6 @@ namespace body_string request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/string/enum/Referenced", false); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); switch (response.Status) { @@ -125,13 +121,11 @@ namespace body_string request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/string/enum/Referenced", false); request.Headers.Add("Content-Type", "application/json"); - var buffer = new ArrayBufferWriter(); - await using var writer = new Utf8JsonWriter(buffer); + using var content = new Utf8JsonRequestContent(); + var writer = content.JsonWriter; writer.WriteStringValue(enumStringBody.ToSerialString()); - writer.Flush(); - request.Content = RequestContent.Create(buffer.WrittenMemory); + request.Content = content; var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -156,7 +150,6 @@ namespace body_string request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/string/enum/ReferencedConstant", false); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); switch (response.Status) { @@ -192,13 +185,11 @@ namespace body_string request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/string/enum/ReferencedConstant", false); request.Headers.Add("Content-Type", "application/json"); - var buffer = new ArrayBufferWriter(); - await using var writer = new Utf8JsonWriter(buffer); + using var content = new Utf8JsonRequestContent(); + var writer = content.JsonWriter; enumStringBody.Serialize(writer); - writer.Flush(); - request.Content = RequestContent.Create(buffer.WrittenMemory); + request.Content = content; var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) diff --git a/test/TestServerProjects/body-string/Generated/Operations/StringOperations.cs b/test/TestServerProjects/body-string/Generated/Operations/StringOperations.cs index 64507e3f..37004dc8 100644 --- a/test/TestServerProjects/body-string/Generated/Operations/StringOperations.cs +++ b/test/TestServerProjects/body-string/Generated/Operations/StringOperations.cs @@ -29,7 +29,6 @@ namespace body_string request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/string/null", false); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); switch (response.Status) { @@ -61,13 +60,11 @@ namespace body_string request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/string/null", false); request.Headers.Add("Content-Type", "application/json"); - var buffer = new ArrayBufferWriter(); - await using var writer = new Utf8JsonWriter(buffer); + using var content = new Utf8JsonRequestContent(); + var writer = content.JsonWriter; writer.WriteStringValue(""); - writer.Flush(); - request.Content = RequestContent.Create(buffer.WrittenMemory); + request.Content = content; var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -92,7 +89,6 @@ namespace body_string request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/string/empty", false); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); switch (response.Status) { @@ -124,13 +120,11 @@ namespace body_string request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/string/empty", false); request.Headers.Add("Content-Type", "application/json"); - var buffer = new ArrayBufferWriter(); - await using var writer = new Utf8JsonWriter(buffer); + using var content = new Utf8JsonRequestContent(); + var writer = content.JsonWriter; writer.WriteStringValue(""); - writer.Flush(); - request.Content = RequestContent.Create(buffer.WrittenMemory); + request.Content = content; var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -155,7 +149,6 @@ namespace body_string request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/string/mbcs", false); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); switch (response.Status) { @@ -187,13 +180,11 @@ namespace body_string request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/string/mbcs", false); request.Headers.Add("Content-Type", "application/json"); - var buffer = new ArrayBufferWriter(); - await using var writer = new Utf8JsonWriter(buffer); + using var content = new Utf8JsonRequestContent(); + var writer = content.JsonWriter; writer.WriteStringValue("啊齄丂狛狜隣郎隣兀﨩ˊ〞〡¦℡㈱‐ー﹡﹢﹫、〓ⅰⅹ⒈€㈠㈩ⅠⅫ! ̄ぁんァヶΑ︴АЯаяāɡㄅㄩ─╋︵﹄︻︱︳︴ⅰⅹɑɡ〇〾⿻⺁䜣€"); - writer.Flush(); - request.Content = RequestContent.Create(buffer.WrittenMemory); + request.Content = content; var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -218,7 +209,6 @@ namespace body_string request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/string/whitespace", false); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); switch (response.Status) { @@ -250,13 +240,11 @@ namespace body_string request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/string/whitespace", false); request.Headers.Add("Content-Type", "application/json"); - var buffer = new ArrayBufferWriter(); - await using var writer = new Utf8JsonWriter(buffer); + using var content = new Utf8JsonRequestContent(); + var writer = content.JsonWriter; writer.WriteStringValue(" Now is the time for all good men to come to the aid of their country "); - writer.Flush(); - request.Content = RequestContent.Create(buffer.WrittenMemory); + request.Content = content; var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -281,7 +269,6 @@ namespace body_string request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/string/notProvided", false); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); switch (response.Status) { @@ -313,7 +300,6 @@ namespace body_string request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/string/base64Encoding", false); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); switch (response.Status) { @@ -345,7 +331,6 @@ namespace body_string request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/string/base64UrlEncoding", false); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); switch (response.Status) { @@ -381,13 +366,11 @@ namespace body_string request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/string/base64UrlEncoding", false); request.Headers.Add("Content-Type", "application/json"); - var buffer = new ArrayBufferWriter(); - await using var writer = new Utf8JsonWriter(buffer); + using var content = new Utf8JsonRequestContent(); + var writer = content.JsonWriter; writer.WriteBase64StringValue(stringBody); - writer.Flush(); - request.Content = RequestContent.Create(buffer.WrittenMemory); + request.Content = content; var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -412,7 +395,6 @@ namespace body_string request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/string/nullBase64UrlEncoding", false); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); switch (response.Status) { diff --git a/test/TestServerProjects/custom-baseUrl-more-options/Generated/Operations/PathsOperations.cs b/test/TestServerProjects/custom-baseUrl-more-options/Generated/Operations/PathsOperations.cs index aaf6732d..866ad635 100644 --- a/test/TestServerProjects/custom-baseUrl-more-options/Generated/Operations/PathsOperations.cs +++ b/test/TestServerProjects/custom-baseUrl-more-options/Generated/Operations/PathsOperations.cs @@ -51,7 +51,6 @@ namespace custom_baseUrl_more_options request.Uri.AppendQuery("keyVersion", keyVersion, true); } var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) diff --git a/test/TestServerProjects/custom-baseUrl/Generated/Operations/PathsOperations.cs b/test/TestServerProjects/custom-baseUrl/Generated/Operations/PathsOperations.cs index d0973ed1..a41aa011 100644 --- a/test/TestServerProjects/custom-baseUrl/Generated/Operations/PathsOperations.cs +++ b/test/TestServerProjects/custom-baseUrl/Generated/Operations/PathsOperations.cs @@ -32,7 +32,6 @@ namespace custom_baseUrl request.Uri.Reset(new Uri($"http://{accountName}{host}")); request.Uri.AppendPath("/customuri", false); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) diff --git a/test/TestServerProjects/extensible-enums-swagger/Generated/Operations/PetOperations.cs b/test/TestServerProjects/extensible-enums-swagger/Generated/Operations/PetOperations.cs index a33f82b5..3786e56e 100644 --- a/test/TestServerProjects/extensible-enums-swagger/Generated/Operations/PetOperations.cs +++ b/test/TestServerProjects/extensible-enums-swagger/Generated/Operations/PetOperations.cs @@ -35,7 +35,6 @@ namespace extensible_enums_swagger request.Uri.AppendPath("/extensibleenums/pet/", false); request.Uri.AppendPath(petId, true); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); switch (response.Status) { @@ -67,13 +66,11 @@ namespace extensible_enums_swagger request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/extensibleenums/pet/addPet", false); request.Headers.Add("Content-Type", "application/json"); - var buffer = new ArrayBufferWriter(); - await using var writer = new Utf8JsonWriter(buffer); + using var content = new Utf8JsonRequestContent(); + var writer = content.JsonWriter; petParam?.Serialize(writer); - writer.Flush(); - request.Content = RequestContent.Create(buffer.WrittenMemory); + request.Content = content; var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); switch (response.Status) { diff --git a/test/TestServerProjects/header/Generated/Operations/HeaderOperations.cs b/test/TestServerProjects/header/Generated/Operations/HeaderOperations.cs index a79cfe4c..55579ebc 100644 --- a/test/TestServerProjects/header/Generated/Operations/HeaderOperations.cs +++ b/test/TestServerProjects/header/Generated/Operations/HeaderOperations.cs @@ -34,7 +34,6 @@ namespace header request.Uri.AppendPath("/header/param/existingkey", false); request.Headers.Add("User-Agent", userAgent); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -59,7 +58,6 @@ namespace header request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/header/response/existingkey", false); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -89,7 +87,6 @@ namespace header request.Uri.AppendPath("/header/param/protectedkey", false); request.Headers.Add("Content-Type", contentType); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -114,7 +111,6 @@ namespace header request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/header/response/protectedkey", false); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -145,7 +141,6 @@ namespace header request.Headers.Add("scenario", scenario); request.Headers.Add("value", value); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -175,7 +170,6 @@ namespace header request.Uri.AppendPath("/header/response/prim/integer", false); request.Headers.Add("scenario", scenario); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -206,7 +200,6 @@ namespace header request.Headers.Add("scenario", scenario); request.Headers.Add("value", value); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -236,7 +229,6 @@ namespace header request.Uri.AppendPath("/header/response/prim/long", false); request.Headers.Add("scenario", scenario); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -267,7 +259,6 @@ namespace header request.Headers.Add("scenario", scenario); request.Headers.Add("value", value); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -297,7 +288,6 @@ namespace header request.Uri.AppendPath("/header/response/prim/float", false); request.Headers.Add("scenario", scenario); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -328,7 +318,6 @@ namespace header request.Headers.Add("scenario", scenario); request.Headers.Add("value", value); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -358,7 +347,6 @@ namespace header request.Uri.AppendPath("/header/response/prim/double", false); request.Headers.Add("scenario", scenario); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -389,7 +377,6 @@ namespace header request.Headers.Add("scenario", scenario); request.Headers.Add("value", value); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -419,7 +406,6 @@ namespace header request.Uri.AppendPath("/header/response/prim/bool", false); request.Headers.Add("scenario", scenario); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -453,7 +439,6 @@ namespace header request.Headers.Add("value", value); } var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -483,7 +468,6 @@ namespace header request.Uri.AppendPath("/header/response/prim/string", false); request.Headers.Add("scenario", scenario); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -514,7 +498,6 @@ namespace header request.Headers.Add("scenario", scenario); request.Headers.Add("value", value, "D"); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -544,7 +527,6 @@ namespace header request.Uri.AppendPath("/header/response/prim/date", false); request.Headers.Add("scenario", scenario); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -575,7 +557,6 @@ namespace header request.Headers.Add("scenario", scenario); request.Headers.Add("value", value, "S"); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -605,7 +586,6 @@ namespace header request.Uri.AppendPath("/header/response/prim/datetime", false); request.Headers.Add("scenario", scenario); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -639,7 +619,6 @@ namespace header request.Headers.Add("value", value.Value, "R"); } var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -669,7 +648,6 @@ namespace header request.Uri.AppendPath("/header/response/prim/datetimerfc1123", false); request.Headers.Add("scenario", scenario); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -700,7 +678,6 @@ namespace header request.Headers.Add("scenario", scenario); request.Headers.Add("value", value); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -730,7 +707,6 @@ namespace header request.Uri.AppendPath("/header/response/prim/duration", false); request.Headers.Add("scenario", scenario); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -765,7 +741,6 @@ namespace header request.Headers.Add("scenario", scenario); request.Headers.Add("value", value); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -795,7 +770,6 @@ namespace header request.Uri.AppendPath("/header/response/prim/byte", false); request.Headers.Add("scenario", scenario); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -829,7 +803,6 @@ namespace header request.Headers.Add("value", value.Value); } var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -859,7 +832,6 @@ namespace header request.Uri.AppendPath("/header/response/prim/enum", false); request.Headers.Add("scenario", scenario); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -884,7 +856,6 @@ namespace header request.Uri.Reset(new Uri($"{host}")); request.Uri.AppendPath("/header/custom/x-ms-client-request-id/9C4D50EE-2D56-4CD3-8152-34347DC9F2B0", false); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) diff --git a/test/TestServerProjects/url-multi-collectionFormat/Generated/Operations/QueriesOperations.cs b/test/TestServerProjects/url-multi-collectionFormat/Generated/Operations/QueriesOperations.cs index 12998787..037e8f4b 100644 --- a/test/TestServerProjects/url-multi-collectionFormat/Generated/Operations/QueriesOperations.cs +++ b/test/TestServerProjects/url-multi-collectionFormat/Generated/Operations/QueriesOperations.cs @@ -33,7 +33,6 @@ namespace url_multi_collectionFormat request.Uri.AppendQueryDelimited("arrayQuery", arrayQuery, ",", true); } var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -62,7 +61,6 @@ namespace url_multi_collectionFormat request.Uri.AppendQueryDelimited("arrayQuery", arrayQuery, ",", true); } var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -91,7 +89,6 @@ namespace url_multi_collectionFormat request.Uri.AppendQueryDelimited("arrayQuery", arrayQuery, ",", true); } var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) diff --git a/test/TestServerProjects/url/Generated/Operations/PathItemsOperations.cs b/test/TestServerProjects/url/Generated/Operations/PathItemsOperations.cs index a3ae1478..f60c3a95 100644 --- a/test/TestServerProjects/url/Generated/Operations/PathItemsOperations.cs +++ b/test/TestServerProjects/url/Generated/Operations/PathItemsOperations.cs @@ -58,7 +58,6 @@ namespace url request.Uri.AppendQuery("localStringQuery", localStringQuery, true); } var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -113,7 +112,6 @@ namespace url request.Uri.AppendQuery("localStringQuery", localStringQuery, true); } var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -168,7 +166,6 @@ namespace url request.Uri.AppendQuery("localStringQuery", localStringQuery, true); } var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -223,7 +220,6 @@ namespace url request.Uri.AppendQuery("localStringQuery", localStringQuery, true); } var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) diff --git a/test/TestServerProjects/url/Generated/Operations/PathsOperations.cs b/test/TestServerProjects/url/Generated/Operations/PathsOperations.cs index ed2fc95b..00dfc552 100644 --- a/test/TestServerProjects/url/Generated/Operations/PathsOperations.cs +++ b/test/TestServerProjects/url/Generated/Operations/PathsOperations.cs @@ -31,7 +31,6 @@ namespace url request.Uri.AppendPath("/paths/bool/true/", false); request.Uri.AppendPath(true, true); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -57,7 +56,6 @@ namespace url request.Uri.AppendPath("/paths/bool/false/", false); request.Uri.AppendPath(false, true); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -83,7 +81,6 @@ namespace url request.Uri.AppendPath("/paths/int/1000000/", false); request.Uri.AppendPath(1000000F, true); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -109,7 +106,6 @@ namespace url request.Uri.AppendPath("/paths/int/-1000000/", false); request.Uri.AppendPath(-1000000F, true); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -135,7 +131,6 @@ namespace url request.Uri.AppendPath("/paths/long/10000000000/", false); request.Uri.AppendPath(1E+10F, true); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -161,7 +156,6 @@ namespace url request.Uri.AppendPath("/paths/long/-10000000000/", false); request.Uri.AppendPath(-1E+10F, true); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -187,7 +181,6 @@ namespace url request.Uri.AppendPath("/paths/float/1.034E+20/", false); request.Uri.AppendPath(1.034E+20F, true); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -213,7 +206,6 @@ namespace url request.Uri.AppendPath("/paths/float/-1.034E-20/", false); request.Uri.AppendPath(-1.034E-20F, true); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -239,7 +231,6 @@ namespace url request.Uri.AppendPath("/paths/double/9999999.999/", false); request.Uri.AppendPath(9999999.999, true); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -265,7 +256,6 @@ namespace url request.Uri.AppendPath("/paths/double/-9999999.999/", false); request.Uri.AppendPath(-9999999.999, true); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -291,7 +281,6 @@ namespace url request.Uri.AppendPath("/paths/string/unicode/", false); request.Uri.AppendPath("啊齄丂狛狜隣郎隣兀﨩", true); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -317,7 +306,6 @@ namespace url request.Uri.AppendPath("/paths/string/begin%21%2A%27%28%29%3B%3A%40%20%26%3D%2B%24%2C%2F%3F%23%5B%5Dend/", false); request.Uri.AppendPath("begin!*'();:@ &=+$,/?#[]end", true); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -343,7 +331,6 @@ namespace url request.Uri.AppendPath("/paths/string/empty/", false); request.Uri.AppendPath("", true); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -373,7 +360,6 @@ namespace url request.Uri.AppendPath("/paths/string/null/", false); request.Uri.AppendPath(stringPath, true); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -399,7 +385,6 @@ namespace url request.Uri.AppendPath("/paths/enum/green%20color/", false); request.Uri.AppendPath(enumPath, true); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -425,7 +410,6 @@ namespace url request.Uri.AppendPath("/paths/string/null/", false); request.Uri.AppendPath(enumPath, true); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -455,7 +439,6 @@ namespace url request.Uri.AppendPath("/paths/byte/multibyte/", false); request.Uri.AppendPath(bytePath, true); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -481,7 +464,6 @@ namespace url request.Uri.AppendPath("/paths/byte/empty/", false); request.Uri.AppendPath(new byte[] { }, true); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -511,7 +493,6 @@ namespace url request.Uri.AppendPath("/paths/byte/null/", false); request.Uri.AppendPath(bytePath, true); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -537,7 +518,6 @@ namespace url request.Uri.AppendPath("/paths/date/2012-01-01/", false); request.Uri.AppendPath(new DateTimeOffset(2012, 1, 1, 0, 0, 0, 0, TimeSpan.Zero), "D", true); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -563,7 +543,6 @@ namespace url request.Uri.AppendPath("/paths/date/null/", false); request.Uri.AppendPath(datePath, "D", true); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -589,7 +568,6 @@ namespace url request.Uri.AppendPath("/paths/datetime/2012-01-01T01%3A01%3A01Z/", false); request.Uri.AppendPath(new DateTimeOffset(2012, 1, 1, 1, 1, 1, 0, TimeSpan.Zero), "S", true); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -615,7 +593,6 @@ namespace url request.Uri.AppendPath("/paths/datetime/null/", false); request.Uri.AppendPath(dateTimePath, "S", true); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -645,7 +622,6 @@ namespace url request.Uri.AppendPath("/paths/string/bG9yZW0/", false); request.Uri.AppendPath(base64UrlPath, true); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -675,7 +651,6 @@ namespace url request.Uri.AppendPath("/paths/array/ArrayPath1%2cbegin%21%2A%27%28%29%3B%3A%40%20%26%3D%2B%24%2C%2F%3F%23%5B%5Dend%2c%2c/", false); request.Uri.AppendPath(arrayPath, true); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -701,7 +676,6 @@ namespace url request.Uri.AppendPath("/paths/int/1460505600/", false); request.Uri.AppendPath(unixTimeUrlPath, "U", true); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) diff --git a/test/TestServerProjects/url/Generated/Operations/QueriesOperations.cs b/test/TestServerProjects/url/Generated/Operations/QueriesOperations.cs index fc70a5e0..c167c51e 100644 --- a/test/TestServerProjects/url/Generated/Operations/QueriesOperations.cs +++ b/test/TestServerProjects/url/Generated/Operations/QueriesOperations.cs @@ -31,7 +31,6 @@ namespace url request.Uri.AppendPath("/queries/bool/true", false); request.Uri.AppendQuery("boolQuery", true, true); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -57,7 +56,6 @@ namespace url request.Uri.AppendPath("/queries/bool/false", false); request.Uri.AppendQuery("boolQuery", false, true); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -86,7 +84,6 @@ namespace url request.Uri.AppendQuery("boolQuery", boolQuery.Value, true); } var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -112,7 +109,6 @@ namespace url request.Uri.AppendPath("/queries/int/1000000", false); request.Uri.AppendQuery("intQuery", 1000000F, true); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -138,7 +134,6 @@ namespace url request.Uri.AppendPath("/queries/int/-1000000", false); request.Uri.AppendQuery("intQuery", -1000000F, true); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -167,7 +162,6 @@ namespace url request.Uri.AppendQuery("intQuery", intQuery.Value, true); } var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -193,7 +187,6 @@ namespace url request.Uri.AppendPath("/queries/long/10000000000", false); request.Uri.AppendQuery("longQuery", 1E+10F, true); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -219,7 +212,6 @@ namespace url request.Uri.AppendPath("/queries/long/-10000000000", false); request.Uri.AppendQuery("longQuery", -1E+10F, true); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -248,7 +240,6 @@ namespace url request.Uri.AppendQuery("longQuery", longQuery.Value, true); } var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -274,7 +265,6 @@ namespace url request.Uri.AppendPath("/queries/float/1.034E+20", false); request.Uri.AppendQuery("floatQuery", 1.034E+20F, true); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -300,7 +290,6 @@ namespace url request.Uri.AppendPath("/queries/float/-1.034E-20", false); request.Uri.AppendQuery("floatQuery", -1.034E-20F, true); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -329,7 +318,6 @@ namespace url request.Uri.AppendQuery("floatQuery", floatQuery.Value, true); } var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -355,7 +343,6 @@ namespace url request.Uri.AppendPath("/queries/double/9999999.999", false); request.Uri.AppendQuery("doubleQuery", 9999999.999, true); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -381,7 +368,6 @@ namespace url request.Uri.AppendPath("/queries/double/-9999999.999", false); request.Uri.AppendQuery("doubleQuery", -9999999.999, true); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -410,7 +396,6 @@ namespace url request.Uri.AppendQuery("doubleQuery", doubleQuery.Value, true); } var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -436,7 +421,6 @@ namespace url request.Uri.AppendPath("/queries/string/unicode/", false); request.Uri.AppendQuery("stringQuery", "啊齄丂狛狜隣郎隣兀﨩", true); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -462,7 +446,6 @@ namespace url request.Uri.AppendPath("/queries/string/begin%21%2A%27%28%29%3B%3A%40%20%26%3D%2B%24%2C%2F%3F%23%5B%5Dend", false); request.Uri.AppendQuery("stringQuery", "begin!*'();:@ &=+$,/?#[]end", true); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -488,7 +471,6 @@ namespace url request.Uri.AppendPath("/queries/string/empty", false); request.Uri.AppendQuery("stringQuery", "", true); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -517,7 +499,6 @@ namespace url request.Uri.AppendQuery("stringQuery", stringQuery, true); } var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -546,7 +527,6 @@ namespace url request.Uri.AppendQuery("enumQuery", enumQuery.Value, true); } var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -575,7 +555,6 @@ namespace url request.Uri.AppendQuery("enumQuery", enumQuery.Value, true); } var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -604,7 +583,6 @@ namespace url request.Uri.AppendQuery("byteQuery", byteQuery, true); } var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -630,7 +608,6 @@ namespace url request.Uri.AppendPath("/queries/byte/empty", false); request.Uri.AppendQuery("byteQuery", new byte[] { }, true); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -659,7 +636,6 @@ namespace url request.Uri.AppendQuery("byteQuery", byteQuery, true); } var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -685,7 +661,6 @@ namespace url request.Uri.AppendPath("/queries/date/2012-01-01", false); request.Uri.AppendQuery("dateQuery", new DateTimeOffset(2012, 1, 1, 0, 0, 0, 0, TimeSpan.Zero), "D", true); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -714,7 +689,6 @@ namespace url request.Uri.AppendQuery("dateQuery", dateQuery.Value, "D", true); } var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -740,7 +714,6 @@ namespace url request.Uri.AppendPath("/queries/datetime/2012-01-01T01%3A01%3A01Z", false); request.Uri.AppendQuery("dateTimeQuery", new DateTimeOffset(2012, 1, 1, 1, 1, 1, 0, TimeSpan.Zero), "S", true); var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -769,7 +742,6 @@ namespace url request.Uri.AppendQuery("dateTimeQuery", dateTimeQuery.Value, "S", true); } var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -798,7 +770,6 @@ namespace url request.Uri.AppendQueryDelimited("arrayQuery", arrayQuery, ",", true); } var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -827,7 +798,6 @@ namespace url request.Uri.AppendQueryDelimited("arrayQuery", arrayQuery, ",", true); } var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -856,7 +826,6 @@ namespace url request.Uri.AppendQueryDelimited("arrayQuery", arrayQuery, ",", true); } var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -885,7 +854,6 @@ namespace url request.Uri.AppendQueryDelimited("arrayQuery", arrayQuery, " ", true); } var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -914,7 +882,6 @@ namespace url request.Uri.AppendQueryDelimited("arrayQuery", arrayQuery, "\t", true); } var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) @@ -943,7 +910,6 @@ namespace url request.Uri.AppendQueryDelimited("arrayQuery", arrayQuery, "|", true); } var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); return response; } catch (Exception e) From a787b3c9bcc51964edf810704b07a7801c7d8ad0 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Wed, 11 Dec 2019 13:50:33 -0800 Subject: [PATCH 4/5] Add tests for number bodies (#334) --- eng/Generate.ps1 | 2 +- package-lock.json | 24 +- package.json | 2 +- src/AutoRest.CSharp.V3/Plugins/Modeler.cs | 2 +- .../Infrastructure/TestServerTestBase.cs | 11 +- .../Infrastructure/TestServerV1.cs | 3 +- .../AutoRest.TestServer.Tests/body-integer.cs | 98 +++ test/AutoRest.TestServer.Tests/body-number.cs | 160 ++++ .../Generated/Models/Error.Serialization.cs | 44 ++ .../body-integer/Generated/Models/Error.cs | 11 + .../Generated/Operations/IntOperations.cs | 441 +++++++++++ .../body-integer/body-integer.csproj | 15 + .../Generated/Models/Error.Serialization.cs | 44 ++ .../body-number/Generated/Models/Error.cs | 11 + .../Generated/Operations/NumberOperations.cs | 741 ++++++++++++++++++ .../body-number/body-number.csproj | 15 + 16 files changed, 1607 insertions(+), 17 deletions(-) create mode 100644 test/AutoRest.TestServer.Tests/body-integer.cs create mode 100644 test/AutoRest.TestServer.Tests/body-number.cs create mode 100644 test/TestServerProjects/body-integer/Generated/Models/Error.Serialization.cs create mode 100644 test/TestServerProjects/body-integer/Generated/Models/Error.cs create mode 100644 test/TestServerProjects/body-integer/Generated/Operations/IntOperations.cs create mode 100644 test/TestServerProjects/body-integer/body-integer.csproj create mode 100644 test/TestServerProjects/body-number/Generated/Models/Error.Serialization.cs create mode 100644 test/TestServerProjects/body-number/Generated/Models/Error.cs create mode 100644 test/TestServerProjects/body-number/Generated/Operations/NumberOperations.cs create mode 100644 test/TestServerProjects/body-number/body-number.csproj diff --git a/eng/Generate.ps1 b/eng/Generate.ps1 index 16ed4106..d3e3ee1f 100644 --- a/eng/Generate.ps1 +++ b/eng/Generate.ps1 @@ -36,7 +36,7 @@ $debugFlags = if (-not $noDebug) { '--debug', '--verbose' } $testServerDirectory = Join-Path $repoRoot 'test' 'TestServerProjects' $configurationPath = Join-Path $testServerDirectory 'readme.tests.md' $testServerSwaggerPath = Join-Path $repoRoot 'node_modules' '@microsoft.azure' 'autorest.testserver' 'swagger' -$testNames = if ($name) { $name } else { 'extensible-enums-swagger', 'url-multi-collectionFormat', 'url', 'body-string', 'body-complex', 'custom-baseUrl', 'custom-baseUrl-more-options', 'header' } +$testNames = if ($name) { $name } else { 'body-number', 'body-integer', 'extensible-enums-swagger', 'url-multi-collectionFormat', 'url', 'body-string', 'body-complex', 'custom-baseUrl', 'custom-baseUrl-more-options', 'header' } if (!$NoReset) { diff --git a/package-lock.json b/package-lock.json index 6e31e99f..716773ec 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,9 +18,9 @@ } }, "@microsoft.azure/autorest.testserver": { - "version": "2.7.1", - "resolved": "https://registry.npmjs.org/@microsoft.azure/autorest.testserver/-/autorest.testserver-2.7.1.tgz", - "integrity": "sha512-j4E9Wx3WVwzc2rfl5OutsW3lOtVsd2lEaLUh1k/uJj0qhwUHmQI0ObLW4fxikfA3k8I5sWqBkakoHjuB93TwUg==", + "version": "2.7.2", + "resolved": "https://registry.npmjs.org/@microsoft.azure/autorest.testserver/-/autorest.testserver-2.7.2.tgz", + "integrity": "sha512-bWnc5FCBh6vV3tU36qPmEZIPOWa6bdVcXV0/cDIf6GlXt6gBR8FU+tmq1JJgMX7uqinrxCANJb1HxnM9bGmm5Q==", "dev": true, "requires": { "azure-storage": "^2.4.0", @@ -518,9 +518,9 @@ "dev": true }, "core-js": { - "version": "2.6.10", - "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.6.10.tgz", - "integrity": "sha512-I39t74+4t+zau64EN1fE5v2W31Adtc/REhzWN+gWRRXg6WH5qAsZm62DHpQ1+Yhe4047T55jvzz7MUqF/dBBlA==", + "version": "2.6.11", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.6.11.tgz", + "integrity": "sha512-5wjnpaT/3dV+XB4borEsnAYQchn00XSgTAWKDkEqv+K8KevjbzmofK6hfJ9TZIlpj2N0xQpazy7PiRQiWHqzWg==", "dev": true }, "core-util-is": { @@ -725,9 +725,9 @@ } }, "es-abstract": { - "version": "1.16.2", - "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.16.2.tgz", - "integrity": "sha512-jYo/J8XU2emLXl3OLwfwtuFfuF2w6DYPs+xy9ZfVyPkDcrauu6LYrw/q2TyCtrbc/KUdCiC5e9UajRhgNkVopA==", + "version": "1.16.3", + "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.16.3.tgz", + "integrity": "sha512-WtY7Fx5LiOnSYgF5eg/1T+GONaGmpvpPdCpSnYij+U2gDTL0UPfWrhDw7b2IYb+9NQJsYpCA0wOQvZfsd6YwRw==", "dev": true, "requires": { "es-to-primitive": "^1.2.1", @@ -1495,9 +1495,9 @@ } }, "psl": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/psl/-/psl-1.5.0.tgz", - "integrity": "sha512-4vqUjKi2huMu1OJiLhi3jN6jeeKvMZdI1tYgi/njW5zV52jNLgSAZSdN16m9bJFe61/cT8ulmw4qFitV9QRsEA==", + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/psl/-/psl-1.6.0.tgz", + "integrity": "sha512-SYKKmVel98NCOYXpkwUqZqh0ahZeeKfmisiLIcEZdsb+WbLv02g/dI5BUmZnIyOe7RzZtLax81nnb2HbvC2tzA==", "dev": true }, "pug": { diff --git a/package.json b/package.json index 2c8be76d..de8bfbff 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "devDependencies": { "@autorest/autorest": "https://github.com/Azure/autorest/releases/download/autorest-3.0.6146/autorest-autorest-3.0.6146.tgz", "@autorest/test-server": "3.0.27", - "@microsoft.azure/autorest.testserver": "^2.7.1" + "@microsoft.azure/autorest.testserver": "^2.7.2" }, "dependencies": {} } diff --git a/src/AutoRest.CSharp.V3/Plugins/Modeler.cs b/src/AutoRest.CSharp.V3/Plugins/Modeler.cs index b383ce12..c142b4af 100644 --- a/src/AutoRest.CSharp.V3/Plugins/Modeler.cs +++ b/src/AutoRest.CSharp.V3/Plugins/Modeler.cs @@ -97,7 +97,7 @@ namespace AutoRest.CSharp.V3.Plugins switch (requestParameter.Schema) { case ConstantSchema constant: - constantOrParameter = ParseClientConstant(constant.Value.Value, CreateType(constant.ValueType, true)); + constantOrParameter = ParseClientConstant(constant.Value.Value, CreateType(constant.ValueType, constant.Value.Value == null)); valueSchema = constant.ValueType; break; case BinarySchema _: diff --git a/test/AutoRest.TestServer.Tests/Infrastructure/TestServerTestBase.cs b/test/AutoRest.TestServer.Tests/Infrastructure/TestServerTestBase.cs index 1a8b5bd1..a4a0bfa2 100644 --- a/test/AutoRest.TestServer.Tests/Infrastructure/TestServerTestBase.cs +++ b/test/AutoRest.TestServer.Tests/Infrastructure/TestServerTestBase.cs @@ -54,7 +54,7 @@ namespace AutoRest.TestServer.Tests.Infrastructure if (missingScenarios.Any()) { - Assert.Fail("Expected scenarios " + string.Join(Environment.NewLine, missingScenarios) + " not defined"); + Assert.Fail("Expected scenarios " + string.Join(Environment.NewLine, missingScenarios.OrderBy(s=>s)) + " not defined"); } } @@ -71,6 +71,15 @@ namespace AutoRest.TestServer.Tests.Infrastructure Assert.AreEqual(200, response.Status, "Unexpected response " + response.ReasonPhrase); }); + public Task Test(Action test, bool ignoreScenario = false) + { + return Test(GetScenarioName(), (host, pipeline) => + { + test(host, pipeline); + return Task.CompletedTask; + }, ignoreScenario); + } + public Task Test(Func test, bool ignoreScenario = false) { return Test(GetScenarioName(), test, ignoreScenario); diff --git a/test/AutoRest.TestServer.Tests/Infrastructure/TestServerV1.cs b/test/AutoRest.TestServer.Tests/Infrastructure/TestServerV1.cs index 696f6cab..60e9504e 100644 --- a/test/AutoRest.TestServer.Tests/Infrastructure/TestServerV1.cs +++ b/test/AutoRest.TestServer.Tests/Infrastructure/TestServerV1.cs @@ -15,7 +15,7 @@ namespace AutoRest.TestServer.Tests.Infrastructure { public class TestServerV1 : IDisposable, ITestServer { - private static Regex _scenariosRegex = new Regex("(coverage|optionalCoverage)\\[(\"|')(?\\w+)(\"|')\\]", RegexOptions.Compiled); + private static Regex _scenariosRegex = new Regex("(coverage|optionalCoverage|optCoverage)\\[(\"|')(?\\w+)(\"|')\\]", RegexOptions.Compiled); private Process _process; public HttpClient Client { get; } @@ -109,6 +109,7 @@ namespace AutoRest.TestServer.Tests.Infrastructure foreach (var request in coverageDocument.RootElement.EnumerateObject()) { var mapping = request.Name; + if (request.Value.ValueKind != JsonValueKind.Number) continue; int value = request.Value.GetInt32(); // HeaderParameterProtectedKey is always matched if (mapping == "HeaderParameterProtectedKey" && value == 1) diff --git a/test/AutoRest.TestServer.Tests/body-integer.cs b/test/AutoRest.TestServer.Tests/body-integer.cs new file mode 100644 index 00000000..731467f4 --- /dev/null +++ b/test/AutoRest.TestServer.Tests/body-integer.cs @@ -0,0 +1,98 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Text.Json; +using System.Threading.Tasks; +using AutoRest.TestServer.Tests.Infrastructure; +using body_integer; +using NUnit.Framework; + +namespace AutoRest.TestServer.Tests +{ + public class IntegerTest : TestServerTestBase + { + public IntegerTest(TestServerVersion version) : base(version, "int") { } + + [Test] + public Task GetIntegerOverflow() => Test((host, pipeline) => + { + Assert.ThrowsAsync(async () => await IntOperations.GetOverflowInt32Async(ClientDiagnostics, pipeline, host)); + }); + + [Test] + public Task GetIntegerUnderflow() => Test((host, pipeline) => + { + Assert.ThrowsAsync(async () => await IntOperations.GetUnderflowInt32Async(ClientDiagnostics, pipeline, host)); + }); + + [Test] + public Task GetIntegerInvalid() => Test((host, pipeline) => + { + Assert.ThrowsAsync(Is.InstanceOf(), async () => await IntOperations.GetInvalidAsync(ClientDiagnostics, pipeline, host)); + }); + + [Test] + public Task GetLongOverflow() => Test((host, pipeline) => + { + Assert.ThrowsAsync(async () => await IntOperations.GetOverflowInt64Async(ClientDiagnostics, pipeline, host)); + }); + + [Test] + public Task GetLongUnderflow() => Test((host, pipeline) => + { + Assert.ThrowsAsync(async () => await IntOperations.GetUnderflowInt64Async(ClientDiagnostics, pipeline, host)); + }); + + [Test] + [Ignore("Unit time in json not implemented")] + public Task GetUnixTime() => TestStatus(async (host, pipeline) => + { + var response = await IntOperations.GetUnixTimeAsync(ClientDiagnostics, pipeline, host); + Assert.AreEqual(DateTimeOffset.FromUnixTimeSeconds(1460505600), response.Value); + return response.GetRawResponse(); + }); + + [Test] + [Ignore("Nullable return types are not implemented")] + public Task GetNullUnixTime() => TestStatus(async (host, pipeline) => + { + var response = await IntOperations.GetNullUnixTimeAsync(ClientDiagnostics, pipeline, host); + Assert.AreEqual(null, response.Value); + return response.GetRawResponse(); + }); + + [Test] + [Ignore("Nullable return types are not implemented")] + public Task GetIntegerNull() => TestStatus(async (host, pipeline) => + { + var response = await IntOperations.GetNullAsync(ClientDiagnostics, pipeline, host); + Assert.AreEqual(null, response.Value); + return response.GetRawResponse(); + }); + + [Test] + public Task GetInvalidUnixTime() => Test((host, pipeline) => + { + Assert.ThrowsAsync(Is.InstanceOf(),async () => await IntOperations.GetInvalidUnixTimeAsync(ClientDiagnostics, pipeline, host)); + }); + + [Test] + public Task PutIntegerMax() => TestStatus(async (host, pipeline) => await IntOperations.PutMax32Async(ClientDiagnostics, pipeline, int.MaxValue, host)); + + [Test] + [IgnoreOnTestServer(TestServerVersion.V2, "Match too strict")] + public Task PutLongMax() => TestStatus(async (host, pipeline) => await IntOperations.PutMax64Async(ClientDiagnostics, pipeline, long.MaxValue, host)); + + [Test] + public Task PutIntegerMin() => TestStatus(async (host, pipeline) => await IntOperations.PutMin32Async(ClientDiagnostics, pipeline, int.MinValue, host)); + + [Test] + [IgnoreOnTestServer(TestServerVersion.V2, "Match too strict")] + public Task PutLongMin() => TestStatus(async (host, pipeline) => await IntOperations.PutMin64Async(ClientDiagnostics, pipeline, long.MinValue, host)); + + [Test] + [Ignore("Unit time in json not implemented")] + public Task PutUnixTime() => TestStatus(async (host, pipeline) => await IntOperations.PutUnixTimeDateAsync(ClientDiagnostics, pipeline, DateTimeOffset.FromUnixTimeSeconds(1460505600), host)); + } +} diff --git a/test/AutoRest.TestServer.Tests/body-number.cs b/test/AutoRest.TestServer.Tests/body-number.cs new file mode 100644 index 00000000..9e44f77d --- /dev/null +++ b/test/AutoRest.TestServer.Tests/body-number.cs @@ -0,0 +1,160 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System.Text.Json; +using System.Threading.Tasks; +using AutoRest.TestServer.Tests.Infrastructure; +using body_number; +using NUnit.Framework; + +namespace AutoRest.TestServer.Tests +{ + public class NumberTest : TestServerTestBase + { + public NumberTest(TestServerVersion version) : base(version, "number") { } + + [Test] + public Task PutFloatBigScientificNotation() => TestStatus(async (host, pipeline) => await NumberOperations.PutBigFloatAsync(ClientDiagnostics, pipeline, 3.402823e+20f, host)); + + [Test] + public Task PutFloatSmallScientificNotation() => TestStatus(async (host, pipeline) => await NumberOperations.PutSmallFloatAsync(ClientDiagnostics, pipeline, 3.402823e-20f, host)); + + [Test] + public Task PutDoubleSmallScientificNotation() => TestStatus(async (host, pipeline) => await NumberOperations.PutSmallDoubleAsync(ClientDiagnostics, pipeline, 2.5976931e-101d, host)); + + [Test] + public Task PutDoubleBigScientificNotation() => TestStatus(async (host, pipeline) => await NumberOperations.PutBigDoubleAsync(ClientDiagnostics, pipeline, 2.5976931e+101d, host)); + + [Test] + [IgnoreOnTestServer(TestServerVersion.V2, "Match too strict")] + public Task PutDecimalBigPositiveDecimal() => TestStatus(async (host, pipeline) => await NumberOperations.PutBigDecimalPositiveDecimalAsync(ClientDiagnostics, pipeline, host)); + + [Test] + [Ignore("Value 2.5976931e+101 is out of range of C# decimal")] + public Task PutDecimalBig() => TestStatus(async (host, pipeline) => await NumberOperations.PutBigDecimalAsync(ClientDiagnostics, pipeline, 2.5976931e+10m, host)); + + [Test] + [IgnoreOnTestServer(TestServerVersion.V2, "Match too strict")] + public Task PutDecimalBigNegativeDecimal() => TestStatus(async (host, pipeline) => await NumberOperations.PutBigDecimalNegativeDecimalAsync(ClientDiagnostics, pipeline, host)); + + [Test] + [Ignore("Value 2.5976931e-101m is out of range of C# decimal")] + public Task PutDecimalSmall() => TestStatus(async (host, pipeline) => await NumberOperations.PutSmallDecimalAsync(ClientDiagnostics, pipeline, 2.5976931e-101m, host)); + + [Test] + public Task PutDoubleBigNegativeDecimal() => TestStatus(async (host, pipeline) => await NumberOperations.PutBigDoubleNegativeDecimalAsync(ClientDiagnostics, pipeline, host)); + + [Test] + public Task PutDoubleBigPositiveDecimal() => TestStatus(async (host, pipeline) => await NumberOperations.PutBigDoublePositiveDecimalAsync(ClientDiagnostics, pipeline, host)); + + [Test] + public Task GetDecimalInvalid() => Test((host, pipeline) => + { + Assert.ThrowsAsync(Is.InstanceOf(), async () => await NumberOperations.GetInvalidDecimalAsync(ClientDiagnostics, pipeline, host)); + }); + + [Test] + public Task GetDoubleInvalid() => Test((host, pipeline) => + { + Assert.ThrowsAsync(Is.InstanceOf(), async () => await NumberOperations.GetInvalidDoubleAsync(ClientDiagnostics, pipeline, host)); + }); + + [Test] + public Task GetFloatInvalid() => Test((host, pipeline) => + { + Assert.ThrowsAsync(Is.InstanceOf(), async () => await NumberOperations.GetInvalidFloatAsync(ClientDiagnostics, pipeline, host)); + }); + + [Test] + [Ignore("Value 2.5976931e+101 is out of range of C# decimal")] + public Task GetDecimalBig() => TestStatus(async (host, pipeline) => + { + var response = await NumberOperations.GetBigDecimalAsync(ClientDiagnostics, pipeline, host); + Assert.AreEqual(2.5976931e+101, response.Value); + return response.GetRawResponse(); + }); + + [Test] + public Task GetDecimalBigNegativeDecimal() => TestStatus(async (host, pipeline) => + { + var response = await NumberOperations.GetBigDecimalNegativeDecimalAsync(ClientDiagnostics, pipeline, host); + Assert.AreEqual(-99999999.99m, response.Value); + return response.GetRawResponse(); + }); + + [Test] + public Task GetDecimalBigPositiveDecimal() => TestStatus(async (host, pipeline) => + { + var response = await NumberOperations.GetBigDecimalPositiveDecimalAsync(ClientDiagnostics, pipeline, host); + Assert.AreEqual(99999999.99m, response.Value); + return response.GetRawResponse(); + }); + + [Test] + [Ignore("Value is out of range of C# decimal")] + public Task GetDecimalSmall() => TestStatus(async (host, pipeline) => + { + var response = await NumberOperations.GetSmallDecimalAsync(ClientDiagnostics, pipeline, host); + Assert.AreEqual(2.5976931e-101m, response.Value); + return response.GetRawResponse(); + }); + + + [Test] + public Task GetDoubleBigScientificNotation() => TestStatus(async (host, pipeline) => + { + var response = await NumberOperations.GetBigDoubleAsync(ClientDiagnostics, pipeline, host); + Assert.AreEqual(2.5976931E+101d, response.Value); + return response.GetRawResponse(); + }); + + [Test] + public Task GetDoubleBigNegativeDecimal() => TestStatus(async (host, pipeline) => + { + var response = await NumberOperations.GetBigDoubleNegativeDecimalAsync(ClientDiagnostics, pipeline, host); + Assert.AreEqual(-99999999.989999995d, response.Value); + return response.GetRawResponse(); + }); + + [Test] + public Task GetDoubleBigPositiveDecimal() => TestStatus(async (host, pipeline) => + { + var response = await NumberOperations.GetBigDoublePositiveDecimalAsync(ClientDiagnostics, pipeline, host); + Assert.AreEqual(99999999.989999995d, response.Value); + return response.GetRawResponse(); + }); + + [Test] + public Task GetDoubleSmallScientificNotation() => TestStatus(async (host, pipeline) => + { + var response = await NumberOperations.GetSmallDoubleAsync(ClientDiagnostics, pipeline, host); + Assert.AreEqual(2.5976931000000001E-101d, response.Value); + return response.GetRawResponse(); + }); + + [Test] + public Task GetFloatBigScientificNotation() => TestStatus(async (host, pipeline) => + { + var response = await NumberOperations.GetBigFloatAsync(ClientDiagnostics, pipeline, host); + Assert.AreEqual(3.40282312E+20f, response.Value); + return response.GetRawResponse(); + }); + + [Test] + public Task GetFloatSmallScientificNotation() => TestStatus(async (host, pipeline) => + { + var response = await NumberOperations.GetSmallFloatAsync(ClientDiagnostics, pipeline, host); + Assert.AreEqual(3.4028229999999997E-20d, response.Value); + return response.GetRawResponse(); + }); + + [Test] + [Ignore("No support for null results")] + public Task GetNumberNull() => TestStatus(async (host, pipeline) => + { + var response = await NumberOperations.GetNullAsync(ClientDiagnostics, pipeline, host); + Assert.Null(response.Value); + return response.GetRawResponse(); + }); + } +} diff --git a/test/TestServerProjects/body-integer/Generated/Models/Error.Serialization.cs b/test/TestServerProjects/body-integer/Generated/Models/Error.Serialization.cs new file mode 100644 index 00000000..077463b4 --- /dev/null +++ b/test/TestServerProjects/body-integer/Generated/Models/Error.Serialization.cs @@ -0,0 +1,44 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System.Text.Json; + +namespace body_integer.Models.V100 +{ + public partial class Error + { + internal void Serialize(Utf8JsonWriter writer) + { + writer.WriteStartObject(); + if (Status != null) + { + writer.WritePropertyName("status"); + writer.WriteNumberValue(Status.Value); + } + if (Message != null) + { + writer.WritePropertyName("message"); + writer.WriteStringValue(Message); + } + writer.WriteEndObject(); + } + internal static Error Deserialize(JsonElement element) + { + var result = new Error(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("status")) + { + result.Status = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("message")) + { + result.Message = property.Value.GetString(); + continue; + } + } + return result; + } + } +} diff --git a/test/TestServerProjects/body-integer/Generated/Models/Error.cs b/test/TestServerProjects/body-integer/Generated/Models/Error.cs new file mode 100644 index 00000000..3bb89722 --- /dev/null +++ b/test/TestServerProjects/body-integer/Generated/Models/Error.cs @@ -0,0 +1,11 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace body_integer.Models.V100 +{ + public partial class Error + { + public int? Status { get; set; } + public string? Message { get; set; } + } +} diff --git a/test/TestServerProjects/body-integer/Generated/Operations/IntOperations.cs b/test/TestServerProjects/body-integer/Generated/Operations/IntOperations.cs new file mode 100644 index 00000000..580d8d43 --- /dev/null +++ b/test/TestServerProjects/body-integer/Generated/Operations/IntOperations.cs @@ -0,0 +1,441 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Text.Json; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; + +namespace body_integer +{ + internal static class IntOperations + { + public static async ValueTask> GetNullAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) + { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + + using var scope = clientDiagnostics.CreateScope("body_integer.GetNull"); + scope.Start(); + try + { + var request = pipeline.CreateRequest(); + request.Method = RequestMethod.Get; + request.Uri.Reset(new Uri($"{host}")); + request.Uri.AppendPath("/int/null", false); + var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); + using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); + switch (response.Status) + { + case 200: + return Response.FromValue(document.RootElement.GetInt32(), response); + default: + throw new Exception(); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + public static async ValueTask> GetInvalidAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) + { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + + using var scope = clientDiagnostics.CreateScope("body_integer.GetInvalid"); + scope.Start(); + try + { + var request = pipeline.CreateRequest(); + request.Method = RequestMethod.Get; + request.Uri.Reset(new Uri($"{host}")); + request.Uri.AppendPath("/int/invalid", false); + var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); + using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); + switch (response.Status) + { + case 200: + return Response.FromValue(document.RootElement.GetInt32(), response); + default: + throw new Exception(); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + public static async ValueTask> GetOverflowInt32Async(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) + { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + + using var scope = clientDiagnostics.CreateScope("body_integer.GetOverflowInt32"); + scope.Start(); + try + { + var request = pipeline.CreateRequest(); + request.Method = RequestMethod.Get; + request.Uri.Reset(new Uri($"{host}")); + request.Uri.AppendPath("/int/overflowint32", false); + var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); + using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); + switch (response.Status) + { + case 200: + return Response.FromValue(document.RootElement.GetInt32(), response); + default: + throw new Exception(); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + public static async ValueTask> GetUnderflowInt32Async(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) + { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + + using var scope = clientDiagnostics.CreateScope("body_integer.GetUnderflowInt32"); + scope.Start(); + try + { + var request = pipeline.CreateRequest(); + request.Method = RequestMethod.Get; + request.Uri.Reset(new Uri($"{host}")); + request.Uri.AppendPath("/int/underflowint32", false); + var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); + using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); + switch (response.Status) + { + case 200: + return Response.FromValue(document.RootElement.GetInt32(), response); + default: + throw new Exception(); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + public static async ValueTask> GetOverflowInt64Async(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) + { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + + using var scope = clientDiagnostics.CreateScope("body_integer.GetOverflowInt64"); + scope.Start(); + try + { + var request = pipeline.CreateRequest(); + request.Method = RequestMethod.Get; + request.Uri.Reset(new Uri($"{host}")); + request.Uri.AppendPath("/int/overflowint64", false); + var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); + using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); + switch (response.Status) + { + case 200: + return Response.FromValue(document.RootElement.GetInt64(), response); + default: + throw new Exception(); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + public static async ValueTask> GetUnderflowInt64Async(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) + { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + + using var scope = clientDiagnostics.CreateScope("body_integer.GetUnderflowInt64"); + scope.Start(); + try + { + var request = pipeline.CreateRequest(); + request.Method = RequestMethod.Get; + request.Uri.Reset(new Uri($"{host}")); + request.Uri.AppendPath("/int/underflowint64", false); + var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); + using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); + switch (response.Status) + { + case 200: + return Response.FromValue(document.RootElement.GetInt64(), response); + default: + throw new Exception(); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + public static async ValueTask PutMax32Async(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, int intBody, string host = "http://localhost:3000", CancellationToken cancellationToken = default) + { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + + using var scope = clientDiagnostics.CreateScope("body_integer.PutMax32"); + scope.Start(); + try + { + var request = pipeline.CreateRequest(); + request.Method = RequestMethod.Put; + request.Uri.Reset(new Uri($"{host}")); + request.Uri.AppendPath("/int/max/32", false); + request.Headers.Add("Content-Type", "application/json"); + using var content = new Utf8JsonRequestContent(); + var writer = content.JsonWriter; + writer.WriteNumberValue(intBody); + request.Content = content; + var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); + return response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + public static async ValueTask PutMax64Async(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, long intBody, string host = "http://localhost:3000", CancellationToken cancellationToken = default) + { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + + using var scope = clientDiagnostics.CreateScope("body_integer.PutMax64"); + scope.Start(); + try + { + var request = pipeline.CreateRequest(); + request.Method = RequestMethod.Put; + request.Uri.Reset(new Uri($"{host}")); + request.Uri.AppendPath("/int/max/64", false); + request.Headers.Add("Content-Type", "application/json"); + using var content = new Utf8JsonRequestContent(); + var writer = content.JsonWriter; + writer.WriteNumberValue(intBody); + request.Content = content; + var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); + return response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + public static async ValueTask PutMin32Async(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, int intBody, string host = "http://localhost:3000", CancellationToken cancellationToken = default) + { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + + using var scope = clientDiagnostics.CreateScope("body_integer.PutMin32"); + scope.Start(); + try + { + var request = pipeline.CreateRequest(); + request.Method = RequestMethod.Put; + request.Uri.Reset(new Uri($"{host}")); + request.Uri.AppendPath("/int/min/32", false); + request.Headers.Add("Content-Type", "application/json"); + using var content = new Utf8JsonRequestContent(); + var writer = content.JsonWriter; + writer.WriteNumberValue(intBody); + request.Content = content; + var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); + return response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + public static async ValueTask PutMin64Async(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, long intBody, string host = "http://localhost:3000", CancellationToken cancellationToken = default) + { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + + using var scope = clientDiagnostics.CreateScope("body_integer.PutMin64"); + scope.Start(); + try + { + var request = pipeline.CreateRequest(); + request.Method = RequestMethod.Put; + request.Uri.Reset(new Uri($"{host}")); + request.Uri.AppendPath("/int/min/64", false); + request.Headers.Add("Content-Type", "application/json"); + using var content = new Utf8JsonRequestContent(); + var writer = content.JsonWriter; + writer.WriteNumberValue(intBody); + request.Content = content; + var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); + return response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + public static async ValueTask> GetUnixTimeAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) + { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + + using var scope = clientDiagnostics.CreateScope("body_integer.GetUnixTime"); + scope.Start(); + try + { + var request = pipeline.CreateRequest(); + request.Method = RequestMethod.Get; + request.Uri.Reset(new Uri($"{host}")); + request.Uri.AppendPath("/int/unixtime", false); + var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); + using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); + switch (response.Status) + { + case 200: + return Response.FromValue(document.RootElement.GetDateTimeOffset(), response); + default: + throw new Exception(); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + public static async ValueTask PutUnixTimeDateAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, DateTimeOffset intBody, string host = "http://localhost:3000", CancellationToken cancellationToken = default) + { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + + using var scope = clientDiagnostics.CreateScope("body_integer.PutUnixTimeDate"); + scope.Start(); + try + { + var request = pipeline.CreateRequest(); + request.Method = RequestMethod.Put; + request.Uri.Reset(new Uri($"{host}")); + request.Uri.AppendPath("/int/unixtime", false); + request.Headers.Add("Content-Type", "application/json"); + using var content = new Utf8JsonRequestContent(); + var writer = content.JsonWriter; + writer.WriteStringValue(intBody.ToString()); + request.Content = content; + var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); + return response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + public static async ValueTask> GetInvalidUnixTimeAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) + { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + + using var scope = clientDiagnostics.CreateScope("body_integer.GetInvalidUnixTime"); + scope.Start(); + try + { + var request = pipeline.CreateRequest(); + request.Method = RequestMethod.Get; + request.Uri.Reset(new Uri($"{host}")); + request.Uri.AppendPath("/int/invalidunixtime", false); + var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); + using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); + switch (response.Status) + { + case 200: + return Response.FromValue(document.RootElement.GetDateTimeOffset(), response); + default: + throw new Exception(); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + public static async ValueTask> GetNullUnixTimeAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) + { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + + using var scope = clientDiagnostics.CreateScope("body_integer.GetNullUnixTime"); + scope.Start(); + try + { + var request = pipeline.CreateRequest(); + request.Method = RequestMethod.Get; + request.Uri.Reset(new Uri($"{host}")); + request.Uri.AppendPath("/int/nullunixtime", false); + var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); + using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); + switch (response.Status) + { + case 200: + return Response.FromValue(document.RootElement.GetDateTimeOffset(), response); + default: + throw new Exception(); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + } +} diff --git a/test/TestServerProjects/body-integer/body-integer.csproj b/test/TestServerProjects/body-integer/body-integer.csproj new file mode 100644 index 00000000..409c8953 --- /dev/null +++ b/test/TestServerProjects/body-integer/body-integer.csproj @@ -0,0 +1,15 @@ + + + + netstandard2.0 + true + annotations + + + + + + + + + diff --git a/test/TestServerProjects/body-number/Generated/Models/Error.Serialization.cs b/test/TestServerProjects/body-number/Generated/Models/Error.Serialization.cs new file mode 100644 index 00000000..a8935fd4 --- /dev/null +++ b/test/TestServerProjects/body-number/Generated/Models/Error.Serialization.cs @@ -0,0 +1,44 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System.Text.Json; + +namespace body_number.Models.V100 +{ + public partial class Error + { + internal void Serialize(Utf8JsonWriter writer) + { + writer.WriteStartObject(); + if (Status != null) + { + writer.WritePropertyName("status"); + writer.WriteNumberValue(Status.Value); + } + if (Message != null) + { + writer.WritePropertyName("message"); + writer.WriteStringValue(Message); + } + writer.WriteEndObject(); + } + internal static Error Deserialize(JsonElement element) + { + var result = new Error(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("status")) + { + result.Status = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("message")) + { + result.Message = property.Value.GetString(); + continue; + } + } + return result; + } + } +} diff --git a/test/TestServerProjects/body-number/Generated/Models/Error.cs b/test/TestServerProjects/body-number/Generated/Models/Error.cs new file mode 100644 index 00000000..ca2d02f0 --- /dev/null +++ b/test/TestServerProjects/body-number/Generated/Models/Error.cs @@ -0,0 +1,11 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace body_number.Models.V100 +{ + public partial class Error + { + public int? Status { get; set; } + public string? Message { get; set; } + } +} diff --git a/test/TestServerProjects/body-number/Generated/Operations/NumberOperations.cs b/test/TestServerProjects/body-number/Generated/Operations/NumberOperations.cs new file mode 100644 index 00000000..622830e1 --- /dev/null +++ b/test/TestServerProjects/body-number/Generated/Operations/NumberOperations.cs @@ -0,0 +1,741 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Text.Json; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; + +namespace body_number +{ + internal static class NumberOperations + { + public static async ValueTask> GetNullAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) + { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + + using var scope = clientDiagnostics.CreateScope("body_number.GetNull"); + scope.Start(); + try + { + var request = pipeline.CreateRequest(); + request.Method = RequestMethod.Get; + request.Uri.Reset(new Uri($"{host}")); + request.Uri.AppendPath("/number/null", false); + var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); + using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); + switch (response.Status) + { + case 200: + return Response.FromValue(document.RootElement.GetSingle(), response); + default: + throw new Exception(); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + public static async ValueTask> GetInvalidFloatAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) + { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + + using var scope = clientDiagnostics.CreateScope("body_number.GetInvalidFloat"); + scope.Start(); + try + { + var request = pipeline.CreateRequest(); + request.Method = RequestMethod.Get; + request.Uri.Reset(new Uri($"{host}")); + request.Uri.AppendPath("/number/invalidfloat", false); + var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); + using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); + switch (response.Status) + { + case 200: + return Response.FromValue(document.RootElement.GetSingle(), response); + default: + throw new Exception(); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + public static async ValueTask> GetInvalidDoubleAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) + { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + + using var scope = clientDiagnostics.CreateScope("body_number.GetInvalidDouble"); + scope.Start(); + try + { + var request = pipeline.CreateRequest(); + request.Method = RequestMethod.Get; + request.Uri.Reset(new Uri($"{host}")); + request.Uri.AppendPath("/number/invaliddouble", false); + var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); + using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); + switch (response.Status) + { + case 200: + return Response.FromValue(document.RootElement.GetDouble(), response); + default: + throw new Exception(); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + public static async ValueTask> GetInvalidDecimalAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) + { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + + using var scope = clientDiagnostics.CreateScope("body_number.GetInvalidDecimal"); + scope.Start(); + try + { + var request = pipeline.CreateRequest(); + request.Method = RequestMethod.Get; + request.Uri.Reset(new Uri($"{host}")); + request.Uri.AppendPath("/number/invaliddecimal", false); + var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); + using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); + switch (response.Status) + { + case 200: + return Response.FromValue(document.RootElement.GetDecimal(), response); + default: + throw new Exception(); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + public static async ValueTask PutBigFloatAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, float numberBody, string host = "http://localhost:3000", CancellationToken cancellationToken = default) + { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + + using var scope = clientDiagnostics.CreateScope("body_number.PutBigFloat"); + scope.Start(); + try + { + var request = pipeline.CreateRequest(); + request.Method = RequestMethod.Put; + request.Uri.Reset(new Uri($"{host}")); + request.Uri.AppendPath("/number/big/float/3.402823e+20", false); + request.Headers.Add("Content-Type", "application/json"); + using var content = new Utf8JsonRequestContent(); + var writer = content.JsonWriter; + writer.WriteNumberValue(numberBody); + request.Content = content; + var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); + return response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + public static async ValueTask> GetBigFloatAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) + { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + + using var scope = clientDiagnostics.CreateScope("body_number.GetBigFloat"); + scope.Start(); + try + { + var request = pipeline.CreateRequest(); + request.Method = RequestMethod.Get; + request.Uri.Reset(new Uri($"{host}")); + request.Uri.AppendPath("/number/big/float/3.402823e+20", false); + var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); + using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); + switch (response.Status) + { + case 200: + return Response.FromValue(document.RootElement.GetSingle(), response); + default: + throw new Exception(); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + public static async ValueTask PutBigDoubleAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, double numberBody, string host = "http://localhost:3000", CancellationToken cancellationToken = default) + { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + + using var scope = clientDiagnostics.CreateScope("body_number.PutBigDouble"); + scope.Start(); + try + { + var request = pipeline.CreateRequest(); + request.Method = RequestMethod.Put; + request.Uri.Reset(new Uri($"{host}")); + request.Uri.AppendPath("/number/big/double/2.5976931e+101", false); + request.Headers.Add("Content-Type", "application/json"); + using var content = new Utf8JsonRequestContent(); + var writer = content.JsonWriter; + writer.WriteNumberValue(numberBody); + request.Content = content; + var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); + return response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + public static async ValueTask> GetBigDoubleAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) + { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + + using var scope = clientDiagnostics.CreateScope("body_number.GetBigDouble"); + scope.Start(); + try + { + var request = pipeline.CreateRequest(); + request.Method = RequestMethod.Get; + request.Uri.Reset(new Uri($"{host}")); + request.Uri.AppendPath("/number/big/double/2.5976931e+101", false); + var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); + using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); + switch (response.Status) + { + case 200: + return Response.FromValue(document.RootElement.GetDouble(), response); + default: + throw new Exception(); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + public static async ValueTask PutBigDoublePositiveDecimalAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) + { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + + using var scope = clientDiagnostics.CreateScope("body_number.PutBigDoublePositiveDecimal"); + scope.Start(); + try + { + var request = pipeline.CreateRequest(); + request.Method = RequestMethod.Put; + request.Uri.Reset(new Uri($"{host}")); + request.Uri.AppendPath("/number/big/double/99999999.99", false); + request.Headers.Add("Content-Type", "application/json"); + using var content = new Utf8JsonRequestContent(); + var writer = content.JsonWriter; + writer.WriteNumberValue(99999999.99); + request.Content = content; + var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); + return response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + public static async ValueTask> GetBigDoublePositiveDecimalAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) + { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + + using var scope = clientDiagnostics.CreateScope("body_number.GetBigDoublePositiveDecimal"); + scope.Start(); + try + { + var request = pipeline.CreateRequest(); + request.Method = RequestMethod.Get; + request.Uri.Reset(new Uri($"{host}")); + request.Uri.AppendPath("/number/big/double/99999999.99", false); + var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); + using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); + switch (response.Status) + { + case 200: + return Response.FromValue(document.RootElement.GetDouble(), response); + default: + throw new Exception(); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + public static async ValueTask PutBigDoubleNegativeDecimalAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) + { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + + using var scope = clientDiagnostics.CreateScope("body_number.PutBigDoubleNegativeDecimal"); + scope.Start(); + try + { + var request = pipeline.CreateRequest(); + request.Method = RequestMethod.Put; + request.Uri.Reset(new Uri($"{host}")); + request.Uri.AppendPath("/number/big/double/-99999999.99", false); + request.Headers.Add("Content-Type", "application/json"); + using var content = new Utf8JsonRequestContent(); + var writer = content.JsonWriter; + writer.WriteNumberValue(-99999999.99); + request.Content = content; + var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); + return response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + public static async ValueTask> GetBigDoubleNegativeDecimalAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) + { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + + using var scope = clientDiagnostics.CreateScope("body_number.GetBigDoubleNegativeDecimal"); + scope.Start(); + try + { + var request = pipeline.CreateRequest(); + request.Method = RequestMethod.Get; + request.Uri.Reset(new Uri($"{host}")); + request.Uri.AppendPath("/number/big/double/-99999999.99", false); + var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); + using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); + switch (response.Status) + { + case 200: + return Response.FromValue(document.RootElement.GetDouble(), response); + default: + throw new Exception(); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + public static async ValueTask PutBigDecimalAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, decimal numberBody, string host = "http://localhost:3000", CancellationToken cancellationToken = default) + { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + + using var scope = clientDiagnostics.CreateScope("body_number.PutBigDecimal"); + scope.Start(); + try + { + var request = pipeline.CreateRequest(); + request.Method = RequestMethod.Put; + request.Uri.Reset(new Uri($"{host}")); + request.Uri.AppendPath("/number/big/decimal/2.5976931e+101", false); + request.Headers.Add("Content-Type", "application/json"); + using var content = new Utf8JsonRequestContent(); + var writer = content.JsonWriter; + writer.WriteNumberValue(numberBody); + request.Content = content; + var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); + return response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + public static async ValueTask> GetBigDecimalAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) + { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + + using var scope = clientDiagnostics.CreateScope("body_number.GetBigDecimal"); + scope.Start(); + try + { + var request = pipeline.CreateRequest(); + request.Method = RequestMethod.Get; + request.Uri.Reset(new Uri($"{host}")); + request.Uri.AppendPath("/number/big/decimal/2.5976931e+101", false); + var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); + using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); + switch (response.Status) + { + case 200: + return Response.FromValue(document.RootElement.GetDecimal(), response); + default: + throw new Exception(); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + public static async ValueTask PutBigDecimalPositiveDecimalAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) + { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + + using var scope = clientDiagnostics.CreateScope("body_number.PutBigDecimalPositiveDecimal"); + scope.Start(); + try + { + var request = pipeline.CreateRequest(); + request.Method = RequestMethod.Put; + request.Uri.Reset(new Uri($"{host}")); + request.Uri.AppendPath("/number/big/decimal/99999999.99", false); + request.Headers.Add("Content-Type", "application/json"); + using var content = new Utf8JsonRequestContent(); + var writer = content.JsonWriter; + writer.WriteNumberValue(99999999.99); + request.Content = content; + var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); + return response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + public static async ValueTask> GetBigDecimalPositiveDecimalAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) + { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + + using var scope = clientDiagnostics.CreateScope("body_number.GetBigDecimalPositiveDecimal"); + scope.Start(); + try + { + var request = pipeline.CreateRequest(); + request.Method = RequestMethod.Get; + request.Uri.Reset(new Uri($"{host}")); + request.Uri.AppendPath("/number/big/decimal/99999999.99", false); + var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); + using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); + switch (response.Status) + { + case 200: + return Response.FromValue(document.RootElement.GetDecimal(), response); + default: + throw new Exception(); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + public static async ValueTask PutBigDecimalNegativeDecimalAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) + { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + + using var scope = clientDiagnostics.CreateScope("body_number.PutBigDecimalNegativeDecimal"); + scope.Start(); + try + { + var request = pipeline.CreateRequest(); + request.Method = RequestMethod.Put; + request.Uri.Reset(new Uri($"{host}")); + request.Uri.AppendPath("/number/big/decimal/-99999999.99", false); + request.Headers.Add("Content-Type", "application/json"); + using var content = new Utf8JsonRequestContent(); + var writer = content.JsonWriter; + writer.WriteNumberValue(-99999999.99); + request.Content = content; + var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); + return response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + public static async ValueTask> GetBigDecimalNegativeDecimalAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) + { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + + using var scope = clientDiagnostics.CreateScope("body_number.GetBigDecimalNegativeDecimal"); + scope.Start(); + try + { + var request = pipeline.CreateRequest(); + request.Method = RequestMethod.Get; + request.Uri.Reset(new Uri($"{host}")); + request.Uri.AppendPath("/number/big/decimal/-99999999.99", false); + var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); + using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); + switch (response.Status) + { + case 200: + return Response.FromValue(document.RootElement.GetDecimal(), response); + default: + throw new Exception(); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + public static async ValueTask PutSmallFloatAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, float numberBody, string host = "http://localhost:3000", CancellationToken cancellationToken = default) + { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + + using var scope = clientDiagnostics.CreateScope("body_number.PutSmallFloat"); + scope.Start(); + try + { + var request = pipeline.CreateRequest(); + request.Method = RequestMethod.Put; + request.Uri.Reset(new Uri($"{host}")); + request.Uri.AppendPath("/number/small/float/3.402823e-20", false); + request.Headers.Add("Content-Type", "application/json"); + using var content = new Utf8JsonRequestContent(); + var writer = content.JsonWriter; + writer.WriteNumberValue(numberBody); + request.Content = content; + var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); + return response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + public static async ValueTask> GetSmallFloatAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) + { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + + using var scope = clientDiagnostics.CreateScope("body_number.GetSmallFloat"); + scope.Start(); + try + { + var request = pipeline.CreateRequest(); + request.Method = RequestMethod.Get; + request.Uri.Reset(new Uri($"{host}")); + request.Uri.AppendPath("/number/small/float/3.402823e-20", false); + var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); + using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); + switch (response.Status) + { + case 200: + return Response.FromValue(document.RootElement.GetDouble(), response); + default: + throw new Exception(); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + public static async ValueTask PutSmallDoubleAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, double numberBody, string host = "http://localhost:3000", CancellationToken cancellationToken = default) + { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + + using var scope = clientDiagnostics.CreateScope("body_number.PutSmallDouble"); + scope.Start(); + try + { + var request = pipeline.CreateRequest(); + request.Method = RequestMethod.Put; + request.Uri.Reset(new Uri($"{host}")); + request.Uri.AppendPath("/number/small/double/2.5976931e-101", false); + request.Headers.Add("Content-Type", "application/json"); + using var content = new Utf8JsonRequestContent(); + var writer = content.JsonWriter; + writer.WriteNumberValue(numberBody); + request.Content = content; + var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); + return response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + public static async ValueTask> GetSmallDoubleAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) + { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + + using var scope = clientDiagnostics.CreateScope("body_number.GetSmallDouble"); + scope.Start(); + try + { + var request = pipeline.CreateRequest(); + request.Method = RequestMethod.Get; + request.Uri.Reset(new Uri($"{host}")); + request.Uri.AppendPath("/number/small/double/2.5976931e-101", false); + var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); + using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); + switch (response.Status) + { + case 200: + return Response.FromValue(document.RootElement.GetDouble(), response); + default: + throw new Exception(); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + public static async ValueTask PutSmallDecimalAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, decimal numberBody, string host = "http://localhost:3000", CancellationToken cancellationToken = default) + { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + + using var scope = clientDiagnostics.CreateScope("body_number.PutSmallDecimal"); + scope.Start(); + try + { + var request = pipeline.CreateRequest(); + request.Method = RequestMethod.Put; + request.Uri.Reset(new Uri($"{host}")); + request.Uri.AppendPath("/number/small/decimal/2.5976931e-101", false); + request.Headers.Add("Content-Type", "application/json"); + using var content = new Utf8JsonRequestContent(); + var writer = content.JsonWriter; + writer.WriteNumberValue(numberBody); + request.Content = content; + var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); + return response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + public static async ValueTask> GetSmallDecimalAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default) + { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + + using var scope = clientDiagnostics.CreateScope("body_number.GetSmallDecimal"); + scope.Start(); + try + { + var request = pipeline.CreateRequest(); + request.Method = RequestMethod.Get; + request.Uri.Reset(new Uri($"{host}")); + request.Uri.AppendPath("/number/small/decimal/2.5976931e-101", false); + var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); + using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); + switch (response.Status) + { + case 200: + return Response.FromValue(document.RootElement.GetDecimal(), response); + default: + throw new Exception(); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + } +} diff --git a/test/TestServerProjects/body-number/body-number.csproj b/test/TestServerProjects/body-number/body-number.csproj new file mode 100644 index 00000000..409c8953 --- /dev/null +++ b/test/TestServerProjects/body-number/body-number.csproj @@ -0,0 +1,15 @@ + + + + netstandard2.0 + true + annotations + + + + + + + + + From 201ed13d17fbf3792b8f221e9a770b52b7bd1691 Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Wed, 11 Dec 2019 14:24:21 -0800 Subject: [PATCH 5/5] Eng script fixes (#327) * Attempting to simplify calling structure of scripts. * Still testing failures. Got it capturing properly. Going to try it on CI. * Forgot npx for CI to run. * Progressively testing changes to the scripts. * Cleaned up script code. Tested running locally for both CodeChecks.ps1 and Generate.ps1. * Addressing code review issues. * Nested try/catch caused failures to be ignored. Inverted noReset to reset, as resetting locally causes npx to not acquire the modelerfour extension. * Attempting to flush output on error for CI. * Removed flush. Trying to source the scripts instead of calling them. * Writing error instead of throwing. * Trying to see what worked before and put it into a separate file. * Removing try/catch to see affect on CI. * Minor cleanup to move toward the other script files' changes. * More cleanup of combined. Should match what is currently there. * Removed parameters to see if that is the issue. * Trying inline script. * Not calling script as inline. * This should now work as intended. * Trying something. * Trying to put the functions into a separate file and simply sourcing that file. * Made it so that the normal script files use a shared set of functions. * Just trying something. * Testing. * Added some readme information on setup and build. Trying to test old cmd call for output/failure. * Back to separate file running, just using cmd to avoid CI issues. * Cleaned up commented code in scripts. * Removed unused scripts. * Removed test failure. * Intentionally adding to generated code to cause failure. * Reverted diff check test (since it was successful). Removed keeping track of progress preference. Made CI do reset always. --- eng/CodeChecks.ps1 | 88 +++++------------------------------- eng/DownloadSharedSource.ps1 | 14 +++--- eng/Generate.ps1 | 56 +++++++++++------------ eng/pipelines/build.yml | 2 +- readme.md | 11 +++++ 5 files changed, 59 insertions(+), 112 deletions(-) diff --git a/eng/CodeChecks.ps1 b/eng/CodeChecks.ps1 index d7a5409d..fbbaae28 100644 --- a/eng/CodeChecks.ps1 +++ b/eng/CodeChecks.ps1 @@ -1,82 +1,18 @@ -#requires -version 5 - -[CmdletBinding()] -param ( - [Parameter(Position=0)] - [ValidateNotNullOrEmpty()] - [string] $ServiceDirectory -) +#Requires -Version 6.0 +param($name, [switch]$noDebug, [switch]$reset) $ErrorActionPreference = 'Stop' Set-StrictMode -Version 1 -$repoRoot = Resolve-Path "$PSScriptRoot/.." +Write-Host 'Downloading shared source files...' +& (Join-Path $PSScriptRoot 'DownloadSharedSource.ps1') -[string[]] $errors = @() +Write-Host 'Generating test clients...' +& (Join-Path $PSScriptRoot 'Generate.ps1') -function LogError([string]$message) { - if ($env:TF_BUILD) { - Write-Host "##vso[task.logissue type=error]$message" - } - Write-Host -f Red "error: $message" - $script:errors += $message -} - -function Invoke-Block([scriptblock]$cmd) { - $cmd | Out-String | Write-Verbose - try - { - & $cmd - - # Need to check both of these cases for errors as they represent different items - # - $?: did the powershell script block throw an error - # - $lastexitcode: did a windows command executed by the script block end in error - if ((-not $?) -or ($lastexitcode -ne 0)) { - if ($error -ne $null) - { - Write-Warning $error[0] - } - throw "Command failed to execute: $cmd" - } - } - catch - { - LogError $_ - } -} - -try { - Write-Host "Downloading files" - Invoke-Block { - & $PSScriptRoot\DownloadSharedSource.ps1 @script:PSBoundParameters - } - - Write-Host "Generate test clients" - Invoke-Block { - & $PSScriptRoot\Generate.ps1 @script:PSBoundParameters - } - - Write-Host "git diff" - & git -c core.safecrlf=false diff --ignore-space-at-eol --exit-code - if ($LastExitCode -ne 0) { - $status = git status -s | Out-String - $status = $status -replace "`n","`n " - LogError "Generated code is not up to date. You may need to run eng\Update-Snippets.ps1 or sdk\storage\generate.ps1 or eng\Export-API.ps1" - } -} -finally { - Write-Host "" - Write-Host "Summary:" - Write-Host "" - Write-Host " $($errors.Length) error(s)" - Write-Host "" - - foreach ($err in $errors) { - Write-Host -f Red "error : $err" - } - - if ($errors.Length -ne 0) { - exit 1 - } - exit 0 -} +Write-Host 'Checking generated file differences...' +git -c core.safecrlf=false diff --ignore-space-at-eol --exit-code +if ($LastExitCode -ne 0) +{ + Write-Error 'Generated code is not up to date. Please run: eng/Generate.ps1' +} \ No newline at end of file diff --git a/eng/DownloadSharedSource.ps1 b/eng/DownloadSharedSource.ps1 index 4a5b3f89..c42f904a 100644 --- a/eng/DownloadSharedSource.ps1 +++ b/eng/DownloadSharedSource.ps1 @@ -1,11 +1,13 @@ +#Requires -Version 6.0 +$ErrorActionPreference = 'Stop' +$ProgressPreference = 'SilentlyContinue' + $downloadPath = Resolve-Path (Join-Path $PSScriptRoot '..' 'src' 'assets' 'Azure.Core.Shared') -$files = "ClientDiagnostics.cs", "ArrayBufferWriter.cs", "DiagnosticScope.cs" -$baseUrl = "https://raw.githubusercontent.com/Azure/azure-sdk-for-net/master/sdk/core/Azure.Core/src/Shared/" +$files = 'ClientDiagnostics.cs', 'ArrayBufferWriter.cs', 'DiagnosticScope.cs' +$baseUrl = 'https://raw.githubusercontent.com/Azure/azure-sdk-for-net/master/sdk/core/Azure.Core/src/Shared/' foreach ($file in $files) { $text = Invoke-WebRequest -Uri "$baseUrl/$file"; - $text.Content.Replace("#nullable enable", "#pragma warning disable CS8600, CS8604, CS8605").Trim() | Out-File "$downloadPath/$file" -} - -exit 0 \ No newline at end of file + $text.Content.Replace('#nullable enable', '#pragma warning disable CS8600, CS8604, CS8605').Trim() | Out-File (Join-Path $downloadPath $file) +} \ No newline at end of file diff --git a/eng/Generate.ps1 b/eng/Generate.ps1 index d3e3ee1f..6277d716 100644 --- a/eng/Generate.ps1 +++ b/eng/Generate.ps1 @@ -1,31 +1,22 @@ -param($name, [switch]$noDebug, [switch]$NoReset) +#Requires -Version 6.0 +param($name, [switch]$noDebug, [switch]$reset) + $ErrorActionPreference = 'Stop' -function Invoke-Block([scriptblock]$cmd) { - $cmd | Out-String | Write-Verbose - & $cmd - - # Need to check both of these cases for errors as they represent different items - # - $?: did the powershell script block throw an error - # - $lastexitcode: did a windows command executed by the script block end in error - if ((-not $?) -or ($lastexitcode -ne 0)) { - if ($error -ne $null) - { - Write-Warning $error[0] - } - throw "Command failed to execute: $cmd" +function Invoke-AutoRest($autoRestArguments) +{ + $command = "npx autorest-beta $autoRestArguments" + Write-Host "> $command" + cmd /c "$command 2>&1" + if($LastExitCode -ne 0) + { + Write-Error "Command failed to execute: $command" } } -function Invoke-AutoRest($autoRestArguments, $repoRoot) { - Invoke-Block { - $command = "npx autorest-beta $autoRestArguments" - $commandText = $command.Replace($repoRoot, "`$(SolutionDir)") - - Write-Host ">" $commandText - - & cmd /c "$command 2>&1" - } +if ($reset -or $env:TF_BUILD) +{ + Invoke-AutoRest '--reset' } # General configuration @@ -36,11 +27,18 @@ $debugFlags = if (-not $noDebug) { '--debug', '--verbose' } $testServerDirectory = Join-Path $repoRoot 'test' 'TestServerProjects' $configurationPath = Join-Path $testServerDirectory 'readme.tests.md' $testServerSwaggerPath = Join-Path $repoRoot 'node_modules' '@microsoft.azure' 'autorest.testserver' 'swagger' -$testNames = if ($name) { $name } else { 'body-number', 'body-integer', 'extensible-enums-swagger', 'url-multi-collectionFormat', 'url', 'body-string', 'body-complex', 'custom-baseUrl', 'custom-baseUrl-more-options', 'header' } - -if (!$NoReset) +$testNames = if ($name) { $name } else { - Invoke-AutoRest "--reset" $repoRoot + 'body-integer', + 'body-number', + 'body-string', + 'extensible-enums-swagger', + 'url-multi-collectionFormat', + 'url', + 'body-complex', + 'custom-baseUrl', + 'custom-baseUrl-more-options', + 'header' } foreach ($testName in $testNames) @@ -48,7 +46,7 @@ foreach ($testName in $testNames) $inputFile = Join-Path $testServerSwaggerPath "$testName.json" $namespace = $testName.Replace('-', '_') $autoRestArguments = "$debugFlags --require=$configurationPath --input-file=$inputFile --title=$testName --namespace=$namespace" - Invoke-AutoRest $autoRestArguments $repoRoot + Invoke-AutoRest $autoRestArguments } # Sample configuration @@ -60,5 +58,5 @@ foreach ($projectName in $projectNames) $projectDirectory = Join-Path $sampleDirectory $projectName $configurationPath = Join-Path $projectDirectory 'readme.md' $autoRestArguments = "$debugFlags --require=$configurationPath" - Invoke-AutoRest $autoRestArguments $repoRoot + Invoke-AutoRest $autoRestArguments } \ No newline at end of file diff --git a/eng/pipelines/build.yml b/eng/pipelines/build.yml index 347b6d9c..24efb043 100644 --- a/eng/pipelines/build.yml +++ b/eng/pipelines/build.yml @@ -29,7 +29,7 @@ jobs: DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1 DOTNET_CLI_TELEMETRY_OPTOUT: 1 DOTNET_MULTILEVEL_LOOKUP: 0 - - pwsh: .\eng\CodeChecks.ps1 + - pwsh: ./eng/CodeChecks.ps1 displayName: "Check if code is up-to-date" - script: | dotnet test AutoRest.CSharp.V3.sln diff --git a/readme.md b/readme.md index 1029e156..0e7711b3 100644 --- a/readme.md +++ b/readme.md @@ -1,6 +1,17 @@ # AutoRest.CSharp.V3 > see https://aka.ms/autorest +## Setup +- [NodeJS](https://nodejs.org/en/) (10.x.x or 12.x.x) +- `npm install` (at root) +- `npm install -g @autorest/autorest` +- [.NET Core SDK](https://dotnet.microsoft.com/download/dotnet-core/3.0) (3.0.100) +- [PowerShell Core](https://github.com/PowerShell/PowerShell/releases/latest) + +## Build +- `dotnet build` (at root) +- `./eng/Generate.ps1` (at root in PowerShell Core) + ## Configuration ```yaml use-extension: