5 changed files with 142 additions and 5 deletions
@ -0,0 +1,72 @@ |
|||
using System; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Avalonia.Animation; |
|||
using Avalonia.Controls; |
|||
using Avalonia.Styling; |
|||
using Avalonia.UnitTests; |
|||
using Avalonia.Data; |
|||
using Xunit; |
|||
|
|||
namespace Avalonia.Animation.UnitTests |
|||
{ |
|||
public class AnimationIterationTests |
|||
{ |
|||
[Fact] |
|||
public void Check_Initial_Inter_and_Trailing_Delay_Values() |
|||
{ |
|||
var keyframe1 = new KeyFrame() |
|||
{ |
|||
new Setter(Border.WidthProperty, 200d), |
|||
}; |
|||
|
|||
var keyframe2 = new KeyFrame() |
|||
{ |
|||
new Setter(Border.WidthProperty, 100d), |
|||
}; |
|||
|
|||
keyframe1.Cue = new Cue(1d); |
|||
keyframe2.Cue = new Cue(0d); |
|||
|
|||
var animation = new Animation() |
|||
{ |
|||
Duration = TimeSpan.FromSeconds(3), |
|||
Delay = TimeSpan.FromSeconds(3), |
|||
DelayBetweenIterations = TimeSpan.FromSeconds(3), |
|||
IterationCount = new IterationCount(2), |
|||
Children = |
|||
{ |
|||
keyframe2, |
|||
keyframe1 |
|||
} |
|||
}; |
|||
|
|||
var border = new Border() |
|||
{ |
|||
Height = 100d, |
|||
Width = 100d |
|||
}; |
|||
|
|||
var clock = new TestClock(); |
|||
var animationRun = animation.RunAsync(border, clock); |
|||
|
|||
clock.Step(TimeSpan.Zero); |
|||
|
|||
// Initial Delay.
|
|||
clock.Step(TimeSpan.FromSeconds(1)); |
|||
Assert.Equal(border.Width, 0d); |
|||
|
|||
clock.Step(TimeSpan.FromSeconds(6)); |
|||
|
|||
// First Inter-Iteration delay.
|
|||
clock.Step(TimeSpan.FromSeconds(8)); |
|||
Assert.Equal(border.Width, 200d); |
|||
|
|||
// Trailing Delay should be non-existent.
|
|||
clock.Step(TimeSpan.FromSeconds(14)); |
|||
Assert.True(animationRun.Status == TaskStatus.RanToCompletion); |
|||
Assert.Equal(border.Width, 100d); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0"> |
|||
<PropertyGroup> |
|||
<TargetFrameworks>netcoreapp2.0</TargetFrameworks> |
|||
<OutputType>Library</OutputType> |
|||
</PropertyGroup> |
|||
<Import Project="..\..\build\UnitTests.NetCore.targets" /> |
|||
<Import Project="..\..\build\Moq.props" /> |
|||
<Import Project="..\..\build\XUnit.props" /> |
|||
<Import Project="..\..\build\Rx.props" /> |
|||
<Import Project="..\..\build\Microsoft.Reactive.Testing.props" /> |
|||
<ItemGroup> |
|||
<ProjectReference Include="..\..\src\Avalonia.Animation\Avalonia.Animation.csproj" /> |
|||
<ProjectReference Include="..\..\src\Avalonia.Base\Avalonia.Base.csproj" /> |
|||
<ProjectReference Include="..\..\src\Avalonia.Controls\Avalonia.Controls.csproj" /> |
|||
<ProjectReference Include="..\..\src\Avalonia.Input\Avalonia.Input.csproj" /> |
|||
<ProjectReference Include="..\..\src\Avalonia.Interactivity\Avalonia.Interactivity.csproj" /> |
|||
<ProjectReference Include="..\..\src\Avalonia.Layout\Avalonia.Layout.csproj" /> |
|||
<ProjectReference Include="..\..\src\Avalonia.Visuals\Avalonia.Visuals.csproj" /> |
|||
<ProjectReference Include="..\..\src\Avalonia.Styling\Avalonia.Styling.csproj" /> |
|||
<ProjectReference Include="..\Avalonia.UnitTests\Avalonia.UnitTests.csproj" /> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" /> |
|||
</ItemGroup> |
|||
</Project> |
|||
@ -0,0 +1,10 @@ |
|||
// Copyright (c) The Avalonia Project. All rights reserved.
|
|||
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|||
|
|||
using System.Reflection; |
|||
using Xunit; |
|||
|
|||
[assembly: AssemblyTitle("Avalonia.Animation.UnitTests")] |
|||
|
|||
// Don't run tests in parallel.
|
|||
[assembly: CollectionBehavior(DisableTestParallelization = true)] |
|||
@ -0,0 +1,28 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
|
|||
namespace Avalonia.Animation.UnitTests |
|||
{ |
|||
internal class TestClock : IClock, IDisposable |
|||
{ |
|||
private IObserver<TimeSpan> _observer; |
|||
|
|||
public PlayState PlayState { get; set; } = PlayState.Run; |
|||
|
|||
public void Dispose() |
|||
{ |
|||
_observer?.OnCompleted(); |
|||
} |
|||
|
|||
public void Step(TimeSpan time) |
|||
{ |
|||
_observer?.OnNext(time); |
|||
} |
|||
|
|||
public IDisposable Subscribe(IObserver<TimeSpan> observer) |
|||
{ |
|||
_observer = observer; |
|||
return this; |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue