Created
May 14, 2019 11:50
-
-
Save grokys/1d3272995cec10a82e2173bb95ddfa45 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Avalonia.Animation; | |
using Avalonia.Controls; | |
using Avalonia.UnitTests; | |
using JetBrains.dotMemoryUnit; | |
using Xunit; | |
using Xunit.Abstractions; | |
namespace Avalonia.LeakTests | |
{ | |
[DotMemoryUnit(FailIfRunWithoutSupport = false)] | |
public class TransitionTests | |
{ | |
public TransitionTests(ITestOutputHelper atr) | |
{ | |
DotMemoryUnitTestOutput.SetOutputMethod(atr.WriteLine); | |
} | |
[Fact] | |
public void Transition_On_StyledProperty_Is_Freed() | |
{ | |
using (UnitTestApplication.Start()) | |
{ | |
var clock = new MockClock(); | |
AvaloniaLocator.CurrentMutable.Bind<IGlobalClock>().ToConstant(clock); | |
Func<Border> run = () => | |
{ | |
var border = new Border | |
{ | |
Transitions = | |
{ | |
new DoubleTransition | |
{ | |
Duration = TimeSpan.FromSeconds(1), | |
Property = Border.OpacityProperty, | |
} | |
} | |
}; | |
border.Opacity = 0; | |
clock.Pulse(TimeSpan.FromSeconds(0)); | |
clock.Pulse(TimeSpan.FromSeconds(0.5)); | |
Assert.Equal(0.5, border.Opacity); | |
clock.Pulse(TimeSpan.FromSeconds(1)); | |
Assert.Equal(0, border.Opacity); | |
return border; | |
}; | |
dotMemory.Check(memory => | |
Assert.Equal(0, memory.GetObjects(where => where.Type.Is<DoubleTransition>()).ObjectsCount)); | |
} | |
} | |
private class MockClock : ClockBase, IGlobalClock | |
{ | |
public new void Pulse(TimeSpan systemTime) => base.Pulse(systemTime); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment