/src/Manos.Tests/Manos.Collections/DataDictionaryTest.cs

http://github.com/jacksonh/manos · C# · 138 lines · 87 code · 28 blank · 23 comment · 0 complexity · 50259a704cb7ae5321fb85ff646569a7 MD5 · raw file

  1. //
  2. // Copyright (C) 2010 Jackson Harper (jackson@manosdemono.com)
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining
  5. // a copy of this software and associated documentation files (the
  6. // "Software"), to deal in the Software without restriction, including
  7. // without limitation the rights to use, copy, modify, merge, publish,
  8. // distribute, sublicense, and/or sell copies of the Software, and to
  9. // permit persons to whom the Software is furnished to do so, subject to
  10. // the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be
  13. // included in all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  19. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  20. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  21. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. //
  23. //
  24. using System;
  25. using NUnit.Framework;
  26. namespace Manos.Collections.Tests
  27. {
  28. [TestFixture]
  29. public class DataDictionaryTest
  30. {
  31. [Test]
  32. public void Get_NoItemAdded_ReturnsNull ()
  33. {
  34. var dd = new DataDictionary ();
  35. string res = dd.Get ("foobar");
  36. Assert.IsNull (res);
  37. }
  38. [Test]
  39. public void Get_EmptyChildrenAdded_ReturnsNull ()
  40. {
  41. var dd = new DataDictionary ();
  42. dd.Children.Add (new DataDictionary ());
  43. dd.Children.Add (new DataDictionary ());
  44. string res = dd.Get ("foobar");
  45. Assert.IsNull (res);
  46. }
  47. [Test]
  48. public void Get_DifferentKeyAdded_ReturnsNull ()
  49. {
  50. var dd = new DataDictionary ();
  51. dd.Set ("blizbar", "baz");
  52. string res = dd.Get ("foobar");
  53. Assert.IsNull (res);
  54. }
  55. [Test]
  56. public void Get_NameSet_ReturnsItem ()
  57. {
  58. var dd = new DataDictionary ();
  59. dd.Set ("foobar", "baz");
  60. string res = dd.Get ("foobar");
  61. Assert.AreEqual ("baz", res);
  62. }
  63. [Test]
  64. public void Get_NameSetTwice_ReturnsSecondItem ()
  65. {
  66. var dd = new DataDictionary ();
  67. dd.Set ("foobar", "blah");
  68. dd.Set ("foobar", "baz");
  69. string res = dd.Get ("foobar");
  70. Assert.AreEqual ("baz", res);
  71. }
  72. [Test]
  73. public void Get_NameSetInChild_ReturnsItem ()
  74. {
  75. var dd = new DataDictionary ();
  76. var child = new DataDictionary ();
  77. dd.Children.Add (child);
  78. child.Set ("foobar", "baz");
  79. string res = dd.Get ("foobar");
  80. Assert.AreEqual ("baz", res);
  81. }
  82. [Test]
  83. public void Get_NameInDictionaryAndChild_ReturnsItemFromDictionary ()
  84. {
  85. var dd = new DataDictionary ();
  86. var child = new DataDictionary ();
  87. dd.Children.Add (child);
  88. child.Set ("foobar", "nooo");
  89. dd.Set ("foobar", "baz");
  90. string res = dd.Get ("foobar");
  91. Assert.AreEqual ("baz", res);
  92. }
  93. [Test]
  94. public void Get_MultipleChildrenWithKey_ReturnsFirstChildAdded ()
  95. {
  96. var dd = new DataDictionary ();
  97. var child = new DataDictionary ();
  98. dd.Children.Add (child);
  99. child.Set ("foobar", "baz");
  100. child = new DataDictionary ();
  101. dd.Children.Add (child);
  102. child.Set ("foobar", "blahh");
  103. child = new DataDictionary ();
  104. dd.Children.Add (child);
  105. child.Set ("foobar", "bork");
  106. string res = dd.Get ("foobar");
  107. Assert.AreEqual ("baz", res);
  108. }
  109. }
  110. }