/// <summary> /// Initializes a new instance of the <see cref="NancyEngine"/> class. /// </summary> /// <param name="dispatcher">An <see cref="IRouteResolver"/> instance that will be used to resolve a route, from the modules, that matches the incoming <see cref="Request"/>.</param> /// <param name="contextFactory">A factory for creating contexts</param> /// <param name="statusCodeHandlers">Error handlers</param> /// <param name="requestTracing">The request tracing instance.</param> /// <param name="diagnosticsConfiguration"></param> /// <param name="staticContentProvider">The provider to use for serving static content</param> public NancyEngine(IRequestDispatcher dispatcher, INancyContextFactory contextFactory, IEnumerable<IStatusCodeHandler> statusCodeHandlers, IRequestTracing requestTracing, DiagnosticsConfiguration diagnosticsConfiguration, IStaticContentProvider staticContentProvider) { if (dispatcher == null) { throw new ArgumentNullException("dispatcher", "The resolver parameter cannot be null."); } if (contextFactory == null) { throw new ArgumentNullException("contextFactory"); } if (statusCodeHandlers == null) { throw new ArgumentNullException("statusCodeHandlers"); } if (requestTracing == null) { throw new ArgumentNullException("requestTracing"); } if (staticContentProvider == null) { throw new ArgumentNullException("staticContentProvider"); } this.dispatcher = dispatcher; this.contextFactory = contextFactory; this.statusCodeHandlers = statusCodeHandlers; this.requestTracing = requestTracing; this.diagnosticsConfiguration = diagnosticsConfiguration; this.staticContentProvider = staticContentProvider; }
/// <summary> /// Initializes a new instance of the <see cref="NancyEngine"/> class. /// </summary> /// <param name="resolver">An <see cref="IRouteResolver"/> instance that will be used to resolve a route, from the modules, that matches the incoming <see cref="Request"/>.</param> /// <param name="routeCache">Cache of all available routes</param> /// <param name="contextFactory">A factory for creating contexts</param> /// <param name="errorHandler">Error handler</param> public NancyEngine(IRouteResolver resolver, IRouteCache routeCache, INancyContextFactory contextFactory, IErrorHandler errorHandler) { if (resolver == null) { throw new ArgumentNullException("resolver", "The resolver parameter cannot be null."); } if (routeCache == null) { throw new ArgumentNullException("routeCache", "The routeCache parameter cannot be null."); } if (contextFactory == null) { throw new ArgumentNullException("contextFactory"); } if (errorHandler == null) { throw new ArgumentNullException("errorHandler"); } this.resolver = resolver; this.routeCache = routeCache; this.contextFactory = contextFactory; this.errorHandler = errorHandler; }
/// <summary> /// Initializes a new instance of the <see cref="NancyEngine"/> class. /// </summary> /// <param name="resolver">An <see cref="IRouteResolver"/> instance that will be used to resolve a route, from the modules, that matches the incoming <see cref="Request"/>.</param> /// <param name="contextFactory">A factory for creating contexts</param> /// <param name="errorHandlers">Error handlers</param> public NancyEngine(IRouteResolver resolver, INancyContextFactory contextFactory, IEnumerable <IErrorHandler> errorHandlers, IRequestTracing requestTracing) { if (resolver == null) { throw new ArgumentNullException("resolver", "The resolver parameter cannot be null."); } //if (routeCache == null) //{ // throw new ArgumentNullException("routeCache", "The routeCache parameter cannot be null."); //} if (contextFactory == null) { throw new ArgumentNullException("contextFactory"); } if (errorHandlers == null) { throw new ArgumentNullException("errorHandlers"); } this.resolver = resolver; //this.routeCache = routeCache; this.contextFactory = contextFactory; this.errorHandlers = errorHandlers; this.requestTracing = requestTracing; }
/// <summary> /// Initializes a new instance of the <see cref="NancyEngine"/> class. /// </summary> /// <param name="dispatcher">An <see cref="IRouteResolver"/> instance that will be used to resolve a route, from the modules, that matches the incoming <see cref="Request"/>.</param> /// <param name="contextFactory">A factory for creating contexts</param> /// <param name="statusCodeHandlers">Error handlers</param> /// <param name="requestTracing">The request tracing instance.</param> /// <param name="diagnosticsConfiguration"></param> /// <param name="staticContentProvider">The provider to use for serving static content</param> public NancyEngine(IRequestDispatcher dispatcher, INancyContextFactory contextFactory, IEnumerable <IStatusCodeHandler> statusCodeHandlers, IRequestTracing requestTracing, DiagnosticsConfiguration diagnosticsConfiguration, IStaticContentProvider staticContentProvider) { if (dispatcher == null) { throw new ArgumentNullException("dispatcher", "The resolver parameter cannot be null."); } if (contextFactory == null) { throw new ArgumentNullException("contextFactory"); } if (statusCodeHandlers == null) { throw new ArgumentNullException("statusCodeHandlers"); } if (requestTracing == null) { throw new ArgumentNullException("requestTracing"); } if (staticContentProvider == null) { throw new ArgumentNullException("staticContentProvider"); } this.dispatcher = dispatcher; this.contextFactory = contextFactory; this.statusCodeHandlers = statusCodeHandlers; this.requestTracing = requestTracing; this.diagnosticsConfiguration = diagnosticsConfiguration; this.staticContentProvider = staticContentProvider; }
public NancyEngineFixture() { this.resolver = A.Fake<IRouteResolver>(); this.response = new Response(); this.route = new FakeRoute(response); this.context = new NancyContext(); this.errorHandler = A.Fake<IErrorHandler>(); this.requestDispatcher = A.Fake<IRequestDispatcher>(); A.CallTo(() => this.requestDispatcher.Dispatch(A<NancyContext>._)).Invokes(x => this.context.Response = new Response()); A.CallTo(() => errorHandler.HandlesStatusCode(A<HttpStatusCode>.Ignored, A<NancyContext>.Ignored)).Returns(false); contextFactory = A.Fake<INancyContextFactory>(); A.CallTo(() => contextFactory.Create()).Returns(context); A.CallTo(() => resolver.Resolve(A<NancyContext>.Ignored)).Returns(new ResolveResult(route, DynamicDictionary.Empty, null, null, null)); var applicationPipelines = new Pipelines(); this.routeInvoker = A.Fake<IRouteInvoker>(); A.CallTo(() => this.routeInvoker.Invoke(A<Route>._, A<DynamicDictionary>._, A<NancyContext>._)).ReturnsLazily(arg => { return (Response)((Route)arg.Arguments[0]).Action.Invoke((DynamicDictionary)arg.Arguments[1]); }); this.engine = new NancyEngine(this.requestDispatcher, contextFactory, new[] { this.errorHandler }, A.Fake<IRequestTracing>()) { RequestPipelinesFactory = ctx => applicationPipelines }; }
/// <summary> /// Initializes a new instance of the <see cref="NancyEngine"/> class. /// </summary> /// <param name="resolver">An <see cref="IRouteResolver"/> instance that will be used to resolve a route, from the modules, that matches the incoming <see cref="Request"/>.</param> /// <param name="routeCache">Cache of all available routes</param> /// <param name="contextFactory">A factory for creating contexts</param> /// <param name="errorHandlers">Error handlers</param> public NancyEngine(IRouteResolver resolver, IRouteCache routeCache, INancyContextFactory contextFactory, IEnumerable<IErrorHandler> errorHandlers) { if (resolver == null) { throw new ArgumentNullException("resolver", "The resolver parameter cannot be null."); } if (routeCache == null) { throw new ArgumentNullException("routeCache", "The routeCache parameter cannot be null."); } if (contextFactory == null) { throw new ArgumentNullException("contextFactory"); } if (errorHandlers == null) { throw new ArgumentNullException("errorHandlers"); } this.resolver = resolver; this.routeCache = routeCache; this.contextFactory = contextFactory; this.errorHandlers = errorHandlers; }
public NancyEngineFixture() { this.resolver = A.Fake<IRouteResolver>(); this.response = new Response(); this.route = new FakeRoute(response); this.context = new NancyContext(); this.statusCodeHandler = A.Fake<IStatusCodeHandler>(); this.requestDispatcher = A.Fake<IRequestDispatcher>(); this.diagnosticsConfiguration = new DiagnosticsConfiguration(); A.CallTo(() => this.requestDispatcher.Dispatch(A<NancyContext>._, A<CancellationToken>._)).Invokes((x) => this.context.Response = new Response()); A.CallTo(() => this.statusCodeHandler.HandlesStatusCode(A<HttpStatusCode>.Ignored, A<NancyContext>.Ignored)).Returns(false); contextFactory = A.Fake<INancyContextFactory>(); A.CallTo(() => contextFactory.Create(A<Request>._)).Returns(context); var resolveResult = new ResolveResult { Route = route, Parameters = DynamicDictionary.Empty, Before = null, After = null, OnError = null }; A.CallTo(() => resolver.Resolve(A<NancyContext>.Ignored)).Returns(resolveResult); var applicationPipelines = new Pipelines(); this.routeInvoker = A.Fake<IRouteInvoker>(); A.CallTo(() => this.routeInvoker.Invoke(A<Route>._, A<CancellationToken>._, A<DynamicDictionary>._, A<NancyContext>._)).ReturnsLazily(arg => { return ((Route)arg.Arguments[0]).Action.Invoke((DynamicDictionary)arg.Arguments[1], A<CancellationToken>._).Result; }); this.engine = new NancyEngine(this.requestDispatcher, this.contextFactory, new[] { this.statusCodeHandler }, A.Fake<IRequestTracing>(), this.diagnosticsConfiguration, new DisabledStaticContentProvider()) { RequestPipelinesFactory = ctx => applicationPipelines }; }
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)).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 SimpleInjectorScopedContextFactory( SimpleInjector.Container container, INancyContextFactory @default) { this.container = container; defaultFactory = @default; }
public NancyEngineFixture() { this.resolver = A.Fake <IRouteResolver>(); this.response = new Response(); this.route = new FakeRoute(response); this.context = new NancyContext(); this.errorHandler = A.Fake <IErrorHandler>(); this.requestDispatcher = A.Fake <IRequestDispatcher>(); A.CallTo(() => this.requestDispatcher.Dispatch(A <NancyContext> ._)).Invokes(x => this.context.Response = new Response()); A.CallTo(() => errorHandler.HandlesStatusCode(A <HttpStatusCode> .Ignored, A <NancyContext> .Ignored)).Returns(false); contextFactory = A.Fake <INancyContextFactory>(); A.CallTo(() => contextFactory.Create()).Returns(context); A.CallTo(() => resolver.Resolve(A <NancyContext> .Ignored)).Returns(new ResolveResult(route, DynamicDictionary.Empty, null, null, null)); var applicationPipelines = new Pipelines(); this.routeInvoker = A.Fake <IRouteInvoker>(); A.CallTo(() => this.routeInvoker.Invoke(A <Route> ._, A <DynamicDictionary> ._, A <NancyContext> ._)).ReturnsLazily(arg => { return((Response)((Route)arg.Arguments[0]).Action.Invoke((DynamicDictionary)arg.Arguments[1])); }); this.engine = new NancyEngine(this.requestDispatcher, contextFactory, new[] { this.errorHandler }, A.Fake <IRequestTracing>()) { RequestPipelinesFactory = ctx => applicationPipelines }; }
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]); }
/// <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="contextFactory">The <see cref="INancyContextFactory"/> that should be used to create a context instance.</param> /// <param name="routeSegmentExtractor"> </param> public RouteCache(INancyModuleCatalog moduleCatalog, INancyContextFactory contextFactory, IRouteSegmentExtractor routeSegmentExtractor, IRouteDescriptionProvider routeDescriptionProvider, ICultureService cultureService) { this.routeSegmentExtractor = routeSegmentExtractor; this.routeDescriptionProvider = routeDescriptionProvider; var request = new Request("GET", "/", "http"); using (var context = contextFactory.Create(request)) { this.BuildCache(moduleCatalog.GetAllModules(context)); } }
public NancyEngineFixture() { this.resolver = A.Fake <IRouteResolver>(); this.response = new Response(); this.route = new FakeRoute(response); this.context = new NancyContext(); contextFactory = A.Fake <INancyContextFactory>(); A.CallTo(() => contextFactory.Create()).Returns(context); A.CallTo(() => resolver.Resolve(A <NancyContext> .Ignored, A <IRouteCache> .Ignored)).Returns(new ResolveResult(route, DynamicDictionary.Empty, null, null)); this.engine = new NancyEngine(resolver, A.Fake <IRouteCache>(), contextFactory); }
public NancyEngineFixture() { this.resolver = A.Fake<IRouteResolver>(); this.response = new Response(); this.route = new FakeRoute(response); this.context = new NancyContext(); contextFactory = A.Fake<INancyContextFactory>(); A.CallTo(() => contextFactory.Create()).Returns(context); A.CallTo(() => resolver.Resolve(A<NancyContext>.Ignored, A<IRouteCache>.Ignored.Argument)).Returns(new ResolveResult(route, DynamicDictionary.Empty, null, null)); this.engine = new NancyEngine(resolver, A.Fake<IRouteCache>(), contextFactory); }
private TCommand GetUseCaseFromQueryString(INancyContextFactory contextFactory) { var context = contextFactory.Create(Request); foreach (var key in context.Request.Query) { context.Request.Form.Add(key, context.Request.Query[key]); } var binder = ModelBinderLocator.GetBinderForType(typeof(TCommand), context); var useCase = (TCommand)binder.Bind(context, typeof(TCommand), null, BindingConfig.Default); return(useCase); }
public NancyEngineWithAsyncCancellation( IRequestDispatcher requestDispatcher, INancyContextFactory nancyContextFactory, IEnumerable <IStatusCodeHandler> statusCodeHandlers, IRequestTracing requestTracing, DiagnosticsConfiguration diagnosticsConfiguration, IStaticContentProvider staticContentProvider) { this.engine = new NancyEngine( requestDispatcher, nancyContextFactory, statusCodeHandlers, requestTracing, diagnosticsConfiguration, staticContentProvider); }
public NancyEngineWithAsyncCancellation( IRequestDispatcher requestDispatcher, INancyContextFactory nancyContextFactory, IEnumerable<IStatusCodeHandler> statusCodeHandlers, IRequestTracing requestTracing, DiagnosticsConfiguration diagnosticsConfiguration, IStaticContentProvider staticContentProvider) { this.engine = new NancyEngine( requestDispatcher, nancyContextFactory, statusCodeHandlers, requestTracing, diagnosticsConfiguration, staticContentProvider); }
/// <summary> /// Initializes a new instance of the <see cref="NancyEngine"/> class. /// </summary> /// <param name="dispatcher">An <see cref="IRouteResolver"/> instance that will be used to resolve a route, from the modules, that matches the incoming <see cref="Request"/>.</param> /// <param name="contextFactory">A factory for creating contexts</param> /// <param name="statusCodeHandlers">Error handlers</param> /// <param name="requestTracing">The request tracing instance.</param> /// <param name="staticContentProvider">The provider to use for serving static content</param> /// <param name="negotiator">The response negotiator.</param> /// <param name="environment">An <see cref="INancyEnvironment"/> instance.</param> public NancyEngine(IRequestDispatcher dispatcher, INancyContextFactory contextFactory, IEnumerable <IStatusCodeHandler> statusCodeHandlers, IRequestTracing requestTracing, IStaticContentProvider staticContentProvider, IResponseNegotiator negotiator, INancyEnvironment environment) { if (dispatcher == null) { throw new ArgumentNullException("dispatcher", "The resolver parameter cannot be null."); } if (contextFactory == null) { throw new ArgumentNullException("contextFactory"); } if (statusCodeHandlers == null) { throw new ArgumentNullException("statusCodeHandlers"); } if (requestTracing == null) { throw new ArgumentNullException("requestTracing"); } if (staticContentProvider == null) { throw new ArgumentNullException("staticContentProvider"); } if (negotiator == null) { throw new ArgumentNullException("negotiator"); } this.dispatcher = dispatcher; this.contextFactory = contextFactory; this.statusCodeHandlers = statusCodeHandlers.ToArray(); this.requestTracing = requestTracing; this.staticContentProvider = staticContentProvider; this.negotiator = negotiator; this.engineDisposedCts = new CancellationTokenSource(); this.traceConfiguration = environment.GetValue <TraceConfiguration>(); }
/// <summary> /// Initializes a new instance of the <see cref="NancyEngine"/> class. /// </summary> /// <param name="dispatcher">An <see cref="IRouteResolver"/> instance that will be used to resolve a route, from the modules, that matches the incoming <see cref="Request"/>.</param> /// <param name="contextFactory">A factory for creating contexts</param> /// <param name="statusCodeHandlers">Error handlers</param> /// <param name="requestTracing">The request tracing instance.</param> /// <param name="staticContentProvider">The provider to use for serving static content</param> /// <param name="negotiator">The response negotiator.</param> /// <param name="environment">An <see cref="INancyEnvironment"/> instance.</param> public NancyEngine(IRequestDispatcher dispatcher, INancyContextFactory contextFactory, IEnumerable<IStatusCodeHandler> statusCodeHandlers, IRequestTracing requestTracing, IStaticContentProvider staticContentProvider, IResponseNegotiator negotiator, INancyEnvironment environment) { if (dispatcher == null) { throw new ArgumentNullException("dispatcher", "The resolver parameter cannot be null."); } if (contextFactory == null) { throw new ArgumentNullException("contextFactory"); } if (statusCodeHandlers == null) { throw new ArgumentNullException("statusCodeHandlers"); } if (requestTracing == null) { throw new ArgumentNullException("requestTracing"); } if (staticContentProvider == null) { throw new ArgumentNullException("staticContentProvider"); } if (negotiator == null) { throw new ArgumentNullException("negotiator"); } this.dispatcher = dispatcher; this.contextFactory = contextFactory; this.statusCodeHandlers = statusCodeHandlers.ToArray(); this.requestTracing = requestTracing; this.staticContentProvider = staticContentProvider; this.negotiator = negotiator; this.engineDisposedCts = new CancellationTokenSource(); this.traceConfiguration = environment.GetValue<TraceConfiguration>(); }
public NancyEngineFixture() { this.resolver = A.Fake<IRouteResolver>(); this.response = new Response(); this.route = new FakeRoute(response); this.context = new NancyContext(); this.errorHandler = A.Fake<IErrorHandler>(); A.CallTo(() => errorHandler.HandlesStatusCode(A<HttpStatusCode>.Ignored)).Returns(false); contextFactory = A.Fake<INancyContextFactory>(); A.CallTo(() => contextFactory.Create()).Returns(context); A.CallTo(() => resolver.Resolve(A<NancyContext>.Ignored, A<IRouteCache>.Ignored)).Returns(new ResolveResult(route, DynamicDictionary.Empty, null, null)); this.engine = new NancyEngine(resolver, A.Fake<IRouteCache>(), contextFactory, this.errorHandler); }
public NancyEngineFixture() { this.environment = new DefaultNancyEnvironment(); this.environment.Tracing( enabled: true, displayErrorTraces: true); this.resolver = A.Fake <IRouteResolver>(); this.response = new Response(); this.route = new FakeRoute(response); this.context = new NancyContext(); this.statusCodeHandler = A.Fake <IStatusCodeHandler>(); this.requestDispatcher = A.Fake <IRequestDispatcher>(); this.negotiator = A.Fake <IResponseNegotiator>(); A.CallTo(() => this.requestDispatcher.Dispatch(A <NancyContext> ._, A <CancellationToken> ._)) .Returns(Task.FromResult(new Response())); A.CallTo(() => this.statusCodeHandler.HandlesStatusCode(A <HttpStatusCode> .Ignored, A <NancyContext> .Ignored)).Returns(false); contextFactory = A.Fake <INancyContextFactory>(); A.CallTo(() => contextFactory.Create(A <Request> ._)).Returns(context); var resolveResult = new ResolveResult { Route = route, Parameters = DynamicDictionary.Empty, Before = null, After = null, OnError = null }; A.CallTo(() => resolver.Resolve(A <NancyContext> .Ignored)).Returns(resolveResult); var applicationPipelines = new Pipelines(); this.routeInvoker = A.Fake <IRouteInvoker>(); A.CallTo(() => this.routeInvoker.Invoke(A <Route> ._, A <CancellationToken> ._, A <DynamicDictionary> ._, A <NancyContext> ._)).ReturnsLazily(arg => { return(((Route)arg.Arguments[0]).Action.Invoke((DynamicDictionary)arg.Arguments[1], A <CancellationToken> ._).Result); }); this.engine = new NancyEngine(this.requestDispatcher, this.contextFactory, new[] { this.statusCodeHandler }, A.Fake <IRequestTracing>(), new DisabledStaticContentProvider(), this.negotiator, this.environment) { RequestPipelinesFactory = ctx => applicationPipelines }; }
protected CommandModule(IBus bus, INancyContextFactory contextFactory) : base("/dispatcher/" + typeof(TCommand).Name.Underscore().Dasherize()) { Get["/"] = p => { var useCase = GetUseCaseFromQueryString(contextFactory); var viewModel = new CommandFormViewModel <TCommand>(useCase, ModulePath); return(Negotiate.WithModel(viewModel).WithView("get")); }; Post["/"] = p => { var command = this.Bind <TCommand>(); bus.Send(command); return(OnDispatched()); }; }
/// <summary> /// Initializes a new instance of the <see cref="NancyEngine"/> class. /// </summary> /// <param name="resolver">An <see cref="IRouteResolver"/> instance that will be used to resolve a route, from the modules, that matches the incoming <see cref="Request"/>.</param> /// <param name="routeCache">Cache of all available routes</param> /// <param name="contextFactory">A factory for creating contexts</param> public NancyEngine(IRouteResolver resolver, IRouteCache routeCache, INancyContextFactory contextFactory) { if (resolver == null) { throw new ArgumentNullException("resolver", "The resolver parameter cannot be null."); } if (routeCache == null) { throw new ArgumentNullException("routeCache", "The routeCache parameter cannot be null."); } if (contextFactory == null) { throw new ArgumentNullException("contextFactory"); } this.resolver = resolver; this.routeCache = routeCache; this.contextFactory = contextFactory; }
/// <summary> /// Initializes a new instance of the <see cref="NancyEngine"/> class. /// </summary> /// <param name="dispatcher">An <see cref="IRouteResolver"/> instance that will be used to resolve a route, from the modules, that matches the incoming <see cref="Request"/>.</param> /// <param name="contextFactory">A factory for creating contexts</param> /// <param name="errorHandlers">Error handlers</param> /// <param name="requestTracing">The request tracing instance.</param> public NancyEngine(IRequestDispatcher dispatcher, INancyContextFactory contextFactory, IEnumerable<IErrorHandler> errorHandlers, IRequestTracing requestTracing) { if (dispatcher == null) { throw new ArgumentNullException("dispatcher", "The resolver parameter cannot be null."); } if (contextFactory == null) { throw new ArgumentNullException("contextFactory"); } if (errorHandlers == null) { throw new ArgumentNullException("errorHandlers"); } this.dispatcher = dispatcher; this.contextFactory = contextFactory; this.errorHandlers = errorHandlers; this.requestTracing = requestTracing; }
/// <summary> /// Initializes a new instance of the <see cref="NancyEngine"/> class. /// </summary> /// <param name="dispatcher">An <see cref="IRouteResolver"/> instance that will be used to resolve a route, from the modules, that matches the incoming <see cref="Request"/>.</param> /// <param name="contextFactory">A factory for creating contexts</param> /// <param name="errorHandlers">Error handlers</param> /// <param name="requestTracing">The request tracing instance.</param> public NancyEngine(IRequestDispatcher dispatcher, INancyContextFactory contextFactory, IEnumerable <IErrorHandler> errorHandlers, IRequestTracing requestTracing) { if (dispatcher == null) { throw new ArgumentNullException("dispatcher", "The resolver parameter cannot be null."); } if (contextFactory == null) { throw new ArgumentNullException("contextFactory"); } if (errorHandlers == null) { throw new ArgumentNullException("errorHandlers"); } this.dispatcher = dispatcher; this.contextFactory = contextFactory; this.errorHandlers = errorHandlers; this.requestTracing = requestTracing; }
public NancyEngineFixture() { this.environment = new DefaultNancyEnvironment(); this.environment.Tracing( enabled: true, displayErrorTraces: true); this.resolver = A.Fake<IRouteResolver>(); this.response = new Response(); this.route = new FakeRoute(response); this.context = new NancyContext(); this.statusCodeHandler = A.Fake<IStatusCodeHandler>(); this.requestDispatcher = A.Fake<IRequestDispatcher>(); this.negotiator = A.Fake<IResponseNegotiator>(); A.CallTo(() => this.requestDispatcher.Dispatch(A<NancyContext>._, A<CancellationToken>._)) .Returns(Task.FromResult(new Response())); A.CallTo(() => this.statusCodeHandler.HandlesStatusCode(A<HttpStatusCode>.Ignored, A<NancyContext>.Ignored)).Returns(false); contextFactory = A.Fake<INancyContextFactory>(); A.CallTo(() => contextFactory.Create(A<Request>._)).Returns(context); var resolveResult = new ResolveResult { Route = route, Parameters = DynamicDictionary.Empty, Before = null, After = null, OnError = null }; A.CallTo(() => resolver.Resolve(A<NancyContext>.Ignored)).Returns(resolveResult); var applicationPipelines = new Pipelines(); this.routeInvoker = A.Fake<IRouteInvoker>(); this.engine = new NancyEngine(this.requestDispatcher, this.contextFactory, new[] { this.statusCodeHandler }, A.Fake<IRequestTracing>(), new DisabledStaticContentProvider(), this.negotiator, this.environment) { RequestPipelinesFactory = ctx => applicationPipelines }; }
public NancyEngineFixture() { this.resolver = A.Fake <IRouteResolver>(); this.response = new Response(); this.route = new FakeRoute(response); this.context = new NancyContext(); this.statusCodeHandler = A.Fake <IStatusCodeHandler>(); this.requestDispatcher = A.Fake <IRequestDispatcher>(); this.diagnosticsConfiguration = new DiagnosticsConfiguration(); A.CallTo(() => this.requestDispatcher.Dispatch(A <NancyContext> ._)).Invokes(x => this.context.Response = new Response()); A.CallTo(() => this.statusCodeHandler.HandlesStatusCode(A <HttpStatusCode> .Ignored, A <NancyContext> .Ignored)).Returns(false); contextFactory = A.Fake <INancyContextFactory>(); A.CallTo(() => contextFactory.Create(A <Request> ._)).Returns(context); var resolveResult = new ResolveResult { Route = route, Parameters = DynamicDictionary.Empty, Before = null, After = null, OnError = null }; A.CallTo(() => resolver.Resolve(A <NancyContext> .Ignored)).Returns(resolveResult); var applicationPipelines = new Pipelines(); this.routeInvoker = A.Fake <IRouteInvoker>(); A.CallTo(() => this.routeInvoker.Invoke(A <Route> ._, A <DynamicDictionary> ._, A <NancyContext> ._)).ReturnsLazily(arg => { return((Response)((Route)arg.Arguments[0]).Action.Invoke((DynamicDictionary)arg.Arguments[1])); }); this.engine = new NancyEngine(this.requestDispatcher, this.contextFactory, new[] { this.statusCodeHandler }, A.Fake <IRequestTracing>(), this.diagnosticsConfiguration, new DisabledStaticContentProvider()) { RequestPipelinesFactory = ctx => applicationPipelines }; }
public NancyEngineFixture() { this.resolver = A.Fake<IRouteResolver>(); this.response = new Response(); this.route = new FakeRoute(response); this.context = new NancyContext(); this.errorHandler = A.Fake<IErrorHandler>(); A.CallTo(() => errorHandler.HandlesStatusCode(A<HttpStatusCode>.Ignored, A<NancyContext>.Ignored)).Returns(false); contextFactory = A.Fake<INancyContextFactory>(); A.CallTo(() => contextFactory.Create()).Returns(context); A.CallTo(() => resolver.Resolve(A<NancyContext>.Ignored)).Returns(new ResolveResult(route, DynamicDictionary.Empty, null, null)); var applicationPipelines = new Pipelines(); this.engine = new NancyEngine(resolver, contextFactory, new[] { this.errorHandler }, A.Fake<IRequestTracing>()) { RequestPipelinesFactory = ctx => applicationPipelines }; }
public NancyEngineFixture() { this.resolver = A.Fake <IRouteResolver>(); this.response = new Response(); this.route = new FakeRoute(response); this.context = new NancyContext(); this.errorHandler = A.Fake <IErrorHandler>(); A.CallTo(() => errorHandler.HandlesStatusCode(A <HttpStatusCode> .Ignored, A <NancyContext> .Ignored)).Returns(false); contextFactory = A.Fake <INancyContextFactory>(); A.CallTo(() => contextFactory.Create()).Returns(context); A.CallTo(() => resolver.Resolve(A <NancyContext> .Ignored)).Returns(new ResolveResult(route, DynamicDictionary.Empty, null, null)); var applicationPipelines = new Pipelines(); this.engine = new NancyEngine(resolver, contextFactory, new[] { this.errorHandler }, A.Fake <IRequestTracing>()) { RequestPipelinesFactory = ctx => applicationPipelines }; }
public NoHandlerRegisteredModule(IBus bus, INancyContextFactory contextFactory) : base(bus, contextFactory) { }
/// <summary> /// Configures the bootstrapper to use the provided instance of <see cref="INancyContextFactory"/>. /// </summary> /// <param name="nancyContextFactory">The <see cref="INancyContextFactory"/> instance that should be used by the bootstrapper.</param> /// <returns>An instance to the current <see cref="FakeNancyBootstrapperConfigurator"/>.</returns> public FakeNancyBootstrapperConfigurator ContextFactory(INancyContextFactory nancyContextFactory) { this.bootstrapper.configuredInstances[typeof(INancyContextFactory)] = nancyContextFactory; return(this); }
public TestCommandModule(IBus bus, INancyContextFactory contextFactory) : base(bus, contextFactory) { }
public RouteCache(INancyModuleCatalog moduleCatalog, IModuleKeyGenerator moduleKeyGenerator, INancyContextFactory contextFactory) { this.moduleKeyGenerator = moduleKeyGenerator; this.BuildCache(moduleCatalog.GetAllModules(contextFactory.Create())); }
public FakeEngine(IRouteResolver resolver, IRouteCache routeCache, INancyContextFactory contextFactory) { Resolver = resolver ?? throw new ArgumentNullException(nameof(resolver), "The resolver parameter cannot be null."); RouteCache = routeCache ?? throw new ArgumentNullException(nameof(routeCache), "The routeCache parameter cannot be null."); ContextFactory = contextFactory ?? throw new ArgumentNullException(nameof(contextFactory)); }
public DeleteAllTheStreamsModule(IBus bus, INancyContextFactory contextFactory) : base(bus, contextFactory) { }
/// <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) { this.moduleKeyGenerator = moduleKeyGenerator; this.routeSegmentExtractor = routeSegmentExtractor; using (var context = contextFactory.Create()) { this.BuildCache(moduleCatalog.GetAllModules(context)); } }
public PingMeModule(IBus bus, INancyContextFactory contextFactory) : base(bus, contextFactory) { }