Unit testing class in a web service in .net -


After doing some digging here, I consulted in this thread:

I had a separate class and My web service class is only for that cover The problem is that when I try to prepare the unit test project in VS-2008, it emphasizes the creation of a unit test, as if the web instead of the specified class I I'm testing service call. I can not go into the class that I am trying to test.

I have a web service "subscription_api.asmx" behind the code "subscription_api.cs" in which "subscription.cs" contains the web code wrapper call to the actual code.

I hope to be able to do the following:

  [TestMethod ()] Public Zero GetSystemStatusTest () {subscription sub = new subscription ()); XmlNode node = sub.GetSystemStatusTest (); Assert.IsNotNull (node); }  

But instead I get this mess which is generated automatically from VS'08:

  /// & lt; Summary & gt; /// GetSystemStatus /// & lt; / Summary & gt; TODO a test for: // Make sure that the UrlToTest attribute specifies a URL on the ASP.NET page (for example, // http: //.../Default.aspx). It is necessary to test the unit tested on the web server, // Are you testing a page, web service, or WCF service [Testimite] [Host Type ("ASPNET")] [Aspen Development ServerHost ("C: \\ CVROOT \\ RNR \\ PRO \\ PRODUCT \\ wms \\ SS \\ Subscription API \ "/ Subscription_API"] [UrlToTest ("http: // localhost / subscription_api")] Public Zero GetSystemStatusTest () { Subscription_Accessor target = new subscription_Accessor (); // TODO: Beginning of an appropriate value of XmlNode = zero; // TODO: Start an appropriate value in XmlNode; Real = target GetSystemStatus (); Extraordinary (Expected, real); Undefined ("Verify the correctness of this test method."); }  

Additionally, there is a "subscription_api.accessor" in the test reference folder.

When I try this:

  [TestMethod ()] Public Zero GetSystemStatusTest2 () {subscription_Accessor sub = new subscription_Accessor (); XMLNode node = subgateSystemStats (); Assert.IsNotNull (node); }  

I get an error:

  test method subscription_api.Test.subscriptionTest.GetSystemStatusTest2 exception was televised: System.TypeInitializationException: for 'subscription_Accessor' Type initializer threw an exception --- & gt; System.ArgumentNullException: The value can not be empty  

I'm actually new to the unit testing and I think lost. Without testing the web service, how can I create a unit test for my membership class in "subscription.cs" only? Am I limited to testing within a single project (I do not expect)? Do I have to keep the target class in my own project outside of the web service project?

It sounds as if your Web service is in the "Web site" project instead of the "web application" project The problem was that web sites have not been created in single DLL, which you can refer to as web projects.

If this is the case and you are using the Web site type project, then you will need to turn it into a web application project to take advantage of the code directly in the testing unit to change your blog. There are many blog posts, just search for "convert asp.net web site to web application".

Alternatively, in addition to / else, you can move this code to your own class library and the library in the project in which your web service is located.


Comments