예제 #1
0
        public void PathParam_AsInt_Throws()
        {
            var entry = new HandlerEntry("GET", "/:id", true, null);
            var ctx   = Server.GetContext(client => client.GetAsync($"/foo"));

            ctx = ContextUtil.Update(ctx, entry);
            Assert.Throws <BadRequestException>(() => ctx.PathParam <int>("id"));
        }
예제 #2
0
        public void PathParam_AsFloat_Equal(int temperature)
        {
            var entry = new HandlerEntry("GET", "/:temperature", true, null);
            var ctx   = Server.GetContext(client => client.GetAsync($"/{temperature}"));

            ctx = ContextUtil.Update(ctx, entry);
            Assert.Equal(temperature, ctx.PathParam <float>("temperature"));
        }
예제 #3
0
        public void PathParam_AsString_Equal(string path, string paramName, string requestPath, string result)
        {
            var entry = new HandlerEntry("GET", path, true, null);
            var ctx   = Server.GetContext(client => client.GetAsync(requestPath));

            ctx = ContextUtil.Update(ctx, entry);
            Assert.Equal(result, ctx.PathParam(paramName));
        }
예제 #4
0
        public void PathParam_AsInt_Equal(int id)
        {
            var entry = new HandlerEntry("GET", "/:id", true, null);
            var ctx   = Server.GetContext(client => client.GetAsync($"/{id}"));

            ctx = ContextUtil.Update(ctx, entry);
            Assert.Equal(id, ctx.PathParam <int>("id"));
        }
예제 #5
0
        private List <HandlerEntry>?TryHandlers(string method, Context ctx)
        {
            var entries = Matcher.FindEntries(method, ctx.Path());

            entries?.ForEach(entry => {
                entry.Handle(ContextUtil.Update(ctx, entry));
            });
            return(entries);
        }