Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit 07c44c9

Browse files
author
gumme
committed
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.
1 parent 0b59cb7 commit 07c44c9

4 files changed

Lines changed: 167 additions & 6 deletions

File tree

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Reflection;
55
using System.Runtime.CompilerServices;
66
using System.Runtime.InteropServices;
7+
using System.Windows.Markup;
78

89
using NUnit.Framework;
910

@@ -20,4 +21,8 @@
2021
[assembly: AssemblyCulture("")]
2122

2223
// Run unit tests on STA thread.
23-
[assembly: RequiresSTA]
24+
[assembly: RequiresSTA]
25+
26+
[assembly: XmlnsPrefix("http://sharpdevelop.net/WpfDesign/Tests/Controls", "sdtcontrols")]
27+
28+
[assembly: XmlnsDefinition("http://sharpdevelop.net/WpfDesign/Tests/Controls", "ICSharpCode.WpfDesign.Tests.Controls")]

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,23 @@ protected DesignItem CreateCanvasContext(string xaml)
5959
return canvasChild;
6060
}
6161

62-
protected void AssertCanvasDesignerOutput(string expectedXaml, DesignContext context)
62+
protected void AssertCanvasDesignerOutput(string expectedXaml, DesignContext context, params String[] additionalXmlns)
6363
{
64+
string canvasStartTag =
65+
"<Canvas xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" " +
66+
"xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\" " +
67+
"xmlns:t=\"" + DesignerTestsNamespace + "\"";
68+
69+
70+
foreach(string ns in additionalXmlns) {
71+
canvasStartTag += " " + ns;
72+
}
73+
74+
expectedXaml = canvasStartTag + ">\n" + expectedXaml.Trim();
75+
6476
expectedXaml =
6577
"<?xml version=\"1.0\" encoding=\"utf-16\"?>\n" +
66-
("<Canvas xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" " +
67-
"xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\" " +
68-
"xmlns:t=\"" + DesignerTestsNamespace + "\">\n" + expectedXaml.Trim())
69-
.Replace("\r", "").Replace("\n", "\n ")
78+
expectedXaml.Replace("\r", "").Replace("\n", "\n ")
7079
+ "\n</Canvas>";
7180

7281
StringWriter stringWriter = new StringWriter();
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
2+
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
3+
using System;
4+
using System.Windows.Controls;
5+
using NUnit.Framework;
6+
7+
namespace ICSharpCode.WpfDesign.Tests.Designer
8+
{
9+
[TestFixture]
10+
public class NamespaceTests : ModelTestHelper
11+
{
12+
13+
[Test]
14+
public void AddControlFromTestNamespace()
15+
{
16+
DesignItem button = CreateCanvasContext("<Button />");
17+
18+
DesignItem canvas = button.Parent;
19+
20+
DesignItem customButton = canvas.Services.Component.RegisterComponentForDesigner(new CustomButton());
21+
canvas.Properties["Children"].CollectionElements.Add(customButton);
22+
23+
AssertCanvasDesignerOutput("<Button />\n" +
24+
"<t:CustomButton />", canvas.Context);
25+
}
26+
27+
[Test]
28+
public void AddControlWithUndeclaredNamespace()
29+
{
30+
DesignItem button = CreateCanvasContext("<Button />");
31+
32+
DesignItem canvas = button.Parent;
33+
34+
DesignItem customButton = canvas.Services.Component.RegisterComponentForDesigner(new ICSharpCode.WpfDesign.Tests.OtherControls.CustomButton());
35+
canvas.Properties["Children"].CollectionElements.Add(customButton);
36+
37+
AssertCanvasDesignerOutput("<Button />\n" +
38+
"<Controls0:CustomButton />",
39+
canvas.Context,
40+
"xmlns:Controls0=\"clr-namespace:ICSharpCode.WpfDesign.Tests.OtherControls;assembly=ICSharpCode.WpfDesign.Tests\"");
41+
}
42+
43+
[Test]
44+
public void AddControlWithUndeclaredNamespaceThatUsesXmlnsPrefixAttribute()
45+
{
46+
DesignItem button = CreateCanvasContext("<Button />");
47+
48+
DesignItem canvas = button.Parent;
49+
50+
DesignItem customButton = canvas.Services.Component.RegisterComponentForDesigner(new ICSharpCode.WpfDesign.Tests.Controls.CustomButton());
51+
canvas.Properties["Children"].CollectionElements.Add(customButton);
52+
53+
AssertCanvasDesignerOutput("<Button />\n" +
54+
"<sdtcontrols:CustomButton />",
55+
canvas.Context,
56+
"xmlns:sdtcontrols=\"http://sharpdevelop.net/WpfDesign/Tests/Controls\"");
57+
}
58+
59+
[Test]
60+
public void AddMultipleControls()
61+
{
62+
DesignItem button = CreateCanvasContext("<Button />");
63+
64+
DesignItem canvas = button.Parent;
65+
66+
DesignItem customControl = canvas.Services.Component.RegisterComponentForDesigner(new CustomButton());
67+
canvas.Properties["Children"].CollectionElements.Add(customControl);
68+
69+
customControl = canvas.Services.Component.RegisterComponentForDesigner(new ICSharpCode.WpfDesign.Tests.Controls.CustomButton());
70+
canvas.Properties["Children"].CollectionElements.Add(customControl);
71+
72+
customControl = canvas.Services.Component.RegisterComponentForDesigner(new ICSharpCode.WpfDesign.Tests.OtherControls.CustomButton());
73+
canvas.Properties["Children"].CollectionElements.Add(customControl);
74+
75+
customControl = canvas.Services.Component.RegisterComponentForDesigner(new ICSharpCode.WpfDesign.Tests.SpecialControls.CustomButton());
76+
canvas.Properties["Children"].CollectionElements.Add(customControl);
77+
78+
customControl = canvas.Services.Component.RegisterComponentForDesigner(new CustomCheckBox());
79+
canvas.Properties["Children"].CollectionElements.Add(customControl);
80+
81+
customControl = canvas.Services.Component.RegisterComponentForDesigner(new ICSharpCode.WpfDesign.Tests.Controls.CustomCheckBox());
82+
canvas.Properties["Children"].CollectionElements.Add(customControl);
83+
84+
customControl = canvas.Services.Component.RegisterComponentForDesigner(new ICSharpCode.WpfDesign.Tests.OtherControls.CustomCheckBox());
85+
canvas.Properties["Children"].CollectionElements.Add(customControl);
86+
87+
customControl = canvas.Services.Component.RegisterComponentForDesigner(new ICSharpCode.WpfDesign.Tests.SpecialControls.CustomCheckBox());
88+
canvas.Properties["Children"].CollectionElements.Add(customControl);
89+
90+
AssertCanvasDesignerOutput("<Button />\n" +
91+
"<t:CustomButton />\n" +
92+
"<sdtcontrols:CustomButton />\n" +
93+
"<Controls0:CustomButton />\n" +
94+
"<Controls1:CustomButton />\n" +
95+
"<t:CustomCheckBox />\n" +
96+
"<sdtcontrols:CustomCheckBox />\n" +
97+
"<Controls0:CustomCheckBox />\n" +
98+
"<Controls1:CustomCheckBox />",
99+
canvas.Context,
100+
"xmlns:sdtcontrols=\"http://sharpdevelop.net/WpfDesign/Tests/Controls\"",
101+
"xmlns:Controls0=\"clr-namespace:ICSharpCode.WpfDesign.Tests.OtherControls;assembly=ICSharpCode.WpfDesign.Tests\"",
102+
"xmlns:Controls1=\"clr-namespace:ICSharpCode.WpfDesign.Tests.SpecialControls;assembly=ICSharpCode.WpfDesign.Tests\"");
103+
}
104+
}
105+
106+
public class CustomButton : Button
107+
{
108+
}
109+
110+
public class CustomCheckBox : CheckBox
111+
{
112+
}
113+
}
114+
115+
namespace ICSharpCode.WpfDesign.Tests.Controls
116+
{
117+
public class CustomButton : Button
118+
{
119+
}
120+
121+
public class CustomCheckBox : CheckBox
122+
{
123+
}
124+
}
125+
126+
namespace ICSharpCode.WpfDesign.Tests.OtherControls
127+
{
128+
public class CustomButton : Button
129+
{
130+
}
131+
132+
public class CustomCheckBox : CheckBox
133+
{
134+
}
135+
}
136+
137+
namespace ICSharpCode.WpfDesign.Tests.SpecialControls
138+
{
139+
public class CustomButton : Button
140+
{
141+
}
142+
143+
public class CustomCheckBox : CheckBox
144+
{
145+
}
146+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
<Compile Include="Designer\MockFocusNavigator.cs" />
6565
<Compile Include="Designer\ModelTestHelper.cs" />
6666
<Compile Include="Designer\ModelTests.cs" />
67+
<Compile Include="Designer\NamespaceTests.cs" />
6768
<Compile Include="Designer\OutlineView\HierarchyTests.cs" />
6869
<Compile Include="Designer\OutlineView\InsertTests.cs" />
6970
<Compile Include="Designer\OutlineView\SelectionTests.cs" />

0 commit comments

Comments
 (0)