|
1 | 1 | using System;
|
| 2 | +using Avalonia.Animation.Animators; |
2 | 3 | using Avalonia.Controls;
|
| 4 | +using Avalonia.Controls.Shapes; |
3 | 5 | using Avalonia.Data;
|
4 | 6 | using Avalonia.Layout;
|
5 | 7 | using Avalonia.Media;
|
@@ -100,6 +102,71 @@ public void Transition_Is_Not_Applied_When_Animated_Value_Changes()
|
100 | 102 | Times.Never);
|
101 | 103 | }
|
102 | 104 |
|
| 105 | + |
| 106 | + [Theory] |
| 107 | + [InlineData(null)] //null value |
| 108 | + [InlineData("stringValue")] //string value |
| 109 | + public void Invalid_Values_In_Animation_Should_Not_Crash_Animations(object invalidValue) |
| 110 | + { |
| 111 | + var keyframe1 = new KeyFrame() |
| 112 | + { |
| 113 | + Setters = |
| 114 | + { |
| 115 | + new Setter(Layoutable.WidthProperty, 1d), |
| 116 | + }, |
| 117 | + KeyTime = TimeSpan.FromSeconds(0) |
| 118 | + }; |
| 119 | + |
| 120 | + var keyframe2 = new KeyFrame() |
| 121 | + { |
| 122 | + Setters = |
| 123 | + { |
| 124 | + new Setter(Layoutable.WidthProperty, 2d), |
| 125 | + }, |
| 126 | + KeyTime = TimeSpan.FromSeconds(2), |
| 127 | + }; |
| 128 | + |
| 129 | + var keyframe3 = new KeyFrame() |
| 130 | + { |
| 131 | + Setters = |
| 132 | + { |
| 133 | + new Setter(Layoutable.WidthProperty, invalidValue), |
| 134 | + }, |
| 135 | + KeyTime = TimeSpan.FromSeconds(3), |
| 136 | + }; |
| 137 | + |
| 138 | + var animation = new Animation() |
| 139 | + { |
| 140 | + Duration = TimeSpan.FromSeconds(3), |
| 141 | + Children = |
| 142 | + { |
| 143 | + keyframe1, |
| 144 | + keyframe2, |
| 145 | + keyframe3 |
| 146 | + }, |
| 147 | + IterationCount = new IterationCount(5), |
| 148 | + PlaybackDirection = PlaybackDirection.Alternate, |
| 149 | + }; |
| 150 | + |
| 151 | + var rect = new Rectangle() |
| 152 | + { |
| 153 | + Width = 11, |
| 154 | + }; |
| 155 | + |
| 156 | + var originalValue = rect.Width; |
| 157 | + |
| 158 | + var clock = new TestClock(); |
| 159 | + var animationRun = animation.RunAsync(rect, clock); |
| 160 | + |
| 161 | + clock.Step(TimeSpan.Zero); |
| 162 | + Assert.Equal(rect.Width, 1); |
| 163 | + clock.Step(TimeSpan.FromSeconds(2)); |
| 164 | + Assert.Equal(rect.Width, 2); |
| 165 | + clock.Step(TimeSpan.FromSeconds(3)); |
| 166 | + //here we have invalid value so value should be expected and set to initial original value |
| 167 | + Assert.Equal(rect.Width, originalValue); |
| 168 | + } |
| 169 | + |
103 | 170 | [Fact]
|
104 | 171 | public void Transition_Is_Not_Applied_When_StyleTrigger_Changes_With_LocalValue_Present()
|
105 | 172 | {
|
|
0 commit comments