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 [Category ("InetAccess")]
\r
17 public class DirectoryServicesDirectoryEntryTest
\r
21 static TestConfiguration configuration;
\r
22 static DirectoryEntry de;
\r
24 #endregion // Fields
\r
26 #region SetUp and TearDown
\r
29 public void TestFixtureSetUp()
\r
32 configuration = new TestConfiguration ();
\r
36 [TestFixtureTearDown]
\r
37 public void TestFixtureTearDown()
\r
50 #region Initialize basics
\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
62 #endregion // Initialize basics
\r
64 #region Human Resources
\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
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
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
90 #endregion // Human Resources
\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
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
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
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
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
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
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
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
175 #endregion // DevQA
\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
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
196 #endregion // Manager
\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
206 cnDanielSmith.Dispose();
\r
207 cnDanielMorgan.Dispose();
\r
209 cnUziCohen_.Dispose();
\r
210 cnManager.Dispose();
\r
211 ouPeople.Dispose();
\r
217 public void TearDown()
\r
224 using (DirectoryEntry root = new DirectoryEntry( configuration.ConnectionString,
\r
225 configuration.Username,
\r
226 configuration.Password,
\r
227 configuration.AuthenticationType)) {
\r
229 foreach(DirectoryEntry child in root.Children) {
\r
230 DeleteTree_DFS(child);
\r
235 private void DeleteTree_DFS(DirectoryEntry de)
\r
237 foreach(DirectoryEntry child in de.Children) {
\r
238 DeleteTree_DFS(child);
\r
241 de.CommitChanges();
\r
244 #endregion //SetUp and TearDown
\r
249 public void DirectoryEntry_DirectoryEntry()
\r
251 de = new DirectoryEntry();
\r
253 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.None);
\r
254 Assert.AreEqual(de.Path,String.Empty);
\r
255 Assert.AreEqual(de.UsePropertyCache,true);
\r
256 Assert.AreEqual(de.Username,null);
\r
261 public void DirectoryEntry_DirectoryEntry_Str()
\r
263 using (DirectoryEntry de = new DirectoryEntry(configuration.ConnectionString)) {
\r
265 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.None);
\r
266 Assert.AreEqual(de.Name,GetName (configuration.BaseDn));
\r
267 Assert.AreEqual(de.Path,configuration.ConnectionString);
\r
268 Assert.AreEqual(de.SchemaClassName,"organization");
\r
269 Assert.AreEqual(de.UsePropertyCache,true);
\r
270 Assert.AreEqual(de.Username,null);
\r
276 public void DirectoryEntry_DirectoryEntry_StrStrStrAuth()
\r
278 if ((configuration.AuthenticationType != AuthenticationTypes.ServerBind) &&
\r
279 (configuration.AuthenticationType != AuthenticationTypes.None) &&
\r
280 (configuration.AuthenticationType != AuthenticationTypes.Anonymous))
\r
283 #region AuthenticationTypes.Anonymous
\r
285 using (DirectoryEntry de = new DirectoryEntry( configuration.ConnectionString,
\r
286 configuration.Username,
\r
287 configuration.Password,
\r
288 AuthenticationTypes.Anonymous)){
\r
290 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Anonymous);
\r
291 //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));
\r
292 Assert.AreEqual(de.Name,GetName (configuration.BaseDn));
\r
293 //Assert.AreEqual(de.NativeGuid,null);
\r
294 Assert.AreEqual(de.Path,configuration.ConnectionString);
\r
295 Assert.AreEqual(de.SchemaClassName,"organization");
\r
296 Assert.AreEqual(de.UsePropertyCache,true);
\r
297 Assert.AreEqual(de.Username,configuration.Username);
\r
300 #endregion //AuthenticationTypes.Anonymous
\r
302 #region AuthenticationTypes.Delegation
\r
304 using (DirectoryEntry de = new DirectoryEntry(configuration.ConnectionString,
\r
305 configuration.Username,
\r
306 configuration.Password,
\r
307 AuthenticationTypes.Delegation)){
\r
309 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Delegation);
\r
310 //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));
\r
311 Assert.AreEqual(de.Name,GetName (configuration.BaseDn));
\r
312 //Assert.AreEqual(de.NativeGuid,null);
\r
313 Assert.AreEqual(de.Path,configuration.ConnectionString);
\r
314 Assert.AreEqual(de.SchemaClassName,"organization");
\r
315 Assert.AreEqual(de.UsePropertyCache,true);
\r
316 Assert.AreEqual(de.Username,configuration.Username);
\r
319 #endregion //AuthenticationTypes.Delegation
\r
321 #region AuthenticationTypes.Encryption
\r
323 // de = new DirectoryEntry( configuration.ConnectionString,
\r
324 // configuration.Username,
\r
325 // configuration.Password,
\r
326 // AuthenticationTypes.Encryption);
\r
328 // Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Encryption);
\r
329 // //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));
\r
330 // Assert.AreEqual(de.Name,"dc=myhosting");
\r
331 // //Assert.AreEqual(de.NativeGuid,null);
\r
332 // Assert.AreEqual(de.Password,configuration.Password);
\r
333 // Assert.AreEqual(de.Path,configuration.ConnectionString);
\r
334 // Assert.AreEqual(de.SchemaClassName,"organization");
\r
335 // Assert.AreEqual(de.UsePropertyCache,true);
\r
336 // Assert.AreEqual(de.Username,configuration.Username);
\r
338 #endregion //AuthenticationTypes.Encryption
\r
340 #region AuthenticationTypes.FastBind
\r
342 using (DirectoryEntry de = new DirectoryEntry(configuration.ConnectionString,
\r
343 configuration.Username,
\r
344 configuration.Password,
\r
345 AuthenticationTypes.FastBind)){
\r
347 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.FastBind);
\r
348 //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));
\r
349 Assert.AreEqual(de.Name,GetName (configuration.BaseDn));
\r
350 //Assert.AreEqual(de.NativeGuid,null);
\r
351 Assert.AreEqual(de.Path,configuration.ConnectionString);
\r
352 Assert.AreEqual(de.SchemaClassName,"organization");
\r
353 Assert.AreEqual(de.UsePropertyCache,true);
\r
354 Assert.AreEqual(de.Username,configuration.Username);
\r
357 #endregion //AuthenticationTypes.FastBind
\r
359 #region AuthenticationTypes.None
\r
361 using (DirectoryEntry de = new DirectoryEntry(configuration.ConnectionString,
\r
362 configuration.Username,
\r
363 configuration.Password,
\r
364 AuthenticationTypes.None)){
\r
366 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.None);
\r
367 //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));
\r
368 Assert.AreEqual(de.Name,GetName (configuration.BaseDn));
\r
369 //Assert.AreEqual(de.NativeGuid,null);
\r
370 Assert.AreEqual(de.Path,configuration.ConnectionString);
\r
371 Assert.AreEqual(de.SchemaClassName,"organization");
\r
372 Assert.AreEqual(de.UsePropertyCache,true);
\r
373 Assert.AreEqual(de.Username,configuration.Username);
\r
376 #endregion //AuthenticationTypes.None
\r
378 #region AuthenticationTypes.ReadonlyServer
\r
380 using (DirectoryEntry de = new DirectoryEntry(configuration.ConnectionString,
\r
381 configuration.Username,
\r
382 configuration.Password,
\r
383 AuthenticationTypes.ReadonlyServer)){
\r
385 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.ReadonlyServer);
\r
386 //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));
\r
387 Assert.AreEqual(de.Name,GetName (configuration.BaseDn));
\r
388 //Assert.AreEqual(de.NativeGuid,null);
\r
389 Assert.AreEqual(de.Path,configuration.ConnectionString);
\r
390 Assert.AreEqual(de.SchemaClassName,"organization");
\r
391 Assert.AreEqual(de.UsePropertyCache,true);
\r
392 Assert.AreEqual(de.Username,configuration.Username);
\r
395 #endregion //AuthenticationTypes.ReadonlyServer
\r
397 #region AuthenticationTypes.Sealing
\r
399 using (DirectoryEntry de = new DirectoryEntry(configuration.ConnectionString,
\r
400 configuration.Username,
\r
401 configuration.Password,
\r
402 AuthenticationTypes.Sealing)){
\r
404 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Sealing);
\r
405 //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));
\r
406 Assert.AreEqual(de.Name,GetName (configuration.BaseDn));
\r
407 //Assert.AreEqual(de.NativeGuid,null);
\r
408 Assert.AreEqual(de.Path,configuration.ConnectionString);
\r
409 Assert.AreEqual(de.SchemaClassName,"organization");
\r
410 Assert.AreEqual(de.UsePropertyCache,true);
\r
411 Assert.AreEqual(de.Username,configuration.Username);
\r
414 #endregion //AuthenticationTypes.Sealing
\r
416 #region AuthenticationTypes.Secure
\r
418 // de = new DirectoryEntry(configuration.ConnectionString,
\r
419 // configuration.Username,
\r
420 // configuration.Password,
\r
421 // AuthenticationTypes.Secure);
\r
423 // Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Secure);
\r
424 // //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));
\r
425 // Assert.AreEqual(de.Name,"dc=myhosting");
\r
426 // //Assert.AreEqual(de.NativeGuid,null);
\r
427 // Assert.AreEqual(de.Password,configuration.Password);
\r
428 // Assert.AreEqual(de.Path,configuration.ConnectionString);
\r
429 // Assert.AreEqual(de.SchemaClassName,"organization");
\r
430 // Assert.AreEqual(de.UsePropertyCache,true);
\r
431 // Assert.AreEqual(de.Username,configuration.Username);
\r
433 #endregion //AuthenticationTypes.Secure
\r
435 #region AuthenticationTypes.SecureSocketsLayer
\r
437 // de = new DirectoryEntry(configuration.ConnectionString,
\r
438 // configuration.Username,
\r
439 // configuration.Password,
\r
440 // AuthenticationTypes.SecureSocketsLayer);
\r
442 // Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.SecureSocketsLayer);
\r
443 // //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));
\r
444 // Assert.AreEqual(de.Name,"dc=myhosting");
\r
445 // //Assert.AreEqual(de.NativeGuid,null);
\r
446 // Assert.AreEqual(de.Password,configuration.Password);
\r
447 // Assert.AreEqual(de.Path,configuration.ConnectionString);
\r
448 // Assert.AreEqual(de.SchemaClassName,"organization");
\r
449 // Assert.AreEqual(de.UsePropertyCache,true);
\r
450 // Assert.AreEqual(de.Username,configuration.Username);
\r
452 #endregion //AuthenticationTypes.SecureSocketsLayer
\r
454 #region AuthenticationTypes.ServerBind
\r
456 using (DirectoryEntry de = new DirectoryEntry(configuration.ConnectionString,
\r
457 configuration.Username,
\r
458 configuration.Password,
\r
459 AuthenticationTypes.ServerBind)){
\r
461 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.ServerBind);
\r
462 //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));
\r
463 Assert.AreEqual(de.Name,GetName (configuration.BaseDn));
\r
464 //Assert.AreEqual(de.NativeGuid,null);
\r
465 Assert.AreEqual(de.Path,configuration.ConnectionString);
\r
466 Assert.AreEqual(de.SchemaClassName,"organization");
\r
467 Assert.AreEqual(de.UsePropertyCache,true);
\r
468 Assert.AreEqual(de.Username,configuration.Username);
\r
471 #endregion //AuthenticationTypes.ServerBind
\r
473 #region AuthenticationTypes.Signing
\r
475 using (DirectoryEntry de = new DirectoryEntry(configuration.ConnectionString,
\r
476 configuration.Username,
\r
477 configuration.Password,
\r
478 AuthenticationTypes.Signing)){
\r
480 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Signing);
\r
481 //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));
\r
482 Assert.AreEqual(de.Name,GetName (configuration.BaseDn));
\r
483 //Assert.AreEqual(de.NativeGuid,null);
\r
484 Assert.AreEqual(de.Path,configuration.ConnectionString);
\r
485 Assert.AreEqual(de.SchemaClassName,"organization");
\r
486 Assert.AreEqual(de.UsePropertyCache,true);
\r
487 Assert.AreEqual(de.Username,configuration.Username);
\r
490 #endregion //AuthenticationTypes.Signing
\r
494 public void DirectoryEntry_Dispose()
\r
496 using (DirectoryEntry root = new DirectoryEntry( configuration.ConnectionString,
\r
497 configuration.Username,
\r
498 configuration.Password,
\r
499 configuration.AuthenticationType)){
\r
501 DirectoryEntry ouPeople = root.Children.Add("ou=printers","Class");
\r
502 ouPeople.Properties["objectClass"].Value = "organizationalUnit";
\r
503 ouPeople.Properties["description"].Value = "All printers in organisation";
\r
504 ouPeople.Properties["ou"].Value = "printers";
\r
505 ouPeople.CommitChanges();
\r
507 ouPeople.Rename("ou=anotherPrinters");
\r
508 ouPeople.CommitChanges();
\r
510 Assert.IsTrue(DirectoryEntry.Exists(configuration.ServerRoot + "ou=anotherPrinters" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn))));
\r
516 public void DirectoryEntry_AuthenticationType()
\r
518 de = new DirectoryEntry();
\r
520 de.AuthenticationType = AuthenticationTypes.Anonymous;
\r
521 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Anonymous);
\r
523 de.AuthenticationType = AuthenticationTypes.Delegation;
\r
524 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Delegation);
\r
526 de.AuthenticationType = AuthenticationTypes.Encryption;
\r
527 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Encryption);
\r
529 de.AuthenticationType = AuthenticationTypes.FastBind;
\r
530 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.FastBind);
\r
532 de.AuthenticationType = AuthenticationTypes.None;
\r
533 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.None);
\r
535 de.AuthenticationType = AuthenticationTypes.ReadonlyServer;
\r
536 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.ReadonlyServer);
\r
538 de.AuthenticationType = AuthenticationTypes.Sealing;
\r
539 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Sealing);
\r
541 de.AuthenticationType = AuthenticationTypes.Secure;
\r
542 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Secure);
\r
544 de.AuthenticationType = AuthenticationTypes.SecureSocketsLayer;
\r
545 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.SecureSocketsLayer);
\r
547 de.AuthenticationType = AuthenticationTypes.ServerBind;
\r
548 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.ServerBind);
\r
550 de.AuthenticationType = AuthenticationTypes.Signing;
\r
551 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Signing);
\r
553 de = new DirectoryEntry(configuration.ConnectionString);
\r
555 de.AuthenticationType = AuthenticationTypes.Anonymous;
\r
556 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Anonymous);
\r
558 de.AuthenticationType = AuthenticationTypes.Delegation;
\r
559 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Delegation);
\r
561 de.AuthenticationType = AuthenticationTypes.Encryption;
\r
562 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Encryption);
\r
564 de.AuthenticationType = AuthenticationTypes.FastBind;
\r
565 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.FastBind);
\r
567 de.AuthenticationType = AuthenticationTypes.None;
\r
568 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.None);
\r
570 de.AuthenticationType = AuthenticationTypes.ReadonlyServer;
\r
571 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.ReadonlyServer);
\r
573 de.AuthenticationType = AuthenticationTypes.Sealing;
\r
574 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Sealing);
\r
576 de.AuthenticationType = AuthenticationTypes.Secure;
\r
577 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Secure);
\r
579 de.AuthenticationType = AuthenticationTypes.SecureSocketsLayer;
\r
580 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.SecureSocketsLayer);
\r
582 de.AuthenticationType = AuthenticationTypes.ServerBind;
\r
583 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.ServerBind);
\r
585 de.AuthenticationType = AuthenticationTypes.Signing;
\r
586 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Signing);
\r
588 de = new DirectoryEntry(configuration.ConnectionString,
\r
589 configuration.Username,
\r
590 configuration.Password,
\r
591 AuthenticationTypes.None);
\r
593 de.AuthenticationType = AuthenticationTypes.Anonymous;
\r
594 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Anonymous);
\r
596 de.AuthenticationType = AuthenticationTypes.Delegation;
\r
597 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Delegation);
\r
599 de.AuthenticationType = AuthenticationTypes.Encryption;
\r
600 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Encryption);
\r
602 de.AuthenticationType = AuthenticationTypes.FastBind;
\r
603 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.FastBind);
\r
605 de.AuthenticationType = AuthenticationTypes.None;
\r
606 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.None);
\r
608 de.AuthenticationType = AuthenticationTypes.ReadonlyServer;
\r
609 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.ReadonlyServer);
\r
611 de.AuthenticationType = AuthenticationTypes.Sealing;
\r
612 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Sealing);
\r
614 de.AuthenticationType = AuthenticationTypes.Secure;
\r
615 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Secure);
\r
617 de.AuthenticationType = AuthenticationTypes.SecureSocketsLayer;
\r
618 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.SecureSocketsLayer);
\r
620 de.AuthenticationType = AuthenticationTypes.ServerBind;
\r
621 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.ServerBind);
\r
623 de.AuthenticationType = AuthenticationTypes.Signing;
\r
624 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Signing);
\r
629 public void DirectoryEntry_UsePropertyCache()
\r
631 string barakTsabariDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
632 de = new DirectoryEntry(barakTsabariDN,
\r
633 configuration.Username,
\r
634 configuration.Password,
\r
635 configuration.AuthenticationType);
\r
637 // UsePropertyCache = true
\r
638 de.UsePropertyCache = true;
\r
639 Assert.AreEqual(de.UsePropertyCache,true);
\r
641 #region Check Properties
\r
643 // Properties changes are cached
\r
644 string oldTelephoneNumber = (string)de.Properties["telephoneNumber"].Value;
\r
645 string newTelephoneNumber = "+972-3-6572345";
\r
647 de.Properties["telephoneNumber"].Value = newTelephoneNumber;
\r
648 using (DirectoryEntry barakTsabariDE = new DirectoryEntry( barakTsabariDN,
\r
649 configuration.Username,
\r
650 configuration.Password,
\r
651 configuration.AuthenticationType)){
\r
653 Assert.AreEqual(barakTsabariDE.Properties["telephoneNumber"].Value,oldTelephoneNumber);
\r
654 de.CommitChanges();
\r
656 using (DirectoryEntry barakTsabariDE = new DirectoryEntry(barakTsabariDN,
\r
657 configuration.Username,
\r
658 configuration.Password,
\r
659 configuration.AuthenticationType)){
\r
660 Assert.AreEqual(barakTsabariDE.Properties["telephoneNumber"].Value,newTelephoneNumber);
\r
662 // restore object state
\r
663 de.Properties["telephoneNumber"].Value = oldTelephoneNumber;
\r
664 de.CommitChanges();
\r
667 #endregion // Check Properties
\r
669 #region Check DeleteTree
\r
671 // DeleteTree is not cached
\r
674 using (DirectoryEntry barakTsabariDE = new DirectoryEntry(barakTsabariDN,
\r
675 configuration.Username,
\r
676 configuration.Password,
\r
677 configuration.AuthenticationType)){
\r
678 barakTsabariDE.Properties["telephoneNumber"].Value = newTelephoneNumber;
\r
679 barakTsabariDE.CommitChanges();
\r
680 Assert.Fail("Object " + barakTsabariDN + " was not deleted from server.");
\r
683 catch(AssertionException ae) {
\r
686 catch (Exception e) {
\r
690 // restore object state
\r
691 using (DirectoryEntry ouHumanResources = new DirectoryEntry( configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
\r
692 configuration.Username,
\r
693 configuration.Password,
\r
694 configuration.AuthenticationType)){
\r
695 using (DirectoryEntry cnBarakTsabari = ouHumanResources.Children.Add("cn=Barak Tsabari","Class")){
\r
696 ((PropertyValueCollection)cnBarakTsabari.Properties["objectClass"]).Add("person");
\r
697 ((PropertyValueCollection)cnBarakTsabari.Properties["objectClass"]).Add("organizationalPerson");
\r
698 cnBarakTsabari.Properties["cn"].Value = "Barak Tsabari";
\r
699 cnBarakTsabari.Properties["facsimileTelephoneNumber"].Value = "+1 906 777 8853";
\r
700 ((PropertyValueCollection)cnBarakTsabari.Properties["ou"]).Add("Human Resources");
\r
701 ((PropertyValueCollection)cnBarakTsabari.Properties["ou"]).Add("People");
\r
702 cnBarakTsabari.Properties["sn"].Value = "Tsabari";
\r
703 cnBarakTsabari.Properties["telephoneNumber"].Value = "+1 906 777 8854";
\r
704 cnBarakTsabari.CommitChanges();
\r
708 #endregion // Check DeleteTree
\r
710 #region Check MoveTo
\r
712 // Move to is not cached
\r
713 de = new DirectoryEntry(barakTsabariDN,
\r
714 configuration.Username,
\r
715 configuration.Password,
\r
716 configuration.AuthenticationType);
\r
718 using (DirectoryEntry ouRnD = new DirectoryEntry( configuration.ServerRoot + "ou=R&D,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
\r
719 configuration.Username,
\r
720 configuration.Password,
\r
721 configuration.AuthenticationType)){
\r
724 using (DirectoryEntry barakTsabariDE = new DirectoryEntry(barakTsabariDN,
\r
725 configuration.Username,
\r
726 configuration.Password,
\r
727 configuration.AuthenticationType)){
\r
728 barakTsabariDE.Properties["telephoneNumber"].Value = newTelephoneNumber;
\r
729 barakTsabariDE.CommitChanges();
\r
730 Assert.Fail("Object " + barakTsabariDN + " was not moved from old location on the server.");
\r
733 catch(AssertionException ae) {
\r
736 catch (Exception e) {
\r
741 using (DirectoryEntry barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=Barak Tsabari,ou=R&D,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
\r
742 configuration.Username,
\r
743 configuration.Password,
\r
744 configuration.AuthenticationType)){
\r
745 Assert.AreEqual(barakTsabariDE.Properties["telephoneNumber"].Value,oldTelephoneNumber);
\r
749 // restore object state
\r
750 using (DirectoryEntry ouHumanResources = new DirectoryEntry( configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
\r
751 configuration.Username,
\r
752 configuration.Password,
\r
753 configuration.AuthenticationType)){
\r
754 using (DirectoryEntry barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=Barak Tsabari,ou=R&D,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
\r
755 configuration.Username,
\r
756 configuration.Password,
\r
757 configuration.AuthenticationType)){
\r
758 barakTsabariDE.MoveTo(ouHumanResources);
\r
759 barakTsabariDE.CommitChanges();
\r
763 #endregion // Check MoveTo
\r
765 #region Check Rename
\r
767 // Rename not chached
\r
768 de = new DirectoryEntry(barakTsabariDN,
\r
769 configuration.Username,
\r
770 configuration.Password,
\r
771 configuration.AuthenticationType);
\r
773 de.Rename("cn=MyUser");
\r
776 using (DirectoryEntry barakTsabariDE = new DirectoryEntry(barakTsabariDN,
\r
777 configuration.Username,
\r
778 configuration.Password,
\r
779 configuration.AuthenticationType)){
\r
780 barakTsabariDE.Properties["telephoneNumber"].Value = newTelephoneNumber;
\r
781 barakTsabariDE.CommitChanges();
\r
782 Assert.Fail("Object " + barakTsabariDN + " was not renamed on the server.");
\r
785 catch(AssertionException ae) {
\r
788 catch (Exception e) {
\r
792 using (DirectoryEntry barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=MyUser,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
\r
793 configuration.Username,
\r
794 configuration.Password,
\r
795 configuration.AuthenticationType)){
\r
796 Assert.AreEqual(barakTsabariDE.Properties["telephoneNumber"].Value,oldTelephoneNumber);
\r
799 // restore object state
\r
800 using (DirectoryEntry barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=MyUser,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
\r
801 configuration.Username,
\r
802 configuration.Password,
\r
803 configuration.AuthenticationType)){
\r
804 barakTsabariDE.Rename("cn=Barak Tsabari");
\r
805 barakTsabariDE.CommitChanges();
\r
808 #endregion // Check Rename
\r
810 // UsePropertyCache = false
\r
811 de = new DirectoryEntry(barakTsabariDN,
\r
812 configuration.Username,
\r
813 configuration.Password,
\r
814 configuration.AuthenticationType);
\r
815 de.UsePropertyCache = false;
\r
816 Assert.AreEqual(de.UsePropertyCache,false);
\r
818 #region Check Properties
\r
820 // Properties changes not cached
\r
821 de.Properties["telephoneNumber"].Value = newTelephoneNumber;
\r
822 using (DirectoryEntry barakTsabariDE = new DirectoryEntry(barakTsabariDN,
\r
823 configuration.Username,
\r
824 configuration.Password,
\r
825 configuration.AuthenticationType)){
\r
828 //Assert.AreEqual(barakTsabariDE.Properties["telephoneNumber"].Value,newTelephoneNumber);
\r
830 #endregion // Check Properties
\r
832 #region Check DeleteTree
\r
834 // DeleteTree is not cached
\r
837 using (DirectoryEntry barakTsabariDE = new DirectoryEntry(barakTsabariDN,
\r
838 configuration.Username,
\r
839 configuration.Password,
\r
840 configuration.AuthenticationType)){
\r
841 barakTsabariDE.Properties["telephoneNumber"].Value = newTelephoneNumber;
\r
842 barakTsabariDE.CommitChanges();
\r
843 Assert.Fail("Object " + barakTsabariDN + " was not deleted from server.");
\r
846 catch(AssertionException ae) {
\r
849 catch (Exception e) {
\r
853 // restore object state
\r
854 using (DirectoryEntry ouHumanResources = new DirectoryEntry( configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
\r
855 configuration.Username,
\r
856 configuration.Password,
\r
857 configuration.AuthenticationType)){
\r
858 using (DirectoryEntry cnBarakTsabari = ouHumanResources.Children.Add("cn=Barak Tsabari","Class")){
\r
859 ((PropertyValueCollection)cnBarakTsabari.Properties["objectClass"]).Add("person");
\r
860 ((PropertyValueCollection)cnBarakTsabari.Properties["objectClass"]).Add("organizationalPerson");
\r
861 cnBarakTsabari.Properties["cn"].Value = "Barak Tsabari";
\r
862 cnBarakTsabari.Properties["facsimileTelephoneNumber"].Value = "+1 906 777 8853";
\r
863 ((PropertyValueCollection)cnBarakTsabari.Properties["ou"]).Add("Human Resources");
\r
864 ((PropertyValueCollection)cnBarakTsabari.Properties["ou"]).Add("People");
\r
865 cnBarakTsabari.Properties["sn"].Value = "Tsabari";
\r
866 cnBarakTsabari.Properties["telephoneNumber"].Value = "+1 906 777 8854";
\r
867 cnBarakTsabari.CommitChanges();
\r
871 #endregion // Check DeleteTree
\r
873 #region Check MoveTo
\r
875 // Move to is not cached
\r
876 de = new DirectoryEntry(barakTsabariDN,
\r
877 configuration.Username,
\r
878 configuration.Password,
\r
879 configuration.AuthenticationType);
\r
881 using (DirectoryEntry ouRnD = new DirectoryEntry( configuration.ServerRoot + "ou=R&D,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
\r
882 configuration.Username,
\r
883 configuration.Password,
\r
884 configuration.AuthenticationType)){
\r
888 using (DirectoryEntry barakTsabariDE = new DirectoryEntry(barakTsabariDN,
\r
889 configuration.Username,
\r
890 configuration.Password,
\r
891 configuration.AuthenticationType)){
\r
892 barakTsabariDE.Properties["telephoneNumber"].Value = newTelephoneNumber;
\r
893 barakTsabariDE.CommitChanges();
\r
894 Assert.Fail("Object " + barakTsabariDN + " was not moved from old location on the server.");
\r
897 catch(AssertionException ae) {
\r
900 catch (Exception e) {
\r
905 using (DirectoryEntry barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=Barak Tsabari,ou=R&D,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
\r
906 configuration.Username,
\r
907 configuration.Password,
\r
908 configuration.AuthenticationType)){
\r
909 Assert.AreEqual(barakTsabariDE.Properties["telephoneNumber"].Value,oldTelephoneNumber);
\r
913 // restore object state
\r
914 using (DirectoryEntry ouHumanResources = new DirectoryEntry( configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
\r
915 configuration.Username,
\r
916 configuration.Password,
\r
917 configuration.AuthenticationType)){
\r
918 using (DirectoryEntry barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=Barak Tsabari,ou=R&D,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
\r
919 configuration.Username,
\r
920 configuration.Password,
\r
921 configuration.AuthenticationType)){
\r
922 barakTsabariDE.MoveTo(ouHumanResources);
\r
923 barakTsabariDE.CommitChanges();
\r
927 #endregion // Check MoveTo
\r
929 #region Check Rename
\r
931 // Rename not chached
\r
932 de = new DirectoryEntry(barakTsabariDN,
\r
933 configuration.Username,
\r
934 configuration.Password,
\r
935 configuration.AuthenticationType);
\r
937 de.Rename("cn=MyUser");
\r
940 using (DirectoryEntry barakTsabariDE = new DirectoryEntry(barakTsabariDN,
\r
941 configuration.Username,
\r
942 configuration.Password,
\r
943 configuration.AuthenticationType)){
\r
944 barakTsabariDE.Properties["telephoneNumber"].Value = newTelephoneNumber;
\r
945 barakTsabariDE.CommitChanges();
\r
946 Assert.Fail("Object " + barakTsabariDN + " was not renamed on the server.");
\r
949 catch(AssertionException ae) {
\r
952 catch (Exception e) {
\r
956 using (DirectoryEntry barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=MyUser,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
\r
957 configuration.Username,
\r
958 configuration.Password,
\r
959 configuration.AuthenticationType)){
\r
960 Assert.AreEqual(barakTsabariDE.Properties["telephoneNumber"].Value,oldTelephoneNumber);
\r
963 // restore object state
\r
964 using (DirectoryEntry barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=MyUser,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
\r
965 configuration.Username,
\r
966 configuration.Password,
\r
967 configuration.AuthenticationType)){
\r
968 barakTsabariDE.Rename("cn=Barak Tsabari");
\r
969 barakTsabariDE.CommitChanges();
\r
972 #endregion // Check Rename
\r
976 [Category("NotWorking")]
\r
977 public void DirectoryEntry_Children()
\r
979 de = new DirectoryEntry();
\r
980 DirectoryEntries children = de.Children;
\r
981 //Assert.AreEqual(children.SchemaFilter.Count,0);
\r
984 de = new DirectoryEntry(configuration.ConnectionString);
\r
985 children = de.Children;
\r
987 //Assert.AreEqual(children.SchemaFilter.Count,0);
\r
989 int childrenCount = 0;
\r
990 foreach(DirectoryEntry childDe in children) {
\r
993 Assert.AreEqual(childrenCount,2);
\r
994 Assert.AreEqual(children.Find("ou=people").Name,"ou=people");
\r
995 Assert.AreEqual(children.Find("cn=Manager").Name,"cn=Manager");
\r
998 de = new DirectoryEntry(configuration.ConnectionString,
\r
999 configuration.Username,
\r
1000 configuration.Password,
\r
1001 configuration.AuthenticationType);
\r
1002 children = de.Children;
\r
1004 //Assert.AreEqual(children.SchemaFilter.Count,0);
\r
1006 childrenCount = 0;
\r
1007 foreach(DirectoryEntry childDe in children) {
\r
1010 Assert.AreEqual(childrenCount,2);
\r
1011 Assert.AreEqual(children.Find("ou=people").Name,"ou=people");
\r
1012 Assert.AreEqual(children.Find("cn=Manager").Name,"cn=Manager");
\r
1014 de = new DirectoryEntry(configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)) ,
\r
1015 configuration.Username,
\r
1016 configuration.Password,
\r
1017 configuration.AuthenticationType);
\r
1018 children = de.Children;
\r
1020 Assert.AreEqual(children.Find("cn=Barak Tsabari").Name,"cn=Barak Tsabari");
\r
1021 Assert.AreEqual(children.Find("cn=John Smith").Name,"cn=John Smith");
\r
1025 public void DirectoryEntry_Name()
\r
1027 de = new DirectoryEntry(configuration.ConnectionString);
\r
1029 de = new DirectoryEntry(configuration.ConnectionString,
\r
1030 configuration.Username,
\r
1031 configuration.Password,
\r
1032 configuration.AuthenticationType);
\r
1034 de = new DirectoryEntry(configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)) ,
\r
1035 configuration.Username,
\r
1036 configuration.Password,
\r
1037 configuration.AuthenticationType);
\r
1038 Assert.AreEqual(de.Name,"ou=Human Resources");
\r
1040 de = new DirectoryEntry(configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)) ,
\r
1041 configuration.Username,
\r
1042 configuration.Password,
\r
1043 configuration.AuthenticationType);
\r
1044 Assert.AreEqual(de.Name,"cn=Barak Tsabari");
\r
1049 public void DirectoryEntry_Parent()
\r
1051 de = new DirectoryEntry(configuration.ConnectionString);
\r
1053 // MS works only with "LDAP" while RFC2255 states "ldap"
\r
1054 Assert.AreEqual(de.Parent.Path.ToLower(),(configuration.ServerRoot + GetParentDN (configuration.BaseDn)).ToLower());
\r
1056 de = new DirectoryEntry(configuration.ConnectionString,
\r
1057 configuration.Username,
\r
1058 configuration.Password,
\r
1059 configuration.AuthenticationType);
\r
1061 // MS works only with "LDAP" while RFC2255 states "ldap"
\r
1062 Assert.AreEqual(de.Parent.Path.ToLower(),(configuration.ServerRoot + GetParentDN (configuration.BaseDn)).ToLower());
\r
1064 de = new DirectoryEntry(configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)) ,
\r
1065 configuration.Username,
\r
1066 configuration.Password,
\r
1067 configuration.AuthenticationType);
\r
1069 // MS works only with "LDAP" while RFC2255 states "ldap"
\r
1070 Assert.AreEqual(de.Parent.Path.ToLower(),(configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn))).ToLower());
\r
1075 public void DirectoryEntry_Path()
\r
1077 string wrongPath = "something that is not LDAP path";
\r
1079 de = new DirectoryEntry();
\r
1081 Assert.AreEqual(de.Path,String.Empty);
\r
1083 de.Path = configuration.ConnectionString;
\r
1084 Assert.AreEqual(de.Path,configuration.ConnectionString);
\r
1087 Assert.AreEqual(de.Path,String.Empty);
\r
1089 de.Path = wrongPath;
\r
1090 Assert.AreEqual(de.Path,wrongPath);
\r
1093 de = new DirectoryEntry(configuration.ConnectionString);
\r
1095 de.Path = configuration.ConnectionString;
\r
1096 Assert.AreEqual(de.Path,configuration.ConnectionString);
\r
1099 Assert.AreEqual(de.Path,String.Empty);
\r
1101 de.Path = wrongPath;
\r
1102 Assert.AreEqual(de.Path,wrongPath);
\r
1105 de = new DirectoryEntry(configuration.ConnectionString,
\r
1106 configuration.Username,
\r
1107 configuration.Password,
\r
1108 configuration.AuthenticationType);
\r
1110 de.Path = configuration.ConnectionString;
\r
1111 Assert.AreEqual(de.Path,configuration.ConnectionString);
\r
1114 Assert.AreEqual(de.Path,String.Empty);
\r
1116 de.Path = wrongPath;
\r
1117 Assert.AreEqual(de.Path,wrongPath);
\r
1119 de = new DirectoryEntry("ldap://myhost:389/ou=people",null,null,AuthenticationTypes.None);
\r
1120 Assert.AreEqual(de.Path,"ldap://myhost:389/ou=people");
\r
1123 Assert.AreEqual(de.Path,String.Empty);
\r
1128 public void DirectoryEntry_Properties1()
\r
1130 de = new DirectoryEntry(configuration.ConnectionString);
\r
1132 Assert.AreEqual(de.Properties.Count,3);
\r
1133 Assert.AreEqual(((PropertyValueCollection)de.Properties["dc"]).Value,"example");
\r
1134 Assert.AreEqual(((PropertyValueCollection)de.Properties["description"]).Value,null);
\r
1137 de = new DirectoryEntry(configuration.ConnectionString,
\r
1138 configuration.Username,
\r
1139 configuration.Password,
\r
1140 configuration.AuthenticationType);
\r
1142 Assert.AreEqual(de.Properties.Count,3);
\r
1143 Assert.AreEqual(((PropertyValueCollection)de.Properties["dc"]).Value,"example");
\r
1144 Assert.AreEqual(((PropertyValueCollection)de.Properties["description"]).Value,null);
\r
1146 // ensure that properties are not accessible after removing an entry from the server
\r
1147 string barakTsabariDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1148 de = new DirectoryEntry(barakTsabariDN,
\r
1149 configuration.Username,
\r
1150 configuration.Password,
\r
1151 configuration.AuthenticationType);
\r
1156 int i = de.Properties.Count;
\r
1157 Assert.Fail("Properties should not be accessible after deleting an entry from the server");
\r
1159 catch(AssertionException ae) {
\r
1162 catch(Exception e) {
\r
1163 // supress exception
\r
1167 string s = (string)((PropertyValueCollection)de.Properties["dc"]).Value;
\r
1168 Assert.Fail("Properties should not be accessible after deleting an entry from the server");
\r
1170 catch(AssertionException ae) {
\r
1173 catch(Exception e) {
\r
1174 // supress exception
\r
1179 public void DirectoryEntry_Properties2()
\r
1181 // delete entry, create a new one (the same) and access properties of the old object
\r
1182 string barakTsabariDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1183 de = new DirectoryEntry(barakTsabariDN,
\r
1184 configuration.Username,
\r
1185 configuration.Password,
\r
1186 configuration.AuthenticationType);
\r
1188 // cause to properties loading
\r
1189 Assert.AreEqual(de.Properties.Count,6);
\r
1190 Assert.AreEqual(((PropertyValueCollection)de.Properties["sn"]).Value,"Tsabari");
\r
1195 // the local property chache is still accessible
\r
1196 Assert.AreEqual(de.Properties.Count,6);
\r
1197 Assert.AreEqual(((PropertyValueCollection)de.Properties["sn"]).Value,"Tsabari");
\r
1199 de.CommitChanges();
\r
1201 // the local property chache is still accessible
\r
1202 ((PropertyValueCollection)de.Properties["sn"]).Value = "Barbari";
\r
1204 // create the entry back again
\r
1205 using (DirectoryEntry ouHumanResources = new DirectoryEntry( configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
\r
1206 configuration.Username,
\r
1207 configuration.Password,
\r
1208 configuration.AuthenticationType)){
\r
1209 using (DirectoryEntry cnBarakTsabari = ouHumanResources.Children.Add("cn=Barak Tsabari","Class")){
\r
1210 ((PropertyValueCollection)cnBarakTsabari.Properties["objectClass"]).Add("person");
\r
1211 ((PropertyValueCollection)cnBarakTsabari.Properties["objectClass"]).Add("organizationalPerson");
\r
1212 cnBarakTsabari.Properties["cn"].Value = "Barak Tsabari";
\r
1213 cnBarakTsabari.Properties["facsimileTelephoneNumber"].Value = "+1 906 777 8853";
\r
1214 ((PropertyValueCollection)cnBarakTsabari.Properties["ou"]).Add("Human Resources");
\r
1215 ((PropertyValueCollection)cnBarakTsabari.Properties["ou"]).Add("People");
\r
1216 cnBarakTsabari.Properties["sn"].Value = "Tsabari";
\r
1217 cnBarakTsabari.Properties["telephoneNumber"].Value = "+1 906 777 8854";
\r
1218 cnBarakTsabari.CommitChanges();
\r
1222 // the local property chache is still accessible
\r
1223 Assert.AreEqual(((PropertyValueCollection)de.Properties["sn"]).Value,"Barbari");
\r
1225 // Refresh from server
\r
1226 de.RefreshCache();
\r
1227 // ensure the properties of an entry are still accessible through the old object
\r
1228 Assert.AreEqual(((PropertyValueCollection)de.Properties["sn"]).Value,"Tsabari");
\r
1234 [Category("NotWorking")]
\r
1235 public void DirectoryEntry_SchemaClassName()
\r
1237 de = new DirectoryEntry();
\r
1238 Assert.AreEqual(de.SchemaClassName,"domainDNS");
\r
1241 de = new DirectoryEntry(configuration.ConnectionString);
\r
1242 Assert.AreEqual(de.SchemaClassName,"organization");
\r
1245 de = new DirectoryEntry(configuration.ConnectionString,
\r
1246 configuration.Username,
\r
1247 configuration.Password,
\r
1248 configuration.AuthenticationType);
\r
1249 Assert.AreEqual(de.SchemaClassName,"organization");
\r
1251 DirectoryEntry de2 = de.Children.Add("ou=My Child","Class");
\r
1252 Assert.AreEqual(de2.SchemaClassName,"Class");
\r
1253 Assert.AreEqual(((PropertyValueCollection)de2.Properties["structuralObjectClass"]).Value,null);
\r
1257 [Category("NotWorking")]
\r
1258 public void DirectoryEntry_SchemaEntry()
\r
1260 de = new DirectoryEntry();
\r
1261 DirectoryEntry schemaEntry = de.SchemaEntry;
\r
1263 // MS works only with "LDAP" while RFC2255 states "ldap"
\r
1264 Assert.AreEqual(schemaEntry.Path.ToLower(),"LDAP://schema/domainDNS".ToLower());
\r
1265 Assert.AreEqual(schemaEntry.Name,"domainDNS");
\r
1266 Assert.AreEqual(schemaEntry.Username,null);
\r
1267 Assert.AreEqual(schemaEntry.UsePropertyCache,true);
\r
1268 Assert.AreEqual(schemaEntry.SchemaClassName,"Class");
\r
1269 Assert.AreEqual(schemaEntry.AuthenticationType,AuthenticationTypes.None);
\r
1272 de = new DirectoryEntry(configuration.ConnectionString);
\r
1273 schemaEntry = de.SchemaEntry;
\r
1275 Assert.AreEqual(schemaEntry.Path,configuration.ServerRoot + "schema/organization");
\r
1276 Assert.AreEqual(schemaEntry.Name,"organization");
\r
1277 Assert.AreEqual(schemaEntry.Username,null);
\r
1278 Assert.AreEqual(schemaEntry.UsePropertyCache,true);
\r
1279 Assert.AreEqual(schemaEntry.SchemaClassName,"Class");
\r
1280 Assert.AreEqual(schemaEntry.AuthenticationType,AuthenticationTypes.None);
\r
1283 de = new DirectoryEntry(configuration.ConnectionString,
\r
1284 configuration.Username,
\r
1285 configuration.Password,
\r
1286 configuration.AuthenticationType);
\r
1287 schemaEntry = de.SchemaEntry;
\r
1289 Assert.AreEqual(schemaEntry.Path,configuration.ServerRoot + "schema/organization");
\r
1290 Assert.AreEqual(schemaEntry.Name,"organization");
\r
1291 Assert.AreEqual(schemaEntry.Username,configuration.Username);
\r
1292 Assert.AreEqual(schemaEntry.UsePropertyCache,true);
\r
1293 Assert.AreEqual(schemaEntry.SchemaClassName,"Class");
\r
1294 Assert.AreEqual(schemaEntry.AuthenticationType,configuration.AuthenticationType);
\r
1299 public void DirectoryEntry_Username()
\r
1301 string wrongUsername = "some wrong username";
\r
1303 de = new DirectoryEntry();
\r
1305 Assert.AreEqual(de.Username,null);
\r
1307 de.Username = configuration.Username;
\r
1308 Assert.AreEqual(de.Username,configuration.Username);
\r
1311 Assert.AreEqual(de.Username,String.Empty);
\r
1313 de.Username = wrongUsername;
\r
1314 Assert.AreEqual(de.Username,wrongUsername);
\r
1317 de = new DirectoryEntry(configuration.ConnectionString);
\r
1319 de.Username = configuration.Username;
\r
1320 Assert.AreEqual(de.Username,configuration.Username);
\r
1323 Assert.AreEqual(de.Username,String.Empty);
\r
1325 de.Username = wrongUsername;
\r
1326 Assert.AreEqual(de.Username,wrongUsername);
\r
1329 de = new DirectoryEntry(configuration.ConnectionString,
\r
1330 configuration.Username,
\r
1331 configuration.Password,
\r
1332 configuration.AuthenticationType);
\r
1334 de.Username = configuration.Username;
\r
1335 Assert.AreEqual(de.Username,configuration.Username);
\r
1338 Assert.AreEqual(de.Username,String.Empty);
\r
1340 de.Username = wrongUsername;
\r
1341 Assert.AreEqual(de.Username,wrongUsername);
\r
1346 public void DirectoryEntry_Close()
\r
1348 de = new DirectoryEntry();
\r
1351 de = new DirectoryEntry(configuration.ConnectionString);
\r
1354 de = new DirectoryEntry(configuration.ConnectionString,
\r
1355 configuration.Username,
\r
1356 configuration.Password,
\r
1357 configuration.AuthenticationType);
\r
1363 public void DirectoryEntry_CommitChanges1()
\r
1365 string humanResourcesDN = configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1366 using (DirectoryEntry ouHumanResources = new DirectoryEntry( humanResourcesDN,
\r
1367 configuration.Username,
\r
1368 configuration.Password,
\r
1369 configuration.AuthenticationType)){
\r
1372 string newEmployeeDN = configuration.ServerRoot + "cn=New Employee,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1373 de = ouHumanResources.Children.Add("cn=New Employee","Class");
\r
1374 Assert.IsFalse(DirectoryEntry.Exists(newEmployeeDN));
\r
1376 de.Properties["objectClass"].Value = "organizationalRole";
\r
1377 de.Properties["cn"].Value = "New Employee";
\r
1378 Assert.IsFalse(DirectoryEntry.Exists(newEmployeeDN));
\r
1380 de.CommitChanges();
\r
1381 Assert.IsTrue(DirectoryEntry.Exists(newEmployeeDN));
\r
1385 string barakTsabariDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1386 de = new DirectoryEntry(barakTsabariDN,
\r
1387 configuration.Username,
\r
1388 configuration.Password,
\r
1389 configuration.AuthenticationType);
\r
1391 string oldTelephone = (string)((PropertyValueCollection)de.Properties["telephoneNumber"]).Value;
\r
1392 string newTelephone = "+972 3 6078596";
\r
1394 // UsePropertyCache - true
\r
1395 de.UsePropertyCache = true;
\r
1396 ((PropertyValueCollection)de.Properties["telephoneNumber"]).Value = newTelephone;
\r
1397 Assert.AreEqual(((PropertyValueCollection)de.Properties["telephoneNumber"]).Value,newTelephone);
\r
1399 using (DirectoryEntry cnBarakTsabari = new DirectoryEntry( barakTsabariDN,
\r
1400 configuration.Username,
\r
1401 configuration.Password,
\r
1402 configuration.AuthenticationType)){
\r
1404 //check that on server there is still an old value
\r
1405 Assert.AreEqual(((PropertyValueCollection)cnBarakTsabari.Properties["telephoneNumber"]).Value,oldTelephone);
\r
1407 de.CommitChanges();
\r
1410 using (DirectoryEntry cnBarakTsabari = new DirectoryEntry(barakTsabariDN,
\r
1411 configuration.Username,
\r
1412 configuration.Password,
\r
1413 configuration.AuthenticationType)){
\r
1415 // check that new value is updated on the server
\r
1416 Assert.AreEqual(((PropertyValueCollection)cnBarakTsabari.Properties["telephoneNumber"]).Value,newTelephone);
\r
1419 // UsePropertyCache - false
\r
1420 de = new DirectoryEntry(barakTsabariDN,
\r
1421 configuration.Username,
\r
1422 configuration.Password,
\r
1423 configuration.AuthenticationType);
\r
1424 de.UsePropertyCache = false;
\r
1425 Assert.AreEqual(((PropertyValueCollection)de.Properties["telephoneNumber"]).Value,newTelephone);
\r
1426 ((PropertyValueCollection)de.Properties["telephoneNumber"]).Value = oldTelephone;
\r
1427 Assert.AreEqual(((PropertyValueCollection)de.Properties["telephoneNumber"]).Value,oldTelephone);
\r
1429 using (DirectoryEntry cnBarakTsabari = new DirectoryEntry(barakTsabariDN,
\r
1430 configuration.Username,
\r
1431 configuration.Password,
\r
1432 configuration.AuthenticationType)){
\r
1434 // check that new value is updated on the server
\r
1435 //Assert.AreEqual(((PropertyValueCollection)cnBarakTsabari.Properties["telephoneNumber"]).Value,oldTelephone);
\r
1438 de.CommitChanges(); // this should do nothing
\r
1442 public void DirectoryEntry_CommitChanges2()
\r
1444 string barakTsabariDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1445 using (DirectoryEntry barakTsabariDE1 = new DirectoryEntry(barakTsabariDN,
\r
1446 configuration.Username,
\r
1447 configuration.Password,
\r
1448 configuration.AuthenticationType)){
\r
1449 barakTsabariDE1.UsePropertyCache = true;
\r
1451 using (DirectoryEntry barakTsabariDE2 = new DirectoryEntry(barakTsabariDN,
\r
1452 configuration.Username,
\r
1453 configuration.Password,
\r
1454 configuration.AuthenticationType)){
\r
1455 barakTsabariDE2.UsePropertyCache = true;
\r
1457 string oldTelephone = (string)((PropertyValueCollection)barakTsabariDE1.Properties["telephoneNumber"]).Value;
\r
1458 string newTelephone = "+972 3 6078596";
\r
1459 string oldFacsimilieTelephoneNumber = (string)((PropertyValueCollection)barakTsabariDE1.Properties["facsimileTelephoneNumber"]).Value;
\r
1460 string newFacsimilieTelephoneNumber1 = "+972-3-9872365";
\r
1461 string newFacsimilieTelephoneNumber2 = "+972-3-9999999";
\r
1463 barakTsabariDE1.Properties["telephoneNumber"].Value = newTelephone;
\r
1464 barakTsabariDE1.Properties["facsimileTelephoneNumber"].Value = newFacsimilieTelephoneNumber1;
\r
1466 barakTsabariDE2.Properties["facsimileTelephoneNumber"].Value = newFacsimilieTelephoneNumber2;
\r
1468 // only the changed properties of each object are set
\r
1470 barakTsabariDE1.CommitChanges();
\r
1471 de = new DirectoryEntry(barakTsabariDN,
\r
1472 configuration.Username,
\r
1473 configuration.Password,
\r
1474 configuration.AuthenticationType);
\r
1475 Assert.AreEqual(de.Properties["telephoneNumber"].Value,newTelephone);
\r
1476 Assert.AreEqual(de.Properties["facsimileTelephoneNumber"].Value,newFacsimilieTelephoneNumber1);
\r
1478 barakTsabariDE2.CommitChanges();
\r
1479 de = new DirectoryEntry(barakTsabariDN,
\r
1480 configuration.Username,
\r
1481 configuration.Password,
\r
1482 configuration.AuthenticationType);
\r
1483 Assert.AreEqual(de.Properties["telephoneNumber"].Value,newTelephone);
\r
1484 Assert.AreEqual(de.Properties["facsimileTelephoneNumber"].Value,newFacsimilieTelephoneNumber2);
\r
1491 [ExpectedException(typeof(NotImplementedException))]
\r
1492 public void DirectoryEntry_CopyTo()
\r
1494 string barakTsabariDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1495 de = new DirectoryEntry(configuration.ConnectionString,
\r
1496 configuration.Username,
\r
1497 configuration.Password,
\r
1498 configuration.AuthenticationType);
\r
1500 using (DirectoryEntry cnBarakTsabari = new DirectoryEntry( barakTsabariDN,
\r
1501 configuration.Username,
\r
1502 configuration.Password,
\r
1503 configuration.AuthenticationType)){
\r
1505 cnBarakTsabari.CopyTo(de);
\r
1511 public void DirectoryEntry_DeleteTree()
\r
1513 string barakTsabariDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1515 Assert.IsTrue(DirectoryEntry.Exists(barakTsabariDN));
\r
1516 de = new DirectoryEntry(barakTsabariDN,
\r
1517 configuration.Username,
\r
1518 configuration.Password,
\r
1519 configuration.AuthenticationType);
\r
1521 // no properties changed
\r
1523 de.CommitChanges();
\r
1525 Assert.IsFalse(DirectoryEntry.Exists(barakTsabariDN));
\r
1527 string johnSmithDN = configuration.ServerRoot + "cn=John Smith,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1529 Assert.IsTrue(DirectoryEntry.Exists(johnSmithDN));
\r
1530 de = new DirectoryEntry(johnSmithDN,
\r
1531 configuration.Username,
\r
1532 configuration.Password,
\r
1533 configuration.AuthenticationType);
\r
1535 de.Properties["telephoneNumber"].Value = "+972 3 9999999";
\r
1537 // some properties changed
\r
1540 de.CommitChanges();
\r
1541 Assert.Fail("Object " + johnSmithDN + " was not deleted from server");
\r
1543 catch(AssertionException ae) {
\r
1546 catch(Exception e) {
\r
1552 public void DirectoryEntry_DeleteTree2()
\r
1554 string johnSmithDN = configuration.ServerRoot + "cn=John Smith,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1556 Assert.IsTrue(DirectoryEntry.Exists(johnSmithDN));
\r
1557 // two objects refer to the same entry
\r
1558 de = new DirectoryEntry(johnSmithDN,
\r
1559 configuration.Username,
\r
1560 configuration.Password,
\r
1561 configuration.AuthenticationType);
\r
1563 using (DirectoryEntry johnSmithDE = new DirectoryEntry(johnSmithDN,
\r
1564 configuration.Username,
\r
1565 configuration.Password,
\r
1566 configuration.AuthenticationType)){
\r
1568 johnSmithDE.Properties["telephoneNumber"].Value = "+972 3 9999999";
\r
1570 // check that the second entry is not accessible after the first is deleted
\r
1572 de.CommitChanges();
\r
1575 johnSmithDE.CommitChanges();
\r
1576 Assert.Fail("Object " + johnSmithDN + " should not be accessible");
\r
1578 catch(AssertionException ae) {
\r
1581 catch(Exception e) {
\r
1589 public void DirectoryEntry_Exists()
\r
1591 string barakTsabariDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1592 string johnSmithDN = configuration.ServerRoot + "cn=John Smith,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1593 string humanResourcesOU = configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1595 Assert.IsTrue(DirectoryEntry.Exists(barakTsabariDN));
\r
1596 Assert.IsTrue(DirectoryEntry.Exists(johnSmithDN));
\r
1597 Assert.IsTrue(DirectoryEntry.Exists(humanResourcesOU));
\r
1599 Assert.IsFalse(DirectoryEntry.Exists(barakTsabariDN + ",dc=mono"));
\r
1604 public void DirectoryEntry_MoveTo_De()
\r
1606 string barakTsabariHumanResourcesDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1607 string barakTsabariDevQaDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=DevQA,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1609 using (DirectoryEntry barakTsabariDE = new DirectoryEntry( barakTsabariHumanResourcesDN,
\r
1610 configuration.Username,
\r
1611 configuration.Password,
\r
1612 configuration.AuthenticationType)){
\r
1614 string devQaOU = configuration.ServerRoot + "ou=DevQA,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1616 using (DirectoryEntry devQaDE = new DirectoryEntry(devQaOU,
\r
1617 configuration.Username,
\r
1618 configuration.Password,
\r
1619 configuration.AuthenticationType)){
\r
1621 barakTsabariDE.MoveTo(devQaDE);
\r
1622 barakTsabariDE.CommitChanges();
\r
1624 Assert.IsTrue(DirectoryEntry.Exists(barakTsabariDevQaDN));
\r
1626 string humanRwsourcesOU = configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1628 using (DirectoryEntry humanResourcesDE = new DirectoryEntry( humanRwsourcesOU,
\r
1629 configuration.Username,
\r
1630 configuration.Password,
\r
1631 configuration.AuthenticationType)){
\r
1633 barakTsabariDE.MoveTo(humanResourcesDE);
\r
1634 barakTsabariDE.CommitChanges();
\r
1636 Assert.IsTrue(DirectoryEntry.Exists(barakTsabariHumanResourcesDN));
\r
1644 public void DirectoryEntry_MoveTo_DeStr()
\r
1646 string barakTsabariHumanResourcesDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1647 string barakTsabariDevQaDN = configuration.ServerRoot + "cn=My Name,ou=DevQA,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1649 using (DirectoryEntry barakTsabariDE = new DirectoryEntry( barakTsabariHumanResourcesDN,
\r
1650 configuration.Username,
\r
1651 configuration.Password,
\r
1652 configuration.AuthenticationType)){
\r
1654 string devQaOU = configuration.ServerRoot + "ou=DevQA,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1656 using (DirectoryEntry devQaDE = new DirectoryEntry(devQaOU,
\r
1657 configuration.Username,
\r
1658 configuration.Password,
\r
1659 configuration.AuthenticationType)){
\r
1661 barakTsabariDE.MoveTo(devQaDE,"cn=My Name");
\r
1662 barakTsabariDE.CommitChanges();
\r
1664 Assert.IsTrue(DirectoryEntry.Exists(barakTsabariDevQaDN));
\r
1666 string humanRwsourcesOU = configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1668 using (DirectoryEntry humanResourcesDE = new DirectoryEntry( humanRwsourcesOU,
\r
1669 configuration.Username,
\r
1670 configuration.Password,
\r
1671 configuration.AuthenticationType)){
\r
1673 barakTsabariDE.MoveTo(humanResourcesDE,"cn=Barak Tsabari");
\r
1674 barakTsabariDE.CommitChanges();
\r
1676 Assert.IsTrue(DirectoryEntry.Exists(barakTsabariHumanResourcesDN));
\r
1683 public void DirectoryEntry_RefreshCache()
\r
1685 de = new DirectoryEntry(configuration.ConnectionString);
\r
1686 de.UsePropertyCache = true;
\r
1688 string newValue = "Just a company";
\r
1689 string oldValue = (string)((PropertyValueCollection)de.Properties["description"]).Value;
\r
1690 ((PropertyValueCollection)de.Properties["description"]).Value = newValue;
\r
1692 Assert.AreEqual(((PropertyValueCollection)de.Properties["description"]).Value,newValue);
\r
1694 de.RefreshCache();
\r
1696 Assert.AreEqual(((PropertyValueCollection)de.Properties["description"]).Value,oldValue);
\r
1698 // call RefeshCache on new entry prior to submitting it to the server shoud fail
\r
1699 string newEmployeeDN = configuration.ServerRoot + "cn=New Employee,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1700 string humanResourcesDN = configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1702 using (DirectoryEntry humanResourcesDE = new DirectoryEntry( humanResourcesDN,
\r
1703 configuration.Username,
\r
1704 configuration.Password,
\r
1705 configuration.AuthenticationType)){
\r
1707 using (DirectoryEntry newEmployeeDE = humanResourcesDE.Children.Add("cn=New Employee","Class")){
\r
1708 Assert.AreEqual(newEmployeeDE.Properties["cn"].Value,null);
\r
1710 ((PropertyValueCollection)newEmployeeDE.Properties["objectClass"]).Add("person");
\r
1711 ((PropertyValueCollection)newEmployeeDE.Properties["objectClass"]).Add("organizationalPerson");
\r
1712 newEmployeeDE.Properties["cn"].Value = "New Employee";
\r
1713 newEmployeeDE.Properties["sn"].Value = "Employee";
\r
1714 newEmployeeDE.Properties["ou"].Value = "Human Resources";
\r
1716 Assert.AreEqual(newEmployeeDE.Properties["cn"].Value,"New Employee");
\r
1719 newEmployeeDE.RefreshCache();
\r
1720 Assert.Fail("Call to RefreshCache did not fail");
\r
1722 catch(AssertionException ae) {
\r
1725 catch (Exception e) {
\r
1726 // supress exception
\r
1729 Assert.AreEqual(newEmployeeDE.Properties["cn"].Value,"New Employee");
\r
1731 newEmployeeDE.CommitChanges();
\r
1733 // now it should work without any problem
\r
1734 newEmployeeDE.RefreshCache();
\r
1736 Assert.AreEqual(newEmployeeDE.Properties["cn"].Value,"New Employee");
\r
1742 public void DirectoryEntry_RefreshCache_StrArr()
\r
1744 de = new DirectoryEntry(configuration.ServerRoot + "cn=Uzi Cohen,cn=Manager" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)));
\r
1745 de.UsePropertyCache = true;
\r
1747 string[] newValues = new string [] { "Just a manager", "Levi" };
\r
1748 string[] oldValues = new string [2];
\r
1749 oldValues [0] = (string)((PropertyValueCollection)de.Properties["description"]).Value;
\r
1750 oldValues [1] = (string)((PropertyValueCollection)de.Properties["sn"]).Value;
\r
1752 ((PropertyValueCollection)de.Properties["description"]).Value = newValues [0];
\r
1753 ((PropertyValueCollection)de.Properties["sn"]).Value = newValues [1];
\r
1755 Assert.AreEqual(((PropertyValueCollection)de.Properties["description"]).Value,newValues [0]);
\r
1756 Assert.AreEqual(((PropertyValueCollection)de.Properties["sn"]).Value,newValues [1]);
\r
1758 de.RefreshCache(new string[] {"cn"});
\r
1760 Assert.AreEqual(((PropertyValueCollection)de.Properties["description"]).Value,newValues [0]);
\r
1761 Assert.AreEqual(((PropertyValueCollection)de.Properties["sn"]).Value,newValues [1]);
\r
1763 de.RefreshCache(new string[] {"description","sn"});
\r
1765 Assert.AreEqual(((PropertyValueCollection)de.Properties["description"]).Value,newValues [0]);
\r
1766 Assert.AreEqual(((PropertyValueCollection)de.Properties["sn"]).Value,oldValues [1]);
\r
1770 public void DirectoryEntry_Rename()
\r
1772 string barakTsabariOldDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1773 string barakTsabariNewDN = configuration.ServerRoot + "cn=My Name,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1775 using (DirectoryEntry barakTsabariDE = new DirectoryEntry( barakTsabariOldDN,
\r
1776 configuration.Username,
\r
1777 configuration.Password,
\r
1778 configuration.AuthenticationType)){
\r
1780 barakTsabariDE.Rename("cn=My Name");
\r
1781 barakTsabariDE.CommitChanges();
\r
1783 Assert.IsTrue(DirectoryEntry.Exists(barakTsabariNewDN));
\r
1785 barakTsabariDE.Rename("cn=Barak Tsabari");
\r
1786 barakTsabariDE.CommitChanges();
\r
1788 Assert.IsTrue(DirectoryEntry.Exists(barakTsabariOldDN));
\r
1794 private static string GetName (string baseDn)
\r
1796 if (baseDn == null || baseDn.Length == 0 || baseDn.IndexOf (',') == -1)
\r
1799 int index = baseDn.IndexOf (',');
\r
1801 return baseDn.Substring (0, index);
\r
1804 private static string GetParentDN (string baseDn)
\r
1806 if (baseDn == null || baseDn.Length == 0 || baseDn.IndexOf (',') == -1)
\r
1807 return String.Empty;
\r
1809 int index = baseDn.IndexOf (',');
\r
1811 return baseDn.Substring (index + 1,baseDn.Length - index - 1);
\r