18 changed files with 311 additions and 166 deletions
@ -0,0 +1,55 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="SelectorTests_Descendent.cs" company="Steven Kirk">
|
|||
// Copyright 2014 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.UnitTests.Styling |
|||
{ |
|||
using System.Linq; |
|||
using System.Reactive.Linq; |
|||
using Microsoft.VisualStudio.TestTools.UnitTesting; |
|||
using Moq; |
|||
using Perspex.Controls; |
|||
using Perspex.Styling; |
|||
using Match = Perspex.Styling.Selector; |
|||
|
|||
[TestClass] |
|||
public class SelectorTests_Descendent |
|||
{ |
|||
[TestMethod] |
|||
public void Descendent_Matches_Control_When_It_Is_Child_OfType() |
|||
{ |
|||
var parent = new Mock<TestLogical1>(); |
|||
var child = new Mock<TestLogical2>(); |
|||
|
|||
parent.Setup(x => x.LogicalChildren).Returns(new[] |
|||
{ |
|||
child.Object, |
|||
}); |
|||
|
|||
var selector = new Selector().OfType<TestLogical1>().Descendent().OfType<TestLogical2>(); |
|||
|
|||
Assert.AreEqual(true, ActivatorValue(selector, child.Object)); |
|||
} |
|||
|
|||
[TestMethod] |
|||
public void Descendent_Matches_Control_When_It_Is_Descendent_OfType() |
|||
{ |
|||
Assert.Fail(); |
|||
} |
|||
|
|||
private static bool ActivatorValue(Match selector, IStyleable control) |
|||
{ |
|||
return selector.GetActivator(control).Take(1).ToEnumerable().Single(); |
|||
} |
|||
|
|||
public abstract class TestLogical1 : TestLogical |
|||
{ |
|||
} |
|||
|
|||
public abstract class TestLogical2 : TestLogical |
|||
{ |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="SubscribeCheck.cs" company="Steven Kirk">
|
|||
// Copyright 2014 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.UnitTests.Styling |
|||
{ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using Perspex.Controls; |
|||
using Perspex.Styling; |
|||
|
|||
public abstract class TestLogical : TestControlBase, ILogical |
|||
{ |
|||
public TestLogical() |
|||
{ |
|||
} |
|||
|
|||
public abstract ILogical LogicalParent |
|||
{ |
|||
get; |
|||
set; |
|||
} |
|||
|
|||
public abstract IEnumerable<ILogical> LogicalChildren |
|||
{ |
|||
get; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,23 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="SubscribeCheck.cs" company="Steven Kirk">
|
|||
// Copyright 2014 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.UnitTests.Styling |
|||
{ |
|||
using System; |
|||
using System.Reactive.Disposables; |
|||
|
|||
public class TestObservable : IObservable<bool> |
|||
{ |
|||
public int SubscribedCount { get; private set; } |
|||
|
|||
public IDisposable Subscribe(IObserver<bool> observer) |
|||
{ |
|||
++this.SubscribedCount; |
|||
observer.OnNext(true); |
|||
return Disposable.Create(() => --this.SubscribedCount); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,21 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="SubscribeCheck.cs" company="Steven Kirk">
|
|||
// Copyright 2014 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.UnitTests.Styling |
|||
{ |
|||
using Perspex.Styling; |
|||
|
|||
public static class TestSelectors |
|||
{ |
|||
public static Selector SubscribeCheck(this Selector selector) |
|||
{ |
|||
return new Selector(selector) |
|||
{ |
|||
Observable = control => ((TestControlBase)control).SubscribeCheckObservable, |
|||
}; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,37 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="SubscribeCheck.cs" company="Steven Kirk">
|
|||
// Copyright 2014 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.UnitTests.Styling |
|||
{ |
|||
using System.Collections.Generic; |
|||
using Perspex.Controls; |
|||
using Perspex.Styling; |
|||
|
|||
public abstract class TestTemplatedControl : ITemplatedControl, IStyleable |
|||
{ |
|||
public abstract Classes Classes |
|||
{ |
|||
get; |
|||
} |
|||
|
|||
public abstract string Id |
|||
{ |
|||
get; |
|||
} |
|||
|
|||
public abstract ITemplatedControl TemplatedParent |
|||
{ |
|||
get; |
|||
} |
|||
|
|||
public abstract IEnumerable<IVisual> VisualChildren |
|||
{ |
|||
get; |
|||
} |
|||
|
|||
public abstract void SetValue(PerspexProperty property, object value, System.IObservable<bool> activator); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue