Библиотека

Магистр ДонНТУ Морозов Дмитрий Сергеевич

Тема выпускной работы: Система моделирования технологической схемы производства и организации работы с документами

Научный руководитель: доцент кафедры компьютерной инженерии, кандидат технических наук Теплинский Сергей Васильевич



Test Run

WCF Service Testing with Sockets


Dr. James McCaffrey


In this month’s column I am joined by Carlos Figueira, a senior software development engineer in Test on the Windows Communication Foundation (WCF) team. With his help I intend to show you how to test WCF services using a network socket-based approach.

A good way for you to see where I’m headed is to examine the screenshots in Figures 1, 2 and 3. Figure 1 shows a WinForm application that hosts a simple-but-representative WCF service named MathService. Behind the scenes, MathService contains a single operation named Sum that accepts two values of type double, then computes and returns their sum.


WCF MathService Service Under Test
Figure 1 WCF MathService Service Under Test


Figure 2 shows a typical WCF ASP.NET Web application client that accepts two values from the user, sends those two values to the MathService service, fetches the response from the service, and displays the result in a ListBox control.


Typical WCF ASP.NET Client
Figure 2 Typical WCF ASP.NET Client


Figure 3 shows a console application test harness that performs functional verification of the MathService service. The test harness sends SOAP messages directly to MathService using a network socket, accepts the response from the service, and compares an expected result with the actual result to determine a pass or fail. In test case #001, the test harness sends 3.4 and 5.7 to the WCF service under test and receives the expected value 9.1. Test case #002 is a deliberate, spurious failure just for demonstration purposes.

In the sections that follow, I first briefly describe the WCF service under test shown in Figure 1 so you’ll understand which factors are relevant when constructing WCF socket-based test automation. Next I briefly explain the demonstration Web client to give you some insight into when socket-based testing is more appropriate than alternative techniques. Then I explain in detail the code that created the test harness so that you will be able to adapt the technique I present here to meet your own needs. This article assumes you have intermediate-level C# coding skills.


WCF Test Harness Run
Figure 3 WCF Test Harness Run


Full acticle can be found here: http://msdn.microsoft.com/en-us/magazine/ee309879.aspx