Browse Source

Gangnam Style

pull/4/head
grokys 12 years ago
parent
commit
63f674d897
  1. 87
      Perspex.UnitTests/Styling/SelectorTests.cs
  2. 4
      Perspex/Styling/Selectors.cs

87
Perspex.UnitTests/Styling/SelectorTests.cs

@ -7,12 +7,13 @@
namespace Perspex.UnitTests.Styling
{
using System;
using System.Linq;
using System.Reactive;
using System.Reactive.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Perspex.Styling;
using Match = Perspex.Styling.Match;
using System.Linq;
using System.Reactive;
using System.Reactive.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Perspex.Controls;
using Perspex.Styling;
using Match = Perspex.Styling.Match;
[TestClass]
public class SelectorTests
@ -90,6 +91,24 @@ namespace Perspex.UnitTests.Styling
CollectionAssert.AreEqual(new[] { false }, target.GetActivator().Take(1).ToEnumerable().ToArray());
}
[TestMethod]
public void Id_Doesnt_Match_Control_With_TemplatedParent()
{
var control = new Control1 { Id = "foo", TemplatedParent = new TemplatedControl1() };
var target = control.Select().Id("foo");
CollectionAssert.AreEqual(new[] { false }, target.GetActivator().Take(1).ToEnumerable().ToArray());
}
[TestMethod]
public void Id_Matches_Control_With_TemplatedParent_After_InTemplateOf()
{
var control = new Control1 { Id = "foo", TemplatedParent = new TemplatedControl1() };
var target = control.Select().InTemplateOf<TemplatedControl1>().Id("foo");
CollectionAssert.AreEqual(new[] { true }, target.GetActivator().Take(1).ToEnumerable().ToArray());
}
[TestMethod]
public void When_Id_Matches_Control_Other_Selectors_Are_Subscribed()
{
@ -112,6 +131,46 @@ namespace Perspex.UnitTests.Styling
Assert.AreEqual(0, control.SubscribeCheckObservable.SubscribedCount);
}
[TestMethod]
public void InTemplateOf_Matches_Control_Of_Correct_Type()
{
var control = new Control1 { TemplatedParent = new TemplatedControl1() };
var target = control.Select().InTemplateOf<TemplatedControl1>();
CollectionAssert.AreEqual(new[] { true }, target.GetActivator().Take(1).ToEnumerable().ToArray());
}
[TestMethod]
public void InTemplateOf_Doesnt_Match_Control_Of_Wrong_Type()
{
var control = new Control1 { TemplatedParent = new TemplatedControl1() };
var target = control.Select().InTemplateOf<TemplatedControl2>();
CollectionAssert.AreEqual(new[] { false }, target.GetActivator().Take(1).ToEnumerable().ToArray());
}
[TestMethod]
public void When_InTemplateOf_Matches_Control_Other_Selectors_Are_Subscribed()
{
var control = new Control1 { TemplatedParent = new TemplatedControl1() };
var target = control.Select().InTemplateOf<TemplatedControl1>().SubscribeCheck();
var result = target.GetActivator().ToEnumerable().Take(1).ToArray();
Assert.AreEqual(1, control.SubscribeCheckObservable.SubscribedCount);
}
[TestMethod]
public void When_InTemplateOf_Doesnt_Match_Control_Other_Selectors_Are_Not_Subscribed()
{
var control = new Control1 { TemplatedParent = new TemplatedControl1() };
var target = control.Select().InTemplateOf<TemplatedControl2>().SubscribeCheck();
var result = target.GetActivator().ToEnumerable().Take(1).ToArray();
Assert.AreEqual(0, control.SubscribeCheckObservable.SubscribedCount);
}
[TestMethod]
public void OfType_Matches_Control_Of_Correct_Type()
{
@ -159,5 +218,21 @@ namespace Perspex.UnitTests.Styling
public class Control2 : SubscribeCheck
{
}
public class TemplatedControl1 : TemplatedControl
{
protected override Size MeasureContent(Size availableSize)
{
throw new NotImplementedException();
}
}
public class TemplatedControl2 : TemplatedControl
{
protected override Size MeasureContent(Size availableSize)
{
throw new NotImplementedException();
}
}
}
}

4
Perspex/Styling/Selectors.cs

@ -59,7 +59,7 @@ namespace Perspex.Styling
return match;
}
public static Match InTemplateOf<T>(this Match match)
public static Match InTemplateOf<T>(this Match match) where T : TemplatedControl
{
Contract.Requires<ArgumentNullException>(match != null);
@ -69,7 +69,7 @@ namespace Perspex.Styling
return match;
}
public static Match OfType<T>(this Match match)
public static Match OfType<T>(this Match match) where T : IStyleable
{
Contract.Requires<ArgumentNullException>(match != null);

Loading…
Cancel
Save