From 01e1835ad884b4c85cca5f31c167876715099032 Mon Sep 17 00:00:00 2001 From: wojciech krysiak Date: Sun, 2 Sep 2018 23:03:21 +0200 Subject: [PATCH] Corrected test implementation --- .../Mixins/ContentControlMixinTests.cs | 60 ++++++------------- 1 file changed, 18 insertions(+), 42 deletions(-) diff --git a/tests/Avalonia.Controls.UnitTests/Mixins/ContentControlMixinTests.cs b/tests/Avalonia.Controls.UnitTests/Mixins/ContentControlMixinTests.cs index a0487842a9..71c396b2c6 100644 --- a/tests/Avalonia.Controls.UnitTests/Mixins/ContentControlMixinTests.cs +++ b/tests/Avalonia.Controls.UnitTests/Mixins/ContentControlMixinTests.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. See licence.md file in the project root for full license information. using System.Collections.Generic; +using System.Linq; using Avalonia.Collections; using Avalonia.Controls.Mixins; using Avalonia.Controls.Presenters; @@ -41,20 +42,10 @@ namespace Avalonia.Controls.UnitTests.Mixins var p1 = new ContentPresenter { Name = "Content_1_Presenter" }; var p2 = new ContentPresenter { Name = "Content_2_Presenter" }; - var callIndex = -1; - var called = new bool[4]; + var itemsAddedThroughMixin = new List(); + var itemsNotAddedThroughMixin = new List(); - void Callback() - { - if (callIndex >= 0) - called[callIndex] = true; - } - - var listMock = new Mock>(); - listMock.Setup(l => l.Contains(It.IsAny())).Returns(false).Callback(Callback); - var list = listMock.Object; - - var target = new TestControl(list) + var target = new TestControl { Template = new FuncControlTemplate(_ => new Panel { @@ -67,26 +58,28 @@ namespace Avalonia.Controls.UnitTests.Mixins }; target.ApplyTemplate(); - callIndex = 0; - p1.Content = new Control(); + Control tc; + + p1.Content = tc = new Control(); p1.UpdateChild(); + itemsAddedThroughMixin.Add(target.GetLogicalChildren().Contains(tc)); - callIndex = 1; - p2.Content = new Control(); + p2.Content = tc = new Control(); p2.UpdateChild(); + itemsAddedThroughMixin.Add(target.GetLogicalChildren().Contains(tc)); target.Template = null; - callIndex = 2; - p1.Content = new Control(); + p1.Content = tc = new Control(); p1.UpdateChild(); + itemsNotAddedThroughMixin.Add(target.GetLogicalChildren().Contains(tc)); - callIndex = 3; - p2.Content = new Control(); + p2.Content = tc = new Control(); p2.UpdateChild(); + itemsNotAddedThroughMixin.Add(target.GetLogicalChildren().Contains(tc)); - - Assert.Equal(new[] { true, true, false, false }, called); + Assert.Equal(new[] { true, true }, itemsAddedThroughMixin); + Assert.Equal(new[] { false, false }, itemsNotAddedThroughMixin); } private class TestControl : TemplatedControl @@ -97,27 +90,10 @@ namespace Avalonia.Controls.UnitTests.Mixins public static readonly StyledProperty Content2Property = AvaloniaProperty.Register(nameof(Content2)); - static TestControl() { - ContentControlMixin.Attach(Content1Property, x => x.GetLogicalChildren(), "Content_1_Presenter"); - ContentControlMixin.Attach(Content2Property, x => x.GetLogicalChildren(), "Content_2_Presenter"); - } - - private IAvaloniaList _mock; - - public TestControl() - { - } - - public TestControl(IAvaloniaList mock) - { - _mock = mock; - } - - public IAvaloniaList GetLogicalChildren() - { - return _mock ?? LogicalChildren; + ContentControlMixin.Attach(Content1Property, x => x.LogicalChildren, "Content_1_Presenter"); + ContentControlMixin.Attach(Content2Property, x => x.LogicalChildren, "Content_2_Presenter"); } public object Content1