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); } } }