public static void Initialize() { var bootstrapper = new WebBootstrapper(); bootstrapper.Initialise(); _engine = bootstrapper.GetEngine(); //_host = new NancyOwinHost(null, NancyBootstrapperLocator.Bootstrapper); }
/// <summary> /// Initializes a new instance of the <see cref="Browser"/> class. /// </summary> /// <param name="bootstrapper">A <see cref="INancyBootstrapper"/> instance that determines the Nancy configuration that should be used by the browser.</param> /// <param name="defaults">The default <see cref="BrowserContext"/> that should be used in a all requests through this browser object.</param> public Browser(INancyBootstrapper bootstrapper, Action <BrowserContext> defaults = null) { bootstrapper.Initialise(); this.engine = bootstrapper.GetEngine(); this.environment = bootstrapper.GetEnvironment(); this.defaultBrowserContext = defaults ?? DefaultBrowserContext; }
/// <summary> /// Initializes a new instance of the <see cref="NancyOwinHost"/> class. /// </summary> /// <param name="next">Next middleware to run if necessary</param> /// <param name="options">The nancy options that should be used by the host.</param> public NancyOwinHost(Func <IDictionary <string, object>, Task> next, NancyOptions options) { this.next = next; this.options = options; options.Bootstrapper.Initialise(); this.engine = options.Bootstrapper.GetEngine(); }
/// <summary> /// Initializes a new instance of the <see cref="Browser"/> class. /// </summary> /// <param name="bootstrapper">A <see cref="INancyBootstrapper"/> instance that determines the Nancy configuration that should be used by the browser.</param> /// <param name="defaults">The default <see cref="BrowserContext"/> that should be used in a all requests through this browser object.</param> public Browser(INancyBootstrapper bootstrapper, Action<BrowserContext> defaults = null) { this.bootstrapper = bootstrapper; this.bootstrapper.Initialise(); this.engine = this.bootstrapper.GetEngine(); this.defaultBrowserContext = defaults ?? DefaultBrowserContext; }
protected RequestSpec() { var locator = new NancyModuleLocator(Assembly.GetExecutingAssembly()); engine = new NancyEngine(locator, new RouteResolver()); }
public NancyEngineFixture() { this.modules = new[] { new FakeNancyModuleWithBasePath() }; this.locator = A.Fake <INancyModuleLocator>(); this.resolver = A.Fake <IRouteResolver>(); this.engine = new NancyEngine(this.locator, this.resolver); }
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 NancyOwinHostFixture() { this.fakeEngine = A.Fake <INancyEngine>(); this.fakeBootstrapper = A.Fake <INancyBootstrapper>(); A.CallTo(() => this.fakeBootstrapper.GetEngine()).Returns(this.fakeEngine); this.host = new NancyOwinHost(fakeBootstrapper); this.fakeResponseCallback = (status, headers, bodyDelegate) => { }; this.fakeErrorCallback = (ex) => { }; this.environment = new Dictionary <string, object>() { { "owin.RequestMethod", "GET" }, { "owin.RequestPath", "/test" }, { "owin.RequestPathBase", "/root" }, { "owin.RequestQueryString", "var=value" }, { "owin.RequestHeaders", new Dictionary <string, string>() }, { "owin.RequestBody", null }, { "owin.RequestScheme", "http" }, { "owin.Version", "1.0" } }; }
/// <summary> /// Initializes a new instance of the <see cref="Browser"/> class. /// </summary> /// <param name="bootstrapper">A <see cref="INancyBootstrapper"/> instance that determines the Nancy configuration that should be used by the browser.</param> /// <param name="defaults">The default <see cref="BrowserContext"/> that should be used in a all requests through this browser object.</param> public Browser(INancyBootstrapper bootstrapper, Action<BrowserContext> defaults = null, bool initialiseBootstrapper = true) { this.bootstrapper = bootstrapper; if (initialiseBootstrapper) this.bootstrapper.Initialise(); this.engine = this.bootstrapper.GetEngine(); this.defaultBrowserContext = defaults ?? this.DefaultBrowserContext; }
public NancyEngineFixture() { this.modules = new[] { new FakeNancyModuleWithBasePath() }; this.locator = A.Fake<INancyModuleLocator>(); this.resolver = A.Fake<IRouteResolver>(); this.engine = new NancyEngine(this.locator, this.resolver); }
public NancyAdapter(AppFunc next, INancyBootstrapper bootstrapper) { bootstrapper.Initialise(); _next = next; _engine = bootstrapper.GetEngine(); }
public NancyOwinHostFixture() { this.fakeEngine = A.Fake<INancyEngine>(); this.fakeBootstrapper = A.Fake<INancyBootstrapper>(); A.CallTo(() => this.fakeBootstrapper.GetEngine()).Returns(this.fakeEngine); this.host = new NancyOwinHost(fakeBootstrapper); this.fakeResponseCallback = (status, headers, bodyDelegate) => { }; this.fakeErrorCallback = (ex) => { }; this.environment = new Dictionary<string, object>() { { "owin.RequestMethod", "GET" }, { "owin.RequestPath", "/test" }, { "owin.RequestPathBase", "/root" }, { "owin.RequestQueryString", "var=value" }, { "owin.RequestHeaders", new Dictionary<string, string> { { "Host", "testserver" } } }, { "owin.RequestBody", null }, { "owin.RequestScheme", "http" }, { "owin.Version", "1.0" } }; }
public NancyEngineFixture() { this.application = A.Fake<INancyApplication>(); this.modules = NancyBootstrapper.BootstrapApplication().ModuleMetas; this.resolver = A.Fake<IRouteResolver>(); this.engine = new NancyEngine(this.resolver, this.application); }
public HttpHost(IPEndPoint endpoint) { var bootStrapper = NancyBootstrapperLocator.Bootstrapper; bootStrapper.Initialise(); m_Engine = bootStrapper.GetEngine(); m_EndPoint = endpoint; }
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 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 NancyOwinHostFixture() { this.fakeEngine = A.Fake <INancyEngine>(); this.fakeBootstrapper = A.Fake <INancyBootstrapper>(); A.CallTo(() => this.fakeBootstrapper.GetEngine()).Returns(this.fakeEngine); this.host = new NancyOwinHost(fakeBootstrapper); this.fakeResponseCallback = (status, headers, bodyDelegate) => { }; this.fakeErrorCallback = (ex) => { }; var tcs = new TaskCompletionSource <object>(); this.environment = new Dictionary <string, object>() { { "owin.RequestMethod", "GET" }, { "owin.RequestPath", "/test" }, { "owin.RequestPathBase", "/root" }, { "owin.RequestQueryString", "var=value" }, { "owin.RequestBody", Stream.Null }, { "owin.RequestHeaders", new Dictionary <string, string[]>(StringComparer.OrdinalIgnoreCase) }, { "owin.RequestScheme", "http" }, { "owin.ResponseHeaders", new Dictionary <string, string[]>(StringComparer.OrdinalIgnoreCase) }, { "owin.ResponseBody", Stream.Null }, { "owin.Version", "1.0" }, { "owin.CallCancelled", CancellationToken.None } }; this.requestHeaders = new Dictionary <string, string[]> { { "Host", new[] { "testserver" } } }; }
/// <summary> /// Initializes a new instance of the <see cref="Browser"/> class. /// </summary> /// <param name="bootstrapper">A <see cref="INancyBootstrapper"/> instance that determines the Nancy configuration that should be used by the browser.</param> /// <param name="defaults">The default <see cref="BrowserContext"/> that should be used in a all requests through this browser object.</param> public Browser(INancyBootstrapper bootstrapper, Action <BrowserContext> defaults = null) { this.bootstrapper = bootstrapper; this.bootstrapper.Initialise(); this.engine = this.bootstrapper.GetEngine(); this.defaultBrowserContext = defaults ?? this.DefaultBrowserContext; }
protected RequestSpec() { var defaultNancyBootstrapper = new DefaultNancyBootstrapper(); defaultNancyBootstrapper.Initialise(); engine = defaultNancyBootstrapper.GetEngine(); }
public NancyMiddleware(RequestDelegate next, NancyOptions options) { _next = next; _options = options; _options.Bootstrapper.Initialise(); _engine = _options.Bootstrapper.GetEngine(); }
public NancyHttpRequestHandler() { var bootstrapper = GetBootstrapper(); this.engine = bootstrapper.GetEngine(); }
public NancyHost(Uri baseUri, INancyBootstrapper bootStrapper) { this.baseUri = baseUri; listener = new HttpListener(); listener.Prefixes.Add(baseUri.ToString()); engine = bootStrapper.GetEngine(); }
protected static void InitNerdBeers() { var bs = new Org.NerdBeers.Specs.Modules.SpecBootStrapper(); bs.Initialise(); Engine = bs.GetEngine(); DB = bs.DB; Req = null; }
static NancyHttpRequestHandler() { var bootstrapper = GetBootstrapper(); bootstrapper.Initialise(); engine = bootstrapper.GetEngine(); }
public NancyEngineFixture() { this.modules = new NancyApplication(new DefaultModuleActivator()).GetModules(); this.locator = A.Fake<INancyModuleLocator>(); this.resolver = A.Fake<IRouteResolver>(); this.application = A.Fake<INancyApplication>(); this.engine = new NancyEngine(this.locator, this.resolver, this.application); }
protected RosannaSpecification() { var bootstrapper = new RosannaBootstrapper(); bootstrapper.Initialise(); Engine = bootstrapper.GetEngine(); Config = bootstrapper.Container.Resolve<IRosannaConfiguration>(); }
static NancyC1FunctionHost() { var bootstrapper = GetBootstrapper(); bootstrapper.Initialise(); Engine = bootstrapper.GetEngine(); }
/// <summary> /// Initializes a new instance of the <see cref="NancyHost"/> class for the specfied <paramref name="baseUris"/>, using /// the provided <paramref name="bootstrapper"/>. /// Uses the specified configuration. /// </summary> /// <param name="bootstrapper">The bootstrapper that should be used to handle the request.</param> /// <param name="configuration">Configuration to use</param> /// <param name="baseUris">The <see cref="Uri"/>s that the host will listen to.</param> public NancyHost(INancyBootstrapper bootstrapper, HostConfiguration configuration, params Uri[] baseUris) { this.configuration = configuration ?? new HostConfiguration(); this.baseUriList = baseUris; bootstrapper.Initialise(); this.engine = bootstrapper.GetEngine(); }
public NancyEngineFixture() { this.resolver = A.Fake<IRouteResolver>(); this.route = new FakeRoute(); A.CallTo(() => resolver.Resolve(A<Request>.Ignored, A<IRouteCache>.Ignored.Argument)).Returns(route); this.engine = new NancyEngine(resolver, A.Fake<IRouteCache>()); }
/// <summary> /// Handles an incoming <see cref="Request"/> async. /// </summary> /// <param name="nancyEngine">The <see cref="INancyEngine"/> instance.</param> /// <param name="request">An <see cref="Request"/> instance, containing the information about the current request.</param> /// <param name="onComplete">Delegate to call when the request is complete</param> /// <param name="onError">Deletate to call when any errors occur</param> public static void HandleRequest( this INancyEngine nancyEngine, Request request, Action <NancyContext> onComplete, Action <Exception> onError) { HandleRequest(nancyEngine, request, null, onComplete, onError, CancellationToken.None); }
public NancyEvent2Host(string host, int port, INancyBootstrapper bootstrapper) { _host = host; _port = port; _bootstrapper = bootstrapper; _bootstrapper.Initialise(); _engine = _bootstrapper.GetEngine(); }
public NancyTestingHttpMessageHandler(INancyEngine engine) { if (engine == null) { throw new ArgumentNullException(nameof(engine)); } this.engine = engine; }
public CustomNancyHost(INancyBootstrapper bootstrapper, HostConfiguration configuration, params Uri[] baseUris) { _bootstrapper = bootstrapper; _configuration = configuration ?? new HostConfiguration(); _baseUriList = baseUris; bootstrapper.Initialise(); _engine = bootstrapper.GetEngine(); }
public IdeaStrikeSpecBase() { CreateMocks(); ContainerBuilder builder = CreateContainerBuilder(); var ideaStrikeTestBootstrapper = new IdeaStrikeTestBootStrapper(CreateContainerBuilder); ideaStrikeTestBootstrapper.Initialise(); engine = ideaStrikeTestBootstrapper.GetEngine(); }
public NancyEvent2Host(string host, int port, INancyBootstrapper bootstrapper, int workers) { _host = host; _port = port; _workers = workers; bootstrapper.Initialise(); _engine = bootstrapper.GetEngine(); }
/// <summary> /// Initializes a new instance of the <see cref="NancyHost"/> class for the specified <paramref name="baseUris"/>, using /// the provided <paramref name="bootstrapper"/>. /// Uses the specified configuration. /// </summary> /// <param name="bootstrapper">The bootstrapper that should be used to handle the request.</param> /// <param name="configuration">Configuration to use</param> /// <param name="baseUris">The <see cref="Uri"/>s that the host will listen to.</param> public NancyHost(INancyBootstrapper bootstrapper, HostConfiguration configuration, params Uri[] baseUris) { this.bootstrapper = bootstrapper; this.configuration = configuration ?? new HostConfiguration(); this.baseUriList = baseUris; bootstrapper.Initialise(); this.engine = bootstrapper.GetEngine(); }
public NancyHost(Uri baseUri, INancyBootstrapper bootStrapper) { this.baseUri = baseUri; listener = new HttpListener(); listener.Prefixes.Add(baseUri.ToString()); bootStrapper.Initialise(); engine = bootStrapper.GetEngine(); }
public void Start() { if (Interlocked.CompareExchange(ref _isInitialized, 1, 0) != 0) { return; // already initialized } _nancyBootstrapper.Initialise(); _engine = _engine ?? _nancyBootstrapper.GetEngine(); }
/// <summary> /// Handles an incoming <see cref="Request"/>. /// </summary> /// <param name="nancyEngine">The <see cref="INancyEngine"/> instance.</param> /// <param name="request">An <see cref="Request"/> instance, containing the information about the current request.</param> /// <param name="preRequest">Delegate to call before the request is processed</param> /// <returns>A <see cref="NancyContext"/> instance containing the request/response context.</returns> public static NancyContext HandleRequest(this INancyEngine nancyEngine, Request request, Func <NancyContext, NancyContext> preRequest) { var task = nancyEngine.HandleRequest(request, preRequest, CancellationToken.None); task.Wait(); if (task.IsFaulted) { throw task.Exception ?? new Exception("Request task faulted"); } return(task.Result); }
static InteractiveSqlHttpRequestHandler() { Try(() => { var bootstrapper = GetBootstrapper(); bootstrapper.Initialise(); engine = bootstrapper.GetEngine(); }); }
public HancyHandlerFixture() { this.context = A.Fake<HttpContextBase>(); this.request = A.Fake<HttpRequestBase>(); this.response = A.Fake<HttpResponseBase>(); this.engine = A.Fake<INancyEngine>(); handler = new NancyHandler(engine); A.CallTo(() => this.context.Request).Returns(this.request); A.CallTo(() => this.context.Response).Returns(this.response); A.CallTo(() => this.response.OutputStream).Returns(new MemoryStream()); }
/// <summary> /// Initializes a new instance of the <see cref="NancyHost"/> class for the specfied <paramref name="baseUris"/>, using /// the provided <paramref name="bootstrapper"/>. /// </summary> /// <param name="bootstrapper">The boostrapper that should be used to handle the request.</param> /// <param name="baseUris">The <see cref="Uri"/>s that the host will listen to.</param> public NancyHost(INancyBootstrapper bootstrapper, params Uri[] baseUris) { baseUriList = baseUris; listener = new HttpListener(); foreach (var baseUri in baseUriList) { listener.Prefixes.Add(baseUri.ToString().Replace("localhost", "+")); } bootstrapper.Initialise(); engine = bootstrapper.GetEngine(); }
public NancyHttpRequestHandler() { INancyBootStrapper bootStrapper = null; var configBootStrapper = GetConfigBootStrapperType(); if (configBootStrapper != null) bootStrapper = (INancyBootStrapper)Activator.CreateInstance(configBootStrapper.Assembly, configBootStrapper.Name); else bootStrapper = NancyBootStrapperLocator.BootStrapper; _Engine = bootStrapper.GetEngine(); }
/// <summary> /// Initializes a new instance of the <see cref="NancyHost"/> class for the specfied <paramref name="baseUris"/>, using /// the provided <paramref name="bootstrapper"/>. /// </summary> /// <param name="bootstrapper">The boostrapper that should be used to handle the request.</param> /// <param name="baseUris">The <see cref="Uri"/>s that the host will listen to.</param> public NancyHost(INancyBootstrapper bootstrapper, params Uri[] baseUris) { baseUriList = baseUris; listener = new HttpListener(); foreach (var baseUri in baseUriList) { listener.Prefixes.Add(baseUri.ToString()); } bootstrapper.Initialise(); engine = bootstrapper.GetEngine(); }
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); }
public NancyMiddleware( NancyOptions options, ILogger <NancyMiddleware> logger, RequestDelegate next) { _options = options; var bootstrapper = _options.Bootstrapper ?? new DefaultNancyBootstrapper(); //new DefaultKestrelBootstrapper(); bootstrapper.Initialise(); _engine = bootstrapper.GetEngine(); _logger = logger; _next = next; }
/// <summary> /// Handles an incoming <see cref="Request"/>. /// </summary> /// <param name="nancyEngine">The <see cref="INancyEngine"/> instance.</param> /// <param name="request">An <see cref="Request"/> instance, containing the information about the current request.</param> /// <param name="preRequest">Delegate to call before the request is processed</param> /// <returns>A <see cref="NancyContext"/> instance containing the request/response context.</returns> public static NancyContext HandleRequest(this INancyEngine nancyEngine, Request request, Func <NancyContext, NancyContext> preRequest) { var task = nancyEngine.HandleRequest(request, preRequest, CancellationToken.None); try { task.Wait(); } catch (Exception ex) { throw ex.FlattenInnerExceptions(); } return(task.Result); }
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 NancyHost(IPAddress address, int port, INancyBootstrapper bootStrapper) { var filter = new LogFilter(); filter.AddStandardRules(); LogFactory.Assign(new ConsoleLogFactory(filter)); server = new Server(); bootStrapper.Initialise(); engine = bootStrapper.GetEngine(); // same as previous example. AppiaModule module = new AppiaModule(engine); server.Add(module); }
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> /// Handles an incoming <see cref="Request"/> async. /// </summary> /// <param name="nancyEngine">The <see cref="INancyEngine"/> instance.</param> /// <param name="request">An <see cref="Request"/> instance, containing the information about the current request.</param> /// <param name="preRequest">Delegate to call before the request is processed</param> /// <param name="onComplete">Delegate to call when the request is complete</param> /// <param name="onError">Delegate to call when any errors occur</param> /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param> public static void HandleRequest( this INancyEngine nancyEngine, Request request, Func <NancyContext, NancyContext> preRequest, Action <NancyContext> onComplete, Action <Exception> onError, CancellationToken cancellationToken) { if (nancyEngine == null) { throw new ArgumentNullException("nancyEngine"); } nancyEngine .HandleRequest(request, preRequest, cancellationToken) .WhenCompleted(t => onComplete(t.Result), t => onError(t.Exception)); }
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 }; }
public NancyHandlerFixture() { this.context = A.Fake<HttpContextBase>(); this.request = A.Fake<HttpRequestBase>(); this.response = A.Fake<HttpResponseBase>(); this.engine = A.Fake<INancyEngine>(); this.handler = new NancyHandler(engine); this.formData = new NameValueCollection(); A.CallTo(() => this.request.Form).ReturnsLazily(() => this.formData); A.CallTo(() => this.request.Url).Returns(new Uri("http://www.foo.com")); A.CallTo(() => this.request.InputStream).Returns(new MemoryStream()); A.CallTo(() => this.request.Headers).Returns(new NameValueCollection()); A.CallTo(() => this.request.AppRelativeCurrentExecutionFilePath).Returns("~/foo"); A.CallTo(() => this.context.Request).Returns(this.request); A.CallTo(() => this.context.Response).Returns(this.response); A.CallTo(() => this.response.OutputStream).Returns(new MemoryStream()); }