From 74fbc3fb0958c2a82236d8ea535e936291991bfb Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Tue, 14 Jul 2020 16:07:54 +0200 Subject: [PATCH] [TouchRunner] Keep track of the last shown test suite, and return to it when the app is relaunched. (#74) --- NUnitLite/TouchRunner/TouchRunner.cs | 62 ++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 3 deletions(-) diff --git a/NUnitLite/TouchRunner/TouchRunner.cs b/NUnitLite/TouchRunner/TouchRunner.cs index 72a921a..68a39f0 100644 --- a/NUnitLite/TouchRunner/TouchRunner.cs +++ b/NUnitLite/TouchRunner/TouchRunner.cs @@ -136,10 +136,53 @@ public void LoadSync () assemblies.Clear (); } + public void SelectLastTestSuite () + { + var lastSuite = NSUserDefaults.StandardUserDefaults.StringForKey ("CurrentTest"); + + if (string.IsNullOrEmpty (lastSuite)) + return; + + var hierarchy = new List (); + var test = Find (suite, lastSuite, hierarchy); + if (hierarchy.Count < 2) + return; + // Remove the last one, that's the main test suite + hierarchy.RemoveAt (hierarchy.Count - 1); + for (var i = hierarchy.Count - 1; i >= 0; i--) { + if (hierarchy [i] is TestSuite ts) { + Show (ts); + } else { + break; + } + } + } + + ITest Find (ITest parent, string fullname, List hierarchy) + { + if (parent.FullName == fullname) { + hierarchy.Add (parent); + return parent; + } + + foreach (var test in parent.Tests) { + var rv = Find (test, fullname, hierarchy); + if (rv != null) { + hierarchy.Add (parent); + return test; + } + } + + return null; + } + + public void AutoRun () { - if (!AutoStart) + if (!AutoStart) { + SelectLastTestSuite (); return; + } ExecuteOnMainThread (() => { Run (); @@ -375,6 +418,10 @@ bool ShowConnectionErrorAlert (string hostname, int port, Exception ex) protected abstract void WriteDeviceInformation (TextWriter writer); + public virtual void Show (TestSuite suite) + { + } + public void CloseWriter () { int total = PassedCount + InconclusiveCount + FailedCount; // ignored are *not* run @@ -559,6 +606,11 @@ public ITest LoadedTest { } } + public void NotifySelectedTest (ITest test) + { + NSUserDefaults.StandardUserDefaults.SetString (test.FullName, "CurrentTest"); + } + public void TestOutput (TestOutput testOutput) { } @@ -694,7 +746,7 @@ void Credits () Dictionary suite_elements = new Dictionary (); Dictionary case_elements = new Dictionary (); - public void Show (TestSuite suite) + public override void Show (TestSuite suite) { NavigationController.PushViewController (suites_dvc [suite], true); } @@ -734,7 +786,11 @@ TestSuiteElement Setup (TestSuite suite) }; root.Add (options); - suites_dvc.Add (suite, new TouchViewController (root)); + var tvc = new TouchViewController (root); + tvc.ViewAppearing += (object sender, EventArgs ea) => { + NotifySelectedTest (suite); + }; + suites_dvc.Add (suite, tvc); return tse; }