• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Sholtee / router / 325

04 Aug 2024 11:38AM UTC coverage: 93.773% (-0.02%) from 93.788%
325

push

appveyor

Sholtee
drop unnecessary ThreadStatic field from AsyncRouterBuilderAddRouteExtensions

1536 of 1638 relevant lines covered (93.77%)

0.94 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

52.17
/SRC/Public/Extensions/AsyncRouterBuilderAddRouteExtensions.cs
1
/********************************************************************************
2
* AsyncRouterBuilderAddRouteExtensions.cs                                       *
3
*                                                                               *
4
* Author: Denes Solti                                                           *
5
********************************************************************************/
6
using System;
7
using System.Linq.Expressions;
8
using System.Reflection;
9

10
namespace Solti.Utils.Router.Extensions
11
{
12
    using Primitives;
13

14
    /// <summary>
15
    /// Defines some extension methods on <see cref="AsyncRouterBuilder"/>.
16
    /// </summary>
17
    public static class AsyncRouterBuilderAddRouteExtensions
18
    {
19
        /// <summary>
20
        /// The <see cref="Extensions.RequestHandlerBuilder"/> to be used. The default is <see cref="MsDiRequestHandlerBuilder"/>
21
        /// </summary>
22
        public static RequestHandlerBuilder RequestHandlerBuilder { get; set; } = new MsDiRequestHandlerBuilder();
1✔
23

24
        /// <summary>
25
        /// Registers a new route.
26
        /// </summary>
27
        /// <param name="self"><see cref="AsyncRouterBuilder"/> instance.</param>
28
        /// <param name="route">Route to be registered.</param>
29
        /// <param name="handler">Method accepting requests on the given route. You may pass async and sync callbacks as well.</param>
30
        /// <param name="methods">Accepted HTTP methods for this route. If omitted "GET" will be used.</param>
31
        /// <exception cref="ArgumentException">If the route already registered.</exception>
32
        public static void AddRoute(this AsyncRouterBuilder self, ParsedRoute route, MethodInfo handler, params string[] methods)
33
        {
1✔
34
            if (self is null)
1✔
35
                throw new ArgumentNullException(nameof(self));
×
36

37
            self.AddRoute
1✔
38
            (
1✔
39
                route,
1✔
40
                RequestHandlerBuilder.CreateFactory(handler, null),
1✔
41
                methods
1✔
42
            );
1✔
43
        }
1✔
44

45
        /// <summary>
46
        /// Registers a new route.
47
        /// </summary>
48
        /// <param name="self"><see cref="AsyncRouterBuilder"/> instance.</param>
49
        /// <param name="route">Route to be registered.</param>
50
        /// <param name="handler">Method accepting requests on the given route. You may pass async and sync callbacks as well.</param>
51
        /// <param name="splitOptions">Specifies how to split the <paramref name="route"/>.</param>
52
        /// <param name="methods">Accepted HTTP methods for this route. If omitted "GET" will be used.</param>
53
        /// <exception cref="ArgumentException">If the route already registered.</exception>
54
        public static void AddRoute(this AsyncRouterBuilder self, string route, MethodInfo handler, SplitOptions splitOptions, params string[] methods) => self.AddRoute
1✔
55
        (
1✔
56
            RouteTemplate.Parse(route, self.Converters, splitOptions),
1✔
57
            handler,
1✔
58
            methods
1✔
59
        );
1✔
60

61
        /// <summary>
62
        /// Registers a new route.
63
        /// </summary>
64
        /// <param name="self"><see cref="AsyncRouterBuilder"/> instance.</param>
65
        /// <param name="route">Route to be registered.</param>
66
        /// <param name="handler">Method accepting requests on the given route. You may pass async and sync callbacks as well.</param>
67
        /// <param name="methods">Accepted HTTP methods for this route. If omitted "GET" will be used.</param>
68
        /// <exception cref="ArgumentException">If the route already registered.</exception>
69
        public static void AddRoute(this AsyncRouterBuilder self, string route, MethodInfo handler, params string[] methods) => self.AddRoute
×
70
        (
×
71
            route,
×
72
            handler,
×
73
            SplitOptions.Default,
×
74
            methods
×
75
        );
×
76

77
        /// <summary>
78
        /// Registers a new route.
79
        /// </summary>
80
        /// <param name="self"><see cref="AsyncRouterBuilder"/> instance.</param>
81
        /// <param name="route">Route to be registered.</param>
82
        /// <param name="handlerExpr">Function accepting requests on the given route.</param>
83
        /// <param name="methods">Accepted HTTP methods for this route. If omitted "GET" will be used.</param>
84
        /// <exception cref="ArgumentException">If the route already registered.</exception>
85
        public static void AddRoute<TService>(this AsyncRouterBuilder self, ParsedRoute route, Expression<Action<TService>> handlerExpr, params string[] methods) => self.AddRoute
×
86
        (
×
87
            route,
×
88
            MethodInfoExtractor.Extract(handlerExpr ?? throw new ArgumentNullException(nameof(handlerExpr))),
×
89
            methods
×
90
        );
×
91

92
        /// <summary>
93
        /// Registers a new route.
94
        /// </summary>
95
        /// <param name="self"><see cref="AsyncRouterBuilder"/> instance.</param>
96
        /// <param name="route">Route to be registered.</param>
97
        /// <param name="handlerExpr">Function accepting requests on the given route.</param>
98
        /// <param name="splitOptions">Specifies how to split the <paramref name="route"/>.</param>
99
        /// <param name="methods">Accepted HTTP methods for this route. If omitted "GET" will be used.</param>
100
        /// <exception cref="ArgumentException">If the route already registered.</exception>
101
        public static void AddRoute<TService>(this AsyncRouterBuilder self, string route, Expression<Action<TService>> handlerExpr, SplitOptions splitOptions, params string[] methods) => AddRoute
×
102
        (
×
103
            self,
×
104
            route,
×
105
            MethodInfoExtractor.Extract(handlerExpr ?? throw new ArgumentNullException(nameof(handlerExpr))),
×
106
            splitOptions,
×
107
            methods
×
108
        );
×
109

110
        /// <summary>
111
        /// Registers a new route.
112
        /// </summary>
113
        /// <param name="self"><see cref="AsyncRouterBuilder"/> instance.</param>
114
        /// <param name="route">Route to be registered.</param>
115
        /// <param name="handlerExpr">Function accepting requests on the given route.</param>
116
        /// <param name="methods">Accepted HTTP methods for this route. If omitted "GET" will be used.</param>
117
        /// <exception cref="ArgumentException">If the route already registered.</exception>
118
        public static void AddRoute<TService>(this AsyncRouterBuilder self, string route, Expression<Action<TService>> handlerExpr, params string[] methods) => AddRoute
1✔
119
        (
1✔
120
            self,
1✔
121
            route,
1✔
122
            handlerExpr,
1✔
123
            SplitOptions.Default,
1✔
124
            methods
1✔
125
        );
1✔
126
    }
127
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc