internal UnitTestResult RunUnitTest (UnitTest test, string suiteName, string pathName, string testName, TestContext testContext)
		{
			var runnerExe = GetCustomConsoleRunnerCommand ();
			if (runnerExe != null)
				return RunWithConsoleRunner (runnerExe, test, suiteName, pathName, testName, testContext);

			var console = testContext.ExecutionContext.ConsoleFactory.CreateConsole ();

			ExternalTestRunner runner = new ExternalTestRunner ();
			runner.Connect (NUnitVersion, testContext.ExecutionContext.ExecutionHandler, console).Wait ();
			LocalTestMonitor localMonitor = new LocalTestMonitor (testContext, test, suiteName, testName != null);

			string[] filter = null;
			if (test != null) {
				if (test is UnitTestGroup && NUnitVersion == NUnitVersion.NUnit2) {
					filter = CollectTests ((UnitTestGroup)test);
				} else if (test.TestId != null) {
					filter = new string [] { test.TestId };
				}
			}

			RunData rd = new RunData ();
			rd.Runner = runner;
			rd.Test = this;
			rd.LocalMonitor = localMonitor;

			var cancelReg = testContext.Monitor.CancellationToken.Register (rd.Cancel);

			UnitTestResult result;
			var crashLogFile = Path.GetTempFileName ();

			try {
				if (string.IsNullOrEmpty (AssemblyPath)) {
					string msg = GettextCatalog.GetString ("Could not get a valid path to the assembly. There may be a conflict in the project configurations.");
					throw new Exception (msg);
				}

				string testRunnerAssembly, testRunnerType;
				GetCustomTestRunner (out testRunnerAssembly, out testRunnerType);

				testContext.Monitor.CancellationToken.ThrowIfCancellationRequested ();
					
				result = runner.Run (localMonitor, filter, AssemblyPath, "", new List<string> (SupportAssemblies), testRunnerType, testRunnerAssembly, crashLogFile).Result;
				if (testName != null)
					result = localMonitor.SingleTestResult;
				
				ReportCrash (testContext, crashLogFile);
				
			} catch (Exception ex) {
				if (ReportCrash (testContext, crashLogFile)) {
					result = UnitTestResult.CreateFailure (GettextCatalog.GetString ("Unhandled exception"), null);
				}
				else if (!localMonitor.Canceled) {
					LoggingService.LogError (ex.ToString ());
					if (localMonitor.RunningTest != null) {
						RuntimeErrorCleanup (testContext, localMonitor.RunningTest, ex);
					} else {
						testContext.Monitor.ReportRuntimeError (null, ex);
						throw;
					}
					result = UnitTestResult.CreateFailure (ex);
				} else {
					result = UnitTestResult.CreateFailure (GettextCatalog.GetString ("Canceled"), null);
				}
			} finally {
				if (console != null)
					console.Dispose ();
				cancelReg.Dispose ();
				runner.Dispose ();
				File.Delete (crashLogFile);
			}
			
			return result;
		}
Пример #2
0
        static void Main(string[] args)
        {
            //var sim = new Simulator();
            //sim.StartTest();
            //return;

            var test = new UnitTest();
            Console.WriteLine("Starting tests {0}", Environment.NewLine);
            Console.WriteLine("POSITIVE CASES:{0}", Environment.NewLine);
            Console.WriteLine("Big Token: {0}{1}", test.GetRealyBigToken(), Environment.NewLine);
            var basicToken = test.GetBasicToken();

            Console.WriteLine("Basic Token: {0}{1}", new Uri(basicToken, UriKind.RelativeOrAbsolute), Environment.NewLine);
            Console.WriteLine("Basic Token: {0}{1}", basicToken, Environment.NewLine);
            Console.WriteLine("Token Appended to URL: {0}{1}", test.GetTokenAppendedToUrl(), Environment.NewLine);
            Console.WriteLine("Token for a specific URL not just an ACL: {0}{1}", test.GetSpecificUrlToken(), Environment.NewLine);
            Console.WriteLine("Token with default StartTime: {0}{1}", test.GetTokenWithDefaultStartTime(), Environment.NewLine);
            Console.WriteLine("Token with simple key: {0}{1}", test.GetTokenWithSimpleKey(), Environment.NewLine);

            Console.WriteLine("NEGATIVE CASES:{0}", Environment.NewLine);
            Console.WriteLine("Token with invalid length key: {0}{1}", test.GetTokenWithInvalidLengthKey(), Environment.NewLine);
            Console.WriteLine("Token with invalid non-alphanum key: {0}{1}", test.GetTokenWithInvalidNonAlphaNumKey(), Environment.NewLine);
            Console.WriteLine("Token with invalid key: {0}{1}", test.GetTokenWithInvalidKey(), Environment.NewLine);

            Console.ReadLine();
        }
Пример #3
0
	void OnGUI() {
		//GUI.DrawTexture (new Rect (0, 0, Screen.width, Screen.height), guiTex);
	    //GUI.DrawTextureWithTexCoords(new Rect(0, 0, 400, 400), skinTex, new Rect(0, 1f - (126f/512f), .2f,126f/512f));
        if (m_Canvas.Width != Screen.width || m_Canvas.Height != Screen.height) m_Canvas.SetSize(Screen.width,Screen.height);
	    if (m_UnitTest == null)
	    {
            //win.Title = "This is a window!";
            // create the unit test control
            m_UnitTest = new UnitTest(m_Canvas);
	    }
        if (Event.current.mousePosition.x != mousex || Event.current.mousePosition.y != mousey)
        {
            mousex = Event.current.mousePosition.x;
            mousey = Event.current.mousePosition.y;
            Event tmpevent = new Event();
            tmpevent.type = EventType.MouseMove;
            tmpevent.mousePosition = Event.current.mousePosition;
            m_Input.ProcessMessage(tmpevent);
        }
	    if (Event.current.type == EventType.Repaint)
	    {
            m_Canvas.RenderCanvas();
            
	    }
        else if (Event.current.type == EventType.MouseDown || Event.current.type == EventType.ScrollWheel || Event.current.type == EventType.MouseUp || Event.current.type == EventType.KeyDown || Event.current.type == EventType.KeyUp)
        {
            m_Input.ProcessMessage(Event.current);
        }
        
	}
Пример #4
0
		public void CanParseOptions()
		{
			string[] args = { "--quiet", "--unused", "--verbose", "--", "path1", "path2" };

			//Test without multi-path option
			//Simulates method that uses: argumentsRemaining = ParseOptions(args);
			var cmd = new UnitTest { ProcessMultiplePaths = false };
			cmd.Run(args);
			Assert.AreEqual(new List<String> { "--unused" }, cmd.ArgumentsRemaining);
			Assert.IsNull(cmd.FilePaths);

			//Test with multi-path option
			//Simulates method that uses: ParseOptions(args, out filePaths, out argumentsRemaining)
			cmd = new UnitTest { ProcessMultiplePaths = true };
			cmd.Run(args);
			Assert.AreEqual(new List<String> { "--unused" }, cmd.ArgumentsRemaining);
			Assert.AreEqual(new List<String> { "path1", "path2" }, cmd.FilePaths);
		}
Пример #5
0
 internal SourceCodeLocation GetSourceCodeLocation(UnitTest test)
 {
     return(GetSourceCodeLocation(test.FixtureTypeNamespace, test.FixtureTypeName, test.Name));
 }
Пример #6
0
 public UnitTestResult GetPreviousResult(string configuration, UnitTest test, DateTime date)
 => cache.TryGetValue(test, out var result) ? result : null;
        public void PrintFamilyPrintsCorrectly()
        {
            // Extended MSTest
            Person person = new Person()
            {
                FirstName = "Robin",
                LastName  = "Rich",
                Age       = 10,
                Mother    = new Person()
                {
                    FirstName = "Anna",
                    LastName  = "Smith",
                    Age       = 38
                },
                Father = new Person()
                {
                    FirstName = "Warren",
                    LastName  = "Rich",
                    Age       = 36,
                    Mother    = new Person()
                    {
                        FirstName = "Elsa",
                        LastName  = "Johnson",
                        Age       = 65
                    },
                    Father = new Person()
                    {
                        FirstName = "Gustav",
                        LastName  = "Rich",
                        Age       = 66
                    }
                }
            };
            PersonPrinter printer = new PersonPrinter();

            string expectedOutput = string.Join(
                Environment.NewLine,
                "Robin Rich (10)",
                "Warren Rich (36)",
                "Gustav Rich (66)",
                "Elsa Johnson (65)",
                "Anna Smith (38)");

            ConsoleAssert.WritesOut(() => printer.PrintFamily(person), expectedOutput);

            // TestTools Code
            UnitTest test = Factory.CreateTest();
            TestVariable <Person>        _person  = test.CreateVariable <Person>("person");
            TestVariable <PersonPrinter> _printer = test.CreateVariable <PersonPrinter>("printer");

            test.Arrange(_person, Expr(() => new Person()
            {
                FirstName = "Robin",
                LastName  = "Rich",
                Age       = 10,
                Mother    = new Person()
                {
                    FirstName = "Anna",
                    LastName  = "Smith",
                    Age       = 38
                },
                Father = new Person()
                {
                    FirstName = "Warren",
                    LastName  = "Rich",
                    Age       = 36,
                    Mother    = new Person()
                    {
                        FirstName = "Elsa",
                        LastName  = "Johnson",
                        Age       = 65
                    },
                    Father = new Person()
                    {
                        FirstName = "Gustav",
                        LastName  = "Rich",
                        Age       = 66
                    }
                }
            }));
            test.ConsoleAssert.WritesOut(
                Lambda(Expr(_printer, _person, (p1, p2) => p1.PrintFamily(p2))),
                Const(expectedOutput));
            test.Execute();
        }
			void ClearRunningStatus (UnitTest t)
			{
				t.Status = TestStatus.Ready;
				UnitTestGroup group = t as UnitTestGroup;
				if (group == null) return;
				foreach (UnitTest ct in group.Tests)
					ClearRunningStatus (ct);
			}
Пример #9
0
 public AsyncReadOnlySessionTests()
 {
     ObjectInfo.MappingConvention = new ConventionMappingConvention(
         UnitTest.GetConventionMappingSettings(IdentifierStrategy.DbGenerated));
 }
		internal SourceCodeLocation GetSourceCodeLocation (UnitTest test)
		{
			return GetSourceCodeLocation (test.FixtureTypeNamespace, test.FixtureTypeName, test.Name);
		}
		void RuntimeErrorCleanup (TestContext testContext, UnitTest t, Exception ex)
		{
			UnitTestResult result = UnitTestResult.CreateFailure (ex);
			t.RegisterResult (testContext, result);
			while (t != null && t != this) {
				testContext.Monitor.EndTest (t, result);
				t.Status = TestStatus.Ready;
				t = t.Parent;
			}
		}
Пример #12
0
        private IEnumerator RunTestsCR()
        {
            while (m_QueuedTests.Count > 0)
            {
                Type testType = m_QueuedTests.Dequeue();

                m_ActiveTest = Activator.CreateInstance(testType) as UnitTest;
                if (m_ActiveTest != null)
                {
                    Log.Status("UnitTestManager", "STARTING UnitTest {0} ...", testType.Name);

                    // wait for the test to complete..
                    bool     bTestException = true;
                    DateTime startTime      = DateTime.Now;
                    try
                    {
                        IEnumerator e = m_ActiveTest.RunTest();
                        while (e.MoveNext())
                        {
                            if (m_ActiveTest.TestFailed)
                            {
                                break;
                            }

                            yield return(null);

                            if ((DateTime.Now - startTime).TotalSeconds > TEST_TIMEOUT)
                            {
                                Log.Error("UnitTestManager", "UnitTest {0} has timed out.", testType.Name);
                                m_ActiveTest.TestFailed = true;
                                break;
                            }
                        }

                        bTestException = false;
                        if (m_ActiveTest.TestFailed)
                        {
                            Log.Error("UnitTestManager", "... UnitTest {0} FAILED.", testType.Name);
                            TestsFailed += 1;
                        }
                        else
                        {
                            Log.Status("UnitTestManager", "... UnitTest {0} COMPLETED.", testType.Name);
                            TestsComplete += 1;
                        }
                    }
                    finally { }

                    if (bTestException)
                    {
                        Log.Error("UnitTestManager", "... UnitTest {0} threw exception.", testType.Name);
                        TestsFailed += 1;
                    }
                }
                else
                {
                    Log.Error("UnitTestManager", "Failed to instantiate test {0}.", testType.Name);
                    TestsFailed += 1;
                }
            }

            if (OnTestCompleteCallback != null)
            {
                OnTestCompleteCallback();
            }

            Log.Status("UnitTestManager", "Tests Completed: {0}, Tests Failed: {1}", TestsComplete, TestsFailed);
#if UNITY_EDITOR
            if (QuitOnTestsComplete)
            {
                EditorApplication.Exit(TestsFailed > 0 ? 1 : 0);
            }
#endif
        }
Пример #13
0
 protected override void SetModelParams(EditSimpleModel model, UnitTest unitTest)
 {
     model.Host = unitTest.PingRule.Host;
 }
Пример #14
0
 public static void Register()
 {
     UnitTest.RegisterAllMethods <_ManualyTest>();
     UnitTest.RegisterAllMethods <_AsyncTest>();
 }
Пример #15
0
 bool TestHasBeenRun(UnitTest test)
 {
     return(test.Status == TestStatus.Ready && !test.IsHistoricResult);
 }
Пример #16
0
 public void RegisterResult(string configuration, UnitTest test, UnitTestResult result)
 => cache.Add(test, result);
Пример #17
0
 public UnitTestResult [] GetResultsToDate(string configuration, UnitTest test, DateTime endDate, int count)
 => cache.Select(x => x.Value).ToArray();
Пример #18
0
 public UnitTestResult [] GetResults(string configuration, UnitTest test, DateTime startDate, DateTime endDate)
 => cache.Select(x => x.Value).ToArray();
Пример #19
0
        internal UnitTestResult RunUnitTest(UnitTest test, string suiteName, string pathName, string testName, TestContext testContext)
        {
            var runnerExe = GetCustomConsoleRunnerCommand();

            if (runnerExe != null)
            {
                return(RunWithConsoleRunner(runnerExe, test, suiteName, pathName, testName, testContext));
            }

            var console = testContext.ExecutionContext.ConsoleFactory.CreateConsole(
                OperationConsoleFactory.CreateConsoleOptions.Default.WithTitle(GettextCatalog.GetString("Unit Tests")));

            ExternalTestRunner runner = new ExternalTestRunner(Path.GetDirectoryName(AssemblyPath));

            runner.ProcessExecutionArchitecture = AssemblyUtilities.GetProcessExecutionArchitectureForAssembly(AssemblyPath);
            runner.Connect(NUnitVersion, testContext.ExecutionContext.ExecutionHandler, console).Wait();
            LocalTestMonitor localMonitor = new LocalTestMonitor(testContext, test, suiteName, testName != null);

            string[] filter = null;
            if (test != null)
            {
                if (test is UnitTestGroup && NUnitVersion == NUnitVersion.NUnit2)
                {
                    filter = CollectTests((UnitTestGroup)test);
                }
                else if (test.TestId != null)
                {
                    filter = new string [] { test.TestId };
                }
            }

            RunData rd = new RunData();

            rd.Runner       = runner;
            rd.Test         = this;
            rd.LocalMonitor = localMonitor;

            var cancelReg = testContext.Monitor.CancellationToken.Register(rd.Cancel);

            UnitTestResult result;
            var            crashLogFile = Path.GetTempFileName();

            try {
                if (string.IsNullOrEmpty(AssemblyPath))
                {
                    string msg = GettextCatalog.GetString("Could not get a valid path to the assembly. There may be a conflict in the project configurations.");
                    throw new Exception(msg);
                }

                string testRunnerAssembly, testRunnerType;
                GetCustomTestRunner(out testRunnerAssembly, out testRunnerType);

                testContext.Monitor.CancellationToken.ThrowIfCancellationRequested();

                var supportAssemblies = new List <string> (GetSupportAssembliesAsync().Result);
                result = runner.Run(localMonitor, filter, AssemblyPath, "", supportAssemblies, testRunnerType, testRunnerAssembly, crashLogFile).Result;
                if (testName != null)
                {
                    result = localMonitor.SingleTestResult;
                }

                ReportCrash(testContext, crashLogFile);
            } catch (Exception ex) {
                if (ReportCrash(testContext, crashLogFile))
                {
                    result = UnitTestResult.CreateFailure(GettextCatalog.GetString("Unhandled exception"), null);
                }
                else if (!localMonitor.Canceled)
                {
                    LoggingService.LogError(ex.ToString());
                    if (localMonitor.RunningTest != null)
                    {
                        RuntimeErrorCleanup(testContext, localMonitor.RunningTest, ex);
                    }
                    else
                    {
                        testContext.Monitor.ReportRuntimeError(null, ex);
                        throw;
                    }
                    result = UnitTestResult.CreateFailure(ex);
                }
                else
                {
                    result = UnitTestResult.CreateFailure(GettextCatalog.GetString("Canceled"), null);
                }
            } finally {
                // Dispose the runner before the console, to make sure the console is available until the runner is disposed.
                runner.Disconnect().Wait();
                runner.Dispose();
                if (console != null)
                {
                    console.Dispose();
                }
                cancelReg.Dispose();
                File.Delete(crashLogFile);
            }

            return(result);
        }
Пример #20
0
 protected override string GetOldReplacementPart(UnitTest unitTest)
 {
     return(unitTest.PingRule.Host);
 }
Пример #21
0
        UnitTestResult RunWithConsoleRunner(ProcessExecutionCommand cmd, UnitTest test, string suiteName, string pathName, string testName, TestContext testContext)
        {
            var outFile               = Path.GetTempFileName();
            var xmlOutputConsole      = new LocalConsole();
            var appDebugOutputConsole = testContext.ExecutionContext.ConsoleFactory.CreateConsole(
                OperationConsoleFactory.CreateConsoleOptions.Default.WithTitle(GettextCatalog.GetString("Unit Tests")));
            OperationConsole cons;

            if (appDebugOutputConsole != null)
            {
                cons = new MultipleOperationConsoles(appDebugOutputConsole, xmlOutputConsole);
            }
            else
            {
                cons = xmlOutputConsole;
            }
            try {
                MonoDevelop.UnitTesting.NUnit.External.TcpTestListener tcpListener = null;
                LocalTestMonitor localMonitor = new LocalTestMonitor(testContext, test, suiteName, testName != null);

                if (!string.IsNullOrEmpty(cmd.Arguments))
                {
                    cmd.Arguments += " ";
                }
                cmd.Arguments += "\"-xml=" + outFile + "\" " + AssemblyPath;

                bool automaticUpdates = cmd.Command != null && (cmd.Command.Contains("GuiUnit") || (cmd.Command.Contains("mdtool.exe") && cmd.Arguments.Contains("run-md-tests")));
                if (!string.IsNullOrEmpty(pathName))
                {
                    cmd.Arguments += " -run=\"" + test.TestId.Replace("\"", "\\\"") + "\"";
                }
                if (automaticUpdates)
                {
                    tcpListener    = new MonoDevelop.UnitTesting.NUnit.External.TcpTestListener(localMonitor, suiteName);
                    cmd.Arguments += " -port=" + tcpListener.Port;
                }
                cmd.WorkingDirectory = Path.GetDirectoryName(AssemblyPath);

                // Note that we always dispose the tcp listener as we don't want it listening
                // forever if the test runner does not try to connect to it
                using (tcpListener) {
                    var handler = testContext.ExecutionContext.ExecutionHandler;

                    if (handler == null)
                    {
                        handler = Runtime.ProcessService.DefaultExecutionHandler;
                    }

                    var p = handler.Execute(cmd, cons);
                    using (testContext.Monitor.CancellationToken.Register(p.Cancel))
                        p.Task.Wait();

                    if (new FileInfo(outFile).Length == 0)
                    {
                        throw new Exception("Command failed");
                    }
                }

                // mdtool.exe does not necessarily guarantee we get automatic updates. It just guarantees
                // that if guiunit is being used then it will give us updates. If you have a regular test
                // assembly compiled against nunit.framework.dll
                if (automaticUpdates && tcpListener.HasReceivedConnection)
                {
                    if (testName != null)
                    {
                        return(localMonitor.SingleTestResult);
                    }
                    return(test.GetLastResult());
                }

                XDocument doc = XDocument.Load(outFile);

                if (doc.Root != null)
                {
                    var root = doc.Root.Elements("test-suite").FirstOrDefault();
                    if (root != null)
                    {
                        xmlOutputConsole.SetDone();
                        var ot = xmlOutputConsole.OutReader.ReadToEnd();
                        var et = xmlOutputConsole.ErrorReader.ReadToEnd();
                        testContext.Monitor.WriteGlobalLog(ot);
                        if (!string.IsNullOrEmpty(et))
                        {
                            testContext.Monitor.WriteGlobalLog("ERROR:\n");
                            testContext.Monitor.WriteGlobalLog(et);
                        }

                        bool macunitStyle = doc.Root.Element("environment") != null && doc.Root.Element("environment").Attribute("macunit-version") != null;
                        var  result       = ReportXmlResult(localMonitor, root, "", macunitStyle);
                        if (testName != null)
                        {
                            result = localMonitor.SingleTestResult;
                        }
                        return(result);
                    }
                }
                throw new Exception("Test results could not be parsed.");
            } catch (Exception ex) {
                xmlOutputConsole.SetDone();
                var ot = xmlOutputConsole.OutReader.ReadToEnd();
                var et = xmlOutputConsole.ErrorReader.ReadToEnd();
                testContext.Monitor.WriteGlobalLog(ot);
                if (!string.IsNullOrEmpty(et))
                {
                    testContext.Monitor.WriteGlobalLog("ERROR:\n");
                    testContext.Monitor.WriteGlobalLog(et);
                }
                testContext.Monitor.ReportRuntimeError("Test execution failed.\n" + ot + "\n" + et, ex);
                return(UnitTestResult.CreateIgnored("Test execution failed"));
            } finally {
                File.Delete(outFile);
                cons.Dispose();
            }
        }
Пример #22
0
 static void Main(string[] args)
 {
     UnitTest.Main();
 }
Пример #23
0
        protected override string GetOldReplacementPart(UnitTest unitTest)
        {
            var url = unitTest.HttpRequestUnitTest.Rules.First(FindRulePredicate()).Url;

            return(GetComponentNameFromUrl(url));
        }
Пример #24
0
		public LocalTestMonitor (TestContext context, ExternalTestRunner runner, UnitTest rootTest, string rootFullName, bool singleTestRun)
		{
			this.rootFullName = rootFullName;
			this.rootTest = rootTest;
			this.context = context;
			this.singleTestRun = singleTestRun;
		}
		UnitTestResult RunWithConsoleRunner (ProcessExecutionCommand cmd, UnitTest test, string suiteName, string pathName, string testName, TestContext testContext)
		{
			var outFile = Path.GetTempFileName ();
			var xmlOutputConsole = new LocalConsole ();
			var appDebugOutputConsole = testContext.ExecutionContext.ConsoleFactory.CreateConsole ();
			OperationConsole cons;
			if (appDebugOutputConsole != null) {
				cons = new MultipleOperationConsoles (appDebugOutputConsole, xmlOutputConsole);
			} else {
				cons = xmlOutputConsole;
			}
			try {
				MonoDevelop.UnitTesting.NUnit.External.TcpTestListener tcpListener = null;
				LocalTestMonitor localMonitor = new LocalTestMonitor (testContext, test, suiteName, testName != null);

				if (!string.IsNullOrEmpty (cmd.Arguments))
					cmd.Arguments += " ";
				cmd.Arguments += "\"-xml=" + outFile + "\" " + AssemblyPath;

				bool automaticUpdates = cmd.Command != null && (cmd.Command.Contains ("GuiUnit") || (cmd.Command.Contains ("mdtool.exe") && cmd.Arguments.Contains ("run-md-tests")));
				if (!string.IsNullOrEmpty(pathName))
					cmd.Arguments += " -run=\"" + test.TestId.Replace("\"", "\\\"") + "\"";
				if (automaticUpdates) {
					tcpListener = new MonoDevelop.UnitTesting.NUnit.External.TcpTestListener (localMonitor, suiteName);
					cmd.Arguments += " -port=" + tcpListener.Port;
				}

				// Note that we always dispose the tcp listener as we don't want it listening
				// forever if the test runner does not try to connect to it
				using (tcpListener) {
					var handler = testContext.ExecutionContext.ExecutionHandler;

					if (handler == null)
						handler = Runtime.ProcessService.DefaultExecutionHandler;
					
					var p = handler.Execute (cmd, cons);
					using (testContext.Monitor.CancellationToken.Register (p.Cancel))
						p.Task.Wait ();

					if (new FileInfo (outFile).Length == 0)
						throw new Exception ("Command failed");
				}

				// mdtool.exe does not necessarily guarantee we get automatic updates. It just guarantees
				// that if guiunit is being used then it will give us updates. If you have a regular test
				// assembly compiled against nunit.framework.dll 
				if (automaticUpdates && tcpListener.HasReceivedConnection) {
					if (testName != null)
						return localMonitor.SingleTestResult;
					return test.GetLastResult ();
				}

				XDocument doc = XDocument.Load (outFile);

				if (doc.Root != null) {
					var root = doc.Root.Elements ("test-suite").FirstOrDefault ();
					if (root != null) {
						xmlOutputConsole.SetDone ();
						var ot = xmlOutputConsole.OutReader.ReadToEnd ();
						var et = xmlOutputConsole.ErrorReader.ReadToEnd ();
						testContext.Monitor.WriteGlobalLog (ot);
						if (!string.IsNullOrEmpty (et)) {
							testContext.Monitor.WriteGlobalLog ("ERROR:\n");
							testContext.Monitor.WriteGlobalLog (et);
						}

						bool macunitStyle = doc.Root.Element ("environment") != null && doc.Root.Element ("environment").Attribute ("macunit-version") != null;
						var result = ReportXmlResult (localMonitor, root, "", macunitStyle);
						if (testName != null)
							result = localMonitor.SingleTestResult;
						return result;
					}
				}
				throw new Exception ("Test results could not be parsed.");
			} catch (Exception ex) {
				xmlOutputConsole.SetDone ();
				var ot = xmlOutputConsole.OutReader.ReadToEnd ();
				var et = xmlOutputConsole.ErrorReader.ReadToEnd ();
				testContext.Monitor.WriteGlobalLog (ot);
				if (!string.IsNullOrEmpty (et)) {
					testContext.Monitor.WriteGlobalLog ("ERROR:\n");
					testContext.Monitor.WriteGlobalLog (et);
				}
				testContext.Monitor.ReportRuntimeError ("Test execution failed.\n" + ot + "\n" + et, ex);
				return UnitTestResult.CreateIgnored ("Test execution failed");
			} finally {
				File.Delete (outFile);
				cons.Dispose ();
			}
		}
Пример #26
0
		void IRemoteEventListener.TestFinished (string test, UnitTestResult result)
		{
			if (Canceled)
				return;
			if (singleTestRun) {
				SingleTestResult = result;
				return;
			}
			
			UnitTest t = GetLocalTest (test);
			if (t == null)
				return;
			
			t.RegisterResult (context, result);
			context.Monitor.EndTest (t, result);
			t.Status = TestStatus.Ready;
			runningTest = null;
		}
Пример #27
0
		UnitTest FindTest (UnitTest t, string testPath)
		{
			var group = t as UnitTestGroup;
			if (group == null)
				return null;
			return SearchRecursive (group, testPath);
		}
Пример #28
0
        public UnitTestSelector(double ypos, UnitTestAdornment coveredLineInfo, IAdornmentLayer layer)
        {
            _layer = layer;
            string HeavyCheckMark          = ((char)(0x2714)).ToString();
            string HeavyMultiplicationSign = ((char)(0x2716)).ToString();

            var myResourceDictionary = new ResourceDictionary();

            myResourceDictionary.Source =
                new Uri("/Testify;component/UnitTestAdornment/ResourceDictionary.xaml",
                        UriKind.RelativeOrAbsolute);

            var backgroundBrush = (Brush)myResourceDictionary["BackgroundBrush"];
            var borderBrush     = (Brush)myResourceDictionary["BorderBrush"];
            var textBrush       = (Brush)myResourceDictionary["TextBrush"];

            if (brush == null)
            {
                brush = (Brush)myResourceDictionary["BackgroundBrush"];
                //brush.Freeze();
                var penBrush = (Brush)myResourceDictionary["BorderBrush"];
                //penBrush.Freeze(); Can't be frozen because it is a Dynamic Resource
                solidPen = new Pen(penBrush, 0.5);
                //solidPen.Freeze(); Can't be frozen because it is a Dynamic Resource
                dashPen = new Pen(penBrush, 0.5);
                //dashPen.DashStyle = DashStyles.Dash;
                //dashPen.Freeze(); Can't be frozen because it is a Dynamic Resource
            }


            var tb = new TextBlock();

            tb.Text = " ";
            const int marginWidth = 20;
            var       Margin      = new Thickness(marginWidth, 0, marginWidth, 0);

            Grid postGrid = new Grid();

            postGrid.RowDefinitions.Add(new RowDefinition());
            postGrid.RowDefinitions.Add(new RowDefinition());
            var cEdge = new ColumnDefinition();

            cEdge.Width = new GridLength(1, GridUnitType.Auto);
            var cEdge2 = new ColumnDefinition {
                Width = new GridLength(19, GridUnitType.Star)
            };

            postGrid.ColumnDefinitions.Add(cEdge);
            postGrid.ColumnDefinitions.Add(new ColumnDefinition());
            postGrid.ColumnDefinitions.Add(cEdge2);
            var rect = new Rectangle();

            rect.Fill   = brush;
            rect.Stroke = (Brush)myResourceDictionary["BorderBrush"];

            var inf = new Size(double.PositiveInfinity, double.PositiveInfinity);

            tb.Measure(inf);

            Grid.SetColumn(rect, 0);
            Grid.SetRow(rect, 0);
            Grid.SetRowSpan(rect, 3);
            Grid.SetColumnSpan(rect, 3);
            postGrid.Children.Add(rect);
            double desiredSize = 0;

            var header = new Label {
                Foreground = textBrush, Background = backgroundBrush, BorderBrush = borderBrush
            };

            Grid.SetRow(header, 0);
            Grid.SetColumn(header, 1);
            Grid.SetColumnSpan(header, 3);
            header.Content = string.Format("Unit tests covering Line # {0}", coveredLineInfo.CoveredLine.LineNumber);
            postGrid.Children.Add(header);
            var unitTests       = coveredLineInfo.CoveredLine.UnitTests;
            var sortedUnitTests = unitTests.OrderByDescending(x => x.IsSuccessful ? 0 : 1).ToList();

            for (int i = 0; i < sortedUnitTests.Count; i++)
            {
                UnitTest test = sortedUnitTests.ElementAt(i);
                postGrid.RowDefinitions.Add(new RowDefinition());
                var icon = new Label {
                    Background = backgroundBrush, BorderBrush = borderBrush, FocusVisualStyle = null
                };
                if (test.IsSuccessful)
                {
                    icon.Content    = HeavyCheckMark;
                    icon.Foreground = new SolidColorBrush(Colors.Green);
                }
                else
                {
                    icon.Content    = HeavyMultiplicationSign;
                    icon.Foreground = new SolidColorBrush(Colors.Red);
                }
                //icon.DataContext = test;
                //Binding iconBinding = new Binding("IsSuccessful");
                //icon.SetBinding(TextBox.TextProperty, iconBinding);
                Grid.SetRow(icon, i + 1);
                Grid.SetColumn(icon, 0);
                postGrid.Children.Add(icon);

                var testName = new TextBox
                {
                    Foreground       = textBrush,
                    Background       = backgroundBrush,
                    BorderBrush      = borderBrush,
                    FocusVisualStyle = null,
                    DataContext      = test,
                    Text             = test.TestMethodName,
                    Margin           = Margin
                };

                var testBinding = new Binding("TestMethodName");

                testName.MouseDoubleClick += TestName_MouseDoubleClick;
                testName.SetBinding(TextBox.TextProperty, testBinding);
                Grid.SetRow(testName, i + 1);
                Grid.SetColumn(testName, 1);
                postGrid.Children.Add(testName);
                testName.Measure(inf);

                if (testName.DesiredSize.Width > desiredSize)
                {
                    desiredSize = testName.DesiredSize.Width;
                }
            }

            SetLeft(postGrid, 0);
            SetTop(postGrid, ypos);

            Focus();
            postGrid.Background           = backgroundBrush;
            postGrid.LostFocus           += postGrid_LostFocus;
            postGrid.MouseLeftButtonDown += postGrid_MouseLeftButtonDown;
            Children.Add(postGrid);
        }
Пример #29
0
        private IEnumerator RunTestsCR()
        {
            while (_queuedTests.Count > 0)
            {
                Type testType = _queuedTests.Dequeue();

                _activeTest = Activator.CreateInstance(testType) as UnitTest;
                if (_activeTest != null)
                {
                    if ((string.IsNullOrEmpty(_activeTest.ProjectToTest()) && string.IsNullOrEmpty(ProjectToTest)) || (_activeTest.ProjectToTest() == ProjectToTest) || (!string.IsNullOrEmpty(_activeTest.ProjectToTest()) && !string.IsNullOrEmpty(ProjectToTest) && ProjectToTest.ToLower().Contains(_activeTest.ProjectToTest().ToLower())))
                    {
                        Log.Status("UnitTestManager.RunTestsCR()", "STARTING UnitTest {0} ...", testType.Name);

                        // wait for the test to complete..
                        bool     bTestException = true;
                        DateTime startTime      = DateTime.Now;
                        try
                        {
                            IEnumerator e = _activeTest.RunTest();
                            while (e.MoveNext())
                            {
                                if (_activeTest.TestFailed)
                                {
                                    break;
                                }

                                yield return(null);

                                if ((DateTime.Now - startTime).TotalSeconds > TestTimeout)
                                {
                                    Log.Error("UnitTestManager.RunTestsCR()", "UnitTest {0} has timed out.", testType.Name);
                                    _activeTest.TestFailed = true;
                                    break;
                                }
                            }

                            bTestException = false;
                            if (_activeTest.TestFailed)
                            {
                                Log.Error("UnitTestManager.RunTestsCR()", "... UnitTest {0} FAILED.", testType.Name);
                                TestsFailed += 1;
                            }
                            else
                            {
                                Log.Status("UnitTestManager.RunTestsCR()", "... UnitTest {0} COMPLETED.", testType.Name);
                                TestsComplete += 1;
                            }
                        }
                        finally
                        {
                        }

                        if (bTestException)
                        {
                            Log.Error("UnitTestManager.RunTestsCR()", "... UnitTest {0} threw exception.", testType.Name);
                            TestsFailed += 1;
                        }
                    }
                    else
                    {
                        //do nothing - because the test we have is not in the project we are testing
                    }
                }
                else
                {
                    Log.Error("UnitTestManager.RunTestsCR()", "Failed to instantiate test {0}.", testType.Name);
                    TestsFailed += 1;
                }
            }

            if (OnTestCompleteCallback != null)
            {
                OnTestCompleteCallback();
            }

            if (TestsComplete == 0 && TestsFailed == 0)
            {
                Log.Status("UnitTestManager.RunTestsCR()", "Nothing to Test");
            }
            else
            {
                Log.Status("UnitTestManager.RunTestsCR()", "Tests Completed: {0}, Tests Failed: {1}", TestsComplete, TestsFailed);
            }

#if UNITY_EDITOR
            if (QuitOnTestsComplete)
            {
                EditorApplication.Exit(TestsFailed > 0 ? 1 : 0);
            }
#endif
        }
Пример #30
0
        protected override void SetModelParams(EditSimpleModel model, UnitTest unitTest)
        {
            var rule = unitTest.HttpRequestUnitTest.Rules.First(FindRulePredicate());

            model.Url = rule.Url;
        }
Пример #31
0
		void IRemoteEventListener.TestStarted (string testCase)
		{
			if (singleTestRun || Canceled)
				return;
			
			UnitTest t = GetLocalTest (testCase);
			if (t == null)
				return;
			
			runningTest = t;
			context.Monitor.BeginTest (t);
			t.Status = TestStatus.Running;
		}
Пример #32
0
 private static void TestVersionComparison()
 {
     UnitTest.Test(ID3.Version.Compare(ID3.Version.v2_0, ID3.Version.v2_0) == 0);
     UnitTest.Test(ID3.Version.Compare(ID3.Version.v2_0, ID3.Version.v2_4) < 0);
     UnitTest.Test(ID3.Version.Compare(ID3.Version.v2_3, ID3.Version.v1_0) > 0);
 }
Пример #33
0
		UnitTest FindTest (UnitTest t, string testPath)
		{
			if (testPath == "")
				return t;

			UnitTestGroup group = t as UnitTestGroup;
			if (group == null)
				return null;

			UnitTest returnTest = group.Tests [testPath];
			if (returnTest != null)
				return returnTest;

			string[] paths = testPath.Split (new char[] {'.'}, 2);
			if (paths.Length == 2) {
				string nextPathSection = paths[0];
				string nextTestCandidate = paths[1];

				UnitTest childTest = group.Tests [nextPathSection];
				if (childTest != null)
					return FindTest (childTest, nextTestCandidate);
			}
			return null;
		}
Пример #34
0
 private static void TestVersionMax()
 {
     UnitTest.Test(ID3.Version.Max(ID3.Version.v2_0, ID3.Version.v2_0) == ID3.Version.v2_0);
     UnitTest.Test(ID3.Version.Max(ID3.Version.v2_3, ID3.Version.v2_0) == ID3.Version.v2_3);
     UnitTest.Test(ID3.Version.Max(ID3.Version.v2_0, ID3.Version.v2_3) == ID3.Version.v2_3);
 }