Beispiel #1
0
        public static IList <UnitTestInfo> GetTestMethods(this Project project)
        {
            var      list          = new List <UnitTestInfo>();
            FileInfo testOutputDll = project.GetOutputFile();

            if (!testOutputDll.Exists)
            {
                return(list);
            }
            Assembly testAssembly = Assembly.LoadFile(testOutputDll.FullName);

            //Type[] types = testAssembly.GetExportedTypes();
            Type[] types;
            try
            {
                types = testAssembly.GetTypes();
            }
            catch (ReflectionTypeLoadException e)
            {
                types = e.Types;
            }

            foreach (Type type in types)
            {
                var type1         = type;
                var testClassAttr = Check.TryCatch <Attribute, Exception>(() => type1.GetCustomAttribute(typeof(TestClassAttribute)));
                if (testClassAttr != null)
                {
                    var members = Check.TryCatch <MethodInfo[], Exception>(() => type1.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod));
                    foreach (MethodInfo member in members)
                    {
                        var       member1        = member;
                        Attribute testMethodAttr = Check.TryCatch <Attribute, Exception>(() => member1.GetCustomAttribute(typeof(TestMethodAttribute)));
                        Attribute ignoreAttr     = Check.TryCatch <Attribute, Exception>(() => member1.GetCustomAttribute(typeof(IgnoreAttribute)));
                        if (testMethodAttr != null && ignoreAttr == null)
                        {
                            var unitTestInfo = new UnitTestInfo(testOutputDll.FullName, member, project);
                            foreach (var t in member.CustomAttributes)
                            {
                                if (t.AttributeType.Name == "OwnerAttribute")
                                {
                                    unitTestInfo.Owner = t.ConstructorArguments[0].Value.ToString();
                                }
                                else if (t.AttributeType.Name == "PriorityAttribute")
                                {
                                    unitTestInfo.Priority = Int32.Parse(t.ConstructorArguments[0].Value.ToString());
                                }
                            }
                            list.Add(unitTestInfo);
                        }
                    }
                }
            }

            return(list);
        }
Beispiel #2
0
        public static ProcessStartInfo GetExecutable(this Project project)
        {
            var userProject   = project.FindUserProject();
            var startupAction = userProject?.Xml.GetPropertyValue("StartAction");

            if (!string.IsNullOrEmpty(startupAction))
            {
                var exe  = userProject.Xml.GetPropertyValue("StartProgram");
                var args = userProject.Xml.GetPropertyValue("StartArguments");
                if (File.Exists(exe))
                {
                    return(new ProcessStartInfo(exe, args));
                }
            }

            startupAction = project.GetPropertyValue("StartAction");
            if (!string.IsNullOrEmpty(startupAction))
            {
                var exe  = project.GetPropertyValue("StartProgram");
                var args = project.GetPropertyValue("StartArguments");
                if (File.Exists(exe))
                {
                    return(new ProcessStartInfo(exe, args));
                }
            }

            var startupObject = project.GetPropertyValue("StartupObject");

            if (!string.IsNullOrEmpty(startupObject) && File.Exists(startupObject))
            {
                return(new ProcessStartInfo(startupObject, string.Empty));
            }

            var outputFile = Check.TryCatch <FileInfo, Exception>(() => project.GetOutputFile(".exe"));

            if (outputFile != null && outputFile.Extension == ".exe" && outputFile.Exists)
            {
                return(new ProcessStartInfo(outputFile.FullName, string.Empty));
            }


            //else
            //{
            //    string path = project.GetPropertyValue("OutputPath");
            //    if (!string.IsNullOrEmpty(path))
            //    {

            //    }
            //}
            return(null);
        }