Skip to content

Commit

Permalink
fix: runtime testing (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaslagoni authored Sep 26, 2024
1 parent aeb7955 commit 7589718
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/runtime-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ jobs:
- name: Setup dotnet
uses: actions/setup-dotnet@v1
with:
dotnet-version: '6.0.x'
dotnet-version: '8.*.*'
- name: Generate C# models
run: npm run runtime:csharp:setup
- name: Run runtime tests
Expand Down
11 changes: 6 additions & 5 deletions examples/csharp-console/csharp-console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@
<RootNamespace>csharp_console</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.Text.Json" Version="8.0.4" />
<Compile Include="tests\*.cs" />
<Compile Include="__gen__\**\*.cs" />
</ItemGroup>

<ItemGroup>
<Folder Include="__gen__\payloads\" />
<PackageReference Include="System.Text.Json" Version="8.0.4" />
</ItemGroup>


<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Target Name="Generate" BeforeTargets="BeforeBuild">
<Message Text="Generating code" />
<Exec Command="node ../../bin/run.mjs generate" />
</Target>

</Project>
2 changes: 1 addition & 1 deletion examples/typescript-library/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
"@the-codegen-project/cli": "^0",
"ts-node": "10.9.2"
}
}
}
4 changes: 2 additions & 2 deletions test/runtime/csharp/codegen.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
"outputPath": "__gen__/payloads/newtonsoft",
"serializationType": "json",
"serializationLibrary": "newtonsoft",
"namespace": "The.Codegen.Project.Newtonsoft",
"namespace": "csharp.__gen__.payloads.newtonsoft",
"id": "payloads-csharp-newtonsoft"
},
{
"preset": "payloads",
"outputPath": "__gen__/payloads/json",
"serializationType": "json",
"serializationLibrary": "json",
"namespace": "The.Codegen.Project.Json",
"namespace": "csharp.__gen__.payloads.json",
"id": "payloads-csharp-json"
}
]
Expand Down
20 changes: 18 additions & 2 deletions test/runtime/csharp/csharp.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<OutputType>Library</OutputType>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>

</PropertyGroup>

<ItemGroup>
Expand All @@ -18,13 +21,26 @@
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="System.Text.Json" Version="8.0.4" />
</ItemGroup>
<ItemGroup>
<Content Include="Resources\*.*">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<Compile Include="tests\*.cs" />
<Compile Include="__gen__\**\*.cs" />
</ItemGroup>

<ItemGroup>
<Using Include="NUnit.Framework" />
</ItemGroup>


<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Target Name="Generate" BeforeTargets="BeforeBuild">
<Message Text="Generating support code" />
<Exec Command="node ../../../bin/run.mjs generate" />
<ItemGroup>
<Compile Include="__gen__\**\*.cs" />
</ItemGroup>
</Target>
</Project>
19 changes: 9 additions & 10 deletions test/runtime/csharp/tests/payloads.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Text.Json;
using The.Codegen.Project;

namespace csharp.tests;

Expand All @@ -8,7 +7,7 @@ public class PayloadTestingJson
[Test]
public void ShouldBeSerializableModel()
{
var model = new The.Codegen.Project.Json.UserSignedUpPayload
var model = new __gen__.payloads.json.UserSignedUpPayload
{
DisplayName = "displayNameTest",
Email = "emailTest"
Expand All @@ -21,23 +20,23 @@ public void ShouldBeSerializableModel()
public void ShouldBeDeserializeToModel()
{
var json = "{\"display_name\":\"displayNameTest\",\"email\":\"emailTest\"}";
var model = The.Codegen.Project.Json.UserSignedUpPayload.Deserialize(json);
var model = __gen__.payloads.json.UserSignedUpPayload.Deserialize(json);
Assert.That("displayNameTest", Is.EqualTo(model.DisplayName));
Assert.That("emailTest", Is.EqualTo(model.Email));
}
[Test]
public void ShouldBeSerializableModelInRoundtrip()
{
var model = new The.Codegen.Project.Json.UserSignedUpPayload
var model = new __gen__.payloads.json.UserSignedUpPayload
{
DisplayName = "displayNameTest",
Email = "emailTest"
};
var json = JsonSerializer.Serialize(model);

var deserializeOptions = new JsonSerializerOptions();
deserializeOptions.Converters.Add(new The.Codegen.Project.Json.UserSignedUpPayloadConverter());
var newModel = JsonSerializer.Deserialize<The.Codegen.Project.Json.UserSignedUpPayload>(json, deserializeOptions);
deserializeOptions.Converters.Add(new __gen__.payloads.json.UserSignedUpPayloadConverter());
var newModel = JsonSerializer.Deserialize<__gen__.payloads.json.UserSignedUpPayload>(json, deserializeOptions);
var newJson = JsonSerializer.Serialize(newModel);
Assert.That(newJson, Is.EqualTo(json));
}
Expand All @@ -48,7 +47,7 @@ public class PayloadTestingNewtonsoft
[Test]
public void ShouldBeSerializableModel()
{
var model = new The.Codegen.Project.Newtonsoft.UserSignedUpPayload
var model = new __gen__.payloads.newtonsoft.UserSignedUpPayload
{
DisplayName = "displayNameTest",
Email = "emailTest"
Expand All @@ -61,20 +60,20 @@ public void ShouldBeSerializableModel()
public void ShouldBeDeserializeToModel()
{
var json = "{\"display_name\":\"displayNameTest\",\"email\":\"emailTest\"}";
var model = The.Codegen.Project.Newtonsoft.UserSignedUpPayload.Deserialize(json);
var model = __gen__.payloads.newtonsoft.UserSignedUpPayload.Deserialize(json);
Assert.That("displayNameTest", Is.EqualTo(model.DisplayName));
Assert.That("emailTest", Is.EqualTo(model.Email));
}
[Test]
public void ShouldBeSerializableModelInRoundtrip()
{
var model = new The.Codegen.Project.Newtonsoft.UserSignedUpPayload
var model = new __gen__.payloads.newtonsoft.UserSignedUpPayload
{
DisplayName = "displayNameTest",
Email = "emailTest"
};
var json = model.Serialize();
var newModel = The.Codegen.Project.Newtonsoft.UserSignedUpPayload.Deserialize(json);
var newModel = __gen__.payloads.newtonsoft.UserSignedUpPayload.Deserialize(json);
var newJson = newModel.Serialize();
Assert.That(newJson, Is.EqualTo(json));
}
Expand Down

0 comments on commit 7589718

Please sign in to comment.