22// The .NET Foundation licenses this file to you under the MIT license. 
33// See the LICENSE file in the project root for more information. 
44
5+ using  System . Collections . Generic ; 
56using  System . Threading . Tasks ; 
67using  System . Windows ; 
78using  System . Windows . Controls ; 
@@ -15,24 +16,55 @@ namespace MahApps.Metro.Tests.Tests
1516    [ TestFixture ] 
1617    public  class  ButtonTests 
1718    { 
19+         private  ButtonWindow ?  window ; 
20+ 
21+         [ OneTimeSetUp ] 
22+         public  async  Task  OneTimeSetUp ( ) 
23+         { 
24+             this . window  =  await  WindowHelpers . CreateInvisibleWindowAsync < ButtonWindow > ( ) . ConfigureAwait ( false ) ; 
25+         } 
26+ 
27+         [ OneTimeTearDown ] 
28+         public  void  OneTimeTearDown ( ) 
29+         { 
30+             this . window ? . Close ( ) ; 
31+             this . window  =  null ; 
32+         } 
33+ 
34+         [ SetUp ] 
35+         public  void  SetUp ( ) 
36+         { 
37+             this . PreparePropertiesForTest ( [ 
38+                 ControlsHelper . ContentCharacterCasingProperty . Name , 
39+                 UIElement . IsEnabledProperty . Name 
40+             ] ) ; 
41+         } 
42+ 
43+         private  void  PreparePropertiesForTest ( IList < string > ?  properties  =  null ) 
44+         { 
45+             this . window ? . DefaultButton . ClearDependencyProperties ( properties ) ; 
46+             this . window ? . SquareButton . ClearDependencyProperties ( properties ) ; 
47+             this . window ? . TheDropDownButton . ClearDependencyProperties ( properties ) ; 
48+             this . window ? . TheSplitButton . ClearDependencyProperties ( properties ) ; 
49+         } 
50+ 
1851        [ Test ] 
19-         public  async   Task  DefaultButtonTextIsUpperCase ( ) 
52+         public  void  DefaultButtonTextIsUpperCase ( ) 
2053        { 
21-             var  window  =  await  WindowHelpers . CreateInvisibleWindowAsync < ButtonWindow > ( ) . ConfigureAwait ( false ) ; 
22-             var  presenter  =  window . DefaultButton . FindChild < ContentPresenter > ( "PART_ContentPresenter" ) ; 
54+             Assert . That ( this . window ,  Is . Not . Null ) ; 
55+ 
56+             var  presenter  =  this . window . DefaultButton . FindChild < ContentPresenter > ( "PART_ContentPresenter" ) ; 
2357
2458            Assert . That ( presenter ,  Is . Not . Null ) ; 
2559            Assert . That ( presenter . Content ,  Is . EqualTo ( "SOMETEXT" ) ) ; 
26- 
27-             window . Close ( ) ; 
2860        } 
2961
3062        [ Test ] 
31-         public  async   Task  DefaultButtonRespectsControlsHelperContentCharacterCasing ( ) 
63+         public  void  DefaultButtonRespectsControlsHelperContentCharacterCasing ( ) 
3264        { 
33-             var   window   =   await   WindowHelpers . CreateInvisibleWindowAsync < ButtonWindow > ( ) . ConfigureAwait ( false ) ; 
65+             Assert . That ( this . window ,   Is . Not . Null ) ; 
3466
35-             Button  defaultButton  =  window . DefaultButton ; 
67+             Button  defaultButton  =  this . window . DefaultButton ; 
3668            Assert . That ( defaultButton ,  Is . Not . Null ) ; 
3769
3870            var  presenter  =  defaultButton . FindChild < ContentPresenter > ( "PART_ContentPresenter" ) ; 
@@ -46,28 +78,25 @@ public async Task DefaultButtonRespectsControlsHelperContentCharacterCasing()
4678
4779            defaultButton . SetValue ( ControlsHelper . ContentCharacterCasingProperty ,  CharacterCasing . Upper ) ; 
4880            Assert . That ( presenter . Content ,  Is . EqualTo ( "SOMETEXT" ) ) ; 
49- 
50-             window . Close ( ) ; 
5181        } 
5282
5383        [ Test ] 
54-         public  async   Task  SquareButtonButtonTextIsLowerCase ( ) 
84+         public  void  SquareButtonButtonTextIsLowerCase ( ) 
5585        { 
56-             var  window  =  await  WindowHelpers . CreateInvisibleWindowAsync < ButtonWindow > ( ) . ConfigureAwait ( false ) ; 
57-             var  presenter  =  window . SquareButton . FindChild < ContentPresenter > ( "PART_ContentPresenter" ) ; 
86+             Assert . That ( this . window ,  Is . Not . Null ) ; 
87+ 
88+             var  presenter  =  this . window . SquareButton . FindChild < ContentPresenter > ( "PART_ContentPresenter" ) ; 
5889
5990            Assert . That ( presenter ,  Is . Not . Null ) ; 
6091            Assert . That ( presenter . Content ,  Is . EqualTo ( "sometext" ) ) ; 
61- 
62-             window . Close ( ) ; 
6392        } 
6493
6594        [ Test ] 
66-         public  async   Task  SquareButtonRespectsButtonHelperContentCharacterCasing ( ) 
95+         public  void  SquareButtonRespectsButtonHelperContentCharacterCasing ( ) 
6796        { 
68-             var   window   =   await   WindowHelpers . CreateInvisibleWindowAsync < ButtonWindow > ( ) . ConfigureAwait ( false ) ; 
97+             Assert . That ( this . window ,   Is . Not . Null ) ; 
6998
70-             Button  squareButton  =  window . SquareButton ; 
99+             Button  squareButton  =  this . window . SquareButton ; 
71100            Assert . That ( squareButton ,  Is . Not . Null ) ; 
72101
73102            var  presenter  =  squareButton . FindChild < ContentPresenter > ( "PART_ContentPresenter" ) ; 
@@ -81,36 +110,30 @@ public async Task SquareButtonRespectsButtonHelperContentCharacterCasing()
81110
82111            squareButton . SetValue ( ControlsHelper . ContentCharacterCasingProperty ,  CharacterCasing . Upper ) ; 
83112            Assert . That ( presenter . Content ,  Is . EqualTo ( "SOMETEXT" ) ) ; 
84- 
85-             window . Close ( ) ; 
86113        } 
87114
88115        [ Test ] 
89-         public  async   Task  DropDownButtonShouldRespectParentIsEnabledProperty ( ) 
116+         public  void  DropDownButtonShouldRespectParentIsEnabledProperty ( ) 
90117        { 
91-             var   window   =   await   WindowHelpers . CreateInvisibleWindowAsync < ButtonWindow > ( ) . ConfigureAwait ( false ) ; 
118+             Assert . That ( this . window ,   Is . Not . Null ) ; 
92119
93-             window . TheStackPanel . SetCurrentValue ( UIElement . IsEnabledProperty ,  false ) ; 
94-             Assert . That ( window . TheDropDownButton . IsEnabled ,  Is . False ) ; 
120+             this . window . TheStackPanel . SetCurrentValue ( UIElement . IsEnabledProperty ,  false ) ; 
121+             Assert . That ( this . window . TheDropDownButton . IsEnabled ,  Is . False ) ; 
95122
96-             window . TheStackPanel . SetCurrentValue ( UIElement . IsEnabledProperty ,  true ) ; 
97-             Assert . That ( window . TheDropDownButton . IsEnabled ,  Is . True ) ; 
98- 
99-             window . Close ( ) ; 
123+             this . window . TheStackPanel . SetCurrentValue ( UIElement . IsEnabledProperty ,  true ) ; 
124+             Assert . That ( this . window . TheDropDownButton . IsEnabled ,  Is . True ) ; 
100125        } 
101126
102127        [ Test ] 
103-         public  async   Task  SplitButtonShouldRespectParentIsEnabledProperty ( ) 
128+         public  void  SplitButtonShouldRespectParentIsEnabledProperty ( ) 
104129        { 
105-             var  window  =  await  WindowHelpers . CreateInvisibleWindowAsync < ButtonWindow > ( ) . ConfigureAwait ( false ) ; 
106- 
107-             window . TheStackPanel . SetCurrentValue ( UIElement . IsEnabledProperty ,  false ) ; 
108-             Assert . That ( window . TheSplitButton . IsEnabled ,  Is . False ) ; 
130+             Assert . That ( this . window ,  Is . Not . Null ) ; 
109131
110-             window . TheStackPanel . SetCurrentValue ( UIElement . IsEnabledProperty ,  true ) ; 
111-             Assert . That ( window . TheSplitButton . IsEnabled ,  Is . True ) ; 
132+             this . window . TheStackPanel . SetCurrentValue ( UIElement . IsEnabledProperty ,  false ) ; 
133+             Assert . That ( this . window . TheSplitButton . IsEnabled ,  Is . False ) ; 
112134
113-             window . Close ( ) ; 
135+             this . window . TheStackPanel . SetCurrentValue ( UIElement . IsEnabledProperty ,  true ) ; 
136+             Assert . That ( this . window . TheSplitButton . IsEnabled ,  Is . True ) ; 
114137        } 
115138    } 
116139} 
0 commit comments