Note that there are some explanatory texts on larger screens.

plurals
  1. POWebApi tests using in memory hosting hang when solution also contains WinForms tests
    primarykey
    data
    text
    <p>I have a solution that contains a number of different projects that include both WinForms and WebApi (RC). I am seeing an issue with WebApi tests hanging when a prior test instantiates a class that derives from <code>System.Windows.Forms.Form</code>. You can find a sample solution that demonstrates the problem here: <a href="https://dl.dropbox.com/u/3688049/SampleSolutions/TestSolution.zip" rel="nofollow">https://dl.dropbox.com/u/3688049/SampleSolutions/TestSolution.zip</a></p> <p>The solution has NuGet package restore enabled so all the dependencies should get pulled down upon build.</p> <p>If the <code>var form = new Form1();</code> call in Class1.cs is not commented out, then the tests will hang (using latest nuget version of nunit). If it is commented out, the tests pass.</p> <p>Any help would be greatly appreciated.</p> <p><strong>Class1.cs</strong></p> <pre class="lang-cs prettyprint-override"><code>[TestFixture] public class Class1 { [Test] public void AaaWindowsFormsApp() { // If this line is not commented out the BbbTestWebApiApp test will hang. var form = new Form1(); } [Test] public void BbbTestWebApiApp() { var config = new HttpConfiguration(); var server = new HttpServer(config, new MyMessageHandler()); var client = new HttpClient(server); var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/"); var response = client.SendAsync(request).Result; Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); } } </code></pre> <p><strong>MyMessageHandler.cs</strong></p> <pre class="lang-cs prettyprint-override"><code>public class MyMessageHandler: DelegatingHandler { protected override Task&lt;HttpResponseMessage&gt; SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { return Task.Factory.StartNew(() =&gt; request.CreateResponse(HttpStatusCode.OK)); } } </code></pre> <p><strong>UPDATE</strong></p> <p>It seems that adding the <code>RequiresSTA</code> attribute to the <code>System.Windows.Forms.Form</code> tests resolves the issue. </p> <p>I'm not sure why adding the WebApi in-memory hosting exposed the problem though.</p> <p><strong>UPDATE 2</strong></p> <p><code>RequiresSTA</code> only seems to help if you are running the tests via the GUI. The console runner still seems to hang.</p>
    singulars
    1. This table or related slice is empty.
    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