CassiniDevNUnitFixture.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net;
  5. using System.Text;
  6. using NUnit.Framework;
  7. namespace CassiniDev.NUnitFixtures.Tests
  8. {
  9. /// <summary>
  10. /// Note: this fixture leverages the in-process CassiniDev server. If you have restrictions or experience
  11. /// issues with the in-process server, simply reference CassiniDev-console and use CassiniDevServerOP.
  12. /// API and usage is same.
  13. /// </summary>
  14. [TestFixture]
  15. public class CassiniDevNUnitFixture : CassiniDevServer
  16. {
  17. [TestFixtureSetUp]
  18. public void TestFixtureSetUp()
  19. {
  20. // assuming your test project and web project or site are in the same parent directory
  21. const string applicationPath = @"..\..\..\..\CassiniDev.TestSite";
  22. // Will start specified application as "localhost" on loopback and first available port in the range 8000-10000 with vpath "/"
  23. StartServer(applicationPath);
  24. // if you would like to exercise more control simply use any of the available overloads
  25. }
  26. [TestFixtureTearDown]
  27. public void TestFixtureTearDown()
  28. {
  29. StopServer();
  30. }
  31. [Test]
  32. public void Test()
  33. {
  34. // normalize URL provides a fully qualified URL rooted on the currently running server's hostname and port
  35. string url = NormalizeUrl("Default.aspx");
  36. WebClient wc = new WebClient();
  37. string actual = wc.DownloadString(url);
  38. Assert.IsTrue(actual.Contains("this is default.aspx"));
  39. // for a web testing utility library that simplifies endpoint testing see the Salient.Web namespace in http://salient.codeplex.com
  40. }
  41. }
  42. }