Skip to content

Instantly share code, notes, and snippets.

@grokys
Created May 14, 2019 11:50
Show Gist options
  • Save grokys/1d3272995cec10a82e2173bb95ddfa45 to your computer and use it in GitHub Desktop.
Save grokys/1d3272995cec10a82e2173bb95ddfa45 to your computer and use it in GitHub Desktop.
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