Browse Source

Add affinity tests

pull/1951/head
artyom 8 years ago
parent
commit
0153c76997
  1. 38
      tests/Avalonia.ReactiveUI.UnitTests/AvaloniaActivationForViewFetcherTest.cs

38
tests/Avalonia.ReactiveUI.UnitTests/AvaloniaActivationForViewFetcherTest.cs

@ -71,25 +71,35 @@ namespace Avalonia
Assert.Equal(2, activated.Count); Assert.Equal(2, activated.Count);
} }
[Fact]
public void GetAffinityForViewShouldReturnNonZeroForVisualElements()
{
var userControl = new TestUserControl();
var activationForViewFetcher = new AvaloniaActivationForViewFetcher();
var forUserControl = activationForViewFetcher.GetAffinityForView(userControl.GetType());
var forNonUserControl = activationForViewFetcher.GetAffinityForView(typeof(object));
Assert.NotEqual(0, forUserControl);
Assert.Equal(0, forNonUserControl);
}
[Fact] [Fact]
public void ActivationForViewFetcherShouldSupportWhenActivated() public void ActivationForViewFetcherShouldSupportWhenActivated()
{ {
var locator = new ModernDependencyResolver(); Locator.CurrentMutable.RegisterConstant(
locator.InitializeSplat(); new AvaloniaActivationForViewFetcher(),
locator.InitializeReactiveUI(); typeof(IActivationForViewFetcher));
locator.RegisterConstant(new AvaloniaActivationForViewFetcher(), typeof(IActivationForViewFetcher));
using (locator.WithResolver())
{
var userControl = new TestUserControlWithWhenActivated();
Assert.False(userControl.Active);
var fakeRenderedDecorator = new FakeRenderDecorator(); var userControl = new TestUserControlWithWhenActivated();
fakeRenderedDecorator.Child = userControl; Assert.False(userControl.Active);
Assert.True(userControl.Active);
fakeRenderedDecorator.Child = null; var fakeRenderedDecorator = new FakeRenderDecorator();
Assert.False(userControl.Active); fakeRenderedDecorator.Child = userControl;
} Assert.True(userControl.Active);
fakeRenderedDecorator.Child = null;
Assert.False(userControl.Active);
} }
} }
} }
Loading…
Cancel
Save