public MetadataModuleRouteMetadataProviderFixture()
        {
            this.resolver = A.Fake<IMetadataModuleResolver>();
            this.module = A.Fake<INancyModule>();
            this.route = new RouteDescription("NamedDescription", "GET", "/things", ctx => true);
            this.metadataModule = new FakeNancyMetadataModule();
            this.metadataModule.Describe[this.route.Name] = desc => { return Metadata; };

            this.provider = new MetadataModuleRouteMetadataProvider(this.resolver);
        }
Ejemplo n.º 2
0
        public Route(RouteDescription description, Func<dynamic, Response> action)
        {
            if (action == null)
            {
                throw new ArgumentNullException("action");
            }

            this.Description = description;
            this.Action = action;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Route"/> type, with the specified <see cref="RouteDescription"/>.
        /// </summary>
        /// <param name="description"></param>
        /// <param name="action">The action that should take place when the route is invoked.</param>
        public Route(RouteDescription description, Func<dynamic, CancellationToken, Task<dynamic>> action)
        {
            if (action == null)
            {
                throw new ArgumentNullException("action");
            }

            this.Description = description;
            this.Action = action;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Route"/> type, with the specified <see cref="RouteDescription"/>.
        /// </summary>
        /// <param name="description"></param>
        /// <param name="action">The action that should take place when the route is invoked.</param>
        public Route(RouteDescription description, Func<dynamic, dynamic> action)
        {
            if (action == null)
            {
                throw new ArgumentNullException("action");
            }

            this.Description = description;
            this.Action = action;
        }
Ejemplo n.º 5
0
        private static Regex BuildRegexMatcher(RouteDescription description)
        {
            var segments =
                description.GetModuleQualifiedPath().Split(new[] { "/" }, StringSplitOptions.RemoveEmptyEntries);

            var parameterizedSegments =
                GetParameterizedSegments(segments);

            var pattern =
                string.Concat(@"^/", string.Join("/", parameterizedSegments), @"$");

            return(new Regex(pattern, RegexOptions.IgnoreCase));
        }
Ejemplo n.º 6
0
        private static Regex BuildRegexMatcher(RouteDescription description)
        {
            var segments =
                description.GetModuleQualifiedPath().Split(new[] {"/"}, StringSplitOptions.RemoveEmptyEntries);

            var parameterizedSegments =
                GetParameterizedSegments(segments);

            var pattern =
                string.Concat(@"^/", string.Join("/", parameterizedSegments), @"$");

            return new Regex(pattern, RegexOptions.IgnoreCase);
        }
Ejemplo n.º 7
0
        private static int GetSegmentCount(RouteDescription description)
        {
            var moduleQualifiedPath =
                description.GetModuleQualifiedPath();

            var indexOfFirstParameter =
                moduleQualifiedPath.IndexOf('{');

            if (indexOfFirstParameter > -1)
            {
                moduleQualifiedPath = moduleQualifiedPath.Substring(0, indexOfFirstParameter);
            }

            return(moduleQualifiedPath.Split('/').Count());
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Gets the <see cref="T:System.Type" /> of the metadata that is created by the provider.
        /// </summary>
        /// <param name="module">The <see cref="T:Nancy.INancyModule" /> instance that the route is declared in.</param>
        /// <param name="routeDescription">A <see cref="T:Nancy.Routing.RouteDescription" /> for the route.</param>
        /// <returns>
        /// A <see cref="T:System.Type" /> instance, or <see langword="null" /> if nothing is found.
        /// </returns>
        public Type GetMetadataType(INancyModule module, RouteDescription routeDescription)
        {
            if (String.IsNullOrWhiteSpace(routeDescription.Name))
                return null;

            // TODO: Yikes, what an ugly hack. We need to figure out a better way to identify routes than their name. [asbjornu]
            switch (routeDescription.Name)
            {
                case JsonSchema:
                case ClientAssembly:
                case ClientNugetPackage:
                case ClientNugetPackageVersioned:
                    return typeof(PomonaRouteMetadata);
            }

            return null;
        }
Ejemplo n.º 9
0
        private static RouteParameters GetParameters(RouteDescription description, GroupCollection groups)
        {
            var segments =
                new ReadOnlyCollection <string>(
                    description.Path.Split(new[] { "/" },
                                           StringSplitOptions.RemoveEmptyEntries).ToList());

            var parameters =
                from segment in segments
                where segment.IsParameterized()
                select segment.GetParameterName();

            dynamic data =
                new RouteParameters();

            foreach (var parameter in parameters)
            {
                data[parameter] = groups[parameter].Value;
            }

            return(data);
        }
Ejemplo n.º 10
0
        private static RouteParameters GetParameters(RouteDescription description, GroupCollection groups)
        {
            var segments =
                new ReadOnlyCollection<string>(
                    description.Path.Split(new[] { "/" },
                    StringSplitOptions.RemoveEmptyEntries).ToList());

            var parameters =
                from segment in segments
                where segment.IsParameterized()
                select segment.GetParameterName();

            dynamic data =
                new RouteParameters();

            foreach (var parameter in parameters)
            {
                data[parameter] = groups[parameter].Value;
            }

            return data;
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Gets the metadata for the provided route.
        /// </summary>
        /// <param name="module">The <see cref="T:Nancy.INancyModule" /> instance that the route is declared in.</param>
        /// <param name="routeDescription">A <see cref="T:Nancy.Routing.RouteDescription" /> for the route.</param>
        /// <returns>
        /// An object representing the metadata for the given route, or <see langword="null" /> if nothing is found.
        /// </returns>
        public object GetMetadata(INancyModule module, RouteDescription routeDescription)
        {
            if (String.IsNullOrWhiteSpace(routeDescription.Name))
                return null;

            // TODO: Yikes, what an ugly hack. We need to figure out a better way to identify routes than their name. [asbjornu]
            switch (routeDescription.Name)
            {
                case JsonSchema:
                    return new PomonaRouteMetadata
                    {
                        ContentType = "application/json",
                        Method = HttpMethod.Get,
                        Relation = "json-schema",
                    };

                case ClientAssembly:
                    return new PomonaRouteMetadata
                    {
                        ContentType = "binary/octet-stream",
                        Method = HttpMethod.Get,
                        Relation = "client-assembly",
                    };

                case ClientNugetPackage:
                case ClientNugetPackageVersioned:
                    return new PomonaRouteMetadata
                    {
                        ContentType = "application/zip",
                        Method = HttpMethod.Get,
                        Relation = "nuget-package",
                    };
            }

            return null;
        }
Ejemplo n.º 12
0
 public static Route FromSync(RouteDescription description, Func <dynamic, dynamic> syncFunc)
 {
     return(new Route(description, Wrap(syncFunc)));
 }
Ejemplo n.º 13
0
        private static int GetSegmentCount(RouteDescription description)
        {
            var moduleQualifiedPath =
                description.GetModuleQualifiedPath();

            var indexOfFirstParameter =
                moduleQualifiedPath.IndexOf('{');

            if (indexOfFirstParameter > -1)
                moduleQualifiedPath = moduleQualifiedPath.Substring(0, indexOfFirstParameter);

            return moduleQualifiedPath.Split('/').Count();
        }
Ejemplo n.º 14
0
 public MetadataModuleFixture()
 {
     this.route = new RouteDescription("NamedDescription", "GET", "/things", ctx => true);
     this.metadataModule = new FakeNancyMetadataModule();
 }
        //public DefaultRouteMetadataProvider(IRouteDescriptionProvider routeDescriptionProvider)
        //{
        //    _routeDescriptionProvider = routeDescriptionProvider;
        //}

        public Type GetMetadataType(INancyModule module, RouteDescription routeDescription)
        {
            return null;
        }
Ejemplo n.º 16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Route"/> type, with the specified <see cref="RouteDescription"/>.
 /// </summary>
 /// <param name="description">An <see cref="RouteDescription"/> instance.</param>
 protected Route(RouteDescription description)
 {
     this.Description = description;
 }
 public object GetMetadata(INancyModule module, RouteDescription routeDescription)
 {
     var description = _routeDescriptionProvider.GetDescription(module, routeDescription.Path);
     return new DefaultRouteMetadata(routeDescription.Method, routeDescription.Path, description);
 }
 /// <summary>
 /// Gets the metadata for the provided route.
 /// </summary>
 /// <param name="module">The <see cref="INancyModule"/> instance that the route is declared in.</param>
 /// <param name="routeDescription">A <see cref="RouteDescription"/> for the route.</param>
 /// <returns>An instance of <typeparamref name="TMetadata"/>.</returns>
 protected abstract TMetadata GetRouteMetadata(INancyModule module, RouteDescription routeDescription);
 /// <summary>
 /// Gets the metadata for the provided route.
 /// </summary>
 /// <param name="module">The <see cref="INancyModule" /> instance that the route is declared in.</param>
 /// <param name="routeDescription">A <see cref="RouteDescription" /> for the route.</param>
 /// <returns>An instance of <typeparamref name="TMetadata"/>.</returns>
 public object GetMetadata(INancyModule module, RouteDescription routeDescription)
 {
     return(this.GetRouteMetadata(module, routeDescription));
 }
 /// <summary>
 /// Gets the <see cref="Type"/> of the metadata that is created by the provider.
 /// </summary>
 /// <param name="module">The <see cref="INancyModule"/> instance that the route is declared in.</param>
 /// <param name="routeDescription">A <see cref="RouteDescription"/> for the route.</param>
 /// <returns>A <see cref="Type"/> instance, or null if none are found.</returns>
 public Type GetMetadataType(INancyModule module, RouteDescription routeDescription)
 {
     return(typeof(TMetadata));
 }
Ejemplo n.º 21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Route"/> type, with the specified <see cref="RouteDescription"/>.
 /// </summary>
 /// <param name="description"></param>
 protected Route(RouteDescription description)
 {
     this.Description = description;
 }
Ejemplo n.º 22
0
        private static int GetSegmentCount(RouteDescription description)
        {
            var workingCopyOfPath = description.Path;

            var indexOfFirstParameter =
                workingCopyOfPath.IndexOf('{');

            if (indexOfFirstParameter > -1)
                workingCopyOfPath = workingCopyOfPath.Substring(0, indexOfFirstParameter);

            return workingCopyOfPath.Split('/').Count();
        }
        /// <summary>
        /// Gets the metadata for the provided route by obtaining it from an associated <see cref="IMetadataModule"/>.
        /// </summary>
        /// <param name="module">The <see cref="INancyModule"/> instance that the route is declared in.</param>
        /// <param name="routeDescription">A <see cref="RouteDescription"/> for the route.</param>
        /// <returns>An object representing the metadata for the given route, or null if none are found.</returns>
        public object GetMetadata(INancyModule module, RouteDescription routeDescription)
        {
            var metadataModule = this.resolver.GetMetadataModule(module);

            return metadataModule != null ? metadataModule.GetMetadata(routeDescription) : null;
        }
        /// <summary>
        /// Gets the <see cref="Type"/> of the metadata that is created by the provider.
        /// </summary>
        /// <param name="module">The <see cref="INancyModule"/> instance that the route is declared in.</param>
        /// <param name="routeDescription">A <see cref="RouteDescription"/> for the route.</param>
        /// <returns>A <see cref="Type"/> instance, or null if none are found.</returns>
        public Type GetMetadataType(INancyModule module, RouteDescription routeDescription)
        {
            var metadataModule = this.resolver.GetMetadataModule(module);

            return metadataModule != null ? metadataModule.MetadataType : null;
        }
Ejemplo n.º 25
0
 /// <summary>
 /// Creates a route from a sync delegate signature
 /// </summary>
 /// <param name="description"></param>
 /// <param name="syncFunc">The action that should take place when the route is invoked.</param>
 /// <returns>A Route instance</returns>
 public static Route FromSync(RouteDescription description, Func<dynamic, dynamic> syncFunc)
 {
     return new Route(description, Wrap(syncFunc));
 }
 public SwaggerRouteMetadata(RouteDescription desc) : this(desc.Path, desc.Method) { }