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.Globalization;
11
using System.Windows.Forms;
13
using ICSharpCode.PythonBinding;
14
using ICSharpCode.Scripting.Tests.Utils;
15
using NUnit.Framework;
16
using PythonBinding.Tests.Utils;
18
namespace PythonBinding.Tests.Designer
21
public class GenerateImageListResourceTestFixture
23
MockResourceWriter resourceWriter;
24
MockComponentCreator componentCreator;
25
string generatedPythonCode;
29
public void SetUpFixture()
31
resourceWriter = new MockResourceWriter();
32
componentCreator = new MockComponentCreator();
33
componentCreator.SetResourceWriter(resourceWriter);
35
using (DesignSurface designSurface = new DesignSurface(typeof(Form))) {
36
IDesignerHost host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
37
IEventBindingService eventBindingService = new MockEventBindingService(host);
38
host.AddService(typeof(IResourceService), componentCreator);
40
Form form = (Form)host.RootComponent;
41
form.ClientSize = new Size(200, 300);
43
PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(form);
44
PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false);
45
namePropertyDescriptor.SetValue(form, "MainForm");
48
icon = new Icon(typeof(GenerateFormResourceTestFixture), "App.ico");
49
ImageList imageList = (ImageList)host.CreateComponent(typeof(ImageList), "imageList1");
50
imageList.Images.Add("App.ico", icon);
51
imageList.Images.Add("", icon);
52
imageList.Images.Add("", icon);
54
DesignerSerializationManager serializationManager = new DesignerSerializationManager(host);
55
using (serializationManager.CreateSession()) {
56
PythonCodeDomSerializer serializer = new PythonCodeDomSerializer(" ");
57
generatedPythonCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager, "RootNamespace", 1);
63
public void TearDownFixture()
69
public void GeneratedCode()
71
string expectedCode = " self._components = System.ComponentModel.Container()\r\n" +
72
" resources = System.Resources.ResourceManager(\"RootNamespace.MainForm\", System.Reflection.Assembly.GetEntryAssembly())\r\n" +
73
" self._imageList1 = System.Windows.Forms.ImageList(self._components)\r\n" +
74
" self.SuspendLayout()\r\n" +
78
" self._imageList1.ImageStream = resources.GetObject(\"imageList1.ImageStream\")\r\n" +
79
" self._imageList1.TransparentColor = System.Drawing.Color.Transparent\r\n" +
80
" self._imageList1.Images.SetKeyName(0, \"App.ico\")\r\n" +
81
" self._imageList1.Images.SetKeyName(1, \"\")\r\n" +
82
" self._imageList1.Images.SetKeyName(2, \"\")\r\n" +
86
" self.ClientSize = System.Drawing.Size(200, 300)\r\n" +
87
" self.Name = \"MainForm\"\r\n" +
88
" self.ResumeLayout(False)\r\n";
90
Assert.AreEqual(expectedCode, generatedPythonCode, generatedPythonCode);
94
public void ImageStreamAddedToResourceWriter()
96
Assert.IsNotNull(resourceWriter.GetResource("imageList1.ImageStream"));