how to test wcf rest services in vs "unit test project"?

Greg Brattle

I've created a new solution with WCF REST services. Now I need to unit test the services. For example, here's a REST service url:

cars/{id}

The GET method should return a car object with the id provided in the querystring. How can I configure through a VS unit test project?

Pedro G. Dias

Simple, create a self-hosted unit test, i.e.

[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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

VS Unit Test Project missing NuGet packages

How to Unit Test a project with Multiple Configurations

How to add an assembly reference in unit test project?

WCF Service times out from windows 8 unit test project

Unit Test Project References Console Application VS2015

VS2015 Unit test project is unable to find a method

how to make connection between visual studio project and unit test project?

How to figure out why ReSharper is not rebuilding unit test project before running?

How can I add an assembly binding redirect to a .net core unit test project?

How can I access data source from different folders in my unit test project?

How to build the Unit Test project along with the 'Visual Studio Build' task in CI build Azure DevOps

How to add a unit test project to my existing asp.net core project?

Android Instrumented unit test on project library

In Visual Studio native unit test, is it possible to couple unit test to a project?

Add a unit test project to an existing Qt Creator project

Enable unmanaged code debugging in Windows Phone 8.1 Unit Test project

ConfigurationManager.AppSettings Returns Null In Unit Test Project

Unable to get Default Constructor for class in Unit Test Project

ASP.NET MVC Unit Test Project Entity Framework error

C# Unit Test project against WebApi with Owin

DeploymentItem(Path, outputDirectory) not working in new Unit-Test project

Errors in Unit Test project when including file from main project

Unable to build My Unit Test Project in Visual Studio 2017

C++ Heap Corruption but only in Unit Test Project

Setting up a Lib Project and Unit Test Project in same workspace

How to return datatable form wcf rest services?

Visual Studio C++ difference between Managed Test Project and Native Unit Test Project

Azure Function Build Pipelines Fails when Unit Test Project references the Function project

Does it matter that Unit Test project template in Visual Studio 2019 is for .NET Framework only?