Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
NamespaceAssemblyBuilder.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 GPL v3. See LICENSE.md for details.
3 #if SILICONSTUDIO_PLATFORM_IOS || SILICONSTUDIO_PLATFORM_ANDROID
4 using System.Collections;
5 using System.Linq;
6 using System.Reflection;
7 using NUnit.Framework.Api;
8 using NUnit.Framework.Internal;
9 
10 namespace SiliconStudio.Paradox.Graphics.Regression
11 {
12  /// <summary>
13  /// Reprocess result of another <see cref="ITestAssemblyBuilder"/> by regrouping test of a given namespace into a TestSuite containing that name.
14  /// It matches Resharper behavior for grouping test by namespace.
15  /// </summary>
16  public class NamespaceAssemblyBuilder : ITestAssemblyBuilder
17  {
18  private ITestAssemblyBuilder innerAssemblyBuilder;
19 
20  public NamespaceAssemblyBuilder(ITestAssemblyBuilder innerAssemblyBuilder)
21  {
22  this.innerAssemblyBuilder = innerAssemblyBuilder;
23  }
24 
25  public TestSuite Build(Assembly assembly, IDictionary options)
26  {
27  return GroupByNamespace(innerAssemblyBuilder.Build(assembly, options));
28  }
29 
30  public TestSuite Build(string assemblyName, IDictionary options)
31  {
32  return GroupByNamespace(innerAssemblyBuilder.Build(assemblyName, options));
33  }
34 
35  public static TestSuite GroupByNamespace(TestSuite testSuite)
36  {
37  if (testSuite == null)
38  return null;
39 
40  var result = new TestSuite(testSuite.Name + ".Application");
41 
42  foreach (var testGroup in testSuite.Tests.GroupBy(x => GetNamespace(x)))
43  {
44  var namespaceSuite = new TestNamespace(testGroup.Key);
45  foreach (var test in testGroup)
46  {
47  namespaceSuite.Tests.Add(test);
48  }
49 
50  result.Tests.Add(namespaceSuite);
51  }
52 
53  return result;
54  }
55 
56  private static string GetNamespace(ITest test)
57  {
58  var name = test.FullName;
59 
60  var lastDot = name.LastIndexOf('.');
61  if (lastDot != -1)
62  name = name.Substring(0, lastDot);
63 
64  return name;
65  }
66  }
67 }
68 #endif