Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
TestCaseElement.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under Apache 2.0 License. See LICENSE.md for details.
3 //
4 // TestCaseElement.cs: MonoTouch.Dialog element for TestCase
5 //
6 // Authors:
7 // Sebastien Pouliot <sebastien@xamarin.com>
8 //
9 // Copyright 2011-2013 Xamarin Inc.
10 //
11 // Licensed under the Apache License, Version 2.0 (the "License");
12 // you may not use this file except in compliance with the License.
13 // You may obtain a copy of the License at
14 //
15 // http://www.apache.org/licenses/LICENSE-2.0
16 //
17 // Unless required by applicable law or agreed to in writing, software
18 // distributed under the License is distributed on an "AS IS" BASIS,
19 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 // See the License for the specific language governing permissions and
21 // limitations under the License.
22 //
23 
24 using System;
25 using System.Reflection;
26 using System.Threading.Tasks;
27 #if XAMCORE_2_0
28 using UIKit;
29 #else
30 using MonoTouch.UIKit;
31 #endif
32 
33 using MonoTouch.Dialog;
34 
35 using NUnit.Framework;
36 using NUnit.Framework.Internal;
37 using NUnit.Framework.Api;
38 
39 namespace SiliconStudio.Paradox.UnitTesting.UI {
40 
42 
43  public TestCaseElement (TestMethod testCase, TouchRunner runner)
44  : base (testCase, runner)
45  {
46  Caption = testCase.Name;
47  Value = "NotExecuted";
48  this.Tapped += async delegate {
49  if (!Runner.OpenWriter (Test.FullName))
50  return;
51 
52  var suite = (testCase.Parent as TestSuite);
53  var context = TestExecutionContext.CurrentContext;
54  context.TestObject = Reflect.Construct (testCase.Method.ReflectedType, null);
55 
56  suite.GetOneTimeSetUpCommand ().Execute (context);
57  await Run ();
58  suite.GetOneTimeTearDownCommand ().Execute (context);
59 
60  Runner.CloseWriter ();
61  // display more details on (any) failure (but not when ignored)
62  if ((TestCase.RunState == RunState.Runnable) && !Result.IsSuccess ()) {
63  var root = new RootElement ("Results") {
64  new Section () {
65  new TestResultElement (Result)
66  }
67  };
68  var dvc = new DialogViewController (root, true) { Autorotate = true };
69  runner.NavigationController.PushViewController (dvc, true);
70  } else if (GetContainerTableView () != null) {
71  var root = GetImmediateRootElement ();
72  root.Reload (this, UITableViewRowAnimation.Fade);
73  }
74  };
75  }
76 
77  public TestMethod TestCase {
78  get { return Test as TestMethod; }
79  }
80 
81  public async Task Run ()
82  {
83  Update (await Runner.Run (TestCase));
84  }
85 
86  public override void Update ()
87  {
88  if (Result.IsIgnored ()) {
89  Value = Result.GetMessage ();
90  DetailColor = UIColor.Orange;
91  } else if (Result.IsSuccess () || Result.IsInconclusive ()) {
92  int counter = Result.AssertCount;
93  Value = String.Format ("{0} {1} ms for {2} assertion{3}",
94  Result.IsInconclusive () ? "Inconclusive." : "Success!",
95  Result.Duration.TotalMilliseconds, counter,
96  counter == 1 ? String.Empty : "s");
97  DetailColor = DarkGreen;
98  } else if (Result.IsFailure ()) {
99  Value = Result.GetMessage ();
100  DetailColor = UIColor.Red;
101  } else {
102  // Assert.Ignore falls into this
103  Value = Result.GetMessage ();
104  }
105  }
106  }
107 }
TestCaseElement(TestMethod testCase, TouchRunner runner)