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 ICSharpCode.NRefactory;
6
using ICSharpCode.PythonBinding;
9
namespace PythonBinding.Tests.Converter
12
/// Tests that assigning a method to an event handler is converted
13
/// from C# to Python correctly.
16
public class AddHandlerConversionTestFixture
18
string csharp = "class Foo\r\n" +
20
"\tpublic Foo()\r\n" +
22
"\t\tbutton = new Button();\r\n" +
23
"\t\tbutton.Click += ButtonClick;\r\n" +
24
"\t\tbutton.MouseDown += self.OnMouseDown;\r\n" +
27
"\tvoid ButtonClick(object sender, EventArgs e)\r\n" +
31
"\tvoid OnMouseDown(object sender, EventArgs e)\r\n" +
37
public void ConvertedPythonCode()
39
string expectedCode = "class Foo(object):\r\n" +
40
"\tdef __init__(self):\r\n" +
41
"\t\tbutton = Button()\r\n" +
42
"\t\tbutton.Click += self.ButtonClick\r\n" +
43
"\t\tbutton.MouseDown += self.OnMouseDown\r\n" +
45
"\tdef ButtonClick(self, sender, e):\r\n" +
48
"\tdef OnMouseDown(self, sender, e):\r\n" +
50
NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(SupportedLanguage.CSharp);
51
string code = converter.Convert(csharp);
53
Assert.AreEqual(expectedCode, code);