1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
5
using System.Diagnostics;
9
using ICSharpCode.Core;
10
using ICSharpCode.PythonBinding;
11
using ICSharpCode.Scripting.Tests.Utils;
12
using ICSharpCode.SharpDevelop.Dom;
13
using ICSharpCode.UnitTesting;
14
using NUnit.Framework;
15
using PythonBinding.Tests.Utils;
16
using UnitTesting.Tests.Utils;
18
namespace PythonBinding.Tests.Testing
21
public class PythonTestDebuggerRunsSelectedTestMethodTestFixture
23
MockDebuggerService debuggerService;
24
UnitTesting.Tests.Utils.MockDebugger debugger;
25
MockMessageService messageService;
26
MockCSharpProject project;
27
PythonTestDebugger testDebugger;
28
MockTestResultsMonitor testResultsMonitor;
29
SelectedTests selectedTests;
30
MockMethod methodToTest;
31
PythonAddInOptions options;
32
MockScriptingFileService fileService;
33
StringBuilder responseFileText;
34
StringWriter responseFileStringWriter;
35
PythonStandardLibraryPath standardLibraryPath;
44
void CreateTestDebugger()
46
debuggerService = new MockDebuggerService();
47
debugger = debuggerService.MockDebugger;
48
messageService = new MockMessageService();
49
testResultsMonitor = new MockTestResultsMonitor();
50
options = new PythonAddInOptions(new Properties());
51
options.PythonFileName = @"c:\ironpython\ipy.exe";
52
standardLibraryPath = new PythonStandardLibraryPath(@"c:\python\lib");
53
fileService = new MockScriptingFileService();
54
testDebugger = new PythonTestDebugger(debuggerService, messageService, testResultsMonitor, options, standardLibraryPath, fileService);
57
void CreateTestMethod()
59
project = new MockCSharpProject();
60
MockClass c = new MockClass("MyNamespace.MyTestClass");
61
methodToTest = new MockMethod(c, "MyTestMethod");
64
void RunTestsOnSelectedTestMethod()
66
fileService.SetTempFileName(@"d:\temp\tmp66.tmp");
67
CreateTemporaryResponseFileWriter();
69
selectedTests = new SelectedTests(project, null, null, methodToTest);
70
testDebugger.Start(selectedTests);
73
void CreateTemporaryResponseFileWriter()
75
responseFileText = new StringBuilder();
76
responseFileStringWriter = new StringWriter(responseFileText);
77
fileService.SetTextWriter(responseFileStringWriter);
81
public void TestDebuggerProcessFileNameIsIronPythonConsoleExeTakenFromAddInOptions()
83
RunTestsOnSelectedTestMethod();
85
string expectedFileName = @"c:\ironpython\ipy.exe";
86
Assert.AreEqual(expectedFileName, debugger.ProcessStartInfo.FileName);
90
public void DisposingTestRunnerDeletesTemporaryResponseFile()
92
fileService.FileNameDeleted = null;
93
RunTestsOnSelectedTestMethod();
94
testDebugger.Dispose();
96
string expectedFileName = @"d:\temp\tmp66.tmp";
97
Assert.AreEqual(expectedFileName, fileService.FileNameDeleted);
101
public void DisposingTestRunnerDisposesTestResultsMonitor()
103
RunTestsOnSelectedTestMethod();
104
testDebugger.Dispose();
105
Assert.IsTrue(testResultsMonitor.IsDisposeMethodCalled);
109
public void CommandLineArgumentHasSharpDevelopTestPythonScriptAndResponseFileName()
111
AddInPathHelper helper = new AddInPathHelper("PythonBinding");
112
AddIn addin = helper.CreateDummyAddInInsideAddInTree();
113
addin.FileName = @"c:\sharpdevelop\addins\pythonbinding\pythonbinding.addin";
115
RunTestsOnSelectedTestMethod();
117
string expectedCommandLine =
119
"\"c:\\sharpdevelop\\addins\\pythonbinding\\TestRunner\\sdtest.py\" " +
120
"\"@d:\\temp\\tmp66.tmp\"";
122
Assert.AreEqual(expectedCommandLine, debugger.ProcessStartInfo.Arguments);
126
public void PythonTestResultReturnedFromTestFinishedEvent()
128
TestResult testResult = null;
129
testDebugger.TestFinished += delegate(object source, TestFinishedEventArgs e) {
130
testResult = e.Result;
132
TestResult testResultToFire = new TestResult("test");
133
testResultsMonitor.FireTestFinishedEvent(testResultToFire);
135
Assert.IsInstanceOf(typeof(PythonTestResult), testResult);
139
public void ResponseFileTextContainsPythonLibraryPathFromPythonStandardLibraryPathObjectIfNotDefinedInAddInOptions()
141
standardLibraryPath.Path = @"c:\python\lib;c:\python\lib\lib-tk";
142
options.PythonLibraryPath = String.Empty;
143
testResultsMonitor.FileName = @"c:\temp\test-results.txt";
144
RunTestsOnSelectedTestMethod();
146
string expectedText =
147
"/p:\"c:\\python\\lib\"\r\n" +
148
"/p:\"c:\\python\\lib\\lib-tk\"\r\n" +
149
"/r:\"c:\\temp\\test-results.txt\"\r\n" +
150
"MyNamespace.MyTestClass.MyTestMethod\r\n";
152
Assert.AreEqual(expectedText, responseFileText.ToString());