public void OneTestPassInParts()
		{
			string resultsText =
				"Name: MyTest\r\n" +
				"Result: Success\r\n";
			
			var stream = new MemoryStream();
			var streamReader = new StreamReader(stream);
			var reader = new TestResultsReader(streamReader);
			var results = new List<TestResult>();
			reader.TestFinished += (sender, e) => results.Add(e.Result);
			
			foreach (char ch in resultsText) {
				byte[] bytes = Encoding.UTF8.GetBytes(new char[] { ch });
				stream.Write(bytes, 0, bytes.Length);
				stream.Position--;
				reader.Run();
			}
			
			Assert.AreEqual(1, results.Count);
			
			TestResult result = results[0];
			Assert.AreEqual("MyTest", result.Name);
			Assert.IsTrue(result.IsSuccess);
		}
		List<TestResult> ReadTestResults(string resultsText)
		{
			var reader = new TestResultsReader(new StringReader(resultsText));
			var results = new List<TestResult>();
			reader.TestFinished += (sender, e) => results.Add(e.Result);
			reader.Run();
			return results;
		}
		public void OneTestPass()
		{
			string resultsText = "Name: MyTest\r\n" +
				"Result: Success\r\n";

			TestResultsReader reader = new TestResultsReader();
			TestResult[] results = reader.Read(resultsText);
			
			Assert.AreEqual(1, results.Length);
			
			TestResult result = results[0];
			Assert.AreEqual("MyTest", result.Name);
			Assert.IsTrue(result.IsSuccess);
			Assert.AreEqual(TestResultType.Success, result.ResultType);
		}
		/// <summary>
		/// Starts monitoring for test results.
		/// </summary>
		public void Start()
		{
			testResultsReader = new TestResultsReader();
			ResetFilePosition();
			
			string filter = fileInfo.Name;
			fileSystemWatcher = new FileSystemWatcher(fileInfo.DirectoryName, filter);
			
			if (File.Exists(fileInfo.FullName)) {
				fileSystemWatcher.NotifyFilter = NotifyFilters.LastWrite;
				fileSystemWatcher.Changed += FileChanged;
			} else {
				fileSystemWatcher.Created += FileCreated;
			}
			fileSystemWatcher.Error += FileSystemWatcherError;
			fileSystemWatcher.EnableRaisingEvents = true;
		}
		public void OneTestFailure()
		{
			string resultsText = "Name: MyTest\r\n" +
				"Result: Failure\r\n";

			TestResultsReader reader = new TestResultsReader();
			TestResult[] results = reader.Read(resultsText);
			
			Assert.AreEqual(1, results.Length);
			
			TestResult result = results[0];
			Assert.AreEqual("MyTest", result.Name);
			Assert.IsTrue(result.IsFailure);
			Assert.IsFalse(result.IsSuccess);
			Assert.IsFalse(result.IsIgnored);
			Assert.AreEqual(TestResultType.Failure, result.ResultType);
		}
示例#6
0
        /// <summary>
        /// Starts monitoring for test results.
        /// </summary>
        public void Start()
        {
            testResultsReader = new TestResultsReader();
            ResetFilePosition();

            string filter = fileInfo.Name;

            fileSystemWatcher = new FileSystemWatcher(fileInfo.DirectoryName, filter);

            if (File.Exists(fileInfo.FullName))
            {
                fileSystemWatcher.NotifyFilter = NotifyFilters.LastWrite;
                fileSystemWatcher.Changed     += FileChanged;
            }
            else
            {
                fileSystemWatcher.Created += FileCreated;
            }
            fileSystemWatcher.Error += FileSystemWatcherError;
            fileSystemWatcher.EnableRaisingEvents = true;
        }
		public void OneTestPassInParts()
		{
			string resultsText = "Name: MyTest\r\n" +
				"Result: Success\r\n";

			TestResultsReader reader = new TestResultsReader();
			
			List<TestResult> results = new List<TestResult>();
			foreach (char ch in resultsText) {
				TestResult[] readResults = reader.Read(ch.ToString());
				if (readResults.Length > 0) {
					foreach (TestResult readResult in readResults) {
						results.Add(readResult);
					}
				}
			}
			
			Assert.AreEqual(1, results.Count);
			
			TestResult result = results[0];
			Assert.AreEqual("MyTest", result.Name);
			Assert.IsTrue(result.IsSuccess);
		}
		public void TestMessage()
		{
			string resultsText = "Name: Test\r\n" +
				"Message: Should not be 0.\r\n" +
				"Result: Failure\r\n";

			TestResultsReader reader = new TestResultsReader();
			TestResult[] results = reader.Read(resultsText);
			
			Assert.AreEqual(1, results.Length);
			
			TestResult result = results[0];
			Assert.AreEqual("Test", result.Name);
			Assert.AreEqual("Should not be 0.", result.Message);
			Assert.IsTrue(result.IsFailure);
		}
		public void TwoTestFailuresWithMultilineMessages()
		{
			string resultsText = "Name: MyTest1\r\n" +
				"Message: FirstLine\r\n" +
				" SecondLine\r\n" +
				"Result: Failure\r\n" +
				"Name: MyTest2\r\n" +
				"Message: FirstLine\r\n" +
				" SecondLine\r\n" +
				" ThirdLine\r\n" +
				"Result: Failure\r\n";

			TestResultsReader reader = new TestResultsReader();
			TestResult[] results = reader.Read(resultsText);
			
			Assert.AreEqual(2, results.Length);
			
			TestResult result1 = results[0];
			Assert.AreEqual("MyTest1", result1.Name);
			Assert.AreEqual("FirstLine\r\nSecondLine", result1.Message);
			Assert.IsTrue(result1.IsFailure);
			
			TestResult result2 = results[1];
			Assert.AreEqual("MyTest2", result2.Name);
			Assert.AreEqual("FirstLine\r\nSecondLine\r\nThirdLine", result2.Message);
			Assert.IsTrue(result2.IsFailure);
		}
		public void TwoTestFailures()
		{
			string resultsText = "Name: MyTest1\r\n" +
				"Result: Failure\r\n" +
				"Name: MyTest2\r\n" +
				"Result: Failure\r\n";

			TestResultsReader reader = new TestResultsReader();
			TestResult[] results = reader.Read(resultsText);
			
			Assert.AreEqual(2, results.Length);
			
			TestResult result1 = results[0];
			Assert.AreEqual("MyTest1", result1.Name);
			Assert.IsTrue(result1.IsFailure);
			
			TestResult result2 = results[1];
			Assert.AreEqual("MyTest2", result2.Name);
			Assert.IsTrue(result2.IsFailure);
		}
		public void MissingNameValuePairOnFirstLine()
		{
			string resultsText = "MissingNameValuePair\r\n" +
				"Name: Test\r\n" +
				"Result: Failure\r\n";

			TestResultsReader reader = new TestResultsReader();
			TestResult[] results = reader.Read(resultsText);
			
			Assert.AreEqual(1, results.Length);
			
			TestResult result = results[0];
			Assert.AreEqual("Test", result.Name);
			Assert.IsTrue(result.IsFailure);
		}
		public void ResultWithNoTestName()
		{
			string resultsText = "Result: Failure\r\n";

			TestResultsReader reader = new TestResultsReader();
			TestResult[] results = reader.Read(resultsText);
			
			Assert.AreEqual(0, results.Length);
		}
		public void TestStackTrace()
		{
			string resultsText = "Name: Test\r\n" +
				"StackTrace: stack trace\r\n" +
				"Result: Failure\r\n";

			TestResultsReader reader = new TestResultsReader();
			TestResult[] results = reader.Read(resultsText);
			
			Assert.AreEqual(1, results.Length);
			
			TestResult result = results[0];
			Assert.AreEqual("Test", result.Name);
			Assert.AreEqual("stack trace", result.StackTrace);
			Assert.IsTrue(result.IsFailure);
		}