From 504764ed5cb4a11bdd41dc1916f71efb0a138e0f Mon Sep 17 00:00:00 2001 From: HavenDV Date: Sun, 4 Aug 2024 18:47:35 +0400 Subject: [PATCH] test: Refactored. --- OpenAI.sln | 35 ++++++++----------- .../OpenAiFunctionsGenerator.cs | 13 +++---- src/libs/OpenAI.Generators/Sources.Calls.cs | 5 +-- src/libs/OpenAI.Generators/Sources.Tools.cs | 5 +-- .../{Generators => }/Steps.cs | 2 +- .../Attributes/OpenAiFunctionsAttribute.cs | 4 +-- .../OpenAI.Generators.IntegrationTests.csproj | 30 ---------------- .../SnapshotTests.cs | 17 --------- .../OpenAI.IntegrationTests.csproj | 2 ++ .../Tools/Tests.Tools.cs} | 3 +- .../Tools/VariousTypesTools.cs} | 9 +++-- .../Tools/WeatherTools.cs} | 9 +++-- .../ModuleInitializer.cs | 2 +- .../OpenAI.SnapshotTests.csproj} | 8 +++-- .../OpenAI.SnapshotTests/SnapshotTests.cs | 17 +++++++++ ...IWeatherTools.Calls.generated.verified.cs} | 30 ++++++++-------- ...IWeatherTools.Tools.generated.verified.cs} | 8 ++--- ...eneratesCorrectly_Diagnostics.verified.txt | 2 +- ...ousTypesTools.Calls.generated.verified.cs} | 18 +++++----- ...ousTypesTools.Tools.generated.verified.cs} | 8 ++--- ...ests.VariousTypes_Diagnostics.verified.txt | 2 +- .../TestHelper.cs | 7 ++-- 22 files changed, 103 insertions(+), 133 deletions(-) rename src/libs/OpenAI.Generators/{Generators => }/OpenAiFunctionsGenerator.cs (82%) rename src/libs/OpenAI.Generators/{Generators => }/Steps.cs (97%) delete mode 100644 src/tests/OpenAI.Generators.IntegrationTests/OpenAI.Generators.IntegrationTests.csproj delete mode 100755 src/tests/OpenAI.Generators.SnapshotTests/SnapshotTests.cs rename src/tests/{OpenAI.Generators.IntegrationTests/Tests.Functions.cs => OpenAI.IntegrationTests/Tools/Tests.Tools.cs} (98%) rename src/tests/{OpenAI.Generators.IntegrationTests/VariousTypesFunctions.cs => OpenAI.IntegrationTests/Tools/VariousTypesTools.cs} (78%) rename src/tests/{OpenAI.Generators.IntegrationTests/WeatherFunctions.cs => OpenAI.IntegrationTests/Tools/WeatherTools.cs} (90%) rename src/tests/{OpenAI.Generators.SnapshotTests => OpenAI.SnapshotTests}/ModuleInitializer.cs (84%) rename src/tests/{OpenAI.Generators.SnapshotTests/OpenAI.Generators.SnapshotTests.csproj => OpenAI.SnapshotTests/OpenAI.SnapshotTests.csproj} (87%) create mode 100755 src/tests/OpenAI.SnapshotTests/SnapshotTests.cs rename src/tests/{OpenAI.Generators.SnapshotTests/Snapshots/IpcGeneratorSnapshotTests.GeneratesCorrectly#IWeatherFunctions.Calls.generated.verified.cs => OpenAI.SnapshotTests/Snapshots/IpcGeneratorSnapshotTests.GeneratesCorrectly#IWeatherTools.Calls.generated.verified.cs} (80%) rename src/tests/{OpenAI.Generators.SnapshotTests/Snapshots/IpcGeneratorSnapshotTests.GeneratesCorrectly#IWeatherFunctions.Tools.generated.verified.cs => OpenAI.SnapshotTests/Snapshots/IpcGeneratorSnapshotTests.GeneratesCorrectly#IWeatherTools.Tools.generated.verified.cs} (93%) rename src/tests/{OpenAI.Generators.SnapshotTests => OpenAI.SnapshotTests}/Snapshots/IpcGeneratorSnapshotTests.GeneratesCorrectly_Diagnostics.verified.txt (75%) rename src/tests/{OpenAI.Generators.SnapshotTests/Snapshots/IpcGeneratorSnapshotTests.VariousTypes#IVariousTypesFunctions.Calls.generated.verified.cs => OpenAI.SnapshotTests/Snapshots/IpcGeneratorSnapshotTests.VariousTypes#IVariousTypesTools.Calls.generated.verified.cs} (83%) rename src/tests/{OpenAI.Generators.SnapshotTests/Snapshots/IpcGeneratorSnapshotTests.VariousTypes#IVariousTypesFunctions.Tools.generated.verified.cs => OpenAI.SnapshotTests/Snapshots/IpcGeneratorSnapshotTests.VariousTypes#IVariousTypesTools.Tools.generated.verified.cs} (92%) rename src/tests/{OpenAI.Generators.SnapshotTests => OpenAI.SnapshotTests}/Snapshots/IpcGeneratorSnapshotTests.VariousTypes_Diagnostics.verified.txt (74%) rename src/tests/{OpenAI.Generators.SnapshotTests => OpenAI.SnapshotTests}/TestHelper.cs (90%) diff --git a/OpenAI.sln b/OpenAI.sln index 530ab1dc..acd05b3a 100755 --- a/OpenAI.sln +++ b/OpenAI.sln @@ -25,14 +25,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{AAA11B78 EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenAI", "src\libs\OpenAI\OpenAI.csproj", "{0028BC85-0064-4CE8-A21A-C1F5E922BD59}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenAI.IntegrationTests", "src\tests\OpenAI.IntegrationTests\OpenAI.IntegrationTests.csproj", "{2C15EAC0-08E6-447A-84E2-1398DDE358AC}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenAI.Generators", "src\libs\OpenAI.Generators\OpenAI.Generators.csproj", "{5504353C-9B7F-402B-9268-4821AB5E73F9}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenAI.Generators.IntegrationTests", "src\tests\OpenAI.Generators.IntegrationTests\OpenAI.Generators.IntegrationTests.csproj", "{83CBA1D2-8424-4925-9F55-BEB64C7E3EE6}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenAI.Generators.SnapshotTests", "src\tests\OpenAI.Generators.SnapshotTests\OpenAI.Generators.SnapshotTests.csproj", "{4F534836-40A3-4E75-8B71-C46CD4FBE137}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FixOpenApiSpec", "src\helpers\FixOpenApiSpec\FixOpenApiSpec.csproj", "{594DCFD8-E707-4232-B878-90FA3D880474}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "helpers", "helpers", "{1A008ECD-2300-4BE4-A302-49DDF8BE0D54}" @@ -41,6 +35,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenAI.Generators.Core", "s EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TrimmingHelper", "src\helpers\TrimmingHelper\TrimmingHelper.csproj", "{9F7DC3A1-B113-4577-875D-73B2DDD6647A}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenAI.IntegrationTests", "src\tests\OpenAI.IntegrationTests\OpenAI.IntegrationTests.csproj", "{A3F06E45-DFA8-4236-BFF5-425091762548}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenAI.SnapshotTests", "src\tests\OpenAI.SnapshotTests\OpenAI.SnapshotTests.csproj", "{F1A9D4C9-0075-4AB0-95A2-095B7DF31FB1}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -51,22 +49,10 @@ Global {0028BC85-0064-4CE8-A21A-C1F5E922BD59}.Debug|Any CPU.Build.0 = Debug|Any CPU {0028BC85-0064-4CE8-A21A-C1F5E922BD59}.Release|Any CPU.ActiveCfg = Release|Any CPU {0028BC85-0064-4CE8-A21A-C1F5E922BD59}.Release|Any CPU.Build.0 = Release|Any CPU - {2C15EAC0-08E6-447A-84E2-1398DDE358AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {2C15EAC0-08E6-447A-84E2-1398DDE358AC}.Debug|Any CPU.Build.0 = Debug|Any CPU - {2C15EAC0-08E6-447A-84E2-1398DDE358AC}.Release|Any CPU.ActiveCfg = Release|Any CPU - {2C15EAC0-08E6-447A-84E2-1398DDE358AC}.Release|Any CPU.Build.0 = Release|Any CPU {5504353C-9B7F-402B-9268-4821AB5E73F9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {5504353C-9B7F-402B-9268-4821AB5E73F9}.Debug|Any CPU.Build.0 = Debug|Any CPU {5504353C-9B7F-402B-9268-4821AB5E73F9}.Release|Any CPU.ActiveCfg = Release|Any CPU {5504353C-9B7F-402B-9268-4821AB5E73F9}.Release|Any CPU.Build.0 = Release|Any CPU - {83CBA1D2-8424-4925-9F55-BEB64C7E3EE6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {83CBA1D2-8424-4925-9F55-BEB64C7E3EE6}.Debug|Any CPU.Build.0 = Debug|Any CPU - {83CBA1D2-8424-4925-9F55-BEB64C7E3EE6}.Release|Any CPU.ActiveCfg = Release|Any CPU - {83CBA1D2-8424-4925-9F55-BEB64C7E3EE6}.Release|Any CPU.Build.0 = Release|Any CPU - {4F534836-40A3-4E75-8B71-C46CD4FBE137}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {4F534836-40A3-4E75-8B71-C46CD4FBE137}.Debug|Any CPU.Build.0 = Debug|Any CPU - {4F534836-40A3-4E75-8B71-C46CD4FBE137}.Release|Any CPU.ActiveCfg = Release|Any CPU - {4F534836-40A3-4E75-8B71-C46CD4FBE137}.Release|Any CPU.Build.0 = Release|Any CPU {594DCFD8-E707-4232-B878-90FA3D880474}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {594DCFD8-E707-4232-B878-90FA3D880474}.Debug|Any CPU.Build.0 = Debug|Any CPU {594DCFD8-E707-4232-B878-90FA3D880474}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -79,19 +65,26 @@ Global {9F7DC3A1-B113-4577-875D-73B2DDD6647A}.Debug|Any CPU.Build.0 = Debug|Any CPU {9F7DC3A1-B113-4577-875D-73B2DDD6647A}.Release|Any CPU.ActiveCfg = Release|Any CPU {9F7DC3A1-B113-4577-875D-73B2DDD6647A}.Release|Any CPU.Build.0 = Release|Any CPU + {A3F06E45-DFA8-4236-BFF5-425091762548}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A3F06E45-DFA8-4236-BFF5-425091762548}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A3F06E45-DFA8-4236-BFF5-425091762548}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A3F06E45-DFA8-4236-BFF5-425091762548}.Release|Any CPU.Build.0 = Release|Any CPU + {F1A9D4C9-0075-4AB0-95A2-095B7DF31FB1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F1A9D4C9-0075-4AB0-95A2-095B7DF31FB1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F1A9D4C9-0075-4AB0-95A2-095B7DF31FB1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F1A9D4C9-0075-4AB0-95A2-095B7DF31FB1}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution {0028BC85-0064-4CE8-A21A-C1F5E922BD59} = {61E7E11E-4558-434C-ACE8-06316A3097B3} - {2C15EAC0-08E6-447A-84E2-1398DDE358AC} = {AAA11B78-2764-4520-A97E-46AA7089A588} {5504353C-9B7F-402B-9268-4821AB5E73F9} = {61E7E11E-4558-434C-ACE8-06316A3097B3} - {83CBA1D2-8424-4925-9F55-BEB64C7E3EE6} = {AAA11B78-2764-4520-A97E-46AA7089A588} - {4F534836-40A3-4E75-8B71-C46CD4FBE137} = {AAA11B78-2764-4520-A97E-46AA7089A588} {594DCFD8-E707-4232-B878-90FA3D880474} = {1A008ECD-2300-4BE4-A302-49DDF8BE0D54} {FCBE699C-CCD3-4809-8128-78956BC3F2C3} = {61E7E11E-4558-434C-ACE8-06316A3097B3} {9F7DC3A1-B113-4577-875D-73B2DDD6647A} = {1A008ECD-2300-4BE4-A302-49DDF8BE0D54} + {A3F06E45-DFA8-4236-BFF5-425091762548} = {AAA11B78-2764-4520-A97E-46AA7089A588} + {F1A9D4C9-0075-4AB0-95A2-095B7DF31FB1} = {AAA11B78-2764-4520-A97E-46AA7089A588} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {CED9A020-DBA5-4BE6-8096-75E528648EC1} diff --git a/src/libs/OpenAI.Generators/Generators/OpenAiFunctionsGenerator.cs b/src/libs/OpenAI.Generators/OpenAiFunctionsGenerator.cs similarity index 82% rename from src/libs/OpenAI.Generators/Generators/OpenAiFunctionsGenerator.cs rename to src/libs/OpenAI.Generators/OpenAiFunctionsGenerator.cs index 5a3002ca..a93ef31d 100755 --- a/src/libs/OpenAI.Generators/Generators/OpenAiFunctionsGenerator.cs +++ b/src/libs/OpenAI.Generators/OpenAiFunctionsGenerator.cs @@ -1,17 +1,18 @@ -using H.Generators.Extensions; +using H.Generators; +using H.Generators.Extensions; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp.Syntax; using OpenAI.Generators.Core.Conversion; -namespace H.Generators; +namespace OpenAI.Generators; [Generator] -public class OpenAiFunctionsGenerator : IIncrementalGenerator +public class OpenAiToolsGenerator : IIncrementalGenerator { #region Constants - public const string Name = nameof(OpenAiFunctionsGenerator); - public const string Id = "OAFG"; + public const string Name = nameof(OpenAiToolsGenerator); + public const string Id = "OATG"; #endregion @@ -21,7 +22,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context) { var attributes = context.SyntaxProvider - .ForAttributeWithMetadataName("OpenAI.OpenAiFunctionsAttribute") + .ForAttributeWithMetadataName("OpenAI.OpenAiToolsAttribute") .SelectManyAllAttributesOfCurrentInterfaceSyntax() .SelectAndReportExceptions(PrepareData, context, Id); diff --git a/src/libs/OpenAI.Generators/Sources.Calls.cs b/src/libs/OpenAI.Generators/Sources.Calls.cs index d4416eed..af986fbb 100755 --- a/src/libs/OpenAI.Generators/Sources.Calls.cs +++ b/src/libs/OpenAI.Generators/Sources.Calls.cs @@ -1,6 +1,7 @@ -using H.Generators.Extensions; +using H.Generators; +using H.Generators.Extensions; -namespace H.Generators; +namespace OpenAI.Generators; internal static partial class Sources { diff --git a/src/libs/OpenAI.Generators/Sources.Tools.cs b/src/libs/OpenAI.Generators/Sources.Tools.cs index 69c66134..8eaa71e1 100755 --- a/src/libs/OpenAI.Generators/Sources.Tools.cs +++ b/src/libs/OpenAI.Generators/Sources.Tools.cs @@ -1,7 +1,8 @@ -using H.Generators.Extensions; +using H.Generators; +using H.Generators.Extensions; using OpenAI.Generators.Core; -namespace H.Generators; +namespace OpenAI.Generators; internal static partial class Sources { diff --git a/src/libs/OpenAI.Generators/Generators/Steps.cs b/src/libs/OpenAI.Generators/Steps.cs similarity index 97% rename from src/libs/OpenAI.Generators/Generators/Steps.cs rename to src/libs/OpenAI.Generators/Steps.cs index 359dad54..2cf00044 100644 --- a/src/libs/OpenAI.Generators/Generators/Steps.cs +++ b/src/libs/OpenAI.Generators/Steps.cs @@ -1,7 +1,7 @@ using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp.Syntax; -namespace H.Generators; +namespace OpenAI.Generators; public static class CommonSteps { diff --git a/src/libs/OpenAI/Attributes/OpenAiFunctionsAttribute.cs b/src/libs/OpenAI/Attributes/OpenAiFunctionsAttribute.cs index d0c3b976..6e0a2e52 100644 --- a/src/libs/OpenAI/Attributes/OpenAiFunctionsAttribute.cs +++ b/src/libs/OpenAI/Attributes/OpenAiFunctionsAttribute.cs @@ -5,5 +5,5 @@ namespace OpenAI; /// /// [AttributeUsage(AttributeTargets.Interface)] -[System.Diagnostics.Conditional("OPENAI_FUNCTIONS_ATTRIBUTES")] -public sealed class OpenAiFunctionsAttribute : Attribute; \ No newline at end of file +[System.Diagnostics.Conditional("OPENAI_TOOLS_ATTRIBUTES")] +public sealed class OpenAiToolsAttribute : Attribute; \ No newline at end of file diff --git a/src/tests/OpenAI.Generators.IntegrationTests/OpenAI.Generators.IntegrationTests.csproj b/src/tests/OpenAI.Generators.IntegrationTests/OpenAI.Generators.IntegrationTests.csproj deleted file mode 100644 index e13aa923..00000000 --- a/src/tests/OpenAI.Generators.IntegrationTests/OpenAI.Generators.IntegrationTests.csproj +++ /dev/null @@ -1,30 +0,0 @@ - - - - net8.0 - false - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - - - - - - - - - - - - - diff --git a/src/tests/OpenAI.Generators.SnapshotTests/SnapshotTests.cs b/src/tests/OpenAI.Generators.SnapshotTests/SnapshotTests.cs deleted file mode 100755 index b001c5e6..00000000 --- a/src/tests/OpenAI.Generators.SnapshotTests/SnapshotTests.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace H.Generators.IntegrationTests; - -[TestClass] -public class IpcGeneratorSnapshotTests : VerifyBase -{ - [TestMethod] - public Task GeneratesCorrectly() - { - return this.CheckSourceAsync(Resources.WeatherFunctions_cs.AsString()); - } - - [TestMethod] - public Task VariousTypes() - { - return this.CheckSourceAsync(Resources.VariousTypesFunctions_cs.AsString()); - } -} \ No newline at end of file diff --git a/src/tests/OpenAI.IntegrationTests/OpenAI.IntegrationTests.csproj b/src/tests/OpenAI.IntegrationTests/OpenAI.IntegrationTests.csproj index 1f9ea98e..2433b74c 100644 --- a/src/tests/OpenAI.IntegrationTests/OpenAI.IntegrationTests.csproj +++ b/src/tests/OpenAI.IntegrationTests/OpenAI.IntegrationTests.csproj @@ -22,6 +22,8 @@ + + \ No newline at end of file diff --git a/src/tests/OpenAI.Generators.IntegrationTests/Tests.Functions.cs b/src/tests/OpenAI.IntegrationTests/Tools/Tests.Tools.cs similarity index 98% rename from src/tests/OpenAI.Generators.IntegrationTests/Tests.Functions.cs rename to src/tests/OpenAI.IntegrationTests/Tools/Tests.Tools.cs index 9e6234ba..5b9d4c16 100755 --- a/src/tests/OpenAI.Generators.IntegrationTests/Tests.Functions.cs +++ b/src/tests/OpenAI.IntegrationTests/Tools/Tests.Tools.cs @@ -4,9 +4,8 @@ using System.Threading.Tasks; using OpenAI; -namespace H.Ipc.Generator.IntegrationTests; +namespace OpenAI.IntegrationTests; -[TestClass] public partial class Tests { [TestMethod] diff --git a/src/tests/OpenAI.Generators.IntegrationTests/VariousTypesFunctions.cs b/src/tests/OpenAI.IntegrationTests/Tools/VariousTypesTools.cs similarity index 78% rename from src/tests/OpenAI.Generators.IntegrationTests/VariousTypesFunctions.cs rename to src/tests/OpenAI.IntegrationTests/Tools/VariousTypesTools.cs index ca601942..67ee13bb 100755 --- a/src/tests/OpenAI.Generators.IntegrationTests/VariousTypesFunctions.cs +++ b/src/tests/OpenAI.IntegrationTests/Tools/VariousTypesTools.cs @@ -1,11 +1,10 @@ using System; -using OpenAI; using DescriptionAttribute = System.ComponentModel.DescriptionAttribute; -namespace H.Ipc.Generator.IntegrationTests; +namespace OpenAI.IntegrationTests; -[OpenAiFunctions] -public interface IVariousTypesFunctions +[OpenAiTools] +public interface IVariousTypesTools { [Description("Get the current weather in a given location")] public bool GetCurrentWeather( @@ -18,7 +17,7 @@ public bool GetCurrentWeather( DateOnly date); } -public class VariousTypesService : IVariousTypesFunctions +public class VariousTypesService : IVariousTypesTools { public bool GetCurrentWeather( long parameter1, diff --git a/src/tests/OpenAI.Generators.IntegrationTests/WeatherFunctions.cs b/src/tests/OpenAI.IntegrationTests/Tools/WeatherTools.cs similarity index 90% rename from src/tests/OpenAI.Generators.IntegrationTests/WeatherFunctions.cs rename to src/tests/OpenAI.IntegrationTests/Tools/WeatherTools.cs index be6a9d39..3ac69a25 100755 --- a/src/tests/OpenAI.Generators.IntegrationTests/WeatherFunctions.cs +++ b/src/tests/OpenAI.IntegrationTests/Tools/WeatherTools.cs @@ -1,9 +1,8 @@ using System.Threading; using System.Threading.Tasks; -using OpenAI; using DescriptionAttribute = System.ComponentModel.DescriptionAttribute; -namespace H.Ipc.Generator.IntegrationTests; +namespace OpenAI.IntegrationTests; public enum Unit { @@ -19,8 +18,8 @@ public class Weather public string Description { get; set; } = string.Empty; } -[OpenAiFunctions] -public interface IWeatherFunctions +[OpenAiTools] +public interface IWeatherTools { [Description("Get the current weather in a given location")] public Weather GetCurrentWeather( @@ -34,7 +33,7 @@ public Task GetCurrentWeatherAsync( CancellationToken cancellationToken = default); } -public class WeatherService : IWeatherFunctions +public class WeatherService : IWeatherTools { public Weather GetCurrentWeather(string location, Unit unit = Unit.Celsius) { diff --git a/src/tests/OpenAI.Generators.SnapshotTests/ModuleInitializer.cs b/src/tests/OpenAI.SnapshotTests/ModuleInitializer.cs similarity index 84% rename from src/tests/OpenAI.Generators.SnapshotTests/ModuleInitializer.cs rename to src/tests/OpenAI.SnapshotTests/ModuleInitializer.cs index f66e221b..8f9e9945 100755 --- a/src/tests/OpenAI.Generators.SnapshotTests/ModuleInitializer.cs +++ b/src/tests/OpenAI.SnapshotTests/ModuleInitializer.cs @@ -1,7 +1,7 @@ using System.Runtime.CompilerServices; using VerifyTests; -namespace H.Generators.IntegrationTests; +namespace OpenAI.SnapshotTests; public static class ModuleInitializer { diff --git a/src/tests/OpenAI.Generators.SnapshotTests/OpenAI.Generators.SnapshotTests.csproj b/src/tests/OpenAI.SnapshotTests/OpenAI.SnapshotTests.csproj similarity index 87% rename from src/tests/OpenAI.Generators.SnapshotTests/OpenAI.Generators.SnapshotTests.csproj rename to src/tests/OpenAI.SnapshotTests/OpenAI.SnapshotTests.csproj index b2099a6e..52132eb3 100644 --- a/src/tests/OpenAI.Generators.SnapshotTests/OpenAI.Generators.SnapshotTests.csproj +++ b/src/tests/OpenAI.SnapshotTests/OpenAI.SnapshotTests.csproj @@ -21,8 +21,8 @@ - - + + @@ -42,4 +42,8 @@ + + + + diff --git a/src/tests/OpenAI.SnapshotTests/SnapshotTests.cs b/src/tests/OpenAI.SnapshotTests/SnapshotTests.cs new file mode 100755 index 00000000..2d7c83ef --- /dev/null +++ b/src/tests/OpenAI.SnapshotTests/SnapshotTests.cs @@ -0,0 +1,17 @@ +namespace OpenAI.SnapshotTests; + +[TestClass] +public class IpcGeneratorSnapshotTests : VerifyBase +{ + [TestMethod] + public Task GeneratesCorrectly() + { + return this.CheckSourceAsync(H.Resources.WeatherTools_cs.AsString()); + } + + [TestMethod] + public Task VariousTypes() + { + return this.CheckSourceAsync(H.Resources.VariousTypesTools_cs.AsString()); + } +} \ No newline at end of file diff --git a/src/tests/OpenAI.Generators.SnapshotTests/Snapshots/IpcGeneratorSnapshotTests.GeneratesCorrectly#IWeatherFunctions.Calls.generated.verified.cs b/src/tests/OpenAI.SnapshotTests/Snapshots/IpcGeneratorSnapshotTests.GeneratesCorrectly#IWeatherTools.Calls.generated.verified.cs similarity index 80% rename from src/tests/OpenAI.Generators.SnapshotTests/Snapshots/IpcGeneratorSnapshotTests.GeneratesCorrectly#IWeatherFunctions.Calls.generated.verified.cs rename to src/tests/OpenAI.SnapshotTests/Snapshots/IpcGeneratorSnapshotTests.GeneratesCorrectly#IWeatherTools.Calls.generated.verified.cs index ef3ebfff..bf4d1446 100644 --- a/src/tests/OpenAI.Generators.SnapshotTests/Snapshots/IpcGeneratorSnapshotTests.GeneratesCorrectly#IWeatherFunctions.Calls.generated.verified.cs +++ b/src/tests/OpenAI.SnapshotTests/Snapshots/IpcGeneratorSnapshotTests.GeneratesCorrectly#IWeatherTools.Calls.generated.verified.cs @@ -1,26 +1,26 @@ -//HintName: IWeatherFunctions.Calls.generated.cs +//HintName: IWeatherTools.Calls.generated.cs using System.Collections.Generic; #nullable enable -namespace H.Ipc.Generator.IntegrationTests +namespace OpenAI.IntegrationTests { - public static partial class WeatherFunctionsExtensions + public static partial class WeatherToolsExtensions { public class GetCurrentWeatherArgs { public string Location { get; set; } = string.Empty; - public global::H.Ipc.Generator.IntegrationTests.Unit Unit { get; set; } + public global::OpenAI.IntegrationTests.Unit Unit { get; set; } } public class GetCurrentWeatherAsyncArgs { public string Location { get; set; } = string.Empty; - public global::H.Ipc.Generator.IntegrationTests.Unit Unit { get; set; } + public global::OpenAI.IntegrationTests.Unit Unit { get; set; } } - public static global::System.Collections.Generic.IReadOnlyDictionary>> AsCalls(this IWeatherFunctions service) + public static global::System.Collections.Generic.IReadOnlyDictionary>> AsCalls(this IWeatherTools service) { return new global::System.Collections.Generic.Dictionary>> { @@ -37,12 +37,12 @@ public class GetCurrentWeatherAsyncArgs }; } - public static WeatherFunctionsExtensions.GetCurrentWeatherArgs AsGetCurrentWeatherArgs( - this IWeatherFunctions functions, + public static WeatherToolsExtensions.GetCurrentWeatherArgs AsGetCurrentWeatherArgs( + this IWeatherTools functions, string json) { return - global::System.Text.Json.JsonSerializer.Deserialize(json, new global::System.Text.Json.JsonSerializerOptions + global::System.Text.Json.JsonSerializer.Deserialize(json, new global::System.Text.Json.JsonSerializerOptions { PropertyNamingPolicy = global::System.Text.Json.JsonNamingPolicy.CamelCase, Converters = {{ new global::System.Text.Json.Serialization.JsonStringEnumConverter(global::System.Text.Json.JsonNamingPolicy.CamelCase) }} @@ -50,12 +50,12 @@ public static WeatherFunctionsExtensions.GetCurrentWeatherArgs AsGetCurrentWeath throw new global::System.InvalidOperationException("Could not deserialize JSON."); } - public static WeatherFunctionsExtensions.GetCurrentWeatherAsyncArgs AsGetCurrentWeatherAsyncArgs( - this IWeatherFunctions functions, + public static WeatherToolsExtensions.GetCurrentWeatherAsyncArgs AsGetCurrentWeatherAsyncArgs( + this IWeatherTools functions, string json) { return - global::System.Text.Json.JsonSerializer.Deserialize(json, new global::System.Text.Json.JsonSerializerOptions + global::System.Text.Json.JsonSerializer.Deserialize(json, new global::System.Text.Json.JsonSerializerOptions { PropertyNamingPolicy = global::System.Text.Json.JsonNamingPolicy.CamelCase, Converters = {{ new global::System.Text.Json.Serialization.JsonStringEnumConverter(global::System.Text.Json.JsonNamingPolicy.CamelCase) }} @@ -63,7 +63,7 @@ public static WeatherFunctionsExtensions.GetCurrentWeatherAsyncArgs AsGetCurrent throw new global::System.InvalidOperationException("Could not deserialize JSON."); } - public static string CallGetCurrentWeather(this IWeatherFunctions functions, string json) + public static string CallGetCurrentWeather(this IWeatherTools functions, string json) { var args = functions.AsGetCurrentWeatherArgs(json); var jsonResult = functions.GetCurrentWeather(args.Location, args.Unit); @@ -78,7 +78,7 @@ public static string CallGetCurrentWeather(this IWeatherFunctions functions, str public static async global::System.Threading.Tasks.Task CallGetCurrentWeatherAsync( - this IWeatherFunctions functions, + this IWeatherTools functions, string json, global::System.Threading.CancellationToken cancellationToken = default) { @@ -95,7 +95,7 @@ public static string CallGetCurrentWeather(this IWeatherFunctions functions, str public static async global::System.Threading.Tasks.Task CallAsync( - this IWeatherFunctions service, + this IWeatherTools service, string functionName, string argumentsAsJson, global::System.Threading.CancellationToken cancellationToken = default) diff --git a/src/tests/OpenAI.Generators.SnapshotTests/Snapshots/IpcGeneratorSnapshotTests.GeneratesCorrectly#IWeatherFunctions.Tools.generated.verified.cs b/src/tests/OpenAI.SnapshotTests/Snapshots/IpcGeneratorSnapshotTests.GeneratesCorrectly#IWeatherTools.Tools.generated.verified.cs similarity index 93% rename from src/tests/OpenAI.Generators.SnapshotTests/Snapshots/IpcGeneratorSnapshotTests.GeneratesCorrectly#IWeatherFunctions.Tools.generated.verified.cs rename to src/tests/OpenAI.SnapshotTests/Snapshots/IpcGeneratorSnapshotTests.GeneratesCorrectly#IWeatherTools.Tools.generated.verified.cs index 3d3a1439..33737ba9 100644 --- a/src/tests/OpenAI.Generators.SnapshotTests/Snapshots/IpcGeneratorSnapshotTests.GeneratesCorrectly#IWeatherFunctions.Tools.generated.verified.cs +++ b/src/tests/OpenAI.SnapshotTests/Snapshots/IpcGeneratorSnapshotTests.GeneratesCorrectly#IWeatherTools.Tools.generated.verified.cs @@ -1,12 +1,12 @@ -//HintName: IWeatherFunctions.Tools.generated.cs +//HintName: IWeatherTools.Tools.generated.cs #nullable enable -namespace H.Ipc.Generator.IntegrationTests +namespace OpenAI.IntegrationTests { - public static partial class WeatherFunctionsExtensions + public static partial class WeatherToolsExtensions { - public static global::System.Collections.Generic.IList AsTools(this IWeatherFunctions functions) + public static global::System.Collections.Generic.IList AsTools(this IWeatherTools functions) { return new global::System.Collections.Generic.List { diff --git a/src/tests/OpenAI.Generators.SnapshotTests/Snapshots/IpcGeneratorSnapshotTests.GeneratesCorrectly_Diagnostics.verified.txt b/src/tests/OpenAI.SnapshotTests/Snapshots/IpcGeneratorSnapshotTests.GeneratesCorrectly_Diagnostics.verified.txt similarity index 75% rename from src/tests/OpenAI.Generators.SnapshotTests/Snapshots/IpcGeneratorSnapshotTests.GeneratesCorrectly_Diagnostics.verified.txt rename to src/tests/OpenAI.SnapshotTests/Snapshots/IpcGeneratorSnapshotTests.GeneratesCorrectly_Diagnostics.verified.txt index 1f513240..cb8a1105 100644 --- a/src/tests/OpenAI.Generators.SnapshotTests/Snapshots/IpcGeneratorSnapshotTests.GeneratesCorrectly_Diagnostics.verified.txt +++ b/src/tests/OpenAI.SnapshotTests/Snapshots/IpcGeneratorSnapshotTests.GeneratesCorrectly_Diagnostics.verified.txt @@ -4,7 +4,7 @@ Title: Unnecessary using directive, Severity: Hidden, WarningLevel: 1, - Location: OpenAI.Generators/H.Generators.OpenAiFunctionsGenerator/IWeatherFunctions.Calls.generated.cs: (1,0)-(1,33), + Location: OpenAI.Generators/OpenAI.Generators.OpenAiToolsGenerator/IWeatherTools.Calls.generated.cs: (1,0)-(1,33), HelpLink: https://msdn.microsoft.com/query/roslyn.query?appId=roslyn&k=k(CS8019), MessageFormat: Unnecessary using directive., Message: Unnecessary using directive., diff --git a/src/tests/OpenAI.Generators.SnapshotTests/Snapshots/IpcGeneratorSnapshotTests.VariousTypes#IVariousTypesFunctions.Calls.generated.verified.cs b/src/tests/OpenAI.SnapshotTests/Snapshots/IpcGeneratorSnapshotTests.VariousTypes#IVariousTypesTools.Calls.generated.verified.cs similarity index 83% rename from src/tests/OpenAI.Generators.SnapshotTests/Snapshots/IpcGeneratorSnapshotTests.VariousTypes#IVariousTypesFunctions.Calls.generated.verified.cs rename to src/tests/OpenAI.SnapshotTests/Snapshots/IpcGeneratorSnapshotTests.VariousTypes#IVariousTypesTools.Calls.generated.verified.cs index 75231214..58bb53b6 100644 --- a/src/tests/OpenAI.Generators.SnapshotTests/Snapshots/IpcGeneratorSnapshotTests.VariousTypes#IVariousTypesFunctions.Calls.generated.verified.cs +++ b/src/tests/OpenAI.SnapshotTests/Snapshots/IpcGeneratorSnapshotTests.VariousTypes#IVariousTypesTools.Calls.generated.verified.cs @@ -1,12 +1,12 @@ -//HintName: IVariousTypesFunctions.Calls.generated.cs +//HintName: IVariousTypesTools.Calls.generated.cs using System.Collections.Generic; #nullable enable -namespace H.Ipc.Generator.IntegrationTests +namespace OpenAI.IntegrationTests { - public static partial class VariousTypesFunctionsExtensions + public static partial class VariousTypesToolsExtensions { public class GetCurrentWeatherArgs { @@ -19,7 +19,7 @@ public class GetCurrentWeatherArgs public global::System.DateOnly Date { get; set; } } - public static global::System.Collections.Generic.IReadOnlyDictionary>> AsCalls(this IVariousTypesFunctions service) + public static global::System.Collections.Generic.IReadOnlyDictionary>> AsCalls(this IVariousTypesTools service) { return new global::System.Collections.Generic.Dictionary>> { @@ -33,12 +33,12 @@ public class GetCurrentWeatherArgs }; } - public static VariousTypesFunctionsExtensions.GetCurrentWeatherArgs AsGetCurrentWeatherArgs( - this IVariousTypesFunctions functions, + public static VariousTypesToolsExtensions.GetCurrentWeatherArgs AsGetCurrentWeatherArgs( + this IVariousTypesTools functions, string json) { return - global::System.Text.Json.JsonSerializer.Deserialize(json, new global::System.Text.Json.JsonSerializerOptions + global::System.Text.Json.JsonSerializer.Deserialize(json, new global::System.Text.Json.JsonSerializerOptions { PropertyNamingPolicy = global::System.Text.Json.JsonNamingPolicy.CamelCase, Converters = {{ new global::System.Text.Json.Serialization.JsonStringEnumConverter(global::System.Text.Json.JsonNamingPolicy.CamelCase) }} @@ -46,7 +46,7 @@ public static VariousTypesFunctionsExtensions.GetCurrentWeatherArgs AsGetCurrent throw new global::System.InvalidOperationException("Could not deserialize JSON."); } - public static string CallGetCurrentWeather(this IVariousTypesFunctions functions, string json) + public static string CallGetCurrentWeather(this IVariousTypesTools functions, string json) { var args = functions.AsGetCurrentWeatherArgs(json); var jsonResult = functions.GetCurrentWeather(args.Parameter1, args.Parameter2, args.Parameter3, args.Parameter4, args.Parameter5, args.DateTime, args.Date); @@ -65,7 +65,7 @@ public static string CallGetCurrentWeather(this IVariousTypesFunctions functions public static async global::System.Threading.Tasks.Task CallAsync( - this IVariousTypesFunctions service, + this IVariousTypesTools service, string functionName, string argumentsAsJson, global::System.Threading.CancellationToken cancellationToken = default) diff --git a/src/tests/OpenAI.Generators.SnapshotTests/Snapshots/IpcGeneratorSnapshotTests.VariousTypes#IVariousTypesFunctions.Tools.generated.verified.cs b/src/tests/OpenAI.SnapshotTests/Snapshots/IpcGeneratorSnapshotTests.VariousTypes#IVariousTypesTools.Tools.generated.verified.cs similarity index 92% rename from src/tests/OpenAI.Generators.SnapshotTests/Snapshots/IpcGeneratorSnapshotTests.VariousTypes#IVariousTypesFunctions.Tools.generated.verified.cs rename to src/tests/OpenAI.SnapshotTests/Snapshots/IpcGeneratorSnapshotTests.VariousTypes#IVariousTypesTools.Tools.generated.verified.cs index 94a096ad..167f15eb 100644 --- a/src/tests/OpenAI.Generators.SnapshotTests/Snapshots/IpcGeneratorSnapshotTests.VariousTypes#IVariousTypesFunctions.Tools.generated.verified.cs +++ b/src/tests/OpenAI.SnapshotTests/Snapshots/IpcGeneratorSnapshotTests.VariousTypes#IVariousTypesTools.Tools.generated.verified.cs @@ -1,12 +1,12 @@ -//HintName: IVariousTypesFunctions.Tools.generated.cs +//HintName: IVariousTypesTools.Tools.generated.cs #nullable enable -namespace H.Ipc.Generator.IntegrationTests +namespace OpenAI.IntegrationTests { - public static partial class VariousTypesFunctionsExtensions + public static partial class VariousTypesToolsExtensions { - public static global::System.Collections.Generic.IList AsTools(this IVariousTypesFunctions functions) + public static global::System.Collections.Generic.IList AsTools(this IVariousTypesTools functions) { return new global::System.Collections.Generic.List { diff --git a/src/tests/OpenAI.Generators.SnapshotTests/Snapshots/IpcGeneratorSnapshotTests.VariousTypes_Diagnostics.verified.txt b/src/tests/OpenAI.SnapshotTests/Snapshots/IpcGeneratorSnapshotTests.VariousTypes_Diagnostics.verified.txt similarity index 74% rename from src/tests/OpenAI.Generators.SnapshotTests/Snapshots/IpcGeneratorSnapshotTests.VariousTypes_Diagnostics.verified.txt rename to src/tests/OpenAI.SnapshotTests/Snapshots/IpcGeneratorSnapshotTests.VariousTypes_Diagnostics.verified.txt index 368bb0c8..59816cbe 100644 --- a/src/tests/OpenAI.Generators.SnapshotTests/Snapshots/IpcGeneratorSnapshotTests.VariousTypes_Diagnostics.verified.txt +++ b/src/tests/OpenAI.SnapshotTests/Snapshots/IpcGeneratorSnapshotTests.VariousTypes_Diagnostics.verified.txt @@ -4,7 +4,7 @@ Title: Unnecessary using directive, Severity: Hidden, WarningLevel: 1, - Location: OpenAI.Generators/H.Generators.OpenAiFunctionsGenerator/IVariousTypesFunctions.Calls.generated.cs: (1,0)-(1,33), + Location: OpenAI.Generators/OpenAI.Generators.OpenAiToolsGenerator/IVariousTypesTools.Calls.generated.cs: (1,0)-(1,33), HelpLink: https://msdn.microsoft.com/query/roslyn.query?appId=roslyn&k=k(CS8019), MessageFormat: Unnecessary using directive., Message: Unnecessary using directive., diff --git a/src/tests/OpenAI.Generators.SnapshotTests/TestHelper.cs b/src/tests/OpenAI.SnapshotTests/TestHelper.cs similarity index 90% rename from src/tests/OpenAI.Generators.SnapshotTests/TestHelper.cs rename to src/tests/OpenAI.SnapshotTests/TestHelper.cs index 58ebdec0..feade67f 100755 --- a/src/tests/OpenAI.Generators.SnapshotTests/TestHelper.cs +++ b/src/tests/OpenAI.SnapshotTests/TestHelper.cs @@ -1,8 +1,9 @@ using H.Generators.Tests.Extensions; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; +using OpenAI.Generators; -namespace H.Generators.IntegrationTests; +namespace OpenAI.SnapshotTests; public static class TestHelper { @@ -14,7 +15,7 @@ public static async Task CheckSourceAsync( var referenceAssemblies = LatestReferenceAssemblies.Net80; var references = await referenceAssemblies.ResolveAsync(null, cancellationToken); references = references - .Add(MetadataReference.CreateFromFile(typeof(OpenAI.OpenAiFunctionsAttribute).Assembly.Location)); + .Add(MetadataReference.CreateFromFile(typeof(OpenAI.OpenAiToolsAttribute).Assembly.Location)); var compilation = (Compilation)CSharpCompilation.Create( assemblyName: "Tests", @@ -25,7 +26,7 @@ public static async Task CheckSourceAsync( references: references, options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)); var driver = CSharpGeneratorDriver - .Create(new OpenAiFunctionsGenerator()) + .Create(new OpenAiToolsGenerator()) .RunGeneratorsAndUpdateCompilation(compilation, out compilation, out _, cancellationToken); var diagnostics = compilation.GetDiagnostics(cancellationToken);