2 // DirectoryServicesDirectoryEntryTest.cs -
\r
3 // NUnit Test Cases for DirectoryServices.DirectoryEntry
\r
6 // Boris Kirzner <borisk@mainsoft.com>
\r
9 using NUnit.Framework;
\r
11 using System.DirectoryServices;
\r
13 namespace MonoTests.System.DirectoryServices
\r
16 public class DirectoryServicesDirectoryEntryTest
\r
20 static TestConfiguration configuration;
\r
21 static DirectoryEntry de;
\r
23 #endregion // Fields
\r
25 #region SetUp and TearDown
\r
28 public void TestFixtureSetUp()
\r
31 configuration = new TestConfiguration ();
\r
33 if (String.IsNullOrEmpty (configuration.ConnectionString))
\r
34 Assert.Ignore ("No configuration");
\r
38 [TestFixtureTearDown]
\r
39 public void TestFixtureTearDown()
\r
52 #region Initialize basics
\r
54 DirectoryEntry root = new DirectoryEntry( configuration.ConnectionString,
\r
55 configuration.Username,
\r
56 configuration.Password,
\r
57 configuration.AuthenticationType);
\r
58 DirectoryEntry ouPeople = root.Children.Add("ou=people","Class");
\r
59 ouPeople.Properties["objectClass"].Value = "organizationalUnit";
\r
60 ouPeople.Properties["description"].Value = "All people in organisation";
\r
61 ouPeople.Properties["ou"].Value = "people";
\r
62 ouPeople.CommitChanges();
\r
64 #endregion // Initialize basics
\r
66 #region Human Resources
\r
68 DirectoryEntry ouHumanResources = ouPeople.Children.Add("ou=Human Resources","Class");
\r
69 ouHumanResources.Properties["objectClass"].Value = "organizationalUnit";
\r
70 ouHumanResources.Properties["ou"].Value = "Human Resources";
\r
71 ouHumanResources.CommitChanges();
\r
73 DirectoryEntry cnJohnSmith = ouHumanResources.Children.Add("cn=John Smith","Class");
\r
74 cnJohnSmith.Properties["objectClass"].Value = "organizationalRole";
\r
75 cnJohnSmith.Properties["cn"].Value = "John Smith";
\r
76 cnJohnSmith.Properties["description"].Value = "Very clever person";
\r
77 cnJohnSmith.Properties["ou"].Value = "Human Resources";
\r
78 cnJohnSmith.Properties["telephoneNumber"].Value = "1 801 555 1212";
\r
79 cnJohnSmith.CommitChanges();
\r
81 DirectoryEntry cnBarakTsabari = ouHumanResources.Children.Add("cn=Barak Tsabari","Class");
\r
82 ((PropertyValueCollection)cnBarakTsabari.Properties["objectClass"]).Add("person");
\r
83 ((PropertyValueCollection)cnBarakTsabari.Properties["objectClass"]).Add("organizationalPerson");
\r
84 cnBarakTsabari.Properties["cn"].Value = "Barak Tsabari";
\r
85 cnBarakTsabari.Properties["facsimileTelephoneNumber"].Value = "+1 906 777 8853";
\r
86 ((PropertyValueCollection)cnBarakTsabari.Properties["ou"]).Add("Human Resources");
\r
87 ((PropertyValueCollection)cnBarakTsabari.Properties["ou"]).Add("People");
\r
88 cnBarakTsabari.Properties["sn"].Value = "Tsabari";
\r
89 cnBarakTsabari.Properties["telephoneNumber"].Value = "+1 906 777 8854";
\r
90 cnBarakTsabari.CommitChanges();
\r
92 #endregion // Human Resources
\r
96 DirectoryEntry ouRnD = ouPeople.Children.Add("ou=R&D","Class");
\r
97 ouRnD.Properties["objectClass"].Value = "organizationalUnit";
\r
98 ouRnD.Properties["ou"].Value = "R&D";
\r
99 ouRnD.CommitChanges();
\r
101 DirectoryEntry cnYossiCohen = ouRnD.Children.Add("cn=Yossi Cohen","Class");
\r
102 ((PropertyValueCollection)cnYossiCohen.Properties["objectClass"]).Add("person");
\r
103 ((PropertyValueCollection)cnYossiCohen.Properties["objectClass"]).Add("organizationalPerson");
\r
104 cnYossiCohen.Properties["cn"].Value = "Yossi Cohen";
\r
105 cnYossiCohen.Properties["facsimileTelephoneNumber"].Value = "+1 503 777 4498";
\r
106 ((PropertyValueCollection)cnYossiCohen.Properties["ou"]).Add("R&D");
\r
107 ((PropertyValueCollection)cnYossiCohen.Properties["ou"]).Add("People");
\r
108 cnYossiCohen.Properties["sn"].Value = "Cohen";
\r
109 cnYossiCohen.Properties["telephoneNumber"].Value = "+1 503 777 4499";
\r
110 cnYossiCohen.CommitChanges();
\r
112 DirectoryEntry cnUziCohen = ouRnD.Children.Add("cn=Uzi Cohen","Class");
\r
113 ((PropertyValueCollection)cnUziCohen.Properties["objectClass"]).Add("person");
\r
114 ((PropertyValueCollection)cnUziCohen.Properties["objectClass"]).Add("organizationalPerson");
\r
115 cnUziCohen.Properties["cn"].Value = "Uzi Cohen";
\r
116 cnUziCohen.Properties["facsimileTelephoneNumber"].Value = "+1 602 333 1234";
\r
117 ((PropertyValueCollection)cnUziCohen.Properties["ou"]).Add("R&D");
\r
118 ((PropertyValueCollection)cnUziCohen.Properties["ou"]).Add("People");
\r
119 cnUziCohen.Properties["sn"].Value = "Cohen";
\r
120 cnUziCohen.Properties["telephoneNumber"].Value = "+1 602 333 1233";
\r
121 cnUziCohen.CommitChanges();
\r
123 DirectoryEntry cnDanielCohen = ouRnD.Children.Add("cn=Daniel Cohen","Class");
\r
124 ((PropertyValueCollection)cnDanielCohen.Properties["objectClass"]).Add("person");
\r
125 ((PropertyValueCollection)cnDanielCohen.Properties["objectClass"]).Add("organizationalPerson");
\r
126 cnDanielCohen.Properties["cn"].Value = "Daniel Cohen";
\r
127 cnDanielCohen.Properties["facsimileTelephoneNumber"].Value = "+1 602 333 1235";
\r
128 ((PropertyValueCollection)cnDanielCohen.Properties["ou"]).Add("R&D");
\r
129 ((PropertyValueCollection)cnDanielCohen.Properties["ou"]).Add("People");
\r
130 cnDanielCohen.Properties["sn"].Value = "Cohen";
\r
131 cnDanielCohen.Properties["telephoneNumber"].Value = "+1 602 333 1236";
\r
132 cnDanielCohen.CommitChanges();
\r
134 DirectoryEntry cnSaraCohen = ouRnD.Children.Add("cn=Sara Cohen","Class");
\r
135 ((PropertyValueCollection)cnSaraCohen.Properties["objectClass"]).Add("person");
\r
136 ((PropertyValueCollection)cnSaraCohen.Properties["objectClass"]).Add("organizationalPerson");
\r
137 cnSaraCohen.Properties["cn"].Value = "Sara Cohen";
\r
138 cnSaraCohen.Properties["facsimileTelephoneNumber"].Value = "+1 602 333 1244";
\r
139 ((PropertyValueCollection)cnSaraCohen.Properties["ou"]).Add("R&D");
\r
140 ((PropertyValueCollection)cnSaraCohen.Properties["ou"]).Add("People");
\r
141 cnSaraCohen.Properties["sn"].Value = "Cohen";
\r
142 cnSaraCohen.Properties["telephoneNumber"].Value = "+1 602 333 1243";
\r
143 cnSaraCohen.CommitChanges();
\r
149 DirectoryEntry ouDevQA = ouPeople.Children.Add("ou=DevQA","Class");
\r
150 ouDevQA.Properties["objectClass"].Value = "organizationalUnit";
\r
151 ouDevQA.Properties["ou"].Value = "DevQA";
\r
152 ouDevQA.CommitChanges();
\r
154 DirectoryEntry cnDanielSmith = ouDevQA.Children.Add("cn=Daniel Smith","Class");
\r
155 ((PropertyValueCollection)cnDanielSmith.Properties["objectClass"]).Add("person");
\r
156 ((PropertyValueCollection)cnDanielSmith.Properties["objectClass"]).Add("organizationalPerson");
\r
157 cnDanielSmith.Properties["cn"].Value = "Daniel Smith";
\r
158 cnDanielSmith.Properties["facsimileTelephoneNumber"].Value = "+1 408 555 3372";
\r
159 cnDanielSmith.Properties["l"].Value = "Santa Clara";
\r
160 ((PropertyValueCollection)cnDanielSmith.Properties["ou"]).Add("DevQA");
\r
161 ((PropertyValueCollection)cnDanielSmith.Properties["ou"]).Add("People");
\r
162 cnDanielSmith.Properties["sn"].Value = "Smith";
\r
163 cnDanielSmith.Properties["telephoneNumber"].Value = "+1 408 555 9519";
\r
164 cnDanielSmith.CommitChanges();
\r
166 DirectoryEntry cnDanielMorgan = ouDevQA.Children.Add("cn=Daniel Morgan","Class");
\r
167 ((PropertyValueCollection)cnDanielMorgan.Properties["objectClass"]).Add("person");
\r
168 ((PropertyValueCollection)cnDanielMorgan.Properties["objectClass"]).Add("organizationalPerson");
\r
169 cnDanielMorgan.Properties["cn"].Value = "Daniel Morgan";
\r
170 cnDanielMorgan.Properties["facsimileTelephoneNumber"].Value = "+1 805 666 5645";
\r
171 ((PropertyValueCollection)cnDanielMorgan.Properties["ou"]).Add("DevQA");
\r
172 ((PropertyValueCollection)cnDanielMorgan.Properties["ou"]).Add("People");
\r
173 cnDanielMorgan.Properties["sn"].Value = "Morgan";
\r
174 cnDanielMorgan.Properties["telephoneNumber"].Value = "+1 805 666 5644";
\r
175 cnDanielMorgan.CommitChanges();
\r
177 #endregion // DevQA
\r
181 DirectoryEntry cnManager = root.Children.Add("cn=Manager","Class");
\r
182 cnManager.Properties["objectClass"].Value = "organizationalRole";
\r
183 cnManager.Properties["cn"].Value = "Manager";
\r
184 cnManager.Properties["facsimileTelephoneNumber"].Value = "+1 602 333 1238";
\r
185 cnManager.CommitChanges();
\r
187 DirectoryEntry cnUziCohen_ = cnManager.Children.Add("cn=Uzi Cohen","Class");
\r
188 ((PropertyValueCollection)cnUziCohen_.Properties["objectClass"]).Add("person");
\r
189 ((PropertyValueCollection)cnUziCohen_.Properties["objectClass"]).Add("organizationalPerson");
\r
190 cnUziCohen_.Properties["cn"].Value = "Uzi Cohen";
\r
191 cnUziCohen_.Properties["facsimileTelephoneNumber"].Value = "+1 602 333 1234";
\r
192 ((PropertyValueCollection)cnUziCohen_.Properties["ou"]).Add("R&D");
\r
193 ((PropertyValueCollection)cnUziCohen_.Properties["ou"]).Add("People");
\r
194 cnUziCohen_.Properties["sn"].Value = "Cohen";
\r
195 cnUziCohen_.Properties["telephoneNumber"].Value = "+1 602 333 1233";
\r
196 cnUziCohen_.CommitChanges();
\r
198 #endregion // Manager
\r
200 cnJohnSmith.Dispose();
\r
201 cnBarakTsabari.Dispose();
\r
202 ouHumanResources.Dispose();
\r
203 cnUziCohen.Dispose();
\r
204 cnYossiCohen.Dispose();
\r
205 cnDanielCohen.Dispose();
\r
206 cnSaraCohen.Dispose();
\r
208 cnDanielSmith.Dispose();
\r
209 cnDanielMorgan.Dispose();
\r
211 cnUziCohen_.Dispose();
\r
212 cnManager.Dispose();
\r
213 ouPeople.Dispose();
\r
219 public void TearDown()
\r
226 using (DirectoryEntry root = new DirectoryEntry( configuration.ConnectionString,
\r
227 configuration.Username,
\r
228 configuration.Password,
\r
229 configuration.AuthenticationType)) {
\r
231 foreach(DirectoryEntry child in root.Children) {
\r
232 DeleteTree_DFS(child);
\r
237 private void DeleteTree_DFS(DirectoryEntry de)
\r
239 foreach(DirectoryEntry child in de.Children) {
\r
240 DeleteTree_DFS(child);
\r
243 de.CommitChanges();
\r
246 #endregion //SetUp and TearDown
\r
251 public void DirectoryEntry_DirectoryEntry()
\r
253 de = new DirectoryEntry();
\r
255 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.None);
\r
256 Assert.AreEqual(de.Path,String.Empty);
\r
257 Assert.AreEqual(de.UsePropertyCache,true);
\r
258 Assert.AreEqual(de.Username,null);
\r
263 public void DirectoryEntry_DirectoryEntry_Str()
\r
265 using (DirectoryEntry de = new DirectoryEntry(configuration.ConnectionString)) {
\r
267 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.None);
\r
268 Assert.AreEqual(de.Name,GetName (configuration.BaseDn));
\r
269 Assert.AreEqual(de.Path,configuration.ConnectionString);
\r
270 Assert.AreEqual(de.SchemaClassName,"organization");
\r
271 Assert.AreEqual(de.UsePropertyCache,true);
\r
272 Assert.AreEqual(de.Username,null);
\r
278 public void DirectoryEntry_DirectoryEntry_StrStrStrAuth()
\r
280 if ((configuration.AuthenticationType != AuthenticationTypes.ServerBind) &&
\r
281 (configuration.AuthenticationType != AuthenticationTypes.None) &&
\r
282 (configuration.AuthenticationType != AuthenticationTypes.Anonymous))
\r
285 #region AuthenticationTypes.Anonymous
\r
287 using (DirectoryEntry de = new DirectoryEntry( configuration.ConnectionString,
\r
288 configuration.Username,
\r
289 configuration.Password,
\r
290 AuthenticationTypes.Anonymous)){
\r
292 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Anonymous);
\r
293 //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));
\r
294 Assert.AreEqual(de.Name,GetName (configuration.BaseDn));
\r
295 //Assert.AreEqual(de.NativeGuid,null);
\r
296 Assert.AreEqual(de.Path,configuration.ConnectionString);
\r
297 Assert.AreEqual(de.SchemaClassName,"organization");
\r
298 Assert.AreEqual(de.UsePropertyCache,true);
\r
299 Assert.AreEqual(de.Username,configuration.Username);
\r
302 #endregion //AuthenticationTypes.Anonymous
\r
304 #region AuthenticationTypes.Delegation
\r
306 using (DirectoryEntry de = new DirectoryEntry(configuration.ConnectionString,
\r
307 configuration.Username,
\r
308 configuration.Password,
\r
309 AuthenticationTypes.Delegation)){
\r
311 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Delegation);
\r
312 //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));
\r
313 Assert.AreEqual(de.Name,GetName (configuration.BaseDn));
\r
314 //Assert.AreEqual(de.NativeGuid,null);
\r
315 Assert.AreEqual(de.Path,configuration.ConnectionString);
\r
316 Assert.AreEqual(de.SchemaClassName,"organization");
\r
317 Assert.AreEqual(de.UsePropertyCache,true);
\r
318 Assert.AreEqual(de.Username,configuration.Username);
\r
321 #endregion //AuthenticationTypes.Delegation
\r
323 #region AuthenticationTypes.Encryption
\r
325 // de = new DirectoryEntry( configuration.ConnectionString,
\r
326 // configuration.Username,
\r
327 // configuration.Password,
\r
328 // AuthenticationTypes.Encryption);
\r
330 // Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Encryption);
\r
331 // //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));
\r
332 // Assert.AreEqual(de.Name,"dc=myhosting");
\r
333 // //Assert.AreEqual(de.NativeGuid,null);
\r
334 // Assert.AreEqual(de.Password,configuration.Password);
\r
335 // Assert.AreEqual(de.Path,configuration.ConnectionString);
\r
336 // Assert.AreEqual(de.SchemaClassName,"organization");
\r
337 // Assert.AreEqual(de.UsePropertyCache,true);
\r
338 // Assert.AreEqual(de.Username,configuration.Username);
\r
340 #endregion //AuthenticationTypes.Encryption
\r
342 #region AuthenticationTypes.FastBind
\r
344 using (DirectoryEntry de = new DirectoryEntry(configuration.ConnectionString,
\r
345 configuration.Username,
\r
346 configuration.Password,
\r
347 AuthenticationTypes.FastBind)){
\r
349 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.FastBind);
\r
350 //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));
\r
351 Assert.AreEqual(de.Name,GetName (configuration.BaseDn));
\r
352 //Assert.AreEqual(de.NativeGuid,null);
\r
353 Assert.AreEqual(de.Path,configuration.ConnectionString);
\r
354 Assert.AreEqual(de.SchemaClassName,"organization");
\r
355 Assert.AreEqual(de.UsePropertyCache,true);
\r
356 Assert.AreEqual(de.Username,configuration.Username);
\r
359 #endregion //AuthenticationTypes.FastBind
\r
361 #region AuthenticationTypes.None
\r
363 using (DirectoryEntry de = new DirectoryEntry(configuration.ConnectionString,
\r
364 configuration.Username,
\r
365 configuration.Password,
\r
366 AuthenticationTypes.None)){
\r
368 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.None);
\r
369 //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));
\r
370 Assert.AreEqual(de.Name,GetName (configuration.BaseDn));
\r
371 //Assert.AreEqual(de.NativeGuid,null);
\r
372 Assert.AreEqual(de.Path,configuration.ConnectionString);
\r
373 Assert.AreEqual(de.SchemaClassName,"organization");
\r
374 Assert.AreEqual(de.UsePropertyCache,true);
\r
375 Assert.AreEqual(de.Username,configuration.Username);
\r
378 #endregion //AuthenticationTypes.None
\r
380 #region AuthenticationTypes.ReadonlyServer
\r
382 using (DirectoryEntry de = new DirectoryEntry(configuration.ConnectionString,
\r
383 configuration.Username,
\r
384 configuration.Password,
\r
385 AuthenticationTypes.ReadonlyServer)){
\r
387 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.ReadonlyServer);
\r
388 //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));
\r
389 Assert.AreEqual(de.Name,GetName (configuration.BaseDn));
\r
390 //Assert.AreEqual(de.NativeGuid,null);
\r
391 Assert.AreEqual(de.Path,configuration.ConnectionString);
\r
392 Assert.AreEqual(de.SchemaClassName,"organization");
\r
393 Assert.AreEqual(de.UsePropertyCache,true);
\r
394 Assert.AreEqual(de.Username,configuration.Username);
\r
397 #endregion //AuthenticationTypes.ReadonlyServer
\r
399 #region AuthenticationTypes.Sealing
\r
401 using (DirectoryEntry de = new DirectoryEntry(configuration.ConnectionString,
\r
402 configuration.Username,
\r
403 configuration.Password,
\r
404 AuthenticationTypes.Sealing)){
\r
406 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Sealing);
\r
407 //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));
\r
408 Assert.AreEqual(de.Name,GetName (configuration.BaseDn));
\r
409 //Assert.AreEqual(de.NativeGuid,null);
\r
410 Assert.AreEqual(de.Path,configuration.ConnectionString);
\r
411 Assert.AreEqual(de.SchemaClassName,"organization");
\r
412 Assert.AreEqual(de.UsePropertyCache,true);
\r
413 Assert.AreEqual(de.Username,configuration.Username);
\r
416 #endregion //AuthenticationTypes.Sealing
\r
418 #region AuthenticationTypes.Secure
\r
420 // de = new DirectoryEntry(configuration.ConnectionString,
\r
421 // configuration.Username,
\r
422 // configuration.Password,
\r
423 // AuthenticationTypes.Secure);
\r
425 // Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Secure);
\r
426 // //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));
\r
427 // Assert.AreEqual(de.Name,"dc=myhosting");
\r
428 // //Assert.AreEqual(de.NativeGuid,null);
\r
429 // Assert.AreEqual(de.Password,configuration.Password);
\r
430 // Assert.AreEqual(de.Path,configuration.ConnectionString);
\r
431 // Assert.AreEqual(de.SchemaClassName,"organization");
\r
432 // Assert.AreEqual(de.UsePropertyCache,true);
\r
433 // Assert.AreEqual(de.Username,configuration.Username);
\r
435 #endregion //AuthenticationTypes.Secure
\r
437 #region AuthenticationTypes.SecureSocketsLayer
\r
439 // de = new DirectoryEntry(configuration.ConnectionString,
\r
440 // configuration.Username,
\r
441 // configuration.Password,
\r
442 // AuthenticationTypes.SecureSocketsLayer);
\r
444 // Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.SecureSocketsLayer);
\r
445 // //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));
\r
446 // Assert.AreEqual(de.Name,"dc=myhosting");
\r
447 // //Assert.AreEqual(de.NativeGuid,null);
\r
448 // Assert.AreEqual(de.Password,configuration.Password);
\r
449 // Assert.AreEqual(de.Path,configuration.ConnectionString);
\r
450 // Assert.AreEqual(de.SchemaClassName,"organization");
\r
451 // Assert.AreEqual(de.UsePropertyCache,true);
\r
452 // Assert.AreEqual(de.Username,configuration.Username);
\r
454 #endregion //AuthenticationTypes.SecureSocketsLayer
\r
456 #region AuthenticationTypes.ServerBind
\r
458 using (DirectoryEntry de = new DirectoryEntry(configuration.ConnectionString,
\r
459 configuration.Username,
\r
460 configuration.Password,
\r
461 AuthenticationTypes.ServerBind)){
\r
463 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.ServerBind);
\r
464 //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));
\r
465 Assert.AreEqual(de.Name,GetName (configuration.BaseDn));
\r
466 //Assert.AreEqual(de.NativeGuid,null);
\r
467 Assert.AreEqual(de.Path,configuration.ConnectionString);
\r
468 Assert.AreEqual(de.SchemaClassName,"organization");
\r
469 Assert.AreEqual(de.UsePropertyCache,true);
\r
470 Assert.AreEqual(de.Username,configuration.Username);
\r
473 #endregion //AuthenticationTypes.ServerBind
\r
475 #region AuthenticationTypes.Signing
\r
477 using (DirectoryEntry de = new DirectoryEntry(configuration.ConnectionString,
\r
478 configuration.Username,
\r
479 configuration.Password,
\r
480 AuthenticationTypes.Signing)){
\r
482 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Signing);
\r
483 //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));
\r
484 Assert.AreEqual(de.Name,GetName (configuration.BaseDn));
\r
485 //Assert.AreEqual(de.NativeGuid,null);
\r
486 Assert.AreEqual(de.Path,configuration.ConnectionString);
\r
487 Assert.AreEqual(de.SchemaClassName,"organization");
\r
488 Assert.AreEqual(de.UsePropertyCache,true);
\r
489 Assert.AreEqual(de.Username,configuration.Username);
\r
492 #endregion //AuthenticationTypes.Signing
\r
496 public void DirectoryEntry_Dispose()
\r
498 using (DirectoryEntry root = new DirectoryEntry( configuration.ConnectionString,
\r
499 configuration.Username,
\r
500 configuration.Password,
\r
501 configuration.AuthenticationType)){
\r
503 DirectoryEntry ouPeople = root.Children.Add("ou=printers","Class");
\r
504 ouPeople.Properties["objectClass"].Value = "organizationalUnit";
\r
505 ouPeople.Properties["description"].Value = "All printers in organisation";
\r
506 ouPeople.Properties["ou"].Value = "printers";
\r
507 ouPeople.CommitChanges();
\r
509 ouPeople.Rename("ou=anotherPrinters");
\r
510 ouPeople.CommitChanges();
\r
512 Assert.IsTrue(DirectoryEntry.Exists(configuration.ServerRoot + "ou=anotherPrinters" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn))));
\r
518 public void DirectoryEntry_AuthenticationType()
\r
520 de = new DirectoryEntry();
\r
522 de.AuthenticationType = AuthenticationTypes.Anonymous;
\r
523 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Anonymous);
\r
525 de.AuthenticationType = AuthenticationTypes.Delegation;
\r
526 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Delegation);
\r
528 de.AuthenticationType = AuthenticationTypes.Encryption;
\r
529 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Encryption);
\r
531 de.AuthenticationType = AuthenticationTypes.FastBind;
\r
532 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.FastBind);
\r
534 de.AuthenticationType = AuthenticationTypes.None;
\r
535 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.None);
\r
537 de.AuthenticationType = AuthenticationTypes.ReadonlyServer;
\r
538 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.ReadonlyServer);
\r
540 de.AuthenticationType = AuthenticationTypes.Sealing;
\r
541 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Sealing);
\r
543 de.AuthenticationType = AuthenticationTypes.Secure;
\r
544 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Secure);
\r
546 de.AuthenticationType = AuthenticationTypes.SecureSocketsLayer;
\r
547 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.SecureSocketsLayer);
\r
549 de.AuthenticationType = AuthenticationTypes.ServerBind;
\r
550 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.ServerBind);
\r
552 de.AuthenticationType = AuthenticationTypes.Signing;
\r
553 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Signing);
\r
555 de = new DirectoryEntry(configuration.ConnectionString);
\r
557 de.AuthenticationType = AuthenticationTypes.Anonymous;
\r
558 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Anonymous);
\r
560 de.AuthenticationType = AuthenticationTypes.Delegation;
\r
561 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Delegation);
\r
563 de.AuthenticationType = AuthenticationTypes.Encryption;
\r
564 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Encryption);
\r
566 de.AuthenticationType = AuthenticationTypes.FastBind;
\r
567 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.FastBind);
\r
569 de.AuthenticationType = AuthenticationTypes.None;
\r
570 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.None);
\r
572 de.AuthenticationType = AuthenticationTypes.ReadonlyServer;
\r
573 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.ReadonlyServer);
\r
575 de.AuthenticationType = AuthenticationTypes.Sealing;
\r
576 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Sealing);
\r
578 de.AuthenticationType = AuthenticationTypes.Secure;
\r
579 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Secure);
\r
581 de.AuthenticationType = AuthenticationTypes.SecureSocketsLayer;
\r
582 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.SecureSocketsLayer);
\r
584 de.AuthenticationType = AuthenticationTypes.ServerBind;
\r
585 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.ServerBind);
\r
587 de.AuthenticationType = AuthenticationTypes.Signing;
\r
588 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Signing);
\r
590 de = new DirectoryEntry(configuration.ConnectionString,
\r
591 configuration.Username,
\r
592 configuration.Password,
\r
593 AuthenticationTypes.None);
\r
595 de.AuthenticationType = AuthenticationTypes.Anonymous;
\r
596 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Anonymous);
\r
598 de.AuthenticationType = AuthenticationTypes.Delegation;
\r
599 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Delegation);
\r
601 de.AuthenticationType = AuthenticationTypes.Encryption;
\r
602 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Encryption);
\r
604 de.AuthenticationType = AuthenticationTypes.FastBind;
\r
605 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.FastBind);
\r
607 de.AuthenticationType = AuthenticationTypes.None;
\r
608 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.None);
\r
610 de.AuthenticationType = AuthenticationTypes.ReadonlyServer;
\r
611 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.ReadonlyServer);
\r
613 de.AuthenticationType = AuthenticationTypes.Sealing;
\r
614 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Sealing);
\r
616 de.AuthenticationType = AuthenticationTypes.Secure;
\r
617 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Secure);
\r
619 de.AuthenticationType = AuthenticationTypes.SecureSocketsLayer;
\r
620 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.SecureSocketsLayer);
\r
622 de.AuthenticationType = AuthenticationTypes.ServerBind;
\r
623 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.ServerBind);
\r
625 de.AuthenticationType = AuthenticationTypes.Signing;
\r
626 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Signing);
\r
631 public void DirectoryEntry_UsePropertyCache()
\r
633 string barakTsabariDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
634 de = new DirectoryEntry(barakTsabariDN,
\r
635 configuration.Username,
\r
636 configuration.Password,
\r
637 configuration.AuthenticationType);
\r
639 // UsePropertyCache = true
\r
640 de.UsePropertyCache = true;
\r
641 Assert.AreEqual(de.UsePropertyCache,true);
\r
643 #region Check Properties
\r
645 // Properties changes are cached
\r
646 string oldTelephoneNumber = (string)de.Properties["telephoneNumber"].Value;
\r
647 string newTelephoneNumber = "+972-3-6572345";
\r
649 de.Properties["telephoneNumber"].Value = newTelephoneNumber;
\r
650 using (DirectoryEntry barakTsabariDE = new DirectoryEntry( barakTsabariDN,
\r
651 configuration.Username,
\r
652 configuration.Password,
\r
653 configuration.AuthenticationType)){
\r
655 Assert.AreEqual(barakTsabariDE.Properties["telephoneNumber"].Value,oldTelephoneNumber);
\r
656 de.CommitChanges();
\r
658 using (DirectoryEntry barakTsabariDE = new DirectoryEntry(barakTsabariDN,
\r
659 configuration.Username,
\r
660 configuration.Password,
\r
661 configuration.AuthenticationType)){
\r
662 Assert.AreEqual(barakTsabariDE.Properties["telephoneNumber"].Value,newTelephoneNumber);
\r
664 // restore object state
\r
665 de.Properties["telephoneNumber"].Value = oldTelephoneNumber;
\r
666 de.CommitChanges();
\r
669 #endregion // Check Properties
\r
671 #region Check DeleteTree
\r
673 // DeleteTree is not cached
\r
676 using (DirectoryEntry barakTsabariDE = new DirectoryEntry(barakTsabariDN,
\r
677 configuration.Username,
\r
678 configuration.Password,
\r
679 configuration.AuthenticationType)){
\r
680 barakTsabariDE.Properties["telephoneNumber"].Value = newTelephoneNumber;
\r
681 barakTsabariDE.CommitChanges();
\r
682 Assert.Fail("Object " + barakTsabariDN + " was not deleted from server.");
\r
685 catch(AssertionException ae) {
\r
688 catch (Exception e) {
\r
692 // restore object state
\r
693 using (DirectoryEntry ouHumanResources = new DirectoryEntry( configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
\r
694 configuration.Username,
\r
695 configuration.Password,
\r
696 configuration.AuthenticationType)){
\r
697 using (DirectoryEntry cnBarakTsabari = ouHumanResources.Children.Add("cn=Barak Tsabari","Class")){
\r
698 ((PropertyValueCollection)cnBarakTsabari.Properties["objectClass"]).Add("person");
\r
699 ((PropertyValueCollection)cnBarakTsabari.Properties["objectClass"]).Add("organizationalPerson");
\r
700 cnBarakTsabari.Properties["cn"].Value = "Barak Tsabari";
\r
701 cnBarakTsabari.Properties["facsimileTelephoneNumber"].Value = "+1 906 777 8853";
\r
702 ((PropertyValueCollection)cnBarakTsabari.Properties["ou"]).Add("Human Resources");
\r
703 ((PropertyValueCollection)cnBarakTsabari.Properties["ou"]).Add("People");
\r
704 cnBarakTsabari.Properties["sn"].Value = "Tsabari";
\r
705 cnBarakTsabari.Properties["telephoneNumber"].Value = "+1 906 777 8854";
\r
706 cnBarakTsabari.CommitChanges();
\r
710 #endregion // Check DeleteTree
\r
712 #region Check MoveTo
\r
714 // Move to is not cached
\r
715 de = new DirectoryEntry(barakTsabariDN,
\r
716 configuration.Username,
\r
717 configuration.Password,
\r
718 configuration.AuthenticationType);
\r
720 using (DirectoryEntry ouRnD = new DirectoryEntry( configuration.ServerRoot + "ou=R&D,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
\r
721 configuration.Username,
\r
722 configuration.Password,
\r
723 configuration.AuthenticationType)){
\r
726 using (DirectoryEntry barakTsabariDE = new DirectoryEntry(barakTsabariDN,
\r
727 configuration.Username,
\r
728 configuration.Password,
\r
729 configuration.AuthenticationType)){
\r
730 barakTsabariDE.Properties["telephoneNumber"].Value = newTelephoneNumber;
\r
731 barakTsabariDE.CommitChanges();
\r
732 Assert.Fail("Object " + barakTsabariDN + " was not moved from old location on the server.");
\r
735 catch(AssertionException ae) {
\r
738 catch (Exception e) {
\r
743 using (DirectoryEntry barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=Barak Tsabari,ou=R&D,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
\r
744 configuration.Username,
\r
745 configuration.Password,
\r
746 configuration.AuthenticationType)){
\r
747 Assert.AreEqual(barakTsabariDE.Properties["telephoneNumber"].Value,oldTelephoneNumber);
\r
751 // restore object state
\r
752 using (DirectoryEntry ouHumanResources = new DirectoryEntry( configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
\r
753 configuration.Username,
\r
754 configuration.Password,
\r
755 configuration.AuthenticationType)){
\r
756 using (DirectoryEntry barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=Barak Tsabari,ou=R&D,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
\r
757 configuration.Username,
\r
758 configuration.Password,
\r
759 configuration.AuthenticationType)){
\r
760 barakTsabariDE.MoveTo(ouHumanResources);
\r
761 barakTsabariDE.CommitChanges();
\r
765 #endregion // Check MoveTo
\r
767 #region Check Rename
\r
769 // Rename not chached
\r
770 de = new DirectoryEntry(barakTsabariDN,
\r
771 configuration.Username,
\r
772 configuration.Password,
\r
773 configuration.AuthenticationType);
\r
775 de.Rename("cn=MyUser");
\r
778 using (DirectoryEntry barakTsabariDE = new DirectoryEntry(barakTsabariDN,
\r
779 configuration.Username,
\r
780 configuration.Password,
\r
781 configuration.AuthenticationType)){
\r
782 barakTsabariDE.Properties["telephoneNumber"].Value = newTelephoneNumber;
\r
783 barakTsabariDE.CommitChanges();
\r
784 Assert.Fail("Object " + barakTsabariDN + " was not renamed on the server.");
\r
787 catch(AssertionException ae) {
\r
790 catch (Exception e) {
\r
794 using (DirectoryEntry barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=MyUser,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
\r
795 configuration.Username,
\r
796 configuration.Password,
\r
797 configuration.AuthenticationType)){
\r
798 Assert.AreEqual(barakTsabariDE.Properties["telephoneNumber"].Value,oldTelephoneNumber);
\r
801 // restore object state
\r
802 using (DirectoryEntry barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=MyUser,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
\r
803 configuration.Username,
\r
804 configuration.Password,
\r
805 configuration.AuthenticationType)){
\r
806 barakTsabariDE.Rename("cn=Barak Tsabari");
\r
807 barakTsabariDE.CommitChanges();
\r
810 #endregion // Check Rename
\r
812 // UsePropertyCache = false
\r
813 de = new DirectoryEntry(barakTsabariDN,
\r
814 configuration.Username,
\r
815 configuration.Password,
\r
816 configuration.AuthenticationType);
\r
817 de.UsePropertyCache = false;
\r
818 Assert.AreEqual(de.UsePropertyCache,false);
\r
820 #region Check Properties
\r
822 // Properties changes not cached
\r
823 de.Properties["telephoneNumber"].Value = newTelephoneNumber;
\r
824 using (DirectoryEntry barakTsabariDE = new DirectoryEntry(barakTsabariDN,
\r
825 configuration.Username,
\r
826 configuration.Password,
\r
827 configuration.AuthenticationType)){
\r
830 //Assert.AreEqual(barakTsabariDE.Properties["telephoneNumber"].Value,newTelephoneNumber);
\r
832 #endregion // Check Properties
\r
834 #region Check DeleteTree
\r
836 // DeleteTree is not cached
\r
839 using (DirectoryEntry barakTsabariDE = new DirectoryEntry(barakTsabariDN,
\r
840 configuration.Username,
\r
841 configuration.Password,
\r
842 configuration.AuthenticationType)){
\r
843 barakTsabariDE.Properties["telephoneNumber"].Value = newTelephoneNumber;
\r
844 barakTsabariDE.CommitChanges();
\r
845 Assert.Fail("Object " + barakTsabariDN + " was not deleted from server.");
\r
848 catch(AssertionException ae) {
\r
851 catch (Exception e) {
\r
855 // restore object state
\r
856 using (DirectoryEntry ouHumanResources = new DirectoryEntry( configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
\r
857 configuration.Username,
\r
858 configuration.Password,
\r
859 configuration.AuthenticationType)){
\r
860 using (DirectoryEntry cnBarakTsabari = ouHumanResources.Children.Add("cn=Barak Tsabari","Class")){
\r
861 ((PropertyValueCollection)cnBarakTsabari.Properties["objectClass"]).Add("person");
\r
862 ((PropertyValueCollection)cnBarakTsabari.Properties["objectClass"]).Add("organizationalPerson");
\r
863 cnBarakTsabari.Properties["cn"].Value = "Barak Tsabari";
\r
864 cnBarakTsabari.Properties["facsimileTelephoneNumber"].Value = "+1 906 777 8853";
\r
865 ((PropertyValueCollection)cnBarakTsabari.Properties["ou"]).Add("Human Resources");
\r
866 ((PropertyValueCollection)cnBarakTsabari.Properties["ou"]).Add("People");
\r
867 cnBarakTsabari.Properties["sn"].Value = "Tsabari";
\r
868 cnBarakTsabari.Properties["telephoneNumber"].Value = "+1 906 777 8854";
\r
869 cnBarakTsabari.CommitChanges();
\r
873 #endregion // Check DeleteTree
\r
875 #region Check MoveTo
\r
877 // Move to is not cached
\r
878 de = new DirectoryEntry(barakTsabariDN,
\r
879 configuration.Username,
\r
880 configuration.Password,
\r
881 configuration.AuthenticationType);
\r
883 using (DirectoryEntry ouRnD = new DirectoryEntry( configuration.ServerRoot + "ou=R&D,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
\r
884 configuration.Username,
\r
885 configuration.Password,
\r
886 configuration.AuthenticationType)){
\r
890 using (DirectoryEntry barakTsabariDE = new DirectoryEntry(barakTsabariDN,
\r
891 configuration.Username,
\r
892 configuration.Password,
\r
893 configuration.AuthenticationType)){
\r
894 barakTsabariDE.Properties["telephoneNumber"].Value = newTelephoneNumber;
\r
895 barakTsabariDE.CommitChanges();
\r
896 Assert.Fail("Object " + barakTsabariDN + " was not moved from old location on the server.");
\r
899 catch(AssertionException ae) {
\r
902 catch (Exception e) {
\r
907 using (DirectoryEntry barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=Barak Tsabari,ou=R&D,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
\r
908 configuration.Username,
\r
909 configuration.Password,
\r
910 configuration.AuthenticationType)){
\r
911 Assert.AreEqual(barakTsabariDE.Properties["telephoneNumber"].Value,oldTelephoneNumber);
\r
915 // restore object state
\r
916 using (DirectoryEntry ouHumanResources = new DirectoryEntry( configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
\r
917 configuration.Username,
\r
918 configuration.Password,
\r
919 configuration.AuthenticationType)){
\r
920 using (DirectoryEntry barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=Barak Tsabari,ou=R&D,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
\r
921 configuration.Username,
\r
922 configuration.Password,
\r
923 configuration.AuthenticationType)){
\r
924 barakTsabariDE.MoveTo(ouHumanResources);
\r
925 barakTsabariDE.CommitChanges();
\r
929 #endregion // Check MoveTo
\r
931 #region Check Rename
\r
933 // Rename not chached
\r
934 de = new DirectoryEntry(barakTsabariDN,
\r
935 configuration.Username,
\r
936 configuration.Password,
\r
937 configuration.AuthenticationType);
\r
939 de.Rename("cn=MyUser");
\r
942 using (DirectoryEntry barakTsabariDE = new DirectoryEntry(barakTsabariDN,
\r
943 configuration.Username,
\r
944 configuration.Password,
\r
945 configuration.AuthenticationType)){
\r
946 barakTsabariDE.Properties["telephoneNumber"].Value = newTelephoneNumber;
\r
947 barakTsabariDE.CommitChanges();
\r
948 Assert.Fail("Object " + barakTsabariDN + " was not renamed on the server.");
\r
951 catch(AssertionException ae) {
\r
954 catch (Exception e) {
\r
958 using (DirectoryEntry barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=MyUser,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
\r
959 configuration.Username,
\r
960 configuration.Password,
\r
961 configuration.AuthenticationType)){
\r
962 Assert.AreEqual(barakTsabariDE.Properties["telephoneNumber"].Value,oldTelephoneNumber);
\r
965 // restore object state
\r
966 using (DirectoryEntry barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=MyUser,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
\r
967 configuration.Username,
\r
968 configuration.Password,
\r
969 configuration.AuthenticationType)){
\r
970 barakTsabariDE.Rename("cn=Barak Tsabari");
\r
971 barakTsabariDE.CommitChanges();
\r
974 #endregion // Check Rename
\r
978 [Category("NotWorking")]
\r
979 public void DirectoryEntry_Children()
\r
981 de = new DirectoryEntry();
\r
982 DirectoryEntries children = de.Children;
\r
983 //Assert.AreEqual(children.SchemaFilter.Count,0);
\r
986 de = new DirectoryEntry(configuration.ConnectionString);
\r
987 children = de.Children;
\r
989 //Assert.AreEqual(children.SchemaFilter.Count,0);
\r
991 int childrenCount = 0;
\r
992 foreach(DirectoryEntry childDe in children) {
\r
995 Assert.AreEqual(childrenCount,2);
\r
996 Assert.AreEqual(children.Find("ou=people").Name,"ou=people");
\r
997 Assert.AreEqual(children.Find("cn=Manager").Name,"cn=Manager");
\r
1000 de = new DirectoryEntry(configuration.ConnectionString,
\r
1001 configuration.Username,
\r
1002 configuration.Password,
\r
1003 configuration.AuthenticationType);
\r
1004 children = de.Children;
\r
1006 //Assert.AreEqual(children.SchemaFilter.Count,0);
\r
1008 childrenCount = 0;
\r
1009 foreach(DirectoryEntry childDe in children) {
\r
1012 Assert.AreEqual(childrenCount,2);
\r
1013 Assert.AreEqual(children.Find("ou=people").Name,"ou=people");
\r
1014 Assert.AreEqual(children.Find("cn=Manager").Name,"cn=Manager");
\r
1016 de = new DirectoryEntry(configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)) ,
\r
1017 configuration.Username,
\r
1018 configuration.Password,
\r
1019 configuration.AuthenticationType);
\r
1020 children = de.Children;
\r
1022 Assert.AreEqual(children.Find("cn=Barak Tsabari").Name,"cn=Barak Tsabari");
\r
1023 Assert.AreEqual(children.Find("cn=John Smith").Name,"cn=John Smith");
\r
1027 public void DirectoryEntry_Name()
\r
1029 de = new DirectoryEntry(configuration.ConnectionString);
\r
1031 de = new DirectoryEntry(configuration.ConnectionString,
\r
1032 configuration.Username,
\r
1033 configuration.Password,
\r
1034 configuration.AuthenticationType);
\r
1036 de = new DirectoryEntry(configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)) ,
\r
1037 configuration.Username,
\r
1038 configuration.Password,
\r
1039 configuration.AuthenticationType);
\r
1040 Assert.AreEqual(de.Name,"ou=Human Resources");
\r
1042 de = new DirectoryEntry(configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)) ,
\r
1043 configuration.Username,
\r
1044 configuration.Password,
\r
1045 configuration.AuthenticationType);
\r
1046 Assert.AreEqual(de.Name,"cn=Barak Tsabari");
\r
1051 public void DirectoryEntry_Parent()
\r
1053 de = new DirectoryEntry(configuration.ConnectionString);
\r
1055 // MS works only with "LDAP" while RFC2255 states "ldap"
\r
1056 Assert.AreEqual(de.Parent.Path.ToLower(),(configuration.ServerRoot + GetParentDN (configuration.BaseDn)).ToLower());
\r
1058 de = new DirectoryEntry(configuration.ConnectionString,
\r
1059 configuration.Username,
\r
1060 configuration.Password,
\r
1061 configuration.AuthenticationType);
\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
1066 de = new DirectoryEntry(configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)) ,
\r
1067 configuration.Username,
\r
1068 configuration.Password,
\r
1069 configuration.AuthenticationType);
\r
1071 // MS works only with "LDAP" while RFC2255 states "ldap"
\r
1072 Assert.AreEqual(de.Parent.Path.ToLower(),(configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn))).ToLower());
\r
1077 public void DirectoryEntry_Path()
\r
1079 string wrongPath = "something that is not LDAP path";
\r
1081 de = new DirectoryEntry();
\r
1083 Assert.AreEqual(de.Path,String.Empty);
\r
1085 de.Path = configuration.ConnectionString;
\r
1086 Assert.AreEqual(de.Path,configuration.ConnectionString);
\r
1089 Assert.AreEqual(de.Path,String.Empty);
\r
1091 de.Path = wrongPath;
\r
1092 Assert.AreEqual(de.Path,wrongPath);
\r
1095 de = new DirectoryEntry(configuration.ConnectionString);
\r
1097 de.Path = configuration.ConnectionString;
\r
1098 Assert.AreEqual(de.Path,configuration.ConnectionString);
\r
1101 Assert.AreEqual(de.Path,String.Empty);
\r
1103 de.Path = wrongPath;
\r
1104 Assert.AreEqual(de.Path,wrongPath);
\r
1107 de = new DirectoryEntry(configuration.ConnectionString,
\r
1108 configuration.Username,
\r
1109 configuration.Password,
\r
1110 configuration.AuthenticationType);
\r
1112 de.Path = configuration.ConnectionString;
\r
1113 Assert.AreEqual(de.Path,configuration.ConnectionString);
\r
1116 Assert.AreEqual(de.Path,String.Empty);
\r
1118 de.Path = wrongPath;
\r
1119 Assert.AreEqual(de.Path,wrongPath);
\r
1121 de = new DirectoryEntry("ldap://myhost:389/ou=people",null,null,AuthenticationTypes.None);
\r
1122 Assert.AreEqual(de.Path,"ldap://myhost:389/ou=people");
\r
1125 Assert.AreEqual(de.Path,String.Empty);
\r
1130 public void DirectoryEntry_Properties1()
\r
1132 de = new DirectoryEntry(configuration.ConnectionString);
\r
1134 Assert.AreEqual(de.Properties.Count,3);
\r
1135 Assert.AreEqual(((PropertyValueCollection)de.Properties["dc"]).Value,"example");
\r
1136 Assert.AreEqual(((PropertyValueCollection)de.Properties["description"]).Value,null);
\r
1139 de = new DirectoryEntry(configuration.ConnectionString,
\r
1140 configuration.Username,
\r
1141 configuration.Password,
\r
1142 configuration.AuthenticationType);
\r
1144 Assert.AreEqual(de.Properties.Count,3);
\r
1145 Assert.AreEqual(((PropertyValueCollection)de.Properties["dc"]).Value,"example");
\r
1146 Assert.AreEqual(((PropertyValueCollection)de.Properties["description"]).Value,null);
\r
1148 // ensure that properties are not accessible after removing an entry from the server
\r
1149 string barakTsabariDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1150 de = new DirectoryEntry(barakTsabariDN,
\r
1151 configuration.Username,
\r
1152 configuration.Password,
\r
1153 configuration.AuthenticationType);
\r
1158 int i = de.Properties.Count;
\r
1159 Assert.Fail("Properties should not be accessible after deleting an entry from the server");
\r
1161 catch(AssertionException ae) {
\r
1164 catch(Exception e) {
\r
1165 // supress exception
\r
1169 string s = (string)((PropertyValueCollection)de.Properties["dc"]).Value;
\r
1170 Assert.Fail("Properties should not be accessible after deleting an entry from the server");
\r
1172 catch(AssertionException ae) {
\r
1175 catch(Exception e) {
\r
1176 // supress exception
\r
1181 public void DirectoryEntry_Properties2()
\r
1183 // delete entry, create a new one (the same) and access properties of the old object
\r
1184 string barakTsabariDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1185 de = new DirectoryEntry(barakTsabariDN,
\r
1186 configuration.Username,
\r
1187 configuration.Password,
\r
1188 configuration.AuthenticationType);
\r
1190 // cause to properties loading
\r
1191 Assert.AreEqual(de.Properties.Count,6);
\r
1192 Assert.AreEqual(((PropertyValueCollection)de.Properties["sn"]).Value,"Tsabari");
\r
1197 // the local property chache is still accessible
\r
1198 Assert.AreEqual(de.Properties.Count,6);
\r
1199 Assert.AreEqual(((PropertyValueCollection)de.Properties["sn"]).Value,"Tsabari");
\r
1201 de.CommitChanges();
\r
1203 // the local property chache is still accessible
\r
1204 ((PropertyValueCollection)de.Properties["sn"]).Value = "Barbari";
\r
1206 // create the entry back again
\r
1207 using (DirectoryEntry ouHumanResources = new DirectoryEntry( configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
\r
1208 configuration.Username,
\r
1209 configuration.Password,
\r
1210 configuration.AuthenticationType)){
\r
1211 using (DirectoryEntry cnBarakTsabari = ouHumanResources.Children.Add("cn=Barak Tsabari","Class")){
\r
1212 ((PropertyValueCollection)cnBarakTsabari.Properties["objectClass"]).Add("person");
\r
1213 ((PropertyValueCollection)cnBarakTsabari.Properties["objectClass"]).Add("organizationalPerson");
\r
1214 cnBarakTsabari.Properties["cn"].Value = "Barak Tsabari";
\r
1215 cnBarakTsabari.Properties["facsimileTelephoneNumber"].Value = "+1 906 777 8853";
\r
1216 ((PropertyValueCollection)cnBarakTsabari.Properties["ou"]).Add("Human Resources");
\r
1217 ((PropertyValueCollection)cnBarakTsabari.Properties["ou"]).Add("People");
\r
1218 cnBarakTsabari.Properties["sn"].Value = "Tsabari";
\r
1219 cnBarakTsabari.Properties["telephoneNumber"].Value = "+1 906 777 8854";
\r
1220 cnBarakTsabari.CommitChanges();
\r
1224 // the local property chache is still accessible
\r
1225 Assert.AreEqual(((PropertyValueCollection)de.Properties["sn"]).Value,"Barbari");
\r
1227 // Refresh from server
\r
1228 de.RefreshCache();
\r
1229 // ensure the properties of an entry are still accessible through the old object
\r
1230 Assert.AreEqual(((PropertyValueCollection)de.Properties["sn"]).Value,"Tsabari");
\r
1236 [Category("NotWorking")]
\r
1237 public void DirectoryEntry_SchemaClassName()
\r
1239 de = new DirectoryEntry();
\r
1240 Assert.AreEqual(de.SchemaClassName,"domainDNS");
\r
1243 de = new DirectoryEntry(configuration.ConnectionString);
\r
1244 Assert.AreEqual(de.SchemaClassName,"organization");
\r
1247 de = new DirectoryEntry(configuration.ConnectionString,
\r
1248 configuration.Username,
\r
1249 configuration.Password,
\r
1250 configuration.AuthenticationType);
\r
1251 Assert.AreEqual(de.SchemaClassName,"organization");
\r
1253 DirectoryEntry de2 = de.Children.Add("ou=My Child","Class");
\r
1254 Assert.AreEqual(de2.SchemaClassName,"Class");
\r
1255 Assert.AreEqual(((PropertyValueCollection)de2.Properties["structuralObjectClass"]).Value,null);
\r
1259 [Category("NotWorking")]
\r
1260 public void DirectoryEntry_SchemaEntry()
\r
1262 de = new DirectoryEntry();
\r
1263 DirectoryEntry schemaEntry = de.SchemaEntry;
\r
1265 // MS works only with "LDAP" while RFC2255 states "ldap"
\r
1266 Assert.AreEqual(schemaEntry.Path.ToLower(),"LDAP://schema/domainDNS".ToLower());
\r
1267 Assert.AreEqual(schemaEntry.Name,"domainDNS");
\r
1268 Assert.AreEqual(schemaEntry.Username,null);
\r
1269 Assert.AreEqual(schemaEntry.UsePropertyCache,true);
\r
1270 Assert.AreEqual(schemaEntry.SchemaClassName,"Class");
\r
1271 Assert.AreEqual(schemaEntry.AuthenticationType,AuthenticationTypes.None);
\r
1274 de = new DirectoryEntry(configuration.ConnectionString);
\r
1275 schemaEntry = de.SchemaEntry;
\r
1277 Assert.AreEqual(schemaEntry.Path,configuration.ServerRoot + "schema/organization");
\r
1278 Assert.AreEqual(schemaEntry.Name,"organization");
\r
1279 Assert.AreEqual(schemaEntry.Username,null);
\r
1280 Assert.AreEqual(schemaEntry.UsePropertyCache,true);
\r
1281 Assert.AreEqual(schemaEntry.SchemaClassName,"Class");
\r
1282 Assert.AreEqual(schemaEntry.AuthenticationType,AuthenticationTypes.None);
\r
1285 de = new DirectoryEntry(configuration.ConnectionString,
\r
1286 configuration.Username,
\r
1287 configuration.Password,
\r
1288 configuration.AuthenticationType);
\r
1289 schemaEntry = de.SchemaEntry;
\r
1291 Assert.AreEqual(schemaEntry.Path,configuration.ServerRoot + "schema/organization");
\r
1292 Assert.AreEqual(schemaEntry.Name,"organization");
\r
1293 Assert.AreEqual(schemaEntry.Username,configuration.Username);
\r
1294 Assert.AreEqual(schemaEntry.UsePropertyCache,true);
\r
1295 Assert.AreEqual(schemaEntry.SchemaClassName,"Class");
\r
1296 Assert.AreEqual(schemaEntry.AuthenticationType,configuration.AuthenticationType);
\r
1301 public void DirectoryEntry_Username()
\r
1303 string wrongUsername = "some wrong username";
\r
1305 de = new DirectoryEntry();
\r
1307 Assert.AreEqual(de.Username,null);
\r
1309 de.Username = configuration.Username;
\r
1310 Assert.AreEqual(de.Username,configuration.Username);
\r
1313 Assert.AreEqual(de.Username,String.Empty);
\r
1315 de.Username = wrongUsername;
\r
1316 Assert.AreEqual(de.Username,wrongUsername);
\r
1319 de = new DirectoryEntry(configuration.ConnectionString);
\r
1321 de.Username = configuration.Username;
\r
1322 Assert.AreEqual(de.Username,configuration.Username);
\r
1325 Assert.AreEqual(de.Username,String.Empty);
\r
1327 de.Username = wrongUsername;
\r
1328 Assert.AreEqual(de.Username,wrongUsername);
\r
1331 de = new DirectoryEntry(configuration.ConnectionString,
\r
1332 configuration.Username,
\r
1333 configuration.Password,
\r
1334 configuration.AuthenticationType);
\r
1336 de.Username = configuration.Username;
\r
1337 Assert.AreEqual(de.Username,configuration.Username);
\r
1340 Assert.AreEqual(de.Username,String.Empty);
\r
1342 de.Username = wrongUsername;
\r
1343 Assert.AreEqual(de.Username,wrongUsername);
\r
1348 public void DirectoryEntry_Close()
\r
1350 de = new DirectoryEntry();
\r
1353 de = new DirectoryEntry(configuration.ConnectionString);
\r
1356 de = new DirectoryEntry(configuration.ConnectionString,
\r
1357 configuration.Username,
\r
1358 configuration.Password,
\r
1359 configuration.AuthenticationType);
\r
1365 public void DirectoryEntry_CommitChanges1()
\r
1367 string humanResourcesDN = configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1368 using (DirectoryEntry ouHumanResources = new DirectoryEntry( humanResourcesDN,
\r
1369 configuration.Username,
\r
1370 configuration.Password,
\r
1371 configuration.AuthenticationType)){
\r
1374 string newEmployeeDN = configuration.ServerRoot + "cn=New Employee,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1375 de = ouHumanResources.Children.Add("cn=New Employee","Class");
\r
1376 Assert.IsFalse(DirectoryEntry.Exists(newEmployeeDN));
\r
1378 de.Properties["objectClass"].Value = "organizationalRole";
\r
1379 de.Properties["cn"].Value = "New Employee";
\r
1380 Assert.IsFalse(DirectoryEntry.Exists(newEmployeeDN));
\r
1382 de.CommitChanges();
\r
1383 Assert.IsTrue(DirectoryEntry.Exists(newEmployeeDN));
\r
1387 string barakTsabariDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1388 de = new DirectoryEntry(barakTsabariDN,
\r
1389 configuration.Username,
\r
1390 configuration.Password,
\r
1391 configuration.AuthenticationType);
\r
1393 string oldTelephone = (string)((PropertyValueCollection)de.Properties["telephoneNumber"]).Value;
\r
1394 string newTelephone = "+972 3 6078596";
\r
1396 // UsePropertyCache - true
\r
1397 de.UsePropertyCache = true;
\r
1398 ((PropertyValueCollection)de.Properties["telephoneNumber"]).Value = newTelephone;
\r
1399 Assert.AreEqual(((PropertyValueCollection)de.Properties["telephoneNumber"]).Value,newTelephone);
\r
1401 using (DirectoryEntry cnBarakTsabari = new DirectoryEntry( barakTsabariDN,
\r
1402 configuration.Username,
\r
1403 configuration.Password,
\r
1404 configuration.AuthenticationType)){
\r
1406 //check that on server there is still an old value
\r
1407 Assert.AreEqual(((PropertyValueCollection)cnBarakTsabari.Properties["telephoneNumber"]).Value,oldTelephone);
\r
1409 de.CommitChanges();
\r
1412 using (DirectoryEntry cnBarakTsabari = new DirectoryEntry(barakTsabariDN,
\r
1413 configuration.Username,
\r
1414 configuration.Password,
\r
1415 configuration.AuthenticationType)){
\r
1417 // check that new value is updated on the server
\r
1418 Assert.AreEqual(((PropertyValueCollection)cnBarakTsabari.Properties["telephoneNumber"]).Value,newTelephone);
\r
1421 // UsePropertyCache - false
\r
1422 de = new DirectoryEntry(barakTsabariDN,
\r
1423 configuration.Username,
\r
1424 configuration.Password,
\r
1425 configuration.AuthenticationType);
\r
1426 de.UsePropertyCache = false;
\r
1427 Assert.AreEqual(((PropertyValueCollection)de.Properties["telephoneNumber"]).Value,newTelephone);
\r
1428 ((PropertyValueCollection)de.Properties["telephoneNumber"]).Value = oldTelephone;
\r
1429 Assert.AreEqual(((PropertyValueCollection)de.Properties["telephoneNumber"]).Value,oldTelephone);
\r
1431 using (DirectoryEntry cnBarakTsabari = new DirectoryEntry(barakTsabariDN,
\r
1432 configuration.Username,
\r
1433 configuration.Password,
\r
1434 configuration.AuthenticationType)){
\r
1436 // check that new value is updated on the server
\r
1437 //Assert.AreEqual(((PropertyValueCollection)cnBarakTsabari.Properties["telephoneNumber"]).Value,oldTelephone);
\r
1440 de.CommitChanges(); // this should do nothing
\r
1444 public void DirectoryEntry_CommitChanges2()
\r
1446 string barakTsabariDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1447 using (DirectoryEntry barakTsabariDE1 = new DirectoryEntry(barakTsabariDN,
\r
1448 configuration.Username,
\r
1449 configuration.Password,
\r
1450 configuration.AuthenticationType)){
\r
1451 barakTsabariDE1.UsePropertyCache = true;
\r
1453 using (DirectoryEntry barakTsabariDE2 = new DirectoryEntry(barakTsabariDN,
\r
1454 configuration.Username,
\r
1455 configuration.Password,
\r
1456 configuration.AuthenticationType)){
\r
1457 barakTsabariDE2.UsePropertyCache = true;
\r
1459 string oldTelephone = (string)((PropertyValueCollection)barakTsabariDE1.Properties["telephoneNumber"]).Value;
\r
1460 string newTelephone = "+972 3 6078596";
\r
1461 string oldFacsimilieTelephoneNumber = (string)((PropertyValueCollection)barakTsabariDE1.Properties["facsimileTelephoneNumber"]).Value;
\r
1462 string newFacsimilieTelephoneNumber1 = "+972-3-9872365";
\r
1463 string newFacsimilieTelephoneNumber2 = "+972-3-9999999";
\r
1465 barakTsabariDE1.Properties["telephoneNumber"].Value = newTelephone;
\r
1466 barakTsabariDE1.Properties["facsimileTelephoneNumber"].Value = newFacsimilieTelephoneNumber1;
\r
1468 barakTsabariDE2.Properties["facsimileTelephoneNumber"].Value = newFacsimilieTelephoneNumber2;
\r
1470 // only the changed properties of each object are set
\r
1472 barakTsabariDE1.CommitChanges();
\r
1473 de = new DirectoryEntry(barakTsabariDN,
\r
1474 configuration.Username,
\r
1475 configuration.Password,
\r
1476 configuration.AuthenticationType);
\r
1477 Assert.AreEqual(de.Properties["telephoneNumber"].Value,newTelephone);
\r
1478 Assert.AreEqual(de.Properties["facsimileTelephoneNumber"].Value,newFacsimilieTelephoneNumber1);
\r
1480 barakTsabariDE2.CommitChanges();
\r
1481 de = new DirectoryEntry(barakTsabariDN,
\r
1482 configuration.Username,
\r
1483 configuration.Password,
\r
1484 configuration.AuthenticationType);
\r
1485 Assert.AreEqual(de.Properties["telephoneNumber"].Value,newTelephone);
\r
1486 Assert.AreEqual(de.Properties["facsimileTelephoneNumber"].Value,newFacsimilieTelephoneNumber2);
\r
1493 [ExpectedException(typeof(NotImplementedException))]
\r
1494 public void DirectoryEntry_CopyTo()
\r
1496 string barakTsabariDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1497 de = new DirectoryEntry(configuration.ConnectionString,
\r
1498 configuration.Username,
\r
1499 configuration.Password,
\r
1500 configuration.AuthenticationType);
\r
1502 using (DirectoryEntry cnBarakTsabari = new DirectoryEntry( barakTsabariDN,
\r
1503 configuration.Username,
\r
1504 configuration.Password,
\r
1505 configuration.AuthenticationType)){
\r
1507 cnBarakTsabari.CopyTo(de);
\r
1513 public void DirectoryEntry_DeleteTree()
\r
1515 string barakTsabariDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1517 Assert.IsTrue(DirectoryEntry.Exists(barakTsabariDN));
\r
1518 de = new DirectoryEntry(barakTsabariDN,
\r
1519 configuration.Username,
\r
1520 configuration.Password,
\r
1521 configuration.AuthenticationType);
\r
1523 // no properties changed
\r
1525 de.CommitChanges();
\r
1527 Assert.IsFalse(DirectoryEntry.Exists(barakTsabariDN));
\r
1529 string johnSmithDN = configuration.ServerRoot + "cn=John Smith,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1531 Assert.IsTrue(DirectoryEntry.Exists(johnSmithDN));
\r
1532 de = new DirectoryEntry(johnSmithDN,
\r
1533 configuration.Username,
\r
1534 configuration.Password,
\r
1535 configuration.AuthenticationType);
\r
1537 de.Properties["telephoneNumber"].Value = "+972 3 9999999";
\r
1539 // some properties changed
\r
1542 de.CommitChanges();
\r
1543 Assert.Fail("Object " + johnSmithDN + " was not deleted from server");
\r
1545 catch(AssertionException ae) {
\r
1548 catch(Exception e) {
\r
1554 public void DirectoryEntry_DeleteTree2()
\r
1556 string johnSmithDN = configuration.ServerRoot + "cn=John Smith,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1558 Assert.IsTrue(DirectoryEntry.Exists(johnSmithDN));
\r
1559 // two objects refer to the same entry
\r
1560 de = new DirectoryEntry(johnSmithDN,
\r
1561 configuration.Username,
\r
1562 configuration.Password,
\r
1563 configuration.AuthenticationType);
\r
1565 using (DirectoryEntry johnSmithDE = new DirectoryEntry(johnSmithDN,
\r
1566 configuration.Username,
\r
1567 configuration.Password,
\r
1568 configuration.AuthenticationType)){
\r
1570 johnSmithDE.Properties["telephoneNumber"].Value = "+972 3 9999999";
\r
1572 // check that the second entry is not accessible after the first is deleted
\r
1574 de.CommitChanges();
\r
1577 johnSmithDE.CommitChanges();
\r
1578 Assert.Fail("Object " + johnSmithDN + " should not be accessible");
\r
1580 catch(AssertionException ae) {
\r
1583 catch(Exception e) {
\r
1591 public void DirectoryEntry_Exists()
\r
1593 string barakTsabariDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1594 string johnSmithDN = configuration.ServerRoot + "cn=John Smith,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1595 string humanResourcesOU = configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1597 Assert.IsTrue(DirectoryEntry.Exists(barakTsabariDN));
\r
1598 Assert.IsTrue(DirectoryEntry.Exists(johnSmithDN));
\r
1599 Assert.IsTrue(DirectoryEntry.Exists(humanResourcesOU));
\r
1601 Assert.IsFalse(DirectoryEntry.Exists(barakTsabariDN + ",dc=mono"));
\r
1606 public void DirectoryEntry_MoveTo_De()
\r
1608 string barakTsabariHumanResourcesDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1609 string barakTsabariDevQaDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=DevQA,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1611 using (DirectoryEntry barakTsabariDE = new DirectoryEntry( barakTsabariHumanResourcesDN,
\r
1612 configuration.Username,
\r
1613 configuration.Password,
\r
1614 configuration.AuthenticationType)){
\r
1616 string devQaOU = configuration.ServerRoot + "ou=DevQA,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1618 using (DirectoryEntry devQaDE = new DirectoryEntry(devQaOU,
\r
1619 configuration.Username,
\r
1620 configuration.Password,
\r
1621 configuration.AuthenticationType)){
\r
1623 barakTsabariDE.MoveTo(devQaDE);
\r
1624 barakTsabariDE.CommitChanges();
\r
1626 Assert.IsTrue(DirectoryEntry.Exists(barakTsabariDevQaDN));
\r
1628 string humanRwsourcesOU = configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1630 using (DirectoryEntry humanResourcesDE = new DirectoryEntry( humanRwsourcesOU,
\r
1631 configuration.Username,
\r
1632 configuration.Password,
\r
1633 configuration.AuthenticationType)){
\r
1635 barakTsabariDE.MoveTo(humanResourcesDE);
\r
1636 barakTsabariDE.CommitChanges();
\r
1638 Assert.IsTrue(DirectoryEntry.Exists(barakTsabariHumanResourcesDN));
\r
1646 public void DirectoryEntry_MoveTo_DeStr()
\r
1648 string barakTsabariHumanResourcesDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1649 string barakTsabariDevQaDN = configuration.ServerRoot + "cn=My Name,ou=DevQA,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1651 using (DirectoryEntry barakTsabariDE = new DirectoryEntry( barakTsabariHumanResourcesDN,
\r
1652 configuration.Username,
\r
1653 configuration.Password,
\r
1654 configuration.AuthenticationType)){
\r
1656 string devQaOU = configuration.ServerRoot + "ou=DevQA,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1658 using (DirectoryEntry devQaDE = new DirectoryEntry(devQaOU,
\r
1659 configuration.Username,
\r
1660 configuration.Password,
\r
1661 configuration.AuthenticationType)){
\r
1663 barakTsabariDE.MoveTo(devQaDE,"cn=My Name");
\r
1664 barakTsabariDE.CommitChanges();
\r
1666 Assert.IsTrue(DirectoryEntry.Exists(barakTsabariDevQaDN));
\r
1668 string humanRwsourcesOU = configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1670 using (DirectoryEntry humanResourcesDE = new DirectoryEntry( humanRwsourcesOU,
\r
1671 configuration.Username,
\r
1672 configuration.Password,
\r
1673 configuration.AuthenticationType)){
\r
1675 barakTsabariDE.MoveTo(humanResourcesDE,"cn=Barak Tsabari");
\r
1676 barakTsabariDE.CommitChanges();
\r
1678 Assert.IsTrue(DirectoryEntry.Exists(barakTsabariHumanResourcesDN));
\r
1685 public void DirectoryEntry_RefreshCache()
\r
1687 de = new DirectoryEntry(configuration.ConnectionString);
\r
1688 de.UsePropertyCache = true;
\r
1690 string newValue = "Just a company";
\r
1691 string oldValue = (string)((PropertyValueCollection)de.Properties["description"]).Value;
\r
1692 ((PropertyValueCollection)de.Properties["description"]).Value = newValue;
\r
1694 Assert.AreEqual(((PropertyValueCollection)de.Properties["description"]).Value,newValue);
\r
1696 de.RefreshCache();
\r
1698 Assert.AreEqual(((PropertyValueCollection)de.Properties["description"]).Value,oldValue);
\r
1700 // call RefeshCache on new entry prior to submitting it to the server shoud fail
\r
1701 string newEmployeeDN = configuration.ServerRoot + "cn=New Employee,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1702 string humanResourcesDN = configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1704 using (DirectoryEntry humanResourcesDE = new DirectoryEntry( humanResourcesDN,
\r
1705 configuration.Username,
\r
1706 configuration.Password,
\r
1707 configuration.AuthenticationType)){
\r
1709 using (DirectoryEntry newEmployeeDE = humanResourcesDE.Children.Add("cn=New Employee","Class")){
\r
1710 Assert.AreEqual(newEmployeeDE.Properties["cn"].Value,null);
\r
1712 ((PropertyValueCollection)newEmployeeDE.Properties["objectClass"]).Add("person");
\r
1713 ((PropertyValueCollection)newEmployeeDE.Properties["objectClass"]).Add("organizationalPerson");
\r
1714 newEmployeeDE.Properties["cn"].Value = "New Employee";
\r
1715 newEmployeeDE.Properties["sn"].Value = "Employee";
\r
1716 newEmployeeDE.Properties["ou"].Value = "Human Resources";
\r
1718 Assert.AreEqual(newEmployeeDE.Properties["cn"].Value,"New Employee");
\r
1721 newEmployeeDE.RefreshCache();
\r
1722 Assert.Fail("Call to RefreshCache did not fail");
\r
1724 catch(AssertionException ae) {
\r
1727 catch (Exception e) {
\r
1728 // supress exception
\r
1731 Assert.AreEqual(newEmployeeDE.Properties["cn"].Value,"New Employee");
\r
1733 newEmployeeDE.CommitChanges();
\r
1735 // now it should work without any problem
\r
1736 newEmployeeDE.RefreshCache();
\r
1738 Assert.AreEqual(newEmployeeDE.Properties["cn"].Value,"New Employee");
\r
1744 public void DirectoryEntry_RefreshCache_StrArr()
\r
1746 de = new DirectoryEntry(configuration.ServerRoot + "cn=Uzi Cohen,cn=Manager" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)));
\r
1747 de.UsePropertyCache = true;
\r
1749 string[] newValues = new string [] { "Just a manager", "Levi" };
\r
1750 string[] oldValues = new string [2];
\r
1751 oldValues [0] = (string)((PropertyValueCollection)de.Properties["description"]).Value;
\r
1752 oldValues [1] = (string)((PropertyValueCollection)de.Properties["sn"]).Value;
\r
1754 ((PropertyValueCollection)de.Properties["description"]).Value = newValues [0];
\r
1755 ((PropertyValueCollection)de.Properties["sn"]).Value = newValues [1];
\r
1757 Assert.AreEqual(((PropertyValueCollection)de.Properties["description"]).Value,newValues [0]);
\r
1758 Assert.AreEqual(((PropertyValueCollection)de.Properties["sn"]).Value,newValues [1]);
\r
1760 de.RefreshCache(new string[] {"cn"});
\r
1762 Assert.AreEqual(((PropertyValueCollection)de.Properties["description"]).Value,newValues [0]);
\r
1763 Assert.AreEqual(((PropertyValueCollection)de.Properties["sn"]).Value,newValues [1]);
\r
1765 de.RefreshCache(new string[] {"description","sn"});
\r
1767 Assert.AreEqual(((PropertyValueCollection)de.Properties["description"]).Value,newValues [0]);
\r
1768 Assert.AreEqual(((PropertyValueCollection)de.Properties["sn"]).Value,oldValues [1]);
\r
1772 public void DirectoryEntry_Rename()
\r
1774 string barakTsabariOldDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1775 string barakTsabariNewDN = configuration.ServerRoot + "cn=My Name,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1777 using (DirectoryEntry barakTsabariDE = new DirectoryEntry( barakTsabariOldDN,
\r
1778 configuration.Username,
\r
1779 configuration.Password,
\r
1780 configuration.AuthenticationType)){
\r
1782 barakTsabariDE.Rename("cn=My Name");
\r
1783 barakTsabariDE.CommitChanges();
\r
1785 Assert.IsTrue(DirectoryEntry.Exists(barakTsabariNewDN));
\r
1787 barakTsabariDE.Rename("cn=Barak Tsabari");
\r
1788 barakTsabariDE.CommitChanges();
\r
1790 Assert.IsTrue(DirectoryEntry.Exists(barakTsabariOldDN));
\r
1796 private static string GetName (string baseDn)
\r
1798 if (baseDn == null || baseDn.Length == 0 || baseDn.IndexOf (',') == -1)
\r
1801 int index = baseDn.IndexOf (',');
\r
1803 return baseDn.Substring (0, index);
\r
1806 private static string GetParentDN (string baseDn)
\r
1808 if (baseDn == null || baseDn.Length == 0 || baseDn.IndexOf (',') == -1)
\r
1809 return String.Empty;
\r
1811 int index = baseDn.IndexOf (',');
\r
1813 return baseDn.Substring (index + 1,baseDn.Length - index - 1);
\r