ResourceTests.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // Copyright (c) The Avalonia 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.Collections.Generic;
  4. using Avalonia.Controls;
  5. using Xunit;
  6. namespace Avalonia.Styling.UnitTests
  7. {
  8. public class ResourceTests
  9. {
  10. [Fact]
  11. public void FindStyleResource_Should_Find_Correct_Resource()
  12. {
  13. Border target;
  14. var tree = new Decorator
  15. {
  16. Styles =
  17. {
  18. new Style
  19. {
  20. Resources = new StyleResources
  21. {
  22. { "Foo", "foo resource" },
  23. { "Bar", "overridden" },
  24. }
  25. }
  26. },
  27. Child = target = new Border
  28. {
  29. Styles =
  30. {
  31. new Style
  32. {
  33. Resources = new StyleResources
  34. {
  35. { "Bar", "again overridden" },
  36. }
  37. },
  38. new Style
  39. {
  40. Resources = new StyleResources
  41. {
  42. { "Bar", "bar resource" },
  43. }
  44. }
  45. }
  46. }
  47. };
  48. Assert.Equal("foo resource", target.FindStyleResource("Foo"));
  49. Assert.Equal("bar resource", target.FindStyleResource("Bar"));
  50. }
  51. [Fact]
  52. public void FindStyleResource_Should_Return_UnsetValue_For_Not_Found()
  53. {
  54. Border target;
  55. var tree = target = new Border
  56. {
  57. Styles =
  58. {
  59. new Style
  60. {
  61. Resources = new StyleResources
  62. {
  63. { "Foo", "foo" },
  64. }
  65. },
  66. }
  67. };
  68. Assert.Equal(AvaloniaProperty.UnsetValue, target.FindStyleResource("Baz"));
  69. }
  70. }
  71. }