Created
June 20, 2012 08:21
-
-
Save rhwy/2958786 to your computer and use it in GitHub Desktop.
Temporary fix for nunit tests with Nancy FX and Monodevelop runner
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Source of the problem: | |
when running a NancyFX based application under Monodevelop it fails during the AssemblyScanner phase of the Nancy bootstrapper | |
Fix: | |
1) get the sources of Nancy | |
2) create a static configuration class just to decouple the ignored assemblies configuration option (AppDomainAssemblyTypeScannerIgnoreHelper) | |
3) change the ctor of the AppDomainAssemblyScanner to initialize the ignoredAssemblies values from the previously created class | |
4) add an ignore list with "nunit" pattern before using the Nancy bootstrapper in your tests | |
Btw, it will be fixed on the next version of Nancy as far as the initial auto-registry will be removed by default. This gist is only here to provide a quick and dirty alternative waiting for that. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 2) | |
public static class AppDomainAssemblyTypeScannerIgnoreHelper | |
{ | |
private static IEnumerable<Func<Assembly,bool>> _ignoreList; | |
public static IEnumerable<Func<Assembly,bool>> IgnoreList | |
{ | |
get { return _ignoreList;} | |
set {_ignoreList = value;} | |
} | |
} | |
// 3) update the static ctor of AppDomainAssemblyTypeScanner: | |
static AppDomainAssemblyTypeScanner() | |
{ | |
ignoredAssemblies = AppDomainAssemblyTypeScannerIgnoreHelper.IgnoreList; | |
LoadNancyAssemblies(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List<Func<Assembly,bool>> list = new List<Func<Assembly,bool>>(); | |
list.Add(a => a.FullName.ToLower().Contains("nunit")); | |
Nancy.Bootstrapper.AppDomainAssemblyTypeScannerIgnoreHelper.IgnoreList = list; | |
var b = new DefaultNancyBootstrapper(); | |
Assert.That(b, Is.Not.Null); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment