@@ -27,19 +27,25 @@ public void Popup_SetPopupOptionsDefaultsNotCalled_UsesPopupOptionsDefaults()
2727 var popupPage = new PopupPage ( new Popup ( ) , null ) ;
2828 var popupBorder = popupPage . Content . PopupBorder ;
2929
30- var tapGestureRecognizer = GetTapOutsideGestureRecognizer ( popupPage ) ;
31-
3230 // Assert
33- Assert . True ( tapGestureRecognizer . Command ? . CanExecute ( null ) ) ;
31+ try
32+ {
33+ // Run using AsyncContext to catch Exception thrown by fire-and-forget ICommand.Execute
34+ AsyncContext . Run ( ( ) => Assert . True ( popupPage . TryExecuteTapOutsideOfPopupCommand ( ) ) ) ;
35+ }
36+ catch ( PopupNotFoundException ) // PopupNotFoundException is expected here because `ShowPopup` was never called
37+ {
38+ }
39+
3440 Assert . Equal ( 2 , popupBorder . StrokeThickness ) ;
3541 Assert . Equal ( Colors . LightGray , popupBorder . Stroke ) ;
3642 Assert . Equal ( Colors . Black . WithAlpha ( 0.3f ) , popupPage . BackgroundColor ) ;
37-
43+
3844 Assert . Equal ( Colors . Black , popupBorder . Shadow . Brush ) ;
3945 Assert . Equal ( new ( 20 , 20 ) , popupBorder . Shadow . Offset ) ;
4046 Assert . Equal ( 40 , popupBorder . Shadow . Radius ) ;
4147 Assert . Equal ( 0.8f , popupBorder . Shadow . Opacity ) ;
42-
48+
4349 Assert . Equal ( new CornerRadius ( 20 , 20 , 20 , 20 ) , ( ( RoundRectangle ? ) popupBorder . StrokeShape ) ? . CornerRadius ) ;
4450 Assert . Equal ( 2 , ( ( RoundRectangle ? ) popupBorder . StrokeShape ) ? . StrokeThickness ) ;
4551 Assert . Equal ( Colors . LightGray , ( ( RoundRectangle ? ) popupBorder . StrokeShape ) ? . Stroke ) ;
@@ -52,19 +58,25 @@ public void Popup_SetPopupOptionsNotCalled_PopupOptionsEmptyUsed_UsesPopupOption
5258 var popupPage = new PopupPage ( new Popup ( ) , PopupOptions . Empty ) ;
5359 var popupBorder = popupPage . Content . PopupBorder ;
5460
55- var tapGestureRecognizer = GetTapOutsideGestureRecognizer ( popupPage ) ;
56-
5761 // Assert
58- Assert . True ( tapGestureRecognizer . Command ? . CanExecute ( null ) ) ;
62+ try
63+ {
64+ // Run using AsyncContext to catch Exception thrown by fire-and-forget ICommand.Execute
65+ AsyncContext . Run ( ( ) => Assert . True ( popupPage . TryExecuteTapOutsideOfPopupCommand ( ) ) ) ;
66+ }
67+ catch ( PopupNotFoundException ) // PopupNotFoundException is expected here because `ShowPopup` was never called
68+ {
69+ }
70+
5971 Assert . Equal ( 2 , popupBorder . StrokeThickness ) ;
6072 Assert . Equal ( Colors . LightGray , popupBorder . Stroke ) ;
6173 Assert . Equal ( Colors . Black . WithAlpha ( 0.3f ) , popupPage . BackgroundColor ) ;
62-
74+
6375 Assert . Equal ( Colors . Black , popupBorder . Shadow . Brush ) ;
6476 Assert . Equal ( new ( 20 , 20 ) , popupBorder . Shadow . Offset ) ;
6577 Assert . Equal ( 40 , popupBorder . Shadow . Radius ) ;
6678 Assert . Equal ( 0.8f , popupBorder . Shadow . Opacity ) ;
67-
79+
6880 Assert . Equal ( new CornerRadius ( 20 , 20 , 20 , 20 ) , ( ( RoundRectangle ? ) popupBorder . StrokeShape ) ? . CornerRadius ) ;
6981 Assert . Equal ( 2 , ( ( RoundRectangle ? ) popupBorder . StrokeShape ) ? . StrokeThickness ) ;
7082 Assert . Equal ( Colors . LightGray , ( ( RoundRectangle ? ) popupBorder . StrokeShape ) ? . Stroke ) ;
@@ -90,20 +102,18 @@ public void Popup_SetPopupDefaultsCalled_UsesDefaultPopupOptionsSettings()
90102
91103 var popupPage = new PopupPage ( new Popup ( ) , null ) ;
92104 var popupBorder = popupPage . Content . PopupBorder ;
93- var tapGestureRecognizer = GetTapOutsideGestureRecognizer ( popupPage ) ;
94105
95106 // Act
96107 try
97108 {
98109 // Run using AsyncContext to catch Exception thrown by fire-and-forget ICommand.Execute
99- AsyncContext . Run ( ( ) => { tapGestureRecognizer . Command ? . Execute ( null ) ; } ) ;
110+ AsyncContext . Run ( ( ) => Assert . True ( popupPage . TryExecuteTapOutsideOfPopupCommand ( ) ) ) ;
100111 }
101112 catch ( PopupNotFoundException ) // PopupNotFoundException is expected here because `ShowPopup` was never called
102113 {
103114 }
104115
105- // // Assert
106- Assert . True ( tapGestureRecognizer . Command ? . CanExecute ( null ) ) ;
116+ // Assert
107117 Assert . True ( hasOnTappingOutsideOfPopupExecuted ) ;
108118 Assert . Equal ( defaultPopupSettings . PageOverlayColor , popupPage . BackgroundColor ) ;
109119 Assert . Equal ( defaultPopupSettings . Shadow , popupBorder . Shadow ) ;
@@ -130,20 +140,18 @@ public void Popup_SetPopupDefaultsCalled_PopupOptionsOverridden_UsesProvidedPopu
130140
131141 var popupPage = new PopupPage ( new Popup ( ) , defaultPopupSettings ) ;
132142 var popupBorder = popupPage . Content . PopupBorder ;
133- var tapGestureRecognizer = GetTapOutsideGestureRecognizer ( popupPage ) ;
134143
135144 // Act
136145 try
137146 {
138147 // Run using AsyncContext to catch Exception thrown by fire-and-forget ICommand.Execute
139- AsyncContext . Run ( ( ) => { tapGestureRecognizer . Command ? . Execute ( null ) ; } ) ;
148+ AsyncContext . Run ( ( ) => Assert . True ( popupPage . TryExecuteTapOutsideOfPopupCommand ( ) ) ) ;
140149 }
141150 catch ( PopupNotFoundException ) // PopupNotFoundException is expected here because `ShowPopup` was never called
142151 {
143152 }
144153
145154 // // Assert
146- Assert . True ( tapGestureRecognizer . Command ? . CanExecute ( null ) ) ;
147155 Assert . True ( hasOnTappingOutsideOfPopupExecuted ) ;
148156 Assert . Equal ( defaultPopupSettings . PageOverlayColor , popupPage . BackgroundColor ) ;
149157 Assert . Equal ( defaultPopupSettings . Shadow , popupBorder . Shadow ) ;
@@ -157,19 +165,25 @@ public void View_SetPopupOptionsDefaultsNotCalled_UsesPopupOptionsDefaults()
157165 var popupPage = new PopupPage ( new View ( ) , null ) ;
158166 var popupBorder = popupPage . Content . PopupBorder ;
159167
160- var tapGestureRecognizer = GetTapOutsideGestureRecognizer ( popupPage ) ;
161-
162168 // Assert
163- Assert . True ( tapGestureRecognizer . Command ? . CanExecute ( null ) ) ;
169+ try
170+ {
171+ // Run using AsyncContext to catch Exception thrown by fire-and-forget ICommand.Execute
172+ AsyncContext . Run ( ( ) => Assert . True ( popupPage . TryExecuteTapOutsideOfPopupCommand ( ) ) ) ;
173+ }
174+ catch ( PopupNotFoundException ) // PopupNotFoundException is expected here because `ShowPopup` was never called
175+ {
176+ }
177+
164178 Assert . Equal ( 2 , popupBorder . StrokeThickness ) ;
165179 Assert . Equal ( Colors . LightGray , popupBorder . Stroke ) ;
166180 Assert . Equal ( Colors . Black . WithAlpha ( 0.3f ) , popupPage . BackgroundColor ) ;
167-
181+
168182 Assert . Equal ( Colors . Black , popupBorder . Shadow . Brush ) ;
169183 Assert . Equal ( new ( 20 , 20 ) , popupBorder . Shadow . Offset ) ;
170184 Assert . Equal ( 40 , popupBorder . Shadow . Radius ) ;
171185 Assert . Equal ( 0.8f , popupBorder . Shadow . Opacity ) ;
172-
186+
173187 Assert . Equal ( new CornerRadius ( 20 , 20 , 20 , 20 ) , ( ( RoundRectangle ? ) popupBorder . StrokeShape ) ? . CornerRadius ) ;
174188 Assert . Equal ( 2 , ( ( RoundRectangle ? ) popupBorder . StrokeShape ) ? . StrokeThickness ) ;
175189 Assert . Equal ( Colors . LightGray , ( ( RoundRectangle ? ) popupBorder . StrokeShape ) ? . Stroke ) ;
@@ -182,19 +196,24 @@ public void View_SetPopupOptionsNotCalled_PopupOptionsEmptyUsed_UsesPopupOptions
182196 var popupPage = new PopupPage ( new View ( ) , PopupOptions . Empty ) ;
183197 var popupBorder = popupPage . Content . PopupBorder ;
184198
185- var tapGestureRecognizer = GetTapOutsideGestureRecognizer ( popupPage ) ;
186-
187- // Assert
188- Assert . True ( tapGestureRecognizer . Command ? . CanExecute ( null ) ) ;
199+ // Assert
200+ try
201+ {
202+ // Run using AsyncContext to catch Exception thrown by fire-and-forget ICommand.Execute
203+ AsyncContext . Run ( ( ) => Assert . True ( popupPage . TryExecuteTapOutsideOfPopupCommand ( ) ) ) ;
204+ }
205+ catch ( PopupNotFoundException ) // PopupNotFoundException is expected here because `ShowPopup` was never called
206+ {
207+ }
189208 Assert . Equal ( 2 , popupBorder . StrokeThickness ) ;
190209 Assert . Equal ( Colors . LightGray , popupBorder . Stroke ) ;
191210 Assert . Equal ( Colors . Black . WithAlpha ( 0.3f ) , popupPage . BackgroundColor ) ;
192-
211+
193212 Assert . Equal ( Colors . Black , popupBorder . Shadow . Brush ) ;
194213 Assert . Equal ( new ( 20 , 20 ) , popupBorder . Shadow . Offset ) ;
195214 Assert . Equal ( 40 , popupBorder . Shadow . Radius ) ;
196215 Assert . Equal ( 0.8f , popupBorder . Shadow . Opacity ) ;
197-
216+
198217 Assert . Equal ( new CornerRadius ( 20 , 20 , 20 , 20 ) , ( ( RoundRectangle ? ) popupBorder . StrokeShape ) ? . CornerRadius ) ;
199218 Assert . Equal ( 2 , ( ( RoundRectangle ? ) popupBorder . StrokeShape ) ? . StrokeThickness ) ;
200219 Assert . Equal ( Colors . LightGray , ( ( RoundRectangle ? ) popupBorder . StrokeShape ) ? . Stroke ) ;
@@ -220,20 +239,18 @@ public void View_SetPopupDefaultsCalled_UsesDefaultPopupOptionsSettings()
220239
221240 var popupPage = new PopupPage ( new View ( ) , null ) ;
222241 var popupBorder = popupPage . Content . PopupBorder ;
223- var tapGestureRecognizer = GetTapOutsideGestureRecognizer ( popupPage ) ;
224242
225243 // Act
226244 try
227245 {
228246 // Run using AsyncContext to catch Exception thrown by fire-and-forget ICommand.Execute
229- AsyncContext . Run ( ( ) => { tapGestureRecognizer . Command ? . Execute ( null ) ; } ) ;
247+ AsyncContext . Run ( ( ) => Assert . True ( popupPage . TryExecuteTapOutsideOfPopupCommand ( ) ) ) ;
230248 }
231249 catch ( PopupNotFoundException ) // PopupNotFoundException is expected here because `ShowPopup` was never called
232250 {
233251 }
234252
235- // // Assert
236- Assert . True ( tapGestureRecognizer . Command ? . CanExecute ( null ) ) ;
253+ // Assert
237254 Assert . True ( hasOnTappingOutsideOfPopupExecuted ) ;
238255 Assert . Equal ( defaultPopupSettings . PageOverlayColor , popupPage . BackgroundColor ) ;
239256 Assert . Equal ( defaultPopupSettings . Shadow , popupBorder . Shadow ) ;
@@ -260,28 +277,21 @@ public void View_SetPopupDefaultsCalled_PopupOptionsOverridden_UsesProvidedPopup
260277
261278 var popupPage = new PopupPage ( new View ( ) , defaultPopupSettings ) ;
262279 var popupBorder = popupPage . Content . PopupBorder ;
263- var tapGestureRecognizer = GetTapOutsideGestureRecognizer ( popupPage ) ;
264280
265- // Act
281+ // // Assert
266282 try
267283 {
268284 // Run using AsyncContext to catch Exception thrown by fire-and-forget ICommand.Execute
269- AsyncContext . Run ( ( ) => { tapGestureRecognizer . Command ? . Execute ( null ) ; } ) ;
285+ AsyncContext . Run ( ( ) => Assert . True ( popupPage . TryExecuteTapOutsideOfPopupCommand ( ) ) ) ;
270286 }
271287 catch ( PopupNotFoundException ) // PopupNotFoundException is expected here because `ShowPopup` was never called
272288 {
273289 }
274290
275- // // Assert
276- Assert . True ( tapGestureRecognizer . Command ? . CanExecute ( null ) ) ;
277291 Assert . True ( hasOnTappingOutsideOfPopupExecuted ) ;
278292 Assert . Equal ( defaultPopupSettings . PageOverlayColor , popupPage . BackgroundColor ) ;
279293 Assert . Equal ( defaultPopupSettings . Shadow , popupBorder . Shadow ) ;
280294 Assert . Equal ( defaultPopupSettings . Shape , popupBorder . StrokeShape ) ;
281295 }
282-
283-
284- static TapGestureRecognizer GetTapOutsideGestureRecognizer ( PopupPage popupPage ) =>
285- ( TapGestureRecognizer ) popupPage . Content . Children . OfType < BoxView > ( ) . Single ( ) . GestureRecognizers [ 0 ] ;
286296}
287297#pragma warning restore CA1416
0 commit comments