1+ using Blake . BuildTools . Utils ;
2+ using Microsoft . Extensions . Logging ;
3+ using Xunit ;
4+
5+ namespace Blake . BuildTools . Tests . Utils ;
6+
7+ public class PluginLoaderTests
8+ {
9+ [ Fact ]
10+ public void LoadPluginDLLs_WithPluginWithDependencies_LoadsSuccessfully ( )
11+ {
12+ // Arrange
13+ var logger = new TestLogger ( ) ;
14+ var pluginPath = Path . GetFullPath ( Path . Combine (
15+ Directory . GetCurrentDirectory ( ) ,
16+ ".." , ".." , ".." , ".." , ".." , "tests" , "Blake.IntegrationTests" ,
17+ "TestPluginWithDependencies" , "bin" , "Debug" , "net8.0" ,
18+ "BlakePlugin.TestPluginWithDependencies.dll"
19+ ) ) ;
20+
21+ // Skip test if plugin doesn't exist (build not run)
22+ if ( ! File . Exists ( pluginPath ) )
23+ {
24+ Assert . True ( true , "Plugin not built - skipping test" ) ;
25+ return ;
26+ }
27+
28+ var files = new List < string > { pluginPath } ;
29+ var plugins = new List < PluginContext > ( ) ;
30+
31+ // Act & Assert - should not throw exception
32+ var exception = Record . Exception ( ( ) =>
33+ {
34+ // Use reflection to call the private method
35+ var method = typeof ( PluginLoader ) . GetMethod ( "LoadPluginDLLs" ,
36+ System . Reflection . BindingFlags . NonPublic | System . Reflection . BindingFlags . Static ) ;
37+ method ? . Invoke ( null , new object [ ] { files , plugins , logger } ) ;
38+ } ) ;
39+
40+ // Assert
41+ Assert . Null ( exception ) ;
42+ Assert . Single ( plugins ) ;
43+ Assert . Equal ( "BlakePlugin.TestPluginWithDependencies" , plugins [ 0 ] . PluginName ) ;
44+
45+ // Ensure no errors were logged
46+ Assert . Empty ( logger . ErrorMessages ) ;
47+ }
48+
49+ private class TestLogger : ILogger
50+ {
51+ public List < string > ErrorMessages { get ; } = new List < string > ( ) ;
52+ public List < string > InfoMessages { get ; } = new List < string > ( ) ;
53+
54+ public IDisposable ? BeginScope < TState > ( TState state ) where TState : notnull => null ;
55+ public bool IsEnabled ( LogLevel logLevel ) => true ;
56+
57+ public void Log < TState > ( LogLevel logLevel , EventId eventId , TState state , Exception ? exception , Func < TState , Exception ? , string > formatter )
58+ {
59+ var message = formatter ( state , exception ) ;
60+ if ( logLevel == LogLevel . Error )
61+ {
62+ ErrorMessages . Add ( message ) ;
63+ }
64+ else if ( logLevel == LogLevel . Information )
65+ {
66+ InfoMessages . Add ( message ) ;
67+ }
68+ }
69+ }
70+ }
0 commit comments