コード例 #1
0
ファイル: WebManager.cs プロジェクト: cubedj/fourdeltaone
 public static void Initialize()
 {
     var bootstrapper = new WebBootstrapper();
     bootstrapper.Initialise();
     _engine = bootstrapper.GetEngine();
     //_host = new NancyOwinHost(null, NancyBootstrapperLocator.Bootstrapper);
 }
コード例 #2
0
ファイル: Browser.cs プロジェクト: zhuozhuowang/Nancy
 /// <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;
 }
コード例 #3
0
 /// <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();
 }
コード例 #4
0
ファイル: Browser.cs プロジェクト: rdterner/Nancy
 /// <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;
 }
コード例 #5
0
ファイル: RequestSpec.cs プロジェクト: gregsochanik/Nancy
        protected RequestSpec()
        {
            var locator =
                new NancyModuleLocator(Assembly.GetExecutingAssembly());

            engine = new NancyEngine(locator, new RouteResolver());
        }
コード例 #6
0
 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);
 }
コード例 #7
0
ファイル: NancyEngineFixture.cs プロジェクト: rhwy/Nancy
        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
                };
        }
コード例 #8
0
        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" }
            };
        }
コード例 #9
0
ファイル: Browser.cs プロジェクト: AIexandr/Nancy
 /// <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;
 }
コード例 #10
0
 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);
 }
コード例 #11
0
        public NancyAdapter(AppFunc next, INancyBootstrapper bootstrapper)
        {
            bootstrapper.Initialise();

            _next   = next;
            _engine = bootstrapper.GetEngine();
        }
コード例 #12
0
ファイル: NancyOwinHostFixture.cs プロジェクト: ChrisMH/Nancy
        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" }
                                   };
        }
コード例 #13
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);
 }
コード例 #14
0
ファイル: HttpHost.cs プロジェクト: rmc47/CloudlogCAT
 public HttpHost(IPEndPoint endpoint)
 {
     var bootStrapper = NancyBootstrapperLocator.Bootstrapper;
     bootStrapper.Initialise();
     m_Engine = bootStrapper.GetEngine();
     m_EndPoint = endpoint;
 }
コード例 #15
0
ファイル: NancyEngineFixture.cs プロジェクト: randacc/Nancy
        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
                };
        }
コード例 #16
0
        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
            };
        }
コード例 #17
0
        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" } }
            };
        }
コード例 #18
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)
 {
     this.bootstrapper = bootstrapper;
     this.bootstrapper.Initialise();
     this.engine = this.bootstrapper.GetEngine();
     this.defaultBrowserContext = defaults ?? this.DefaultBrowserContext;
 }
コード例 #19
0
ファイル: RequestSpec.cs プロジェクト: rmueller/Nancy
        protected RequestSpec()
        {
            var defaultNancyBootstrapper = new DefaultNancyBootstrapper();

            defaultNancyBootstrapper.Initialise();

            engine = defaultNancyBootstrapper.GetEngine();
        }
コード例 #20
0
        public NancyMiddleware(RequestDelegate next, NancyOptions options)
        {
            _next = next;

            _options = options;
            _options.Bootstrapper.Initialise();
            _engine = _options.Bootstrapper.GetEngine();
        }
コード例 #21
0
ファイル: RequestSpec.cs プロジェクト: nathanpalmer/Nancy
        protected RequestSpec()
        {
            var defaultNancyBootstrapper = new DefaultNancyBootstrapper();

            defaultNancyBootstrapper.Initialise();

            engine = defaultNancyBootstrapper.GetEngine();
        }
コード例 #22
0
        public NancyHttpRequestHandler()
        {
            var bootstrapper =
                GetBootstrapper();

            this.engine =
                bootstrapper.GetEngine();
        }
コード例 #23
0
ファイル: NancyHost.cs プロジェクト: avlasova/Nancy
        public NancyHost(Uri baseUri, INancyBootstrapper bootStrapper)
        {
            this.baseUri = baseUri;
            listener = new HttpListener();
            listener.Prefixes.Add(baseUri.ToString());

            engine = bootStrapper.GetEngine();
        }
コード例 #24
0
        public static void Initialize()
        {
            var bootstrapper = new WebBootstrapper();

            bootstrapper.Initialise();
            _engine = bootstrapper.GetEngine();
            //_host = new NancyOwinHost(null, NancyBootstrapperLocator.Bootstrapper);
        }
コード例 #25
0
 protected static void InitNerdBeers()
 {
     var bs = new Org.NerdBeers.Specs.Modules.SpecBootStrapper();
     bs.Initialise();
     Engine = bs.GetEngine();
     DB = bs.DB;
     Req = null;
 }
コード例 #26
0
        static NancyHttpRequestHandler()
        {
            var bootstrapper = GetBootstrapper();

            bootstrapper.Initialise();

            engine = bootstrapper.GetEngine();
        }
コード例 #27
0
 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);
 }
コード例 #28
0
        protected RosannaSpecification()
        {
            var bootstrapper = new RosannaBootstrapper();
            bootstrapper.Initialise();

            Engine = bootstrapper.GetEngine();
            Config = bootstrapper.Container.Resolve<IRosannaConfiguration>();
        }
コード例 #29
0
        static NancyC1FunctionHost()
        {
            var bootstrapper = GetBootstrapper();

            bootstrapper.Initialise();

            Engine = bootstrapper.GetEngine();
        }
コード例 #30
0
ファイル: NancyHost.cs プロジェクト: shafiahmed/Nancy
        /// <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();
        }
コード例 #31
0
ファイル: NancyEngineFixture.cs プロジェクト: avlasova/Nancy
        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>());
        }
コード例 #32
0
 /// <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);
 }
        static NancyHttpRequestHandler()
        {
            var bootstrapper = GetBootstrapper();

            bootstrapper.Initialise();

            engine = bootstrapper.GetEngine();
        }
コード例 #34
0
		public NancyEvent2Host(string host, int port, INancyBootstrapper bootstrapper)
		{
			_host = host;
			_port = port;
			_bootstrapper = bootstrapper;
			_bootstrapper.Initialise();
			_engine = _bootstrapper.GetEngine();
		}
コード例 #35
0
 public NancyTestingHttpMessageHandler(INancyEngine engine)
 {
     if (engine == null)
     {
         throw new ArgumentNullException(nameof(engine));
     }
     this.engine = engine;
 }
コード例 #36
0
 public CustomNancyHost(INancyBootstrapper bootstrapper, HostConfiguration configuration, params Uri[] baseUris)
 {
     _bootstrapper  = bootstrapper;
     _configuration = configuration ?? new HostConfiguration();
     _baseUriList   = baseUris;
     bootstrapper.Initialise();
     _engine = bootstrapper.GetEngine();
 }
コード例 #37
0
        public IdeaStrikeSpecBase()
        {
            CreateMocks();
            ContainerBuilder builder = CreateContainerBuilder();

            var ideaStrikeTestBootstrapper = new IdeaStrikeTestBootStrapper(CreateContainerBuilder);
            ideaStrikeTestBootstrapper.Initialise();
            engine = ideaStrikeTestBootstrapper.GetEngine();
        }
コード例 #38
0
        public NancyEvent2Host(string host, int port, INancyBootstrapper bootstrapper, int workers)
        {
            _host = host;
            _port = port;
            _workers = workers;

            bootstrapper.Initialise();
            _engine = bootstrapper.GetEngine();
        }
コード例 #39
0
ファイル: NancyHost.cs プロジェクト: afwilliams/Nancy
        /// <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();
        }
コード例 #40
0
        public NancyEvent2Host(string host, int port, INancyBootstrapper bootstrapper, int workers)
        {
            _host    = host;
            _port    = port;
            _workers = workers;

            bootstrapper.Initialise();
            _engine = bootstrapper.GetEngine();
        }
コード例 #41
0
        protected static void InitNerdBeers()
        {
            var bs = new Org.NerdBeers.Specs.Modules.SpecBootStrapper();

            bs.Initialise();
            Engine = bs.GetEngine();
            DB     = bs.DB;
            Req    = null;
        }
コード例 #42
0
        public NancyHost(Uri baseUri, INancyBootstrapper bootStrapper)
        {
            this.baseUri = baseUri;
            listener     = new HttpListener();
            listener.Prefixes.Add(baseUri.ToString());

            bootStrapper.Initialise();
            engine = bootStrapper.GetEngine();
        }
コード例 #43
0
        public void Start()
        {
            if (Interlocked.CompareExchange(ref _isInitialized, 1, 0) != 0)
            {
                return;                 // already initialized
            }

            _nancyBootstrapper.Initialise();

            _engine = _engine ?? _nancyBootstrapper.GetEngine();
        }
コード例 #44
0
        /// <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);
        }
コード例 #45
0
        static InteractiveSqlHttpRequestHandler()
        {
            Try(() =>
            {
                var bootstrapper = GetBootstrapper();

                bootstrapper.Initialise();

                engine = bootstrapper.GetEngine();

            });
        }
コード例 #46
0
        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());
        }
コード例 #47
0
ファイル: NancyHost.cs プロジェクト: raoulmillais/Nancy
        /// <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();
        }
コード例 #48
0
ファイル: NancyHttpRequestHandler.cs プロジェクト: tt/Nancy
        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();
        }
コード例 #49
0
ファイル: NancyHost.cs プロジェクト: williware/Nancy
        /// <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();
        }
コード例 #50
0
        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);
        }
コード例 #51
0
ファイル: NancyEngineFixture.cs プロジェクト: ToJans/Nancy
        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);
        }
コード例 #52
0
        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;
        }
コード例 #53
0
        /// <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);
 }
コード例 #55
0
        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);
		}
コード例 #57
0
        /// <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));
        }
コード例 #58
0
        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);
        }
コード例 #59
0
        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
            };
        }
コード例 #60
0
        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());
        }