Skip to content

Instantly share code, notes, and snippets.

@Vidarls
Created August 17, 2011 06:51
Show Gist options
  • Save Vidarls/1150968 to your computer and use it in GitHub Desktop.
Save Vidarls/1150968 to your computer and use it in GitHub Desktop.
Xunit support for approval tests
namespace ApprovalTests.StackTraceParsers
{
public class StackTraceParser : IStackTraceParser
{
private static IStackTraceParser[] parsers;
private IStackTraceParser parser;
public bool Parse(StackTrace stackTrace)
{
foreach (IStackTraceParser p in getParsers())
{
if (p.Parse(stackTrace))
{
parser = p;
return true;
}
}
throw new Exception(string.Format("Could Find Namer for {0}", stackTrace));
}
public string ApprovalName
{
get { return parser.ApprovalName; }
}
public string SourcePath
{
get { return parser.SourcePath; }
}
private static void LoadIfApplicable(List<IStackTraceParser> found, AttributeStackTraceParser p)
{
if (p.IsApplicable())
{
found.Add(p);
}
}
private IStackTraceParser[] getParsers()
{
if (parsers == null)
{
var found = new List<IStackTraceParser>();
LoadIfApplicable(found, new NUnitStackTraceParser());
LoadIfApplicable(found, new VSStackTraceParser());
LoadIfApplicable(found, new MbUnitStackTraceParser());
LoadIfApplicable(found, new XUnitStackTraceParser());
parsers = found.ToArray();
}
return parsers;
}
}
}
using System;
namespace ApprovalTests.StackTraceParsers
{
public class XUnitStackTraceParser : AttributeStackTraceParser
{
protected override string GetAttributeType()
{
return "Xunit.FactAttribute";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment