@@ -144,149 +144,172 @@ public async Task VerifySizeIsChangeableFromResource()
144144 double originalWidth = 0 ;
145145 double previousWidth = 0 ;
146146
147+ // Store original resource values for cleanup
148+ object originalFontSize = null ;
149+ object originalItemSpacing = null ;
150+
147151 RunOnUIThread . Execute ( ( ) =>
148152 {
149- var ratingControl = new RatingControl ( ) ;
153+ // Store original values
154+ originalFontSize = Application . Current . Resources [ "RatingControlFontSizeForRendering" ] ;
155+ originalItemSpacing = Application . Current . Resources [ "RatingControlItemSpacing" ] ;
156+ } ) ;
150157
151- ratingControl . Loaded += ( sender , e ) =>
158+ try
159+ {
160+ RunOnUIThread . Execute ( ( ) =>
152161 {
153- originalWidth = ratingControl . ActualWidth ;
154- previousWidth = originalWidth ;
155- loadedEvent . Set ( ) ;
156- } ;
162+ var ratingControl = new RatingControl ( ) ;
157163
158- ratingControl . Unloaded += ( sender , e ) => unloadedEvent . Set ( ) ;
164+ ratingControl . Loaded += ( sender , e ) =>
165+ {
166+ originalWidth = ratingControl . ActualWidth ;
167+ previousWidth = originalWidth ;
168+ loadedEvent . Set ( ) ;
169+ } ;
159170
160- Content = ratingControl ;
161- } ) ;
171+ ratingControl . Unloaded += ( sender , e ) => unloadedEvent . Set ( ) ;
162172
163- await loadedEvent . WaitOne ( ) ;
164- await TestServices . WindowHelper . WaitForIdle ( ) ;
173+ Content = ratingControl ;
174+ } ) ;
165175
166- RunOnUIThread . Execute ( ( ) =>
167- {
168- Content = null ;
169- } ) ;
170-
171- await unloadedEvent . WaitOne ( ) ;
172- await TestServices . WindowHelper . WaitForIdle ( ) ;
176+ await loadedEvent . WaitOne ( ) ;
177+ await TestServices . WindowHelper . WaitForIdle ( ) ;
173178
174- RunOnUIThread . Execute ( ( ) =>
175- {
176- Application . Current . Resources [ "RatingControlFontSizeForRendering" ] = 20.0 ;
179+ RunOnUIThread . Execute ( ( ) =>
180+ {
181+ Content = null ;
182+ } ) ;
177183
178- var ratingControl = new RatingControl ( ) ;
184+ await unloadedEvent . WaitOne ( ) ;
185+ await TestServices . WindowHelper . WaitForIdle ( ) ;
179186
180- ratingControl . Loaded += ( sender , e ) =>
187+ RunOnUIThread . Execute ( ( ) =>
181188 {
182- Verify . IsLessThan ( ratingControl . ActualWidth , previousWidth ) ;
183- previousWidth = ratingControl . ActualWidth ;
184- loadedEvent . Set ( ) ;
185- } ;
189+ Application . Current . Resources [ "RatingControlFontSizeForRendering" ] = 20.0 ;
186190
187- ratingControl . Unloaded += ( sender , e ) => unloadedEvent . Set ( ) ;
191+ var ratingControl = new RatingControl ( ) ;
188192
189- Content = ratingControl ;
190- } ) ;
193+ ratingControl . Loaded += ( sender , e ) =>
194+ {
195+ Verify . IsLessThan ( ratingControl . ActualWidth , previousWidth ) ;
196+ previousWidth = ratingControl . ActualWidth ;
197+ loadedEvent . Set ( ) ;
198+ } ;
191199
192- await loadedEvent . WaitOne ( ) ;
193- await TestServices . WindowHelper . WaitForIdle ( ) ;
200+ ratingControl . Unloaded += ( sender , e ) => unloadedEvent . Set ( ) ;
194201
195- RunOnUIThread . Execute ( ( ) =>
196- {
197- Content = null ;
198- } ) ;
202+ Content = ratingControl ;
203+ } ) ;
199204
200- await unloadedEvent . WaitOne ( ) ;
201- await TestServices . WindowHelper . WaitForIdle ( ) ;
205+ await loadedEvent . WaitOne ( ) ;
206+ await TestServices . WindowHelper . WaitForIdle ( ) ;
202207
203- RunOnUIThread . Execute ( ( ) =>
204- {
205- Application . Current . Resources [ "RatingControlItemSpacing" ] = 20.0 ;
208+ RunOnUIThread . Execute ( ( ) =>
209+ {
210+ Content = null ;
211+ } ) ;
206212
207- var ratingControl = new RatingControl ( ) ;
213+ await unloadedEvent . WaitOne ( ) ;
214+ await TestServices . WindowHelper . WaitForIdle ( ) ;
208215
209- ratingControl . Loaded += ( sender , e ) =>
216+ RunOnUIThread . Execute ( ( ) =>
210217 {
211- Verify . IsGreaterThan ( ratingControl . ActualWidth , previousWidth ) ;
212- previousWidth = ratingControl . ActualWidth ;
213- loadedEvent . Set ( ) ;
214- } ;
218+ Application . Current . Resources [ "RatingControlItemSpacing" ] = 20.0 ;
215219
216- ratingControl . Unloaded += ( sender , e ) => unloadedEvent . Set ( ) ;
220+ var ratingControl = new RatingControl ( ) ;
217221
218- Content = ratingControl ;
219- } ) ;
222+ ratingControl . Loaded += ( sender , e ) =>
223+ {
224+ Verify . IsGreaterThan ( ratingControl . ActualWidth , previousWidth ) ;
225+ previousWidth = ratingControl . ActualWidth ;
226+ loadedEvent . Set ( ) ;
227+ } ;
220228
221- await loadedEvent . WaitOne ( ) ;
222- await TestServices . WindowHelper . WaitForIdle ( ) ;
229+ ratingControl . Unloaded += ( sender , e ) => unloadedEvent . Set ( ) ;
223230
224- RunOnUIThread . Execute ( ( ) =>
225- {
226- Content = null ;
227- } ) ;
231+ Content = ratingControl ;
232+ } ) ;
228233
229- await unloadedEvent . WaitOne ( ) ;
230- await TestServices . WindowHelper . WaitForIdle ( ) ;
234+ await loadedEvent . WaitOne ( ) ;
235+ await TestServices . WindowHelper . WaitForIdle ( ) ;
231236
232- RunOnUIThread . Execute ( ( ) =>
233- {
234- Application . Current . Resources [ "RatingControlFontSizeForRendering" ] = 48.0 ;
235- Application . Current . Resources . Remove ( "RatingControlItemSpacing" ) ;
237+ RunOnUIThread . Execute ( ( ) =>
238+ {
239+ Content = null ;
240+ } ) ;
236241
237- var ratingControl = new RatingControl ( ) ;
242+ await unloadedEvent . WaitOne ( ) ;
243+ await TestServices . WindowHelper . WaitForIdle ( ) ;
238244
239- ratingControl . Loaded += ( sender , e ) =>
245+ RunOnUIThread . Execute ( ( ) =>
240246 {
241- Verify . IsGreaterThan ( ratingControl . ActualWidth , originalWidth ) ;
242- Verify . IsGreaterThan ( ratingControl . ActualWidth , previousWidth ) ;
243- previousWidth = ratingControl . ActualWidth ;
244- loadedEvent . Set ( ) ;
245- } ;
247+ Application . Current . Resources [ "RatingControlFontSizeForRendering" ] = 48.0 ;
248+ Application . Current . Resources . Remove ( "RatingControlItemSpacing" ) ;
246249
247- ratingControl . Unloaded += ( sender , e ) => unloadedEvent . Set ( ) ;
250+ var ratingControl = new RatingControl ( ) ;
248251
249- Content = ratingControl ;
250- } ) ;
252+ ratingControl . Loaded += ( sender , e ) =>
253+ {
254+ Verify . IsGreaterThan ( ratingControl . ActualWidth , originalWidth ) ;
255+ Verify . IsGreaterThan ( ratingControl . ActualWidth , previousWidth ) ;
256+ previousWidth = ratingControl . ActualWidth ;
257+ loadedEvent . Set ( ) ;
258+ } ;
251259
252- await loadedEvent . WaitOne ( ) ;
253- await TestServices . WindowHelper . WaitForIdle ( ) ;
260+ ratingControl . Unloaded += ( sender , e ) => unloadedEvent . Set ( ) ;
254261
255- RunOnUIThread . Execute ( ( ) =>
256- {
257- Content = null ;
258- } ) ;
262+ Content = ratingControl ;
263+ } ) ;
259264
260- await unloadedEvent . WaitOne ( ) ;
261- await TestServices . WindowHelper . WaitForIdle ( ) ;
265+ await loadedEvent . WaitOne ( ) ;
266+ await TestServices . WindowHelper . WaitForIdle ( ) ;
262267
263- RunOnUIThread . Execute ( ( ) =>
264- {
265- Application . Current . Resources [ "RatingControlItemSpacing" ] = 2.0 ;
268+ RunOnUIThread . Execute ( ( ) =>
269+ {
270+ Content = null ;
271+ } ) ;
266272
267- var ratingControl = new RatingControl ( ) ;
273+ await unloadedEvent . WaitOne ( ) ;
274+ await TestServices . WindowHelper . WaitForIdle ( ) ;
268275
269- ratingControl . Loaded += ( sender , e ) =>
276+ RunOnUIThread . Execute ( ( ) =>
270277 {
271- Verify . IsLessThan ( ratingControl . ActualWidth , previousWidth ) ;
272- loadedEvent . Set ( ) ;
273- } ;
278+ Application . Current . Resources [ "RatingControlItemSpacing" ] = 2.0 ;
274279
275- ratingControl . Unloaded += ( sender , e ) => unloadedEvent . Set ( ) ;
280+ var ratingControl = new RatingControl ( ) ;
276281
277- Content = ratingControl ;
278- } ) ;
282+ ratingControl . Loaded += ( sender , e ) =>
283+ {
284+ Verify . IsLessThan ( ratingControl . ActualWidth , previousWidth ) ;
285+ loadedEvent . Set ( ) ;
286+ } ;
279287
280- await loadedEvent . WaitOne ( ) ;
281- await TestServices . WindowHelper . WaitForIdle ( ) ;
288+ ratingControl . Unloaded += ( sender , e ) => unloadedEvent . Set ( ) ;
282289
283- RunOnUIThread . Execute ( ( ) =>
284- {
285- Content = null ;
286- } ) ;
290+ Content = ratingControl ;
291+ } ) ;
287292
288- await unloadedEvent . WaitOne ( ) ;
289- await TestServices . WindowHelper . WaitForIdle ( ) ;
293+ await loadedEvent . WaitOne ( ) ;
294+ await TestServices . WindowHelper . WaitForIdle ( ) ;
295+
296+ RunOnUIThread . Execute ( ( ) =>
297+ {
298+ Content = null ;
299+ } ) ;
300+
301+ await unloadedEvent . WaitOne ( ) ;
302+ await TestServices . WindowHelper . WaitForIdle ( ) ;
303+ }
304+ finally
305+ {
306+ // Restore original resource values
307+ RunOnUIThread . Execute ( ( ) =>
308+ {
309+ Application . Current . Resources [ "RatingControlFontSizeForRendering" ] = originalFontSize ;
310+ Application . Current . Resources [ "RatingControlItemSpacing" ] = originalItemSpacing ;
311+ } ) ;
312+ }
290313 }
291314 }
292315}
0 commit comments