コード例 #1
0
		public void Error()
		{
			string path = "xyz";
			string parameters = "pdq";
			var sut = new ProcessRunner();
			using (StringWriter standardOutputWriter = new StringWriter())
			using (StringWriter errorOutputWriter = new StringWriter())
			{
				sut.Run(path, parameters, standardOutputWriter, errorOutputWriter);

				string standardOutput = standardOutputWriter.GetStringBuilder().ToString();
				Assert.IsNullOrEmpty(standardOutput);

				string errorOutput = errorOutputWriter.GetStringBuilder().ToString();
				Assert.IsNotNullOrEmpty(errorOutput);
			}
		}
コード例 #2
0
		public void Success()
		{
			string path = "C:\\windows\\system32\\tasklist.exe";
			string parameters = "/v";
			var sut = new ProcessRunner();
			using(StringWriter standardOutputWriter = new StringWriter())
			using(StringWriter errorOutputWriter = new StringWriter())
			{
				sut.Run(path, parameters, standardOutputWriter, errorOutputWriter);

				string standardOutput = standardOutputWriter.GetStringBuilder().ToString();
				Assert.IsNotNullOrEmpty(standardOutput);

				string errorOutput = errorOutputWriter.GetStringBuilder().ToString();
				Assert.IsNullOrEmpty(errorOutput.Trim());
			}
		}
コード例 #3
0
 public static ISqlConnectionInfo GetSqlConnectionInfo()
 {
     lock(_locker)
     {
         if(!_isLoaded)
         {
             string directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
             string roundhousePath = Path.Combine(directory, "rh.exe");
             var connectionString = ConfigurationManager.ConnectionStrings["SrirachaSql"];
             if(connectionString == null || string.IsNullOrEmpty(connectionString.ConnectionString))
             {
                 throw new Exception("Missing connection string SrirachaSql");
             }
             string scriptRelativePath = AppSettingsHelper.GetRequiredSetting("ScriptRelativePath");
             string scriptDirectory;
             if(NCrunch.Framework.NCrunchEnvironment.NCrunchIsResident())
             {
                 scriptDirectory = Path.Combine(Path.GetDirectoryName(NCrunch.Framework.NCrunchEnvironment.GetOriginalProjectPath()), scriptRelativePath);
             }
             else 
             {
                 scriptDirectory = Path.GetFullPath(scriptRelativePath);
                 if (!Directory.Exists(scriptDirectory))
                 {
                     scriptDirectory = Path.GetFullPath(Path.Combine("..", scriptRelativePath));
                 }
                 if (!Directory.Exists(scriptDirectory))
                 {
                     scriptDirectory = Path.GetFullPath(Path.Combine("..", "..", scriptRelativePath));
                 }
             }
             if(!Directory.Exists(scriptDirectory))
             {
                 throw new Exception("Script directory not found: " + scriptDirectory);
             }
             string parameters = string.Format("--connstring \"{0}\" --files=\"{1}\" --silent", connectionString.ConnectionString, scriptDirectory);
             var processRunner = new ProcessRunner();
             var outputWriter = new StringWriter();
             var errorWriter = new StringWriter();
             int exitCode = processRunner.Run(roundhousePath, parameters, outputWriter, errorWriter);
             _isLoaded = true;
         }
         return new SqlConnectionInfo();
     }
 }