diff --git a/.gitignore b/.gitignore index e641539a..63d89bf5 100644 --- a/.gitignore +++ b/.gitignore @@ -262,3 +262,5 @@ paket-files/ /src/TypeGen/TypeGen.Cli/NuGet.config /src/TypeGen/TypeGen.Core/TypeGen.Core.xml generated-typescript +/src/TypeGen/TypeGen.Core.Test/foo.ts +/src/TypeGen/TypeGen.Core.Test/tgconfig.json diff --git a/appveyor.yml b/appveyor.yml index cf112260..b4ecbaac 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -16,7 +16,7 @@ before_build: - dotnet restore src/TypeGen/TypeGen.Core - dotnet restore src/TypeGen/TypeGen.Cli.Test - dotnet restore src/TypeGen/TypeGen.Core.Test - - dotnet restore src/TypeGen/TypeGen.IntegrationTest + - dotnet restore src/TypeGen/TypeGen.FileContentTest build: project: src/TypeGen/TypeGen.sln diff --git a/nuget-dotnetcli/dotnet-typegen.nuspec b/nuget-dotnetcli/dotnet-typegen.nuspec index 2e11b146..b11faf93 100644 --- a/nuget-dotnetcli/dotnet-typegen.nuspec +++ b/nuget-dotnetcli/dotnet-typegen.nuspec @@ -2,7 +2,7 @@ dotnet-typegen - 4.4.1 + 4.5.0 Jacek Burzynski Jacek Burzynski LICENSE @@ -11,7 +11,9 @@ false TypeGen .NET Core CLI tool (TypeGen is a single-class-per-file C# to TypeScript generator) -- fixed exportTypesAsInterfacesByDefault and useImportType not working in tgconfig.json +- added the ability to blacklist/whitelist individual types (this also fixes records not generating correctly #164) +- TS class : TS interface inheritance is now possible - in this case TS class implements TS interface +- added the ability to specify custom header and body as an attribute or spec #166 #167 code-generator generator code typescript ts csharp cs dotnet cli diff --git a/nuget/TypeGen.nuspec b/nuget/TypeGen.nuspec index 00f0935c..f95110de 100644 --- a/nuget/TypeGen.nuspec +++ b/nuget/TypeGen.nuspec @@ -2,7 +2,7 @@ TypeGen - 4.4.1 + 4.5.0 Jacek Burzynski Jacek Burzynski LICENSE @@ -11,7 +11,9 @@ false TypeGen is a single-class-per-file C# to TypeScript generator -- fixed exportTypesAsInterfacesByDefault and useImportType not working in tgconfig.json +- added the ability to blacklist/whitelist individual types (this also fixes records not generating correctly #164) +- TS class : TS interface inheritance is now possible - in this case TS class implements TS interface +- added the ability to specify custom header and body as an attribute or spec #166 #167 code-generator generator code typescript ts csharp cs diff --git a/src/TypeGen/TypeGen.Cli.Test/ApplicationTest.cs b/src/TypeGen/TypeGen.Cli.Test/ApplicationTest.cs new file mode 100644 index 00000000..ea152c8a --- /dev/null +++ b/src/TypeGen/TypeGen.Cli.Test/ApplicationTest.cs @@ -0,0 +1,44 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using NSubstitute; +using TypeGen.Cli.Ui; +using TypeGen.Core.Logging; +using Xunit; + +namespace TypeGen.Cli.Test; + +public class ApplicationTest +{ + [Fact] + public async Task Run_CommandIsGetCwd_CorrectPresenterMethodCalled() + { + // arrange + var args = new[] { "getcwd" }; + var logger = Substitute.For(); + var presenter = Substitute.For(); + var sut = new Application(logger, presenter); + + // act + await sut.Run(args); + + // assert + presenter.Received(1).GetCwd(); + } + + [Fact] + public async Task Run_CommandIsGenerate_CorrectPresenterMethodCalled() + { + // arrange + var args = new[] { "generate" }; + var logger = Substitute.For(); + var presenter = Substitute.For(); + var sut = new Application(logger, presenter); + + // act + await sut.Run(args); + + // assert + presenter.Received(1).Generate(Arg.Any(), Arg.Any>(), + Arg.Any>(), Arg.Any()); + } +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.Cli.Test/Business/ConsoleArgsReaderTest.cs b/src/TypeGen/TypeGen.Cli.Test/Business/ConsoleArgsReaderTest.cs deleted file mode 100644 index a110984d..00000000 --- a/src/TypeGen/TypeGen.Cli.Test/Business/ConsoleArgsReaderTest.cs +++ /dev/null @@ -1,234 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using TypeGen.Cli.Business; -using Xunit; - -namespace TypeGen.Cli.Test.Business -{ - public class ConsoleArgsReaderTest - { - private readonly IConsoleArgsReader _consoleArgsReader = new ConsoleArgsReader(); - - [Theory] - [MemberData(nameof(ContainsGetCwdCommand_TestData))] - public void ContainsGetCwdCommand_Test(string[] args, bool expectedResult) - { - bool actualResult = _consoleArgsReader.ContainsGetCwdCommand(args); - Assert.Equal(expectedResult, actualResult); - } - - public static IEnumerable ContainsGetCwdCommand_TestData = new[] - { - new object[] { new[] { "asdf", "getcwd", "d" }, true }, - new object[] { new[] { "asdf", "GETCWD", "d" }, true }, - new object[] { new[] { "asdf", "GeTCwD", "d" }, true }, - new object[] { new[] { "getcwd" }, true }, - new object[] { new[] { "asdf", "d" }, false }, - new object[] { new string[] {}, false } - }; - - [Theory] - [MemberData(nameof(ContainsGenerateCommand_TestData))] - public void ContainsGenerateCommand_Test(string[] args, bool expectedResult) - { - bool actualResult = _consoleArgsReader.ContainsGenerateCommand(args); - Assert.Equal(expectedResult, actualResult); - } - - public static IEnumerable ContainsGenerateCommand_TestData = new[] - { - new object[] { new[] { "asdf", "generate", "d" }, true }, - new object[] { new[] { "asdf", "GENERATE", "d" }, true }, - new object[] { new[] { "asdf", "GeNeRAtE", "d" }, true }, - new object[] { new[] { "generate" }, true }, - new object[] { new[] { "asdf", "d" }, false }, - new object[] { new string[] {}, false } - }; - - [Theory] - [MemberData(nameof(ContainsAnyCommand_TestData))] - public void ContainsAnyCommand_Test(string[] args, bool expectedResult) - { - bool actualResult = _consoleArgsReader.ContainsAnyCommand(args); - Assert.Equal(expectedResult, actualResult); - } - - public static IEnumerable ContainsAnyCommand_TestData = new[] - { - new object[] { new[] { "asdf", "generate", "d" }, true }, - new object[] { new[] { "asdf", "GetCWD", "d" }, true }, - new object[] { new[] { "asdf", "GeNeRAtE", "gETcwd" }, true }, - new object[] { new[] { "generate" }, true }, - new object[] { new[] { "generatea" }, false }, - new object[] { new[] { "getcwd" }, true }, - new object[] { new[] { "agetcwd" }, false }, - new object[] { new[] { "agenerate" }, false }, - new object[] { new[] { "getcwda" }, false }, - new object[] { new[] { "-getcwd" }, false }, - new object[] { new[] { "-generate" }, false }, - new object[] { new[] { "asdf", "d" }, false }, - new object[] { new string[] {}, false } - }; - - [Theory] - [MemberData(nameof(ContainsHelpOption_TestData))] - public void ContainsHelpOption_Test(string[] args, bool expectedResult) - { - bool actualResult = _consoleArgsReader.ContainsHelpOption(args); - Assert.Equal(expectedResult, actualResult); - } - - public static IEnumerable ContainsHelpOption_TestData = new[] - { - new object[] { new[] { "asdf", "-h", "d" }, true }, - new object[] { new[] { "asdf", "--help", "d" }, true }, - new object[] { new[] { "asdf", "-H", "d" }, true }, - new object[] { new[] { "asdf", "--HELP", "d" }, true }, - new object[] { new[] { "asdf", "--HeLp", "d" }, true }, - new object[] { new[] { "-h" }, true }, - new object[] { new[] { "--help" }, true }, - new object[] { new[] { "asdf", "d" }, false }, - new object[] { new string[] {}, false } - }; - - [Theory] - [MemberData(nameof(ContainsProjectFolderOption_TestData))] - public void ContainsProjectFolderOption_Test(string[] args, bool expectedResult) - { - bool actualResult = _consoleArgsReader.ContainsProjectFolderOption(args); - Assert.Equal(expectedResult, actualResult); - } - - public static IEnumerable ContainsProjectFolderOption_TestData = new[] - { - new object[] { new[] { "asdf", "-p", "d" }, true }, - new object[] { new[] { "asdf", "--project-folder", "d" }, true }, - new object[] { new[] { "asdf", "-P", "d" }, true }, - new object[] { new[] { "asdf", "--PROJECT-FOLDER", "d" }, true }, - new object[] { new[] { "asdf", "--PrOjECt-FoldER", "d" }, true }, - new object[] { new[] { "-p" }, true }, - new object[] { new[] { "--project-folder" }, true }, - new object[] { new[] { "asdf", "d" }, false }, - new object[] { new string[] {}, false } - }; - - [Theory] - [MemberData(nameof(ContainsOutputFolderOption_TestData))] - public void ContainsOutputFolderOption_Test(string[] args, bool expectedResult) - { - bool actualResult = _consoleArgsReader.ContainsOutputOption(args); - Assert.Equal(expectedResult, actualResult); - } - - public static IEnumerable ContainsOutputFolderOption_TestData = new[] - { - new object[] { new[] { "asdf", "-o", "d" }, true }, - new object[] { new[] { "asdf", "--output-folder", "d" }, true }, - new object[] { new[] { "asdf", "-O", "d" }, true }, - new object[] { new[] { "asdf", "--OUTPUT-FOLDER", "d" }, true }, - new object[] { new[] { "asdf", "--OuTpUt-FoldER", "d" }, true }, - new object[] { new[] { "-o" }, true }, - new object[] { new[] { "--output-folder" }, true }, - new object[] { new[] { "asdf", "d" }, false }, - new object[] { new string[] {}, false } - }; - - [Theory] - [MemberData(nameof(ContainsVerboseOption_TestData))] - public void ContainsVerboseOption_Test(string[] args, bool expectedResult) - { - bool actualResult = _consoleArgsReader.ContainsVerboseOption(args); - Assert.Equal(expectedResult, actualResult); - } - - public static IEnumerable ContainsVerboseOption_TestData = new[] - { - new object[] { new[] { "asdf", "-v", "d" }, true }, - new object[] { new[] { "asdf", "--verbose", "d" }, true }, - new object[] { new[] { "asdf", "-V", "d" }, true }, - new object[] { new[] { "asdf", "--VERBOSE", "d" }, true }, - new object[] { new[] { "asdf", "--VeRbOSE", "d" }, true }, - new object[] { new[] { "-v" }, true }, - new object[] { new[] { "--verbose" }, true }, - new object[] { new[] { "asdf", "d" }, false }, - new object[] { new string[] {}, false } - }; - - [Theory] - [MemberData(nameof(GetProjectFolders_TestData))] - public void GetProjectFolders_Test(string[] args, IEnumerable expectedResult) - { - IEnumerable actualResult = _consoleArgsReader.GetProjectFolders(args); - Assert.Equal(expectedResult, actualResult); - } - - public static IEnumerable GetProjectFolders_TestData = new[] - { - new object[] { new[] { "-p", "asdf", "project/folder" }, new [] { "asdf" } }, - new object[] { new[] { "--project-folder", "asdf", @"C:\project\folder" }, new [] { "asdf" } }, - new object[] { new[] { "-p", "asdf|qwer", "--config-path", "zxcv" }, new [] { "asdf", "qwer" } }, - new object[] { new[] { "--project-folder", @"D:\my\folder|some/other/folder|that/folder", "--config-path", "zxcv|qwer" }, new [] { @"D:\my\folder", "some/other/folder", "that/folder" } }, - new object[] { new[] { "asdf" }, new string[] {} }, - new object[] { new string[] {}, new string[] {} } - }; - - [Fact] - public void GetProjectFolders_ParameterPresentAndNoPathsSpecified_ExceptionThrown() - { - var args = new[] { "--project-folder" }; - Assert.Throws(() => _consoleArgsReader.GetProjectFolders(args)); - } - - [Theory] - [MemberData(nameof(GetOutputFolder_TestData))] - public void GetOutputFolder_Test(string[] args, string expectedResult) - { - string actualResult = _consoleArgsReader.GetOutputFolder(args); - Assert.Equal(expectedResult, actualResult); - } - - public static IEnumerable GetOutputFolder_TestData = new[] - { - new object[] { new[] { "-o", "asdf", "project/folder" }, "asdf" }, - new object[] { new[] { "--output-folder", "asdf", @"C:\project\folder" }, "asdf" }, - new object[] { new[] { "-o", "asdf|qwer", "--config-path", "zxcv" }, "asdf" }, - new object[] { new[] { "--output-folder", @"D:\my\folder|some/other/folder|that/folder", "--config-path", "zxcv|qwer" }, @"D:\my\folder" }, - new object[] { new[] { "asdf" }, null }, - new object[] { new string[] {}, null } - }; - - [Fact] - public void GetOutputFolder_ParameterPresentAndNoPathsSpecified_ExceptionThrown() - { - var args = new[] { "--output-folder" }; - Assert.Throws(() => _consoleArgsReader.GetOutputFolder(args)); - } - - [Theory] - [MemberData(nameof(GetConfigPaths_TestData))] - public void GetConfigPaths_Test(string[] args, IEnumerable expectedResult) - { - IEnumerable actualResult = _consoleArgsReader.GetConfigPaths(args); - Assert.Equal(expectedResult, actualResult); - } - - public static IEnumerable GetConfigPaths_TestData = new[] - { - new object[] { new[] { "asdf", "-c", "zxcv" }, new [] { "zxcv" } }, - new object[] { new[] { "asdf", "--config-path", "zxcv" }, new [] { "zxcv" } }, - new object[] { new[] { "asdf", "-c", "zxcv", "qwer" }, new [] { "zxcv" } }, - new object[] { new[] { "asdf", "--config-path", "zxcv|qwer" }, new [] { "zxcv", "qwer" } }, - new object[] { new[] { "asdf", "-c", @"my\path|C:\Program Files\path" }, new [] { @"my\path", @"C:\Program Files\path" } }, - new object[] { new[] { "asdf", "--config-path", @"my\path|C:\Program Files\path|other/path" }, new [] { @"my\path", @"C:\Program Files\path", "other/path" } }, - new object[] { new[] { "asdf" }, new string[] {} }, - new object[] { new string[] {}, new string[] {} } - }; - - [Fact] - public void GetConfigPaths_ParameterPresentAndNoPathsSpecified_ExceptionThrown() - { - var args = new[] { "--config-path" }; - Assert.Throws(() => _consoleArgsReader.GetConfigPaths(args)); - } - } -} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.IntegrationTest/CliSmokeTest.cs b/src/TypeGen/TypeGen.Cli.Test/CliSmokeTest.cs similarity index 97% rename from src/TypeGen/TypeGen.IntegrationTest/CliSmokeTest.cs rename to src/TypeGen/TypeGen.Cli.Test/CliSmokeTest.cs index 25f03f73..27fb6268 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CliSmokeTest.cs +++ b/src/TypeGen/TypeGen.Cli.Test/CliSmokeTest.cs @@ -7,7 +7,7 @@ using FluentAssertions; using Xunit; -namespace TypeGen.IntegrationTest +namespace TypeGen.Cli.Test { public class CliSmokeTest { @@ -16,7 +16,7 @@ public void Cli_should_finish_with_success() { // arrange - const string projectToGeneratePath = "../../../../TypeGen.IntegrationTest"; + const string projectToGeneratePath = "../../../../TypeGen.FileContentTest"; const string cliFileName = "TypeGen.Cli.exe"; string[] cliPossibleDirectories = { "../../../../TypeGen.Cli/bin/Debug/net7.0", diff --git a/src/TypeGen/TypeGen.Cli.Test/GenerationConfig/GeneratorOptionsProviderTest.cs b/src/TypeGen/TypeGen.Cli.Test/GenerationConfig/GeneratorOptionsProviderTest.cs new file mode 100644 index 00000000..92c6290d --- /dev/null +++ b/src/TypeGen/TypeGen.Cli.Test/GenerationConfig/GeneratorOptionsProviderTest.cs @@ -0,0 +1,71 @@ +using System; +using System.Linq; +using System.Reflection; +using FluentAssertions; +using NSubstitute; +using TypeGen.Cli.GenerationConfig; +using TypeGen.Cli.TypeResolution; +using TypeGen.Core.Generator; +using Xunit; + +namespace TypeGen.Cli.Test.GenerationConfig; + +public class GeneratorOptionsProviderTest +{ + [Fact] + public void GetGeneratorOptions_Should_ConcatenateBlacklists() + { + // arrange + const string projectFolder = "test"; + var tgConfigBlacklist = new[] { "MyType" }; + var tgConfig = GetDefaultTgConfigWithoutConverters(); + tgConfig.TypeBlacklist = tgConfigBlacklist; + var expected = GeneratorOptions.DefaultTypeBlacklist.Concat(tgConfigBlacklist); + + var converterResolver = Substitute.For(); + var sut = new GeneratorOptionsProvider(converterResolver); + + // act + var actual = sut.GetGeneratorOptions(tgConfig, Enumerable.Empty(), projectFolder) + .TypeBlacklist; + + // assert + actual.Should().BeEquivalentTo(expected); + } + + [Fact] + public void GetGeneratorOptions_WhitelistGiven_WhitelistRemovesTypesFromBlacklist() + { + // arrange + const string projectFolder = "test"; + var tgConfigBlacklist = new[] { "MyType" }; + var tgConfigWhitelist = new[] { typeof(IConvertible).FullName }; + var tgConfig = GetDefaultTgConfigWithoutConverters(); + tgConfig.TypeBlacklist = tgConfigBlacklist; + tgConfig.TypeWhitelist = tgConfigWhitelist; + var expected = GeneratorOptions.DefaultTypeBlacklist.Concat(tgConfigBlacklist).Except(tgConfigWhitelist); + + var converterResolver = Substitute.For(); + var sut = new GeneratorOptionsProvider(converterResolver); + + // act + var actual = sut.GetGeneratorOptions(tgConfig, Enumerable.Empty(), projectFolder) + .TypeBlacklist; + + // assert + actual.Should().BeEquivalentTo(expected); + } + + private static TgConfig GetDefaultTgConfigWithoutConverters() + { + var tgConfig = new TgConfig(); + tgConfig.MergeWithDefaultParams(); + tgConfig.FileNameConverters = Array.Empty(); + tgConfig.PropertyNameConverters = Array.Empty(); + tgConfig.TypeNameConverters = Array.Empty(); + tgConfig.EnumStringInitializersConverters = Array.Empty(); + tgConfig.EnumValueNameConverters = Array.Empty(); + + return tgConfig; + } +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.Cli.Test/Models/TgConfigTest.cs b/src/TypeGen/TypeGen.Cli.Test/GenerationConfig/TgConfigTest.cs similarity index 58% rename from src/TypeGen/TypeGen.Cli.Test/Models/TgConfigTest.cs rename to src/TypeGen/TypeGen.Cli.Test/GenerationConfig/TgConfigTest.cs index 1c7d2487..2bcf7f5c 100644 --- a/src/TypeGen/TypeGen.Cli.Test/Models/TgConfigTest.cs +++ b/src/TypeGen/TypeGen.Cli.Test/GenerationConfig/TgConfigTest.cs @@ -1,11 +1,8 @@ -using System.Linq; -using TypeGen.Cli.Models; -using TypeGen.Core; +using FluentAssertions; +using TypeGen.Cli.GenerationConfig; using Xunit; -using TypeGen.Cli.Extensions; -using TypeGen.Core.Extensions; -namespace TypeGen.Cli.Test.Models +namespace TypeGen.Cli.Test.GenerationConfig { public class TgConfigTest { @@ -26,20 +23,22 @@ public void MergeWithDefaultParams_ParametersNull_DefaultValuesAssignedToParamet var tgConfig = new TgConfig(); tgConfig.MergeWithDefaultParams(); - Assert.Equal(new string[0], tgConfig.Assemblies); - Assert.False(tgConfig.ExplicitPublicAccessor); - Assert.False(tgConfig.SingleQuotes); - Assert.False(tgConfig.AddFilesToProject); - Assert.Equal("ts", tgConfig.TypeScriptFileExtension); - Assert.Equal(4, tgConfig.TabLength); - Assert.Equal(new [] { "PascalCaseToKebabCaseConverter" }, tgConfig.FileNameConverters); - Assert.Equal(new string[0], tgConfig.TypeNameConverters); - Assert.Equal(new[] { "PascalCaseToCamelCaseConverter" }, tgConfig.PropertyNameConverters); - Assert.Equal(new string[0], tgConfig.EnumValueNameConverters); - Assert.Equal(new string[0], tgConfig.ExternalAssemblyPaths); - Assert.False(tgConfig.CreateIndexFile); - Assert.Equal("", tgConfig.CsNullableTranslation); - Assert.Equal("", tgConfig.OutputPath); + tgConfig.Assemblies.Should().BeEmpty(); + tgConfig.ExplicitPublicAccessor.Should().BeFalse(); + tgConfig.SingleQuotes.Should().BeFalse(); + tgConfig.AddFilesToProject.Should().BeFalse(); + tgConfig.TypeScriptFileExtension.Should().Be("ts"); + tgConfig.TabLength.Should().Be(4); + tgConfig.FileNameConverters.Should().BeEquivalentTo("PascalCaseToKebabCaseConverter"); + tgConfig.TypeNameConverters.Should().BeEmpty(); + tgConfig.PropertyNameConverters.Should().BeEquivalentTo("PascalCaseToCamelCaseConverter"); + tgConfig.EnumValueNameConverters.Should().BeEmpty(); + tgConfig.ExternalAssemblyPaths.Should().BeEmpty(); + tgConfig.CreateIndexFile.Should().BeFalse(); + tgConfig.CsNullableTranslation.Should().BeEmpty(); + tgConfig.OutputPath.Should().BeEmpty(); + tgConfig.TypeBlacklist.Should().BeEmpty(); + tgConfig.TypeWhitelist.Should().BeEmpty(); } [Fact] diff --git a/src/TypeGen/TypeGen.Cli/AppConfig.cs b/src/TypeGen/TypeGen.Cli/AppConfig.cs deleted file mode 100644 index a67eb3c6..00000000 --- a/src/TypeGen/TypeGen.Cli/AppConfig.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace TypeGen.Cli -{ - internal class AppConfig - { - public static string Version => "4.4.1"; - } -} diff --git a/src/TypeGen/TypeGen.Cli/Application.cs b/src/TypeGen/TypeGen.Cli/Application.cs new file mode 100644 index 00000000..0c97735e --- /dev/null +++ b/src/TypeGen/TypeGen.Cli/Application.cs @@ -0,0 +1,129 @@ +using System; +using System.Collections.Generic; +using System.CommandLine; +using System.CommandLine.Builder; +using System.CommandLine.Help; +using System.CommandLine.Invocation; +using System.CommandLine.Parsing; +using System.Linq; +using System.Reflection; +using System.Threading.Tasks; +using TypeGen.Cli.Ui; +using TypeGen.Core; +using TypeGen.Core.Logging; + +namespace TypeGen.Cli; + +internal class Application : IApplication +{ + private readonly ILogger _logger; + private readonly IPresenter _presenter; + + private ExitCode _exitCode = ExitCode.Success; + + public Application(ILogger logger, IPresenter presenter) + { + _logger = logger; + _presenter = presenter; + } + + public async Task Run(string[] args) + { + try + { + var parser = BuildCommandLine(); + await parser.InvokeAsync(args); + return _exitCode; + } + catch (AssemblyResolutionException e) + { + var message = e.Message + + "Consider adding any external assembly directories in the externalAssemblyPaths parameter. " + + "If you're using ASP.NET Core, add your NuGet directory to externalAssemblyPaths parameter (you can use global NuGet packages directory alias: \"\")"; + _logger.Log($"{message}{Environment.NewLine}{e.StackTrace}", LogLevel.Error); + return ExitCode.Error; + } + catch (ReflectionTypeLoadException e) + { + foreach (var loaderException in e.LoaderExceptions) + { + _logger.Log($"Type load error: {loaderException.Message}{Environment.NewLine}{e.StackTrace}", LogLevel.Error); + } + return ExitCode.Error; + } + catch (Exception e) + { + _logger.Log($"{e.Message}{Environment.NewLine}{e.StackTrace}", LogLevel.Error); + return ExitCode.Error; + } + } + + private Parser BuildCommandLine() + { + var rootCommand = new RootCommand + { + Name = "[dotnet-]typegen" + }; + + var generateCommand = new Command("generate", "Generate TypeScript sources"); + + var verboseOption = new Option + (name: "--verbose", + description: "Show verbose output", + getDefaultValue: () => false); + verboseOption.AddAlias("-v"); + + var projectFolderOption = new Option> + (name: "--project-folder", + description: "The project folder path(s)"); + projectFolderOption.AddAlias("-p"); + + var configPathOption = new Option> + (name: "--config-path", + description: "The config file path(s)"); + configPathOption.AddAlias("-c"); + + var outputFolderOption = new Option + (name: "--output-folder", + description: "Project's output folder"); + configPathOption.AddAlias("-o"); + + generateCommand.AddOption(verboseOption); + generateCommand.AddOption(projectFolderOption); + generateCommand.AddOption(configPathOption); + generateCommand.AddOption(outputFolderOption); + + generateCommand.SetHandler((v, p, c, o) => + { + _exitCode = ExitCodeFromActionResult(_presenter.Generate(v, p, c, o)); + }, + verboseOption, + projectFolderOption, + configPathOption, + outputFolderOption); + + var getCwdCommand = new Command("getcwd", "Get current working directory"); + getCwdCommand.SetHandler(() => + { + _exitCode = ExitCodeFromActionResult(_presenter.GetCwd()); + }); + + rootCommand.AddCommand(generateCommand); + rootCommand.AddCommand(getCwdCommand); + + return new CommandLineBuilder(rootCommand) + .UseDefaults() + .UseHelp(ctx => ctx.HelpBuilder.CustomizeLayout( + _ => HelpBuilder.Default + .GetLayout() + .Skip(1) + .Prepend(_ => + { + Console.WriteLine($"TypeGen v{ApplicationConfig.Version}"); + }))) + .Build(); + } + + private static ExitCode ExitCodeFromActionResult(ActionResult actionResult) => + actionResult.IsSuccess ? ExitCode.Success : ExitCode.Error; +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.Cli/ApplicationConfig.cs b/src/TypeGen/TypeGen.Cli/ApplicationConfig.cs new file mode 100644 index 00000000..ed529414 --- /dev/null +++ b/src/TypeGen/TypeGen.Cli/ApplicationConfig.cs @@ -0,0 +1,6 @@ +namespace TypeGen.Cli; + +internal class ApplicationConfig +{ + public const string Version = "4.5.0"; +} diff --git a/src/TypeGen/TypeGen.Cli/AssemblyInfo.cs b/src/TypeGen/TypeGen.Cli/AssemblyInfo.cs index 30994595..1a7778c9 100644 --- a/src/TypeGen/TypeGen.Cli/AssemblyInfo.cs +++ b/src/TypeGen/TypeGen.Cli/AssemblyInfo.cs @@ -1,6 +1,7 @@ -using System.Runtime.CompilerServices; +using System.Reflection; +using System.Runtime.CompilerServices; -[assembly: InternalsVisibleTo("TypeGen.IntegrationTest")] +[assembly: InternalsVisibleTo("TypeGen.FileContentTest")] [assembly: InternalsVisibleTo("TypeGen.Cli.Test")] [assembly: InternalsVisibleTo("TypeGen.Core.Test")] [assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")] \ No newline at end of file diff --git a/src/TypeGen/TypeGen.Cli/Build/IProjectBuild.cs b/src/TypeGen/TypeGen.Cli/Build/IProjectBuild.cs new file mode 100644 index 00000000..a36ba649 --- /dev/null +++ b/src/TypeGen/TypeGen.Cli/Build/IProjectBuild.cs @@ -0,0 +1,6 @@ +namespace TypeGen.Cli.Build; + +internal interface IProjectBuild +{ + void Build(string projectFolder); +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.Cli/Business/ProjectBuilder.cs b/src/TypeGen/TypeGen.Cli/Build/ProjectBuild.cs similarity index 85% rename from src/TypeGen/TypeGen.Cli/Business/ProjectBuilder.cs rename to src/TypeGen/TypeGen.Cli/Build/ProjectBuild.cs index 9e15db8c..2e0a3f00 100644 --- a/src/TypeGen/TypeGen.Cli/Business/ProjectBuilder.cs +++ b/src/TypeGen/TypeGen.Cli/Build/ProjectBuild.cs @@ -1,18 +1,14 @@ using System; -using System.Collections.Generic; using System.Diagnostics; -using System.IO; -using System.Linq; using TypeGen.Core.Logging; -using TypeGen.Core.Storage; -namespace TypeGen.Cli.Business +namespace TypeGen.Cli.Build { - internal class ProjectBuilder + internal class ProjectBuild : IProjectBuild { private readonly ILogger _logger; - public ProjectBuilder(ILogger logger) + public ProjectBuild(ILogger logger) { _logger = logger; } diff --git a/src/TypeGen/TypeGen.Cli/Business/ConsoleArgsReader.cs b/src/TypeGen/TypeGen.Cli/Business/ConsoleArgsReader.cs deleted file mode 100644 index 5726ab75..00000000 --- a/src/TypeGen/TypeGen.Cli/Business/ConsoleArgsReader.cs +++ /dev/null @@ -1,55 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using TypeGen.Core.Extensions; - -namespace TypeGen.Cli.Business -{ - internal class ConsoleArgsReader : IConsoleArgsReader - { - private const string GetCwdCommand = "GETCWD"; - private const string GenerateCommand = "GENERATE"; - - /// - /// Used to separate two or more paths; not a directory separator - /// - private const string PathSeparator = "|"; - - public bool ContainsGetCwdCommand(string[] args) => ContainsCommand(args, GetCwdCommand); - public bool ContainsGenerateCommand(string[] args) => ContainsCommand(args, GenerateCommand); - public bool ContainsAnyCommand(string[] args) => ContainsGenerateCommand(args) || ContainsGetCwdCommand(args); - private bool ContainsCommand(string[] args, string command) => args.Any(arg => string.Equals(arg, command, StringComparison.InvariantCultureIgnoreCase)); - - public bool ContainsHelpOption(string[] args) => ContainsOption(args, "-h", "--help"); - public bool ContainsProjectFolderOption(string[] args) => ContainsOption(args, "-p", "--project-folder"); - public bool ContainsOutputOption(string[] args) => ContainsOption(args, "-o", "--output-folder"); - public bool ContainsVerboseOption(string[] args) => ContainsOption(args, "-v", "--verbose"); - private bool ContainsOption(string[] args, string optionShortName, string optionFullName) => args.Any(arg => string.Equals(arg, optionShortName, StringComparison.InvariantCultureIgnoreCase) || string.Equals(arg, optionFullName, StringComparison.InvariantCultureIgnoreCase)); - - public IEnumerable GetProjectFolders(string[] args) => GetPathsParam(args, "-p", "--project-folder"); - public string GetOutputFolder(string[] args) => GetPathsParam(args, "-o", "--output-folder").FirstOrDefault(); - public IEnumerable GetConfigPaths(string[] args) => GetPathsParam(args, "-c", "--config-path"); - - private IEnumerable GetPathsParam(string[] args, string paramShortName, string paramFullName) - { - int index = -1; - - for (var i = 0; i < args.Length; i++) - { - if (args[i].Equals(paramShortName, StringComparison.InvariantCultureIgnoreCase) || - args[i].Equals(paramFullName, StringComparison.InvariantCultureIgnoreCase)) - { - index = i; - break; - } - } - - if (index < 0) return Enumerable.Empty(); - - if (args.Length < index + 2) throw new CliException($"{paramShortName}|{paramFullName} parameter present, but no path specified"); - return args[index + 1].Split(PathSeparator); - } - } -} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.Cli/Business/IAssemblyResolver.cs b/src/TypeGen/TypeGen.Cli/Business/IAssemblyResolver.cs deleted file mode 100644 index 950c19e3..00000000 --- a/src/TypeGen/TypeGen.Cli/Business/IAssemblyResolver.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Collections.Generic; - -namespace TypeGen.Cli.Business -{ - internal interface IAssemblyResolver - { - IEnumerable Directories { get; set; } - void Register(); - void Unregister(); - } -} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.Cli/Business/IConsoleArgsReader.cs b/src/TypeGen/TypeGen.Cli/Business/IConsoleArgsReader.cs deleted file mode 100644 index 2d3f38c3..00000000 --- a/src/TypeGen/TypeGen.Cli/Business/IConsoleArgsReader.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System.Collections.Generic; - -namespace TypeGen.Cli.Business -{ - internal interface IConsoleArgsReader - { - bool ContainsGetCwdCommand(string[] args); - bool ContainsGenerateCommand(string[] args); - bool ContainsAnyCommand(string[] args); - bool ContainsHelpOption(string[] args); - bool ContainsProjectFolderOption(string[] args); - bool ContainsOutputOption(string[] args); - bool ContainsVerboseOption(string[] args); - IEnumerable GetProjectFolders(string[] args); - string GetOutputFolder(string[] args); - IEnumerable GetConfigPaths(string[] args); - } -} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.Cli/Business/IGeneratorOptionsProvider.cs b/src/TypeGen/TypeGen.Cli/Business/IGeneratorOptionsProvider.cs deleted file mode 100644 index b32cbcc4..00000000 --- a/src/TypeGen/TypeGen.Cli/Business/IGeneratorOptionsProvider.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System.Collections.Generic; -using System.Reflection; -using TypeGen.Cli.Models; -using TypeGen.Core; -using TypeGen.Core.Generator; - -namespace TypeGen.Cli.Business -{ - internal interface IGeneratorOptionsProvider - { - /// - /// Returns the GeneratorOptions object based on the passed ConfigParams - /// - /// - /// - /// - /// - GeneratorOptions GetGeneratorOptions(TgConfig config, IEnumerable assemblies, string projectFolder); - } -} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.Cli/Business/IProjectFileManager.cs b/src/TypeGen/TypeGen.Cli/Business/IProjectFileManager.cs deleted file mode 100644 index a3dee5a7..00000000 --- a/src/TypeGen/TypeGen.Cli/Business/IProjectFileManager.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System.Xml; - -namespace TypeGen.Cli.Business -{ - internal interface IProjectFileManager - { - bool ContainsTsFile(XmlDocument projectFile, string filePath); - XmlDocument ReadFromProjectFolder(string projectFolder); - void SaveProjectFile(string projectFolder, XmlDocument projectFile); - void AddTsFile(XmlDocument projectFile, string filePath); - } -} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.Cli/DependencyInjection/ServiceCollectionExtensions.cs b/src/TypeGen/TypeGen.Cli/DependencyInjection/ServiceCollectionExtensions.cs new file mode 100644 index 00000000..1c803bf7 --- /dev/null +++ b/src/TypeGen/TypeGen.Cli/DependencyInjection/ServiceCollectionExtensions.cs @@ -0,0 +1,24 @@ +using System.Linq; +using System.Reflection; +using Microsoft.Extensions.DependencyInjection; +using TypeGen.Cli.Extensions; +using TypeGen.Core.Validation; + +namespace TypeGen.Cli.DependencyInjection; + +internal static class ServiceCollectionExtensions +{ + public static void AddInterfacesWithSingleImplementation(this ServiceCollection @this) + { + Requires.NotNull(@this, nameof(@this)); + + var allTypes = Assembly.GetExecutingAssembly().GetTypes(); + + var typePairs = allTypes.Where(@interface => @interface.IsInterface + && allTypes.Count(@class => @class.IsClass && @class.ImplementsInterface(@interface.FullName)) == 1) + .Select(@interface => (@interface, @class: allTypes.Single(@class => @class.ImplementsInterface(@interface.FullName)))); + + foreach (var pair in typePairs) + @this.AddTransient(pair.@interface, pair.@class); + } +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.Cli/ExitCode.cs b/src/TypeGen/TypeGen.Cli/ExitCode.cs index bd4ef7c9..6477f83f 100644 --- a/src/TypeGen/TypeGen.Cli/ExitCode.cs +++ b/src/TypeGen/TypeGen.Cli/ExitCode.cs @@ -1,6 +1,6 @@ namespace TypeGen.Cli; -public enum ExitCode : int +internal enum ExitCode { Success = 0, Error = 1 diff --git a/src/TypeGen/TypeGen.Cli/Extensions/PathExtensions.cs b/src/TypeGen/TypeGen.Cli/Extensions/PathExtensions.cs index 09943777..aae3c097 100644 --- a/src/TypeGen/TypeGen.Cli/Extensions/PathExtensions.cs +++ b/src/TypeGen/TypeGen.Cli/Extensions/PathExtensions.cs @@ -3,6 +3,7 @@ using System.IO; using System.Text; using TypeGen.Core.Storage; +using TypeGen.Core.Validation; namespace TypeGen.Cli.Extensions { @@ -11,7 +12,15 @@ internal static class PathExtensions public static string ToAbsolutePath(this string path, IFileSystem fileSystem) { if (string.IsNullOrWhiteSpace(path)) return path; - return Path.IsPathRooted(path) ? path : Path.Combine(fileSystem.GetCurrentDirectory(), path); + return path.RelativeOrRooted(fileSystem.GetCurrentDirectory()); + } + + public static string RelativeOrRooted(this string path, string basePath) + { + Requires.NotNull(path, nameof(path)); + Requires.NotNull(basePath, nameof(basePath)); + + return Path.IsPathRooted(path) ? path : Path.Combine(basePath, path); } } } diff --git a/src/TypeGen/TypeGen.Cli/Extensions/TypeExtensions.cs b/src/TypeGen/TypeGen.Cli/Extensions/TypeExtensions.cs new file mode 100644 index 00000000..480f2e52 --- /dev/null +++ b/src/TypeGen/TypeGen.Cli/Extensions/TypeExtensions.cs @@ -0,0 +1,15 @@ +using System; +using TypeGen.Core.Validation; + +namespace TypeGen.Cli.Extensions; + +internal static class TypeExtensions +{ + public static bool ImplementsInterface(this Type @this, string interfaceName) + { + Requires.NotNull(@this, nameof(@this)); + Requires.NotNullOrEmpty(interfaceName, nameof(interfaceName)); + + return @this.GetInterface(interfaceName) != null; + } +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.Cli/GenerationConfig/ConfigConsoleOptions.cs b/src/TypeGen/TypeGen.Cli/GenerationConfig/ConfigConsoleOptions.cs new file mode 100644 index 00000000..8d1f1c29 --- /dev/null +++ b/src/TypeGen/TypeGen.Cli/GenerationConfig/ConfigConsoleOptions.cs @@ -0,0 +1,3 @@ +namespace TypeGen.Cli.GenerationConfig; + +internal record ConfigConsoleOptions(string OutputFolder); \ No newline at end of file diff --git a/src/TypeGen/TypeGen.Cli/Business/ConfigProvider.cs b/src/TypeGen/TypeGen.Cli/GenerationConfig/ConfigProvider.cs similarity index 76% rename from src/TypeGen/TypeGen.Cli/Business/ConfigProvider.cs rename to src/TypeGen/TypeGen.Cli/GenerationConfig/ConfigProvider.cs index c711032d..dc86e9e3 100644 --- a/src/TypeGen/TypeGen.Cli/Business/ConfigProvider.cs +++ b/src/TypeGen/TypeGen.Cli/GenerationConfig/ConfigProvider.cs @@ -1,17 +1,13 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.IO; using System.Linq; -using System.Text; -using System.Threading.Tasks; using Newtonsoft.Json; -using TypeGen.Cli.Models; +using TypeGen.Cli.Extensions; using TypeGen.Core.Logging; -using TypeGen.Core.Utils; using TypeGen.Core.Storage; using TypeGen.Core.Validation; -namespace TypeGen.Cli.Business +namespace TypeGen.Cli.GenerationConfig { internal class ConfigProvider : IConfigProvider { @@ -26,40 +22,43 @@ public ConfigProvider(IFileSystem fileSystem, } /// - /// Creates a config object from a given config file + /// Creates an instance of TgConfig from /// /// /// + /// /// - public TgConfig GetConfig(string configPath, string projectFolder) + public TgConfig GetConfig(string configPath, string projectFolder, ConfigConsoleOptions consoleOptions) { - Requires.NotNullOrEmpty(configPath, nameof(configPath)); Requires.NotNullOrEmpty(projectFolder, nameof(projectFolder)); - if (!_fileSystem.FileExists(configPath)) - { - _logger.Log($"No config file found for project \"{projectFolder}\". Default configuration will be used.", LogLevel.Debug); - - TgConfig defaultConfig = new TgConfig() - .MergeWithDefaultParams() - .Normalize(); - - UpdateConfigAssemblyPaths(defaultConfig, projectFolder); - return defaultConfig; - } - - _logger.Log($"Reading the config file from \"{configPath}\"", LogLevel.Debug); - - string tgConfigJson = _fileSystem.ReadFile(configPath); - TgConfig config = JsonConvert.DeserializeObject(tgConfigJson) - .MergeWithDefaultParams() - .Normalize(); + configPath = !string.IsNullOrEmpty(configPath) + ? configPath.RelativeOrRooted(projectFolder) + : "tgconfig.json".RelativeOrRooted(projectFolder); + + _logger.Log(_fileSystem.FileExists(configPath) + ? $"Reading the config file from \"{configPath}\"" + : $"No config file found for project \"{projectFolder}\". Default configuration will be used.", + LogLevel.Debug); + + var config = _fileSystem.FileExists(configPath) + ? JsonConvert.DeserializeObject(_fileSystem.ReadFile(configPath)) + : new TgConfig(); + OverrideWithConsoleOptions(config, consoleOptions); + config.MergeWithDefaultParams(); + config.Normalize(); + UpdateConfigAssemblyPaths(config, projectFolder); - + return config; } + private static void OverrideWithConsoleOptions(TgConfig config, ConfigConsoleOptions consoleOptions) + { + if (consoleOptions.OutputFolder != null) config.OutputPath = consoleOptions.OutputFolder; + } + private void UpdateConfigAssemblyPaths(TgConfig config, string projectFolder) { if (!string.IsNullOrEmpty(config.AssemblyPath)) diff --git a/src/TypeGen/TypeGen.Cli/Business/GeneratorOptionsProvider.cs b/src/TypeGen/TypeGen.Cli/GenerationConfig/GeneratorOptionsProvider.cs similarity index 75% rename from src/TypeGen/TypeGen.Cli/Business/GeneratorOptionsProvider.cs rename to src/TypeGen/TypeGen.Cli/GenerationConfig/GeneratorOptionsProvider.cs index bc3fcad8..b8d5cb23 100644 --- a/src/TypeGen/TypeGen.Cli/Business/GeneratorOptionsProvider.cs +++ b/src/TypeGen/TypeGen.Cli/GenerationConfig/GeneratorOptionsProvider.cs @@ -1,34 +1,22 @@ using System; using System.Collections.Generic; -using System.IO; using System.Linq; using System.Reflection; -using System.Text; -using System.Threading.Tasks; using TypeGen.Cli.Extensions; -using TypeGen.Cli.Models; -using TypeGen.Core; +using TypeGen.Cli.TypeResolution; using TypeGen.Core.Converters; -using TypeGen.Core.Extensions; using TypeGen.Core.Generator; -using TypeGen.Core.Generator.Services; -using TypeGen.Core.Logging; -using TypeGen.Core.Storage; using TypeGen.Core.Validation; -namespace TypeGen.Cli.Business +namespace TypeGen.Cli.GenerationConfig { internal class GeneratorOptionsProvider : IGeneratorOptionsProvider { - private readonly IFileSystem _fileSystem; - private readonly ILogger _logger; + private readonly IConverterResolver _converterResolver; - private TypeResolver _typeResolver; - - public GeneratorOptionsProvider(IFileSystem fileSystem, ILogger logger) + public GeneratorOptionsProvider(IConverterResolver converterResolver) { - _fileSystem = fileSystem; - _logger = logger; + _converterResolver = converterResolver; } /// @@ -37,6 +25,7 @@ public GeneratorOptionsProvider(IFileSystem fileSystem, ILogger logger) /// /// /// + /// /// public GeneratorOptions GetGeneratorOptions(TgConfig config, IEnumerable assemblies, string projectFolder) { @@ -44,10 +33,9 @@ public GeneratorOptions GetGeneratorOptions(TgConfig config, IEnumerable GetTypeBlacklist(string[] configTypeBlacklist, string[] configTypeWhitelist) + { + var defaultBlacklist = GeneratorOptions.DefaultTypeBlacklist.ToArray(); + var blacklist = defaultBlacklist.Concat(configTypeBlacklist).Except(configTypeWhitelist); + return new HashSet(blacklist); + } + private TypeNameConverterCollection GetTypeNameConvertersFromConfig(IEnumerable typeNameConverters) { - IEnumerable converters = GetConverters(typeNameConverters); + var converters = _converterResolver.Resolve(typeNameConverters); return new TypeNameConverterCollection(converters); } private MemberNameConverterCollection GetMemberNameConvertersFromConfig(IEnumerable nameConverters) { - IEnumerable converters = GetConverters(nameConverters); + IEnumerable converters = _converterResolver.Resolve(nameConverters); return new MemberNameConverterCollection(converters); } - - private IEnumerable GetConverters(IEnumerable converters) - { - return converters - .Select(name => _typeResolver.Resolve(name, "Converter", new[] { typeof(T) })) - .Where(t => t != null) - .Select(t => (T)Activator.CreateInstance(t)); - } } } diff --git a/src/TypeGen/TypeGen.Cli/Business/IConfigProvider.cs b/src/TypeGen/TypeGen.Cli/GenerationConfig/IConfigProvider.cs similarity index 72% rename from src/TypeGen/TypeGen.Cli/Business/IConfigProvider.cs rename to src/TypeGen/TypeGen.Cli/GenerationConfig/IConfigProvider.cs index 06bec0c2..f5b7a8d3 100644 --- a/src/TypeGen/TypeGen.Cli/Business/IConfigProvider.cs +++ b/src/TypeGen/TypeGen.Cli/GenerationConfig/IConfigProvider.cs @@ -1,6 +1,4 @@ -using TypeGen.Cli.Models; - -namespace TypeGen.Cli.Business +namespace TypeGen.Cli.GenerationConfig { internal interface IConfigProvider { @@ -9,7 +7,8 @@ internal interface IConfigProvider /// /// /// + /// /// - TgConfig GetConfig(string configPath, string projectFolder); + TgConfig GetConfig(string configPath, string projectFolder, ConfigConsoleOptions consoleOptions); } } \ No newline at end of file diff --git a/src/TypeGen/TypeGen.Cli/GenerationConfig/IGeneratorOptionsProvider.cs b/src/TypeGen/TypeGen.Cli/GenerationConfig/IGeneratorOptionsProvider.cs new file mode 100644 index 00000000..15141ae5 --- /dev/null +++ b/src/TypeGen/TypeGen.Cli/GenerationConfig/IGeneratorOptionsProvider.cs @@ -0,0 +1,18 @@ +using System.Collections.Generic; +using System.Reflection; +using TypeGen.Core.Generator; + +namespace TypeGen.Cli.GenerationConfig; + +internal interface IGeneratorOptionsProvider +{ + /// + /// Returns the GeneratorOptions object based on the passed ConfigParams + /// + /// + /// + /// + /// + /// + GeneratorOptions GetGeneratorOptions(TgConfig config, IEnumerable assemblies, string projectFolder); +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.Cli/Models/TgConfig.cs b/src/TypeGen/TypeGen.Cli/GenerationConfig/TgConfig.cs similarity index 93% rename from src/TypeGen/TypeGen.Cli/Models/TgConfig.cs rename to src/TypeGen/TypeGen.Cli/GenerationConfig/TgConfig.cs index c10bdd2a..8d4e8146 100644 --- a/src/TypeGen/TypeGen.Cli/Models/TgConfig.cs +++ b/src/TypeGen/TypeGen.Cli/GenerationConfig/TgConfig.cs @@ -1,14 +1,11 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Runtime.Serialization; using TypeGen.Cli.Extensions; -using TypeGen.Core; -using TypeGen.Core.Converters; using TypeGen.Core.Extensions; using TypeGen.Core.Generator; -namespace TypeGen.Cli.Models +namespace TypeGen.Cli.GenerationConfig { /// /// Represents console configuration @@ -18,6 +15,8 @@ internal class TgConfig public static bool DefaultAddFilesToProject => false; public static bool DefaultBuildProject => false; public static string DefaultProjectOutputFolder => "bin"; + public static string[] DefaultTypeBlacklist => Array.Empty(); + public static string[] DefaultTypeWhitelist => Array.Empty(); [Obsolete("Use Assemblies instead")] public string AssemblyPath { get; set; } @@ -52,6 +51,8 @@ internal class TgConfig public string ProjectOutputFolder { get; set; } public bool? ExportTypesAsInterfacesByDefault { get; set; } public bool? UseImportType { get; set; } + public string[] TypeBlacklist { get; set; } + public string[] TypeWhitelist { get; set; } public TgConfig Normalize() { @@ -98,6 +99,8 @@ public TgConfig MergeWithDefaultParams() if (ProjectOutputFolder == null) ProjectOutputFolder = DefaultProjectOutputFolder; if (ExportTypesAsInterfacesByDefault == null) ExportTypesAsInterfacesByDefault = GeneratorOptions.DefaultExportTypesAsInterfacesByDefault; if (UseImportType == null) UseImportType = GeneratorOptions.DefaultUseImportType; + if (TypeBlacklist == null) TypeBlacklist = DefaultTypeBlacklist; + if (TypeWhitelist == null) TypeWhitelist = DefaultTypeWhitelist; return this; } diff --git a/src/TypeGen/TypeGen.Cli/IApplication.cs b/src/TypeGen/TypeGen.Cli/IApplication.cs new file mode 100644 index 00000000..3185c991 --- /dev/null +++ b/src/TypeGen/TypeGen.Cli/IApplication.cs @@ -0,0 +1,8 @@ +using System.Threading.Tasks; + +namespace TypeGen.Cli; + +internal interface IApplication +{ + Task Run(string[] args); +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.Cli/Program.cs b/src/TypeGen/TypeGen.Cli/Program.cs index 38c27ae3..271599eb 100644 --- a/src/TypeGen/TypeGen.Cli/Program.cs +++ b/src/TypeGen/TypeGen.Cli/Program.cs @@ -1,211 +1,22 @@ using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Reflection; -using System.Xml; -using TypeGen.Cli.Business; -using TypeGen.Cli.Models; -using TypeGen.Core; -using TypeGen.Core.Extensions; -using TypeGen.Core.Generator; +using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; +using TypeGen.Cli.DependencyInjection; using TypeGen.Core.Logging; -using TypeGen.Core.SpecGeneration; using TypeGen.Core.Storage; -using IGeneratorOptionsProvider = TypeGen.Cli.Business.IGeneratorOptionsProvider; -using GeneratorOptionsProvider = TypeGen.Cli.Business.GeneratorOptionsProvider; -namespace TypeGen.Cli +namespace TypeGen.Cli; + +internal class Program { - internal class Program + private static async Task Main(string[] args) { - private static IConsoleArgsReader _consoleArgsReader; - private static ILogger _logger; - private static IFileSystem _fileSystem; - private static IConfigProvider _configProvider; - private static IGeneratorOptionsProvider _generatorOptionsProvider; - private static IProjectFileManager _projectFileManager; - private static ProjectBuilder _projectBuilder; - private static IAssemblyResolver _assemblyResolver; - - private static void InitializeServices(string[] args) - { - _consoleArgsReader = new ConsoleArgsReader(); - - bool verbose = _consoleArgsReader.ContainsVerboseOption(args); - _logger = new ConsoleLogger(verbose); - - _fileSystem = new FileSystem(); - _configProvider = new ConfigProvider(_fileSystem, _logger); - _generatorOptionsProvider = new GeneratorOptionsProvider(_fileSystem, _logger); - _projectFileManager = new ProjectFileManager(_fileSystem); - _projectBuilder = new ProjectBuilder(_logger); - } - - private static int Main(string[] args) - { - try - { - InitializeServices(args); - - if (args == null || args.Length == 0 || _consoleArgsReader.ContainsHelpOption(args) || _consoleArgsReader.ContainsAnyCommand(args) == false) - { - ShowHelp(); - return (int)ExitCode.Success; - } - - if (_consoleArgsReader.ContainsGetCwdCommand(args)) - { - string cwd = _fileSystem.GetCurrentDirectory(); - Console.WriteLine($"Current working directory is: {cwd}"); - return (int)ExitCode.Success; - } - - string[] configPaths = _consoleArgsReader.GetConfigPaths(args).ToArray(); - - string[] projectFolders = _consoleArgsReader.ContainsProjectFolderOption(args) ? - _consoleArgsReader.GetProjectFolders(args).ToArray() : - new [] { "." }; - - string? outputFolder = _consoleArgsReader.ContainsOutputOption(args) ? - _consoleArgsReader.GetOutputFolder(args) : null; - - for (var i = 0; i < projectFolders.Length; i++) - { - string projectFolder = projectFolders[i]; - string configPath = configPaths.HasIndex(i) ? configPaths[i] : null; - - _assemblyResolver = new AssemblyResolver(_fileSystem, _logger, projectFolder); - - Generate(projectFolder, configPath, outputFolder); - } - - return (int)ExitCode.Success; - } - catch (AssemblyResolutionException e) - { - string message = e.Message + - "Consider adding any external assembly directories in the externalAssemblyPaths parameter. " + - "If you're using ASP.NET Core, add your NuGet directory to externalAssemblyPaths parameter (you can use global NuGet packages directory alias: \"\")"; - _logger.Log($"{message}{Environment.NewLine}{e.StackTrace}", LogLevel.Error); - return (int)ExitCode.Error; - } - catch (ReflectionTypeLoadException e) - { - foreach (Exception loaderException in e.LoaderExceptions) - { - _logger.Log($"TYPE LOAD ERROR: {loaderException.Message}{Environment.NewLine}{e.StackTrace}", LogLevel.Error); - } - return (int)ExitCode.Error; - } - catch (Exception e) - { - _logger.Log($"ERROR: {e.Message}{Environment.NewLine}{e.StackTrace}", LogLevel.Error); - return (int)ExitCode.Error; - } - } - - private static void Generate(string projectFolder, string configPath, string? outputFolder) - { - // get config - - configPath = !string.IsNullOrEmpty(configPath) - ? Path.Combine(projectFolder, configPath) - : Path.Combine(projectFolder, "tgconfig.json"); - - TgConfig config = _configProvider.GetConfig(configPath, projectFolder); - - // register assembly resolver - - _assemblyResolver.Directories = config.ExternalAssemblyPaths; - _assemblyResolver.Register(); - - IEnumerable assemblies = GetAssemblies(config.GetAssemblies()).ToArray(); - - // create generator - - GeneratorOptions generatorOptions = _generatorOptionsProvider.GetGeneratorOptions(config, assemblies, projectFolder); - generatorOptions.BaseOutputDirectory = outputFolder ?? Path.Combine(projectFolder, config.OutputPath); - var generator = new Generator(generatorOptions, _logger); - - // generate - - if (config.ClearOutputDirectory == true) _fileSystem.ClearDirectory(generatorOptions.BaseOutputDirectory); - if (config.BuildProject == true) _projectBuilder.Build(projectFolder); - - _logger.Log($"Generating files for project \"{projectFolder}\"...", LogLevel.Info); - - var generatedFiles = new List(); - - if (!config.GenerationSpecs.Any() || config.GenerateFromAssemblies == true) - { - generatedFiles.AddRange(generator.Generate(assemblies)); - } - - if (config.GenerationSpecs.Any()) - { - var typeResolver = new TypeResolver(_logger, _fileSystem, projectFolder, assemblies); - - IEnumerable generationSpecs = config.GenerationSpecs - .Select(name => typeResolver.Resolve(name, "GenerationSpec")) - .Where(t => t != null) - .Select(t => (GenerationSpec)Activator.CreateInstance(t)) - .ToArray(); - - generatedFiles.AddRange(generator.Generate(generationSpecs)); - } - - foreach (string file in generatedFiles) - { - _logger.Log($"Generated {file}", LogLevel.Info); - } - - if (config.AddFilesToProject ?? TgConfig.DefaultAddFilesToProject) - { - AddFilesToProject(projectFolder, generatedFiles); - } - - // unregister assembly resolver - - _assemblyResolver.Unregister(); - - _logger.Log($"Files for project \"{projectFolder}\" generated successfully.{Environment.NewLine}", LogLevel.Info); - } - - private static void AddFilesToProject(string projectFolder, IEnumerable generatedFiles) - { - XmlDocument projectFile = _projectFileManager.ReadFromProjectFolder(projectFolder); - - foreach (string filePath in generatedFiles) - { - _projectFileManager.AddTsFile(projectFile, filePath); - } - - _projectFileManager.SaveProjectFile(projectFolder, projectFile); - } - - private static IEnumerable GetAssemblies(IEnumerable assemblyNames) - { - return assemblyNames.Select(Assembly.LoadFrom); - } + var services = new ServiceCollection(); + services.AddInterfacesWithSingleImplementation(); + services.AddTransient(); + services.AddTransient(); - private static void ShowHelp() - { - Console.WriteLine($"TypeGen v{AppConfig.Version}" + Environment.NewLine + - Environment.NewLine + - "Usage: [dotnet-]typegen [options] [command]" + Environment.NewLine + - Environment.NewLine + - "Options:" + Environment.NewLine + - "-h|--help Show help information" + Environment.NewLine + - "-v|--verbose Show verbose output" + Environment.NewLine + - "-p|--project-folder Set project folder path(s)" + Environment.NewLine + - "-c|--config-path Set config path(s) to use" + Environment.NewLine + - Environment.NewLine + - "Commands:" + Environment.NewLine + - "generate Generate TypeScript files" + Environment.NewLine + - "getcwd Get current working directory" + Environment.NewLine + - Environment.NewLine + - "For more information please visit project's website: http://jburzynski.net/TypeGen"); - } + var serviceProvider = services.BuildServiceProvider(true); + return (int)await serviceProvider.GetService().Run(args); } -} +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.Cli/ProjectFileManagement/IProjectFileManager.cs b/src/TypeGen/TypeGen.Cli/ProjectFileManagement/IProjectFileManager.cs new file mode 100644 index 00000000..db17ab98 --- /dev/null +++ b/src/TypeGen/TypeGen.Cli/ProjectFileManagement/IProjectFileManager.cs @@ -0,0 +1,14 @@ +using System.Collections.Generic; +using System.Xml; + +namespace TypeGen.Cli.ProjectFileManagement +{ + internal interface IProjectFileManager + { + bool ContainsTsFile(XmlDocument projectDocument, string filePath); + XmlDocument ReadFromProjectFolder(string projectFolder); + void SaveProjectFile(string projectFolder, XmlDocument projectFile); + void AddTsFile(XmlDocument projectDocument, string filePath); + void AddTsFiles(XmlDocument projectDocument, IEnumerable filePaths); + } +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.Cli/Business/ProjectFileManager.cs b/src/TypeGen/TypeGen.Cli/ProjectFileManagement/ProjectFileManager.cs similarity index 73% rename from src/TypeGen/TypeGen.Cli/Business/ProjectFileManager.cs rename to src/TypeGen/TypeGen.Cli/ProjectFileManagement/ProjectFileManager.cs index 5aaff973..1d8229d4 100644 --- a/src/TypeGen/TypeGen.Cli/Business/ProjectFileManager.cs +++ b/src/TypeGen/TypeGen.Cli/ProjectFileManagement/ProjectFileManager.cs @@ -1,16 +1,10 @@ -using System; -using System.Collections.Generic; -using System.IO; +using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Xml; -using TypeGen.Core.Utils; -using TypeGen.Core.Extensions; using TypeGen.Core.Storage; using TypeGen.Core.Validation; -namespace TypeGen.Cli.Business +namespace TypeGen.Cli.ProjectFileManagement { /// /// For ASP.NET (.NET Framework) versions (addFilesToProject parameter in TypeGen CLI) @@ -26,11 +20,11 @@ public ProjectFileManager(IFileSystem fileSystem) _fileSystem = fileSystem; } - public bool ContainsTsFile(XmlDocument projectFile, string filePath) + public bool ContainsTsFile(XmlDocument projectDocument, string filePath) { - Requires.NotNull(projectFile, nameof(projectFile)); + Requires.NotNull(projectDocument, nameof(projectDocument)); - XmlNodeList itemGroups = projectFile.DocumentElement?.SelectNodes($"{TypeScriptCompileXPath}[@Include='{filePath}']"); + XmlNodeList itemGroups = projectDocument.DocumentElement?.SelectNodes($"{TypeScriptCompileXPath}[@Include='{filePath}']"); return itemGroups != null && itemGroups.Count > 0; } @@ -58,22 +52,28 @@ private string GetProjectPath(string projectFolder) .FirstOrDefault(x => x.EndsWith(".csproj")); } - public void AddTsFile(XmlDocument projectFile, string filePath) + public void AddTsFiles(XmlDocument projectDocument, IEnumerable filePaths) { - Requires.NotNull(projectFile, nameof(projectFile)); + foreach (var filePath in filePaths) + AddTsFile(projectDocument, filePath); + } + + public void AddTsFile(XmlDocument projectDocument, string filePath) + { + Requires.NotNull(projectDocument, nameof(projectDocument)); - XmlElement documentElement = projectFile.DocumentElement; + XmlElement documentElement = projectDocument.DocumentElement; if (documentElement == null) throw new CliException("Project file has no XML document element"); - if (ContainsTsFile(projectFile, filePath)) return; + if (ContainsTsFile(projectDocument, filePath)) return; XmlNode itemGroupNode = documentElement .SelectSingleNode(TypeScriptCompileXPath) ?.ParentNode - ?? AddItemGroup(projectFile); + ?? AddItemGroup(projectDocument); itemGroupNode.AppendChild( - CreateItemGroupChild(projectFile, "TypeScriptCompile", filePath) + CreateItemGroupChild(projectDocument, "TypeScriptCompile", filePath) ); } diff --git a/src/TypeGen/TypeGen.Cli/TypeGen.Cli.csproj b/src/TypeGen/TypeGen.Cli/TypeGen.Cli.csproj index 5e7f83dc..1af81555 100644 --- a/src/TypeGen/TypeGen.Cli/TypeGen.Cli.csproj +++ b/src/TypeGen/TypeGen.Cli/TypeGen.Cli.csproj @@ -1,11 +1,18 @@ - + Exe net7.0 + 4.5.0.0 + 4.5.0.0 + 4.5.0 + TypeGen + + + diff --git a/src/TypeGen/TypeGen.Cli/Business/AssemblyResolver.cs b/src/TypeGen/TypeGen.Cli/TypeResolution/AssemblyResolver.cs similarity index 90% rename from src/TypeGen/TypeGen.Cli/Business/AssemblyResolver.cs rename to src/TypeGen/TypeGen.Cli/TypeResolution/AssemblyResolver.cs index 19105ed9..695200e8 100644 --- a/src/TypeGen/TypeGen.Cli/Business/AssemblyResolver.cs +++ b/src/TypeGen/TypeGen.Cli/TypeResolution/AssemblyResolver.cs @@ -9,29 +9,24 @@ using TypeGen.Core.Logging; using TypeGen.Core.Storage; -namespace TypeGen.Cli.Business +namespace TypeGen.Cli.TypeResolution { - internal class AssemblyResolver : IAssemblyResolver + internal class AssemblyResolver : IDisposable { private readonly IFileSystem _fileSystem; private readonly ILogger _logger; private readonly string _projectFolder; - - private IEnumerable _directories; - public IEnumerable Directories - { - get => _directories; - set => _directories = value?.Select(d => Path.IsPathRooted(d) ? d : Path.Combine(_projectFolder, d)); - } + private readonly IEnumerable _directories; private readonly string _globalFallbackPath; private readonly string _sharedFolder; private List _nugetPackagesFolders; - public AssemblyResolver(IFileSystem fileSystem, ILogger logger, string projectFolder) + public AssemblyResolver(IFileSystem fileSystem, ILogger logger, string projectFolder, IEnumerable directories) { _fileSystem = fileSystem; _logger = logger; + _directories = directories; _projectFolder = projectFolder.ToAbsolutePath(_fileSystem); string dotnetInstallPath = GetDotnetInstallPath(); @@ -41,6 +36,7 @@ public AssemblyResolver(IFileSystem fileSystem, ILogger logger, string projectFo if (_fileSystem.DirectoryExists(dotNetInstallSharedPath)) _sharedFolder = dotNetInstallSharedPath; PopulateNuGetPackageFolders(); + Register(); } private void PopulateNuGetPackageFolders() @@ -53,12 +49,12 @@ private void PopulateNuGetPackageFolders() if (!_nugetPackagesFolders.Contains(_globalFallbackPath) && Directory.Exists(_globalFallbackPath)) _nugetPackagesFolders.Add(_globalFallbackPath); } - public void Register() + private void Register() { AppDomain.CurrentDomain.AssemblyResolve += AssemblyResolve; } - public void Unregister() + private void Unregister() { AppDomain.CurrentDomain.AssemblyResolve -= AssemblyResolve; } @@ -74,7 +70,7 @@ private Assembly AssemblyResolve(object sender, ResolveEventArgs args) if (assembly != null) return assembly; // user-defined - assembly = FindByPackageName(Directories, args.Name); + assembly = FindByPackageName(_directories, args.Name); if (assembly != null) return assembly; // step 2 - search recursively (shared + user-defined + nuget global + nuget fallback) @@ -90,14 +86,14 @@ private Assembly AssemblyResolve(object sender, ResolveEventArgs args) } // user-defined - assembly = FindRecursive(Directories, assemblyFileName, assemblyVersion); + assembly = FindRecursive(_directories, assemblyFileName, assemblyVersion); if (assembly != null) return assembly; // nuget assembly = FindRecursive(_nugetPackagesFolders, assemblyFileName, assemblyVersion); // log if assembly not found - List searchedDirectories = Directories.Concat(_nugetPackagesFolders).Concat(new[] {_sharedFolder}).ToList(); + List searchedDirectories = _directories.Concat(_nugetPackagesFolders).Concat(new[] {_sharedFolder}).ToList(); if (assembly == null) _logger.Log($"Could not resolve assembly: {args.Name} in any of the searched directories: {string.Join("; ", searchedDirectories)}", LogLevel.Error); // return assembly or null @@ -207,5 +203,17 @@ private string GetDotnetInstallPath() return @"C:\Program Files\dotnet"; // old behavior } + ~AssemblyResolver() => Dispose(false); + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + protected virtual void Dispose(bool disposing) + { + Unregister(); + } } } diff --git a/src/TypeGen/TypeGen.Cli/TypeResolution/ConverterResolver.cs b/src/TypeGen/TypeGen.Cli/TypeResolution/ConverterResolver.cs new file mode 100644 index 00000000..f37217c6 --- /dev/null +++ b/src/TypeGen/TypeGen.Cli/TypeResolution/ConverterResolver.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using TypeGen.Core.SpecGeneration; + +namespace TypeGen.Cli.TypeResolution; + +internal class ConverterResolver : IConverterResolver +{ + private readonly ITypeResolver _typeResolver; + + public ConverterResolver(ITypeResolver typeResolver) + { + _typeResolver = typeResolver; + } + + public IReadOnlyList Resolve(IEnumerable names) + { + return names + .Select(name => _typeResolver.Resolve(name, "Converter", new[] { typeof(T) })) + .Where(t => t != null) + .Select(t => (T)Activator.CreateInstance(t)) + .ToList(); + } +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.Cli/TypeResolution/GenerationSpecResolver.cs b/src/TypeGen/TypeGen.Cli/TypeResolution/GenerationSpecResolver.cs new file mode 100644 index 00000000..69738f7e --- /dev/null +++ b/src/TypeGen/TypeGen.Cli/TypeResolution/GenerationSpecResolver.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using TypeGen.Core.SpecGeneration; + +namespace TypeGen.Cli.TypeResolution; + +internal class GenerationSpecResolver : IGenerationSpecResolver +{ + private readonly ITypeResolver _typeResolver; + + public GenerationSpecResolver(ITypeResolver typeResolver) + { + _typeResolver = typeResolver; + } + + public IReadOnlyList Resolve(IEnumerable names) + { + return names + .Select(name => _typeResolver.Resolve(name, "GenerationSpec")) + .Where(t => t != null) + .Select(t => (GenerationSpec)Activator.CreateInstance(t)) + .ToList(); + } +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.Cli/TypeResolution/IConverterResolver.cs b/src/TypeGen/TypeGen.Cli/TypeResolution/IConverterResolver.cs new file mode 100644 index 00000000..97612062 --- /dev/null +++ b/src/TypeGen/TypeGen.Cli/TypeResolution/IConverterResolver.cs @@ -0,0 +1,8 @@ +using System.Collections.Generic; + +namespace TypeGen.Cli.TypeResolution; + +internal interface IConverterResolver +{ + IReadOnlyList Resolve(IEnumerable names); +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.Cli/TypeResolution/IGenerationSpecResolver.cs b/src/TypeGen/TypeGen.Cli/TypeResolution/IGenerationSpecResolver.cs new file mode 100644 index 00000000..4122317b --- /dev/null +++ b/src/TypeGen/TypeGen.Cli/TypeResolution/IGenerationSpecResolver.cs @@ -0,0 +1,9 @@ +using System.Collections.Generic; +using TypeGen.Core.SpecGeneration; + +namespace TypeGen.Cli.TypeResolution; + +internal interface IGenerationSpecResolver +{ + IReadOnlyList Resolve(IEnumerable names); +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.Cli/TypeResolution/ITypeResolver.cs b/src/TypeGen/TypeGen.Cli/TypeResolution/ITypeResolver.cs new file mode 100644 index 00000000..7baf6e0b --- /dev/null +++ b/src/TypeGen/TypeGen.Cli/TypeResolution/ITypeResolver.cs @@ -0,0 +1,9 @@ +using System; +using System.Collections.Generic; + +namespace TypeGen.Cli.TypeResolution; + +internal interface ITypeResolver +{ + Type Resolve(string typeIdentifier, string typeNameSuffix = null, IEnumerable interfaceConstraints = null, IEnumerable baseTypeConstraints = null); +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.Cli/Business/TypeResolver.cs b/src/TypeGen/TypeGen.Cli/TypeResolution/TypeResolver.cs similarity index 98% rename from src/TypeGen/TypeGen.Cli/Business/TypeResolver.cs rename to src/TypeGen/TypeGen.Cli/TypeResolution/TypeResolver.cs index 4a8f0c4f..90d849e8 100644 --- a/src/TypeGen/TypeGen.Cli/Business/TypeResolver.cs +++ b/src/TypeGen/TypeGen.Cli/TypeResolution/TypeResolver.cs @@ -3,15 +3,14 @@ using System.IO; using System.Linq; using System.Reflection; -using TypeGen.Core; using TypeGen.Core.Extensions; using TypeGen.Core.Generator; using TypeGen.Core.Logging; using TypeGen.Core.Storage; -namespace TypeGen.Cli.Business +namespace TypeGen.Cli.TypeResolution { - internal class TypeResolver + internal class TypeResolver : ITypeResolver { private readonly ILogger _logger; private readonly IFileSystem _fileSystem; diff --git a/src/TypeGen/TypeGen.Cli/Ui/ActionResult.cs b/src/TypeGen/TypeGen.Cli/Ui/ActionResult.cs new file mode 100644 index 00000000..fad8a10a --- /dev/null +++ b/src/TypeGen/TypeGen.Cli/Ui/ActionResult.cs @@ -0,0 +1,13 @@ +namespace TypeGen.Cli.Ui; + +internal class ActionResult +{ + public bool IsSuccess { get; private set; } + + private ActionResult() + { + } + + public static ActionResult Success() => new() { IsSuccess = true }; + public static ActionResult Failure() => new() { IsSuccess = false }; +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.Cli/Ui/ConsoleOutput.cs b/src/TypeGen/TypeGen.Cli/Ui/ConsoleOutput.cs new file mode 100644 index 00000000..62f24b40 --- /dev/null +++ b/src/TypeGen/TypeGen.Cli/Ui/ConsoleOutput.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using TypeGen.Core.Storage; +using static TypeGen.Core.Utils.ConsoleUtils; + +namespace TypeGen.Cli.Ui; + +internal class ConsoleOutput : IConsoleOutput +{ + private readonly IFileSystem _fileSystem; + + public ConsoleOutput(IFileSystem fileSystem) + { + _fileSystem = fileSystem; + } + + public void ShowCwd() + { + var cwd = _fileSystem.GetCurrentDirectory(); + Console.WriteLine($"Current working directory is: {cwd}"); + } + + public void ShowGenerationBegin(string projectFolder) + { + Console.WriteLine($"Generating files for project \"{projectFolder}\"..."); + } + + public void ShowGeneratedFiles(List generatedFiles) + { + foreach (var file in generatedFiles) + Console.WriteLine($"Generated {file}"); + } + + public void ShowGenerationEnd(string projectFolder) + { + Console.WriteLine($"Files for project \"{projectFolder}\" generated successfully.{Environment.NewLine}"); + } + + public void ShowErrors(IEnumerable messages) + { + WithColor(ConsoleColor.Red, () => + { + foreach (var message in messages) Console.WriteLine(message); + }); + } +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.Cli/Ui/IConsoleOutput.cs b/src/TypeGen/TypeGen.Cli/Ui/IConsoleOutput.cs new file mode 100644 index 00000000..341ce3b3 --- /dev/null +++ b/src/TypeGen/TypeGen.Cli/Ui/IConsoleOutput.cs @@ -0,0 +1,12 @@ +using System.Collections.Generic; + +namespace TypeGen.Cli.Ui; + +internal interface IConsoleOutput +{ + void ShowCwd(); + void ShowGenerationBegin(string projectFolder); + void ShowGeneratedFiles(List generatedFiles); + void ShowGenerationEnd(string projectFolder); + void ShowErrors(IEnumerable messages); +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.Cli/Ui/IPresenter.cs b/src/TypeGen/TypeGen.Cli/Ui/IPresenter.cs new file mode 100644 index 00000000..ce98b34d --- /dev/null +++ b/src/TypeGen/TypeGen.Cli/Ui/IPresenter.cs @@ -0,0 +1,9 @@ +using System.Collections.Generic; + +namespace TypeGen.Cli.Ui; + +internal interface IPresenter +{ + ActionResult GetCwd(); + ActionResult Generate(bool verbose, IReadOnlyCollection projectFolderPaths, IReadOnlyCollection configPaths, string outputFolder); +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.Cli/Ui/Presenter.cs b/src/TypeGen/TypeGen.Cli/Ui/Presenter.cs new file mode 100644 index 00000000..98612f70 --- /dev/null +++ b/src/TypeGen/TypeGen.Cli/Ui/Presenter.cs @@ -0,0 +1,133 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Mail; +using System.Reflection; +using System.Threading.Tasks; +using TypeGen.Cli.Build; +using TypeGen.Cli.GenerationConfig; +using TypeGen.Cli.ProjectFileManagement; +using TypeGen.Cli.TypeResolution; +using TypeGen.Cli.Ui.Validation; +using TypeGen.Core.Extensions; +using TypeGen.Core.Generator; +using TypeGen.Core.Logging; +using TypeGen.Core.Storage; + +namespace TypeGen.Cli.Ui; + +internal class Presenter : IPresenter +{ + private readonly ILogger _logger; + private readonly IConsoleOutput _consoleOutput; + private readonly IFileSystem _fileSystem; + private readonly IConfigProvider _configProvider; + private readonly IProjectBuild _projectBuild; + private readonly IProjectFileManager _projectFileManager; + + private readonly IGenerateValidator _generateValidator; + + public Presenter( + IConsoleOutput consoleOutput, + IFileSystem fileSystem, + ILogger logger, + IConfigProvider configProvider, + IProjectBuild projectBuild, + IProjectFileManager projectFileManager, + IGenerateValidator generateValidator) + { + _consoleOutput = consoleOutput; + _fileSystem = fileSystem; + _logger = logger; + _configProvider = configProvider; + _projectBuild = projectBuild; + _projectFileManager = projectFileManager; + _generateValidator = generateValidator; + } + + public ActionResult GetCwd() + { + _consoleOutput.ShowCwd(); + return ActionResult.Success(); + } + + public ActionResult Generate(bool verbose, IReadOnlyCollection projectFolderPaths, IReadOnlyCollection configPaths, string outputFolder) + { + if (projectFolderPaths.IsNullOrEmpty()) projectFolderPaths = new[] { "." }; + var validationResult = _generateValidator.Validate(verbose, projectFolderPaths, configPaths, outputFolder); + + validationResult + .Match( + () => GeneratePrivate(verbose, projectFolderPaths, configPaths, outputFolder), + messages => _consoleOutput.ShowErrors(messages) + ); + + return validationResult.IsSuccess ? ActionResult.Success() : ActionResult.Failure(); + } + + private void GeneratePrivate(bool verbose, IReadOnlyCollection projectFolderPaths, IReadOnlyCollection configPaths, string outputFolder) + { + SetLoggerVerbosity(verbose); + + if (configPaths.None()) configPaths = Enumerable.Repeat((string)null, projectFolderPaths.Count).ToList(); + var projectConfigPairs = projectFolderPaths + .Zip(configPaths) + .Select(x => (projectFolderPath: x.First, configPath: x.Second)); + + foreach (var pair in projectConfigPairs) + GenerateSingle(pair.projectFolderPath, pair.configPath, outputFolder); + } + + private void GenerateSingle(string projectFolder, string configPath, string outputFolder) + { + // prep + + var configConsoleOptions = new ConfigConsoleOptions(outputFolder); + var config = _configProvider.GetConfig(configPath, projectFolder, configConsoleOptions); + var assemblies = config.GetAssemblies().Select(Assembly.LoadFrom).ToList(); + + using var assemblyResolver = new AssemblyResolver(_fileSystem, _logger, projectFolder, config.ExternalAssemblyPaths); + var typeResolver = new TypeResolver(_logger, _fileSystem, projectFolder, assemblies); + var converterResolver = new ConverterResolver(typeResolver); + var generationSpecResolver = new GenerationSpecResolver(typeResolver); + + var generatorOptionsProvider = new GeneratorOptionsProvider(converterResolver); + var generatorOptions = generatorOptionsProvider.GetGeneratorOptions(config, assemblies, projectFolder); + var generator = new Generator(generatorOptions, _logger); + + // generate + + if (config.ClearOutputDirectory == true) _fileSystem.ClearDirectory(generatorOptions.BaseOutputDirectory); + if (config.BuildProject == true) _projectBuild.Build(projectFolder); + + _consoleOutput.ShowGenerationBegin(projectFolder); + + var generatedFiles = new List(); + + if (config.GenerationSpecs.None() || config.GenerateFromAssemblies == true) + generatedFiles.AddRange(generator.Generate(assemblies)); + + if (config.GenerationSpecs.Any()) + { + var generationSpecs = generationSpecResolver.Resolve(config.GenerationSpecs); + generatedFiles.AddRange(generator.Generate(generationSpecs)); + } + + if (config.AddFilesToProject == true) AddFilesToProject(projectFolder, generatedFiles); + + _consoleOutput.ShowGeneratedFiles(generatedFiles); + _consoleOutput.ShowGenerationEnd(projectFolder); + } + + private void AddFilesToProject(string projectFolder, IEnumerable generatedFiles) + { + var projectDocument = _projectFileManager.ReadFromProjectFolder(projectFolder); + _projectFileManager.AddTsFiles(projectDocument, generatedFiles); + _projectFileManager.SaveProjectFile(projectFolder, projectDocument); + } + + private void SetLoggerVerbosity(bool verbose) + { + _logger.MinLevel = verbose ? LogLevel.Debug : LogLevel.Info; + } +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.Cli/Ui/Validation/GenerateValidator.cs b/src/TypeGen/TypeGen.Cli/Ui/Validation/GenerateValidator.cs new file mode 100644 index 00000000..4a456472 --- /dev/null +++ b/src/TypeGen/TypeGen.Cli/Ui/Validation/GenerateValidator.cs @@ -0,0 +1,21 @@ +using System.Collections.Generic; +using System.Linq; +using TypeGen.Core.Extensions; + +namespace TypeGen.Cli.Ui.Validation; + +internal class GenerateValidator : IGenerateValidator +{ + public ValidationResult Validate(bool verbose, IReadOnlyCollection projectFolderPaths, IReadOnlyCollection configPaths, string outputFolder) + { + var messages = new List(); + + if (configPaths.IsNotNullAndNotEmpty()) + { + if (projectFolderPaths.Count != configPaths.Count) + messages.Add("The number of project folders and config paths must be the same."); + } + + return new ValidationResult(messages); + } +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.Cli/Ui/Validation/IGenerateValidator.cs b/src/TypeGen/TypeGen.Cli/Ui/Validation/IGenerateValidator.cs new file mode 100644 index 00000000..061d4283 --- /dev/null +++ b/src/TypeGen/TypeGen.Cli/Ui/Validation/IGenerateValidator.cs @@ -0,0 +1,8 @@ +using System.Collections.Generic; + +namespace TypeGen.Cli.Ui.Validation; + +internal interface IGenerateValidator +{ + ValidationResult Validate(bool verbose, IReadOnlyCollection projectFolderPaths, IReadOnlyCollection configPaths, string outputFolder); +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.Cli/Ui/Validation/ValidationResult.cs b/src/TypeGen/TypeGen.Cli/Ui/Validation/ValidationResult.cs new file mode 100644 index 00000000..c05f8876 --- /dev/null +++ b/src/TypeGen/TypeGen.Cli/Ui/Validation/ValidationResult.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using TypeGen.Core.Extensions; + +namespace TypeGen.Cli.Ui.Validation; + +internal class ValidationResult +{ + public bool IsSuccess { get; } + public IReadOnlyCollection Messages { get; } + + public ValidationResult(IEnumerable messages) + { + var messagesList = messages.ToList(); + + if (messagesList.IsNullOrEmpty()) + { + IsSuccess = true; + Messages = Array.Empty(); + } + else + { + IsSuccess = false; + Messages = messagesList.ToList(); + } + } + + public void Match(Action onSuccess, Action> onFailure) + { + if (IsSuccess) + onSuccess(); + else + onFailure(Messages); + } +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.Core.Test/Extensions/StringExtensionsTest.cs b/src/TypeGen/TypeGen.Core.Test/Extensions/StringExtensionsTest.cs index 415d9c78..97f49f4e 100644 --- a/src/TypeGen/TypeGen.Core.Test/Extensions/StringExtensionsTest.cs +++ b/src/TypeGen/TypeGen.Core.Test/Extensions/StringExtensionsTest.cs @@ -53,7 +53,17 @@ public void RemoveTypeArity_Test(string input, string expectedResult) [InlineData("NonGenericType", "NonGenericType")] public void RemoveTypeGenericComponent_Test(string input, string expectedResult) { - string actualResult = input.RemoveTypeGenericComponent(); + string actualResult = input.RemoveTsTypeNameGenericComponent(); + Assert.Equal(expectedResult, actualResult); + } + + [Theory] + [InlineData("Foo.Bar.Baz", "Foo.Bar.Baz")] + [InlineData("Foo.Bar.Baz`2", "Foo.Bar.Baz`2")] + [InlineData("Foo.Bar.Baz`2[[System.Int32, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.String, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]", "Foo.Bar.Baz`2")] + public void RemoveGenericArgumentsFromTypeName_Test(string input, string expectedResult) + { + string actualResult = input.RemoveGenericArgumentsFromTypeName(); Assert.Equal(expectedResult, actualResult); } diff --git a/src/TypeGen/TypeGen.IntegrationTest/ExceptionShouldContainInitialType.cs b/src/TypeGen/TypeGen.Core.Test/Generator/ExceptionShouldContainInitialType.cs similarity index 85% rename from src/TypeGen/TypeGen.IntegrationTest/ExceptionShouldContainInitialType.cs rename to src/TypeGen/TypeGen.Core.Test/Generator/ExceptionShouldContainInitialType.cs index da7269d7..b014e8b1 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/ExceptionShouldContainInitialType.cs +++ b/src/TypeGen/TypeGen.Core.Test/Generator/ExceptionShouldContainInitialType.cs @@ -1,12 +1,10 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -using TypeGen.Core; -using TypeGen.Core.Generator; using TypeGen.Core.SpecGeneration; using Xunit; -namespace TypeGen.IntegrationTest; +namespace TypeGen.Core.Test.Generator; public class ExceptionShouldContainInitialType { @@ -18,10 +16,10 @@ public async Task ShouldThrowExceptionWithInitialTypeNameWhenDependencyTypeFails { var type = typeof(TestExceptions); var spec = new ExceptionsGenerationSpec(); - var generator = new Generator(); + var generator = new Core.Generator.Generator(); try { - await generator.GenerateAsync(new[] { spec }); + await generator.GenerateAsync(spec); Assert.True(true, "Exception not thrown"); } catch (CoreException ex) diff --git a/src/TypeGen/TypeGen.Core.Test/Generator/GeneratorOptionsTest.cs b/src/TypeGen/TypeGen.Core.Test/Generator/GeneratorOptionsTest.cs new file mode 100644 index 00000000..9121acd1 --- /dev/null +++ b/src/TypeGen/TypeGen.Core.Test/Generator/GeneratorOptionsTest.cs @@ -0,0 +1,51 @@ +using System; +using FluentAssertions; +using TypeGen.Core.Generator; +using Xunit; + +namespace TypeGen.Core.Test.Generator; + +public class GeneratorOptionsTest +{ + [Theory] + [InlineData(typeof(IConvertible), true)] + [InlineData(typeof(GeneratorOptionsTest), false)] + public void IsTypeBlacklisted_Test(Type type, bool expected) + { + var sut = new GeneratorOptions(); + sut.IsTypeBlacklisted(type).Should().Be(expected); + } + + [Theory] + [InlineData(typeof(IConvertible), false)] + [InlineData(typeof(GeneratorOptionsTest), true)] + public void IsTypeNotBlacklisted_Test(Type type, bool expected) + { + var sut = new GeneratorOptions(); + sut.IsTypeNotBlacklisted(type).Should().Be(expected); + } + + [Fact] + public void IsTypeBlacklisted_Should_MatchTypeFullName() + { + // arrange + var sut = new GeneratorOptions(); + sut.TypeBlacklist.Add(GetType().FullName); + + // act + // assert + sut.IsTypeBlacklisted(GetType()).Should().BeTrue(); + } + + [Fact] + public void IsTypeBlacklisted_Should_MatchTypeName() + { + // arrange + var sut = new GeneratorOptions(); + sut.TypeBlacklist.Add(GetType().Name); + + // act + // assert + sut.IsTypeBlacklisted(GetType()).Should().BeTrue(); + } +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.Core.Test/Generator/GeneratorTest.cs b/src/TypeGen/TypeGen.Core.Test/Generator/GeneratorTest.cs new file mode 100644 index 00000000..5f90aa58 --- /dev/null +++ b/src/TypeGen/TypeGen.Core.Test/Generator/GeneratorTest.cs @@ -0,0 +1,71 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using FluentAssertions; +using NSubstitute; +using TypeGen.Core.Generator; +using TypeGen.Core.SpecGeneration; +using TypeGen.Core.Storage; +using Xunit; + +namespace TypeGen.Core.Test.Generator; + +public class GeneratorTest +{ + [Fact] + public async Task generation_callbacks_should_be_invoked_in_correct_order() + { + // arrange + var options = new GeneratorOptions(); + var fileSystemMock = Substitute.For(); + var generator = new Core.Generator.Generator(options, fileSystemMock); + var generationSpec = new GenerationCallbackOrderSpec(); + + // act + await generator.GenerateAsync(generationSpec); + + // assert + generationSpec.CallbackOrder.Should().BeEquivalentTo(new[] + { + nameof(GenerationSpec.OnBeforeGeneration), + nameof(GenerationSpec.OnBeforeBarrelGeneration), + nameof(GenerationSpec.OnAfterGeneration), + }); + } + + private class GenerationCallbackOrderSpec : GenerationSpec + { + public List CallbackOrder { get; } = new(); + + public GenerationCallbackOrderSpec() + { + AddClass(); + } + + public override void OnBeforeGeneration(OnBeforeGenerationArgs args) + { + base.OnBeforeGeneration(args); + CallbackOrder.Add(nameof(OnBeforeGeneration)); + Console.WriteLine(nameof(OnBeforeGeneration)); + } + + public override void OnBeforeBarrelGeneration(OnBeforeBarrelGenerationArgs args) + { + base.OnBeforeBarrelGeneration(args); + CallbackOrder.Add(nameof(OnBeforeBarrelGeneration)); + Console.WriteLine(nameof(OnBeforeBarrelGeneration)); + } + + public override void OnAfterGeneration(OnAfterGenerationArgs args) + { + base.OnAfterGeneration(args); + CallbackOrder.Add(nameof(OnAfterGeneration)); + Console.WriteLine(nameof(OnAfterGeneration)); + } + + private class Foo + { + public string HelloWorld { get; set; } + } + } +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.Core.Test/Generator/Services/TypeServiceTest.cs b/src/TypeGen/TypeGen.Core.Test/Generator/Services/TypeServiceTest.cs index effcfcf5..7290a9c0 100644 --- a/src/TypeGen/TypeGen.Core.Test/Generator/Services/TypeServiceTest.cs +++ b/src/TypeGen/TypeGen.Core.Test/Generator/Services/TypeServiceTest.cs @@ -98,18 +98,6 @@ public void GetTsBuiltInTypeName_TypeGiven_TsBuiltInTypeNameReturned(Type type, Assert.Equal(expectedResult, actualResult); } - [Theory] - [InlineData(typeof(MyClass), true)] - [InlineData(typeof(MyEnum), false)] - [InlineData(typeof(TsClass), true)] - [InlineData(typeof(TsInterface), false)] - [InlineData(typeof(TsEnum), false)] - public void IsTsClass_TypeGiven_DeterminedIfTsClass(Type type, bool expectedResult) - { - bool actualResult = _typeService.IsTsClass(type); - Assert.Equal(expectedResult, actualResult); - } - [Theory] [InlineData(typeof(MyClass), false)] [InlineData(typeof(MyEnum), false)] diff --git a/src/TypeGen/TypeGen.Core.Test/SpecGeneration/ClassSpecBuilderTest.cs b/src/TypeGen/TypeGen.Core.Test/SpecGeneration/ClassSpecBuilderTest.cs index 9b4ce06d..367d9ba1 100644 --- a/src/TypeGen/TypeGen.Core.Test/SpecGeneration/ClassSpecBuilderTest.cs +++ b/src/TypeGen/TypeGen.Core.Test/SpecGeneration/ClassSpecBuilderTest.cs @@ -57,6 +57,32 @@ public void CustomBase_Invoked_SpecUpdated() Assert.Equal(isDefaultExport, ((TsCustomBaseAttribute)attribute).IsDefaultExport); } + [Fact] + public void CustomHeader_Invoked_SpecUpdated() + { + const string header = "header"; + var spec = new TypeSpec(new ExportTsInterfaceAttribute()); + var builder = new ClassSpecBuilder(spec); + + builder.CustomHeader(header); + + var attribute = spec.ExportAttribute; + Assert.Equal(header, attribute.CustomHeader); + } + + [Fact] + public void CustomBody_Invoked_SpecUpdated() + { + const string body = "body"; + var spec = new TypeSpec(new ExportTsInterfaceAttribute()); + var builder = new ClassSpecBuilder(spec); + + builder.CustomBody(body); + + var attribute = spec.ExportAttribute; + Assert.Equal(body, attribute.CustomBody); + } + [Theory] [InlineData(true)] [InlineData(false)] @@ -256,4 +282,4 @@ public void Undefined_Invoked_SpecUpdated() Assert.IsType(attribute); } } -} \ No newline at end of file +} diff --git a/src/TypeGen/TypeGen.Core.Test/SpecGeneration/Generic/InterfaceSpecBuilderTest.cs b/src/TypeGen/TypeGen.Core.Test/SpecGeneration/Generic/InterfaceSpecBuilderTest.cs index 9f53e440..b7bd798a 100644 --- a/src/TypeGen/TypeGen.Core.Test/SpecGeneration/Generic/InterfaceSpecBuilderTest.cs +++ b/src/TypeGen/TypeGen.Core.Test/SpecGeneration/Generic/InterfaceSpecBuilderTest.cs @@ -85,6 +85,32 @@ public void CustomBase_Invoked_SpecUpdated() Assert.Equal(isDefaultExport, ((TsCustomBaseAttribute)attribute).IsDefaultExport); } + [Fact] + public void CustomHeader_Invoked_SpecUpdated() + { + const string header = "header"; + var spec = new TypeSpec(new ExportTsInterfaceAttribute()); + var builder = new TypeGen.Core.SpecGeneration.Builders.Generic.InterfaceSpecBuilder(spec); + + builder.CustomHeader(header); + + var attribute = spec.ExportAttribute; + Assert.Equal(header, attribute.CustomHeader); + } + + [Fact] + public void CustomBody_Invoked_SpecUpdated() + { + const string body = "body"; + var spec = new TypeSpec(new ExportTsInterfaceAttribute()); + var builder = new TypeGen.Core.SpecGeneration.Builders.Generic.InterfaceSpecBuilder(spec); + + builder.CustomBody(body); + + var attribute = spec.ExportAttribute; + Assert.Equal(body, attribute.CustomBody); + } + [Theory] [InlineData(true)] [InlineData(false)] @@ -271,4 +297,4 @@ public void Undefined_Invoked_SpecUpdated() Assert.IsType(attribute); } } -} \ No newline at end of file +} diff --git a/src/TypeGen/TypeGen.Core/AssemblyInfo.cs b/src/TypeGen/TypeGen.Core/AssemblyInfo.cs index 99437e4c..ace9df75 100644 --- a/src/TypeGen/TypeGen.Core/AssemblyInfo.cs +++ b/src/TypeGen/TypeGen.Core/AssemblyInfo.cs @@ -1,7 +1,8 @@ -using System.Runtime.CompilerServices; +using System.Reflection; +using System.Runtime.CompilerServices; [assembly: InternalsVisibleTo("TypeGen.Cli")] -[assembly: InternalsVisibleTo("TypeGen.IntegrationTest")] +[assembly: InternalsVisibleTo("TypeGen.FileContentTest")] [assembly: InternalsVisibleTo("TypeGen.Cli.Test")] [assembly: InternalsVisibleTo("TypeGen.Core.Test")] -[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")] +[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")] \ No newline at end of file diff --git a/src/TypeGen/TypeGen.Core/Extensions/AttributeExtensions.cs b/src/TypeGen/TypeGen.Core/Extensions/AttributeExtensions.cs new file mode 100644 index 00000000..2fe17ac7 --- /dev/null +++ b/src/TypeGen/TypeGen.Core/Extensions/AttributeExtensions.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using TypeGen.Core.TypeAnnotations; +using TypeGen.Core.Validation; + +namespace TypeGen.Core.Extensions; + +internal static class AttributeExtensions +{ + public static IEnumerable GetTypeGenAttributes(this IEnumerable @this) + { + Requires.NotNull(@this, nameof(@this)); + return @this.Where(x => x.IsTypeGenAttribute()); + } + + public static bool IsTypeGenAttribute(this Attribute @this) + { + Requires.NotNull(@this, nameof(@this)); + var tgAttributesNamespace = typeof(ExportAttribute).Namespace; + return @this.GetType().Namespace == tgAttributesNamespace; + } +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.Core/Extensions/EnumerableExtensions.cs b/src/TypeGen/TypeGen.Core/Extensions/EnumerableExtensions.cs index 6d92316b..e9b11923 100644 --- a/src/TypeGen/TypeGen.Core/Extensions/EnumerableExtensions.cs +++ b/src/TypeGen/TypeGen.Core/Extensions/EnumerableExtensions.cs @@ -60,6 +60,15 @@ public static bool IsNullOrEmpty(this IEnumerable enumerable) return !enumerable.Any(); } + /// + /// Checks if an enumerable is not null and not empty + /// + /// + /// + /// + public static bool IsNotNullAndNotEmpty(this IEnumerable enumerable) + => !enumerable.IsNullOrEmpty(); + /// /// Checks if the is empty. /// @@ -76,5 +85,8 @@ public static bool IsNullOrEmpty(this IEnumerable enumerable) /// /// public static bool None(this IEnumerable enumerable, Func predicate) => !enumerable.Any(predicate); + + public static bool Contains(this IEnumerable enumerable, Func predicate) + => enumerable.Where(predicate).Any(); } } diff --git a/src/TypeGen/TypeGen.Core/Extensions/StringExtensions.cs b/src/TypeGen/TypeGen.Core/Extensions/StringExtensions.cs index d70117dd..23688010 100644 --- a/src/TypeGen/TypeGen.Core/Extensions/StringExtensions.cs +++ b/src/TypeGen/TypeGen.Core/Extensions/StringExtensions.cs @@ -62,16 +62,27 @@ public static string RemoveTypeArity(this string value) } /// - /// Removes generic component from the type, e.g. "MyType" becomes "MyType" + /// Removes generic component from the TypeScript type name, e.g. "MyType<T>" becomes "MyType" /// /// /// - public static string RemoveTypeGenericComponent(this string value) + public static string RemoveTsTypeNameGenericComponent(this string value) { Requires.NotNull(value, nameof(value)); return value.Split('<')[0]; } + /// + /// Removes generic arguments from the type name. + /// + /// + /// + public static string RemoveGenericArgumentsFromTypeName(this string value) + { + Requires.NotNull(value, nameof(value)); + return value.Split('[')[0]; + } + /// /// Gets the type from a TypeScript type union indicated by the given index. /// E.g. the following string: "Date | null | undefined" is a TS type union with 3 types and each of these types can be accessed with an index from 0 to 2. diff --git a/src/TypeGen/TypeGen.Core/Extensions/TypeExtensions.cs b/src/TypeGen/TypeGen.Core/Extensions/TypeExtensions.cs index 0845fc76..e18be5b5 100644 --- a/src/TypeGen/TypeGen.Core/Extensions/TypeExtensions.cs +++ b/src/TypeGen/TypeGen.Core/Extensions/TypeExtensions.cs @@ -104,11 +104,22 @@ public static bool IsStatic(this MemberInfo memberInfo) public static bool IsNullable(this MemberInfo memberInfo) { Requires.NotNull(memberInfo, nameof(memberInfo)); - + var contextualMember = memberInfo.ToContextualAccessor(); return contextualMember.Nullability == Nullability.Nullable; } - + + /// + /// Checks if a property or field is nullable + /// + /// + /// + public static bool IsNullable(this Type type) + { + Requires.NotNull(type, nameof(type)); + return Nullable.GetUnderlyingType(type) != null; + } + /// /// Maps an enumerable to an enumerable of the elements' type names /// diff --git a/src/TypeGen/TypeGen.Core/Generator/Generator.cs b/src/TypeGen/TypeGen.Core/Generator/Generator.cs index f4a37242..35b56a69 100644 --- a/src/TypeGen/TypeGen.Core/Generator/Generator.cs +++ b/src/TypeGen/TypeGen.Core/Generator/Generator.cs @@ -109,6 +109,26 @@ public Task> GenerateAsync(IEnumerable gener { return Task.Run(() => Generate(generationSpecs)); } + + /// + /// Generates TypeScript files from a GenerationSpec + /// + /// + /// Generated TypeScript file paths (relative to the Options.BaseOutputDirectory) + public Task> GenerateAsync(params GenerationSpec[] generationSpecs) + { + return GenerateAsync((IEnumerable)generationSpecs); + } + + /// + /// Generates TypeScript sources from GenerationSpecs. + /// + /// + /// Generated TypeScript file paths (relative to the Options.BaseOutputDirectory) + public IEnumerable Generate(params GenerationSpec[] generationSpecs) + { + return Generate((IEnumerable)generationSpecs); + } /// /// Generates TypeScript sources from GenerationSpecs. @@ -118,31 +138,34 @@ public Task> GenerateAsync(IEnumerable gener public IEnumerable Generate(IEnumerable generationSpecs) { Requires.NotNullOrEmpty(generationSpecs, nameof(generationSpecs)); - + + generationSpecs = generationSpecs.ToList(); var files = new List(); _generationContext = new GenerationContext(_fileSystem); // generate types + foreach (GenerationSpec generationSpec in generationSpecs) + generationSpec.OnBeforeGeneration(new OnBeforeGenerationArgs(Options)); + foreach (GenerationSpec generationSpec in generationSpecs) { _metadataReaderFactory.GenerationSpec = generationSpec; - generationSpec.OnBeforeGeneration(new OnBeforeGenerationArgs(Options)); - + foreach (KeyValuePair kvp in generationSpec.TypeSpecs) - files.AddRange(GenerateTypePrivate(kvp.Key)); + files.AddRange(GenerateMarkedType(kvp.Key)); } files = files.Distinct().ToList(); // generate barrels - if (Options.CreateIndexFile) - files.AddRange(GenerateIndexFile(files)); - foreach (GenerationSpec generationSpec in generationSpecs) generationSpec.OnBeforeBarrelGeneration(new OnBeforeBarrelGenerationArgs(Options, files.ToList())); + if (Options.CreateIndexFile) + files.AddRange(GenerateIndexFile(files)); + foreach (GenerationSpec generationSpec in generationSpecs) foreach (BarrelSpec barrelSpec in generationSpec.BarrelSpecs) files.AddRange(GenerateBarrel(barrelSpec)); @@ -152,7 +175,7 @@ public IEnumerable Generate(IEnumerable generationSpecs) return files; } - + /// /// Generates TypeScript files from an assembly /// @@ -303,8 +326,10 @@ private IEnumerable GenerateIndexFile(IEnumerable generatedFiles return new[] { filename }; } - private IEnumerable GenerateTypePrivate(Type type) + private IEnumerable GenerateMarkedType(Type type) { + if (Options.IsTypeBlacklisted(type)) return Enumerable.Empty(); + IEnumerable files = Enumerable.Empty(); _generationContext.BeginTypeGeneration(type); @@ -342,7 +367,7 @@ private IEnumerable GenerateType(Type type) return GenerateEnum(type, enumAttribute); } - return GenerateNotMarked(type, Options.BaseOutputDirectory); + return GenerateNotMarkedType(type, Options.BaseOutputDirectory); } /// @@ -351,8 +376,10 @@ private IEnumerable GenerateType(Type type) /// /// /// Generated TypeScript file paths (relative to the Options.BaseOutputDirectory) - private IEnumerable GenerateNotMarked(Type type, string outputDirectory) + private IEnumerable GenerateNotMarkedType(Type type, string outputDirectory) { + if (Options.IsTypeBlacklisted(type)) return Enumerable.Empty(); + var typeInfo = type.GetTypeInfo(); if (typeInfo.IsClass || typeInfo.IsStruct()) { @@ -406,11 +433,15 @@ private IEnumerable GenerateClass(Type type, ExportTsClassAttribute clas // generate the file content string tsTypeName = _typeService.GetTsTypeName(type, true); - string tsTypeNameFirstPart = tsTypeName.RemoveTypeGenericComponent(); + string tsTypeNameFirstPart = tsTypeName.RemoveTsTypeNameGenericComponent(); string filePath = GetFilePath(type, outputDir); string filePathRelative = GetRelativeFilePath(type, outputDir); - string customHead = _tsContentGenerator.GetCustomHead(filePath); - string customBody = _tsContentGenerator.GetCustomBody(filePath, Options.TabLength); + string customInFileHead = _tsContentGenerator.GetCustomHead(filePath); + string customAttributeHead = classAttribute.CustomHeader; + string customHead = string.Join(Environment.NewLine, new[] { customInFileHead, customAttributeHead }.Where(i => !string.IsNullOrWhiteSpace(i))); + string customInFileBody = _tsContentGenerator.GetCustomBody(filePath, Options.TabLength); + string customAttributeBody = classAttribute.CustomBody; + string customBody = string.Join(Environment.NewLine, new[] { customInFileBody, customAttributeBody }.Where(i => !string.IsNullOrWhiteSpace(i))); var tsDoc = GetTsDocForType(type); var content = _typeService.UseDefaultExport(type) ? @@ -455,11 +486,15 @@ private IEnumerable GenerateInterface(Type type, ExportTsInterfaceAttrib // generate the file content string tsTypeName = _typeService.GetTsTypeName(type, true); - string tsTypeNameFirstPart = tsTypeName.RemoveTypeGenericComponent(); + string tsTypeNameFirstPart = tsTypeName.RemoveTsTypeNameGenericComponent(); string filePath = GetFilePath(type, outputDir); string filePathRelative = GetRelativeFilePath(type, outputDir); - string customHead = _tsContentGenerator.GetCustomHead(filePath); - string customBody = _tsContentGenerator.GetCustomBody(filePath, Options.TabLength); + string customInFileHead = _tsContentGenerator.GetCustomHead(filePath); + string customAttributeHead = interfaceAttribute.CustomHeader; + string customHead = string.Join(Environment.NewLine, new[] { customInFileHead, customAttributeHead }.Where(i => !string.IsNullOrWhiteSpace(i))); + string customInFileBody = _tsContentGenerator.GetCustomBody(filePath, Options.TabLength); + string customAttributeBody = interfaceAttribute.CustomBody; + string customBody = string.Join(Environment.NewLine, new[] { customInFileBody, customAttributeBody }.Where(i => !string.IsNullOrWhiteSpace(i))); var tsDoc = GetTsDocForType(type); var content = _typeService.UseDefaultExport(type) ? @@ -533,6 +568,7 @@ private bool IsReadonlyTsProperty(MemberInfo memberInfo) private string GetClassPropertyText(Type type, MemberInfo memberInfo) { LogClassPropertyWarnings(memberInfo); + if (_typeService.MemberTypeContainsBlacklistedType(memberInfo)) ThrowMemberTypeIsBlacklisted(memberInfo); string modifiers = Options.ExplicitPublicAccessor ? "public " : ""; @@ -569,6 +605,16 @@ private string GetClassPropertyText(Type type, MemberInfo memberInfo) return _templateService.FillClassPropertyTemplate(modifiers, name, typeName, typeUnions, isOptional, tsDoc); } + private static void ThrowMemberTypeIsBlacklisted(MemberInfo memberInfo) + { + throw new CoreException($"Member '{memberInfo.DeclaringType.FullName}.{memberInfo.Name}'" + + $" contains a blacklisted type. Possible solutions:" + + $"{Environment.NewLine}1. Remove the type from blacklist." + + $"{Environment.NewLine}2. Remove the member." + + $"{Environment.NewLine}3. Add TsTypeAttribute to the member." + + $"{Environment.NewLine}4. Create custom type mapping for the blacklisted type."); + } + private string GetTsDocForMember(Type type, MemberInfo memberInfo) { if (_generationContext.DoesNotContainXmlDocForAssembly(type.Assembly)) return ""; @@ -625,6 +671,7 @@ private string GetClassPropertiesText(Type type) private string GetInterfacePropertyText(Type type, MemberInfo memberInfo) { LogInterfacePropertyWarnings(memberInfo); + if (_typeService.MemberTypeContainsBlacklistedType(memberInfo)) ThrowMemberTypeIsBlacklisted(memberInfo); string modifiers = ""; if (IsReadonlyTsProperty(memberInfo)) modifiers += "readonly "; @@ -721,7 +768,7 @@ private string GetEnumMembersText(Type type, bool asUnionType) } /// - /// Generates type dependencies' files for a given type + /// Generates type dependencies for a given type /// /// /// @@ -729,40 +776,28 @@ private string GetEnumMembersText(Type type, bool asUnionType) private IEnumerable GenerateTypeDependencies(Type type, string outputDir) { var generatedFiles = new List(); - IEnumerable typeDependencies = _typeDependencyService.GetTypeDependencies(type); + var typeDependencies = _typeDependencyService.GetTypeDependencies(type); - foreach (TypeDependencyInfo typeDependencyInfo in typeDependencies) + foreach (var typeDependencyInfo in typeDependencies) { - Type typeDependency = typeDependencyInfo.Type; - - // dependency type TypeScript file generation + var typeDependency = typeDependencyInfo.Type; + if (typeDependency.HasExportAttribute(_metadataReaderFactory.GetInstance()) || _generationContext.IsTypeGenerated(typeDependency)) continue; + + var defaultOutputAttribute = typeDependencyInfo.MemberAttributes + ?.FirstOrDefault(a => a is TsDefaultTypeOutputAttribute) + as TsDefaultTypeOutputAttribute; - // dependency HAS an ExportTsX attribute (AND hasn't been generated yet) - if (typeDependency.HasExportAttribute(_metadataReaderFactory.GetInstance()) && !_generationContext.IsTypeGenerated(typeDependency)) + var defaultOutputDir = defaultOutputAttribute?.OutputDir ?? outputDir; + + _generationContext.AddGeneratedType(typeDependency); + + try { - _generationContext.AddGeneratedType(typeDependency); - generatedFiles.AddRange(GenerateTypePrivate(typeDependency)); + generatedFiles.AddRange(GenerateNotMarkedType(typeDependency, defaultOutputDir)); } - - // dependency DOESN'T HAVE an ExportTsX attribute (AND hasn't been generated for the currently generated type yet) - if (!typeDependency.HasExportAttribute(_metadataReaderFactory.GetInstance()) && !_generationContext.IsTypeGeneratedForType(typeDependency)) + catch (Exception ex) { - var defaultOutputAttribute = typeDependencyInfo.MemberAttributes - ?.FirstOrDefault(a => a is TsDefaultTypeOutputAttribute) - as TsDefaultTypeOutputAttribute; - - string defaultOutputDir = defaultOutputAttribute?.OutputDir ?? outputDir; - - _generationContext.AddGeneratedType(typeDependency); - - try - { - generatedFiles.AddRange(GenerateNotMarked(typeDependency, defaultOutputDir)); - } - catch (CoreException ex) - { - throw new CoreException($"Error generating dependencies types for {type.FullName}", ex); - } + throw new CoreException($"Error generating type dependencies for '{type.FullName}'", ex); } } diff --git a/src/TypeGen/TypeGen.Core/Generator/GeneratorOptions.cs b/src/TypeGen/TypeGen.Core/Generator/GeneratorOptions.cs index 17e70545..1aaacd4f 100644 --- a/src/TypeGen/TypeGen.Core/Generator/GeneratorOptions.cs +++ b/src/TypeGen/TypeGen.Core/Generator/GeneratorOptions.cs @@ -1,7 +1,11 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; using TypeGen.Core.Converters; +using TypeGen.Core.Extensions; using TypeGen.Core.Generator.Services; using TypeGen.Core.Utils; +using TypeGen.Core.Validation; namespace TypeGen.Core.Generator { @@ -34,6 +38,23 @@ public class GeneratorOptions public static bool DefaultExportTypesAsInterfacesByDefault => false; public static bool DefaultUseImportType => false; + public static HashSet DefaultTypeBlacklist => new(new [] + { + "System.IAsyncDisposable", + typeof(ICloneable).FullName, + typeof(IComparable).FullName, + typeof(IComparable<>).FullName, + typeof(IConvertible).FullName, + typeof(IDisposable).FullName, + typeof(IEquatable<>).FullName, + typeof(IFormattable).FullName, + "System.IParsable`1", + typeof(ISerializable).FullName, + "System.ISpanFormattable", + "System.ISpanParsable`1", + typeof(ValueType).FullName + }); + /// /// A collection (chain) of converters used for converting C# file names to TypeScript file names /// @@ -45,7 +66,7 @@ public class GeneratorOptions public TypeNameConverterCollection TypeNameConverters { get; set; } = DefaultTypeNameConverters; /// - /// A collection (chain) of converters used for converting C# class property names to TypeScript class property names + /// A collection (chain) of converters used for converting C# property names to TypeScript property names /// public MemberNameConverterCollection PropertyNameConverters { get; set; } = DefaultPropertyNameConverters; @@ -162,5 +183,33 @@ public string BaseOutputDirectory /// public bool UseImportType { get; set; } = DefaultUseImportType; + /// + /// Specifies types which should not be generated. + /// + public HashSet TypeBlacklist { get; set; } = DefaultTypeBlacklist; + + /// + /// Checks if the type is on the type blacklist. + /// + /// The type. + /// true if the type is on the blacklist, false otherwise + public bool IsTypeBlacklisted(Type type) + { + Requires.NotNull(type, nameof(type)); + + if (type.IsGenericParameter) return false; + + var nameWithNamespace = $"{type.Namespace}.{type.Name}"; + + return TypeBlacklist.Contains(nameWithNamespace.RemoveGenericArgumentsFromTypeName()) + || TypeBlacklist.Contains(type.Name.RemoveGenericArgumentsFromTypeName()); + } + + /// + /// Checks if the type is not on the type blacklist. + /// + /// The type. + /// true if the type is not on the blacklist, false otherwise + public bool IsTypeNotBlacklisted(Type type) => !IsTypeBlacklisted(type); } } diff --git a/src/TypeGen/TypeGen.Core/Generator/Services/ITypeService.cs b/src/TypeGen/TypeGen.Core/Generator/Services/ITypeService.cs index a58e378a..f39856e7 100644 --- a/src/TypeGen/TypeGen.Core/Generator/Services/ITypeService.cs +++ b/src/TypeGen/TypeGen.Core/Generator/Services/ITypeService.cs @@ -20,14 +20,6 @@ internal interface ITypeService /// one of: object, bool, string, int, long, float, double, decimal; or any type specified in GeneratorOptions.CustomMappings /// TypeScript type name. Null if the passed type cannot be represented as a TypeScript simple type. string GetTsBuiltInTypeName(Type type); - - /// - /// Determines whether the type represents a TypeScript class - /// - /// - /// True if the type represents a TypeScript class; false otherwise - /// Thrown if the type is null - bool IsTsClass(Type type); /// /// Determines whether the type represents a TypeScript class @@ -72,7 +64,7 @@ internal interface ITypeService /// /// /// - bool IsIngoredGenericConstarint(Type type); + bool IsIgnoredGenericConstarint(Type type); /// /// Gets TypeScript type name for a type @@ -126,6 +118,8 @@ internal interface ITypeService bool UseDefaultExport(Type type); IEnumerable GetTypeUnions(MemberInfo memberInfo); - IEnumerable GetInterfaces(Type type); + IEnumerable GetImplementedInterfaces(Type type); + bool TypeContainsBlacklistedType(Type type); + bool MemberTypeContainsBlacklistedType(MemberInfo memberInfo); } } \ No newline at end of file diff --git a/src/TypeGen/TypeGen.Core/Generator/Services/TsContentGenerator.cs b/src/TypeGen/TypeGen.Core/Generator/Services/TsContentGenerator.cs index cc8d66b7..490ee4fe 100644 --- a/src/TypeGen/TypeGen.Core/Generator/Services/TsContentGenerator.cs +++ b/src/TypeGen/TypeGen.Core/Generator/Services/TsContentGenerator.cs @@ -112,7 +112,7 @@ public string GetExtendsForInterfacesText(Type type) Requires.NotNull(type, nameof(type)); Requires.NotNull(GeneratorOptions.TypeNameConverters, nameof(GeneratorOptions.TypeNameConverters)); - IEnumerable baseTypes = _typeService.GetInterfaces(type); + IEnumerable baseTypes = _typeService.GetImplementedInterfaces(type); if (!baseTypes.Any()) return ""; IEnumerable baseTypeNames = baseTypes.Select(baseType => _typeService.GetTsTypeName(baseType, true)); @@ -129,10 +129,10 @@ public string GetImplementsText(Type type) Requires.NotNull(type, nameof(type)); Requires.NotNull(GeneratorOptions.TypeNameConverters, nameof(GeneratorOptions.TypeNameConverters)); - IEnumerable baseTypes = _typeService.GetInterfaces(type); - if (!baseTypes.Any()) return ""; + IEnumerable implementedInterfaces = _typeService.GetImplementedInterfaces(type); + if (!implementedInterfaces.Any()) return ""; - IEnumerable baseTypeNames = baseTypes.Select(baseType => _typeService.GetTsTypeName(baseType, true)); + IEnumerable baseTypeNames = implementedInterfaces.Select(baseType => _typeService.GetTsTypeName(baseType, true)); return _templateService.GetImplementsText(baseTypeNames); } diff --git a/src/TypeGen/TypeGen.Core/Generator/Services/TypeDependencyService.cs b/src/TypeGen/TypeGen.Core/Generator/Services/TypeDependencyService.cs index f1dacb74..d1932d24 100644 --- a/src/TypeGen/TypeGen.Core/Generator/Services/TypeDependencyService.cs +++ b/src/TypeGen/TypeGen.Core/Generator/Services/TypeDependencyService.cs @@ -55,6 +55,7 @@ public IEnumerable GetTypeDependencies(Type type) .Concat(GetMemberTypeDependencies(type)) .Distinct(new TypeDependencyInfoTypeComparer()) .Where(t => t.Type != type) + .Where(t => GeneratorOptions.IsTypeNotBlacklisted(t.Type)) .ToList(); } @@ -76,7 +77,7 @@ private IEnumerable GetGenericTypeDefinitionDependencies(Typ var stripped = _typeService.StripNullable(constraint); Type baseFlatType = _typeService.GetFlatType(stripped); - if (_typeService.IsIngoredGenericConstarint(baseFlatType)) + if (_typeService.IsIgnoredGenericConstarint(baseFlatType)) continue; result.AddRange(GetFlatTypeDependencies(baseFlatType)); @@ -112,7 +113,7 @@ private IEnumerable GetImplementedInterfaceTypesDependencies { if (_metadataReaderFactory.GetInstance().GetAttribute(type) != null) return Enumerable.Empty(); - var baseTypes = _typeService.GetInterfaces(type); + var baseTypes = _typeService.GetImplementedInterfaces(type); if (!baseTypes.Any()) return Enumerable.Empty(); return baseTypes diff --git a/src/TypeGen/TypeGen.Core/Generator/Services/TypeService.cs b/src/TypeGen/TypeGen.Core/Generator/Services/TypeService.cs index 8b2d7087..4a9649b5 100644 --- a/src/TypeGen/TypeGen.Core/Generator/Services/TypeService.cs +++ b/src/TypeGen/TypeGen.Core/Generator/Services/TypeService.cs @@ -15,7 +15,7 @@ namespace TypeGen.Core.Generator.Services /// internal class TypeService : ITypeService { - private static HashSet IgnoredGenricConstraints = new HashSet + private static HashSet IgnoredGenricConstraints = new() { typeof(ValueType) }; @@ -45,44 +45,45 @@ public bool IsEnumType(Type type) return type.IsEnum; } - private string GenerateCustomType(Type t, string customType) + private string ConstructTsTypeName(Type type, string tsTypeNameTemplate) { // For custom types mappings ending with <>, construct the relevant generic custom type - if (customType.EndsWith("<>")) + if (tsTypeNameTemplate.EndsWith("<>")) { - customType = customType.Substring(0, customType.Length - 2); // Strip <> - string[] genericArgumentNames = t.GetGenericArguments() + tsTypeNameTemplate = tsTypeNameTemplate.Substring(0, tsTypeNameTemplate.Length - 2); // Strip <> + string[] genericArgumentNames = type.GetGenericArguments() .Select(t2 => t2.IsGenericParameter ? t2.Name : GetTsTypeName(t2, false)) .ToArray(); - customType = $"{customType}<{string.Join(", ", genericArgumentNames)}>"; + tsTypeNameTemplate = $"{tsTypeNameTemplate}<{string.Join(", ", genericArgumentNames)}>"; } // For custom types not ending with <>, leave the custom type as-is (not generic) - return customType; + return tsTypeNameTemplate; } - private bool TryGetCustomTypeMapping(Type t, out string customType) + private bool TryGetCustomTypeMapping(Type type, out string tsTypeName) { - if (t != null && t.FullName != null && GeneratorOptions.CustomTypeMappings != null) + if (type is { FullName: not null } && GeneratorOptions.CustomTypeMappings != null) { // Check for given type as-is (and combined generics) - if (GeneratorOptions.CustomTypeMappings.TryGetValue(t.FullName, out string customTypeMappingValue)) + if (GeneratorOptions.CustomTypeMappings.TryGetValue(type.FullName, out var customTypeMappingValue)) { - customType = GenerateCustomType(t, customTypeMappingValue); + tsTypeName = ConstructTsTypeName(type, customTypeMappingValue); return true; } - else if (t.IsConstructedGenericType) + + if (type.IsConstructedGenericType) { // Check for generic type - Type genericType = t.GetGenericTypeDefinition(); + Type genericType = type.GetGenericTypeDefinition(); if (GeneratorOptions.CustomTypeMappings.TryGetValue(genericType.FullName, out customTypeMappingValue)) { - customType = GenerateCustomType(t, customTypeMappingValue); + tsTypeName = ConstructTsTypeName(type, customTypeMappingValue); return true; } } } - customType = null; + tsTypeName = null; return false; } @@ -126,29 +127,12 @@ public string GetTsBuiltInTypeName(Type type) return null; } } - - /// - public bool IsTsClass(Type type) - { - Requires.NotNull(type, nameof(type)); - TypeInfo typeInfo = type.GetTypeInfo(); - - if (!typeInfo.IsClass) return false; - - var exportAttribute = MetadataReader.GetAttribute(type); - return exportAttribute == null || exportAttribute is ExportTsClassAttribute; - } /// public bool IsTsInterface(Type type) { Requires.NotNull(type, nameof(type)); - TypeInfo typeInfo = type.GetTypeInfo(); - - if (!typeInfo.IsClass) return false; - - var exportAttribute = MetadataReader.GetAttribute(type); - return exportAttribute is ExportTsInterfaceAttribute; + return MetadataReader.GetAttribute(type) != null; } /// @@ -157,9 +141,7 @@ public Type GetMemberType(MemberInfo memberInfo) Requires.NotNull(memberInfo, nameof(memberInfo)); if (!memberInfo.Is() && !memberInfo.Is()) - { throw new ArgumentException($"{memberInfo} must be either a FieldInfo or a PropertyInfo"); - } return memberInfo is PropertyInfo info ? StripNullable(info.PropertyType) @@ -195,7 +177,7 @@ public bool IsCustomGenericType(Type type) } /// - public bool IsIngoredGenericConstarint(Type type) + public bool IsIgnoredGenericConstarint(Type type) { return IgnoredGenricConstraints.Contains(type); } @@ -215,36 +197,13 @@ public string GetTsTypeName(Type type, bool forTypeDeclaration = false) type = StripNullable(type); - if (TryGetCustomTypeMapping(type, out string customType)) - { - return customType; - } - - // handle simple types - if (IsTsBuiltInType(type)) - { - return GetTsBuiltInTypeName(type); - } - - // handle collection types - if (IsCollectionType(type)) - { - return GetTsCollectionTypeName(type); - } - - // handle dictionaries - if (IsDictionaryType(type)) - { - return GetTsDictionaryTypeName(type); - } - - // handle custom generic types - if (IsCustomGenericType(type)) - { - return GetGenericTsTypeName(type, forTypeDeclaration); - } + if (TryGetCustomTypeMapping(type, out string customType)) return customType; + + if (IsTsBuiltInType(type)) return GetTsBuiltInTypeName(type); + if (IsCollectionType(type)) return GetTsCollectionTypeName(type); + if (IsDictionaryType(type)) return GetTsDictionaryTypeName(type); + if (IsCustomGenericType(type)) return GetGenericTsTypeName(type, forTypeDeclaration); - // handle custom types & generic parameters string typeNameNoArity = type.Name.RemoveTypeArity(); return type.IsGenericParameter ? typeNameNoArity : GeneratorOptions.TypeNameConverters.Convert(typeNameNoArity, type); } @@ -259,17 +218,48 @@ public string GetTsTypeName(MemberInfo memberInfo) if (typeAttribute != null) { if (string.IsNullOrWhiteSpace(typeAttribute.TypeName)) - { throw new CoreException($"No type specified in TsType attribute for member '{memberInfo.Name}' declared in '{memberInfo.DeclaringType?.FullName}'"); - } Type type = GetMemberType(memberInfo); - return GenerateCustomType(type, typeAttribute.TypeName); + return ConstructTsTypeName(type, typeAttribute.TypeName); } return GetTsTypeNameForMember(memberInfo); } + public bool MemberTypeContainsBlacklistedType(MemberInfo memberInfo) + { + Requires.NotNull(memberInfo, nameof(memberInfo)); + + var type = GetMemberType(memberInfo); + return TypeContainsBlacklistedType(type); + } + + public bool TypeContainsBlacklistedType(Type type) + { + Requires.NotNull(type, nameof(type)); + + if (type.IsGenericParameter) return false; + + type = StripNullable(type); + if (GeneratorOptions.IsTypeBlacklisted(type)) return true; + + if (IsCollectionType(type)) + { + var elementType = GetTsCollectionElementType(type); + if (GeneratorOptions.IsTypeBlacklisted(elementType)) return true; + } + + if (type.IsGenericType) + { + return type.GetGenericArguments() + .Select(TypeContainsBlacklistedType) + .Any(x => x); + } + + return false; + } + /// /// Gets TypeScript type name for a member /// @@ -278,17 +268,11 @@ public string GetTsTypeName(MemberInfo memberInfo) /// Thrown when member or typeNameConverters is null private string GetTsTypeNameForMember(MemberInfo memberInfo) { - // special case - dynamic property/field - if (memberInfo.GetCustomAttribute() != null) - { return "any"; - } - - // otherwise, resolve by type Type type = GetMemberType(memberInfo); - return GetTsTypeName(type); + return GetTsTypeName(type, false); } #if NET6_0_OR_GREATER @@ -438,7 +422,7 @@ private string GetGenericTsTypeNameForDeclaration(Type type) /// private string GetGenericTsTypeConstraintsForDeclaration(Type type) { - var constraints = type.GetGenericParameterConstraints().Where(t => !IsIngoredGenericConstarint(t)).ToArray(); + var constraints = type.GetGenericParameterConstraints().Where(t => !IsIgnoredGenericConstarint(t)).ToArray(); if (constraints.Length < 1) return type.Name; @@ -487,8 +471,7 @@ private string GetGenericTsTypeNameDeclarationAgnostic(Type type, Func private Type GetTsCollectionElementType(Type type) { - // handle array types - Type elementType = type.GetElementType(); + Type elementType = type.GetElementType(); // this is for arrays if (elementType != null) { return StripNullable(elementType); @@ -496,10 +479,8 @@ private Type GetTsCollectionElementType(Type type) switch (type.Name) { - // handle IEnumerable<> case "IEnumerable`1": return StripNullable(type.GetGenericArguments()[0]); - // handle IEnumerable case "IEnumerable": return typeof(object); } @@ -540,25 +521,35 @@ public Type StripNullable(Type type) public Type GetBaseType(Type type) { Requires.NotNull(type, nameof(type)); - - Type baseType = type.GetTypeInfo().BaseType; - if (baseType == null || baseType == typeof(object)) return null; - - if (IsTsClass(type) && IsTsInterface(baseType)) throw new CoreException($"Attempted to generate class '{type.FullName}' which extends an interface '{baseType.FullName}', which is not a valid inheritance chain in TypeScript"); + var baseType = type.GetTypeInfo().BaseType; + + if (IsNullOrObjectOrBlacklisted(baseType) || IsTsInterface(baseType)) + return null; return baseType; } /// - public IEnumerable GetInterfaces(Type type) + public IEnumerable GetImplementedInterfaces(Type type) { Requires.NotNull(type, nameof(type)); + + var result = type.GetTypeInfo().ImplementedInterfaces + .Where(GeneratorOptions.IsTypeNotBlacklisted); - IEnumerable baseTypes = type.GetTypeInfo().ImplementedInterfaces; - - // if (IsTsClass(type) && IsTsInterface(baseType)) throw new CoreException($"Attempted to generate class '{type.FullName}' which extends an interface '{baseType.FullName}', which is not a valid inheritance chain in TypeScript"); + var baseType = type.GetTypeInfo().BaseType; + if (IsNotNullAndNotObjectAndNotBlacklisted(baseType) && IsTsInterface(baseType)) + result = result.Concat(new[] { baseType }); - return baseTypes; + return result; } + + private bool IsNullOrObjectOrBlacklisted(Type type) => + type == null + || type == typeof(object) + || GeneratorOptions.IsTypeBlacklisted(type); + + private bool IsNotNullAndNotObjectAndNotBlacklisted(Type type) => + !IsNullOrObjectOrBlacklisted(type); } } diff --git a/src/TypeGen/TypeGen.Core/Logging/ConsoleLogger.cs b/src/TypeGen/TypeGen.Core/Logging/ConsoleLogger.cs index b4e758ff..d8d7df0a 100644 --- a/src/TypeGen/TypeGen.Core/Logging/ConsoleLogger.cs +++ b/src/TypeGen/TypeGen.Core/Logging/ConsoleLogger.cs @@ -1,5 +1,6 @@ using System; using TypeGen.Core.Validation; +using static TypeGen.Core.Utils.ConsoleUtils; namespace TypeGen.Core.Logging { @@ -8,11 +9,11 @@ namespace TypeGen.Core.Logging /// public class ConsoleLogger : ILogger { - private readonly bool _verbose; + public LogLevel MinLevel { get; set; } - public ConsoleLogger(bool verbose) + public ConsoleLogger(LogLevel minLevel = LogLevel.Info) { - _verbose = verbose; + MinLevel = minLevel; } /// @@ -24,26 +25,16 @@ public void Log(string message, LogLevel level) { Requires.NotNullOrEmpty(message, nameof(message)); - LogLevel minLevel = _verbose ? LogLevel.Debug : LogLevel.Info; + if (level < MinLevel) return; - if (level < minLevel) return; - - ConsoleColor oldColor = Console.ForegroundColor; - - switch (level) + var color = level switch { - case LogLevel.Warning: - message = "WARNING: " + message; - Console.ForegroundColor = ConsoleColor.Yellow; - break; - case LogLevel.Error: - Console.ForegroundColor = ConsoleColor.Red; - break; - } + LogLevel.Warning => ConsoleColor.Yellow, + LogLevel.Error => ConsoleColor.Red, + _ => Console.ForegroundColor + }; - Console.WriteLine(message); - - Console.ForegroundColor = oldColor; + WithColor(color, () => Console.WriteLine(message)); } } } diff --git a/src/TypeGen/TypeGen.Core/Logging/ILogger.cs b/src/TypeGen/TypeGen.Core/Logging/ILogger.cs index f2e55b47..c20c48c0 100644 --- a/src/TypeGen/TypeGen.Core/Logging/ILogger.cs +++ b/src/TypeGen/TypeGen.Core/Logging/ILogger.cs @@ -2,6 +2,7 @@ { public interface ILogger { + LogLevel MinLevel { get; set; } void Log(string message, LogLevel level); } } \ No newline at end of file diff --git a/src/TypeGen/TypeGen.Core/Shims/IsExternalInit.cs b/src/TypeGen/TypeGen.Core/Shims/IsExternalInit.cs new file mode 100644 index 00000000..499252ad --- /dev/null +++ b/src/TypeGen/TypeGen.Core/Shims/IsExternalInit.cs @@ -0,0 +1,3 @@ +namespace System.Runtime.CompilerServices; + +internal static class IsExternalInit {} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.Core/SpecGeneration/Builders/ClassSpecBuilderBase.cs b/src/TypeGen/TypeGen.Core/SpecGeneration/Builders/ClassSpecBuilderBase.cs index a39408a3..15d9866d 100644 --- a/src/TypeGen/TypeGen.Core/SpecGeneration/Builders/ClassSpecBuilderBase.cs +++ b/src/TypeGen/TypeGen.Core/SpecGeneration/Builders/ClassSpecBuilderBase.cs @@ -6,6 +6,8 @@ namespace TypeGen.Core.SpecGeneration.Builders { public abstract class ClassSpecBuilderBase : SpecBuilderBase, ICustomBaseTrait, + ICustomHeaderTrait, + ICustomBodyTrait, IDefaultExportTrait, IDefaultTypeOutputTrait, IDefaultValueTrait, @@ -26,6 +28,8 @@ public abstract class ClassSpecBuilderBase : SpecBuilderBase, where TSelf : SpecBuilderBase { private readonly CustomBaseTrait _customBaseTrait; + private readonly CustomBodyTrait _customBodyTrait; + private readonly CustomHeaderTrait _customHeaderTrait; private readonly DefaultExportTrait _defaultExportTrait; private readonly DefaultTypeOutputTrait _defaultTypeOutputTrait; private readonly DefaultValueTrait _defaultValueTrait; @@ -48,6 +52,8 @@ internal ClassSpecBuilderBase(TypeSpec typeSpec) : base(typeSpec) { MemberTrait = new MemberTrait(this as TSelf, typeSpec); _customBaseTrait = new CustomBaseTrait(this as TSelf, typeSpec); + _customBodyTrait = new CustomBodyTrait(this as TSelf, typeSpec); + _customHeaderTrait = new CustomHeaderTrait(this as TSelf, typeSpec); _defaultExportTrait = new DefaultExportTrait(this as TSelf, typeSpec); _defaultTypeOutputTrait = new DefaultTypeOutputTrait(this as TSelf, typeSpec, MemberTrait); _defaultValueTrait = new DefaultValueTrait(this as TSelf, typeSpec, MemberTrait); @@ -75,7 +81,15 @@ public TSelf CustomBase(string @base = null, string importPath = null, string or public TSelf CustomBase(string @base = null, string importPath = null, string originalTypeName = null, bool isDefaultExport = false, params ImplementedInterface[] implementedInterfaces) => _customBaseTrait.CustomBase(@base, importPath, originalTypeName, isDefaultExport, implementedInterfaces); - + + /// + public TSelf CustomBody(string body) + => _customBodyTrait.CustomBody(body); + + /// + public TSelf CustomHeader(string header) + => _customHeaderTrait.CustomHeader(header); + /// public TSelf DefaultExport(bool enabled = true) => _defaultExportTrait.DefaultExport(enabled); diff --git a/src/TypeGen/TypeGen.Core/SpecGeneration/Builders/InterfaceSpecBuilderBase.cs b/src/TypeGen/TypeGen.Core/SpecGeneration/Builders/InterfaceSpecBuilderBase.cs index a7558fa4..54efcd60 100644 --- a/src/TypeGen/TypeGen.Core/SpecGeneration/Builders/InterfaceSpecBuilderBase.cs +++ b/src/TypeGen/TypeGen.Core/SpecGeneration/Builders/InterfaceSpecBuilderBase.cs @@ -9,6 +9,8 @@ namespace TypeGen.Core.SpecGeneration.Builders /// public abstract class InterfaceSpecBuilderBase : SpecBuilderBase, ICustomBaseTrait, + ICustomHeaderTrait, + ICustomBodyTrait, IDefaultExportTrait, IDefaultTypeOutputTrait, IDefaultValueTrait, @@ -28,6 +30,8 @@ public abstract class InterfaceSpecBuilderBase : SpecBuilderBase, where TSelf : SpecBuilderBase { private readonly CustomBaseTrait _customBaseTrait; + private readonly CustomBodyTrait _customBodyTrait; + private readonly CustomHeaderTrait _customHeaderTrait; private readonly DefaultExportTrait _defaultExportTrait; private readonly DefaultTypeOutputTrait _defaultTypeOutputTrait; private readonly DefaultValueTrait _defaultValueTrait; @@ -49,6 +53,8 @@ internal InterfaceSpecBuilderBase(TypeSpec typeSpec) : base(typeSpec) { MemberTrait = new MemberTrait(this as TSelf, typeSpec); _customBaseTrait = new CustomBaseTrait(this as TSelf, typeSpec); + _customBodyTrait = new CustomBodyTrait(this as TSelf, typeSpec); + _customHeaderTrait = new CustomHeaderTrait(this as TSelf, typeSpec); _defaultExportTrait = new DefaultExportTrait(this as TSelf, typeSpec); _defaultTypeOutputTrait = new DefaultTypeOutputTrait(this as TSelf, typeSpec, MemberTrait); _defaultValueTrait = new DefaultValueTrait(this as TSelf, typeSpec, MemberTrait); @@ -75,6 +81,14 @@ public TSelf CustomBase(string @base = null, string importPath = null, string or public TSelf CustomBase(string @base = null, string importPath = null, string originalTypeName = null, bool isDefaultExport = false, params ImplementedInterface[] implementedInterfaces) => _customBaseTrait.CustomBase(@base, importPath, originalTypeName, isDefaultExport, implementedInterfaces); + + /// + public TSelf CustomBody(string body) + => _customBodyTrait.CustomBody(body); + + /// + public TSelf CustomHeader(string header) + => _customHeaderTrait.CustomHeader(header); /// public TSelf DefaultExport(bool enabled = true) => _defaultExportTrait.DefaultExport(enabled); @@ -131,4 +145,4 @@ public TSelf Type(string typeName, string importPath = null, string originalType /// public TSelf Undefined() => _undefinedTrait.Undefined(); } -} \ No newline at end of file +} diff --git a/src/TypeGen/TypeGen.Core/SpecGeneration/Builders/Traits/CustomBodyTrait.cs b/src/TypeGen/TypeGen.Core/SpecGeneration/Builders/Traits/CustomBodyTrait.cs new file mode 100644 index 00000000..90624a88 --- /dev/null +++ b/src/TypeGen/TypeGen.Core/SpecGeneration/Builders/Traits/CustomBodyTrait.cs @@ -0,0 +1,21 @@ +using TypeGen.Core.TypeAnnotations; + +namespace TypeGen.Core.SpecGeneration.Builders.Traits; + +internal class CustomBodyTrait : ICustomBodyTrait +{ + private readonly TSpecBuilder _this; + private readonly TypeSpec _typeSpec; + + public CustomBodyTrait(TSpecBuilder @this, TypeSpec typeSpec) + { + _this = @this; + _typeSpec = typeSpec; + } + + public TSpecBuilder CustomBody(string body) + { + _typeSpec.SetCustomBody(body); + return _this; + } +} diff --git a/src/TypeGen/TypeGen.Core/SpecGeneration/Builders/Traits/CustomHeaderTrait.cs b/src/TypeGen/TypeGen.Core/SpecGeneration/Builders/Traits/CustomHeaderTrait.cs new file mode 100644 index 00000000..5ece8940 --- /dev/null +++ b/src/TypeGen/TypeGen.Core/SpecGeneration/Builders/Traits/CustomHeaderTrait.cs @@ -0,0 +1,21 @@ +using TypeGen.Core.TypeAnnotations; + +namespace TypeGen.Core.SpecGeneration.Builders.Traits; + +internal class CustomHeaderTrait : ICustomHeaderTrait +{ + private readonly TSpecBuilder _this; + private readonly TypeSpec _typeSpec; + + public CustomHeaderTrait(TSpecBuilder @this, TypeSpec typeSpec) + { + _this = @this; + _typeSpec = typeSpec; + } + + public TSpecBuilder CustomHeader(string header) + { + _typeSpec.SetCustomHeader(header); + return _this; + } +} diff --git a/src/TypeGen/TypeGen.Core/SpecGeneration/Builders/Traits/ICustomBodyTrait.cs b/src/TypeGen/TypeGen.Core/SpecGeneration/Builders/Traits/ICustomBodyTrait.cs new file mode 100644 index 00000000..58dd12ce --- /dev/null +++ b/src/TypeGen/TypeGen.Core/SpecGeneration/Builders/Traits/ICustomBodyTrait.cs @@ -0,0 +1,10 @@ +namespace TypeGen.Core.SpecGeneration.Builders.Traits; + +internal interface ICustomBodyTrait +{ + /// + /// Indicates type has a custom body (equivalent of TsExportAttribute's CustomBody). + /// + /// The current instance of . + TSpecBuilder CustomBody(string body); +} diff --git a/src/TypeGen/TypeGen.Core/SpecGeneration/Builders/Traits/ICustomHeaderTrait.cs b/src/TypeGen/TypeGen.Core/SpecGeneration/Builders/Traits/ICustomHeaderTrait.cs new file mode 100644 index 00000000..ab69a726 --- /dev/null +++ b/src/TypeGen/TypeGen.Core/SpecGeneration/Builders/Traits/ICustomHeaderTrait.cs @@ -0,0 +1,10 @@ +namespace TypeGen.Core.SpecGeneration.Builders.Traits; + +internal interface ICustomHeaderTrait +{ + /// + /// Indicates type has a custom header (equivalent of TsExportAttribute's CustomHeader). + /// + /// The current instance of . + TSpecBuilder CustomHeader(string header); +} diff --git a/src/TypeGen/TypeGen.Core/SpecGeneration/GenerationSpec.cs b/src/TypeGen/TypeGen.Core/SpecGeneration/GenerationSpec.cs index 8d984ac8..bf9b75d2 100644 --- a/src/TypeGen/TypeGen.Core/SpecGeneration/GenerationSpec.cs +++ b/src/TypeGen/TypeGen.Core/SpecGeneration/GenerationSpec.cs @@ -1,7 +1,9 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Linq; using System.Reflection; +using TypeGen.Core.Generator; using TypeGen.Core.SpecGeneration.Builders; using TypeGen.Core.SpecGeneration.Builders.Generic; using TypeGen.Core.TypeAnnotations; @@ -22,14 +24,27 @@ protected GenerationSpec() BarrelSpecs = new List(); } + /// + /// The callback invoked before any files from the current generation spec are generated. + /// + /// The callback arguments. public virtual void OnBeforeGeneration(OnBeforeGenerationArgs args) { } + /// + /// The callback invoked after the translated TypeScript files are generated from the current generation spec, + /// but before any barrel files are generated for the current generation spec. + /// + /// The callback arguments. public virtual void OnBeforeBarrelGeneration(OnBeforeBarrelGenerationArgs args) { } + /// + /// The callback invoked after all files from the current generation spec are generated. + /// + /// The callback arguments. public virtual void OnAfterGeneration(OnAfterGenerationArgs args) { } diff --git a/src/TypeGen/TypeGen.Core/SpecGeneration/TypeSpec.cs b/src/TypeGen/TypeGen.Core/SpecGeneration/TypeSpec.cs index f8f1f67e..89d131c6 100644 --- a/src/TypeGen/TypeGen.Core/SpecGeneration/TypeSpec.cs +++ b/src/TypeGen/TypeGen.Core/SpecGeneration/TypeSpec.cs @@ -21,7 +21,7 @@ public TypeSpec(ExportAttribute exportAttribute) _memberAttributes = new Dictionary>(); _additionalAttributes = new List(); } - + public void AddMember(string memberName) => _memberAttributes[memberName] = new List(); public void AddCustomBaseAttribute(string @base = null, string importPath = null, string originalTypeName = null, bool isDefaultExport = false, @@ -32,6 +32,8 @@ public void AddCustomBaseAttribute(string @base = null, string importPath = null public void AddDefaultValueAttribute(string memberName, string defaultValue) => AddMemberAttribute(memberName, new TsDefaultValueAttribute(defaultValue)); public void AddIgnoreAttribute(string memberName) => AddMemberAttribute(memberName, new TsIgnoreAttribute()); public void AddIgnoreBaseAttribute() => AddAdditionalAttribute(new TsIgnoreBaseAttribute()); + public void SetCustomHeader(string header) { ExportAttribute.CustomHeader = header; } + public void SetCustomBody(string body) { ExportAttribute.CustomBody = body; } public void AddMemberNameAttribute(string memberName, string name) => AddMemberAttribute(memberName, new TsMemberNameAttribute(name)); public void AddNotNullAttribute(string memberName) => AddMemberAttribute(memberName, new TsNotNullAttribute()); public void AddNotReadonlyAttribute(string memberName) => AddMemberAttribute(memberName, new TsNotReadonlyAttribute()); @@ -48,8 +50,8 @@ public void AddTypeAttribute(string memberName, string typeName, string importPa public void AddTypeUnionsAttribute(string memberName, IEnumerable typeUnions) => AddMemberAttribute(memberName, new TsTypeUnionsAttribute(typeUnions)); public void AddTypeUnionsAttribute(string memberName, params string[] typeUnions) => AddMemberAttribute(memberName, new TsTypeUnionsAttribute(typeUnions)); public void AddUndefinedAttribute(string memberName) => AddMemberAttribute(memberName, new TsUndefinedAttribute()); - + private void AddMemberAttribute(string memberName, Attribute attribute) => MemberAttributes[memberName].Add(attribute); private void AddAdditionalAttribute(Attribute attribute) => _additionalAttributes.Add(attribute); } -} \ No newline at end of file +} diff --git a/src/TypeGen/TypeGen.Core/TypeAnnotations/ExportAttribute.cs b/src/TypeGen/TypeGen.Core/TypeAnnotations/ExportAttribute.cs index 509dc0a4..be5b55d2 100644 --- a/src/TypeGen/TypeGen.Core/TypeAnnotations/ExportAttribute.cs +++ b/src/TypeGen/TypeGen.Core/TypeAnnotations/ExportAttribute.cs @@ -11,7 +11,9 @@ namespace TypeGen.Core.TypeAnnotations public abstract class ExportAttribute : Attribute { private string _outputDir; - + private string _customHeader; + private string _customBody; + /// /// TypeScript file output directory /// @@ -20,5 +22,23 @@ public string OutputDir get => _outputDir; set => _outputDir = FileSystemUtils.AsDirectory(value); } + + /// + /// TypeScript file custom header + /// + public string CustomHeader + { + get => _customHeader; + set => _customHeader = value; + } + + /// + /// TypeScript file custom body + /// + public string CustomBody + { + get => _customBody; + set => _customBody = value; + } } } diff --git a/src/TypeGen/TypeGen.Core/TypeGen.Core.csproj b/src/TypeGen/TypeGen.Core/TypeGen.Core.csproj index be93202d..57345189 100644 --- a/src/TypeGen/TypeGen.Core/TypeGen.Core.csproj +++ b/src/TypeGen/TypeGen.Core/TypeGen.Core.csproj @@ -1,8 +1,10 @@ - + netstandard2.0;net7.0 TypeGen.Core.xml latest + 4.5.0.0 + 4.5.0.0 diff --git a/src/TypeGen/TypeGen.Core/TypeModel/Conversion/ReflectionToCsModelConverter.cs b/src/TypeGen/TypeGen.Core/TypeModel/Conversion/ReflectionToCsModelConverter.cs new file mode 100644 index 00000000..cb9189dd --- /dev/null +++ b/src/TypeGen/TypeGen.Core/TypeModel/Conversion/ReflectionToCsModelConverter.cs @@ -0,0 +1,160 @@ +#nullable enable +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using TypeGen.Core.Extensions; +using TypeGen.Core.TypeModel.Csharp; +using TypeGen.Core.Validation; + +namespace TypeGen.Core.TypeModel.Conversion; + +internal class ReflectionToCsModelConverter +{ + public static CsType ConvertType(Type type) + { + Requires.NotNull(type, nameof(type)); + + return type.IsNullable() + ? ConvertTypePrivate(Nullable.GetUnderlyingType(type)!, true) + : ConvertTypePrivate(type, false); + } + + private static CsType ConvertTypePrivate(Type type, bool isNullable) + => type switch + { + { IsGenericParameter: true } => ConvertGenericParameter(type), + { IsPrimitive: true } => ConvertPrimitive(type, isNullable), + { IsEnum: true } => ConvertEnum(type, isNullable), + { IsClass: true } => ConvertClass(type, isNullable), + { IsInterface: true } => ConvertInterface(type, isNullable), + not null when type.IsStruct() => ConvertStruct(type, isNullable), + _ => throw new ArgumentException($"Type '{type!.FullName}' is not supported. Only classes, interfaces, structs, enums and generic parameters can be translated to TypeScript.") + }; + + private static CsGenericParameter ConvertGenericParameter(Type type) + { + return new CsGenericParameter(type.Name); + } + + private static CsPrimitive ConvertPrimitive(Type type, bool isNullable) + { + return new CsPrimitive(type.FullName, type.Name, isNullable); + } + + private static CsEnum ConvertEnum(Type type, bool isNullable) + { + var values = GetEnumValues(type); + var tgAttributes = GetTgAttributes(type); + + return new CsEnum(type.FullName, type.Name, tgAttributes, values, isNullable); + } + + private static CsGpType ConvertClass(Type type, bool isNullable) + { + var genericTypes = GetGenericTypes(type); + var @base = GetBase(type); + var implementedInterfaces = GetImplementedInterfaces(type); + var tgAttributes = GetTgAttributes(type); + var fields = GetFields(type); + var properties = GetProperties(type); + + return CsGpType.Class(type.FullName!, + type.Name, + isNullable, + genericTypes, + @base, + implementedInterfaces, + fields, + properties, + tgAttributes); + } + + private static CsGpType ConvertInterface(Type type, bool isNullable) + { + var genericTypes = GetGenericTypes(type); + var @base = GetBase(type); + var tgAttributes = GetTgAttributes(type); + var properties = GetProperties(type); + + return CsGpType.Interface(type.FullName!, + type.Name, + isNullable, + genericTypes, + @base, + properties, + tgAttributes); + } + + private static CsGpType ConvertStruct(Type type, bool isNullable) + { + var genericTypes = GetGenericTypes(type); + var tgAttributes = GetTgAttributes(type); + var fields = GetFields(type); + var properties = GetProperties(type); + + return CsGpType.Struct(type.FullName!, + type.Name, + isNullable, + genericTypes, + fields, + properties, + tgAttributes); + } + + private static IReadOnlyCollection GetEnumValues(Type type) + { + return type.GetFields(BindingFlags.Public | BindingFlags.Static) + .Select(fieldInfo => + { + var enumValue = fieldInfo.GetValue(null); + var underlyingValue = Convert.ChangeType(enumValue, Enum.GetUnderlyingType(type)); + return new CsEnumValue(fieldInfo.Name, underlyingValue); + }) + .ToList(); + } + + private static IReadOnlyCollection GetGenericTypes(Type type) + { + var reflectionGenericTypes = type.IsGenericTypeDefinition + ? type.GetTypeInfo().GenericTypeParameters + : type.GenericTypeArguments; + return reflectionGenericTypes.Select(ConvertType).ToList(); + } + + private static CsGpType? GetBase(Type type) + => type.BaseType != null ? (CsGpType)ConvertType(type.BaseType) : null; + + private static IReadOnlyCollection GetImplementedInterfaces(Type type) + => type.GetInterfaces() + .Select(ConvertType) + .Cast() + .ToList(); + + private static IReadOnlyCollection GetTgAttributes(Type type) + => type.GetCustomAttributes().GetTypeGenAttributes().ToList(); + + private static IReadOnlyCollection GetProperties(Type type) + => type.GetProperties() + .Select(propertyInfo => + { + var propertyType = ConvertType(propertyInfo.PropertyType); + var name = propertyInfo.Name; + var defaultValue = propertyInfo.GetValue(null); + return new CsProperty(propertyType, name, defaultValue); + }) + .ToList(); + + private static IReadOnlyCollection GetFields(Type type) + { + return type.GetFields() + .Select(fieldInfo => + { + var fieldType = ConvertType(fieldInfo.FieldType); + var name = fieldInfo.Name; + var defaultValue = fieldInfo.GetValue(null); + return new CsField(fieldType, name, defaultValue); + }) + .ToList(); + } +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.Core/TypeModel/Csharp/CsEnum.cs b/src/TypeGen/TypeGen.Core/TypeModel/Csharp/CsEnum.cs new file mode 100644 index 00000000..8f60e5b2 --- /dev/null +++ b/src/TypeGen/TypeGen.Core/TypeModel/Csharp/CsEnum.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; + +namespace TypeGen.Core.TypeModel.Csharp; + +internal class CsEnum : CsType +{ + public string FullName { get; } + public IReadOnlyCollection TgAttributes { get; } + public IReadOnlyCollection Values { get; } + + public CsEnum(string fullName, + string name, + IReadOnlyCollection tgAttributes, + IReadOnlyCollection values, + bool isNullable) + : base(name, isNullable) + { + FullName = fullName; + Values = values; + TgAttributes = tgAttributes; + } + + +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.Core/TypeModel/Csharp/CsEnumValue.cs b/src/TypeGen/TypeGen.Core/TypeModel/Csharp/CsEnumValue.cs new file mode 100644 index 00000000..872ca696 --- /dev/null +++ b/src/TypeGen/TypeGen.Core/TypeModel/Csharp/CsEnumValue.cs @@ -0,0 +1,13 @@ +namespace TypeGen.Core.TypeModel.Csharp; + +internal class CsEnumValue +{ + public string Name { get; } + public object UnderlyingValue { get; } + + public CsEnumValue(string name, object underlyingValue) + { + Name = name; + UnderlyingValue = underlyingValue; + } +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.Core/TypeModel/Csharp/CsField.cs b/src/TypeGen/TypeGen.Core/TypeModel/Csharp/CsField.cs new file mode 100644 index 00000000..a44cb233 --- /dev/null +++ b/src/TypeGen/TypeGen.Core/TypeModel/Csharp/CsField.cs @@ -0,0 +1,15 @@ +namespace TypeGen.Core.TypeModel.Csharp; + +internal class CsField +{ + public CsType Type { get; } + public string Name { get; } + public object DefaultValue { get; } + + public CsField(CsType type, string name, object defaultValue) + { + Type = type; + Name = name; + DefaultValue = defaultValue; + } +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.Core/TypeModel/Csharp/CsGenericParameter.cs b/src/TypeGen/TypeGen.Core/TypeModel/Csharp/CsGenericParameter.cs new file mode 100644 index 00000000..6872a9d1 --- /dev/null +++ b/src/TypeGen/TypeGen.Core/TypeModel/Csharp/CsGenericParameter.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace TypeGen.Core.TypeModel.Csharp; + +internal class CsGenericParameter : CsType +{ + public CsGenericParameter(string name) : base(name, false) + { + } +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.Core/TypeModel/Csharp/CsGpType.cs b/src/TypeGen/TypeGen.Core/TypeModel/Csharp/CsGpType.cs new file mode 100644 index 00000000..bd5351a2 --- /dev/null +++ b/src/TypeGen/TypeGen.Core/TypeModel/Csharp/CsGpType.cs @@ -0,0 +1,98 @@ +#nullable enable +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using TypeGen.Core.Extensions; + +namespace TypeGen.Core.TypeModel.Csharp; + +/// +/// General purpose C# type. Covers classes, interfaces, structs, records etc. +/// +internal class CsGpType : CsType +{ + public string FullName { get; init; } + public IReadOnlyCollection GenericTypes { get; init; } + public CsGpType? Base { get; init; } + public IReadOnlyCollection ImplementedInterfaces { get; init; } + public IReadOnlyCollection Fields { get; init; } + public IReadOnlyCollection Properties { get; init; } + public IReadOnlyCollection TgAttributes { get; init; } + + public bool IsNonDictionaryEnumerable => + FullName != typeof(string).FullName + && !IsDictionary + && (ImplementsInterface(typeof(IEnumerable).FullName!) || FullName.StartsWith(typeof(IEnumerable).FullName!)); + + public bool IsDictionary => + ImplementsInterface(typeof(IDictionary<,>).FullName!) + || FullName.StartsWith(typeof(IDictionary<,>).FullName!) + || ImplementsInterface(typeof(IDictionary).FullName!) + || FullName.StartsWith(typeof(IDictionary).FullName!); + + private CsGpType(string name, bool isNullable) + : base(name, isNullable) + { + } + + public static CsGpType Class(string fullName, + string name, + bool isNullable, + IReadOnlyCollection genericTypes, + CsGpType? @base, + IReadOnlyCollection implementedInterfaces, + IReadOnlyCollection fields, + IReadOnlyCollection properties, + IReadOnlyCollection tgAttributes) + { + return new CsGpType(name, isNullable) + { + FullName = fullName, + GenericTypes = genericTypes, + Base = @base, + ImplementedInterfaces = implementedInterfaces, + Fields = fields, + Properties = properties, + TgAttributes = tgAttributes + }; + } + + public static CsGpType Interface(string fullName, + string name, + bool isNullable, + IReadOnlyCollection genericTypes, + CsGpType? @base, + IReadOnlyCollection properties, + IReadOnlyCollection tgAttributes) + { + return new CsGpType(name, isNullable) + { + FullName = fullName, + GenericTypes = genericTypes, + Base = @base, + Properties = properties, + TgAttributes = tgAttributes + }; + } + + public static CsGpType Struct(string fullName, + string name, + bool isNullable, + IReadOnlyCollection genericTypes, + IReadOnlyCollection fields, + IReadOnlyCollection properties, + IReadOnlyCollection tgAttributes) + { + return new CsGpType(name, isNullable) + { + FullName = fullName, + GenericTypes = genericTypes, + Fields = fields, + Properties = properties, + TgAttributes = tgAttributes + }; + } + + private bool ImplementsInterface(string fullName) => ImplementedInterfaces.Contains(x => x.FullName == fullName); +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.Core/TypeModel/Csharp/CsPrimitive.cs b/src/TypeGen/TypeGen.Core/TypeModel/Csharp/CsPrimitive.cs new file mode 100644 index 00000000..602460da --- /dev/null +++ b/src/TypeGen/TypeGen.Core/TypeModel/Csharp/CsPrimitive.cs @@ -0,0 +1,12 @@ +namespace TypeGen.Core.TypeModel.Csharp; + +internal class CsPrimitive : CsType +{ + public string FullName { get; } + + public CsPrimitive(string fullName, string name, bool isNullable) + : base(name, isNullable) + { + FullName = fullName; + } +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.Core/TypeModel/Csharp/CsProperty.cs b/src/TypeGen/TypeGen.Core/TypeModel/Csharp/CsProperty.cs new file mode 100644 index 00000000..a808a3d0 --- /dev/null +++ b/src/TypeGen/TypeGen.Core/TypeModel/Csharp/CsProperty.cs @@ -0,0 +1,15 @@ +namespace TypeGen.Core.TypeModel.Csharp; + +internal class CsProperty +{ + public CsType Type { get; } + public string Name { get; } + public object DefaultValue { get; } + + public CsProperty(CsType type, string name, object defaultValue) + { + Type = type; + Name = name; + DefaultValue = defaultValue; + } +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.Core/TypeModel/Csharp/CsType.cs b/src/TypeGen/TypeGen.Core/TypeModel/Csharp/CsType.cs new file mode 100644 index 00000000..9333cc96 --- /dev/null +++ b/src/TypeGen/TypeGen.Core/TypeModel/Csharp/CsType.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; + +namespace TypeGen.Core.TypeModel.Csharp; + +internal abstract class CsType +{ + public string Name { get; } + public bool IsNullable { get; } + + protected CsType(string name, bool isNullable) + { + Name = name; + IsNullable = isNullable; + } +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.Core/TypeModel/TypeScript/TsClass.cs b/src/TypeGen/TypeGen.Core/TypeModel/TypeScript/TsClass.cs new file mode 100644 index 00000000..84baaa5e --- /dev/null +++ b/src/TypeGen/TypeGen.Core/TypeModel/TypeScript/TsClass.cs @@ -0,0 +1,16 @@ +using System.Collections.Generic; + +namespace TypeGen.Core.TypeModel.TypeScript; + +internal class TsClass : TsType +{ + public IReadOnlyCollection Imports { get; } + public string Base { get; } + public IReadOnlyCollection ImplementedInterfaces { get; set; } + public IReadOnlyCollection Properties { get; set; } + + public TsClass(string name, IReadOnlyCollection imports) + : base(name) + { + } +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.Core/TypeModel/TypeScript/TsEnum.cs b/src/TypeGen/TypeGen.Core/TypeModel/TypeScript/TsEnum.cs new file mode 100644 index 00000000..f109f808 --- /dev/null +++ b/src/TypeGen/TypeGen.Core/TypeModel/TypeScript/TsEnum.cs @@ -0,0 +1,12 @@ +using System.Collections.Generic; + +namespace TypeGen.Core.TypeModel.TypeScript; + +internal class TsEnum : TsType +{ + public IReadOnlyCollection Values { get; } + + public TsEnum(string name) : base(name) + { + } +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.Core/TypeModel/TypeScript/TsEnumValue.cs b/src/TypeGen/TypeGen.Core/TypeModel/TypeScript/TsEnumValue.cs new file mode 100644 index 00000000..f1a829cb --- /dev/null +++ b/src/TypeGen/TypeGen.Core/TypeModel/TypeScript/TsEnumValue.cs @@ -0,0 +1,8 @@ +namespace TypeGen.Core.TypeModel.TypeScript; + +internal class TsEnumValue +{ + public string Name { get; } + public string UnderlyingValue { get; } + public TsUnderlyingValueType UnderlyingValueType { get; } +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.Core/TypeModel/TypeScript/TsImport.cs b/src/TypeGen/TypeGen.Core/TypeModel/TypeScript/TsImport.cs new file mode 100644 index 00000000..8a630cd5 --- /dev/null +++ b/src/TypeGen/TypeGen.Core/TypeModel/TypeScript/TsImport.cs @@ -0,0 +1,9 @@ +namespace TypeGen.Core.TypeModel.TypeScript; + +internal class TsImport +{ + public string TypeName { get; } + public string OriginalTypeName { get; } + public string ImportPath { get; } + public bool IsDefaultExport { get; } +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.Core/TypeModel/TypeScript/TsInterface.cs b/src/TypeGen/TypeGen.Core/TypeModel/TypeScript/TsInterface.cs new file mode 100644 index 00000000..d5962e36 --- /dev/null +++ b/src/TypeGen/TypeGen.Core/TypeModel/TypeScript/TsInterface.cs @@ -0,0 +1,14 @@ +using System.Collections.Generic; + +namespace TypeGen.Core.TypeModel.TypeScript; + +internal class TsInterface : TsType +{ + public IReadOnlyCollection Imports { get; } + public string Base { get; } + public IReadOnlyCollection Properties { get; set; } + + public TsInterface(string name) : base(name) + { + } +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.Core/TypeModel/TypeScript/TsProperty.cs b/src/TypeGen/TypeGen.Core/TypeModel/TypeScript/TsProperty.cs new file mode 100644 index 00000000..a08b7741 --- /dev/null +++ b/src/TypeGen/TypeGen.Core/TypeModel/TypeScript/TsProperty.cs @@ -0,0 +1,9 @@ +namespace TypeGen.Core.TypeModel.TypeScript; + +internal class TsProperty +{ + public string Type { get; } + public string Name { get; } + public bool IsOptional { get; } + public string DefaultValue { get; } +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.Core/TypeModel/TypeScript/TsType.cs b/src/TypeGen/TypeGen.Core/TypeModel/TypeScript/TsType.cs new file mode 100644 index 00000000..81cddcd4 --- /dev/null +++ b/src/TypeGen/TypeGen.Core/TypeModel/TypeScript/TsType.cs @@ -0,0 +1,13 @@ +using System.Collections.Generic; + +namespace TypeGen.Core.TypeModel.TypeScript; + +internal abstract class TsType +{ + public string Name { get; } + + protected TsType(string name) + { + Name = name; + } +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.Core/TypeModel/TypeScript/TsUnderlyingValueType.cs b/src/TypeGen/TypeGen.Core/TypeModel/TypeScript/TsUnderlyingValueType.cs new file mode 100644 index 00000000..d14053bf --- /dev/null +++ b/src/TypeGen/TypeGen.Core/TypeModel/TypeScript/TsUnderlyingValueType.cs @@ -0,0 +1,7 @@ +namespace TypeGen.Core.TypeModel.TypeScript; + +internal enum TsUnderlyingValueType +{ + Number, + String +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.Core/Utils/ConsoleUtils.cs b/src/TypeGen/TypeGen.Core/Utils/ConsoleUtils.cs new file mode 100644 index 00000000..e4fc4342 --- /dev/null +++ b/src/TypeGen/TypeGen.Core/Utils/ConsoleUtils.cs @@ -0,0 +1,14 @@ +using System; + +namespace TypeGen.Core.Utils; + +internal class ConsoleUtils +{ + public static void WithColor(ConsoleColor color, Action action) + { + var oldColor = Console.ForegroundColor; + Console.ForegroundColor = color; + action(); + Console.ForegroundColor = oldColor; + } +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.FileContentTest/Blacklist/BlacklistTest.cs b/src/TypeGen/TypeGen.FileContentTest/Blacklist/BlacklistTest.cs new file mode 100644 index 00000000..ad24dec8 --- /dev/null +++ b/src/TypeGen/TypeGen.FileContentTest/Blacklist/BlacklistTest.cs @@ -0,0 +1,163 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using FluentAssertions; +using TypeGen.Core; +using TypeGen.Core.Generator; +using TypeGen.Core.SpecGeneration; +using TypeGen.FileContentTest.Blacklist.Entities; +using TypeGen.FileContentTest.TestingUtils; +using Xunit; + +namespace TypeGen.FileContentTest.Blacklist +{ + public class BlacklistTest : GenerationTestBase + { + [Fact] + public async Task ClassWithBlacklistedBase_Test() + { + var type = typeof(ClassWithBlacklistedBase); + const string expectedLocation = "TypeGen.FileContentTest.Blacklist.Expected.class-with-blacklisted-base.ts"; + var blacklist = new HashSet { typeof(Bar).FullName }; + var generationSpec = new ClassWithBlacklistedBaseGenerationSpec(); + var generatorOptions = new GeneratorOptions { TypeBlacklist = blacklist }; + + await TestGenerationSpec(type, expectedLocation, generationSpec, generatorOptions); + } + + [Fact] + public async Task ClassWithBlacklistedInterface_Test() + { + var type = typeof(ClassWithBlacklistedInterface); + const string expectedLocation = "TypeGen.FileContentTest.Blacklist.Expected.class-with-blacklisted-interface.ts"; + var blacklist = new HashSet { typeof(IFoo).FullName }; + var generationSpec = new ClassWithBlacklistedInterfaceGenerationSpec(); + var generatorOptions = new GeneratorOptions { TypeBlacklist = blacklist }; + + await TestGenerationSpec(type, expectedLocation, generationSpec, generatorOptions); + } + + [Fact] + public async Task InterfaceWithBlacklistedBase_Test() + { + var type = typeof(InterfaceWithBlacklistedBase); + const string expectedLocation = "TypeGen.FileContentTest.Blacklist.Expected.interface-with-blacklisted-base.ts"; + var blacklist = new HashSet { typeof(IFoo).FullName }; + var generationSpec = new InterfaceWithBlacklistedBaseGenerationSpec(); + var generatorOptions = new GeneratorOptions { TypeBlacklist = blacklist }; + + await TestGenerationSpec(type, expectedLocation, generationSpec, generatorOptions); + } + + [Fact] + public void ClassWithBlacklistedPropertyType_Test() + { + var blacklist = new HashSet { typeof(Baz).FullName }; + var generatorOptions = new GeneratorOptions { TypeBlacklist = blacklist }; + var generator = new Generator(generatorOptions); + var generationSpec = new ClassWithBlacklistedPropertyTypeGenerationSpec(); + + ((Action)(() => generator.Generate(new[] { generationSpec }))).Should().Throw(); + } + + [Fact] + public void ClassWithBlacklistedTypeInDictionary_Test() + { + var blacklist = new HashSet { typeof(Baz).FullName }; + var generatorOptions = new GeneratorOptions { TypeBlacklist = blacklist }; + var generator = new Generator(generatorOptions); + var generationSpec = new ClassWithBlacklistedTypeInDictionaryGenerationSpec(); + + ((Action)(() => generator.Generate(new[] { generationSpec }))).Should().Throw(); + } + + [Fact] + public void ClassWithBlacklistedTypeInArray_Test() + { + var blacklist = new HashSet { typeof(Baz).FullName }; + var generatorOptions = new GeneratorOptions { TypeBlacklist = blacklist }; + var generator = new Generator(generatorOptions); + var generationSpec = new ClassWithBlacklistedTypeInArrayGenerationSpec(); + + ((Action)(() => generator.Generate(new[] { generationSpec }))).Should().Throw(); + } + + [Fact] + public void ClassWithBlacklistedTypeInCustomGeneric_Test() + { + var blacklist = new HashSet { typeof(Baz).FullName }; + var generatorOptions = new GeneratorOptions { TypeBlacklist = blacklist }; + var generator = new Generator(generatorOptions); + var generationSpec = new ClassWithBlacklistedTypeInCustomGenericGenerationSpec(); + + ((Action)(() => generator.Generate(new[] { generationSpec }))).Should().Throw(); + } + + [Fact] + public void InterfaceWithBlacklistedPropertyType_Test() + { + var blacklist = new HashSet { typeof(Baz).FullName }; + var generatorOptions = new GeneratorOptions { TypeBlacklist = blacklist }; + var generator = new Generator(generatorOptions); + var generationSpec = new InterfaceWithBlacklistedPropertyTypeGenerationSpec(); + + ((Action)(() => generator.Generate(new[] { generationSpec }))).Should().Throw(); + } + + [Fact] + public async Task Record_Test() + { + var type = typeof(MyRecord); + const string expectedLocation = "TypeGen.FileContentTest.Blacklist.Expected.my-record.ts"; + var generationSpec = new RecordGenerationSpec(); + var generatorOptions = new GeneratorOptions(); + + await TestGenerationSpec(type, expectedLocation, generationSpec, generatorOptions); + } + + private class ClassWithBlacklistedBaseGenerationSpec : GenerationSpec + { + public ClassWithBlacklistedBaseGenerationSpec() => AddClass(); + } + + private class ClassWithBlacklistedInterfaceGenerationSpec : GenerationSpec + { + public ClassWithBlacklistedInterfaceGenerationSpec() => AddClass(); + } + + private class InterfaceWithBlacklistedBaseGenerationSpec : GenerationSpec + { + public InterfaceWithBlacklistedBaseGenerationSpec() => AddInterface(); + } + + private class ClassWithBlacklistedPropertyTypeGenerationSpec : GenerationSpec + { + public ClassWithBlacklistedPropertyTypeGenerationSpec() => AddClass(); + } + + private class ClassWithBlacklistedTypeInDictionaryGenerationSpec : GenerationSpec + { + public ClassWithBlacklistedTypeInDictionaryGenerationSpec() => AddClass(); + } + + private class ClassWithBlacklistedTypeInArrayGenerationSpec : GenerationSpec + { + public ClassWithBlacklistedTypeInArrayGenerationSpec() => AddClass(); + } + + private class ClassWithBlacklistedTypeInCustomGenericGenerationSpec : GenerationSpec + { + public ClassWithBlacklistedTypeInCustomGenericGenerationSpec() => AddClass(); + } + + private class InterfaceWithBlacklistedPropertyTypeGenerationSpec : GenerationSpec + { + public InterfaceWithBlacklistedPropertyTypeGenerationSpec() => AddClass(); + } + + private class RecordGenerationSpec : GenerationSpec + { + public RecordGenerationSpec() => AddClass(); + } + } +} diff --git a/src/TypeGen/TypeGen.FileContentTest/Blacklist/Entities/Bar.cs b/src/TypeGen/TypeGen.FileContentTest/Blacklist/Entities/Bar.cs new file mode 100644 index 00000000..a0dd8bb5 --- /dev/null +++ b/src/TypeGen/TypeGen.FileContentTest/Blacklist/Entities/Bar.cs @@ -0,0 +1,6 @@ +namespace TypeGen.FileContentTest.Blacklist.Entities; + +public class Bar +{ + +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.FileContentTest/Blacklist/Entities/Baz.cs b/src/TypeGen/TypeGen.FileContentTest/Blacklist/Entities/Baz.cs new file mode 100644 index 00000000..79283f49 --- /dev/null +++ b/src/TypeGen/TypeGen.FileContentTest/Blacklist/Entities/Baz.cs @@ -0,0 +1,6 @@ +namespace TypeGen.FileContentTest.Blacklist.Entities; + +public class Baz +{ + +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.FileContentTest/Blacklist/Entities/ClassWithBlacklistedBase.cs b/src/TypeGen/TypeGen.FileContentTest/Blacklist/Entities/ClassWithBlacklistedBase.cs new file mode 100644 index 00000000..3562e07a --- /dev/null +++ b/src/TypeGen/TypeGen.FileContentTest/Blacklist/Entities/ClassWithBlacklistedBase.cs @@ -0,0 +1,9 @@ +using TypeGen.Core.TypeAnnotations; + +namespace TypeGen.FileContentTest.Blacklist.Entities; + +[ExportTsClass] +public class ClassWithBlacklistedBase : Bar, IFoo +{ + +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.FileContentTest/Blacklist/Entities/ClassWithBlacklistedInterface.cs b/src/TypeGen/TypeGen.FileContentTest/Blacklist/Entities/ClassWithBlacklistedInterface.cs new file mode 100644 index 00000000..bccb8c5e --- /dev/null +++ b/src/TypeGen/TypeGen.FileContentTest/Blacklist/Entities/ClassWithBlacklistedInterface.cs @@ -0,0 +1,9 @@ +using TypeGen.Core.TypeAnnotations; + +namespace TypeGen.FileContentTest.Blacklist.Entities; + +[ExportTsClass] +public class ClassWithBlacklistedInterface : Bar, IFoo +{ + +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.FileContentTest/Blacklist/Entities/ClassWithBlacklistedPropertyType.cs b/src/TypeGen/TypeGen.FileContentTest/Blacklist/Entities/ClassWithBlacklistedPropertyType.cs new file mode 100644 index 00000000..3c6728b6 --- /dev/null +++ b/src/TypeGen/TypeGen.FileContentTest/Blacklist/Entities/ClassWithBlacklistedPropertyType.cs @@ -0,0 +1,9 @@ +using TypeGen.Core.TypeAnnotations; + +namespace TypeGen.FileContentTest.Blacklist.Entities; + +[ExportTsClass] +public class ClassWithBlacklistedPropertyType +{ + public Baz BazProp { get; set; } +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.FileContentTest/Blacklist/Entities/ClassWithBlacklistedTypeInArray.cs b/src/TypeGen/TypeGen.FileContentTest/Blacklist/Entities/ClassWithBlacklistedTypeInArray.cs new file mode 100644 index 00000000..55300af2 --- /dev/null +++ b/src/TypeGen/TypeGen.FileContentTest/Blacklist/Entities/ClassWithBlacklistedTypeInArray.cs @@ -0,0 +1,9 @@ +using TypeGen.Core.TypeAnnotations; + +namespace TypeGen.FileContentTest.Blacklist.Entities; + +[ExportTsClass] +public class ClassWithBlacklistedTypeInArray +{ + public Baz[] BazProp { get; set; } +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.FileContentTest/Blacklist/Entities/ClassWithBlacklistedTypeInCustomGeneric.cs b/src/TypeGen/TypeGen.FileContentTest/Blacklist/Entities/ClassWithBlacklistedTypeInCustomGeneric.cs new file mode 100644 index 00000000..be65421a --- /dev/null +++ b/src/TypeGen/TypeGen.FileContentTest/Blacklist/Entities/ClassWithBlacklistedTypeInCustomGeneric.cs @@ -0,0 +1,10 @@ +using System; +using TypeGen.Core.TypeAnnotations; + +namespace TypeGen.FileContentTest.Blacklist.Entities; + +[ExportTsClass] +public class ClassWithBlacklistedTypeInCustomGeneric +{ + public CustomGeneric, DateTime> BazProp { get; set; } +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.FileContentTest/Blacklist/Entities/ClassWithBlacklistedTypeInDictionary.cs b/src/TypeGen/TypeGen.FileContentTest/Blacklist/Entities/ClassWithBlacklistedTypeInDictionary.cs new file mode 100644 index 00000000..b34b9688 --- /dev/null +++ b/src/TypeGen/TypeGen.FileContentTest/Blacklist/Entities/ClassWithBlacklistedTypeInDictionary.cs @@ -0,0 +1,10 @@ +using System.Collections.Generic; +using TypeGen.Core.TypeAnnotations; + +namespace TypeGen.FileContentTest.Blacklist.Entities; + +[ExportTsClass] +public class ClassWithBlacklistedTypeInDictionary +{ + public IDictionary BazProp { get; set; } +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.FileContentTest/Blacklist/Entities/CustomGeneric.cs b/src/TypeGen/TypeGen.FileContentTest/Blacklist/Entities/CustomGeneric.cs new file mode 100644 index 00000000..1d0c2f80 --- /dev/null +++ b/src/TypeGen/TypeGen.FileContentTest/Blacklist/Entities/CustomGeneric.cs @@ -0,0 +1,6 @@ +namespace TypeGen.FileContentTest.Blacklist.Entities; + +public class CustomGeneric +{ + +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.FileContentTest/Blacklist/Entities/IFoo.cs b/src/TypeGen/TypeGen.FileContentTest/Blacklist/Entities/IFoo.cs new file mode 100644 index 00000000..84c22422 --- /dev/null +++ b/src/TypeGen/TypeGen.FileContentTest/Blacklist/Entities/IFoo.cs @@ -0,0 +1,6 @@ +namespace TypeGen.FileContentTest.Blacklist.Entities; + +public interface IFoo +{ + +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.FileContentTest/Blacklist/Entities/InterfaceWithBlacklistedBase.cs b/src/TypeGen/TypeGen.FileContentTest/Blacklist/Entities/InterfaceWithBlacklistedBase.cs new file mode 100644 index 00000000..2a85f21c --- /dev/null +++ b/src/TypeGen/TypeGen.FileContentTest/Blacklist/Entities/InterfaceWithBlacklistedBase.cs @@ -0,0 +1,9 @@ +using TypeGen.Core.TypeAnnotations; + +namespace TypeGen.FileContentTest.Blacklist.Entities; + +[ExportTsInterface] +public interface InterfaceWithBlacklistedBase : IFoo +{ + +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.FileContentTest/Blacklist/Entities/InterfaceWithBlacklistedPropertyType.cs b/src/TypeGen/TypeGen.FileContentTest/Blacklist/Entities/InterfaceWithBlacklistedPropertyType.cs new file mode 100644 index 00000000..790dc521 --- /dev/null +++ b/src/TypeGen/TypeGen.FileContentTest/Blacklist/Entities/InterfaceWithBlacklistedPropertyType.cs @@ -0,0 +1,9 @@ +using TypeGen.Core.TypeAnnotations; + +namespace TypeGen.FileContentTest.Blacklist.Entities; + +[ExportTsInterface] +public interface InterfaceWithBlacklistedPropertyType +{ + Baz BazProp { get; set; } +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.FileContentTest/Blacklist/Entities/MyRecord.cs b/src/TypeGen/TypeGen.FileContentTest/Blacklist/Entities/MyRecord.cs new file mode 100644 index 00000000..55f69345 --- /dev/null +++ b/src/TypeGen/TypeGen.FileContentTest/Blacklist/Entities/MyRecord.cs @@ -0,0 +1,3 @@ +namespace TypeGen.FileContentTest.Blacklist.Entities; + +public record MyRecord(); \ No newline at end of file diff --git a/src/TypeGen/TypeGen.FileContentTest/Blacklist/Expected/class-with-blacklisted-base.ts b/src/TypeGen/TypeGen.FileContentTest/Blacklist/Expected/class-with-blacklisted-base.ts new file mode 100644 index 00000000..9b255a1e --- /dev/null +++ b/src/TypeGen/TypeGen.FileContentTest/Blacklist/Expected/class-with-blacklisted-base.ts @@ -0,0 +1,9 @@ +/** + * This is a TypeGen auto-generated file. + * Any changes made to this file can be lost when this file is regenerated. + */ + +import { IFoo } from "./i-foo"; + +export class ClassWithBlacklistedBase implements IFoo { +} diff --git a/src/TypeGen/TypeGen.FileContentTest/Blacklist/Expected/class-with-blacklisted-interface.ts b/src/TypeGen/TypeGen.FileContentTest/Blacklist/Expected/class-with-blacklisted-interface.ts new file mode 100644 index 00000000..3f7738ad --- /dev/null +++ b/src/TypeGen/TypeGen.FileContentTest/Blacklist/Expected/class-with-blacklisted-interface.ts @@ -0,0 +1,9 @@ +/** + * This is a TypeGen auto-generated file. + * Any changes made to this file can be lost when this file is regenerated. + */ + +import { Bar } from "./bar"; + +export class ClassWithBlacklistedInterface extends Bar { +} diff --git a/src/TypeGen/TypeGen.FileContentTest/Blacklist/Expected/interface-with-blacklisted-base.ts b/src/TypeGen/TypeGen.FileContentTest/Blacklist/Expected/interface-with-blacklisted-base.ts new file mode 100644 index 00000000..a436dd8a --- /dev/null +++ b/src/TypeGen/TypeGen.FileContentTest/Blacklist/Expected/interface-with-blacklisted-base.ts @@ -0,0 +1,7 @@ +/** + * This is a TypeGen auto-generated file. + * Any changes made to this file can be lost when this file is regenerated. + */ + +export interface InterfaceWithBlacklistedBase { +} diff --git a/src/TypeGen/TypeGen.FileContentTest/Blacklist/Expected/my-record.ts b/src/TypeGen/TypeGen.FileContentTest/Blacklist/Expected/my-record.ts new file mode 100644 index 00000000..ef75d2df --- /dev/null +++ b/src/TypeGen/TypeGen.FileContentTest/Blacklist/Expected/my-record.ts @@ -0,0 +1,7 @@ +/** + * This is a TypeGen auto-generated file. + * Any changes made to this file can be lost when this file is regenerated. + */ + +export class MyRecord { +} diff --git a/src/TypeGen/TypeGen.IntegrationTest/CircularGenericConstraint/CircularGenericConstraintTest.cs b/src/TypeGen/TypeGen.FileContentTest/CircularGenericConstraint/CircularGenericConstraintTest.cs similarity index 66% rename from src/TypeGen/TypeGen.IntegrationTest/CircularGenericConstraint/CircularGenericConstraintTest.cs rename to src/TypeGen/TypeGen.FileContentTest/CircularGenericConstraint/CircularGenericConstraintTest.cs index fbc95a28..637fa74e 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CircularGenericConstraint/CircularGenericConstraintTest.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CircularGenericConstraint/CircularGenericConstraintTest.cs @@ -1,11 +1,10 @@ using System; using System.Threading.Tasks; -using TypeGen.IntegrationTest.CircularGenericConstraint.TestClasses; -using TypeGen.IntegrationTest.CommonCases; -using TypeGen.IntegrationTest.TestingUtils; +using TypeGen.FileContentTest.CircularGenericConstraint.Entities; +using TypeGen.FileContentTest.TestingUtils; using Xunit; -namespace TypeGen.IntegrationTest.CircularGenericConstraint +namespace TypeGen.FileContentTest.CircularGenericConstraint { public class CircularGenericConstraintTest : GenerationTestBase { @@ -16,12 +15,12 @@ public class CircularGenericConstraintTest : GenerationTestBase /// /// [Theory] - [InlineData(typeof(RecursiveConstraintClass<>), @"TypeGen.IntegrationTest.CircularGenericConstraint.Expected.RecursiveConstraintClass.ts")] - [InlineData(typeof(IRecursiveConstraintInterface<>), @"TypeGen.IntegrationTest.CircularGenericConstraint.Expected.IRecursiveConstraintInterface.ts")] - [InlineData(typeof(IRecursiveConstraintInterfaceWithClassConstraint<>), @"TypeGen.IntegrationTest.CircularGenericConstraint.Expected.IRecursiveConstraintInterfaceWithClassConstraint.ts")] - [InlineData(typeof(IRecursiveConstraintInterfaceWithStructConstraint<>), @"TypeGen.IntegrationTest.CircularGenericConstraint.Expected.IRecursiveConstraintInterfaceWithStructConstraint.ts")] - [InlineData(typeof(IMultipleConstraintInterface<>), @"TypeGen.IntegrationTest.CircularGenericConstraint.Expected.IMultipleConstraintInterface.ts")] - [InlineData(typeof(ICicrularConstraintInterface<,>), @"TypeGen.IntegrationTest.CircularGenericConstraint.Expected.ICicrularConstraintInterface.ts")] + [InlineData(typeof(RecursiveConstraintClass<>), @"TypeGen.FileContentTest.CircularGenericConstraint.Expected.RecursiveConstraintClass.ts")] + [InlineData(typeof(IRecursiveConstraintInterface<>), @"TypeGen.FileContentTest.CircularGenericConstraint.Expected.IRecursiveConstraintInterface.ts")] + [InlineData(typeof(IRecursiveConstraintInterfaceWithClassConstraint<>), @"TypeGen.FileContentTest.CircularGenericConstraint.Expected.IRecursiveConstraintInterfaceWithClassConstraint.ts")] + [InlineData(typeof(IRecursiveConstraintInterfaceWithStructConstraint<>), @"TypeGen.FileContentTest.CircularGenericConstraint.Expected.IRecursiveConstraintInterfaceWithStructConstraint.ts")] + [InlineData(typeof(IMultipleConstraintInterface<>), @"TypeGen.FileContentTest.CircularGenericConstraint.Expected.IMultipleConstraintInterface.ts")] + [InlineData(typeof(ICicrularConstraintInterface<,>), @"TypeGen.FileContentTest.CircularGenericConstraint.Expected.ICicrularConstraintInterface.ts")] public async Task GeneratesCorrectly(Type type, string expectedLocation) { await TestFromAssembly(type, expectedLocation); diff --git a/src/TypeGen/TypeGen.IntegrationTest/CircularGenericConstraint/TestClasses/TestClasses.cs b/src/TypeGen/TypeGen.FileContentTest/CircularGenericConstraint/Entities/TestClasses.cs similarity index 94% rename from src/TypeGen/TypeGen.IntegrationTest/CircularGenericConstraint/TestClasses/TestClasses.cs rename to src/TypeGen/TypeGen.FileContentTest/CircularGenericConstraint/Entities/TestClasses.cs index 9c1281cc..17e1ebd5 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CircularGenericConstraint/TestClasses/TestClasses.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CircularGenericConstraint/Entities/TestClasses.cs @@ -1,6 +1,6 @@ using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.CircularGenericConstraint.TestClasses +namespace TypeGen.FileContentTest.CircularGenericConstraint.Entities { [ExportTsClass] public class RecursiveConstraintClass diff --git a/src/TypeGen/TypeGen.IntegrationTest/CircularGenericConstraint/Expected/ICicrularConstraintInterface.ts b/src/TypeGen/TypeGen.FileContentTest/CircularGenericConstraint/Expected/ICicrularConstraintInterface.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/CircularGenericConstraint/Expected/ICicrularConstraintInterface.ts rename to src/TypeGen/TypeGen.FileContentTest/CircularGenericConstraint/Expected/ICicrularConstraintInterface.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/CircularGenericConstraint/Expected/IMultipleConstraintInterface.ts b/src/TypeGen/TypeGen.FileContentTest/CircularGenericConstraint/Expected/IMultipleConstraintInterface.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/CircularGenericConstraint/Expected/IMultipleConstraintInterface.ts rename to src/TypeGen/TypeGen.FileContentTest/CircularGenericConstraint/Expected/IMultipleConstraintInterface.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/CircularGenericConstraint/Expected/IRecursiveConstraintInterface.ts b/src/TypeGen/TypeGen.FileContentTest/CircularGenericConstraint/Expected/IRecursiveConstraintInterface.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/CircularGenericConstraint/Expected/IRecursiveConstraintInterface.ts rename to src/TypeGen/TypeGen.FileContentTest/CircularGenericConstraint/Expected/IRecursiveConstraintInterface.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/CircularGenericConstraint/Expected/IRecursiveConstraintInterfaceWithClassConstraint.ts b/src/TypeGen/TypeGen.FileContentTest/CircularGenericConstraint/Expected/IRecursiveConstraintInterfaceWithClassConstraint.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/CircularGenericConstraint/Expected/IRecursiveConstraintInterfaceWithClassConstraint.ts rename to src/TypeGen/TypeGen.FileContentTest/CircularGenericConstraint/Expected/IRecursiveConstraintInterfaceWithClassConstraint.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/CircularGenericConstraint/Expected/IRecursiveConstraintInterfaceWithStructConstraint.ts b/src/TypeGen/TypeGen.FileContentTest/CircularGenericConstraint/Expected/IRecursiveConstraintInterfaceWithStructConstraint.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/CircularGenericConstraint/Expected/IRecursiveConstraintInterfaceWithStructConstraint.ts rename to src/TypeGen/TypeGen.FileContentTest/CircularGenericConstraint/Expected/IRecursiveConstraintInterfaceWithStructConstraint.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/CircularGenericConstraint/Expected/RecursiveConstraintClass.ts b/src/TypeGen/TypeGen.FileContentTest/CircularGenericConstraint/Expected/RecursiveConstraintClass.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/CircularGenericConstraint/Expected/RecursiveConstraintClass.ts rename to src/TypeGen/TypeGen.FileContentTest/CircularGenericConstraint/Expected/RecursiveConstraintClass.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/Comments/CommentsTest.cs b/src/TypeGen/TypeGen.FileContentTest/Comments/CommentsTest.cs similarity index 63% rename from src/TypeGen/TypeGen.IntegrationTest/Comments/CommentsTest.cs rename to src/TypeGen/TypeGen.FileContentTest/Comments/CommentsTest.cs index 921cf873..88374299 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/Comments/CommentsTest.cs +++ b/src/TypeGen/TypeGen.FileContentTest/Comments/CommentsTest.cs @@ -2,25 +2,25 @@ using System.Threading.Tasks; using TypeGen.Core.Generator; using TypeGen.Core.SpecGeneration; -using TypeGen.IntegrationTest.Comments.Entities; -using TypeGen.IntegrationTest.TestingUtils; +using TypeGen.FileContentTest.Comments.Entities; +using TypeGen.FileContentTest.TestingUtils; using Xunit; -namespace TypeGen.IntegrationTest.Comments; +namespace TypeGen.FileContentTest.Comments; public class CommentsTest : GenerationTestBase { [Theory] - [InlineData(typeof(TsClass), "TypeGen.IntegrationTest.Comments.Expected.ts-class.ts", false)] - [InlineData(typeof(TsClass), "TypeGen.IntegrationTest.Comments.Expected.ts-class-default-export.ts", true)] - [InlineData(typeof(TsGeneric<,>), "TypeGen.IntegrationTest.Comments.Expected.ts-generic.ts", false)] - [InlineData(typeof(TsGeneric<,>), "TypeGen.IntegrationTest.Comments.Expected.ts-generic-default-export.ts", true)] - [InlineData(typeof(ITsInterface), "TypeGen.IntegrationTest.Comments.Expected.i-ts-interface.ts", false)] - [InlineData(typeof(ITsInterface), "TypeGen.IntegrationTest.Comments.Expected.i-ts-interface-default-export.ts", true)] - [InlineData(typeof(TsEnum), "TypeGen.IntegrationTest.Comments.Expected.ts-enum.ts", false)] - [InlineData(typeof(TsEnum), "TypeGen.IntegrationTest.Comments.Expected.ts-enum-default-export.ts", true)] - [InlineData(typeof(TsEnumUnion), "TypeGen.IntegrationTest.Comments.Expected.ts-enum-union.ts", false)] - [InlineData(typeof(TsEnumUnion), "TypeGen.IntegrationTest.Comments.Expected.ts-enum-union-default-export.ts", true)] + [InlineData(typeof(TsClass), "TypeGen.FileContentTest.Comments.Expected.ts-class.ts", false)] + [InlineData(typeof(TsClass), "TypeGen.FileContentTest.Comments.Expected.ts-class-default-export.ts", true)] + [InlineData(typeof(TsGeneric<,>), "TypeGen.FileContentTest.Comments.Expected.ts-generic.ts", false)] + [InlineData(typeof(TsGeneric<,>), "TypeGen.FileContentTest.Comments.Expected.ts-generic-default-export.ts", true)] + [InlineData(typeof(ITsInterface), "TypeGen.FileContentTest.Comments.Expected.i-ts-interface.ts", false)] + [InlineData(typeof(ITsInterface), "TypeGen.FileContentTest.Comments.Expected.i-ts-interface-default-export.ts", true)] + [InlineData(typeof(TsEnum), "TypeGen.FileContentTest.Comments.Expected.ts-enum.ts", false)] + [InlineData(typeof(TsEnum), "TypeGen.FileContentTest.Comments.Expected.ts-enum-default-export.ts", true)] + [InlineData(typeof(TsEnumUnion), "TypeGen.FileContentTest.Comments.Expected.ts-enum-union.ts", false)] + [InlineData(typeof(TsEnumUnion), "TypeGen.FileContentTest.Comments.Expected.ts-enum-union-default-export.ts", true)] public async Task TestCommentsGenerationSpec(Type type, string expectedLocation, bool useDefaultExport) { var generationSpec = new CommentsGenerationSpec(); diff --git a/src/TypeGen/TypeGen.IntegrationTest/Comments/Entities/ITsInterface.cs b/src/TypeGen/TypeGen.FileContentTest/Comments/Entities/ITsInterface.cs similarity index 78% rename from src/TypeGen/TypeGen.IntegrationTest/Comments/Entities/ITsInterface.cs rename to src/TypeGen/TypeGen.FileContentTest/Comments/Entities/ITsInterface.cs index cf74f91f..648075c5 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/Comments/Entities/ITsInterface.cs +++ b/src/TypeGen/TypeGen.FileContentTest/Comments/Entities/ITsInterface.cs @@ -1,4 +1,4 @@ -namespace TypeGen.IntegrationTest.Comments.Entities; +namespace TypeGen.FileContentTest.Comments.Entities; /// /// This is an interface. diff --git a/src/TypeGen/TypeGen.IntegrationTest/Comments/Entities/TsClass.cs b/src/TypeGen/TypeGen.FileContentTest/Comments/Entities/TsClass.cs similarity index 93% rename from src/TypeGen/TypeGen.IntegrationTest/Comments/Entities/TsClass.cs rename to src/TypeGen/TypeGen.FileContentTest/Comments/Entities/TsClass.cs index 7138a2a6..1052108d 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/Comments/Entities/TsClass.cs +++ b/src/TypeGen/TypeGen.FileContentTest/Comments/Entities/TsClass.cs @@ -1,4 +1,4 @@ -namespace TypeGen.IntegrationTest.Comments.Entities; +namespace TypeGen.FileContentTest.Comments.Entities; /// /// This is the summary of TsClass. diff --git a/src/TypeGen/TypeGen.IntegrationTest/Comments/Entities/TsEnum.cs b/src/TypeGen/TypeGen.FileContentTest/Comments/Entities/TsEnum.cs similarity index 87% rename from src/TypeGen/TypeGen.IntegrationTest/Comments/Entities/TsEnum.cs rename to src/TypeGen/TypeGen.FileContentTest/Comments/Entities/TsEnum.cs index 23778979..04c63431 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/Comments/Entities/TsEnum.cs +++ b/src/TypeGen/TypeGen.FileContentTest/Comments/Entities/TsEnum.cs @@ -1,4 +1,4 @@ -namespace TypeGen.IntegrationTest.Comments.Entities; +namespace TypeGen.FileContentTest.Comments.Entities; /// /// I can't think of a good reason for this enum. diff --git a/src/TypeGen/TypeGen.IntegrationTest/Comments/Entities/TsEnumUnion.cs b/src/TypeGen/TypeGen.FileContentTest/Comments/Entities/TsEnumUnion.cs similarity index 86% rename from src/TypeGen/TypeGen.IntegrationTest/Comments/Entities/TsEnumUnion.cs rename to src/TypeGen/TypeGen.FileContentTest/Comments/Entities/TsEnumUnion.cs index 2d977956..3f2ced39 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/Comments/Entities/TsEnumUnion.cs +++ b/src/TypeGen/TypeGen.FileContentTest/Comments/Entities/TsEnumUnion.cs @@ -1,4 +1,4 @@ -namespace TypeGen.IntegrationTest.Comments.Entities; +namespace TypeGen.FileContentTest.Comments.Entities; /// /// This has union types. diff --git a/src/TypeGen/TypeGen.IntegrationTest/Comments/Entities/TsGeneric.cs b/src/TypeGen/TypeGen.FileContentTest/Comments/Entities/TsGeneric.cs similarity index 81% rename from src/TypeGen/TypeGen.IntegrationTest/Comments/Entities/TsGeneric.cs rename to src/TypeGen/TypeGen.FileContentTest/Comments/Entities/TsGeneric.cs index f14a3f70..9cfc3deb 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/Comments/Entities/TsGeneric.cs +++ b/src/TypeGen/TypeGen.FileContentTest/Comments/Entities/TsGeneric.cs @@ -1,4 +1,4 @@ -namespace TypeGen.IntegrationTest.Comments.Entities; +namespace TypeGen.FileContentTest.Comments.Entities; /// /// A very complicated generic type. diff --git a/src/TypeGen/TypeGen.IntegrationTest/Comments/Expected/i-ts-interface-default-export.ts b/src/TypeGen/TypeGen.FileContentTest/Comments/Expected/i-ts-interface-default-export.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/Comments/Expected/i-ts-interface-default-export.ts rename to src/TypeGen/TypeGen.FileContentTest/Comments/Expected/i-ts-interface-default-export.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/Comments/Expected/i-ts-interface.ts b/src/TypeGen/TypeGen.FileContentTest/Comments/Expected/i-ts-interface.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/Comments/Expected/i-ts-interface.ts rename to src/TypeGen/TypeGen.FileContentTest/Comments/Expected/i-ts-interface.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/Comments/Expected/ts-class-default-export.ts b/src/TypeGen/TypeGen.FileContentTest/Comments/Expected/ts-class-default-export.ts similarity index 91% rename from src/TypeGen/TypeGen.IntegrationTest/Comments/Expected/ts-class-default-export.ts rename to src/TypeGen/TypeGen.FileContentTest/Comments/Expected/ts-class-default-export.ts index 60ec6260..b4bad7c1 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/Comments/Expected/ts-class-default-export.ts +++ b/src/TypeGen/TypeGen.FileContentTest/Comments/Expected/ts-class-default-export.ts @@ -8,7 +8,7 @@ import TsEnum from "./ts-enum"; /** * This is the summary of TsClass. * It has many lines. - * This one is the last one. See @see {@link TypeGen.IntegrationTest.Comments.Entities.TsClass} for more details. + * This one is the last one. See @see {@link TypeGen.FileContentTest.Comments.Entities.TsClass} for more details. * * @example * This is how you can code: @see {@link http://example.com}. diff --git a/src/TypeGen/TypeGen.IntegrationTest/Comments/Expected/ts-class.ts b/src/TypeGen/TypeGen.FileContentTest/Comments/Expected/ts-class.ts similarity index 91% rename from src/TypeGen/TypeGen.IntegrationTest/Comments/Expected/ts-class.ts rename to src/TypeGen/TypeGen.FileContentTest/Comments/Expected/ts-class.ts index f0f47d16..8a664026 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/Comments/Expected/ts-class.ts +++ b/src/TypeGen/TypeGen.FileContentTest/Comments/Expected/ts-class.ts @@ -8,7 +8,7 @@ import { TsEnum } from "./ts-enum"; /** * This is the summary of TsClass. * It has many lines. - * This one is the last one. See @see {@link TypeGen.IntegrationTest.Comments.Entities.TsClass} for more details. + * This one is the last one. See @see {@link TypeGen.FileContentTest.Comments.Entities.TsClass} for more details. * * @example * This is how you can code: @see {@link http://example.com}. diff --git a/src/TypeGen/TypeGen.IntegrationTest/Comments/Expected/ts-enum-default-export.ts b/src/TypeGen/TypeGen.FileContentTest/Comments/Expected/ts-enum-default-export.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/Comments/Expected/ts-enum-default-export.ts rename to src/TypeGen/TypeGen.FileContentTest/Comments/Expected/ts-enum-default-export.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/Comments/Expected/ts-enum-union-default-export.ts b/src/TypeGen/TypeGen.FileContentTest/Comments/Expected/ts-enum-union-default-export.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/Comments/Expected/ts-enum-union-default-export.ts rename to src/TypeGen/TypeGen.FileContentTest/Comments/Expected/ts-enum-union-default-export.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/Comments/Expected/ts-enum-union.ts b/src/TypeGen/TypeGen.FileContentTest/Comments/Expected/ts-enum-union.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/Comments/Expected/ts-enum-union.ts rename to src/TypeGen/TypeGen.FileContentTest/Comments/Expected/ts-enum-union.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/Comments/Expected/ts-enum.ts b/src/TypeGen/TypeGen.FileContentTest/Comments/Expected/ts-enum.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/Comments/Expected/ts-enum.ts rename to src/TypeGen/TypeGen.FileContentTest/Comments/Expected/ts-enum.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/Comments/Expected/ts-generic-default-export.ts b/src/TypeGen/TypeGen.FileContentTest/Comments/Expected/ts-generic-default-export.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/Comments/Expected/ts-generic-default-export.ts rename to src/TypeGen/TypeGen.FileContentTest/Comments/Expected/ts-generic-default-export.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/Comments/Expected/ts-generic.ts b/src/TypeGen/TypeGen.FileContentTest/Comments/Expected/ts-generic.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/Comments/Expected/ts-generic.ts rename to src/TypeGen/TypeGen.FileContentTest/Comments/Expected/ts-generic.ts diff --git a/src/TypeGen/TypeGen.FileContentTest/CommonCases/CommonCasesGenerationTest.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/CommonCasesGenerationTest.cs new file mode 100644 index 00000000..1e6daaff --- /dev/null +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/CommonCasesGenerationTest.cs @@ -0,0 +1,103 @@ +using System; +using System.Threading.Tasks; +using TypeGen.FileContentTest.CommonCases.Entities; +using TypeGen.FileContentTest.CommonCases.Entities.Constants; +using TypeGen.FileContentTest.CommonCases.Entities.ErrorCase; +using TypeGen.FileContentTest.TestingUtils; +using Xunit; +using CustomBaseClass = TypeGen.FileContentTest.CommonCases.Entities.CustomBaseClass; +using CustomBaseCustomImport = TypeGen.FileContentTest.CommonCases.Entities.CustomBaseCustomImport; +using CustomEmptyBaseClass = TypeGen.FileContentTest.CommonCases.Entities.CustomEmptyBaseClass; +using DefaultMemberValues = TypeGen.FileContentTest.CommonCases.Entities.DefaultMemberValues; +using ExtendedPrimitivesClass = TypeGen.FileContentTest.CommonCases.Entities.ExtendedPrimitivesClass; +using ExternalDepsClass = TypeGen.FileContentTest.CommonCases.Entities.ExternalDepsClass; +using ITestInterface = TypeGen.FileContentTest.CommonCases.Entities.ITestInterface; +using LiteDbEntity = TypeGen.FileContentTest.CommonCases.Entities.LiteDbEntity; +using NoSlashOutputDir = TypeGen.FileContentTest.CommonCases.Entities.NoSlashOutputDir; +using ReadonlyInterface = TypeGen.FileContentTest.CommonCases.Entities.ReadonlyInterface; +using StaticReadonly = TypeGen.FileContentTest.CommonCases.Entities.StaticReadonly; +using StrictNullsClass = TypeGen.FileContentTest.CommonCases.Entities.StrictNullsClass; +using TestInterface = TypeGen.FileContentTest.CommonCases.Entities.TestInterface; +using TypeUnions = TypeGen.FileContentTest.CommonCases.Entities.TypeUnions; + +namespace TypeGen.FileContentTest.CommonCases +{ + public class CommonCasesGenerationTest : GenerationTestBase + { + /// + /// Tests if types are correctly translated to TypeScript. + /// The tested types contain all major use cases that should be supported. + /// + /// + /// + /// + [Theory] + [InlineData(typeof(FooConstants), "TypeGen.FileContentTest.CommonCases.Expected.foo-constants.ts")] + [InlineData(typeof(CustomBaseCustomImport), "TypeGen.FileContentTest.CommonCases.Expected.custom-base-custom-import.ts")] + [InlineData(typeof(Bar), "TypeGen.FileContentTest.CommonCases.Expected.bar.ts")] + [InlineData(typeof(Entities.BaseClass<>), "TypeGen.FileContentTest.CommonCases.Expected.base-class.ts")] + [InlineData(typeof(BaseClass2<>), "TypeGen.FileContentTest.CommonCases.Expected.base-class2.ts")] + [InlineData(typeof(C), "TypeGen.FileContentTest.CommonCases.Expected.c.ts")] + [InlineData(typeof(CustomBaseClass), "TypeGen.FileContentTest.CommonCases.Expected.custom-base-class.ts")] + [InlineData(typeof(CustomEmptyBaseClass), "TypeGen.FileContentTest.CommonCases.Expected.custom-empty-base-class.ts")] + [InlineData(typeof(D), "TypeGen.FileContentTest.CommonCases.Expected.d.ts")] + [InlineData(typeof(DefaultMemberValues), "TypeGen.FileContentTest.CommonCases.Expected.default-member-values.ts")] + [InlineData(typeof(EClass), "TypeGen.FileContentTest.CommonCases.Expected.e-class.ts")] + [InlineData(typeof(ExtendedPrimitivesClass), "TypeGen.FileContentTest.CommonCases.Expected.extended-primitives-class.ts")] + [InlineData(typeof(ExternalDepsClass), "TypeGen.FileContentTest.CommonCases.Expected.external-deps-class.ts")] + [InlineData(typeof(FClass), "TypeGen.FileContentTest.CommonCases.Expected.f-class.ts")] + [InlineData(typeof(FooType), "TypeGen.FileContentTest.CommonCases.Expected.foo-type.ts")] + [InlineData(typeof(Foo), "TypeGen.FileContentTest.CommonCases.Expected.foo.ts")] + [InlineData(typeof(Entities.GenericBaseClass<>), "TypeGen.FileContentTest.CommonCases.Expected.generic-base-class.ts")] + [InlineData(typeof(GenericClass<>), "TypeGen.FileContentTest.CommonCases.Expected.generic-class.ts")] + [InlineData(typeof(Entities.GenericWithRestrictions<>), "TypeGen.FileContentTest.CommonCases.Expected.generic-with-restrictions.ts")] + [InlineData(typeof(ITestInterface), "TypeGen.FileContentTest.CommonCases.Expected.i-test-interface.ts")] + [InlineData(typeof(LiteDbEntity), "TypeGen.FileContentTest.CommonCases.Expected.lite-db-entity.ts")] + [InlineData(typeof(ReadonlyInterface), "TypeGen.FileContentTest.CommonCases.Expected.readonly-interface.ts")] + [InlineData(typeof(StandaloneEnum), "TypeGen.FileContentTest.CommonCases.Expected.standalone-enum.ts")] + [InlineData(typeof(EnumShortValues), "TypeGen.FileContentTest.CommonCases.Expected.enum-short-values.ts")] + [InlineData(typeof(EnumAsUnionType), "TypeGen.FileContentTest.CommonCases.Expected.enum-as-union-type.ts")] + [InlineData(typeof(DictionaryWithEnumKey), "TypeGen.FileContentTest.CommonCases.Expected.dictionary-with-enum-key.ts")] + [InlineData(typeof(DictionaryStringObjectErrorCase), "TypeGen.FileContentTest.CommonCases.Expected.dictionary-string-object-error-case.ts")] + [InlineData(typeof(StaticReadonly), "TypeGen.FileContentTest.CommonCases.Expected.static-readonly.ts")] + [InlineData(typeof(StrictNullsClass), "TypeGen.FileContentTest.CommonCases.Expected.strict-nulls-class.ts")] + [InlineData(typeof(TypeUnions), "TypeGen.FileContentTest.CommonCases.Expected.type-unions.ts")] + [InlineData(typeof(WithGenericBaseClassCustomType), "TypeGen.FileContentTest.CommonCases.Expected.with-generic-base-class-custom-type.ts")] + [InlineData(typeof(WithIgnoredBaseAndCustomBase), "TypeGen.FileContentTest.CommonCases.Expected.with-ignored-base-and-custom-base.ts")] + [InlineData(typeof(WithIgnoredBase), "TypeGen.FileContentTest.CommonCases.Expected.with-ignored-base.ts")] + [InlineData(typeof(NoSlashOutputDir), "TypeGen.FileContentTest.CommonCases.Expected.no.slash.output.dir.no-slash-output-dir.ts")] + [InlineData(typeof(Entities.BaseClass<>), "TypeGen.FileContentTest.CommonCases.Expected.test_classes.base-class.ts")] + [InlineData(typeof(BaseClass2<>), "TypeGen.FileContentTest.CommonCases.Expected.test_classes.base-class2.ts")] + [InlineData(typeof(CircularRefClass1), "TypeGen.FileContentTest.CommonCases.Expected.test_classes.circular-ref-class1.ts")] + [InlineData(typeof(CircularRefClass2), "TypeGen.FileContentTest.CommonCases.Expected.test_classes.circular-ref-class2.ts")] + [InlineData(typeof(TestClass<,>), "TypeGen.FileContentTest.CommonCases.Expected.test_classes.test-class.ts")] + [InlineData(typeof(TestEnum), "TypeGen.FileContentTest.CommonCases.Expected.test_enums.test-enum.ts")] + [InlineData(typeof(TestInterface), "TypeGen.FileContentTest.CommonCases.Expected.test_interfaces.test-interface.ts")] + [InlineData(typeof(NestedEntity), "TypeGen.FileContentTest.CommonCases.Expected.very.nested.directory.nested-entity.ts")] + [InlineData(typeof(ArrayOfNullable), "TypeGen.FileContentTest.CommonCases.Expected.array-of-nullable.ts")] + + // now do the cases above for structs (when possible) + + [InlineData(typeof(Entities.Constants.Structs.FooConstants), "TypeGen.FileContentTest.CommonCases.Expected.foo-constants.ts")] + [InlineData(typeof(Entities.Structs.CustomBaseCustomImport), "TypeGen.FileContentTest.CommonCases.Expected.custom-base-custom-import.ts")] + [InlineData(typeof(Entities.Structs.CustomBaseClass), "TypeGen.FileContentTest.CommonCases.Expected.custom-base-class.ts")] + [InlineData(typeof(Entities.Structs.CustomEmptyBaseClass), "TypeGen.FileContentTest.CommonCases.Expected.custom-empty-base-class.ts")] + [InlineData(typeof(Entities.Structs.DefaultMemberValues), "TypeGen.FileContentTest.CommonCases.Expected.default-member-values_struct.ts")] + [InlineData(typeof(Entities.Structs.ExtendedPrimitivesClass), "TypeGen.FileContentTest.CommonCases.Expected.extended-primitives-class.ts")] + [InlineData(typeof(Entities.Structs.ExternalDepsClass), "TypeGen.FileContentTest.CommonCases.Expected.external-deps-class.ts")] + [InlineData(typeof(Entities.Structs.GenericBaseClass<>), "TypeGen.FileContentTest.CommonCases.Expected.generic-base-class.ts")] + [InlineData(typeof(Entities.Structs.GenericWithRestrictions<>), "TypeGen.FileContentTest.CommonCases.Expected.generic-with-restrictions.ts")] + [InlineData(typeof(Entities.Structs.ITestInterface), "TypeGen.FileContentTest.CommonCases.Expected.i-test-interface.ts")] + [InlineData(typeof(Entities.Structs.LiteDbEntity), "TypeGen.FileContentTest.CommonCases.Expected.lite-db-entity.ts")] + [InlineData(typeof(Entities.Structs.ReadonlyInterface), "TypeGen.FileContentTest.CommonCases.Expected.readonly-interface.ts")] + [InlineData(typeof(Entities.Structs.StaticReadonly), "TypeGen.FileContentTest.CommonCases.Expected.static-readonly.ts")] + [InlineData(typeof(Entities.Structs.StrictNullsClass), "TypeGen.FileContentTest.CommonCases.Expected.strict-nulls-class.ts")] + [InlineData(typeof(Entities.Structs.TypeUnions), "TypeGen.FileContentTest.CommonCases.Expected.type-unions.ts")] + [InlineData(typeof(Entities.Structs.NoSlashOutputDir), "TypeGen.FileContentTest.CommonCases.Expected.no.slash.output.dir.no-slash-output-dir.ts")] + [InlineData(typeof(Entities.Structs.TestInterface), "TypeGen.FileContentTest.CommonCases.Expected.test_interfaces.test-interface.ts")] + public async Task TestCommonCases(Type type, string expectedLocation) + { + await TestFromAssembly(type, expectedLocation); + } + } +} diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/ArrayOfNullable.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/ArrayOfNullable.cs similarity index 69% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/ArrayOfNullable.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/ArrayOfNullable.cs index 6b55eceb..1b894a9a 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/ArrayOfNullable.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/ArrayOfNullable.cs @@ -1,6 +1,6 @@ using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.CommonCases.Entities; +namespace TypeGen.FileContentTest.CommonCases.Entities; [ExportTsClass] public class ArrayOfNullable diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/BaseClass.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/BaseClass.cs similarity index 60% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/BaseClass.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/BaseClass.cs index 57de8a2b..72c07298 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/BaseClass.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/BaseClass.cs @@ -1,4 +1,4 @@ -namespace TypeGen.IntegrationTest.CommonCases.Entities +namespace TypeGen.FileContentTest.CommonCases.Entities { public class BaseClass { diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/BaseClass2.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/BaseClass2.cs similarity index 73% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/BaseClass2.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/BaseClass2.cs index c1e87f1c..4561e58d 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/BaseClass2.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/BaseClass2.cs @@ -1,4 +1,4 @@ -namespace TypeGen.IntegrationTest.CommonCases.Entities +namespace TypeGen.FileContentTest.CommonCases.Entities { public abstract class BaseClass2 { diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/CircularRefClass1.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/CircularRefClass1.cs similarity index 81% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/CircularRefClass1.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/CircularRefClass1.cs index f4efdd64..2d97018f 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/CircularRefClass1.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/CircularRefClass1.cs @@ -1,7 +1,7 @@ using System; using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.CommonCases.Entities +namespace TypeGen.FileContentTest.CommonCases.Entities { public class CircularRefClass1 { diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/CircularRefClass2.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/CircularRefClass2.cs similarity index 66% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/CircularRefClass2.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/CircularRefClass2.cs index 89dab4f5..555f68ed 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/CircularRefClass2.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/CircularRefClass2.cs @@ -1,4 +1,4 @@ -namespace TypeGen.IntegrationTest.CommonCases.Entities +namespace TypeGen.FileContentTest.CommonCases.Entities { public class CircularRefClass2 { diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Constants/FooConstants.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Constants/FooConstants.cs similarity index 91% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Constants/FooConstants.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Constants/FooConstants.cs index eb4d7a23..55e2accc 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Constants/FooConstants.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Constants/FooConstants.cs @@ -1,6 +1,6 @@ using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.CommonCases.Entities.Constants +namespace TypeGen.FileContentTest.CommonCases.Entities.Constants { [ExportTsClass] public static class FooConstants diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Constants/Structs/FooConstants.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Constants/Structs/FooConstants.cs similarity index 91% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Constants/Structs/FooConstants.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Constants/Structs/FooConstants.cs index c610cdc7..38400ced 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Constants/Structs/FooConstants.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Constants/Structs/FooConstants.cs @@ -1,6 +1,6 @@ using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.CommonCases.Entities.Constants.Structs +namespace TypeGen.FileContentTest.CommonCases.Entities.Constants.Structs { [ExportTsClass] public struct FooConstants diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/CustomBaseClass.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/CustomBaseClass.cs similarity index 78% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/CustomBaseClass.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/CustomBaseClass.cs index e93ae45c..c31edcf9 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/CustomBaseClass.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/CustomBaseClass.cs @@ -1,6 +1,6 @@ using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.CommonCases.Entities +namespace TypeGen.FileContentTest.CommonCases.Entities { [ExportTsClass] [TsCustomBase("AcmeCustomBase")] diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/CustomBaseCustomImport.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/CustomBaseCustomImport.cs similarity index 77% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/CustomBaseCustomImport.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/CustomBaseCustomImport.cs index 765b39ab..39558a3d 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/CustomBaseCustomImport.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/CustomBaseCustomImport.cs @@ -1,6 +1,6 @@ using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.CommonCases.Entities +namespace TypeGen.FileContentTest.CommonCases.Entities { [ExportTsInterface] [TsCustomBase("MB", "./my/base/my-base", "MyBase")] diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/CustomEmptyBaseClass.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/CustomEmptyBaseClass.cs similarity index 78% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/CustomEmptyBaseClass.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/CustomEmptyBaseClass.cs index 21e27338..d64d1216 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/CustomEmptyBaseClass.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/CustomEmptyBaseClass.cs @@ -1,6 +1,6 @@ using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.CommonCases.Entities +namespace TypeGen.FileContentTest.CommonCases.Entities { [ExportTsInterface] [TsCustomBase] diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/CustomMappingsClassGenerationIssue/ClassWithUri.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/CustomMappingsClassGenerationIssue/ClassWithUri.cs similarity index 71% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/CustomMappingsClassGenerationIssue/ClassWithUri.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/CustomMappingsClassGenerationIssue/ClassWithUri.cs index 22194965..93677fb0 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/CustomMappingsClassGenerationIssue/ClassWithUri.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/CustomMappingsClassGenerationIssue/ClassWithUri.cs @@ -1,7 +1,7 @@ using System; using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.CommonCases.Entities.CustomMappingsClassGenerationIssue; +namespace TypeGen.FileContentTest.CommonCases.Entities.CustomMappingsClassGenerationIssue; [ExportTsClass] public class ClassWithUri diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/DefaultMemberComplexValues.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/DefaultMemberComplexValues.cs similarity index 83% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/DefaultMemberComplexValues.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/DefaultMemberComplexValues.cs index 20f33373..8d8bd86b 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/DefaultMemberComplexValues.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/DefaultMemberComplexValues.cs @@ -1,6 +1,6 @@ #nullable enable -namespace TypeGen.IntegrationTest.CommonCases.Entities +namespace TypeGen.FileContentTest.CommonCases.Entities { public class DefaultMemberComplexValues { diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/DefaultMemberValues.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/DefaultMemberValues.cs similarity index 92% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/DefaultMemberValues.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/DefaultMemberValues.cs index a8c3c1c6..8c0e84aa 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/DefaultMemberValues.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/DefaultMemberValues.cs @@ -1,7 +1,7 @@ using System; using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.CommonCases.Entities +namespace TypeGen.FileContentTest.CommonCases.Entities { [ExportTsClass] public class DefaultMemberValues diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/DictionaryStringObjectErrorCase.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/DictionaryStringObjectErrorCase.cs similarity index 77% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/DictionaryStringObjectErrorCase.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/DictionaryStringObjectErrorCase.cs index 139dfbe7..963af2a2 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/DictionaryStringObjectErrorCase.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/DictionaryStringObjectErrorCase.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.CommonCases.Entities; +namespace TypeGen.FileContentTest.CommonCases.Entities; [ExportTsClass] public class DictionaryStringObjectErrorCase diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/DictionaryWithEnumKey.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/DictionaryWithEnumKey.cs similarity index 78% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/DictionaryWithEnumKey.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/DictionaryWithEnumKey.cs index 32782800..945c5405 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/DictionaryWithEnumKey.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/DictionaryWithEnumKey.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.CommonCases.Entities; +namespace TypeGen.FileContentTest.CommonCases.Entities; [ExportTsClass] public class DictionaryWithEnumKey diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/EnumAsUnionType.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/EnumAsUnionType.cs similarity index 76% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/EnumAsUnionType.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/EnumAsUnionType.cs index 9a805dd3..6bcd91b9 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/EnumAsUnionType.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/EnumAsUnionType.cs @@ -1,6 +1,6 @@ using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.CommonCases.Entities +namespace TypeGen.FileContentTest.CommonCases.Entities { [ExportTsEnum(AsUnionType = true)] public enum EnumAsUnionType diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/EnumShortValues.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/EnumShortValues.cs similarity index 71% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/EnumShortValues.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/EnumShortValues.cs index 12fa2805..521af860 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/EnumShortValues.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/EnumShortValues.cs @@ -1,6 +1,6 @@ using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.CommonCases.Entities +namespace TypeGen.FileContentTest.CommonCases.Entities { [ExportTsEnum] public enum EnumShortValues : short diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/EnumWithCustomHeadAndBody.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/EnumWithCustomHeadAndBody.cs similarity index 68% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/EnumWithCustomHeadAndBody.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/EnumWithCustomHeadAndBody.cs index 9dbd2b7f..16a77e90 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/EnumWithCustomHeadAndBody.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/EnumWithCustomHeadAndBody.cs @@ -1,6 +1,6 @@ using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.CommonCases.Entities; +namespace TypeGen.FileContentTest.CommonCases.Entities; [ExportTsEnum] public enum EnumWithCustomHeadAndBody diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/ErrorCase/Bar.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/ErrorCase/Bar.cs similarity index 86% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/ErrorCase/Bar.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/ErrorCase/Bar.cs index 496eff44..1610ff52 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/ErrorCase/Bar.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/ErrorCase/Bar.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -namespace TypeGen.IntegrationTest.CommonCases.Entities.ErrorCase +namespace TypeGen.FileContentTest.CommonCases.Entities.ErrorCase { public class Bar { diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/ErrorCase/C.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/ErrorCase/C.cs similarity index 87% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/ErrorCase/C.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/ErrorCase/C.cs index 24263531..648e3af5 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/ErrorCase/C.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/ErrorCase/C.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -namespace TypeGen.IntegrationTest.CommonCases.Entities.ErrorCase +namespace TypeGen.FileContentTest.CommonCases.Entities.ErrorCase { public class C { diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/ErrorCase/D.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/ErrorCase/D.cs similarity index 96% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/ErrorCase/D.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/ErrorCase/D.cs index 29222c62..78257181 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/ErrorCase/D.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/ErrorCase/D.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.CommonCases.Entities.ErrorCase +namespace TypeGen.FileContentTest.CommonCases.Entities.ErrorCase { public class D : GenericClass { diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/ErrorCase/EClass.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/ErrorCase/EClass.cs similarity index 93% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/ErrorCase/EClass.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/ErrorCase/EClass.cs index 75271d15..6676e634 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/ErrorCase/EClass.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/ErrorCase/EClass.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; -namespace TypeGen.IntegrationTest.CommonCases.Entities.ErrorCase +namespace TypeGen.FileContentTest.CommonCases.Entities.ErrorCase { public class EClass : GenericClass { diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/ErrorCase/FClass.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/ErrorCase/FClass.cs similarity index 88% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/ErrorCase/FClass.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/ErrorCase/FClass.cs index c0880e0d..6ed0a407 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/ErrorCase/FClass.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/ErrorCase/FClass.cs @@ -1,6 +1,6 @@ using System.ComponentModel.DataAnnotations; -namespace TypeGen.IntegrationTest.CommonCases.Entities.ErrorCase +namespace TypeGen.FileContentTest.CommonCases.Entities.ErrorCase { public class FClass : GenericClass { diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/ErrorCase/Foo.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/ErrorCase/Foo.cs similarity index 84% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/ErrorCase/Foo.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/ErrorCase/Foo.cs index 9ce88aa1..fa242c59 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/ErrorCase/Foo.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/ErrorCase/Foo.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.CommonCases.Entities.ErrorCase +namespace TypeGen.FileContentTest.CommonCases.Entities.ErrorCase { [ExportTsClass] public class Foo diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/ErrorCase/FooType.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/ErrorCase/FooType.cs similarity index 66% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/ErrorCase/FooType.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/ErrorCase/FooType.cs index 3f740359..6d581cd4 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/ErrorCase/FooType.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/ErrorCase/FooType.cs @@ -1,4 +1,4 @@ -namespace TypeGen.IntegrationTest.CommonCases.Entities.ErrorCase +namespace TypeGen.FileContentTest.CommonCases.Entities.ErrorCase { public enum FooType { diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/ExtendedPrimitivesClass.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/ExtendedPrimitivesClass.cs similarity index 93% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/ExtendedPrimitivesClass.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/ExtendedPrimitivesClass.cs index 4cc46ad1..3c34f845 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/ExtendedPrimitivesClass.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/ExtendedPrimitivesClass.cs @@ -1,7 +1,7 @@ using System; using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.CommonCases.Entities +namespace TypeGen.FileContentTest.CommonCases.Entities { [ExportTsClass] public class ExtendedPrimitivesClass diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/ExternalDepsClass.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/ExternalDepsClass.cs similarity index 79% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/ExternalDepsClass.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/ExternalDepsClass.cs index 39cb5bf6..a1872a75 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/ExternalDepsClass.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/ExternalDepsClass.cs @@ -1,7 +1,7 @@ using Microsoft.AspNetCore.Identity; using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.CommonCases.Entities +namespace TypeGen.FileContentTest.CommonCases.Entities { [ExportTsClass] public class ExternalDepsClass diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/GenericBaseClass.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/GenericBaseClass.cs similarity index 67% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/GenericBaseClass.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/GenericBaseClass.cs index 38897f31..32dfd969 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/GenericBaseClass.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/GenericBaseClass.cs @@ -1,6 +1,6 @@ using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.CommonCases.Entities +namespace TypeGen.FileContentTest.CommonCases.Entities { [ExportTsClass] public class GenericBaseClass diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/GenericClass.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/GenericClass.cs similarity index 83% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/GenericClass.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/GenericClass.cs index 277c380d..5c34fae1 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/GenericClass.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/GenericClass.cs @@ -1,6 +1,6 @@ using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.CommonCases.Entities +namespace TypeGen.FileContentTest.CommonCases.Entities { [ExportTsClass] public class GenericClass : GenericBaseClass diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/GenericWithRestrictions.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/GenericWithRestrictions.cs similarity index 72% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/GenericWithRestrictions.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/GenericWithRestrictions.cs index 1194d009..777b1789 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/GenericWithRestrictions.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/GenericWithRestrictions.cs @@ -1,6 +1,6 @@ using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.CommonCases.Entities +namespace TypeGen.FileContentTest.CommonCases.Entities { [ExportTsClass] public class GenericWithRestrictions where T: TestInterface diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/ITestInterface.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/ITestInterface.cs similarity index 81% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/ITestInterface.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/ITestInterface.cs index a6a0d43e..e135005d 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/ITestInterface.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/ITestInterface.cs @@ -1,7 +1,7 @@ using System; using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.CommonCases.Entities +namespace TypeGen.FileContentTest.CommonCases.Entities { [ExportTsInterface] public interface ITestInterface diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/JsonProperty/JsonPropertyTest.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/JsonProperty/JsonPropertyTest.cs similarity index 79% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/JsonProperty/JsonPropertyTest.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/JsonProperty/JsonPropertyTest.cs index 00561870..98b15c75 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/JsonProperty/JsonPropertyTest.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/JsonProperty/JsonPropertyTest.cs @@ -1,7 +1,7 @@ using Newtonsoft.Json; using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.CommonCases.Entities.JsonProperty +namespace TypeGen.FileContentTest.CommonCases.Entities.JsonProperty { [ExportTsClass(OutputDir = "json-property-test")] public class JsonPropertyTest diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/LiteDbEntity.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/LiteDbEntity.cs similarity index 81% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/LiteDbEntity.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/LiteDbEntity.cs index 9a7cd432..91fd905b 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/LiteDbEntity.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/LiteDbEntity.cs @@ -1,7 +1,7 @@ using LiteDB; using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.CommonCases.Entities +namespace TypeGen.FileContentTest.CommonCases.Entities { [ExportTsClass] public class LiteDbEntity diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/NestedEntity.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/NestedEntity.cs similarity index 84% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/NestedEntity.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/NestedEntity.cs index 743cab14..0bfea944 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/NestedEntity.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/NestedEntity.cs @@ -1,6 +1,6 @@ using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.CommonCases.Entities +namespace TypeGen.FileContentTest.CommonCases.Entities { [ExportTsInterface(OutputDir = "./very/nested/directory/")] public class NestedEntity diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/NoSlashOutputDir.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/NoSlashOutputDir.cs similarity index 78% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/NoSlashOutputDir.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/NoSlashOutputDir.cs index be92f91a..76888711 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/NoSlashOutputDir.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/NoSlashOutputDir.cs @@ -1,6 +1,6 @@ using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.CommonCases.Entities +namespace TypeGen.FileContentTest.CommonCases.Entities { [ExportTsClass(OutputDir = "no/slash/output/dir")] public class NoSlashOutputDir diff --git a/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/NotGeneratedBaseClass.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/NotGeneratedBaseClass.cs new file mode 100644 index 00000000..1819e4f2 --- /dev/null +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/NotGeneratedBaseClass.cs @@ -0,0 +1,6 @@ +namespace TypeGen.FileContentTest.CommonCases.Entities +{ + public class NotGeneratedBaseClass + { + } +} diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/ReadonlyInterface.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/ReadonlyInterface.cs similarity index 73% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/ReadonlyInterface.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/ReadonlyInterface.cs index bf172b44..6e367c8a 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/ReadonlyInterface.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/ReadonlyInterface.cs @@ -1,6 +1,6 @@ using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.CommonCases.Entities +namespace TypeGen.FileContentTest.CommonCases.Entities { [ExportTsInterface] public class ReadonlyInterface diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/StandaloneEnum.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/StandaloneEnum.cs similarity index 72% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/StandaloneEnum.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/StandaloneEnum.cs index cb876aa6..98e85329 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/StandaloneEnum.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/StandaloneEnum.cs @@ -1,6 +1,6 @@ using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.CommonCases.Entities +namespace TypeGen.FileContentTest.CommonCases.Entities { [ExportTsEnum] public enum StandaloneEnum diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/StaticReadonly.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/StaticReadonly.cs similarity index 88% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/StaticReadonly.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/StaticReadonly.cs index bf8cc3fa..f29d45b4 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/StaticReadonly.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/StaticReadonly.cs @@ -1,6 +1,6 @@ using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.CommonCases.Entities +namespace TypeGen.FileContentTest.CommonCases.Entities { [ExportTsClass] public class StaticReadonly diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/StrictNullsClass.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/StrictNullsClass.cs similarity index 93% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/StrictNullsClass.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/StrictNullsClass.cs index 1fc2d0ca..5f6b013e 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/StrictNullsClass.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/StrictNullsClass.cs @@ -1,6 +1,6 @@ using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.CommonCases.Entities +namespace TypeGen.FileContentTest.CommonCases.Entities { [ExportTsClass] public class StrictNullsClass diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Structs/BaseClass.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Structs/BaseClass.cs similarity index 59% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Structs/BaseClass.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Structs/BaseClass.cs index c7e3da82..46f546fe 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Structs/BaseClass.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Structs/BaseClass.cs @@ -1,4 +1,4 @@ -namespace TypeGen.IntegrationTest.CommonCases.Entities.Structs +namespace TypeGen.FileContentTest.CommonCases.Entities.Structs { public struct BaseClass { diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Structs/CustomBaseClass.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Structs/CustomBaseClass.cs similarity index 76% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Structs/CustomBaseClass.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Structs/CustomBaseClass.cs index d15dc290..671175cf 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Structs/CustomBaseClass.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Structs/CustomBaseClass.cs @@ -1,6 +1,6 @@ using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.CommonCases.Entities.Structs +namespace TypeGen.FileContentTest.CommonCases.Entities.Structs { [ExportTsClass] [TsCustomBase("AcmeCustomBase")] diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Structs/CustomBaseCustomImport.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Structs/CustomBaseCustomImport.cs similarity index 70% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Structs/CustomBaseCustomImport.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Structs/CustomBaseCustomImport.cs index ececf2eb..2ca02e70 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Structs/CustomBaseCustomImport.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Structs/CustomBaseCustomImport.cs @@ -1,6 +1,6 @@ using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.CommonCases.Entities.Structs; +namespace TypeGen.FileContentTest.CommonCases.Entities.Structs; [ExportTsInterface] [TsCustomBase("MB", "./my/base/my-base", "MyBase")] diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Structs/CustomEmptyBaseClass.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Structs/CustomEmptyBaseClass.cs similarity index 74% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Structs/CustomEmptyBaseClass.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Structs/CustomEmptyBaseClass.cs index eab9811c..b569e0fe 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Structs/CustomEmptyBaseClass.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Structs/CustomEmptyBaseClass.cs @@ -1,6 +1,6 @@ using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.CommonCases.Entities.Structs +namespace TypeGen.FileContentTest.CommonCases.Entities.Structs { [ExportTsInterface] [TsCustomBase] diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Structs/DefaultMemberComplexValues.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Structs/DefaultMemberComplexValues.cs similarity index 86% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Structs/DefaultMemberComplexValues.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Structs/DefaultMemberComplexValues.cs index d5f0bfb0..d455e309 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Structs/DefaultMemberComplexValues.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Structs/DefaultMemberComplexValues.cs @@ -1,6 +1,6 @@ #nullable enable -namespace TypeGen.IntegrationTest.CommonCases.Entities.Structs +namespace TypeGen.FileContentTest.CommonCases.Entities.Structs { public struct DefaultMemberComplexValues { diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Structs/DefaultMemberValues.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Structs/DefaultMemberValues.cs similarity index 93% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Structs/DefaultMemberValues.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Structs/DefaultMemberValues.cs index 5a88c29e..14692a34 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Structs/DefaultMemberValues.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Structs/DefaultMemberValues.cs @@ -1,7 +1,7 @@ using System; using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.CommonCases.Entities.Structs +namespace TypeGen.FileContentTest.CommonCases.Entities.Structs { [ExportTsClass] public struct DefaultMemberValues diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Structs/ExtendedPrimitivesClass.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Structs/ExtendedPrimitivesClass.cs similarity index 94% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Structs/ExtendedPrimitivesClass.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Structs/ExtendedPrimitivesClass.cs index e57fe2e8..5aab5639 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Structs/ExtendedPrimitivesClass.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Structs/ExtendedPrimitivesClass.cs @@ -1,7 +1,7 @@ using System; using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.CommonCases.Entities.Structs +namespace TypeGen.FileContentTest.CommonCases.Entities.Structs { [ExportTsClass] public struct ExtendedPrimitivesClass diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Structs/ExternalDepsClass.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Structs/ExternalDepsClass.cs similarity index 77% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Structs/ExternalDepsClass.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Structs/ExternalDepsClass.cs index d8d96921..65e3c306 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Structs/ExternalDepsClass.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Structs/ExternalDepsClass.cs @@ -1,7 +1,7 @@ using Microsoft.AspNetCore.Identity; using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.CommonCases.Entities.Structs +namespace TypeGen.FileContentTest.CommonCases.Entities.Structs { [ExportTsClass] public struct ExternalDepsClass diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Structs/GenericBaseClass.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Structs/GenericBaseClass.cs similarity index 58% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Structs/GenericBaseClass.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Structs/GenericBaseClass.cs index 5b05a8b9..e5a23fec 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Structs/GenericBaseClass.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Structs/GenericBaseClass.cs @@ -1,6 +1,6 @@ using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.CommonCases.Entities.Structs; +namespace TypeGen.FileContentTest.CommonCases.Entities.Structs; [ExportTsClass] public struct GenericBaseClass diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Structs/GenericWithRestrictions.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Structs/GenericWithRestrictions.cs similarity index 71% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Structs/GenericWithRestrictions.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Structs/GenericWithRestrictions.cs index ee9372de..8c1516fc 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Structs/GenericWithRestrictions.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Structs/GenericWithRestrictions.cs @@ -1,6 +1,6 @@ using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.CommonCases.Entities.Structs +namespace TypeGen.FileContentTest.CommonCases.Entities.Structs { [ExportTsClass] public struct GenericWithRestrictions where T: Entities.TestInterface diff --git a/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Structs/IBar.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Structs/IBar.cs new file mode 100644 index 00000000..a832d8ae --- /dev/null +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Structs/IBar.cs @@ -0,0 +1,6 @@ +namespace TypeGen.FileContentTest.CommonCases.Entities.Structs; + +public interface IBar +{ + +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Structs/IFoo.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Structs/IFoo.cs new file mode 100644 index 00000000..9cdebd35 --- /dev/null +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Structs/IFoo.cs @@ -0,0 +1,6 @@ +namespace TypeGen.FileContentTest.CommonCases.Entities.Structs; + +public interface IFoo +{ + +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Structs/ITestInterface.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Structs/ITestInterface.cs similarity index 80% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Structs/ITestInterface.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Structs/ITestInterface.cs index 77bf281d..9c9102d1 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Structs/ITestInterface.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Structs/ITestInterface.cs @@ -1,7 +1,7 @@ using System; using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.CommonCases.Entities.Structs +namespace TypeGen.FileContentTest.CommonCases.Entities.Structs { [ExportTsInterface] public struct ITestInterface diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Structs/LiteDbEntity.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Structs/LiteDbEntity.cs similarity index 79% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Structs/LiteDbEntity.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Structs/LiteDbEntity.cs index d230bc0e..982ff641 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Structs/LiteDbEntity.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Structs/LiteDbEntity.cs @@ -1,7 +1,7 @@ using LiteDB; using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.CommonCases.Entities.Structs +namespace TypeGen.FileContentTest.CommonCases.Entities.Structs { [ExportTsClass] public struct LiteDbEntity diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Structs/NoSlashOutputDir.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Structs/NoSlashOutputDir.cs similarity index 76% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Structs/NoSlashOutputDir.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Structs/NoSlashOutputDir.cs index a0734de2..c01009b0 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Structs/NoSlashOutputDir.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Structs/NoSlashOutputDir.cs @@ -1,6 +1,6 @@ using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.CommonCases.Entities.Structs +namespace TypeGen.FileContentTest.CommonCases.Entities.Structs { [ExportTsClass(OutputDir = "no/slash/output/dir")] public struct NoSlashOutputDir diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Structs/ReadonlyInterface.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Structs/ReadonlyInterface.cs similarity index 71% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Structs/ReadonlyInterface.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Structs/ReadonlyInterface.cs index 2460c444..e5f8d99b 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Structs/ReadonlyInterface.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Structs/ReadonlyInterface.cs @@ -1,6 +1,6 @@ using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.CommonCases.Entities.Structs +namespace TypeGen.FileContentTest.CommonCases.Entities.Structs { [ExportTsInterface] public struct ReadonlyInterface diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Structs/StaticReadonly.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Structs/StaticReadonly.cs similarity index 87% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Structs/StaticReadonly.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Structs/StaticReadonly.cs index 9a48e570..df828a53 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Structs/StaticReadonly.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Structs/StaticReadonly.cs @@ -1,6 +1,6 @@ using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.CommonCases.Entities.Structs +namespace TypeGen.FileContentTest.CommonCases.Entities.Structs { [ExportTsClass] public struct StaticReadonly diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Structs/StrictNullsClass.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Structs/StrictNullsClass.cs similarity index 92% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Structs/StrictNullsClass.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Structs/StrictNullsClass.cs index 529e9279..4e265e7a 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Structs/StrictNullsClass.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Structs/StrictNullsClass.cs @@ -1,6 +1,6 @@ using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.CommonCases.Entities.Structs +namespace TypeGen.FileContentTest.CommonCases.Entities.Structs { [ExportTsClass] public struct StrictNullsClass diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Structs/TestInterface.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Structs/TestInterface.cs similarity index 74% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Structs/TestInterface.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Structs/TestInterface.cs index 27a1c9fa..e98f3691 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Structs/TestInterface.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Structs/TestInterface.cs @@ -1,6 +1,6 @@ using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.CommonCases.Entities.Structs +namespace TypeGen.FileContentTest.CommonCases.Entities.Structs { [ExportTsInterface(OutputDir = "test-interfaces")] public struct TestInterface diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Structs/TypeUnions.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Structs/TypeUnions.cs similarity index 87% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Structs/TypeUnions.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Structs/TypeUnions.cs index 8683d1ca..3ea310a6 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Structs/TypeUnions.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/Structs/TypeUnions.cs @@ -1,6 +1,6 @@ using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.CommonCases.Entities.Structs +namespace TypeGen.FileContentTest.CommonCases.Entities.Structs { [ExportTsClass] public struct TypeUnions diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/TestClass.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/TestClass.cs similarity index 96% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/TestClass.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/TestClass.cs index c0aa0774..338508a7 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/TestClass.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/TestClass.cs @@ -3,7 +3,7 @@ using System.Text.RegularExpressions; using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.CommonCases.Entities +namespace TypeGen.FileContentTest.CommonCases.Entities { [ExportTsClass(OutputDir = "test-classes")] public class TestClass : BaseClass where U : BaseClass2 diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/TestEnum.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/TestEnum.cs similarity index 73% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/TestEnum.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/TestEnum.cs index 2dc9e277..bf9393a1 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/TestEnum.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/TestEnum.cs @@ -1,6 +1,6 @@ using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.CommonCases.Entities +namespace TypeGen.FileContentTest.CommonCases.Entities { [ExportTsEnum(OutputDir = "test-enums", IsConst = true)] public enum TestEnum diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/TestInterface.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/TestInterface.cs similarity index 77% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/TestInterface.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/TestInterface.cs index b5809f30..c32dd90e 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/TestInterface.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/TestInterface.cs @@ -1,6 +1,6 @@ using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.CommonCases.Entities +namespace TypeGen.FileContentTest.CommonCases.Entities { [ExportTsInterface(OutputDir = "test-interfaces")] public class TestInterface diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/TypeUnions.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/TypeUnions.cs similarity index 88% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/TypeUnions.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/TypeUnions.cs index 315020bf..df2b6ac8 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/TypeUnions.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/TypeUnions.cs @@ -1,6 +1,6 @@ using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.CommonCases.Entities +namespace TypeGen.FileContentTest.CommonCases.Entities { [ExportTsClass] public class TypeUnions diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/WithGenericBaseClassCustomType.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/WithGenericBaseClassCustomType.cs similarity index 76% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/WithGenericBaseClassCustomType.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/WithGenericBaseClassCustomType.cs index 7e742122..cf9ee46a 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/WithGenericBaseClassCustomType.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/WithGenericBaseClassCustomType.cs @@ -1,6 +1,6 @@ using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.CommonCases.Entities +namespace TypeGen.FileContentTest.CommonCases.Entities { [ExportTsClass] public class WithGenericBaseClassCustomType : BaseClass>> diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/WithIgnoredBase.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/WithIgnoredBase.cs similarity index 78% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/WithIgnoredBase.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/WithIgnoredBase.cs index c4536141..201065a0 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/WithIgnoredBase.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/WithIgnoredBase.cs @@ -1,6 +1,6 @@ using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.CommonCases.Entities +namespace TypeGen.FileContentTest.CommonCases.Entities { [ExportTsClass] [TsIgnoreBase] diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/WithIgnoredBaseAndCustomBase.cs b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/WithIgnoredBaseAndCustomBase.cs similarity index 78% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/WithIgnoredBaseAndCustomBase.cs rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/WithIgnoredBaseAndCustomBase.cs index 447e2f6f..19e0ce52 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/WithIgnoredBaseAndCustomBase.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Entities/WithIgnoredBaseAndCustomBase.cs @@ -1,6 +1,6 @@ using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.CommonCases.Entities +namespace TypeGen.FileContentTest.CommonCases.Entities { [ExportTsClass] [TsIgnoreBase] diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/array-of-nullable.ts b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/array-of-nullable.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/array-of-nullable.ts rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/array-of-nullable.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/bar.ts b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/bar.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/bar.ts rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/bar.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/base-class.ts b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/base-class.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/base-class.ts rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/base-class.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/base-class2.ts b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/base-class2.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/base-class2.ts rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/base-class2.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/c.ts b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/c.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/c.ts rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/c.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/custom-base-class.ts b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/custom-base-class.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/custom-base-class.ts rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/custom-base-class.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/custom-base-custom-import.ts b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/custom-base-custom-import.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/custom-base-custom-import.ts rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/custom-base-custom-import.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/custom-empty-base-class.ts b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/custom-empty-base-class.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/custom-empty-base-class.ts rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/custom-empty-base-class.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/d.ts b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/d.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/d.ts rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/d.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/default-member-values.ts b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/default-member-values.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/default-member-values.ts rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/default-member-values.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/default-member-values_struct.ts b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/default-member-values_struct.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/default-member-values_struct.ts rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/default-member-values_struct.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/dictionary-string-object-error-case.ts b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/dictionary-string-object-error-case.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/dictionary-string-object-error-case.ts rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/dictionary-string-object-error-case.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/dictionary-with-enum-key.ts b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/dictionary-with-enum-key.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/dictionary-with-enum-key.ts rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/dictionary-with-enum-key.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/e-class.ts b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/e-class.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/e-class.ts rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/e-class.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/enum-as-union-type.ts b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/enum-as-union-type.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/enum-as-union-type.ts rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/enum-as-union-type.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/enum-short-values.ts b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/enum-short-values.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/enum-short-values.ts rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/enum-short-values.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/extended-primitives-class.ts b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/extended-primitives-class.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/extended-primitives-class.ts rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/extended-primitives-class.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/external-deps-class.ts b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/external-deps-class.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/external-deps-class.ts rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/external-deps-class.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/f-class.ts b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/f-class.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/f-class.ts rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/f-class.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/foo-constants.ts b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/foo-constants.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/foo-constants.ts rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/foo-constants.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/foo-type.ts b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/foo-type.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/foo-type.ts rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/foo-type.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/foo.ts b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/foo.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/foo.ts rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/foo.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/generic-base-class.ts b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/generic-base-class.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/generic-base-class.ts rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/generic-base-class.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/generic-class.ts b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/generic-class.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/generic-class.ts rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/generic-class.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/generic-with-restrictions.ts b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/generic-with-restrictions.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/generic-with-restrictions.ts rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/generic-with-restrictions.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/i-test-interface.ts b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/i-test-interface.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/i-test-interface.ts rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/i-test-interface.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/index.ts b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/index.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/index.ts rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/index.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/lite-db-entity.ts b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/lite-db-entity.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/lite-db-entity.ts rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/lite-db-entity.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/no/slash/output/dir/no-slash-output-dir.ts b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/no/slash/output/dir/no-slash-output-dir.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/no/slash/output/dir/no-slash-output-dir.ts rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/no/slash/output/dir/no-slash-output-dir.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/readonly-interface.ts b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/readonly-interface.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/readonly-interface.ts rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/readonly-interface.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/standalone-enum.ts b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/standalone-enum.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/standalone-enum.ts rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/standalone-enum.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/static-readonly.ts b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/static-readonly.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/static-readonly.ts rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/static-readonly.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/strict-nulls-class.ts b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/strict-nulls-class.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/strict-nulls-class.ts rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/strict-nulls-class.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/test-classes/base-class.ts b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/test-classes/base-class.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/test-classes/base-class.ts rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/test-classes/base-class.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/test-classes/base-class2.ts b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/test-classes/base-class2.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/test-classes/base-class2.ts rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/test-classes/base-class2.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/test-classes/circular-ref-class1.ts b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/test-classes/circular-ref-class1.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/test-classes/circular-ref-class1.ts rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/test-classes/circular-ref-class1.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/test-classes/circular-ref-class2.ts b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/test-classes/circular-ref-class2.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/test-classes/circular-ref-class2.ts rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/test-classes/circular-ref-class2.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/test-classes/test-class.ts b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/test-classes/test-class.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/test-classes/test-class.ts rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/test-classes/test-class.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/test-enums/test-enum.ts b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/test-enums/test-enum.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/test-enums/test-enum.ts rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/test-enums/test-enum.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/test-interfaces/test-interface.ts b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/test-interfaces/test-interface.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/test-interfaces/test-interface.ts rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/test-interfaces/test-interface.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/type-unions.ts b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/type-unions.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/type-unions.ts rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/type-unions.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/very/nested/directory/nested-entity.ts b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/very/nested/directory/nested-entity.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/very/nested/directory/nested-entity.ts rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/very/nested/directory/nested-entity.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/with-generic-base-class-custom-type.ts b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/with-generic-base-class-custom-type.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/with-generic-base-class-custom-type.ts rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/with-generic-base-class-custom-type.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/with-ignored-base-and-custom-base.ts b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/with-ignored-base-and-custom-base.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/with-ignored-base-and-custom-base.ts rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/with-ignored-base-and-custom-base.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/with-ignored-base.ts b/src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/with-ignored-base.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/CommonCases/Expected/with-ignored-base.ts rename to src/TypeGen/TypeGen.FileContentTest/CommonCases/Expected/with-ignored-base.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/ConstantsOnly/ConstantsOnlyTest.cs b/src/TypeGen/TypeGen.FileContentTest/ConstantsOnly/ConstantsOnlyTest.cs similarity index 77% rename from src/TypeGen/TypeGen.IntegrationTest/ConstantsOnly/ConstantsOnlyTest.cs rename to src/TypeGen/TypeGen.FileContentTest/ConstantsOnly/ConstantsOnlyTest.cs index 1628e900..ccab3b10 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/ConstantsOnly/ConstantsOnlyTest.cs +++ b/src/TypeGen/TypeGen.FileContentTest/ConstantsOnly/ConstantsOnlyTest.cs @@ -2,15 +2,15 @@ using System.Threading.Tasks; using TypeGen.Core.Generator; using TypeGen.Core.SpecGeneration; -using TypeGen.IntegrationTest.TestingUtils; +using TypeGen.FileContentTest.TestingUtils; using Xunit; -namespace TypeGen.IntegrationTest.ConstantsOnly; +namespace TypeGen.FileContentTest.ConstantsOnly; public class ConstantsOnlyTest : GenerationTestBase { [Theory] - [InlineData(typeof(Entities.ConstantsOnly), "TypeGen.IntegrationTest.ConstantsOnly.Expected.constants-only.ts")] + [InlineData(typeof(Entities.ConstantsOnly), "TypeGen.FileContentTest.ConstantsOnly.Expected.constants-only.ts")] public async Task TestConstantsOnlyGenerationSpec(Type type, string expectedLocation) { var generationSpec = new ConstantsOnlyGenerationSpec(); diff --git a/src/TypeGen/TypeGen.IntegrationTest/ConstantsOnly/Entities/ConstantsOnly.cs b/src/TypeGen/TypeGen.FileContentTest/ConstantsOnly/Entities/ConstantsOnly.cs similarity index 91% rename from src/TypeGen/TypeGen.IntegrationTest/ConstantsOnly/Entities/ConstantsOnly.cs rename to src/TypeGen/TypeGen.FileContentTest/ConstantsOnly/Entities/ConstantsOnly.cs index 74751787..59bbf2ce 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/ConstantsOnly/Entities/ConstantsOnly.cs +++ b/src/TypeGen/TypeGen.FileContentTest/ConstantsOnly/Entities/ConstantsOnly.cs @@ -1,6 +1,6 @@ using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.ConstantsOnly.Entities +namespace TypeGen.FileContentTest.ConstantsOnly.Entities { [ExportTsClass] public class ConstantsOnly diff --git a/src/TypeGen/TypeGen.IntegrationTest/ConstantsOnly/Expected/constants-only.ts b/src/TypeGen/TypeGen.FileContentTest/ConstantsOnly/Expected/constants-only.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/ConstantsOnly/Expected/constants-only.ts rename to src/TypeGen/TypeGen.FileContentTest/ConstantsOnly/Expected/constants-only.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/Converters/JsonMemberNameConverter.cs b/src/TypeGen/TypeGen.FileContentTest/Converters/JsonMemberNameConverter.cs similarity index 89% rename from src/TypeGen/TypeGen.IntegrationTest/Converters/JsonMemberNameConverter.cs rename to src/TypeGen/TypeGen.FileContentTest/Converters/JsonMemberNameConverter.cs index f25efa62..21219302 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/Converters/JsonMemberNameConverter.cs +++ b/src/TypeGen/TypeGen.FileContentTest/Converters/JsonMemberNameConverter.cs @@ -2,7 +2,7 @@ using Newtonsoft.Json; using TypeGen.Core.Converters; -namespace TypeGen.IntegrationTest.Converters +namespace TypeGen.FileContentTest.Converters { public class JsonMemberNameConverter : IMemberNameConverter { diff --git a/src/TypeGen/TypeGen.IntegrationTest/Converters/PascalCaseToCamelCaseJsonConverter.cs b/src/TypeGen/TypeGen.FileContentTest/Converters/PascalCaseToCamelCaseJsonConverter.cs similarity index 91% rename from src/TypeGen/TypeGen.IntegrationTest/Converters/PascalCaseToCamelCaseJsonConverter.cs rename to src/TypeGen/TypeGen.FileContentTest/Converters/PascalCaseToCamelCaseJsonConverter.cs index 99b6fdbc..74442fab 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/Converters/PascalCaseToCamelCaseJsonConverter.cs +++ b/src/TypeGen/TypeGen.FileContentTest/Converters/PascalCaseToCamelCaseJsonConverter.cs @@ -2,7 +2,7 @@ using Newtonsoft.Json; using TypeGen.Core.Converters; -namespace TypeGen.IntegrationTest.Converters +namespace TypeGen.FileContentTest.Converters { public class PascalCaseToCamelCaseJsonConverter : IMemberNameConverter { diff --git a/src/TypeGen/TypeGen.IntegrationTest/CustomBaseInterfaces/CustomBaseInterfacesTest.cs b/src/TypeGen/TypeGen.FileContentTest/CustomBaseInterfaces/CustomBaseInterfacesTest.cs similarity index 81% rename from src/TypeGen/TypeGen.IntegrationTest/CustomBaseInterfaces/CustomBaseInterfacesTest.cs rename to src/TypeGen/TypeGen.FileContentTest/CustomBaseInterfaces/CustomBaseInterfacesTest.cs index e3099449..63d81803 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CustomBaseInterfaces/CustomBaseInterfacesTest.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CustomBaseInterfaces/CustomBaseInterfacesTest.cs @@ -3,16 +3,16 @@ using TypeGen.Core.Generator; using TypeGen.Core.SpecGeneration; using TypeGen.Core.TypeAnnotations; -using TypeGen.IntegrationTest.CustomBaseInterfaces.Entities; -using TypeGen.IntegrationTest.TestingUtils; +using TypeGen.FileContentTest.CustomBaseInterfaces.Entities; +using TypeGen.FileContentTest.TestingUtils; using Xunit; -namespace TypeGen.IntegrationTest.CustomBaseInterfaces; +namespace TypeGen.FileContentTest.CustomBaseInterfaces; public class CustomBaseInterfacesTest : GenerationTestBase { [Theory] - [InlineData(typeof(Foo), "TypeGen.IntegrationTest.CustomBaseInterfaces.Expected.foo.ts")] + [InlineData(typeof(Foo), "TypeGen.FileContentTest.CustomBaseInterfaces.Expected.foo.ts")] public async Task TestCustomBaseInterfacesGenerationSpec(Type type, string expectedLocation) { var generationSpec = new CustomBaseInterfacesGenerationSpec(); @@ -21,7 +21,7 @@ public async Task TestCustomBaseInterfacesGenerationSpec(Type type, string expec } [Theory] - [InlineData(typeof(Foo), "TypeGen.IntegrationTest.CustomBaseInterfaces.Expected.foo.ts")] + [InlineData(typeof(Foo), "TypeGen.FileContentTest.CustomBaseInterfaces.Expected.foo.ts")] public async Task TestCustomBaseInterfacesFromAssembly(Type type, string expectedLocation) { await TestFromAssembly(type, expectedLocation); diff --git a/src/TypeGen/TypeGen.IntegrationTest/CustomBaseInterfaces/Entities/Foo.cs b/src/TypeGen/TypeGen.FileContentTest/CustomBaseInterfaces/Entities/Foo.cs similarity index 78% rename from src/TypeGen/TypeGen.IntegrationTest/CustomBaseInterfaces/Entities/Foo.cs rename to src/TypeGen/TypeGen.FileContentTest/CustomBaseInterfaces/Entities/Foo.cs index 609a7dda..d8a9e0d6 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CustomBaseInterfaces/Entities/Foo.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CustomBaseInterfaces/Entities/Foo.cs @@ -1,6 +1,6 @@ using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.CustomBaseInterfaces.Entities; +namespace TypeGen.FileContentTest.CustomBaseInterfaces.Entities; [ExportTsClass] [TsCustomBase(null, null, null, false, diff --git a/src/TypeGen/TypeGen.FileContentTest/CustomBaseInterfaces/Entities/ITest.cs b/src/TypeGen/TypeGen.FileContentTest/CustomBaseInterfaces/Entities/ITest.cs new file mode 100644 index 00000000..82e9fded --- /dev/null +++ b/src/TypeGen/TypeGen.FileContentTest/CustomBaseInterfaces/Entities/ITest.cs @@ -0,0 +1,6 @@ +namespace TypeGen.FileContentTest.CustomBaseInterfaces.Entities; + +public interface ITest +{ + +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.IntegrationTest/CustomBaseInterfaces/Expected/foo.ts b/src/TypeGen/TypeGen.FileContentTest/CustomBaseInterfaces/Expected/foo.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/CustomBaseInterfaces/Expected/foo.ts rename to src/TypeGen/TypeGen.FileContentTest/CustomBaseInterfaces/Expected/foo.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/CustomMappingsClassGeneration/CustomMappingsClassGeneration.cs b/src/TypeGen/TypeGen.FileContentTest/CustomMappingsClassGeneration/CustomMappingsClassGeneration.cs similarity index 86% rename from src/TypeGen/TypeGen.IntegrationTest/CustomMappingsClassGeneration/CustomMappingsClassGeneration.cs rename to src/TypeGen/TypeGen.FileContentTest/CustomMappingsClassGeneration/CustomMappingsClassGeneration.cs index 7bb211c8..667cffd8 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/CustomMappingsClassGeneration/CustomMappingsClassGeneration.cs +++ b/src/TypeGen/TypeGen.FileContentTest/CustomMappingsClassGeneration/CustomMappingsClassGeneration.cs @@ -3,12 +3,11 @@ using System.Threading.Tasks; using TypeGen.Core.Generator; using TypeGen.Core.SpecGeneration; -using TypeGen.IntegrationTest.CommonCases.Entities.CustomMappingsClassGenerationIssue; -using TypeGen.IntegrationTest.Extensions; -using TypeGen.IntegrationTest.TestingUtils; +using TypeGen.FileContentTest.CommonCases.Entities.CustomMappingsClassGenerationIssue; +using TypeGen.FileContentTest.TestingUtils; using Xunit; -namespace TypeGen.IntegrationTest.CustomMappingsClassGeneration +namespace TypeGen.FileContentTest.CustomMappingsClassGeneration { public class CustomMappingsClassGeneration : GenerationTestBase { @@ -16,7 +15,7 @@ public class CustomMappingsClassGeneration : GenerationTestBase public async Task GeneratesCorrectly() { var type = typeof(ClassWithUri); - var expectedLocation = @"TypeGen.IntegrationTest.CustomMappingsClassGeneration.Expected.class-with-uri.ts"; + var expectedLocation = @"TypeGen.FileContentTest.CustomMappingsClassGeneration.Expected.class-with-uri.ts"; var spec = new TestGenerationSpec(); var generatorOptions = new GeneratorOptions { diff --git a/src/TypeGen/TypeGen.IntegrationTest/CustomMappingsClassGeneration/Expected/class-with-uri.ts b/src/TypeGen/TypeGen.FileContentTest/CustomMappingsClassGeneration/Expected/class-with-uri.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/CustomMappingsClassGeneration/Expected/class-with-uri.ts rename to src/TypeGen/TypeGen.FileContentTest/CustomMappingsClassGeneration/Expected/class-with-uri.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/DefaultExport/DefaultExportTest.cs b/src/TypeGen/TypeGen.FileContentTest/DefaultExport/DefaultExportTest.cs similarity index 57% rename from src/TypeGen/TypeGen.IntegrationTest/DefaultExport/DefaultExportTest.cs rename to src/TypeGen/TypeGen.FileContentTest/DefaultExport/DefaultExportTest.cs index 283a4217..8f85979c 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/DefaultExport/DefaultExportTest.cs +++ b/src/TypeGen/TypeGen.FileContentTest/DefaultExport/DefaultExportTest.cs @@ -1,12 +1,10 @@ using System; using System.Threading.Tasks; -using TypeGen.IntegrationTest.CircularGenericConstraint.TestClasses; -using TypeGen.IntegrationTest.CommonCases; -using TypeGen.IntegrationTest.DefaultExport.Entities; -using TypeGen.IntegrationTest.TestingUtils; +using TypeGen.FileContentTest.DefaultExport.Entities; +using TypeGen.FileContentTest.TestingUtils; using Xunit; -namespace TypeGen.IntegrationTest.DefaultExport +namespace TypeGen.FileContentTest.DefaultExport { public class DefaultExportTest : GenerationTestBase { @@ -17,19 +15,19 @@ public class DefaultExportTest : GenerationTestBase /// /// [Theory] - [InlineData(typeof(ClassWithDefaultExport), "TypeGen.IntegrationTest.DefaultExport.Expected.class-with-default-export.ts")] - [InlineData(typeof(GenericClassWithDefaultExport<,>), "TypeGen.IntegrationTest.DefaultExport.Expected.generic-class-with-default-export.ts")] - [InlineData(typeof(ClassWithImports), "TypeGen.IntegrationTest.DefaultExport.Expected.class-with-imports.ts")] - [InlineData(typeof(ClassWithoutDefaultExport), "TypeGen.IntegrationTest.DefaultExport.Expected.class-without-default-export.ts")] - [InlineData(typeof(InterfaceWithDefaultExport), "TypeGen.IntegrationTest.DefaultExport.Expected.interface-with-default-export.ts")] + [InlineData(typeof(ClassWithDefaultExport), "TypeGen.FileContentTest.DefaultExport.Expected.class-with-default-export.ts")] + [InlineData(typeof(GenericClassWithDefaultExport<,>), "TypeGen.FileContentTest.DefaultExport.Expected.generic-class-with-default-export.ts")] + [InlineData(typeof(ClassWithImports), "TypeGen.FileContentTest.DefaultExport.Expected.class-with-imports.ts")] + [InlineData(typeof(ClassWithoutDefaultExport), "TypeGen.FileContentTest.DefaultExport.Expected.class-without-default-export.ts")] + [InlineData(typeof(InterfaceWithDefaultExport), "TypeGen.FileContentTest.DefaultExport.Expected.interface-with-default-export.ts")] // structs - [InlineData(typeof(DefaultExport.Entities.Structs.ClassWithDefaultExport), "TypeGen.IntegrationTest.DefaultExport.Expected.class-with-default-export.ts")] - [InlineData(typeof(DefaultExport.Entities.Structs.GenericClassWithDefaultExport<,>), "TypeGen.IntegrationTest.DefaultExport.Expected.generic-class-with-default-export.ts")] - [InlineData(typeof(DefaultExport.Entities.Structs.ClassWithImports), "TypeGen.IntegrationTest.DefaultExport.Expected.class-with-imports.ts")] - [InlineData(typeof(DefaultExport.Entities.Structs.ClassWithoutDefaultExport), "TypeGen.IntegrationTest.DefaultExport.Expected.class-without-default-export.ts")] - [InlineData(typeof(DefaultExport.Entities.Structs.InterfaceWithDefaultExport), "TypeGen.IntegrationTest.DefaultExport.Expected.interface-with-default-export.ts")] + [InlineData(typeof(DefaultExport.Entities.Structs.ClassWithDefaultExport), "TypeGen.FileContentTest.DefaultExport.Expected.class-with-default-export.ts")] + [InlineData(typeof(DefaultExport.Entities.Structs.GenericClassWithDefaultExport<,>), "TypeGen.FileContentTest.DefaultExport.Expected.generic-class-with-default-export.ts")] + [InlineData(typeof(DefaultExport.Entities.Structs.ClassWithImports), "TypeGen.FileContentTest.DefaultExport.Expected.class-with-imports.ts")] + [InlineData(typeof(DefaultExport.Entities.Structs.ClassWithoutDefaultExport), "TypeGen.FileContentTest.DefaultExport.Expected.class-without-default-export.ts")] + [InlineData(typeof(DefaultExport.Entities.Structs.InterfaceWithDefaultExport), "TypeGen.FileContentTest.DefaultExport.Expected.interface-with-default-export.ts")] public async Task GeneratesCorrectly(Type type, string expectedLocation) { await TestFromAssembly(type, expectedLocation); diff --git a/src/TypeGen/TypeGen.IntegrationTest/DefaultExport/Entities/ClassWithDefaultExport.cs b/src/TypeGen/TypeGen.FileContentTest/DefaultExport/Entities/ClassWithDefaultExport.cs similarity index 75% rename from src/TypeGen/TypeGen.IntegrationTest/DefaultExport/Entities/ClassWithDefaultExport.cs rename to src/TypeGen/TypeGen.FileContentTest/DefaultExport/Entities/ClassWithDefaultExport.cs index e2658bb2..8782573a 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/DefaultExport/Entities/ClassWithDefaultExport.cs +++ b/src/TypeGen/TypeGen.FileContentTest/DefaultExport/Entities/ClassWithDefaultExport.cs @@ -1,6 +1,6 @@ using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.DefaultExport.Entities +namespace TypeGen.FileContentTest.DefaultExport.Entities { [ExportTsClass(OutputDir = "default-export/")] [TsDefaultExport] diff --git a/src/TypeGen/TypeGen.IntegrationTest/DefaultExport/Entities/ClassWithImports.cs b/src/TypeGen/TypeGen.FileContentTest/DefaultExport/Entities/ClassWithImports.cs similarity index 92% rename from src/TypeGen/TypeGen.IntegrationTest/DefaultExport/Entities/ClassWithImports.cs rename to src/TypeGen/TypeGen.FileContentTest/DefaultExport/Entities/ClassWithImports.cs index eb6538ca..0da9a326 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/DefaultExport/Entities/ClassWithImports.cs +++ b/src/TypeGen/TypeGen.FileContentTest/DefaultExport/Entities/ClassWithImports.cs @@ -1,6 +1,6 @@ using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.DefaultExport.Entities +namespace TypeGen.FileContentTest.DefaultExport.Entities { [ExportTsClass(OutputDir = "default-export/")] [TsCustomBase("BaseWithDefaultExport", "./my-path/example/base", isDefaultExport: true)] diff --git a/src/TypeGen/TypeGen.IntegrationTest/DefaultExport/Entities/ClassWithoutDefaultExport.cs b/src/TypeGen/TypeGen.FileContentTest/DefaultExport/Entities/ClassWithoutDefaultExport.cs similarity index 73% rename from src/TypeGen/TypeGen.IntegrationTest/DefaultExport/Entities/ClassWithoutDefaultExport.cs rename to src/TypeGen/TypeGen.FileContentTest/DefaultExport/Entities/ClassWithoutDefaultExport.cs index 763fea07..237a93ed 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/DefaultExport/Entities/ClassWithoutDefaultExport.cs +++ b/src/TypeGen/TypeGen.FileContentTest/DefaultExport/Entities/ClassWithoutDefaultExport.cs @@ -1,6 +1,6 @@ using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.DefaultExport.Entities +namespace TypeGen.FileContentTest.DefaultExport.Entities { [ExportTsClass(OutputDir = "default-export/")] public class ClassWithoutDefaultExport diff --git a/src/TypeGen/TypeGen.IntegrationTest/DefaultExport/Entities/GenericClassWithDefaultExport.cs b/src/TypeGen/TypeGen.FileContentTest/DefaultExport/Entities/GenericClassWithDefaultExport.cs similarity index 76% rename from src/TypeGen/TypeGen.IntegrationTest/DefaultExport/Entities/GenericClassWithDefaultExport.cs rename to src/TypeGen/TypeGen.FileContentTest/DefaultExport/Entities/GenericClassWithDefaultExport.cs index 0307e99a..dab876e5 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/DefaultExport/Entities/GenericClassWithDefaultExport.cs +++ b/src/TypeGen/TypeGen.FileContentTest/DefaultExport/Entities/GenericClassWithDefaultExport.cs @@ -1,6 +1,6 @@ using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.DefaultExport.Entities +namespace TypeGen.FileContentTest.DefaultExport.Entities { [ExportTsClass(OutputDir = "default-export")] [TsDefaultExport] diff --git a/src/TypeGen/TypeGen.IntegrationTest/DefaultExport/Entities/InterfaceWithDefaultExport.cs b/src/TypeGen/TypeGen.FileContentTest/DefaultExport/Entities/InterfaceWithDefaultExport.cs similarity index 76% rename from src/TypeGen/TypeGen.IntegrationTest/DefaultExport/Entities/InterfaceWithDefaultExport.cs rename to src/TypeGen/TypeGen.FileContentTest/DefaultExport/Entities/InterfaceWithDefaultExport.cs index f2900b65..9fc84f5c 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/DefaultExport/Entities/InterfaceWithDefaultExport.cs +++ b/src/TypeGen/TypeGen.FileContentTest/DefaultExport/Entities/InterfaceWithDefaultExport.cs @@ -1,6 +1,6 @@ using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.DefaultExport.Entities +namespace TypeGen.FileContentTest.DefaultExport.Entities { [ExportTsInterface(OutputDir = "default-export/")] [TsDefaultExport] diff --git a/src/TypeGen/TypeGen.IntegrationTest/DefaultExport/Entities/Structs/ClassWithDefaultExport.cs b/src/TypeGen/TypeGen.FileContentTest/DefaultExport/Entities/Structs/ClassWithDefaultExport.cs similarity index 73% rename from src/TypeGen/TypeGen.IntegrationTest/DefaultExport/Entities/Structs/ClassWithDefaultExport.cs rename to src/TypeGen/TypeGen.FileContentTest/DefaultExport/Entities/Structs/ClassWithDefaultExport.cs index a8adda97..1a64d527 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/DefaultExport/Entities/Structs/ClassWithDefaultExport.cs +++ b/src/TypeGen/TypeGen.FileContentTest/DefaultExport/Entities/Structs/ClassWithDefaultExport.cs @@ -1,6 +1,6 @@ using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.DefaultExport.Entities.Structs +namespace TypeGen.FileContentTest.DefaultExport.Entities.Structs { [ExportTsClass(OutputDir = "default-export/")] [TsDefaultExport] diff --git a/src/TypeGen/TypeGen.IntegrationTest/DefaultExport/Entities/Structs/ClassWithImports.cs b/src/TypeGen/TypeGen.FileContentTest/DefaultExport/Entities/Structs/ClassWithImports.cs similarity index 91% rename from src/TypeGen/TypeGen.IntegrationTest/DefaultExport/Entities/Structs/ClassWithImports.cs rename to src/TypeGen/TypeGen.FileContentTest/DefaultExport/Entities/Structs/ClassWithImports.cs index 4271c316..a00d9a81 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/DefaultExport/Entities/Structs/ClassWithImports.cs +++ b/src/TypeGen/TypeGen.FileContentTest/DefaultExport/Entities/Structs/ClassWithImports.cs @@ -1,6 +1,6 @@ using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.DefaultExport.Entities.Structs +namespace TypeGen.FileContentTest.DefaultExport.Entities.Structs { [ExportTsClass(OutputDir = "default-export/")] [TsCustomBase("BaseWithDefaultExport", "./my-path/example/base", isDefaultExport: true)] diff --git a/src/TypeGen/TypeGen.IntegrationTest/DefaultExport/Entities/Structs/ClassWithoutDefaultExport.cs b/src/TypeGen/TypeGen.FileContentTest/DefaultExport/Entities/Structs/ClassWithoutDefaultExport.cs similarity index 71% rename from src/TypeGen/TypeGen.IntegrationTest/DefaultExport/Entities/Structs/ClassWithoutDefaultExport.cs rename to src/TypeGen/TypeGen.FileContentTest/DefaultExport/Entities/Structs/ClassWithoutDefaultExport.cs index d90fd135..520c5b81 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/DefaultExport/Entities/Structs/ClassWithoutDefaultExport.cs +++ b/src/TypeGen/TypeGen.FileContentTest/DefaultExport/Entities/Structs/ClassWithoutDefaultExport.cs @@ -1,6 +1,6 @@ using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.DefaultExport.Entities.Structs +namespace TypeGen.FileContentTest.DefaultExport.Entities.Structs { [ExportTsClass(OutputDir = "default-export/")] public struct ClassWithoutDefaultExport diff --git a/src/TypeGen/TypeGen.IntegrationTest/DefaultExport/Entities/Structs/GenericClassWithDefaultExport.cs b/src/TypeGen/TypeGen.FileContentTest/DefaultExport/Entities/Structs/GenericClassWithDefaultExport.cs similarity index 74% rename from src/TypeGen/TypeGen.IntegrationTest/DefaultExport/Entities/Structs/GenericClassWithDefaultExport.cs rename to src/TypeGen/TypeGen.FileContentTest/DefaultExport/Entities/Structs/GenericClassWithDefaultExport.cs index e7cc43bc..0cc69ef6 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/DefaultExport/Entities/Structs/GenericClassWithDefaultExport.cs +++ b/src/TypeGen/TypeGen.FileContentTest/DefaultExport/Entities/Structs/GenericClassWithDefaultExport.cs @@ -1,6 +1,6 @@ using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.DefaultExport.Entities.Structs +namespace TypeGen.FileContentTest.DefaultExport.Entities.Structs { [ExportTsClass(OutputDir = "default-export")] [TsDefaultExport] diff --git a/src/TypeGen/TypeGen.IntegrationTest/DefaultExport/Entities/Structs/InterfaceWithDefaultExport.cs b/src/TypeGen/TypeGen.FileContentTest/DefaultExport/Entities/Structs/InterfaceWithDefaultExport.cs similarity index 74% rename from src/TypeGen/TypeGen.IntegrationTest/DefaultExport/Entities/Structs/InterfaceWithDefaultExport.cs rename to src/TypeGen/TypeGen.FileContentTest/DefaultExport/Entities/Structs/InterfaceWithDefaultExport.cs index 0c83eed3..17dd6775 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/DefaultExport/Entities/Structs/InterfaceWithDefaultExport.cs +++ b/src/TypeGen/TypeGen.FileContentTest/DefaultExport/Entities/Structs/InterfaceWithDefaultExport.cs @@ -1,6 +1,6 @@ using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.DefaultExport.Entities.Structs +namespace TypeGen.FileContentTest.DefaultExport.Entities.Structs { [ExportTsInterface(OutputDir = "default-export/")] [TsDefaultExport] diff --git a/src/TypeGen/TypeGen.IntegrationTest/DefaultExport/Expected/class-with-default-export.ts b/src/TypeGen/TypeGen.FileContentTest/DefaultExport/Expected/class-with-default-export.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/DefaultExport/Expected/class-with-default-export.ts rename to src/TypeGen/TypeGen.FileContentTest/DefaultExport/Expected/class-with-default-export.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/DefaultExport/Expected/class-with-imports.ts b/src/TypeGen/TypeGen.FileContentTest/DefaultExport/Expected/class-with-imports.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/DefaultExport/Expected/class-with-imports.ts rename to src/TypeGen/TypeGen.FileContentTest/DefaultExport/Expected/class-with-imports.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/DefaultExport/Expected/class-without-default-export.ts b/src/TypeGen/TypeGen.FileContentTest/DefaultExport/Expected/class-without-default-export.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/DefaultExport/Expected/class-without-default-export.ts rename to src/TypeGen/TypeGen.FileContentTest/DefaultExport/Expected/class-without-default-export.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/DefaultExport/Expected/generic-class-with-default-export.ts b/src/TypeGen/TypeGen.FileContentTest/DefaultExport/Expected/generic-class-with-default-export.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/DefaultExport/Expected/generic-class-with-default-export.ts rename to src/TypeGen/TypeGen.FileContentTest/DefaultExport/Expected/generic-class-with-default-export.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/DefaultExport/Expected/interface-with-default-export.ts b/src/TypeGen/TypeGen.FileContentTest/DefaultExport/Expected/interface-with-default-export.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/DefaultExport/Expected/interface-with-default-export.ts rename to src/TypeGen/TypeGen.FileContentTest/DefaultExport/Expected/interface-with-default-export.ts diff --git a/src/TypeGen/TypeGen.FileContentTest/ExportTypesAsInterfacesByDefault/Entities/Child.cs b/src/TypeGen/TypeGen.FileContentTest/ExportTypesAsInterfacesByDefault/Entities/Child.cs new file mode 100644 index 00000000..5f3f50ea --- /dev/null +++ b/src/TypeGen/TypeGen.FileContentTest/ExportTypesAsInterfacesByDefault/Entities/Child.cs @@ -0,0 +1,6 @@ +namespace TypeGen.FileContentTest.ExportTypesAsInterfacesByDefault.Entities; + +public class Child +{ + +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.IntegrationTest/ExportTypesAsInterfacesByDefault/Entities/Parent.cs b/src/TypeGen/TypeGen.FileContentTest/ExportTypesAsInterfacesByDefault/Entities/Parent.cs similarity index 52% rename from src/TypeGen/TypeGen.IntegrationTest/ExportTypesAsInterfacesByDefault/Entities/Parent.cs rename to src/TypeGen/TypeGen.FileContentTest/ExportTypesAsInterfacesByDefault/Entities/Parent.cs index d3b6e8cd..9d07a19d 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/ExportTypesAsInterfacesByDefault/Entities/Parent.cs +++ b/src/TypeGen/TypeGen.FileContentTest/ExportTypesAsInterfacesByDefault/Entities/Parent.cs @@ -1,4 +1,4 @@ -namespace TypeGen.IntegrationTest.ExportTypesAsInterfacesByDefault.Entities; +namespace TypeGen.FileContentTest.ExportTypesAsInterfacesByDefault.Entities; public class Parent { diff --git a/src/TypeGen/TypeGen.IntegrationTest/ExportTypesAsInterfacesByDefault/Expected/child-as-class.ts b/src/TypeGen/TypeGen.FileContentTest/ExportTypesAsInterfacesByDefault/Expected/child-as-class.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/ExportTypesAsInterfacesByDefault/Expected/child-as-class.ts rename to src/TypeGen/TypeGen.FileContentTest/ExportTypesAsInterfacesByDefault/Expected/child-as-class.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/ExportTypesAsInterfacesByDefault/Expected/child-as-interface.ts b/src/TypeGen/TypeGen.FileContentTest/ExportTypesAsInterfacesByDefault/Expected/child-as-interface.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/ExportTypesAsInterfacesByDefault/Expected/child-as-interface.ts rename to src/TypeGen/TypeGen.FileContentTest/ExportTypesAsInterfacesByDefault/Expected/child-as-interface.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/ExportTypesAsInterfacesByDefault/ExportTypesAsInterfacesByDefaultTest.cs b/src/TypeGen/TypeGen.FileContentTest/ExportTypesAsInterfacesByDefault/ExportTypesAsInterfacesByDefaultTest.cs similarity index 81% rename from src/TypeGen/TypeGen.IntegrationTest/ExportTypesAsInterfacesByDefault/ExportTypesAsInterfacesByDefaultTest.cs rename to src/TypeGen/TypeGen.FileContentTest/ExportTypesAsInterfacesByDefault/ExportTypesAsInterfacesByDefaultTest.cs index d007f8f4..33d3c707 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/ExportTypesAsInterfacesByDefault/ExportTypesAsInterfacesByDefaultTest.cs +++ b/src/TypeGen/TypeGen.FileContentTest/ExportTypesAsInterfacesByDefault/ExportTypesAsInterfacesByDefaultTest.cs @@ -1,11 +1,11 @@ using System.Threading.Tasks; using TypeGen.Core.Generator; using TypeGen.Core.SpecGeneration; -using TypeGen.IntegrationTest.ExportTypesAsInterfacesByDefault.Entities; -using TypeGen.IntegrationTest.TestingUtils; +using TypeGen.FileContentTest.ExportTypesAsInterfacesByDefault.Entities; +using TypeGen.FileContentTest.TestingUtils; using Xunit; -namespace TypeGen.IntegrationTest.ExportTypesAsInterfacesByDefault; +namespace TypeGen.FileContentTest.ExportTypesAsInterfacesByDefault; public class ExportTypesAsInterfacesByDefaultTest : GenerationTestBase { @@ -13,7 +13,7 @@ public class ExportTypesAsInterfacesByDefaultTest : GenerationTestBase public async Task if_option_not_set_should_generate_class() { var type = typeof(Child); - const string expectedLocation = "TypeGen.IntegrationTest.ExportTypesAsInterfacesByDefault.Expected.child-as-class.ts"; + const string expectedLocation = "TypeGen.FileContentTest.ExportTypesAsInterfacesByDefault.Expected.child-as-class.ts"; var generatorOptions = new GeneratorOptions(); var generationSpec = new ExportTypesAsInterfacesByDefaultGenerationSpec(); await TestGenerationSpec(type, expectedLocation, generationSpec, generatorOptions); @@ -23,7 +23,7 @@ public async Task if_option_not_set_should_generate_class() public async Task if_option_set_should_generate_interface() { var type = typeof(Child); - const string expectedLocation = "TypeGen.IntegrationTest.ExportTypesAsInterfacesByDefault.Expected.child-as-interface.ts"; + const string expectedLocation = "TypeGen.FileContentTest.ExportTypesAsInterfacesByDefault.Expected.child-as-interface.ts"; var generatorOptions = new GeneratorOptions { ExportTypesAsInterfacesByDefault = true }; var generationSpec = new ExportTypesAsInterfacesByDefaultGenerationSpec(); await TestGenerationSpec(type, expectedLocation, generationSpec, generatorOptions); diff --git a/src/TypeGen/TypeGen.FileContentTest/Extensions/StringExtensions.cs b/src/TypeGen/TypeGen.FileContentTest/Extensions/StringExtensions.cs new file mode 100644 index 00000000..32fa03b8 --- /dev/null +++ b/src/TypeGen/TypeGen.FileContentTest/Extensions/StringExtensions.cs @@ -0,0 +1,12 @@ +namespace TypeGen.FileContentTest.Extensions; + +public static class StringExtensions +{ + public static string NormalizeFileContent(this string content) + => content + .Trim('\uFEFF', '\u200B') + .Trim() + .Replace("\n", "") + .Replace("\r", "") + .Replace("\r\n", ""); +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.IntegrationTest/GenerationSpecForStructs/GenerationSpecsForStructsTest.cs b/src/TypeGen/TypeGen.FileContentTest/GenerationSpecForStructs/GenerationSpecsForStructsTest.cs similarity index 68% rename from src/TypeGen/TypeGen.IntegrationTest/GenerationSpecForStructs/GenerationSpecsForStructsTest.cs rename to src/TypeGen/TypeGen.FileContentTest/GenerationSpecForStructs/GenerationSpecsForStructsTest.cs index 7cb46e9b..cd54bbf4 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/GenerationSpecForStructs/GenerationSpecsForStructsTest.cs +++ b/src/TypeGen/TypeGen.FileContentTest/GenerationSpecForStructs/GenerationSpecsForStructsTest.cs @@ -2,21 +2,21 @@ using System.Threading.Tasks; using TypeGen.Core.Generator; using TypeGen.Core.SpecGeneration; -using TypeGen.IntegrationTest.CommonCases.Entities.Structs; -using TypeGen.IntegrationTest.TestingUtils; +using TypeGen.FileContentTest.CommonCases.Entities.Structs; +using TypeGen.FileContentTest.TestingUtils; using Xunit; -namespace TypeGen.IntegrationTest.GenerationSpecForStructs; +namespace TypeGen.FileContentTest.GenerationSpecForStructs; public class GenerationSpecsForStructsTest : GenerationTestBase { [Theory] - [InlineData(typeof(CustomBaseClass), "TypeGen.IntegrationTest.CommonCases.Expected.custom-base-class.ts")] - [InlineData(typeof(CustomBaseCustomImport), "TypeGen.IntegrationTest.CommonCases.Expected.custom-base-custom-import.ts")] - [InlineData(typeof(CustomEmptyBaseClass), "TypeGen.IntegrationTest.CommonCases.Expected.custom-empty-base-class.ts")] - [InlineData(typeof(ExtendedPrimitivesClass), "TypeGen.IntegrationTest.CommonCases.Expected.extended-primitives-class.ts")] - [InlineData(typeof(ExternalDepsClass), "TypeGen.IntegrationTest.CommonCases.Expected.external-deps-class.ts")] - [InlineData(typeof(GenericBaseClass<>), "TypeGen.IntegrationTest.CommonCases.Expected.generic-base-class.ts")] + [InlineData(typeof(CustomBaseClass), "TypeGen.FileContentTest.CommonCases.Expected.custom-base-class.ts")] + [InlineData(typeof(CustomBaseCustomImport), "TypeGen.FileContentTest.CommonCases.Expected.custom-base-custom-import.ts")] + [InlineData(typeof(CustomEmptyBaseClass), "TypeGen.FileContentTest.CommonCases.Expected.custom-empty-base-class.ts")] + [InlineData(typeof(ExtendedPrimitivesClass), "TypeGen.FileContentTest.CommonCases.Expected.extended-primitives-class.ts")] + [InlineData(typeof(ExternalDepsClass), "TypeGen.FileContentTest.CommonCases.Expected.external-deps-class.ts")] + [InlineData(typeof(GenericBaseClass<>), "TypeGen.FileContentTest.CommonCases.Expected.generic-base-class.ts")] public async Task TestGenerationSpecForStructs(Type type, string expectedLocation) { var generationSpec = new StructsGenerationSpec(); diff --git a/src/TypeGen/TypeGen.FileContentTest/IgnoreBaseInterfaces/Entities/ITest.cs b/src/TypeGen/TypeGen.FileContentTest/IgnoreBaseInterfaces/Entities/ITest.cs new file mode 100644 index 00000000..63ae6ca3 --- /dev/null +++ b/src/TypeGen/TypeGen.FileContentTest/IgnoreBaseInterfaces/Entities/ITest.cs @@ -0,0 +1,6 @@ +namespace TypeGen.FileContentTest.IgnoreBaseInterfaces.Entities; + +public interface ITest +{ + +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.IntegrationTest/IgnoreBaseInterfaces/Entities/Test.cs b/src/TypeGen/TypeGen.FileContentTest/IgnoreBaseInterfaces/Entities/Test.cs similarity index 68% rename from src/TypeGen/TypeGen.IntegrationTest/IgnoreBaseInterfaces/Entities/Test.cs rename to src/TypeGen/TypeGen.FileContentTest/IgnoreBaseInterfaces/Entities/Test.cs index 2450dbbd..0112a8cf 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/IgnoreBaseInterfaces/Entities/Test.cs +++ b/src/TypeGen/TypeGen.FileContentTest/IgnoreBaseInterfaces/Entities/Test.cs @@ -1,6 +1,6 @@ using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.IgnoreBaseInterfaces.Entities; +namespace TypeGen.FileContentTest.IgnoreBaseInterfaces.Entities; [ExportTsClass] [TsIgnoreBase] diff --git a/src/TypeGen/TypeGen.IntegrationTest/IgnoreBaseInterfaces/Expected/test.ts b/src/TypeGen/TypeGen.FileContentTest/IgnoreBaseInterfaces/Expected/test.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/IgnoreBaseInterfaces/Expected/test.ts rename to src/TypeGen/TypeGen.FileContentTest/IgnoreBaseInterfaces/Expected/test.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/IgnoreBaseInterfaces/IgnoreBaseInterfacesTest.cs b/src/TypeGen/TypeGen.FileContentTest/IgnoreBaseInterfaces/IgnoreBaseInterfacesTest.cs similarity index 58% rename from src/TypeGen/TypeGen.IntegrationTest/IgnoreBaseInterfaces/IgnoreBaseInterfacesTest.cs rename to src/TypeGen/TypeGen.FileContentTest/IgnoreBaseInterfaces/IgnoreBaseInterfacesTest.cs index 345c324d..998b26e5 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/IgnoreBaseInterfaces/IgnoreBaseInterfacesTest.cs +++ b/src/TypeGen/TypeGen.FileContentTest/IgnoreBaseInterfaces/IgnoreBaseInterfacesTest.cs @@ -1,15 +1,15 @@ using System; using System.Threading.Tasks; -using TypeGen.IntegrationTest.IgnoreBaseInterfaces.Entities; -using TypeGen.IntegrationTest.TestingUtils; +using TypeGen.FileContentTest.IgnoreBaseInterfaces.Entities; +using TypeGen.FileContentTest.TestingUtils; using Xunit; -namespace TypeGen.IntegrationTest.IgnoreBaseInterfaces; +namespace TypeGen.FileContentTest.IgnoreBaseInterfaces; public class IgnoreBaseInterfacesTest : GenerationTestBase { [Theory] - [InlineData(typeof(Test), "TypeGen.IntegrationTest.IgnoreBaseInterfaces.Expected.test.ts")] + [InlineData(typeof(Test), "TypeGen.FileContentTest.IgnoreBaseInterfaces.Expected.test.ts")] public async Task TestIgnoreBaseInterfaces(Type type, string expectedLocation) { await TestFromAssembly(type, expectedLocation); diff --git a/src/TypeGen/TypeGen.FileContentTest/ImportType/Entities/DepClass.cs b/src/TypeGen/TypeGen.FileContentTest/ImportType/Entities/DepClass.cs new file mode 100644 index 00000000..78efd327 --- /dev/null +++ b/src/TypeGen/TypeGen.FileContentTest/ImportType/Entities/DepClass.cs @@ -0,0 +1,6 @@ +namespace TypeGen.FileContentTest.ImportType.Entities; + +public class DepClass +{ + +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.IntegrationTest/ImportType/Entities/TsClass.cs b/src/TypeGen/TypeGen.FileContentTest/ImportType/Entities/TsClass.cs similarity index 53% rename from src/TypeGen/TypeGen.IntegrationTest/ImportType/Entities/TsClass.cs rename to src/TypeGen/TypeGen.FileContentTest/ImportType/Entities/TsClass.cs index 00a0435b..e77fb07f 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/ImportType/Entities/TsClass.cs +++ b/src/TypeGen/TypeGen.FileContentTest/ImportType/Entities/TsClass.cs @@ -1,4 +1,4 @@ -namespace TypeGen.IntegrationTest.ImportType.Entities; +namespace TypeGen.FileContentTest.ImportType.Entities; public class TsClass { diff --git a/src/TypeGen/TypeGen.IntegrationTest/ImportType/Expected/ts-class-default-export.ts b/src/TypeGen/TypeGen.FileContentTest/ImportType/Expected/ts-class-default-export.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/ImportType/Expected/ts-class-default-export.ts rename to src/TypeGen/TypeGen.FileContentTest/ImportType/Expected/ts-class-default-export.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/ImportType/Expected/ts-class.ts b/src/TypeGen/TypeGen.FileContentTest/ImportType/Expected/ts-class.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/ImportType/Expected/ts-class.ts rename to src/TypeGen/TypeGen.FileContentTest/ImportType/Expected/ts-class.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/ImportType/ImportTypeTest.cs b/src/TypeGen/TypeGen.FileContentTest/ImportType/ImportTypeTest.cs similarity index 71% rename from src/TypeGen/TypeGen.IntegrationTest/ImportType/ImportTypeTest.cs rename to src/TypeGen/TypeGen.FileContentTest/ImportType/ImportTypeTest.cs index 5e934f08..e21bab14 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/ImportType/ImportTypeTest.cs +++ b/src/TypeGen/TypeGen.FileContentTest/ImportType/ImportTypeTest.cs @@ -2,18 +2,17 @@ using System.Threading.Tasks; using TypeGen.Core.Generator; using TypeGen.Core.SpecGeneration; -using TypeGen.IntegrationTest.IgnoreBaseInterfaces.Entities; -using TypeGen.IntegrationTest.ImportType.Entities; -using TypeGen.IntegrationTest.TestingUtils; +using TypeGen.FileContentTest.ImportType.Entities; +using TypeGen.FileContentTest.TestingUtils; using Xunit; -namespace TypeGen.IntegrationTest.ImportType; +namespace TypeGen.FileContentTest.ImportType; public class ImportTypeTest : GenerationTestBase { [Theory] - [InlineData(typeof(TsClass), "TypeGen.IntegrationTest.ImportType.Expected.ts-class.ts", false)] - [InlineData(typeof(TsClass), "TypeGen.IntegrationTest.ImportType.Expected.ts-class-default-export.ts", true)] + [InlineData(typeof(TsClass), "TypeGen.FileContentTest.ImportType.Expected.ts-class.ts", false)] + [InlineData(typeof(TsClass), "TypeGen.FileContentTest.ImportType.Expected.ts-class-default-export.ts", true)] public async Task TestImportType(Type type, string expectedLocation, bool useDefaultExport) { var generationSpec = new ImportTypeGenerationSpec(); diff --git a/src/TypeGen/TypeGen.IntegrationTest/NullableTranslation/Entities/NullableClass.cs b/src/TypeGen/TypeGen.FileContentTest/NullableTranslation/Entities/NullableClass.cs similarity index 92% rename from src/TypeGen/TypeGen.IntegrationTest/NullableTranslation/Entities/NullableClass.cs rename to src/TypeGen/TypeGen.FileContentTest/NullableTranslation/Entities/NullableClass.cs index c449332d..d48c1c2e 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/NullableTranslation/Entities/NullableClass.cs +++ b/src/TypeGen/TypeGen.FileContentTest/NullableTranslation/Entities/NullableClass.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using TypeGen.Core.TypeAnnotations; -namespace TypeGen.IntegrationTest.NullableTranslation.Entities +namespace TypeGen.FileContentTest.NullableTranslation.Entities { [ExportTsClass] public class NullableClass diff --git a/src/TypeGen/TypeGen.IntegrationTest/NullableTranslation/Expected/nullable-class.ts b/src/TypeGen/TypeGen.FileContentTest/NullableTranslation/Expected/nullable-class.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/NullableTranslation/Expected/nullable-class.ts rename to src/TypeGen/TypeGen.FileContentTest/NullableTranslation/Expected/nullable-class.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/NullableTranslation/NullableTranslationTest.cs b/src/TypeGen/TypeGen.FileContentTest/NullableTranslation/NullableTranslationTest.cs similarity index 79% rename from src/TypeGen/TypeGen.IntegrationTest/NullableTranslation/NullableTranslationTest.cs rename to src/TypeGen/TypeGen.FileContentTest/NullableTranslation/NullableTranslationTest.cs index 7c18f3c9..9bb5850b 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/NullableTranslation/NullableTranslationTest.cs +++ b/src/TypeGen/TypeGen.FileContentTest/NullableTranslation/NullableTranslationTest.cs @@ -3,16 +3,16 @@ using TypeGen.Core; using TypeGen.Core.Generator; using TypeGen.Core.SpecGeneration; -using TypeGen.IntegrationTest.NullableTranslation.Entities; -using TypeGen.IntegrationTest.TestingUtils; +using TypeGen.FileContentTest.NullableTranslation.Entities; +using TypeGen.FileContentTest.TestingUtils; using Xunit; -namespace TypeGen.IntegrationTest.NullableTranslation; +namespace TypeGen.FileContentTest.NullableTranslation; public class NullableTranslationTest : GenerationTestBase { [Theory] - [InlineData(typeof(NullableClass), "TypeGen.IntegrationTest.NullableTranslation.Expected.nullable-class.ts")] + [InlineData(typeof(NullableClass), "TypeGen.FileContentTest.NullableTranslation.Expected.nullable-class.ts")] public async Task TestNullableTranslationGenerationSpec(Type type, string expectedLocation) { var generationSpec = new NullableTranslationGenerationSpec(); diff --git a/src/TypeGen/TypeGen.FileContentTest/StructImplementsInterfaces/Entities/ImplementsInterfaces.cs b/src/TypeGen/TypeGen.FileContentTest/StructImplementsInterfaces/Entities/ImplementsInterfaces.cs new file mode 100644 index 00000000..0287470e --- /dev/null +++ b/src/TypeGen/TypeGen.FileContentTest/StructImplementsInterfaces/Entities/ImplementsInterfaces.cs @@ -0,0 +1,10 @@ +using TypeGen.Core.TypeAnnotations; +using TypeGen.FileContentTest.CommonCases.Entities.Structs; + +namespace TypeGen.FileContentTest.StructImplementsInterfaces.Entities; + +[ExportTsClass] +public struct ImplementsInterfaces : IFoo, IBar +{ + +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.IntegrationTest/StructImplementsInterfaces/Expected/implements-interfaces.ts b/src/TypeGen/TypeGen.FileContentTest/StructImplementsInterfaces/Expected/implements-interfaces.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/StructImplementsInterfaces/Expected/implements-interfaces.ts rename to src/TypeGen/TypeGen.FileContentTest/StructImplementsInterfaces/Expected/implements-interfaces.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/StructImplementsInterfaces/StructImplementsInterfacesTest.cs b/src/TypeGen/TypeGen.FileContentTest/StructImplementsInterfaces/StructImplementsInterfacesTest.cs similarity index 61% rename from src/TypeGen/TypeGen.IntegrationTest/StructImplementsInterfaces/StructImplementsInterfacesTest.cs rename to src/TypeGen/TypeGen.FileContentTest/StructImplementsInterfaces/StructImplementsInterfacesTest.cs index 7848f5e9..b63da5d7 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/StructImplementsInterfaces/StructImplementsInterfacesTest.cs +++ b/src/TypeGen/TypeGen.FileContentTest/StructImplementsInterfaces/StructImplementsInterfacesTest.cs @@ -1,21 +1,17 @@ using System; using System.Threading.Tasks; -using TypeGen.Core; using TypeGen.Core.Generator; using TypeGen.Core.SpecGeneration; -using TypeGen.Core.TypeAnnotations; -using TypeGen.IntegrationTest.CommonCases.Entities.Structs; -using TypeGen.IntegrationTest.NullableTranslation.Entities; -using TypeGen.IntegrationTest.StructImplementsInterfaces.Entities; -using TypeGen.IntegrationTest.TestingUtils; +using TypeGen.FileContentTest.StructImplementsInterfaces.Entities; +using TypeGen.FileContentTest.TestingUtils; using Xunit; -namespace TypeGen.IntegrationTest.StructImplementsInterfaces; +namespace TypeGen.FileContentTest.StructImplementsInterfaces; public class StructImplementsInterfacesTest : GenerationTestBase { [Theory] - [InlineData(typeof(ImplementsInterfaces), "TypeGen.IntegrationTest.StructImplementsInterfaces.Expected.implements-interfaces.ts")] + [InlineData(typeof(ImplementsInterfaces), "TypeGen.FileContentTest.StructImplementsInterfaces.Expected.implements-interfaces.ts")] public async Task TestStructImplementsInterfacesFromGenerationSpec(Type type, string expectedLocation) { var generationSpec = new StructImplementsInterfacesGenerationSpec(); @@ -24,7 +20,7 @@ public async Task TestStructImplementsInterfacesFromGenerationSpec(Type type, st } [Theory] - [InlineData(typeof(ImplementsInterfaces), "TypeGen.IntegrationTest.StructImplementsInterfaces.Expected.implements-interfaces.ts")] + [InlineData(typeof(ImplementsInterfaces), "TypeGen.FileContentTest.StructImplementsInterfaces.Expected.implements-interfaces.ts")] public async Task TestStructImplementsInterfacesFromAssembly(Type type, string expectedLocation) { await TestFromAssembly(type, expectedLocation); diff --git a/src/TypeGen/TypeGen.FileContentTest/TestingUtils/EmbededResourceReader.cs b/src/TypeGen/TypeGen.FileContentTest/TestingUtils/EmbededResourceReader.cs new file mode 100644 index 00000000..11b62c00 --- /dev/null +++ b/src/TypeGen/TypeGen.FileContentTest/TestingUtils/EmbededResourceReader.cs @@ -0,0 +1,23 @@ +using System; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using TypeGen.Core; + +namespace TypeGen.FileContentTest.TestingUtils +{ + public static class EmbededResourceReader + { + public static async Task GetEmbeddedResourceAsync(string name) + { + await using var stream = typeof(EmbededResourceReader).GetTypeInfo().Assembly.GetManifestResourceStream(name); + + if (stream == null) + throw new CoreException($"Could not find embedded resource '{name}'"); + + var contentBytes = new byte[stream.Length]; + await stream.ReadAsync(contentBytes.AsMemory(0, (int)stream.Length)); + return Encoding.UTF8.GetString(contentBytes); + } + } +} diff --git a/src/TypeGen/TypeGen.IntegrationTest/TestingUtils/GeneratedOutput.cs b/src/TypeGen/TypeGen.FileContentTest/TestingUtils/GeneratedOutput.cs similarity index 95% rename from src/TypeGen/TypeGen.IntegrationTest/TestingUtils/GeneratedOutput.cs rename to src/TypeGen/TypeGen.FileContentTest/TestingUtils/GeneratedOutput.cs index c98bbebb..3a6443e9 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/TestingUtils/GeneratedOutput.cs +++ b/src/TypeGen/TypeGen.FileContentTest/TestingUtils/GeneratedOutput.cs @@ -1,7 +1,7 @@ using System; using Gen = TypeGen.Core.Generator; -namespace TypeGen.IntegrationTest.TestingUtils +namespace TypeGen.FileContentTest.TestingUtils { public class GeneratedOutput { diff --git a/src/TypeGen/TypeGen.IntegrationTest/TestingUtils/GenerationTestBase.cs b/src/TypeGen/TypeGen.FileContentTest/TestingUtils/GenerationTestBase.cs similarity index 59% rename from src/TypeGen/TypeGen.IntegrationTest/TestingUtils/GenerationTestBase.cs rename to src/TypeGen/TypeGen.FileContentTest/TestingUtils/GenerationTestBase.cs index c7933e43..27dee9eb 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/TestingUtils/GenerationTestBase.cs +++ b/src/TypeGen/TypeGen.FileContentTest/TestingUtils/GenerationTestBase.cs @@ -1,11 +1,11 @@ using System; using System.Threading.Tasks; +using FluentAssertions; using TypeGen.Core.Generator; using TypeGen.Core.SpecGeneration; -using TypeGen.IntegrationTest.Extensions; -using Xunit; +using TypeGen.FileContentTest.Extensions; -namespace TypeGen.IntegrationTest.TestingUtils; +namespace TypeGen.FileContentTest.TestingUtils; public class GenerationTestBase { @@ -17,23 +17,23 @@ protected async Task TestFromAssembly(Type type, string expectedLocation) var interceptor = GeneratorOutputInterceptor.CreateInterceptor(generator); await generator.GenerateAsync(type.Assembly); - var expected = (await readExpectedTask).Trim(); + var expected = (await readExpectedTask).NormalizeFileContent(); - Assert.True(interceptor.GeneratedOutputs.ContainsKey(type)); - Assert.Equal(expected, interceptor.GeneratedOutputs[type].Content.FormatOutput()); + interceptor.GeneratedOutputs.Should().ContainKey(type); + interceptor.GeneratedOutputs[type].Content.NormalizeFileContent().Should().Be(expected); } protected static async Task TestGenerationSpec(Type type, string expectedLocation, GenerationSpec generationSpec, GeneratorOptions generatorOptions) { var readExpectedTask = EmbededResourceReader.GetEmbeddedResourceAsync(expectedLocation); - var generator = new Core.Generator.Generator(generatorOptions); + var generator = new Generator(generatorOptions); var interceptor = GeneratorOutputInterceptor.CreateInterceptor(generator); await generator.GenerateAsync(new[] { generationSpec }); - var expected = (await readExpectedTask).Trim(); + var expected = (await readExpectedTask).NormalizeFileContent(); - Assert.True(interceptor.GeneratedOutputs.ContainsKey(type)); - Assert.Equal(expected, interceptor.GeneratedOutputs[type].Content.FormatOutput()); + interceptor.GeneratedOutputs.Should().ContainKey(type); + interceptor.GeneratedOutputs[type].Content.NormalizeFileContent().Should().Be(expected); } } \ No newline at end of file diff --git a/src/TypeGen/TypeGen.IntegrationTest/TestingUtils/GeneratorOutputInterceptor.cs b/src/TypeGen/TypeGen.FileContentTest/TestingUtils/GeneratorOutputInterceptor.cs similarity index 97% rename from src/TypeGen/TypeGen.IntegrationTest/TestingUtils/GeneratorOutputInterceptor.cs rename to src/TypeGen/TypeGen.FileContentTest/TestingUtils/GeneratorOutputInterceptor.cs index cf021b1b..ecfb2d20 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/TestingUtils/GeneratorOutputInterceptor.cs +++ b/src/TypeGen/TypeGen.FileContentTest/TestingUtils/GeneratorOutputInterceptor.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using Gen = TypeGen.Core.Generator; -namespace TypeGen.IntegrationTest.TestingUtils +namespace TypeGen.FileContentTest.TestingUtils { /// /// Intercepts the output produced by the diff --git a/src/TypeGen/TypeGen.FileContentTest/TsClassExtendsTsInterface/Entities/TsClass.cs b/src/TypeGen/TypeGen.FileContentTest/TsClassExtendsTsInterface/Entities/TsClass.cs new file mode 100644 index 00000000..ed983e97 --- /dev/null +++ b/src/TypeGen/TypeGen.FileContentTest/TsClassExtendsTsInterface/Entities/TsClass.cs @@ -0,0 +1,5 @@ +namespace TypeGen.FileContentTest.TsClassExtendsTsInterface.Entities; + +public class TsClass : TsInterface +{ +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.FileContentTest/TsClassExtendsTsInterface/Entities/TsInterface.cs b/src/TypeGen/TypeGen.FileContentTest/TsClassExtendsTsInterface/Entities/TsInterface.cs new file mode 100644 index 00000000..9f47925a --- /dev/null +++ b/src/TypeGen/TypeGen.FileContentTest/TsClassExtendsTsInterface/Entities/TsInterface.cs @@ -0,0 +1,6 @@ +namespace TypeGen.FileContentTest.TsClassExtendsTsInterface.Entities; + +public class TsInterface +{ + +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.FileContentTest/TsClassExtendsTsInterface/Expected/ts-class.ts b/src/TypeGen/TypeGen.FileContentTest/TsClassExtendsTsInterface/Expected/ts-class.ts new file mode 100644 index 00000000..97505a6c --- /dev/null +++ b/src/TypeGen/TypeGen.FileContentTest/TsClassExtendsTsInterface/Expected/ts-class.ts @@ -0,0 +1,9 @@ +/** + * This is a TypeGen auto-generated file. + * Any changes made to this file can be lost when this file is regenerated. + */ + +import { TsInterface } from "./ts-interface"; + +export class TsClass implements TsInterface { +} diff --git a/src/TypeGen/TypeGen.FileContentTest/TsClassExtendsTsInterface/TsClassExtendsTsInterfaceTest.cs b/src/TypeGen/TypeGen.FileContentTest/TsClassExtendsTsInterface/TsClassExtendsTsInterfaceTest.cs new file mode 100644 index 00000000..bb3400f1 --- /dev/null +++ b/src/TypeGen/TypeGen.FileContentTest/TsClassExtendsTsInterface/TsClassExtendsTsInterfaceTest.cs @@ -0,0 +1,31 @@ +using System.Threading.Tasks; +using TypeGen.Core.Generator; +using TypeGen.Core.SpecGeneration; +using TypeGen.FileContentTest.TestingUtils; +using TypeGen.FileContentTest.TsClassExtendsTsInterface.Entities; +using Xunit; + +namespace TypeGen.FileContentTest.TsClassExtendsTsInterface; + +public class TsClassExtendsTsInterfaceTest : GenerationTestBase +{ + [Fact] + public async Task TsClassExtendsTsInterface_Test() + { + var type = typeof(TsClass); + const string expectedLocation = "TypeGen.FileContentTest.TsClassExtendsTsInterface.Expected.ts-class.ts"; + var generationSpec = new TsClassExtendsTsInterfaceGenerationSpec(); + var generatorOptions = new GeneratorOptions(); + + await TestGenerationSpec(type, expectedLocation, generationSpec, generatorOptions); + } + + private class TsClassExtendsTsInterfaceGenerationSpec : GenerationSpec + { + public TsClassExtendsTsInterfaceGenerationSpec() + { + AddClass(); + AddInterface(); + } + } +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.FileContentTest/TsInterfaceInheritance/Entities/Base.cs b/src/TypeGen/TypeGen.FileContentTest/TsInterfaceInheritance/Entities/Base.cs new file mode 100644 index 00000000..afd03802 --- /dev/null +++ b/src/TypeGen/TypeGen.FileContentTest/TsInterfaceInheritance/Entities/Base.cs @@ -0,0 +1,6 @@ +namespace TypeGen.FileContentTest.TsInterfaceInheritance.Entities; + +public class Base +{ + +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.FileContentTest/TsInterfaceInheritance/Entities/Sub.cs b/src/TypeGen/TypeGen.FileContentTest/TsInterfaceInheritance/Entities/Sub.cs new file mode 100644 index 00000000..e4b86907 --- /dev/null +++ b/src/TypeGen/TypeGen.FileContentTest/TsInterfaceInheritance/Entities/Sub.cs @@ -0,0 +1,6 @@ +namespace TypeGen.FileContentTest.TsInterfaceInheritance.Entities; + +public class Sub : Base +{ + +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.FileContentTest/TsInterfaceInheritance/Expected/sub.ts b/src/TypeGen/TypeGen.FileContentTest/TsInterfaceInheritance/Expected/sub.ts new file mode 100644 index 00000000..e5eb8448 --- /dev/null +++ b/src/TypeGen/TypeGen.FileContentTest/TsInterfaceInheritance/Expected/sub.ts @@ -0,0 +1,9 @@ +/** + * This is a TypeGen auto-generated file. + * Any changes made to this file can be lost when this file is regenerated. + */ + +import { Base } from "./base"; + +export interface Sub extends Base { +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.FileContentTest/TsInterfaceInheritance/TsInterfaceInheritanceTest.cs b/src/TypeGen/TypeGen.FileContentTest/TsInterfaceInheritance/TsInterfaceInheritanceTest.cs new file mode 100644 index 00000000..0a898080 --- /dev/null +++ b/src/TypeGen/TypeGen.FileContentTest/TsInterfaceInheritance/TsInterfaceInheritanceTest.cs @@ -0,0 +1,31 @@ +using System.Threading.Tasks; +using TypeGen.Core.Generator; +using TypeGen.Core.SpecGeneration; +using TypeGen.FileContentTest.TestingUtils; +using TypeGen.FileContentTest.TsInterfaceInheritance.Entities; +using Xunit; + +namespace TypeGen.FileContentTest.TsInterfaceInheritance; + +public class TsInterfaceInheritanceTest : GenerationTestBase +{ + [Fact] + public async Task cs_classes_which_are_ts_interfaces_should_respect_ts_interface_inheritance() + { + var type = typeof(Sub); + const string expectedLocation = "TypeGen.FileContentTest.TsInterfaceInheritance.Expected.sub.ts"; + var generationSpec = new TsInterfaceInheritanceGenerationSpec(); + var generatorOptions = new GeneratorOptions(); + + await TestGenerationSpec(type, expectedLocation, generationSpec, generatorOptions); + } + + private class TsInterfaceInheritanceGenerationSpec : GenerationSpec + { + public TsInterfaceInheritanceGenerationSpec() + { + AddInterface(); + AddInterface(); + } + } +} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.IntegrationTest/TypeGen.IntegrationTest.csproj b/src/TypeGen/TypeGen.FileContentTest/TypeGen.FileContentTest.csproj similarity index 92% rename from src/TypeGen/TypeGen.IntegrationTest/TypeGen.IntegrationTest.csproj rename to src/TypeGen/TypeGen.FileContentTest/TypeGen.FileContentTest.csproj index 7751ea29..93719d7e 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/TypeGen.IntegrationTest.csproj +++ b/src/TypeGen/TypeGen.FileContentTest/TypeGen.FileContentTest.csproj @@ -5,15 +5,15 @@ false - TypeGen.IntegrationTest + TypeGen.FileContentTest - bin\Debug\TypeGen.IntegrationTest.xml + bin\Debug\TypeGen.FileContentTest.xml - bin\Release\TypeGen.IntegrationTest.xml + bin\Release\TypeGen.FileContentTest.xml @@ -32,6 +32,10 @@ + + + + @@ -108,6 +112,8 @@ + + diff --git a/src/TypeGen/TypeGen.IntegrationTest/UseDefaultExportBreaksInterfaceInheritance/Entities/IId.cs b/src/TypeGen/TypeGen.FileContentTest/UseDefaultExportBreaksInterfaceInheritance/Entities/IId.cs similarity index 53% rename from src/TypeGen/TypeGen.IntegrationTest/UseDefaultExportBreaksInterfaceInheritance/Entities/IId.cs rename to src/TypeGen/TypeGen.FileContentTest/UseDefaultExportBreaksInterfaceInheritance/Entities/IId.cs index 0a9f7f27..5b98bd2f 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/UseDefaultExportBreaksInterfaceInheritance/Entities/IId.cs +++ b/src/TypeGen/TypeGen.FileContentTest/UseDefaultExportBreaksInterfaceInheritance/Entities/IId.cs @@ -1,4 +1,4 @@ -namespace TypeGen.IntegrationTest.UseDefaultExportBreaksInterfaceInheritance.Entities; +namespace TypeGen.FileContentTest.UseDefaultExportBreaksInterfaceInheritance.Entities; public interface IId { diff --git a/src/TypeGen/TypeGen.IntegrationTest/UseDefaultExportBreaksInterfaceInheritance/Entities/IIdentifier.cs b/src/TypeGen/TypeGen.FileContentTest/UseDefaultExportBreaksInterfaceInheritance/Entities/IIdentifier.cs similarity index 58% rename from src/TypeGen/TypeGen.IntegrationTest/UseDefaultExportBreaksInterfaceInheritance/Entities/IIdentifier.cs rename to src/TypeGen/TypeGen.FileContentTest/UseDefaultExportBreaksInterfaceInheritance/Entities/IIdentifier.cs index 596222d1..09ddedef 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/UseDefaultExportBreaksInterfaceInheritance/Entities/IIdentifier.cs +++ b/src/TypeGen/TypeGen.FileContentTest/UseDefaultExportBreaksInterfaceInheritance/Entities/IIdentifier.cs @@ -1,4 +1,4 @@ -namespace TypeGen.IntegrationTest.UseDefaultExportBreaksInterfaceInheritance.Entities; +namespace TypeGen.FileContentTest.UseDefaultExportBreaksInterfaceInheritance.Entities; public interface IIdentifier { diff --git a/src/TypeGen/TypeGen.IntegrationTest/UseDefaultExportBreaksInterfaceInheritance/Entities/ProductDto.cs b/src/TypeGen/TypeGen.FileContentTest/UseDefaultExportBreaksInterfaceInheritance/Entities/ProductDto.cs similarity index 69% rename from src/TypeGen/TypeGen.IntegrationTest/UseDefaultExportBreaksInterfaceInheritance/Entities/ProductDto.cs rename to src/TypeGen/TypeGen.FileContentTest/UseDefaultExportBreaksInterfaceInheritance/Entities/ProductDto.cs index dd3c50a5..aab7ddfb 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/UseDefaultExportBreaksInterfaceInheritance/Entities/ProductDto.cs +++ b/src/TypeGen/TypeGen.FileContentTest/UseDefaultExportBreaksInterfaceInheritance/Entities/ProductDto.cs @@ -1,4 +1,4 @@ -namespace TypeGen.IntegrationTest.UseDefaultExportBreaksInterfaceInheritance.Entities; +namespace TypeGen.FileContentTest.UseDefaultExportBreaksInterfaceInheritance.Entities; public class ProductDto : IId, IIdentifier { diff --git a/src/TypeGen/TypeGen.IntegrationTest/UseDefaultExportBreaksInterfaceInheritance/Expected/product-dto.ts b/src/TypeGen/TypeGen.FileContentTest/UseDefaultExportBreaksInterfaceInheritance/Expected/product-dto.ts similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/UseDefaultExportBreaksInterfaceInheritance/Expected/product-dto.ts rename to src/TypeGen/TypeGen.FileContentTest/UseDefaultExportBreaksInterfaceInheritance/Expected/product-dto.ts diff --git a/src/TypeGen/TypeGen.IntegrationTest/UseDefaultExportBreaksInterfaceInheritance/UseDefaultExportBreaksInterfaceInheritanceTest.cs b/src/TypeGen/TypeGen.FileContentTest/UseDefaultExportBreaksInterfaceInheritance/UseDefaultExportBreaksInterfaceInheritanceTest.cs similarity index 81% rename from src/TypeGen/TypeGen.IntegrationTest/UseDefaultExportBreaksInterfaceInheritance/UseDefaultExportBreaksInterfaceInheritanceTest.cs rename to src/TypeGen/TypeGen.FileContentTest/UseDefaultExportBreaksInterfaceInheritance/UseDefaultExportBreaksInterfaceInheritanceTest.cs index 3169682b..b3ad0a36 100644 --- a/src/TypeGen/TypeGen.IntegrationTest/UseDefaultExportBreaksInterfaceInheritance/UseDefaultExportBreaksInterfaceInheritanceTest.cs +++ b/src/TypeGen/TypeGen.FileContentTest/UseDefaultExportBreaksInterfaceInheritance/UseDefaultExportBreaksInterfaceInheritanceTest.cs @@ -1,16 +1,16 @@ using System; using System.Threading.Tasks; using TypeGen.Core.SpecGeneration; -using TypeGen.IntegrationTest.TestingUtils; -using TypeGen.IntegrationTest.UseDefaultExportBreaksInterfaceInheritance.Entities; +using TypeGen.FileContentTest.TestingUtils; +using TypeGen.FileContentTest.UseDefaultExportBreaksInterfaceInheritance.Entities; using Xunit; -namespace TypeGen.IntegrationTest.UseDefaultExportBreaksInterfaceInheritance; +namespace TypeGen.FileContentTest.UseDefaultExportBreaksInterfaceInheritance; public class UseDefaultExportBreaksInterfaceInheritanceTest : GenerationTestBase { [Theory] - [InlineData(typeof(ProductDto), "TypeGen.IntegrationTest.UseDefaultExportBreaksInterfaceInheritance.Expected.product-dto.ts")] + [InlineData(typeof(ProductDto), "TypeGen.FileContentTest.UseDefaultExportBreaksInterfaceInheritance.Expected.product-dto.ts")] public async Task TestUseDefaultExportBreaksInterfaceInheritanceGenerationSpec(Type type, string expectedLocation) { var generationSpec = new UseDefaultExportBreaksInterfaceInheritanceGenerationSpec(); diff --git a/src/TypeGen/TypeGen.IntegrationTest/tgconfig.json b/src/TypeGen/TypeGen.FileContentTest/tgconfig.json similarity index 100% rename from src/TypeGen/TypeGen.IntegrationTest/tgconfig.json rename to src/TypeGen/TypeGen.FileContentTest/tgconfig.json diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/CommonCasesGenerationTest.cs b/src/TypeGen/TypeGen.IntegrationTest/CommonCases/CommonCasesGenerationTest.cs deleted file mode 100644 index 9bbfff65..00000000 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/CommonCasesGenerationTest.cs +++ /dev/null @@ -1,107 +0,0 @@ -using System; -using System.Threading.Tasks; -using TypeGen.IntegrationTest.CommonCases.Entities; -using TypeGen.IntegrationTest.CommonCases.Entities.Constants; -using TypeGen.IntegrationTest.CommonCases.Entities.ErrorCase; -using TypeGen.IntegrationTest.CommonCases.Entities.Structs; -using TypeGen.IntegrationTest.DefaultExport.Entities; -using TypeGen.IntegrationTest.IgnoreBaseInterfaces.Entities; -using TypeGen.IntegrationTest.TestingUtils; -using Xunit; -using Gen = TypeGen.Core.Generator; -using CustomBaseClass = TypeGen.IntegrationTest.CommonCases.Entities.CustomBaseClass; -using CustomBaseCustomImport = TypeGen.IntegrationTest.CommonCases.Entities.CustomBaseCustomImport; -using CustomEmptyBaseClass = TypeGen.IntegrationTest.CommonCases.Entities.CustomEmptyBaseClass; -using DefaultMemberValues = TypeGen.IntegrationTest.CommonCases.Entities.DefaultMemberValues; -using ExtendedPrimitivesClass = TypeGen.IntegrationTest.CommonCases.Entities.ExtendedPrimitivesClass; -using ExternalDepsClass = TypeGen.IntegrationTest.CommonCases.Entities.ExternalDepsClass; -using ITestInterface = TypeGen.IntegrationTest.CommonCases.Entities.ITestInterface; -using LiteDbEntity = TypeGen.IntegrationTest.CommonCases.Entities.LiteDbEntity; -using NoSlashOutputDir = TypeGen.IntegrationTest.CommonCases.Entities.NoSlashOutputDir; -using ReadonlyInterface = TypeGen.IntegrationTest.CommonCases.Entities.ReadonlyInterface; -using StaticReadonly = TypeGen.IntegrationTest.CommonCases.Entities.StaticReadonly; -using StrictNullsClass = TypeGen.IntegrationTest.CommonCases.Entities.StrictNullsClass; -using TestInterface = TypeGen.IntegrationTest.CommonCases.Entities.TestInterface; -using TypeUnions = TypeGen.IntegrationTest.CommonCases.Entities.TypeUnions; - -namespace TypeGen.IntegrationTest.CommonCases -{ - public class CommonCasesGenerationTest : GenerationTestBase - { - /// - /// Tests if types are correctly translated to TypeScript. - /// The tested types contain all major use cases that should be supported. - /// - /// - /// - /// - [Theory] - [InlineData(typeof(FooConstants), "TypeGen.IntegrationTest.CommonCases.Expected.foo-constants.ts")] - [InlineData(typeof(CustomBaseCustomImport), "TypeGen.IntegrationTest.CommonCases.Expected.custom-base-custom-import.ts")] - [InlineData(typeof(Bar), "TypeGen.IntegrationTest.CommonCases.Expected.bar.ts")] - [InlineData(typeof(Entities.BaseClass<>), "TypeGen.IntegrationTest.CommonCases.Expected.base-class.ts")] - [InlineData(typeof(BaseClass2<>), "TypeGen.IntegrationTest.CommonCases.Expected.base-class2.ts")] - [InlineData(typeof(C), "TypeGen.IntegrationTest.CommonCases.Expected.c.ts")] - [InlineData(typeof(CustomBaseClass), "TypeGen.IntegrationTest.CommonCases.Expected.custom-base-class.ts")] - [InlineData(typeof(CustomEmptyBaseClass), "TypeGen.IntegrationTest.CommonCases.Expected.custom-empty-base-class.ts")] - [InlineData(typeof(D), "TypeGen.IntegrationTest.CommonCases.Expected.d.ts")] - [InlineData(typeof(DefaultMemberValues), "TypeGen.IntegrationTest.CommonCases.Expected.default-member-values.ts")] - [InlineData(typeof(EClass), "TypeGen.IntegrationTest.CommonCases.Expected.e-class.ts")] - [InlineData(typeof(ExtendedPrimitivesClass), "TypeGen.IntegrationTest.CommonCases.Expected.extended-primitives-class.ts")] - [InlineData(typeof(ExternalDepsClass), "TypeGen.IntegrationTest.CommonCases.Expected.external-deps-class.ts")] - [InlineData(typeof(FClass), "TypeGen.IntegrationTest.CommonCases.Expected.f-class.ts")] - [InlineData(typeof(FooType), "TypeGen.IntegrationTest.CommonCases.Expected.foo-type.ts")] - [InlineData(typeof(Foo), "TypeGen.IntegrationTest.CommonCases.Expected.foo.ts")] - [InlineData(typeof(Entities.GenericBaseClass<>), "TypeGen.IntegrationTest.CommonCases.Expected.generic-base-class.ts")] - [InlineData(typeof(GenericClass<>), "TypeGen.IntegrationTest.CommonCases.Expected.generic-class.ts")] - [InlineData(typeof(Entities.GenericWithRestrictions<>), "TypeGen.IntegrationTest.CommonCases.Expected.generic-with-restrictions.ts")] - [InlineData(typeof(ITestInterface), "TypeGen.IntegrationTest.CommonCases.Expected.i-test-interface.ts")] - [InlineData(typeof(LiteDbEntity), "TypeGen.IntegrationTest.CommonCases.Expected.lite-db-entity.ts")] - [InlineData(typeof(ReadonlyInterface), "TypeGen.IntegrationTest.CommonCases.Expected.readonly-interface.ts")] - [InlineData(typeof(StandaloneEnum), "TypeGen.IntegrationTest.CommonCases.Expected.standalone-enum.ts")] - [InlineData(typeof(EnumShortValues), "TypeGen.IntegrationTest.CommonCases.Expected.enum-short-values.ts")] - [InlineData(typeof(EnumAsUnionType), "TypeGen.IntegrationTest.CommonCases.Expected.enum-as-union-type.ts")] - [InlineData(typeof(DictionaryWithEnumKey), "TypeGen.IntegrationTest.CommonCases.Expected.dictionary-with-enum-key.ts")] - [InlineData(typeof(DictionaryStringObjectErrorCase), "TypeGen.IntegrationTest.CommonCases.Expected.dictionary-string-object-error-case.ts")] - [InlineData(typeof(StaticReadonly), "TypeGen.IntegrationTest.CommonCases.Expected.static-readonly.ts")] - [InlineData(typeof(StrictNullsClass), "TypeGen.IntegrationTest.CommonCases.Expected.strict-nulls-class.ts")] - [InlineData(typeof(TypeUnions), "TypeGen.IntegrationTest.CommonCases.Expected.type-unions.ts")] - [InlineData(typeof(WithGenericBaseClassCustomType), "TypeGen.IntegrationTest.CommonCases.Expected.with-generic-base-class-custom-type.ts")] - [InlineData(typeof(WithIgnoredBaseAndCustomBase), "TypeGen.IntegrationTest.CommonCases.Expected.with-ignored-base-and-custom-base.ts")] - [InlineData(typeof(WithIgnoredBase), "TypeGen.IntegrationTest.CommonCases.Expected.with-ignored-base.ts")] - [InlineData(typeof(NoSlashOutputDir), "TypeGen.IntegrationTest.CommonCases.Expected.no.slash.output.dir.no-slash-output-dir.ts")] - [InlineData(typeof(Entities.BaseClass<>), "TypeGen.IntegrationTest.CommonCases.Expected.test_classes.base-class.ts")] - [InlineData(typeof(BaseClass2<>), "TypeGen.IntegrationTest.CommonCases.Expected.test_classes.base-class2.ts")] - [InlineData(typeof(CircularRefClass1), "TypeGen.IntegrationTest.CommonCases.Expected.test_classes.circular-ref-class1.ts")] - [InlineData(typeof(CircularRefClass2), "TypeGen.IntegrationTest.CommonCases.Expected.test_classes.circular-ref-class2.ts")] - [InlineData(typeof(TestClass<,>), "TypeGen.IntegrationTest.CommonCases.Expected.test_classes.test-class.ts")] - [InlineData(typeof(TestEnum), "TypeGen.IntegrationTest.CommonCases.Expected.test_enums.test-enum.ts")] - [InlineData(typeof(TestInterface), "TypeGen.IntegrationTest.CommonCases.Expected.test_interfaces.test-interface.ts")] - [InlineData(typeof(NestedEntity), "TypeGen.IntegrationTest.CommonCases.Expected.very.nested.directory.nested-entity.ts")] - [InlineData(typeof(ArrayOfNullable), "TypeGen.IntegrationTest.CommonCases.Expected.array-of-nullable.ts")] - - // now do the cases above for structs (when possible) - - [InlineData(typeof(Entities.Constants.Structs.FooConstants), "TypeGen.IntegrationTest.CommonCases.Expected.foo-constants.ts")] - [InlineData(typeof(Entities.Structs.CustomBaseCustomImport), "TypeGen.IntegrationTest.CommonCases.Expected.custom-base-custom-import.ts")] - [InlineData(typeof(Entities.Structs.CustomBaseClass), "TypeGen.IntegrationTest.CommonCases.Expected.custom-base-class.ts")] - [InlineData(typeof(Entities.Structs.CustomEmptyBaseClass), "TypeGen.IntegrationTest.CommonCases.Expected.custom-empty-base-class.ts")] - [InlineData(typeof(Entities.Structs.DefaultMemberValues), "TypeGen.IntegrationTest.CommonCases.Expected.default-member-values_struct.ts")] - [InlineData(typeof(Entities.Structs.ExtendedPrimitivesClass), "TypeGen.IntegrationTest.CommonCases.Expected.extended-primitives-class.ts")] - [InlineData(typeof(Entities.Structs.ExternalDepsClass), "TypeGen.IntegrationTest.CommonCases.Expected.external-deps-class.ts")] - [InlineData(typeof(Entities.Structs.GenericBaseClass<>), "TypeGen.IntegrationTest.CommonCases.Expected.generic-base-class.ts")] - [InlineData(typeof(Entities.Structs.GenericWithRestrictions<>), "TypeGen.IntegrationTest.CommonCases.Expected.generic-with-restrictions.ts")] - [InlineData(typeof(Entities.Structs.ITestInterface), "TypeGen.IntegrationTest.CommonCases.Expected.i-test-interface.ts")] - [InlineData(typeof(Entities.Structs.LiteDbEntity), "TypeGen.IntegrationTest.CommonCases.Expected.lite-db-entity.ts")] - [InlineData(typeof(Entities.Structs.ReadonlyInterface), "TypeGen.IntegrationTest.CommonCases.Expected.readonly-interface.ts")] - [InlineData(typeof(Entities.Structs.StaticReadonly), "TypeGen.IntegrationTest.CommonCases.Expected.static-readonly.ts")] - [InlineData(typeof(Entities.Structs.StrictNullsClass), "TypeGen.IntegrationTest.CommonCases.Expected.strict-nulls-class.ts")] - [InlineData(typeof(Entities.Structs.TypeUnions), "TypeGen.IntegrationTest.CommonCases.Expected.type-unions.ts")] - [InlineData(typeof(Entities.Structs.NoSlashOutputDir), "TypeGen.IntegrationTest.CommonCases.Expected.no.slash.output.dir.no-slash-output-dir.ts")] - [InlineData(typeof(Entities.Structs.TestInterface), "TypeGen.IntegrationTest.CommonCases.Expected.test_interfaces.test-interface.ts")] - public async Task TestCommonCases(Type type, string expectedLocation) - { - await TestFromAssembly(type, expectedLocation); - } - } -} diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/NotGeneratedBaseClass.cs b/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/NotGeneratedBaseClass.cs deleted file mode 100644 index 8bb32455..00000000 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/NotGeneratedBaseClass.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace TypeGen.IntegrationTest.CommonCases.Entities -{ - public class NotGeneratedBaseClass - { - } -} diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Structs/IBar.cs b/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Structs/IBar.cs deleted file mode 100644 index e8dd97db..00000000 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Structs/IBar.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace TypeGen.IntegrationTest.CommonCases.Entities.Structs; - -public interface IBar -{ - -} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Structs/IFoo.cs b/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Structs/IFoo.cs deleted file mode 100644 index 82342e3b..00000000 --- a/src/TypeGen/TypeGen.IntegrationTest/CommonCases/Entities/Structs/IFoo.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace TypeGen.IntegrationTest.CommonCases.Entities.Structs; - -public interface IFoo -{ - -} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.IntegrationTest/CustomBaseInterfaces/Entities/ITest.cs b/src/TypeGen/TypeGen.IntegrationTest/CustomBaseInterfaces/Entities/ITest.cs deleted file mode 100644 index 533cf50d..00000000 --- a/src/TypeGen/TypeGen.IntegrationTest/CustomBaseInterfaces/Entities/ITest.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace TypeGen.IntegrationTest.CustomBaseInterfaces.Entities; - -public interface ITest -{ - -} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.IntegrationTest/ExportTypesAsInterfacesByDefault/Entities/Child.cs b/src/TypeGen/TypeGen.IntegrationTest/ExportTypesAsInterfacesByDefault/Entities/Child.cs deleted file mode 100644 index b9b24389..00000000 --- a/src/TypeGen/TypeGen.IntegrationTest/ExportTypesAsInterfacesByDefault/Entities/Child.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace TypeGen.IntegrationTest.ExportTypesAsInterfacesByDefault.Entities; - -public class Child -{ - -} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.IntegrationTest/Extensions/StringExtensions.cs b/src/TypeGen/TypeGen.IntegrationTest/Extensions/StringExtensions.cs deleted file mode 100644 index 624ca8bd..00000000 --- a/src/TypeGen/TypeGen.IntegrationTest/Extensions/StringExtensions.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace TypeGen.IntegrationTest.Extensions; - -public static class StringExtensions -{ - public static string FormatOutput(this string output) - => output - .Trim() - .Replace("\n", "") - .Replace("\r", "") - .Replace("\r\n", ""); -} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.IntegrationTest/IgnoreBaseInterfaces/Entities/ITest.cs b/src/TypeGen/TypeGen.IntegrationTest/IgnoreBaseInterfaces/Entities/ITest.cs deleted file mode 100644 index df86d689..00000000 --- a/src/TypeGen/TypeGen.IntegrationTest/IgnoreBaseInterfaces/Entities/ITest.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace TypeGen.IntegrationTest.IgnoreBaseInterfaces.Entities; - -public interface ITest -{ - -} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.IntegrationTest/ImportType/Entities/DepClass.cs b/src/TypeGen/TypeGen.IntegrationTest/ImportType/Entities/DepClass.cs deleted file mode 100644 index 9fdf5934..00000000 --- a/src/TypeGen/TypeGen.IntegrationTest/ImportType/Entities/DepClass.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace TypeGen.IntegrationTest.ImportType.Entities; - -public class DepClass -{ - -} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.IntegrationTest/StructImplementsInterfaces/Entities/ImplementsInterfaces.cs b/src/TypeGen/TypeGen.IntegrationTest/StructImplementsInterfaces/Entities/ImplementsInterfaces.cs deleted file mode 100644 index 5d168466..00000000 --- a/src/TypeGen/TypeGen.IntegrationTest/StructImplementsInterfaces/Entities/ImplementsInterfaces.cs +++ /dev/null @@ -1,10 +0,0 @@ -using TypeGen.Core.TypeAnnotations; -using TypeGen.IntegrationTest.CommonCases.Entities.Structs; - -namespace TypeGen.IntegrationTest.StructImplementsInterfaces.Entities; - -[ExportTsClass] -public struct ImplementsInterfaces : IFoo, IBar -{ - -} \ No newline at end of file diff --git a/src/TypeGen/TypeGen.IntegrationTest/TestingUtils/EmbededResourceReader.cs b/src/TypeGen/TypeGen.IntegrationTest/TestingUtils/EmbededResourceReader.cs deleted file mode 100644 index ea6a6507..00000000 --- a/src/TypeGen/TypeGen.IntegrationTest/TestingUtils/EmbededResourceReader.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System.IO; -using System.Reflection; -using System.Text; -using System.Threading.Tasks; -using TypeGen.Core; - -namespace TypeGen.IntegrationTest.TestingUtils -{ - public static class EmbededResourceReader - { - public static async Task GetEmbeddedResourceAsync(string name) - { - using (Stream stream = typeof(EmbededResourceReader).GetTypeInfo().Assembly.GetManifestResourceStream(name)) - { - if (stream == null) - { - throw new CoreException($"Could not find embedded resource '{name}'"); - } - - var contentBytes = new byte[stream.Length]; - await stream.ReadAsync(contentBytes, 0, (int)stream.Length); - var res = Encoding.UTF8.GetString(contentBytes); - return res - .Trim('\uFEFF') - .Replace("\n", "") - .Replace("\r", "") - .Replace("\r\n", ""); - } - } - } -} diff --git a/src/TypeGen/TypeGen.sln b/src/TypeGen/TypeGen.sln index 67bdf1d4..6013efa2 100644 --- a/src/TypeGen/TypeGen.sln +++ b/src/TypeGen/TypeGen.sln @@ -11,7 +11,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TypeGen.Core.Test", "TypeGe EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TypeGen.Cli.Test", "TypeGen.Cli.Test\TypeGen.Cli.Test.csproj", "{7A524558-A065-44EB-B9BC-1DC46ED4042C}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TypeGen.IntegrationTest", "TypeGen.IntegrationTest\TypeGen.IntegrationTest.csproj", "{CC91A6B3-AA7E-42B5-B920-5F21DB14D791}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TypeGen.FileContentTest", "TypeGen.FileContentTest\TypeGen.FileContentTest.csproj", "{CC91A6B3-AA7E-42B5-B920-5F21DB14D791}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/update-version.ps1 b/update-version.ps1 index dad496cd..2cf8db11 100644 --- a/update-version.ps1 +++ b/update-version.ps1 @@ -1,52 +1,81 @@ if ($args.Length -eq 0) { Write-Host "examples: -./update-version increment # increments the minor version, i.e. the middle part of the version ./update-version 2.4.9 # changes the current version to 2.4.9" exit } $versionRegex = "^\d+\.\d+\.\d+$" +$newVersion = $args[0] -$oldVersion = (Select-Xml //version "nuget\TypeGen.nuspec")[0].Node.InnerText +if (-not ($newVersion -match $versionRegex)) { + Write-Host "Wrong version format. Should be: $($versionRegex)" + exit +} +$oldVersion = (Select-Xml //version "nuget\TypeGen.nuspec")[0].Node.InnerText $oldVersionMajor = $oldVersion.Split(".")[0] $oldVersionMinor = $oldVersion.Split(".")[1] -$newVersionMinor = ($oldVersionMinor -as [int]) + 1 -$newVersion = if ($args -contains "increment") {"$($oldVersionMajor).$($newVersionMinor).0"} else {$args[0]} +$newVersionMajor = $newVersion.Split(".")[0] +$newVersionMinor = $newVersion.Split(".")[1] -if (-not ($newVersion -match $versionRegex)) { - Write-Host "Wrong version format. Should be: $($versionRegex)" - exit -} +$assemblyOldVersion = "$($oldVersionMajor).$($oldVersionMinor).0.0" +$assemblyNewVersion = "$($newVersionMajor).$($newVersionMinor).0.0" # replace files' contents $nuspecPath = "nuget\TypeGen.nuspec" if (Test-Path $nuspecPath) { - (Get-Content $nuspecPath).Replace("$($oldVersion)", "$($newVersion)") | Set-Content $nuspecPath + (Get-Content $nuspecPath) ` + -Replace "$($oldVersion)", "$($newVersion)" ` + | Set-Content $nuspecPath } $dotNetCliNuspecPath = "nuget-dotnetcli\dotnet-typegen.nuspec" if (Test-Path $dotNetCliNuspecPath) { - (Get-Content $dotNetCliNuspecPath).Replace("$($oldVersion)", "$($newVersion)") | Set-Content $dotNetCliNuspecPath - #.Replace("id=""TypeGen"" version=""$($oldVersion)""", "id=""TypeGen"" version=""$($newVersion)""") + (Get-Content $dotNetCliNuspecPath) ` + -Replace "$($oldVersion)", "$($newVersion)" ` + | Set-Content $dotNetCliNuspecPath } -#$docsConfPath = "..\TypeGenDocs\source\conf.py" -#if (Test-Path $docsConfPath) { -# (Get-Content $docsConfPath).Replace("version = u'$($oldVersion)'", "version = u'$($newVersion)'") | Set-Content $docsConfPath -#} - -$appConfigPath = "src\TypeGen\TypeGen.Cli\AppConfig.cs" +$appConfigPath = "src\TypeGen\TypeGen.Cli\ApplicationConfig.cs" if (Test-Path $appConfigPath) { - (Get-Content $appConfigPath).Replace("Version => ""$($oldVersion)""", "Version => ""$($newVersion)""") | Set-Content $appConfigPath + (Get-Content $appConfigPath) ` + -Replace "Version => ""$($oldVersion)""", "Version => ""$($newVersion)""" ` + | Set-Content $appConfigPath } $nugetUpdatePath = "nuget-update.ps1" if (Test-Path $nugetUpdatePath) { - (Get-Content $nugetUpdatePath).Replace("TypeGen.$($oldVersion)", "TypeGen.$($newVersion)").Replace("dotnet-typegen.$($oldVersion)", "dotnet-typegen.$($newVersion)") | Set-Content $nugetUpdatePath + (Get-Content $nugetUpdatePath) ` + -Replace "TypeGen.$($oldVersion)", "TypeGen.$($newVersion)" ` + -Replace "dotnet-typegen.$($oldVersion)", "dotnet-typegen.$($newVersion)" ` + | Set-Content $nugetUpdatePath +} + +$applicationConfigPath = "src\TypeGen\TypeGen.Cli\ApplicationConfig.cs" +if (Test-Path $applicationConfigPath) { + (Get-Content $applicationConfigPath) ` + -Replace "Version = ""$($oldVersion)""", "Version = ""$($newVersion)""" ` + | Set-Content $applicationConfigPath +} + +$typeGenCliCsprojPath = "src\TypeGen\TypeGen.Cli\TypeGen.Cli.csproj" +if (Test-Path $typeGenCliCsprojPath) { + (Get-Content $typeGenCliCsprojPath) ` + -Replace "$($assemblyOldVersion)", "$($assemblyNewVersion)" ` + -Replace "$($assemblyOldVersion)", "$($assemblyNewVersion)" ` + -Replace "$($oldVersion)", "$($newVersion)" ` + | Set-Content $typeGenCliCsprojPath +} + +$typeGenCoreCsprojPath = "src\TypeGen\TypeGen.Core\TypeGen.Core.csproj" +if (Test-Path $typeGenCoreCsprojPath) { + (Get-Content $typeGenCoreCsprojPath) ` + -Replace "$($assemblyOldVersion)", "$($assemblyNewVersion)" ` + -Replace "$($assemblyOldVersion)", "$($assemblyNewVersion)" ` + | Set-Content $typeGenCoreCsprojPath } # remove old NuGet package