本文整理汇总了C#中ITypeInfo.GetMethods方法的典型用法代码示例。如果您正苦于以下问题:C# ITypeInfo.GetMethods方法的具体用法?C# ITypeInfo.GetMethods怎么用?C# ITypeInfo.GetMethods使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITypeInfo
的用法示例。
在下文中一共展示了ITypeInfo.GetMethods方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindImpl
/// <summary>
/// Core implementation to discover unit tests in a given test class.
/// </summary>
/// <param name="type">The test class.</param>
/// <param name="includeSourceInformation">Set to <c>true</c> to attempt to include source information.</param>
/// <param name="messageBus">The message sink to send discovery messages to.</param>
/// <returns>Returns <c>true</c> if discovery should continue; <c>false</c> otherwise.</returns>
protected virtual bool FindImpl(ITypeInfo type, bool includeSourceInformation, IMessageBus messageBus)
{
string currentDirectory = Directory.GetCurrentDirectory();
var testCollection = TestCollectionFactory.Get(type);
try
{
if (!String.IsNullOrEmpty(assemblyInfo.AssemblyPath))
Directory.SetCurrentDirectory(Path.GetDirectoryName(assemblyInfo.AssemblyPath));
foreach (var method in type.GetMethods(includePrivateMethods: true))
{
var factAttribute = method.GetCustomAttributes(typeof(FactAttribute)).FirstOrDefault();
if (factAttribute != null)
{
var discovererAttribute = factAttribute.GetCustomAttributes(typeof(TestCaseDiscovererAttribute)).FirstOrDefault();
if (discovererAttribute != null)
{
var args = discovererAttribute.GetConstructorArguments().Cast<string>().ToList();
var discovererType = Reflector.GetType(args[1], args[0]);
if (discovererType != null)
{
var discoverer = GetDiscoverer(discovererType);
if (discoverer != null)
foreach (var testCase in discoverer.Discover(testCollection, assemblyInfo, type, method, factAttribute))
if (!messageBus.QueueMessage(new TestCaseDiscoveryMessage(UpdateTestCaseWithSourceInfo(testCase, includeSourceInformation))))
return false;
}
else
messageAggregator.Add(new EnvironmentalWarning { Message = String.Format("Could not create discoverer type '{0}, {1}'", args[0], args[1]) });
}
}
}
}
catch (Exception ex)
{
messageAggregator.Add(new EnvironmentalWarning { Message = String.Format("Exception during discovery:{0}{1}", Environment.NewLine, ex) });
}
finally
{
Directory.SetCurrentDirectory(currentDirectory);
}
return true;
}
示例2: FindImpl
/// <summary>
/// Core implementation to discover unit tests in a given test class.
/// </summary>
/// <param name="type">The test class.</param>
/// <param name="includeSourceInformation">Set to <c>true</c> to attempt to include source information.</param>
/// <param name="messageSink">The message sink to send discovery messages to.</param>
/// <returns>Returns <c>true</c> if discovery should continue; <c>false</c> otherwise.</returns>
protected virtual bool FindImpl(ITypeInfo type, bool includeSourceInformation, IMessageSink messageSink)
{
string currentDirectory = Directory.GetCurrentDirectory();
var testCollection = TestCollectionFactory.Get(type);
try
{
if (!String.IsNullOrEmpty(assemblyInfo.AssemblyPath))
Directory.SetCurrentDirectory(Path.GetDirectoryName(assemblyInfo.AssemblyPath));
foreach (IMethodInfo method in type.GetMethods(includePrivateMethods: true))
{
IAttributeInfo factAttribute = method.GetCustomAttributes(typeof(FactAttribute)).FirstOrDefault();
if (factAttribute != null)
{
IAttributeInfo discovererAttribute = factAttribute.GetCustomAttributes(typeof(XunitDiscovererAttribute)).FirstOrDefault();
if (discovererAttribute != null)
{
var args = discovererAttribute.GetConstructorArguments().Cast<string>().ToList();
var discovererType = Reflector.GetType(args[1], args[0]);
if (discovererType != null)
{
IXunitDiscoverer discoverer = (IXunitDiscoverer)Activator.CreateInstance(discovererType);
foreach (XunitTestCase testCase in discoverer.Discover(testCollection, assemblyInfo, type, method, factAttribute))
if (!messageSink.OnMessage(new TestCaseDiscoveryMessage(UpdateTestCaseWithSourceInfo(testCase, includeSourceInformation))))
return false;
}
// TODO: Figure out a way to report back an error when discovererType is not available
// TODO: What if the discovererType can't be created or cast to IXunitDiscoverer?
// TODO: Performance optimization: cache instances of the discoverer type
}
}
}
return true;
}
finally
{
Directory.SetCurrentDirectory(currentDirectory);
}
}
示例3: FindTestsForType
/// <inheritdoc/>
protected override bool FindTestsForType(ITypeInfo type, bool includeSourceInformation, IMessageBus messageBus)
{
var testCollection = TestCollectionFactory.Get(type);
foreach (var method in type.GetMethods(includePrivateMethods: true))
if (!FindTestsForMethod(testCollection, type, method, includeSourceInformation, messageBus))
return false;
return true;
}
示例4: GetTestMethods
/// <summary>
/// Retrieves a list of the test methods from the test class.
/// </summary>
/// <param name="type">The type to be inspected</param>
/// <returns>The test methods</returns>
public static IEnumerable<IMethodInfo> GetTestMethods(ITypeInfo type)
{
foreach (IMethodInfo method in type.GetMethods())
if (MethodUtility.IsTest(method))
yield return method;
}
示例5: CreateTypeTest
private MSTest CreateTypeTest(ITypeInfo typeInfo)
{
MSTest typeTest = new MSTest(typeInfo.Name, typeInfo);
typeTest.Kind = TestKinds.Fixture;
foreach (IMethodInfo method in typeInfo.GetMethods(BindingFlags.Public | BindingFlags.Instance))
{
IEnumerable<IAttributeInfo> methodAttributes = method.GetAttributeInfos(null, true);
foreach (IAttributeInfo methodAttribute in methodAttributes)
{
if (methodAttribute.Type.FullName.CompareTo(MSTestAttributes.TestMethodAttribute) == 0)
{
try
{
MSTest testMethod = CreateMethodTest(typeInfo, method);
typeTest.AddChild(testMethod);
}
catch (Exception ex)
{
TestModel.AddAnnotation(new Annotation(AnnotationType.Error, method, "An exception was thrown while exploring an MSTest test method.", ex));
}
break;
}
}
}
PopulateTestClassMetadata(typeInfo, typeTest);
// Add XML documentation.
string xmlDocumentation = typeInfo.GetXmlDocumentation();
if (xmlDocumentation != null)
typeTest.Metadata.SetValue(MetadataKeys.XmlDocumentation, xmlDocumentation);
return typeTest;
}