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+ }
0 commit comments