Пример #1
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);
        }
Пример #2
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();
                    }
                }
            }
        }