Skip to content

Commit

Permalink
feat: Fixed problems. Added IntegrationTests.
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed Apr 8, 2023
1 parent 0424ae4 commit f14bb68
Show file tree
Hide file tree
Showing 5 changed files with 156 additions and 0 deletions.
7 changes: 7 additions & 0 deletions OpenAIGenerator.sln
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenAIGenerator.SnapshotTests", "src\tests\OpenAIGenerator.SnapshotTests\OpenAIGenerator.SnapshotTests.csproj", "{A70EF69D-A519-4571-81BC-E066A1DAED27}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenAIGenerator.IntegrationTests", "src\tests\OpenAIGenerator.IntegrationTests\OpenAIGenerator.IntegrationTests.csproj", "{A23C604E-04A3-41F8-BF25-FD6ED6E8AA51}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -36,13 +38,18 @@ Global
{A70EF69D-A519-4571-81BC-E066A1DAED27}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A70EF69D-A519-4571-81BC-E066A1DAED27}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A70EF69D-A519-4571-81BC-E066A1DAED27}.Release|Any CPU.Build.0 = Release|Any CPU
{A23C604E-04A3-41F8-BF25-FD6ED6E8AA51}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A23C604E-04A3-41F8-BF25-FD6ED6E8AA51}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A23C604E-04A3-41F8-BF25-FD6ED6E8AA51}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A23C604E-04A3-41F8-BF25-FD6ED6E8AA51}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{8C39C5CD-A8D1-4528-9FCE-0190BD515466} = {6E5BF389-3D3F-4D74-9DD0-3B199CB529C5}
{A70EF69D-A519-4571-81BC-E066A1DAED27} = {9CAA231D-7BE1-46C9-ACD6-EB2E569CEBEA}
{A23C604E-04A3-41F8-BF25-FD6ED6E8AA51} = {9CAA231D-7BE1-46C9-ACD6-EB2E569CEBEA}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {1493AEE4-9211-46E9-BFE6-8F629EAC5693}
Expand Down
104 changes: 104 additions & 0 deletions src/libs/OpenAIGenerator/OpenAIGenerator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,109 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<PropertyGroup>
<GetTargetPathDependsOn>$(GetTargetPathDependsOn);AddGenerationTimeReferences</GetTargetPathDependsOn>
</PropertyGroup>

<!--
https://github.com/dotnet/roslyn/issues/52017#issuecomment-1046216200
This automatically adds explicit and transient dependencies so that they are available at the time the generator is executed.
-->
<Target Name="AddGenerationTimeReferences" DependsOnTargets="ResolveReferences">
<ItemGroup>
<_SystemLibs Include="Microsoft.CodeAnalysis" />
<_SystemLibs Include="Microsoft.CodeAnalysis.CSharp" />
<_SystemLibs Include="Microsoft.CodeAnalysis.CSharp.Workspaces" />
<_SystemLibs Include="Microsoft.CodeAnalysis.Workspaces" />
<_SystemLibs Include="System.Buffers" />
<_SystemLibs Include="System.Collections.Immutable" />
<_SystemLibs Include="System.Composition.AttributedModel" />
<_SystemLibs Include="System.Composition.Convention" />
<_SystemLibs Include="System.Composition.Hosting" />
<_SystemLibs Include="System.Composition.Runtime" />
<_SystemLibs Include="System.Composition.TypedParts" />
<_SystemLibs Include="System.IO.Pipelines" />
<_SystemLibs Include="System.Memory" />
<_SystemLibs Include="System.Numerics.Vectors" />
<_SystemLibs Include="System.Reflection.Metadata" />
<_SystemLibs Include="System.Runtime.CompilerServices.Unsafe" />
<_SystemLibs Include="System.Text.Encoding.CodePages" />
<_SystemLibs Include="System.Threading.Tasks.Extensions" />

<_SystemLibs Include="Microsoft.NETCore.Platforms" />
<_SystemLibs Include="Microsoft.Win32.Primitives" />
<_SystemLibs Include="System.AppContext" />
<_SystemLibs Include="System.Collections" />
<_SystemLibs Include="System.Collections.Concurrent" />
<_SystemLibs Include="System.Console" />
<_SystemLibs Include="System.Diagnostics.Debug" />
<_SystemLibs Include="System.Diagnostics.Tools" />
<_SystemLibs Include="System.Diagnostics.Tracing" />
<_SystemLibs Include="System.Globalization" />
<_SystemLibs Include="System.Globalization.Calendars" />
<_SystemLibs Include="System.IO" />
<_SystemLibs Include="System.IO.Compression" />
<_SystemLibs Include="System.IO.Compression.ZipFile" />
<_SystemLibs Include="System.IO.FileSystem" />
<_SystemLibs Include="System.IO.FileSystem.Primitives" />
<_SystemLibs Include="System.Linq" />
<_SystemLibs Include="System.Linq.Expressions" />
<_SystemLibs Include="System.Net.Http" />
<_SystemLibs Include="System.Net.Primitives" />
<_SystemLibs Include="System.Net.Sockets" />
<_SystemLibs Include="System.ObjectModel" />
<_SystemLibs Include="System.Reflection" />
<_SystemLibs Include="System.Reflection.Extensions" />
<_SystemLibs Include="System.Reflection.Primitives" />
<_SystemLibs Include="System.Resources.ResourceManager" />
<_SystemLibs Include="System.Runtime" />
<_SystemLibs Include="System.Runtime.Extensions" />
<_SystemLibs Include="System.Runtime.Handles" />
<_SystemLibs Include="System.Runtime.InteropServices" />
<_SystemLibs Include="System.Runtime.InteropServices.RuntimeInformation" />
<_SystemLibs Include="System.Runtime.Numerics" />
<_SystemLibs Include="System.Security.Cryptography.Algorithms" />
<_SystemLibs Include="System.Security.Cryptography.Encoding" />
<_SystemLibs Include="System.Security.Cryptography.Primitives" />
<_SystemLibs Include="System.Security.Cryptography.X509Certificates" />
<_SystemLibs Include="System.Text.Encoding" />
<_SystemLibs Include="System.Text.Encoding.Extensions" />
<_SystemLibs Include="System.Text.RegularExpressions" />
<_SystemLibs Include="System.Threading" />
<_SystemLibs Include="System.Threading.Tasks" />
<_SystemLibs Include="System.Threading.Timer" />
<_SystemLibs Include="System.Xml.ReaderWriter" />
<_SystemLibs Include="System.Xml.XDocument" />

<!-- Fix for Reference assemblies should not be loaded for execution. They can only be loaded in the Reflection-only loader context. (0x80131058)) -->
<_SystemLibs Include="System.Dynamic.Runtime" />

<!-- https://github.com/HavenDV/H.Generators.Extensions/issues/3 -->
<_SystemLibs Include="Microsoft.CSharp" />
<_SystemLibs Include="System.Runtime.Serialization.Primitives" />

<!-- https://discord.com/channels/988253265550532680/988253266393579583/1075854799821623346 -->
<_SystemLibs Include="System.ComponentModel" />
<_SystemLibs Include="System.Runtime.Serialization.Formatters" />
</ItemGroup>

<PropertyGroup>
<_SystemLibsProperty>@(_SystemLibs)</_SystemLibsProperty>
<_ResolvedCompileFileDefinitions>@(ResolvedCompileFileDefinitions)</_ResolvedCompileFileDefinitions>
</PropertyGroup>

<ItemGroup>
<ResolvedCompileFileDefinitionsWithoutSystem Include="%(ResolvedCompileFileDefinitions.Identity)" Condition="$(_SystemLibsProperty) != '' AND $(_ResolvedCompileFileDefinitions) != '' AND !$(_SystemLibsProperty.Contains(%(ResolvedCompileFileDefinitions.Filename)))" />
<ResolvedCompileFileDefinitionsWithoutSystemNonRef Include="@(ResolvedCompileFileDefinitionsWithoutSystem->Replace('\ref\', '\lib\')->Replace('/ref/', '/lib/'))" />
</ItemGroup>

<ItemGroup>
<None Include="@(ResolvedCompileFileDefinitionsWithoutSystemNonRef)" Pack="true" PackagePath="analyzers/dotnet/cs" />
<TargetPathWithTargetPlatformMoniker Include="@(ResolvedCompileFileDefinitionsWithoutSystemNonRef)" IncludeRuntimeDependency="false" />
</ItemGroup>

<Message Text="Added generation time reference: %(ResolvedCompileFileDefinitionsWithoutSystemNonRef.Identity)" Importance="high" Condition="$(_ResolvedCompileFileDefinitions) != ''"/>
</Target>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<OpenAIGenerator_ApiKey>$(OPENAI_API_KEY)</OpenAIGenerator_ApiKey>
</PropertyGroup>

<Import Project="../../libs/OpenAIGenerator/OpenAIGenerator.props" />

<ItemGroup Label="Base packages">
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="1.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" />
<PackageReference Include="FluentAssertions" Version="6.5.1" />
</ItemGroup>

<ItemGroup Label="GlobalUsings">
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" />
<Using Include="FluentAssertions" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\libs\OpenAIGenerator\OpenAIGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Write simple calculator class in C#. It should have 2 methods: Add and Multiply.
Both methods should take 2 arguments and return result.
You can use only + and * operators.
You can't use any other methods or classes.
14 changes: 14 additions & 0 deletions src/tests/OpenAIGenerator.IntegrationTests/Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace H.Ipc.Generator.IntegrationTests;

[TestClass]
public class NSwagGeneratorTests
{
[TestMethod]
public void GeneratesClientCorrectly()
{
var calculator = new Calculator();

calculator.Add(1, 1).Should().Be(2);
calculator.Multiply(1, 1).Should().Be(1);
}
}

0 comments on commit f14bb68

Please sign in to comment.