Exemplo n.º 1
0
		public UIViewController TestView()
		{
			// Create a view with a Button to run the tests and a Text View for the Results.
			var vc = new UIViewController();
			
			var btn = new UIButton(new RectangleF(0, 0, 100, 40));
			btn.SetTitle("Run Tests", UIControlState.Normal);
			btn.BackgroundColor = UIColor.White;
			btn.SetTitleColor(UIColor.Black, UIControlState.Normal);
			
			var textResults = new UITextView(new RectangleF(0, 50, vc.View.Bounds.Width, 40));
			textResults.Text = "";
			textResults.Hidden = true;
			
			// Setup Test here
			btn.TouchUpInside += (sender, e) => 
			{
				Console.WriteLine("Running Tests...");
				textResults.Text = "Tests Running";
			 	btn.Enabled = false;
				
				textResults.SetNeedsDisplay();
				btn.SetNeedsDisplay();
				
				try	
				{	
					var results = RunTests();
					
					var failed = results.Where(r => !r.Pass).ToList();
					
					textResults.Text = failed.Count == 0 ? "All Filters Passed" : "These filters failed " + string.Join(Environment.NewLine, failed.Select (r => r.FilterName));
					textResults.Hidden = false;
				}
				finally
				{
					btn.Enabled = true;
				}
			};
			
			vc.View.AddSubviews(btn, textResults);
			
			return vc;
		}