开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜