Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@3987 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
6 changed files with 367 additions and 53 deletions
@ -0,0 +1,95 @@
@@ -0,0 +1,95 @@
|
||||
// <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.Reflection; |
||||
using System.Windows.Forms; |
||||
|
||||
using ICSharpCode.PythonBinding; |
||||
using NUnit.Framework; |
||||
|
||||
namespace PythonBinding.Tests.Designer |
||||
{ |
||||
/// <summary>
|
||||
/// Tests that the AddRange or Add method that takes an array of items can be determined.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class FindAddRangeMethodTests |
||||
{ |
||||
[Test] |
||||
public void MenuStripItemsAddRangeMethod() |
||||
{ |
||||
using (MenuStrip menuStrip = new MenuStrip()) { |
||||
MethodInfo expectedMethodInfo = FindMethod(menuStrip.Items, "AddRange", typeof(ToolStripItem[])); |
||||
Assert.IsNotNull(expectedMethodInfo); |
||||
|
||||
Assert.AreSame(expectedMethodInfo, PythonForm.GetAddRangeSerializationMethod(menuStrip.Items)); |
||||
} |
||||
} |
||||
|
||||
[Test] |
||||
public void GetArrayParameterType() |
||||
{ |
||||
using (MenuStrip menuStrip = new MenuStrip()) { |
||||
MethodInfo methodInfo = FindMethod(menuStrip.Items, "AddRange", typeof(ToolStripItem[])); |
||||
Assert.AreEqual(typeof(ToolStripItem), PythonForm.GetArrayParameterType(methodInfo)); |
||||
} |
||||
} |
||||
|
||||
[Test] |
||||
public void GetArrayParameterTypeFromMethodWithNoParameters() |
||||
{ |
||||
MethodInfo methodInfo = typeof(String).GetMethod("Clone"); |
||||
Assert.IsNull(PythonForm.GetArrayParameterType(methodInfo)); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetArrayParameterTypeWithNullMethodInfo() |
||||
{ |
||||
Assert.IsNull(PythonForm.GetArrayParameterType(null)); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Form.Controls.AddRange() method should not be returned since it is marked with
|
||||
/// DesignerSerializationVisibility.Hidden.
|
||||
/// </summary>
|
||||
[Test] |
||||
public void FormControlsAddRangeMethodNotFound() |
||||
{ |
||||
using (Form form = new Form()) { |
||||
Assert.IsNull(PythonForm.GetAddRangeSerializationMethod(form.Controls)); |
||||
} |
||||
} |
||||
|
||||
[Test] |
||||
public void FormControlsAddMethod() |
||||
{ |
||||
using (Form form = new Form()) { |
||||
MethodInfo expectedMethodInfo = FindMethod(form.Controls, "Add", typeof(Control)); |
||||
Assert.IsNotNull(expectedMethodInfo); |
||||
|
||||
Assert.AreSame(expectedMethodInfo, PythonForm.GetAddSerializationMethod(form.Controls)); |
||||
} |
||||
} |
||||
|
||||
static MethodInfo FindMethod(object obj, string methodName, Type parameterType) |
||||
{ |
||||
foreach (MethodInfo methodInfo in obj.GetType().GetMethods()) { |
||||
if (methodInfo.Name == methodName) { |
||||
ParameterInfo[] parameters = methodInfo.GetParameters(); |
||||
if (parameters.Length == 1) { |
||||
ParameterInfo param = parameters[0]; |
||||
if (param.ParameterType == parameterType) { |
||||
return methodInfo; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,46 @@
@@ -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.Windows.Forms; |
||||
using ICSharpCode.PythonBinding; |
||||
using NUnit.Framework; |
||||
|
||||
namespace PythonBinding.Tests.Designer |
||||
{ |
||||
/// <summary>
|
||||
/// Gets properties that are marked as DesignerSerializationVisibility.Content
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class GetSerializableContentPropertiesTestFixture |
||||
{ |
||||
PropertyDescriptorCollection properties; |
||||
|
||||
[TestFixtureSetUp] |
||||
public void SetUpFixture() |
||||
{ |
||||
using (Form form = new Form()) { |
||||
// Modify Form.Text so it is identified as needing serialization.
|
||||
form.Text = "abc"; |
||||
properties = PythonForm.GetSerializableContentProperties(form); |
||||
} |
||||
} |
||||
|
||||
[Test] |
||||
public void FormControlsPropertyReturned() |
||||
{ |
||||
Assert.IsNotNull(properties.Find("Controls", false), "Property not found: Controls"); |
||||
} |
||||
|
||||
[Test] |
||||
public void FormTextPropertyIsNotReturned() |
||||
{ |
||||
Assert.IsNull(properties.Find("Text", false), "Property should not be found: Text"); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,77 @@
@@ -0,0 +1,77 @@
|
||||
// <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 ICSharpCode.PythonBinding; |
||||
using NUnit.Framework; |
||||
using PythonBinding.Tests.Utils; |
||||
|
||||
namespace PythonBinding.Tests.Designer |
||||
{ |
||||
[TestFixture] |
||||
public class IsSitedComponentTests : ISite |
||||
{ |
||||
[Test] |
||||
public void NullComponent() |
||||
{ |
||||
Assert.IsFalse(PythonForm.IsSitedComponent(null)); |
||||
} |
||||
|
||||
[Test] |
||||
public void ComponentNotSited() |
||||
{ |
||||
Assert.IsFalse(PythonForm.IsSitedComponent(new Component())); |
||||
} |
||||
|
||||
[Test] |
||||
public void SitedComponent() |
||||
{ |
||||
Component component = new Component(); |
||||
component.Site = this; |
||||
Assert.IsTrue(PythonForm.IsSitedComponent(component)); |
||||
} |
||||
|
||||
[Test] |
||||
public void NonComponent() |
||||
{ |
||||
Assert.IsFalse(PythonForm.IsSitedComponent(String.Empty)); |
||||
} |
||||
|
||||
public IComponent Component { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public IContainer Container { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public bool DesignMode { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public string Name { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
set { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public object GetService(Type serviceType) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
} |
||||
Loading…
Reference in new issue