Skip to content

Instantly share code, notes, and snippets.

@gasparnagy
Last active January 3, 2016 21:18
Show Gist options
  • Save gasparnagy/8520497 to your computer and use it in GitHub Desktop.
Save gasparnagy/8520497 to your computer and use it in GitHub Desktop.
Simple helper method that I use in integration tests to have more consistent notion and implementation of the different test folders.
using System;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
namespace TechTalk.SpecRun.Helpers
{
internal static class TestFolders
{
public static readonly string UniqueId = DateTime.Now.ToString("s", CultureInfo.InvariantCulture).Replace(":", "");
public static string InputFolder
{
get { return Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath); }
}
public static string OutputFolder
{
//a simple solution that puts everyting to the output folder directly would look like this:
//get { return Directory.GetCurrentDirectory(); }
get
{
var outputFolder = Path.Combine(Directory.GetCurrentDirectory(), UniqueId);
if (!Directory.Exists(outputFolder))
Directory.CreateDirectory(outputFolder);
return outputFolder;
}
}
public static string TempFolder
{
get { return Path.GetTempPath(); }
}
// very simple helper methods that can improve the test code readability
public static string GetInputFilePath(string fileName)
{
return Path.GetFullPath(Path.Combine(InputFolder, fileName));
}
public static string GetOutputFilePath(string fileName)
{
return Path.GetFullPath(Path.Combine(OutputFolder, fileName));
}
public static string GetTempFilePath(string fileName)
{
return Path.GetFullPath(Path.Combine(TempFolder, fileName));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment