8,497
社区成员
发帖
与我相关
我的任务
分享
public class TestRunner
{
private List<Assembly> _assemblies = new List<Assembly>();
private List<Pair> _TestProcs = null;
/// <summary>
/// 从测试程序集中找出的测试用例。可以通过修改此集合内容自定义测试用例。
/// </summary>
public List<Pair> TestProcs
{
get
{
if (_TestProcs == null)
{
_TestProcs = new List<Pair>();
_assemblies.ForEach(asm =>
asm.GetTypes()
.ForEach(t => t.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static)
.Where(m => m.ReturnParameter.ParameterType == typeof(void) && m.GetParameters().Length == 0)
.ForEach(m =>
{
var att = m.GetCustomAttributes(typeof(RunTestAttribute), false);
if (att.Length != 0)
{
RunTestAttribute attr = att[0] as RunTestAttribute;
if (attr.TimeStamp >= this.MinTime && attr.TimeStamp <= this.MaxTime)
for (var n = 0; n < attr.实例数 * this.FuckTimes; n++)
TestProcs.Add(new Pair()
{
Proc = (ThreadStart)Delegate.CreateDelegate(typeof(ThreadStart), m),
Attr = attr
});
}
})));
}
return _TestProcs;
}
}
public TestRunner()
{
var thisAsmName = Assembly.GetExecutingAssembly().GetName().Name;
AppDomain.CurrentDomain.GetAssemblies()
.Where(asm => asm.GetReferencedAssemblies().Any(a => a.Name == thisAsmName))
.ForEach(asm => _assemblies.Add(asm));
}
.................
static public void ForEach<T>(this IEnumerable<T> array, Action<T> action)
{
foreach (T x in array)
{
action(x); ;
}
}