RunProgramInGuest() public méthode

public RunProgramInGuest ( string fullPath, string param ) : void
fullPath string
param string
Résultat void
Exemple #1
0
        private void RunScriptInGuest(VMware vmware, string script)
        {
            string scriptFile      = Path.ChangeExtension(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()), ".bat");
            var    guestScriptName = string.Format(@"C:\{0}.bat", Guid.NewGuid().ToString("N"));

            File.WriteAllText(scriptFile, script);

            try
            {
                vmware.CopyFileToGuest(scriptFile, guestScriptName);
            }
            finally
            {
                File.Delete(scriptFile);
            }

            vmware.RunProgramInGuest(guestScriptName, string.Empty);
        }
        private void RunScriptInGuest(VMware vmware, string script)
        {
            string scriptFile = Path.ChangeExtension(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()), ".bat");
             var guestScriptName = string.Format(@"C:\{0}.bat", Guid.NewGuid().ToString("N"));

             File.WriteAllText(scriptFile, script);

             try
             {
            vmware.CopyFileToGuest(scriptFile, guestScriptName);
             }
             finally
             {
            File.Delete(scriptFile);
             }

             vmware.RunProgramInGuest(guestScriptName, string.Empty);
        }
        private void RunInternal()
        {
            VMware vm = new VMware();

             if (!File.Exists(ExpandVariables(NUnitPath) + "\\nunit-console.exe"))
             throw new Exception("Incorrect path to NUnit.");

            string fixtureSourcePath = TestSettings.GetFixturePath();
            string fixturePath = fixtureSourcePath + @"\bin\Release";
             // Check that the test fixture is available.
             var testAssemblies = Directory.GetFiles(fixturePath, "*.dll");
             if (!testAssemblies.Any())
            throw new Exception("Test assembly not found.");

            string runTestsScriptName = "RunTestsInVmware.bat";
            string runTestScripts = fixtureSourcePath + @"\" + runTestsScriptName;
            string guestTestPath = @"C:\Nunit";

            string softwareUnderTestFullPath = _softwareUnderTest;
            string softwareUnderTestName = Path.GetFileName(softwareUnderTestFullPath);

            string softwareUnderTestSilentParmas = "/SILENT";

            string sslFolder = Path.Combine(TestSettings.GetTestFolder(), "SSL examples");

            vm.Connect();

            vm.OpenVM(_environment.VMwarePath);

             try
             {
            vm.RevertToSnapshot(_environment.SnapshotName);
            vm.LoginInGuest("VMware", "vmware");

            // Make sure we have an IP address.
            EnsureNetworkAccess(vm);

            // Set up test paths.
            vm.CreateDirectory(guestTestPath);
            vm.CreateDirectory(@"C:\Temp");

            // Install
            vm.CopyFileToGuest(softwareUnderTestFullPath, guestTestPath + "\\" + softwareUnderTestName);
            vm.RunProgramInGuest(guestTestPath + "\\" + softwareUnderTestName, softwareUnderTestSilentParmas);

            foreach (PostInstallFileCopy copyOperation in _environment.PostInstallFileCopy)
               vm.CopyFileToGuest(copyOperation.From, copyOperation.To);

            foreach (PostInstallCommand command in _environment.PostInstallCommands)
               vm.RunProgramInGuest(command.Executable, command.Parameters);

            // Configure Nunit
            vm.CopyFolderToGuest(ExpandVariables(NUnitPath), guestTestPath);
            vm.CopyFolderToGuest(Path.Combine(ExpandVariables(NUnitPath), "lib"), Path.Combine(guestTestPath, "lib"));
            vm.CopyFolderToGuest(fixturePath, guestTestPath);
            vm.CopyFileToGuest(runTestScripts, guestTestPath + "\\" + runTestsScriptName);

            // Other required stuff.
            vm.CopyFolderToGuest(sslFolder, @"C:\SSL examples");
            vm.CopyFolderToGuest(Path.Combine(sslFolder, "WithPassword"), @"C:\SSL examples\WithPassword");

            bool useLocalVersion = false;

            if (useLocalVersion)
            {
               CopyLocalVersion(vm);
            }

            // Run NUnit
            vm.RunProgramInGuest(guestTestPath + "\\" + runTestsScriptName, "");

            // Collect results.
            string localResultFile = Path.GetTempFileName() + ".xml";
            string localLogFile = Path.GetTempFileName() + ".log";
            vm.CopyFileToHost(guestTestPath + "\\TestResult.xml", localResultFile);
            vm.CopyFileToHost(guestTestPath + "\\TestResult.log", localLogFile);

            XmlDocument doc = new XmlDocument();
            doc.Load(localResultFile);

            int failureCount = Convert.ToInt32(doc.LastChild.Attributes["failures"].Value);
            int errorCount = Convert.ToInt32(doc.LastChild.Attributes["errors"].Value);

            if (failureCount == 0 && errorCount == 0)
               return;

            string resultContent = File.ReadAllText(localResultFile);
            string logContent = File.ReadAllText(localLogFile);
            throw new Exception(resultContent + "\r\n\r\n" + logContent);
             }
             finally
             {
            vm.PowerOff();
             }
        }
Exemple #4
0
        private void RunInternal()
        {
            VMware vm = new VMware();

            if (!File.Exists(ExpandVariables(NUnitPath) + "\\nunit-console.exe"))
            {
                throw new Exception("Incorrect path to NUnit.");
            }

            string fixtureSourcePath = TestSettings.GetFixturePath();
            string fixturePath       = fixtureSourcePath + @"\bin\x86\Release";

            // Check that the test fixture is available.
            var testAssemblies = Directory.GetFiles(fixturePath, "*.dll");

            if (!testAssemblies.Any())
            {
                throw new Exception("Test assembly not found.");
            }


            string runTestsScriptName = "RunTestsInVmware.bat";
            string runTestScripts     = fixtureSourcePath + @"\" + runTestsScriptName;
            string guestTestPath      = @"C:\Nunit";

            string softwareUnderTestFullPath = _softwareUnderTest;
            string softwareUnderTestName     = Path.GetFileName(softwareUnderTestFullPath);

            string softwareUnderTestSilentParmas = "/SILENT";

            string sslFolder = Path.Combine(TestSettings.GetTestFolder(), "SSL examples");

            vm.Connect();
            vm.OpenVM(_environment.VMwarePath);

            vm.RevertToSnapshot(_environment.SnapshotName);
            vm.LoginInGuest("VMware", "vmware");

            // Make sure we have an IP address.
            EnsureNetworkAccess(vm);

            // Set up test paths.
            vm.CreateDirectory(guestTestPath);
            vm.CreateDirectory(@"C:\Temp");

            // Install
            vm.CopyFileToGuest(softwareUnderTestFullPath, guestTestPath + "\\" + softwareUnderTestName);
            vm.RunProgramInGuest(guestTestPath + "\\" + softwareUnderTestName, softwareUnderTestSilentParmas);

            foreach (PostInstallFileCopy copyOperation in _environment.PostInstallFileCopy)
            {
                vm.CopyFileToGuest(copyOperation.From, copyOperation.To);
            }

            foreach (PostInstallCommand command in _environment.PostInstallCommands)
            {
                vm.RunProgramInGuest(command.Executable, command.Parameters);
            }

            // Configure Nunit
            vm.CopyFolderToGuest(ExpandVariables(NUnitPath), guestTestPath);
            vm.CopyFolderToGuest(Path.Combine(ExpandVariables(NUnitPath), "lib"), Path.Combine(guestTestPath, "lib"));
            vm.CopyFolderToGuest(fixturePath, guestTestPath);
            vm.CopyFileToGuest(runTestScripts, guestTestPath + "\\" + runTestsScriptName);

            // Other required stuff.
            vm.CopyFolderToGuest(sslFolder, @"C:\SSL examples");
            vm.CopyFolderToGuest(Path.Combine(sslFolder, "WithPassword"), @"C:\SSL examples\WithPassword");

            bool useLocalVersion = true;

            if (useLocalVersion)
            {
                CopyLocalVersion(vm);
            }


            // Run NUnit
            vm.RunProgramInGuest(guestTestPath + "\\" + runTestsScriptName, "");

            // Collect results.
            string localResultFile = System.IO.Path.GetTempFileName() + ".xml";
            string localLogFile    = System.IO.Path.GetTempFileName() + ".log";

            vm.CopyFileToHost(guestTestPath + "\\TestResult.xml", localResultFile);
            vm.CopyFileToHost(guestTestPath + "\\TestResult.log", localLogFile);

            XmlDocument doc = new XmlDocument();

            doc.Load(localResultFile);

            int failureCount = Convert.ToInt32(doc.LastChild.Attributes["failures"].Value);
            int errorCount   = Convert.ToInt32(doc.LastChild.Attributes["errors"].Value);

            if (failureCount == 0 && errorCount == 0)
            {
                vm.PowerOff();
                return;
            }

            string resultContent = File.ReadAllText(localResultFile);
            string logContent    = File.ReadAllText(localLogFile);

            throw new Exception(resultContent + "\r\n\r\n" + logContent);
        }
Exemple #5
0
        private void RunInternal()
        {
            VMware vm = new VMware();

            bool success = true;

            try
            {
                string fixtureSourcePath = TestSettings.GetFixturePath();
                string fixturePath       = fixtureSourcePath + @"\bin\Release";

                string runTestsScriptName = "RunTestsInVmware.bat";
                string runTestScripts     = fixtureSourcePath + @"\" + runTestsScriptName;
                string guestTestPath      = @"C:\Nunit";

                string softwareUnderTestFullPath = TestSettings.GetSoftwareUnderTest();
                string softwareUnderTestName     = Path.GetFileName(softwareUnderTestFullPath);

                string softwareUnderTestSilentParmas = "/SILENT";

                string sslFolder = Path.Combine(TestSettings.GetTestFolder(), "SSL examples");

                vm.Connect();
                vm.OpenVM(_environment.VMwarePath);
                vm.RevertToSnapshot(_environment.SnapshotName);
                vm.LoginInGuest("VMware", "vmware");

                // Make sure we have an IP address.
                vm.RunProgramInGuest("ipconfig.exe", "/renew");
                vm.RunProgramInGuest("ipconfig.exe", "/renew");

                // Set up test paths.
                vm.CreateDirectory(guestTestPath);
                vm.CreateDirectory(@"C:\Temp");

                // Install
                vm.CopyFileToGuest(softwareUnderTestFullPath, guestTestPath + "\\" + softwareUnderTestName);
                vm.RunProgramInGuest(guestTestPath + "\\" + softwareUnderTestName, softwareUnderTestSilentParmas);

                foreach (PostInstallFileCopy copyOperation in _environment.PostInstallFileCopy)
                {
                    vm.CopyFileToGuest(copyOperation.From, copyOperation.To);
                }

                foreach (PostInstallCommand command in _environment.PostInstallCommands)
                {
                    vm.RunProgramInGuest(command.Executable, command.Parameters);
                }

                // Configure Nunit
                vm.CopyFolderToGuest(ExpandVariables(NUnitPath), guestTestPath);
                vm.CopyFolderToGuest(Path.Combine(ExpandVariables(NUnitPath), "lib"), Path.Combine(guestTestPath, "lib"));
                vm.CopyFolderToGuest(fixturePath, guestTestPath);
                vm.CopyFileToGuest(runTestScripts, guestTestPath + "\\" + runTestsScriptName);

                // Other required stuff.
                vm.CopyFolderToGuest(sslFolder, @"C:\SSL examples");
                vm.CopyFolderToGuest(Path.Combine(sslFolder, "WithPassword"), @"C:\SSL examples\WithPassword");

                // Run NUnit
                vm.RunProgramInGuest(guestTestPath + "\\" + runTestsScriptName, "");

                // Collect results.
                string localResultFile = System.IO.Path.GetTempFileName() + ".xml";
                vm.CopyFileToHost(guestTestPath + "\\TestResult.xml", localResultFile);

                XmlDocument doc = new XmlDocument();
                doc.Load(localResultFile);

                string failures     = doc.LastChild.Attributes["failures"].Value;
                int    failureCount = Convert.ToInt32(failures);

                if (failureCount == 0)
                {
                    return;
                }

                string resultContent = File.ReadAllText(localResultFile);
                success = false;

                throw new Exception(resultContent);
            }
            catch (ThreadAbortException)
            {
                // Aborting. Power of virtual machine.
                vm.PowerOff();
                vm = null;
            }
            catch (Exception e)
            {
                success = false;
                throw e;
            }
            finally
            {
                if (success || _embedded || !_stopOnError)
                {
                    if (vm != null)
                    {
                        vm.PowerOff();
                    }
                }
            }
        }
Exemple #6
0
        private void RunInternal()
        {
            VMware vm = new VMware();

             bool success = true;

             if (!File.Exists(ExpandVariables(NUnitPath) + "\\nunit-console.exe"))
             throw new Exception("Incorrect path to NUnit.");

             try
             {
            string fixtureSourcePath = TestSettings.GetFixturePath();
            string fixturePath = fixtureSourcePath + @"\bin\Release";

            string runTestsScriptName = "RunTestsInVmware.bat";
            string runTestScripts = fixtureSourcePath + @"\" + runTestsScriptName;
            string guestTestPath = @"C:\Nunit";

            string softwareUnderTestFullPath = TestSettings.GetSoftwareUnderTest();
            string softwareUnderTestName = Path.GetFileName(softwareUnderTestFullPath);

            string softwareUnderTestSilentParmas = "/SILENT";

            string sslFolder = Path.Combine(TestSettings.GetTestFolder(), "SSL examples");

            vm.Connect();
            vm.OpenVM(_environment.VMwarePath);
            vm.RevertToSnapshot(_environment.SnapshotName);
            vm.LoginInGuest("VMware", "vmware");

            // Make sure we have an IP address.
            vm.RunProgramInGuest("ipconfig.exe", "/renew");
            vm.RunProgramInGuest("ipconfig.exe", "/renew");

            // Set up test paths.
            vm.CreateDirectory(guestTestPath);
            vm.CreateDirectory(@"C:\Temp");

            // Install
            vm.CopyFileToGuest(softwareUnderTestFullPath, guestTestPath + "\\" + softwareUnderTestName);
            vm.RunProgramInGuest(guestTestPath + "\\" + softwareUnderTestName, softwareUnderTestSilentParmas);

            foreach (PostInstallFileCopy copyOperation in _environment.PostInstallFileCopy)
               vm.CopyFileToGuest(copyOperation.From, copyOperation.To);

            foreach (PostInstallCommand command in _environment.PostInstallCommands)
               vm.RunProgramInGuest(command.Executable, command.Parameters);

            // Configure Nunit
            vm.CopyFolderToGuest(ExpandVariables(NUnitPath), guestTestPath);
            vm.CopyFolderToGuest(Path.Combine(ExpandVariables(NUnitPath), "lib"), Path.Combine(guestTestPath, "lib"));
            vm.CopyFolderToGuest(fixturePath, guestTestPath);
            vm.CopyFileToGuest(runTestScripts, guestTestPath + "\\" + runTestsScriptName);

            // Other required stuff.
            vm.CopyFolderToGuest(sslFolder, @"C:\SSL examples");
            vm.CopyFolderToGuest(Path.Combine(sslFolder, "WithPassword"), @"C:\SSL examples\WithPassword");

            // Run NUnit
            vm.RunProgramInGuest(guestTestPath + "\\" + runTestsScriptName, "");

            // Collect results.
            string localResultFile = System.IO.Path.GetTempFileName() + ".xml";
            vm.CopyFileToHost(guestTestPath + "\\TestResult.xml", localResultFile);

            XmlDocument doc = new XmlDocument();
            doc.Load(localResultFile);

            string failures = doc.LastChild.Attributes["failures"].Value;
            int failureCount = Convert.ToInt32(failures);

            if (failureCount == 0)
               return;

            string resultContent = File.ReadAllText(localResultFile);
            success = false;

            throw new Exception(resultContent);
             }
             catch (ThreadAbortException)
             {
            // Aborting. Power of virtual machine.
            vm.PowerOff();
            vm = null;

             }
             catch (Exception e)
             {
            success = false;
            throw e;
             }
             finally
             {
            if (success || _embedded || !_stopOnError)
            {
               if (vm != null)
                  vm.PowerOff();
            }
             }
        }