简体   繁体   English

单元测试WCF REST服务

[英]Unit Testing WCF REST Services

I've got a WCF REST Service which I'd like to unit test. 我有一个WCF REST服务,我想进行单元测试。 ie - I've got all the business logic tested (full separation of layers), but would like to check if the WCF service works as wanted with all the logic and the real DB. 即 - 我已经测试了所有业务逻辑(完全分离层),但是想检查WCF服务是否按照所有逻辑和真实数据库的要求工作。

I couldn't find any useful info on this. 我找不到任何有用的信息。

Each method looks like this: 每种方法如下所示:

[WebGet(UriTemplate = "Version?ts={ts}", ResponseFormat = System.ServiceModel.Web.WebMessageFormat.Json)]
public WCF_Response GetVersion( string ts)
{
    return new ApiVersion { 
        version = VersionManager.CurrentVersion(),
    };
}

ie - with an URI template. 即 - 使用URI模板。 Otherwise it's a normal WCF service. 否则,这是一个普通的WCF服务。

Before I write a web based unit testing, help would be much appreciated :) 在我编写基于Web的单元测试之前,非常感谢帮助:)

Checkout http://www.castleproject.org/container/facilities/trunk/wcf/index.html 结帐http://www.castleproject.org/container/facilities/trunk/wcf/index.html

I used it last year on a large WCF rest project and it worked great. 我去年在一个大型的WCF休息项目中使用它并且效果很好。

Don't have access to the codebase anymore but the unit tests also used castle windsor IoC, so I could run all tests with no external dependencies. 不再访问代码库,但单元测试也使用了城堡windsor IoC,所以我可以运行所有测试,没有外部依赖。

They looked something like 他们看起来像

Component.For<IOrder>()
     .Named("order.service")
     .ImplementedBy<Order>()
    .ActAs(new RestServiceModel()
     {
      Endpoints = new IWcfEndpoint[] { WcfEndpoint.BoundTo(new WebHttpBinding() { TransferMode=TransferMode.Streamed, MaxBufferSize=int.MaxValue,MaxReceivedMessageSize=long.MaxValue }).At(OrderUrlBase) }
     })

Now the service is hosted by the unit test(not in IIS) and can be called using OrderUrlBase Url 现在,服务由单元测试(不在IIS中)托管,可以使用OrderUrlBase Url调用

Waitin可用于测试Web应用程序 - 我认为它也可以用于REST服务。

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

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