AnimationIterationTests.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using System;
  2. using System.Linq;
  3. using System.Text;
  4. using System.Threading.Tasks;
  5. using Avalonia.Animation;
  6. using Avalonia.Controls;
  7. using Avalonia.Styling;
  8. using Avalonia.UnitTests;
  9. using Avalonia.Data;
  10. using Xunit;
  11. namespace Avalonia.Animation.UnitTests
  12. {
  13. public class AnimationIterationTests
  14. {
  15. [Fact]
  16. public void Check_Initial_Inter_and_Trailing_Delay_Values()
  17. {
  18. var keyframe1 = new KeyFrame()
  19. {
  20. Setters = {
  21. new Setter(Border.WidthProperty, 200d),
  22. },
  23. Cue = new Cue(1d)
  24. };
  25. var keyframe2 = new KeyFrame()
  26. {
  27. Setters = {
  28. new Setter(Border.WidthProperty, 100d),
  29. },
  30. Cue = new Cue(0d)
  31. };
  32. var animation = new Animation()
  33. {
  34. Duration = TimeSpan.FromSeconds(3),
  35. Delay = TimeSpan.FromSeconds(3),
  36. DelayBetweenIterations = TimeSpan.FromSeconds(3),
  37. IterationCount = new IterationCount(2),
  38. Children =
  39. {
  40. keyframe2,
  41. keyframe1
  42. }
  43. };
  44. var border = new Border()
  45. {
  46. Height = 100d,
  47. Width = 100d
  48. };
  49. var clock = new TestClock();
  50. var animationRun = animation.RunAsync(border, clock);
  51. clock.Step(TimeSpan.Zero);
  52. // Initial Delay.
  53. clock.Step(TimeSpan.FromSeconds(1));
  54. Assert.Equal(border.Width, 0d);
  55. clock.Step(TimeSpan.FromSeconds(6));
  56. // First Inter-Iteration delay.
  57. clock.Step(TimeSpan.FromSeconds(8));
  58. Assert.Equal(border.Width, 200d);
  59. // Trailing Delay should be non-existent.
  60. clock.Step(TimeSpan.FromSeconds(14));
  61. Assert.True(animationRun.Status == TaskStatus.RanToCompletion);
  62. Assert.Equal(border.Width, 100d);
  63. }
  64. }
  65. }