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