-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
TestBase.cs
55 lines (50 loc) · 1.41 KB
/
TestBase.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Linq;
using VW;
using System.Text.RegularExpressions;
using System.Runtime.InteropServices;
using System.Diagnostics;
namespace cs_unittest
{
[TestClass]
public abstract class TestBase : IDisposable
{
public TestBase()
{
this.Init();
}
[TestInitialize]
public void Init()
{
// CMake will copy test files to a "test" sub-directory of the binary output directory
var basePath = Path.GetDirectoryName(typeof(TestBase).Assembly.Location);
#if NETCOREAPP3_0_OR_GREATER
var testPath = Path.Join(basePath, "test");
#else
var testPath = basePath + @"\test";
#endif
Debug.Assert(Directory.Exists(testPath), $"Could not find directory: {testPath}");
Environment.CurrentDirectory = testPath;
if (!Directory.Exists("models"))
{
Directory.CreateDirectory("models");
}
}
public void Dispose()
{
try
{
if (Directory.Exists("models"))
{
Directory.Delete("models", true);
}
}
catch (Exception ex)
{
Console.WriteLine("Failed to delete model directory: "+ex.Message);
}
}
}
}