Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@4016 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
7 changed files with 266 additions and 57 deletions
@ -0,0 +1,85 @@
@@ -0,0 +1,85 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using ICSharpCode.PythonBinding; |
||||
using ICSharpCode.FormsDesigner; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using NUnit.Framework; |
||||
using PythonBinding.Tests.Utils; |
||||
|
||||
namespace PythonBinding.Tests.Designer |
||||
{ |
||||
/// <summary>
|
||||
/// Tests the PythonDesignerGenerator does not insert an event handler if a method already exists with the same
|
||||
/// name.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class EventHandlerAlreadyExistsTestFixture : InsertEventHandlerTestFixtureBase |
||||
{ |
||||
public override void AfterSetUpFixture() |
||||
{ |
||||
MockEventDescriptor mockEventDescriptor = new MockEventDescriptor("Click"); |
||||
generator.InsertComponentEvent(null, mockEventDescriptor, "mybuttonclick", String.Empty, out file, out position); |
||||
insertedEventHandler = generator.InsertComponentEvent(null, mockEventDescriptor, "mybuttonclick", String.Empty, out file, out position); |
||||
} |
||||
|
||||
[Test] |
||||
public void CodeAfterInsertComponentEventMethodCalledIsNotChanged() |
||||
{ |
||||
string expectedCode = GetTextEditorCode(); |
||||
Assert.AreEqual(expectedCode, viewContent.DesignerCodeFileContent); |
||||
} |
||||
|
||||
[Test] |
||||
public void InsertComponentEventMethodReturnsTrue() |
||||
{ |
||||
Assert.IsTrue(insertedEventHandler); |
||||
} |
||||
|
||||
[Test] |
||||
public void FileIsForm() |
||||
{ |
||||
Assert.AreEqual(fileName, file); |
||||
} |
||||
|
||||
[Test] |
||||
public void PositionOfEventHandlerIsLine12() |
||||
{ |
||||
Assert.AreEqual(12, position); |
||||
} |
||||
|
||||
[Test] |
||||
public void TextPassedToParseFileMethod() |
||||
{ |
||||
Assert.AreEqual(GetTextEditorCode(), generator.TextContentPassedToParseFileMethod); |
||||
} |
||||
|
||||
[Test] |
||||
public void FileNamePassedToParseFileMethod() |
||||
{ |
||||
Assert.AreEqual(fileName, generator.FileNamePassedToParseFileMethod); |
||||
} |
||||
|
||||
protected override string GetTextEditorCode() |
||||
{ |
||||
return "from System.Windows.Forms import Form\r\n" + |
||||
"\r\n" + |
||||
"class MainForm(Form):\r\n" + |
||||
"\tdef __init__(self):\r\n" + |
||||
"\t\tself.InitializeComponents()\r\n" + |
||||
"\t\r\n" + |
||||
"\tdef InitializeComponents(self):\r\n" + |
||||
"\t\tself._button1 = System.Windows.Forms.Button()\r\n" + |
||||
"\t\tself._button1.Click += mybuttonclick\r\n" + |
||||
"\t\tself.Controls.Add(self._button1)\r\n" + |
||||
"\t\r\n" + |
||||
"\tdef mybuttonclick(self, sender, e)\r\n" + |
||||
"\t\tpass\r\n"; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,57 @@
@@ -0,0 +1,57 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using ICSharpCode.PythonBinding; |
||||
using ICSharpCode.FormsDesigner; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using NUnit.Framework; |
||||
using PythonBinding.Tests.Utils; |
||||
|
||||
namespace PythonBinding.Tests.Designer |
||||
{ |
||||
/// <summary>
|
||||
/// An event handler should be inserted if a method exists in the form's class but has the incorrect
|
||||
/// number of parameters.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class EventHandlerExistsWithIncorrectParameterCountTestFixture : InsertEventHandlerTestFixtureBase |
||||
{ |
||||
public override void AfterSetUpFixture() |
||||
{ |
||||
MockEventDescriptor mockEventDescriptor = new MockEventDescriptor("Click"); |
||||
insertedEventHandler = generator.InsertComponentEvent(null, mockEventDescriptor, "mybuttonclick", String.Empty, out file, out position); |
||||
} |
||||
|
||||
[Test] |
||||
public void ExpectedCodeAfterEventHandlerInserted() |
||||
{ |
||||
string expectedCode = GetTextEditorCode(); |
||||
string eventHandler = "\tdef mybuttonclick(self, sender, e):\r\n" + |
||||
"\t\tpass"; |
||||
expectedCode = expectedCode + "\r\n" + eventHandler; |
||||
|
||||
Assert.AreEqual(expectedCode, viewContent.DesignerCodeFileContent); |
||||
} |
||||
|
||||
protected override string GetTextEditorCode() |
||||
{ |
||||
return "from System.Windows.Forms import Form\r\n" + |
||||
"\r\n" + |
||||
"class MainForm(Form):\r\n" + |
||||
"\tdef __init__(self):\r\n" + |
||||
"\t\tself.InitializeComponents()\r\n" + |
||||
"\t\r\n" + |
||||
"\tdef InitializeComponents(self):\r\n" + |
||||
"\t\tself._button1 = System.Windows.Forms.Button()\r\n" + |
||||
"\t\tself._button1.Click += mybuttonclick\r\n" + |
||||
"\t\r\n" + |
||||
"\tdef mybuttonclick(self)\r\n" + |
||||
"\t\tpass\r\n"; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,63 @@
@@ -0,0 +1,63 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using ICSharpCode.PythonBinding; |
||||
using ICSharpCode.FormsDesigner; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using NUnit.Framework; |
||||
using PythonBinding.Tests.Utils; |
||||
|
||||
namespace PythonBinding.Tests.Designer |
||||
{ |
||||
/// <summary>
|
||||
/// Base class that tests the PythonDesignerGenerator.InsertEventComponent method.
|
||||
/// </summary>
|
||||
public class InsertEventHandlerTestFixtureBase |
||||
{ |
||||
protected string file; |
||||
protected int position; |
||||
protected bool insertedEventHandler; |
||||
protected MockTextEditorViewContent mockViewContent; |
||||
protected DerivedFormDesignerViewContent viewContent; |
||||
protected string fileName = @"C:\Projects\Python\mainform.py"; |
||||
protected DerivedPythonDesignerGenerator generator; |
||||
|
||||
[TestFixtureSetUp] |
||||
public void SetUpFixture() |
||||
{ |
||||
generator = new DerivedPythonDesignerGenerator(); |
||||
mockViewContent = new MockTextEditorViewContent(); |
||||
viewContent = new DerivedFormDesignerViewContent(mockViewContent, new MockOpenedFile(fileName)); |
||||
generator.Attach(viewContent); |
||||
viewContent.DesignerCodeFileContent = GetTextEditorCode(); |
||||
|
||||
ParseInformation parseInfo = new ParseInformation(); |
||||
PythonParser parser = new PythonParser(); |
||||
ICompilationUnit parserCompilationUnit = parser.Parse(new DefaultProjectContent(), fileName, GetTextEditorCode()); |
||||
parseInfo.SetCompilationUnit(parserCompilationUnit); |
||||
generator.ParseInfoToReturnFromParseFileMethod = parseInfo; |
||||
|
||||
AfterSetUpFixture(); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Called at the end of the SetUpFixture method.
|
||||
/// </summary>
|
||||
public virtual void AfterSetUpFixture() |
||||
{ |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the form's code.
|
||||
/// </summary>
|
||||
protected virtual string GetTextEditorCode() |
||||
{ |
||||
return String.Empty; |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue