Skip to content

Commit

Permalink
added basic unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
CodySchrank committed Aug 8, 2019
1 parent d710d92 commit e2d3a2c
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 13 deletions.
137 changes: 124 additions & 13 deletions Source/MTTRunner.Tests/UnitTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@
using MTTRunner;
using System.IO;
using System;
using System.Text.RegularExpressions;

namespace MTTRunner.Tests
{
public class BasicTests
{
private readonly string CurrentDir = Directory.GetCurrentDirectory();
private readonly string CurrentDir = Directory.GetCurrentDirectory().Replace("\\", "/");
private readonly string WorkingDir = "workingDir/";
private readonly string ConvertDir = "convertDir/";
private string VehicleFile;

[SetUp]
public void Setup()
{
var resources = CurrentDir.Replace("\\", "/").Replace("Source/MTTRunner.Tests/bin/Debug/netcoreapp2.2", "example/Resources");
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);
Expand All @@ -30,25 +34,118 @@ public void Setup()
[Test]
public void WorkingDirExists()
{
if(Directory.Exists(Path.Combine(CurrentDir, WorkingDir))) {
Assert.Pass();
} else {
Assert.Fail();
}

Assert.That(Directory.Exists(Path.Combine(CurrentDir, WorkingDir)));
}

[Test]
public void ConvertDirExists()
{
if(Directory.Exists(Path.Combine(CurrentDir, ConvertDir))) {
Assert.Pass();
} else {
Assert.Fail();
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.
Expand Down Expand Up @@ -87,4 +184,18 @@ private static void DirectoryCopy(string sourceDirName, string destDirName, bool
}
}
}
}
}

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+");
}
}
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 e2d3a2c

Please sign in to comment.