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 ;
5+ using System . Windows . Controls ;
6+
7+ using NUnit . Framework ;
8+
9+ namespace ICSharpCode . WpfDesign . Tests . Designer
10+ {
11+ [ TestFixture ]
12+ public class NamespaceTests : ModelTestHelper
13+ {
14+
15+ [ Test ]
16+ public void AddControlFromTestNamespace ( )
17+ {
18+ DesignItem button = CreateCanvasContext ( "<Button />" ) ;
19+
20+ DesignItem canvas = button . Parent ;
21+
22+ DesignItem customButton = canvas . Services . Component . RegisterComponentForDesigner ( new CustomButton ( ) ) ;
23+ canvas . Properties [ "Children" ] . CollectionElements . Add ( customButton ) ;
24+
25+ AssertCanvasDesignerOutput ( "<Button />\n " +
26+ "<t:CustomButton />" , canvas . Context ) ;
27+ }
28+
29+ [ Test ]
30+ public void AddControlWithUndeclaredNamespace ( )
31+ {
32+ DesignItem button = CreateCanvasContext ( "<Button />" ) ;
33+
34+ DesignItem canvas = button . Parent ;
35+
36+ DesignItem customButton = canvas . Services . Component . RegisterComponentForDesigner ( new ICSharpCode . WpfDesign . Tests . OtherControls . CustomButton ( ) ) ;
37+ canvas . Properties [ "Children" ] . CollectionElements . Add ( customButton ) ;
38+
39+ AssertCanvasDesignerOutput ( "<Button />\n " +
40+ "<Controls0:CustomButton />" ,
41+ canvas . Context ,
42+ "xmlns:Controls0=\" clr-namespace:ICSharpCode.WpfDesign.Tests.OtherControls;assembly=ICSharpCode.WpfDesign.Tests\" " ) ;
43+ }
44+
45+ [ Test ]
46+ public void AddControlWithUndeclaredNamespaceThatUsesXmlnsPrefixAttribute ( )
47+ {
48+ DesignItem button = CreateCanvasContext ( "<Button />" ) ;
49+
50+ DesignItem canvas = button . Parent ;
51+
52+ DesignItem customButton = canvas . Services . Component . RegisterComponentForDesigner ( new ICSharpCode . WpfDesign . Tests . Controls . CustomButton ( ) ) ;
53+ canvas . Properties [ "Children" ] . CollectionElements . Add ( customButton ) ;
54+
55+ AssertCanvasDesignerOutput ( "<Button />\n " +
56+ "<sdtcontrols:CustomButton />" ,
57+ canvas . Context ,
58+ "xmlns:sdtcontrols=\" http://sharpdevelop.net/WpfDesign/Tests/Controls\" " ) ;
59+ }
60+
61+ [ Test ]
62+ public void AddMultipleControls ( )
63+ {
64+ DesignItem button = CreateCanvasContext ( "<Button />" ) ;
65+
66+ DesignItem canvas = button . Parent ;
67+
68+ DesignItem customControl = canvas . Services . Component . RegisterComponentForDesigner ( new CustomButton ( ) ) ;
69+ canvas . Properties [ "Children" ] . CollectionElements . Add ( customControl ) ;
70+
71+ customControl = canvas . Services . Component . RegisterComponentForDesigner ( new ICSharpCode . WpfDesign . Tests . Controls . CustomButton ( ) ) ;
72+ canvas . Properties [ "Children" ] . CollectionElements . Add ( customControl ) ;
73+
74+ customControl = canvas . Services . Component . RegisterComponentForDesigner ( new ICSharpCode . WpfDesign . Tests . OtherControls . CustomButton ( ) ) ;
75+ canvas . Properties [ "Children" ] . CollectionElements . Add ( customControl ) ;
76+
77+ customControl = canvas . Services . Component . RegisterComponentForDesigner ( new ICSharpCode . WpfDesign . Tests . SpecialControls . CustomButton ( ) ) ;
78+ canvas . Properties [ "Children" ] . CollectionElements . Add ( customControl ) ;
79+
80+ customControl = canvas . Services . Component . RegisterComponentForDesigner ( new CustomCheckBox ( ) ) ;
81+ canvas . Properties [ "Children" ] . CollectionElements . Add ( customControl ) ;
82+
83+ customControl = canvas . Services . Component . RegisterComponentForDesigner ( new ICSharpCode . WpfDesign . Tests . Controls . CustomCheckBox ( ) ) ;
84+ canvas . Properties [ "Children" ] . CollectionElements . Add ( customControl ) ;
85+
86+ customControl = canvas . Services . Component . RegisterComponentForDesigner ( new ICSharpCode . WpfDesign . Tests . OtherControls . CustomCheckBox ( ) ) ;
87+ canvas . Properties [ "Children" ] . CollectionElements . Add ( customControl ) ;
88+
89+ customControl = canvas . Services . Component . RegisterComponentForDesigner ( new ICSharpCode . WpfDesign . Tests . SpecialControls . CustomCheckBox ( ) ) ;
90+ canvas . Properties [ "Children" ] . CollectionElements . Add ( customControl ) ;
91+
92+ AssertCanvasDesignerOutput ( "<Button />\n " +
93+ "<t:CustomButton />\n " +
94+ "<sdtcontrols:CustomButton />\n " +
95+ "<Controls0:CustomButton />\n " +
96+ "<Controls1:CustomButton />\n " +
97+ "<t:CustomCheckBox />\n " +
98+ "<sdtcontrols:CustomCheckBox />\n " +
99+ "<Controls0:CustomCheckBox />\n " +
100+ "<Controls1:CustomCheckBox />" ,
101+ canvas . Context ,
102+ "xmlns:sdtcontrols=\" http://sharpdevelop.net/WpfDesign/Tests/Controls\" " ,
103+ "xmlns:Controls0=\" clr-namespace:ICSharpCode.WpfDesign.Tests.OtherControls;assembly=ICSharpCode.WpfDesign.Tests\" " ,
104+ "xmlns:Controls1=\" clr-namespace:ICSharpCode.WpfDesign.Tests.SpecialControls;assembly=ICSharpCode.WpfDesign.Tests\" " ) ;
105+ }
106+ }
107+
108+ public class CustomButton : Button
109+ {
110+ public static readonly DependencyProperty TestAttachedProperty = DependencyProperty . RegisterAttached ( "TestAttached" , typeof ( double ) , typeof ( CustomButton ) ,
111+ new FrameworkPropertyMetadata ( Double . NaN ) ) ;
112+
113+ public static double GetTestAttached ( UIElement element )
114+ {
115+ return ( double ) element . GetValue ( TestAttachedProperty ) ;
116+ }
117+
118+ public static void SetTestAttached ( UIElement element , double value )
119+ {
120+ element . SetValue ( TestAttachedProperty , value ) ;
121+ }
122+ }
123+
124+ public class CustomCheckBox : CheckBox
125+ {
126+ }
127+ }
128+
129+ namespace ICSharpCode . WpfDesign . Tests . Controls
130+ {
131+ public class CustomButton : Button
132+ {
133+ public static readonly DependencyProperty TestAttachedProperty = DependencyProperty . RegisterAttached ( "TestAttached" , typeof ( double ) , typeof ( CustomButton ) ,
134+ new FrameworkPropertyMetadata ( Double . NaN ) ) ;
135+
136+ public static double GetTestAttached ( UIElement element )
137+ {
138+ return ( double ) element . GetValue ( TestAttachedProperty ) ;
139+ }
140+
141+ public static void SetTestAttached ( UIElement element , double value )
142+ {
143+ element . SetValue ( TestAttachedProperty , value ) ;
144+ }
145+ }
146+
147+ public class CustomCheckBox : CheckBox
148+ {
149+ }
150+ }
151+
152+ namespace ICSharpCode . WpfDesign . Tests . OtherControls
153+ {
154+ public class CustomButton : Button
155+ {
156+ public static readonly DependencyProperty TestAttachedProperty = DependencyProperty . RegisterAttached ( "TestAttached" , typeof ( double ) , typeof ( CustomButton ) ,
157+ new FrameworkPropertyMetadata ( Double . NaN ) ) ;
158+
159+ public static double GetTestAttached ( UIElement element )
160+ {
161+ return ( double ) element . GetValue ( TestAttachedProperty ) ;
162+ }
163+
164+ public static void SetTestAttached ( UIElement element , double value )
165+ {
166+ element . SetValue ( TestAttachedProperty , value ) ;
167+ }
168+ }
169+
170+ public class CustomCheckBox : CheckBox
171+ {
172+ }
173+ }
174+
175+ namespace ICSharpCode . WpfDesign . Tests . SpecialControls
176+ {
177+ public class CustomButton : Button
178+ {
179+ }
180+
181+ public class CustomCheckBox : CheckBox
182+ {
183+ }
184+ }
0 commit comments