1: /*
2: Copyright (c) 2011 <a href="http://www.gutgames.com">James Craig</a>
3:
4: Permission is hereby granted, free of charge, to any person obtaining a copy
5: of this software and associated documentation files (the "Software"), to deal
6: in the Software without restriction, including without limitation the rights
7: to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8: copies of the Software, and to permit persons to whom the Software is
9: furnished to do so, subject to the following conditions:
10:
11: The above copyright notice and this permission notice shall be included in
12: all copies or substantial portions of the Software.
13:
14: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15: IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16: FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17: AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18: LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19: OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20: THE SOFTWARE.*/
21:
22: #region Usings
23: using System;
24: using System.Collections.Generic;
25: using System.Linq;
26: using System.Text;
27: using Utilities.DataTypes.Patterns.BaseClasses;
28: using System.Reflection;
29: using MoonUnitLoader.Configuration;
30: #endregion
31:
32: namespace MoonUnitLoader
33: { 34: /// <summary>
35: /// Manager class for unit testing framework
36: /// </summary>
37: public class Manager : Singleton<Manager>
38: { 39: #region Constructor
40:
41: /// <summary>
42: /// Constructor
43: /// </summary>
44: protected Manager()
45: : base()
46: { 47: Configuration = Gestalt.Manager.Instance.GetConfigFile<Configuration.Configuration>("MoonUnitLoader"); 48: AssemblyName Name = AssemblyName.GetAssemblyName(Configuration.AssemblyLocation);
49: MoonUnitAssembly = AppDomain.CurrentDomain.Load(Name);
50: MoonUnitManagerType = MoonUnitAssembly.GetType("MoonUnit.Manager"); 51: PropertyInfo InstanceProperty = MoonUnitManagerType.GetProperty("Instance", BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy); 52: MethodInfo Method = InstanceProperty.GetGetMethod();
53: MoonUnitManager = Method.Invoke(null, new object[] { }); 54: TestAssembly = MoonUnitManagerType.GetMethod("Test", new Type[] { typeof(Assembly) }); 55: TestArray = MoonUnitManagerType.GetMethod("Test", new Type[] { typeof(Type[]) }); 56: TestType = MoonUnitManagerType.GetMethod("Test", new Type[] { typeof(Type) }); 57: }
58:
59: #endregion
60:
61: #region Function
62:
63: /// <summary>
64: /// Tests an assembly
65: /// </summary>
66: /// <param name="AssemblyToTest">Assembly to test</param>
67: /// <returns>XML string containing the results</returns>
68: public string Test(Assembly AssemblyToTest)
69: { 70: return (string)TestAssembly.Invoke(MoonUnitManager, new object[] { AssemblyToTest }); 71: }
72:
73: /// <summary>
74: /// Tests a list of types
75: /// </summary>
76: /// <param name="Types">Types to test</param>
77: /// <returns>XML string containing the results</returns>
78: public string Test(Type[] Types)
79: { 80: return (string)TestArray.Invoke(MoonUnitManager, new object[] { Types }); 81: }
82:
83: /// <summary>
84: /// Tests a type
85: /// </summary>
86: /// <param name="Type">Type to test</param>
87: /// <returns>XML string containing the results</returns>
88: public string Test(Type Type)
89: { 90: return (string)TestType.Invoke(MoonUnitManager, new object[] { Type }); 91: }
92:
93: #endregion
94:
95: #region Properties
96:
97: private Configuration.Configuration Configuration { get; set; } 98: private Assembly MoonUnitAssembly { get; set; } 99: private object MoonUnitManager { get; set; } 100: private Type MoonUnitManagerType { get; set; } 101: private MethodInfo TestAssembly { get; set; } 102: private MethodInfo TestArray { get; set; } 103: private MethodInfo TestType { get; set; } 104:
105: #endregion
106: }
107: }
108: