Ejemplo n.º 1
0
		void RunInternal (ApplicationManager appMan)
		{
			ITestCase test = Activator.CreateInstance (TestType) as ITestCase;
			var runItems = new List <TestRunItem> ();			
			if (!test.SetUp (runItems)) {
				Success = false;
				FailureDetails = "Test aborted in setup phase.";
				return;
			}

			if (runItems.Count == 0) {
				Success = false;
				FailureDetails = "No test run items returned by the test case.";
				return;
			}
			
			Response response, previousResponse = null;
			TestRunner runner;
			string[] formValues;
			
			try {
				Console.Write ('[');
				foreach (var tri in runItems) {
					if (tri == null)
						continue;

					runner = null;
					response = null;
					try {
						runner = appMan.CreateObject (Info.Name, typeof (TestRunner), test.VirtualPath, test.PhysicalPath, true) as TestRunner;
						if (runner == null) {
							Success = false;
							throw new InvalidOperationException ("runner must not be null.");
						}
						
						if (tri.PostValues != null && previousResponse != null)
							formValues = ExtractFormAndHiddenControls (previousResponse);
						else
							formValues = null;
						
						response = runner.Run (tri.Url, tri.PathInfo, tri.PostValues, formValues);
						if (tri.Callback == null)
							continue;

						tri.TestRunData = runner.TestRunData;
						tri.StatusCode = runner.StatusCode;
						tri.Redirected = runner.Redirected;
						tri.RedirectLocation = runner.RedirectLocation;	

						if (tri.Callback != null)
							tri.Callback (response.Body, tri);
						
						Console.Write ('.');
					} catch (Exception) {
						FailedUrl = tri.Url;
						FailedUrlDescription = tri.UrlDescription;

						if (tri.Callback != null) {
							MethodInfo mi = tri.Callback.Method;
							FailedUrlCallbackName = FormatMethodName (mi);
						}
						Console.Write ('F');
						throw;
					} finally {
						if (runner != null) {
							runner.Stop (true);
							AppDomain.Unload (runner.Domain);
						}
						runner = null;
						previousResponse = response;
					}
				}
			} catch (AssertionException ex) {
				throw new TestCaseFailureException ("Assertion failed.", ex.Message, ex);
			} finally {
				Console.Write (']');
			}
		}