PageRenderTime 87ms CodeModel.GetById 82ms app.highlight 2ms RepoModel.GetById 2ms app.codeStats 0ms

/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
 25using System;
 26using NUnit.Framework;
 27
 28
 29namespace Manos.Collections.Tests
 30{
 31	[TestFixture]
 32	public class DataDictionaryTest
 33	{
 34		[Test]
 35		public void Get_NoItemAdded_ReturnsNull ()
 36		{
 37			var dd = new DataDictionary ();
 38			
 39			string res = dd.Get ("foobar");
 40			Assert.IsNull (res);
 41		}
 42		
 43		[Test]
 44		public void Get_EmptyChildrenAdded_ReturnsNull ()
 45		{
 46			var dd = new DataDictionary ();
 47			
 48			dd.Children.Add (new DataDictionary ());
 49			dd.Children.Add (new DataDictionary ());
 50			
 51			string res = dd.Get ("foobar");
 52			Assert.IsNull (res);
 53		}
 54		
 55		[Test]
 56		public void Get_DifferentKeyAdded_ReturnsNull ()
 57		{
 58			var dd = new DataDictionary ();
 59			
 60			dd.Set ("blizbar", "baz");
 61			
 62			string res = dd.Get ("foobar");
 63			Assert.IsNull (res);
 64		}
 65		
 66		[Test]
 67		public void Get_NameSet_ReturnsItem ()
 68		{
 69			var dd = new DataDictionary ();
 70			
 71			dd.Set ("foobar", "baz");
 72			
 73			string res = dd.Get ("foobar");
 74			Assert.AreEqual ("baz", res);
 75		}
 76		
 77		[Test]
 78		public void Get_NameSetTwice_ReturnsSecondItem ()
 79		{
 80			var dd = new DataDictionary ();
 81			
 82			dd.Set ("foobar", "blah");
 83			dd.Set ("foobar", "baz");
 84			
 85			string res = dd.Get ("foobar");
 86			Assert.AreEqual ("baz", res);
 87		}
 88		
 89		[Test]
 90		public void Get_NameSetInChild_ReturnsItem ()
 91		{
 92			var dd = new DataDictionary ();
 93			var child = new DataDictionary ();
 94			
 95			dd.Children.Add (child);
 96			child.Set ("foobar", "baz");
 97			
 98			string res = dd.Get ("foobar");
 99			Assert.AreEqual ("baz", res);
100		}
101		
102		[Test]
103		public void Get_NameInDictionaryAndChild_ReturnsItemFromDictionary ()
104		{
105			var dd = new DataDictionary ();
106			var child = new DataDictionary ();
107			
108			dd.Children.Add (child);
109			child.Set ("foobar", "nooo");
110			dd.Set ("foobar", "baz");
111			
112			string res = dd.Get ("foobar");
113			Assert.AreEqual ("baz", res);
114		}
115		
116		[Test]
117		public void Get_MultipleChildrenWithKey_ReturnsFirstChildAdded ()
118		{
119			var dd = new DataDictionary ();
120			var child = new DataDictionary ();
121			
122			dd.Children.Add (child);
123			child.Set ("foobar", "baz");
124			
125			child = new DataDictionary ();
126			dd.Children.Add (child);
127			child.Set ("foobar", "blahh");
128			
129			child = new DataDictionary ();
130			dd.Children.Add (child);
131			child.Set ("foobar", "bork");
132			
133			string res = dd.Get ("foobar");
134			Assert.AreEqual ("baz", res);
135		}
136	}
137}
138