Пример #1
0
        public static void Run(string dllName, string dllLocation, string category, string module, List <string> testCase)
        {
            LogMessageToFile("Killing MsTest.exe");
            KillMsTest();
            string path           = ConfigurationManager.AppSettings["TestRunBatchFileLocation"] + "test" + DateTime.Now.ToString("hhmmss") + ".bat";
            var    contentBuilder = new StringBuilder();
            string msTestPath     = null;

            LoggerUtil.LogMessageToFile("Finding MSTest.exe on the system");

            if (!File.Exists(@"C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\MSTest.exe"))
            {
                string[] msTestPaths = null;
                try
                {
                    string temp = CommandUtils.GetMsTestPath().Split(new string[] { "Directory of" },
                                                                     System.StringSplitOptions.None)[1];
                    LogMessageToFile("Split result of mstest path is : " + temp);
                    msTestPaths = temp.Split(new string[] { @"\IDE" }, System.StringSplitOptions.None);
                    msTestPath  = msTestPaths[0].Trim() + @"\IDE\";
                    LogMessageToFile("MsTestPath found using enumeration is File is " + msTestPath);
                }
                catch (Exception ex)
                {
                    LogMessageToFile("Exception caught at finding MSTest.exe path is : " + ex.ToString());
                }
                finally
                {
                    if (msTestPath == null)
                    {
                        LogMessageToFile("Throwing Custom Exception for mstestpath to be null.");
                        throw new CustomException("Please Install Test Agent or Visual Studio to run test cases.");
                    }
                }
            }
            else
            {
                msTestPath = @"C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\";
            }
            LoggerUtil.LogMessageToFile("The MSTest executable path is : " + msTestPath);

            contentBuilder.AppendLine(@"cd " + msTestPath);
            contentBuilder.Append(@"MSTest.exe /testcontainer:""");
            string otLoc = OTGen.CreateOrderedTest(testCase, dllName, dllLocation, ConfigurationManager.AppSettings["XmlSchema"],
                                                   ConfigurationManager.AppSettings["MSType"], dllLocation.Substring(0, dllLocation.LastIndexOf('\\')));

            contentBuilder.Append(otLoc + "\"");
            contentBuilder.Append(" /testsettings:\"");
            string settingFilePath = @"C:\Automation\Automation.testsettings";
            string loc             = CreateNewTestResultpath(ConfigurationManager.AppSettings["TrxFileLocation"]).ToString();

            contentBuilder.Append(settingFilePath + "\"");

            contentBuilder.Append(" /resultsfile:\"");

            contentBuilder.Append(loc + "\"");

            LogBatFileOutput(contentBuilder, path);

            CommandUtils.DeleteTestBatFiles();

            using (var writer = new StreamWriter(path))
            {
                writer.WriteLine(contentBuilder.ToString());
                writer.Close();
            }

            var start = new ProcessStartInfo
            {
                FileName               = path,
                UseShellExecute        = false,
                RedirectStandardOutput = true,
                CreateNoWindow         = true,
                WindowStyle            = ProcessWindowStyle.Hidden
            };

            DateTime dt = DateTime.Now;

            using (Process process = Process.Start(start))
            {
                if (process != null)
                {
                    System.Threading.Thread.Sleep(2000);
                    dt = DateTime.Now;
                    LogMessageToFile("MSTest triggered without waiting for the process");
                }
            }
        }
Пример #2
0
        public static void RunDirectCall(string dllName, string dllLocation, string category, string module, List <string> testCase)
        {
            KillMsTest();
            string path           = ConfigurationManager.AppSettings["TestRunBatchFileLocation"] + "test" + DateTime.Now.ToString("hhmmss") + ".bat";
            var    contentBuilder = new StringBuilder();
            string msTestPath     = null;

            LoggerUtil.LogMessageToFile("Finding MSTest.exe on the system");

            if (!File.Exists(@"C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\MSTest.exe"))
            {
                string[] msTestPaths = null;
                try
                {
                    msTestPaths = CommandUtils.GetMsTestPath().Split(new string[] { "Directory of" },
                                                                     System.StringSplitOptions.None)[1].Split(new string[] { "IDE" }, System.StringSplitOptions.None);
                }
                catch (Exception ex)
                {
                    LogMessageToFile("Exception caught at finding MSTest.exe path is : " + ex.ToString());
                }
                finally
                {
                    if (msTestPath == null || !msTestPath.Contains("Visual Studio"))
                    {
                        throw new CustomException("Please Install Test Agent or Visual Studio to run test cases.");
                    }
                    msTestPath = msTestPaths[0].Trim() + @"IDE\";
                }
            }
            else
            {
                msTestPath = @"C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\";
            }

            contentBuilder.AppendLine(@"cd " + msTestPath);
            contentBuilder.Append(@"MSTest.exe /testcontainer:""");
            string otLoc = OTGen.CreateOrderedTest(testCase, dllName, dllLocation, ConfigurationManager.AppSettings["XmlSchema"],
                                                   ConfigurationManager.AppSettings["MSType"], dllLocation.Substring(0, dllLocation.LastIndexOf('\\')));

            contentBuilder.Append(otLoc + "\"");

            //if (module == "All")
            //{
            //}
            //else
            //{
            //    if (testCase == "All")
            //    {
            //        contentBuilder.Append(" /category:");
            //        contentBuilder.Append("\"" + module + "\"");
            //    }
            //    else
            //    {
            //        contentBuilder.Append(" /test:");
            //        contentBuilder.Append(testCase);
            //    }
            //}
            contentBuilder.Append(" /testsettings:\"");
            string settingFilePath = @"C:\Automation\Automation.testsettings";
            string loc             = CreateNewTestResultpath(ConfigurationManager.AppSettings["TrxFileLocation"]).ToString();

            contentBuilder.Append(settingFilePath + "\"");
            //string tempLoc = loc.ToString().Replace("Results.trx", "");
            //string destFilePath = tempLoc + "Automation.testsettings";
            //contentBuilder.Append("Automation.testsettings"+"\"");
            //File.Copy(settingFilePath, destFilePath);
            contentBuilder.Append(" /resultsfile:\"");
            //checkin comment
            contentBuilder.Append(loc + "\"");
            contentBuilder.AppendLine("  ");
            //contentBuilder.AppendLine("taskkill /F /IM CdcSmartClientContainer.exe /T");
            contentBuilder.AppendLine("exit");

            LogBatFileOutput(contentBuilder, path);

            CommandUtils.DeleteTestBatFiles();

            using (var writer = new StreamWriter(path))
            {
                writer.WriteLine(contentBuilder.ToString());

                writer.Close();
            }

            var start = new ProcessStartInfo
            {
                FileName               = path,
                UseShellExecute        = false,
                RedirectStandardOutput = true,
                CreateNoWindow         = true,
                WindowStyle            = ProcessWindowStyle.Hidden
            };


            using (Process process = Process.Start(start))
            {
                LogMessageToFile("MSTest triggered without waiting for the process");
                //if (process != null)
                //{
                //    //using (StreamReader reader = process.StandardOutput)
                //    //{
                //    //    string result = reader.ReadToEnd();
                //    //    LogMessageToFile(result);
                //    //}
                //    process.WaitForExit();
                //}
            }
        }