public UnitTest(UnitTestInfo unitTestInfo, LinkerMethodInfo linkerMethodInfo) { UnitTestInfo = unitTestInfo; LinkerMethodInfo = linkerMethodInfo; Status = unitTestInfo.Skip ? UnitTestStatus.Skipped : UnitTestStatus.Pending; }
private static void GetExpectedResult(UnitTestInfo unitTest) { try { unitTest.Expected = unitTest.MethodInfo.Invoke(null, unitTest.Values); } catch (Exception e) { if (e.InnerException is DivideByZeroException || e.InnerException is OverflowException) { unitTest.Skip = true; } else { unitTest.Skip = true; } } }
public static List <UnitTestInfo> DiscoverUnitTests() { var unitTests = new List <UnitTestInfo>(); var assembly = typeof(MosaUnitTestAttribute).Assembly; var methods = assembly.GetTypes() .SelectMany(t => t.GetMethods()) .Where(m => m.GetCustomAttributes(typeof(MosaUnitTestAttribute), false).Length > 0) .ToArray(); foreach (var method in methods) { var fullMethodName = method.DeclaringType.FullName + "." + method.Name; foreach (var attribute in method.GetCustomAttributes <MosaUnitTestAttribute>()) { foreach (var paramValues in GetParameters(attribute)) { var unitTest = new UnitTestInfo() { MethodInfo = method, FullMethodName = fullMethodName, Values = paramValues, UnitTestAttribute = attribute, }; unitTests.Add(unitTest); GetExpectedResult(unitTest); } } } return(unitTests); }
public static LinkerMethodInfo GetMethodInfo(TypeSystem typeSystem, MosaLinker linker, UnitTestInfo unitTestInfo) { string fullMethodName = unitTestInfo.FullMethodName; int first = fullMethodName.LastIndexOf("."); int second = fullMethodName.LastIndexOf(".", first - 1); var methodNamespaceName = fullMethodName.Substring(0, second); var methodTypeName = fullMethodName.Substring(second + 1, first - second - 1); var methodName = fullMethodName.Substring(first + 1); var method = FindMosaMethod( typeSystem, methodNamespaceName, methodTypeName, methodName, unitTestInfo.Values); var address = GetMethodAddress(method, linker); var methodInfo = new LinkerMethodInfo { MethodNamespaceName = methodNamespaceName, MethodTypeName = methodTypeName, MethodName = methodName, MosaMethod = method, MosaMethodAddress = address }; return(methodInfo); }