-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from CodySchrank/mtt-tests
Added foundation for testing
- Loading branch information
Showing
8 changed files
with
314 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Tests | ||
|
||
Run with `dotnet test` in root folder |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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+"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters