本文整理汇总了C#中IMethodInfo类的典型用法代码示例。如果您正苦于以下问题:C# IMethodInfo类的具体用法?C# IMethodInfo怎么用?C# IMethodInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IMethodInfo类属于命名空间,在下文中一共展示了IMethodInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MethodTokenExpression
public MethodTokenExpression(IMethodInfo method)
{
this.method = method;
#if !MONO
declaringType = method.DeclaringType;
#endif
}
示例2: EnumerateTestCommands
protected override IEnumerable<ITestCommand> EnumerateTestCommands(IMethodInfo method)
{
if (method == null)
{
return new[] { new ExceptionCommand(new MethodCall(method), new ArgumentNullException("method")) };
}
IEnumerable<ITestCommand> backgroundCommands;
IEnumerable<ICommand> scenarioCommands;
// NOTE: any exception must be wrapped in a command, otherwise the test runner will retry this method infinitely
try
{
backgroundCommands = this.EnumerateBackgroundCommands(method).ToArray();
scenarioCommands = this.EnumerateScenarioCommands(method).ToArray();
}
catch (Exception ex)
{
return new[] { new ExceptionCommand(new MethodCall(method), ex) };
}
// NOTE: this is not in the try catch since we are yielding internally
// TODO: address this - see http://stackoverflow.com/a/346772/49241
return scenarioCommands.SelectMany(
scenarioCommand => CurrentScenario.ExtractCommands(scenarioCommand.MethodCall, backgroundCommands.Concat(new[] { scenarioCommand })));
}
示例3: TestMethod
/// <summary>
/// Initializes a new instance of the <see cref="TestMethod"/> class.
/// </summary>
/// <param name="method">The method to be used as a test.</param>
/// <param name="parentSuite">The suite or fixture to which the new test will be added</param>
public TestMethod(IMethodInfo method, Test parentSuite) : base(method )
{
// Needed to give proper fullname to test in a parameterized fixture.
// Without this, the arguments to the fixture are not included.
if (parentSuite != null)
FullName = parentSuite.FullName + "." + Name;
}
示例4: CreateTestCommands
public IEnumerable<ITestCommand> CreateTestCommands(IMethodInfo testMethod, IFixtureSet fixtureSet)
{
foreach (var command in MethodUtility.GetTestCommands(testMethod))
{
yield return new ParadigmTestCommand(testMethod, fixtureSet.ApplyFixturesToCommand(command), GetNameFor(command), new ConstructorInvokingObjectFactory(_testClassType.Type, _parameters.Select(x => x.Value).ToArray()));
}
}
示例5: DecorateContainingScope
/// <inheritdoc />
protected override void DecorateContainingScope(IPatternScope containingScope, IMethodInfo methodInfo)
{
Type formattableType = methodInfo.Parameters[0].Resolve(true).ParameterType;
var extensionPoints = (IExtensionPoints)RuntimeAccessor.ServiceLocator.ResolveByComponentId("Gallio.ExtensionPoints");
CustomTestEnvironment.SetUpThreadChain.Before(() => extensionPoints.CustomFormatters.Register(formattableType, x => (string)methodInfo.Resolve(true).Invoke(this, new[] { x })));
CustomTestEnvironment.TeardownThreadChain.After(() => extensionPoints.CustomFormatters.Unregister(formattableType));
}
示例6: EnumerateTestCommands
public IEnumerable<ITestCommand> EnumerateTestCommands(IMethodInfo testMethod)
{
var commands = command.EnumerateTestCommands(testMethod).ToList();
if (!commands.Any())
commands.Add(new FactCommand(testMethod));
return commands;
}
示例7: FailedResult
public FailedResult(IMethodInfo method, Exception exception, string displayName)
: base(method, displayName)
{
ExceptionType = exception.GetType().FullName;
Message = ExceptionUtility.GetMessage(exception);
StackTrace = ExceptionUtility.GetStackTrace(exception);
}
示例8: BuildFrom
/// <summary>
/// Construct one or more TestMethods from a given MethodInfo,
/// using available parameter data.
/// </summary>
/// <param name="method">The MethodInfo for which tests are to be constructed.</param>
/// <param name="suite">The suite to which the tests will be added.</param>
/// <returns>One or more TestMethods</returns>
public IEnumerable<TestMethod> BuildFrom(IMethodInfo method, Test suite)
{
List<TestMethod> tests = new List<TestMethod>();
IParameterInfo[] parameters = method.GetParameters();
if (parameters.Length > 0)
{
IEnumerable[] sources = new IEnumerable[parameters.Length];
try
{
for (int i = 0; i < parameters.Length; i++)
sources[i] = _dataProvider.GetDataFor(parameters[i]);
}
catch (InvalidDataSourceException ex)
{
var parms = new TestCaseParameters();
parms.RunState = RunState.NotRunnable;
parms.Properties.Set(PropertyNames.SkipReason, ex.Message);
tests.Add(_builder.BuildTestMethod(method, suite, parms));
return tests;
}
foreach (var parms in _strategy.GetTestCases(sources))
tests.Add(_builder.BuildTestMethod(method, suite, (TestCaseParameters)parms));
}
return tests;
}
示例9: RepositoryTheoryCommand
public RepositoryTheoryCommand(IMethodInfo method, RepositoryProvider provider)
:base(method)
{
_provider = provider;
DisplayName = string.Format(
"{0} - DatabaseProvider: {1}", DisplayName, _provider);
}
示例10: UnresolvedMethodInfo
internal UnresolvedMethodInfo(IMethodInfo adapter)
{
if (adapter == null)
throw new ArgumentNullException("adapter");
this.adapter = adapter;
}
示例11: FindTestsForMethod
/// <summary>
/// Finds the tests on a test method.
/// </summary>
/// <param name="testCollection">The test collection that the test method belongs to.</param>
/// <param name="type">The test class that the test method belongs to.</param>
/// <param name="method">The test method.</param>
/// <param name="includeSourceInformation">Set to <c>true</c> to indicate that source information should be included.</param>
/// <param name="messageBus">The message bus to report discovery messages to.</param>
/// <returns>Return <c>true</c> to continue test discovery, <c>false</c>, otherwise.</returns>
protected virtual bool FindTestsForMethod(ITestCollection testCollection, ITypeInfo type, IMethodInfo method, bool includeSourceInformation, IMessageBus messageBus)
{
var factAttribute = method.GetCustomAttributes(typeof(FactAttribute)).FirstOrDefault();
if (factAttribute == null)
return true;
var testCaseDiscovererAttribute = factAttribute.GetCustomAttributes(typeof(XunitTestCaseDiscovererAttribute)).FirstOrDefault();
if (testCaseDiscovererAttribute == null)
return true;
var args = testCaseDiscovererAttribute.GetConstructorArguments().Cast<string>().ToList();
var discovererType = Reflector.GetType(args[1], args[0]);
if (discovererType == null)
return true;
var discoverer = GetDiscoverer(discovererType);
if (discoverer == null)
return true;
foreach (var testCase in discoverer.Discover(testCollection, AssemblyInfo, type, method, factAttribute))
if (!ReportDiscoveredTestCase(testCase, includeSourceInformation, messageBus))
return false;
return true;
}
示例12: EnumerateTestCommands
public IEnumerable<ITestCommand> EnumerateTestCommands(IMethodInfo testMethod)
{
EnumerateTestCommands__Called = true;
EnumerateTestCommands_TestMethod = testMethod;
return EnumerateTestCommands__Result ?? testClassCommand.EnumerateTestCommands(testMethod);
}
示例13: MethodResult
protected MethodResult(IMethodInfo method, string displayName)
: this(method.Name,
method.TypeName,
displayName,
MethodUtility.GetTraits(method))
{
}
示例14: EnumerateTestCommands
protected override IEnumerable<ITestCommand> EnumerateTestCommands(IMethodInfo method)
{
var commands = base.EnumerateTestCommands(method);
var attrs = method.MethodInfo.GetCustomAttributes(typeof(DataAttribute), false);
if (commands.Count() != attrs.Count())
{
throw new InvalidOperationException("Some data attribute doesn't generate test command");
}
var filteredCommands = new List<ITestCommand>();
int index = 0;
foreach (var command in commands)
{
var theoryCmd = command as TheoryCommand;
var skippableData = attrs.ElementAt(index++) as ISkippable;
if (skippableData != null &&
!string.IsNullOrEmpty(skippableData.SkipReason))
{
SkipCommand cmd = new SkipCommand(method, theoryCmd.DisplayName, skippableData.SkipReason);
filteredCommands.Add(cmd);
}
else
{
filteredCommands.Add(command);
}
}
return filteredCommands;
}
示例15: EnumerateTestCommands
protected override IEnumerable<ITestCommand> EnumerateTestCommands(IMethodInfo method)
{
if (DateTime.Today < SkipUntil)
return Enumerable.Empty<ITestCommand>();
throw new InvalidOperationException("Time bombed fact expired");
//return base.EnumerateTestCommands(method);
}