Browse Source

Added failing animation test.

pull/8600/head
Steven Kirk 4 years ago
parent
commit
ed11b75b81
  1. 61
      tests/Avalonia.Base.UnitTests/Styling/StyleTests.cs

61
tests/Avalonia.Base.UnitTests/Styling/StyleTests.cs

@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using Avalonia.Animation;
using Avalonia.Base.UnitTests.Animation;
using Avalonia.Controls;
using Avalonia.Controls.Templates;
using Avalonia.Data;
@ -794,6 +796,56 @@ namespace Avalonia.Base.UnitTests.Styling
Assert.Throws<InvalidOperationException>(() => parent.Children.Add(nested));
}
[Fact]
public void Animations_Should_Be_Activated_And_Deactivated()
{
Style style = new Style(x => x.OfType<Class1>().Class("foo"))
{
Animations =
{
new Avalonia.Animation.Animation
{
Duration = TimeSpan.FromSeconds(1),
Children =
{
new KeyFrame
{
Setters =
{
new Setter { Property = Class1.DoubleProperty, Value = 5.0 }
},
},
new KeyFrame
{
Setters =
{
new Setter { Property = Class1.DoubleProperty, Value = 10.0 }
},
Cue = new Cue(1d)
}
},
}
}
};
var clock = new TestClock();
var target = new Class1 { Clock = clock };
style.TryAttach(target, null);
Assert.Equal(0.0, target.Double);
target.Classes.Add("foo");
clock.Step(TimeSpan.Zero);
Assert.Equal(5.0, target.Double);
clock.Step(TimeSpan.FromSeconds(0.5));
Assert.Equal(7.5, target.Double);
target.Classes.Remove("foo");
Assert.Equal(0.0, target.Double);
}
private class Class1 : Control
{
public static readonly StyledProperty<string> FooProperty =
@ -802,6 +854,9 @@ namespace Avalonia.Base.UnitTests.Styling
public static readonly StyledProperty<Class1> ChildProperty =
AvaloniaProperty.Register<Class1, Class1>(nameof(Child));
public static readonly StyledProperty<double> DoubleProperty =
AvaloniaProperty.Register<Class1, double>(nameof(Double));
public string Foo
{
get { return GetValue(FooProperty); }
@ -814,6 +869,12 @@ namespace Avalonia.Base.UnitTests.Styling
set => SetValue(ChildProperty, value);
}
public double Double
{
get => GetValue(DoubleProperty);
set => SetValue(DoubleProperty, value);
}
protected override Size MeasureOverride(Size availableSize)
{
throw new NotImplementedException();

Loading…
Cancel
Save