using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.IO;
namespace Systin.Library.UnitTests{
class Util
{
public static Assembly GetAssemblyPathRelativeToCurrentAssembly(string languageDriverDll, ref List<Type> mAssemblyTypes)
{
string pathToLanguageLibrary = GetPathToLanguageLibrary(languageDriverDll);
Assembly assembly = Assembly.LoadFile(pathToLanguageLibrary);
mAssemblyTypes = new List<Type>();
foreach (Type type in assembly.GetTypes())
{
if (type.IsClass)
{
mAssemblyTypes.Add(type);
}
}
return assembly;
}
public static string GetPathToLanguageLibrary(string languageDriverDll)
{
string path = Assembly.GetCallingAssembly().Location.ToString();
string pathToDllDirectory = System.IO.Path.GetDirectoryName(path);
string pathToLanguageLibrary = pathToDllDirectory + @"\" + languageDriverDll;
return pathToLanguageLibrary;
}
public static LanguageDriverClass GetLanguageDriverUnderTest(String classNameToTestWith, List<Type> mAssemblyTypes)
{
Type classUnderTest = FindClassInList(classNameToTestWith, mAssemblyTypes);
LanguageDriverClass ldc = LanguageDriverClass.Factory(classUnderTest);
return ldc;
}
public static Type FindClassInList(string className, List<Type> mAssemblyTypes)
{
//Search through for the right class to test
foreach (Type type in mAssemblyTypes)
{
if (type.Name.Equals(className))
{
return type;
}
}
return null;
}
public static Stack<string> GetActionTakenByMethod(LanguageDriverClass ldc)
{
object o = ldc.ActivatedInstance.GetType().GetProperty("CallStack").GetValue(ldc.ActivatedInstance, null);
//string actionTaken = ldc.ActivatedInstance.GetType().GetField("ActionTaken").GetValue(ldc.ActivatedInstance).ToString();
return ((Stack<string>)o);
}
}
}
|