Testing.Run_Test C# (CSharp) Method

Run_Test() private method

private Run_Test ( dynamic, data ) : object
data dynamic,
return object
    public static object Run_Test(dynamic data)
    {
        try
        {
            Type type = Assembly.GetExecutingAssembly().GetType(data.ClassName);
            var test = Activator.CreateInstance(type);
            type.InvokeMember(data.MethodName, BindingFlags.InvokeMethod, null, test, new object[0]);

            //Ensure no exception expected
            MethodInfo method = type.GetMethod(data.MethodName);
            var attribute = method.GetCustomAttributes(typeof(ExpectedException), true).FirstOrDefault();
            if (attribute != null)
            {
                data.HasPassed = "false";
                data.Message = "Exception "+ ((ExpectedException) attribute).Type.Name + " did not occur as expected";
            }
            else
            {
                data.HasPassed = "true";
            }
        }
        catch (Exception ex)
        {
            data.HasPassed = "false";
            data.Message = ex.InnerException.Message;

            Type type = Assembly.GetExecutingAssembly().GetType(data.ClassName);
            if (type != null)
            {
                //Ensure the exception is expected
                MethodInfo method = type.GetMethod(data.MethodName);
                var attribute = method.GetCustomAttributes(typeof(ExpectedException), true).FirstOrDefault();
                if (attribute != null)
                {
                    if (((ExpectedException) attribute).Type.Equals(ex.InnerException.GetType()))
                    {
                        data.HasPassed = "true";
                        data.Message = "";
                    }
                }
            }
        }
        return data;
    }