public DefaultRouteResolverFixture() { this.routeDescriptionProvider = A.Fake<IRouteDescriptionProvider>(); this.moduleBuilder = A.Fake<INancyModuleBuilder>(); A.CallTo(() => this.moduleBuilder.BuildModule(A<NancyModule>.Ignored, A<NancyContext>.Ignored)). ReturnsLazily(r => r.Arguments[0] as NancyModule); this.catalog = A.Fake<INancyModuleCatalog>(); A.CallTo(() => this.catalog.GetModuleByKey(A<string>.Ignored, A<NancyContext>.Ignored)).Returns(expectedModule); this.expectedAction = x => HttpStatusCode.OK; this.expectedModule = new FakeNancyModule(x => x.AddGetRoute("/foo/bar", this.expectedAction)); A.CallTo(() => this.catalog.GetModuleByKey(A<string>.Ignored, A<NancyContext>.Ignored)).ReturnsLazily(() => this.expectedModule); this.matcher = A.Fake<IRoutePatternMatcher>(); A.CallTo(() => this.matcher.Match(A<string>.Ignored, A<string>.Ignored, A<IEnumerable<string>>.Ignored, A<NancyContext>.Ignored)).ReturnsLazily(x => new FakeRoutePatternMatchResult(c => { c.IsMatch(((string)x.Arguments[0]).Equals(((string)x.Arguments[1]))); c.AddParameter("foo", "bar"); })); this.moduleKeyGenerator = A.Fake<IModuleKeyGenerator>(); A.CallTo(() => moduleKeyGenerator.GetKeyForModuleType(A<Type>._)).ReturnsLazily(x => (string)x.Arguments[0]); }
public DefaultRouteResolverFixture() { this.moduleBuilder = A.Fake <INancyModuleBuilder>(); A.CallTo(() => this.moduleBuilder.BuildModule(A <NancyModule> .Ignored, A <NancyContext> .Ignored)). ReturnsLazily(r => r.Arguments[0] as NancyModule); this.catalog = A.Fake <INancyModuleCatalog>(); A.CallTo(() => this.catalog.GetModuleByKey(A <string> .Ignored, A <NancyContext> .Ignored)).Returns(expectedModule); this.expectedAction = x => HttpStatusCode.OK; this.expectedModule = new FakeNancyModule(x => x.AddGetRoute("/foo/bar", this.expectedAction)); A.CallTo(() => this.catalog.GetModuleByKey(A <string> .Ignored, A <NancyContext> .Ignored)).ReturnsLazily(() => this.expectedModule); this.matcher = A.Fake <IRoutePatternMatcher>(); A.CallTo(() => this.matcher.Match(A <string> .Ignored, A <string> .Ignored, A <NancyContext> .Ignored)).ReturnsLazily(x => new FakeRoutePatternMatchResult(c => { c.IsMatch(((string)x.Arguments[0]).Equals(((string)x.Arguments[1]))); c.AddParameter("foo", "bar"); })); this.contextFactory = A.Fake <INancyContextFactory>(); this.moduleKeyGenerator = A.Fake <IModuleKeyGenerator>(); A.CallTo(() => moduleKeyGenerator.GetKeyForModuleType(A <Type> ._)).ReturnsLazily(x => (string)x.Arguments[0]); }
public DefaultRouteCache(INancyModuleCatalog moduleCatalog, IModuleKeyGenerator moduleKeyGenerator) { _ModuleKeyGenerator = moduleKeyGenerator; _Cache = new List<RouteCacheEntry>(); BuildCache(moduleCatalog.GetAllModules()); }
private static TinyIoCContainer ConfigureContainer(IModuleKeyGenerator moduleKeyGenerator, IEnumerable <IDiagnosticsProvider> providers, IRootPathProvider rootPathProvider, IRequestTracing requestTracing, NancyInternalConfiguration configuration, DiagnosticsConfiguration diagnosticsConfiguration) { var diagContainer = new TinyIoCContainer(); diagContainer.Register <IModuleKeyGenerator>(moduleKeyGenerator); diagContainer.Register <IInteractiveDiagnostics, InteractiveDiagnostics>(); diagContainer.Register <IRequestTracing>(requestTracing); diagContainer.Register <IRootPathProvider>(rootPathProvider); diagContainer.Register <NancyInternalConfiguration>(configuration); diagContainer.Register <IModelBinderLocator, DefaultModelBinderLocator>(); diagContainer.Register <IBinder, DefaultBinder>(); diagContainer.Register <IFieldNameConverter, DefaultFieldNameConverter>(); diagContainer.Register <BindingDefaults, BindingDefaults>(); diagContainer.Register <ISerializer, DefaultJsonSerializer>(); diagContainer.Register <DiagnosticsConfiguration>(diagnosticsConfiguration); foreach (var diagnosticsProvider in providers) { diagContainer.Register <IDiagnosticsProvider>(diagnosticsProvider, diagnosticsProvider.GetType().FullName); } foreach (var moduleType in AppDomainAssemblyTypeScanner.TypesOf <DiagnosticModule>().ToArray()) { diagContainer.Register(typeof(NancyModule), moduleType, moduleKeyGenerator.GetKeyForModuleType(moduleType)).AsMultiInstance(); } return(diagContainer); }
private static TinyIoCContainer ConfigureContainer(IModuleKeyGenerator moduleKeyGenerator, IEnumerable<IDiagnosticsProvider> providers, IRootPathProvider rootPathProvider, IRequestTracing requestTracing, NancyInternalConfiguration configuration, DiagnosticsConfiguration diagnosticsConfiguration) { var diagContainer = new TinyIoCContainer(); diagContainer.Register<IModuleKeyGenerator>(moduleKeyGenerator); diagContainer.Register<IInteractiveDiagnostics, InteractiveDiagnostics>(); diagContainer.Register<IRequestTracing>(requestTracing); diagContainer.Register<IRootPathProvider>(rootPathProvider); diagContainer.Register<NancyInternalConfiguration>(configuration); diagContainer.Register<IModelBinderLocator, DefaultModelBinderLocator>(); diagContainer.Register<IBinder, DefaultBinder>(); diagContainer.Register<IFieldNameConverter, DefaultFieldNameConverter>(); diagContainer.Register<BindingDefaults, BindingDefaults>(); diagContainer.Register<ISerializer, DefaultJsonSerializer>(); diagContainer.Register<DiagnosticsConfiguration>(diagnosticsConfiguration); foreach (var diagnosticsProvider in providers) { diagContainer.Register<IDiagnosticsProvider>(diagnosticsProvider, diagnosticsProvider.GetType().FullName); } foreach (var moduleType in AppDomainAssemblyTypeScanner.TypesOf<DiagnosticModule>().ToArray()) { diagContainer.Register(typeof(NancyModule), moduleType, moduleKeyGenerator.GetKeyForModuleType(moduleType)).AsMultiInstance(); } return diagContainer; }
/// <summary> /// Initializes a new instance of the <see cref="NancyRebuildableCache"/> class. /// </summary> /// <param name="moduleCatalog">The <see cref="INancyModuleCatalog"/> that should be used by the cache.</param> /// <param name="moduleKeyGenerator">The <see cref="IModuleKeyGenerator"/> used to generate module keys.</param> /// <param name="contextFactory">The <see cref="INancyContextFactory"/> that should be used to create a context instance.</param> /// <param name="routeSegmentExtractor"> </param> public NancyRebuildableCache(INancyModuleCatalog moduleCatalog, IModuleKeyGenerator moduleKeyGenerator, INancyContextFactory contextFactory) : base(moduleCatalog, moduleKeyGenerator, contextFactory) { this.moduleKeyGenerator = moduleKeyGenerator; //this.routeSegmentExtractor = routeSegmentExtractor; //this.routeDescriptionProvider = routeDescriptionProvider; this.contextFactory = contextFactory; this.moduleCatalog = moduleCatalog; }
/// <summary> /// Initializes a new instance of the <see cref="RouteCache"/> class. /// </summary> /// <param name="moduleCatalog">The <see cref="INancyModuleCatalog"/> that should be used by the cache.</param> /// <param name="moduleKeyGenerator">The <see cref="IModuleKeyGenerator"/> used to generate module keys.</param> /// <param name="contextFactory">The <see cref="INancyContextFactory"/> that should be used to create a context instance.</param> public RouteCache(INancyModuleCatalog moduleCatalog, IModuleKeyGenerator moduleKeyGenerator, INancyContextFactory contextFactory) { this.moduleKeyGenerator = moduleKeyGenerator; using (var context = contextFactory.Create()) { this.BuildCache(moduleCatalog.GetAllModules(context)); } }
/// <summary> /// Initializes a new instance of the <see cref="RouteCache"/> class. /// </summary> /// <param name="moduleCatalog">The <see cref="INancyModuleCatalog"/> that should be used by the cache.</param> /// <param name="moduleKeyGenerator">The <see cref="IModuleKeyGenerator"/> used to generate module keys.</param> /// <param name="contextFactory">The <see cref="INancyContextFactory"/> that should be used to create a context instance.</param> /// <param name="routeSegmentExtractor"> </param> public RouteCache(INancyModuleCatalog moduleCatalog, IModuleKeyGenerator moduleKeyGenerator, INancyContextFactory contextFactory, IRouteSegmentExtractor routeSegmentExtractor, IRouteDescriptionProvider routeDescriptionProvider) { this.moduleKeyGenerator = moduleKeyGenerator; this.routeSegmentExtractor = routeSegmentExtractor; this.routeDescriptionProvider = routeDescriptionProvider; using (var context = contextFactory.Create()) { this.BuildCache(moduleCatalog.GetAllModules(context)); } }
/// <summary> /// Returns available NancyModule types /// </summary> /// <returns>IEnumerable containing all NancyModule Type definitions</returns> protected virtual IEnumerable <ModuleRegistration> GetModuleTypes(IModuleKeyGenerator moduleKeyGenerator) { var moduleType = typeof(NancyModule); var locatedModuleTypes = from type in AppDomainAssemblyTypeScanner.Types where moduleType.IsAssignableFrom(type) select new ModuleRegistration(type, moduleKeyGenerator.GetKeyForModuleType(type)); return(locatedModuleTypes); }
/// <summary> /// Initializes a new instance of the <see cref="RouteCache"/> class. /// </summary> /// <param name="moduleCatalog">The <see cref="INancyModuleCatalog"/> that should be used by the cache.</param> /// <param name="moduleKeyGenerator">The <see cref="IModuleKeyGenerator"/> used to generate module keys.</param> /// <param name="contextFactory">The <see cref="INancyContextFactory"/> that should be used to create a context instance.</param> /// <param name="routeSegmentExtractor"> </param> public RouteCache(INancyModuleCatalog moduleCatalog, IModuleKeyGenerator moduleKeyGenerator, INancyContextFactory contextFactory, IRouteSegmentExtractor routeSegmentExtractor, IRouteDescriptionProvider routeDescriptionProvider, ICultureService cultureService) { this.moduleKeyGenerator = moduleKeyGenerator; this.routeSegmentExtractor = routeSegmentExtractor; this.routeDescriptionProvider = routeDescriptionProvider; var request = new Request("GET", "/", "http"); using (var context = contextFactory.Create(request)) { this.BuildCache(moduleCatalog.GetAllModules(context)); } }
public DiagnosticsModuleCatalog(IModuleKeyGenerator keyGenerator, IEnumerable <IDiagnosticsProvider> providers, IRootPathProvider rootPathProvider, IRequestTracing requestTracing, NancyInternalConfiguration configuration, DiagnosticsConfiguration diagnosticsConfiguration) { this.container = ConfigureContainer(keyGenerator, providers, rootPathProvider, requestTracing, configuration, diagnosticsConfiguration); }
public DiagnosticsModuleCatalog(IModuleKeyGenerator keyGenerator, IEnumerable<IDiagnosticsProvider> providers, IRootPathProvider rootPathProvider, IRequestTracing requestTracing, NancyInternalConfiguration configuration, DiagnosticsConfiguration diagnosticsConfiguration) { this.container = ConfigureContainer(keyGenerator, providers, rootPathProvider, requestTracing, configuration, diagnosticsConfiguration); }
/// <summary> /// Configures the bootstrapper to use the provided instance of <see cref="IModuleKeyGenerator"/>. /// </summary> /// <param name="moduleKeyGenerator">The <see cref="IModuleKeyGenerator"/> instance that should be used by the bootstrapper.</param> /// <returns>An instance to the current <see cref="FakeNancyBootstrapperConfigurator"/>.</returns> public FakeNancyBootstrapperConfigurator ModuleKeyGenerator(IModuleKeyGenerator moduleKeyGenerator) { this.bootstrapper.configuredInstances[typeof(IModuleKeyGenerator)] = moduleKeyGenerator; return(this); }
protected override IEnumerable <ModuleRegistration> GetModuleTypes(IModuleKeyGenerator moduleKeyGenerator) { return(ModuleRegistrations); }