Skip to content

Commit

Permalink
Adding unit tests for typescript property and enum names
Browse files Browse the repository at this point in the history
  • Loading branch information
stewartgordonsitka committed Aug 10, 2021
1 parent 6c83049 commit 17e8abf
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
28 changes: 27 additions & 1 deletion Source/MTTRunner.Tests/UnitTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.IO;
using System;
using System.Text.RegularExpressions;
using MTT;

namespace MTTRunner.Tests
{
Expand All @@ -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");

Expand All @@ -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]
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions Source/MTTRunner/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 17e8abf

Please sign in to comment.