Browse Source

Create directory for MS Test results file if it does not exist.

Handle MS Test results file not being created.
pull/18/merge
Matt Ward 13 years ago
parent
commit
1dad071f48
  1. 20
      samples/MSTest/MSTest.SharpDevelop/MSTestDebugger.cs
  2. 24
      samples/MSTest/MSTest.SharpDevelop/MSTestRunner.cs

20
samples/MSTest/MSTest.SharpDevelop/MSTestDebugger.cs

@ -49,6 +49,7 @@ namespace ICSharpCode.MSTest @@ -49,6 +49,7 @@ namespace ICSharpCode.MSTest
protected override ProcessStartInfo GetProcessStartInfo(SelectedTests selectedTests)
{
resultsFileName = new MSTestResultsFileName(selectedTests).FileName;
CreateDirectoryForResultsFile();
var mstestApplication = new MSTestApplication(selectedTests, resultsFileName);
return mstestApplication.ProcessStartInfo;
}
@ -64,6 +65,14 @@ namespace ICSharpCode.MSTest @@ -64,6 +65,14 @@ namespace ICSharpCode.MSTest
return messageService.AskQuestion(question, caption);
}
void CreateDirectoryForResultsFile()
{
string path = Path.GetDirectoryName(resultsFileName);
if (!Directory.Exists(path)) {
Directory.CreateDirectory(path);
}
}
void Start(ProcessStartInfo startInfo)
{
StartDebugger(startInfo);
@ -89,9 +98,14 @@ namespace ICSharpCode.MSTest @@ -89,9 +98,14 @@ namespace ICSharpCode.MSTest
{
debugger.DebugStopped -= DebugStopped;
var testResults = new MSTestResults(resultsFileName);
var workbench = new UnitTestWorkbench();
workbench.SafeThreadAsyncCall(() => UpdateTestResults(testResults));
if (File.Exists(resultsFileName)) {
var testResults = new MSTestResults(resultsFileName);
var workbench = new UnitTestWorkbench();
workbench.SafeThreadAsyncCall(() => UpdateTestResults(testResults));
} else {
messageService.ShowFormattedErrorMessage("Unable to find test results file: '{0}'.", resultsFileName);
OnAllTestsFinished(source, e);
}
}
void UpdateTestResults(MSTestResults testResults)

24
samples/MSTest/MSTest.SharpDevelop/MSTestRunner.cs

@ -42,9 +42,14 @@ namespace ICSharpCode.MSTest @@ -42,9 +42,14 @@ namespace ICSharpCode.MSTest
void ProcessRunnerExited(object source, EventArgs e)
{
// Read all tests.
var testResults = new MSTestResults(resultsFileName);
var workbench = new UnitTestWorkbench();
workbench.SafeThreadAsyncCall(() => UpdateTestResults(testResults));
if (FileExists(resultsFileName)) {
var testResults = new MSTestResults(resultsFileName);
var workbench = new UnitTestWorkbench();
workbench.SafeThreadAsyncCall(() => UpdateTestResults(testResults));
} else {
messageService.ShowFormattedErrorMessage("Unable to find test results file: '{0}'.", resultsFileName);
OnAllTestsFinished(source, e);
}
}
void UpdateTestResults(MSTestResults testResults)
@ -70,6 +75,7 @@ namespace ICSharpCode.MSTest @@ -70,6 +75,7 @@ namespace ICSharpCode.MSTest
protected override ProcessStartInfo GetProcessStartInfo(SelectedTests selectedTests)
{
resultsFileName = new MSTestResultsFileName(selectedTests).FileName;
CreateDirectoryForResultsFile();
var mstestApplication = new MSTestApplication(selectedTests, resultsFileName);
return mstestApplication.ProcessStartInfo;
}
@ -78,7 +84,7 @@ namespace ICSharpCode.MSTest @@ -78,7 +84,7 @@ namespace ICSharpCode.MSTest
{
LogCommandLine(processStartInfo);
if (ApplicationFileNameExists(processStartInfo.FileName)) {
if (FileExists(processStartInfo.FileName)) {
processRunner.WorkingDirectory = processStartInfo.WorkingDirectory;
processRunner.Start(processStartInfo.FileName, processStartInfo.Arguments);
} else {
@ -86,7 +92,15 @@ namespace ICSharpCode.MSTest @@ -86,7 +92,15 @@ namespace ICSharpCode.MSTest
}
}
bool ApplicationFileNameExists(string fileName)
void CreateDirectoryForResultsFile()
{
string path = Path.GetDirectoryName(resultsFileName);
if (!Directory.Exists(path)) {
Directory.CreateDirectory(path);
}
}
bool FileExists(string fileName)
{
return fileSystem.FileExists(fileName);
}

Loading…
Cancel
Save