public void AddProgramToFirewallFact() { // Arrange var mockProcessRunner = new Mock<IProcessRunner>(MockBehavior.Strict); mockProcessRunner.Setup(m => m.Start(It.Is<Process>( p => p.StartInfo.FileName == "netsh.exe" && p.StartInfo.Arguments == @"firewall add allowedprogram ""mytool.exe"" TestEasyTool enable"))) .Returns(true); mockProcessRunner.Setup(m => m.WaitForExit(It.Is<Process>( p => p.StartInfo.FileName == "netsh.exe" && p.StartInfo.Arguments == @"firewall add allowedprogram ""mytool.exe"" TestEasyTool enable"), 60000)) .Returns(true); // Act // Assert var helper = new FirewallHelper(mockProcessRunner.Object); helper.AddProgramToFirewall("mytool.exe", "TestEasyTool"); }
public void AddPortToFirewallFact() { // Arrange var mockProcessRunner = new Mock<IProcessRunner>(MockBehavior.Strict); mockProcessRunner.Setup(m => m.Start(It.Is<Process>( p => p.StartInfo.FileName == "netsh.exe" && p.StartInfo.Arguments == @"firewall add portopening tcp 444 TestEasyTool"))) .Returns(true); mockProcessRunner.Setup(m => m.WaitForExit(It.Is<Process>( p => p.StartInfo.FileName == "netsh.exe" && p.StartInfo.Arguments == @"firewall add portopening tcp 444 TestEasyTool"), 60000)) .Returns(true); // Act // Assert var helper = new FirewallHelper(mockProcessRunner.Object); helper.AddPortToFirewall(444, "TestEasyTool"); }
/// <summary> /// Try to download tools from (if they don't exist): /// - the path in the tool element in the configuration corresponding to tool name /// - default tools path specified in tools defaultRemoteToolsPath="" /// and copies it into tools defaultLocalToolsPath="" /// </summary> public string DownloadTool( string toolName, string sourcePath = "", string targetPath = "", bool addToFirewall = false) { if (string.IsNullOrEmpty(toolName)) { throw new ArgumentNullException(toolName); } // set default values sourcePath = string.IsNullOrEmpty(sourcePath) ? TestEasyConfig.Instance.Tools.DefaultRemoteToolsPath : sourcePath; targetPath = string.IsNullOrEmpty(targetPath) ? TestEasyConfig.Instance.Tools.DefaultLocalToolsPath : targetPath; // see if tool is registered in config and get config's path var toolElement = TestEasyConfig.Instance.Tools.Tools[toolName.ToLowerInvariant()]; toolName = toolElement != null ? toolElement.Path : toolName; if (FileSystem.FileExists(toolName)) { // if tool path is provided, then use it instead of default tools path sourcePath = Path.GetDirectoryName(toolName) ?? ""; } toolName = Path.GetFileName(toolName) ?? toolName; // prepare target path var currentDirectory = FileSystem.GetExecutingAssemblyDirectory(); targetPath = string.IsNullOrEmpty(targetPath) ? currentDirectory : EnvironmentSystem.ExpandEnvironmentVariables(targetPath); if (!FileSystem.DirectoryExists(targetPath)) { FileSystem.DirectoryCreate(targetPath); } var fullPathSource = Path.Combine(sourcePath, toolName); var fullPathTarget = Path.Combine(targetPath, toolName); // if tool was not copied before - copy it if (!FileSystem.FileExists(fullPathTarget) || WasFileModified(fullPathSource, fullPathTarget)) { if (!FileSystem.FileExists(fullPathSource)) { throw new FileNotFoundException( string.Format( "Tool '{0}' was not found and can not be copied to current folder. Please make sure path '{1}' exists or use another Browser to work around.", toolName, sourcePath)); } FileSystem.FileCopy(fullPathSource, fullPathTarget, true); if (addToFirewall) { var firewallHelper = new FirewallHelper(ProcessRunner); firewallHelper.AddProgramToFirewall(fullPathTarget, "TestEasyTool"); } } return fullPathTarget; }
/// <summary> /// Try to download tools from (if they don't exist): /// - the path in the tool element in the configuration corresponding to tool name /// - default tools path specified in tools defaultRemoteToolsPath="" /// and copies it into tools defaultLocalToolsPath="" /// </summary> public string DownloadTool( string toolName, string sourcePath = "", string targetPath = "", bool addToFirewall = false) { if (string.IsNullOrEmpty(toolName)) { throw new ArgumentNullException(toolName); } // set default values sourcePath = string.IsNullOrEmpty(sourcePath) ? TestEasyConfig.Instance.Tools.DefaultRemoteToolsPath : sourcePath; targetPath = string.IsNullOrEmpty(targetPath) ? TestEasyConfig.Instance.Tools.DefaultLocalToolsPath : targetPath; // see if tool is registered in config and get config's path var toolElement = TestEasyConfig.Instance.Tools.Tools[toolName.ToLowerInvariant()]; toolName = toolElement != null ? toolElement.Path : toolName; if (FileSystem.FileExists(toolName)) { // if tool path is provided, then use it instead of default tools path sourcePath = Path.GetDirectoryName(toolName) ?? ""; } toolName = Path.GetFileName(toolName) ?? toolName; // prepare target path var currentDirectory = FileSystem.GetExecutingAssemblyDirectory(); targetPath = string.IsNullOrEmpty(targetPath) ? currentDirectory : EnvironmentSystem.ExpandEnvironmentVariables(targetPath); if (!FileSystem.DirectoryExists(targetPath)) { FileSystem.DirectoryCreate(targetPath); } var fullPathSource = Path.Combine(sourcePath, toolName); var fullPathTarget = Path.Combine(targetPath, toolName); // if tool was not copied before - copy it if (!FileSystem.FileExists(fullPathTarget) || WasFileModified(fullPathSource, fullPathTarget)) { if (!FileSystem.FileExists(fullPathSource)) { throw new FileNotFoundException( string.Format( "Tool '{0}' was not found and can not be copied to current folder. Please make sure path '{1}' exists or use another Browser to work around.", toolName, sourcePath)); } FileSystem.FileCopy(fullPathSource, fullPathTarget, true); if (addToFirewall) { var firewallHelper = new FirewallHelper(ProcessRunner); firewallHelper.AddProgramToFirewall(fullPathTarget, "TestEasyTool"); } } return(fullPathTarget); }