示例#1
0
		/// <summary>
		/// Starts the specified server.
		/// </summary>
		/// <param name="server">The server.</param>
		public void Start(IServer server)
		{
			RequiresNotNull(server);
			var instructions = new BuildInstructions(Guid.Empty, string.Empty, string.Empty);
			try
			{
				instructions = GetBuildInstructions(server);
				BuildProject(server, instructions);
				ExecuteNUnitTestRunner(server, instructions);
			}
			catch (FileNotFoundException e)
			{
				log.Log(LogSeverity.Error,  $"The file was not found: {e.FileName}");
				var status = new ClientInformation(Environment.MachineName, instructions.Session, BuildStatus.Failed,
					new TestResult[0]);
				server.UpdateClientStatus(status);
			}
			catch (Win32Exception e)
			{
				log.Log(LogSeverity.Error, $"Error launching the build process: {e.Message}");
				var status = new ClientInformation(Environment.MachineName, instructions.Session, BuildStatus.Failed,
					new TestResult[0]);
				server.UpdateClientStatus(status);
			}
			catch (ApplicationException e)
			{
				log.Log(LogSeverity.Error, $"Error building the project: {e.Message}");
				var status = new ClientInformation(Environment.MachineName, instructions.Session, BuildStatus.Failed,
					new TestResult[0]);
				server.UpdateClientStatus(status);
			}
		}
示例#2
0
			/// <summary>
			/// Initializes a new instance of the <see cref="Item"/> class.
			/// </summary>
			/// <param name="client">The client.</param>
			public Item(ClientInformation client)
			{
				RequiresNotNull(client);
				this.Client = client;
				var r = client.TestResults.Select(x => x.Name + ": " + x.Status).Take(10);
				var tip = string.Join(" | ", r);
				this.Tip = tip + (client.TestResults.Count > 10 ? " | ..." : string.Empty);
				Passed = client.TestResults.Count(x => x.Status == TestStatus.Passed);
			}
示例#3
0
		private BuildInstructions GetBuildInstructions(IServer server)
		{
			log.Log(LogSeverity.Information, "Getting build instructions");
			var instructions = server.GetBuildInstructions(Environment.MachineName);
			log.Log(LogSeverity.Information, $"Building session {instructions.Session}");
			var status = new ClientInformation(Environment.MachineName, instructions.Session, BuildStatus.InProgress,
				new TestResult[0]);
			server.UpdateClientStatus(status);
			return instructions;
		}
示例#4
0
		private void ExecuteNUnitTestRunner(IServer server, BuildInstructions instructions)
		{
			log.Log(LogSeverity.Information, "Executing NUnit Test Runner");
			XmlNode result2;
			using (var r = new TestEngine())
			{
				r.Initialize();
				var pkg = new TestPackage(instructions.TargetUnitTestingAssembly);
				using (var runner = r.GetRunner(pkg))
				{
					var filter = TestFilter.Empty;
					var tests = runner.CountTestCases(filter);
					log.Log(LogSeverity.Information, $"Found {tests} tests");
					result2 = runner.Run(null, filter);
				}
			}
			
			Func<string, TestStatus> parse = x =>
			{
				if(x == "Passed") return TestStatus.Passed;
				return TestStatus.Failed;
			};

			ClientInformation status;
			try
			{
				var root = XDocument.Parse(result2.OuterXml);
				var testResults =
					from el in root.Descendants("test-case")
					select new TestResult(el.Attribute("name").Value, parse(el.Attribute("result").Value));
				status = new ClientInformation(Environment.MachineName, instructions.Session, BuildStatus.Successful, testResults.ToArray());
			}
			catch (Exception e)
			{
				var msg = "Error parsing test result XML document, check version of NUnit";
				log.Log(LogSeverity.Error, msg);
				throw new ApplicationException(msg, e);
			}
			
			server.UpdateClientStatus(status);
			log.Log(LogSeverity.Information, "Test fixtures execution complete");
		}
示例#5
0
		private void BuildProject(IServer server, BuildInstructions instructions)
		{
			log.Log(LogSeverity.Information, "Building project");
			var startOptions = new ProcessStartInfo(instructions.BuildCommand);
			startOptions.UseShellExecute = false;
			var process = Process.Start(startOptions);
			ClientInformation status;
			if (!process.WaitForExit(TimeOutMilliseconds))
			{
				status = new ClientInformation(Environment.MachineName, instructions.Session, BuildStatus.Failed, new TestResult[0]);
				server.UpdateClientStatus(status);
				log.Log(LogSeverity.Warning, $"Build project is timed out, {process.ExitTime}");
				throw new TimeoutException();
			}

			var result = process.ExitCode == 0 ? BuildStatus.InProgress : BuildStatus.Failed;
			status = new ClientInformation(Environment.MachineName, instructions.Session, result, new TestResult[0]);
			server.UpdateClientStatus(status);
			if (result == BuildStatus.Failed)
			{
				log.Log(LogSeverity.Error, $"Build project failed: executing {instructions.BuildCommand} - Exit code {process.ExitCode}");
				throw new ApplicationException();
			}
		}
示例#6
0
		/// <summary>
		/// Updates the client status.
		/// </summary>
		/// <param name="info">The information.</param>
		public void UpdateClientStatus(ClientInformation info)
		{
			RequiresNotNull(info);
			statusBySession[info.Session] = info;
		}