mardi 3 mai 2016

Unit test with WebApp runs on double thread?

Before anyone starts to complain i misuse the term 'unit'-testing - I think code using WebApp is probably not great for it - i just find it usefull.

Given this code:

public class Server
{
    public IDisposable SignalR { get; private set; }

    public void Start()
    {
        SignalR = WebApp.Start<Startup>("http://localhost:812");
    }

    public void Stop()
    {
        SignalR.Dispose();
    }
}

class Startup
{
    public void Configuration(IAppBuilder app)
    {
        app.MapSignalR();
    }
}

with these test methods:

[TestClass]
public class UnitTest1
{
    [TestMethod]
    public void TestMethod1()
    {
        var Server = new Server();
        Server.Start();
        Server.Stop();
    }

    [TestMethod]
    public void TestMethod2()
    {
        Debug.WriteLine("Expect only once. Threadid: "+Thread.CurrentThread.ManagedThreadId);
    }
}

How is it possible / avoidable / whatever that i receive the following output when dubugging the tests:

[Whole lotta loading....]d loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Expect only once. Threadid: 6
Expect only once. Threadid: 6
The thread '<No Name>' (0x29f0) has exited with code 0 (0x0).
The thread '<No Name>' (0x450) has exited with code 0 (0x0).
The program '[16484] te.processhost.managed.exe: Managed (v4.0.30319)' has exited with code 0 (0x0).

It looks as if the methods running after the first one runs on 'double' threads or something...

Aucun commentaire:

Enregistrer un commentaire