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.Collections.Generic;
6
using System.ComponentModel;
7
using System.ComponentModel.Design;
8
using System.ComponentModel.Design.Serialization;
10
using System.Windows.Forms;
12
using ICSharpCode.RubyBinding;
13
using ICSharpCode.Scripting.Tests.Utils;
14
using NUnit.Framework;
15
using RubyBinding.Tests.Utils;
17
namespace RubyBinding.Tests.Designer
20
public class GenerateTableLayoutPanelTestFixture
22
string generatedRubyCode;
25
public void SetUpFixture()
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);
33
PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(form);
34
PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false);
35
namePropertyDescriptor.SetValue(form, "MainForm");
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;
49
form.Controls.Add(tableLayoutPanel1);
51
DesignerSerializationManager serializationManager = new DesignerSerializationManager(host);
52
using (serializationManager.CreateSession()) {
53
RubyCodeDomSerializer serializer = new RubyCodeDomSerializer(" ");
54
generatedRubyCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager, String.Empty, 1);
60
public void GeneratedCode()
62
string expectedCode = " @tableLayoutPanel1 = System::Windows::Forms::TableLayoutPanel.new()\r\n" +
63
" self.SuspendLayout()\r\n" +
65
" # tableLayoutPanel1\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" +
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";
85
Assert.AreEqual(expectedCode, generatedRubyCode, generatedRubyCode);