Browse Source

Added namespace tests to test XML-namespaces that is added automatically in the document root when controls or types outside the default XML-namespace is used.

pull/68/head
gumme 12 years ago
parent
commit
07c44c9870
  1. 7
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/AssemblyInfo.cs
  2. 19
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/ModelTestHelper.cs
  3. 146
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/NamespaceTests.cs
  4. 1
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/WpfDesign.Tests.csproj

7
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/AssemblyInfo.cs

@ -4,6 +4,7 @@ @@ -4,6 +4,7 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Windows.Markup;
using NUnit.Framework;
@ -20,4 +21,8 @@ using NUnit.Framework; @@ -20,4 +21,8 @@ using NUnit.Framework;
[assembly: AssemblyCulture("")]
// Run unit tests on STA thread.
[assembly: RequiresSTA]
[assembly: RequiresSTA]
[assembly: XmlnsPrefix("http://sharpdevelop.net/WpfDesign/Tests/Controls", "sdtcontrols")]
[assembly: XmlnsDefinition("http://sharpdevelop.net/WpfDesign/Tests/Controls", "ICSharpCode.WpfDesign.Tests.Controls")]

19
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/ModelTestHelper.cs

@ -59,14 +59,23 @@ namespace ICSharpCode.WpfDesign.Tests.Designer @@ -59,14 +59,23 @@ namespace ICSharpCode.WpfDesign.Tests.Designer
return canvasChild;
}
protected void AssertCanvasDesignerOutput(string expectedXaml, DesignContext context)
protected void AssertCanvasDesignerOutput(string expectedXaml, DesignContext context, params String[] additionalXmlns)
{
string canvasStartTag =
"<Canvas xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" " +
"xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\" " +
"xmlns:t=\"" + DesignerTestsNamespace + "\"";
foreach(string ns in additionalXmlns) {
canvasStartTag += " " + ns;
}
expectedXaml = canvasStartTag + ">\n" + expectedXaml.Trim();
expectedXaml =
"<?xml version=\"1.0\" encoding=\"utf-16\"?>\n" +
("<Canvas xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" " +
"xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\" " +
"xmlns:t=\"" + DesignerTestsNamespace + "\">\n" + expectedXaml.Trim())
.Replace("\r", "").Replace("\n", "\n ")
expectedXaml.Replace("\r", "").Replace("\n", "\n ")
+ "\n</Canvas>";
StringWriter stringWriter = new StringWriter();

146
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/NamespaceTests.cs

@ -0,0 +1,146 @@ @@ -0,0 +1,146 @@
// 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.Windows.Controls;
using NUnit.Framework;
namespace ICSharpCode.WpfDesign.Tests.Designer
{
[TestFixture]
public class NamespaceTests : ModelTestHelper
{
[Test]
public void AddControlFromTestNamespace()
{
DesignItem button = CreateCanvasContext("<Button />");
DesignItem canvas = button.Parent;
DesignItem customButton = canvas.Services.Component.RegisterComponentForDesigner(new CustomButton());
canvas.Properties["Children"].CollectionElements.Add(customButton);
AssertCanvasDesignerOutput("<Button />\n" +
"<t:CustomButton />", canvas.Context);
}
[Test]
public void AddControlWithUndeclaredNamespace()
{
DesignItem button = CreateCanvasContext("<Button />");
DesignItem canvas = button.Parent;
DesignItem customButton = canvas.Services.Component.RegisterComponentForDesigner(new ICSharpCode.WpfDesign.Tests.OtherControls.CustomButton());
canvas.Properties["Children"].CollectionElements.Add(customButton);
AssertCanvasDesignerOutput("<Button />\n" +
"<Controls0:CustomButton />",
canvas.Context,
"xmlns:Controls0=\"clr-namespace:ICSharpCode.WpfDesign.Tests.OtherControls;assembly=ICSharpCode.WpfDesign.Tests\"");
}
[Test]
public void AddControlWithUndeclaredNamespaceThatUsesXmlnsPrefixAttribute()
{
DesignItem button = CreateCanvasContext("<Button />");
DesignItem canvas = button.Parent;
DesignItem customButton = canvas.Services.Component.RegisterComponentForDesigner(new ICSharpCode.WpfDesign.Tests.Controls.CustomButton());
canvas.Properties["Children"].CollectionElements.Add(customButton);
AssertCanvasDesignerOutput("<Button />\n" +
"<sdtcontrols:CustomButton />",
canvas.Context,
"xmlns:sdtcontrols=\"http://sharpdevelop.net/WpfDesign/Tests/Controls\"");
}
[Test]
public void AddMultipleControls()
{
DesignItem button = CreateCanvasContext("<Button />");
DesignItem canvas = button.Parent;
DesignItem customControl = canvas.Services.Component.RegisterComponentForDesigner(new CustomButton());
canvas.Properties["Children"].CollectionElements.Add(customControl);
customControl = canvas.Services.Component.RegisterComponentForDesigner(new ICSharpCode.WpfDesign.Tests.Controls.CustomButton());
canvas.Properties["Children"].CollectionElements.Add(customControl);
customControl = canvas.Services.Component.RegisterComponentForDesigner(new ICSharpCode.WpfDesign.Tests.OtherControls.CustomButton());
canvas.Properties["Children"].CollectionElements.Add(customControl);
customControl = canvas.Services.Component.RegisterComponentForDesigner(new ICSharpCode.WpfDesign.Tests.SpecialControls.CustomButton());
canvas.Properties["Children"].CollectionElements.Add(customControl);
customControl = canvas.Services.Component.RegisterComponentForDesigner(new CustomCheckBox());
canvas.Properties["Children"].CollectionElements.Add(customControl);
customControl = canvas.Services.Component.RegisterComponentForDesigner(new ICSharpCode.WpfDesign.Tests.Controls.CustomCheckBox());
canvas.Properties["Children"].CollectionElements.Add(customControl);
customControl = canvas.Services.Component.RegisterComponentForDesigner(new ICSharpCode.WpfDesign.Tests.OtherControls.CustomCheckBox());
canvas.Properties["Children"].CollectionElements.Add(customControl);
customControl = canvas.Services.Component.RegisterComponentForDesigner(new ICSharpCode.WpfDesign.Tests.SpecialControls.CustomCheckBox());
canvas.Properties["Children"].CollectionElements.Add(customControl);
AssertCanvasDesignerOutput("<Button />\n" +
"<t:CustomButton />\n" +
"<sdtcontrols:CustomButton />\n" +
"<Controls0:CustomButton />\n" +
"<Controls1:CustomButton />\n" +
"<t:CustomCheckBox />\n" +
"<sdtcontrols:CustomCheckBox />\n" +
"<Controls0:CustomCheckBox />\n" +
"<Controls1:CustomCheckBox />",
canvas.Context,
"xmlns:sdtcontrols=\"http://sharpdevelop.net/WpfDesign/Tests/Controls\"",
"xmlns:Controls0=\"clr-namespace:ICSharpCode.WpfDesign.Tests.OtherControls;assembly=ICSharpCode.WpfDesign.Tests\"",
"xmlns:Controls1=\"clr-namespace:ICSharpCode.WpfDesign.Tests.SpecialControls;assembly=ICSharpCode.WpfDesign.Tests\"");
}
}
public class CustomButton : Button
{
}
public class CustomCheckBox : CheckBox
{
}
}
namespace ICSharpCode.WpfDesign.Tests.Controls
{
public class CustomButton : Button
{
}
public class CustomCheckBox : CheckBox
{
}
}
namespace ICSharpCode.WpfDesign.Tests.OtherControls
{
public class CustomButton : Button
{
}
public class CustomCheckBox : CheckBox
{
}
}
namespace ICSharpCode.WpfDesign.Tests.SpecialControls
{
public class CustomButton : Button
{
}
public class CustomCheckBox : CheckBox
{
}
}

1
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/WpfDesign.Tests.csproj

@ -64,6 +64,7 @@ @@ -64,6 +64,7 @@
<Compile Include="Designer\MockFocusNavigator.cs" />
<Compile Include="Designer\ModelTestHelper.cs" />
<Compile Include="Designer\ModelTests.cs" />
<Compile Include="Designer\NamespaceTests.cs" />
<Compile Include="Designer\OutlineView\HierarchyTests.cs" />
<Compile Include="Designer\OutlineView\InsertTests.cs" />
<Compile Include="Designer\OutlineView\SelectionTests.cs" />

Loading…
Cancel
Save