NameScopeTests.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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;
  4. using Xunit;
  5. namespace Avalonia.Controls.UnitTests
  6. {
  7. public class NameScopeTests
  8. {
  9. [Fact]
  10. public void Register_Registers_Element()
  11. {
  12. var target = new NameScope();
  13. var element = new object();
  14. target.Register("foo", element);
  15. Assert.Same(element, target.Find("foo"));
  16. }
  17. [Fact]
  18. public void Unregister_Unregisters_Element()
  19. {
  20. var target = new NameScope();
  21. var element = new object();
  22. target.Register("foo", element);
  23. target.Unregister("foo");
  24. Assert.Null(target.Find("foo"));
  25. }
  26. [Fact]
  27. public void Cannot_Register_New_Element_With_Existing_Name()
  28. {
  29. var target = new NameScope();
  30. target.Register("foo", new object());
  31. Assert.Throws<ArgumentException>(() => target.Register("foo", new object()));
  32. }
  33. [Fact]
  34. public void Can_Register_Same_Element_More_Than_Once()
  35. {
  36. var target = new NameScope();
  37. var element = new object();
  38. target.Register("foo", element);
  39. target.Register("foo", element);
  40. Assert.Same(element, target.Find("foo"));
  41. }
  42. }
  43. }