-
-
Notifications
You must be signed in to change notification settings - Fork 164
Expand file tree
/
Copy pathTestBase.cs
More file actions
42 lines (37 loc) · 1.23 KB
/
TestBase.cs
File metadata and controls
42 lines (37 loc) · 1.23 KB
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
using System;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
namespace GeoJSON.Net.Tests
{
public abstract class TestBase
{
private static readonly Assembly ThisAssembly = typeof(TestBase)
#if NETCOREAPP1_1
.GetTypeInfo()
#endif
.Assembly;
private static readonly string AssemblyName = ThisAssembly.GetName().Name;
public static string AssemblyDirectory
{
get
{
string codeBase = ThisAssembly.CodeBase;
UriBuilder uri = new UriBuilder(codeBase);
string path = Uri.UnescapeDataString(uri.Path);
return Path.GetDirectoryName(path);
}
}
protected string GetExpectedJson([CallerMemberName] string name = null)
{
var type = GetType().Name;
var projectFolder = GetType().Namespace.Substring(AssemblyName.Length + 1);
var path = Path.Combine(AssemblyDirectory, @"./", projectFolder, type + "_" + name + ".json");
if (!File.Exists(path))
{
throw new FileNotFoundException("file not found at " + path);
}
return File.ReadAllText(path);
}
}
}