Browse Source

Move IronPython and IronRuby designer loader code into the common Scripting project.

pull/1/head
mrward 15 years ago
parent
commit
dcf38c768d
  1. 2
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonComponentWalker.cs
  2. 144
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonDesignerLoader.cs
  3. 83
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GetComponentFromDesignerLoaderTestFixture.cs
  4. 64
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GetInstanceFromDesignerLoaderTestFixture.cs
  5. 90
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GetResourcesFromDesignerLoaderTestFixture.cs
  6. 28
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/NullGeneratorPassedToLoader.cs
  7. 177
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/PythonDesignerLoaderTestFixture.cs
  8. 6
      src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj
  9. 61
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/DerivedPythonDesignerLoader.cs
  10. 2
      src/AddIns/BackendBindings/Ruby/RubyBinding/Project/Src/RubyComponentWalker.cs
  11. 144
      src/AddIns/BackendBindings/Ruby/RubyBinding/Project/Src/RubyDesignerLoader.cs
  12. 83
      src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Designer/GetComponentFromDesignerLoaderTestFixture.cs
  13. 63
      src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Designer/GetInstanceFromDesignerLoaderTestFixture.cs
  14. 90
      src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Designer/GetResourcesFromDesignerLoaderTestFixture.cs
  15. 28
      src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Designer/NullGeneratorPassedToLoader.cs
  16. 184
      src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Designer/RubyDesignerLoaderTestFixture.cs
  17. 6
      src/AddIns/BackendBindings/Ruby/RubyBinding/Test/RubyBinding.Tests.csproj
  18. 66
      src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Utils/DerivedRubyDesignerLoader.cs
  19. 3
      src/AddIns/BackendBindings/Scripting/Project/ICSharpCode.Scripting.csproj
  20. 17
      src/AddIns/BackendBindings/Scripting/Project/Src/IComponentWalker.cs
  21. 156
      src/AddIns/BackendBindings/Scripting/Project/Src/ScriptingDesignerLoader.cs
  22. 127
      src/AddIns/BackendBindings/Scripting/Test/Designer/ScriptingDesignerLoaderGetResourcesTests.cs
  23. 404
      src/AddIns/BackendBindings/Scripting/Test/Designer/ScriptingDesignerLoaderTests.cs
  24. 5
      src/AddIns/BackendBindings/Scripting/Test/ICSharpCode.Scripting.Tests.csproj
  25. 6
      src/AddIns/BackendBindings/Scripting/Test/Utils/CreatedComponent.cs
  26. 24
      src/AddIns/BackendBindings/Scripting/Test/Utils/FakeComponentWalker.cs
  27. 113
      src/AddIns/BackendBindings/Scripting/Test/Utils/FakeDesignerSerializationManager.cs
  28. 4
      src/AddIns/BackendBindings/Scripting/Test/Utils/MockResourceService.cs
  29. 40
      src/AddIns/BackendBindings/Scripting/Test/Utils/TestableScriptingDesignerLoader.cs

2
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonComponentWalker.cs

@ -22,7 +22,7 @@ namespace ICSharpCode.PythonBinding @@ -22,7 +22,7 @@ namespace ICSharpCode.PythonBinding
/// <summary>
/// Visits the code's Python AST and creates a Windows Form.
/// </summary>
public class PythonComponentWalker : PythonWalker
public class PythonComponentWalker : PythonWalker, IComponentWalker
{
IComponent component;
PythonControlFieldExpression fieldExpression;

144
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonDesignerLoader.cs

@ -2,18 +2,7 @@ @@ -2,18 +2,7 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.CodeDom;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.ComponentModel.Design.Serialization;
using System.Globalization;
using System.Resources;
using System.Security.Permissions;
using ICSharpCode.FormsDesigner;
using ICSharpCode.FormsDesigner.Services;
using ICSharpCode.Scripting;
namespace ICSharpCode.PythonBinding
@ -24,141 +13,16 @@ namespace ICSharpCode.PythonBinding @@ -24,141 +13,16 @@ namespace ICSharpCode.PythonBinding
/// </summary>
[PermissionSet(SecurityAction.InheritanceDemand, Name="FullTrust")]
[PermissionSet(SecurityAction.LinkDemand, Name="FullTrust")]
public class PythonDesignerLoader : BasicDesignerLoader, IComponentCreator
public class PythonDesignerLoader : ScriptingDesignerLoader
{
IScriptingDesignerGenerator generator;
IDesignerSerializationManager serializationManager;
Dictionary<string, IComponent> addedObjects = new Dictionary<string, IComponent>();
public PythonDesignerLoader(IScriptingDesignerGenerator generator)
: base(generator)
{
if (generator == null) {
throw new ArgumentException("Generator cannot be null.", "generator");
}
this.generator = generator;
}
public override void BeginLoad(IDesignerLoaderHost host)
{
host.AddService(typeof(ComponentSerializationService), new CodeDomComponentSerializationService((IServiceProvider)host));
host.AddService(typeof(INameCreationService), new ScriptingNameCreationService(host));
host.AddService(typeof(IDesignerSerializationService), new DesignerSerializationService(host));
ProjectResourceService projectResourceService = host.GetService(typeof(ProjectResourceService)) as ProjectResourceService;
if (projectResourceService != null) {
projectResourceService.DesignerSupportsProjectResources = false;
}
base.BeginLoad(host);
}
/// <summary>
/// Creates a component of the specified type.
/// </summary>
public IComponent CreateComponent(Type componentClass, string name)
{
return base.LoaderHost.CreateComponent(componentClass, name);
}
/// <summary>
/// Adds a component.
/// </summary>
public void Add(IComponent component, string name)
{
base.LoaderHost.Container.Add(component, name);
addedObjects.Add(name, component);
}
/// <summary>
/// Gets a component that has been added to the loader.
/// </summary>
/// <returns>Null if the component cannot be found.</returns>
public IComponent GetComponent(string name)
{
IComponent component = null;
addedObjects.TryGetValue(name, out component);
return component;
}
/// <summary>
/// Gets the root component.
/// </summary>
public IComponent RootComponent {
get { return base.LoaderHost.RootComponent; }
}
/// <summary>
/// Creates a new instance of the specified type.
/// </summary>
public object CreateInstance(Type type, ICollection arguments, string name, bool addToContainer)
{
return serializationManager.CreateInstance(type, arguments, name, addToContainer);
}
/// <summary>
/// Gets an instance by name.
/// </summary>
public object GetInstance(string name)
{
return serializationManager.GetInstance(name);
}
/// <summary>
/// Gets the type given its name.
/// </summary>
public Type GetType(string typeName)
{
return serializationManager.GetType(typeName);
}
/// <summary>
/// Gets the property descriptor associated with the event.
/// </summary>
public PropertyDescriptor GetEventProperty(EventDescriptor e)
{
IEventBindingService eventBindingService = GetService(typeof(IEventBindingService)) as IEventBindingService;
return eventBindingService.GetEventProperty(e);
}
/// <summary>
/// Gets the resource reader for the specified culture.
/// </summary>
public IResourceReader GetResourceReader(CultureInfo info)
{
IResourceService resourceService = (IResourceService)LoaderHost.GetService(typeof(IResourceService));
if (resourceService != null) {
return resourceService.GetResourceReader(info);
}
return null;
}
/// <summary>
/// Gets the resource writer for the specified culture.
/// </summary>
public IResourceWriter GetResourceWriter(CultureInfo info)
{
IResourceService resourceService = (IResourceService)LoaderHost.GetService(typeof(IResourceService));
if (resourceService != null) {
return resourceService.GetResourceWriter(info);
}
return null;
}
/// <summary>
/// Passes the designer host's root component to the generator so it can update the
/// source code with changes made at design time.
/// </summary>
protected override void PerformFlush(IDesignerSerializationManager serializationManager)
protected override IComponentWalker CreateComponentWalker(IComponentCreator componentCreator)
{
generator.MergeRootComponentChanges(LoaderHost, serializationManager);
return new PythonComponentWalker(componentCreator);
}
protected override void PerformLoad(IDesignerSerializationManager serializationManager)
{
// Create designer root object.
this.serializationManager = serializationManager;
PythonComponentWalker visitor = new PythonComponentWalker(this);
visitor.CreateComponent(generator.ViewContent.DesignerCodeFileContent);
}
}
}

83
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GetComponentFromDesignerLoaderTestFixture.cs

@ -1,83 +0,0 @@ @@ -1,83 +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.Serialization;
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 the GetComponent method of the PythonDesignerLoader.
/// </summary>
[TestFixture]
public class GetComponentFromDesignerLoaderTestFixture
{
PythonDesignerLoader loader;
TextBox textBox;
MockDesignerLoaderHost host;
Label label;
[SetUp]
public void Init()
{
host = new MockDesignerLoaderHost();
loader = new PythonDesignerLoader(new MockDesignerGenerator());
loader.BeginLoad(host);
textBox = (TextBox)loader.CreateComponent(typeof(TextBox), "textBox1");
label = (Label)loader.CreateComponent(typeof(Label), "label1");
loader.Add(label, "label1");
}
[TearDown]
public void TearDown()
{
if (textBox != null) {
textBox.Dispose();
}
if (label != null) {
label.Dispose();
}
if (loader != null) {
loader.Dispose();
}
}
[Test]
public void LabelAddedToContainer()
{
Assert.AreEqual(label, host.Container.Components["label1"]);
}
[Test]
public void TextBoxIsNotAddedToContainer()
{
Assert.IsNull(host.Container.Components["textBox1"]);
}
[Test]
public void GetUnknownCreatedComponent()
{
Assert.IsNull(loader.GetComponent("unknown"));
}
[Test]
public void GetTextBoxComponent()
{
Assert.IsNull(loader.GetComponent("textBox1"));
}
[Test]
public void GetLabelComponent()
{
Assert.AreEqual(label, loader.GetComponent("label1"));
}
}
}

64
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GetInstanceFromDesignerLoaderTestFixture.cs

@ -1,64 +0,0 @@ @@ -1,64 +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.Serialization;
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 the GetInstance method of the PythonDesignerLoader.
/// </summary>
[TestFixture]
public class GetInstanceFromDesignerLoaderTestFixture
{
PythonDesignerLoader loader;
MockDesignerLoaderHost host;
ListViewItem listViewItem1;
object instance;
Type type;
string typeName;
[SetUp]
public void Init()
{
host = new MockDesignerLoaderHost();
loader = new PythonDesignerLoader(new MockDesignerGenerator());
loader.BeginLoad(host);
DesignerSerializationManager designerSerializationManager = (DesignerSerializationManager)host.GetService(typeof(IDesignerSerializationManager));
using (designerSerializationManager.CreateSession()) {
listViewItem1 = (ListViewItem)loader.CreateInstance(typeof(ListViewItem), new object[0], "listViewItem1", false);
instance = loader.GetInstance("listViewItem1");
typeName = typeof(Int32).FullName;
type = loader.GetType(typeName);
}
}
[Test]
public void GetListViewInstance()
{
Assert.AreEqual(listViewItem1, instance);
}
[Test]
public void GetTypeFromLoader()
{
Assert.AreEqual(typeof(Int32), type);
}
[Test]
public void TypeNameUsed()
{
Assert.AreEqual(typeName, host.TypeResolutionService.LastTypeNameResolved);
}
}
}

90
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GetResourcesFromDesignerLoaderTestFixture.cs

@ -1,90 +0,0 @@ @@ -1,90 +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.Globalization;
using System.Resources;
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 the GetResourceReader method of the PythonDesignerLoader.
/// </summary>
[TestFixture]
public class GetResourcesFromDesignerLoaderTestFixture
{
PythonDesignerLoader loader;
MockDesignerLoaderHost host;
MockResourceReader reader;
MockResourceService resourceService;
MockResourceReader dummyReader;
MockResourceWriter dummyWriter;
MockResourceWriter writer;
[SetUp]
public void Init()
{
dummyReader = new MockResourceReader();
dummyWriter = new MockResourceWriter();
resourceService = new MockResourceService();
resourceService.SetResourceReader(dummyReader);
resourceService.SetResourceWriter(dummyWriter);
host = new MockDesignerLoaderHost();
host.AddService(typeof(IResourceService), resourceService);
loader = new PythonDesignerLoader(new MockDesignerGenerator());
loader.BeginLoad(host);
reader = loader.GetResourceReader(CultureInfo.InvariantCulture) as MockResourceReader;
writer = loader.GetResourceWriter(CultureInfo.InvariantCulture) as MockResourceWriter;
}
[Test]
public void ResourceReaderInstance()
{
Assert.IsTrue(Object.ReferenceEquals(dummyReader, reader));
}
[Test]
public void CultureInfoPassedToResourceServiceForReader()
{
Assert.AreEqual(CultureInfo.InvariantCulture, resourceService.ResourceReaderCultureInfo);
}
[Test]
public void GetReaderWhenNoResourceService()
{
PythonDesignerLoader loader = new PythonDesignerLoader(new MockDesignerGenerator());
loader.BeginLoad(new MockDesignerLoaderHost());
Assert.IsNull(loader.GetResourceReader(CultureInfo.InvariantCulture));
}
[Test]
public void GetWriterWhenNoResourceService()
{
PythonDesignerLoader loader = new PythonDesignerLoader(new MockDesignerGenerator());
loader.BeginLoad(new MockDesignerLoaderHost());
Assert.IsNull(loader.GetResourceWriter(CultureInfo.InvariantCulture));
}
[Test]
public void ResourceWriterInstance()
{
Assert.IsTrue(Object.ReferenceEquals(dummyWriter, writer));
}
[Test]
public void CultureInfoPassedToResourceServiceForWriter()
{
Assert.AreEqual(CultureInfo.InvariantCulture, resourceService.ResourceWriterCultureInfo);
}
}
}

28
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/NullGeneratorPassedToLoader.cs

@ -1,28 +0,0 @@ @@ -1,28 +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 ICSharpCode.PythonBinding;
using NUnit.Framework;
namespace PythonBinding.Tests.Designer
{
/// <summary>
/// Tests that the PythonDesignerLoader throws an exception
/// when created with a null IDesignerGenerator.
/// </summary>
[TestFixture]
public class NullGeneratorPassedToLoader
{
[Test]
public void ThrowsException()
{
try {
PythonDesignerLoader loader = new PythonDesignerLoader(null);
Assert.Fail("Expected an argument exception before this line.");
} catch (ArgumentException ex) {
Assert.AreEqual("generator", ex.ParamName);
}
}
}
}

177
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/PythonDesignerLoaderTestFixture.cs

@ -1,177 +0,0 @@ @@ -1,177 +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.CodeDom;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.ComponentModel.Design.Serialization;
using System.IO;
using System.Windows.Forms;
using ICSharpCode.FormsDesigner;
using ICSharpCode.FormsDesigner.Services;
using ICSharpCode.PythonBinding;
using ICSharpCode.Scripting;
using ICSharpCode.Scripting.Tests.Utils;
using NUnit.Framework;
using PythonBinding.Tests.Utils;
namespace PythonBinding.Tests.Designer
{
/// <summary>
/// Tests basic operation of the PythonDesignerLoader.
/// </summary>
[TestFixture]
public class PythonDesignerLoaderTestFixture
{
FormsDesignerViewContent view;
DerivedPythonDesignerLoader loader;
MockDesignerGenerator generator;
MockTypeResolutionService mockTypeResolutionService;
MockDesignerLoaderHost mockDesignerLoaderHost;
MockExtenderProviderService mockExtenderProviderService;
IComponent rootComponent;
Form designedForm;
MockEventBindingService mockEventBindingService;
MockResourceService mockResourceService;
DesignerSerializationManager serializationManager;
[TestFixtureSetUp]
public void SetUpFixture()
{
generator = new MockDesignerGenerator();
view = new FormsDesignerViewContent(new MockViewContent(), new MockOpenedFile("Test.py"));
generator.Attach(view);
view.DesignerCodeFileContent = GetFormCode();
loader = new DerivedPythonDesignerLoader(generator);
// Begin load.
mockDesignerLoaderHost = new MockDesignerLoaderHost();
mockResourceService = new MockResourceService();
mockDesignerLoaderHost.AddService(typeof(IResourceService), mockResourceService);
mockTypeResolutionService = mockDesignerLoaderHost.TypeResolutionService;
mockExtenderProviderService = new MockExtenderProviderService();
mockDesignerLoaderHost.AddService(typeof(IExtenderProviderService), mockExtenderProviderService);
mockDesignerLoaderHost.AddService(typeof(ProjectResourceService), new ProjectResourceService(new MockProjectContent()));
mockEventBindingService = new MockEventBindingService();
mockDesignerLoaderHost.AddService(typeof(IEventBindingService), mockEventBindingService);
serializationManager = new DesignerSerializationManager(mockDesignerLoaderHost);
loader.BeginLoad(mockDesignerLoaderHost);
rootComponent = mockDesignerLoaderHost.RootComponent;
designedForm = new Form();
designedForm.Name = "NewMainForm";
mockDesignerLoaderHost.RootComponent = designedForm;
loader.CallPerformFlush(serializationManager);
}
[TestFixtureTearDown]
public void TearDownFixture()
{
loader.Dispose();
designedForm.Dispose();
}
[Test]
public void IsDerivedFromBasicDesignerLoader()
{
BasicDesignerLoader basicLoader = loader as BasicDesignerLoader;
Assert.IsNotNull(basicLoader);
}
[Test]
public void CreateComponent()
{
List<CreatedComponent> expectedCreatedComponents = new List<CreatedComponent>();
expectedCreatedComponents.Add(new CreatedComponent(typeof(Form).FullName, "MainForm", null));
Assert.AreEqual(expectedCreatedComponents, mockDesignerLoaderHost.CreatedComponents);
}
[Test]
public void ComponentSerializationServiceCreated()
{
CodeDomComponentSerializationService service = mockDesignerLoaderHost.GetService(typeof(ComponentSerializationService)) as CodeDomComponentSerializationService;
Assert.IsNotNull(service);
}
[Test]
public void NameCreationServiceCreated()
{
ScriptingNameCreationService service = mockDesignerLoaderHost.GetService(typeof(INameCreationService)) as ScriptingNameCreationService;
Assert.IsNotNull(service);
}
[Test]
public void DesignerSerializationServiceCreated()
{
DesignerSerializationService service = mockDesignerLoaderHost.GetService(typeof(IDesignerSerializationService)) as DesignerSerializationService;
Assert.IsNotNull(service);
}
[Test]
public void ProjectResourceServiceDesignerDoesNotSupportProjectResources()
{
ProjectResourceService service = mockDesignerLoaderHost.GetService(typeof(ProjectResourceService)) as ProjectResourceService;
Assert.IsFalse(service.DesignerSupportsProjectResources);
}
[Test]
public void RootDesignerComponentNameIsMainForm()
{
Form form = rootComponent as Form;
Assert.AreEqual("MainForm", form.Name);
}
[Test]
public void PerformFlushUsesDesignerHost()
{
Assert.AreEqual(mockDesignerLoaderHost, generator.MergeChangesHost);
}
[Test]
public void GetEventPropertyUsesEventBindingService()
{
IEventBindingService eventBindingService = (IEventBindingService)mockEventBindingService;
EventDescriptor e = TypeDescriptor.GetEvents(typeof(Form)).Find("Load", true);
PropertyDescriptor expectedProperty = eventBindingService.GetEventProperty(e);
Assert.AreEqual(expectedProperty, loader.GetEventProperty(e));
}
[Test]
public void GetRootComponentFromLoader()
{
Assert.AreEqual(designedForm, loader.RootComponent);
}
[Test]
public void SerializationManagerPassedToMergeRootComponentMethod()
{
Assert.IsTrue(Object.ReferenceEquals(serializationManager, generator.MergeChangesSerializationManager));
}
/// <summary>
/// The code that the designer loader will parse.
/// </summary>
string GetFormCode()
{
return "from System.Windows.Forms import Form\r\n" +
"\r\n" +
"class MainForm(Form):\r\n" +
"\tdef __init__(self):\r\n" +
"\t\tself.InitializeComponents()\r\n" +
"\t\r\n" +
"\tdef InitializeComponents(self):\r\n" +
"\t\tself.Name = 'MainForm'\r\n";
}
}
}

6
src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj

@ -253,9 +253,6 @@ @@ -253,9 +253,6 @@
<Compile Include="Designer\GenerateToolTipFormTestFixture.cs" />
<Compile Include="Designer\GenerateTreeViewTestFixture.cs" />
<Compile Include="Designer\GeneratorMergeFindsInitializeComponentsTestFixture.cs" />
<Compile Include="Designer\GetComponentFromDesignerLoaderTestFixture.cs" />
<Compile Include="Designer\GetInstanceFromDesignerLoaderTestFixture.cs" />
<Compile Include="Designer\GetResourcesFromDesignerLoaderTestFixture.cs" />
<Compile Include="Designer\IgnoreDesignTimePropertiesTestFixture.cs" />
<Compile Include="Designer\InsertEventHandlerTestFixtureBase.cs" />
<Compile Include="Designer\InsertEventHandlerWithSpaceIndentTestFixture.cs" />
@ -305,9 +302,7 @@ @@ -305,9 +302,7 @@
<Compile Include="Designer\PythonControlFieldExpressionTests.cs" />
<Compile Include="Designer\PythonGeneratorTestFixture.cs" />
<Compile Include="Designer\IsFormDesignableTestFixture.cs" />
<Compile Include="Designer\NullGeneratorPassedToLoader.cs" />
<Compile Include="Designer\PythonDesignerLoaderProviderTestFixture.cs" />
<Compile Include="Designer\PythonDesignerLoaderTestFixture.cs" />
<Compile Include="Designer\PythonPropertyAssignmentToStringTests.cs" />
<Compile Include="Designer\RemoveMainMenuStripFromFormTestFixture.cs" />
<Compile Include="Designer\TextBoxNotAddedToFormTestFixture.cs" />
@ -431,7 +426,6 @@ @@ -431,7 +426,6 @@
<Compile Include="Utils\DerivedPythonCodeCompletionBinding.cs" />
<Compile Include="Utils\DerivedPythonConsoleHost.cs" />
<Compile Include="Utils\DerivedPythonDesignerGenerator.cs" />
<Compile Include="Utils\DerivedPythonDesignerLoader.cs" />
<Compile Include="Utils\DerivedPythonFormsDesignerDisplayBinding.cs" />
<Compile Include="Utils\PythonMSBuildEngineHelper.cs" />
<Compile Include="Utils\TestablePythonConsole.cs" />

61
src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/DerivedPythonDesignerLoader.cs

@ -1,61 +0,0 @@ @@ -1,61 +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.CodeDom;
using System.CodeDom.Compiler;
using System.Collections;
using System.ComponentModel.Design;
using System.ComponentModel.Design.Serialization;
using System.IO;
using ICSharpCode.FormsDesigner;
using ICSharpCode.PythonBinding;
using ICSharpCode.Scripting;
namespace PythonBinding.Tests.Utils
{
/// <summary>
/// PythonDesignerLoader derived class that provides access to
/// various protected methods so we can use them when testing.
/// </summary>
public class DerivedPythonDesignerLoader : PythonDesignerLoader
{
public DerivedPythonDesignerLoader(IScriptingDesignerGenerator generator) : base(generator)
{
}
public void CallPerformFlush(IDesignerSerializationManager serializationManager)
{
base.PerformFlush(serializationManager);
}
protected override void OnEndLoad(bool successful, ICollection errors)
{
if (errors != null) {
foreach (object o in errors) {
Exception ex = o as Exception;
if (ex != null) {
System.Console.WriteLine("DesignerLoader.OnEndLoad: Exception: " + ex.ToString());
}
}
}
base.OnEndLoad(successful, errors);
}
protected override void OnBeginLoad()
{
base.OnBeginLoad();
}
protected override void Initialize()
{
base.Initialize();
}
protected override void PerformLoad(IDesignerSerializationManager manager)
{
base.PerformLoad(manager);
}
}
}

2
src/AddIns/BackendBindings/Ruby/RubyBinding/Project/Src/RubyComponentWalker.cs

@ -25,7 +25,7 @@ namespace ICSharpCode.RubyBinding @@ -25,7 +25,7 @@ namespace ICSharpCode.RubyBinding
/// <summary>
/// Visits the code's Ruby AST and creates a Windows Form.
/// </summary>
public class RubyComponentWalker : Walker
public class RubyComponentWalker : Walker, IComponentWalker
{
IComponent component;
IComponentCreator componentCreator;

144
src/AddIns/BackendBindings/Ruby/RubyBinding/Project/Src/RubyDesignerLoader.cs

@ -2,18 +2,7 @@ @@ -2,18 +2,7 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.CodeDom;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.ComponentModel.Design.Serialization;
using System.Globalization;
using System.Resources;
using System.Security.Permissions;
using ICSharpCode.FormsDesigner;
using ICSharpCode.FormsDesigner.Services;
using ICSharpCode.Scripting;
namespace ICSharpCode.RubyBinding
@ -24,141 +13,16 @@ namespace ICSharpCode.RubyBinding @@ -24,141 +13,16 @@ namespace ICSharpCode.RubyBinding
/// </summary>
[PermissionSet(SecurityAction.InheritanceDemand, Name="FullTrust")]
[PermissionSet(SecurityAction.LinkDemand, Name="FullTrust")]
public class RubyDesignerLoader : BasicDesignerLoader, IComponentCreator
public class RubyDesignerLoader : ScriptingDesignerLoader
{
IScriptingDesignerGenerator generator;
IDesignerSerializationManager serializationManager;
Dictionary<string, IComponent> addedObjects = new Dictionary<string, IComponent>();
public RubyDesignerLoader(IScriptingDesignerGenerator generator)
: base(generator)
{
if (generator == null) {
throw new ArgumentException("Generator cannot be null.", "generator");
}
this.generator = generator;
}
public override void BeginLoad(IDesignerLoaderHost host)
{
host.AddService(typeof(ComponentSerializationService), new CodeDomComponentSerializationService((IServiceProvider)host));
host.AddService(typeof(INameCreationService), new ScriptingNameCreationService(host));
host.AddService(typeof(IDesignerSerializationService), new DesignerSerializationService(host));
ProjectResourceService projectResourceService = host.GetService(typeof(ProjectResourceService)) as ProjectResourceService;
if (projectResourceService != null) {
projectResourceService.DesignerSupportsProjectResources = false;
}
base.BeginLoad(host);
}
/// <summary>
/// Creates a component of the specified type.
/// </summary>
public IComponent CreateComponent(Type componentClass, string name)
{
return base.LoaderHost.CreateComponent(componentClass, name);
}
/// <summary>
/// Adds a component.
/// </summary>
public void Add(IComponent component, string name)
{
base.LoaderHost.Container.Add(component, name);
addedObjects.Add(name, component);
}
/// <summary>
/// Gets a component that has been added to the loader.
/// </summary>
/// <returns>Null if the component cannot be found.</returns>
public IComponent GetComponent(string name)
{
IComponent component = null;
addedObjects.TryGetValue(name, out component);
return component;
}
/// <summary>
/// Gets the root component.
/// </summary>
public IComponent RootComponent {
get { return base.LoaderHost.RootComponent; }
}
/// <summary>
/// Creates a new instance of the specified type.
/// </summary>
public object CreateInstance(Type type, ICollection arguments, string name, bool addToContainer)
{
return serializationManager.CreateInstance(type, arguments, name, addToContainer);
}
/// <summary>
/// Gets an instance by name.
/// </summary>
public object GetInstance(string name)
{
return serializationManager.GetInstance(name);
}
/// <summary>
/// Gets the type given its name.
/// </summary>
public Type GetType(string typeName)
{
return serializationManager.GetType(typeName);
}
/// <summary>
/// Gets the property descriptor associated with the event.
/// </summary>
public PropertyDescriptor GetEventProperty(EventDescriptor e)
{
IEventBindingService eventBindingService = GetService(typeof(IEventBindingService)) as IEventBindingService;
return eventBindingService.GetEventProperty(e);
}
/// <summary>
/// Gets the resource reader for the specified culture.
/// </summary>
public IResourceReader GetResourceReader(CultureInfo info)
{
IResourceService resourceService = (IResourceService)LoaderHost.GetService(typeof(IResourceService));
if (resourceService != null) {
return resourceService.GetResourceReader(info);
}
return null;
}
/// <summary>
/// Gets the resource writer for the specified culture.
/// </summary>
public IResourceWriter GetResourceWriter(CultureInfo info)
{
IResourceService resourceService = (IResourceService)LoaderHost.GetService(typeof(IResourceService));
if (resourceService != null) {
return resourceService.GetResourceWriter(info);
}
return null;
}
/// <summary>
/// Passes the designer host's root component to the generator so it can update the
/// source code with changes made at design time.
/// </summary>
protected override void PerformFlush(IDesignerSerializationManager serializationManager)
protected override IComponentWalker CreateComponentWalker(IComponentCreator componentCreator)
{
generator.MergeRootComponentChanges(LoaderHost, serializationManager);
return new RubyComponentWalker(componentCreator);
}
protected override void PerformLoad(IDesignerSerializationManager serializationManager)
{
// Create designer root object.
this.serializationManager = serializationManager;
RubyComponentWalker visitor = new RubyComponentWalker(this);
visitor.CreateComponent(generator.ViewContent.DesignerCodeFileContent);
}
}
}

83
src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Designer/GetComponentFromDesignerLoaderTestFixture.cs

@ -1,83 +0,0 @@ @@ -1,83 +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.Serialization;
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 the GetComponent method of the RubyDesignerLoader.
/// </summary>
[TestFixture]
public class GetComponentFromDesignerLoaderTestFixture
{
RubyDesignerLoader loader;
TextBox textBox;
MockDesignerLoaderHost host;
Label label;
[SetUp]
public void Init()
{
host = new MockDesignerLoaderHost();
loader = new RubyDesignerLoader(new MockDesignerGenerator());
loader.BeginLoad(host);
textBox = (TextBox)loader.CreateComponent(typeof(TextBox), "textBox1");
label = (Label)loader.CreateComponent(typeof(Label), "label1");
loader.Add(label, "label1");
}
[TearDown]
public void TearDown()
{
if (textBox != null) {
textBox.Dispose();
}
if (label != null) {
label.Dispose();
}
if (loader != null) {
loader.Dispose();
}
}
[Test]
public void LabelAddedToContainer()
{
Assert.AreEqual(label, host.Container.Components["label1"]);
}
[Test]
public void TextBoxIsNotAddedToContainer()
{
Assert.IsNull(host.Container.Components["textBox1"]);
}
[Test]
public void GetUnknownCreatedComponent()
{
Assert.IsNull(loader.GetComponent("unknown"));
}
[Test]
public void GetTextBoxComponent()
{
Assert.IsNull(loader.GetComponent("textBox1"));
}
[Test]
public void GetLabelComponent()
{
Assert.AreEqual(label, loader.GetComponent("label1"));
}
}
}

63
src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Designer/GetInstanceFromDesignerLoaderTestFixture.cs

@ -1,63 +0,0 @@ @@ -1,63 +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.Serialization;
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 the GetInstance method of the RubyDesignerLoader.
/// </summary>
[TestFixture]
public class GetInstanceFromDesignerLoaderTestFixture
{
RubyDesignerLoader loader;
MockDesignerLoaderHost host;
ListViewItem listViewItem1;
object instance;
Type type;
string typeName;
[SetUp]
public void Init()
{
host = new MockDesignerLoaderHost();
loader = new RubyDesignerLoader(new MockDesignerGenerator());
loader.BeginLoad(host);
DesignerSerializationManager designerSerializationManager = (DesignerSerializationManager)host.GetService(typeof(IDesignerSerializationManager));
using (designerSerializationManager.CreateSession()) {
listViewItem1 = (ListViewItem)loader.CreateInstance(typeof(ListViewItem), new object[0], "listViewItem1", false);
instance = loader.GetInstance("listViewItem1");
typeName = typeof(Int32).FullName;
type = loader.GetType(typeName);
}
}
[Test]
public void GetListViewInstance()
{
Assert.AreEqual(listViewItem1, instance);
}
[Test]
public void GetTypeFromLoader()
{
Assert.AreEqual(typeof(Int32), type);
}
[Test]
public void TypeNameUsed()
{
Assert.AreEqual(typeName, host.TypeResolutionService.LastTypeNameResolved);
}
}
}

90
src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Designer/GetResourcesFromDesignerLoaderTestFixture.cs

@ -1,90 +0,0 @@ @@ -1,90 +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.Globalization;
using System.Resources;
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 the GetResourceReader method of the RubyDesignerLoader.
/// </summary>
[TestFixture]
public class GetResourcesFromDesignerLoaderTestFixture
{
RubyDesignerLoader loader;
MockDesignerLoaderHost host;
MockResourceReader reader;
MockResourceService resourceService;
MockResourceReader dummyReader;
MockResourceWriter dummyWriter;
MockResourceWriter writer;
[SetUp]
public void Init()
{
dummyReader = new MockResourceReader();
dummyWriter = new MockResourceWriter();
resourceService = new MockResourceService();
resourceService.SetResourceReader(dummyReader);
resourceService.SetResourceWriter(dummyWriter);
host = new MockDesignerLoaderHost();
host.AddService(typeof(IResourceService), resourceService);
loader = new RubyDesignerLoader(new MockDesignerGenerator());
loader.BeginLoad(host);
reader = loader.GetResourceReader(CultureInfo.InvariantCulture) as MockResourceReader;
writer = loader.GetResourceWriter(CultureInfo.InvariantCulture) as MockResourceWriter;
}
[Test]
public void ResourceReaderInstance()
{
Assert.IsTrue(Object.ReferenceEquals(dummyReader, reader));
}
[Test]
public void CultureInfoPassedToResourceServiceForReader()
{
Assert.AreEqual(CultureInfo.InvariantCulture, resourceService.ResourceReaderCultureInfo);
}
[Test]
public void GetReaderWhenNoResourceService()
{
RubyDesignerLoader loader = new RubyDesignerLoader(new MockDesignerGenerator());
loader.BeginLoad(new MockDesignerLoaderHost());
Assert.IsNull(loader.GetResourceReader(CultureInfo.InvariantCulture));
}
[Test]
public void GetWriterWhenNoResourceService()
{
RubyDesignerLoader loader = new RubyDesignerLoader(new MockDesignerGenerator());
loader.BeginLoad(new MockDesignerLoaderHost());
Assert.IsNull(loader.GetResourceWriter(CultureInfo.InvariantCulture));
}
[Test]
public void ResourceWriterInstance()
{
Assert.IsTrue(Object.ReferenceEquals(dummyWriter, writer));
}
[Test]
public void CultureInfoPassedToResourceServiceForWriter()
{
Assert.AreEqual(CultureInfo.InvariantCulture, resourceService.ResourceWriterCultureInfo);
}
}
}

28
src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Designer/NullGeneratorPassedToLoader.cs

@ -1,28 +0,0 @@ @@ -1,28 +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 ICSharpCode.RubyBinding;
using NUnit.Framework;
namespace RubyBinding.Tests.Designer
{
/// <summary>
/// Tests that the RubyDesignerLoader throws an exception
/// when created with a null IDesignerGenerator.
/// </summary>
[TestFixture]
public class NullGeneratorPassedToLoader
{
[Test]
public void ThrowsException()
{
try {
RubyDesignerLoader loader = new RubyDesignerLoader(null);
Assert.Fail("Expected an argument exception before this line.");
} catch (ArgumentException ex) {
Assert.AreEqual("generator", ex.ParamName);
}
}
}
}

184
src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Designer/RubyDesignerLoaderTestFixture.cs

@ -1,184 +0,0 @@ @@ -1,184 +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.CodeDom;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.ComponentModel.Design.Serialization;
using System.IO;
using System.Windows.Forms;
using ICSharpCode.FormsDesigner;
using ICSharpCode.FormsDesigner.Services;
using ICSharpCode.RubyBinding;
using ICSharpCode.Scripting;
using ICSharpCode.Scripting.Tests.Utils;
using NUnit.Framework;
using RubyBinding.Tests.Utils;
namespace RubyBinding.Tests.Designer
{
/// <summary>
/// Tests basic operation of the RubyDesignerLoader.
/// </summary>
[TestFixture]
public class RubyDesignerLoaderTestFixture
{
FormsDesignerViewContent view;
DerivedRubyDesignerLoader loader;
MockDesignerGenerator generator;
MockTypeResolutionService mockTypeResolutionService;
MockDesignerLoaderHost mockDesignerLoaderHost;
MockExtenderProviderService mockExtenderProviderService;
IComponent rootComponent;
Form designedForm;
MockEventBindingService mockEventBindingService;
MockResourceService mockResourceService;
DesignerSerializationManager serializationManager;
[TestFixtureSetUp]
public void SetUpFixture()
{
generator = new MockDesignerGenerator();
view = new FormsDesignerViewContent(new MockViewContent(), new MockOpenedFile("Test.rb"));
generator.Attach(view);
view.DesignerCodeFileContent = GetFormCode();
loader = new DerivedRubyDesignerLoader(generator);
// Begin load.
mockDesignerLoaderHost = new MockDesignerLoaderHost();
mockResourceService = new MockResourceService();
mockDesignerLoaderHost.AddService(typeof(IResourceService), mockResourceService);
mockTypeResolutionService = mockDesignerLoaderHost.TypeResolutionService;
mockExtenderProviderService = new MockExtenderProviderService();
mockDesignerLoaderHost.AddService(typeof(IExtenderProviderService), mockExtenderProviderService);
mockDesignerLoaderHost.AddService(typeof(ProjectResourceService), new ProjectResourceService(new MockProjectContent()));
mockEventBindingService = new MockEventBindingService();
mockDesignerLoaderHost.AddService(typeof(IEventBindingService), mockEventBindingService);
serializationManager = new DesignerSerializationManager(mockDesignerLoaderHost);
System.Console.WriteLine("Before BeginLoad");
loader.BeginLoad(mockDesignerLoaderHost);
System.Console.WriteLine("After BeginLoad");
rootComponent = mockDesignerLoaderHost.RootComponent;
designedForm = new Form();
designedForm.Name = "NewMainForm";
mockDesignerLoaderHost.RootComponent = designedForm;
loader.CallPerformFlush(serializationManager);
}
[TestFixtureTearDown]
public void TearDownFixture()
{
loader.Dispose();
designedForm.Dispose();
}
[Test]
public void IsDerivedFromBasicDesignerLoader()
{
BasicDesignerLoader basicLoader = loader as BasicDesignerLoader;
Assert.IsNotNull(basicLoader);
}
[Test]
public void CreateComponent()
{
List<CreatedComponent> expectedCreatedComponents = new List<CreatedComponent>();
expectedCreatedComponents.Add(new CreatedComponent(typeof(Form).FullName, "MainForm", null));
Assert.AreEqual(expectedCreatedComponents, mockDesignerLoaderHost.CreatedComponents);
}
[Test]
public void ComponentSerializationServiceCreated()
{
CodeDomComponentSerializationService service = mockDesignerLoaderHost.GetService(typeof(ComponentSerializationService)) as CodeDomComponentSerializationService;
Assert.IsNotNull(service);
}
[Test]
public void NameCreationServiceCreated()
{
ScriptingNameCreationService service = mockDesignerLoaderHost.GetService(typeof(INameCreationService)) as ScriptingNameCreationService;
Assert.IsNotNull(service);
}
[Test]
public void DesignerSerializationServiceCreated()
{
DesignerSerializationService service = mockDesignerLoaderHost.GetService(typeof(IDesignerSerializationService)) as DesignerSerializationService;
Assert.IsNotNull(service);
}
[Test]
public void ProjectResourceServiceDesignerDoesNotSupportProjectResources()
{
ProjectResourceService service = mockDesignerLoaderHost.GetService(typeof(ProjectResourceService)) as ProjectResourceService;
Assert.IsFalse(service.DesignerSupportsProjectResources);
}
[Test]
public void RootDesignerComponentNameIsMainForm()
{
Form form = rootComponent as Form;
Assert.AreEqual("MainForm", form.Name);
}
[Test]
public void PerformFlushUsesDesignerHost()
{
Assert.AreEqual(mockDesignerLoaderHost, generator.MergeChangesHost);
}
[Test]
public void GetEventPropertyUsesEventBindingService()
{
IEventBindingService eventBindingService = (IEventBindingService)mockEventBindingService;
EventDescriptor e = TypeDescriptor.GetEvents(typeof(Form)).Find("Load", true);
PropertyDescriptor expectedProperty = eventBindingService.GetEventProperty(e);
Assert.AreEqual(expectedProperty, loader.GetEventProperty(e));
}
[Test]
public void GetRootComponentFromLoader()
{
Assert.AreEqual(designedForm, loader.RootComponent);
}
[Test]
public void SerializationManagerPassedToMergeRootComponentMethod()
{
Assert.IsTrue(Object.ReferenceEquals(serializationManager, generator.MergeChangesSerializationManager));
}
/// <summary>
/// The code that the designer loader will parse.
/// </summary>
string GetFormCode()
{
return "require \"mscorlib\"\r\n" +
"require \"System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\"\r\n" +
"require \"System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a\"\r\n" +
"\r\n" +
"class MainForm < System::Windows::Forms::Form\r\n" +
"\tdef initialize()\r\n" +
"\t\tself.InitializeComponents()\r\n" +
"\tend\r\n" +
"\t\r\n" +
"\tdef InitializeComponents()\r\n" +
"\t\tself.Name = 'MainForm'\r\n" +
"\tend\r\n" +
"end";
}
}
}

6
src/AddIns/BackendBindings/Ruby/RubyBinding/Test/RubyBinding.Tests.csproj

@ -228,9 +228,6 @@ @@ -228,9 +228,6 @@
<Compile Include="Designer\GenerateToolTipFormTestFixture.cs" />
<Compile Include="Designer\GenerateTreeViewTestFixture.cs" />
<Compile Include="Designer\GeneratorMergeFindsInitializeComponentsTestFixture.cs" />
<Compile Include="Designer\GetComponentFromDesignerLoaderTestFixture.cs" />
<Compile Include="Designer\GetInstanceFromDesignerLoaderTestFixture.cs" />
<Compile Include="Designer\GetResourcesFromDesignerLoaderTestFixture.cs" />
<Compile Include="Designer\IgnoreDesignTimePropertiesTestFixture.cs" />
<Compile Include="Designer\InsertEventHandlerTestFixtureBase.cs" />
<Compile Include="Designer\InsertEventHandlerWithSpaceIndentTestFixture.cs" />
@ -273,7 +270,6 @@ @@ -273,7 +270,6 @@
<Compile Include="Designer\MergeFormTestFixture.cs" />
<Compile Include="Designer\MissingInitializeComponentMethodTestFixture.cs" />
<Compile Include="Designer\NoNewLineAfterInitializeComponentMethodTestFixture.cs" />
<Compile Include="Designer\NullGeneratorPassedToLoader.cs" />
<Compile Include="Designer\OneCompatibleMethodTestFixture.cs" />
<Compile Include="Designer\ProjectRootNamespacePassedToMergeTestFixture.cs" />
<Compile Include="Designer\RemoveMainMenuStripFromFormTestFixture.cs" />
@ -282,7 +278,6 @@ @@ -282,7 +278,6 @@
<Compile Include="Designer\RubyCodeDeserializerTests.cs" />
<Compile Include="Designer\RubyControlFieldExpressionTests.cs" />
<Compile Include="Designer\RubyDesignerLoaderProviderTestFixture.cs" />
<Compile Include="Designer\RubyDesignerLoaderTestFixture.cs" />
<Compile Include="Designer\RubyDesignerGeneratorTestFixture.cs" />
<Compile Include="Designer\RubyPropertyAssignmentToStringTests.cs" />
<Compile Include="Designer\TextBoxNotAddedToFormTestFixture.cs" />
@ -325,7 +320,6 @@ @@ -325,7 +320,6 @@
<Compile Include="Utils\DerivedRubyAddInOptions.cs" />
<Compile Include="Utils\DerivedRubyConsoleHost.cs" />
<Compile Include="Utils\DerivedRubyDesignerGenerator.cs" />
<Compile Include="Utils\DerivedRubyDesignerLoader.cs" />
<Compile Include="Utils\DerivedRubyFormsDesignerDisplayBinding.cs" />
<Compile Include="Utils\RubyBindingAddInFile.cs" />
<Compile Include="Utils\RubyMSBuildEngineHelper.cs" />

66
src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Utils/DerivedRubyDesignerLoader.cs

@ -1,66 +0,0 @@ @@ -1,66 +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.CodeDom;
using System.CodeDom.Compiler;
using System.Collections;
using System.ComponentModel.Design;
using System.ComponentModel.Design.Serialization;
using System.IO;
using ICSharpCode.FormsDesigner;
using ICSharpCode.RubyBinding;
using ICSharpCode.Scripting;
namespace RubyBinding.Tests.Utils
{
/// <summary>
/// RubyDesignerLoader derived class that provides access to
/// various protected methods so we can use them when testing.
/// </summary>
public class DerivedRubyDesignerLoader : RubyDesignerLoader
{
public DerivedRubyDesignerLoader(IScriptingDesignerGenerator generator) : base(generator)
{
}
public void CallPerformFlush(IDesignerSerializationManager serializationManager)
{
base.PerformFlush(serializationManager);
}
protected override void OnEndLoad(bool successful, ICollection errors)
{
System.Console.WriteLine("DesignerLoader.OnEndLoad: successful: " + successful);
if (errors != null) {
foreach (object o in errors) {
Exception ex = o as Exception;
if (ex != null) {
System.Console.WriteLine("DesignerLoader.OnEndLoad: Exception: " + ex.ToString());
}
}
}
base.OnEndLoad(successful, errors);
}
protected override void OnBeginLoad()
{
System.Console.WriteLine("DesignerLoader.OnBeginLoad");
base.OnBeginLoad();
}
protected override void Initialize()
{
System.Console.WriteLine("DesignerLoader.Initialize");
base.Initialize();
}
protected override void PerformLoad(IDesignerSerializationManager manager)
{
System.Console.WriteLine("DesignerLoader.PerformLoad Before");
base.PerformLoad(manager);
System.Console.WriteLine("DesignerLoader.PerformLoad After");
}
}
}

3
src/AddIns/BackendBindings/Scripting/Project/ICSharpCode.Scripting.csproj

@ -43,6 +43,7 @@ @@ -43,6 +43,7 @@
<RequiredTargetFramework>3.0</RequiredTargetFramework>
</Reference>
<Reference Include="System" />
<Reference Include="System.Design" />
<Reference Include="System.Drawing" />
<Reference Include="System.Xaml">
<RequiredTargetFramework>4.0</RequiredTargetFramework>
@ -66,6 +67,7 @@ @@ -66,6 +67,7 @@
<Compile Include="Src\ControlDispatcher.cs" />
<Compile Include="Src\CreateTextWriterInfo.cs" />
<Compile Include="Src\IComponentCreator.cs" />
<Compile Include="Src\IComponentWalker.cs" />
<Compile Include="Src\IControlDispatcher.cs" />
<Compile Include="Src\ILock.cs" />
<Compile Include="Src\IMemberProvider.cs" />
@ -81,6 +83,7 @@ @@ -81,6 +83,7 @@
<Compile Include="Src\ScriptingConsoleOutputStream.cs" />
<Compile Include="Src\ScriptingConsoleTextEditor.cs" />
<Compile Include="Src\ScriptingConsoleTextEditorKeyEventArgs.cs" />
<Compile Include="Src\ScriptingDesignerLoader.cs" />
<Compile Include="Src\ScriptingFileService.cs" />
<Compile Include="Src\ScriptingNameCreationService.cs" />
<Compile Include="Src\ScriptingTextEditorViewContent.cs" />

17
src/AddIns/BackendBindings/Scripting/Project/Src/IComponentWalker.cs

@ -0,0 +1,17 @@ @@ -0,0 +1,17 @@
// <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;
namespace ICSharpCode.Scripting
{
public interface IComponentWalker
{
IComponent CreateComponent(string code);
}
}

156
src/AddIns/BackendBindings/Scripting/Project/Src/ScriptingDesignerLoader.cs

@ -0,0 +1,156 @@ @@ -0,0 +1,156 @@
// 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.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.ComponentModel.Design.Serialization;
using System.Globalization;
using System.Resources;
using System.Security.Permissions;
using ICSharpCode.FormsDesigner.Services;
namespace ICSharpCode.Scripting
{
/// <summary>
/// Loads the form or control's code so the forms designer can
/// display it.
/// </summary>
[PermissionSet(SecurityAction.InheritanceDemand, Name="FullTrust")]
[PermissionSet(SecurityAction.LinkDemand, Name="FullTrust")]
public class ScriptingDesignerLoader : BasicDesignerLoader, IComponentCreator
{
IScriptingDesignerGenerator generator;
IDesignerSerializationManager serializationManager;
IResourceService resourceService;
Dictionary<string, IComponent> addedObjects = new Dictionary<string, IComponent>();
public ScriptingDesignerLoader(IScriptingDesignerGenerator generator)
{
if (generator == null) {
throw new ArgumentException("Generator cannot be null.", "generator");
}
this.generator = generator;
}
public override void BeginLoad(IDesignerLoaderHost host)
{
AddServices(host);
SetDesignerSupportsProjectResourcesToFalse(host);
base.BeginLoad(host);
}
void AddServices(IDesignerLoaderHost host)
{
host.AddService(typeof(ComponentSerializationService), new CodeDomComponentSerializationService((IServiceProvider)host));
host.AddService(typeof(INameCreationService), new ScriptingNameCreationService(host));
host.AddService(typeof(IDesignerSerializationService), new DesignerSerializationService(host));
}
void SetDesignerSupportsProjectResourcesToFalse(IDesignerLoaderHost host)
{
ProjectResourceService projectResourceService = host.GetService(typeof(ProjectResourceService)) as ProjectResourceService;
if (projectResourceService != null) {
projectResourceService.DesignerSupportsProjectResources = false;
}
}
public IComponent CreateComponent(Type componentClass, string name)
{
return base.LoaderHost.CreateComponent(componentClass, name);
}
public void Add(IComponent component, string name)
{
base.LoaderHost.Container.Add(component, name);
}
/// <summary>
/// Gets a component that has been added to the loader.
/// </summary>
/// <returns>Null if the component cannot be found.</returns>
public IComponent GetComponent(string name)
{
return LoaderHost.Container.Components[name];
}
public IComponent RootComponent {
get { return base.LoaderHost.RootComponent; }
}
public object CreateInstance(Type type, ICollection arguments, string name, bool addToContainer)
{
return serializationManager.CreateInstance(type, arguments, name, addToContainer);
}
public object GetInstance(string name)
{
return serializationManager.GetInstance(name);
}
public Type GetType(string typeName)
{
return serializationManager.GetType(typeName);
}
/// <summary>
/// Gets the property descriptor associated with the event.
/// </summary>
public PropertyDescriptor GetEventProperty(EventDescriptor e)
{
IEventBindingService eventBindingService = GetService(typeof(IEventBindingService)) as IEventBindingService;
return eventBindingService.GetEventProperty(e);
}
public IResourceReader GetResourceReader(CultureInfo info)
{
if (GetResourceService()) {
return resourceService.GetResourceReader(info);
}
return null;
}
bool GetResourceService()
{
resourceService = (IResourceService)LoaderHost.GetService(typeof(IResourceService));
return resourceService != null;
}
public IResourceWriter GetResourceWriter(CultureInfo info)
{
if (GetResourceService()) {
return resourceService.GetResourceWriter(info);
}
return null;
}
/// <summary>
/// Passes the designer host's root component to the generator so it can update the
/// source code with changes made at design time.
/// </summary>
protected override void PerformFlush(IDesignerSerializationManager serializationManager)
{
generator.MergeRootComponentChanges(LoaderHost, serializationManager);
}
protected override void PerformLoad(IDesignerSerializationManager serializationManager)
{
this.serializationManager = serializationManager;
CreateComponents();
}
void CreateComponents()
{
IComponentWalker walker = CreateComponentWalker(this);
walker.CreateComponent(generator.ViewContent.DesignerCodeFileContent);
}
protected virtual IComponentWalker CreateComponentWalker(IComponentCreator componentCreator)
{
return null;
}
}
}

127
src/AddIns/BackendBindings/Scripting/Test/Designer/ScriptingDesignerLoaderGetResourcesTests.cs

@ -0,0 +1,127 @@ @@ -0,0 +1,127 @@
// 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.Globalization;
using System.Resources;
using System.Windows.Forms;
using ICSharpCode.Scripting;
using ICSharpCode.Scripting.Tests.Utils;
using NUnit.Framework;
namespace ICSharpCode.Scripting.Tests.Designer
{
[TestFixture]
public class ScriptingDesignerLoaderGetResourcesTests
{
ScriptingDesignerLoader loader;
MockDesignerLoaderHost host;
MockResourceService resourceService;
MockResourceReader fakeReader;
MockResourceWriter fakeWriter;
MockResourceWriter writer;
MockResourceReader reader;
[Test]
public void GetResourceReader_PassedInvariantCulture_ReturnsReaderFromResourceService()
{
BeginLoad();
GetResourceReader();
Assert.AreEqual(fakeReader, reader);
}
void BeginLoad()
{
CreateResourceService();
CreateDesignerLoaderHost();
host.AddService(typeof(IResourceService), resourceService);
BeginLoad(host);
}
void CreateResourceService()
{
fakeReader = new MockResourceReader();
fakeWriter = new MockResourceWriter();
resourceService = new MockResourceService();
resourceService.SetResourceReader(fakeReader);
resourceService.SetResourceWriter(fakeWriter);
}
void CreateDesignerLoaderHost()
{
host = new MockDesignerLoaderHost();
}
void BeginLoad(IDesignerLoaderHost host)
{
loader = new ScriptingDesignerLoader(new MockDesignerGenerator());
loader.BeginLoad(host);
}
void BeginLoadWithoutResourceService()
{
CreateDesignerLoaderHost();
BeginLoad(host);
}
void GetResourceReader()
{
reader = loader.GetResourceReader(CultureInfo.InvariantCulture) as MockResourceReader;
}
void GetResourceWriter()
{
writer = loader.GetResourceWriter(CultureInfo.InvariantCulture) as MockResourceWriter;
}
[Test]
public void GetResourceReader_PassedInvariantCulture_CultureInfoPassedToResourceServiceForReader()
{
BeginLoad();
GetResourceReader();
CultureInfo culture = resourceService.CultureInfoPassedToGetResourceReader;
CultureInfo expectedCulture = CultureInfo.InvariantCulture;
Assert.AreEqual(expectedCulture, culture);
}
[Test]
public void GetResourceReader_NoResourceService_ReturnsNull()
{
BeginLoadWithoutResourceService();
GetResourceReader();
Assert.IsNull(reader);
}
[Test]
public void GetResourceWriter_PassedInvariantCulture_ReturnsWriterFromResourceService()
{
BeginLoad();
GetResourceWriter();
Assert.AreEqual(fakeWriter, writer);
}
[Test]
public void GetResourceWriter_PassedInvariantCulture_CultureInfoPassedToResourceServiceForWriter()
{
BeginLoad();
GetResourceWriter();
CultureInfo culture = resourceService.CultureInfoPassedToGetResourceWriter;
CultureInfo expectedCulture = CultureInfo.InvariantCulture;
Assert.AreEqual(expectedCulture, culture);
}
[Test]
public void GetResourceWriter_NoResourceService_ReturnsNull()
{
BeginLoadWithoutResourceService();
GetResourceWriter();
Assert.IsNull(writer);
}
}
}

404
src/AddIns/BackendBindings/Scripting/Test/Designer/ScriptingDesignerLoaderTests.cs

@ -0,0 +1,404 @@ @@ -0,0 +1,404 @@
// <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;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.ComponentModel.Design.Serialization;
using System.Windows.Forms;
using ICSharpCode.FormsDesigner;
using ICSharpCode.FormsDesigner.Services;
using ICSharpCode.Scripting.Tests.Utils;
using NUnit.Framework;
namespace ICSharpCode.Scripting.Tests.Designer
{
[TestFixture]
[RequiresSTA]
public class ScriptingDesignerLoaderTests
{
MockDesignerGenerator fakeGenerator;
TestableScriptingDesignerLoader loader;
MockDesignerLoaderHost fakeDesignerLoaderHost;
MockEventBindingService fakeEventBindingService;
FormsDesignerViewContent formsDesignerView;
FakeDesignerSerializationManager fakeSerializationManager;
[SetUp]
public void Init()
{
CreateScriptingDesignerLoader();
}
void CreateScriptingDesignerLoader()
{
fakeGenerator = new MockDesignerGenerator();
loader = new TestableScriptingDesignerLoader(fakeGenerator);
formsDesignerView = new FormsDesignerViewContent(new MockViewContent(), new MockOpenedFile("Test.py"));
fakeGenerator.Attach(formsDesignerView);
}
[TearDown]
public void TearDown()
{
loader.Dispose();
}
[Test]
public void ScriptingDesignerLoaderClass_NewInstance_IsBasicDesignerLoader()
{
BasicDesignerLoader basicLoader = loader as BasicDesignerLoader;
Assert.IsNotNull(basicLoader);
}
[Test]
public void BeginLoad_PassedFakeDesignerLoaderHost_ComponentSerializationServiceAddedToDesignerLoaderHost()
{
BeginLoad();
CodeDomComponentSerializationService service = fakeDesignerLoaderHost.GetService(typeof(ComponentSerializationService)) as CodeDomComponentSerializationService;
Assert.IsNotNull(service);
}
void BeginLoad()
{
CreateDesignerLoaderHostWithoutProjectResourceService();
fakeDesignerLoaderHost.AddService(typeof(ProjectResourceService), new ProjectResourceService(new MockProjectContent()));
loader.BeginLoad(fakeDesignerLoaderHost);
}
void CreateDesignerLoaderHostWithoutProjectResourceService()
{
fakeDesignerLoaderHost = new MockDesignerLoaderHost();
fakeEventBindingService = new MockEventBindingService();
fakeDesignerLoaderHost.AddService(typeof(IEventBindingService), fakeEventBindingService);
}
[Test]
public void BeginLoad_PassedFakeDesignerLoaderHost_NameCreationServiceAddedToDesignerLoaderHost()
{
BeginLoad();
ScriptingNameCreationService service = fakeDesignerLoaderHost.GetService(typeof(INameCreationService)) as ScriptingNameCreationService;
Assert.IsNotNull(service);
}
[Test]
public void BeginLoad_PassedFakeDesignerLoaderHost_DesignerSerializationServiceAddedToDesignerLoaderHost()
{
BeginLoad();
DesignerSerializationService service = fakeDesignerLoaderHost.GetService(typeof(IDesignerSerializationService)) as DesignerSerializationService;
Assert.IsNotNull(service);
}
[Test]
public void BeginLoad_PassedFakeDesignerLoaderHost_ProjectResourceServiceDesignerAddedToDesignerLoaderHostDoesNotSupportProjectResources()
{
BeginLoad();
ProjectResourceService service = fakeDesignerLoaderHost.GetService(typeof(ProjectResourceService)) as ProjectResourceService;
Assert.IsFalse(service.DesignerSupportsProjectResources);
}
[Test]
public void GetEventProperty_PassedFormLoadEventDescriptor_ReturnsPropertyDescriptorFromEventBindingService()
{
BeginLoad();
IEventBindingService eventBindingService = (IEventBindingService)fakeEventBindingService;
EventDescriptor e = TypeDescriptor.GetEvents(typeof(Form)).Find("Load", true);
PropertyDescriptor propertyDescriptor = loader.GetEventProperty(e);
PropertyDescriptor expectedPropertyDescriptor = eventBindingService.GetEventProperty(e);
Assert.AreEqual(expectedPropertyDescriptor, propertyDescriptor);
}
[Test]
public void ScriptingDesignerLoaderConstructor_PassedNullGenerator_ThrowsArgumentException()
{
ArgumentException ex = Assert.Throws<ArgumentException>(delegate {
loader = new TestableScriptingDesignerLoader(null);
});
string paramName = ex.ParamName;
string expectedParamName = "generator";
Assert.AreEqual(expectedParamName, paramName);
}
[Test]
public void PerformFlush_PassedDesignerSerializationManager_DesignerLoaderHostPassedToMergeRootComponentChangesMethod()
{
BeginLoad();
DesignerSerializationManager serializationManager = new DesignerSerializationManager();
loader.CallPerformFlush(serializationManager);
IDesignerHost host = fakeGenerator.MergeChangesHost;
Assert.AreEqual(fakeDesignerLoaderHost, host);
}
[Test]
public void PerformFlush_PassedDesignerSerializationManager_SerializationManagerPassedToMergeRootComponentMethod()
{
BeginLoad();
DesignerSerializationManager expectedSerializationManager = new DesignerSerializationManager();
loader.CallPerformFlush(expectedSerializationManager);
IDesignerSerializationManager serializationManager = fakeGenerator.MergeChangesSerializationManager;
Assert.AreEqual(expectedSerializationManager, serializationManager);
}
[Test]
public void RootComponent_DesignerLoaderHostRootComponentIsForm_ReturnsDesignerLoaderHostRootComponent()
{
BeginLoad();
using (Form form = new Form()) {
fakeDesignerLoaderHost.RootComponent = form;
IComponent rootComponent = loader.RootComponent;
Assert.AreEqual(form, rootComponent);
}
}
[Test]
public void BeginLoad_PassedFakeDesignerLoaderHost_CallsCreatesComponentWalkerPassingNonNullComponentCreator()
{
BeginLoad();
IComponentCreator componentCreator = loader.ComponentCreatorPassedToCreateComponentWalker;
Assert.IsNotNull(componentCreator);
}
[Test]
public void BeginLoad_PassedFakeDesignerLoaderHost_CallsComponentWalkerCreateComponentMethodPassingFormCode()
{
string expectedCode =
"MyForm(Form):\r\n" +
" pass";
formsDesignerView.DesignerCodeFileContent = expectedCode;
BeginLoad();
string code = loader.FakeComponentWalker.CodePassedToCreateComponent;
Assert.AreEqual(expectedCode, code);
}
[Test]
public void BeginLoad_NoProjectResourceService_NullReferenceExceptionIsNotThrown()
{
CreateDesignerLoaderHostWithoutProjectResourceService();
Assert.DoesNotThrow(delegate { loader.BeginLoad(fakeDesignerLoaderHost); });
}
[Test]
public void CreateComponent_CreateTextBox_TextBoxTypePassedToDesignerLoaderHostCreateComponentMethod()
{
BeginLoad();
loader.CreateComponent(typeof(TextBox), "MyTextBox");
CreatedComponent createdComponent = fakeDesignerLoaderHost.CreatedComponents[0];
CreatedComponent expectedCreatedComponent = new CreatedComponent("System.Windows.Forms.TextBox", "MyTextBox");
Assert.AreEqual(expectedCreatedComponent, createdComponent);
}
[Test]
public void CreateComponent_CreateTextBox_TextBoxInstanceReturned()
{
BeginLoad();
IComponent component = loader.CreateComponent(typeof(TextBox), "MyTextBox");
bool result = component is TextBox;
Assert.IsTrue(result);
}
[Test]
public void Add_AddTextBox_AddsTextBoxToDesignerLoaderHostContainer()
{
BeginLoad();
using (TextBox textBox = new TextBox()) {
loader.Add(textBox, "MyTextBox");
IComponent component = fakeDesignerLoaderHost.Container.Components["MyTextBox"];
Assert.AreEqual(textBox, component);
}
}
[Test]
public void GetComponent_TextBoxAddedToLoader_ReturnsTextBox()
{
BeginLoad();
using (TextBox textBox = new TextBox()) {
loader.Add(textBox, "MyTextBox");
IComponent component = loader.GetComponent("MyTextBox");
Assert.AreEqual(textBox, component);
}
}
[Test]
public void GetComponent_NoComponentsAddedToLoader_ReturnsNull()
{
BeginLoad();
IComponent component = loader.GetComponent("MyTextBox");
Assert.IsNull(component);
}
[Test]
public void GetType_PassedTypeName_ReturnsTypeFromDesignerSerializationManager()
{
CreateDesignerSerializationManager();
loader.CallPerformLoad(fakeSerializationManager);
Type expectedType = typeof(string);
fakeSerializationManager.TypeToReturnFromGetType = expectedType;
Type type = loader.GetType("string");
Assert.AreEqual(expectedType, type);
}
void CreateDesignerSerializationManager()
{
fakeSerializationManager = new FakeDesignerSerializationManager();
}
[Test]
public void GetType_PassedTypeName_TypeNamePassedToDesignerSerializationManager()
{
CreateDesignerSerializationManager();
loader.CallPerformLoad(fakeSerializationManager);
string expectedTypeName = "test";
loader.GetType(expectedTypeName);
string typeName = fakeSerializationManager.TypeNamePassedToGetType;
Assert.AreEqual(expectedTypeName, typeName);
}
[Test]
public void GetInstance_PassedName_ReturnsInstanceFromDesignerSerializationManager()
{
CreateDesignerSerializationManager();
loader.CallPerformLoad(fakeSerializationManager);
object expectedInstance = new object();
fakeSerializationManager.InstanceToReturnFromGetInstance = expectedInstance;
object instance = loader.GetInstance("test");
Assert.AreEqual(expectedInstance, instance);
}
[Test]
public void GetInstance_PassedName_InstanceNamePassedToDesignerSerializationManager()
{
CreateDesignerSerializationManager();
loader.CallPerformLoad(fakeSerializationManager);
string expectedName = "test";
loader.GetInstance(expectedName);
string name = fakeSerializationManager.NamePassedToGetInstance;
Assert.AreEqual(expectedName, name);
}
[Test]
public void CreateInstance_PassedType_ReturnsInstanceFromDesignerSerializationManager()
{
CreateDesignerSerializationManager();
loader.CallPerformLoad(fakeSerializationManager);
object expectedInstance = new object();
fakeSerializationManager.InstanceToReturnFromCreateInstance = expectedInstance;
object instance = LoaderCreateInstance(typeof(string));
Assert.AreEqual(expectedInstance, instance);
}
object LoaderCreateInstance(Type type)
{
return LoaderCreateInstance(type, null, null, false);
}
object LoaderCreateInstance(string name)
{
return LoaderCreateInstance(null, null, name, false);
}
object LoaderCreateInstance(ICollection arguments)
{
return LoaderCreateInstance(null, arguments, null, false);
}
object LoaderCreateInstance(bool addToContainer)
{
return LoaderCreateInstance(null, null, null, addToContainer);
}
object LoaderCreateInstance(Type type, ICollection arguments, string name, bool addToContainer)
{
return loader.CreateInstance(type, arguments, name, addToContainer);
}
[Test]
public void CreateInstance_PassedType_TypePassedToDesignerSerializationManager()
{
CreateDesignerSerializationManager();
loader.CallPerformLoad(fakeSerializationManager);
Type expectedType = typeof(string);
LoaderCreateInstance(expectedType);
Type type = fakeSerializationManager.TypePassedToCreateInstance;
Assert.AreEqual(expectedType, type);
}
[Test]
public void CreateInstance_PassedName_NamePassedToDesignerSerializationManager()
{
CreateDesignerSerializationManager();
loader.CallPerformLoad(fakeSerializationManager);
string expectedName = "test";
LoaderCreateInstance(expectedName);
string name = fakeSerializationManager.NamePassedToCreateInstance;
Assert.AreEqual(expectedName, name);
}
[Test]
public void CreateInstance_PassedTrueAddToContainer_AddToContainerPassedToDesignerSerializationManager()
{
CreateDesignerSerializationManager();
loader.CallPerformLoad(fakeSerializationManager);
LoaderCreateInstance(true);
bool addToContainer = fakeSerializationManager.AddToContainerPassedToCreateInstance;
Assert.IsTrue(addToContainer);
}
[Test]
public void CreateInstance_PassedFalseAddToContainer_AddToContainerPassedToDesignerSerializationManager()
{
CreateDesignerSerializationManager();
loader.CallPerformLoad(fakeSerializationManager);
LoaderCreateInstance(false);
bool addToContainer = fakeSerializationManager.AddToContainerPassedToCreateInstance;
Assert.IsFalse(addToContainer);
}
[Test]
public void CreateInstance_PassedArguments_ArgumentsPassedToDesignerSerializationManager()
{
CreateDesignerSerializationManager();
loader.CallPerformLoad(fakeSerializationManager);
string[] expectedArguments = new string[] { "a", "b" };
LoaderCreateInstance(expectedArguments);
ICollection arguments = fakeSerializationManager.ArgumentsPassedToCreateInstance;
Assert.AreEqual(expectedArguments, arguments);
}
}
}

5
src/AddIns/BackendBindings/Scripting/Test/ICSharpCode.Scripting.Tests.csproj

@ -78,6 +78,8 @@ @@ -78,6 +78,8 @@
<Compile Include="Console\ThreadSafeScriptingConsoleTextEditorTests.cs" />
<Compile Include="Designer\NameCreationServiceTests.cs" />
<Compile Include="Designer\ScriptingCodeBuilderTests.cs" />
<Compile Include="Designer\ScriptingDesignerLoaderGetResourcesTests.cs" />
<Compile Include="Designer\ScriptingDesignerLoaderTests.cs" />
<Compile Include="Testing\CreateTextWriterFromCreateTextWriterInfoTestFixture.cs" />
<Compile Include="Testing\CreateTextWriterInfoEqualsTestFixture.cs" />
<Compile Include="Utils\AddedComponent.cs" />
@ -92,6 +94,8 @@ @@ -92,6 +94,8 @@
<Compile Include="Utils\DerivedToolStripMenuItem.cs" />
<Compile Include="Utils\DoublePropertyUserControl.cs" />
<Compile Include="Utils\FakeCaret.cs" />
<Compile Include="Utils\FakeComponentWalker.cs" />
<Compile Include="Utils\FakeDesignerSerializationManager.cs" />
<Compile Include="Utils\FakeDocument.cs" />
<Compile Include="Utils\FakeDocumentLine.cs" />
<Compile Include="Utils\FakeLock.cs" />
@ -128,6 +132,7 @@ @@ -128,6 +132,7 @@
<Compile Include="Utils\MSBuildEngineHelper.cs" />
<Compile Include="Utils\NullPropertyUserControl.cs" />
<Compile Include="Utils\SupportInitCustomControl.cs" />
<Compile Include="Utils\TestableScriptingDesignerLoader.cs" />
<Compile Include="Utils\Tests\AddInPathHelperTests.cs" />
<Compile Include="Utils\Tests\MockComponentCreatorTests.cs" />
<Compile Include="Utils\Tests\MockConsoleTextEditorTests.cs" />

6
src/AddIns/BackendBindings/Scripting/Test/Utils/CreatedComponent.cs

@ -18,6 +18,12 @@ namespace ICSharpCode.Scripting.Tests.Utils @@ -18,6 +18,12 @@ namespace ICSharpCode.Scripting.Tests.Utils
Component = component;
}
public CreatedComponent(string typeName, string name)
{
TypeName = typeName;
Name = name;
}
public string TypeName { get; set; }
public string Name { get; set; }
public IComponent Component { get; set; }

24
src/AddIns/BackendBindings/Scripting/Test/Utils/FakeComponentWalker.cs

@ -0,0 +1,24 @@ @@ -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;
using ICSharpCode.Scripting;
namespace ICSharpCode.Scripting.Tests.Utils
{
public class FakeComponentWalker : IComponentWalker
{
public string CodePassedToCreateComponent;
public IComponent CreateComponent(string code)
{
CodePassedToCreateComponent = code;
return null;
}
}
}

113
src/AddIns/BackendBindings/Scripting/Test/Utils/FakeDesignerSerializationManager.cs

@ -0,0 +1,113 @@ @@ -0,0 +1,113 @@
// <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;
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;
namespace ICSharpCode.Scripting.Tests.Utils
{
public class FakeDesignerSerializationManager : IDesignerSerializationManager
{
public Type TypeToReturnFromGetType;
public string TypeNamePassedToGetType;
public object InstanceToReturnFromGetInstance;
public string NamePassedToGetInstance;
public object InstanceToReturnFromCreateInstance;
public Type TypePassedToCreateInstance;
public ICollection ArgumentsPassedToCreateInstance;
public string NamePassedToCreateInstance;
public bool AddToContainerPassedToCreateInstance;
public event ResolveNameEventHandler ResolveName;
protected virtual void OnResolveName(ResolveNameEventArgs e)
{
if (ResolveName != null) {
ResolveName(this, e);
}
}
public event EventHandler SerializationComplete;
protected virtual void OnSerializationComplete(EventArgs e)
{
if (SerializationComplete != null) {
SerializationComplete(this, e);
}
}
public ContextStack Context {
get {
throw new NotImplementedException();
}
}
public PropertyDescriptorCollection Properties {
get {
throw new NotImplementedException();
}
}
public void AddSerializationProvider(IDesignerSerializationProvider provider)
{
throw new NotImplementedException();
}
public object CreateInstance(Type type, ICollection arguments, string name, bool addToContainer)
{
TypePassedToCreateInstance = type;
ArgumentsPassedToCreateInstance = arguments;
NamePassedToCreateInstance = name;
AddToContainerPassedToCreateInstance = addToContainer;
return InstanceToReturnFromCreateInstance;
}
public object GetInstance(string name)
{
NamePassedToGetInstance = name;
return InstanceToReturnFromGetInstance;
}
public string GetName(object value)
{
throw new NotImplementedException();
}
public object GetSerializer(Type objectType, Type serializerType)
{
throw new NotImplementedException();
}
public Type GetType(string typeName)
{
TypeNamePassedToGetType = typeName;
return TypeToReturnFromGetType;
}
public void RemoveSerializationProvider(IDesignerSerializationProvider provider)
{
throw new NotImplementedException();
}
public void ReportError(object errorInformation)
{
throw new NotImplementedException();
}
public void SetName(object instance, string name)
{
throw new NotImplementedException();
}
public object GetService(Type serviceType)
{
throw new NotImplementedException();
}
}
}

4
src/AddIns/BackendBindings/Scripting/Test/Utils/MockResourceService.cs

@ -39,7 +39,7 @@ namespace ICSharpCode.Scripting.Tests.Utils @@ -39,7 +39,7 @@ namespace ICSharpCode.Scripting.Tests.Utils
/// <summary>
/// Gets the culture passed to GetResourceReader.
/// </summary>
public CultureInfo ResourceReaderCultureInfo {
public CultureInfo CultureInfoPassedToGetResourceReader {
get { return readerCultureInfo; }
}
@ -52,7 +52,7 @@ namespace ICSharpCode.Scripting.Tests.Utils @@ -52,7 +52,7 @@ namespace ICSharpCode.Scripting.Tests.Utils
/// <summary>
/// Gets the culture passed to GetResourceWriter.
/// </summary>
public CultureInfo ResourceWriterCultureInfo {
public CultureInfo CultureInfoPassedToGetResourceWriter {
get { return writerCultureInfo; }
}
}

40
src/AddIns/BackendBindings/Scripting/Test/Utils/TestableScriptingDesignerLoader.cs

@ -0,0 +1,40 @@ @@ -0,0 +1,40 @@
// <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 ICSharpCode.Scripting;
namespace ICSharpCode.Scripting.Tests.Utils
{
public class TestableScriptingDesignerLoader : ScriptingDesignerLoader
{
public IComponentCreator ComponentCreatorPassedToCreateComponentWalker;
public FakeComponentWalker FakeComponentWalker = new FakeComponentWalker();
public TestableScriptingDesignerLoader(IScriptingDesignerGenerator generator)
: base(generator)
{
}
public void CallPerformFlush(IDesignerSerializationManager serializationManager)
{
base.PerformFlush(serializationManager);
}
public void CallPerformLoad(IDesignerSerializationManager serializationManager)
{
base.PerformLoad(serializationManager);
}
protected override IComponentWalker CreateComponentWalker(IComponentCreator componentCreator)
{
ComponentCreatorPassedToCreateComponentWalker = componentCreator;
return FakeComponentWalker;
}
}
}
Loading…
Cancel
Save