53 lines
1.8 KiB
C#
53 lines
1.8 KiB
C#
using NUnit.Framework;
|
|
using System;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
using System.Text.RegularExpressions;
|
|
using VerifyTests;
|
|
|
|
namespace Strata.RxNorm.Biz.Test.Unit.Extensions
|
|
{
|
|
[ExcludeFromCodeCoverage]
|
|
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, string suffix = "")
|
|
{
|
|
var testName = context.Test.Name.Replace("\"", "_");
|
|
testName = suffix == string.Empty
|
|
? $"{testName}".SplitCamelCase()
|
|
: $"{testName} - {suffix}".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;
|
|
}
|
|
|
|
}
|
|
}
|