1 //
2 // Tests for System.Web.UI.WebControls.ImageMap.cs
3 //
4 // Author:
5 //  Hagit Yidov (hagity@mainsoft.com
6 //
7 // (C) 2005 Mainsoft Corporation (http://www.mainsoft.com)
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28 
29 using NUnit.Framework;
30 using System;
31 using System.IO;
32 using System.Globalization;
33 using System.Web;
34 using System.Web.UI;
35 using System.Web.UI.WebControls;
36 using MonoTests.stand_alone.WebHarness;
37 using MonoTests.SystemWeb.Framework;
38 using System.Threading;
39 using System.Collections;
40 
41 namespace MonoTests.System.Web.UI.WebControls {
42 	[TestFixture]
43 	public class TreeNodeBindingCollectionTest {
44 
45 		[Test]
TreeNodeBindingCollection_Method_Add()46 		public void TreeNodeBindingCollection_Method_Add () {
47 			TreeView tv = new TreeView ();
48 			Assert.AreEqual (0, tv.DataBindings.Count, "BeforeAdd");
49 			TreeNodeBinding tnb = new TreeNodeBinding ();
50 			tnb.DataMember = "TreeNodeBinding";
51 			tv.DataBindings.Add (tnb);
52 			Assert.AreEqual (1, tv.DataBindings.Count, "AfterAdd1");
53 			Assert.AreEqual ("TreeNodeBinding", tv.DataBindings[0].DataMember, "AfterAdd2");
54 		}
55 
56 		[Test]
TreeNodeBindingCollection_Method_Clear()57 		public void TreeNodeBindingCollection_Method_Clear () {
58 			TreeView tv = new TreeView ();
59 			tv.DataBindings.Add (new TreeNodeBinding ());
60 			tv.DataBindings.Add (new TreeNodeBinding ());
61 			tv.DataBindings.Add (new TreeNodeBinding ());
62 			Assert.AreEqual (3, tv.DataBindings.Count, "BeforeClear");
63 			tv.DataBindings.Clear ();
64 			Assert.AreEqual (0, tv.DataBindings.Count, "AfterClear");
65 		}
66 
67 		[Test]
TreeNodeBindingCollection_Method_Contains()68 		public void TreeNodeBindingCollection_Method_Contains () {
69 			TreeView tv = new TreeView ();
70 			TreeNodeBinding tnb = new TreeNodeBinding ();
71 			tv.DataBindings.Add (new TreeNodeBinding ());
72 			Assert.AreEqual (false, tv.DataBindings.Contains (tnb), "BeforeContains");
73 			tv.DataBindings.Add (tnb);
74 			tv.DataBindings.Add (new TreeNodeBinding ());
75 			Assert.AreEqual (true, tv.DataBindings.Contains (tnb), "AfterContains");
76 		}
77 
78 		[Test]
TreeNodeBindingCollection_Method_CopyTo()79 		public void TreeNodeBindingCollection_Method_CopyTo () {
80 			TreeView tv = new TreeView ();
81 			TreeNodeBinding[] bindingArray = new TreeNodeBinding[10];
82 			tv.DataBindings.Add (new TreeNodeBinding ());
83 			TreeNodeBinding tnb = new TreeNodeBinding ();
84 			tnb.DataMember = "TreeNodeBinding";
85 			tv.DataBindings.Add (tnb);
86 			tv.DataBindings.Add (new TreeNodeBinding ());
87 			Assert.AreEqual (3, tv.DataBindings.Count, "BeforeCopyTo");
88 			tv.DataBindings.CopyTo (bindingArray, 3);
89 			Assert.AreEqual ("TreeNodeBinding", bindingArray[4].DataMember, "AfterCopyTo");
90 		}
91 
92 		[Test]
TreeNodeBindingCollection_Method_IndexOf()93 		public void TreeNodeBindingCollection_Method_IndexOf () {
94 			TreeView tv = new TreeView ();
95 			TreeNodeBinding tnb = new TreeNodeBinding ();
96 			tv.DataBindings.Add (new TreeNodeBinding ());
97 			tv.DataBindings.Add (new TreeNodeBinding ());
98 			Assert.AreEqual (-1, tv.DataBindings.IndexOf (tnb), "BeforeIndexOf");
99 			tv.DataBindings.Add (tnb);
100 			tv.DataBindings.Add (new TreeNodeBinding ());
101 			Assert.AreEqual (2, tv.DataBindings.IndexOf (tnb), "AfterIndexOf");
102 		}
103 
104 		[Test]
TreeNodeBindingCollection_Method_Insert()105 		public void TreeNodeBindingCollection_Method_Insert () {
106 			TreeView tv = new TreeView ();
107 			tv.DataBindings.Add (new TreeNodeBinding ());
108 			tv.DataBindings.Add (new TreeNodeBinding ());
109 			Assert.AreEqual (2, tv.DataBindings.Count, "BeforeInsert");
110 			TreeNodeBinding tnb = new TreeNodeBinding ();
111 			tnb.DataMember = "TreeNodeBinding";
112 			tv.DataBindings.Insert (1, tnb);
113 			Assert.AreEqual (3, tv.DataBindings.Count, "AfterInsert1");
114 			Assert.AreEqual ("TreeNodeBinding", tv.DataBindings[1].DataMember, "AfterInsert2");
115 		}
116 
117 		[Test]
TreeNodeBindingCollection_Method_Remove()118 		public void TreeNodeBindingCollection_Method_Remove () {
119 			TreeView tv = new TreeView ();
120 			TreeNodeBinding tnb1 = new TreeNodeBinding ();
121 			tnb1.DataMember = "first";
122 			TreeNodeBinding tnb2 = new TreeNodeBinding ();
123 			tnb2.DataMember = "second";
124 			TreeNodeBinding tnb3 = new TreeNodeBinding ();
125 			tnb3.DataMember = "third";
126 			tv.DataBindings.Add (tnb1);
127 			tv.DataBindings.Add (tnb2);
128 			tv.DataBindings.Add (tnb3);
129 			Assert.AreEqual (3, tv.DataBindings.Count, "BeforeRemove1");
130 			Assert.AreEqual ("second", tv.DataBindings[1].DataMember, "BeforeRemove2");
131 			tv.DataBindings.Remove (tnb2);
132 			Assert.AreEqual (2, tv.DataBindings.Count, "AfterRemove1");
133 			Assert.AreEqual ("third", tv.DataBindings[1].DataMember, "AfterRemove2");
134 		}
135 
136 		[Test]
TreeNodeBindingCollection_Method_RemoveAt()137 		public void TreeNodeBindingCollection_Method_RemoveAt () {
138 			TreeView tv = new TreeView ();
139 			TreeNodeBinding tnb1 = new TreeNodeBinding ();
140 			tnb1.DataMember = "first";
141 			TreeNodeBinding tnb2 = new TreeNodeBinding ();
142 			tnb2.DataMember = "second";
143 			TreeNodeBinding tnb3 = new TreeNodeBinding ();
144 			tnb3.DataMember = "third";
145 			tv.DataBindings.Add (tnb1);
146 			tv.DataBindings.Add (tnb2);
147 			tv.DataBindings.Add (tnb3);
148 			Assert.AreEqual (3, tv.DataBindings.Count, "BeforeRemove1");
149 			Assert.AreEqual ("second", tv.DataBindings[1].DataMember, "BeforeRemove2");
150 			tv.DataBindings.RemoveAt (1);
151 			Assert.AreEqual (2, tv.DataBindings.Count, "AfterRemove1");
152 			Assert.AreEqual ("third", tv.DataBindings[1].DataMember, "AfterRemove2");
153 		}
154 	}
155 }
156 
157 
158