diff --git a/test/AutoRest.TestServer.Tests/multiple-inheritance.cs b/test/AutoRest.TestServer.Tests/multiple-inheritance.cs new file mode 100644 index 00000000..3a11ebc7 --- /dev/null +++ b/test/AutoRest.TestServer.Tests/multiple-inheritance.cs @@ -0,0 +1,106 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System.Threading.Tasks; +using AutoRest.TestServer.Tests.Infrastructure; +using multiple_inheritance; +using multiple_inheritance.Models; +using NUnit.Framework; + +namespace AutoRest.TestServer.Tests +{ + [IgnoreOnTestServer(TestServerVersion.V2, "Requests not matched")] + public class MultipleInheritanceTest : TestServerTestBase + { + public MultipleInheritanceTest(TestServerVersion version) : base(version, "multipleInheritance") { } + + [Test] + public Task MultipleInheritanceCatGet() => Test(async (host, pipeline) => + { + var result = await new ServiceClient(ClientDiagnostics, pipeline, host).RestClient.GetCatAsync(); + Assert.AreEqual("Whiskers", result.Value.Name); + Assert.IsTrue(result.Value.LikesMilk); + Assert.IsTrue(result.Value.Meows); + Assert.IsTrue(result.Value.Hisses); + }); + + [Test] + public Task MultipleInheritanceCatPut() => Test(async (host, pipeline) => + { + var value = new Cat("Boots", false, true, false); + var result = await new ServiceClient(ClientDiagnostics, pipeline, host).RestClient.PutCatAsync(value); + Assert.AreEqual(200, result.GetRawResponse().Status); + Assert.AreEqual("Cat was correct!", result.Value); + }); + + [Test] + public Task MultipleInheritanceFelineGet() => Test(async (host, pipeline) => + { + var result = await new ServiceClient(ClientDiagnostics, pipeline, host).RestClient.GetFelineAsync(); + Assert.IsTrue(result.Value.Meows); + Assert.IsTrue(result.Value.Hisses); + }); + + [Test] + public Task MultipleInheritanceFelinePut() => Test(async (host, pipeline) => + { + var value = new Feline(false, true); + var result = await new ServiceClient(ClientDiagnostics, pipeline, host).RestClient.PutFelineAsync(value); + Assert.AreEqual(200, result.GetRawResponse().Status); + Assert.AreEqual("Feline was correct!", result.Value); + }); + + [Test] + public Task MultipleInheritanceHorseGet() => Test(async (host, pipeline) => + { + var result = await new ServiceClient(ClientDiagnostics, pipeline, host).RestClient.GetHorseAsync(); + Assert.AreEqual("Fred", result.Value.Name); + Assert.IsTrue(result.Value.IsAShowHorse); + }); + + [Test] + public Task MultipleInheritanceHorsePut() => Test(async (host, pipeline) => + { + var value = new Horse("General", false); + var result = await new ServiceClient(ClientDiagnostics, pipeline, host).RestClient.PutHorseAsync(value); + Assert.AreEqual(200, result.GetRawResponse().Status); + Assert.AreEqual("Horse was correct!", result.Value); + }); + + [Test] + public Task MultipleInheritanceKittenGet() => Test(async (host, pipeline) => + { + var result = await new ServiceClient(ClientDiagnostics, pipeline, host).RestClient.GetKittenAsync(); + Assert.AreEqual("Gatito", result.Value.Name); + Assert.IsTrue(result.Value.LikesMilk); + Assert.IsTrue(result.Value.Meows); + Assert.IsTrue(result.Value.Hisses); + Assert.IsFalse(result.Value.EatsMiceYet); + }); + + [Test] + public Task MultipleInheritanceKittenPut() => Test(async (host, pipeline) => + { + var value = new Kitten("Kitty", false, true, false, true); + var result = await new ServiceClient(ClientDiagnostics, pipeline, host).RestClient.PutKittenAsync(value); + Assert.AreEqual(200, result.GetRawResponse().Status); + Assert.AreEqual("Kitten was correct!", result.Value); + }); + + [Test] + public Task MultipleInheritancePetGet() => Test(async (host, pipeline) => + { + var result = await new ServiceClient(ClientDiagnostics, pipeline, host).RestClient.GetPetAsync(); + Assert.AreEqual("Peanut", result.Value.Name); + }); + + [Test] + public Task MultipleInheritancePetPut() => Test(async (host, pipeline) => + { + var value = new Pet("Butter"); + var result = await new ServiceClient(ClientDiagnostics, pipeline, host).RestClient.PutPetAsync(value); + Assert.AreEqual(200, result.GetRawResponse().Status); + Assert.AreEqual("Pet was correct!", result.Value); + }); + } +} diff --git a/test/AutoRest.TestServer.Tests/object-type.cs b/test/AutoRest.TestServer.Tests/object-type.cs index 062b6ab5..8afca761 100644 --- a/test/AutoRest.TestServer.Tests/object-type.cs +++ b/test/AutoRest.TestServer.Tests/object-type.cs @@ -1,10 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using System; using System.Collections.Generic; -using System.Linq; -using System.Reflection; using System.Threading.Tasks; using AutoRest.TestServer.Tests.Infrastructure; using Azure; diff --git a/test/TestServerProjects/multiple-inheritance/CodeModel.yaml b/test/TestServerProjects/multiple-inheritance/CodeModel.yaml new file mode 100644 index 00000000..140e9fcd --- /dev/null +++ b/test/TestServerProjects/multiple-inheritance/CodeModel.yaml @@ -0,0 +1,911 @@ +! +info: ! + description: Service client for multiinheritance client testing + title: Multiple Inheritance Service Client +schemas: ! + booleans: + - ! &ref_2 + type: boolean + language: ! + default: + name: Boolean + description: '' + protocol: ! {} + numbers: + - ! &ref_8 + type: integer + precision: 32 + language: ! + default: + name: Integer + description: '' + protocol: ! {} + strings: + - ! &ref_0 + type: string + language: ! + default: + name: String + description: simple string + protocol: ! {} + - ! &ref_7 + type: string + apiVersions: + - ! + version: 3.0.0 + language: ! + default: + name: PetName + description: '' + protocol: ! {} + - ! &ref_9 + type: string + apiVersions: + - ! + version: 3.0.0 + language: ! + default: + name: ErrorMessage + description: '' + protocol: ! {} + - ! &ref_14 + type: string + apiVersions: + - ! + version: 3.0.0 + language: ! + default: + name: String + description: '' + protocol: ! {} + constants: + - ! &ref_12 + type: constant + value: ! + value: application/json + valueType: *ref_0 + language: ! + default: + name: ApplicationJson + description: Content Type 'application/json' + protocol: ! {} + objects: + - ! &ref_1 + type: object + apiVersions: + - ! + version: 3.0.0 + children: ! + all: + - ! &ref_6 + type: object + apiVersions: + - ! + version: 3.0.0 + parents: ! + all: + - *ref_1 + immediate: + - *ref_1 + properties: + - ! + schema: *ref_2 + serializedName: isAShowHorse + language: ! + default: + name: isAShowHorse + description: '' + protocol: ! {} + serializationFormats: + - json + usage: + - output + - input + language: ! + default: + name: Horse + description: '' + namespace: '' + protocol: ! {} + - ! &ref_3 + type: object + apiVersions: + - ! + version: 3.0.0 + children: ! + all: + - ! &ref_4 + type: object + apiVersions: + - ! + version: 3.0.0 + parents: ! + all: + - *ref_3 + - *ref_1 + - ! &ref_5 + type: object + apiVersions: + - ! + version: 3.0.0 + children: ! + all: + - *ref_3 + - *ref_4 + - *ref_4 + immediate: + - *ref_3 + properties: + - ! + schema: *ref_2 + serializedName: meows + language: ! + default: + name: meows + description: '' + protocol: ! {} + - ! + schema: *ref_2 + serializedName: hisses + language: ! + default: + name: hisses + description: '' + protocol: ! {} + serializationFormats: + - json + usage: + - output + - input + language: ! + default: + name: Feline + description: '' + namespace: '' + protocol: ! {} + - *ref_1 + - *ref_5 + immediate: + - *ref_3 + properties: + - ! + schema: *ref_2 + serializedName: eatsMiceYet + language: ! + default: + name: eatsMiceYet + description: '' + protocol: ! {} + serializationFormats: + - json + usage: + - output + - input + language: ! + default: + name: Kitten + description: '' + namespace: '' + protocol: ! {} + immediate: + - *ref_4 + parents: ! + all: + - *ref_1 + - *ref_5 + - *ref_1 + - *ref_5 + immediate: + - *ref_1 + - *ref_5 + properties: + - ! + schema: *ref_2 + serializedName: likesMilk + language: ! + default: + name: likesMilk + description: '' + protocol: ! {} + serializationFormats: + - json + usage: + - output + - input + language: ! + default: + name: Cat + description: '' + namespace: '' + protocol: ! {} + - *ref_4 + - *ref_4 + immediate: + - *ref_6 + - *ref_3 + properties: + - ! + schema: *ref_7 + required: true + serializedName: name + language: ! + default: + name: name + description: '' + protocol: ! {} + serializationFormats: + - json + usage: + - output + - input + language: ! + default: + name: Pet + description: '' + namespace: '' + protocol: ! {} + - *ref_6 + - ! &ref_11 + type: object + apiVersions: + - ! + version: 3.0.0 + properties: + - ! + schema: *ref_8 + serializedName: status + language: ! + default: + name: status + description: '' + protocol: ! {} + - ! + schema: *ref_9 + serializedName: message + language: ! + default: + name: message + description: '' + protocol: ! {} + serializationFormats: + - json + usage: + - output + language: ! + default: + name: Error + description: '' + namespace: '' + protocol: ! {} + - *ref_5 + - *ref_3 + - *ref_4 +globalParameters: +- ! &ref_10 + schema: *ref_0 + clientDefaultValue: 'http://localhost:3000' + implementation: Client + origin: 'modelerfour:synthesized/host' + required: true + extensions: + x-ms-skip-url-encoding: true + language: ! + default: + name: $host + description: server parameter + serializedName: $host + protocol: ! + http: ! + in: uri +operationGroups: +- ! + $key: '' + operations: + - ! + apiVersions: + - ! + version: 3.0.0 + parameters: + - *ref_10 + requests: + - ! + language: ! + default: + name: '' + description: '' + protocol: ! + http: ! + path: /multipleInheritance/horse + method: get + uri: '{$host}' + signatureParameters: [] + responses: + - ! + schema: *ref_6 + language: ! + default: + name: '' + description: '' + protocol: ! + http: ! + knownMediaType: json + mediaTypes: + - application/json + statusCodes: + - '200' + exceptions: + - ! + schema: *ref_11 + language: ! + default: + name: '' + description: '' + protocol: ! + http: ! + knownMediaType: json + mediaTypes: + - application/json + statusCodes: + - default + language: ! + default: + name: GetHorse + description: Get a horse with name 'Fred' and isAShowHorse true + protocol: ! {} + - ! + apiVersions: + - ! + version: 3.0.0 + parameters: + - *ref_10 + requests: + - ! + parameters: + - ! + schema: *ref_12 + implementation: Method + origin: 'modelerfour:synthesized/content-type' + required: true + language: ! + default: + name: contentType + description: Body Parameter content-type + serializedName: Content-Type + protocol: ! + http: ! + in: header + - ! &ref_13 + schema: *ref_6 + implementation: Method + required: true + language: ! + default: + name: horse + description: Put a horse with name 'General' and isAShowHorse false + protocol: ! + http: ! + in: body + style: json + signatureParameters: + - *ref_13 + language: ! + default: + name: '' + description: '' + protocol: ! + http: ! + path: /multipleInheritance/horse + method: put + knownMediaType: json + mediaTypes: + - application/json + uri: '{$host}' + signatureParameters: [] + responses: + - ! + schema: *ref_14 + language: ! + default: + name: '' + description: '' + protocol: ! + http: ! + knownMediaType: json + mediaTypes: + - application/json + statusCodes: + - '200' + language: ! + default: + name: PutHorse + description: Put a horse with name 'General' and isAShowHorse false + protocol: ! {} + - ! + apiVersions: + - ! + version: 3.0.0 + parameters: + - *ref_10 + requests: + - ! + language: ! + default: + name: '' + description: '' + protocol: ! + http: ! + path: /multipleInheritance/pet + method: get + uri: '{$host}' + signatureParameters: [] + responses: + - ! + schema: *ref_1 + language: ! + default: + name: '' + description: '' + protocol: ! + http: ! + knownMediaType: json + mediaTypes: + - application/json + statusCodes: + - '200' + exceptions: + - ! + schema: *ref_11 + language: ! + default: + name: '' + description: '' + protocol: ! + http: ! + knownMediaType: json + mediaTypes: + - application/json + statusCodes: + - default + language: ! + default: + name: GetPet + description: Get a pet with name 'Peanut' + protocol: ! {} + - ! + apiVersions: + - ! + version: 3.0.0 + parameters: + - *ref_10 + requests: + - ! + parameters: + - ! + schema: *ref_12 + implementation: Method + origin: 'modelerfour:synthesized/content-type' + required: true + language: ! + default: + name: contentType + description: Body Parameter content-type + serializedName: Content-Type + protocol: ! + http: ! + in: header + - ! &ref_15 + schema: *ref_1 + implementation: Method + required: true + language: ! + default: + name: pet + description: Put a pet with name 'Butter' + protocol: ! + http: ! + in: body + style: json + signatureParameters: + - *ref_15 + language: ! + default: + name: '' + description: '' + protocol: ! + http: ! + path: /multipleInheritance/pet + method: put + knownMediaType: json + mediaTypes: + - application/json + uri: '{$host}' + signatureParameters: [] + responses: + - ! + schema: *ref_14 + language: ! + default: + name: '' + description: '' + protocol: ! + http: ! + knownMediaType: json + mediaTypes: + - application/json + statusCodes: + - '200' + language: ! + default: + name: PutPet + description: Put a pet with name 'Butter' + protocol: ! {} + - ! + apiVersions: + - ! + version: 3.0.0 + parameters: + - *ref_10 + requests: + - ! + language: ! + default: + name: '' + description: '' + protocol: ! + http: ! + path: /multipleInheritance/feline + method: get + uri: '{$host}' + signatureParameters: [] + responses: + - ! + schema: *ref_5 + language: ! + default: + name: '' + description: '' + protocol: ! + http: ! + knownMediaType: json + mediaTypes: + - application/json + statusCodes: + - '200' + exceptions: + - ! + schema: *ref_11 + language: ! + default: + name: '' + description: '' + protocol: ! + http: ! + knownMediaType: json + mediaTypes: + - application/json + statusCodes: + - default + language: ! + default: + name: GetFeline + description: Get a feline where meows and hisses are true + protocol: ! {} + - ! + apiVersions: + - ! + version: 3.0.0 + parameters: + - *ref_10 + requests: + - ! + parameters: + - ! + schema: *ref_12 + implementation: Method + origin: 'modelerfour:synthesized/content-type' + required: true + language: ! + default: + name: contentType + description: Body Parameter content-type + serializedName: Content-Type + protocol: ! + http: ! + in: header + - ! &ref_16 + schema: *ref_5 + implementation: Method + required: true + language: ! + default: + name: feline + description: Put a feline who hisses and doesn't meow + protocol: ! + http: ! + in: body + style: json + signatureParameters: + - *ref_16 + language: ! + default: + name: '' + description: '' + protocol: ! + http: ! + path: /multipleInheritance/feline + method: put + knownMediaType: json + mediaTypes: + - application/json + uri: '{$host}' + signatureParameters: [] + responses: + - ! + schema: *ref_14 + language: ! + default: + name: '' + description: '' + protocol: ! + http: ! + knownMediaType: json + mediaTypes: + - application/json + statusCodes: + - '200' + language: ! + default: + name: PutFeline + description: Put a feline who hisses and doesn't meow + protocol: ! {} + - ! + apiVersions: + - ! + version: 3.0.0 + parameters: + - *ref_10 + requests: + - ! + language: ! + default: + name: '' + description: '' + protocol: ! + http: ! + path: /multipleInheritance/cat + method: get + uri: '{$host}' + signatureParameters: [] + responses: + - ! + schema: *ref_3 + language: ! + default: + name: '' + description: '' + protocol: ! + http: ! + knownMediaType: json + mediaTypes: + - application/json + statusCodes: + - '200' + exceptions: + - ! + schema: *ref_11 + language: ! + default: + name: '' + description: '' + protocol: ! + http: ! + knownMediaType: json + mediaTypes: + - application/json + statusCodes: + - default + language: ! + default: + name: GetCat + description: 'Get a cat with name ''Whiskers'' where likesMilk, meows, and hisses is true' + protocol: ! {} + - ! + apiVersions: + - ! + version: 3.0.0 + parameters: + - *ref_10 + requests: + - ! + parameters: + - ! + schema: *ref_12 + implementation: Method + origin: 'modelerfour:synthesized/content-type' + required: true + language: ! + default: + name: contentType + description: Body Parameter content-type + serializedName: Content-Type + protocol: ! + http: ! + in: header + - ! &ref_17 + schema: *ref_3 + implementation: Method + required: true + language: ! + default: + name: cat + description: 'Put a cat with name ''Boots'' where likesMilk and hisses is false, meows is true' + protocol: ! + http: ! + in: body + style: json + signatureParameters: + - *ref_17 + language: ! + default: + name: '' + description: '' + protocol: ! + http: ! + path: /multipleInheritance/cat + method: put + knownMediaType: json + mediaTypes: + - application/json + uri: '{$host}' + signatureParameters: [] + responses: + - ! + schema: *ref_14 + language: ! + default: + name: '' + description: '' + protocol: ! + http: ! + knownMediaType: json + mediaTypes: + - application/json + statusCodes: + - '200' + language: ! + default: + name: PutCat + description: 'Put a cat with name ''Boots'' where likesMilk and hisses is false, meows is true' + protocol: ! {} + - ! + apiVersions: + - ! + version: 3.0.0 + parameters: + - *ref_10 + requests: + - ! + language: ! + default: + name: '' + description: '' + protocol: ! + http: ! + path: /multipleInheritance/kitten + method: get + uri: '{$host}' + signatureParameters: [] + responses: + - ! + schema: *ref_4 + language: ! + default: + name: '' + description: '' + protocol: ! + http: ! + knownMediaType: json + mediaTypes: + - application/json + statusCodes: + - '200' + exceptions: + - ! + schema: *ref_11 + language: ! + default: + name: '' + description: '' + protocol: ! + http: ! + knownMediaType: json + mediaTypes: + - application/json + statusCodes: + - default + language: ! + default: + name: GetKitten + description: 'Get a kitten with name ''Gatito'' where likesMilk and meows is true, and hisses and eatsMiceYet is false' + protocol: ! {} + - ! + apiVersions: + - ! + version: 3.0.0 + parameters: + - *ref_10 + requests: + - ! + parameters: + - ! + schema: *ref_12 + implementation: Method + origin: 'modelerfour:synthesized/content-type' + required: true + language: ! + default: + name: contentType + description: Body Parameter content-type + serializedName: Content-Type + protocol: ! + http: ! + in: header + - ! &ref_18 + schema: *ref_4 + implementation: Method + required: true + language: ! + default: + name: kitten + description: 'Put a kitten with name ''Kitty'' where likesMilk and hisses is false, meows and eatsMiceYet is true' + protocol: ! + http: ! + in: body + style: json + signatureParameters: + - *ref_18 + language: ! + default: + name: '' + description: '' + protocol: ! + http: ! + path: /multipleInheritance/kitten + method: put + knownMediaType: json + mediaTypes: + - application/json + uri: '{$host}' + signatureParameters: [] + responses: + - ! + schema: *ref_14 + language: ! + default: + name: '' + description: '' + protocol: ! + http: ! + knownMediaType: json + mediaTypes: + - application/json + statusCodes: + - '200' + language: ! + default: + name: PutKitten + description: 'Put a kitten with name ''Kitty'' where likesMilk and hisses is false, meows and eatsMiceYet is true' + protocol: ! {} + language: ! + default: + name: '' + description: '' + protocol: ! {} +security: ! + authenticationRequired: false +language: ! + default: + name: MultipleInheritanceServiceClient + description: '' +protocol: ! + http: ! {} diff --git a/test/TestServerProjects/multiple-inheritance/Configuration.json b/test/TestServerProjects/multiple-inheritance/Configuration.json new file mode 100644 index 00000000..fb5eb4ae --- /dev/null +++ b/test/TestServerProjects/multiple-inheritance/Configuration.json @@ -0,0 +1 @@ +{"OutputFolder":".","Namespace":"multiple_inheritance","LibraryName":"multiple_inheritance","SharedSourceFolder":"..\\..\\..\\src\\assets","AzureArm":false} \ No newline at end of file diff --git a/test/TestServerProjects/multiple-inheritance/Generated/Models/Cat.Serialization.cs b/test/TestServerProjects/multiple-inheritance/Generated/Models/Cat.Serialization.cs new file mode 100644 index 00000000..f73bba67 --- /dev/null +++ b/test/TestServerProjects/multiple-inheritance/Generated/Models/Cat.Serialization.cs @@ -0,0 +1,82 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure.Core; + +namespace multiple_inheritance.Models +{ + public partial class Cat : IUtf8JsonSerializable + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + { + writer.WriteStartObject(); + if (LikesMilk != null) + { + writer.WritePropertyName("likesMilk"); + writer.WriteBooleanValue(LikesMilk.Value); + } + if (Meows != null) + { + writer.WritePropertyName("meows"); + writer.WriteBooleanValue(Meows.Value); + } + if (Hisses != null) + { + writer.WritePropertyName("hisses"); + writer.WriteBooleanValue(Hisses.Value); + } + writer.WritePropertyName("name"); + writer.WriteStringValue(Name); + writer.WriteEndObject(); + } + + internal static Cat DeserializeCat(JsonElement element) + { + bool? likesMilk = default; + bool? meows = default; + bool? hisses = default; + string name = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("likesMilk")) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + likesMilk = property.Value.GetBoolean(); + continue; + } + if (property.NameEquals("meows")) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + meows = property.Value.GetBoolean(); + continue; + } + if (property.NameEquals("hisses")) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + hisses = property.Value.GetBoolean(); + continue; + } + if (property.NameEquals("name")) + { + name = property.Value.GetString(); + continue; + } + } + return new Cat(name, likesMilk, meows, hisses); + } + } +} diff --git a/test/TestServerProjects/multiple-inheritance/Generated/Models/Cat.cs b/test/TestServerProjects/multiple-inheritance/Generated/Models/Cat.cs new file mode 100644 index 00000000..57051bd5 --- /dev/null +++ b/test/TestServerProjects/multiple-inheritance/Generated/Models/Cat.cs @@ -0,0 +1,46 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; + +namespace multiple_inheritance.Models +{ + /// The Cat. + public partial class Cat : Pet + { + /// Initializes a new instance of Cat. + /// . + public Cat(string name) : base(name) + { + if (name == null) + { + throw new ArgumentNullException(nameof(name)); + } + } + + /// Initializes a new instance of Cat. + /// . + /// . + /// . + /// . + internal Cat(string name, bool? likesMilk, bool? meows, bool? hisses) : base(name) + { + if (name == null) + { + throw new ArgumentNullException(nameof(name)); + } + + LikesMilk = likesMilk; + Meows = meows; + Hisses = hisses; + } + + public bool? LikesMilk { get; set; } + public bool? Meows { get; set; } + public bool? Hisses { get; set; } + } +} diff --git a/test/TestServerProjects/multiple-inheritance/Generated/Models/Error.Serialization.cs b/test/TestServerProjects/multiple-inheritance/Generated/Models/Error.Serialization.cs new file mode 100644 index 00000000..be10485c --- /dev/null +++ b/test/TestServerProjects/multiple-inheritance/Generated/Models/Error.Serialization.cs @@ -0,0 +1,43 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure.Core; + +namespace multiple_inheritance.Models +{ + public partial class Error + { + internal static Error DeserializeError(JsonElement element) + { + int? status = default; + string message = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("status")) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + status = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("message")) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + message = property.Value.GetString(); + continue; + } + } + return new Error(status, message); + } + } +} diff --git a/test/TestServerProjects/multiple-inheritance/Generated/Models/Error.cs b/test/TestServerProjects/multiple-inheritance/Generated/Models/Error.cs new file mode 100644 index 00000000..299f7e2c --- /dev/null +++ b/test/TestServerProjects/multiple-inheritance/Generated/Models/Error.cs @@ -0,0 +1,30 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +namespace multiple_inheritance.Models +{ + /// The Error. + public partial class Error + { + /// Initializes a new instance of Error. + internal Error() + { + } + + /// Initializes a new instance of Error. + /// . + /// . + internal Error(int? status, string message) + { + Status = status; + Message = message; + } + + public int? Status { get; } + public string Message { get; } + } +} diff --git a/test/TestServerProjects/multiple-inheritance/Generated/Models/Feline.Serialization.cs b/test/TestServerProjects/multiple-inheritance/Generated/Models/Feline.Serialization.cs new file mode 100644 index 00000000..ece03009 --- /dev/null +++ b/test/TestServerProjects/multiple-inheritance/Generated/Models/Feline.Serialization.cs @@ -0,0 +1,59 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure.Core; + +namespace multiple_inheritance.Models +{ + public partial class Feline : IUtf8JsonSerializable + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + { + writer.WriteStartObject(); + if (Meows != null) + { + writer.WritePropertyName("meows"); + writer.WriteBooleanValue(Meows.Value); + } + if (Hisses != null) + { + writer.WritePropertyName("hisses"); + writer.WriteBooleanValue(Hisses.Value); + } + writer.WriteEndObject(); + } + + internal static Feline DeserializeFeline(JsonElement element) + { + bool? meows = default; + bool? hisses = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("meows")) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + meows = property.Value.GetBoolean(); + continue; + } + if (property.NameEquals("hisses")) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + hisses = property.Value.GetBoolean(); + continue; + } + } + return new Feline(meows, hisses); + } + } +} diff --git a/test/TestServerProjects/multiple-inheritance/Generated/Models/Feline.cs b/test/TestServerProjects/multiple-inheritance/Generated/Models/Feline.cs new file mode 100644 index 00000000..75f6ad0e --- /dev/null +++ b/test/TestServerProjects/multiple-inheritance/Generated/Models/Feline.cs @@ -0,0 +1,30 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +namespace multiple_inheritance.Models +{ + /// The Feline. + public partial class Feline + { + /// Initializes a new instance of Feline. + public Feline() + { + } + + /// Initializes a new instance of Feline. + /// . + /// . + internal Feline(bool? meows, bool? hisses) + { + Meows = meows; + Hisses = hisses; + } + + public bool? Meows { get; set; } + public bool? Hisses { get; set; } + } +} diff --git a/test/TestServerProjects/multiple-inheritance/Generated/Models/Horse.Serialization.cs b/test/TestServerProjects/multiple-inheritance/Generated/Models/Horse.Serialization.cs new file mode 100644 index 00000000..87fe487d --- /dev/null +++ b/test/TestServerProjects/multiple-inheritance/Generated/Models/Horse.Serialization.cs @@ -0,0 +1,52 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure.Core; + +namespace multiple_inheritance.Models +{ + public partial class Horse : IUtf8JsonSerializable + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + { + writer.WriteStartObject(); + if (IsAShowHorse != null) + { + writer.WritePropertyName("isAShowHorse"); + writer.WriteBooleanValue(IsAShowHorse.Value); + } + writer.WritePropertyName("name"); + writer.WriteStringValue(Name); + writer.WriteEndObject(); + } + + internal static Horse DeserializeHorse(JsonElement element) + { + bool? isAShowHorse = default; + string name = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("isAShowHorse")) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + isAShowHorse = property.Value.GetBoolean(); + continue; + } + if (property.NameEquals("name")) + { + name = property.Value.GetString(); + continue; + } + } + return new Horse(name, isAShowHorse); + } + } +} diff --git a/test/TestServerProjects/multiple-inheritance/Generated/Models/Horse.cs b/test/TestServerProjects/multiple-inheritance/Generated/Models/Horse.cs new file mode 100644 index 00000000..73d54f09 --- /dev/null +++ b/test/TestServerProjects/multiple-inheritance/Generated/Models/Horse.cs @@ -0,0 +1,40 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; + +namespace multiple_inheritance.Models +{ + /// The Horse. + public partial class Horse : Pet + { + /// Initializes a new instance of Horse. + /// . + public Horse(string name) : base(name) + { + if (name == null) + { + throw new ArgumentNullException(nameof(name)); + } + } + + /// Initializes a new instance of Horse. + /// . + /// . + internal Horse(string name, bool? isAShowHorse) : base(name) + { + if (name == null) + { + throw new ArgumentNullException(nameof(name)); + } + + IsAShowHorse = isAShowHorse; + } + + public bool? IsAShowHorse { get; set; } + } +} diff --git a/test/TestServerProjects/multiple-inheritance/Generated/Models/Kitten.Serialization.cs b/test/TestServerProjects/multiple-inheritance/Generated/Models/Kitten.Serialization.cs new file mode 100644 index 00000000..6c35e684 --- /dev/null +++ b/test/TestServerProjects/multiple-inheritance/Generated/Models/Kitten.Serialization.cs @@ -0,0 +1,97 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure.Core; + +namespace multiple_inheritance.Models +{ + public partial class Kitten : IUtf8JsonSerializable + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + { + writer.WriteStartObject(); + if (EatsMiceYet != null) + { + writer.WritePropertyName("eatsMiceYet"); + writer.WriteBooleanValue(EatsMiceYet.Value); + } + if (LikesMilk != null) + { + writer.WritePropertyName("likesMilk"); + writer.WriteBooleanValue(LikesMilk.Value); + } + if (Meows != null) + { + writer.WritePropertyName("meows"); + writer.WriteBooleanValue(Meows.Value); + } + if (Hisses != null) + { + writer.WritePropertyName("hisses"); + writer.WriteBooleanValue(Hisses.Value); + } + writer.WritePropertyName("name"); + writer.WriteStringValue(Name); + writer.WriteEndObject(); + } + + internal static Kitten DeserializeKitten(JsonElement element) + { + bool? eatsMiceYet = default; + bool? likesMilk = default; + bool? meows = default; + bool? hisses = default; + string name = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("eatsMiceYet")) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + eatsMiceYet = property.Value.GetBoolean(); + continue; + } + if (property.NameEquals("likesMilk")) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + likesMilk = property.Value.GetBoolean(); + continue; + } + if (property.NameEquals("meows")) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + meows = property.Value.GetBoolean(); + continue; + } + if (property.NameEquals("hisses")) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + hisses = property.Value.GetBoolean(); + continue; + } + if (property.NameEquals("name")) + { + name = property.Value.GetString(); + continue; + } + } + return new Kitten(name, likesMilk, meows, hisses, eatsMiceYet); + } + } +} diff --git a/test/TestServerProjects/multiple-inheritance/Generated/Models/Kitten.cs b/test/TestServerProjects/multiple-inheritance/Generated/Models/Kitten.cs new file mode 100644 index 00000000..84e05daa --- /dev/null +++ b/test/TestServerProjects/multiple-inheritance/Generated/Models/Kitten.cs @@ -0,0 +1,43 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; + +namespace multiple_inheritance.Models +{ + /// The Kitten. + public partial class Kitten : Cat + { + /// Initializes a new instance of Kitten. + /// . + public Kitten(string name) : base(name) + { + if (name == null) + { + throw new ArgumentNullException(nameof(name)); + } + } + + /// Initializes a new instance of Kitten. + /// . + /// . + /// . + /// . + /// . + internal Kitten(string name, bool? likesMilk, bool? meows, bool? hisses, bool? eatsMiceYet) : base(name, likesMilk, meows, hisses) + { + if (name == null) + { + throw new ArgumentNullException(nameof(name)); + } + + EatsMiceYet = eatsMiceYet; + } + + public bool? EatsMiceYet { get; set; } + } +} diff --git a/test/TestServerProjects/multiple-inheritance/Generated/Models/Pet.Serialization.cs b/test/TestServerProjects/multiple-inheritance/Generated/Models/Pet.Serialization.cs new file mode 100644 index 00000000..0164edf4 --- /dev/null +++ b/test/TestServerProjects/multiple-inheritance/Generated/Models/Pet.Serialization.cs @@ -0,0 +1,37 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure.Core; + +namespace multiple_inheritance.Models +{ + public partial class Pet : IUtf8JsonSerializable + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + { + writer.WriteStartObject(); + writer.WritePropertyName("name"); + writer.WriteStringValue(Name); + writer.WriteEndObject(); + } + + internal static Pet DeserializePet(JsonElement element) + { + string name = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("name")) + { + name = property.Value.GetString(); + continue; + } + } + return new Pet(name); + } + } +} diff --git a/test/TestServerProjects/multiple-inheritance/Generated/Models/Pet.cs b/test/TestServerProjects/multiple-inheritance/Generated/Models/Pet.cs new file mode 100644 index 00000000..572a7cfd --- /dev/null +++ b/test/TestServerProjects/multiple-inheritance/Generated/Models/Pet.cs @@ -0,0 +1,29 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; + +namespace multiple_inheritance.Models +{ + /// The Pet. + public partial class Pet + { + /// Initializes a new instance of Pet. + /// . + public Pet(string name) + { + if (name == null) + { + throw new ArgumentNullException(nameof(name)); + } + + Name = name; + } + + public string Name { get; } + } +} diff --git a/test/TestServerProjects/multiple-inheritance/Generated/Operations/ServiceClient.cs b/test/TestServerProjects/multiple-inheritance/Generated/Operations/ServiceClient.cs new file mode 100644 index 00000000..c19a625c --- /dev/null +++ b/test/TestServerProjects/multiple-inheritance/Generated/Operations/ServiceClient.cs @@ -0,0 +1,183 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core.Pipeline; +using multiple_inheritance.Models; + +namespace multiple_inheritance +{ + public partial class ServiceClient + { + private readonly ClientDiagnostics _clientDiagnostics; + private readonly HttpPipeline _pipeline; + internal ServiceRestClient RestClient { get; } + /// Initializes a new instance of ServiceClient for mocking. + protected ServiceClient() + { + } + /// Initializes a new instance of ServiceClient. + internal ServiceClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000") + { + RestClient = new ServiceRestClient(clientDiagnostics, pipeline, host); + _clientDiagnostics = clientDiagnostics; + _pipeline = pipeline; + } + + /// Get a horse with name 'Fred' and isAShowHorse true. + /// The cancellation token to use. + public virtual async Task> GetHorseAsync(CancellationToken cancellationToken = default) + { + return await RestClient.GetHorseAsync(cancellationToken).ConfigureAwait(false); + } + + /// Get a horse with name 'Fred' and isAShowHorse true. + /// The cancellation token to use. + public virtual Response GetHorse(CancellationToken cancellationToken = default) + { + return RestClient.GetHorse(cancellationToken); + } + + /// Put a horse with name 'General' and isAShowHorse false. + /// Put a horse with name 'General' and isAShowHorse false. + /// The cancellation token to use. + public virtual async Task> PutHorseAsync(Horse horse, CancellationToken cancellationToken = default) + { + return await RestClient.PutHorseAsync(horse, cancellationToken).ConfigureAwait(false); + } + + /// Put a horse with name 'General' and isAShowHorse false. + /// Put a horse with name 'General' and isAShowHorse false. + /// The cancellation token to use. + public virtual Response PutHorse(Horse horse, CancellationToken cancellationToken = default) + { + return RestClient.PutHorse(horse, cancellationToken); + } + + /// Get a pet with name 'Peanut'. + /// The cancellation token to use. + public virtual async Task> GetPetAsync(CancellationToken cancellationToken = default) + { + return await RestClient.GetPetAsync(cancellationToken).ConfigureAwait(false); + } + + /// Get a pet with name 'Peanut'. + /// The cancellation token to use. + public virtual Response GetPet(CancellationToken cancellationToken = default) + { + return RestClient.GetPet(cancellationToken); + } + + /// Put a pet with name 'Butter'. + /// Put a pet with name 'Butter'. + /// The cancellation token to use. + public virtual async Task> PutPetAsync(Pet pet, CancellationToken cancellationToken = default) + { + return await RestClient.PutPetAsync(pet, cancellationToken).ConfigureAwait(false); + } + + /// Put a pet with name 'Butter'. + /// Put a pet with name 'Butter'. + /// The cancellation token to use. + public virtual Response PutPet(Pet pet, CancellationToken cancellationToken = default) + { + return RestClient.PutPet(pet, cancellationToken); + } + + /// Get a feline where meows and hisses are true. + /// The cancellation token to use. + public virtual async Task> GetFelineAsync(CancellationToken cancellationToken = default) + { + return await RestClient.GetFelineAsync(cancellationToken).ConfigureAwait(false); + } + + /// Get a feline where meows and hisses are true. + /// The cancellation token to use. + public virtual Response GetFeline(CancellationToken cancellationToken = default) + { + return RestClient.GetFeline(cancellationToken); + } + + /// Put a feline who hisses and doesn't meow. + /// Put a feline who hisses and doesn't meow. + /// The cancellation token to use. + public virtual async Task> PutFelineAsync(Feline feline, CancellationToken cancellationToken = default) + { + return await RestClient.PutFelineAsync(feline, cancellationToken).ConfigureAwait(false); + } + + /// Put a feline who hisses and doesn't meow. + /// Put a feline who hisses and doesn't meow. + /// The cancellation token to use. + public virtual Response PutFeline(Feline feline, CancellationToken cancellationToken = default) + { + return RestClient.PutFeline(feline, cancellationToken); + } + + /// Get a cat with name 'Whiskers' where likesMilk, meows, and hisses is true. + /// The cancellation token to use. + public virtual async Task> GetCatAsync(CancellationToken cancellationToken = default) + { + return await RestClient.GetCatAsync(cancellationToken).ConfigureAwait(false); + } + + /// Get a cat with name 'Whiskers' where likesMilk, meows, and hisses is true. + /// The cancellation token to use. + public virtual Response GetCat(CancellationToken cancellationToken = default) + { + return RestClient.GetCat(cancellationToken); + } + + /// Put a cat with name 'Boots' where likesMilk and hisses is false, meows is true. + /// Put a cat with name 'Boots' where likesMilk and hisses is false, meows is true. + /// The cancellation token to use. + public virtual async Task> PutCatAsync(Cat cat, CancellationToken cancellationToken = default) + { + return await RestClient.PutCatAsync(cat, cancellationToken).ConfigureAwait(false); + } + + /// Put a cat with name 'Boots' where likesMilk and hisses is false, meows is true. + /// Put a cat with name 'Boots' where likesMilk and hisses is false, meows is true. + /// The cancellation token to use. + public virtual Response PutCat(Cat cat, CancellationToken cancellationToken = default) + { + return RestClient.PutCat(cat, cancellationToken); + } + + /// Get a kitten with name 'Gatito' where likesMilk and meows is true, and hisses and eatsMiceYet is false. + /// The cancellation token to use. + public virtual async Task> GetKittenAsync(CancellationToken cancellationToken = default) + { + return await RestClient.GetKittenAsync(cancellationToken).ConfigureAwait(false); + } + + /// Get a kitten with name 'Gatito' where likesMilk and meows is true, and hisses and eatsMiceYet is false. + /// The cancellation token to use. + public virtual Response GetKitten(CancellationToken cancellationToken = default) + { + return RestClient.GetKitten(cancellationToken); + } + + /// Put a kitten with name 'Kitty' where likesMilk and hisses is false, meows and eatsMiceYet is true. + /// Put a kitten with name 'Kitty' where likesMilk and hisses is false, meows and eatsMiceYet is true. + /// The cancellation token to use. + public virtual async Task> PutKittenAsync(Kitten kitten, CancellationToken cancellationToken = default) + { + return await RestClient.PutKittenAsync(kitten, cancellationToken).ConfigureAwait(false); + } + + /// Put a kitten with name 'Kitty' where likesMilk and hisses is false, meows and eatsMiceYet is true. + /// Put a kitten with name 'Kitty' where likesMilk and hisses is false, meows and eatsMiceYet is true. + /// The cancellation token to use. + public virtual Response PutKitten(Kitten kitten, CancellationToken cancellationToken = default) + { + return RestClient.PutKitten(kitten, cancellationToken); + } + } +} diff --git a/test/TestServerProjects/multiple-inheritance/Generated/Operations/ServiceRestClient.cs b/test/TestServerProjects/multiple-inheritance/Generated/Operations/ServiceRestClient.cs new file mode 100644 index 00000000..aa12a712 --- /dev/null +++ b/test/TestServerProjects/multiple-inheritance/Generated/Operations/ServiceRestClient.cs @@ -0,0 +1,978 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Text.Json; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; +using multiple_inheritance.Models; + +namespace multiple_inheritance +{ + internal partial class ServiceRestClient + { + private string host; + private ClientDiagnostics _clientDiagnostics; + private HttpPipeline _pipeline; + + /// Initializes a new instance of ServiceRestClient. + public ServiceRestClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000") + { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + + this.host = host; + _clientDiagnostics = clientDiagnostics; + _pipeline = pipeline; + } + + internal HttpMessage CreateGetHorseRequest() + { + var message = _pipeline.CreateMessage(); + var request = message.Request; + request.Method = RequestMethod.Get; + var uri = new RawRequestUriBuilder(); + uri.AppendRaw(host, false); + uri.AppendPath("/multipleInheritance/horse", false); + request.Uri = uri; + return message; + } + + /// Get a horse with name 'Fred' and isAShowHorse true. + /// The cancellation token to use. + public async ValueTask> GetHorseAsync(CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ServiceClient.GetHorse"); + scope.Start(); + try + { + using var message = CreateGetHorseRequest(); + await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); + switch (message.Response.Status) + { + case 200: + { + Horse value = default; + using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); + if (document.RootElement.ValueKind == JsonValueKind.Null) + { + value = null; + } + else + { + value = Horse.DeserializeHorse(document.RootElement); + } + return Response.FromValue(value, message.Response); + } + default: + throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Get a horse with name 'Fred' and isAShowHorse true. + /// The cancellation token to use. + public Response GetHorse(CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ServiceClient.GetHorse"); + scope.Start(); + try + { + using var message = CreateGetHorseRequest(); + _pipeline.Send(message, cancellationToken); + switch (message.Response.Status) + { + case 200: + { + Horse value = default; + using var document = JsonDocument.Parse(message.Response.ContentStream); + if (document.RootElement.ValueKind == JsonValueKind.Null) + { + value = null; + } + else + { + value = Horse.DeserializeHorse(document.RootElement); + } + return Response.FromValue(value, message.Response); + } + default: + throw _clientDiagnostics.CreateRequestFailedException(message.Response); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + internal HttpMessage CreatePutHorseRequest(Horse horse) + { + var message = _pipeline.CreateMessage(); + var request = message.Request; + request.Method = RequestMethod.Put; + var uri = new RawRequestUriBuilder(); + uri.AppendRaw(host, false); + uri.AppendPath("/multipleInheritance/horse", false); + request.Uri = uri; + request.Headers.Add("Content-Type", "application/json"); + using var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(horse); + request.Content = content; + return message; + } + + /// Put a horse with name 'General' and isAShowHorse false. + /// Put a horse with name 'General' and isAShowHorse false. + /// The cancellation token to use. + public async ValueTask> PutHorseAsync(Horse horse, CancellationToken cancellationToken = default) + { + if (horse == null) + { + throw new ArgumentNullException(nameof(horse)); + } + + using var scope = _clientDiagnostics.CreateScope("ServiceClient.PutHorse"); + scope.Start(); + try + { + using var message = CreatePutHorseRequest(horse); + await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); + switch (message.Response.Status) + { + case 200: + { + string value = default; + using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); + if (document.RootElement.ValueKind == JsonValueKind.Null) + { + value = null; + } + else + { + value = document.RootElement.GetString(); + } + return Response.FromValue(value, message.Response); + } + default: + throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Put a horse with name 'General' and isAShowHorse false. + /// Put a horse with name 'General' and isAShowHorse false. + /// The cancellation token to use. + public Response PutHorse(Horse horse, CancellationToken cancellationToken = default) + { + if (horse == null) + { + throw new ArgumentNullException(nameof(horse)); + } + + using var scope = _clientDiagnostics.CreateScope("ServiceClient.PutHorse"); + scope.Start(); + try + { + using var message = CreatePutHorseRequest(horse); + _pipeline.Send(message, cancellationToken); + switch (message.Response.Status) + { + case 200: + { + string value = default; + using var document = JsonDocument.Parse(message.Response.ContentStream); + if (document.RootElement.ValueKind == JsonValueKind.Null) + { + value = null; + } + else + { + value = document.RootElement.GetString(); + } + return Response.FromValue(value, message.Response); + } + default: + throw _clientDiagnostics.CreateRequestFailedException(message.Response); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + internal HttpMessage CreateGetPetRequest() + { + var message = _pipeline.CreateMessage(); + var request = message.Request; + request.Method = RequestMethod.Get; + var uri = new RawRequestUriBuilder(); + uri.AppendRaw(host, false); + uri.AppendPath("/multipleInheritance/pet", false); + request.Uri = uri; + return message; + } + + /// Get a pet with name 'Peanut'. + /// The cancellation token to use. + public async ValueTask> GetPetAsync(CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ServiceClient.GetPet"); + scope.Start(); + try + { + using var message = CreateGetPetRequest(); + await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); + switch (message.Response.Status) + { + case 200: + { + Pet value = default; + using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); + if (document.RootElement.ValueKind == JsonValueKind.Null) + { + value = null; + } + else + { + value = Pet.DeserializePet(document.RootElement); + } + return Response.FromValue(value, message.Response); + } + default: + throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Get a pet with name 'Peanut'. + /// The cancellation token to use. + public Response GetPet(CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ServiceClient.GetPet"); + scope.Start(); + try + { + using var message = CreateGetPetRequest(); + _pipeline.Send(message, cancellationToken); + switch (message.Response.Status) + { + case 200: + { + Pet value = default; + using var document = JsonDocument.Parse(message.Response.ContentStream); + if (document.RootElement.ValueKind == JsonValueKind.Null) + { + value = null; + } + else + { + value = Pet.DeserializePet(document.RootElement); + } + return Response.FromValue(value, message.Response); + } + default: + throw _clientDiagnostics.CreateRequestFailedException(message.Response); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + internal HttpMessage CreatePutPetRequest(Pet pet) + { + var message = _pipeline.CreateMessage(); + var request = message.Request; + request.Method = RequestMethod.Put; + var uri = new RawRequestUriBuilder(); + uri.AppendRaw(host, false); + uri.AppendPath("/multipleInheritance/pet", false); + request.Uri = uri; + request.Headers.Add("Content-Type", "application/json"); + using var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(pet); + request.Content = content; + return message; + } + + /// Put a pet with name 'Butter'. + /// Put a pet with name 'Butter'. + /// The cancellation token to use. + public async ValueTask> PutPetAsync(Pet pet, CancellationToken cancellationToken = default) + { + if (pet == null) + { + throw new ArgumentNullException(nameof(pet)); + } + + using var scope = _clientDiagnostics.CreateScope("ServiceClient.PutPet"); + scope.Start(); + try + { + using var message = CreatePutPetRequest(pet); + await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); + switch (message.Response.Status) + { + case 200: + { + string value = default; + using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); + if (document.RootElement.ValueKind == JsonValueKind.Null) + { + value = null; + } + else + { + value = document.RootElement.GetString(); + } + return Response.FromValue(value, message.Response); + } + default: + throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Put a pet with name 'Butter'. + /// Put a pet with name 'Butter'. + /// The cancellation token to use. + public Response PutPet(Pet pet, CancellationToken cancellationToken = default) + { + if (pet == null) + { + throw new ArgumentNullException(nameof(pet)); + } + + using var scope = _clientDiagnostics.CreateScope("ServiceClient.PutPet"); + scope.Start(); + try + { + using var message = CreatePutPetRequest(pet); + _pipeline.Send(message, cancellationToken); + switch (message.Response.Status) + { + case 200: + { + string value = default; + using var document = JsonDocument.Parse(message.Response.ContentStream); + if (document.RootElement.ValueKind == JsonValueKind.Null) + { + value = null; + } + else + { + value = document.RootElement.GetString(); + } + return Response.FromValue(value, message.Response); + } + default: + throw _clientDiagnostics.CreateRequestFailedException(message.Response); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + internal HttpMessage CreateGetFelineRequest() + { + var message = _pipeline.CreateMessage(); + var request = message.Request; + request.Method = RequestMethod.Get; + var uri = new RawRequestUriBuilder(); + uri.AppendRaw(host, false); + uri.AppendPath("/multipleInheritance/feline", false); + request.Uri = uri; + return message; + } + + /// Get a feline where meows and hisses are true. + /// The cancellation token to use. + public async ValueTask> GetFelineAsync(CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ServiceClient.GetFeline"); + scope.Start(); + try + { + using var message = CreateGetFelineRequest(); + await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); + switch (message.Response.Status) + { + case 200: + { + Feline value = default; + using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); + if (document.RootElement.ValueKind == JsonValueKind.Null) + { + value = null; + } + else + { + value = Feline.DeserializeFeline(document.RootElement); + } + return Response.FromValue(value, message.Response); + } + default: + throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Get a feline where meows and hisses are true. + /// The cancellation token to use. + public Response GetFeline(CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ServiceClient.GetFeline"); + scope.Start(); + try + { + using var message = CreateGetFelineRequest(); + _pipeline.Send(message, cancellationToken); + switch (message.Response.Status) + { + case 200: + { + Feline value = default; + using var document = JsonDocument.Parse(message.Response.ContentStream); + if (document.RootElement.ValueKind == JsonValueKind.Null) + { + value = null; + } + else + { + value = Feline.DeserializeFeline(document.RootElement); + } + return Response.FromValue(value, message.Response); + } + default: + throw _clientDiagnostics.CreateRequestFailedException(message.Response); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + internal HttpMessage CreatePutFelineRequest(Feline feline) + { + var message = _pipeline.CreateMessage(); + var request = message.Request; + request.Method = RequestMethod.Put; + var uri = new RawRequestUriBuilder(); + uri.AppendRaw(host, false); + uri.AppendPath("/multipleInheritance/feline", false); + request.Uri = uri; + request.Headers.Add("Content-Type", "application/json"); + using var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(feline); + request.Content = content; + return message; + } + + /// Put a feline who hisses and doesn't meow. + /// Put a feline who hisses and doesn't meow. + /// The cancellation token to use. + public async ValueTask> PutFelineAsync(Feline feline, CancellationToken cancellationToken = default) + { + if (feline == null) + { + throw new ArgumentNullException(nameof(feline)); + } + + using var scope = _clientDiagnostics.CreateScope("ServiceClient.PutFeline"); + scope.Start(); + try + { + using var message = CreatePutFelineRequest(feline); + await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); + switch (message.Response.Status) + { + case 200: + { + string value = default; + using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); + if (document.RootElement.ValueKind == JsonValueKind.Null) + { + value = null; + } + else + { + value = document.RootElement.GetString(); + } + return Response.FromValue(value, message.Response); + } + default: + throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Put a feline who hisses and doesn't meow. + /// Put a feline who hisses and doesn't meow. + /// The cancellation token to use. + public Response PutFeline(Feline feline, CancellationToken cancellationToken = default) + { + if (feline == null) + { + throw new ArgumentNullException(nameof(feline)); + } + + using var scope = _clientDiagnostics.CreateScope("ServiceClient.PutFeline"); + scope.Start(); + try + { + using var message = CreatePutFelineRequest(feline); + _pipeline.Send(message, cancellationToken); + switch (message.Response.Status) + { + case 200: + { + string value = default; + using var document = JsonDocument.Parse(message.Response.ContentStream); + if (document.RootElement.ValueKind == JsonValueKind.Null) + { + value = null; + } + else + { + value = document.RootElement.GetString(); + } + return Response.FromValue(value, message.Response); + } + default: + throw _clientDiagnostics.CreateRequestFailedException(message.Response); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + internal HttpMessage CreateGetCatRequest() + { + var message = _pipeline.CreateMessage(); + var request = message.Request; + request.Method = RequestMethod.Get; + var uri = new RawRequestUriBuilder(); + uri.AppendRaw(host, false); + uri.AppendPath("/multipleInheritance/cat", false); + request.Uri = uri; + return message; + } + + /// Get a cat with name 'Whiskers' where likesMilk, meows, and hisses is true. + /// The cancellation token to use. + public async ValueTask> GetCatAsync(CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ServiceClient.GetCat"); + scope.Start(); + try + { + using var message = CreateGetCatRequest(); + await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); + switch (message.Response.Status) + { + case 200: + { + Cat value = default; + using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); + if (document.RootElement.ValueKind == JsonValueKind.Null) + { + value = null; + } + else + { + value = Cat.DeserializeCat(document.RootElement); + } + return Response.FromValue(value, message.Response); + } + default: + throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Get a cat with name 'Whiskers' where likesMilk, meows, and hisses is true. + /// The cancellation token to use. + public Response GetCat(CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ServiceClient.GetCat"); + scope.Start(); + try + { + using var message = CreateGetCatRequest(); + _pipeline.Send(message, cancellationToken); + switch (message.Response.Status) + { + case 200: + { + Cat value = default; + using var document = JsonDocument.Parse(message.Response.ContentStream); + if (document.RootElement.ValueKind == JsonValueKind.Null) + { + value = null; + } + else + { + value = Cat.DeserializeCat(document.RootElement); + } + return Response.FromValue(value, message.Response); + } + default: + throw _clientDiagnostics.CreateRequestFailedException(message.Response); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + internal HttpMessage CreatePutCatRequest(Cat cat) + { + var message = _pipeline.CreateMessage(); + var request = message.Request; + request.Method = RequestMethod.Put; + var uri = new RawRequestUriBuilder(); + uri.AppendRaw(host, false); + uri.AppendPath("/multipleInheritance/cat", false); + request.Uri = uri; + request.Headers.Add("Content-Type", "application/json"); + using var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(cat); + request.Content = content; + return message; + } + + /// Put a cat with name 'Boots' where likesMilk and hisses is false, meows is true. + /// Put a cat with name 'Boots' where likesMilk and hisses is false, meows is true. + /// The cancellation token to use. + public async ValueTask> PutCatAsync(Cat cat, CancellationToken cancellationToken = default) + { + if (cat == null) + { + throw new ArgumentNullException(nameof(cat)); + } + + using var scope = _clientDiagnostics.CreateScope("ServiceClient.PutCat"); + scope.Start(); + try + { + using var message = CreatePutCatRequest(cat); + await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); + switch (message.Response.Status) + { + case 200: + { + string value = default; + using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); + if (document.RootElement.ValueKind == JsonValueKind.Null) + { + value = null; + } + else + { + value = document.RootElement.GetString(); + } + return Response.FromValue(value, message.Response); + } + default: + throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Put a cat with name 'Boots' where likesMilk and hisses is false, meows is true. + /// Put a cat with name 'Boots' where likesMilk and hisses is false, meows is true. + /// The cancellation token to use. + public Response PutCat(Cat cat, CancellationToken cancellationToken = default) + { + if (cat == null) + { + throw new ArgumentNullException(nameof(cat)); + } + + using var scope = _clientDiagnostics.CreateScope("ServiceClient.PutCat"); + scope.Start(); + try + { + using var message = CreatePutCatRequest(cat); + _pipeline.Send(message, cancellationToken); + switch (message.Response.Status) + { + case 200: + { + string value = default; + using var document = JsonDocument.Parse(message.Response.ContentStream); + if (document.RootElement.ValueKind == JsonValueKind.Null) + { + value = null; + } + else + { + value = document.RootElement.GetString(); + } + return Response.FromValue(value, message.Response); + } + default: + throw _clientDiagnostics.CreateRequestFailedException(message.Response); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + internal HttpMessage CreateGetKittenRequest() + { + var message = _pipeline.CreateMessage(); + var request = message.Request; + request.Method = RequestMethod.Get; + var uri = new RawRequestUriBuilder(); + uri.AppendRaw(host, false); + uri.AppendPath("/multipleInheritance/kitten", false); + request.Uri = uri; + return message; + } + + /// Get a kitten with name 'Gatito' where likesMilk and meows is true, and hisses and eatsMiceYet is false. + /// The cancellation token to use. + public async ValueTask> GetKittenAsync(CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ServiceClient.GetKitten"); + scope.Start(); + try + { + using var message = CreateGetKittenRequest(); + await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); + switch (message.Response.Status) + { + case 200: + { + Kitten value = default; + using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); + if (document.RootElement.ValueKind == JsonValueKind.Null) + { + value = null; + } + else + { + value = Kitten.DeserializeKitten(document.RootElement); + } + return Response.FromValue(value, message.Response); + } + default: + throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Get a kitten with name 'Gatito' where likesMilk and meows is true, and hisses and eatsMiceYet is false. + /// The cancellation token to use. + public Response GetKitten(CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ServiceClient.GetKitten"); + scope.Start(); + try + { + using var message = CreateGetKittenRequest(); + _pipeline.Send(message, cancellationToken); + switch (message.Response.Status) + { + case 200: + { + Kitten value = default; + using var document = JsonDocument.Parse(message.Response.ContentStream); + if (document.RootElement.ValueKind == JsonValueKind.Null) + { + value = null; + } + else + { + value = Kitten.DeserializeKitten(document.RootElement); + } + return Response.FromValue(value, message.Response); + } + default: + throw _clientDiagnostics.CreateRequestFailedException(message.Response); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + internal HttpMessage CreatePutKittenRequest(Kitten kitten) + { + var message = _pipeline.CreateMessage(); + var request = message.Request; + request.Method = RequestMethod.Put; + var uri = new RawRequestUriBuilder(); + uri.AppendRaw(host, false); + uri.AppendPath("/multipleInheritance/kitten", false); + request.Uri = uri; + request.Headers.Add("Content-Type", "application/json"); + using var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(kitten); + request.Content = content; + return message; + } + + /// Put a kitten with name 'Kitty' where likesMilk and hisses is false, meows and eatsMiceYet is true. + /// Put a kitten with name 'Kitty' where likesMilk and hisses is false, meows and eatsMiceYet is true. + /// The cancellation token to use. + public async ValueTask> PutKittenAsync(Kitten kitten, CancellationToken cancellationToken = default) + { + if (kitten == null) + { + throw new ArgumentNullException(nameof(kitten)); + } + + using var scope = _clientDiagnostics.CreateScope("ServiceClient.PutKitten"); + scope.Start(); + try + { + using var message = CreatePutKittenRequest(kitten); + await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); + switch (message.Response.Status) + { + case 200: + { + string value = default; + using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); + if (document.RootElement.ValueKind == JsonValueKind.Null) + { + value = null; + } + else + { + value = document.RootElement.GetString(); + } + return Response.FromValue(value, message.Response); + } + default: + throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Put a kitten with name 'Kitty' where likesMilk and hisses is false, meows and eatsMiceYet is true. + /// Put a kitten with name 'Kitty' where likesMilk and hisses is false, meows and eatsMiceYet is true. + /// The cancellation token to use. + public Response PutKitten(Kitten kitten, CancellationToken cancellationToken = default) + { + if (kitten == null) + { + throw new ArgumentNullException(nameof(kitten)); + } + + using var scope = _clientDiagnostics.CreateScope("ServiceClient.PutKitten"); + scope.Start(); + try + { + using var message = CreatePutKittenRequest(kitten); + _pipeline.Send(message, cancellationToken); + switch (message.Response.Status) + { + case 200: + { + string value = default; + using var document = JsonDocument.Parse(message.Response.ContentStream); + if (document.RootElement.ValueKind == JsonValueKind.Null) + { + value = null; + } + else + { + value = document.RootElement.GetString(); + } + return Response.FromValue(value, message.Response); + } + default: + throw _clientDiagnostics.CreateRequestFailedException(message.Response); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + } +} diff --git a/test/TestServerProjects/multiple-inheritance/multiple_inheritance.csproj b/test/TestServerProjects/multiple-inheritance/multiple_inheritance.csproj new file mode 100644 index 00000000..e3fd25b1 --- /dev/null +++ b/test/TestServerProjects/multiple-inheritance/multiple_inheritance.csproj @@ -0,0 +1,15 @@ + + + + netstandard2.0 + true + annotations + + + + + + + + +