Skip to content

Commit

Permalink
Fixing the problems with the test of the Applications
Browse files Browse the repository at this point in the history
  • Loading branch information
Baudin999 committed Dec 23, 2019
1 parent 6c2ae5c commit 3f54b57
Show file tree
Hide file tree
Showing 39 changed files with 747 additions and 426 deletions.
5 changes: 5 additions & 0 deletions ApplicationTests/ApplicationTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,9 @@
<ItemGroup>
<Folder Include="CSharp\" />
</ItemGroup>
<ItemGroup>
<None Update="xunit.runner.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
41 changes: 41 additions & 0 deletions ApplicationTests/BaseApplicationTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.IO;
using System.Threading.Tasks;
using Project;
using Xunit.Abstractions;

namespace ApplicationTests
{
public class BaseFileWatcherTest : IDisposable
{
protected readonly ITestOutputHelper output;
protected readonly string dir;
protected readonly FileProject project;

public BaseFileWatcherTest(ITestOutputHelper _output, string _dir)
{
dir = Path.GetFullPath(_dir, Directory.GetCurrentDirectory());
Console.WriteLine("STARTING: " + dir);
if (Directory.Exists(dir))
{
Directory.Delete(dir, true);
}
Directory.CreateDirectory(dir);
output = _output;
project = new FileProject(dir);
project.Watch();
}

public void Dispose()
{
project.Dispose();
Directory.Delete(dir, true);
Console.WriteLine("CLEANUP: " + dir);
}

protected string path(string add)
{
return Path.GetFullPath(add, dir);
}
}
}
51 changes: 15 additions & 36 deletions ApplicationTests/CreateModuleInProject.cs
Original file line number Diff line number Diff line change
@@ -1,54 +1,33 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using CLI;
using Project;
using Xunit;
using Xunit.Abstractions;

namespace ApplicationTests
{
public class CreateModuleInProject: IDisposable
public class CreateModuleInProject : BaseFileWatcherTest
{
readonly string dir = Path.GetFullPath("CreateModuleInProject", Directory.GetCurrentDirectory());
readonly Project project;
public CreateModuleInProject()
public CreateModuleInProject(ITestOutputHelper output) : base(output, "CreateModuleInProject") { }

[Fact]
public async Task CreateModule()
{
try
{
Directory.Delete(dir, true);
var module = await project.CreateModule("Test");
Assert.True(File.Exists(path("Test.car")));
Assert.NotNull(module);
Assert.Equal("Test", module.Name);
Assert.Equal(this.path("Test.car"), module.FilePath);
}
catch (Exception)
catch (Exception ex)
{
Debug.WriteLine("Delete Directory failed in unit test.");
Console.WriteLine(dir + ": " + ex.Message);
}
Directory.CreateDirectory(dir);
project = new Project(dir);
}

[Fact]
public void CreateModule()
{
project.CreateModule("Test");
Assert.True(File.Exists(path("Test.car")));

/*
* Modules are not automatically parsed and added to the project
* when they are created. This gives you the option of using the
* CLI as a very very simple "build my files" type of solution.
*/
var module = project.FindModule("Test");
Assert.Null(module);
}


public void Dispose()
{
project.Dispose();
//Directory.Delete(dir, true);
}

private string path(string add)
{
return Path.GetFullPath(add, dir);
}
}
}
42 changes: 42 additions & 0 deletions ApplicationTests/DeleteModuleInproject.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using CLI;
using Project;
using Xunit;
using Xunit.Abstractions;

namespace ApplicationTests
{
public class DeleteModuleInproject : BaseFileWatcherTest
{
public DeleteModuleInproject(ITestOutputHelper output) : base(output, "DeleteModuleInproject") { }

[Fact]
public async Task CreateModule()
{
try
{
var module = await project.CreateModule("Test");
var filePath = module.FilePath.Clone().ToString();
var outPath = module.OutPath.Clone().ToString();

Assert.True(File.Exists(path("Test.car")));
Assert.NotNull(module);
Assert.Equal("Test", module.Name);
Assert.Equal(this.path("Test.car"), module.FilePath);

var deleteResult = await project.DeleteModule("Test");

await Task.Delay(100);
Assert.True(deleteResult);
Assert.False(File.Exists(filePath));
Assert.False(Directory.Exists(outPath));
} catch (Exception ex)
{
Console.WriteLine(dir + ": " + ex.Message);
}
}
}
}
4 changes: 3 additions & 1 deletion ApplicationTests/ModuleStream_tests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using System.Threading.Tasks;
using CLI;
using Project;
using Xunit;

namespace ApplicationTests
Expand All @@ -12,6 +12,7 @@ public class ModuleStream_tests : IDisposable

public ModuleStream_tests()
{
Console.WriteLine("STARTING: ModuleStream");
moduleStream = new ModuleStream();
}

Expand All @@ -37,6 +38,7 @@ public Task CreateModuleStream()
public void Dispose()
{
moduleStream.Dispose();
Console.WriteLine("CLEANUP: ModuleStream");
}
}
}
35 changes: 35 additions & 0 deletions ApplicationTests/MoveModuleInProject.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using System.IO;
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;

namespace ApplicationTests
{
public class MoveModuleInProject : BaseFileWatcherTest
{
public MoveModuleInProject(ITestOutputHelper output) : base(output, "MoveModuleInProject") { }

[Fact]
public async Task MoveModule()
{
try
{
var module = await project.CreateModule("Test");
Assert.True(File.Exists(path("Test.car")));
Assert.NotNull(module);
Assert.Equal("Test", module.Name);
Assert.Equal(this.path("Test.car"), module.FilePath);

var newModule = await project.MoveModule(module.Name, "Other");
var oldModule = project.FindModule("Test");
Assert.Null(oldModule);
Assert.NotNull(newModule);
}
catch (Exception ex)
{
Console.WriteLine(dir + ": " + ex.Message);
}
}
}
}
58 changes: 20 additions & 38 deletions ApplicationTests/ParseMultipleFiles.cs
Original file line number Diff line number Diff line change
@@ -1,60 +1,42 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using CLI;
using Project;
using Xunit;
using Xunit.Abstractions;

namespace ApplicationTests
{
public class ParseMultipleFiles : IDisposable
public class ParseMultipleFiles : BaseFileWatcherTest
{

private readonly string dir = Path.GetFullPath("ParseMultipleFiles", Directory.GetCurrentDirectory());
private readonly Project project;
public ParseMultipleFiles()

public ParseMultipleFiles(ITestOutputHelper output) : base(output, "ParseMultipleFiles") { }

[Fact]
public async Task Execute()
{
try
{
Directory.Delete(dir, true);
} catch (Exception) {
Debug.WriteLine("Delete Directory failed in unit test.");
}
Directory.CreateDirectory(dir);
File.WriteAllText(path("First.car"), @"# The first document
var tasks = new List<Task>();
tasks.Add(project.CreateModule("First", @"# The first document
type Person
");
File.WriteAllText(path("Second.car"), @"
"));
tasks.Add(project.CreateModule("Second", @"
open Person
# The second document
type School
");

project = new Project(dir);
}

[Fact]
#pragma warning disable IDE0051 // Remove unused private members
private void CreateModule()
#pragma warning restore IDE0051 // Remove unused private members
{
Assert.Equal(2, project.Modules.Count);
var second = project.FindModule("Second");
Assert.Equal(3, second.Generator.AST.Count);
}


public void Dispose()
{
project.Dispose();
Directory.Delete(dir, true);
"));
await Task.WhenAll(tasks.ToArray());
Assert.Equal(2, project.Modules.Count);
}
catch (Exception ex)
{
Console.WriteLine(dir + ": " + ex.Message);
}
}

private string path(string add)
{
return Path.GetFullPath(add, dir);
}
}
}
51 changes: 12 additions & 39 deletions ApplicationTests/ProjectFileWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,56 +3,29 @@
using System.IO;
using System.Threading.Tasks;
using CLI;
using Project;
using Xunit;
using Xunit.Abstractions;

namespace ApplicationTests
{
public class ProjectFileWatcher: IDisposable
public class ProjectFileWatcher : BaseFileWatcherTest
{
private readonly ITestOutputHelper output;
private readonly string dir = Path.GetFullPath("ProjectFileWatcher", Directory.GetCurrentDirectory());
private readonly Project project;
public ProjectFileWatcher(ITestOutputHelper output)

public ProjectFileWatcher(ITestOutputHelper output) : base(output, "ProjectFileWatcher") { }

[Fact]
public async Task CreateModule()
{
try
{
Directory.Delete(dir, true);
} catch (Exception) {
Debug.WriteLine("Delete Directory failed in unit test.");
await project.CreateModule("Test");
Assert.True(File.Exists(path("Test.car")));
}
Directory.CreateDirectory(dir);

this.output = output;
project = new Project(dir);
Task.Run(() =>
catch (Exception ex)
{
project.Watch();
});


}

[Fact]
#pragma warning disable IDE0051 // Remove unused private members
private void CreateModule()
#pragma warning restore IDE0051 // Remove unused private members
{
project.CreateModule("Test");
Assert.True(File.Exists(path("Test.car")));
}


public void Dispose()
{
output.WriteLine("q");
project.Dispose();
Directory.Delete(dir, true);
}

private string path(string add)
{
return Path.GetFullPath(add, dir);
Console.WriteLine(dir + ": " + ex.Message);
}
}
}
}
Loading

0 comments on commit 3f54b57

Please sign in to comment.