Created
August 17, 2011 06:51
-
-
Save Vidarls/1150968 to your computer and use it in GitHub Desktop.
Xunit support for approval tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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