From 9838d3a3d5ec0fa72e4cadb2db9f8360aa8bcb45 Mon Sep 17 00:00:00 2001 From: Timothy Makkison Date: Mon, 1 Jul 2024 15:08:29 +0100 Subject: [PATCH 1/2] feat: first --- RefitGenerator.Tests/BaseGeneratorTests.cs | 13 ++++ RefitGenerator.Tests/Fixture.cs | 72 +++++++++++++++++++ RefitGenerator.Tests/ModuleInitializer.cs | 20 ++++++ .../RefitGenerator.Tests.csproj | 38 ++++++++++ 4 files changed, 143 insertions(+) create mode 100644 RefitGenerator.Tests/BaseGeneratorTests.cs create mode 100644 RefitGenerator.Tests/Fixture.cs create mode 100644 RefitGenerator.Tests/ModuleInitializer.cs create mode 100644 RefitGenerator.Tests/RefitGenerator.Tests.csproj diff --git a/RefitGenerator.Tests/BaseGeneratorTests.cs b/RefitGenerator.Tests/BaseGeneratorTests.cs new file mode 100644 index 000000000..93bc5e982 --- /dev/null +++ b/RefitGenerator.Tests/BaseGeneratorTests.cs @@ -0,0 +1,13 @@ +namespace RefitGenerator.Tests; + +[UsesVerify] +public class BaseGeneratorTests +{ + [Fact] + public Task Test1() + { + var verify = VerifyXunit.Verifier.Verify("ranDriver"); + + return verify.ToTask(); + } +} diff --git a/RefitGenerator.Tests/Fixture.cs b/RefitGenerator.Tests/Fixture.cs new file mode 100644 index 000000000..a085a7d5e --- /dev/null +++ b/RefitGenerator.Tests/Fixture.cs @@ -0,0 +1,72 @@ +using System.Reflection; + +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; + +using Refit; +using Refit.Generator; + +namespace RefitGenerator.Tests; + + +public static class Fixture +{ + public static readonly Type[] ImportantAssemblies = new[] + { + typeof(Binder), + typeof(GetAttribute), + typeof(System.Reactive.Unit), + typeof(System.Linq.Enumerable), + typeof(Newtonsoft.Json.JsonConvert), + typeof(Xunit.FactAttribute), + typeof(System.Net.Http.HttpContent), + // typeof(ModelObject), + typeof(Attribute) + }; + + public static Assembly[] AssemblyReferencesForCodegen => + AppDomain.CurrentDomain + .GetAssemblies() + .Concat(ImportantAssemblies.Select(x=>x.Assembly)) + .Distinct() + .Where(a => !a.IsDynamic) + .ToArray(); + + public static Compilation CreateLibrary(params string[] source) + { + var references = new List(); + var assemblies = AssemblyReferencesForCodegen; + foreach (Assembly assembly in assemblies) + { + if (!assembly.IsDynamic) + { + references.Add(MetadataReference.CreateFromFile(assembly.Location)); + } + } + + var compilation = CSharpCompilation.Create( + "compilation", + source.Select(s => CSharpSyntaxTree.ParseText(s)), + references, + new CSharpCompilationOptions(OutputKind.ConsoleApplication) + ); + + return compilation; + } + + public static Task VerifyGenerator(string source) + { + var compilation = CreateLibrary(source); + + var generator = new InterfaceStubGenerator(); + var driver = CSharpGeneratorDriver.Create(generator); + + var ranDriver = driver.RunGenerators(compilation); + var verify = VerifyXunit.Verifier.Verify(ranDriver); + + return verify.ToTask(); + } + + public static Task SourceFromResourceFile(string file) => + File.ReadAllTextAsync(Path.Combine("resources", file)); +} diff --git a/RefitGenerator.Tests/ModuleInitializer.cs b/RefitGenerator.Tests/ModuleInitializer.cs new file mode 100644 index 000000000..50643c469 --- /dev/null +++ b/RefitGenerator.Tests/ModuleInitializer.cs @@ -0,0 +1,20 @@ +using System.Runtime.CompilerServices; + +namespace RefitGenerator.Tests; + +public static class ModuleInitializer +{ + // ModuleInitializer should only be used in apps +#pragma warning disable CA2255 + [ModuleInitializer] +#pragma warning restore CA2255 + public static void Init() + { + Verifier.DerivePathInfo( + (file, _, type, method) => new(Path.Join(Path.GetDirectoryName(file), "_snapshots"), type.Name, method.Name) + ); + + VerifySourceGenerators.Initialize(); + VerifyDiffPlex.Initialize(VerifyTests.DiffPlex.OutputType.Compact); + } +} diff --git a/RefitGenerator.Tests/RefitGenerator.Tests.csproj b/RefitGenerator.Tests/RefitGenerator.Tests.csproj new file mode 100644 index 000000000..a3e458d64 --- /dev/null +++ b/RefitGenerator.Tests/RefitGenerator.Tests.csproj @@ -0,0 +1,38 @@ + + + + net462;net6.0;net8.0 + enable + enable + + false + true + + + + + + + + + + + + + + + + + + + + %(RecursiveDir)\resources\%(Filename)%(Extension) + Always + + + + + + + + From 4f82183c7057da17e7f3f9fd883bdccb2fc1cc7f Mon Sep 17 00:00:00 2001 From: Timothy Makkison Date: Mon, 1 Jul 2024 21:23:32 +0100 Subject: [PATCH 2/2] feat: add snapshot tests for generated code --- Refit.Tests/InterfaceStubGenerator.cs | 7 +- Refit.sln | 19 + RefitGenerator.Tests/BaseGeneratorTests.cs | 13 - RefitGenerator.Tests/BaseTestClass.cs | 16 + RefitGenerator.Tests/Fixture.cs | 56 ++- RefitGenerator.Tests/ModuleInitializer.cs | 20 - .../RefitGenerator.Tests.csproj | 10 +- RefitGenerator.Tests/RefitGeneratorTests.cs | 26 + ...nterfacesSmokeTest#Generated.g.verified.cs | 24 + ...terfacesSmokeTest#IGitHubApi.g.verified.cs | 462 ++++++++++++++++++ ...okeTest#IGitHubApiDisposable.g.verified.cs | 72 +++ ...esSmokeTest#INestedGitHubApi.g.verified.cs | 296 +++++++++++ ...sSmokeTest#PreserveAttribute.g.verified.cs | 19 + ...NamespaceSmokeTest#Generated.g.verified.cs | 24 + ...est#IServiceWithoutNamespace.g.verified.cs | 96 ++++ ...eSmokeTest#PreserveAttribute.g.verified.cs | 19 + 16 files changed, 1129 insertions(+), 50 deletions(-) delete mode 100644 RefitGenerator.Tests/BaseGeneratorTests.cs create mode 100644 RefitGenerator.Tests/BaseTestClass.cs delete mode 100644 RefitGenerator.Tests/ModuleInitializer.cs create mode 100644 RefitGenerator.Tests/RefitGeneratorTests.cs create mode 100644 RefitGenerator.Tests/_snapshots/RefitGeneratorTests.FindInterfacesSmokeTest#Generated.g.verified.cs create mode 100644 RefitGenerator.Tests/_snapshots/RefitGeneratorTests.FindInterfacesSmokeTest#IGitHubApi.g.verified.cs create mode 100644 RefitGenerator.Tests/_snapshots/RefitGeneratorTests.FindInterfacesSmokeTest#IGitHubApiDisposable.g.verified.cs create mode 100644 RefitGenerator.Tests/_snapshots/RefitGeneratorTests.FindInterfacesSmokeTest#INestedGitHubApi.g.verified.cs create mode 100644 RefitGenerator.Tests/_snapshots/RefitGeneratorTests.FindInterfacesSmokeTest#PreserveAttribute.g.verified.cs create mode 100644 RefitGenerator.Tests/_snapshots/RefitGeneratorTests.GenerateInterfaceStubsWithoutNamespaceSmokeTest#Generated.g.verified.cs create mode 100644 RefitGenerator.Tests/_snapshots/RefitGeneratorTests.GenerateInterfaceStubsWithoutNamespaceSmokeTest#IServiceWithoutNamespace.g.verified.cs create mode 100644 RefitGenerator.Tests/_snapshots/RefitGeneratorTests.GenerateInterfaceStubsWithoutNamespaceSmokeTest#PreserveAttribute.g.verified.cs diff --git a/Refit.Tests/InterfaceStubGenerator.cs b/Refit.Tests/InterfaceStubGenerator.cs index 6157543fb..31e9b48c1 100644 --- a/Refit.Tests/InterfaceStubGenerator.cs +++ b/Refit.Tests/InterfaceStubGenerator.cs @@ -1,10 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Collections.Immutable; -using System.IO; -using System.Linq; +using System.Collections.Immutable; using System.Reflection; -using System.Threading.Tasks; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.Testing; diff --git a/Refit.sln b/Refit.sln index 6edc2aa7b..de8514ae1 100644 --- a/Refit.sln +++ b/Refit.sln @@ -34,6 +34,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Refit.Xml", "Refit.Xml\Refi EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Refit.Benchmarks", "Refit.Benchmarks\Refit.Benchmarks.csproj", "{ABD72A27-9C30-481A-8303-D8F825A8FD47}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RefitGenerator.Tests", "RefitGenerator.Tests\RefitGenerator.Tests.csproj", "{10790A5E-8FB6-451B-BCBC-8F641973F22C}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -174,6 +176,22 @@ Global {ABD72A27-9C30-481A-8303-D8F825A8FD47}.Release|x64.Build.0 = Release|Any CPU {ABD72A27-9C30-481A-8303-D8F825A8FD47}.Release|x86.ActiveCfg = Release|Any CPU {ABD72A27-9C30-481A-8303-D8F825A8FD47}.Release|x86.Build.0 = Release|Any CPU + {10790A5E-8FB6-451B-BCBC-8F641973F22C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {10790A5E-8FB6-451B-BCBC-8F641973F22C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {10790A5E-8FB6-451B-BCBC-8F641973F22C}.Debug|ARM.ActiveCfg = Debug|Any CPU + {10790A5E-8FB6-451B-BCBC-8F641973F22C}.Debug|ARM.Build.0 = Debug|Any CPU + {10790A5E-8FB6-451B-BCBC-8F641973F22C}.Debug|x64.ActiveCfg = Debug|Any CPU + {10790A5E-8FB6-451B-BCBC-8F641973F22C}.Debug|x64.Build.0 = Debug|Any CPU + {10790A5E-8FB6-451B-BCBC-8F641973F22C}.Debug|x86.ActiveCfg = Debug|Any CPU + {10790A5E-8FB6-451B-BCBC-8F641973F22C}.Debug|x86.Build.0 = Debug|Any CPU + {10790A5E-8FB6-451B-BCBC-8F641973F22C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {10790A5E-8FB6-451B-BCBC-8F641973F22C}.Release|Any CPU.Build.0 = Release|Any CPU + {10790A5E-8FB6-451B-BCBC-8F641973F22C}.Release|ARM.ActiveCfg = Release|Any CPU + {10790A5E-8FB6-451B-BCBC-8F641973F22C}.Release|ARM.Build.0 = Release|Any CPU + {10790A5E-8FB6-451B-BCBC-8F641973F22C}.Release|x64.ActiveCfg = Release|Any CPU + {10790A5E-8FB6-451B-BCBC-8F641973F22C}.Release|x64.Build.0 = Release|Any CPU + {10790A5E-8FB6-451B-BCBC-8F641973F22C}.Release|x86.ActiveCfg = Release|Any CPU + {10790A5E-8FB6-451B-BCBC-8F641973F22C}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -181,6 +199,7 @@ Global GlobalSection(NestedProjects) = preSolution {EB833B36-D3CA-4308-A776-8D574F2ADF64} = {0E99249A-FB80-4C60-8FD3-13820E853FF7} {ABD72A27-9C30-481A-8303-D8F825A8FD47} = {0E99249A-FB80-4C60-8FD3-13820E853FF7} + {10790A5E-8FB6-451B-BCBC-8F641973F22C} = {0E99249A-FB80-4C60-8FD3-13820E853FF7} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {6E9C2873-AFF9-4D32-A784-1BA094814054} diff --git a/RefitGenerator.Tests/BaseGeneratorTests.cs b/RefitGenerator.Tests/BaseGeneratorTests.cs deleted file mode 100644 index 93bc5e982..000000000 --- a/RefitGenerator.Tests/BaseGeneratorTests.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace RefitGenerator.Tests; - -[UsesVerify] -public class BaseGeneratorTests -{ - [Fact] - public Task Test1() - { - var verify = VerifyXunit.Verifier.Verify("ranDriver"); - - return verify.ToTask(); - } -} diff --git a/RefitGenerator.Tests/BaseTestClass.cs b/RefitGenerator.Tests/BaseTestClass.cs new file mode 100644 index 000000000..e738eb43f --- /dev/null +++ b/RefitGenerator.Tests/BaseTestClass.cs @@ -0,0 +1,16 @@ +using System.Runtime.CompilerServices; + +namespace RefitGenerator.Tests; + +public class BaseTestClass +{ + static BaseTestClass() + { + Verifier.DerivePathInfo( + (file, _, type, method) => new(Path.Combine(Path.GetDirectoryName(file), "_snapshots"), type.Name, method.Name) + ); + + VerifySourceGenerators.Initialize(); + VerifyDiffPlex.Initialize(VerifyTests.DiffPlex.OutputType.Compact); + } +} diff --git a/RefitGenerator.Tests/Fixture.cs b/RefitGenerator.Tests/Fixture.cs index a085a7d5e..07f6026b8 100644 --- a/RefitGenerator.Tests/Fixture.cs +++ b/RefitGenerator.Tests/Fixture.cs @@ -1,5 +1,6 @@ -using System.Reflection; - +using System.Net.Http; +using System.Reflection; +using System.Runtime.CompilerServices; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; @@ -11,15 +12,24 @@ namespace RefitGenerator.Tests; public static class Fixture { - public static readonly Type[] ImportantAssemblies = new[] + private const string MainTestFile = "Refit.Tests"; + + static readonly MetadataReference RefitAssembly = MetadataReference.CreateFromFile( + typeof(GetAttribute).Assembly.Location, + documentation: XmlDocumentationProvider.CreateFromFile( + Path.ChangeExtension(typeof(GetAttribute).Assembly.Location, ".xml") + ) + ); + + private static readonly Type[] ImportantAssemblies = new[] { typeof(Binder), typeof(GetAttribute), typeof(System.Reactive.Unit), - typeof(System.Linq.Enumerable), + typeof(Enumerable), typeof(Newtonsoft.Json.JsonConvert), - typeof(Xunit.FactAttribute), - typeof(System.Net.Http.HttpContent), + typeof(FactAttribute), + typeof(HttpContent), // typeof(ModelObject), typeof(Attribute) }; @@ -36,7 +46,7 @@ public static Compilation CreateLibrary(params string[] source) { var references = new List(); var assemblies = AssemblyReferencesForCodegen; - foreach (Assembly assembly in assemblies) + foreach (var assembly in assemblies) { if (!assembly.IsDynamic) { @@ -44,6 +54,7 @@ public static Compilation CreateLibrary(params string[] source) } } + references.Add(RefitAssembly); var compilation = CSharpCompilation.Create( "compilation", source.Select(s => CSharpSyntaxTree.ParseText(s)), @@ -63,10 +74,35 @@ public static Task VerifyGenerator(string source) var ranDriver = driver.RunGenerators(compilation); var verify = VerifyXunit.Verifier.Verify(ranDriver); - return verify.ToTask(); } - public static Task SourceFromResourceFile(string file) => - File.ReadAllTextAsync(Path.Combine("resources", file)); + public static async Task GetFileFromRefitTest(string file) + { +#if NET481 + return File.ReadAllText(GetRefitTestPath(file)); +#else + return await File.ReadAllTextAsync(GetRefitTestPath(file)).ConfigureAwait(false); +#endif + } + + private static string GetRefitTestPath(params string[] paths) + { + var ret = GetIntegrationTestRootDirectory(); + var start = ret.Split('\\'); + // ReSharper disable once UseIndexFromEndExpression + start[start.Length - 1] = MainTestFile; + ret = string.Join("\\", start); + return (new FileInfo(paths.Aggregate(ret, Path.Combine))).FullName; + } + + private static string GetIntegrationTestRootDirectory([CallerFilePath] string filePath = default) + { + // XXX: This is an evil hack, but it's okay for a unit test + // We can't use Assembly.Location because unit test runners love + // to move stuff to temp directories + var di = new DirectoryInfo(Path.Combine(Path.GetDirectoryName(filePath))); + + return di.FullName; + } } diff --git a/RefitGenerator.Tests/ModuleInitializer.cs b/RefitGenerator.Tests/ModuleInitializer.cs deleted file mode 100644 index 50643c469..000000000 --- a/RefitGenerator.Tests/ModuleInitializer.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System.Runtime.CompilerServices; - -namespace RefitGenerator.Tests; - -public static class ModuleInitializer -{ - // ModuleInitializer should only be used in apps -#pragma warning disable CA2255 - [ModuleInitializer] -#pragma warning restore CA2255 - public static void Init() - { - Verifier.DerivePathInfo( - (file, _, type, method) => new(Path.Join(Path.GetDirectoryName(file), "_snapshots"), type.Name, method.Name) - ); - - VerifySourceGenerators.Initialize(); - VerifyDiffPlex.Initialize(VerifyTests.DiffPlex.OutputType.Compact); - } -} diff --git a/RefitGenerator.Tests/RefitGenerator.Tests.csproj b/RefitGenerator.Tests/RefitGenerator.Tests.csproj index a3e458d64..44204f10f 100644 --- a/RefitGenerator.Tests/RefitGenerator.Tests.csproj +++ b/RefitGenerator.Tests/RefitGenerator.Tests.csproj @@ -1,12 +1,15 @@ + + - net462;net6.0;net8.0 + net481;net6.0;net8.0 enable enable false true + $(NoWarn);CS1591;CA1819;CA2000;CA2007;CA1056;CA1707;CA1861;xUnit1031 @@ -19,6 +22,11 @@ + + + + + diff --git a/RefitGenerator.Tests/RefitGeneratorTests.cs b/RefitGenerator.Tests/RefitGeneratorTests.cs new file mode 100644 index 000000000..318ae8b0a --- /dev/null +++ b/RefitGenerator.Tests/RefitGeneratorTests.cs @@ -0,0 +1,26 @@ +namespace RefitGenerator.Tests; + +[UsesVerify] +public class RefitGeneratorTests : BaseTestClass +{ + [Fact] + public async Task NoRefitInterfacesSmokeTest() + { + var input = await Fixture.GetFileFromRefitTest("IInterfaceWithoutRefit.cs"); + await Fixture.VerifyGenerator(input); + } + + [Fact] + public async Task FindInterfacesSmokeTest() + { + var input = await Fixture.GetFileFromRefitTest("GitHubApi.cs"); + await Fixture.VerifyGenerator(input); + } + + [Fact] + public async Task GenerateInterfaceStubsWithoutNamespaceSmokeTest() + { + var input = await Fixture.GetFileFromRefitTest("IServiceWithoutNamespace.cs"); + await Fixture.VerifyGenerator(input); + } +} diff --git a/RefitGenerator.Tests/_snapshots/RefitGeneratorTests.FindInterfacesSmokeTest#Generated.g.verified.cs b/RefitGenerator.Tests/_snapshots/RefitGeneratorTests.FindInterfacesSmokeTest#Generated.g.verified.cs new file mode 100644 index 000000000..4470d5d71 --- /dev/null +++ b/RefitGenerator.Tests/_snapshots/RefitGeneratorTests.FindInterfacesSmokeTest#Generated.g.verified.cs @@ -0,0 +1,24 @@ +//HintName: Generated.g.cs + +#pragma warning disable +namespace Refit.Implementation +{ + + /// + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.Diagnostics.DebuggerNonUserCode] + [global::RefitInternalGenerated.PreserveAttribute] + [global::System.Reflection.Obfuscation(Exclude=true)] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + internal static partial class Generated + { +#if NET5_0_OR_GREATER + [System.Runtime.CompilerServices.ModuleInitializer] + [System.Diagnostics.CodeAnalysis.DynamicDependency(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All, typeof(global::Refit.Implementation.Generated))] + public static void Initialize() + { + } +#endif + } +} +#pragma warning restore diff --git a/RefitGenerator.Tests/_snapshots/RefitGeneratorTests.FindInterfacesSmokeTest#IGitHubApi.g.verified.cs b/RefitGenerator.Tests/_snapshots/RefitGeneratorTests.FindInterfacesSmokeTest#IGitHubApi.g.verified.cs new file mode 100644 index 000000000..4078da1ac --- /dev/null +++ b/RefitGenerator.Tests/_snapshots/RefitGeneratorTests.FindInterfacesSmokeTest#IGitHubApi.g.verified.cs @@ -0,0 +1,462 @@ +//HintName: IGitHubApi.g.cs +#nullable disable +#pragma warning disable +namespace Refit.Implementation +{ + + partial class Generated + { + + /// + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.Diagnostics.DebuggerNonUserCode] + [global::RefitInternalGenerated.PreserveAttribute] + [global::System.Reflection.Obfuscation(Exclude=true)] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + partial class RefitTestsIGitHubApi + : global::Refit.Tests.IGitHubApi + + { + /// + public global::System.Net.Http.HttpClient Client { get; } + readonly global::Refit.IRequestBuilder requestBuilder; + + /// + public RefitTestsIGitHubApi(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder) + { + Client = client; + this.requestBuilder = requestBuilder; + } + + + + private static readonly global::System.Type[] ______typeParameters = new global::System.Type[] {typeof(string) }; + + /// + public async global::System.Threading.Tasks.Task GetUser(string @userName) + { + var ______arguments = new object[] { @userName }; + var ______func = requestBuilder.BuildRestResultFuncForMethod("GetUser", ______typeParameters ); + try + { + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + private static readonly global::System.Type[] ______typeParameters0 = new global::System.Type[] {typeof(string) }; + + /// + public global::System.IObservable GetUserObservable(string @userName) + { + var ______arguments = new object[] { @userName }; + var ______func = requestBuilder.BuildRestResultFuncForMethod("GetUserObservable", ______typeParameters0 ); + try + { + return (global::System.IObservable)______func(this.Client, ______arguments); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + private static readonly global::System.Type[] ______typeParameters1 = new global::System.Type[] {typeof(string) }; + + /// + public global::System.IObservable GetUserCamelCase(string @userName) + { + var ______arguments = new object[] { @userName }; + var ______func = requestBuilder.BuildRestResultFuncForMethod("GetUserCamelCase", ______typeParameters1 ); + try + { + return (global::System.IObservable)______func(this.Client, ______arguments); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + private static readonly global::System.Type[] ______typeParameters2 = new global::System.Type[] {typeof(string), typeof(global::System.Threading.CancellationToken) }; + + /// + public async global::System.Threading.Tasks.Task> GetOrgMembers(string @orgName, global::System.Threading.CancellationToken @cancellationToken) + { + var ______arguments = new object[] { @orgName, @cancellationToken }; + var ______func = requestBuilder.BuildRestResultFuncForMethod("GetOrgMembers", ______typeParameters2 ); + try + { + return await ((global::System.Threading.Tasks.Task>)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + private static readonly global::System.Type[] ______typeParameters3 = new global::System.Type[] {typeof(string) }; + + /// + public async global::System.Threading.Tasks.Task FindUsers(string @q) + { + var ______arguments = new object[] { @q }; + var ______func = requestBuilder.BuildRestResultFuncForMethod("FindUsers", ______typeParameters3 ); + try + { + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + /// + public async global::System.Threading.Tasks.Task GetIndex() + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("GetIndex", global::System.Array.Empty() ); + try + { + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + /// + public global::System.IObservable GetIndexObservable() + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("GetIndexObservable", global::System.Array.Empty() ); + try + { + return (global::System.IObservable)______func(this.Client, ______arguments); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + /// + public async global::System.Threading.Tasks.Task NothingToSeeHere() + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("NothingToSeeHere", global::System.Array.Empty() ); + try + { + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + /// + public async global::System.Threading.Tasks.Task> NothingToSeeHereWithMetadata() + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("NothingToSeeHereWithMetadata", global::System.Array.Empty() ); + try + { + return await ((global::System.Threading.Tasks.Task>)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + private static readonly global::System.Type[] ______typeParameters4 = new global::System.Type[] {typeof(string) }; + + /// + public async global::System.Threading.Tasks.Task> GetUserWithMetadata(string @userName) + { + var ______arguments = new object[] { @userName }; + var ______func = requestBuilder.BuildRestResultFuncForMethod("GetUserWithMetadata", ______typeParameters4 ); + try + { + return await ((global::System.Threading.Tasks.Task>)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + private static readonly global::System.Type[] ______typeParameters5 = new global::System.Type[] {typeof(string) }; + + /// + public global::System.IObservable> GetUserObservableWithMetadata(string @userName) + { + var ______arguments = new object[] { @userName }; + var ______func = requestBuilder.BuildRestResultFuncForMethod("GetUserObservableWithMetadata", ______typeParameters5 ); + try + { + return (global::System.IObservable>)______func(this.Client, ______arguments); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + private static readonly global::System.Type[] ______typeParameters6 = new global::System.Type[] {typeof(global::Refit.Tests.User) }; + + /// + public async global::System.Threading.Tasks.Task CreateUser(global::Refit.Tests.User @user) + { + var ______arguments = new object[] { @user }; + var ______func = requestBuilder.BuildRestResultFuncForMethod("CreateUser", ______typeParameters6 ); + try + { + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + private static readonly global::System.Type[] ______typeParameters7 = new global::System.Type[] {typeof(global::Refit.Tests.User) }; + + /// + public async global::System.Threading.Tasks.Task> CreateUserWithMetadata(global::Refit.Tests.User @user) + { + var ______arguments = new object[] { @user }; + var ______func = requestBuilder.BuildRestResultFuncForMethod("CreateUserWithMetadata", ______typeParameters7 ); + try + { + return await ((global::System.Threading.Tasks.Task>)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + private static readonly global::System.Type[] ______typeParameters8 = new global::System.Type[] {typeof(string) }; + + /// + async global::System.Threading.Tasks.Task global::Refit.Tests.IGitHubApi.GetUser(string @userName) + { + var ______arguments = new object[] { @userName }; + var ______func = requestBuilder.BuildRestResultFuncForMethod("GetUser", ______typeParameters8 ); + try + { + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + private static readonly global::System.Type[] ______typeParameters9 = new global::System.Type[] {typeof(string) }; + + /// + global::System.IObservable global::Refit.Tests.IGitHubApi.GetUserObservable(string @userName) + { + var ______arguments = new object[] { @userName }; + var ______func = requestBuilder.BuildRestResultFuncForMethod("GetUserObservable", ______typeParameters9 ); + try + { + return (global::System.IObservable)______func(this.Client, ______arguments); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + private static readonly global::System.Type[] ______typeParameters10 = new global::System.Type[] {typeof(string) }; + + /// + global::System.IObservable global::Refit.Tests.IGitHubApi.GetUserCamelCase(string @userName) + { + var ______arguments = new object[] { @userName }; + var ______func = requestBuilder.BuildRestResultFuncForMethod("GetUserCamelCase", ______typeParameters10 ); + try + { + return (global::System.IObservable)______func(this.Client, ______arguments); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + private static readonly global::System.Type[] ______typeParameters11 = new global::System.Type[] {typeof(string), typeof(global::System.Threading.CancellationToken) }; + + /// + async global::System.Threading.Tasks.Task> global::Refit.Tests.IGitHubApi.GetOrgMembers(string @orgName, global::System.Threading.CancellationToken @cancellationToken) + { + var ______arguments = new object[] { @orgName, @cancellationToken }; + var ______func = requestBuilder.BuildRestResultFuncForMethod("GetOrgMembers", ______typeParameters11 ); + try + { + return await ((global::System.Threading.Tasks.Task>)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + private static readonly global::System.Type[] ______typeParameters12 = new global::System.Type[] {typeof(string) }; + + /// + async global::System.Threading.Tasks.Task global::Refit.Tests.IGitHubApi.FindUsers(string @q) + { + var ______arguments = new object[] { @q }; + var ______func = requestBuilder.BuildRestResultFuncForMethod("FindUsers", ______typeParameters12 ); + try + { + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + /// + async global::System.Threading.Tasks.Task global::Refit.Tests.IGitHubApi.GetIndex() + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("GetIndex", global::System.Array.Empty() ); + try + { + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + /// + global::System.IObservable global::Refit.Tests.IGitHubApi.GetIndexObservable() + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("GetIndexObservable", global::System.Array.Empty() ); + try + { + return (global::System.IObservable)______func(this.Client, ______arguments); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + /// + async global::System.Threading.Tasks.Task global::Refit.Tests.IGitHubApi.NothingToSeeHere() + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("NothingToSeeHere", global::System.Array.Empty() ); + try + { + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + /// + async global::System.Threading.Tasks.Task> global::Refit.Tests.IGitHubApi.NothingToSeeHereWithMetadata() + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("NothingToSeeHereWithMetadata", global::System.Array.Empty() ); + try + { + return await ((global::System.Threading.Tasks.Task>)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + private static readonly global::System.Type[] ______typeParameters13 = new global::System.Type[] {typeof(string) }; + + /// + async global::System.Threading.Tasks.Task> global::Refit.Tests.IGitHubApi.GetUserWithMetadata(string @userName) + { + var ______arguments = new object[] { @userName }; + var ______func = requestBuilder.BuildRestResultFuncForMethod("GetUserWithMetadata", ______typeParameters13 ); + try + { + return await ((global::System.Threading.Tasks.Task>)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + private static readonly global::System.Type[] ______typeParameters14 = new global::System.Type[] {typeof(string) }; + + /// + global::System.IObservable> global::Refit.Tests.IGitHubApi.GetUserObservableWithMetadata(string @userName) + { + var ______arguments = new object[] { @userName }; + var ______func = requestBuilder.BuildRestResultFuncForMethod("GetUserObservableWithMetadata", ______typeParameters14 ); + try + { + return (global::System.IObservable>)______func(this.Client, ______arguments); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + private static readonly global::System.Type[] ______typeParameters15 = new global::System.Type[] {typeof(global::Refit.Tests.User) }; + + /// + async global::System.Threading.Tasks.Task global::Refit.Tests.IGitHubApi.CreateUser(global::Refit.Tests.User @user) + { + var ______arguments = new object[] { @user }; + var ______func = requestBuilder.BuildRestResultFuncForMethod("CreateUser", ______typeParameters15 ); + try + { + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + private static readonly global::System.Type[] ______typeParameters16 = new global::System.Type[] {typeof(global::Refit.Tests.User) }; + + /// + async global::System.Threading.Tasks.Task> global::Refit.Tests.IGitHubApi.CreateUserWithMetadata(global::Refit.Tests.User @user) + { + var ______arguments = new object[] { @user }; + var ______func = requestBuilder.BuildRestResultFuncForMethod("CreateUserWithMetadata", ______typeParameters16 ); + try + { + return await ((global::System.Threading.Tasks.Task>)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + } + } +} + +#pragma warning restore diff --git a/RefitGenerator.Tests/_snapshots/RefitGeneratorTests.FindInterfacesSmokeTest#IGitHubApiDisposable.g.verified.cs b/RefitGenerator.Tests/_snapshots/RefitGeneratorTests.FindInterfacesSmokeTest#IGitHubApiDisposable.g.verified.cs new file mode 100644 index 000000000..768c0272a --- /dev/null +++ b/RefitGenerator.Tests/_snapshots/RefitGeneratorTests.FindInterfacesSmokeTest#IGitHubApiDisposable.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: IGitHubApiDisposable.g.cs +#nullable disable +#pragma warning disable +namespace Refit.Implementation +{ + + partial class Generated + { + + /// + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.Diagnostics.DebuggerNonUserCode] + [global::RefitInternalGenerated.PreserveAttribute] + [global::System.Reflection.Obfuscation(Exclude=true)] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + partial class RefitTestsIGitHubApiDisposable + : global::Refit.Tests.IGitHubApiDisposable + + { + /// + public global::System.Net.Http.HttpClient Client { get; } + readonly global::Refit.IRequestBuilder requestBuilder; + + /// + public RefitTestsIGitHubApiDisposable(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder) + { + Client = client; + this.requestBuilder = requestBuilder; + } + + + + /// + public async global::System.Threading.Tasks.Task RefitMethod() + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("RefitMethod", global::System.Array.Empty() ); + try + { + await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + /// + async global::System.Threading.Tasks.Task global::Refit.Tests.IGitHubApiDisposable.RefitMethod() + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("RefitMethod", global::System.Array.Empty() ); + try + { + await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + /// + void global::System.IDisposable.Dispose() + { + Client?.Dispose(); + } + } + } +} + +#pragma warning restore diff --git a/RefitGenerator.Tests/_snapshots/RefitGeneratorTests.FindInterfacesSmokeTest#INestedGitHubApi.g.verified.cs b/RefitGenerator.Tests/_snapshots/RefitGeneratorTests.FindInterfacesSmokeTest#INestedGitHubApi.g.verified.cs new file mode 100644 index 000000000..01907e7f1 --- /dev/null +++ b/RefitGenerator.Tests/_snapshots/RefitGeneratorTests.FindInterfacesSmokeTest#INestedGitHubApi.g.verified.cs @@ -0,0 +1,296 @@ +//HintName: INestedGitHubApi.g.cs +#nullable disable +#pragma warning disable +namespace Refit.Implementation +{ + + partial class Generated + { + + /// + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.Diagnostics.DebuggerNonUserCode] + [global::RefitInternalGenerated.PreserveAttribute] + [global::System.Reflection.Obfuscation(Exclude=true)] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + partial class RefitTestsTestNestedINestedGitHubApi + : global::Refit.Tests.TestNested.INestedGitHubApi + + { + /// + public global::System.Net.Http.HttpClient Client { get; } + readonly global::Refit.IRequestBuilder requestBuilder; + + /// + public RefitTestsTestNestedINestedGitHubApi(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder) + { + Client = client; + this.requestBuilder = requestBuilder; + } + + + + private static readonly global::System.Type[] ______typeParameters = new global::System.Type[] {typeof(string) }; + + /// + public async global::System.Threading.Tasks.Task GetUser(string @userName) + { + var ______arguments = new object[] { @userName }; + var ______func = requestBuilder.BuildRestResultFuncForMethod("GetUser", ______typeParameters ); + try + { + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + private static readonly global::System.Type[] ______typeParameters0 = new global::System.Type[] {typeof(string) }; + + /// + public global::System.IObservable GetUserObservable(string @userName) + { + var ______arguments = new object[] { @userName }; + var ______func = requestBuilder.BuildRestResultFuncForMethod("GetUserObservable", ______typeParameters0 ); + try + { + return (global::System.IObservable)______func(this.Client, ______arguments); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + private static readonly global::System.Type[] ______typeParameters1 = new global::System.Type[] {typeof(string) }; + + /// + public global::System.IObservable GetUserCamelCase(string @userName) + { + var ______arguments = new object[] { @userName }; + var ______func = requestBuilder.BuildRestResultFuncForMethod("GetUserCamelCase", ______typeParameters1 ); + try + { + return (global::System.IObservable)______func(this.Client, ______arguments); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + private static readonly global::System.Type[] ______typeParameters2 = new global::System.Type[] {typeof(string) }; + + /// + public async global::System.Threading.Tasks.Task> GetOrgMembers(string @orgName) + { + var ______arguments = new object[] { @orgName }; + var ______func = requestBuilder.BuildRestResultFuncForMethod("GetOrgMembers", ______typeParameters2 ); + try + { + return await ((global::System.Threading.Tasks.Task>)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + private static readonly global::System.Type[] ______typeParameters3 = new global::System.Type[] {typeof(string) }; + + /// + public async global::System.Threading.Tasks.Task FindUsers(string @q) + { + var ______arguments = new object[] { @q }; + var ______func = requestBuilder.BuildRestResultFuncForMethod("FindUsers", ______typeParameters3 ); + try + { + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + /// + public async global::System.Threading.Tasks.Task GetIndex() + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("GetIndex", global::System.Array.Empty() ); + try + { + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + /// + public global::System.IObservable GetIndexObservable() + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("GetIndexObservable", global::System.Array.Empty() ); + try + { + return (global::System.IObservable)______func(this.Client, ______arguments); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + /// + public async global::System.Threading.Tasks.Task NothingToSeeHere() + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("NothingToSeeHere", global::System.Array.Empty() ); + try + { + await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + private static readonly global::System.Type[] ______typeParameters4 = new global::System.Type[] {typeof(string) }; + + /// + async global::System.Threading.Tasks.Task global::Refit.Tests.TestNested.INestedGitHubApi.GetUser(string @userName) + { + var ______arguments = new object[] { @userName }; + var ______func = requestBuilder.BuildRestResultFuncForMethod("GetUser", ______typeParameters4 ); + try + { + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + private static readonly global::System.Type[] ______typeParameters5 = new global::System.Type[] {typeof(string) }; + + /// + global::System.IObservable global::Refit.Tests.TestNested.INestedGitHubApi.GetUserObservable(string @userName) + { + var ______arguments = new object[] { @userName }; + var ______func = requestBuilder.BuildRestResultFuncForMethod("GetUserObservable", ______typeParameters5 ); + try + { + return (global::System.IObservable)______func(this.Client, ______arguments); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + private static readonly global::System.Type[] ______typeParameters6 = new global::System.Type[] {typeof(string) }; + + /// + global::System.IObservable global::Refit.Tests.TestNested.INestedGitHubApi.GetUserCamelCase(string @userName) + { + var ______arguments = new object[] { @userName }; + var ______func = requestBuilder.BuildRestResultFuncForMethod("GetUserCamelCase", ______typeParameters6 ); + try + { + return (global::System.IObservable)______func(this.Client, ______arguments); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + private static readonly global::System.Type[] ______typeParameters7 = new global::System.Type[] {typeof(string) }; + + /// + async global::System.Threading.Tasks.Task> global::Refit.Tests.TestNested.INestedGitHubApi.GetOrgMembers(string @orgName) + { + var ______arguments = new object[] { @orgName }; + var ______func = requestBuilder.BuildRestResultFuncForMethod("GetOrgMembers", ______typeParameters7 ); + try + { + return await ((global::System.Threading.Tasks.Task>)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + private static readonly global::System.Type[] ______typeParameters8 = new global::System.Type[] {typeof(string) }; + + /// + async global::System.Threading.Tasks.Task global::Refit.Tests.TestNested.INestedGitHubApi.FindUsers(string @q) + { + var ______arguments = new object[] { @q }; + var ______func = requestBuilder.BuildRestResultFuncForMethod("FindUsers", ______typeParameters8 ); + try + { + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + /// + async global::System.Threading.Tasks.Task global::Refit.Tests.TestNested.INestedGitHubApi.GetIndex() + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("GetIndex", global::System.Array.Empty() ); + try + { + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + /// + global::System.IObservable global::Refit.Tests.TestNested.INestedGitHubApi.GetIndexObservable() + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("GetIndexObservable", global::System.Array.Empty() ); + try + { + return (global::System.IObservable)______func(this.Client, ______arguments); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + /// + async global::System.Threading.Tasks.Task global::Refit.Tests.TestNested.INestedGitHubApi.NothingToSeeHere() + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("NothingToSeeHere", global::System.Array.Empty() ); + try + { + await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + } + } +} + +#pragma warning restore diff --git a/RefitGenerator.Tests/_snapshots/RefitGeneratorTests.FindInterfacesSmokeTest#PreserveAttribute.g.verified.cs b/RefitGenerator.Tests/_snapshots/RefitGeneratorTests.FindInterfacesSmokeTest#PreserveAttribute.g.verified.cs new file mode 100644 index 000000000..71b34929f --- /dev/null +++ b/RefitGenerator.Tests/_snapshots/RefitGeneratorTests.FindInterfacesSmokeTest#PreserveAttribute.g.verified.cs @@ -0,0 +1,19 @@ +//HintName: PreserveAttribute.g.cs + +#pragma warning disable +namespace RefitInternalGenerated +{ + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + [global::System.AttributeUsage (global::System.AttributeTargets.Class | global::System.AttributeTargets.Struct | global::System.AttributeTargets.Enum | global::System.AttributeTargets.Constructor | global::System.AttributeTargets.Method | global::System.AttributeTargets.Property | global::System.AttributeTargets.Field | global::System.AttributeTargets.Event | global::System.AttributeTargets.Interface | global::System.AttributeTargets.Delegate)] + sealed class PreserveAttribute : global::System.Attribute + { + // + // Fields + // + public bool AllMembers; + + public bool Conditional; + } +} +#pragma warning restore diff --git a/RefitGenerator.Tests/_snapshots/RefitGeneratorTests.GenerateInterfaceStubsWithoutNamespaceSmokeTest#Generated.g.verified.cs b/RefitGenerator.Tests/_snapshots/RefitGeneratorTests.GenerateInterfaceStubsWithoutNamespaceSmokeTest#Generated.g.verified.cs new file mode 100644 index 000000000..4470d5d71 --- /dev/null +++ b/RefitGenerator.Tests/_snapshots/RefitGeneratorTests.GenerateInterfaceStubsWithoutNamespaceSmokeTest#Generated.g.verified.cs @@ -0,0 +1,24 @@ +//HintName: Generated.g.cs + +#pragma warning disable +namespace Refit.Implementation +{ + + /// + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.Diagnostics.DebuggerNonUserCode] + [global::RefitInternalGenerated.PreserveAttribute] + [global::System.Reflection.Obfuscation(Exclude=true)] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + internal static partial class Generated + { +#if NET5_0_OR_GREATER + [System.Runtime.CompilerServices.ModuleInitializer] + [System.Diagnostics.CodeAnalysis.DynamicDependency(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All, typeof(global::Refit.Implementation.Generated))] + public static void Initialize() + { + } +#endif + } +} +#pragma warning restore diff --git a/RefitGenerator.Tests/_snapshots/RefitGeneratorTests.GenerateInterfaceStubsWithoutNamespaceSmokeTest#IServiceWithoutNamespace.g.verified.cs b/RefitGenerator.Tests/_snapshots/RefitGeneratorTests.GenerateInterfaceStubsWithoutNamespaceSmokeTest#IServiceWithoutNamespace.g.verified.cs new file mode 100644 index 000000000..e3552deab --- /dev/null +++ b/RefitGenerator.Tests/_snapshots/RefitGeneratorTests.GenerateInterfaceStubsWithoutNamespaceSmokeTest#IServiceWithoutNamespace.g.verified.cs @@ -0,0 +1,96 @@ +//HintName: IServiceWithoutNamespace.g.cs +#nullable disable +#pragma warning disable +namespace Refit.Implementation +{ + + partial class Generated + { + + /// + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.Diagnostics.DebuggerNonUserCode] + [global::RefitInternalGenerated.PreserveAttribute] + [global::System.Reflection.Obfuscation(Exclude=true)] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + partial class IServiceWithoutNamespace + : global::IServiceWithoutNamespace + + { + /// + public global::System.Net.Http.HttpClient Client { get; } + readonly global::Refit.IRequestBuilder requestBuilder; + + /// + public IServiceWithoutNamespace(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder) + { + Client = client; + this.requestBuilder = requestBuilder; + } + + + + /// + public async global::System.Threading.Tasks.Task GetRoot() + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("GetRoot", global::System.Array.Empty() ); + try + { + await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + /// + public async global::System.Threading.Tasks.Task PostRoot() + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("PostRoot", global::System.Array.Empty() ); + try + { + await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + /// + async global::System.Threading.Tasks.Task global::IServiceWithoutNamespace.GetRoot() + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("GetRoot", global::System.Array.Empty() ); + try + { + await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + /// + async global::System.Threading.Tasks.Task global::IServiceWithoutNamespace.PostRoot() + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("PostRoot", global::System.Array.Empty() ); + try + { + await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + } + } +} + +#pragma warning restore diff --git a/RefitGenerator.Tests/_snapshots/RefitGeneratorTests.GenerateInterfaceStubsWithoutNamespaceSmokeTest#PreserveAttribute.g.verified.cs b/RefitGenerator.Tests/_snapshots/RefitGeneratorTests.GenerateInterfaceStubsWithoutNamespaceSmokeTest#PreserveAttribute.g.verified.cs new file mode 100644 index 000000000..71b34929f --- /dev/null +++ b/RefitGenerator.Tests/_snapshots/RefitGeneratorTests.GenerateInterfaceStubsWithoutNamespaceSmokeTest#PreserveAttribute.g.verified.cs @@ -0,0 +1,19 @@ +//HintName: PreserveAttribute.g.cs + +#pragma warning disable +namespace RefitInternalGenerated +{ + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + [global::System.AttributeUsage (global::System.AttributeTargets.Class | global::System.AttributeTargets.Struct | global::System.AttributeTargets.Enum | global::System.AttributeTargets.Constructor | global::System.AttributeTargets.Method | global::System.AttributeTargets.Property | global::System.AttributeTargets.Field | global::System.AttributeTargets.Event | global::System.AttributeTargets.Interface | global::System.AttributeTargets.Delegate)] + sealed class PreserveAttribute : global::System.Attribute + { + // + // Fields + // + public bool AllMembers; + + public bool Conditional; + } +} +#pragma warning restore