Skip to content
Merged

Fix2658 #2757

Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
More unit tests
Also ensured the DoubleToCornerRadiusConverter returns a CornerRadius of 0 for negative values.
  • Loading branch information
nicolaihenriksen committed Jul 2, 2022
commit ea971426c4a3eca9ffb5a9e56a287211d38d412a
24 changes: 23 additions & 1 deletion MaterialDesignThemes.UITests/WPF/Cards/OutlinedCardTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,26 @@ public async Task OutlinedCard_UsesThemeColorForBorder()

recorder.Success();
}
}

[Fact]
public async Task OutlinedCard_UniformCornerRadiusApplied_AppliesCornerRadiusOnBorder()
{
await using var recorder = new TestRecorder(App);

//Arrange
IVisualElement<Card> card = await LoadXaml<Card>(
@"<materialDesign:Card Content=""Hello World"" Style=""{StaticResource MaterialDesignOutlinedCard}"" UniformCornerRadius=""5"" />");
IVisualElement<Border> internalBorder = await card.GetElement<Border>();

//Act
CornerRadius? internalBorderCornerRadius = await internalBorder.GetCornerRadius();

//Assert
Assert.Equal(5, internalBorderCornerRadius.Value.TopLeft);
Assert.Equal(5, internalBorderCornerRadius.Value.TopRight);
Assert.Equal(5, internalBorderCornerRadius.Value.BottomRight);
Assert.Equal(5, internalBorderCornerRadius.Value.BottomLeft);

recorder.Success();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Globalization;
using MaterialDesignThemes.Wpf.Converters;
using Xunit;

namespace MaterialDesignThemes.Wpf.Tests.Converters;

public class DoubleToCornerRadiusConverterTests
{
[Theory]
[InlineData(-0.16, 0.0)]
[InlineData(0.16, 0.16)]
[InlineData(5.0, 5.0)]
public void AllCultureParseParameterCorrectly(object parameter, double expectedCornerRadius)
{
var converter = new DoubleToCornerRadiusConverter();
foreach (var culture in CultureInfo.GetCultures(CultureTypes.AllCultures))
{
var cornerRadius = (CornerRadius?)converter.Convert(parameter, typeof(CornerRadius), parameter, culture);

Assert.Equal(expectedCornerRadius, cornerRadius.Value.TopLeft);
Assert.Equal(expectedCornerRadius, cornerRadius.Value.TopRight);
Assert.Equal(expectedCornerRadius, cornerRadius.Value.BottomRight);
Assert.Equal(expectedCornerRadius, cornerRadius.Value.BottomLeft);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ internal class DoubleToCornerRadiusConverter : IValueConverter
{
public static readonly DoubleToCornerRadiusConverter Instance = new();

public object Convert(object value, Type targetType, object parameter, CultureInfo culture) => new CornerRadius((double)value);
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) => new CornerRadius(Math.Max(0, (double)value));

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new NotImplementedException();
}