I've got a WCF REST Service which I'd like to unit test. i.e - 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 th开发者_高级运维e real DB.
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(),
};
}
i.e - with an URI template. Otherwise it's a normal WCF service.
Before I write a web based unit testing, help would be much appreciated :)
Waitin can be used to test web applications- I assume that it could be leveraged for REST services as well.
Checkout 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.
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.
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
精彩评论