Browse Source

Refactored UI Catalog Scenario class to support ToString()

Tig Kindel 2 years ago
parent
commit
b09b3ad8f2

+ 6 - 6
Terminal.Gui/Core/SearchCollectionNavigator.cs

@@ -12,14 +12,14 @@ namespace Terminal.Gui {
 		DateTime lastKeystroke = DateTime.MinValue;
 		DateTime lastKeystroke = DateTime.MinValue;
 		const int TypingDelay = 250;
 		const int TypingDelay = 250;
 		public StringComparer Comparer { get; set; } = StringComparer.InvariantCultureIgnoreCase;
 		public StringComparer Comparer { get; set; } = StringComparer.InvariantCultureIgnoreCase;
-		private IEnumerable<string> Collection { get => _collection; set => _collection = value; }
+		private IEnumerable<object> Collection { get => _collection; set => _collection = value; }
 
 
-		private IEnumerable<string> _collection;
+		private IEnumerable<object> _collection;
 
 
-		public SearchCollectionNavigator (IEnumerable<string> collection) { _collection = collection; }
+		public SearchCollectionNavigator (IEnumerable<object> collection) { _collection = collection; }
 
 
 
 
-		public int CalculateNewIndex (IEnumerable<string> collection, int currentIndex, char keyStruck)
+		public int CalculateNewIndex (IEnumerable<object> collection, int currentIndex, char keyStruck)
 		{
 		{
 			// if user presses a key
 			// if user presses a key
 			if (true) {//char.IsLetterOrDigit (keyStruck) || char.IsPunctuation (keyStruck) || char.IsSymbol(keyStruck)) {
 			if (true) {//char.IsLetterOrDigit (keyStruck) || char.IsPunctuation (keyStruck) || char.IsSymbol(keyStruck)) {
@@ -85,7 +85,7 @@ namespace Terminal.Gui {
 			return CalculateNewIndex (Collection, currentIndex, keyStruck);
 			return CalculateNewIndex (Collection, currentIndex, keyStruck);
 		}
 		}
 
 
-		private int GetNextIndexMatching (IEnumerable<string> collection, int currentIndex, string search, bool preferNotToMoveToNewIndexes = false)
+		private int GetNextIndexMatching (IEnumerable<object> collection, int currentIndex, string search, bool preferNotToMoveToNewIndexes = false)
 		{
 		{
 			if (string.IsNullOrEmpty (search)) {
 			if (string.IsNullOrEmpty (search)) {
 				return -1;
 				return -1;
@@ -93,7 +93,7 @@ namespace Terminal.Gui {
 
 
 			// find indexes of items that start with the search text
 			// find indexes of items that start with the search text
 			int [] matchingIndexes = collection.Select ((item, idx) => (item, idx))
 			int [] matchingIndexes = collection.Select ((item, idx) => (item, idx))
-				  .Where (k => k.Item1?.StartsWith (search, StringComparison.InvariantCultureIgnoreCase) ?? false)
+				  .Where (k => k.item?.ToString().StartsWith (search, StringComparison.InvariantCultureIgnoreCase) ?? false)
 				  .Select (k => k.idx)
 				  .Select (k => k.idx)
 				  .ToArray ();
 				  .ToArray ();
 
 

+ 1 - 1
Terminal.Gui/Views/ListView.cs

@@ -439,7 +439,7 @@ namespace Terminal.Gui {
 			if (!kb.IsAlt && !kb.IsCapslock && !kb.IsCtrl && !kb.IsScrolllock && !kb.IsNumlock) {
 			if (!kb.IsAlt && !kb.IsCapslock && !kb.IsCtrl && !kb.IsScrolllock && !kb.IsNumlock) {
 				if (navigator == null) {
 				if (navigator == null) {
 					// BUGBUG: If items change this needs to be recreated.
 					// BUGBUG: If items change this needs to be recreated.
-					navigator = new SearchCollectionNavigator (source.ToList().Cast<string>());
+					navigator = new SearchCollectionNavigator (source.ToList ().Cast<object> ());
 				}
 				}
 				SelectedItem = navigator.CalculateNewIndex (SelectedItem, (char)kb.KeyValue);
 				SelectedItem = navigator.CalculateNewIndex (SelectedItem, (char)kb.KeyValue);
 				EnsuresVisibilitySelectedItem ();
 				EnsuresVisibilitySelectedItem ();

+ 16 - 7
UICatalog/Scenario.cs

@@ -73,7 +73,7 @@ namespace UICatalog {
 		/// Overrides that do not call the base.<see cref="Run"/>, must call <see cref="Application.Init"/> before creating any views or calling other Terminal.Gui APIs.
 		/// Overrides that do not call the base.<see cref="Run"/>, must call <see cref="Application.Init"/> before creating any views or calling other Terminal.Gui APIs.
 		/// </para>
 		/// </para>
 		/// </remarks>
 		/// </remarks>
-		public virtual void Init(Toplevel top, ColorScheme colorScheme)
+		public virtual void Init (Toplevel top, ColorScheme colorScheme)
 		{
 		{
 			Application.Init ();
 			Application.Init ();
 
 
@@ -177,7 +177,14 @@ namespace UICatalog {
 		/// <returns>list of category names</returns>
 		/// <returns>list of category names</returns>
 		public List<string> GetCategories () => ScenarioCategory.GetCategories (this.GetType ());
 		public List<string> GetCategories () => ScenarioCategory.GetCategories (this.GetType ());
 
 
-		public override string ToString () => $"{GetName (),-30}{GetDescription ()}";
+		private static int _maxScenarioNameLen = 30;
+
+		/// <summary>
+		/// Gets the Scenario Name + Description with the Description padded
+		/// based on the longest known Scenario name.
+		/// </summary>
+		/// <returns></returns>
+		public override string ToString () => $"{GetName ().PadRight(_maxScenarioNameLen)}{GetDescription ()}";
 
 
 		/// <summary>
 		/// <summary>
 		/// Override this to implement the <see cref="Scenario"/> setup logic (create controls, etc...). 
 		/// Override this to implement the <see cref="Scenario"/> setup logic (create controls, etc...). 
@@ -232,12 +239,14 @@ namespace UICatalog {
 		/// Returns an instance of each <see cref="Scenario"/> defined in the project. 
 		/// Returns an instance of each <see cref="Scenario"/> defined in the project. 
 		/// https://stackoverflow.com/questions/5411694/get-all-inherited-classes-of-an-abstract-class
 		/// https://stackoverflow.com/questions/5411694/get-all-inherited-classes-of-an-abstract-class
 		/// </summary>
 		/// </summary>
-		public static List<Type> GetDerivedClasses<T> ()
+		public static List<Scenario> GetScenarios ()
 		{
 		{
-			List<Type> objects = new List<Type> ();
-			foreach (Type type in typeof (T).Assembly.GetTypes ()
-			 .Where (myType => myType.IsClass && !myType.IsAbstract && myType.IsSubclassOf (typeof (T)))) {
-				objects.Add (type);
+			List<Scenario> objects = new List<Scenario> ();
+			foreach (Type type in typeof (Scenario).Assembly.ExportedTypes
+			 .Where (myType => myType.IsClass && !myType.IsAbstract && myType.IsSubclassOf (typeof (Scenario)))) {
+				var scenario = (Scenario)Activator.CreateInstance (type);
+				objects.Add (scenario);
+				_maxScenarioNameLen = Math.Max (_maxScenarioNameLen, scenario.GetName ().Length + 1);
 			}
 			}
 			return objects;
 			return objects;
 		}
 		}

+ 12 - 9
UICatalog/Scenarios/ListViewWithSelection.cs

@@ -3,6 +3,7 @@ using System;
 using System.Collections;
 using System.Collections;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Linq;
 using System.Linq;
+using System.Text.Json.Nodes;
 using Terminal.Gui;
 using Terminal.Gui;
 using Attribute = Terminal.Gui.Attribute;
 using Attribute = Terminal.Gui.Attribute;
 
 
@@ -16,11 +17,13 @@ namespace UICatalog.Scenarios {
 		public CheckBox _allowMultipleCB;
 		public CheckBox _allowMultipleCB;
 		public ListView _listView;
 		public ListView _listView;
 
 
-		public List<Type> _scenarios = Scenario.GetDerivedClasses<Scenario>().OrderBy (t => Scenario.ScenarioMetadata.GetName (t)).ToList ();
+		public List<Scenario> _scenarios;
 
 
 		public override void Setup ()
 		public override void Setup ()
 		{
 		{
-			_customRenderCB = new CheckBox ("Render with columns") {
+			_scenarios = Scenario.GetScenarios ().OrderBy (s => s.GetName ()).ToList ();
+
+			_customRenderCB = new CheckBox ("Use custom rendering") {
 				X = 0,
 				X = 0,
 				Y = 0,
 				Y = 0,
 				Height = 1,
 				Height = 1,
@@ -137,11 +140,11 @@ namespace UICatalog.Scenarios {
 		// This is basically the same implementation used by the UICatalog main window
 		// This is basically the same implementation used by the UICatalog main window
 		internal class ScenarioListDataSource : IListDataSource {
 		internal class ScenarioListDataSource : IListDataSource {
 			int _nameColumnWidth = 30;
 			int _nameColumnWidth = 30;
-			private List<Type> scenarios;
+			private List<Scenario> scenarios;
 			BitArray marks;
 			BitArray marks;
 			int count, len;
 			int count, len;
 
 
-			public List<Type> Scenarios {
+			public List<Scenario> Scenarios {
 				get => scenarios;
 				get => scenarios;
 				set {
 				set {
 					if (value != null) {
 					if (value != null) {
@@ -163,14 +166,14 @@ namespace UICatalog.Scenarios {
 
 
 			public int Length => len;
 			public int Length => len;
 
 
-			public ScenarioListDataSource (List<Type> itemList) => Scenarios = itemList;
+			public ScenarioListDataSource (List<Scenario> itemList) => Scenarios = itemList;
 
 
 			public void Render (ListView container, ConsoleDriver driver, bool selected, int item, int col, int line, int width, int start = 0)
 			public void Render (ListView container, ConsoleDriver driver, bool selected, int item, int col, int line, int width, int start = 0)
 			{
 			{
 				container.Move (col, line);
 				container.Move (col, line);
 				// Equivalent to an interpolated string like $"{Scenarios[item].Name, -widtestname}"; if such a thing were possible
 				// Equivalent to an interpolated string like $"{Scenarios[item].Name, -widtestname}"; if such a thing were possible
-				var s = String.Format (String.Format ("{{0,{0}}}", -_nameColumnWidth), Scenario.ScenarioMetadata.GetName (Scenarios [item]));
-				RenderUstr (driver, $"{s}  {Scenario.ScenarioMetadata.GetDescription (Scenarios [item])}", col, line, width, start);
+				var s = String.Format (String.Format ("{{0,{0}}}", -_nameColumnWidth), Scenarios [item].GetName ());
+				RenderUstr (driver, $"{s} ({Scenarios [item].GetDescription ()})", col, line, width, start);
 			}
 			}
 
 
 			public void SetMark (int item, bool value)
 			public void SetMark (int item, bool value)
@@ -187,8 +190,8 @@ namespace UICatalog.Scenarios {
 
 
 				int maxLength = 0;
 				int maxLength = 0;
 				for (int i = 0; i < scenarios.Count; i++) {
 				for (int i = 0; i < scenarios.Count; i++) {
-					var s = String.Format (String.Format ("{{0,{0}}}", -_nameColumnWidth), Scenario.ScenarioMetadata.GetName (Scenarios [i]));
-					var sc = $"{s}  {Scenario.ScenarioMetadata.GetDescription (Scenarios [i])}";
+					var s = String.Format (String.Format ("{{0,{0}}}", -_nameColumnWidth), Scenarios [i].GetName ());
+					var sc = $"{s}  {Scenarios [i].GetDescription ()}";
 					var l = sc.Length;
 					var l = sc.Length;
 					if (l > maxLength) {
 					if (l > maxLength) {
 						maxLength = l;
 						maxLength = l;

+ 16 - 53
UICatalog/UICatalog.cs

@@ -53,7 +53,7 @@ namespace UICatalog {
 		private static List<string> _categories;
 		private static List<string> _categories;
 		private static ListView _categoryListView;
 		private static ListView _categoryListView;
 		private static FrameView _rightPane;
 		private static FrameView _rightPane;
-		private static List<Type> _scenarios;
+		private static List<Scenario> _scenarios;
 		private static ListView _scenarioListView;
 		private static ListView _scenarioListView;
 		private static StatusBar _statusBar;
 		private static StatusBar _statusBar;
 		private static StatusItem _capslock;
 		private static StatusItem _capslock;
@@ -75,15 +75,15 @@ namespace UICatalog {
 			if (Debugger.IsAttached)
 			if (Debugger.IsAttached)
 				CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.GetCultureInfo ("en-US");
 				CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.GetCultureInfo ("en-US");
 
 
-			_scenarios = Scenario.GetDerivedClasses<Scenario> ().OrderBy (t => Scenario.ScenarioMetadata.GetName (t)).ToList ();
+			_scenarios = Scenario.GetScenarios ();
 
 
 			if (args.Length > 0 && args.Contains ("-usc")) {
 			if (args.Length > 0 && args.Contains ("-usc")) {
 				_useSystemConsole = true;
 				_useSystemConsole = true;
 				args = args.Where (val => val != "-usc").ToArray ();
 				args = args.Where (val => val != "-usc").ToArray ();
 			}
 			}
 			if (args.Length > 0) {
 			if (args.Length > 0) {
-				var item = _scenarios.FindIndex (t => Scenario.ScenarioMetadata.GetName (t).Equals (args [0], StringComparison.OrdinalIgnoreCase));
-				_runningScenario = (Scenario)Activator.CreateInstance (_scenarios [item]);
+				var item = _scenarios.FindIndex (s => s.GetName ().Equals (args [0], StringComparison.OrdinalIgnoreCase));
+				_runningScenario = (Scenario)Activator.CreateInstance (_scenarios [item].GetType());
 				Application.UseSystemConsole = _useSystemConsole;
 				Application.UseSystemConsole = _useSystemConsole;
 				Application.Init ();
 				Application.Init ();
 				_runningScenario.Init (Application.Top, _baseColorScheme);
 				_runningScenario.Init (Application.Top, _baseColorScheme);
@@ -218,7 +218,7 @@ namespace UICatalog {
 			_rightPane.Title = $"{_rightPane.Title} ({_rightPane.ShortcutTag})";
 			_rightPane.Title = $"{_rightPane.Title} ({_rightPane.ShortcutTag})";
 			_rightPane.ShortcutAction = () => _rightPane.SetFocus ();
 			_rightPane.ShortcutAction = () => _rightPane.SetFocus ();
 
 
-			_nameColumnWidth = Scenario.ScenarioMetadata.GetName (_scenarios.OrderByDescending (t => Scenario.ScenarioMetadata.GetName (t).Length).FirstOrDefault ()).Length;
+			_nameColumnWidth = _scenarios.OrderByDescending (s => s.GetName ().Length).FirstOrDefault ().GetName().Length;
 
 
 			_scenarioListView = new ListView () {
 			_scenarioListView = new ListView () {
 				X = 0,
 				X = 0,
@@ -462,42 +462,6 @@ namespace UICatalog {
 					break;
 					break;
 				}
 				}
 			}
 			}
-
-			//MenuItem CheckedMenuMenuItem (ustring menuItem, Action action, Func<bool> checkFunction)
-			//{
-			//	var mi = new MenuItem ();
-			//	mi.Title = menuItem;
-			//	mi.Shortcut = Key.AltMask + index.ToString () [0];
-			//	index++;
-			//	mi.CheckType |= MenuItemCheckStyle.Checked;
-			//	mi.Checked = checkFunction ();
-			//	mi.Action = () => {
-			//		action?.Invoke ();
-			//		mi.Title = menuItem;
-			//		mi.Checked = checkFunction ();
-			//	};
-			//	return mi;
-			//}
-
-			//return new MenuItem [] {
-			//	CheckedMenuMenuItem ("Use _System Console",
-			//		() => {
-			//			_useSystemConsole = !_useSystemConsole;
-			//		},
-			//		() => _useSystemConsole),
-			//	CheckedMenuMenuItem ("Diagnostics: _Frame Padding",
-			//		() => {
-			//			ConsoleDriver.Diagnostics ^= ConsoleDriver.DiagnosticFlags.FramePadding;
-			//			_top.SetNeedsDisplay ();
-			//		},
-			//		() => (ConsoleDriver.Diagnostics & ConsoleDriver.DiagnosticFlags.FramePadding) == ConsoleDriver.DiagnosticFlags.FramePadding),
-			//	CheckedMenuMenuItem ("Diagnostics: Frame _Ruler",
-			//		() => {
-			//			ConsoleDriver.Diagnostics ^= ConsoleDriver.DiagnosticFlags.FrameRuler;
-			//			_top.SetNeedsDisplay ();
-			//		},
-			//		() => (ConsoleDriver.Diagnostics & ConsoleDriver.DiagnosticFlags.FrameRuler) == ConsoleDriver.DiagnosticFlags.FrameRuler),
-			//};
 		}
 		}
 
 
 		static void SetColorScheme ()
 		static void SetColorScheme ()
@@ -533,8 +497,8 @@ namespace UICatalog {
 		{
 		{
 			if (_runningScenario is null) {
 			if (_runningScenario is null) {
 				_scenarioListViewItem = _scenarioListView.SelectedItem;
 				_scenarioListViewItem = _scenarioListView.SelectedItem;
-				var source = _scenarioListView.Source as ScenarioListDataSource;
-				_runningScenario = (Scenario)Activator.CreateInstance (source.Scenarios [_scenarioListView.SelectedItem]);
+				// Create new instance of scenario (even though Scenarios contains instnaces)
+				_runningScenario = (Scenario)Activator.CreateInstance (_scenarioListView.Source.ToList() [_scenarioListView.SelectedItem].GetType());
 				Application.RequestStop ();
 				Application.RequestStop ();
 			}
 			}
 		}
 		}
@@ -542,7 +506,7 @@ namespace UICatalog {
 		internal class ScenarioListDataSource : IListDataSource {
 		internal class ScenarioListDataSource : IListDataSource {
 			private readonly int len;
 			private readonly int len;
 
 
-			public List<Type> Scenarios { get; set; }
+			public List<Scenario> Scenarios { get; set; }
 
 
 			public bool IsMarked (int item) => false;
 			public bool IsMarked (int item) => false;
 
 
@@ -550,7 +514,7 @@ namespace UICatalog {
 
 
 			public int Length => len;
 			public int Length => len;
 
 
-			public ScenarioListDataSource (List<Type> itemList)
+			public ScenarioListDataSource (List<Scenario> itemList)
 			{
 			{
 				Scenarios = itemList;
 				Scenarios = itemList;
 				len = GetMaxLengthItem ();
 				len = GetMaxLengthItem ();
@@ -560,8 +524,8 @@ namespace UICatalog {
 			{
 			{
 				container.Move (col, line);
 				container.Move (col, line);
 				// Equivalent to an interpolated string like $"{Scenarios[item].Name, -widtestname}"; if such a thing were possible
 				// Equivalent to an interpolated string like $"{Scenarios[item].Name, -widtestname}"; if such a thing were possible
-				var s = String.Format (String.Format ("{{0,{0}}}", -_nameColumnWidth), Scenario.ScenarioMetadata.GetName (Scenarios [item]));
-				RenderUstr (driver, $"{s}  {Scenario.ScenarioMetadata.GetDescription (Scenarios [item])}", col, line, width, start);
+				var s = String.Format (String.Format ("{{0,{0}}}", -_nameColumnWidth), Scenarios [item].GetName());
+				RenderUstr (driver, $"{s}  {Scenarios [item].GetDescription()}", col, line, width, start);
 			}
 			}
 
 
 			public void SetMark (int item, bool value)
 			public void SetMark (int item, bool value)
@@ -576,14 +540,13 @@ namespace UICatalog {
 
 
 				int maxLength = 0;
 				int maxLength = 0;
 				for (int i = 0; i < Scenarios.Count; i++) {
 				for (int i = 0; i < Scenarios.Count; i++) {
-					var s = String.Format (String.Format ("{{0,{0}}}", -_nameColumnWidth), Scenario.ScenarioMetadata.GetName (Scenarios [i]));
-					var sc = $"{s}  {Scenario.ScenarioMetadata.GetDescription (Scenarios [i])}";
+					var s = String.Format (String.Format ("{{0,{0}}}", -_nameColumnWidth), Scenarios [i].GetName());
+					var sc = $"{s}  {Scenarios [i].GetDescription()}";
 					var l = sc.Length;
 					var l = sc.Length;
 					if (l > maxLength) {
 					if (l > maxLength) {
 						maxLength = l;
 						maxLength = l;
 					}
 					}
 				}
 				}
-
 				return maxLength;
 				return maxLength;
 			}
 			}
 
 
@@ -661,15 +624,15 @@ namespace UICatalog {
 			}
 			}
 			_categoryListViewItem = _categoryListView.SelectedItem;
 			_categoryListViewItem = _categoryListView.SelectedItem;
 			var item = _categories [_categoryListViewItem];
 			var item = _categories [_categoryListViewItem];
-			List<Type> newlist;
+			List<Scenario> newlist;
 			if (_categoryListViewItem == 0) {
 			if (_categoryListViewItem == 0) {
 				// First category is "All"
 				// First category is "All"
 				newlist = _scenarios;
 				newlist = _scenarios;
 
 
 			} else {
 			} else {
-				newlist = _scenarios.Where (t => Scenario.ScenarioCategory.GetCategories (t).Contains (item)).ToList ();
+				newlist = _scenarios.Where (s => s.GetCategories ().Contains (item)).ToList ();
 			}
 			}
-			_scenarioListView.Source = new ScenarioListDataSource (newlist);
+			_scenarioListView.SetSource(newlist.ToList());
 			_scenarioListView.SelectedItem = _scenarioListViewItem;
 			_scenarioListView.SelectedItem = _scenarioListViewItem;
 
 
 		}
 		}

+ 11 - 13
UnitTests/ScenarioTests.cs

@@ -49,19 +49,18 @@ namespace Terminal.Gui {
 		[Fact]
 		[Fact]
 		public void Run_All_Scenarios ()
 		public void Run_All_Scenarios ()
 		{
 		{
-			List<Type> scenarioClasses = Scenario.GetDerivedClasses<Scenario> ();
-			Assert.NotEmpty (scenarioClasses);
+			List<Scenario> scenarios = Scenario.GetScenarios ();
+			Assert.NotEmpty (scenarios);
 
 
-			foreach (var scenarioClass in scenarioClasses) {
+			foreach (var scenario in scenarios) {
 
 
-				output.WriteLine ($"Running Scenario '{scenarioClass.Name}'");
+				output.WriteLine ($"Running Scenario '{scenario}'");
 
 
 				Func<MainLoop, bool> closeCallback = (MainLoop loop) => {
 				Func<MainLoop, bool> closeCallback = (MainLoop loop) => {
 					Application.RequestStop ();
 					Application.RequestStop ();
 					return false;
 					return false;
 				};
 				};
 
 
-				var scenario = (Scenario)Activator.CreateInstance (scenarioClass);
 				Application.Init (new FakeDriver (), new FakeMainLoop (() => FakeConsole.ReadKey (true)));
 				Application.Init (new FakeDriver (), new FakeMainLoop (() => FakeConsole.ReadKey (true)));
 
 
 				// Close after a short period of time
 				// Close after a short period of time
@@ -83,11 +82,11 @@ namespace Terminal.Gui {
 		[Fact]
 		[Fact]
 		public void Run_Generic ()
 		public void Run_Generic ()
 		{
 		{
-			List<Type> scenarioClasses = Scenario.GetDerivedClasses<Scenario> ();
-			Assert.NotEmpty (scenarioClasses);
+			List<Scenario> scenarios = Scenario.GetScenarios ();
+			Assert.NotEmpty (scenarios);
 
 
-			var item = scenarioClasses.FindIndex (t => Scenario.ScenarioMetadata.GetName (t).Equals ("Generic", StringComparison.OrdinalIgnoreCase));
-			var scenarioClass = scenarioClasses [item];
+			var item = scenarios.FindIndex (s => s.GetName ().Equals ("Generic", StringComparison.OrdinalIgnoreCase));
+			var generic = scenarios [item];
 			// Setup some fake keypresses 
 			// Setup some fake keypresses 
 			// Passing empty string will cause just a ctrl-q to be fired
 			// Passing empty string will cause just a ctrl-q to be fired
 			int stackSize = CreateInput ("");
 			int stackSize = CreateInput ("");
@@ -116,13 +115,12 @@ namespace Terminal.Gui {
 				Assert.Equal (Key.CtrlMask | Key.Q, args.KeyEvent.Key);
 				Assert.Equal (Key.CtrlMask | Key.Q, args.KeyEvent.Key);
 			};
 			};
 
 
-			var scenario = (Scenario)Activator.CreateInstance (scenarioClass);
-			scenario.Init (Application.Top, Colors.Base);
-			scenario.Setup ();
+			generic.Init (Application.Top, Colors.Base);
+			generic.Setup ();
 			// There is no need to call Application.Begin because Init already creates the Application.Top
 			// There is no need to call Application.Begin because Init already creates the Application.Top
 			// If Application.RunState is used then the Application.RunLoop must also be used instead Application.Run.
 			// If Application.RunState is used then the Application.RunLoop must also be used instead Application.Run.
 			//var rs = Application.Begin (Application.Top);
 			//var rs = Application.Begin (Application.Top);
-			scenario.Run ();
+			generic.Run ();
 
 
 			//Application.End (rs);
 			//Application.End (rs);