Exclude a check if unittest running

i have a few unittests running using it’s own AppHost.
How can i exclude 2 lines of code if the unittest is running inside my service?

                    //If unittest dont run this code
                    if (false)

I have a TestAppHost looking like this

   public class TestAppHost : AppHostHttpListenerBase
    /// <summary>
    ///     Default constructor.
    ///     Base constructor requires a name and assembly to locate web service classes.
    /// </summary>
    public TestAppHost()
        : base("BokaMera.API", typeof (ResourceTimeExceptionService).Assembly)

Sorry for my lack of competence here but maybe you can help me?

Running an AppHostHttpListenerBase in a Unit Test runs exactly the same instance when running a Self Host AppHostHttpListenerBase.

So you’ll need to explicitly set a flag yourself to indicate that it’s running in a Unit Test. You can use the existing TestMode property for this, e.g:

appHost = new TestAppHost { TestMode = true }
1 Like

Thx for the nice solution!