diff --git a/MTT.sln b/MTT.sln new file mode 100644 index 0000000..741c3d4 --- /dev/null +++ b/MTT.sln @@ -0,0 +1,69 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26124.0 +MinimumVisualStudioVersion = 15.0.26124.0 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Source", "Source", "{E8F70989-6978-472E-AC1A-0097110BB638}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MTT", "Source\MTT\MTT.csproj", "{483F21EA-F84C-49E8-BF1A-FC03FF8BA965}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MTTRunner", "Source\MTTRunner\MTTRunner.csproj", "{AE561C86-8C30-4668-B499-9D7770C5D84B}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MTTRunner.Tests", "Source\MTTRunner.Tests\MTTRunner.Tests.csproj", "{0413F47D-C62A-46E4-8E3D-281DD33B84E3}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {483F21EA-F84C-49E8-BF1A-FC03FF8BA965}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {483F21EA-F84C-49E8-BF1A-FC03FF8BA965}.Debug|Any CPU.Build.0 = Debug|Any CPU + {483F21EA-F84C-49E8-BF1A-FC03FF8BA965}.Debug|x64.ActiveCfg = Debug|Any CPU + {483F21EA-F84C-49E8-BF1A-FC03FF8BA965}.Debug|x64.Build.0 = Debug|Any CPU + {483F21EA-F84C-49E8-BF1A-FC03FF8BA965}.Debug|x86.ActiveCfg = Debug|Any CPU + {483F21EA-F84C-49E8-BF1A-FC03FF8BA965}.Debug|x86.Build.0 = Debug|Any CPU + {483F21EA-F84C-49E8-BF1A-FC03FF8BA965}.Release|Any CPU.ActiveCfg = Release|Any CPU + {483F21EA-F84C-49E8-BF1A-FC03FF8BA965}.Release|Any CPU.Build.0 = Release|Any CPU + {483F21EA-F84C-49E8-BF1A-FC03FF8BA965}.Release|x64.ActiveCfg = Release|Any CPU + {483F21EA-F84C-49E8-BF1A-FC03FF8BA965}.Release|x64.Build.0 = Release|Any CPU + {483F21EA-F84C-49E8-BF1A-FC03FF8BA965}.Release|x86.ActiveCfg = Release|Any CPU + {483F21EA-F84C-49E8-BF1A-FC03FF8BA965}.Release|x86.Build.0 = Release|Any CPU + {AE561C86-8C30-4668-B499-9D7770C5D84B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AE561C86-8C30-4668-B499-9D7770C5D84B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AE561C86-8C30-4668-B499-9D7770C5D84B}.Debug|x64.ActiveCfg = Debug|Any CPU + {AE561C86-8C30-4668-B499-9D7770C5D84B}.Debug|x64.Build.0 = Debug|Any CPU + {AE561C86-8C30-4668-B499-9D7770C5D84B}.Debug|x86.ActiveCfg = Debug|Any CPU + {AE561C86-8C30-4668-B499-9D7770C5D84B}.Debug|x86.Build.0 = Debug|Any CPU + {AE561C86-8C30-4668-B499-9D7770C5D84B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AE561C86-8C30-4668-B499-9D7770C5D84B}.Release|Any CPU.Build.0 = Release|Any CPU + {AE561C86-8C30-4668-B499-9D7770C5D84B}.Release|x64.ActiveCfg = Release|Any CPU + {AE561C86-8C30-4668-B499-9D7770C5D84B}.Release|x64.Build.0 = Release|Any CPU + {AE561C86-8C30-4668-B499-9D7770C5D84B}.Release|x86.ActiveCfg = Release|Any CPU + {AE561C86-8C30-4668-B499-9D7770C5D84B}.Release|x86.Build.0 = Release|Any CPU + {0413F47D-C62A-46E4-8E3D-281DD33B84E3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0413F47D-C62A-46E4-8E3D-281DD33B84E3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0413F47D-C62A-46E4-8E3D-281DD33B84E3}.Debug|x64.ActiveCfg = Debug|Any CPU + {0413F47D-C62A-46E4-8E3D-281DD33B84E3}.Debug|x64.Build.0 = Debug|Any CPU + {0413F47D-C62A-46E4-8E3D-281DD33B84E3}.Debug|x86.ActiveCfg = Debug|Any CPU + {0413F47D-C62A-46E4-8E3D-281DD33B84E3}.Debug|x86.Build.0 = Debug|Any CPU + {0413F47D-C62A-46E4-8E3D-281DD33B84E3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0413F47D-C62A-46E4-8E3D-281DD33B84E3}.Release|Any CPU.Build.0 = Release|Any CPU + {0413F47D-C62A-46E4-8E3D-281DD33B84E3}.Release|x64.ActiveCfg = Release|Any CPU + {0413F47D-C62A-46E4-8E3D-281DD33B84E3}.Release|x64.Build.0 = Release|Any CPU + {0413F47D-C62A-46E4-8E3D-281DD33B84E3}.Release|x86.ActiveCfg = Release|Any CPU + {0413F47D-C62A-46E4-8E3D-281DD33B84E3}.Release|x86.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {483F21EA-F84C-49E8-BF1A-FC03FF8BA965} = {E8F70989-6978-472E-AC1A-0097110BB638} + {AE561C86-8C30-4668-B499-9D7770C5D84B} = {E8F70989-6978-472E-AC1A-0097110BB638} + {0413F47D-C62A-46E4-8E3D-281DD33B84E3} = {E8F70989-6978-472E-AC1A-0097110BB638} + EndGlobalSection +EndGlobal diff --git a/Source/MTTRunner.Tests/MTTRunner.Tests.csproj b/Source/MTTRunner.Tests/MTTRunner.Tests.csproj new file mode 100644 index 0000000..7479d85 --- /dev/null +++ b/Source/MTTRunner.Tests/MTTRunner.Tests.csproj @@ -0,0 +1,19 @@ + + + + netcoreapp2.2 + + false + + + + + + + + + + + + + diff --git a/Source/MTTRunner.Tests/README.MD b/Source/MTTRunner.Tests/README.MD new file mode 100644 index 0000000..6d9f269 --- /dev/null +++ b/Source/MTTRunner.Tests/README.MD @@ -0,0 +1,3 @@ +# Tests + +Run with `dotnet test` in root folder \ No newline at end of file diff --git a/Source/MTTRunner.Tests/UnitTest.cs b/Source/MTTRunner.Tests/UnitTest.cs new file mode 100644 index 0000000..24372c0 --- /dev/null +++ b/Source/MTTRunner.Tests/UnitTest.cs @@ -0,0 +1,201 @@ +using NUnit.Framework; +using MTTRunner; +using System.IO; +using System; +using System.Text.RegularExpressions; + +namespace MTTRunner.Tests +{ + public class BasicTests + { + private readonly string CurrentDir = Directory.GetCurrentDirectory().Replace("\\", "/"); + private readonly string WorkingDir = "workingDir/"; + private readonly string ConvertDir = "convertDir/"; + private string VehicleFile; + + [SetUp] + public void Setup() + { + VehicleFile = Path.Combine(CurrentDir, ConvertDir, "Vehicles/vehicle.ts"); + + var resources = CurrentDir.Replace("Source/MTTRunner.Tests/bin/Debug/netcoreapp2.2", "example/Resources"); + + if(Directory.Exists(WorkingDir)) { + Directory.Delete(WorkingDir, true); + } + + DirectoryCopy(resources, WorkingDir, true); + + var dirs = new string[] {WorkingDir, ConvertDir}; + + MTTRunner.Program.StartService(dirs); + } + + [Test] + public void WorkingDirExists() + { + Assert.That(Directory.Exists(Path.Combine(CurrentDir, WorkingDir))); + } + + [Test] + public void ConvertDirExists() + { + Assert.That(Directory.Exists(Path.Combine(CurrentDir, ConvertDir))); + } + + [Test] + public void ConvertedFileExists() + { + Assert.That(File.Exists(VehicleFile)); + } + + [Test] + public void AutoGeneratedExists() { + string[] lines = System.IO.File.ReadAllLines(VehicleFile); + + Assert.That(lines[0], Is.EqualTo("/* Auto Generated */")); + } + + [Test] + public void DifferentDirImportStatementExists() { + string[] lines = System.IO.File.ReadAllLines(VehicleFile); + + Assert.That(lines[2], Is.EqualTo("import { Entity } from \"./../entity\"")); + } + + [Test] + public void SameDirImportStatementExists() { + string[] lines = System.IO.File.ReadAllLines(VehicleFile); + + Assert.That(lines[3], Is.EqualTo("import { VehicleState } from \"./vehicleState\"")); + } + + [Test] + public void ClassTransformationExists() { + string[] lines = System.IO.File.ReadAllLines(VehicleFile); + + Assert.That(lines[6], Is.EqualTo("export interface Vehicle extends Entity {")); + } + + [Test] + public void PropertyExists() { + string[] lines = System.IO.File.ReadAllLines(VehicleFile); + + Assert.That(lines[7], Is.EqualTo(" year: number;")); + } + + [Test] + public void OptionalPropertyExists() { + string[] lines = System.IO.File.ReadAllLines(VehicleFile); + + Assert.That(lines[10], Is.EqualTo(" mileage?: number;")); + } + + [Test] + public void EnumPropertyExists() { + string[] lines = System.IO.File.ReadAllLines(VehicleFile); + + Assert.That(lines[12], Is.EqualTo(" condition: VehicleState;")); + } + + [Test] + public void ArrayExists() { + string[] lines = System.IO.File.ReadAllLines(VehicleFile); + + Assert.That(lines[13], Is.EqualTo(" parts: Part[];")); + } + + [Test] + public void CommentsDoNotExist() { + string[] lines = System.IO.File.ReadAllLines(VehicleFile); + + foreach(string line in lines) { + Assert.That(line, Does.Not.Contain("//")); + } + } + + [Test] + public void PreprocessorDirectivesDoNotExist() { + string[] lines = System.IO.File.ReadAllLines(VehicleFile); + + foreach(string line in lines) { + Assert.That(line.IsNotPreProcessorDirective()); + } + } + + [Test] + public void UsingStatementDoesNotExist() { + string[] lines = System.IO.File.ReadAllLines(VehicleFile); + + foreach(string line in lines) { + Assert.That(line.DoesNotStrictContain("using")); + } + } + + [Test] + public void NamespaceStatementDoesNotExist() { + string[] lines = System.IO.File.ReadAllLines(VehicleFile); + + foreach(string line in lines) { + Assert.That(line.DoesNotStrictContain("namespace")); + } + } + + /** + + Helper Methods + + */ + private static void DirectoryCopy(string sourceDirName, string destDirName, bool copySubDirs) + { + // Get the subdirectories for the specified directory. + DirectoryInfo dir = new DirectoryInfo(sourceDirName); + + if (!dir.Exists) + { + throw new DirectoryNotFoundException( + "Source directory does not exist or could not be found: " + + sourceDirName); + } + + DirectoryInfo[] dirs = dir.GetDirectories(); + // If the destination directory doesn't exist, create it. + if (!Directory.Exists(destDirName)) + { + Directory.CreateDirectory(destDirName); + } + + // Get the files in the directory and copy them to the new location. + FileInfo[] files = dir.GetFiles(); + foreach (FileInfo file in files) + { + string temppath = Path.Combine(destDirName, file.Name); + file.CopyTo(temppath, false); + } + + // If copying subdirectories, copy them and their contents to new location. + if (copySubDirs) + { + foreach (DirectoryInfo subdir in dirs) + { + string temppath = Path.Combine(destDirName, subdir.Name); + DirectoryCopy(subdir.FullName, temppath, copySubDirs); + } + } + } + } +} + +public static class StringExtension + { + public static bool DoesNotStrictContain(this string str, string match) + { + string reg = "(^|\\s)" + match + "(\\s|$)"; + return !Regex.IsMatch(str, reg); + } + + public static bool IsNotPreProcessorDirective(this string str) + { + return !Regex.IsMatch(str, @"^#\w+"); + } + } \ No newline at end of file diff --git a/Source/MTTRunner/Program.cs b/Source/MTTRunner/Program.cs index e852f2a..7391c48 100644 --- a/Source/MTTRunner/Program.cs +++ b/Source/MTTRunner/Program.cs @@ -3,7 +3,7 @@ namespace MTTRunner { - class Program + public class Program { /// /// Defines the entry point of the application. @@ -13,19 +13,22 @@ static void Main(string[] args) { if (args.Length != 2) { - Console.WriteLine("Arguments should contain the ConvertDirectory and the WorkingDirectory"); - Console.ReadLine(); - return; + throw new Exception("Arguments should contain the ConvertDirectory and the WorkingDirectory"); } + Program.StartService(args); + } + + public static void StartService(string[] args) { var convertService = new ConvertService((logString, logArgs) => Console.WriteLine(logString, logArgs)) { - ConvertDirectory = args[0], - WorkingDirectory = args[1] + WorkingDirectory = args[0], + ConvertDirectory = args[1] }; + convertService.Execute(); - - Console.ReadLine(); } + + } } diff --git a/Source/MTTRunner/README.md b/Source/MTTRunner/README.md new file mode 100644 index 0000000..260f9aa --- /dev/null +++ b/Source/MTTRunner/README.md @@ -0,0 +1,9 @@ +# MTTRunner + +MTTRunner allows easier running and testing of MTT + +## Usage + +`dotnet run $INPUT $OUTPUT` + +Where `$INPUT` is the WorkingDirectory and `$OUTPUT` is the ConvertDirectory diff --git a/build.ps1 b/build.ps1 index 449c3d5..917f44b 100644 --- a/build.ps1 +++ b/build.ps1 @@ -12,6 +12,7 @@ Remove-Item artifacts/ -Recurse -ErrorAction Ignore Remove-Item Example/obj/ -Recurse -ErrorAction Ignore Remove-Item Source/MTT/obj/ -Recurse -ErrorAction Ignore +exec dotnet test exec dotnet restore ./Source/MTT/ exec dotnet pack -c Release ./Source/MTT/ exec dotnet restore ./Example/ diff --git a/build.sh b/build.sh index e446c07..dbb9426 100755 --- a/build.sh +++ b/build.sh @@ -27,6 +27,7 @@ else rm -rf Example/obj/ rm -rf Source/MTT/obj/ + __exec dotnet test __exec dotnet restore ./Source/MTT/ __exec dotnet pack -c Release ./Source/MTT/ __exec dotnet restore ./Example/