@@ -537,5 +537,47 @@ void Execute(string fullnameOrNickname, int age)
537
537
boundName . Should ( ) . Be ( "Gandalf" ) ;
538
538
boundAge . Should ( ) . Be ( 425 ) ;
539
539
}
540
+
541
+ [ Theory ]
542
+ [ InlineData ( typeof ( ConcreteTestCommandHandler ) , 42 ) ]
543
+ [ InlineData ( typeof ( VirtualTestCommandHandler ) , 42 ) ]
544
+ [ InlineData ( typeof ( OverridenVirtualTestCommandHandler ) , 41 ) ]
545
+ public async Task Method_invoked_is_matching_to_the_interface_implementation ( Type type , int expectedResult )
546
+ {
547
+ var command = new Command ( "command" ) ;
548
+ command . Handler = CommandHandler . Create ( type . GetMethod ( nameof ( ICommandHandler . InvokeAsync ) ) ) ;
549
+
550
+ var parser = new Parser ( command ) ;
551
+
552
+ int result = await parser . InvokeAsync ( "command" , _console ) ;
553
+
554
+ result . Should ( ) . Be ( expectedResult ) ;
555
+ }
556
+
557
+ public abstract class AbstractTestCommandHandler : ICommandHandler
558
+ {
559
+ public abstract Task < int > DoJobAsync ( ) ;
560
+
561
+ public Task < int > InvokeAsync ( InvocationContext context )
562
+ => DoJobAsync ( ) ;
563
+ }
564
+
565
+ public sealed class ConcreteTestCommandHandler : AbstractTestCommandHandler
566
+ {
567
+ public override Task < int > DoJobAsync ( )
568
+ => Task . FromResult ( 42 ) ;
569
+ }
570
+
571
+ public class VirtualTestCommandHandler : ICommandHandler
572
+ {
573
+ public virtual Task < int > InvokeAsync ( InvocationContext context )
574
+ => Task . FromResult ( 42 ) ;
575
+ }
576
+
577
+ public class OverridenVirtualTestCommandHandler : VirtualTestCommandHandler
578
+ {
579
+ public override Task < int > InvokeAsync ( InvocationContext context )
580
+ => Task . FromResult ( 41 ) ;
581
+ }
540
582
}
541
583
}
0 commit comments