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.ComponentModel;
6
using System.ComponentModel.Design;
7
using System.ComponentModel.Design.Serialization;
9
using System.Windows.Forms;
10
using ICSharpCode.PythonBinding;
11
using NUnit.Framework;
12
using PythonBinding.Tests.Utils;
14
namespace PythonBinding.Tests.Designer
17
public class GenerateTextBoxFormTestFixture
19
string generatedPythonCode;
22
public void SetUpFixture()
24
using (DesignSurface designSurface = new DesignSurface(typeof(Form))) {
25
IDesignerHost host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
26
Form form = (Form)host.RootComponent;
27
form.ClientSize = new Size(284, 264);
29
PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(form);
30
PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false);
31
namePropertyDescriptor.SetValue(form, "MainForm");
33
TextBox textBox = (TextBox)host.CreateComponent(typeof(TextBox), "textBox1");
34
textBox.Size = new Size(110, 20);
36
textBox.Location = new Point(10, 10);
38
form.Controls.Add(textBox);
40
DesignerSerializationManager serializationManager = new DesignerSerializationManager(host);
41
using (serializationManager.CreateSession()) {
42
PythonCodeDomSerializer serializer = new PythonCodeDomSerializer(" ");
43
generatedPythonCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager, String.Empty, 1);
49
public void GeneratedCode()
51
string expectedCode = " self._textBox1 = System.Windows.Forms.TextBox()\r\n" +
52
" self.SuspendLayout()\r\n" +
56
" self._textBox1.Location = System.Drawing.Point(10, 10)\r\n" +
57
" self._textBox1.Name = \"textBox1\"\r\n" +
58
" self._textBox1.Size = System.Drawing.Size(110, 20)\r\n" +
59
" self._textBox1.TabIndex = 1\r\n" +
63
" self.ClientSize = System.Drawing.Size(284, 264)\r\n" +
64
" self.Controls.Add(self._textBox1)\r\n" +
65
" self.Name = \"MainForm\"\r\n" +
66
" self.ResumeLayout(False)\r\n" +
67
" self.PerformLayout()\r\n";
69
Assert.AreEqual(expectedCode, generatedPythonCode);