SelectorTests_Multiple.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright (c) The Perspex Project. All rights reserved.
  2. // Licensed under the MIT license. See licence.md file in the project root for full license information.
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using Perspex.Controls;
  7. using Perspex.Controls.Templates;
  8. using Perspex.Styling;
  9. using Xunit;
  10. namespace Perspex.Styling.UnitTests
  11. {
  12. public class SelectorTests_Multiple
  13. {
  14. [Fact]
  15. public void Template_Child_Of_Control_With_Two_Classes()
  16. {
  17. var template = new FuncControlTemplate(parent =>
  18. {
  19. return new Border
  20. {
  21. Name = "border",
  22. };
  23. });
  24. var control = new Button
  25. {
  26. Template = template,
  27. };
  28. control.ApplyTemplate();
  29. var selector = new Selector()
  30. .OfType<Button>()
  31. .Class("foo")
  32. .Class("bar")
  33. .Template()
  34. .Name("border");
  35. var border = (Border)((IVisual)control).VisualChildren.Single();
  36. var values = new List<bool>();
  37. var activator = selector.Match(border).ObservableResult;
  38. activator.Subscribe(x => values.Add(x));
  39. Assert.Equal(new[] { false }, values);
  40. control.Classes.Add("foo", "bar");
  41. Assert.Equal(new[] { false, true }, values);
  42. control.Classes.Remove("foo");
  43. Assert.Equal(new[] { false, true, false }, values);
  44. }
  45. }
  46. }