~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateTextBoxFormTestFixture.cs

  • Committer: sk
  • Date: 2011-09-10 05:17:57 UTC
  • Revision ID: halega@halega.com-20110910051757-qfouz1llya9m6boy
4.1.0.7915 Release Candidate 1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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)
 
3
 
 
4
using System;
 
5
using System.ComponentModel;
 
6
using System.ComponentModel.Design;
 
7
using System.ComponentModel.Design.Serialization;
 
8
using System.Drawing;
 
9
using System.Windows.Forms;
 
10
using ICSharpCode.PythonBinding;
 
11
using NUnit.Framework;
 
12
using PythonBinding.Tests.Utils;
 
13
 
 
14
namespace PythonBinding.Tests.Designer
 
15
{
 
16
        [TestFixture]
 
17
        public class GenerateTextBoxFormTestFixture
 
18
        {
 
19
                string generatedPythonCode;
 
20
                
 
21
                [TestFixtureSetUp]
 
22
                public void SetUpFixture()
 
23
                {
 
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);
 
28
                                
 
29
                                PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(form);
 
30
                                PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false);
 
31
                                namePropertyDescriptor.SetValue(form, "MainForm");
 
32
                                
 
33
                                TextBox textBox = (TextBox)host.CreateComponent(typeof(TextBox), "textBox1");
 
34
                                textBox.Size = new Size(110, 20);
 
35
                                textBox.TabIndex = 1;
 
36
                                textBox.Location = new Point(10, 10);
 
37
                                
 
38
                                form.Controls.Add(textBox);
 
39
                                
 
40
                                DesignerSerializationManager serializationManager = new DesignerSerializationManager(host);
 
41
                                using (serializationManager.CreateSession()) {                                  
 
42
                                        PythonCodeDomSerializer serializer = new PythonCodeDomSerializer("    ");
 
43
                                        generatedPythonCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager, String.Empty, 1);
 
44
                                }
 
45
                        }
 
46
                }
 
47
                
 
48
                [Test]
 
49
                public void GeneratedCode()
 
50
                {
 
51
                        string expectedCode = "    self._textBox1 = System.Windows.Forms.TextBox()\r\n" +
 
52
                                                                "    self.SuspendLayout()\r\n" +
 
53
                                                                "    # \r\n" +
 
54
                                                                "    # textBox1\r\n" +
 
55
                                                                "    # \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" +
 
60
                                                                "    # \r\n" +
 
61
                                                                "    # MainForm\r\n" +
 
62
                                                                "    # \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";
 
68
                        
 
69
                        Assert.AreEqual(expectedCode, generatedPythonCode);
 
70
                }               
 
71
        }
 
72
}