mirror of
https://github.com/mRemoteNG/mRemoteNG.git
synced 2026-02-25 19:38:37 +08:00
When multiple builds had to run, these tests would sometimes fail due to the file system being a shared resource. Each test now creates its own random folder and cleans it up after the test runs
39 lines
1.2 KiB
C#
39 lines
1.2 KiB
C#
using System.IO;
|
|
|
|
namespace mRemoteNGTests.TestHelpers
|
|
{
|
|
public class FileTestHelpers
|
|
{
|
|
public static void DeleteTestFile(string path)
|
|
{
|
|
if (File.Exists(path))
|
|
File.Delete(path);
|
|
}
|
|
|
|
public static void DeleteFilesInDirectory(string directory, string fileMatching)
|
|
{
|
|
var filesToDelete = Directory.GetFiles(directory, fileMatching, SearchOption.TopDirectoryOnly);
|
|
foreach (var file in filesToDelete)
|
|
if (File.Exists(file))
|
|
File.Delete(file);
|
|
}
|
|
|
|
public static string NewTempFilePath()
|
|
{
|
|
var newPath = Path.Combine(GetTestSpecificTempDirectory(), Path.GetRandomFileName());
|
|
var folderPath = Path.GetDirectoryName(newPath);
|
|
if (!Directory.Exists(folderPath))
|
|
Directory.CreateDirectory(folderPath);
|
|
return newPath;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets a testing directory that should be unique for a
|
|
/// particular mRemoteNG test.
|
|
/// </summary>
|
|
public static string GetTestSpecificTempDirectory()
|
|
{
|
|
return Path.Combine(Path.GetTempPath(), "mRemoteNGTests", Path.GetRandomFileName());
|
|
}
|
|
}
|
|
} |