开发者

Is it possible Create and Close wcf Service Host in MS Test

开发者 https://www.devze.com 2023-01-23 02:38 出处:网络
I usually use NUnit as a UnitTest Framework ,however where I work now they use solely MSTest . In Nunit I could use the following:

I usually use NUnit as a UnitTest Framework ,however where I work now they use solely MSTest . In Nunit I could use the following:

    [FixtureSetup]
    public override void MainSetup()
    {
开发者_JAVA百科        _serviceHost = new ServiceHost(typeof(PersonService));
        _serviceHost.Open();
     }
     [FixtureTearDown]
     public override void MainTeardown()
     {
        _serviceHost.Close();
     }

I have noticed that in MSTest if you want to initialize for the duration of all test and close after all tests have run you have to use below STATIC method and as you know I cannot use my class anymore. The below method will crash!!!

    [ClassInitialize()]
    public static void MyClassInitialize(TestContext testContext)
    {
        _serviceHost = new ServiceHost(typeof(PersonService));
        _serviceHost.Open();
    }

How can I initialize my service Host once and close after all the test have run in MSTest?

Thanks for any suggestions


If you make the _serviceHost variable static too, you should be safe.

0

精彩评论

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