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