Exemplo n.º 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);
 }
Exemplo n.º 2
0
        public IRoute GetRoute(IRequest request, IEnumerable<ModuleMeta> metas, INancyApplication application)
        {
            var matchingRoutes =
                from meta in metas
                from description in meta.RouteDescriptions
                let matcher = BuildRegexMatcher(description)
                let result = matcher.Match(request.Uri)
                where result.Success
                select new
                {
                    Groups = result.Groups,
                    Meta = meta,
                    Description = description
                };

            var selected = matchingRoutes
                .OrderByDescending(x => GetSegmentCount(x.Description))
                .FirstOrDefault();

            if (selected == null)
            {
                return new NoMatchingRouteFoundRoute(request.Uri);
            }
            var instance = application.Container.Resolve<NancyModule>(selected.Meta.TypeName);
            //var instance = application.Activator.CreateInstance(selected.Meta.Type);
            instance.Application = application;
            instance.Request = request;
            var action = instance.GetRoutes(selected.Description.Method)[selected.Description.Path];
            return new Route(selected.Description.GetModuleQualifiedPath(), GetParameters(selected.Description, selected.Groups), instance, action);
        }
 public void Initialize(INancyApplication application)
 {
     var registries = application.Container.Resolve<IEnumerable<IViewEngineRegistry>>();
     foreach (var registry in registries)
     {
         application.TemplateProcessors.Add(registry.Extension, registry.Executor);
     }
 }
Exemplo n.º 4
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);
 }
Exemplo n.º 5
0
 private static IList<ModuleMeta> GetModuleMetaList(INancyApplication application, string method)
 {
     IEnumerable<ModuleMeta> list;
     if (!application.ModuleMetas.TryGetValue(method, out list))
     {
         list = new List<ModuleMeta>();
         application.ModuleMetas[method] = list;
     }
     return list as IList<ModuleMeta>;
 }
Exemplo n.º 6
0
        public IRoute GetRoute(IRequest request, IEnumerable<ModuleMeta> meta, INancyApplication application)
        {
            var description = (from m in meta
                               from d in m.RouteDescriptions
                               where d.ModulePath + d.Path == request.Uri
                               select d).First();

            this.ModulePath = description.ModulePath;
            this.Path = description.Path;

            return new FakeRoute();
        }
Exemplo n.º 7
0
        public void Initialize(INancyApplication application)
        {
            var modules = application.Container.Resolve<IEnumerable<Func<NancyModule>>>();
            foreach (var module in modules)
            {
                var mod = module();
                AddModuleMetaToApplication(application, mod, "GET");

                AddModuleMetaToApplication(application, mod, "POST");

                AddModuleMetaToApplication(application, mod, "PUT");

                AddModuleMetaToApplication(application, mod, "DELETE");
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NancyEngine"/> class.
        /// </summary>
        /// <param name="locator">An <see cref="INancyModuleLocator"/> instance, that will be used to locate <see cref="NancyModule"/> instances</param>
        /// <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>
        public NancyEngine(IRouteResolver resolver, INancyApplication application)
        {
            if (resolver == null)
            {
                throw new ArgumentNullException("resolver", "The resolver parameter cannot be null.");
            }

            if (application == null)
            {
                throw new ArgumentNullException("application", "The application parameter cannot be null.");
            }

            this.resolver = resolver;
            this.application = application;
        }
Exemplo n.º 9
0
        public void Initialize(INancyApplication application)
        {
            var container = application.Container;

            if (!container.Contains<TemplateManagerProvider>())
            {
                var tags = container.Resolve<IEnumerable<Tag>>();
                var filters = container.Resolve<IEnumerable<Filter>>();
                var settings = container.Resolve<IEnumerable<Setting>>();
                var templateProvider = new TemplateManagerProvider()
                    .WithFilters(filters)
                    .WithTags(tags)
                    .WithSettings(settings);
                container.Register<TemplateManagerProvider>(templateProvider);
            }
        }
 public void Run(INancyApplication application)
 {
 }
Exemplo n.º 11
0
 private static void AddModuleMetaToApplication(INancyApplication application, NancyModule mod, string action)
 {
     IList<ModuleMeta> postList = GetModuleMetaList(application, action);
     postList.Add(new ModuleMeta(mod.GetType(), mod.GetRouteDescription(action)));
 }