23 changed files with 72 additions and 318 deletions
@ -1,107 +0,0 @@ |
|||||||
// <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.Design.Serialization; |
|
||||||
using System.Windows.Forms; |
|
||||||
|
|
||||||
using ICSharpCode.PythonBinding; |
|
||||||
using ICSharpCode.Scripting.Tests.Utils; |
|
||||||
using NUnit.Framework; |
|
||||||
using PythonBinding.Tests.Utils; |
|
||||||
|
|
||||||
namespace PythonBinding.Tests.Designer |
|
||||||
{ |
|
||||||
[TestFixture] |
|
||||||
public class NameCreationServiceTestFixture |
|
||||||
{ |
|
||||||
PythonNameCreationService nameCreationService; |
|
||||||
MockDesignerLoaderHost host; |
|
||||||
|
|
||||||
[SetUp] |
|
||||||
public void Init() |
|
||||||
{ |
|
||||||
host = new MockDesignerLoaderHost(); |
|
||||||
host.Container.Add(new Button(), "button1"); |
|
||||||
nameCreationService = new PythonNameCreationService(host); |
|
||||||
} |
|
||||||
|
|
||||||
[Test] |
|
||||||
public void IsValidNameReturnsFalseIfComponentInContainerAlreadyUsesName() |
|
||||||
{ |
|
||||||
Assert.IsFalse(nameCreationService.IsValidName("button1")); |
|
||||||
} |
|
||||||
|
|
||||||
[Test] |
|
||||||
public void IsValidNameReturnsTrueIfNameNotInUse() |
|
||||||
{ |
|
||||||
Assert.IsTrue(nameCreationService.IsValidName("unknown")); |
|
||||||
} |
|
||||||
|
|
||||||
[Test] |
|
||||||
public void NullReferenceNotThrownWhenHostContainerIsNull() |
|
||||||
{ |
|
||||||
host.Container = null; |
|
||||||
Assert.IsTrue(nameCreationService.IsValidName("button1")); |
|
||||||
} |
|
||||||
|
|
||||||
[Test] |
|
||||||
public void CreateNameReturnsTypeNameFollowedByNumberOne() |
|
||||||
{ |
|
||||||
Assert.AreEqual("button1", nameCreationService.CreateName(null, typeof(Button))); |
|
||||||
} |
|
||||||
|
|
||||||
[Test] |
|
||||||
public void CreateNameReturnsTypeNameFollowedByNumberTwoIfNameExistsInContainer() |
|
||||||
{ |
|
||||||
Assert.AreEqual("button2", nameCreationService.CreateName(host.Container, typeof(Button))); |
|
||||||
} |
|
||||||
|
|
||||||
[Test] |
|
||||||
public void ValidateNameThrowsExceptionIfNameExistsInContainer() |
|
||||||
{ |
|
||||||
Exception ex = Assert.Throws<Exception>(delegate { nameCreationService.ValidateName("button1"); }); |
|
||||||
Assert.AreEqual("Invalid name button1", ex.Message); |
|
||||||
} |
|
||||||
|
|
||||||
[Test] |
|
||||||
public void ValidateNameDoesNotThrowExceptionIfNameDoesNotExistInContainer() |
|
||||||
{ |
|
||||||
Assert.DoesNotThrow(delegate { nameCreationService.ValidateName("button2"); }); |
|
||||||
} |
|
||||||
|
|
||||||
[Test] |
|
||||||
public void IsValidReturnsFalseWhenNameIsNull() |
|
||||||
{ |
|
||||||
Assert.IsFalse(nameCreationService.IsValidName(null)); |
|
||||||
} |
|
||||||
|
|
||||||
[Test] |
|
||||||
public void IsValidReturnsFalseWhenNameIsEmptyString() |
|
||||||
{ |
|
||||||
Assert.IsFalse(nameCreationService.IsValidName(String.Empty)); |
|
||||||
} |
|
||||||
|
|
||||||
[Test] |
|
||||||
public void IsValidReturnsFalseWhenNameContainsNonLetterOrDigit() |
|
||||||
{ |
|
||||||
Assert.IsFalse(nameCreationService.IsValidName("a%b")); |
|
||||||
} |
|
||||||
|
|
||||||
[Test] |
|
||||||
public void IsValidReturnsFalseWhenFirstCharacterOfNameIsNumber() |
|
||||||
{ |
|
||||||
Assert.IsFalse(nameCreationService.IsValidName("1abc")); |
|
||||||
} |
|
||||||
|
|
||||||
[Test] |
|
||||||
public void IsValidReturnsTrueWhenFirstCharacterOfNameIsUnderscore() |
|
||||||
{ |
|
||||||
Assert.IsTrue(nameCreationService.IsValidName("_abc")); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
@ -1,99 +0,0 @@ |
|||||||
// <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.CodeDom; |
|
||||||
using System.CodeDom.Compiler; |
|
||||||
using System.Collections; |
|
||||||
using System.Collections.Generic; |
|
||||||
using System.ComponentModel; |
|
||||||
using System.ComponentModel.Design; |
|
||||||
using System.ComponentModel.Design.Serialization; |
|
||||||
using System.Reflection; |
|
||||||
using System.Windows.Forms; |
|
||||||
|
|
||||||
using ICSharpCode.FormsDesigner; |
|
||||||
using ICSharpCode.PythonBinding; |
|
||||||
using ICSharpCode.SharpDevelop; |
|
||||||
|
|
||||||
namespace PythonBinding.Tests.Utils |
|
||||||
{ |
|
||||||
/// <summary>
|
|
||||||
/// Mock IDesignerGenerator class.
|
|
||||||
/// </summary>
|
|
||||||
public class MockDesignerGenerator : IPythonDesignerGenerator |
|
||||||
{ |
|
||||||
FormsDesignerViewContent viewContent; |
|
||||||
IDesignerHost mergeChangesHost; |
|
||||||
IDesignerSerializationManager mergeChangesSerializationManager; |
|
||||||
|
|
||||||
public MockDesignerGenerator() |
|
||||||
{ |
|
||||||
} |
|
||||||
|
|
||||||
public CodeDomProvider CodeDomProvider { |
|
||||||
get { return null; } |
|
||||||
} |
|
||||||
|
|
||||||
public FormsDesignerViewContent ViewContent { |
|
||||||
get { return this.viewContent; } |
|
||||||
} |
|
||||||
|
|
||||||
public void Attach(FormsDesignerViewContent viewContent) |
|
||||||
{ |
|
||||||
this.viewContent = viewContent; |
|
||||||
} |
|
||||||
|
|
||||||
public void Detach() |
|
||||||
{ |
|
||||||
this.viewContent = null; |
|
||||||
} |
|
||||||
|
|
||||||
public IEnumerable<OpenedFile> GetSourceFiles(out OpenedFile designerCodeFile) |
|
||||||
{ |
|
||||||
designerCodeFile = this.viewContent.DesignerCodeFile; |
|
||||||
return new [] {designerCodeFile}; |
|
||||||
} |
|
||||||
|
|
||||||
public void MergeFormChanges(CodeCompileUnit unit) |
|
||||||
{ |
|
||||||
} |
|
||||||
|
|
||||||
public void NotifyFormRenamed(string newName) |
|
||||||
{ |
|
||||||
} |
|
||||||
|
|
||||||
public void MergeRootComponentChanges(IDesignerHost host, IDesignerSerializationManager serializationManager) |
|
||||||
{ |
|
||||||
mergeChangesHost = host; |
|
||||||
mergeChangesSerializationManager = serializationManager; |
|
||||||
} |
|
||||||
|
|
||||||
public IDesignerHost MergeChangesHost { |
|
||||||
get { return mergeChangesHost; } |
|
||||||
} |
|
||||||
|
|
||||||
public IDesignerSerializationManager MergeChangesSerializationManager { |
|
||||||
get { return mergeChangesSerializationManager; } |
|
||||||
} |
|
||||||
|
|
||||||
public bool InsertComponentEvent(IComponent component, System.ComponentModel.EventDescriptor edesc, string eventMethodName, string body, out string file, out int position) |
|
||||||
{ |
|
||||||
throw new NotImplementedException(); |
|
||||||
} |
|
||||||
|
|
||||||
public ICollection GetCompatibleMethods(EventDescriptor edesc) |
|
||||||
{ |
|
||||||
throw new NotImplementedException(); |
|
||||||
} |
|
||||||
|
|
||||||
public ICollection GetCompatibleMethods(EventInfo edesc) |
|
||||||
{ |
|
||||||
throw new NotImplementedException(); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
@ -1,51 +0,0 @@ |
|||||||
// <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 ICSharpCode.FormsDesigner; |
|
||||||
|
|
||||||
namespace ICSharpCode.RubyBinding |
|
||||||
{ |
|
||||||
public class RubyNameCreationService : INameCreationService |
|
||||||
{ |
|
||||||
IDesignerHost host; |
|
||||||
XmlDesignerNameCreationService nameCreationService; |
|
||||||
|
|
||||||
public RubyNameCreationService(IDesignerHost host) |
|
||||||
{ |
|
||||||
this.host = host; |
|
||||||
nameCreationService = new XmlDesignerNameCreationService(host); |
|
||||||
} |
|
||||||
|
|
||||||
public string CreateName(IContainer container, Type dataType) |
|
||||||
{ |
|
||||||
return nameCreationService.CreateName(container, dataType); |
|
||||||
} |
|
||||||
|
|
||||||
public bool IsValidName(string name) |
|
||||||
{ |
|
||||||
if (!nameCreationService.IsValidName(name)) { |
|
||||||
return false; |
|
||||||
} |
|
||||||
|
|
||||||
if (host.Container != null) { |
|
||||||
return host.Container.Components[name] == null; |
|
||||||
} |
|
||||||
return true; |
|
||||||
} |
|
||||||
|
|
||||||
public void ValidateName(string name) |
|
||||||
{ |
|
||||||
if (!IsValidName(name)) { |
|
||||||
throw new Exception("Invalid name " + name); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,24 @@ |
|||||||
|
// <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.Design; |
||||||
|
using System.ComponentModel.Design.Serialization; |
||||||
|
|
||||||
|
using ICSharpCode.FormsDesigner; |
||||||
|
|
||||||
|
namespace ICSharpCode.Scripting |
||||||
|
{ |
||||||
|
public interface IScriptingDesignerGenerator : IDesignerGenerator |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Updates the form or user control's InitializeComponent method with any
|
||||||
|
/// changes to the designed form or user control.
|
||||||
|
/// </summary>
|
||||||
|
void MergeRootComponentChanges(IDesignerHost host, IDesignerSerializationManager serializationManager); |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue