简体   繁体   English

如何在vs“单元测试项目”中测试wcf休息服务?

[英]how to test wcf rest services in vs “unit test project”?

I've created a new solution with WCF REST services. 我用WCF REST服务创建了一个新的解决方案。 Now I need to unit test the services. 现在我需要对服务进行单元测试。 For example, here's a REST service url: 例如,这是一个REST服务URL:

cars/{id} 汽车/ {ID}

The GET method should return a car object with the id provided in the querystring. GET方法应该返回一个car对象,其中包含查询字符串中提供的id。 How can I configure through a VS unit test project? 如何通过VS单元测试项目进行配置?

Simple, create a self-hosted unit test, ie 简单,创建一个自托管单元测试,即

[TestInitialize]
public void Before_Each_Test()
{
   var host = new ServiceHost(typeof(CarService));
   // Override with local endpoint, i.e. a TCP connection, local IP etc

   host.Open();
}

Then dont forget to shut down the host in TestCleanup, of course. 然后别忘了在TestCleanup中关闭主机。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM