File tree Expand file tree Collapse file tree 2 files changed +19
-16
lines changed
tests/MicroBatchFramework.Tests Expand file tree Collapse file tree 2 files changed +19
-16
lines changed Original file line number Diff line number Diff line change @@ -211,28 +211,27 @@ static List<Type> GetBatchTypes()
211211 MethodInfo foundMethod = null ;
212212 foreach ( var baseType in batchBaseTypes )
213213 {
214- if ( split . Length == 2 )
214+ bool isFound = false ;
215+ foreach ( var ( method , cmdattr ) in baseType . GetMethods ( ) .
216+ Select ( m => ( MethodInfo : m , Attr : m . GetCustomAttribute < CommandAttribute > ( ) ) ) . Where ( x => x . Attr != null ) )
215217 {
216- if ( baseType . Name . Equals ( split [ 0 ] , StringComparison . OrdinalIgnoreCase ) )
218+ if ( cmdattr . CommandNames . Any ( x => arg0 . Equals ( x , StringComparison . OrdinalIgnoreCase ) ) )
217219 {
218- if ( foundType != null )
219- {
220- throw new InvalidOperationException ( "Duplicate BatchBase TypeName is not allowed, " + foundType . FullName + " and " + baseType . FullName ) ;
221- }
222220 foundType = baseType ;
223- foundMethod = baseType . GetMethod ( split [ 1 ] ) ;
221+ foundMethod = method ;
222+ isFound = true ;
224223 }
225224 }
226- else
225+ if ( ! isFound && split . Length == 2 )
227226 {
228- foreach ( var ( method , cmdattr ) in baseType . GetMethods ( ) .
229- Select ( m => ( MethodInfo : m , Attr : m . GetCustomAttribute < CommandAttribute > ( ) ) ) . Where ( x => x . Attr != null ) )
227+ if ( baseType . Name . Equals ( split [ 0 ] , StringComparison . OrdinalIgnoreCase ) )
230228 {
231- if ( cmdattr . CommandNames . Any ( x => arg0 . Equals ( x , StringComparison . OrdinalIgnoreCase ) ) )
229+ if ( foundType != null )
232230 {
233- foundType = baseType ;
234- foundMethod = method ;
231+ throw new InvalidOperationException ( "Duplicate BatchBase TypeName is not allowed, " + foundType . FullName + " and " + baseType . FullName ) ;
235232 }
233+ foundType = baseType ;
234+ foundMethod = baseType . GetMethod ( split [ 1 ] ) ;
236235 }
237236 }
238237 }
Original file line number Diff line number Diff line change @@ -31,12 +31,16 @@ class ResultContainer
3131 [ Fact ]
3232 public async Task TestCommandName ( )
3333 {
34- var hostBuilder = BatchHost . CreateDefaultBuilder ( )
34+ var host = BatchHost . CreateDefaultBuilder ( )
3535 . ConfigureServices ( ( c , services ) =>
3636 {
3737 services . AddSingleton < ResultContainer > ( ) ;
38- } ) ;
39- await hostBuilder . RunBatchEngineAsync ( new string [ ] { "test" , "-value" , "1" } ) ;
38+ } )
39+ . UseBatchEngine < CommandAttributeTestCommand > ( new string [ ] { "test" , "-value" , "1" } )
40+ . Build ( ) ;
41+ var result = host . Services . GetService < ResultContainer > ( ) ;
42+ await host . RunAsync ( ) ;
43+ result . X . Should ( ) . Be ( 1 ) ;
4044 }
4145
4246 }
You can’t perform that action at this time.
0 commit comments