title: Unit testing class in a web service in .net
body: <p>After some digging here, I took the advice in this thread: <a href="https://stackoverflow.com/questions/371961/how-to-unit-test-c-web-service-with-visual-studio-2008">How to unit test C# Web Service with Visual Studio 2008</a></p>
  
  <p>I've created a separate class and my web service class is just a wrapper for that one. The problem is that when I try to create a unit test project in VS2008, it insists on creating a unit test that acts like I'm testing the web service calls instead of the class I specified. I can't get to the class I'm trying to test.</p>
  
  <p>I have a web service "subscription_api.asmx". The code behind is "subscription_api.cs" which contains the web method wrapper calls to the real code at "subscription.cs". </p>
  
  <p>I would expect to be able to do the following:</p>
  
  <pre><code>[TestMethod()]
          public void GetSystemStatusTest()
          {
              subscription sub = new subscription();
              XmlNode node = sub.GetSystemStatusTest();
              Assert.IsNotNull(node);
          }
  </code></pre>
  
  <p>But instead I get this mess which is autogenerated from VS'08:</p>
  
  <pre><code>/// &lt;summary&gt;
          ///A test for GetSystemStatus
          ///&lt;/summary&gt;
          // TODO: Ensure that the UrlToTest attribute specifies a URL to an ASP.NET page (for example,
          // http://.../Default.aspx). This is necessary for the unit test to be executed on the web server,
          // whether you are testing a page, web service, or a WCF service.
          [TestMethod()]
          [HostType("ASP.NET")]
          [AspNetDevelopmentServerHost("C:\\CVSROOT\\rnr\\pro\\product\\wms\\ss\\subscription_api", "/subscription_api")]
          [UrlToTest("http://localhost/subscription_api")]
          public void GetSystemStatusTest()
          {
              subscription_Accessor target = new subscription_Accessor(); // TODO: Initialize to an appropriate value
              XmlNode expected = null; // TODO: Initialize to an appropriate value
              XmlNode actual;
              actual = target.GetSystemStatus();
              Assert.AreEqual(expected, actual);
              Assert.Inconclusive("Verify the correctness of this test method.");
          }
  </code></pre>
  
  <p>Additionally, there is a "subscription_api.accessor" in the Test References folder.</p>
  
  <p>When I try this:</p>
  
  <pre><code>[TestMethod()]
  public void GetSystemStatusTest2()
  {
      subscription_Accessor sub = new subscription_Accessor();
      XmlNode node = sub.GetSystemStatus();
      Assert.IsNotNull(node);
  }
  </code></pre>
  
  <p>I get an error:</p>
  
  <pre><code>Test method subscription_api.Test.subscriptionTest.GetSystemStatusTest2 threw exception:  System.TypeInitializationException: The type initializer for 'subscription_Accessor' threw an exception. ---&gt;  System.ArgumentNullException: Value cannot be null.
  </code></pre>
  
  <p>I'm really new to unit testing and feel lost. How can I create a unit test just for my subscription class in "subscription.cs" without testing the web service? Am I limited to testing within the same project (I hope not)? Do I have to put the target class in its own project outside of the web service project?</p>