Skip to content

Commit

Permalink
More tests for #5027.
Browse files Browse the repository at this point in the history
  • Loading branch information
grokys committed Nov 18, 2020
1 parent 72a4317 commit 662b1e0
Show file tree
Hide file tree
Showing 2 changed files with 199 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<OutputType>Library</OutputType>
<NoWarn>CS0067</NoWarn>
<IsTestProject>true</IsTestProject>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<Import Project="..\..\build\UnitTests.NetCore.targets" />
<Import Project="..\..\build\UnitTests.NetFX.props" />
Expand Down
198 changes: 198 additions & 0 deletions tests/Avalonia.Styling.UnitTests/StyleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,204 @@ public void Later_Styles_Should_Override_Earlier_3()
Assert.Equal(new[] { "foodefault", "Bar" }, values);
}

[Fact]
public void Inactive_Values_Should_Not_Be_Made_Active_During_Style_Attach()
{
using var app = UnitTestApplication.Start(TestServices.RealStyler);

var root = new TestRoot
{
Styles =
{
new Style(x => x.OfType<Class1>())
{
Setters =
{
new Setter(Class1.FooProperty, "Foo"),
},
},

new Style(x => x.OfType<Class1>())
{
Setters =
{
new Setter(Class1.FooProperty, "Bar"),
},
}
}
};

var values = new List<string>();
var target = new Class1();

target.GetObservable(Class1.FooProperty).Subscribe(x => values.Add(x));
root.Child = target;

Assert.Equal(new[] { "foodefault", "Bar" }, values);
}

[Fact]
public void Inactive_Bindings_Should_Not_Be_Made_Active_During_Style_Attach()
{
using var app = UnitTestApplication.Start(TestServices.RealStyler);

var root = new TestRoot
{
Styles =
{
new Style(x => x.OfType<Class1>())
{
Setters =
{
new Setter(Class1.FooProperty, new Binding("Foo")),
},
},

new Style(x => x.OfType<Class1>())
{
Setters =
{
new Setter(Class1.FooProperty, new Binding("Bar")),
},
}
}
};

var values = new List<string>();
var target = new Class1
{
DataContext = new
{
Foo = "Foo",
Bar = "Bar",
}
};

target.GetObservable(Class1.FooProperty).Subscribe(x => values.Add(x));
root.Child = target;

Assert.Equal(new[] { "foodefault", "Bar" }, values);
}

[Fact]
public void Inactive_Values_Should_Not_Be_Made_Active_During_Style_Detach()
{
using var app = UnitTestApplication.Start(TestServices.RealStyler);

var root = new TestRoot
{
Styles =
{
new Style(x => x.OfType<Class1>())
{
Setters =
{
new Setter(Class1.FooProperty, "Foo"),
},
},

new Style(x => x.OfType<Class1>())
{
Setters =
{
new Setter(Class1.FooProperty, "Bar"),
},
}
}
};

var target = new Class1();
root.Child = target;

var values = new List<string>();
target.GetObservable(Class1.FooProperty).Subscribe(x => values.Add(x));
root.Child = null;

Assert.Equal(new[] { "Bar", "foodefault" }, values);
}

[Fact]
public void Inactive_Values_Should_Not_Be_Made_Active_During_Style_Detach_2()
{
using var app = UnitTestApplication.Start(TestServices.RealStyler);

var root = new TestRoot
{
Styles =
{
new Style(x => x.OfType<Class1>().Class("foo"))
{
Setters =
{
new Setter(Class1.FooProperty, "Foo"),
},
},

new Style(x => x.OfType<Class1>())
{
Setters =
{
new Setter(Class1.FooProperty, "Bar"),
},
}
}
};

var target = new Class1 { Classes = { "foo" } };
root.Child = target;

var values = new List<string>();
target.GetObservable(Class1.FooProperty).Subscribe(x => values.Add(x));
root.Child = null;

Assert.Equal(new[] { "Foo", "foodefault" }, values);
}

[Fact]
public void Inactive_Bindings_Should_Not_Be_Made_Active_During_Style_Detach()
{
using var app = UnitTestApplication.Start(TestServices.RealStyler);

var root = new TestRoot
{
Styles =
{
new Style(x => x.OfType<Class1>())
{
Setters =
{
new Setter(Class1.FooProperty, new Binding("Foo")),
},
},

new Style(x => x.OfType<Class1>())
{
Setters =
{
new Setter(Class1.FooProperty, new Binding("Bar")),
},
}
}
};

var target = new Class1
{
DataContext = new
{
Foo = "Foo",
Bar = "Bar",
}
};

root.Child = target;

var values = new List<string>();
target.GetObservable(Class1.FooProperty).Subscribe(x => values.Add(x));
root.Child = null;

Assert.Equal(new[] { "Bar", "foodefault" }, values);
}

[Fact]
public void Template_In_Non_Matching_Style_Is_Not_Built()
{
Expand Down

0 comments on commit 662b1e0

Please sign in to comment.