~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Designer/GenerateFormLocationTestFixture.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
 
 
11
using ICSharpCode.RubyBinding;
 
12
using ICSharpCode.Scripting.Tests.Utils;
 
13
using NUnit.Framework;
 
14
using RubyBinding.Tests.Utils;
 
15
 
 
16
namespace RubyBinding.Tests.Designer
 
17
{
 
18
        [TestFixture]
 
19
        public class GenerateFormLocationTestFixture
 
20
        {
 
21
                string generatedRubyCode;
 
22
                
 
23
                [TestFixtureSetUp]
 
24
                public void SetUpFixture()
 
25
                {
 
26
                        using (DesignSurface designSurface = new DesignSurface(typeof(Form))) {
 
27
                                IDesignerHost host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
 
28
                                IEventBindingService eventBindingService = new MockEventBindingService(host);
 
29
                                Form form = (Form)host.RootComponent;
 
30
                                form.ClientSize = new Size(284, 264);
 
31
 
 
32
                                PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(form);
 
33
                                PropertyDescriptor descriptor = descriptors.Find("Location", false);
 
34
                                descriptor.SetValue(form, new Point(10, 20));
 
35
 
 
36
                                PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false);
 
37
                                namePropertyDescriptor.SetValue(form, "MainForm");
 
38
                                
 
39
                                DesignerSerializationManager serializationManager = new DesignerSerializationManager(host);
 
40
                                using (serializationManager.CreateSession()) {                                  
 
41
                                        RubyCodeDomSerializer serializer = new RubyCodeDomSerializer("    ");
 
42
                                        generatedRubyCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager, 1);
 
43
                                }
 
44
                        }
 
45
                }
 
46
                
 
47
                [Test]
 
48
                public void GeneratedCode()
 
49
                {
 
50
                        string expectedCode = "    self.SuspendLayout()\r\n" +
 
51
                                                                "    # \r\n" +
 
52
                                                                "    # MainForm\r\n" +
 
53
                                                                "    # \r\n" +
 
54
                                                                "    self.ClientSize = System::Drawing::Size.new(284, 264)\r\n" +
 
55
                                                                "    self.Location = System::Drawing::Point.new(10, 20)\r\n" +
 
56
                                                                "    self.Name = \"MainForm\"\r\n" +
 
57
                                                                "    self.ResumeLayout(false)\r\n";
 
58
                        
 
59
                        Assert.AreEqual(expectedCode, generatedRubyCode);
 
60
                }
 
61
        }
 
62
}