@@ -111,5 +111,141 @@ public void AnimatedIconSourceTest()
111111 Verify . IsTrue ( animatedIcon . MirroredWhenRightToLeft ) ;
112112 } ) ;
113113 }
114+
115+ [ TestMethod ]
116+ public void CreateIconElementReturnsCorrectTypeTest ( )
117+ {
118+ RunOnUIThread . Execute ( ( ) =>
119+ {
120+ Log . Comment ( "Verify BitmapIconSource creates BitmapIcon" ) ;
121+ var bitmapIconSource = new BitmapIconSource ( ) ;
122+ var bitmapIcon = bitmapIconSource . CreateIconElement ( ) ;
123+ Verify . IsNotNull ( bitmapIcon ) ;
124+ Verify . IsTrue ( bitmapIcon is BitmapIcon ) ;
125+
126+ Log . Comment ( "Verify FontIconSource creates FontIcon" ) ;
127+ var fontIconSource = new FontIconSource ( ) ;
128+ var fontIcon = fontIconSource . CreateIconElement ( ) ;
129+ Verify . IsNotNull ( fontIcon ) ;
130+ Verify . IsTrue ( fontIcon is FontIcon ) ;
131+
132+ Log . Comment ( "Verify SymbolIconSource creates SymbolIcon" ) ;
133+ var symbolIconSource = new SymbolIconSource ( ) ;
134+ var symbolIcon = symbolIconSource . CreateIconElement ( ) ;
135+ Verify . IsNotNull ( symbolIcon ) ;
136+ Verify . IsTrue ( symbolIcon is SymbolIcon ) ;
137+
138+ Log . Comment ( "Verify PathIconSource creates PathIcon" ) ;
139+ var pathIconSource = new PathIconSource ( ) ;
140+ var pathIcon = pathIconSource . CreateIconElement ( ) ;
141+ Verify . IsNotNull ( pathIcon ) ;
142+ Verify . IsTrue ( pathIcon is PathIcon ) ;
143+ } ) ;
144+ }
145+
146+ [ TestMethod ]
147+ public void CreateIconElementForegroundTest ( )
148+ {
149+ FontIconSource iconSource1 = null ;
150+ FontIconSource iconSource2 = null ;
151+ FontIcon icon1 = null ;
152+ FontIcon icon2 = null ;
153+
154+ RunOnUIThread . Execute ( ( ) =>
155+ {
156+ iconSource1 = new FontIconSource ( )
157+ {
158+ Foreground = new SolidColorBrush ( Microsoft . UI . Colors . Blue )
159+ } ;
160+
161+ iconSource2 = new FontIconSource ( ) ;
162+
163+ Log . Comment ( "Create first icon element with foreground already set" ) ;
164+ icon1 = iconSource1 . CreateIconElement ( ) as FontIcon ;
165+ Verify . IsNotNull ( icon1 ) ;
166+
167+ Log . Comment ( "Create second icon element with foreground not set" ) ;
168+ icon2 = iconSource2 . CreateIconElement ( ) as FontIcon ;
169+ Verify . IsNotNull ( icon2 ) ;
170+ } ) ;
171+
172+ IdleSynchronizer . Wait ( ) ;
173+
174+ RunOnUIThread . Execute ( ( ) =>
175+ {
176+ Log . Comment ( "Verify foreground is applied to both icon elements" ) ;
177+ Verify . IsTrue ( icon1 . Foreground is SolidColorBrush ) ;
178+ Verify . IsTrue ( icon2 . Foreground is SolidColorBrush ) ;
179+ Verify . AreEqual ( Microsoft . UI . Colors . Blue , ( icon1 . Foreground as SolidColorBrush ) . Color ) ;
180+ } ) ;
181+ }
182+
183+ [ TestMethod ]
184+ public void PropertyChangePropagationToCreatedElements ( )
185+ {
186+ FontIconSource iconSource = null ;
187+ FontIcon icon = null ;
188+
189+ RunOnUIThread . Execute ( ( ) =>
190+ {
191+ iconSource = new FontIconSource ( ) ;
192+
193+ Log . Comment ( "Create icon element before setting properties" ) ;
194+ icon = iconSource . CreateIconElement ( ) as FontIcon ;
195+
196+ Verify . IsNotNull ( icon ) ;
197+ } ) ;
198+
199+ IdleSynchronizer . Wait ( ) ;
200+
201+ RunOnUIThread . Execute ( ( ) =>
202+ {
203+ Log . Comment ( "Verify foreground is not null before setting" ) ;
204+ Verify . IsNotNull ( icon . Foreground ) ;
205+
206+ Log . Comment ( "Change foreground on IconSource" ) ;
207+ iconSource . Foreground = new SolidColorBrush ( Microsoft . UI . Colors . Red ) ;
208+ } ) ;
209+
210+ IdleSynchronizer . Wait ( ) ;
211+
212+ RunOnUIThread . Execute ( ( ) =>
213+ {
214+ Log . Comment ( "Verify foreground propagates to created element" ) ;
215+ Verify . IsTrue ( icon . Foreground is SolidColorBrush ) ;
216+ Verify . AreEqual ( Microsoft . UI . Colors . Red , ( icon . Foreground as SolidColorBrush ) . Color ) ;
217+ } ) ;
218+ }
219+
220+ [ TestMethod ]
221+ public void CreateIconElementPreservesIconSourceProperties ( )
222+ {
223+ FontIconSource fontIconSource = null ;
224+ FontIcon fontIcon = null ;
225+
226+ RunOnUIThread . Execute ( ( ) =>
227+ {
228+ fontIconSource = new FontIconSource ( ) ;
229+ fontIconSource . Glyph = "\uE001 " ;
230+ fontIconSource . FontSize = 24 ;
231+ fontIconSource . FontFamily = new Microsoft . UI . Xaml . Media . FontFamily ( "Segoe UI Symbol" ) ;
232+ fontIconSource . Foreground = new SolidColorBrush ( Microsoft . UI . Colors . Purple ) ;
233+
234+ Log . Comment ( "Create icon element from configured source" ) ;
235+ fontIcon = fontIconSource . CreateIconElement ( ) as FontIcon ;
236+ Verify . IsNotNull ( fontIcon ) ;
237+ } ) ;
238+
239+ IdleSynchronizer . Wait ( ) ;
240+
241+ RunOnUIThread . Execute ( ( ) =>
242+ {
243+ Log . Comment ( "Verify all properties are transferred to the icon element" ) ;
244+ Verify . AreEqual ( "\uE001 " , fontIcon . Glyph ) ;
245+ Verify . AreEqual ( 24.0 , fontIcon . FontSize ) ;
246+ Verify . AreEqual ( "Segoe UI Symbol" , fontIcon . FontFamily . Source ) ;
247+ Verify . AreEqual ( Microsoft . UI . Colors . Purple , ( fontIcon . Foreground as SolidColorBrush ) . Color ) ;
248+ } ) ;
249+ }
114250 }
115251}
0 commit comments