public void Should_resolve_bootstrapper_type_from_unique_type() { // Given var list = new List <Type> { typeof(MyFirstBootstwapper) }; var typeCatalog = new TestTypeCatalog(list); // When var bootstrapperType = NancyBootstrapperLocator.GetBootstrapperType(typeCatalog); // Then bootstrapperType.ShouldEqual(typeof(MyFirstBootstwapper)); }
public void Should_throw_exception_when_multiple_bootstrappers_are_located() { // Given var list = new List <Type> { typeof(MyFirstBootstwapper), typeof(AnotherFirstBootstwapper) }; var typeCatalog = new TestTypeCatalog(list); // When var result = Record.Exception(() => NancyBootstrapperLocator.GetBootstrapperType(typeCatalog)); // Then result.ShouldNotBeNull(); result.GetType().ShouldEqual(typeof(BootstrapperException)); }
/// <summary> /// Initializes a new instance of the <see cref="InfoModule"/> class, with /// the provided <paramref name="rootPathProvider"/>, <paramref name="configuration"/>, /// <paramref name="environment"/>, <paramref name="typeCatalog"/> and <paramref name="assemblyCatalog"/>. /// </summary> /// <param name="rootPathProvider">The root path provider.</param> /// <param name="configuration">The configuration.</param> /// <param name="environment">The environment.</param> /// <param name="typeCatalog">The type catalog.</param> /// <param name="assemblyCatalog">The assembly catalog.</param> public InfoModule(IRootPathProvider rootPathProvider, NancyInternalConfiguration configuration, INancyEnvironment environment, ITypeCatalog typeCatalog, IAssemblyCatalog assemblyCatalog) : base("/info") { this.typeCatalog = typeCatalog; this.assemblyCatalog = assemblyCatalog; Get("/", _ => { return(View["Info"]); }); Get("/data", _ => { dynamic data = new ExpandoObject(); data.Nancy = new ExpandoObject(); data.Nancy.Version = string.Format("v{0}", this.GetType().GetTypeInfo().Assembly.GetName().Version.ToString()); data.Nancy.TracesDisabled = !environment.GetValue <TraceConfiguration>().DisplayErrorTraces; data.Nancy.CaseSensitivity = StaticConfiguration.CaseSensitive ? "Sensitive" : "Insensitive"; data.Nancy.RootPath = rootPathProvider.GetRootPath(); data.Nancy.Hosting = GetHosting(); data.Nancy.BootstrapperContainer = GetBootstrapperContainer(); data.Nancy.LocatedBootstrapper = NancyBootstrapperLocator.GetBootstrapperType().ToString(); data.Nancy.LoadedViewEngines = GetViewEngines(); data.Configuration = new Dictionary <string, object>(); foreach (var propertyInfo in configuration.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public)) { var value = propertyInfo.GetValue(configuration, null); data.Configuration[propertyInfo.Name] = (!typeof(IEnumerable).IsAssignableFrom(value.GetType())) ? new[] { value.ToString() } : ((IEnumerable <object>)value).Select(x => x.ToString()); } return(this.Response.AsJson((object)data)); }); }