Browse Source

Added unit test for #10226.

pull/10273/head
José Pedro 4 years ago
parent
commit
04df472194
No known key found for this signature in database GPG Key ID: B8247B9301707B83
  1. 40
      tests/Avalonia.Base.UnitTests/Styling/StyledElementTests_Theming.cs

40
tests/Avalonia.Base.UnitTests/Styling/StyledElementTests_Theming.cs

@ -104,7 +104,7 @@ public class StyledElementTests_Theming
target.Theme = null; target.Theme = null;
Assert.Equal("style", target.Tag); Assert.Equal("style", target.Tag);
} }
[Fact] [Fact]
public void TemplatedParent_Theme_Is_Detached_From_Template_Controls_When_Theme_Property_Cleared() public void TemplatedParent_Theme_Is_Detached_From_Template_Controls_When_Theme_Property_Cleared()
{ {
@ -539,12 +539,42 @@ public class StyledElementTests_Theming
Assert.Same(target.Theme, theme3); Assert.Same(target.Theme, theme3);
} }
[Fact]
public void TemplatedParent_Theme_Change_Applies_To_Children()
{
var theme = CreateDerivedTheme();
var target = CreateTarget();
Assert.Null(target.Theme);
Assert.Null(target.Template);
var root = CreateRoot(target, theme.BasedOn);
Assert.NotNull(target.Theme);
Assert.NotNull(target.Template);
root.Styles.Add(new Style(x => x.OfType<ThemedControl>().Class("foo"))
{
Setters = { new Setter(StyledElement.ThemeProperty, theme) }
});
root.LayoutManager.ExecuteLayoutPass();
var border = Assert.IsType<Border>(target.VisualChild);
Assert.Equal(Brushes.Red, border.Background);
target.Classes.Add("foo");
root.LayoutManager.ExecuteLayoutPass();
Assert.Equal(Brushes.Green, border.Background);
}
private static ThemedControl CreateTarget() private static ThemedControl CreateTarget()
{ {
return new ThemedControl(); return new ThemedControl();
} }
private static TestRoot CreateRoot(Control child) private static TestRoot CreateRoot(Control child, ControlTheme? theme = null)
{ {
var result = new TestRoot() var result = new TestRoot()
{ {
@ -552,7 +582,7 @@ public class StyledElementTests_Theming
{ {
new Style(x => x.OfType<ThemedControl>()) new Style(x => x.OfType<ThemedControl>())
{ {
Setters = { new Setter(StyledElement.ThemeProperty, CreateTheme()) } Setters = { new Setter(StyledElement.ThemeProperty, theme ?? CreateTheme()) }
} }
} }
}; };
@ -580,8 +610,8 @@ public class StyledElementTests_Theming
{ {
new Style(x => x.Nesting().Template().OfType<Border>()) new Style(x => x.Nesting().Template().OfType<Border>())
{ {
Setters = Setters =
{ {
new Setter(Border.BackgroundProperty, Brushes.Red), new Setter(Border.BackgroundProperty, Brushes.Red),
new Setter(Control.TagProperty, tag), new Setter(Control.TagProperty, tag),
} }

Loading…
Cancel
Save