Exemplo n.º 1
0
        private void EnsureNetworkAccess(VMware vmware)
        {
            string pingResultData = string.Empty;

            DateTime timeoutTime = DateTime.UtcNow.AddSeconds(20);

            while (DateTime.UtcNow < timeoutTime)
            {
                string script = @"echo %time% >> C:\pingresult.txt
                              ipconfig /renew >> C:\pingresult.txt
                              ping www.google.com -n 1 >> C:\pingresult.txt";

                RunScriptInGuest(vmware, script);

                string pingResultFile = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());

                vmware.CopyFileToHost("C:\\pingresult.txt", pingResultFile);

                pingResultData = File.ReadAllText(pingResultFile);

                if (pingResultData.Contains("Reply from "))
                {
                    return;
                }

                Thread.Sleep(TimeSpan.FromSeconds(1));
            }

            throw new Exception("No network access. Ping result: " + pingResultData);
        }
Exemplo n.º 2
0
        private void CopyLocalVersion(VMware vm)
        {
            const string localPath =
            @"C:\dev\hmailserver\hmailserver\source\Server\hMailServer\Release\hMailServer.exe";

             RunScriptInGuest(vm, "NET STOP HMAILSERVER");
             RunScriptInGuest(vm, @"MKDIR ""C:\Program Files (x86)\hMailServer\Bin\");
             RunScriptInGuest(vm, @"MKDIR ""C:\Program Files\hMailServer\Bin\");
             vm.CopyFileToGuest(localPath, @"C:\Program Files (x86)\hMailServer\Bin\hMailServer.exe");
             vm.CopyFileToGuest(localPath, @"C:\Program Files\hMailServer\Bin\hMailServer.exe");
             RunScriptInGuest(vm, "NET START HMAILSERVER");
        }
Exemplo n.º 3
0
        private void CopyLocalVersion(VMware vm)
        {
            const string localPath =
                @"C:\dev\hmailserver\hmailserver\source\Server\hMailServer\Release\hMailServer.exe";

            RunScriptInGuest(vm, "NET STOP HMAILSERVER");
            RunScriptInGuest(vm, @"MKDIR ""C:\Program Files (x86)\hMailServer\Bin\");
            RunScriptInGuest(vm, @"MKDIR ""C:\Program Files\hMailServer\Bin\");
            vm.CopyFileToGuest(localPath, @"C:\Program Files (x86)\hMailServer\Bin\hMailServer.exe");
            vm.CopyFileToGuest(localPath, @"C:\Program Files\hMailServer\Bin\hMailServer.exe");
            RunScriptInGuest(vm, "NET START HMAILSERVER");
        }
Exemplo n.º 4
0
        private void CopyLocalVersion(VMware vm)
        {
            string currentDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            var localExecutable = Path.Combine(currentDir,
                                               @"..\..\..\..\..\..\source\Server\hMailServer\x64\Release\hMailServer.exe");

            if (!File.Exists(localExecutable))
            {
                throw new Exception($"The executable {localExecutable} could not be found.");
            }

            RunScriptInGuest(vm, "NET STOP HMAILSERVER");
            vm.CopyFileToGuest(localExecutable, @"C:\Program Files\hMailServer\Bin\hMailServer.exe");
            RunScriptInGuest(vm, "NET START HMAILSERVER");
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
0
        private void EnsureNetworkAccess(VMware vmware)
        {
            string pingResultData = string.Empty;

            for (int i = 0; i < 5; i++)
            {
                string script = "ipconfig /renew\r\nping www.google.com -n 1 > C:\\pingresult.txt";
                RunScriptInGuest(vmware, script);

                string pingResultFile = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());

                vmware.CopyFileToHost("C:\\pingresult.txt", pingResultFile);

                pingResultData = File.ReadAllText(pingResultFile);

                if (pingResultData.Contains("Reply from "))
                {
                    return;
                }
            }

            throw new Exception("No network access. Ping result: " + pingResultData);
        }
Exemplo n.º 7
0
        private void EnsureNetworkAccess(VMware vmware)
        {
            string pingResultData = string.Empty;

             DateTime timeoutTime = DateTime.UtcNow.AddSeconds(20);

             while (DateTime.UtcNow < timeoutTime)
             {
            string script = @"echo %time% >> C:\pingresult.txt
                              ipconfig /renew >> C:\pingresult.txt
                              ping www.google.com -n 1 >> C:\pingresult.txt";

            RunScriptInGuest(vmware, script);

            string pingResultFile = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());

            vmware.CopyFileToHost("C:\\pingresult.txt", pingResultFile);

            pingResultData = File.ReadAllText(pingResultFile);

            if (pingResultData.Contains("Reply from "))
               return;

            Thread.Sleep(TimeSpan.FromSeconds(1));
             }

             throw new Exception("No network access. Ping result: " + pingResultData);
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
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\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();
             }
        }
Exemplo n.º 10
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);
        }
Exemplo n.º 11
0
        private void EnsureNetworkAccess(VMware vmware)
        {
            string pingResultData = string.Empty;

             for (int i = 0; i < 5; i++)
             {
            string script = "ipconfig /renew\r\nping www.google.com -n 1 > C:\\pingresult.txt";
            RunScriptInGuest(vmware, script);

            string pingResultFile = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());

            vmware.CopyFileToHost("C:\\pingresult.txt", pingResultFile);

            pingResultData = File.ReadAllText(pingResultFile);

            if (pingResultData.Contains("Reply from "))
               return;
             }

             throw new Exception("No network access. Ping result: " + pingResultData);
        }
Exemplo n.º 12
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();
                    }
                }
            }
        }
Exemplo n.º 13
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();
            }
             }
        }