This project has moved. For the latest updates, please go here.
1
Vote

Build against latest xunit trunk

description

Hello
 
In our project we are using latest xunit trunk. I had to do the following to get TypeResolver compiling (see extended LambdaTestCommand ctor):
 
/// <summary>
/// Marks a test method as being a data theory. Data theories are tests which 
///  are fed various bits of data from a data source, mapping to parameters on 
///  the test method.  If the data source contains multiple rows, then the test 
///  method is executed multiple times (once with each data row).
/// </summary>
public class GenericTheoryAttribute : TheoryAttribute {
 
    /// <summary>
    /// Creates instances of <see cref="Xunit.Extensions.TheoryCommand"/> which represent individual intended
    ///  invocations of the test method, one per data row in the data source.
    /// </summary>
    protected override IEnumerable<ITestCommand> EnumerateTestCommands( IMethodInfo method ) {
        var methodInfo = method.MethodInfo;
        var concreteMethods = GenericTypeResolver.GetConcreteMethods( methodInfo );
 
        if( concreteMethods.Length == 0 )
            return new LambdaTestCommand( method, this.DisplayName, this.Timeout ,( ) => { throw new InvalidOperationException( "Could not find any arguments to satisfy the generic method " + methodInfo.GetDescriptiveName( ) ); } )
                .MakeEnumerable<ITestCommand>( );
 
        return
            from concreteMethod in concreteMethods
            from testCommand in EnumerateBaseTestCommands( concreteMethod )
            select testCommand;
    }
 
    private IEnumerable<ITestCommand> EnumerateBaseTestCommands( MethodInfo concreteMethod ) {
        return base.EnumerateTestCommands( Reflector.Wrap( concreteMethod ) );
    }
 
 
    // From Xunit.Extensions.TheoryAttribute
    private class LambdaTestCommand : TestCommand {
        readonly Assert.ThrowsDelegate lambda;
 
        public LambdaTestCommand( IMethodInfo method, string displayName, int timeout, Assert.ThrowsDelegate lambda )
            : base( method, displayName, timeout ) {
            this.lambda = lambda;
        }
 
        public override bool ShouldCreateInstance {
            get { return false; }
        }
 
        public override MethodResult Execute( object testClass ) {
            try {
                lambda( );
                return new PassedResult( testMethod, DisplayName );
            }
            catch( Exception ex ) {
                return new FailedResult( testMethod, ex, DisplayName );
            }
        }
    }
 
}

comments

EmperorXLII wrote May 7, 2010 at 2:55 AM

When the next version of xUnit is officially released, I will create a new release of Type Resolver as well. Until then, your update looks correct for the pre-release source in the xUnit trunk.

LOBOMINATOR wrote Jun 21, 2010 at 8:22 AM

New version 1.6 is out!

wrote Feb 2, 2013 at 5:47 AM