@@ -31,55 +31,32 @@ public async Task CanInitialize()
3131
3232 Assert . NotEmpty ( allPlugins ) ;
3333 }
34-
34+
3535 [ Fact ]
3636 public async Task CanInitializeWithCriteria ( )
3737 {
3838 var catalog = new AssemblyPluginCatalog ( @"..\..\..\..\..\Assemblies\bin\netstandard2.0\TestAssembly1.dll" , configure =>
3939 {
4040 configure . HasName ( "*Plugin" ) ;
4141 } ) ;
42-
42+
4343 await catalog . Initialize ( ) ;
4444
4545 var allPlugins = catalog . GetPlugins ( ) ;
4646
4747 Assert . Single ( allPlugins ) ;
4848 }
49-
49+
5050 [ Fact ]
5151 public async Task CanConfigureNamingOptions ( )
5252 {
5353 var options = new AssemblyPluginCatalogOptions ( )
5454 {
55- PluginNameOptions = new PluginNameOptions ( )
56- {
57- PluginNameGenerator = ( nameOptions , type ) => type . FullName + "Modified"
58- }
55+ PluginNameOptions = new PluginNameOptions ( ) { PluginNameGenerator = ( nameOptions , type ) => type . FullName + "Modified" }
5956 } ;
60-
61- var catalog = new AssemblyPluginCatalog ( @"..\..\..\..\..\Assemblies\bin\netstandard2.0\TestAssembly1.dll" , options ) ;
62-
63- await catalog . Initialize ( ) ;
6457
65- var allPlugins = catalog . GetPlugins ( ) ;
58+ var catalog = new AssemblyPluginCatalog ( @"..\..\..\..\..\Assemblies\bin\netstandard2.0\TestAssembly1.dll" , options ) ;
6659
67- foreach ( var plugin in allPlugins )
68- {
69- Assert . EndsWith ( "Modified" , plugin . Name ) ;
70- }
71- }
72-
73- [ Fact ]
74- public async Task CanConfigureDefaultNamingOptions ( )
75- {
76- AssemblyPluginCatalogOptions . Defaults . PluginNameOptions = new PluginNameOptions ( )
77- {
78- PluginNameGenerator = ( nameOptions , type ) => type . FullName + "Modified"
79- } ;
80-
81- var catalog = new AssemblyPluginCatalog ( @"..\..\..\..\..\Assemblies\bin\netstandard2.0\TestAssembly1.dll" ) ;
82-
8360 await catalog . Initialize ( ) ;
8461
8562 var allPlugins = catalog . GetPlugins ( ) ;
@@ -89,44 +66,7 @@ public async Task CanConfigureDefaultNamingOptions()
8966 Assert . EndsWith ( "Modified" , plugin . Name ) ;
9067 }
9168 }
92-
93- [ Fact ]
94- public async Task CanOverrideDefaultNamingOptions ( )
95- {
96- AssemblyPluginCatalogOptions . Defaults . PluginNameOptions = new PluginNameOptions ( )
97- {
98- PluginNameGenerator = ( nameOptions , type ) => type . FullName + "Modified"
99- } ;
100-
101- var options = new AssemblyPluginCatalogOptions ( )
102- {
103- PluginNameOptions = new PluginNameOptions ( )
104- {
105- PluginNameGenerator = ( nameOptions , type ) => type . FullName + "Overridden"
106- }
107- } ;
108-
109- var catalog = new AssemblyPluginCatalog ( @"..\..\..\..\..\Assemblies\bin\netstandard2.0\TestAssembly1.dll" ) ;
110- var catalog2 = new AssemblyPluginCatalog ( @"..\..\..\..\..\Assemblies\bin\netstandard2.0\TestAssembly2.dll" , options ) ;
111-
112- await catalog . Initialize ( ) ;
113- await catalog2 . Initialize ( ) ;
11469
115- var catalog1Plugins = catalog . GetPlugins ( ) ;
116-
117- foreach ( var plugin in catalog1Plugins )
118- {
119- Assert . EndsWith ( "Modified" , plugin . Name ) ;
120- }
121-
122- var catalog2Plugins = catalog2 . GetPlugins ( ) ;
123-
124- foreach ( var plugin in catalog2Plugins )
125- {
126- Assert . EndsWith ( "Overridden" , plugin . Name ) ;
127- }
128- }
129-
13070 [ Fact ]
13171 public async Task ByDefaultOnlyContainsPublicNonAbstractClasses ( )
13272 {
@@ -139,15 +79,15 @@ public async Task ByDefaultOnlyContainsPublicNonAbstractClasses()
13979 Assert . False ( plugin . Type . IsAbstract ) ;
14080 Assert . False ( plugin . Type . IsInterface ) ;
14181 }
142-
82+
14383 [ Fact ]
14484 public async Task CanIncludeAbstractClassesUsingCriteria ( )
14585 {
14686 var catalog = new AssemblyPluginCatalog ( @"..\..\..\..\..\Assemblies\bin\netstandard2.0\TestAssembly1.dll" , builder =>
14787 {
14888 builder . IsAbstract ( true ) ;
14989 } ) ;
150-
90+
15191 await catalog . Initialize ( ) ;
15292
15393 var allPlugins = catalog . GetPlugins ( ) ;
@@ -224,14 +164,13 @@ public async Task CanUseHostsDependencies()
224164
225165 var newPlugin = folder1Catalog . Single ( ) ;
226166 var oldPlugin = folder2Catalog . Single ( ) ;
227-
228-
167+
229168 dynamic newPluginJsonResolver = Activator . CreateInstance ( newPlugin ) ;
230169 var newPluginVersion = newPluginJsonResolver . GetVersion ( ) ;
231-
170+
232171 dynamic oldPluginJsonResolver = Activator . CreateInstance ( oldPlugin ) ;
233172 var oldPluginVersion = oldPluginJsonResolver . GetVersion ( ) ;
234-
173+
235174 Assert . Equal ( "12.0.0.0" , newPluginVersion ) ;
236175 Assert . Equal ( "12.0.0.0" , oldPluginVersion ) ;
237176 }
@@ -241,30 +180,91 @@ public async Task CanUseSelectedHoststDependencies()
241180 {
242181 // Make sure that the referenced version of JSON.NET is loaded into memory
243182 var json = Newtonsoft . Json . JsonConvert . SerializeObject ( 1 ) ;
183+
244184 // Make sure that the referenced version of Microsoft.Extensions.Logging is loaded into memory
245185 var logging = new Microsoft . Extensions . Logging . LoggerFactory ( ) ;
246-
247- var options = new AssemblyPluginCatalogOptions ( ) ; ;
186+
187+ var options = new AssemblyPluginCatalogOptions ( ) ;
188+ ;
189+
248190 options . PluginLoadContextOptions = new PluginLoadContextOptions ( )
249191 {
250192 UseHostApplicationAssemblies = UseHostApplicationAssembliesEnum . Selected ,
251- HostApplicationAssemblies = new List < AssemblyName > ( )
252- {
253- typeof ( Microsoft . Extensions . Logging . LoggerFactory ) . Assembly . GetName ( )
254- }
193+ HostApplicationAssemblies = new List < AssemblyName > ( ) { typeof ( Microsoft . Extensions . Logging . LoggerFactory ) . Assembly . GetName ( ) }
255194 } ;
256-
195+
257196 var catalog = new AssemblyPluginCatalog ( @"..\..\..\..\..\Assemblies\bin\JsonOld\netstandard2.0\JsonNetOld.dll" , options ) ;
258197 await catalog . Initialize ( ) ;
259-
198+
260199 var oldPlugin = catalog . Single ( ) ;
261-
200+
262201 dynamic oldPluginJsonResolver = Activator . CreateInstance ( oldPlugin ) ;
263202 var oldPluginVersion = oldPluginJsonResolver . GetVersion ( ) ;
264203 var loggerVersion = oldPluginJsonResolver . GetLoggingVersion ( ) ;
265-
204+
266205 Assert . Equal ( "3.1.2.0" , loggerVersion ) ;
267206 Assert . Equal ( "9.0.0.0" , oldPluginVersion ) ;
268207 }
208+
209+ [ Collection ( nameof ( NotThreadSafeResourceCollection ) ) ]
210+ public class DefaultOptions : IDisposable
211+ {
212+ public DefaultOptions ( )
213+ {
214+ AssemblyPluginCatalogOptions . Defaults . PluginNameOptions = new PluginNameOptions ( )
215+ {
216+ PluginNameGenerator = ( nameOptions , type ) => type . FullName + "Modified"
217+ } ;
218+ }
219+
220+ [ Fact ]
221+ public async Task CanConfigureDefaultNamingOptions ( )
222+ {
223+ var catalog = new AssemblyPluginCatalog ( @"..\..\..\..\..\Assemblies\bin\netstandard2.0\TestAssembly1.dll" ) ;
224+
225+ await catalog . Initialize ( ) ;
226+
227+ var allPlugins = catalog . GetPlugins ( ) ;
228+
229+ foreach ( var plugin in allPlugins )
230+ {
231+ Assert . EndsWith ( "Modified" , plugin . Name ) ;
232+ }
233+ }
234+
235+ [ Fact ]
236+ public async Task CanOverrideDefaultNamingOptions ( )
237+ {
238+ var options = new AssemblyPluginCatalogOptions ( )
239+ {
240+ PluginNameOptions = new PluginNameOptions ( ) { PluginNameGenerator = ( nameOptions , type ) => type . FullName + "Overridden" }
241+ } ;
242+
243+ var catalog = new AssemblyPluginCatalog ( @"..\..\..\..\..\Assemblies\bin\netstandard2.0\TestAssembly1.dll" ) ;
244+ var catalog2 = new AssemblyPluginCatalog ( @"..\..\..\..\..\Assemblies\bin\netstandard2.0\TestAssembly2.dll" , options ) ;
245+
246+ await catalog . Initialize ( ) ;
247+ await catalog2 . Initialize ( ) ;
248+
249+ var catalog1Plugins = catalog . GetPlugins ( ) ;
250+
251+ foreach ( var plugin in catalog1Plugins )
252+ {
253+ Assert . EndsWith ( "Modified" , plugin . Name ) ;
254+ }
255+
256+ var catalog2Plugins = catalog2 . GetPlugins ( ) ;
257+
258+ foreach ( var plugin in catalog2Plugins )
259+ {
260+ Assert . EndsWith ( "Overridden" , plugin . Name ) ;
261+ }
262+ }
263+
264+ public void Dispose ( )
265+ {
266+ AssemblyPluginCatalogOptions . Defaults . PluginNameOptions = new PluginNameOptions ( ) ;
267+ }
268+ }
269269 }
270270}
0 commit comments