[bcl] Remove the ValueAdd and InetAccess NUnit categories (#2212)
[mono.git] / mcs / class / System.DirectoryServices / Test / System.DirectoryServices / DirectoryServicesDirectoryEntryTest.cs
1 //\r
2 // DirectoryServicesDirectoryEntryTest.cs -\r
3 //      NUnit Test Cases for DirectoryServices.DirectoryEntry\r
4 //\r
5 // Author:\r
6 //      Boris Kirzner  <borisk@mainsoft.com>\r
7 //\r
8 \r
9 using NUnit.Framework;\r
10 using System;\r
11 using System.DirectoryServices;\r
12 \r
13 namespace MonoTests.System.DirectoryServices \r
14 {\r
15         [TestFixture]\r
16         public class DirectoryServicesDirectoryEntryTest\r
17         {\r
18                 #region Fields\r
19 \r
20                 static TestConfiguration configuration;\r
21                 static DirectoryEntry de;\r
22 \r
23                 #endregion // Fields\r
24 \r
25                 #region SetUp and TearDown\r
26 \r
27                 [TestFixtureSetUp]\r
28                 public void TestFixtureSetUp()\r
29                 {\r
30                         de = null;\r
31                         configuration = new TestConfiguration ();\r
32 \r
33                         if (String.IsNullOrEmpty (configuration.ConnectionString))\r
34                                 Assert.Ignore ("No configuration");\r
35                 }\r
36 \r
37 \r
38                 [TestFixtureTearDown]\r
39                 public void TestFixtureTearDown()\r
40                 {\r
41                         if (de != null)\r
42                                 de.Dispose ();\r
43                         de = null;\r
44                 }\r
45 \r
46 \r
47                 [SetUp]\r
48                 public void SetUp()\r
49                 {\r
50                         TearDown();\r
51 \r
52                         #region Initialize basics\r
53 \r
54                         DirectoryEntry root = new DirectoryEntry(       configuration.ConnectionString,\r
55                                                                                                                 configuration.Username,\r
56                                                                                                                 configuration.Password,\r
57                                                                                                                 configuration.AuthenticationType);\r
58                         DirectoryEntry ouPeople = root.Children.Add("ou=people","Class");\r
59                         ouPeople.Properties["objectClass"].Value = "organizationalUnit";\r
60                         ouPeople.Properties["description"].Value = "All people in organisation";\r
61                         ouPeople.Properties["ou"].Value = "people";\r
62                         ouPeople.CommitChanges();\r
63 \r
64                         #endregion // Initialize basics\r
65 \r
66                         #region Human Resources\r
67  \r
68                         DirectoryEntry ouHumanResources = ouPeople.Children.Add("ou=Human Resources","Class");\r
69                         ouHumanResources.Properties["objectClass"].Value = "organizationalUnit";\r
70                         ouHumanResources.Properties["ou"].Value = "Human Resources";\r
71                         ouHumanResources.CommitChanges();\r
72 \r
73                         DirectoryEntry cnJohnSmith = ouHumanResources.Children.Add("cn=John Smith","Class");\r
74                         cnJohnSmith.Properties["objectClass"].Value = "organizationalRole";\r
75                         cnJohnSmith.Properties["cn"].Value = "John Smith";\r
76                         cnJohnSmith.Properties["description"].Value = "Very clever person";\r
77                         cnJohnSmith.Properties["ou"].Value = "Human Resources";\r
78                         cnJohnSmith.Properties["telephoneNumber"].Value = "1 801 555 1212";\r
79                         cnJohnSmith.CommitChanges();\r
80 \r
81                         DirectoryEntry cnBarakTsabari = ouHumanResources.Children.Add("cn=Barak Tsabari","Class");\r
82                         ((PropertyValueCollection)cnBarakTsabari.Properties["objectClass"]).Add("person");\r
83                         ((PropertyValueCollection)cnBarakTsabari.Properties["objectClass"]).Add("organizationalPerson");\r
84                         cnBarakTsabari.Properties["cn"].Value = "Barak Tsabari";\r
85                         cnBarakTsabari.Properties["facsimileTelephoneNumber"].Value = "+1 906 777 8853";\r
86                         ((PropertyValueCollection)cnBarakTsabari.Properties["ou"]).Add("Human Resources");\r
87                         ((PropertyValueCollection)cnBarakTsabari.Properties["ou"]).Add("People");\r
88                         cnBarakTsabari.Properties["sn"].Value = "Tsabari";\r
89                         cnBarakTsabari.Properties["telephoneNumber"].Value = "+1 906 777 8854";\r
90                         cnBarakTsabari.CommitChanges();\r
91 \r
92                         #endregion // Human Resources\r
93 \r
94                         #region R&D\r
95 \r
96                         DirectoryEntry ouRnD = ouPeople.Children.Add("ou=R&D","Class");\r
97                         ouRnD.Properties["objectClass"].Value = "organizationalUnit";\r
98                         ouRnD.Properties["ou"].Value = "R&D";\r
99                         ouRnD.CommitChanges();\r
100 \r
101                         DirectoryEntry cnYossiCohen = ouRnD.Children.Add("cn=Yossi Cohen","Class");\r
102                         ((PropertyValueCollection)cnYossiCohen.Properties["objectClass"]).Add("person");\r
103                         ((PropertyValueCollection)cnYossiCohen.Properties["objectClass"]).Add("organizationalPerson");\r
104                         cnYossiCohen.Properties["cn"].Value = "Yossi Cohen";\r
105                         cnYossiCohen.Properties["facsimileTelephoneNumber"].Value = "+1 503 777 4498";\r
106                         ((PropertyValueCollection)cnYossiCohen.Properties["ou"]).Add("R&D");\r
107                         ((PropertyValueCollection)cnYossiCohen.Properties["ou"]).Add("People");\r
108                         cnYossiCohen.Properties["sn"].Value = "Cohen";\r
109                         cnYossiCohen.Properties["telephoneNumber"].Value = "+1 503 777 4499";\r
110                         cnYossiCohen.CommitChanges();\r
111 \r
112                         DirectoryEntry cnUziCohen = ouRnD.Children.Add("cn=Uzi Cohen","Class");\r
113                         ((PropertyValueCollection)cnUziCohen.Properties["objectClass"]).Add("person");\r
114                         ((PropertyValueCollection)cnUziCohen.Properties["objectClass"]).Add("organizationalPerson");\r
115                         cnUziCohen.Properties["cn"].Value = "Uzi Cohen";\r
116                         cnUziCohen.Properties["facsimileTelephoneNumber"].Value = "+1 602 333 1234";\r
117                         ((PropertyValueCollection)cnUziCohen.Properties["ou"]).Add("R&D");\r
118                         ((PropertyValueCollection)cnUziCohen.Properties["ou"]).Add("People");\r
119                         cnUziCohen.Properties["sn"].Value = "Cohen";\r
120                         cnUziCohen.Properties["telephoneNumber"].Value = "+1 602 333 1233";\r
121                         cnUziCohen.CommitChanges();\r
122 \r
123                         DirectoryEntry cnDanielCohen = ouRnD.Children.Add("cn=Daniel Cohen","Class");\r
124                         ((PropertyValueCollection)cnDanielCohen.Properties["objectClass"]).Add("person");\r
125                         ((PropertyValueCollection)cnDanielCohen.Properties["objectClass"]).Add("organizationalPerson");\r
126                         cnDanielCohen.Properties["cn"].Value = "Daniel Cohen";\r
127                         cnDanielCohen.Properties["facsimileTelephoneNumber"].Value = "+1 602 333 1235";\r
128                         ((PropertyValueCollection)cnDanielCohen.Properties["ou"]).Add("R&D");\r
129                         ((PropertyValueCollection)cnDanielCohen.Properties["ou"]).Add("People");\r
130                         cnDanielCohen.Properties["sn"].Value = "Cohen";\r
131                         cnDanielCohen.Properties["telephoneNumber"].Value = "+1 602 333 1236";\r
132                         cnDanielCohen.CommitChanges();\r
133 \r
134                         DirectoryEntry cnSaraCohen = ouRnD.Children.Add("cn=Sara Cohen","Class");\r
135                         ((PropertyValueCollection)cnSaraCohen.Properties["objectClass"]).Add("person");\r
136                         ((PropertyValueCollection)cnSaraCohen.Properties["objectClass"]).Add("organizationalPerson");\r
137                         cnSaraCohen.Properties["cn"].Value = "Sara Cohen";\r
138                         cnSaraCohen.Properties["facsimileTelephoneNumber"].Value = "+1 602 333 1244";\r
139                         ((PropertyValueCollection)cnSaraCohen.Properties["ou"]).Add("R&D");\r
140                         ((PropertyValueCollection)cnSaraCohen.Properties["ou"]).Add("People");\r
141                         cnSaraCohen.Properties["sn"].Value = "Cohen";\r
142                         cnSaraCohen.Properties["telephoneNumber"].Value = "+1 602 333 1243";\r
143                         cnSaraCohen.CommitChanges();\r
144 \r
145                         #endregion // R&D\r
146 \r
147                         #region DevQA\r
148 \r
149                         DirectoryEntry ouDevQA = ouPeople.Children.Add("ou=DevQA","Class");\r
150                         ouDevQA.Properties["objectClass"].Value = "organizationalUnit";\r
151                         ouDevQA.Properties["ou"].Value = "DevQA";\r
152                         ouDevQA.CommitChanges();\r
153 \r
154                         DirectoryEntry cnDanielSmith = ouDevQA.Children.Add("cn=Daniel Smith","Class");\r
155                         ((PropertyValueCollection)cnDanielSmith.Properties["objectClass"]).Add("person");\r
156                         ((PropertyValueCollection)cnDanielSmith.Properties["objectClass"]).Add("organizationalPerson");\r
157                         cnDanielSmith.Properties["cn"].Value = "Daniel Smith";\r
158                         cnDanielSmith.Properties["facsimileTelephoneNumber"].Value = "+1 408 555 3372";\r
159                         cnDanielSmith.Properties["l"].Value = "Santa Clara";\r
160                         ((PropertyValueCollection)cnDanielSmith.Properties["ou"]).Add("DevQA");\r
161                         ((PropertyValueCollection)cnDanielSmith.Properties["ou"]).Add("People");\r
162                         cnDanielSmith.Properties["sn"].Value = "Smith";\r
163                         cnDanielSmith.Properties["telephoneNumber"].Value = "+1 408 555 9519";\r
164                         cnDanielSmith.CommitChanges();\r
165 \r
166                         DirectoryEntry cnDanielMorgan = ouDevQA.Children.Add("cn=Daniel Morgan","Class");\r
167                         ((PropertyValueCollection)cnDanielMorgan.Properties["objectClass"]).Add("person");\r
168                         ((PropertyValueCollection)cnDanielMorgan.Properties["objectClass"]).Add("organizationalPerson");\r
169                         cnDanielMorgan.Properties["cn"].Value = "Daniel Morgan";\r
170                         cnDanielMorgan.Properties["facsimileTelephoneNumber"].Value = "+1 805 666 5645";\r
171                         ((PropertyValueCollection)cnDanielMorgan.Properties["ou"]).Add("DevQA");\r
172                         ((PropertyValueCollection)cnDanielMorgan.Properties["ou"]).Add("People");\r
173                         cnDanielMorgan.Properties["sn"].Value = "Morgan";\r
174                         cnDanielMorgan.Properties["telephoneNumber"].Value = "+1 805 666 5644";\r
175                         cnDanielMorgan.CommitChanges();\r
176 \r
177                         #endregion // DevQA\r
178 \r
179                         #region Manager\r
180 \r
181                         DirectoryEntry cnManager = root.Children.Add("cn=Manager","Class");\r
182                         cnManager.Properties["objectClass"].Value = "organizationalRole";\r
183                         cnManager.Properties["cn"].Value = "Manager";\r
184                         cnManager.Properties["facsimileTelephoneNumber"].Value = "+1 602 333 1238";\r
185                         cnManager.CommitChanges();\r
186 \r
187                         DirectoryEntry cnUziCohen_ = cnManager.Children.Add("cn=Uzi Cohen","Class");\r
188                         ((PropertyValueCollection)cnUziCohen_.Properties["objectClass"]).Add("person");\r
189                         ((PropertyValueCollection)cnUziCohen_.Properties["objectClass"]).Add("organizationalPerson");\r
190                         cnUziCohen_.Properties["cn"].Value = "Uzi Cohen";\r
191                         cnUziCohen_.Properties["facsimileTelephoneNumber"].Value = "+1 602 333 1234";\r
192                         ((PropertyValueCollection)cnUziCohen_.Properties["ou"]).Add("R&D");\r
193                         ((PropertyValueCollection)cnUziCohen_.Properties["ou"]).Add("People");\r
194                         cnUziCohen_.Properties["sn"].Value = "Cohen";\r
195                         cnUziCohen_.Properties["telephoneNumber"].Value = "+1 602 333 1233";\r
196                         cnUziCohen_.CommitChanges();\r
197 \r
198                         #endregion // Manager\r
199                                                 \r
200                         cnJohnSmith.Dispose();\r
201                         cnBarakTsabari.Dispose();\r
202                         ouHumanResources.Dispose();\r
203                         cnUziCohen.Dispose();\r
204                         cnYossiCohen.Dispose();\r
205                         cnDanielCohen.Dispose();\r
206                         cnSaraCohen.Dispose();\r
207                         ouRnD.Dispose();\r
208                         cnDanielSmith.Dispose();\r
209                         cnDanielMorgan.Dispose();\r
210                         ouDevQA.Dispose();\r
211                         cnUziCohen_.Dispose();\r
212                         cnManager.Dispose();\r
213                         ouPeople.Dispose();\r
214                         root.Dispose();\r
215                 }\r
216 \r
217 \r
218                 [TearDown]\r
219                 public void TearDown()\r
220                 {\r
221                         if (de != null)\r
222                                 de.Dispose ();\r
223 \r
224                         de = null;\r
225 \r
226                         using (DirectoryEntry root = new DirectoryEntry(        configuration.ConnectionString,\r
227                                                                                                                 configuration.Username,\r
228                                                                                                                 configuration.Password,\r
229                                                                                                                 configuration.AuthenticationType)) {\r
230                         \r
231                         foreach(DirectoryEntry child in root.Children) {\r
232                                 DeleteTree_DFS(child);\r
233                         }\r
234                         }\r
235                 }\r
236 \r
237                 private void DeleteTree_DFS(DirectoryEntry de)\r
238                 {\r
239                         foreach(DirectoryEntry child in de.Children) {\r
240                                 DeleteTree_DFS(child);\r
241                         }\r
242                         de.DeleteTree();\r
243                         de.CommitChanges();\r
244                 }\r
245 \r
246                 #endregion //SetUp and TearDown\r
247 \r
248                 #region Tests\r
249 \r
250                 [Test]\r
251                 public void DirectoryEntry_DirectoryEntry()\r
252                 {\r
253                         de = new DirectoryEntry();\r
254 \r
255                         Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.None);\r
256                         Assert.AreEqual(de.Path,String.Empty);\r
257                         Assert.AreEqual(de.UsePropertyCache,true);\r
258                         Assert.AreEqual(de.Username,null);              \r
259                 }\r
260 \r
261 \r
262                 [Test]\r
263                 public void DirectoryEntry_DirectoryEntry_Str()\r
264                 {\r
265                         using (DirectoryEntry de = new DirectoryEntry(configuration.ConnectionString)) {\r
266                         \r
267                         Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.None);\r
268                         Assert.AreEqual(de.Name,GetName (configuration.BaseDn));\r
269                         Assert.AreEqual(de.Path,configuration.ConnectionString);\r
270                         Assert.AreEqual(de.SchemaClassName,"organization");\r
271                         Assert.AreEqual(de.UsePropertyCache,true);\r
272                         Assert.AreEqual(de.Username,null);\r
273                         }\r
274                 }\r
275 \r
276 \r
277                 [Test]\r
278                 public void DirectoryEntry_DirectoryEntry_StrStrStrAuth()\r
279                 {\r
280                         if ((configuration.AuthenticationType != AuthenticationTypes.ServerBind) && \r
281                                 (configuration.AuthenticationType != AuthenticationTypes.None) && \r
282                                 (configuration.AuthenticationType != AuthenticationTypes.Anonymous))\r
283                                 return;\r
284 \r
285                         #region AuthenticationTypes.Anonymous\r
286 \r
287                         using (DirectoryEntry de = new DirectoryEntry(  configuration.ConnectionString,\r
288                                                                                                         configuration.Username,\r
289                                                                                                         configuration.Password,\r
290                                                                                                         AuthenticationTypes.Anonymous)){\r
291                         \r
292                         Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Anonymous);\r
293                         //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));\r
294                         Assert.AreEqual(de.Name,GetName (configuration.BaseDn));\r
295                         //Assert.AreEqual(de.NativeGuid,null);\r
296                         Assert.AreEqual(de.Path,configuration.ConnectionString);\r
297                         Assert.AreEqual(de.SchemaClassName,"organization");\r
298                         Assert.AreEqual(de.UsePropertyCache,true);\r
299                         Assert.AreEqual(de.Username,configuration.Username);\r
300                         }\r
301 \r
302                         #endregion //AuthenticationTypes.Anonymous\r
303 \r
304                         #region AuthenticationTypes.Delegation\r
305 \r
306                         using (DirectoryEntry de = new DirectoryEntry(configuration.ConnectionString,\r
307                                                                         configuration.Username,\r
308                                                                         configuration.Password,\r
309                                                                         AuthenticationTypes.Delegation)){\r
310                         \r
311                         Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Delegation);\r
312                         //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));\r
313                         Assert.AreEqual(de.Name,GetName (configuration.BaseDn));\r
314                         //Assert.AreEqual(de.NativeGuid,null);\r
315                         Assert.AreEqual(de.Path,configuration.ConnectionString);\r
316                         Assert.AreEqual(de.SchemaClassName,"organization");\r
317                         Assert.AreEqual(de.UsePropertyCache,true);\r
318                         Assert.AreEqual(de.Username,configuration.Username);\r
319                         }\r
320 \r
321                         #endregion //AuthenticationTypes.Delegation\r
322 \r
323                         #region AuthenticationTypes.Encryption\r
324 \r
325                         //                      de = new DirectoryEntry(        configuration.ConnectionString,\r
326                         //                                                                                                      configuration.Username,\r
327                         //                                                                                                      configuration.Password,\r
328                         //                                                                                                      AuthenticationTypes.Encryption);\r
329                         //                      \r
330                         //                      Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Encryption);\r
331                         //                      //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));\r
332                         //                      Assert.AreEqual(de.Name,"dc=myhosting");\r
333                         //                      //Assert.AreEqual(de.NativeGuid,null);\r
334                         //                      Assert.AreEqual(de.Password,configuration.Password);\r
335                         //                      Assert.AreEqual(de.Path,configuration.ConnectionString);\r
336                         //                      Assert.AreEqual(de.SchemaClassName,"organization");\r
337                         //                      Assert.AreEqual(de.UsePropertyCache,true);\r
338                         //                      Assert.AreEqual(de.Username,configuration.Username);\r
339 \r
340                         #endregion //AuthenticationTypes.Encryption\r
341 \r
342                         #region AuthenticationTypes.FastBind\r
343 \r
344                         using (DirectoryEntry de = new DirectoryEntry(configuration.ConnectionString,\r
345                                                                         configuration.Username,\r
346                                                                         configuration.Password,\r
347                                                                         AuthenticationTypes.FastBind)){\r
348                         \r
349                         Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.FastBind);\r
350                         //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));\r
351                         Assert.AreEqual(de.Name,GetName (configuration.BaseDn));\r
352                         //Assert.AreEqual(de.NativeGuid,null);\r
353                         Assert.AreEqual(de.Path,configuration.ConnectionString);\r
354                         Assert.AreEqual(de.SchemaClassName,"organization");\r
355                         Assert.AreEqual(de.UsePropertyCache,true);\r
356                         Assert.AreEqual(de.Username,configuration.Username);\r
357                         }\r
358 \r
359                         #endregion //AuthenticationTypes.FastBind\r
360 \r
361                         #region AuthenticationTypes.None\r
362 \r
363                         using (DirectoryEntry de = new DirectoryEntry(configuration.ConnectionString,\r
364                                                                         configuration.Username,\r
365                                                                         configuration.Password,\r
366                                                                         AuthenticationTypes.None)){\r
367                         \r
368                         Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.None);\r
369                         //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));\r
370                         Assert.AreEqual(de.Name,GetName (configuration.BaseDn));\r
371                         //Assert.AreEqual(de.NativeGuid,null);\r
372                         Assert.AreEqual(de.Path,configuration.ConnectionString);\r
373                         Assert.AreEqual(de.SchemaClassName,"organization");\r
374                         Assert.AreEqual(de.UsePropertyCache,true);\r
375                         Assert.AreEqual(de.Username,configuration.Username);\r
376                         }\r
377 \r
378                         #endregion //AuthenticationTypes.None\r
379 \r
380                         #region AuthenticationTypes.ReadonlyServer\r
381 \r
382                         using (DirectoryEntry de = new DirectoryEntry(configuration.ConnectionString,\r
383                                                                         configuration.Username,\r
384                                                                         configuration.Password,\r
385                                                                         AuthenticationTypes.ReadonlyServer)){\r
386                         \r
387                         Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.ReadonlyServer);\r
388                         //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));\r
389                         Assert.AreEqual(de.Name,GetName (configuration.BaseDn));\r
390                         //Assert.AreEqual(de.NativeGuid,null);\r
391                         Assert.AreEqual(de.Path,configuration.ConnectionString);\r
392                         Assert.AreEqual(de.SchemaClassName,"organization");\r
393                         Assert.AreEqual(de.UsePropertyCache,true);\r
394                         Assert.AreEqual(de.Username,configuration.Username);\r
395                         }\r
396 \r
397                         #endregion //AuthenticationTypes.ReadonlyServer\r
398 \r
399                         #region AuthenticationTypes.Sealing\r
400 \r
401                         using (DirectoryEntry de = new DirectoryEntry(configuration.ConnectionString,\r
402                                                                         configuration.Username,\r
403                                                                         configuration.Password,\r
404                                                                         AuthenticationTypes.Sealing)){\r
405                         \r
406                         Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Sealing);\r
407                         //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));\r
408                         Assert.AreEqual(de.Name,GetName (configuration.BaseDn));\r
409                         //Assert.AreEqual(de.NativeGuid,null);\r
410                         Assert.AreEqual(de.Path,configuration.ConnectionString);\r
411                         Assert.AreEqual(de.SchemaClassName,"organization");\r
412                         Assert.AreEqual(de.UsePropertyCache,true);\r
413                         Assert.AreEqual(de.Username,configuration.Username);\r
414                         }\r
415 \r
416                         #endregion //AuthenticationTypes.Sealing\r
417 \r
418                         #region AuthenticationTypes.Secure\r
419 \r
420                         //                      de = new DirectoryEntry(configuration.ConnectionString,\r
421                         //                                                                      configuration.Username,\r
422                         //                                                                      configuration.Password,\r
423                         //                                                                      AuthenticationTypes.Secure);\r
424                         //                      \r
425                         //                      Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Secure);\r
426                         //                      //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));\r
427                         //                      Assert.AreEqual(de.Name,"dc=myhosting");\r
428                         //                      //Assert.AreEqual(de.NativeGuid,null);\r
429                         //                      Assert.AreEqual(de.Password,configuration.Password);\r
430                         //                      Assert.AreEqual(de.Path,configuration.ConnectionString);\r
431                         //                      Assert.AreEqual(de.SchemaClassName,"organization");\r
432                         //                      Assert.AreEqual(de.UsePropertyCache,true);\r
433                         //                      Assert.AreEqual(de.Username,configuration.Username);\r
434 \r
435                         #endregion //AuthenticationTypes.Secure\r
436 \r
437                         #region AuthenticationTypes.SecureSocketsLayer\r
438 \r
439                         //                      de = new DirectoryEntry(configuration.ConnectionString,\r
440                         //                                                                      configuration.Username,\r
441                         //                                                                      configuration.Password,\r
442                         //                                                                      AuthenticationTypes.SecureSocketsLayer);\r
443                         //                      \r
444                         //                      Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.SecureSocketsLayer);\r
445                         //                      //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));\r
446                         //                      Assert.AreEqual(de.Name,"dc=myhosting");\r
447                         //                      //Assert.AreEqual(de.NativeGuid,null);\r
448                         //                      Assert.AreEqual(de.Password,configuration.Password);\r
449                         //                      Assert.AreEqual(de.Path,configuration.ConnectionString);\r
450                         //                      Assert.AreEqual(de.SchemaClassName,"organization");\r
451                         //                      Assert.AreEqual(de.UsePropertyCache,true);\r
452                         //                      Assert.AreEqual(de.Username,configuration.Username);\r
453 \r
454                         #endregion //AuthenticationTypes.SecureSocketsLayer\r
455 \r
456                         #region AuthenticationTypes.ServerBind\r
457 \r
458                         using (DirectoryEntry de = new DirectoryEntry(configuration.ConnectionString,\r
459                                                                         configuration.Username,\r
460                                                                         configuration.Password,\r
461                                                                         AuthenticationTypes.ServerBind)){\r
462                         \r
463                         Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.ServerBind);\r
464                         //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));\r
465                         Assert.AreEqual(de.Name,GetName (configuration.BaseDn));\r
466                         //Assert.AreEqual(de.NativeGuid,null);\r
467                         Assert.AreEqual(de.Path,configuration.ConnectionString);\r
468                         Assert.AreEqual(de.SchemaClassName,"organization");\r
469                         Assert.AreEqual(de.UsePropertyCache,true);\r
470                         Assert.AreEqual(de.Username,configuration.Username);\r
471                         }\r
472 \r
473                         #endregion //AuthenticationTypes.ServerBind\r
474 \r
475                         #region AuthenticationTypes.Signing\r
476 \r
477                         using (DirectoryEntry de = new DirectoryEntry(configuration.ConnectionString,\r
478                                                                         configuration.Username,\r
479                                                                         configuration.Password,\r
480                                                                         AuthenticationTypes.Signing)){\r
481                         \r
482                         Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Signing);\r
483                         //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));\r
484                         Assert.AreEqual(de.Name,GetName (configuration.BaseDn));\r
485                         //Assert.AreEqual(de.NativeGuid,null);\r
486                         Assert.AreEqual(de.Path,configuration.ConnectionString);\r
487                         Assert.AreEqual(de.SchemaClassName,"organization");\r
488                         Assert.AreEqual(de.UsePropertyCache,true);\r
489                         Assert.AreEqual(de.Username,configuration.Username);\r
490                         }\r
491 \r
492                         #endregion //AuthenticationTypes.Signing\r
493                 }\r
494 \r
495                 [Test]\r
496                 public void DirectoryEntry_Dispose()\r
497                 {\r
498                         using (DirectoryEntry root = new DirectoryEntry(        configuration.ConnectionString,\r
499                                                                                                                 configuration.Username,\r
500                                                                                                                 configuration.Password,\r
501                                                                                                                 configuration.AuthenticationType)){\r
502 \r
503                         DirectoryEntry ouPeople = root.Children.Add("ou=printers","Class");\r
504                         ouPeople.Properties["objectClass"].Value = "organizationalUnit";\r
505                         ouPeople.Properties["description"].Value = "All printers in organisation";\r
506                         ouPeople.Properties["ou"].Value = "printers";\r
507                         ouPeople.CommitChanges();\r
508 \r
509                         ouPeople.Rename("ou=anotherPrinters");\r
510                         ouPeople.CommitChanges();\r
511 \r
512                         Assert.IsTrue(DirectoryEntry.Exists(configuration.ServerRoot + "ou=anotherPrinters" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn))));\r
513                         }\r
514                 }\r
515 \r
516 \r
517                 [Test]\r
518                 public void DirectoryEntry_AuthenticationType()\r
519                 {\r
520                         de = new DirectoryEntry();\r
521 \r
522                         de.AuthenticationType = AuthenticationTypes.Anonymous;\r
523                         Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Anonymous);\r
524 \r
525                         de.AuthenticationType = AuthenticationTypes.Delegation;\r
526                         Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Delegation);\r
527 \r
528                         de.AuthenticationType = AuthenticationTypes.Encryption;\r
529                         Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Encryption);\r
530 \r
531                         de.AuthenticationType = AuthenticationTypes.FastBind;\r
532                         Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.FastBind);\r
533 \r
534                         de.AuthenticationType = AuthenticationTypes.None;\r
535                         Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.None);\r
536 \r
537                         de.AuthenticationType = AuthenticationTypes.ReadonlyServer;\r
538                         Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.ReadonlyServer);\r
539 \r
540                         de.AuthenticationType = AuthenticationTypes.Sealing;\r
541                         Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Sealing);\r
542 \r
543                         de.AuthenticationType = AuthenticationTypes.Secure;\r
544                         Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Secure);\r
545 \r
546                         de.AuthenticationType = AuthenticationTypes.SecureSocketsLayer;\r
547                         Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.SecureSocketsLayer);\r
548 \r
549                         de.AuthenticationType = AuthenticationTypes.ServerBind;\r
550                         Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.ServerBind);\r
551 \r
552                         de.AuthenticationType = AuthenticationTypes.Signing;\r
553                         Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Signing);\r
554 \r
555                         de = new DirectoryEntry(configuration.ConnectionString);\r
556 \r
557                         de.AuthenticationType = AuthenticationTypes.Anonymous;\r
558                         Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Anonymous);\r
559 \r
560                         de.AuthenticationType = AuthenticationTypes.Delegation;\r
561                         Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Delegation);\r
562 \r
563                         de.AuthenticationType = AuthenticationTypes.Encryption;\r
564                         Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Encryption);\r
565 \r
566                         de.AuthenticationType = AuthenticationTypes.FastBind;\r
567                         Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.FastBind);\r
568 \r
569                         de.AuthenticationType = AuthenticationTypes.None;\r
570                         Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.None);\r
571 \r
572                         de.AuthenticationType = AuthenticationTypes.ReadonlyServer;\r
573                         Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.ReadonlyServer);\r
574 \r
575                         de.AuthenticationType = AuthenticationTypes.Sealing;\r
576                         Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Sealing);\r
577 \r
578                         de.AuthenticationType = AuthenticationTypes.Secure;\r
579                         Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Secure);\r
580 \r
581                         de.AuthenticationType = AuthenticationTypes.SecureSocketsLayer;\r
582                         Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.SecureSocketsLayer);\r
583 \r
584                         de.AuthenticationType = AuthenticationTypes.ServerBind;\r
585                         Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.ServerBind);\r
586 \r
587                         de.AuthenticationType = AuthenticationTypes.Signing;\r
588                         Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Signing);\r
589 \r
590                         de = new DirectoryEntry(configuration.ConnectionString,\r
591                                                                         configuration.Username,\r
592                                                                         configuration.Password,\r
593                                                                         AuthenticationTypes.None);\r
594 \r
595                         de.AuthenticationType = AuthenticationTypes.Anonymous;\r
596                         Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Anonymous);\r
597 \r
598                         de.AuthenticationType = AuthenticationTypes.Delegation;\r
599                         Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Delegation);\r
600 \r
601                         de.AuthenticationType = AuthenticationTypes.Encryption;\r
602                         Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Encryption);\r
603 \r
604                         de.AuthenticationType = AuthenticationTypes.FastBind;\r
605                         Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.FastBind);\r
606 \r
607                         de.AuthenticationType = AuthenticationTypes.None;\r
608                         Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.None);\r
609 \r
610                         de.AuthenticationType = AuthenticationTypes.ReadonlyServer;\r
611                         Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.ReadonlyServer);\r
612 \r
613                         de.AuthenticationType = AuthenticationTypes.Sealing;\r
614                         Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Sealing);\r
615 \r
616                         de.AuthenticationType = AuthenticationTypes.Secure;\r
617                         Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Secure);\r
618 \r
619                         de.AuthenticationType = AuthenticationTypes.SecureSocketsLayer;\r
620                         Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.SecureSocketsLayer);\r
621 \r
622                         de.AuthenticationType = AuthenticationTypes.ServerBind;\r
623                         Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.ServerBind);\r
624 \r
625                         de.AuthenticationType = AuthenticationTypes.Signing;\r
626                         Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Signing);\r
627                 }\r
628 \r
629                 \r
630                 [Test]\r
631                 public void DirectoryEntry_UsePropertyCache()\r
632                 {\r
633                         string barakTsabariDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));\r
634                         de = new DirectoryEntry(barakTsabariDN,\r
635                                                                         configuration.Username,\r
636                                                                         configuration.Password,\r
637                                                                         configuration.AuthenticationType);\r
638 \r
639                         // UsePropertyCache = true\r
640                         de.UsePropertyCache = true;\r
641                         Assert.AreEqual(de.UsePropertyCache,true);\r
642 \r
643                         #region Check Properties\r
644 \r
645                         // Properties changes are cached\r
646                         string oldTelephoneNumber = (string)de.Properties["telephoneNumber"].Value;\r
647                         string newTelephoneNumber = "+972-3-6572345";\r
648 \r
649                         de.Properties["telephoneNumber"].Value = newTelephoneNumber;\r
650                         using (DirectoryEntry barakTsabariDE = new DirectoryEntry(      barakTsabariDN,\r
651                                                                                                                                 configuration.Username,\r
652                                                                                                                                 configuration.Password,\r
653                                                                                                                                 configuration.AuthenticationType)){\r
654 \r
655                         Assert.AreEqual(barakTsabariDE.Properties["telephoneNumber"].Value,oldTelephoneNumber);\r
656                         de.CommitChanges();\r
657                         }\r
658                         using (DirectoryEntry barakTsabariDE = new DirectoryEntry(barakTsabariDN,\r
659                                                                                                 configuration.Username,\r
660                                                                                                 configuration.Password,\r
661                                                                                                 configuration.AuthenticationType)){\r
662                         Assert.AreEqual(barakTsabariDE.Properties["telephoneNumber"].Value,newTelephoneNumber);\r
663 \r
664                         // restore object state\r
665                         de.Properties["telephoneNumber"].Value = oldTelephoneNumber;\r
666                         de.CommitChanges();\r
667                         }\r
668 \r
669                         #endregion // Check Properties\r
670 \r
671                         #region Check DeleteTree\r
672 \r
673                         // DeleteTree is not cached\r
674                         de.DeleteTree();\r
675                         try {\r
676                                 using (DirectoryEntry barakTsabariDE = new DirectoryEntry(barakTsabariDN,\r
677                                                                                                         configuration.Username,\r
678                                                                                                         configuration.Password,\r
679                                                                                                         configuration.AuthenticationType)){\r
680                                 barakTsabariDE.Properties["telephoneNumber"].Value = newTelephoneNumber;\r
681                                 barakTsabariDE.CommitChanges();\r
682                                 Assert.Fail("Object " + barakTsabariDN + " was not deleted from server.");\r
683                                 }\r
684                         }\r
685                         catch(AssertionException ae) {\r
686                                 throw ae;\r
687                         }\r
688                         catch (Exception e) {\r
689                                 // do nothing\r
690                         }\r
691 \r
692                         // restore object state\r
693                         using (DirectoryEntry ouHumanResources = new DirectoryEntry(    configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),\r
694                                                                                                                                         configuration.Username,\r
695                                                                                                                                         configuration.Password,\r
696                                                                                                                                         configuration.AuthenticationType)){\r
697                         using (DirectoryEntry cnBarakTsabari = ouHumanResources.Children.Add("cn=Barak Tsabari","Class")){\r
698                         ((PropertyValueCollection)cnBarakTsabari.Properties["objectClass"]).Add("person");\r
699                         ((PropertyValueCollection)cnBarakTsabari.Properties["objectClass"]).Add("organizationalPerson");\r
700                         cnBarakTsabari.Properties["cn"].Value = "Barak Tsabari";\r
701                         cnBarakTsabari.Properties["facsimileTelephoneNumber"].Value = "+1 906 777 8853";\r
702                         ((PropertyValueCollection)cnBarakTsabari.Properties["ou"]).Add("Human Resources");\r
703                         ((PropertyValueCollection)cnBarakTsabari.Properties["ou"]).Add("People");\r
704                         cnBarakTsabari.Properties["sn"].Value = "Tsabari";\r
705                         cnBarakTsabari.Properties["telephoneNumber"].Value = "+1 906 777 8854";\r
706                         cnBarakTsabari.CommitChanges();\r
707                         }\r
708                         }\r
709 \r
710                         #endregion // Check DeleteTree\r
711 \r
712                         #region Check MoveTo\r
713 \r
714                         // Move to is not cached\r
715                         de = new DirectoryEntry(barakTsabariDN,\r
716                                                                         configuration.Username,\r
717                                                                         configuration.Password,\r
718                                                                         configuration.AuthenticationType);\r
719 \r
720                         using (DirectoryEntry ouRnD = new DirectoryEntry(       configuration.ServerRoot + "ou=R&D,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),\r
721                                                                                                                 configuration.Username,\r
722                                                                                                                 configuration.Password,\r
723                                                                                                                 configuration.AuthenticationType)){\r
724                         de.MoveTo(ouRnD);\r
725                         try {\r
726                                 using (DirectoryEntry barakTsabariDE = new DirectoryEntry(barakTsabariDN,\r
727                                                                                                         configuration.Username,\r
728                                                                                                         configuration.Password,\r
729                                                                                                         configuration.AuthenticationType)){\r
730                                 barakTsabariDE.Properties["telephoneNumber"].Value = newTelephoneNumber;\r
731                                 barakTsabariDE.CommitChanges();\r
732                                 Assert.Fail("Object " + barakTsabariDN + " was not moved from old location on the server.");\r
733                                 }\r
734                         }\r
735                         catch(AssertionException ae) {\r
736                                 throw ae;\r
737                         }\r
738                         catch (Exception e) {\r
739                                 // do nothing\r
740                         }\r
741                         }\r
742 \r
743                         using (DirectoryEntry barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=Barak Tsabari,ou=R&D,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),\r
744                                                                                                 configuration.Username,\r
745                                                                                                 configuration.Password,\r
746                                                                                                 configuration.AuthenticationType)){\r
747                         Assert.AreEqual(barakTsabariDE.Properties["telephoneNumber"].Value,oldTelephoneNumber);\r
748                         }\r
749                         \r
750 \r
751                         // restore object state\r
752                         using (DirectoryEntry ouHumanResources = new DirectoryEntry(    configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),\r
753                                                                                                                                         configuration.Username,\r
754                                                                                                                                         configuration.Password,\r
755                                                                                                                                         configuration.AuthenticationType)){\r
756                         using (DirectoryEntry barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=Barak Tsabari,ou=R&D,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),\r
757                                                                                                 configuration.Username,\r
758                                                                                                 configuration.Password,\r
759                                                                                                 configuration.AuthenticationType)){\r
760                         barakTsabariDE.MoveTo(ouHumanResources);\r
761                         barakTsabariDE.CommitChanges();\r
762                         }\r
763                         }\r
764 \r
765                         #endregion // Check MoveTo\r
766 \r
767                         #region Check Rename\r
768 \r
769                         // Rename not chached\r
770                         de = new DirectoryEntry(barakTsabariDN,\r
771                                                                         configuration.Username,\r
772                                                                         configuration.Password,\r
773                                                                         configuration.AuthenticationType);\r
774 \r
775                         de.Rename("cn=MyUser");\r
776 \r
777                         try {\r
778                                 using (DirectoryEntry barakTsabariDE = new DirectoryEntry(barakTsabariDN,\r
779                                                                                                         configuration.Username,\r
780                                                                                                         configuration.Password,\r
781                                                                                                         configuration.AuthenticationType)){\r
782                                 barakTsabariDE.Properties["telephoneNumber"].Value = newTelephoneNumber;\r
783                                 barakTsabariDE.CommitChanges();\r
784                                 Assert.Fail("Object " + barakTsabariDN + " was not renamed on the server.");\r
785                                 }\r
786                         }\r
787                         catch(AssertionException ae) {\r
788                                 throw ae;\r
789                         }\r
790                         catch (Exception e) {\r
791                                 // do nothing\r
792                         }\r
793 \r
794                         using (DirectoryEntry barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=MyUser,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),\r
795                                                                                                 configuration.Username,\r
796                                                                                                 configuration.Password,\r
797                                                                                                 configuration.AuthenticationType)){\r
798                         Assert.AreEqual(barakTsabariDE.Properties["telephoneNumber"].Value,oldTelephoneNumber);\r
799                         }\r
800 \r
801                         // restore object state\r
802                         using (DirectoryEntry barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=MyUser,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),\r
803                                                                                                 configuration.Username,\r
804                                                                                                 configuration.Password,\r
805                                                                                                 configuration.AuthenticationType)){\r
806                         barakTsabariDE.Rename("cn=Barak Tsabari");\r
807                         barakTsabariDE.CommitChanges();\r
808                         }\r
809 \r
810                         #endregion // Check Rename\r
811 \r
812                         // UsePropertyCache = false     \r
813                         de = new DirectoryEntry(barakTsabariDN,\r
814                                                                         configuration.Username,\r
815                                                                         configuration.Password,\r
816                                                                         configuration.AuthenticationType);\r
817                         de.UsePropertyCache = false;\r
818                         Assert.AreEqual(de.UsePropertyCache,false);\r
819 \r
820                         #region Check Properties\r
821 \r
822                         // Properties changes not cached\r
823                         de.Properties["telephoneNumber"].Value = newTelephoneNumber;\r
824                         using (DirectoryEntry barakTsabariDE = new DirectoryEntry(barakTsabariDN,\r
825                                                                                                 configuration.Username,\r
826                                                                                                 configuration.Password,\r
827                                                                                                 configuration.AuthenticationType)){\r
828                         }\r
829 \r
830                         //Assert.AreEqual(barakTsabariDE.Properties["telephoneNumber"].Value,newTelephoneNumber);\r
831 \r
832                         #endregion // Check Properties\r
833 \r
834                         #region Check DeleteTree\r
835 \r
836                         // DeleteTree is not cached\r
837                         de.DeleteTree();\r
838                         try {\r
839                                 using (DirectoryEntry barakTsabariDE = new DirectoryEntry(barakTsabariDN,\r
840                                                                                                         configuration.Username,\r
841                                                                                                         configuration.Password,\r
842                                                                                                         configuration.AuthenticationType)){\r
843                                 barakTsabariDE.Properties["telephoneNumber"].Value = newTelephoneNumber;\r
844                                 barakTsabariDE.CommitChanges();\r
845                                 Assert.Fail("Object " + barakTsabariDN + " was not deleted from server.");\r
846                                 }\r
847                         }\r
848                         catch(AssertionException ae) {\r
849                                 throw ae;\r
850                         }\r
851                         catch (Exception e) {\r
852                                 // do nothing\r
853                         }\r
854 \r
855                         // restore object state\r
856                         using (DirectoryEntry ouHumanResources = new DirectoryEntry(    configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),\r
857                                                                                                                                         configuration.Username,\r
858                                                                                                                                         configuration.Password,\r
859                                                                                                                                         configuration.AuthenticationType)){\r
860                         using (DirectoryEntry cnBarakTsabari = ouHumanResources.Children.Add("cn=Barak Tsabari","Class")){\r
861                         ((PropertyValueCollection)cnBarakTsabari.Properties["objectClass"]).Add("person");\r
862                         ((PropertyValueCollection)cnBarakTsabari.Properties["objectClass"]).Add("organizationalPerson");\r
863                         cnBarakTsabari.Properties["cn"].Value = "Barak Tsabari";\r
864                         cnBarakTsabari.Properties["facsimileTelephoneNumber"].Value = "+1 906 777 8853";\r
865                         ((PropertyValueCollection)cnBarakTsabari.Properties["ou"]).Add("Human Resources");\r
866                         ((PropertyValueCollection)cnBarakTsabari.Properties["ou"]).Add("People");\r
867                         cnBarakTsabari.Properties["sn"].Value = "Tsabari";\r
868                         cnBarakTsabari.Properties["telephoneNumber"].Value = "+1 906 777 8854";\r
869                         cnBarakTsabari.CommitChanges();\r
870                         }\r
871                         }\r
872 \r
873                         #endregion // Check DeleteTree\r
874 \r
875                         #region Check MoveTo\r
876 \r
877                         // Move to is not cached\r
878                         de = new DirectoryEntry(barakTsabariDN,\r
879                                                                         configuration.Username,\r
880                                                                         configuration.Password,\r
881                                                                         configuration.AuthenticationType);\r
882 \r
883                         using (DirectoryEntry ouRnD = new DirectoryEntry(       configuration.ServerRoot + "ou=R&D,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),\r
884                                                                                 configuration.Username,\r
885                                                                                 configuration.Password,\r
886                                                                                 configuration.AuthenticationType)){\r
887                         de.MoveTo(ouRnD);\r
888                         }\r
889                         try {\r
890                                 using (DirectoryEntry barakTsabariDE = new DirectoryEntry(barakTsabariDN,\r
891                                                                                                         configuration.Username,\r
892                                                                                                         configuration.Password,\r
893                                                                                                         configuration.AuthenticationType)){\r
894                                 barakTsabariDE.Properties["telephoneNumber"].Value = newTelephoneNumber;\r
895                                 barakTsabariDE.CommitChanges();\r
896                                 Assert.Fail("Object " + barakTsabariDN + " was not moved from old location on the server.");\r
897                                 }\r
898                         }\r
899                         catch(AssertionException ae) {\r
900                                 throw ae;\r
901                         }\r
902                         catch (Exception e) {\r
903                                 // do nothing\r
904                         }\r
905 \r
906 \r
907                         using (DirectoryEntry barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=Barak Tsabari,ou=R&D,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),\r
908                                                                                                 configuration.Username,\r
909                                                                                                 configuration.Password,\r
910                                                                                                 configuration.AuthenticationType)){\r
911                         Assert.AreEqual(barakTsabariDE.Properties["telephoneNumber"].Value,oldTelephoneNumber);\r
912                         }\r
913                         \r
914 \r
915                         // restore object state\r
916                         using (DirectoryEntry ouHumanResources = new DirectoryEntry(    configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),\r
917                                                                                                                                         configuration.Username,\r
918                                                                                                                                         configuration.Password,\r
919                                                                                                                                         configuration.AuthenticationType)){\r
920                         using (DirectoryEntry barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=Barak Tsabari,ou=R&D,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),\r
921                                                                                                 configuration.Username,\r
922                                                                                                 configuration.Password,\r
923                                                                                                 configuration.AuthenticationType)){\r
924                         barakTsabariDE.MoveTo(ouHumanResources);\r
925                         barakTsabariDE.CommitChanges();\r
926                         }\r
927                         }\r
928 \r
929                         #endregion // Check MoveTo\r
930 \r
931                         #region Check Rename\r
932 \r
933                         // Rename not chached\r
934                         de = new DirectoryEntry(barakTsabariDN,\r
935                                                                         configuration.Username,\r
936                                                                         configuration.Password,\r
937                                                                         configuration.AuthenticationType);\r
938 \r
939                         de.Rename("cn=MyUser");\r
940 \r
941                         try {\r
942                                 using (DirectoryEntry barakTsabariDE = new DirectoryEntry(barakTsabariDN,\r
943                                                                                                         configuration.Username,\r
944                                                                                                         configuration.Password,\r
945                                                                                                         configuration.AuthenticationType)){\r
946                                 barakTsabariDE.Properties["telephoneNumber"].Value = newTelephoneNumber;\r
947                                 barakTsabariDE.CommitChanges();\r
948                                 Assert.Fail("Object " + barakTsabariDN + " was not renamed on the server.");\r
949                                 }\r
950                         }\r
951                         catch(AssertionException ae) {\r
952                                 throw ae;\r
953                         }\r
954                         catch (Exception e) {\r
955                                 // do nothing\r
956                         }\r
957 \r
958                         using (DirectoryEntry barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=MyUser,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),\r
959                                                                                                 configuration.Username,\r
960                                                                                                 configuration.Password,\r
961                                                                                                 configuration.AuthenticationType)){\r
962                         Assert.AreEqual(barakTsabariDE.Properties["telephoneNumber"].Value,oldTelephoneNumber);\r
963                         }\r
964 \r
965                         // restore object state\r
966                         using (DirectoryEntry barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=MyUser,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),\r
967                                                                                                 configuration.Username,\r
968                                                                                                 configuration.Password,\r
969                                                                                                 configuration.AuthenticationType)){\r
970                         barakTsabariDE.Rename("cn=Barak Tsabari");\r
971                         barakTsabariDE.CommitChanges();\r
972                         }\r
973 \r
974                         #endregion // Check Rename\r
975                 }\r
976 \r
977                 [Test]\r
978                 [Category("NotWorking")]\r
979                 public void DirectoryEntry_Children()\r
980                 {\r
981                         de = new DirectoryEntry();\r
982                         DirectoryEntries children = de.Children;\r
983                         //Assert.AreEqual(children.SchemaFilter.Count,0);       \r
984 \r
985 \r
986                         de = new DirectoryEntry(configuration.ConnectionString);\r
987                         children = de.Children;\r
988 \r
989                         //Assert.AreEqual(children.SchemaFilter.Count,0);\r
990 \r
991                         int childrenCount = 0;\r
992                         foreach(DirectoryEntry childDe in children) {\r
993                                 childrenCount++;\r
994                         }\r
995                         Assert.AreEqual(childrenCount,2);\r
996                         Assert.AreEqual(children.Find("ou=people").Name,"ou=people");\r
997                         Assert.AreEqual(children.Find("cn=Manager").Name,"cn=Manager");\r
998 \r
999 \r
1000                         de = new DirectoryEntry(configuration.ConnectionString,\r
1001                                                                         configuration.Username,\r
1002                                                                         configuration.Password,\r
1003                                                                         configuration.AuthenticationType);\r
1004                         children = de.Children;\r
1005 \r
1006                         //Assert.AreEqual(children.SchemaFilter.Count,0);\r
1007 \r
1008                         childrenCount = 0;\r
1009                         foreach(DirectoryEntry childDe in children) {\r
1010                                 childrenCount++;\r
1011                         }\r
1012                         Assert.AreEqual(childrenCount,2);\r
1013                         Assert.AreEqual(children.Find("ou=people").Name,"ou=people");\r
1014                         Assert.AreEqual(children.Find("cn=Manager").Name,"cn=Manager");\r
1015 \r
1016                         de = new DirectoryEntry(configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)) ,\r
1017                                                                         configuration.Username,\r
1018                                                                         configuration.Password,\r
1019                                                                         configuration.AuthenticationType);\r
1020                         children = de.Children;\r
1021 \r
1022                         Assert.AreEqual(children.Find("cn=Barak Tsabari").Name,"cn=Barak Tsabari");\r
1023                         Assert.AreEqual(children.Find("cn=John Smith").Name,"cn=John Smith");\r
1024                 }\r
1025 \r
1026                 [Test]\r
1027                 public void DirectoryEntry_Name()\r
1028                 {\r
1029                         de = new DirectoryEntry(configuration.ConnectionString);\r
1030 \r
1031                         de = new DirectoryEntry(configuration.ConnectionString,\r
1032                                                                         configuration.Username,\r
1033                                                                         configuration.Password,\r
1034                                                                         configuration.AuthenticationType);\r
1035 \r
1036                         de = new DirectoryEntry(configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)) ,\r
1037                                                                         configuration.Username,\r
1038                                                                         configuration.Password,\r
1039                                                                         configuration.AuthenticationType);\r
1040                         Assert.AreEqual(de.Name,"ou=Human Resources");\r
1041 \r
1042                         de = new DirectoryEntry(configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)) ,\r
1043                                                                         configuration.Username,\r
1044                                                                         configuration.Password,\r
1045                                                                         configuration.AuthenticationType);\r
1046                         Assert.AreEqual(de.Name,"cn=Barak Tsabari");\r
1047                 }\r
1048                 \r
1049 \r
1050                 [Test]\r
1051                 public void DirectoryEntry_Parent()\r
1052                 {\r
1053                         de = new DirectoryEntry(configuration.ConnectionString);\r
1054 \r
1055                         // MS works only with "LDAP" while RFC2255 states "ldap"\r
1056                         Assert.AreEqual(de.Parent.Path.ToLower(),(configuration.ServerRoot + GetParentDN (configuration.BaseDn)).ToLower());\r
1057 \r
1058                         de = new DirectoryEntry(configuration.ConnectionString,\r
1059                                                                         configuration.Username,\r
1060                                                                         configuration.Password,\r
1061                                                                         configuration.AuthenticationType);\r
1062 \r
1063                         // MS works only with "LDAP" while RFC2255 states "ldap"\r
1064                         Assert.AreEqual(de.Parent.Path.ToLower(),(configuration.ServerRoot + GetParentDN (configuration.BaseDn)).ToLower());\r
1065 \r
1066                         de = new DirectoryEntry(configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)) ,\r
1067                                                                         configuration.Username,\r
1068                                                                         configuration.Password,\r
1069                                                                         configuration.AuthenticationType);\r
1070 \r
1071                         // MS works only with "LDAP" while RFC2255 states "ldap"\r
1072                         Assert.AreEqual(de.Parent.Path.ToLower(),(configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn))).ToLower());\r
1073                 }\r
1074 \r
1075 \r
1076                 [Test]\r
1077                 public void DirectoryEntry_Path()\r
1078                 {\r
1079                         string wrongPath = "something that is not LDAP path";\r
1080 \r
1081                         de = new DirectoryEntry();\r
1082 \r
1083                         Assert.AreEqual(de.Path,String.Empty);\r
1084 \r
1085                         de.Path = configuration.ConnectionString;\r
1086                         Assert.AreEqual(de.Path,configuration.ConnectionString);\r
1087 \r
1088                         de.Path = "";\r
1089                         Assert.AreEqual(de.Path,String.Empty);\r
1090                         \r
1091                         de.Path = wrongPath;\r
1092                         Assert.AreEqual(de.Path,wrongPath);\r
1093 \r
1094 \r
1095                         de = new DirectoryEntry(configuration.ConnectionString);\r
1096 \r
1097                         de.Path = configuration.ConnectionString;\r
1098                         Assert.AreEqual(de.Path,configuration.ConnectionString);\r
1099 \r
1100                         de.Path = "";\r
1101                         Assert.AreEqual(de.Path,String.Empty);\r
1102 \r
1103                         de.Path = wrongPath;\r
1104                         Assert.AreEqual(de.Path,wrongPath);\r
1105 \r
1106                         \r
1107                         de = new DirectoryEntry(configuration.ConnectionString,\r
1108                                                                         configuration.Username,\r
1109                                                                         configuration.Password,\r
1110                                                                         configuration.AuthenticationType);\r
1111 \r
1112                         de.Path = configuration.ConnectionString;\r
1113                         Assert.AreEqual(de.Path,configuration.ConnectionString);\r
1114 \r
1115                         de.Path = "";\r
1116                         Assert.AreEqual(de.Path,String.Empty);\r
1117 \r
1118                         de.Path = wrongPath;\r
1119                         Assert.AreEqual(de.Path,wrongPath);\r
1120 \r
1121                         de = new DirectoryEntry("ldap://myhost:389/ou=people",null,null,AuthenticationTypes.None);\r
1122                         Assert.AreEqual(de.Path,"ldap://myhost:389/ou=people");\r
1123 \r
1124                         de.Path = null;\r
1125                         Assert.AreEqual(de.Path,String.Empty);\r
1126                 }\r
1127 \r
1128 \r
1129                 [Test]\r
1130                 public void DirectoryEntry_Properties1()\r
1131                 {\r
1132                         de = new DirectoryEntry(configuration.ConnectionString);\r
1133 \r
1134                         Assert.AreEqual(de.Properties.Count,3);\r
1135                         Assert.AreEqual(((PropertyValueCollection)de.Properties["dc"]).Value,"example");\r
1136                         Assert.AreEqual(((PropertyValueCollection)de.Properties["description"]).Value,null);\r
1137 \r
1138                         \r
1139                         de = new DirectoryEntry(configuration.ConnectionString,\r
1140                                                                         configuration.Username,\r
1141                                                                         configuration.Password,\r
1142                                                                         configuration.AuthenticationType);\r
1143 \r
1144                         Assert.AreEqual(de.Properties.Count,3);\r
1145                         Assert.AreEqual(((PropertyValueCollection)de.Properties["dc"]).Value,"example");\r
1146                         Assert.AreEqual(((PropertyValueCollection)de.Properties["description"]).Value,null);\r
1147 \r
1148                         // ensure that properties are not accessible after removing an entry from the server\r
1149                         string barakTsabariDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));\r
1150                         de = new DirectoryEntry(barakTsabariDN,\r
1151                                                                         configuration.Username,\r
1152                                                                         configuration.Password,\r
1153                                                                         configuration.AuthenticationType);\r
1154                         \r
1155                         de.DeleteTree();\r
1156                         \r
1157                         try {\r
1158                                 int i = de.Properties.Count;\r
1159                                 Assert.Fail("Properties should not be accessible after deleting an entry from the server");\r
1160                         }\r
1161                         catch(AssertionException ae) {\r
1162                                 throw ae;\r
1163                         }\r
1164                         catch(Exception e) {\r
1165                                 // supress exception\r
1166                         }\r
1167 \r
1168                         try {\r
1169                                 string s = (string)((PropertyValueCollection)de.Properties["dc"]).Value;\r
1170                                 Assert.Fail("Properties should not be accessible after deleting an entry from the server");\r
1171                         }\r
1172                         catch(AssertionException ae) {\r
1173                                 throw ae;\r
1174                         }\r
1175                         catch(Exception e) {\r
1176                                 // supress exception\r
1177                         }\r
1178                 }\r
1179 \r
1180                 [Test]\r
1181                 public void DirectoryEntry_Properties2()\r
1182                 {\r
1183                         // delete entry, create a new one (the same) and access properties of the old object\r
1184                         string barakTsabariDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));\r
1185                         de = new DirectoryEntry(barakTsabariDN,\r
1186                                                                         configuration.Username,\r
1187                                                                         configuration.Password,\r
1188                                                                         configuration.AuthenticationType);\r
1189 \r
1190                         // cause to properties loading\r
1191                         Assert.AreEqual(de.Properties.Count,6);\r
1192                         Assert.AreEqual(((PropertyValueCollection)de.Properties["sn"]).Value,"Tsabari");\r
1193 \r
1194                         // delete entry\r
1195                         de.DeleteTree();\r
1196 \r
1197                         // the local property chache is still accessible\r
1198                         Assert.AreEqual(de.Properties.Count,6);\r
1199                         Assert.AreEqual(((PropertyValueCollection)de.Properties["sn"]).Value,"Tsabari");\r
1200 \r
1201                         de.CommitChanges();\r
1202 \r
1203                         // the local property chache is still accessible\r
1204                         ((PropertyValueCollection)de.Properties["sn"]).Value = "Barbari";\r
1205 \r
1206                         // create the entry back again\r
1207                         using (DirectoryEntry ouHumanResources = new DirectoryEntry(    configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),\r
1208                                                                                                                                         configuration.Username,\r
1209                                                                                                                                         configuration.Password,\r
1210                                                                                                                                         configuration.AuthenticationType)){\r
1211                         using (DirectoryEntry cnBarakTsabari = ouHumanResources.Children.Add("cn=Barak Tsabari","Class")){\r
1212                         ((PropertyValueCollection)cnBarakTsabari.Properties["objectClass"]).Add("person");\r
1213                         ((PropertyValueCollection)cnBarakTsabari.Properties["objectClass"]).Add("organizationalPerson");\r
1214                         cnBarakTsabari.Properties["cn"].Value = "Barak Tsabari";\r
1215                         cnBarakTsabari.Properties["facsimileTelephoneNumber"].Value = "+1 906 777 8853";\r
1216                         ((PropertyValueCollection)cnBarakTsabari.Properties["ou"]).Add("Human Resources");\r
1217                         ((PropertyValueCollection)cnBarakTsabari.Properties["ou"]).Add("People");\r
1218                         cnBarakTsabari.Properties["sn"].Value = "Tsabari";\r
1219                         cnBarakTsabari.Properties["telephoneNumber"].Value = "+1 906 777 8854";\r
1220                         cnBarakTsabari.CommitChanges();\r
1221                         }\r
1222                         }\r
1223                         \r
1224                         // the local property chache is still accessible\r
1225                         Assert.AreEqual(((PropertyValueCollection)de.Properties["sn"]).Value,"Barbari");\r
1226 \r
1227                         // Refresh from server\r
1228                         de.RefreshCache();\r
1229                         // ensure the properties of an entry are still accessible through the old object\r
1230                         Assert.AreEqual(((PropertyValueCollection)de.Properties["sn"]).Value,"Tsabari");\r
1231 \r
1232                 }\r
1233 \r
1234 \r
1235                 [Test]\r
1236                 [Category("NotWorking")]\r
1237                 public void DirectoryEntry_SchemaClassName()\r
1238                 {\r
1239                         de = new DirectoryEntry();\r
1240                         Assert.AreEqual(de.SchemaClassName,"domainDNS");\r
1241 \r
1242 \r
1243                         de = new DirectoryEntry(configuration.ConnectionString);\r
1244                         Assert.AreEqual(de.SchemaClassName,"organization");\r
1245 \r
1246 \r
1247                         de = new DirectoryEntry(configuration.ConnectionString,\r
1248                                                                         configuration.Username,\r
1249                                                                         configuration.Password,\r
1250                                                                         configuration.AuthenticationType);\r
1251                         Assert.AreEqual(de.SchemaClassName,"organization");\r
1252 \r
1253                         DirectoryEntry de2 = de.Children.Add("ou=My Child","Class");\r
1254                         Assert.AreEqual(de2.SchemaClassName,"Class");\r
1255                         Assert.AreEqual(((PropertyValueCollection)de2.Properties["structuralObjectClass"]).Value,null);\r
1256                 }\r
1257 \r
1258                 [Test]\r
1259                 [Category("NotWorking")]\r
1260                 public void DirectoryEntry_SchemaEntry()\r
1261                 {\r
1262                         de = new DirectoryEntry();\r
1263                         DirectoryEntry schemaEntry = de.SchemaEntry;\r
1264 \r
1265                         // MS works only with "LDAP" while RFC2255 states "ldap"\r
1266                         Assert.AreEqual(schemaEntry.Path.ToLower(),"LDAP://schema/domainDNS".ToLower());\r
1267                         Assert.AreEqual(schemaEntry.Name,"domainDNS");\r
1268                         Assert.AreEqual(schemaEntry.Username,null);\r
1269                         Assert.AreEqual(schemaEntry.UsePropertyCache,true);\r
1270                         Assert.AreEqual(schemaEntry.SchemaClassName,"Class");\r
1271                         Assert.AreEqual(schemaEntry.AuthenticationType,AuthenticationTypes.None);\r
1272 \r
1273 \r
1274                         de = new DirectoryEntry(configuration.ConnectionString);\r
1275                         schemaEntry = de.SchemaEntry;\r
1276 \r
1277                         Assert.AreEqual(schemaEntry.Path,configuration.ServerRoot + "schema/organization");\r
1278                         Assert.AreEqual(schemaEntry.Name,"organization");\r
1279                         Assert.AreEqual(schemaEntry.Username,null);\r
1280                         Assert.AreEqual(schemaEntry.UsePropertyCache,true);\r
1281                         Assert.AreEqual(schemaEntry.SchemaClassName,"Class");\r
1282                         Assert.AreEqual(schemaEntry.AuthenticationType,AuthenticationTypes.None);\r
1283 \r
1284 \r
1285                         de = new DirectoryEntry(configuration.ConnectionString,\r
1286                                                                         configuration.Username,\r
1287                                                                         configuration.Password,\r
1288                                                                         configuration.AuthenticationType);\r
1289                         schemaEntry = de.SchemaEntry;\r
1290 \r
1291                         Assert.AreEqual(schemaEntry.Path,configuration.ServerRoot + "schema/organization");\r
1292                         Assert.AreEqual(schemaEntry.Name,"organization");\r
1293                         Assert.AreEqual(schemaEntry.Username,configuration.Username);\r
1294                         Assert.AreEqual(schemaEntry.UsePropertyCache,true);\r
1295                         Assert.AreEqual(schemaEntry.SchemaClassName,"Class");\r
1296                         Assert.AreEqual(schemaEntry.AuthenticationType,configuration.AuthenticationType);\r
1297                 }               \r
1298 \r
1299 \r
1300                 [Test]\r
1301                 public void DirectoryEntry_Username()\r
1302                 {\r
1303                         string wrongUsername = "some wrong username";\r
1304 \r
1305                         de = new DirectoryEntry();\r
1306 \r
1307                         Assert.AreEqual(de.Username,null);\r
1308 \r
1309                         de.Username = configuration.Username;\r
1310                         Assert.AreEqual(de.Username,configuration.Username);\r
1311 \r
1312                         de.Username = "";\r
1313                         Assert.AreEqual(de.Username,String.Empty);\r
1314                         \r
1315                         de.Username = wrongUsername;\r
1316                         Assert.AreEqual(de.Username,wrongUsername);\r
1317 \r
1318 \r
1319                         de = new DirectoryEntry(configuration.ConnectionString);\r
1320 \r
1321                         de.Username = configuration.Username;\r
1322                         Assert.AreEqual(de.Username,configuration.Username);\r
1323 \r
1324                         de.Username = "";\r
1325                         Assert.AreEqual(de.Username,String.Empty);\r
1326 \r
1327                         de.Username = wrongUsername;\r
1328                         Assert.AreEqual(de.Username,wrongUsername);\r
1329 \r
1330                         \r
1331                         de = new DirectoryEntry(configuration.ConnectionString,\r
1332                                                                         configuration.Username,\r
1333                                                                         configuration.Password,\r
1334                                                                         configuration.AuthenticationType);\r
1335 \r
1336                         de.Username = configuration.Username;\r
1337                         Assert.AreEqual(de.Username,configuration.Username);\r
1338 \r
1339                         de.Username = "";\r
1340                         Assert.AreEqual(de.Username,String.Empty);\r
1341 \r
1342                         de.Username = wrongUsername;\r
1343                         Assert.AreEqual(de.Username,wrongUsername);\r
1344                 }\r
1345 \r
1346 \r
1347                 [Test]\r
1348                 public void DirectoryEntry_Close()\r
1349                 {\r
1350                         de = new DirectoryEntry();\r
1351                         de.Close();\r
1352 \r
1353                         de = new DirectoryEntry(configuration.ConnectionString);\r
1354                         de.Close();\r
1355         \r
1356                         de = new DirectoryEntry(configuration.ConnectionString,\r
1357                                                                         configuration.Username,\r
1358                                                                         configuration.Password,\r
1359                                                                         configuration.AuthenticationType);\r
1360                         de.Close();\r
1361                 }\r
1362 \r
1363 \r
1364                 [Test]\r
1365                 public void DirectoryEntry_CommitChanges1()\r
1366                 {\r
1367                         string humanResourcesDN = configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));\r
1368                         using (DirectoryEntry ouHumanResources = new DirectoryEntry(    humanResourcesDN,\r
1369                                                                                                                                         configuration.Username,\r
1370                                                                                                                                         configuration.Password,\r
1371                                                                                                                                         configuration.AuthenticationType)){\r
1372 \r
1373                         // new entry\r
1374                         string newEmployeeDN = configuration.ServerRoot + "cn=New Employee,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));\r
1375                         de = ouHumanResources.Children.Add("cn=New Employee","Class");\r
1376                         Assert.IsFalse(DirectoryEntry.Exists(newEmployeeDN));\r
1377 \r
1378                         de.Properties["objectClass"].Value = "organizationalRole";\r
1379                         de.Properties["cn"].Value = "New Employee";\r
1380                         Assert.IsFalse(DirectoryEntry.Exists(newEmployeeDN));\r
1381                         \r
1382                         de.CommitChanges();\r
1383                         Assert.IsTrue(DirectoryEntry.Exists(newEmployeeDN));\r
1384                         }\r
1385 \r
1386                         // existing entry\r
1387                         string barakTsabariDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));\r
1388                         de = new DirectoryEntry(barakTsabariDN,\r
1389                                                                         configuration.Username,\r
1390                                                                         configuration.Password,\r
1391                                                                         configuration.AuthenticationType);\r
1392 \r
1393                         string oldTelephone = (string)((PropertyValueCollection)de.Properties["telephoneNumber"]).Value;\r
1394                         string newTelephone = "+972 3 6078596";\r
1395 \r
1396                         // UsePropertyCache - true\r
1397                         de.UsePropertyCache = true;\r
1398                         ((PropertyValueCollection)de.Properties["telephoneNumber"]).Value = newTelephone;\r
1399                         Assert.AreEqual(((PropertyValueCollection)de.Properties["telephoneNumber"]).Value,newTelephone);\r
1400 \r
1401                         using (DirectoryEntry cnBarakTsabari = new DirectoryEntry(      barakTsabariDN,\r
1402                                                                                                                                 configuration.Username,\r
1403                                                                                                                                 configuration.Password,\r
1404                                                                                                                                 configuration.AuthenticationType)){\r
1405 \r
1406                         //check that on server there is still an old value\r
1407                         Assert.AreEqual(((PropertyValueCollection)cnBarakTsabari.Properties["telephoneNumber"]).Value,oldTelephone);\r
1408 \r
1409                         de.CommitChanges();\r
1410                         }\r
1411 \r
1412                         using (DirectoryEntry cnBarakTsabari = new DirectoryEntry(barakTsabariDN,\r
1413                                                                                                 configuration.Username,\r
1414                                                                                                 configuration.Password,\r
1415                                                                                                 configuration.AuthenticationType)){\r
1416 \r
1417                         // check that new value is updated on the server\r
1418                         Assert.AreEqual(((PropertyValueCollection)cnBarakTsabari.Properties["telephoneNumber"]).Value,newTelephone);\r
1419                         }\r
1420 \r
1421                         // UsePropertyCache - false\r
1422                         de = new DirectoryEntry(barakTsabariDN,\r
1423                                                                         configuration.Username,\r
1424                                                                         configuration.Password,\r
1425                                                                         configuration.AuthenticationType);\r
1426                         de.UsePropertyCache = false;\r
1427                         Assert.AreEqual(((PropertyValueCollection)de.Properties["telephoneNumber"]).Value,newTelephone);\r
1428                         ((PropertyValueCollection)de.Properties["telephoneNumber"]).Value = oldTelephone;\r
1429                         Assert.AreEqual(((PropertyValueCollection)de.Properties["telephoneNumber"]).Value,oldTelephone);\r
1430 \r
1431                         using (DirectoryEntry cnBarakTsabari = new DirectoryEntry(barakTsabariDN,\r
1432                                                                                                 configuration.Username,\r
1433                                                                                                 configuration.Password,\r
1434                                                                                                 configuration.AuthenticationType)){\r
1435 \r
1436                         // check that new value is updated on the server\r
1437                         //Assert.AreEqual(((PropertyValueCollection)cnBarakTsabari.Properties["telephoneNumber"]).Value,oldTelephone);\r
1438                         }\r
1439 \r
1440                         de.CommitChanges(); // this should do nothing\r
1441                 }\r
1442 \r
1443                 [Test]\r
1444                 public void DirectoryEntry_CommitChanges2()\r
1445                 {\r
1446                         string barakTsabariDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));\r
1447                         using (DirectoryEntry barakTsabariDE1 = new DirectoryEntry(barakTsabariDN,\r
1448                                                                                                                                 configuration.Username,\r
1449                                                                                                                                 configuration.Password,\r
1450                                                                                                                                 configuration.AuthenticationType)){\r
1451                         barakTsabariDE1.UsePropertyCache = true;\r
1452 \r
1453                         using (DirectoryEntry barakTsabariDE2 = new DirectoryEntry(barakTsabariDN,\r
1454                                                                                                                                 configuration.Username,\r
1455                                                                                                                                 configuration.Password,\r
1456                                                                                                                                 configuration.AuthenticationType)){\r
1457                         barakTsabariDE2.UsePropertyCache = true;\r
1458 \r
1459                         string oldTelephone = (string)((PropertyValueCollection)barakTsabariDE1.Properties["telephoneNumber"]).Value;\r
1460                         string newTelephone = "+972 3 6078596";\r
1461                         string oldFacsimilieTelephoneNumber = (string)((PropertyValueCollection)barakTsabariDE1.Properties["facsimileTelephoneNumber"]).Value;\r
1462                         string newFacsimilieTelephoneNumber1 = "+972-3-9872365";\r
1463                         string newFacsimilieTelephoneNumber2 = "+972-3-9999999";\r
1464 \r
1465                         barakTsabariDE1.Properties["telephoneNumber"].Value = newTelephone;\r
1466                         barakTsabariDE1.Properties["facsimileTelephoneNumber"].Value = newFacsimilieTelephoneNumber1;\r
1467 \r
1468                         barakTsabariDE2.Properties["facsimileTelephoneNumber"].Value = newFacsimilieTelephoneNumber2;\r
1469 \r
1470                         // only the changed properties of each object are set\r
1471 \r
1472                         barakTsabariDE1.CommitChanges();\r
1473                         de = new DirectoryEntry(barakTsabariDN,\r
1474                                                                         configuration.Username,\r
1475                                                                         configuration.Password,\r
1476                                                                         configuration.AuthenticationType);\r
1477                         Assert.AreEqual(de.Properties["telephoneNumber"].Value,newTelephone);\r
1478                         Assert.AreEqual(de.Properties["facsimileTelephoneNumber"].Value,newFacsimilieTelephoneNumber1);\r
1479 \r
1480                         barakTsabariDE2.CommitChanges();\r
1481                         de = new DirectoryEntry(barakTsabariDN,\r
1482                                                                         configuration.Username,\r
1483                                                                         configuration.Password,\r
1484                                                                         configuration.AuthenticationType);\r
1485                         Assert.AreEqual(de.Properties["telephoneNumber"].Value,newTelephone);\r
1486                         Assert.AreEqual(de.Properties["facsimileTelephoneNumber"].Value,newFacsimilieTelephoneNumber2);\r
1487                         }\r
1488                         }\r
1489                 }\r
1490 \r
1491 \r
1492                 [Test]\r
1493                 [ExpectedException(typeof(NotImplementedException))]\r
1494                 public void DirectoryEntry_CopyTo()\r
1495                 {\r
1496                         string barakTsabariDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));\r
1497                         de = new DirectoryEntry(configuration.ConnectionString,\r
1498                                                                         configuration.Username,\r
1499                                                                         configuration.Password,\r
1500                                                                         configuration.AuthenticationType);\r
1501 \r
1502                         using (DirectoryEntry cnBarakTsabari = new DirectoryEntry(      barakTsabariDN,\r
1503                                                                                                                                 configuration.Username,\r
1504                                                                                                                                 configuration.Password,\r
1505                                                                                                                                 configuration.AuthenticationType)){\r
1506 \r
1507                         cnBarakTsabari.CopyTo(de);\r
1508                         }\r
1509                 }\r
1510 \r
1511 \r
1512                 [Test]\r
1513                 public void DirectoryEntry_DeleteTree()\r
1514                 {\r
1515                         string barakTsabariDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));\r
1516 \r
1517                         Assert.IsTrue(DirectoryEntry.Exists(barakTsabariDN));\r
1518                         de = new DirectoryEntry(barakTsabariDN,\r
1519                                                                         configuration.Username,\r
1520                                                                         configuration.Password,\r
1521                                                                         configuration.AuthenticationType);                                              \r
1522 \r
1523                         // no properties changed\r
1524                         de.DeleteTree();\r
1525                         de.CommitChanges();\r
1526 \r
1527                         Assert.IsFalse(DirectoryEntry.Exists(barakTsabariDN));\r
1528 \r
1529                         string johnSmithDN = configuration.ServerRoot + "cn=John Smith,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));\r
1530 \r
1531                         Assert.IsTrue(DirectoryEntry.Exists(johnSmithDN));\r
1532                         de = new DirectoryEntry(johnSmithDN,\r
1533                                                                         configuration.Username,\r
1534                                                                         configuration.Password,\r
1535                                                                         configuration.AuthenticationType);\r
1536 \r
1537                         de.Properties["telephoneNumber"].Value = "+972 3 9999999";\r
1538 \r
1539                         // some properties changed\r
1540                         de.DeleteTree();\r
1541                         try {\r
1542                                 de.CommitChanges();                                     \r
1543                                 Assert.Fail("Object " + johnSmithDN + " was not deleted from server");\r
1544                         }\r
1545                         catch(AssertionException ae) {\r
1546                                 throw ae;\r
1547                         }\r
1548                         catch(Exception e) {\r
1549                                 // do nothing\r
1550                         }\r
1551                 }\r
1552 \r
1553                 [Test]\r
1554                 public void DirectoryEntry_DeleteTree2()\r
1555                 {\r
1556                         string johnSmithDN = configuration.ServerRoot + "cn=John Smith,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));\r
1557 \r
1558                         Assert.IsTrue(DirectoryEntry.Exists(johnSmithDN));\r
1559                         // two objects refer to the same entry\r
1560                         de = new DirectoryEntry(johnSmithDN,\r
1561                                                                         configuration.Username,\r
1562                                                                         configuration.Password,\r
1563                                                                         configuration.AuthenticationType);\r
1564 \r
1565                         using (DirectoryEntry johnSmithDE = new DirectoryEntry(johnSmithDN,\r
1566                                                                                                                         configuration.Username,\r
1567                                                                                                                         configuration.Password,\r
1568                                                                                                                         configuration.AuthenticationType)){\r
1569 \r
1570                         johnSmithDE.Properties["telephoneNumber"].Value = "+972 3 9999999";\r
1571 \r
1572                         // check that the second entry is not accessible after the first is deleted\r
1573                         de.DeleteTree();\r
1574                         de.CommitChanges();\r
1575 \r
1576                         try {\r
1577                                 johnSmithDE.CommitChanges();                                    \r
1578                                 Assert.Fail("Object " + johnSmithDN + " should not be accessible");\r
1579                         }\r
1580                         catch(AssertionException ae) {\r
1581                                 throw ae;\r
1582                         }\r
1583                         catch(Exception e) {\r
1584                                 // do nothing\r
1585                         }\r
1586                         }\r
1587                 }\r
1588 \r
1589 \r
1590                 [Test]\r
1591                 public void DirectoryEntry_Exists()\r
1592                 {\r
1593                         string barakTsabariDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));\r
1594                         string johnSmithDN = configuration.ServerRoot + "cn=John Smith,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));\r
1595                         string humanResourcesOU = configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));\r
1596 \r
1597                         Assert.IsTrue(DirectoryEntry.Exists(barakTsabariDN));\r
1598                         Assert.IsTrue(DirectoryEntry.Exists(johnSmithDN));\r
1599                         Assert.IsTrue(DirectoryEntry.Exists(humanResourcesOU));\r
1600 \r
1601                         Assert.IsFalse(DirectoryEntry.Exists(barakTsabariDN + ",dc=mono"));\r
1602                 }\r
1603 \r
1604 \r
1605                 [Test]\r
1606                 public void DirectoryEntry_MoveTo_De()\r
1607                 {\r
1608                         string barakTsabariHumanResourcesDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));\r
1609                         string barakTsabariDevQaDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=DevQA,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));\r
1610 \r
1611                         using (DirectoryEntry barakTsabariDE = new DirectoryEntry(      barakTsabariHumanResourcesDN,\r
1612                                                                                                                                 configuration.Username,\r
1613                                                                                                                                 configuration.Password,\r
1614                                                                                                                                 configuration.AuthenticationType)){\r
1615 \r
1616                         string devQaOU = configuration.ServerRoot + "ou=DevQA,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));\r
1617 \r
1618                         using (DirectoryEntry devQaDE = new DirectoryEntry(devQaOU,\r
1619                                                                                                                 configuration.Username,\r
1620                                                                                                                 configuration.Password,\r
1621                                                                                                                 configuration.AuthenticationType)){\r
1622 \r
1623                         barakTsabariDE.MoveTo(devQaDE);\r
1624                         barakTsabariDE.CommitChanges();\r
1625 \r
1626                         Assert.IsTrue(DirectoryEntry.Exists(barakTsabariDevQaDN));\r
1627 \r
1628                         string humanRwsourcesOU = configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));\r
1629 \r
1630                         using (DirectoryEntry humanResourcesDE = new DirectoryEntry(    humanRwsourcesOU,\r
1631                                                                                                                                         configuration.Username,\r
1632                                                                                                                                         configuration.Password,\r
1633                                                                                                                                         configuration.AuthenticationType)){\r
1634 \r
1635                         barakTsabariDE.MoveTo(humanResourcesDE);\r
1636                         barakTsabariDE.CommitChanges();\r
1637 \r
1638                         Assert.IsTrue(DirectoryEntry.Exists(barakTsabariHumanResourcesDN));\r
1639                         }\r
1640                         }\r
1641                         }\r
1642                 }\r
1643 \r
1644 \r
1645                 [Test]\r
1646                 public void DirectoryEntry_MoveTo_DeStr()\r
1647                 {\r
1648                         string barakTsabariHumanResourcesDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));\r
1649                         string barakTsabariDevQaDN = configuration.ServerRoot + "cn=My Name,ou=DevQA,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));\r
1650 \r
1651                         using (DirectoryEntry barakTsabariDE = new DirectoryEntry(      barakTsabariHumanResourcesDN,\r
1652                                                                                                                                 configuration.Username,\r
1653                                                                                                                                 configuration.Password,\r
1654                                                                                                                                 configuration.AuthenticationType)){\r
1655 \r
1656                         string devQaOU = configuration.ServerRoot + "ou=DevQA,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));\r
1657 \r
1658                         using (DirectoryEntry devQaDE = new DirectoryEntry(devQaOU,\r
1659                                                                                                                 configuration.Username,\r
1660                                                                                                                 configuration.Password,\r
1661                                                                                                                 configuration.AuthenticationType)){\r
1662 \r
1663                         barakTsabariDE.MoveTo(devQaDE,"cn=My Name");\r
1664                         barakTsabariDE.CommitChanges();\r
1665 \r
1666                         Assert.IsTrue(DirectoryEntry.Exists(barakTsabariDevQaDN));\r
1667 \r
1668                         string humanRwsourcesOU = configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));\r
1669 \r
1670                         using (DirectoryEntry humanResourcesDE = new DirectoryEntry(    humanRwsourcesOU,\r
1671                                                                                                                                         configuration.Username,\r
1672                                                                                                                                         configuration.Password,\r
1673                                                                                                                                         configuration.AuthenticationType)){\r
1674 \r
1675                         barakTsabariDE.MoveTo(humanResourcesDE,"cn=Barak Tsabari");\r
1676                         barakTsabariDE.CommitChanges();\r
1677 \r
1678                         Assert.IsTrue(DirectoryEntry.Exists(barakTsabariHumanResourcesDN));\r
1679                         }\r
1680                         }\r
1681                         }\r
1682                 }\r
1683 \r
1684                 [Test]\r
1685                 public void DirectoryEntry_RefreshCache()\r
1686                 {\r
1687                         de = new DirectoryEntry(configuration.ConnectionString);\r
1688                         de.UsePropertyCache = true;\r
1689                         \r
1690                         string newValue = "Just a company";\r
1691                         string oldValue = (string)((PropertyValueCollection)de.Properties["description"]).Value;\r
1692                         ((PropertyValueCollection)de.Properties["description"]).Value = newValue;\r
1693                         \r
1694                         Assert.AreEqual(((PropertyValueCollection)de.Properties["description"]).Value,newValue);\r
1695 \r
1696                         de.RefreshCache();\r
1697 \r
1698                         Assert.AreEqual(((PropertyValueCollection)de.Properties["description"]).Value,oldValue);\r
1699                         \r
1700                         // call RefeshCache on new entry prior to submitting it to the server shoud fail\r
1701                         string newEmployeeDN = configuration.ServerRoot + "cn=New Employee,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));\r
1702                         string humanResourcesDN = configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));\r
1703 \r
1704                         using (DirectoryEntry humanResourcesDE = new DirectoryEntry(    humanResourcesDN,\r
1705                                                                                                                                         configuration.Username,\r
1706                                                                                                                                         configuration.Password,\r
1707                                                                                                                                         configuration.AuthenticationType)){\r
1708 \r
1709                         using (DirectoryEntry newEmployeeDE = humanResourcesDE.Children.Add("cn=New Employee","Class")){\r
1710                         Assert.AreEqual(newEmployeeDE.Properties["cn"].Value,null);\r
1711 \r
1712                         ((PropertyValueCollection)newEmployeeDE.Properties["objectClass"]).Add("person");\r
1713                         ((PropertyValueCollection)newEmployeeDE.Properties["objectClass"]).Add("organizationalPerson");\r
1714                         newEmployeeDE.Properties["cn"].Value = "New Employee";\r
1715                         newEmployeeDE.Properties["sn"].Value = "Employee";\r
1716                         newEmployeeDE.Properties["ou"].Value = "Human Resources";\r
1717 \r
1718                         Assert.AreEqual(newEmployeeDE.Properties["cn"].Value,"New Employee");\r
1719 \r
1720                         try {\r
1721                                 newEmployeeDE.RefreshCache();\r
1722                                 Assert.Fail("Call to RefreshCache did not fail");\r
1723                         }\r
1724                         catch(AssertionException ae) {\r
1725                                 throw ae;\r
1726                         }\r
1727                         catch (Exception e) {\r
1728                                 // supress exception\r
1729                         }\r
1730 \r
1731                         Assert.AreEqual(newEmployeeDE.Properties["cn"].Value,"New Employee");\r
1732 \r
1733                         newEmployeeDE.CommitChanges();\r
1734 \r
1735                         // now it should work without any problem\r
1736                         newEmployeeDE.RefreshCache();\r
1737 \r
1738                         Assert.AreEqual(newEmployeeDE.Properties["cn"].Value,"New Employee");\r
1739                         }\r
1740                         }\r
1741                 }\r
1742 \r
1743                 [Test]\r
1744                 public void DirectoryEntry_RefreshCache_StrArr()\r
1745                 {                       \r
1746                         de = new DirectoryEntry(configuration.ServerRoot + "cn=Uzi Cohen,cn=Manager" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)));\r
1747                         de.UsePropertyCache = true;\r
1748                         \r
1749                         string[] newValues = new string [] { "Just a manager", "Levi" };\r
1750                         string[] oldValues = new string [2];\r
1751                         oldValues [0] = (string)((PropertyValueCollection)de.Properties["description"]).Value;\r
1752                         oldValues [1] = (string)((PropertyValueCollection)de.Properties["sn"]).Value;\r
1753                         \r
1754                         ((PropertyValueCollection)de.Properties["description"]).Value = newValues [0];\r
1755                         ((PropertyValueCollection)de.Properties["sn"]).Value = newValues [1];\r
1756                         \r
1757                         Assert.AreEqual(((PropertyValueCollection)de.Properties["description"]).Value,newValues [0]);\r
1758                         Assert.AreEqual(((PropertyValueCollection)de.Properties["sn"]).Value,newValues [1]);\r
1759 \r
1760                         de.RefreshCache(new string[] {"cn"});\r
1761 \r
1762                         Assert.AreEqual(((PropertyValueCollection)de.Properties["description"]).Value,newValues [0]);\r
1763                         Assert.AreEqual(((PropertyValueCollection)de.Properties["sn"]).Value,newValues [1]);\r
1764 \r
1765                         de.RefreshCache(new string[] {"description","sn"});\r
1766 \r
1767                         Assert.AreEqual(((PropertyValueCollection)de.Properties["description"]).Value,newValues [0]);\r
1768                         Assert.AreEqual(((PropertyValueCollection)de.Properties["sn"]).Value,oldValues [1]);    \r
1769                 }\r
1770 \r
1771                 [Test]\r
1772                 public void DirectoryEntry_Rename()\r
1773                 {\r
1774                         string barakTsabariOldDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));\r
1775                         string barakTsabariNewDN = configuration.ServerRoot + "cn=My Name,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));\r
1776 \r
1777                         using (DirectoryEntry barakTsabariDE = new DirectoryEntry(      barakTsabariOldDN,\r
1778                                                                                                                                 configuration.Username,\r
1779                                                                                                                                 configuration.Password,\r
1780                                                                                                                                 configuration.AuthenticationType)){\r
1781 \r
1782                         barakTsabariDE.Rename("cn=My Name");\r
1783                         barakTsabariDE.CommitChanges();\r
1784 \r
1785                         Assert.IsTrue(DirectoryEntry.Exists(barakTsabariNewDN));\r
1786 \r
1787                         barakTsabariDE.Rename("cn=Barak Tsabari");\r
1788                         barakTsabariDE.CommitChanges();\r
1789 \r
1790                         Assert.IsTrue(DirectoryEntry.Exists(barakTsabariOldDN));\r
1791                         }\r
1792                 }\r
1793 \r
1794                 #endregion Tests\r
1795 \r
1796                 private static string GetName (string baseDn)\r
1797                 {\r
1798                         if (baseDn == null || baseDn.Length == 0 || baseDn.IndexOf (',') == -1)\r
1799                                 return baseDn;\r
1800 \r
1801                         int index = baseDn.IndexOf (',');\r
1802 \r
1803                         return baseDn.Substring (0, index);\r
1804                 }\r
1805 \r
1806                 private static string GetParentDN (string baseDn)\r
1807                 {\r
1808                         if (baseDn == null || baseDn.Length == 0 || baseDn.IndexOf (',') == -1)\r
1809                                 return String.Empty;\r
1810 \r
1811                         int index = baseDn.IndexOf (',');\r
1812 \r
1813                         return baseDn.Substring (index + 1,baseDn.Length - index - 1);\r
1814                 }\r
1815         }\r
1816 }\r