Skip to content

Commit

Permalink
fix setter tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
danwalmsley committed Jul 6, 2022
1 parent 4823790 commit a4279a5
Showing 1 changed file with 31 additions and 32 deletions.
63 changes: 31 additions & 32 deletions tests/Avalonia.Styling.UnitTests/SetterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
using Avalonia.Controls.Templates;
using Avalonia.Data;
using Avalonia.Data.Converters;
using Avalonia.Diagnostics;
using Avalonia.Styling;
using Moq;
using Xunit;

namespace Avalonia.Styling.UnitTests
namespace Avalonia.Base.UnitTests.Styling
{
public class SetterTests
{
Expand Down Expand Up @@ -89,66 +91,63 @@ public void Does_Not_Call_Converter_ConvertBack_On_OneWay_Binding()
[Fact]
public void Setter_Should_Apply_Value_Without_Activator_With_Style_Priority()
{
var control = new Mock<IStyleable>();
var style = Mock.Of<Style>();
var control = new Control();
var setter = new Setter(TextBlock.TagProperty, "foo");

setter.Instance(control.Object).Start(false);
setter.Instance(control).Start(false);

control.Verify(x => x.SetValue(
TextBlock.TagProperty,
"foo",
BindingPriority.Style));
Assert.Equal("foo", control.Tag);
Assert.Equal(BindingPriority.Style, control.GetDiagnostic(TextBlock.TagProperty).Priority);
}

[Fact]
public void Setter_Should_Apply_Value_With_Activator_As_Binding_With_StyleTrigger_Priority()
{
var control = new Mock<IStyleable>();
var style = Mock.Of<Style>();
var control = new Canvas();
var setter = new Setter(TextBlock.TagProperty, "foo");
var activator = new Subject<bool>();

var instance = setter.Instance(control.Object);
var instance = setter.Instance(control);
instance.Start(true);
instance.Activate();

control.Verify(x => x.Bind(
TextBlock.TagProperty,
It.IsAny<IObservable<BindingValue<object>>>(),
BindingPriority.StyleTrigger));
Assert.Equal("foo", control.Tag);
Assert.Equal(BindingPriority.StyleTrigger, control.GetDiagnostic(TextBlock.TagProperty).Priority);
}

[Fact]
public void Setter_Should_Apply_Binding_Without_Activator_With_Style_Priority()
{
var control = new Mock<IStyleable>();
var style = Mock.Of<Style>();
var setter = new Setter(TextBlock.TagProperty, CreateMockBinding(TextBlock.TagProperty));
var control = new Canvas();
var source = new { Foo = "foo" };
var setter = new Setter(TextBlock.TagProperty, new Binding
{
Source = source,
Path = nameof(source.Foo),
});

setter.Instance(control.Object).Start(false);
setter.Instance(control).Start(false);

control.Verify(x => x.Bind(
TextBlock.TagProperty,
It.IsAny<PropertySetterBindingInstance<object>>(),
BindingPriority.Style));
Assert.Equal("foo", control.Tag);
Assert.Equal(BindingPriority.Style, control.GetDiagnostic(TextBlock.TagProperty).Priority);
}

[Fact]
public void Setter_Should_Apply_Binding_With_Activator_With_StyleTrigger_Priority()
{
var control = new Mock<IStyleable>();
var style = Mock.Of<Style>();
var setter = new Setter(TextBlock.TagProperty, CreateMockBinding(TextBlock.TagProperty));
var control = new Canvas();
var source = new { Foo = "foo" };
var setter = new Setter(TextBlock.TagProperty, new Binding
{
Source = source,
Path = nameof(source.Foo),
});

var instance = setter.Instance(control.Object);
var instance = setter.Instance(control);
instance.Start(true);
instance.Activate();

control.Verify(x => x.Bind(
TextBlock.TagProperty,
It.IsAny<IObservable<BindingValue<object>>>(),
BindingPriority.StyleTrigger));
Assert.Equal("foo", control.Tag);
Assert.Equal(BindingPriority.StyleTrigger, control.GetDiagnostic(TextBlock.TagProperty).Priority);
}

[Fact]
Expand Down

0 comments on commit a4279a5

Please sign in to comment.