public void SetUpFixture()
        {
            resourceWriter   = new MockResourceWriter();
            componentCreator = new MockComponentCreator();
            componentCreator.SetResourceWriter(resourceWriter);

            using (DesignSurface designSurface = new DesignSurface(typeof(Form))) {
                IDesignerHost        host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
                IEventBindingService eventBindingService = new MockEventBindingService(host);
                host.AddService(typeof(IResourceService), componentCreator);

                Form form = (Form)host.RootComponent;
                form.ClientSize = new Size(200, 300);

                PropertyDescriptorCollection descriptors            = TypeDescriptor.GetProperties(form);
                PropertyDescriptor           namePropertyDescriptor = descriptors.Find("Name", false);
                namePropertyDescriptor.SetValue(form, "MainForm");

                // Set bitmap as form background image.
                bitmap = new Bitmap(10, 10);
                form.BackgroundImage = bitmap;

                icon      = new Icon(typeof(GenerateFormResourceTestFixture), "App.ico");
                form.Icon = icon;

                DesignerSerializationManager serializationManager = new DesignerSerializationManager(host);
                using (serializationManager.CreateSession()) {
                    PythonCodeDomSerializer serializer = new PythonCodeDomSerializer("    ");
                    generatedPythonCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager, "RootNamespace", 1);
                }
            }
        }
        public void SetUpFixture()
        {
            resourceWriter   = new MockResourceWriter();
            componentCreator = new MockComponentCreator();
            componentCreator.SetResourceWriter(resourceWriter);

            using (DesignSurface designSurface = new DesignSurface(typeof(Form))) {
                IDesignerHost        host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
                IEventBindingService eventBindingService = new MockEventBindingService(host);
                host.AddService(typeof(IResourceService), componentCreator);

                Form form = (Form)host.RootComponent;
                form.ClientSize = new Size(200, 300);

                PropertyDescriptorCollection descriptors            = TypeDescriptor.GetProperties(form);
                PropertyDescriptor           namePropertyDescriptor = descriptors.Find("Name", false);
                namePropertyDescriptor.SetValue(form, "MainForm");

                // Add ImageList.
                icon = new Icon(typeof(GenerateFormResourceTestFixture), "App.ico");
                ImageList imageList = (ImageList)host.CreateComponent(typeof(ImageList), "imageList1");
                imageList.Images.Add("App.ico", icon);
                imageList.Images.Add("", icon);
                imageList.Images.Add("", icon);

                DesignerSerializationManager serializationManager = new DesignerSerializationManager(host);
                using (serializationManager.CreateSession()) {
                    RubyCodeDomSerializer serializer = new RubyCodeDomSerializer("    ");
                    generatedRubyCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager, "RootNamespace", 1);
                }
            }
        }
        public void Init()
        {
            componentCreator = new MockComponentCreator();
            MockDesignerLoaderHost mockDesignerLoaderHost = new MockDesignerLoaderHost();

            deserializer = new PythonCodeDeserializer(componentCreator);
        }
Exemplo n.º 4
0
        public void SetUpFixture()
        {
            MockComponentCreator componentCreator = new MockComponentCreator();
            MethodCall           callExpression   = RubyParserHelper.GetMethodCall(code);
            RubyCodeDeserializer deserializer     = new RubyCodeDeserializer(componentCreator);

            args = deserializer.GetArguments(callExpression);
        }
        public void SetUpFixture()
        {
            MockComponentCreator   componentCreator = new MockComponentCreator();
            CallExpression         callExpression   = PythonParserHelper.GetCallExpression(code);
            PythonCodeDeserializer deserializer     = new PythonCodeDeserializer(componentCreator);

            args = deserializer.GetArguments(callExpression);
        }
        public void SetUpFixture()
        {
            componentCreator = new MockComponentCreator();
            listViewItem1    = (ListViewItem)componentCreator.CreateInstance(typeof(ListViewItem), new object[0], "listViewItem1", false);

            MethodCall callExpression = RubyParserHelper.GetMethodCall(RubyCode);

            mockDesignerLoaderHost = new MockDesignerLoaderHost();
            typeResolutionService  = mockDesignerLoaderHost.TypeResolutionService;
            RubyCodeDeserializer deserializer = new RubyCodeDeserializer(componentCreator);

            deserializedObject = deserializer.Deserialize(callExpression.Arguments.Expressions[0]);
        }
        public void SetUpFixture()
        {
            componentCreator = new MockComponentCreator();
            listViewItem1    = (ListViewItem)componentCreator.CreateInstance(typeof(ListViewItem), new object[0], "listViewItem1", false);

            CallExpression callExpression = PythonParserHelper.GetCallExpression(pythonCode);

            mockDesignerLoaderHost = new MockDesignerLoaderHost();
            typeResolutionService  = mockDesignerLoaderHost.TypeResolutionService;
            PythonCodeDeserializer deserializer = new PythonCodeDeserializer(componentCreator);

            deserializedObject = deserializer.Deserialize(callExpression.Args[0].Expression);
        }
        public void GetObjectForUnknownComponent()
        {
            string pythonCode = "self._menuStrip1.SuspendLayout()";

            CallExpression callExpression      = PythonParserHelper.GetCallExpression(pythonCode);
            PythonControlFieldExpression field = PythonControlFieldExpression.Create(callExpression);

            using (MenuStrip menuStrip = new MenuStrip()) {
                MockComponentCreator creator = new MockComponentCreator();
                creator.Add(menuStrip, "unknown");
                Assert.IsNull(field.GetMember(creator));
            }
        }
        public void GetObjectForUnknownComponent()
        {
            string RubyCode = "@menuStrip1.SuspendLayout()";

            MethodCall call = RubyParserHelper.GetMethodCall(RubyCode);
            RubyControlFieldExpression field = RubyControlFieldExpression.Create(call);

            using (MenuStrip menuStrip = new MenuStrip()) {
                MockComponentCreator creator = new MockComponentCreator();
                creator.Add(menuStrip, "unknown");
                Assert.IsNull(field.GetMember(creator));
            }
        }
        public void SetUpFixture()
        {
            resourceWriter   = new MockResourceWriter();
            componentCreator = new MockComponentCreator();
            componentCreator.SetResourceWriter(resourceWriter);

            resourceWriter2   = new MockResourceWriter();
            componentCreator2 = new MockComponentCreator();
            componentCreator2.SetResourceWriter(resourceWriter2);

            using (DesignSurface designSurface = new DesignSurface(typeof(Form))) {
                IDesignerHost        host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
                IEventBindingService eventBindingService = new MockEventBindingService(host);
                host.AddService(typeof(IResourceService), componentCreator);

                Form form = (Form)host.RootComponent;
                form.ClientSize = new Size(200, 300);

                PropertyDescriptorCollection descriptors            = TypeDescriptor.GetProperties(form);
                PropertyDescriptor           namePropertyDescriptor = descriptors.Find("Name", false);
                namePropertyDescriptor.SetValue(form, "MainForm");

                // Add picture box
                PictureBox pictureBox = (PictureBox)host.CreateComponent(typeof(PictureBox), "pictureBox1");
                pictureBox.Location = new Point(0, 0);
                bitmap              = new Bitmap(10, 10);
                pictureBox.Image    = bitmap;
                pictureBox.Size     = new Size(100, 120);
                pictureBox.TabIndex = 0;
                form.Controls.Add(pictureBox);

                // Add bitmap to form.
                form.BackgroundImage = new Bitmap(10, 10);

                DesignerSerializationManager serializationManager = new DesignerSerializationManager(host);
                using (serializationManager.CreateSession()) {
                    PythonCodeDomSerializer serializer = new PythonCodeDomSerializer("    ");
                    generatedPythonCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager, String.Empty, 1);
                }

                // Check that calling the GenerateInitializeComponentMethodBody also generates a resource file.
                host.RemoveService(typeof(IResourceService));
                host.AddService(typeof(IResourceService), componentCreator2);

                serializationManager = new DesignerSerializationManager(host);
                using (serializationManager.CreateSession()) {
                    PythonCodeDomSerializer serializer = new PythonCodeDomSerializer("    ");
                    serializer.GenerateInitializeComponentMethodBody(host, serializationManager, String.Empty, 1);
                }
            }
        }
        public void SetUpFixture()
        {
            componentCreator = new MockComponentCreator();

            AssignmentStatement assignment = PythonParserHelper.GetAssignmentStatement(GetPythonCode());

            rhsAssignmentNode = assignment.Right;

            mockDesignerLoaderHost = new MockDesignerLoaderHost();
            typeResolutionService  = mockDesignerLoaderHost.TypeResolutionService;
            PythonCodeDeserializer deserializer = new PythonCodeDeserializer(componentCreator);

            deserializedObject = deserializer.Deserialize(rhsAssignmentNode);
        }
        public void SetUpFixture()
        {
            componentCreator = new MockComponentCreator();

            SimpleAssignmentExpression assignment = RubyParserHelper.GetSimpleAssignmentExpression(GetRubyCode());

            rhsAssignmentExpression = assignment.Right;

            mockDesignerLoaderHost = new MockDesignerLoaderHost();
            typeResolutionService  = mockDesignerLoaderHost.TypeResolutionService;
            RubyCodeDeserializer deserializer = new RubyCodeDeserializer(componentCreator);

            deserializedObject = deserializer.Deserialize(rhsAssignmentExpression);
        }
        public void GetObjectInMethodCall()
        {
            string pythonCode = "self._menuStrip1.Items.AddRange(System.Array[System.Windows.Forms.ToolStripItem](\r\n" +
                                "    [self._fileToolStripMenuItem,\r\n" +
                                "    self._editToolStripMenuItem]))";

            CallExpression callExpression      = PythonParserHelper.GetCallExpression(pythonCode);
            PythonControlFieldExpression field = PythonControlFieldExpression.Create(callExpression);

            using (MenuStrip menuStrip = new MenuStrip()) {
                MockComponentCreator creator = new MockComponentCreator();
                creator.Add(menuStrip, "menuStrip1");
                Assert.AreSame(menuStrip.Items, field.GetMember(creator));
            }
        }
        public void GetObjectInMethodCall()
        {
            string RubyCode = "@menuStrip1.Items.AddRange(System::Array[System::Windows::Forms::ToolStripItem].new(\r\n" +
                              "    [@fileToolStripMenuItem,\r\n" +
                              "    @editToolStripMenuItem]))";

            MethodCall call = RubyParserHelper.GetMethodCall(RubyCode);
            RubyControlFieldExpression field = RubyControlFieldExpression.Create(call);

            using (MenuStrip menuStrip = new MenuStrip()) {
                MockComponentCreator creator = new MockComponentCreator();
                creator.Add(menuStrip, "menuStrip1");
                Assert.AreSame(menuStrip.Items, field.GetMember(creator));
            }
        }
        public void GetInstanceObjectInMethodCall()
        {
            string pythonCode = "treeNode1.Nodes.AddRange(System.Array[System.Windows.Forms.TreeNode](\r\n" +
                                "    [treeNode2]))";

            CallExpression callExpression      = PythonParserHelper.GetCallExpression(pythonCode);
            PythonControlFieldExpression field = PythonControlFieldExpression.Create(callExpression);

            TreeNode             treeNode1 = new TreeNode();
            TreeNode             treeNode2 = new TreeNode();
            MockComponentCreator creator   = new MockComponentCreator();

            creator.AddInstance(treeNode1, "treeNode1");
            creator.AddInstance(treeNode2, "treeNode2");
            object member = field.GetMember(creator);

            Assert.AreSame(treeNode1.Nodes, member);
        }
        public void GetInstanceObjectInMethodCall()
        {
            string RubyCode = "treeNode1.Nodes.AddRange(System::Array[System::Windows::Forms::TreeNode].new(\r\n" +
                              "    [treeNode2]))";

            MethodCall callExpression        = RubyParserHelper.GetMethodCall(RubyCode);
            RubyControlFieldExpression field = RubyControlFieldExpression.Create(callExpression);

            TreeNode             treeNode1 = new TreeNode();
            TreeNode             treeNode2 = new TreeNode();
            MockComponentCreator creator   = new MockComponentCreator();

            creator.AddInstance(treeNode1, "treeNode1");
            creator.AddInstance(treeNode2, "treeNode2");
            object member = field.GetMember(creator);

            Assert.AreSame(treeNode1.Nodes, member);
        }
Exemplo n.º 17
0
 public void Init()
 {
     componentCreator = new MockComponentCreator();
 }
 public void SetUpFixture()
 {
     componentCreator = new MockComponentCreator();
     deserializer     = new PythonCodeDeserializer(componentCreator);
 }