diff --git a/src/CommunityToolkit.Maui.Markup.UnitTests/BindingHelpers.cs b/src/CommunityToolkit.Maui.Markup.UnitTests/BindingHelpers.cs index 3913bfed..388c5f0d 100644 --- a/src/CommunityToolkit.Maui.Markup.UnitTests/BindingHelpers.cs +++ b/src/CommunityToolkit.Maui.Markup.UnitTests/BindingHelpers.cs @@ -1,6 +1,5 @@ -using System.Globalization; +using System.Globalization; using System.Reflection; -using Microsoft.Maui.Controls.Internals; using NUnit.Framework; namespace CommunityToolkit.Maui.Markup.UnitTests; @@ -79,14 +78,17 @@ internal static void AssertTypedBindingExists { Assert.That(binding, Is.Not.Null); Assert.That(binding.Mode, Is.EqualTo(expectedBindingMode)); - Assert.That(binding.Converter?.ToString(), Is.EqualTo(expectedConverter?.ToString())); + var actualConverter = binding.Converter?.GetType().Name.StartsWith("GetterValueConverter", StringComparison.Ordinal) is true && expectedConverter is null + ? null + : binding.Converter; + Assert.That(actualConverter?.ToString(), Is.EqualTo(expectedConverter?.ToString())); Assert.That(binding.ConverterParameter, Is.EqualTo(expectedConverterParameter)); @@ -200,8 +202,6 @@ internal static void AssertBindingExists( internal static Binding? GetBinding(BindableObject bindable, BindableProperty property) => GetBindingBase(bindable, property); - internal static TypedBindingBase? GetTypedBinding(BindableObject bindable, BindableProperty property) => GetBindingBase(bindable, property); - internal static MultiBinding? GetMultiBinding(BindableObject bindable, BindableProperty property) => GetBindingBase(bindable, property); /// @@ -213,8 +213,15 @@ internal static void AssertBindingExists( { getContextMethodInfo ??= typeof(BindableObject).GetMethod("GetContext", BindingFlags.NonPublic | BindingFlags.Instance); - var context = (BindableObject.BindablePropertyContext?)getContextMethodInfo?.Invoke(bindable, [property]); - return (TBinding?)context?.Bindings.GetValue(); + var context = getContextMethodInfo?.Invoke(bindable, [property]); + var contextType = context?.GetType(); + var bindings = contextType?.GetProperty("Bindings", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(context) + ?? contextType?.GetField("Bindings", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(context); + var binding = bindings?.GetType() + .GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) + .SingleOrDefault(static method => method.Name is "GetValue" && method.GetParameters().Length is 0) + ?.Invoke(bindings, null); + return binding as TBinding; } internal static IValueConverter AssertConvert(this IValueConverter converter, TValue value, object? parameter, TConvertedValue expectedConvertedValue, bool twoWay = false, bool backOnly = false, CultureInfo? culture = null) diff --git a/src/CommunityToolkit.Maui.Markup.UnitTests/ElementExtensionsTests.cs b/src/CommunityToolkit.Maui.Markup.UnitTests/ElementExtensionsTests.cs index bf2e1833..775ea12e 100644 --- a/src/CommunityToolkit.Maui.Markup.UnitTests/ElementExtensionsTests.cs +++ b/src/CommunityToolkit.Maui.Markup.UnitTests/ElementExtensionsTests.cs @@ -60,39 +60,39 @@ public void EffectsMultiple() [Test] public void FontSize() - => TestPropertiesSet(l => l.FontSize(8), (FontElement.FontSizeProperty, 6.0, 8.0)); + => TestPropertiesSet(l => l.FontSize(8), (Label.FontSizeProperty, 6.0, 8.0)); [Test] public void Bold() - => TestPropertiesSet(l => l.Bold(), (FontElement.FontAttributesProperty, FontAttributes.None, FontAttributes.Bold)); + => TestPropertiesSet(l => l.Bold(), (Label.FontAttributesProperty, FontAttributes.None, FontAttributes.Bold)); [Test] public void Italic() - => TestPropertiesSet(l => l.Italic(), (FontElement.FontAttributesProperty, FontAttributes.None, FontAttributes.Italic)); + => TestPropertiesSet(l => l.Italic(), (Label.FontAttributesProperty, FontAttributes.None, FontAttributes.Italic)); [Test] public void FontWithPositionalParameters() => TestPropertiesSet( l => l.Font("AFontName", 8, true, true), - (FontElement.FontSizeProperty, 6.0, 8.0), - (FontElement.FontAttributesProperty, FontAttributes.None, FontAttributes.Bold | FontAttributes.Italic), - (FontElement.FontFamilyProperty, string.Empty, "AFontName")); + (Label.FontSizeProperty, 6.0, 8.0), + (Label.FontAttributesProperty, FontAttributes.None, FontAttributes.Bold | FontAttributes.Italic), + (Label.FontFamilyProperty, string.Empty, "AFontName")); [Test] public void FontWithSizeNamedParameter() - => TestPropertiesSet(l => l.Font(size: 8), (FontElement.FontSizeProperty, 6.0, 8.0)); + => TestPropertiesSet(l => l.Font(size: 8), (Label.FontSizeProperty, 6.0, 8.0)); [Test] public void FontWithBoldNamedParameter() - => TestPropertiesSet(l => l.Font(bold: true), (FontElement.FontAttributesProperty, FontAttributes.None, FontAttributes.Bold)); + => TestPropertiesSet(l => l.Font(bold: true), (Label.FontAttributesProperty, FontAttributes.None, FontAttributes.Bold)); [Test] public void FontWithItalicNamedParameter() - => TestPropertiesSet(l => l.Font(italic: true), (FontElement.FontAttributesProperty, FontAttributes.None, FontAttributes.Italic)); + => TestPropertiesSet(l => l.Font(italic: true), (Label.FontAttributesProperty, FontAttributes.None, FontAttributes.Italic)); [Test] public void FontWithFamilyNamedParameter() - => TestPropertiesSet(l => l.Font(family: "AFontName"), (FontElement.FontFamilyProperty, string.Empty, "AFontName")); + => TestPropertiesSet(l => l.Font(family: "AFontName"), (Label.FontFamilyProperty, string.Empty, "AFontName")); static Label AssertDynamicResources() { diff --git a/src/CommunityToolkit.Maui.Markup.UnitTests/GesturesExtensionsTests.cs b/src/CommunityToolkit.Maui.Markup.UnitTests/GesturesExtensionsTests.cs index 805bf367..f14653f1 100644 --- a/src/CommunityToolkit.Maui.Markup.UnitTests/GesturesExtensionsTests.cs +++ b/src/CommunityToolkit.Maui.Markup.UnitTests/GesturesExtensionsTests.cs @@ -206,7 +206,7 @@ public void BindTapGestureDefaults() Assert.That(gestureElement.GestureRecognizers[0], Is.InstanceOf()); }); - BindingHelpers.AssertTypedBindingExists((TapGestureRecognizer)gestureElement.GestureRecognizers[0], TapGestureRecognizer.CommandProperty, BindingMode.Default, gestureElement.BindingContext); + BindingHelpers.AssertTypedBindingExists((TapGestureRecognizer)gestureElement.GestureRecognizers[0], TapGestureRecognizer.CommandProperty, BindingMode.OneWay, gestureElement.BindingContext); } [Test] @@ -232,6 +232,29 @@ public void BindTapGestureDefaultsWithNestedBindings() }); BindingHelpers.AssertTypedBindingExists((TapGestureRecognizer)gestureElement.GestureRecognizers[0], TapGestureRecognizer.CommandProperty, BindingMode.OneTime, gestureElement.BindingContext); + Assert.That(BindingHelpers.GetBinding((TapGestureRecognizer)gestureElement.GestureRecognizers[0], TapGestureRecognizer.CommandProperty)?.Path, Is.EqualTo("NestedCommand.SetGuidCommand")); + } + + [Test] + public void BindTapGestureExpressionOverloadUsesNestedBindingPaths() + { + var gestureElement = new TGestureElement + { + BindingContext = new ViewModel() + }; + + gestureElement.BindTapGesture( + getter: static (ViewModel vm) => vm.NestedCommand.SetGuidCommand, + commandBindingMode: BindingMode.OneTime, + parameterGetter: static (ViewModel vm) => vm.NestedCommand.Id); + + var tapGestureRecognizer = (TapGestureRecognizer)gestureElement.GestureRecognizers[0]; + + Assert.Multiple(() => + { + Assert.That(BindingHelpers.GetBinding(tapGestureRecognizer, TapGestureRecognizer.CommandProperty)?.Path, Is.EqualTo("NestedCommand.SetGuidCommand")); + Assert.That(BindingHelpers.GetBinding(tapGestureRecognizer, TapGestureRecognizer.CommandParameterProperty)?.Path, Is.EqualTo("NestedCommand.Id")); + }); } [Test] @@ -308,7 +331,12 @@ public void BindTapGesturePositionalParametersWithNestedBindings() }); BindingHelpers.AssertTypedBindingExists(tapGestureRecognizer, TapGestureRecognizer.CommandProperty, BindingMode.OneTime, gestureElement.BindingContext); - BindingHelpers.AssertTypedBindingExists(tapGestureRecognizer, TapGestureRecognizer.CommandParameterProperty, BindingMode.Default, gestureElement.BindingContext); + BindingHelpers.AssertTypedBindingExists(tapGestureRecognizer, TapGestureRecognizer.CommandParameterProperty, BindingMode.OneWay, gestureElement.BindingContext); + Assert.Multiple(() => + { + Assert.That(BindingHelpers.GetBinding(tapGestureRecognizer, TapGestureRecognizer.CommandProperty)?.Path, Is.EqualTo("NestedCommand.SetGuidCommand")); + Assert.That(BindingHelpers.GetBinding(tapGestureRecognizer, TapGestureRecognizer.CommandParameterProperty)?.Path, Is.EqualTo("NestedCommand.Id")); + }); } [Test] @@ -323,7 +351,7 @@ public void BindSwipeGestureDefaults() Assert.That(gestureElement.GestureRecognizers, Has.Count.EqualTo(1)); Assert.That(gestureElement.GestureRecognizers[0], Is.InstanceOf()); - BindingHelpers.AssertTypedBindingExists((SwipeGestureRecognizer)gestureElement.GestureRecognizers[0], SwipeGestureRecognizer.CommandProperty, BindingMode.Default, gestureElement.BindingContext); + BindingHelpers.AssertTypedBindingExists((SwipeGestureRecognizer)gestureElement.GestureRecognizers[0], SwipeGestureRecognizer.CommandProperty, BindingMode.OneWay, gestureElement.BindingContext); } [Test] @@ -349,6 +377,29 @@ public void BindSwipeGestureWithNestedBindings() }); BindingHelpers.AssertTypedBindingExists((SwipeGestureRecognizer)gestureElement.GestureRecognizers[0], SwipeGestureRecognizer.CommandProperty, BindingMode.OneTime, gestureElement.BindingContext); + Assert.That(BindingHelpers.GetBinding((SwipeGestureRecognizer)gestureElement.GestureRecognizers[0], SwipeGestureRecognizer.CommandProperty)?.Path, Is.EqualTo("NestedCommand.SetGuidCommand")); + } + + [Test] + public void BindSwipeGestureExpressionOverloadUsesNestedBindingPaths() + { + var gestureElement = new TGestureElement + { + BindingContext = new ViewModel() + }; + + gestureElement.BindSwipeGesture( + getter: static (ViewModel vm) => vm.NestedCommand.SetGuidCommand, + commandBindingMode: BindingMode.OneTime, + parameterGetter: static (ViewModel vm) => vm.NestedCommand.Id); + + var swipeGestureRecognizer = (SwipeGestureRecognizer)gestureElement.GestureRecognizers[0]; + + Assert.Multiple(() => + { + Assert.That(BindingHelpers.GetBinding(swipeGestureRecognizer, SwipeGestureRecognizer.CommandProperty)?.Path, Is.EqualTo("NestedCommand.SetGuidCommand")); + Assert.That(BindingHelpers.GetBinding(swipeGestureRecognizer, SwipeGestureRecognizer.CommandParameterProperty)?.Path, Is.EqualTo("NestedCommand.Id")); + }); } [Test] @@ -429,7 +480,13 @@ public void BindSwipeGesturePositionalParametersWithNestedBindings() }); BindingHelpers.AssertTypedBindingExists((SwipeGestureRecognizer)gestureElement.GestureRecognizers[0], SwipeGestureRecognizer.CommandProperty, BindingMode.OneTime, gestureElement.BindingContext); - BindingHelpers.AssertTypedBindingExists((SwipeGestureRecognizer)gestureElement.GestureRecognizers[0], SwipeGestureRecognizer.CommandParameterProperty, BindingMode.Default, gestureElement.BindingContext); + BindingHelpers.AssertTypedBindingExists((SwipeGestureRecognizer)gestureElement.GestureRecognizers[0], SwipeGestureRecognizer.CommandParameterProperty, BindingMode.OneWay, gestureElement.BindingContext); + Assert.Multiple(() => + { + var swipeGestureRecognizer = (SwipeGestureRecognizer)gestureElement.GestureRecognizers[0]; + Assert.That(BindingHelpers.GetBinding(swipeGestureRecognizer, SwipeGestureRecognizer.CommandProperty)?.Path, Is.EqualTo("NestedCommand.SetGuidCommand")); + Assert.That(BindingHelpers.GetBinding(swipeGestureRecognizer, SwipeGestureRecognizer.CommandParameterProperty)?.Path, Is.EqualTo("NestedCommand.Id")); + }); } [Test] diff --git a/src/CommunityToolkit.Maui.Markup.UnitTests/ImageExtensionTests.cs b/src/CommunityToolkit.Maui.Markup.UnitTests/ImageExtensionTests.cs index 5d5f1291..2a83e2ff 100644 --- a/src/CommunityToolkit.Maui.Markup.UnitTests/ImageExtensionTests.cs +++ b/src/CommunityToolkit.Maui.Markup.UnitTests/ImageExtensionTests.cs @@ -23,14 +23,29 @@ public void SetSourceTest() [Test] public void SetAspectTest() { - TestPropertiesSet(i => i.Aspect(Aspect.AspectFill), (ImageElement.AspectProperty, Aspect.AspectFill)); - TestPropertiesSet(i => i.Aspect(Aspect.Center), (ImageElement.AspectProperty, Aspect.Center)); - TestPropertiesSet(i => i.Aspect(Aspect.Fill), (ImageElement.AspectProperty, Aspect.Fill)); + TestPropertiesSet(i => i.Aspect(Aspect.AspectFill), (Image.AspectProperty, Aspect.AspectFill)); + TestPropertiesSet(i => i.Aspect(Aspect.Center), (Image.AspectProperty, Aspect.Center)); + TestPropertiesSet(i => i.Aspect(Aspect.Fill), (Image.AspectProperty, Aspect.Fill)); } [Test] public void SetIsOpaqueTest() - => TestPropertiesSet(i => i.IsOpaque(true), (ImageElement.IsOpaqueProperty, true)); + => TestPropertiesSet(i => i.IsOpaque(true), (Image.IsOpaqueProperty, true)); + + [Test] + public void SupportsImageButton() + { + var imageButton = new ImageButton().Source(resourceToLoad); + + Assert.Multiple(() => + { + Assert.That(imageButton.Source, Is.InstanceOf()); + Assert.That(((FileImageSource)imageButton.Source).File, Is.EqualTo(resourceToLoad)); + }); + + TestPropertiesSet(new ImageButton(), imageButton => imageButton.Aspect(Aspect.Center), (ImageButton.AspectProperty, Aspect.Center)); + TestPropertiesSet(new ImageButton(), imageButton => imageButton.IsOpaque(true), (ImageButton.IsOpaqueProperty, true)); + } [Test] public void SupportDerivedFromImage() diff --git a/src/CommunityToolkit.Maui.Markup.UnitTests/Mocks/MockApplication.cs b/src/CommunityToolkit.Maui.Markup.UnitTests/Mocks/MockApplication.cs index daed3192..c1846663 100644 --- a/src/CommunityToolkit.Maui.Markup.UnitTests/Mocks/MockApplication.cs +++ b/src/CommunityToolkit.Maui.Markup.UnitTests/Mocks/MockApplication.cs @@ -1,4 +1,3 @@ -using Microsoft.Maui.Controls.Internals; using Microsoft.Maui.Handlers; namespace CommunityToolkit.Maui.Markup.UnitTests.Mocks; @@ -9,9 +8,6 @@ public MockApplication(IServiceProvider serviceProvider) Resources = new MockResourceDictionary(); Services = serviceProvider; -#pragma warning disable CS0612 // Type or member is obsolete - DependencyService.Register(); -#pragma warning restore CS0612 // Type or member is obsolete } public IApplication Application => this; diff --git a/src/CommunityToolkit.Maui.Markup.UnitTests/Mocks/MockResourcesProvider.cs b/src/CommunityToolkit.Maui.Markup.UnitTests/Mocks/MockResourcesProvider.cs deleted file mode 100644 index 4bfa6d5e..00000000 --- a/src/CommunityToolkit.Maui.Markup.UnitTests/Mocks/MockResourcesProvider.cs +++ /dev/null @@ -1,14 +0,0 @@ -using Microsoft.Maui.Controls.Internals; -namespace CommunityToolkit.Maui.Markup.UnitTests.Mocks; - - -// Inspired by https://github.com/dotnet/maui/blob/79695fbb7ba6517a334c795ecf0a1d6358ef309a/src/Controls/Foldable/test/MockPlatformServices.cs#L145-L176 - -#pragma warning disable CS0612 // Type or member is obsolete -class MockResourcesProvider : ISystemResourcesProvider -#pragma warning restore CS0612 // Type or member is obsolete -{ - readonly ResourceDictionary dictionary = new(); - - public IResourceDictionary GetSystemResources() => dictionary; -} \ No newline at end of file diff --git a/src/CommunityToolkit.Maui.Markup.UnitTests/PaceholderExtensionsTests.cs b/src/CommunityToolkit.Maui.Markup.UnitTests/PaceholderExtensionsTests.cs index 6d2b9465..6889b5d7 100644 --- a/src/CommunityToolkit.Maui.Markup.UnitTests/PaceholderExtensionsTests.cs +++ b/src/CommunityToolkit.Maui.Markup.UnitTests/PaceholderExtensionsTests.cs @@ -6,15 +6,30 @@ class PaceholderExtensionsTests : BaseMarkupTestFixture { [Test] public void SetPlaceholderTest() - => TestPropertiesSet(e => e.Placeholder("Hello World"), (PlaceholderElement.PlaceholderProperty, "Hello World")); + => TestPropertiesSet(e => e.Placeholder("Hello World"), (Entry.PlaceholderProperty, "Hello World")); [Test] public void SetPlaceholderAndColorTest() - => TestPropertiesSet(e => e.Placeholder("Hello World", Colors.Red), (PlaceholderElement.PlaceholderProperty, "Hello World"), (PlaceholderElement.PlaceholderColorProperty, Colors.Red)); + => TestPropertiesSet(e => e.Placeholder("Hello World", Colors.Red), (Entry.PlaceholderProperty, "Hello World"), (Entry.PlaceholderColorProperty, Colors.Red)); [Test] public void SetPlaceholderColorTest() - => TestPropertiesSet(e => e.PlaceholderColor(Colors.Red), (PlaceholderElement.PlaceholderColorProperty, Colors.Red)); + => TestPropertiesSet(e => e.PlaceholderColor(Colors.Red), (Entry.PlaceholderColorProperty, Colors.Red)); + + [Test] + public void SupportsSearchBar() + { + var searchBar = new SearchBar() + .Placeholder("Hello World") + .PlaceholderColor(Colors.Blue) + .Placeholder("Hello World 2", Colors.Red); + + Assert.Multiple(() => + { + Assert.That(searchBar.Placeholder, Is.EqualTo("Hello World 2")); + Assert.That(searchBar.PlaceholderColor, Is.EqualTo(Colors.Red)); + }); + } [Test] public void SupportDerivedFromEditor() diff --git a/src/CommunityToolkit.Maui.Markup.UnitTests/PaddingElementExtensionsTests.cs b/src/CommunityToolkit.Maui.Markup.UnitTests/PaddingElementExtensionsTests.cs index 52afb4a3..473ea2d8 100644 --- a/src/CommunityToolkit.Maui.Markup.UnitTests/PaddingElementExtensionsTests.cs +++ b/src/CommunityToolkit.Maui.Markup.UnitTests/PaddingElementExtensionsTests.cs @@ -2,38 +2,80 @@ using NUnit.Framework; namespace CommunityToolkit.Maui.Markup.UnitTests; -[TestFixture(typeof(Button))] -[TestFixture(typeof(Border))] -[TestFixture(typeof(ImageButton))] -[TestFixture(typeof(Label))] -[TestFixture(typeof(Page))] -class PaddingElementExtensionsTests : BaseMarkupTestFixture where TPaddingElement : Element, IPaddingElement, new() +[TestFixture] +class PaddingElementExtensionsTests : BaseMarkupTestFixture { - [Test] - public void PaddingThickness() - => TestPropertiesSet(l => l.Padding(new Thickness(1)), (PaddingElement.PaddingProperty, new Thickness(0), new Thickness(1))); + static readonly PaddingCase[] paddingCases = + [ + new("Border", () => new Border(), Border.PaddingProperty, (bindable, padding) => ((Border)bindable).Padding(padding), (bindable, uniformSize) => ((Border)bindable).Padding(uniformSize), (bindable, horizontal, vertical) => ((Border)bindable).Padding(horizontal, vertical), (bindable, left, top, right, bottom) => ((Border)bindable).Paddings(left, top, right, bottom)), + new("Button", () => new Button(), Button.PaddingProperty, (bindable, padding) => ((Button)bindable).Padding(padding), (bindable, uniformSize) => ((Button)bindable).Padding(uniformSize), (bindable, horizontal, vertical) => ((Button)bindable).Padding(horizontal, vertical), (bindable, left, top, right, bottom) => ((Button)bindable).Paddings(left, top, right, bottom)), + new("ImageButton", () => new ImageButton(), ImageButton.PaddingProperty, (bindable, padding) => ((ImageButton)bindable).Padding(padding), (bindable, uniformSize) => ((ImageButton)bindable).Padding(uniformSize), (bindable, horizontal, vertical) => ((ImageButton)bindable).Padding(horizontal, vertical), (bindable, left, top, right, bottom) => ((ImageButton)bindable).Paddings(left, top, right, bottom)), + new("Label", () => new Label(), Label.PaddingProperty, (bindable, padding) => ((Label)bindable).Padding(padding), (bindable, uniformSize) => ((Label)bindable).Padding(uniformSize), (bindable, horizontal, vertical) => ((Label)bindable).Padding(horizontal, vertical), (bindable, left, top, right, bottom) => ((Label)bindable).Paddings(left, top, right, bottom)), + new("Page", () => new Page(), Page.PaddingProperty, (bindable, padding) => ((Page)bindable).Padding(padding), (bindable, uniformSize) => ((Page)bindable).Padding(uniformSize), (bindable, horizontal, vertical) => ((Page)bindable).Padding(horizontal, vertical), (bindable, left, top, right, bottom) => ((Page)bindable).Paddings(left, top, right, bottom)), + new("ScrollView", () => new ScrollView(), ScrollView.PaddingProperty, (bindable, padding) => ((ScrollView)bindable).Padding(padding), (bindable, uniformSize) => ((ScrollView)bindable).Padding(uniformSize), (bindable, horizontal, vertical) => ((ScrollView)bindable).Padding(horizontal, vertical), (bindable, left, top, right, bottom) => ((ScrollView)bindable).Paddings(left, top, right, bottom)) + ]; - [Test] - public void PaddingUniform() - => TestPropertiesSet(l => l.Padding(1), (PaddingElement.PaddingProperty, new Thickness(0), new Thickness(1))); + [TestCaseSource(nameof(paddingCases))] + public void PaddingThickness(PaddingCase paddingCase) + { + var bindable = paddingCase.Create(); + TestPropertiesSet(bindable, b => paddingCase.SetThickness(b, new Thickness(1)), (paddingCase.Property, new Thickness(0), new Thickness(1))); + } - [Test] - public void PaddingHorizontalVertical() - => TestPropertiesSet(l => l.Padding(1, 2), (PaddingElement.PaddingProperty, new Thickness(0), new Thickness(1, 2))); + [TestCaseSource(nameof(paddingCases))] + public void PaddingUniform(PaddingCase paddingCase) + { + var bindable = paddingCase.Create(); + TestPropertiesSet(bindable, b => paddingCase.SetUniform(b, 1), (paddingCase.Property, new Thickness(0), new Thickness(1))); + } - [Test] - public void Paddings() - => TestPropertiesSet(l => l.Paddings(left: 1, top: 2, right: 3, bottom: 4), (PaddingElement.PaddingProperty, new Thickness(0), new Thickness(1, 2, 3, 4))); + [TestCaseSource(nameof(paddingCases))] + public void PaddingHorizontalVertical(PaddingCase paddingCase) + { + var bindable = paddingCase.Create(); + TestPropertiesSet(bindable, b => paddingCase.SetHorizontalVertical(b, 1, 2), (paddingCase.Property, new Thickness(0), new Thickness(1, 2))); + } + + [TestCaseSource(nameof(paddingCases))] + public void Paddings(PaddingCase paddingCase) + { + var bindable = paddingCase.Create(); + TestPropertiesSet(bindable, b => paddingCase.SetPaddings(b, 1, 2, 3, 4), (paddingCase.Property, new Thickness(0), new Thickness(1, 2, 3, 4))); + } [Test] public void SupportDerivedFrom() { - Assert.That(new DerivedFrom() - .Padding(1) - .Padding(1, 2) - .Paddings(left: 1, top: 2, right: 3, bottom: 4), - Is.InstanceOf()); + DerivedFrom derivedFrom = new DerivedFrom() + .Padding(1) + .Padding(1, 2) + .Paddings(left: 1, top: 2, right: 3, bottom: 4); + + DerivedFromScrollView derivedFromScrollView = new DerivedFromScrollView() + .Padding(1) + .Padding(1, 2) + .Paddings(left: 1, top: 2, right: 3, bottom: 4); + + Assert.Multiple(() => + { + Assert.That(derivedFrom, Is.InstanceOf()); + Assert.That(derivedFromScrollView, Is.InstanceOf()); + }); + } + + public sealed record PaddingCase( + string Name, + Func Create, + BindableProperty Property, + Action SetThickness, + Action SetUniform, + Action SetHorizontalVertical, + Action SetPaddings) + { + public override string ToString() => Name; } class DerivedFrom : ContentView { } -} \ No newline at end of file + + class DerivedFromScrollView : ScrollView { } +} diff --git a/src/CommunityToolkit.Maui.Markup.UnitTests/TextTests.cs b/src/CommunityToolkit.Maui.Markup.UnitTests/TextTests.cs index e72585eb..7bf6b674 100644 --- a/src/CommunityToolkit.Maui.Markup.UnitTests/TextTests.cs +++ b/src/CommunityToolkit.Maui.Markup.UnitTests/TextTests.cs @@ -6,11 +6,11 @@ class LabelTextTests : BaseMarkupTestFixture