public void Name_Doesnt_Match_Control_With_TemplatedParent() { var control = new Control1 { TemplatedParent = new Mock<ITemplatedControl>().Object }; var target = new Selector().Name("foo"); var activator = target.Match(control); Assert.False(target.Match(control).ImmediateResult); }
public void OfType_Matches_Control_Of_Correct_Type() { var control = new Control1(); var target = new Selector().OfType<Control1>(); Assert.True(target.Match(control).ImmediateResult); }
public void OfType_Matches_Control_With_TemplatedParent() { var control = new Control1 { TemplatedParent = new Mock<ITemplatedControl>().Object }; var target = new Selector().OfType<Control1>(); Assert.True(target.Match(control).ImmediateResult); }
public void Child_Doesnt_Match_Control_When_It_Has_No_Parent() { var control = new TestLogical3(); var selector = new Selector().OfType<TestLogical1>().Child().OfType<TestLogical3>(); Assert.False(selector.Match(control).ImmediateResult); }
public void Name_Matches_Control_With_Correct_Name() { var control = new Control1 { Name = "foo" }; var target = new Selector().Name("foo"); Assert.True(target.Match(control).ImmediateResult); }
public void Name_Doesnt_Match_Control_Of_Wrong_Name() { var control = new Control1 { Name = "foo" }; var target = new Selector().Name("bar"); Assert.False(target.Match(control).ImmediateResult); }
public void OfType_Doesnt_Match_Control_Of_Wrong_Type() { var control = new Control2(); var target = new Selector().OfType<Control1>(); Assert.False(target.Match(control).ImmediateResult); }
public async Task Class_Tracks_Additions() { var control = new Control1(); var target = new Selector().Class("foo"); var activator = target.Match(control).ObservableResult; Assert.False(await activator.Take(1)); control.Classes.Add("foo"); Assert.True(await activator.Take(1)); }
public void Child_Matches_Control_When_It_Is_Child_OfType() { var parent = new TestLogical1(); var child = new TestLogical2(); child.LogicalParent = parent; var selector = new Selector().OfType<TestLogical1>().Child().OfType<TestLogical2>(); Assert.True(selector.Match(child).ImmediateResult); }
public async Task PropertyEquals_Matches_When_Property_Has_Matching_Value() { var control = new TextBlock(); var target = new Selector().PropertyEquals(TextBlock.TextProperty, "foo"); var activator = target.Match(control).ObservableResult; Assert.False(await activator.Take(1)); control.Text = "foo"; Assert.True(await activator.Take(1)); control.Text = null; Assert.False(await activator.Take(1)); }
private static SelectorMatch MatchTemplate(IStyleable control, Selector previous) { IStyleable templatedParent = control.TemplatedParent as IStyleable; if (templatedParent == null) { throw new InvalidOperationException( "Cannot call Template selector on control with null TemplatedParent."); } return(previous.Match(templatedParent)); }
public async Task Class_Doesnt_Match_Control_Without_Class() { var control = new Control1 { Classes = new Classes { "bar" }, }; var target = new Selector().Class("foo"); var activator = target.Match(control).ObservableResult; Assert.False(await activator.Take(1)); }
public async Task Class_Matches_Control_With_TemplatedParent() { var control = new Control1 { Classes = new Classes { "foo" }, TemplatedParent = new Mock<ITemplatedControl>().Object, }; var target = new Selector().Class("foo"); var activator = target.Match(control).ObservableResult; Assert.True(await activator.Take(1)); }
private static SelectorMatch MatchChild(IStyleable control, Selector previous) { var parent = ((ILogical)control).LogicalParent; if (parent != null) { return(previous.Match((IStyleable)parent)); } else { return(SelectorMatch.False); } }
public void Descendent_Matches_Control_When_It_Is_Descendent_OfType() { var grandparent = new TestLogical1(); var parent = new TestLogical2(); var child = new TestLogical3(); parent.LogicalParent = grandparent; child.LogicalParent = parent; var selector = new Selector().OfType<TestLogical1>().Descendent().OfType<TestLogical3>(); Assert.True(selector.Match(child).ImmediateResult); }
protected override SelectorMatch Evaluate(IStyleable control, bool subscribe) { var controlParent = ((ILogical)control).LogicalParent; if (controlParent != null) { return(_parent.Match((IStyleable)controlParent, subscribe)); } else { return(SelectorMatch.False); } }
public void Child_Doesnt_Match_Control_When_It_Is_Grandchild_OfType() { var grandparent = new TestLogical1(); var parent = new TestLogical2(); var child = new TestLogical3(); parent.LogicalParent = grandparent; child.LogicalParent = parent; var selector = new Selector().OfType<TestLogical1>().Child().OfType<TestLogical3>(); Assert.False(selector.Match(child).ImmediateResult); }
/// <summary> /// Attaches the style to a control if the style's selector matches. /// </summary> /// <param name="control">The control to attach to.</param> public void Attach(IStyleable control) { var description = "Style " + Selector.ToString(); var match = Selector.Match(control); if (match.ImmediateResult != false) { foreach (var setter in Setters) { setter.Apply(this, control, match.ObservableResult); } } }
public async Task Class_Tracks_Removals() { var control = new Control1 { Classes = new Classes { "foo" }, }; var target = new Selector().Class("foo"); var activator = target.Match(control).ObservableResult; Assert.True(await activator.Take(1)); control.Classes.Remove("foo"); Assert.False(await activator.Take(1)); }
public async Task Descendent_Matches_Control_When_It_Is_Descendent_OfType_And_Class() { var grandparent = new TestLogical1(); var parent = new TestLogical2(); var child = new TestLogical3(); grandparent.Classes.Add("foo"); parent.LogicalParent = grandparent; child.LogicalParent = parent; var selector = new Selector().OfType<TestLogical1>().Class("foo").Descendent().OfType<TestLogical3>(); var activator = selector.Match(child).ObservableResult; Assert.True(await activator.Take(1)); }
public async Task Child_Matches_Control_When_It_Is_Child_OfType_And_Class() { var parent = new TestLogical1(); var child = new TestLogical2(); child.LogicalParent = parent; var selector = new Selector().OfType<TestLogical1>().Class("foo").Child().OfType<TestLogical2>(); var activator = selector.Match(child).ObservableResult; Assert.False(await activator.Take(1)); parent.Classes.Add("foo"); Assert.True(await activator.Take(1)); parent.Classes.Remove("foo"); Assert.False(await activator.Take(1)); }
protected override SelectorMatch Evaluate(IStyleable control, bool subscribe) { ILogical c = (ILogical)control; List <IObservable <bool> > descendentMatches = new List <IObservable <bool> >(); while (c != null) { c = c.LogicalParent; if (c is IStyleable) { var match = _parent.Match((IStyleable)c, subscribe); if (match.ImmediateResult != null) { if (match.ImmediateResult == true) { return(SelectorMatch.True); } } else { descendentMatches.Add(match.ObservableResult); } } } if (descendentMatches.Count > 0) { return(new SelectorMatch(StyleActivator.Or(descendentMatches))); } else { return(SelectorMatch.False); } }
public void Template_Child_Of_Control_With_Two_Classes() { var template = new ControlTemplate(parent => { return new Border { Name = "border", }; }); var control = new Button { Template = template, }; control.ApplyTemplate(); var selector = new Selector() .OfType<Button>() .Class("foo") .Class("bar") .Template() .Name("border"); var border = (Border)((IVisual)control).VisualChildren.Single(); var values = new List<bool>(); var activator = selector.Match(border).ObservableResult; activator.Subscribe(x => values.Add(x)); Assert.Equal(new[] { false }, values); control.Classes.Add("foo", "bar"); Assert.Equal(new[] { false, true }, values); control.Classes.Remove("foo"); Assert.Equal(new[] { false, true, false }, values); }
public async Task Multiple_Classes() { var control = new Control1(); var target = new Selector().Class("foo").Class("bar"); var activator = target.Match(control).ObservableResult; Assert.False(await activator.Take(1)); control.Classes.Add("foo"); Assert.False(await activator.Take(1)); control.Classes.Add("bar"); Assert.True(await activator.Take(1)); control.Classes.Remove("bar"); Assert.False(await activator.Take(1)); }
public async Task Descendent_Matches_Any_Ancestor() { var grandparent = new TestLogical1(); var parent = new TestLogical1(); var child = new TestLogical3(); parent.LogicalParent = grandparent; child.LogicalParent = parent; var selector = new Selector().OfType<TestLogical1>().Class("foo").Descendent().OfType<TestLogical3>(); var activator = selector.Match(child).ObservableResult; Assert.False(await activator.Take(1)); parent.Classes.Add("foo"); Assert.True(await activator.Take(1)); grandparent.Classes.Add("foo"); Assert.True(await activator.Take(1)); parent.Classes.Remove("foo"); Assert.True(await activator.Take(1)); grandparent.Classes.Remove("foo"); Assert.False(await activator.Take(1)); }