我一直在尝试使用OWIN TestServer类实现集成测试,除了PUT或DELETE方法的实现之外,一切都有效.POST方法代码(有效)如下所示:
using (var server = TestServer.Create<Startup>())
{
var response = await server.CreateRequest(uri)
.AddHeader("Authorization", "Bearer " + _token)
.And(
request =>
request.Content =
new ObjectContent(typeof (T), command, new JsonMediaTypeFormatter()))
.PostAsync();
Assert.AreEqual(response.StatusCode, expectedStatusCode);
return await response.Content.ReadAsStringAsync();
}
Run Code Online (Sandbox Code Playgroud)
要执行PUT请求,我尝试了以下两种方法:
using (var server = TestServer.Create<Startup>())
{
var response = await server.CreateRequest(uri)
.AddHeader("Authorization", "Bearer " + _token)
.And(
request =>
request.Content =
new ObjectContent(typeof (T), command, new JsonMediaTypeFormatter()))
.And(request => request.Method = = HttpMethod.Put)
.PostAsync();
Assert.AreEqual(response.StatusCode, expectedStatusCode);
return await response.Content.ReadAsStringAsync();
}
Run Code Online (Sandbox Code Playgroud)
和
using (var …Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,我在点击时间链接时切换是否student属于training time或不属于.
# controller
def time
@student = Student.find(params[:student_id])
@time = TrainingTime.find(params[:training_time_id])
@student.toggle_time(@time)
respond_to do |format|
format.html { redirect_to @student }
format.js
end
end
# routes
resources :students do
match "time/:training_time_id", to: "students#time", as: :toggle_time
end
# view
<%= link_to t.time_format, student_toggle_time_path(@student, t), remote: true %>
Run Code Online (Sandbox Code Playgroud)
目前它正在使用匹配,但是设置它的正确方法是什么?为什么?
感谢您的输入.
我有一个对象:
Account
{
Id,
Name,
CurrentBalance
}
Run Code Online (Sandbox Code Playgroud)
Id是一个不可变的键,Name是一个可变的字符串,并CurrentBalance从与该帐户关联的所有事务计算.
我坚持GET \Accounts\{Id}不会是幂等的事实,因为对事务的更改将导致更改CurrentBalance.我应该从对象中删除此字段并发出请求
POST \Accounts\{Id}\CurrentBalance
Run Code Online (Sandbox Code Playgroud)
但现在我必须多次调用服务器来获取CurrentBalance所有对象:
GET \Accounts
POST \Accounts\{Id1}\CurrentBalance
POST \Accounts\{Id2}\CurrentBalance
POST \Accounts\{Id3}\CurrentBalance
....
Run Code Online (Sandbox Code Playgroud)
我想我只是想看看是否已经有一种标准的方法可以解决这个问题,我错过了?
UPDATE
第2部分,如果原始对象通过GET正常.我更新的唯一方法Account.Name是通过PATCH,因为我不允许更新到CurrentBalance,对吗?
注意
我意识到我可以把它放在客户端上以获取所有事务并计算它,但我更愿意在服务器上执行此操作有多种原因
我试图在Express应用程序中找到一种处理404和405状态代码的方法,但是要分开处理它们。
例如:我有一个类似以下的路由器:
// Add routes for every path we define here.
server.use('/', require('./indexRoutes'))
server.use('/account', require('./accountRoutes'))
// Handling route errors.
server.all('*', (request, response) =>
response.status(404).send('Invalid route (not found).')
)
Run Code Online (Sandbox Code Playgroud)
但是,该server.all方法将处理无效的路由或无效的HTTP动词。有没有一种方法可以分开对待它们,以便为每种情况发送不同的状态,内容和所有内容?
谢谢你们!
我有这样的终点
/profiles/1
Run Code Online (Sandbox Code Playgroud)
我想获取ID为1的配置文件,但同时将访问的属性增加1。该属性作为对象的一部分出现。我应该使用哪个HTTP动词来获取访问属性增加1的配置文件对象。
每次获取ID为1的配置文件时,访问的属性都会增加1。
http-verbs ×5
http ×2
rest ×2
c# ×1
express ×1
idempotent ×1
node.js ×1
owin ×1
routes ×1
routing ×1