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 //
2 // Copyright 2011-2012 Xamarin Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 using System;
18 using Android.Content;
19 using Android.Views;
20 using NUnit.Framework.Api;
21 using NUnit.Framework.Internal;
22 
23 namespace Android.NUnitLite.UI {
24 
26 
27  public TestCaseElement (ITest test) : base (test)
28  {
29  if (test.RunState == RunState.Runnable)
30  Indicator = "..."; // hint there's more
31  }
32 
33  protected override string GetCaption ()
34  {
35  string color, message;
36 
37  if (Result == null)
38  {
39  color = "white";
40  message = "Not Executed";
41  }
42  else if (Result.IsIgnored())
43  {
44  color = "#FF7700";
45  message = Result.GetMessage();
46  }
47  else if (Result.IsSuccess() || Result.IsInconclusive())
48  {
49  message = String.Format("{0} for {1} assertion{2}",
50  Result.IsInconclusive() ? "Inconclusive." : "Success!",
51  Result.AssertCount,
52  Result.AssertCount == 1 ? String.Empty : "s");
53  color = "green";
54  }
55  else if (Result.IsFailure())
56  {
57  message = Result.GetMessage();
58  color = "red";
59  }
60  else
61  {
62  message = Result.GetMessage();
63  color = "grey";
64  }
65 
66  return string.Format("<b>{0}</b><br><font color='{1}'>{2}</font>", Result == null ? Test.Name : Result.Name, color, message);
67  }
68 
69  public TestMethod TestCase {
70  get { return Test as TestMethod; }
71  }
72 
73  public override View GetView (Context context, View convertView, ViewGroup parent)
74  {
75  View view = base.GetView (context, convertView, parent);
76  view.Click += async delegate {
77  if (TestCase.RunState != RunState.Runnable)
78  return;
79 
80  AndroidRunner runner = AndroidRunner.Runner;
81  if (!runner.OpenWriter ("Run " + TestCase.FullName, context))
82  return;
83 
84  try
85  {
86  await runner.Run(TestCase);
87  }
88  finally {
89  runner.CloseWriter ();
90  Update();
91  }
92 
93  if (!Result.IsSuccess()) {
94  Intent intent = new Intent (context, typeof (TestResultActivity));
95  intent.PutExtra ("TestCase", Name);
96  intent.AddFlags (ActivityFlags.NewTask);
97  context.StartActivity (intent);
98  }
99  };
100  return view;
101  }
102  }
103 }
bool OpenWriter(string message, Context activity)
override View GetView(Context context, View convertView, ViewGroup parent)
Overriden my most derived classes, creates a view that creates a View with the contents for display ...