开发者

Integration testing, how can i wrap a REST call which changes databsae in a transaction?

I have code like this:

[Fact]
public void should_return_at_least_3_users()
{
  Rest.Call("http://localhost/admin/users/makeasfree/3");

  var response = Rest.Call<List<Users>>("http://localhost/admin/freeusers");
  response.Count.ShouldBeGreaterThan(0);
}

I've tried t开发者_StackOverflow中文版o surround this with TransactionScope but does not work. There is any way to roll back test changes without doing whole database restore?


It is unlikely that there are any good solutions to this problem as supporting distributed two phase commit transactions across HTTP requests would violate the stateless nature of http requests. Transactions can live behind a REST interface, but they should not be put in front.

I realize that you may only want the transactions to allow you to do integration testing, but do you really want to be doing integration testing using an environment that is not the same as your production environment.

And if you still are not convinced, then you should watch this video :-).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜