2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
// See the LICENSE file in the project root for more information.
4
4
5
+ using System . Collections . Generic ;
5
6
using System . Threading . Tasks ;
6
7
using System . Windows ;
7
8
using System . Windows . Controls ;
@@ -15,24 +16,55 @@ namespace MahApps.Metro.Tests.Tests
15
16
[ TestFixture ]
16
17
public class ButtonTests
17
18
{
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
+
18
51
[ Test ]
19
- public async Task DefaultButtonTextIsUpperCase ( )
52
+ public void DefaultButtonTextIsUpperCase ( )
20
53
{
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" ) ;
23
57
24
58
Assert . That ( presenter , Is . Not . Null ) ;
25
59
Assert . That ( presenter . Content , Is . EqualTo ( "SOMETEXT" ) ) ;
26
-
27
- window . Close ( ) ;
28
60
}
29
61
30
62
[ Test ]
31
- public async Task DefaultButtonRespectsControlsHelperContentCharacterCasing ( )
63
+ public void DefaultButtonRespectsControlsHelperContentCharacterCasing ( )
32
64
{
33
- var window = await WindowHelpers . CreateInvisibleWindowAsync < ButtonWindow > ( ) . ConfigureAwait ( false ) ;
65
+ Assert . That ( this . window , Is . Not . Null ) ;
34
66
35
- Button defaultButton = window . DefaultButton ;
67
+ Button defaultButton = this . window . DefaultButton ;
36
68
Assert . That ( defaultButton , Is . Not . Null ) ;
37
69
38
70
var presenter = defaultButton . FindChild < ContentPresenter > ( "PART_ContentPresenter" ) ;
@@ -46,28 +78,25 @@ public async Task DefaultButtonRespectsControlsHelperContentCharacterCasing()
46
78
47
79
defaultButton . SetValue ( ControlsHelper . ContentCharacterCasingProperty , CharacterCasing . Upper ) ;
48
80
Assert . That ( presenter . Content , Is . EqualTo ( "SOMETEXT" ) ) ;
49
-
50
- window . Close ( ) ;
51
81
}
52
82
53
83
[ Test ]
54
- public async Task SquareButtonButtonTextIsLowerCase ( )
84
+ public void SquareButtonButtonTextIsLowerCase ( )
55
85
{
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" ) ;
58
89
59
90
Assert . That ( presenter , Is . Not . Null ) ;
60
91
Assert . That ( presenter . Content , Is . EqualTo ( "sometext" ) ) ;
61
-
62
- window . Close ( ) ;
63
92
}
64
93
65
94
[ Test ]
66
- public async Task SquareButtonRespectsButtonHelperContentCharacterCasing ( )
95
+ public void SquareButtonRespectsButtonHelperContentCharacterCasing ( )
67
96
{
68
- var window = await WindowHelpers . CreateInvisibleWindowAsync < ButtonWindow > ( ) . ConfigureAwait ( false ) ;
97
+ Assert . That ( this . window , Is . Not . Null ) ;
69
98
70
- Button squareButton = window . SquareButton ;
99
+ Button squareButton = this . window . SquareButton ;
71
100
Assert . That ( squareButton , Is . Not . Null ) ;
72
101
73
102
var presenter = squareButton . FindChild < ContentPresenter > ( "PART_ContentPresenter" ) ;
@@ -81,36 +110,30 @@ public async Task SquareButtonRespectsButtonHelperContentCharacterCasing()
81
110
82
111
squareButton . SetValue ( ControlsHelper . ContentCharacterCasingProperty , CharacterCasing . Upper ) ;
83
112
Assert . That ( presenter . Content , Is . EqualTo ( "SOMETEXT" ) ) ;
84
-
85
- window . Close ( ) ;
86
113
}
87
114
88
115
[ Test ]
89
- public async Task DropDownButtonShouldRespectParentIsEnabledProperty ( )
116
+ public void DropDownButtonShouldRespectParentIsEnabledProperty ( )
90
117
{
91
- var window = await WindowHelpers . CreateInvisibleWindowAsync < ButtonWindow > ( ) . ConfigureAwait ( false ) ;
118
+ Assert . That ( this . window , Is . Not . Null ) ;
92
119
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 ) ;
95
122
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 ) ;
100
125
}
101
126
102
127
[ Test ]
103
- public async Task SplitButtonShouldRespectParentIsEnabledProperty ( )
128
+ public void SplitButtonShouldRespectParentIsEnabledProperty ( )
104
129
{
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 ) ;
109
131
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 ) ;
112
134
113
- window . Close ( ) ;
135
+ this . window . TheStackPanel . SetCurrentValue ( UIElement . IsEnabledProperty , true ) ;
136
+ Assert . That ( this . window . TheSplitButton . IsEnabled , Is . True ) ;
114
137
}
115
138
}
116
139
}
0 commit comments