Testing web service in VS08

Last post 02-29-2008 5:40 AM by vipi. 1 replies.

Sort Posts:

  • Testing web service in VS08

    02-18-2008, 4:29 AM
    • Loading...
    • vipi
    • Joined on 10-13-2006, 4:25 AM
    • Czech Republic
    • Posts 23

    Hello,
    I need create unit test for my web service in VS 2008 Professional.
    If I create new unit test directly on method in my App_Code directory the wizard creates new test project with selected test methods. 

    1            /// <summary>
    2            ///A test for GetUpdatedObjects
    3            ///</summary>
    4            [TestMethod()]
    5            [HostType("ASP.NET")]
    6            [AspNetDevelopmentServerHost("C:\\Test\\code\\Web\\Core\\WebService", "/WebService")]
    7            [UrlToTest("http://localhost/WebService")]
    8            public void GetUpdatedObjectsTest()
    9            {
    10               BrokerService_Accessor target = new BrokerService_Accessor(); // TODO: Initialize to an appropriate value
    11               DateTime lastUpdate = new DateTime(); // TODO: Initialize to an appropriate value
    12               Guid applicationGuid = new Guid(); // TODO: Initialize to an appropriate value
    13               DateTime actualUpdate = new DateTime(); // TODO: Initialize to an appropriate value
    14               DateTime actualUpdateExpected = new DateTime(); // TODO: Initialize to an appropriate value
    15               List expected = null; // TODO: Initialize to an appropriate value
    ... 

     
    But if I run this test the response is following: The Web request 'http://localhost:2246/WebService' completed successfully without running the test. This can occur when configuring the Web application for testing fails (an ASP.NET server error occurs when processing the request), or when no ASP.NET page is executed (the URL may point to an HTML page, a Web service, or a directory listing). Running tests in ASP.NET requires the URL to resolve to an ASP.NET page and for the page to execute properly up to the Load event. The response from the request is stored in the file 'WebRequestResponse_GetUpdatedObjectsTes.html' with the test results; typically this file can be opened with a Web browser to view its contents.

    I have tried searching another ways to testing web methods, but I have not found any good solution.

    What is proper way to test web methods? What is ***_Accessor usable for?

    Any help will be appreciated..
     

    vipi
  • Re: Testing web service in VS08

    02-29-2008, 5:40 AM
    Answer
    • Loading...
    • vipi
    • Joined on 10-13-2006, 4:25 AM
    • Czech Republic
    • Posts 23

    I have discovered that if you want test project which uses web services or component which references such as projects -- it's important to:

    1. create unit test to project which uses web service (just right click..)
    2. do not use any hosttype, aspnetdevelopmentserverhost, urltotest atrributes, just simple TestMethod()
    3. you need add to test project app.config file as same as app.config in tested component  (you can copy that to test project or better is add as link).
      • It's from reason that because that test process running in other domain, more info at http://207.46.196.83/MSDN/ShowPost.aspx?PostID=2482486&SiteID=1
    4. Just run the test, it works fine..
    Stick out tongue
    vipi
Page 1 of 1 (2 items)
Microsoft Communities
Page view counter