using System;
using System.Collections;
using System.Reflection;
using QC.QTMDotNetKernelInterface;
using QC.QTMDotNetKernelInterface.Environment;

namespace QC.QTMDotNetKernel.Registry;

public class TestClass : MarshalByRefObject
{
	private Type type;

	private string fullName;

	private bool isTestClass;

	private Hashtable methods = new Hashtable();

	private Hashtable properties = new Hashtable();

	private object instance;

	private TestAssembly parent;

	public string FullName
	{
		get
		{
			return fullName;
		}
		set
		{
			fullName = value;
		}
	}

	public Hashtable Methods
	{
		get
		{
			return methods;
		}
		set
		{
			methods = value;
		}
	}

	public Hashtable Properties
	{
		get
		{
			return properties;
		}
		set
		{
			properties = value;
		}
	}

	public bool IsTestClass
	{
		get
		{
			return isTestClass;
		}
		set
		{
			isTestClass = value;
		}
	}

	public Type TestType
	{
		get
		{
			return type;
		}
		set
		{
			type = value;
		}
	}

	public object Instance
	{
		get
		{
			return instance;
		}
		set
		{
			instance = value;
		}
	}

	public TestAssembly Parent
	{
		get
		{
			return parent;
		}
		set
		{
			parent = value;
		}
	}

	public QSPREnvironment Environment
	{
		get
		{
			return Parent.Environment;
		}
		set
		{
			Parent.Environment = value;
		}
	}

	public TestClass()
	{
	}

	public TestClass(Type type)
	{
		this.type = type;
		fullName = type.FullName;
		MethodInfo[] array = type.GetMethods();
		MethodInfo[] array2 = array;
		foreach (MethodInfo methodInfo in array2)
		{
			AddMethod(methodInfo);
		}
		MemberInfo[] members = type.GetMembers();
		MemberInfo[] array3 = members;
		foreach (MemberInfo memberInfo in array3)
		{
			if (memberInfo.MemberType == MemberTypes.Property)
			{
				PropertyInfo pInfo = (PropertyInfo)memberInfo;
				AddProperty(pInfo);
			}
		}
		foreach (TestMethod value in methods.Values)
		{
			foreach (TestProperty value2 in properties.Values)
			{
				value.AddProperty(value2);
			}
		}
	}

	private bool AddMethod(MethodInfo methodInfo)
	{
		try
		{
			bool created;
			TestMethod testMethod = new TestMethod(methodInfo, out created);
			if (created)
			{
				testMethod.Parent = this;
				if (!methods.Contains(testMethod.Name))
				{
					methods.Add(testMethod.Name, testMethod);
				}
				return true;
			}
		}
		catch
		{
		}
		return false;
	}

	private bool AddProperty(PropertyInfo pInfo)
	{
		try
		{
			bool created;
			TestProperty testProperty = new TestProperty(pInfo, out created);
			if (created)
			{
				testProperty.Parent = this;
				if (!properties.Contains(testProperty.Name))
				{
					properties.Add(testProperty.Name, testProperty);
				}
				return true;
			}
		}
		catch
		{
		}
		return false;
	}

	public void ApplyAttributes()
	{
		Attribute[] customAttributes = Attribute.GetCustomAttributes(TestType);
		Attribute[] array = customAttributes;
		foreach (Attribute attribute in array)
		{
			if (attribute is QTMTestClass)
			{
				IsTestClass = true;
				break;
			}
		}
		try
		{
			foreach (TestProperty value in properties.Values)
			{
				value.ApplyAttributes();
			}
		}
		catch
		{
		}
		try
		{
			foreach (TestMethod value2 in methods.Values)
			{
				value2.ApplyAttributes();
			}
		}
		catch
		{
		}
	}

	public void CreateTestSelections(string methodName, object parameters)
	{
		try
		{
			if (methods.Contains(methodName))
			{
				TestMethod testMethod = (TestMethod)methods[methodName];
				testMethod.Selected = true;
				testMethod.CreateParameterSelections(parameters);
			}
		}
		catch
		{
		}
	}
}
