Files

49 lines
1.7 KiB
C#

using System;
using System.IO;
using System.Text.RegularExpressions;
using VerifyTests;
namespace Strata.DecisionSupport.Biz.Test.Unit
{
public static class TestExtensions
{
/// <summary>
/// The test name
/// </summary>
/// <param name="context"></param>
/// <returns>
/// The name of the test split by camel case for a max length of 200 characters.
/// </returns>
public static string TestName(this TestContext context)
{
var regexSpecial = new Regex($"[{Regex.Escape(new string(Path.GetInvalidFileNameChars()) + "<>")}]");
var testName = regexSpecial.Replace(context.Test.Name, "").SplitCamelCase();
testName = testName[..Math.Min(200, testName.Length)];
return testName;
}
public static string SplitCamelCase(this string input)
{
if (string.IsNullOrEmpty(input)) { return input; }
const string pattern = "([a-z](?=[A-Z])|[A-Z](?=[A-Z][a-r + t-z])|[A-Z](?=[A-Z][s][a-z]))";
if (input.StartsWith("FY", StringComparison.Ordinal))
{ // hack for FY2012, etc
return "FY " + Regex.Replace(input.Remove(0, 2), pattern, "$1 ");
}
input = Regex.Replace(input, @"\{|\}|:|,|\)|\(", "", RegexOptions.Singleline | RegexOptions.IgnoreCase);
return Regex.Replace(input, pattern, "$1 ");
}
public static VerifySettings TestSettings()
{
var settings = new VerifySettings();
settings.UseDirectory("snapshots");
settings.ScrubInlineGuids();
return settings;
}
}
}