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.PythonBinding;
13
using ICSharpCode.Scripting.Tests.Utils;
14
using NUnit.Framework;
15
using PythonBinding.Tests.Utils;
17
namespace PythonBinding.Tests.Designer
20
/// Adding a MenuStrip control to a form in the designer generates code for a
21
/// miniToolStrip - System.Windows.Forms.Design.ToolStripTemplateNode+TransparentToolStrip()
22
/// This is a design time control and should be ignored.
25
public class GenerateMenuStripFormTestFixture
27
string generatedPythonCode;
30
public void SetUpFixture()
32
using (DesignSurface designSurface = new DesignSurface(typeof(Form))) {
33
IDesignerHost host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
34
IEventBindingService eventBindingService = new MockEventBindingService(host);
35
Form form = (Form)host.RootComponent;
36
form.ClientSize = new Size(200, 300);
38
PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(form);
39
PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false);
40
namePropertyDescriptor.SetValue(form, "MainForm");
43
MenuStrip menuStrip = (MenuStrip)host.CreateComponent(typeof(MenuStrip), "menuStrip1");
44
menuStrip.Text = "menuStrip1";
45
menuStrip.TabIndex = 0;
46
menuStrip.Location = new Point(0, 0);
47
form.Controls.Add(menuStrip);
49
DesignerSerializationManager serializationManager = new DesignerSerializationManager(host);
50
using (serializationManager.CreateSession()) {
51
PythonCodeDomSerializer serializer = new PythonCodeDomSerializer(" ");
52
generatedPythonCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager, String.Empty, 1);
58
public void GeneratedCode()
60
string expectedCode = " self._menuStrip1 = System.Windows.Forms.MenuStrip()\r\n" +
61
" self.SuspendLayout()\r\n" +
65
" self._menuStrip1.Location = System.Drawing.Point(0, 0)\r\n" +
66
" self._menuStrip1.Name = \"menuStrip1\"\r\n" +
67
" self._menuStrip1.Size = System.Drawing.Size(200, 24)\r\n" +
68
" self._menuStrip1.TabIndex = 0\r\n" +
69
" self._menuStrip1.Text = \"menuStrip1\"\r\n" +
73
" self.ClientSize = System.Drawing.Size(200, 300)\r\n" +
74
" self.Controls.Add(self._menuStrip1)\r\n" +
75
" self.Name = \"MainForm\"\r\n" +
76
" self.ResumeLayout(False)\r\n" +
77
" self.PerformLayout()\r\n";
79
Assert.AreEqual(expectedCode, generatedPythonCode);