@@ -231,6 +231,29 @@ public void TextBlockForegroundConverter_ShouldReturnFractionalGradientStops_Whe
231
231
Assert . Equal ( brush . Color . WithAlphaChannel ( RatingBar . TextBlockForegroundConverter . SemiTransparent ) , stop2 . Color ) ;
232
232
}
233
233
234
+ [ Fact ]
235
+ public void TextBlockForegroundConverter_ShouldReturnFractionalGradientStops_WhenValueCovers10PercentOfButtonValueAndDirectionIsInverted ( )
236
+ {
237
+ // Arrange
238
+ SolidColorBrush brush = Brushes . Red ;
239
+ IMultiValueConverter converter = RatingBar . TextBlockForegroundConverter . Instance ;
240
+ object [ ] values = Arrange_TextBlockForegroundConverterValues ( brush , value : 1.1 , buttonValue : 2 , invertDirection : true ) ;
241
+
242
+ // Act
243
+ var result = converter . Convert ( values , typeof ( Brush ) , null , CultureInfo . CurrentCulture ) as Brush ;
244
+
245
+ // Assert
246
+ Assert . IsAssignableFrom < LinearGradientBrush > ( result ) ;
247
+ LinearGradientBrush resultBrush = ( LinearGradientBrush ) result ! ;
248
+ Assert . Equal ( 2 , resultBrush . GradientStops . Count ) ;
249
+ GradientStop stop1 = resultBrush . GradientStops [ 0 ] ;
250
+ GradientStop stop2 = resultBrush . GradientStops [ 1 ] ;
251
+ Assert . Equal ( 0.9 , stop1 . Offset , 10 ) ;
252
+ Assert . Equal ( brush . Color . WithAlphaChannel ( RatingBar . TextBlockForegroundConverter . SemiTransparent ) , stop1 . Color ) ;
253
+ Assert . Equal ( 0.9 , stop2 . Offset , 10 ) ;
254
+ Assert . Equal ( brush . Color , stop2 . Color ) ;
255
+ }
256
+
234
257
[ Fact ]
235
258
public void TextBlockForegroundConverter_ShouldReturnFractionalGradientStops_WhenValueCovers42PercentOfButtonValue ( )
236
259
{
@@ -277,15 +300,15 @@ public void TextBlockForegroundConverter_ShouldReturnFractionalGradientStops_Whe
277
300
Assert . Equal ( brush . Color . WithAlphaChannel ( RatingBar . TextBlockForegroundConverter . SemiTransparent ) , stop2 . Color ) ;
278
301
}
279
302
280
- private static object [ ] Arrange_TextBlockForegroundConverterValues ( SolidColorBrush brush , double value , int buttonValue , Orientation orientation = Orientation . Horizontal ) =>
281
- new object [ ] { brush , orientation , value , buttonValue } ;
303
+ private static object [ ] Arrange_TextBlockForegroundConverterValues ( SolidColorBrush brush , double value , int buttonValue , Orientation orientation = Orientation . Horizontal , bool invertDirection = false ) =>
304
+ new object [ ] { brush , orientation , invertDirection , value , buttonValue } ;
282
305
283
306
[ Fact ]
284
307
public void PreviewIndicatorTransformXConverter_ShouldCenterPreviewIndicator_WhenFractionalValuesAreDisabledAndOrientationIsHorizontal ( )
285
308
{
286
309
// Arrange
287
310
IMultiValueConverter converter = RatingBar . PreviewIndicatorTransformXConverter . Instance ;
288
- object [ ] values = Arrange_PreviewIndicatorTransformXConverterValues ( 100 , 20 , Orientation . Horizontal , false , 1 , 1 ) ;
311
+ object [ ] values = Arrange_PreviewIndicatorTransformXConverterValues ( 100 , 20 , Orientation . Horizontal , false , false , 1 , 1 ) ;
289
312
290
313
// Act
291
314
double ? result = converter . Convert ( values , typeof ( double ) , null , CultureInfo . CurrentCulture ) as double ? ;
@@ -295,27 +318,29 @@ public void PreviewIndicatorTransformXConverter_ShouldCenterPreviewIndicator_Whe
295
318
Assert . Equal ( 40.0 , result ) ; // 50% of 100 minus 20/2
296
319
}
297
320
298
- [ Fact ]
299
- public void PreviewIndicatorTransformXConverter_ShouldOffsetPreviewIndicatorByPercentage_WhenFractionalValuesAreEnabledAndOrientationIsHorizontal ( )
321
+ [ Theory ]
322
+ [ InlineData ( false , 15.0 ) ] // 25% of 100 minus 20/2
323
+ [ InlineData ( true , 65.0 ) ] // 75% of 100 minus 20/2
324
+ public void PreviewIndicatorTransformXConverter_ShouldOffsetPreviewIndicatorByPercentage_WhenFractionalValuesAreEnabledAndOrientationIsHorizontal ( bool invertDirection , double expectedValue )
300
325
{
301
326
// Arrange
302
327
IMultiValueConverter converter = RatingBar . PreviewIndicatorTransformXConverter . Instance ;
303
- object [ ] values = Arrange_PreviewIndicatorTransformXConverterValues ( 100 , 20 , Orientation . Horizontal , true , 1.25 , 1 ) ;
328
+ object [ ] values = Arrange_PreviewIndicatorTransformXConverterValues ( 100 , 20 , Orientation . Horizontal , invertDirection , true , 1.25 , 1 ) ;
304
329
305
330
// Act
306
331
double ? result = converter . Convert ( values , typeof ( double ) , null , CultureInfo . CurrentCulture ) as double ? ;
307
332
308
333
// Assert
309
334
Assert . NotNull ( result ) ;
310
- Assert . Equal ( 15.0 , result ) ; // 25% of 100 minus 20/2
335
+ Assert . Equal ( expectedValue , result ) ;
311
336
}
312
337
313
338
[ Fact ]
314
339
public void PreviewIndicatorTransformXConverter_ShouldPlacePreviewIndicatorWithSmallMargin_WhenFractionalValuesAreDisabledAndOrientationIsVertical ( )
315
340
{
316
341
// Arrange
317
342
IMultiValueConverter converter = RatingBar . PreviewIndicatorTransformXConverter . Instance ;
318
- object [ ] values = Arrange_PreviewIndicatorTransformXConverterValues ( 100 , 20 , Orientation . Vertical , false , 1 , 1 ) ;
343
+ object [ ] values = Arrange_PreviewIndicatorTransformXConverterValues ( 100 , 20 , Orientation . Vertical , false , false , 1 , 1 ) ;
319
344
double expectedValue = - 20 - RatingBar . PreviewIndicatorTransformXConverter . Margin ;
320
345
321
346
// Act
@@ -331,7 +356,7 @@ public void PreviewIndicatorTransformXConverter_ShouldPlacePreviewIndicatorWithS
331
356
{
332
357
// Arrange
333
358
IMultiValueConverter converter = RatingBar . PreviewIndicatorTransformXConverter . Instance ;
334
- object [ ] values = Arrange_PreviewIndicatorTransformXConverterValues ( 100 , 20 , Orientation . Vertical , true , 1.25 , 1 ) ;
359
+ object [ ] values = Arrange_PreviewIndicatorTransformXConverterValues ( 100 , 20 , Orientation . Vertical , false , true , 1.25 , 1 ) ;
335
360
double expectedValue = - 20 - RatingBar . PreviewIndicatorTransformXConverter . Margin ;
336
361
337
362
// Act
@@ -344,15 +369,15 @@ public void PreviewIndicatorTransformXConverter_ShouldPlacePreviewIndicatorWithS
344
369
345
370
346
371
347
- private static object [ ] Arrange_PreviewIndicatorTransformXConverterValues ( double ratingBarButtonActualWidth , double previewValueActualWidth , Orientation orientation , bool isFractionalValueEnabled , double previewValue , int buttonValue ) =>
348
- new object [ ] { ratingBarButtonActualWidth , previewValueActualWidth , orientation , isFractionalValueEnabled , previewValue , buttonValue } ;
372
+ private static object [ ] Arrange_PreviewIndicatorTransformXConverterValues ( double ratingBarButtonActualWidth , double previewValueActualWidth , Orientation orientation , bool invertDirection , bool isFractionalValueEnabled , double previewValue , int buttonValue ) =>
373
+ new object [ ] { ratingBarButtonActualWidth , previewValueActualWidth , orientation , invertDirection , isFractionalValueEnabled , previewValue , buttonValue } ;
349
374
350
375
[ Fact ]
351
376
public void PreviewIndicatorTransformYConverter_ShouldPlacePreviewIndicatorWithSmallMargin_WhenFractionalValuesAreDisabledAndOrientationIsHorizontal ( )
352
377
{
353
378
// Arrange
354
379
IMultiValueConverter converter = RatingBar . PreviewIndicatorTransformYConverter . Instance ;
355
- object [ ] values = Arrange_PreviewIndicatorTransformYConverterValues ( 100 , 20 , Orientation . Horizontal , false , 1 , 1 ) ;
380
+ object [ ] values = Arrange_PreviewIndicatorTransformYConverterValues ( 100 , 20 , Orientation . Horizontal , false , false , 1 , 1 ) ;
356
381
double expectedValue = - 20 - RatingBar . PreviewIndicatorTransformYConverter . Margin ;
357
382
358
383
// Act
@@ -368,7 +393,7 @@ public void PreviewIndicatorTransformYConverter_ShouldPlacePreviewIndicatorWithS
368
393
{
369
394
// Arrange
370
395
IMultiValueConverter converter = RatingBar . PreviewIndicatorTransformYConverter . Instance ;
371
- object [ ] values = Arrange_PreviewIndicatorTransformYConverterValues ( 100 , 20 , Orientation . Horizontal , true , 1.25 , 1 ) ;
396
+ object [ ] values = Arrange_PreviewIndicatorTransformYConverterValues ( 100 , 20 , Orientation . Horizontal , false , true , 1.25 , 1 ) ;
372
397
double expectedValue = - 20 - RatingBar . PreviewIndicatorTransformYConverter . Margin ;
373
398
374
399
// Act
@@ -384,7 +409,7 @@ public void PreviewIndicatorTransformYConverter_ShouldCenterPreviewIndicator_Whe
384
409
{
385
410
// Arrange
386
411
IMultiValueConverter converter = RatingBar . PreviewIndicatorTransformYConverter . Instance ;
387
- object [ ] values = Arrange_PreviewIndicatorTransformYConverterValues ( 100 , 20 , Orientation . Vertical , false , 1 , 1 ) ;
412
+ object [ ] values = Arrange_PreviewIndicatorTransformYConverterValues ( 100 , 20 , Orientation . Vertical , false , false , 1 , 1 ) ;
388
413
389
414
// Act
390
415
double ? result = converter . Convert ( values , typeof ( double ) , null , CultureInfo . CurrentCulture ) as double ? ;
@@ -394,23 +419,25 @@ public void PreviewIndicatorTransformYConverter_ShouldCenterPreviewIndicator_Whe
394
419
Assert . Equal ( 40.0 , result ) ; // 50% of 100 minus 20/2
395
420
}
396
421
397
- [ Fact ]
398
- public void PreviewIndicatorTransformYConverter_ShouldPreviewIndicatorByPercentage_WhenFractionalValuesAreEnabledAndOrientationIsVertical ( )
422
+ [ Theory ]
423
+ [ InlineData ( false , 15.0 ) ] // 25% of 100 minus 20/2
424
+ [ InlineData ( true , 65.0 ) ] // 75% of 100 minus 20/2
425
+ public void PreviewIndicatorTransformYConverter_ShouldPreviewIndicatorByPercentage_WhenFractionalValuesAreEnabledAndOrientationIsVertical ( bool invertDirection , double expectedValue )
399
426
{
400
427
// Arrange
401
428
IMultiValueConverter converter = RatingBar . PreviewIndicatorTransformYConverter . Instance ;
402
- object [ ] values = Arrange_PreviewIndicatorTransformYConverterValues ( 100 , 20 , Orientation . Vertical , true , 1.25 , 1 ) ;
429
+ object [ ] values = Arrange_PreviewIndicatorTransformYConverterValues ( 100 , 20 , Orientation . Vertical , invertDirection , true , 1.25 , 1 ) ;
403
430
404
431
// Act
405
432
double ? result = converter . Convert ( values , typeof ( double ) , null , CultureInfo . CurrentCulture ) as double ? ;
406
433
407
434
// Assert
408
435
Assert . NotNull ( result ) ;
409
- Assert . Equal ( 15.0 , result ) ; // 25% of 100 minus 20/2
436
+ Assert . Equal ( expectedValue , result ) ;
410
437
}
411
438
412
- private static object [ ] Arrange_PreviewIndicatorTransformYConverterValues ( double ratingBarButtonActualHeight , double previewValueActualHeight , Orientation orientation , bool isFractionalValueEnabled , double previewValue , int buttonValue ) =>
413
- new object [ ] { ratingBarButtonActualHeight , previewValueActualHeight , orientation , isFractionalValueEnabled , previewValue , buttonValue } ;
439
+ private static object [ ] Arrange_PreviewIndicatorTransformYConverterValues ( double ratingBarButtonActualHeight , double previewValueActualHeight , Orientation orientation , bool invertDirection , bool isFractionalValueEnabled , double previewValue , int buttonValue ) =>
440
+ new object [ ] { ratingBarButtonActualHeight , previewValueActualHeight , orientation , invertDirection , isFractionalValueEnabled , previewValue , buttonValue } ;
414
441
}
415
442
416
443
internal static class ColorExtensions
0 commit comments