static void Main(string[] args) { using (var operatingSystem = new RemoteEnvironment(Ip, UserName, Password, @"c:\Users\Eugene\source\repos\PSTools\PsExec.exe")) { // Copy nUnit test to Guest PC operatingSystem.CopyFileFromHostToGuest( PathToNUnitTest + @"\ZigZagConversion.zip", @"C:\_work"); // Unzip nUnit test on Guest PC operatingSystem.WindowsShellInstance.DetachElevatedCommandInGuestNoRemoteOutput( @"7z.exe x -aoa -oc:\_work\Output c:\_work\ZigZagConversion.zip", TimeSpan.FromSeconds(1)); // Execute nUnit test on Guest PC operatingSystem.WindowsShellInstance.DetachElevatedCommandInGuestNoRemoteOutput( @"nunit3-console --work=c:\_work\Output c:\_work\Output\ZigZagTest.dll", TimeSpan.FromSeconds(1)); // Verify that nunit execution test result (TestResult.xml) exist in "c:\_work\Output" if (operatingSystem.FileExistsInGuest(@"c:\_work\Output\TestResult.xml")) { // Copy Test Result from Guest to Host operatingSystem.CopyFileFromGuestToHost( @"c:\_work\Output\TestResult.xml", PathToNUnitTest); } } }
public TestManager() { var ip = ConfigurationManager.AppSettings.Get("IP"); var userName = ConfigurationManager.AppSettings.Get("Username"); var password = ConfigurationManager.AppSettings.Get("Password"); var pathToPsExec = ConfigurationManager.AppSettings.Get("PathToPsExec"); pathToTests = ConfigurationManager.AppSettings.Get("PathToTests"); guestPathToTests = ConfigurationManager.AppSettings.Get("GuestPathToTests"); testDllName = ConfigurationManager.AppSettings.Get("TestDllName"); testXmlName = ConfigurationManager.AppSettings.Get("TestXmlName"); pathToTestsResult = ConfigurationManager.AppSettings.Get("PathToTestsResult"); Guard.ArgumentNotNullOrEmpty(ip, nameof(ip)); Guard.ArgumentNotNullOrEmpty(userName, nameof(userName)); Guard.ArgumentNotNullOrEmpty(password, nameof(password)); Guard.ArgumentNotNullOrEmpty(pathToPsExec, nameof(pathToPsExec)); Guard.ArgumentNotNullOrEmpty(pathToTests, nameof(pathToTests)); Guard.ArgumentNotNullOrEmpty(guestPathToTests, nameof(guestPathToTests)); Guard.ArgumentNotNullOrEmpty(testDllName, nameof(testDllName)); Guard.ArgumentNotNullOrEmpty(testXmlName, nameof(testXmlName)); Guard.ArgumentNotNullOrEmpty(pathToTestsResult, nameof(pathToTestsResult)); operatingSystem = new RemoteEnvironment(ip, userName, password, pathToPsExec); Guard.ArgumentNotNull(operatingSystem, nameof(operatingSystem)); }
public void ExecuteUiTestOnRemoteHost() { // Test Assumption C:\_work folder exist on remote Host using (var operatingSystem = new RemoteEnvironment(Ip, UserName, Password, PsToolPath)) { // Copy nUnit test to Guest PC operatingSystem.CopyFileFromHostToGuest( _pathToUinUnitTest + @"\ReSharperUITests.zip", @"C:\_work"); // Unzip nUnit test on Guest PC operatingSystem.WindowsShellInstance.DetachElevatedCommandInGuestNoRemoteOutput( @"7z.exe x -aoa -oc:\_work\Output c:\_work\ReSharperUITests.zip", TimeSpan.FromSeconds(1)); // Execute nUnit test on Guest PC operatingSystem.WindowsShellInstance.DetachElevatedCommandInGuestNoRemoteOutput( @"nunit3-console --work=c:\_work\Output c:\_work\Output\ReSharperUITest.dll", TimeSpan.FromSeconds(1)); // Verify that nunit execution test result (TestResult.xml) exist in "c:\_work\Output" Assert.True(operatingSystem.FileExistsInGuest(@"c:\_work\Output\TestResult.xml")); // Remove previously copied test result if (File.Exists(_pathToUinUnitTest + @"\TestResult.xml")) { File.Delete(_pathToUinUnitTest + @"\TestResult.xml"); } // Copy Test Result from Guest to Host operatingSystem.CopyFileFromGuestToHost( @"c:\_work\Output\TestResult.xml", _pathToUinUnitTest); // TestContext.AddTestAttachment(_pathToUinUnitTest + @"\TestResult.xml", "NUnit Test Result on remote host"); } }
/// <summary> /// New instance of a guest operating system wrapper. /// </summary> /// <param name="env">Remote environment.</param> public WindowsShell(RemoteEnvironment env, string psExecPath) { Env = env; PsExecWrapperInstance = new PsExecWrapper(env); // Warmup run of cmd using psexec. Required mainly for the case of machines with some network problem on startup OsTestLogger.WriteLine("Start sample initial program with big timeout to ensure all remaining will be also fine with short timeout."); RetryUtility.RetryAction( () => DetachElevatedCommandInGuestNoRemoteOutput("cmd.exe /c echo \"cmd was run ok.\"", TimeSpan.FromSeconds(180)), 50, 2000); }