Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing TransactionScope when integration testing web apis
    primarykey
    data
    text
    <p>At the moment, I'm doing something similar to <a href="http://www.strathweb.com/2012/06/asp-net-web-api-integration-testing-with-in-memory-hosting/">this</a> to integration test a library that communicates with our API controllers, and so far so good, but I've run into a snag. In all of our other integration tests, we run the test inside an MSDTC transaction at isolation level ReadCommitted so that each one gets its own little private session with the databases and such, and at the end of each test, the transactions are rolled back. ..But that doesn't work for <em>these</em> tests because the transactions are per-thread and all of the HttpClient/HttpServer methods are asynchronous, so the work is done on a different thread than the main one for that test, doesn't have an ambient transaction to subscribe to, and goes right along and commits.</p> <p>I've come across a few posts about how to open a TransactionScope on one thread and then create a dependent transaction to be passed to a new task via a closure, but I have no idea how to apply that to an HttpClient that's connected to an in-memory HttpServer. I <em>suspect</em> I'm just not thinking about it the right way, but that's about all I have to go on.</p> <p>What would make sense/work/etc? I have full control over the creation of the HttpServer and the HttpClient that will connect to it, but I'm at a loss as to what to do with them.</p> <p>UPDATE:</p> <p>Some progress has been made- I wrote a message handler that can create a dependent transaction on the worker thread <em>if</em> Transaction.Current is populated when it gets there, and for some of my calls it is, but for others it isn't, and I'm wondering if I may be chasing shadows - like, there's a lot of ContinueWith around, and I think it's executed on the calling thread (which would naturally have a transaction) if the antecedent task is already complete.</p> <p>Would it be possible just to run the whole thing synchronously and carry the test's thread all the way through? I've experimented some with ContinueWith'ing synchronously without much success..</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload