31 changed files with 650 additions and 559 deletions
@ -1,76 +0,0 @@ |
|||||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
|
||||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
|
||||||
|
|
||||||
using System; |
|
||||||
using System.ComponentModel; |
|
||||||
using System.ComponentModel.Design; |
|
||||||
using System.ComponentModel.Design.Serialization; |
|
||||||
using System.Drawing; |
|
||||||
using System.Windows.Forms; |
|
||||||
|
|
||||||
using ICSharpCode.PythonBinding; |
|
||||||
using ICSharpCode.Scripting.Tests.Utils; |
|
||||||
using NUnit.Framework; |
|
||||||
using PythonBinding.Tests.Utils; |
|
||||||
|
|
||||||
namespace PythonBinding.Tests.Designer |
|
||||||
{ |
|
||||||
/// <summary>
|
|
||||||
/// Tests that a null property value does not cause a NullReferenceException.
|
|
||||||
/// </summary>
|
|
||||||
[TestFixture] |
|
||||||
public class AppendNullPropertyValueTestFixture |
|
||||||
{ |
|
||||||
string generatedPythonCode; |
|
||||||
|
|
||||||
[TestFixtureSetUp] |
|
||||||
public void SetUpFixture() |
|
||||||
{ |
|
||||||
using (DesignSurface designSurface = new DesignSurface(typeof(UserControl))) { |
|
||||||
IDesignerHost host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost)); |
|
||||||
IEventBindingService eventBindingService = new MockEventBindingService(host); |
|
||||||
UserControl userControl = (UserControl)host.RootComponent; |
|
||||||
userControl.ClientSize = new Size(200, 300); |
|
||||||
|
|
||||||
NullPropertyUserControl control = (NullPropertyUserControl)host.CreateComponent(typeof(NullPropertyUserControl), "userControl1"); |
|
||||||
control.Location = new Point(0, 0); |
|
||||||
control.Size = new Size(10, 10); |
|
||||||
userControl.Controls.Add(control); |
|
||||||
|
|
||||||
PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(userControl); |
|
||||||
PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false); |
|
||||||
namePropertyDescriptor.SetValue(userControl, "MainControl"); |
|
||||||
|
|
||||||
DesignerSerializationManager serializationManager = new DesignerSerializationManager(host); |
|
||||||
using (serializationManager.CreateSession()) { |
|
||||||
PythonCodeDomSerializer serializer = new PythonCodeDomSerializer(" "); |
|
||||||
generatedPythonCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
[Test] |
|
||||||
public void GeneratedCode() |
|
||||||
{ |
|
||||||
string expectedCode = "self._userControl1 = ICSharpCode.Scripting.Tests.Utils.NullPropertyUserControl()\r\n" + |
|
||||||
"self.SuspendLayout()\r\n" + |
|
||||||
"# \r\n" + |
|
||||||
"# userControl1\r\n" + |
|
||||||
"# \r\n" + |
|
||||||
"self._userControl1.FooBar = None\r\n" + |
|
||||||
"self._userControl1.Location = System.Drawing.Point(0, 0)\r\n" + |
|
||||||
"self._userControl1.Name = \"userControl1\"\r\n" + |
|
||||||
"self._userControl1.Size = System.Drawing.Size(10, 10)\r\n" + |
|
||||||
"self._userControl1.TabIndex = 0\r\n" + |
|
||||||
"# \r\n" + |
|
||||||
"# MainControl\r\n" + |
|
||||||
"# \r\n" + |
|
||||||
"self.Controls.Add(self._userControl1)\r\n" + |
|
||||||
"self.Name = \"MainControl\"\r\n" + |
|
||||||
"self.Size = System.Drawing.Size(200, 300)\r\n" + |
|
||||||
"self.ResumeLayout(False)\r\n"; |
|
||||||
|
|
||||||
Assert.AreEqual(expectedCode, generatedPythonCode, generatedPythonCode); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,45 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.Scripting; |
||||||
|
using ICSharpCode.Scripting.Tests.Designer; |
||||||
|
using NUnit.Framework; |
||||||
|
using PythonBinding.Tests.Utils; |
||||||
|
|
||||||
|
namespace PythonBinding.Tests.Designer |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class GenerateUserControlWithNullPropertyValueTests : GenerateUserControlWithNullPropertyValueTestsBase |
||||||
|
{ |
||||||
|
[Test] |
||||||
|
public void GeneratedCode() |
||||||
|
{ |
||||||
|
string expectedCode = |
||||||
|
"self._userControl1 = ICSharpCode.Scripting.Tests.Utils.NullPropertyUserControl()\r\n" + |
||||||
|
"self.SuspendLayout()\r\n" + |
||||||
|
"# \r\n" + |
||||||
|
"# userControl1\r\n" + |
||||||
|
"# \r\n" + |
||||||
|
"self._userControl1.FooBar = None\r\n" + |
||||||
|
"self._userControl1.Location = System.Drawing.Point(0, 0)\r\n" + |
||||||
|
"self._userControl1.Name = \"userControl1\"\r\n" + |
||||||
|
"self._userControl1.Size = System.Drawing.Size(10, 10)\r\n" + |
||||||
|
"self._userControl1.TabIndex = 0\r\n" + |
||||||
|
"# \r\n" + |
||||||
|
"# MainControl\r\n" + |
||||||
|
"# \r\n" + |
||||||
|
"self.Controls.Add(self._userControl1)\r\n" + |
||||||
|
"self.Name = \"MainControl\"\r\n" + |
||||||
|
"self.Size = System.Drawing.Size(200, 300)\r\n" + |
||||||
|
"self.ResumeLayout(False)\r\n"; |
||||||
|
|
||||||
|
Assert.AreEqual(expectedCode, generatedCode, generatedCode); |
||||||
|
} |
||||||
|
|
||||||
|
protected override IScriptingCodeDomSerializer CreateSerializer() |
||||||
|
{ |
||||||
|
return PythonCodeDomSerializerHelper.CreateSerializer(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,20 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.PythonBinding; |
||||||
|
|
||||||
|
namespace PythonBinding.Tests.Utils |
||||||
|
{ |
||||||
|
public class PythonCodeDomSerializerHelper |
||||||
|
{ |
||||||
|
public static PythonCodeDomSerializer CreateSerializer() |
||||||
|
{ |
||||||
|
return new PythonCodeDomSerializer(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,21 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.PythonBinding; |
||||||
|
using ICSharpCode.Scripting; |
||||||
|
|
||||||
|
namespace PythonBinding.Tests.Utils |
||||||
|
{ |
||||||
|
public class PythonComponentWalkerHelper |
||||||
|
{ |
||||||
|
public static IComponentWalker CreateComponentWalker(IComponentCreator componentCreator) |
||||||
|
{ |
||||||
|
return new PythonComponentWalker(componentCreator); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -1,77 +0,0 @@ |
|||||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
|
||||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
|
||||||
|
|
||||||
using System; |
|
||||||
using System.ComponentModel; |
|
||||||
using System.ComponentModel.Design; |
|
||||||
using System.ComponentModel.Design.Serialization; |
|
||||||
using System.Drawing; |
|
||||||
using System.Windows.Forms; |
|
||||||
|
|
||||||
using ICSharpCode.RubyBinding; |
|
||||||
using ICSharpCode.Scripting.Tests.Utils; |
|
||||||
using NUnit.Framework; |
|
||||||
using RubyBinding.Tests.Utils; |
|
||||||
|
|
||||||
namespace RubyBinding.Tests.Designer |
|
||||||
{ |
|
||||||
/// <summary>
|
|
||||||
/// Tests that a null property value does not cause a NullReferenceException.
|
|
||||||
/// </summary>
|
|
||||||
[TestFixture] |
|
||||||
public class AppendNullPropertyValueTestFixture |
|
||||||
{ |
|
||||||
string generatedRubyCode; |
|
||||||
|
|
||||||
[TestFixtureSetUp] |
|
||||||
public void SetUpFixture() |
|
||||||
{ |
|
||||||
using (DesignSurface designSurface = new DesignSurface(typeof(UserControl))) { |
|
||||||
IDesignerHost host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost)); |
|
||||||
IEventBindingService eventBindingService = new MockEventBindingService(host); |
|
||||||
UserControl userControl = (UserControl)host.RootComponent; |
|
||||||
userControl.ClientSize = new Size(200, 300); |
|
||||||
|
|
||||||
NullPropertyUserControl control = (NullPropertyUserControl)host.CreateComponent(typeof(NullPropertyUserControl), "userControl1"); |
|
||||||
control.Location = new Point(0, 0); |
|
||||||
control.Size = new Size(10, 10); |
|
||||||
userControl.Controls.Add(control); |
|
||||||
|
|
||||||
PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(userControl); |
|
||||||
PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false); |
|
||||||
namePropertyDescriptor.SetValue(userControl, "MainControl"); |
|
||||||
|
|
||||||
DesignerSerializationManager serializationManager = new DesignerSerializationManager(host); |
|
||||||
using (serializationManager.CreateSession()) { |
|
||||||
RubyCodeDomSerializer serializer = new RubyCodeDomSerializer(" "); |
|
||||||
generatedRubyCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
[Test] |
|
||||||
public void GeneratedCode() |
|
||||||
{ |
|
||||||
string expectedCode = |
|
||||||
"@userControl1 = ICSharpCode::Scripting::Tests::Utils::NullPropertyUserControl.new()\r\n" + |
|
||||||
"self.SuspendLayout()\r\n" + |
|
||||||
"# \r\n" + |
|
||||||
"# userControl1\r\n" + |
|
||||||
"# \r\n" + |
|
||||||
"@userControl1.FooBar = nil\r\n" + |
|
||||||
"@userControl1.Location = System::Drawing::Point.new(0, 0)\r\n" + |
|
||||||
"@userControl1.Name = \"userControl1\"\r\n" + |
|
||||||
"@userControl1.Size = System::Drawing::Size.new(10, 10)\r\n" + |
|
||||||
"@userControl1.TabIndex = 0\r\n" + |
|
||||||
"# \r\n" + |
|
||||||
"# MainControl\r\n" + |
|
||||||
"# \r\n" + |
|
||||||
"self.Controls.Add(@userControl1)\r\n" + |
|
||||||
"self.Name = \"MainControl\"\r\n" + |
|
||||||
"self.Size = System::Drawing::Size.new(200, 300)\r\n" + |
|
||||||
"self.ResumeLayout(false)\r\n"; |
|
||||||
|
|
||||||
Assert.AreEqual(expectedCode, generatedRubyCode, generatedRubyCode); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,48 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.Scripting; |
||||||
|
using ICSharpCode.Scripting.Tests.Designer; |
||||||
|
using NUnit.Framework; |
||||||
|
using RubyBinding.Tests.Utils; |
||||||
|
|
||||||
|
namespace RubyBinding.Tests.Designer |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Tests that a null property value does not cause a NullReferenceException.
|
||||||
|
/// </summary>
|
||||||
|
[TestFixture] |
||||||
|
public class GenerateUserControlWithNullPropertyValueTests : GenerateUserControlWithNullPropertyValueTestsBase |
||||||
|
{ |
||||||
|
[Test] |
||||||
|
public void GeneratedCode() |
||||||
|
{ |
||||||
|
string expectedCode = |
||||||
|
"@userControl1 = ICSharpCode::Scripting::Tests::Utils::NullPropertyUserControl.new()\r\n" + |
||||||
|
"self.SuspendLayout()\r\n" + |
||||||
|
"# \r\n" + |
||||||
|
"# userControl1\r\n" + |
||||||
|
"# \r\n" + |
||||||
|
"@userControl1.FooBar = nil\r\n" + |
||||||
|
"@userControl1.Location = System::Drawing::Point.new(0, 0)\r\n" + |
||||||
|
"@userControl1.Name = \"userControl1\"\r\n" + |
||||||
|
"@userControl1.Size = System::Drawing::Size.new(10, 10)\r\n" + |
||||||
|
"@userControl1.TabIndex = 0\r\n" + |
||||||
|
"# \r\n" + |
||||||
|
"# MainControl\r\n" + |
||||||
|
"# \r\n" + |
||||||
|
"self.Controls.Add(@userControl1)\r\n" + |
||||||
|
"self.Name = \"MainControl\"\r\n" + |
||||||
|
"self.Size = System::Drawing::Size.new(200, 300)\r\n" + |
||||||
|
"self.ResumeLayout(false)\r\n"; |
||||||
|
|
||||||
|
Assert.AreEqual(expectedCode, generatedCode, generatedCode); |
||||||
|
} |
||||||
|
|
||||||
|
protected override IScriptingCodeDomSerializer CreateSerializer() |
||||||
|
{ |
||||||
|
return RubyCodeDomSerializerHelper.CreateSerializer(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,20 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.RubyBinding; |
||||||
|
|
||||||
|
namespace RubyBinding.Tests.Utils |
||||||
|
{ |
||||||
|
public class RubyCodeDomSerializerHelper |
||||||
|
{ |
||||||
|
public static RubyCodeDomSerializer CreateSerializer() |
||||||
|
{ |
||||||
|
return new RubyCodeDomSerializer(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,21 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.RubyBinding; |
||||||
|
using ICSharpCode.Scripting; |
||||||
|
|
||||||
|
namespace RubyBinding.Tests.Utils |
||||||
|
{ |
||||||
|
public class RubyComponentWalkerHelper |
||||||
|
{ |
||||||
|
public static IComponentWalker CreateComponentWalker(IComponentCreator componentCreator) |
||||||
|
{ |
||||||
|
return new RubyComponentWalker(componentCreator); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,48 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.Scripting.Tests.Utils; |
||||||
|
using NUnit.Framework; |
||||||
|
|
||||||
|
namespace ICSharpCode.Scripting.Tests.Designer |
||||||
|
{ |
||||||
|
public abstract class CallBeginInitOnLoadTestsBase : LoadFormTestsBase |
||||||
|
{ |
||||||
|
public SupportInitCustomControl Control { |
||||||
|
get { return Form.Controls[0] as SupportInitCustomControl; } |
||||||
|
} |
||||||
|
|
||||||
|
public SupportInitCustomControl LocalControl { |
||||||
|
get { return base.ComponentCreator.GetInstance("localVariable") as SupportInitCustomControl; } |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void BeginInitCalled() |
||||||
|
{ |
||||||
|
Assert.IsTrue(Control.IsBeginInitCalled); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void EndInitCalled() |
||||||
|
{ |
||||||
|
Assert.IsTrue(Control.IsEndInitCalled); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void BeginInitCalledOnLocalVariable() |
||||||
|
{ |
||||||
|
Assert.IsTrue(LocalControl.IsBeginInitCalled); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void EndInitCalledOnLocalVariable() |
||||||
|
{ |
||||||
|
Assert.IsTrue(LocalControl.IsEndInitCalled); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,55 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using System.ComponentModel; |
||||||
|
using System.ComponentModel.Design; |
||||||
|
using System.ComponentModel.Design.Serialization; |
||||||
|
using System.Drawing; |
||||||
|
using System.Windows.Forms; |
||||||
|
|
||||||
|
using ICSharpCode.Scripting; |
||||||
|
using ICSharpCode.Scripting.Tests.Utils; |
||||||
|
using NUnit.Framework; |
||||||
|
|
||||||
|
namespace ICSharpCode.Scripting.Tests.Designer |
||||||
|
{ |
||||||
|
public abstract class GenerateAcceptButtonFormTestsBase : GenerateDesignerCodeTestsBase |
||||||
|
{ |
||||||
|
[TestFixtureSetUp] |
||||||
|
public void SetUpFixture() |
||||||
|
{ |
||||||
|
using (DesignSurface designSurface = new DesignSurface(typeof(Form))) { |
||||||
|
IDesignerHost host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost)); |
||||||
|
IEventBindingService eventBindingService = new MockEventBindingService(host); |
||||||
|
Form form = (Form)host.RootComponent; |
||||||
|
form.ClientSize = new Size(200, 300); |
||||||
|
|
||||||
|
Button button = (Button)host.CreateComponent(typeof(Button), "button1"); |
||||||
|
button.Location = new Point(0, 0); |
||||||
|
button.Size = new Size(10, 10); |
||||||
|
button.Text = "button1"; |
||||||
|
button.UseCompatibleTextRendering = false; |
||||||
|
form.Controls.Add(button); |
||||||
|
|
||||||
|
PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(form); |
||||||
|
PropertyDescriptor acceptButtonPropertyDescriptor = descriptors.Find("AcceptButton", false); |
||||||
|
acceptButtonPropertyDescriptor.SetValue(form, button); |
||||||
|
|
||||||
|
PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false); |
||||||
|
namePropertyDescriptor.SetValue(form, "MainForm"); |
||||||
|
|
||||||
|
DesignerSerializationManager serializationManager = new DesignerSerializationManager(host); |
||||||
|
using (serializationManager.CreateSession()) { |
||||||
|
IScriptingCodeDomSerializer serializer = CreateSerializer(); |
||||||
|
generatedCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,18 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
|
||||||
|
namespace ICSharpCode.Scripting.Tests.Designer |
||||||
|
{ |
||||||
|
public abstract class GenerateDesignerCodeTestsBase |
||||||
|
{ |
||||||
|
protected string generatedCode; |
||||||
|
|
||||||
|
protected abstract IScriptingCodeDomSerializer CreateSerializer(); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,46 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.ComponentModel; |
||||||
|
using System.ComponentModel.Design; |
||||||
|
using System.ComponentModel.Design.Serialization; |
||||||
|
using System.Drawing; |
||||||
|
using System.Windows.Forms; |
||||||
|
using ICSharpCode.Scripting; |
||||||
|
using NUnit.Framework; |
||||||
|
|
||||||
|
namespace ICSharpCode.Scripting.Tests.Designer |
||||||
|
{ |
||||||
|
public abstract class GenerateEnabledUsingPropertyDescriptorTestsBase : GenerateDesignerCodeTestsBase |
||||||
|
{ |
||||||
|
[TestFixtureSetUp] |
||||||
|
public void SetUpFixture() |
||||||
|
{ |
||||||
|
using (DesignSurface designSurface = new DesignSurface(typeof(Form))) { |
||||||
|
IDesignerHost host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost)); |
||||||
|
Form form = (Form)host.RootComponent; |
||||||
|
form.ClientSize = new Size(284, 264); |
||||||
|
form.AllowDrop = false; |
||||||
|
form.Enabled = false; |
||||||
|
|
||||||
|
PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(form); |
||||||
|
PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false); |
||||||
|
namePropertyDescriptor.SetValue(form, "MainForm"); |
||||||
|
|
||||||
|
PropertyDescriptor enabledPropertyDescriptor = descriptors.Find("Enabled", false); |
||||||
|
enabledPropertyDescriptor.SetValue(form, false); |
||||||
|
|
||||||
|
DesignerSerializationManager serializationManager = new DesignerSerializationManager(host); |
||||||
|
using (serializationManager.CreateSession()) { |
||||||
|
IScriptingCodeDomSerializer serializer = CreateSerializer(); |
||||||
|
generatedCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,49 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.ComponentModel; |
||||||
|
using System.ComponentModel.Design; |
||||||
|
using System.ComponentModel.Design.Serialization; |
||||||
|
using System.Drawing; |
||||||
|
using System.Windows.Forms; |
||||||
|
|
||||||
|
using ICSharpCode.Scripting; |
||||||
|
using ICSharpCode.Scripting.Tests.Utils; |
||||||
|
using NUnit.Framework; |
||||||
|
|
||||||
|
namespace ICSharpCode.Scripting.Tests.Designer |
||||||
|
{ |
||||||
|
public abstract class GenerateUserControlWithNullPropertyValueTestsBase : GenerateDesignerCodeTestsBase |
||||||
|
{ |
||||||
|
[TestFixtureSetUp] |
||||||
|
public void SetUpFixture() |
||||||
|
{ |
||||||
|
using (DesignSurface designSurface = new DesignSurface(typeof(UserControl))) { |
||||||
|
IDesignerHost host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost)); |
||||||
|
IEventBindingService eventBindingService = new MockEventBindingService(host); |
||||||
|
UserControl userControl = (UserControl)host.RootComponent; |
||||||
|
userControl.ClientSize = new Size(200, 300); |
||||||
|
|
||||||
|
NullPropertyUserControl control = (NullPropertyUserControl)host.CreateComponent(typeof(NullPropertyUserControl), "userControl1"); |
||||||
|
control.Location = new Point(0, 0); |
||||||
|
control.Size = new Size(10, 10); |
||||||
|
userControl.Controls.Add(control); |
||||||
|
|
||||||
|
PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(userControl); |
||||||
|
PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false); |
||||||
|
namePropertyDescriptor.SetValue(userControl, "MainControl"); |
||||||
|
|
||||||
|
DesignerSerializationManager serializationManager = new DesignerSerializationManager(host); |
||||||
|
using (serializationManager.CreateSession()) { |
||||||
|
IScriptingCodeDomSerializer serializer = CreateSerializer(); |
||||||
|
generatedCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,58 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Drawing; |
||||||
|
using System.Reflection; |
||||||
|
using System.Windows.Forms; |
||||||
|
|
||||||
|
using ICSharpCode.Scripting; |
||||||
|
using ICSharpCode.Scripting.Tests.Utils; |
||||||
|
using NUnit.Framework; |
||||||
|
|
||||||
|
namespace ICSharpCode.Scripting.Tests.Designer |
||||||
|
{ |
||||||
|
public abstract class LoadFormTestsBase |
||||||
|
{ |
||||||
|
MockComponentCreator componentCreator = new MockComponentCreator(); |
||||||
|
Form form; |
||||||
|
|
||||||
|
[TestFixtureSetUp] |
||||||
|
public void SetUpFixture() |
||||||
|
{ |
||||||
|
BeforeSetUpFixture(); |
||||||
|
IComponentWalker walker = CreateComponentWalker(componentCreator); |
||||||
|
form = walker.CreateComponent(Code) as Form; |
||||||
|
} |
||||||
|
|
||||||
|
[TestFixtureTearDown] |
||||||
|
public void TearDownFixture() |
||||||
|
{ |
||||||
|
form.Dispose(); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Called at the start of SetUpFixture method before anything is setup.
|
||||||
|
/// </summary>
|
||||||
|
public virtual void BeforeSetUpFixture() |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
protected abstract IComponentWalker CreateComponentWalker(IComponentCreator componentCreator); |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the code that will be loaded.
|
||||||
|
/// </summary>
|
||||||
|
public virtual string Code { |
||||||
|
get { return String.Empty; } |
||||||
|
} |
||||||
|
|
||||||
|
protected MockComponentCreator ComponentCreator { |
||||||
|
get { return componentCreator; } |
||||||
|
} |
||||||
|
|
||||||
|
protected Form Form { |
||||||
|
get { return form; } |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,55 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.ComponentModel; |
||||||
|
using System.ComponentModel.Design.Serialization; |
||||||
|
using System.Globalization; |
||||||
|
using System.Reflection; |
||||||
|
|
||||||
|
namespace ICSharpCode.Scripting.Tests.Utils |
||||||
|
{ |
||||||
|
[TypeConverter(typeof(CustomClassTypeConverter))] |
||||||
|
public class CustomClass |
||||||
|
{ |
||||||
|
public string Name { get; set; } |
||||||
|
public string Category { get; set; } |
||||||
|
|
||||||
|
public CustomClass() |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public CustomClass(string name, string category) |
||||||
|
{ |
||||||
|
this.Name = name; |
||||||
|
this.Category = category; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public class CustomClassTypeConverter : TypeConverter |
||||||
|
{ |
||||||
|
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) |
||||||
|
{ |
||||||
|
if (destinationType == typeof(InstanceDescriptor)) { |
||||||
|
CustomClass c = value as CustomClass; |
||||||
|
if (c != null) { |
||||||
|
ConstructorInfo info = typeof(CustomClass).GetConstructor(new Type[] {typeof(String), typeof(String)}); |
||||||
|
return new InstanceDescriptor(info, new object[] {c.Name, c.Category}); |
||||||
|
} |
||||||
|
} |
||||||
|
return base.ConvertTo(context, culture, value, destinationType); |
||||||
|
} |
||||||
|
|
||||||
|
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) |
||||||
|
{ |
||||||
|
if (destinationType == typeof(InstanceDescriptor)) { |
||||||
|
return true; |
||||||
|
} |
||||||
|
return base.CanConvertTo(context, destinationType); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue