~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Designer/GenerateTableLayoutPanelTestFixture.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.Collections.Generic;
 
6
using System.ComponentModel;
 
7
using System.ComponentModel.Design;
 
8
using System.ComponentModel.Design.Serialization;
 
9
using System.Drawing;
 
10
using System.Windows.Forms;
 
11
 
 
12
using ICSharpCode.RubyBinding;
 
13
using ICSharpCode.Scripting.Tests.Utils;
 
14
using NUnit.Framework;
 
15
using RubyBinding.Tests.Utils;
 
16
 
 
17
namespace RubyBinding.Tests.Designer
 
18
{
 
19
        [TestFixture]
 
20
        public class GenerateTableLayoutPanelTestFixture
 
21
        {
 
22
                string generatedRubyCode;
 
23
                
 
24
                [TestFixtureSetUp]
 
25
                public void SetUpFixture()
 
26
                {
 
27
                        using (DesignSurface designSurface = new DesignSurface(typeof(Form))) {
 
28
                                IDesignerHost host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
 
29
                                IEventBindingService eventBindingService = new MockEventBindingService(host);
 
30
                                Form form = (Form)host.RootComponent;
 
31
                                form.ClientSize = new Size(200, 300);
 
32
 
 
33
                                PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(form);
 
34
                                PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false);
 
35
                                namePropertyDescriptor.SetValue(form, "MainForm");
 
36
                                
 
37
                                // Add table layout panel.
 
38
                                TableLayoutPanel tableLayoutPanel1 = (TableLayoutPanel)host.CreateComponent(typeof(TableLayoutPanel), "tableLayoutPanel1");
 
39
                                tableLayoutPanel1.ColumnCount = 2;
 
40
                                tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 40F));
 
41
                                tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 60F));
 
42
                                tableLayoutPanel1.Location = new Point(0, 0);
 
43
                                tableLayoutPanel1.RowCount = 2;
 
44
                                tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Absolute, 20F));
 
45
                                tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Absolute, 25F));
 
46
                                tableLayoutPanel1.Size = new Size(200, 100);
 
47
                                tableLayoutPanel1.TabIndex = 0;
 
48
                                                                
 
49
                                form.Controls.Add(tableLayoutPanel1);
 
50
                                
 
51
                                DesignerSerializationManager serializationManager = new DesignerSerializationManager(host);
 
52
                                using (serializationManager.CreateSession()) {                                  
 
53
                                        RubyCodeDomSerializer serializer = new RubyCodeDomSerializer("    ");
 
54
                                        generatedRubyCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager, String.Empty, 1);
 
55
                                }
 
56
                        }
 
57
                }
 
58
                
 
59
                [Test]
 
60
                public void GeneratedCode()
 
61
                {
 
62
                        string expectedCode = "    @tableLayoutPanel1 = System::Windows::Forms::TableLayoutPanel.new()\r\n" +
 
63
                                                                "    self.SuspendLayout()\r\n" +
 
64
                                                                "    # \r\n" +
 
65
                                                                "    # tableLayoutPanel1\r\n" +
 
66
                                                                "    # \r\n" +
 
67
                                                                "    @tableLayoutPanel1.ColumnCount = 2\r\n" +
 
68
                                                                "    @tableLayoutPanel1.ColumnStyles.Add(System::Windows::Forms::ColumnStyle.new(System::Windows::Forms::SizeType.Percent, 40))\r\n" +
 
69
                                                                "    @tableLayoutPanel1.ColumnStyles.Add(System::Windows::Forms::ColumnStyle.new(System::Windows::Forms::SizeType.Percent, 60))\r\n" +
 
70
                                                                "    @tableLayoutPanel1.Location = System::Drawing::Point.new(0, 0)\r\n" +
 
71
                                                                "    @tableLayoutPanel1.Name = \"tableLayoutPanel1\"\r\n" +
 
72
                                                                "    @tableLayoutPanel1.RowCount = 2\r\n" +
 
73
                                                                "    @tableLayoutPanel1.RowStyles.Add(System::Windows::Forms::RowStyle.new(System::Windows::Forms::SizeType.Absolute, 20))\r\n" +
 
74
                                                                "    @tableLayoutPanel1.RowStyles.Add(System::Windows::Forms::RowStyle.new(System::Windows::Forms::SizeType.Absolute, 25))\r\n" +
 
75
                                                                "    @tableLayoutPanel1.Size = System::Drawing::Size.new(200, 100)\r\n" +
 
76
                                                                "    @tableLayoutPanel1.TabIndex = 0\r\n" +
 
77
                                                                "    # \r\n" +
 
78
                                                                "    # MainForm\r\n" +
 
79
                                                                "    # \r\n" +
 
80
                                                                "    self.ClientSize = System::Drawing::Size.new(200, 300)\r\n" +
 
81
                                                                "    self.Controls.Add(@tableLayoutPanel1)\r\n" +
 
82
                                                                "    self.Name = \"MainForm\"\r\n" +
 
83
                                                                "    self.ResumeLayout(false)\r\n";
 
84
                        
 
85
                        Assert.AreEqual(expectedCode, generatedRubyCode, generatedRubyCode);
 
86
                }               
 
87
        }
 
88
}