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")); }
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")); }
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)); }
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")); }
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); }