The*_*Cat 4 unit-testing nancy
我试图通过Nancy.Testing.Browser对象传递路由参数(而不是查询参数!).我理解(现在)如何向/从我的NancyModule发送和使用查询字符串:
var customerResponse = browser.Get("/customer/id", with =>
{
with.HttpRequest();
with.Query("{id}", alansIdGuid.ToString());
});
Run Code Online (Sandbox Code Playgroud)
...
Get["/customer/{id}"] = parameters =>
{
string idFromQuery = Request.Query.id;
Customer customerFromId = _customerRepo.GetCustomerById(idFromQuery);
return Response.AsJson<Customer>(customerFromId);
};
Run Code Online (Sandbox Code Playgroud)
但是 - 我想要做的是点击我的路线并检索我的路线参数,如下所示:
Get["/customer/{id}"] = parameters =>
{
string id = parameters.id;
Customer customerFromId = _customerRepo.GetCustomerById(id);
return Response.AsJson<Customer>(customerFromId);
};
Run Code Online (Sandbox Code Playgroud)
如何使用Nancy.Testing.Browser将我的Id参数作为路由参数传递?
- 没有使用标题,Cookie或查询字符串?
这是一个3小时的搜索看似简单的任务!以下问题围绕这个问题展开,但不解决它:
我是个白痴...我猜答案对其他人来说似乎很明显!
var customerResponse = browser.Get("/customer/" + alansIdGuid.ToString(), with =>
{
with.HttpRequest();
});
Run Code Online (Sandbox Code Playgroud)
只需将查询字符串/值附加到您正在使用的Nancy.Testing.Browser对象的请求URL的末尾.
| 归档时间: |
|
| 查看次数: |
1486 次 |
| 最近记录: |