InlineDictionaryTests.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #nullable enable
  2. using System.Collections.Generic;
  3. using Avalonia.Utilities;
  4. using Xunit;
  5. namespace Avalonia.Base.UnitTests.Utilities;
  6. public class InlineDictionaryTests
  7. {
  8. [Fact]
  9. public void Set_Twice_With_Single_Item_Works()
  10. {
  11. var dic = new InlineDictionary<string, int>();
  12. dic["foo"] = 1;
  13. Assert.Equal(1, dic["foo"]);
  14. dic["foo"] = 2;
  15. Assert.Equal(2, dic["foo"]);
  16. }
  17. [Fact]
  18. public void Enumeration_After_Add_With_Internal_Array_Works()
  19. {
  20. var dic = new InlineDictionary<string, int>();
  21. dic.Add("foo", 1);
  22. dic.Add("bar", 2);
  23. dic.Add("baz", 3);
  24. Assert.Equal(
  25. new[] {
  26. new KeyValuePair<string, int>("foo", 1),
  27. new KeyValuePair<string, int>("bar", 2),
  28. new KeyValuePair<string, int>("baz", 3)
  29. },
  30. dic);
  31. }
  32. [Fact]
  33. public void Enumeration_After_Remove_With_Internal_Array_Works()
  34. {
  35. var dic = new InlineDictionary<string, int>();
  36. dic.Add("foo", 1);
  37. dic.Add("bar", 2);
  38. dic.Add("baz", 3);
  39. Assert.Equal(
  40. new[] {
  41. new KeyValuePair<string, int>("foo", 1),
  42. new KeyValuePair<string, int>("bar", 2),
  43. new KeyValuePair<string, int>("baz", 3)
  44. },
  45. dic);
  46. dic.Remove("bar");
  47. Assert.Equal(
  48. new[] {
  49. new KeyValuePair<string, int>("foo", 1),
  50. new KeyValuePair<string, int>("baz", 3)
  51. },
  52. dic);
  53. }
  54. }