From 17e8abf8bd48df10a15465ba97475f9e40b1472a Mon Sep 17 00:00:00 2001 From: stewartgordonsitka Date: Tue, 10 Aug 2021 10:12:04 -0700 Subject: [PATCH] Adding unit tests for typescript property and enum names --- Source/MTTRunner.Tests/UnitTest.cs | 28 +++++++++++++++++++++++++++- Source/MTTRunner/Program.cs | 5 +++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/Source/MTTRunner.Tests/UnitTest.cs b/Source/MTTRunner.Tests/UnitTest.cs index 4f4c36d..d9bdfde 100644 --- a/Source/MTTRunner.Tests/UnitTest.cs +++ b/Source/MTTRunner.Tests/UnitTest.cs @@ -3,6 +3,7 @@ using System.IO; using System; using System.Text.RegularExpressions; +using MTT; namespace MTTRunner.Tests { @@ -11,14 +12,19 @@ public class BasicTests private readonly string CurrentDir = Directory.GetCurrentDirectory().Replace("\\", "/"); private readonly string WorkingDir = "workingDir/"; private readonly string ConvertDir = "convertDir/"; + private readonly string ConvertDirPascal = "convertDirPascal/"; private string VehicleFile; + private string VehicleFilePascal; private string VehicleStateFile; + private string VehicleStateFilePascal; [SetUp] public void Setup() { VehicleFile = Path.Combine(CurrentDir, ConvertDir, "Vehicles/vehicle.ts"); VehicleStateFile = Path.Combine(CurrentDir, ConvertDir, "Vehicles/vehicleState.ts"); + VehicleFilePascal = Path.Combine(CurrentDir, ConvertDirPascal, "Vehicles/vehicle.ts"); + VehicleStateFilePascal = Path.Combine(CurrentDir, ConvertDirPascal, "Vehicles/vehicleState.ts"); var resources = CurrentDir.Replace("Source/MTTRunner.Tests/bin/Debug/netcoreapp3.1", "example/Resources"); @@ -32,9 +38,13 @@ public void Setup() DirectoryCopy(resources, WorkingDir, true); + // Start service for standard tests var dirs = new string[] {WorkingDir, ConvertDir}; - MTTRunner.Program.StartService(dirs); + + // Start service for testing Pascal casing + var pascalCaseDirs = new string[] {WorkingDir, ConvertDirPascal}; + MTTRunner.Program.StartService(pascalCaseDirs, PropertyStyle.PascalCase); } [Test] @@ -90,6 +100,14 @@ public void PropertyExists() { Assert.That(lines[8], Is.EqualTo(" year: number;")); } + [Test] + public void PropertyExistsWithPascalCase() + { + string[] lines = System.IO.File.ReadAllLines(VehicleFilePascal); + + Assert.That(lines[8], Is.EqualTo(" Year: number;")); + } + [Test] public void OptionalPropertyExists() { string[] lines = System.IO.File.ReadAllLines(VehicleFile); @@ -191,6 +209,14 @@ public void EnumPropertyWithValueExists() { Assert.That(lines[3], Is.EqualTo(" broken = 1,")); } + [Test] + public void PascalEnumPropertyWithValueExists() + { + string[] lines = System.IO.File.ReadAllLines(VehicleStateFilePascal); + + Assert.That(lines[3], Is.EqualTo(" Broken = 1,")); + } + [Test] public void EnumPropertyWithoutValueExists() { string[] lines = System.IO.File.ReadAllLines(VehicleStateFile); diff --git a/Source/MTTRunner/Program.cs b/Source/MTTRunner/Program.cs index 19d0f13..d8590c6 100644 --- a/Source/MTTRunner/Program.cs +++ b/Source/MTTRunner/Program.cs @@ -25,11 +25,12 @@ static void Main(string[] args) Program.StartService(args); } - public static void StartService(string[] args) { + public static void StartService(string[] args, PropertyStyle propertyStyle = PropertyStyle.CamelCase) { var convertService = new ConvertService((logString, logArgs) => Console.WriteLine(logString, logArgs)) { WorkingDirectory = args[0], - ConvertDirectory = args[1] + ConvertDirectory = args[1], + PropertyStyle = propertyStyle }; convertService.Execute();