Skip to content

Commit

Permalink
Merge pull request #68 from skbkontur/add-net8-support
Browse files Browse the repository at this point in the history
Add NET8 support, fix various tests on non-Windows platforms
  • Loading branch information
fakefeik authored Jan 9, 2024
2 parents 0232730 + 629202a commit 237c802
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 34 deletions.
6 changes: 3 additions & 3 deletions AspNetCoreExample.Api/AspNetCoreExample.Api.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>latest</LangVersion>
Expand All @@ -13,8 +13,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.4" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>

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

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<OutputType>Exe</OutputType>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
Expand Down
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Nerdbank.GitVersioning" Version="3.6.128" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="Nerdbank.GitVersioning" Version="3.6.133" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<AssemblyName>SkbKontur.TypeScript.ContractGenerator.Cli</AssemblyName>
<RootNamespace>SkbKontur.TypeScript.ContractGenerator.Cli</RootNamespace>
<PackageId>SkbKontur.TypeScript.ContractGenerator.Cli</PackageId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.7.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.8.0" />
</ItemGroup>

</Project>
43 changes: 25 additions & 18 deletions TypeScript.ContractGenerator.Tests/CliTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ public class CliTest
[Test]
public void CliGenerated()
{
RunCmdCommand($"dotnet {pathToSlnDirectory}/TypeScript.ContractGenerator.Cli/bin/{configuration}/net7.0/SkbKontur.TypeScript.ContractGenerator.Cli.dll " +
$"-a {pathToSlnDirectory}/AspNetCoreExample.Api/bin/{configuration}/net7.0/AspNetCoreExample.Api.dll " +
$"-o {TestContext.CurrentContext.TestDirectory}/cliOutput " +
"--nullabilityMode NullableReference " +
"--lintMode TsLint");
RunDotnetCommand($"{pathToSlnDirectory}/TypeScript.ContractGenerator.Cli/bin/{configuration}/{targetFramework}/SkbKontur.TypeScript.ContractGenerator.Cli.dll " +
$"-a {pathToSlnDirectory}/AspNetCoreExample.Api/bin/{configuration}/{targetFramework}/AspNetCoreExample.Api.dll " +
$"-o {TestContext.CurrentContext.TestDirectory}/cliOutput " +
"--nullabilityMode NullableReference " +
"--lintMode TsLint");

var expectedDirectory = $"{pathToSlnDirectory}/AspNetCoreExample.Generator/output";
var actualDirectory = $"{TestContext.CurrentContext.TestDirectory}/cliOutput";
Expand All @@ -27,40 +27,47 @@ public void CliGenerated()
[Test]
public void RoslynCliGenerated()
{
RunCmdCommand($"dotnet {pathToSlnDirectory}/TypeScript.ContractGenerator.Cli/bin/{configuration}/net7.0/SkbKontur.TypeScript.ContractGenerator.Cli.dll " +
$"-d {pathToSlnDirectory}/AspNetCoreExample.Api " +
$"-a {typeof(ControllerBase).Assembly.Location} " +
$"-o {TestContext.CurrentContext.TestDirectory}/roslynCliOutput " +
"--nullabilityMode NullableReference " +
"--lintMode TsLint");
RunDotnetCommand($"{pathToSlnDirectory}/TypeScript.ContractGenerator.Cli/bin/{configuration}/{targetFramework}/SkbKontur.TypeScript.ContractGenerator.Cli.dll " +
$"-d {pathToSlnDirectory}/AspNetCoreExample.Api " +
$"-a {typeof(ControllerBase).Assembly.Location} " +
$"-o {TestContext.CurrentContext.TestDirectory}/roslynCliOutput " +
"--nullabilityMode NullableReference " +
"--lintMode TsLint");

var expectedDirectory = $"{pathToSlnDirectory}/AspNetCoreExample.Generator/output";
var actualDirectory = $"{TestContext.CurrentContext.TestDirectory}/roslynCliOutput";
TestBase.CheckDirectoriesEquivalenceInner(expectedDirectory, actualDirectory, generatedOnly : true);
}

private static void RunCmdCommand(string command)
private static void RunDotnetCommand(string command)
{
var process = new Process
{
StartInfo =
StartInfo = new ProcessStartInfo("dotnet", command)
{
FileName = "cmd.exe",
WindowStyle = ProcessWindowStyle.Hidden,
Arguments = "/C " + command,
}
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false
},
};

process.Start();
process.WaitForExit();

process.ExitCode.Should().Be(0);
process.StandardOutput.ReadToEnd().Trim().Should().Be("Generating TypeScript");
process.StandardError.ReadToEnd().Trim().Should().BeEmpty();
}

private static readonly string pathToSlnDirectory = $"{TestContext.CurrentContext.TestDirectory}/../../../../";

private const string targetFramework = "net8.0";

#if RELEASE
const string configuration = "Release";
private const string configuration = "Release";
#elif DEBUG
const string configuration = "Debug";
private const string configuration = "Debug";
#endif
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.IO;

using SkbKontur.TypeScript.ContractGenerator.Abstractions;
using SkbKontur.TypeScript.ContractGenerator.CodeDom;
using SkbKontur.TypeScript.ContractGenerator.TypeBuilders;
Expand All @@ -8,7 +10,7 @@ public class SimpleStructureTypeLocator : ICustomTypeGenerator
{
public string GetTypeLocation(ITypeInfo type)
{
return $"{type.Name}\\{type.Name}";
return $"{type.Name}{Path.DirectorySeparatorChar}{type.Name}";
}

public ITypeBuildingContext? ResolveType(string initialUnitPath, ITypeGenerator typeGenerator, ITypeInfo type, ITypeScriptUnitFactory unitFactory)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net48;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net48;net6.0;net8.0</TargetFrameworks>
<AssemblyName>SkbKontur.TypeScript.ContractGenerator.Tests</AssemblyName>
<RootNamespace>SkbKontur.TypeScript.ContractGenerator.Tests</RootNamespace>
</PropertyGroup>
Expand All @@ -11,12 +11,12 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="DiffPlex" Version="1.7.1" />
<PackageReference Include="FluentAssertions" Version="6.11.0" />
<PackageReference Include="DiffPlex" Version="1.7.2" />
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.1.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.4.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "7.0.0",
"version": "8.0.0",
"rollForward": "latestFeature"
}
}

0 comments on commit 237c802

Please sign in to comment.