Skip to content

Commit

Permalink
Merge pull request #25 from CodySchrank/mtt-tests
Browse files Browse the repository at this point in the history
Added foundation for testing
  • Loading branch information
CodySchrank authored Aug 8, 2019
2 parents 9592c3d + e2d3a2c commit aded608
Show file tree
Hide file tree
Showing 8 changed files with 314 additions and 8 deletions.
69 changes: 69 additions & 0 deletions MTT.sln
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions Source/MTTRunner.Tests/MTTRunner.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="nunit" Version="3.11.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.11.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\MTTRunner\MTTRunner.csproj" />
</ItemGroup>

</Project>
3 changes: 3 additions & 0 deletions Source/MTTRunner.Tests/README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Tests

Run with `dotnet test` in root folder
201 changes: 201 additions & 0 deletions Source/MTTRunner.Tests/UnitTest.cs
Original file line number Diff line number Diff line change
@@ -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+");
}
}
19 changes: 11 additions & 8 deletions Source/MTTRunner/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace MTTRunner
{
class Program
public class Program
{
/// <summary>
/// Defines the entry point of the application.
Expand All @@ -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();
}


}
}
9 changes: 9 additions & 0 deletions Source/MTTRunner/README.md
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
1 change: 1 addition & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down

0 comments on commit aded608

Please sign in to comment.