Ver Fonte

Tweaked unit tests to be more robust

Charlie Kindel há 2 anos atrás
pai
commit
fc6f830339

+ 6 - 14
UICatalog/Scenarios/BackgroundWorkerCollection.cs

@@ -12,22 +12,14 @@ namespace UICatalog.Scenarios {
 	[ScenarioCategory ("Dialogs")]
 	[ScenarioCategory ("Controls")]
 	public class BackgroundWorkerCollection : Scenario {
-		public override void Init (Toplevel top, ColorScheme colorScheme)
-		{
-			//Application.Init ();
-		}
-
 		public override void Run ()
 		{
-			// For Scenarios that want to use `Applciation.Run<T>` to create a new Toplevel, there are two choices:
-
-			// 1) Override `Scenario.Init` and do nothing in it.
-			// The call to `Application.Run<MdiMain>` in `Run` implies an `Application.Init()` call.
-			//
-			// 2) Just override `Run` but call `Application.Top.Dispose` then `Application.Shutdown ()`. This
-			// works around bug #520, ensuring the `Toplevel` created by `Init` gets Disposed.
-			//Application.Top.Dispose ();
-			//Application.Shutdown ();
+			// BUGBUG: work around Issue #520: Ensuring the `Toplevel` created by `Init` gets Disposed...
+			// For Scenarios that want to use `Applciation.Run<T>` to create a new Toplevel: 
+			// Override `Run` and call `Application.Top.Dispose` before calling `Application.Run<T>`.
+			if (Application.Top != null) {
+				Application.Top.Dispose ();
+			}
 
 			Application.Run<MdiMain> ();
 		}

+ 2 - 1
UICatalog/Scenarios/Editor.cs

@@ -30,11 +30,12 @@ namespace UICatalog.Scenarios {
 		private TabView _tabView;
 		private MenuItem _miForceMinimumPosToZero;
 		private bool _forceMinimumPosToZero = true;
-		private readonly List<CultureInfo> _cultureInfos = Application.SupportedCultures;
+		private List<CultureInfo> _cultureInfos;
 
 		public override void Init (Toplevel top, ColorScheme colorScheme)
 		{
 			Application.Init ();
+			_cultureInfos = Application.SupportedCultures;
 			Top = top != null ? top : Application.Top;
 
 			Win = new Window (_fileName ?? "Untitled") {

+ 6 - 0
UnitTests/ScenarioTests.cs

@@ -70,6 +70,12 @@ namespace UICatalog {
 				scenario.Setup ();
 				scenario.Run ();
 				Application.Shutdown ();
+#if DEBUG_IDISPOSABLE
+				foreach (var inst in Responder.Instances) {
+					Assert.True (inst.WasDisposed);
+				}
+				Responder.Instances.Clear ();
+#endif
 			}
 #if DEBUG_IDISPOSABLE
 			foreach (var inst in Responder.Instances) {