2019-11-08 02:31:44 +01:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Test.Loader
|
|
|
|
|
|
{
|
|
|
|
|
|
public class TestUtils
|
|
|
|
|
|
{
|
|
|
|
|
|
private static string solutionDir;
|
|
|
|
|
|
private static string executableDir;
|
|
|
|
|
|
|
|
|
|
|
|
#region DeploymentItem()
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2022-11-29 18:21:52 +01:00
|
|
|
|
/// Replacement for [DeploymentItemAttribute], which doesn't work with VS2010 + ReSharper
|
2019-11-08 02:31:44 +01:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static string DeploymentItem(string file)
|
|
|
|
|
|
{
|
|
|
|
|
|
GetSolutionBaseDir();
|
|
|
|
|
|
GetExecutableDir();
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-01-09 12:06:32 +01:00
|
|
|
|
var src = Path.Combine(solutionDir, file);
|
|
|
|
|
|
var dest = Path.Combine(executableDir, Path.GetFileName(file));
|
|
|
|
|
|
if (Directory.Exists(src))
|
|
|
|
|
|
DeployRecursively(src, dest);
|
|
|
|
|
|
else
|
|
|
|
|
|
File.Copy(src, dest, true);
|
|
|
|
|
|
return dest;
|
2019-11-08 02:31:44 +01:00
|
|
|
|
}
|
2021-01-09 12:06:32 +01:00
|
|
|
|
|
|
|
|
|
|
private static void DeployRecursively(string src, string dest)
|
|
|
|
|
|
{
|
2021-03-14 22:13:22 +01:00
|
|
|
|
Directory.CreateDirectory(dest);
|
2021-01-09 12:06:32 +01:00
|
|
|
|
foreach(var file in Directory.GetFiles(src))
|
|
|
|
|
|
File.Copy(file, Path.Combine(dest, Path.GetFileName(file)), true);
|
|
|
|
|
|
foreach(var subdir in Directory.GetDirectories(src))
|
|
|
|
|
|
DeployRecursively(subdir, Path.Combine(dest, Path.GetFileName(subdir)));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-11-08 02:31:44 +01:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region GetSolutionBaseDir()
|
|
|
|
|
|
public static string GetSolutionBaseDir()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (solutionDir != null)
|
|
|
|
|
|
return solutionDir;
|
|
|
|
|
|
|
|
|
|
|
|
var dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
|
|
|
|
|
do
|
|
|
|
|
|
{
|
|
|
|
|
|
if (File.Exists(dir + "\\ChanSort.sln"))
|
|
|
|
|
|
return solutionDir = dir;
|
|
|
|
|
|
dir = Path.GetDirectoryName(dir);
|
|
|
|
|
|
} while (!string.IsNullOrEmpty(dir));
|
|
|
|
|
|
|
|
|
|
|
|
dir = Environment.CurrentDirectory;
|
|
|
|
|
|
do
|
|
|
|
|
|
{
|
|
|
|
|
|
if (File.Exists(dir + "\\ChanSort.sln"))
|
|
|
|
|
|
return solutionDir = dir;
|
|
|
|
|
|
dir = Path.GetDirectoryName(dir);
|
|
|
|
|
|
} while (!string.IsNullOrEmpty(dir));
|
|
|
|
|
|
|
|
|
|
|
|
throw new InvalidOperationException("Cannot determine base directory of ChanSort solution");
|
|
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region GetExecutableDir()
|
|
|
|
|
|
public static string GetExecutableDir()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (executableDir == null)
|
|
|
|
|
|
executableDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
|
|
|
|
|
return executableDir;
|
|
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|