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.Password,null);
\r
255 Assert.AreEqual(de.Path,String.Empty);
\r
256 Assert.AreEqual(de.UsePropertyCache,true);
\r
257 Assert.AreEqual(de.Username,null);
\r
262 public void DirectoryEntry_DirectoryEntry_Str()
\r
264 using (DirectoryEntry de = new DirectoryEntry(configuration.ConnectionString)) {
\r
266 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.None);
\r
267 Assert.AreEqual(de.Name,GetName (configuration.BaseDn));
\r
268 Assert.AreEqual(de.Password,null);
\r
269 Assert.AreEqual(de.Path,configuration.ConnectionString);
\r
270 Assert.AreEqual(de.SchemaClassName,"organization");
\r
271 Assert.AreEqual(de.UsePropertyCache,true);
\r
272 Assert.AreEqual(de.Username,null);
\r
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.Password,configuration.Password);
\r
297 Assert.AreEqual(de.Path,configuration.ConnectionString);
\r
298 Assert.AreEqual(de.SchemaClassName,"organization");
\r
299 Assert.AreEqual(de.UsePropertyCache,true);
\r
300 Assert.AreEqual(de.Username,configuration.Username);
\r
303 #endregion //AuthenticationTypes.Anonymous
\r
305 #region AuthenticationTypes.Delegation
\r
307 using (DirectoryEntry de = new DirectoryEntry(configuration.ConnectionString,
\r
308 configuration.Username,
\r
309 configuration.Password,
\r
310 AuthenticationTypes.Delegation)){
\r
312 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Delegation);
\r
313 //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));
\r
314 Assert.AreEqual(de.Name,GetName (configuration.BaseDn));
\r
315 //Assert.AreEqual(de.NativeGuid,null);
\r
316 Assert.AreEqual(de.Password,configuration.Password);
\r
317 Assert.AreEqual(de.Path,configuration.ConnectionString);
\r
318 Assert.AreEqual(de.SchemaClassName,"organization");
\r
319 Assert.AreEqual(de.UsePropertyCache,true);
\r
320 Assert.AreEqual(de.Username,configuration.Username);
\r
323 #endregion //AuthenticationTypes.Delegation
\r
325 #region AuthenticationTypes.Encryption
\r
327 // de = new DirectoryEntry( configuration.ConnectionString,
\r
328 // configuration.Username,
\r
329 // configuration.Password,
\r
330 // AuthenticationTypes.Encryption);
\r
332 // Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Encryption);
\r
333 // //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));
\r
334 // Assert.AreEqual(de.Name,"dc=myhosting");
\r
335 // //Assert.AreEqual(de.NativeGuid,null);
\r
336 // Assert.AreEqual(de.Password,configuration.Password);
\r
337 // Assert.AreEqual(de.Path,configuration.ConnectionString);
\r
338 // Assert.AreEqual(de.SchemaClassName,"organization");
\r
339 // Assert.AreEqual(de.UsePropertyCache,true);
\r
340 // Assert.AreEqual(de.Username,configuration.Username);
\r
342 #endregion //AuthenticationTypes.Encryption
\r
344 #region AuthenticationTypes.FastBind
\r
346 using (DirectoryEntry de = new DirectoryEntry(configuration.ConnectionString,
\r
347 configuration.Username,
\r
348 configuration.Password,
\r
349 AuthenticationTypes.FastBind)){
\r
351 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.FastBind);
\r
352 //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));
\r
353 Assert.AreEqual(de.Name,GetName (configuration.BaseDn));
\r
354 //Assert.AreEqual(de.NativeGuid,null);
\r
355 Assert.AreEqual(de.Password,configuration.Password);
\r
356 Assert.AreEqual(de.Path,configuration.ConnectionString);
\r
357 Assert.AreEqual(de.SchemaClassName,"organization");
\r
358 Assert.AreEqual(de.UsePropertyCache,true);
\r
359 Assert.AreEqual(de.Username,configuration.Username);
\r
362 #endregion //AuthenticationTypes.FastBind
\r
364 #region AuthenticationTypes.None
\r
366 using (DirectoryEntry de = new DirectoryEntry(configuration.ConnectionString,
\r
367 configuration.Username,
\r
368 configuration.Password,
\r
369 AuthenticationTypes.None)){
\r
371 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.None);
\r
372 //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));
\r
373 Assert.AreEqual(de.Name,GetName (configuration.BaseDn));
\r
374 //Assert.AreEqual(de.NativeGuid,null);
\r
375 Assert.AreEqual(de.Password,configuration.Password);
\r
376 Assert.AreEqual(de.Path,configuration.ConnectionString);
\r
377 Assert.AreEqual(de.SchemaClassName,"organization");
\r
378 Assert.AreEqual(de.UsePropertyCache,true);
\r
379 Assert.AreEqual(de.Username,configuration.Username);
\r
382 #endregion //AuthenticationTypes.None
\r
384 #region AuthenticationTypes.ReadonlyServer
\r
386 using (DirectoryEntry de = new DirectoryEntry(configuration.ConnectionString,
\r
387 configuration.Username,
\r
388 configuration.Password,
\r
389 AuthenticationTypes.ReadonlyServer)){
\r
391 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.ReadonlyServer);
\r
392 //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));
\r
393 Assert.AreEqual(de.Name,GetName (configuration.BaseDn));
\r
394 //Assert.AreEqual(de.NativeGuid,null);
\r
395 Assert.AreEqual(de.Password,configuration.Password);
\r
396 Assert.AreEqual(de.Path,configuration.ConnectionString);
\r
397 Assert.AreEqual(de.SchemaClassName,"organization");
\r
398 Assert.AreEqual(de.UsePropertyCache,true);
\r
399 Assert.AreEqual(de.Username,configuration.Username);
\r
402 #endregion //AuthenticationTypes.ReadonlyServer
\r
404 #region AuthenticationTypes.Sealing
\r
406 using (DirectoryEntry de = new DirectoryEntry(configuration.ConnectionString,
\r
407 configuration.Username,
\r
408 configuration.Password,
\r
409 AuthenticationTypes.Sealing)){
\r
411 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Sealing);
\r
412 //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));
\r
413 Assert.AreEqual(de.Name,GetName (configuration.BaseDn));
\r
414 //Assert.AreEqual(de.NativeGuid,null);
\r
415 Assert.AreEqual(de.Password,configuration.Password);
\r
416 Assert.AreEqual(de.Path,configuration.ConnectionString);
\r
417 Assert.AreEqual(de.SchemaClassName,"organization");
\r
418 Assert.AreEqual(de.UsePropertyCache,true);
\r
419 Assert.AreEqual(de.Username,configuration.Username);
\r
422 #endregion //AuthenticationTypes.Sealing
\r
424 #region AuthenticationTypes.Secure
\r
426 // de = new DirectoryEntry(configuration.ConnectionString,
\r
427 // configuration.Username,
\r
428 // configuration.Password,
\r
429 // AuthenticationTypes.Secure);
\r
431 // Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Secure);
\r
432 // //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));
\r
433 // Assert.AreEqual(de.Name,"dc=myhosting");
\r
434 // //Assert.AreEqual(de.NativeGuid,null);
\r
435 // Assert.AreEqual(de.Password,configuration.Password);
\r
436 // Assert.AreEqual(de.Path,configuration.ConnectionString);
\r
437 // Assert.AreEqual(de.SchemaClassName,"organization");
\r
438 // Assert.AreEqual(de.UsePropertyCache,true);
\r
439 // Assert.AreEqual(de.Username,configuration.Username);
\r
441 #endregion //AuthenticationTypes.Secure
\r
443 #region AuthenticationTypes.SecureSocketsLayer
\r
445 // de = new DirectoryEntry(configuration.ConnectionString,
\r
446 // configuration.Username,
\r
447 // configuration.Password,
\r
448 // AuthenticationTypes.SecureSocketsLayer);
\r
450 // Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.SecureSocketsLayer);
\r
451 // //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));
\r
452 // Assert.AreEqual(de.Name,"dc=myhosting");
\r
453 // //Assert.AreEqual(de.NativeGuid,null);
\r
454 // Assert.AreEqual(de.Password,configuration.Password);
\r
455 // Assert.AreEqual(de.Path,configuration.ConnectionString);
\r
456 // Assert.AreEqual(de.SchemaClassName,"organization");
\r
457 // Assert.AreEqual(de.UsePropertyCache,true);
\r
458 // Assert.AreEqual(de.Username,configuration.Username);
\r
460 #endregion //AuthenticationTypes.SecureSocketsLayer
\r
462 #region AuthenticationTypes.ServerBind
\r
464 using (DirectoryEntry de = new DirectoryEntry(configuration.ConnectionString,
\r
465 configuration.Username,
\r
466 configuration.Password,
\r
467 AuthenticationTypes.ServerBind)){
\r
469 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.ServerBind);
\r
470 //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));
\r
471 Assert.AreEqual(de.Name,GetName (configuration.BaseDn));
\r
472 //Assert.AreEqual(de.NativeGuid,null);
\r
473 Assert.AreEqual(de.Password,configuration.Password);
\r
474 Assert.AreEqual(de.Path,configuration.ConnectionString);
\r
475 Assert.AreEqual(de.SchemaClassName,"organization");
\r
476 Assert.AreEqual(de.UsePropertyCache,true);
\r
477 Assert.AreEqual(de.Username,configuration.Username);
\r
480 #endregion //AuthenticationTypes.ServerBind
\r
482 #region AuthenticationTypes.Signing
\r
484 using (DirectoryEntry de = new DirectoryEntry(configuration.ConnectionString,
\r
485 configuration.Username,
\r
486 configuration.Password,
\r
487 AuthenticationTypes.Signing)){
\r
489 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Signing);
\r
490 //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));
\r
491 Assert.AreEqual(de.Name,GetName (configuration.BaseDn));
\r
492 //Assert.AreEqual(de.NativeGuid,null);
\r
493 Assert.AreEqual(de.Password,configuration.Password);
\r
494 Assert.AreEqual(de.Path,configuration.ConnectionString);
\r
495 Assert.AreEqual(de.SchemaClassName,"organization");
\r
496 Assert.AreEqual(de.UsePropertyCache,true);
\r
497 Assert.AreEqual(de.Username,configuration.Username);
\r
500 #endregion //AuthenticationTypes.Signing
\r
504 public void DirectoryEntry_Dispose()
\r
506 using (DirectoryEntry root = new DirectoryEntry( configuration.ConnectionString,
\r
507 configuration.Username,
\r
508 configuration.Password,
\r
509 configuration.AuthenticationType)){
\r
511 DirectoryEntry ouPeople = root.Children.Add("ou=printers","Class");
\r
512 ouPeople.Properties["objectClass"].Value = "organizationalUnit";
\r
513 ouPeople.Properties["description"].Value = "All printers in organisation";
\r
514 ouPeople.Properties["ou"].Value = "printers";
\r
515 ouPeople.CommitChanges();
\r
517 ouPeople.Rename("ou=anotherPrinters");
\r
518 ouPeople.CommitChanges();
\r
520 Assert.IsTrue(DirectoryEntry.Exists(configuration.ServerRoot + "ou=anotherPrinters" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn))));
\r
526 public void DirectoryEntry_AuthenticationType()
\r
528 de = new DirectoryEntry();
\r
530 de.AuthenticationType = AuthenticationTypes.Anonymous;
\r
531 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Anonymous);
\r
533 de.AuthenticationType = AuthenticationTypes.Delegation;
\r
534 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Delegation);
\r
536 de.AuthenticationType = AuthenticationTypes.Encryption;
\r
537 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Encryption);
\r
539 de.AuthenticationType = AuthenticationTypes.FastBind;
\r
540 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.FastBind);
\r
542 de.AuthenticationType = AuthenticationTypes.None;
\r
543 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.None);
\r
545 de.AuthenticationType = AuthenticationTypes.ReadonlyServer;
\r
546 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.ReadonlyServer);
\r
548 de.AuthenticationType = AuthenticationTypes.Sealing;
\r
549 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Sealing);
\r
551 de.AuthenticationType = AuthenticationTypes.Secure;
\r
552 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Secure);
\r
554 de.AuthenticationType = AuthenticationTypes.SecureSocketsLayer;
\r
555 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.SecureSocketsLayer);
\r
557 de.AuthenticationType = AuthenticationTypes.ServerBind;
\r
558 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.ServerBind);
\r
560 de.AuthenticationType = AuthenticationTypes.Signing;
\r
561 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Signing);
\r
563 de = new DirectoryEntry(configuration.ConnectionString);
\r
565 de.AuthenticationType = AuthenticationTypes.Anonymous;
\r
566 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Anonymous);
\r
568 de.AuthenticationType = AuthenticationTypes.Delegation;
\r
569 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Delegation);
\r
571 de.AuthenticationType = AuthenticationTypes.Encryption;
\r
572 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Encryption);
\r
574 de.AuthenticationType = AuthenticationTypes.FastBind;
\r
575 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.FastBind);
\r
577 de.AuthenticationType = AuthenticationTypes.None;
\r
578 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.None);
\r
580 de.AuthenticationType = AuthenticationTypes.ReadonlyServer;
\r
581 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.ReadonlyServer);
\r
583 de.AuthenticationType = AuthenticationTypes.Sealing;
\r
584 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Sealing);
\r
586 de.AuthenticationType = AuthenticationTypes.Secure;
\r
587 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Secure);
\r
589 de.AuthenticationType = AuthenticationTypes.SecureSocketsLayer;
\r
590 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.SecureSocketsLayer);
\r
592 de.AuthenticationType = AuthenticationTypes.ServerBind;
\r
593 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.ServerBind);
\r
595 de.AuthenticationType = AuthenticationTypes.Signing;
\r
596 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Signing);
\r
598 de = new DirectoryEntry(configuration.ConnectionString,
\r
599 configuration.Username,
\r
600 configuration.Password,
\r
601 AuthenticationTypes.None);
\r
603 de.AuthenticationType = AuthenticationTypes.Anonymous;
\r
604 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Anonymous);
\r
606 de.AuthenticationType = AuthenticationTypes.Delegation;
\r
607 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Delegation);
\r
609 de.AuthenticationType = AuthenticationTypes.Encryption;
\r
610 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Encryption);
\r
612 de.AuthenticationType = AuthenticationTypes.FastBind;
\r
613 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.FastBind);
\r
615 de.AuthenticationType = AuthenticationTypes.None;
\r
616 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.None);
\r
618 de.AuthenticationType = AuthenticationTypes.ReadonlyServer;
\r
619 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.ReadonlyServer);
\r
621 de.AuthenticationType = AuthenticationTypes.Sealing;
\r
622 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Sealing);
\r
624 de.AuthenticationType = AuthenticationTypes.Secure;
\r
625 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Secure);
\r
627 de.AuthenticationType = AuthenticationTypes.SecureSocketsLayer;
\r
628 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.SecureSocketsLayer);
\r
630 de.AuthenticationType = AuthenticationTypes.ServerBind;
\r
631 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.ServerBind);
\r
633 de.AuthenticationType = AuthenticationTypes.Signing;
\r
634 Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Signing);
\r
639 public void DirectoryEntry_UsePropertyCache()
\r
641 string barakTsabariDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
642 de = new DirectoryEntry(barakTsabariDN,
\r
643 configuration.Username,
\r
644 configuration.Password,
\r
645 configuration.AuthenticationType);
\r
647 // UsePropertyCache = true
\r
648 de.UsePropertyCache = true;
\r
649 Assert.AreEqual(de.UsePropertyCache,true);
\r
651 #region Check Properties
\r
653 // Properties changes are cached
\r
654 string oldTelephoneNumber = (string)de.Properties["telephoneNumber"].Value;
\r
655 string newTelephoneNumber = "+972-3-6572345";
\r
657 de.Properties["telephoneNumber"].Value = newTelephoneNumber;
\r
658 using (DirectoryEntry barakTsabariDE = new DirectoryEntry( barakTsabariDN,
\r
659 configuration.Username,
\r
660 configuration.Password,
\r
661 configuration.AuthenticationType)){
\r
663 Assert.AreEqual(barakTsabariDE.Properties["telephoneNumber"].Value,oldTelephoneNumber);
\r
664 de.CommitChanges();
\r
666 using (DirectoryEntry barakTsabariDE = new DirectoryEntry(barakTsabariDN,
\r
667 configuration.Username,
\r
668 configuration.Password,
\r
669 configuration.AuthenticationType)){
\r
670 Assert.AreEqual(barakTsabariDE.Properties["telephoneNumber"].Value,newTelephoneNumber);
\r
672 // restore object state
\r
673 de.Properties["telephoneNumber"].Value = oldTelephoneNumber;
\r
674 de.CommitChanges();
\r
677 #endregion // Check Properties
\r
679 #region Check DeleteTree
\r
681 // DeleteTree is not cached
\r
684 using (DirectoryEntry barakTsabariDE = new DirectoryEntry(barakTsabariDN,
\r
685 configuration.Username,
\r
686 configuration.Password,
\r
687 configuration.AuthenticationType)){
\r
688 barakTsabariDE.Properties["telephoneNumber"].Value = newTelephoneNumber;
\r
689 barakTsabariDE.CommitChanges();
\r
690 Assert.Fail("Object " + barakTsabariDN + " was not deleted from server.");
\r
693 catch(AssertionException ae) {
\r
696 catch (Exception e) {
\r
700 // restore object state
\r
701 using (DirectoryEntry ouHumanResources = new DirectoryEntry( configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
\r
702 configuration.Username,
\r
703 configuration.Password,
\r
704 configuration.AuthenticationType)){
\r
705 using (DirectoryEntry cnBarakTsabari = ouHumanResources.Children.Add("cn=Barak Tsabari","Class")){
\r
706 ((PropertyValueCollection)cnBarakTsabari.Properties["objectClass"]).Add("person");
\r
707 ((PropertyValueCollection)cnBarakTsabari.Properties["objectClass"]).Add("organizationalPerson");
\r
708 cnBarakTsabari.Properties["cn"].Value = "Barak Tsabari";
\r
709 cnBarakTsabari.Properties["facsimileTelephoneNumber"].Value = "+1 906 777 8853";
\r
710 ((PropertyValueCollection)cnBarakTsabari.Properties["ou"]).Add("Human Resources");
\r
711 ((PropertyValueCollection)cnBarakTsabari.Properties["ou"]).Add("People");
\r
712 cnBarakTsabari.Properties["sn"].Value = "Tsabari";
\r
713 cnBarakTsabari.Properties["telephoneNumber"].Value = "+1 906 777 8854";
\r
714 cnBarakTsabari.CommitChanges();
\r
718 #endregion // Check DeleteTree
\r
720 #region Check MoveTo
\r
722 // Move to is not cached
\r
723 de = new DirectoryEntry(barakTsabariDN,
\r
724 configuration.Username,
\r
725 configuration.Password,
\r
726 configuration.AuthenticationType);
\r
728 using (DirectoryEntry ouRnD = new DirectoryEntry( configuration.ServerRoot + "ou=R&D,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
\r
729 configuration.Username,
\r
730 configuration.Password,
\r
731 configuration.AuthenticationType)){
\r
734 using (DirectoryEntry barakTsabariDE = new DirectoryEntry(barakTsabariDN,
\r
735 configuration.Username,
\r
736 configuration.Password,
\r
737 configuration.AuthenticationType)){
\r
738 barakTsabariDE.Properties["telephoneNumber"].Value = newTelephoneNumber;
\r
739 barakTsabariDE.CommitChanges();
\r
740 Assert.Fail("Object " + barakTsabariDN + " was not moved from old location on the server.");
\r
743 catch(AssertionException ae) {
\r
746 catch (Exception e) {
\r
751 using (DirectoryEntry barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=Barak Tsabari,ou=R&D,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
\r
752 configuration.Username,
\r
753 configuration.Password,
\r
754 configuration.AuthenticationType)){
\r
755 Assert.AreEqual(barakTsabariDE.Properties["telephoneNumber"].Value,oldTelephoneNumber);
\r
759 // restore object state
\r
760 using (DirectoryEntry ouHumanResources = new DirectoryEntry( configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
\r
761 configuration.Username,
\r
762 configuration.Password,
\r
763 configuration.AuthenticationType)){
\r
764 using (DirectoryEntry barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=Barak Tsabari,ou=R&D,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
\r
765 configuration.Username,
\r
766 configuration.Password,
\r
767 configuration.AuthenticationType)){
\r
768 barakTsabariDE.MoveTo(ouHumanResources);
\r
769 barakTsabariDE.CommitChanges();
\r
773 #endregion // Check MoveTo
\r
775 #region Check Rename
\r
777 // Rename not chached
\r
778 de = new DirectoryEntry(barakTsabariDN,
\r
779 configuration.Username,
\r
780 configuration.Password,
\r
781 configuration.AuthenticationType);
\r
783 de.Rename("cn=MyUser");
\r
786 using (DirectoryEntry barakTsabariDE = new DirectoryEntry(barakTsabariDN,
\r
787 configuration.Username,
\r
788 configuration.Password,
\r
789 configuration.AuthenticationType)){
\r
790 barakTsabariDE.Properties["telephoneNumber"].Value = newTelephoneNumber;
\r
791 barakTsabariDE.CommitChanges();
\r
792 Assert.Fail("Object " + barakTsabariDN + " was not renamed on the server.");
\r
795 catch(AssertionException ae) {
\r
798 catch (Exception e) {
\r
802 using (DirectoryEntry barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=MyUser,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
\r
803 configuration.Username,
\r
804 configuration.Password,
\r
805 configuration.AuthenticationType)){
\r
806 Assert.AreEqual(barakTsabariDE.Properties["telephoneNumber"].Value,oldTelephoneNumber);
\r
809 // restore object state
\r
810 using (DirectoryEntry barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=MyUser,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
\r
811 configuration.Username,
\r
812 configuration.Password,
\r
813 configuration.AuthenticationType)){
\r
814 barakTsabariDE.Rename("cn=Barak Tsabari");
\r
815 barakTsabariDE.CommitChanges();
\r
818 #endregion // Check Rename
\r
820 // UsePropertyCache = false
\r
821 de = new DirectoryEntry(barakTsabariDN,
\r
822 configuration.Username,
\r
823 configuration.Password,
\r
824 configuration.AuthenticationType);
\r
825 de.UsePropertyCache = false;
\r
826 Assert.AreEqual(de.UsePropertyCache,false);
\r
828 #region Check Properties
\r
830 // Properties changes not cached
\r
831 de.Properties["telephoneNumber"].Value = newTelephoneNumber;
\r
832 using (DirectoryEntry barakTsabariDE = new DirectoryEntry(barakTsabariDN,
\r
833 configuration.Username,
\r
834 configuration.Password,
\r
835 configuration.AuthenticationType)){
\r
838 //Assert.AreEqual(barakTsabariDE.Properties["telephoneNumber"].Value,newTelephoneNumber);
\r
840 #endregion // Check Properties
\r
842 #region Check DeleteTree
\r
844 // DeleteTree is not cached
\r
847 using (DirectoryEntry barakTsabariDE = new DirectoryEntry(barakTsabariDN,
\r
848 configuration.Username,
\r
849 configuration.Password,
\r
850 configuration.AuthenticationType)){
\r
851 barakTsabariDE.Properties["telephoneNumber"].Value = newTelephoneNumber;
\r
852 barakTsabariDE.CommitChanges();
\r
853 Assert.Fail("Object " + barakTsabariDN + " was not deleted from server.");
\r
856 catch(AssertionException ae) {
\r
859 catch (Exception e) {
\r
863 // restore object state
\r
864 using (DirectoryEntry ouHumanResources = new DirectoryEntry( configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
\r
865 configuration.Username,
\r
866 configuration.Password,
\r
867 configuration.AuthenticationType)){
\r
868 using (DirectoryEntry cnBarakTsabari = ouHumanResources.Children.Add("cn=Barak Tsabari","Class")){
\r
869 ((PropertyValueCollection)cnBarakTsabari.Properties["objectClass"]).Add("person");
\r
870 ((PropertyValueCollection)cnBarakTsabari.Properties["objectClass"]).Add("organizationalPerson");
\r
871 cnBarakTsabari.Properties["cn"].Value = "Barak Tsabari";
\r
872 cnBarakTsabari.Properties["facsimileTelephoneNumber"].Value = "+1 906 777 8853";
\r
873 ((PropertyValueCollection)cnBarakTsabari.Properties["ou"]).Add("Human Resources");
\r
874 ((PropertyValueCollection)cnBarakTsabari.Properties["ou"]).Add("People");
\r
875 cnBarakTsabari.Properties["sn"].Value = "Tsabari";
\r
876 cnBarakTsabari.Properties["telephoneNumber"].Value = "+1 906 777 8854";
\r
877 cnBarakTsabari.CommitChanges();
\r
881 #endregion // Check DeleteTree
\r
883 #region Check MoveTo
\r
885 // Move to is not cached
\r
886 de = new DirectoryEntry(barakTsabariDN,
\r
887 configuration.Username,
\r
888 configuration.Password,
\r
889 configuration.AuthenticationType);
\r
891 using (DirectoryEntry ouRnD = new DirectoryEntry( configuration.ServerRoot + "ou=R&D,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
\r
892 configuration.Username,
\r
893 configuration.Password,
\r
894 configuration.AuthenticationType)){
\r
898 using (DirectoryEntry barakTsabariDE = new DirectoryEntry(barakTsabariDN,
\r
899 configuration.Username,
\r
900 configuration.Password,
\r
901 configuration.AuthenticationType)){
\r
902 barakTsabariDE.Properties["telephoneNumber"].Value = newTelephoneNumber;
\r
903 barakTsabariDE.CommitChanges();
\r
904 Assert.Fail("Object " + barakTsabariDN + " was not moved from old location on the server.");
\r
907 catch(AssertionException ae) {
\r
910 catch (Exception e) {
\r
915 using (DirectoryEntry barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=Barak Tsabari,ou=R&D,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
\r
916 configuration.Username,
\r
917 configuration.Password,
\r
918 configuration.AuthenticationType)){
\r
919 Assert.AreEqual(barakTsabariDE.Properties["telephoneNumber"].Value,oldTelephoneNumber);
\r
923 // restore object state
\r
924 using (DirectoryEntry ouHumanResources = new DirectoryEntry( configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
\r
925 configuration.Username,
\r
926 configuration.Password,
\r
927 configuration.AuthenticationType)){
\r
928 using (DirectoryEntry barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=Barak Tsabari,ou=R&D,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
\r
929 configuration.Username,
\r
930 configuration.Password,
\r
931 configuration.AuthenticationType)){
\r
932 barakTsabariDE.MoveTo(ouHumanResources);
\r
933 barakTsabariDE.CommitChanges();
\r
937 #endregion // Check MoveTo
\r
939 #region Check Rename
\r
941 // Rename not chached
\r
942 de = new DirectoryEntry(barakTsabariDN,
\r
943 configuration.Username,
\r
944 configuration.Password,
\r
945 configuration.AuthenticationType);
\r
947 de.Rename("cn=MyUser");
\r
950 using (DirectoryEntry barakTsabariDE = new DirectoryEntry(barakTsabariDN,
\r
951 configuration.Username,
\r
952 configuration.Password,
\r
953 configuration.AuthenticationType)){
\r
954 barakTsabariDE.Properties["telephoneNumber"].Value = newTelephoneNumber;
\r
955 barakTsabariDE.CommitChanges();
\r
956 Assert.Fail("Object " + barakTsabariDN + " was not renamed on the server.");
\r
959 catch(AssertionException ae) {
\r
962 catch (Exception e) {
\r
966 using (DirectoryEntry barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=MyUser,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
\r
967 configuration.Username,
\r
968 configuration.Password,
\r
969 configuration.AuthenticationType)){
\r
970 Assert.AreEqual(barakTsabariDE.Properties["telephoneNumber"].Value,oldTelephoneNumber);
\r
973 // restore object state
\r
974 using (DirectoryEntry barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=MyUser,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
\r
975 configuration.Username,
\r
976 configuration.Password,
\r
977 configuration.AuthenticationType)){
\r
978 barakTsabariDE.Rename("cn=Barak Tsabari");
\r
979 barakTsabariDE.CommitChanges();
\r
982 #endregion // Check Rename
\r
986 [Category("NotWorking")]
\r
987 public void DirectoryEntry_Children()
\r
989 de = new DirectoryEntry();
\r
990 DirectoryEntries children = de.Children;
\r
991 //Assert.AreEqual(children.SchemaFilter.Count,0);
\r
994 de = new DirectoryEntry(configuration.ConnectionString);
\r
995 children = de.Children;
\r
997 //Assert.AreEqual(children.SchemaFilter.Count,0);
\r
999 int childrenCount = 0;
\r
1000 foreach(DirectoryEntry childDe in children) {
\r
1003 Assert.AreEqual(childrenCount,2);
\r
1004 Assert.AreEqual(children.Find("ou=people").Name,"ou=people");
\r
1005 Assert.AreEqual(children.Find("cn=Manager").Name,"cn=Manager");
\r
1008 de = new DirectoryEntry(configuration.ConnectionString,
\r
1009 configuration.Username,
\r
1010 configuration.Password,
\r
1011 configuration.AuthenticationType);
\r
1012 children = de.Children;
\r
1014 //Assert.AreEqual(children.SchemaFilter.Count,0);
\r
1016 childrenCount = 0;
\r
1017 foreach(DirectoryEntry childDe in children) {
\r
1020 Assert.AreEqual(childrenCount,2);
\r
1021 Assert.AreEqual(children.Find("ou=people").Name,"ou=people");
\r
1022 Assert.AreEqual(children.Find("cn=Manager").Name,"cn=Manager");
\r
1024 de = new DirectoryEntry(configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)) ,
\r
1025 configuration.Username,
\r
1026 configuration.Password,
\r
1027 configuration.AuthenticationType);
\r
1028 children = de.Children;
\r
1030 Assert.AreEqual(children.Find("cn=Barak Tsabari").Name,"cn=Barak Tsabari");
\r
1031 Assert.AreEqual(children.Find("cn=John Smith").Name,"cn=John Smith");
\r
1035 public void DirectoryEntry_Name()
\r
1037 de = new DirectoryEntry(configuration.ConnectionString);
\r
1039 de = new DirectoryEntry(configuration.ConnectionString,
\r
1040 configuration.Username,
\r
1041 configuration.Password,
\r
1042 configuration.AuthenticationType);
\r
1044 de = new DirectoryEntry(configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)) ,
\r
1045 configuration.Username,
\r
1046 configuration.Password,
\r
1047 configuration.AuthenticationType);
\r
1048 Assert.AreEqual(de.Name,"ou=Human Resources");
\r
1050 de = new DirectoryEntry(configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)) ,
\r
1051 configuration.Username,
\r
1052 configuration.Password,
\r
1053 configuration.AuthenticationType);
\r
1054 Assert.AreEqual(de.Name,"cn=Barak Tsabari");
\r
1059 public void DirectoryEntry_Parent()
\r
1061 de = new DirectoryEntry(configuration.ConnectionString);
\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.ConnectionString,
\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 + GetParentDN (configuration.BaseDn)).ToLower());
\r
1074 de = new DirectoryEntry(configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)) ,
\r
1075 configuration.Username,
\r
1076 configuration.Password,
\r
1077 configuration.AuthenticationType);
\r
1079 // MS works only with "LDAP" while RFC2255 states "ldap"
\r
1080 Assert.AreEqual(de.Parent.Path.ToLower(),(configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn))).ToLower());
\r
1085 public void DirectoryEntry_Password()
\r
1087 string wrongPassword = "some wrong password";
\r
1089 de = new DirectoryEntry();
\r
1091 Assert.AreEqual(de.Password,null);
\r
1093 de.Password = configuration.Password;
\r
1094 Assert.AreEqual(de.Password,configuration.Password);
\r
1097 Assert.AreEqual(de.Password,String.Empty);
\r
1099 de.Password = wrongPassword;
\r
1100 Assert.AreEqual(de.Password,wrongPassword);
\r
1103 de = new DirectoryEntry(configuration.ConnectionString);
\r
1105 de.Password = configuration.Password;
\r
1106 Assert.AreEqual(de.Password,configuration.Password);
\r
1109 Assert.AreEqual(de.Password,String.Empty);
\r
1111 de.Password = wrongPassword;
\r
1112 Assert.AreEqual(de.Password,wrongPassword);
\r
1115 de = new DirectoryEntry(configuration.ConnectionString,
\r
1116 configuration.Username,
\r
1117 configuration.Password,
\r
1118 configuration.AuthenticationType);
\r
1120 de.Password = configuration.Password;
\r
1121 Assert.AreEqual(de.Password,configuration.Password);
\r
1124 Assert.AreEqual(de.Password,String.Empty);
\r
1126 de.Password = wrongPassword;
\r
1127 Assert.AreEqual(de.Password,wrongPassword);
\r
1132 public void DirectoryEntry_Path()
\r
1134 string wrongPath = "something that is not LDAP path";
\r
1136 de = new DirectoryEntry();
\r
1138 Assert.AreEqual(de.Path,String.Empty);
\r
1140 de.Path = configuration.ConnectionString;
\r
1141 Assert.AreEqual(de.Path,configuration.ConnectionString);
\r
1144 Assert.AreEqual(de.Path,String.Empty);
\r
1146 de.Path = wrongPath;
\r
1147 Assert.AreEqual(de.Path,wrongPath);
\r
1150 de = new DirectoryEntry(configuration.ConnectionString);
\r
1152 de.Path = configuration.ConnectionString;
\r
1153 Assert.AreEqual(de.Path,configuration.ConnectionString);
\r
1156 Assert.AreEqual(de.Path,String.Empty);
\r
1158 de.Path = wrongPath;
\r
1159 Assert.AreEqual(de.Path,wrongPath);
\r
1162 de = new DirectoryEntry(configuration.ConnectionString,
\r
1163 configuration.Username,
\r
1164 configuration.Password,
\r
1165 configuration.AuthenticationType);
\r
1167 de.Path = configuration.ConnectionString;
\r
1168 Assert.AreEqual(de.Path,configuration.ConnectionString);
\r
1171 Assert.AreEqual(de.Path,String.Empty);
\r
1173 de.Path = wrongPath;
\r
1174 Assert.AreEqual(de.Path,wrongPath);
\r
1176 de = new DirectoryEntry("ldap://myhost:389/ou=people",null,null,AuthenticationTypes.None);
\r
1177 Assert.AreEqual(de.Path,"ldap://myhost:389/ou=people");
\r
1180 Assert.AreEqual(de.Path,String.Empty);
\r
1185 public void DirectoryEntry_Properties1()
\r
1187 de = new DirectoryEntry(configuration.ConnectionString);
\r
1189 Assert.AreEqual(de.Properties.Count,3);
\r
1190 Assert.AreEqual(((PropertyValueCollection)de.Properties["dc"]).Value,"mainsoft");
\r
1191 Assert.AreEqual(((PropertyValueCollection)de.Properties["description"]).Value,null);
\r
1194 de = new DirectoryEntry(configuration.ConnectionString,
\r
1195 configuration.Username,
\r
1196 configuration.Password,
\r
1197 configuration.AuthenticationType);
\r
1199 Assert.AreEqual(de.Properties.Count,3);
\r
1200 Assert.AreEqual(((PropertyValueCollection)de.Properties["dc"]).Value,"mainsoft");
\r
1201 Assert.AreEqual(((PropertyValueCollection)de.Properties["description"]).Value,null);
\r
1203 // ensure that properties are not accessible after removing an entry from the server
\r
1204 string barakTsabariDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1205 de = new DirectoryEntry(barakTsabariDN,
\r
1206 configuration.Username,
\r
1207 configuration.Password,
\r
1208 configuration.AuthenticationType);
\r
1213 int i = de.Properties.Count;
\r
1214 Assert.Fail("Properties should not be accessible after deleting an entry from the server");
\r
1216 catch(AssertionException ae) {
\r
1219 catch(Exception e) {
\r
1220 // supress exception
\r
1224 string s = (string)((PropertyValueCollection)de.Properties["dc"]).Value;
\r
1225 Assert.Fail("Properties should not be accessible after deleting an entry from the server");
\r
1227 catch(AssertionException ae) {
\r
1230 catch(Exception e) {
\r
1231 // supress exception
\r
1236 public void DirectoryEntry_Properties2()
\r
1238 // delete entry, create a new one (the same) and access properties of the old object
\r
1239 string barakTsabariDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1240 de = new DirectoryEntry(barakTsabariDN,
\r
1241 configuration.Username,
\r
1242 configuration.Password,
\r
1243 configuration.AuthenticationType);
\r
1245 // cause to properties loading
\r
1246 Assert.AreEqual(de.Properties.Count,6);
\r
1247 Assert.AreEqual(((PropertyValueCollection)de.Properties["sn"]).Value,"Tsabari");
\r
1252 // the local property chache is still accessible
\r
1253 Assert.AreEqual(de.Properties.Count,6);
\r
1254 Assert.AreEqual(((PropertyValueCollection)de.Properties["sn"]).Value,"Tsabari");
\r
1256 de.CommitChanges();
\r
1258 // the local property chache is still accessible
\r
1259 ((PropertyValueCollection)de.Properties["sn"]).Value = "Barbari";
\r
1261 // create the entry back again
\r
1262 using (DirectoryEntry ouHumanResources = new DirectoryEntry( configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
\r
1263 configuration.Username,
\r
1264 configuration.Password,
\r
1265 configuration.AuthenticationType)){
\r
1266 using (DirectoryEntry cnBarakTsabari = ouHumanResources.Children.Add("cn=Barak Tsabari","Class")){
\r
1267 ((PropertyValueCollection)cnBarakTsabari.Properties["objectClass"]).Add("person");
\r
1268 ((PropertyValueCollection)cnBarakTsabari.Properties["objectClass"]).Add("organizationalPerson");
\r
1269 cnBarakTsabari.Properties["cn"].Value = "Barak Tsabari";
\r
1270 cnBarakTsabari.Properties["facsimileTelephoneNumber"].Value = "+1 906 777 8853";
\r
1271 ((PropertyValueCollection)cnBarakTsabari.Properties["ou"]).Add("Human Resources");
\r
1272 ((PropertyValueCollection)cnBarakTsabari.Properties["ou"]).Add("People");
\r
1273 cnBarakTsabari.Properties["sn"].Value = "Tsabari";
\r
1274 cnBarakTsabari.Properties["telephoneNumber"].Value = "+1 906 777 8854";
\r
1275 cnBarakTsabari.CommitChanges();
\r
1279 // the local property chache is still accessible
\r
1280 Assert.AreEqual(((PropertyValueCollection)de.Properties["sn"]).Value,"Barbari");
\r
1282 // Refresh from server
\r
1283 de.RefreshCache();
\r
1284 // ensure the properties of an entry are still accessible through the old object
\r
1285 Assert.AreEqual(((PropertyValueCollection)de.Properties["sn"]).Value,"Tsabari");
\r
1291 [Category("NotWorking")]
\r
1292 public void DirectoryEntry_SchemaClassName()
\r
1294 de = new DirectoryEntry();
\r
1295 Assert.AreEqual(de.SchemaClassName,"domainDNS");
\r
1298 de = new DirectoryEntry(configuration.ConnectionString);
\r
1299 Assert.AreEqual(de.SchemaClassName,"organization");
\r
1302 de = new DirectoryEntry(configuration.ConnectionString,
\r
1303 configuration.Username,
\r
1304 configuration.Password,
\r
1305 configuration.AuthenticationType);
\r
1306 Assert.AreEqual(de.SchemaClassName,"organization");
\r
1308 DirectoryEntry de2 = de.Children.Add("ou=My Child","Class");
\r
1309 Assert.AreEqual(de2.SchemaClassName,"Class");
\r
1310 Assert.AreEqual(((PropertyValueCollection)de2.Properties["structuralObjectClass"]).Value,null);
\r
1314 [Category("NotWorking")]
\r
1315 public void DirectoryEntry_SchemaEntry()
\r
1317 de = new DirectoryEntry();
\r
1318 DirectoryEntry schemaEntry = de.SchemaEntry;
\r
1320 // MS works only with "LDAP" while RFC2255 states "ldap"
\r
1321 Assert.AreEqual(schemaEntry.Path.ToLower(),"LDAP://schema/domainDNS".ToLower());
\r
1322 Assert.AreEqual(schemaEntry.Name,"domainDNS");
\r
1323 Assert.AreEqual(schemaEntry.Username,null);
\r
1324 Assert.AreEqual(schemaEntry.Password,null);
\r
1325 Assert.AreEqual(schemaEntry.UsePropertyCache,true);
\r
1326 Assert.AreEqual(schemaEntry.SchemaClassName,"Class");
\r
1327 Assert.AreEqual(schemaEntry.AuthenticationType,AuthenticationTypes.None);
\r
1330 de = new DirectoryEntry(configuration.ConnectionString);
\r
1331 schemaEntry = de.SchemaEntry;
\r
1333 Assert.AreEqual(schemaEntry.Path,configuration.ServerRoot + "schema/organization");
\r
1334 Assert.AreEqual(schemaEntry.Name,"organization");
\r
1335 Assert.AreEqual(schemaEntry.Username,null);
\r
1336 Assert.AreEqual(schemaEntry.Password,null);
\r
1337 Assert.AreEqual(schemaEntry.UsePropertyCache,true);
\r
1338 Assert.AreEqual(schemaEntry.SchemaClassName,"Class");
\r
1339 Assert.AreEqual(schemaEntry.AuthenticationType,AuthenticationTypes.None);
\r
1342 de = new DirectoryEntry(configuration.ConnectionString,
\r
1343 configuration.Username,
\r
1344 configuration.Password,
\r
1345 configuration.AuthenticationType);
\r
1346 schemaEntry = de.SchemaEntry;
\r
1348 Assert.AreEqual(schemaEntry.Path,configuration.ServerRoot + "schema/organization");
\r
1349 Assert.AreEqual(schemaEntry.Name,"organization");
\r
1350 Assert.AreEqual(schemaEntry.Username,configuration.Username);
\r
1351 Assert.AreEqual(schemaEntry.Password,configuration.Password);
\r
1352 Assert.AreEqual(schemaEntry.UsePropertyCache,true);
\r
1353 Assert.AreEqual(schemaEntry.SchemaClassName,"Class");
\r
1354 Assert.AreEqual(schemaEntry.AuthenticationType,configuration.AuthenticationType);
\r
1359 public void DirectoryEntry_Username()
\r
1361 string wrongUsername = "some wrong username";
\r
1363 de = new DirectoryEntry();
\r
1365 Assert.AreEqual(de.Username,null);
\r
1367 de.Username = configuration.Username;
\r
1368 Assert.AreEqual(de.Username,configuration.Username);
\r
1371 Assert.AreEqual(de.Username,String.Empty);
\r
1373 de.Username = wrongUsername;
\r
1374 Assert.AreEqual(de.Username,wrongUsername);
\r
1377 de = new DirectoryEntry(configuration.ConnectionString);
\r
1379 de.Username = configuration.Username;
\r
1380 Assert.AreEqual(de.Username,configuration.Username);
\r
1383 Assert.AreEqual(de.Username,String.Empty);
\r
1385 de.Username = wrongUsername;
\r
1386 Assert.AreEqual(de.Username,wrongUsername);
\r
1389 de = new DirectoryEntry(configuration.ConnectionString,
\r
1390 configuration.Username,
\r
1391 configuration.Password,
\r
1392 configuration.AuthenticationType);
\r
1394 de.Username = configuration.Username;
\r
1395 Assert.AreEqual(de.Username,configuration.Username);
\r
1398 Assert.AreEqual(de.Username,String.Empty);
\r
1400 de.Username = wrongUsername;
\r
1401 Assert.AreEqual(de.Username,wrongUsername);
\r
1406 public void DirectoryEntry_Close()
\r
1408 de = new DirectoryEntry();
\r
1411 de = new DirectoryEntry(configuration.ConnectionString);
\r
1414 de = new DirectoryEntry(configuration.ConnectionString,
\r
1415 configuration.Username,
\r
1416 configuration.Password,
\r
1417 configuration.AuthenticationType);
\r
1423 public void DirectoryEntry_CommitChanges1()
\r
1425 string humanResourcesDN = configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1426 using (DirectoryEntry ouHumanResources = new DirectoryEntry( humanResourcesDN,
\r
1427 configuration.Username,
\r
1428 configuration.Password,
\r
1429 configuration.AuthenticationType)){
\r
1432 string newEmployeeDN = configuration.ServerRoot + "cn=New Employee,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1433 de = ouHumanResources.Children.Add("cn=New Employee","Class");
\r
1434 Assert.IsFalse(DirectoryEntry.Exists(newEmployeeDN));
\r
1436 de.Properties["objectClass"].Value = "organizationalRole";
\r
1437 de.Properties["cn"].Value = "New Employee";
\r
1438 Assert.IsFalse(DirectoryEntry.Exists(newEmployeeDN));
\r
1440 de.CommitChanges();
\r
1441 Assert.IsTrue(DirectoryEntry.Exists(newEmployeeDN));
\r
1445 string barakTsabariDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1446 de = new DirectoryEntry(barakTsabariDN,
\r
1447 configuration.Username,
\r
1448 configuration.Password,
\r
1449 configuration.AuthenticationType);
\r
1451 string oldTelephone = (string)((PropertyValueCollection)de.Properties["telephoneNumber"]).Value;
\r
1452 string newTelephone = "+972 3 6078596";
\r
1454 // UsePropertyCache - true
\r
1455 de.UsePropertyCache = true;
\r
1456 ((PropertyValueCollection)de.Properties["telephoneNumber"]).Value = newTelephone;
\r
1457 Assert.AreEqual(((PropertyValueCollection)de.Properties["telephoneNumber"]).Value,newTelephone);
\r
1459 using (DirectoryEntry cnBarakTsabari = new DirectoryEntry( barakTsabariDN,
\r
1460 configuration.Username,
\r
1461 configuration.Password,
\r
1462 configuration.AuthenticationType)){
\r
1464 //check that on server there is still an old value
\r
1465 Assert.AreEqual(((PropertyValueCollection)cnBarakTsabari.Properties["telephoneNumber"]).Value,oldTelephone);
\r
1467 de.CommitChanges();
\r
1470 using (DirectoryEntry cnBarakTsabari = new DirectoryEntry(barakTsabariDN,
\r
1471 configuration.Username,
\r
1472 configuration.Password,
\r
1473 configuration.AuthenticationType)){
\r
1475 // check that new value is updated on the server
\r
1476 Assert.AreEqual(((PropertyValueCollection)cnBarakTsabari.Properties["telephoneNumber"]).Value,newTelephone);
\r
1479 // UsePropertyCache - false
\r
1480 de = new DirectoryEntry(barakTsabariDN,
\r
1481 configuration.Username,
\r
1482 configuration.Password,
\r
1483 configuration.AuthenticationType);
\r
1484 de.UsePropertyCache = false;
\r
1485 Assert.AreEqual(((PropertyValueCollection)de.Properties["telephoneNumber"]).Value,newTelephone);
\r
1486 ((PropertyValueCollection)de.Properties["telephoneNumber"]).Value = oldTelephone;
\r
1487 Assert.AreEqual(((PropertyValueCollection)de.Properties["telephoneNumber"]).Value,oldTelephone);
\r
1489 using (DirectoryEntry cnBarakTsabari = new DirectoryEntry(barakTsabariDN,
\r
1490 configuration.Username,
\r
1491 configuration.Password,
\r
1492 configuration.AuthenticationType)){
\r
1494 // check that new value is updated on the server
\r
1495 //Assert.AreEqual(((PropertyValueCollection)cnBarakTsabari.Properties["telephoneNumber"]).Value,oldTelephone);
\r
1498 de.CommitChanges(); // this should do nothing
\r
1502 public void DirectoryEntry_CommitChanges2()
\r
1504 string barakTsabariDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1505 using (DirectoryEntry barakTsabariDE1 = new DirectoryEntry(barakTsabariDN,
\r
1506 configuration.Username,
\r
1507 configuration.Password,
\r
1508 configuration.AuthenticationType)){
\r
1509 barakTsabariDE1.UsePropertyCache = true;
\r
1511 using (DirectoryEntry barakTsabariDE2 = new DirectoryEntry(barakTsabariDN,
\r
1512 configuration.Username,
\r
1513 configuration.Password,
\r
1514 configuration.AuthenticationType)){
\r
1515 barakTsabariDE2.UsePropertyCache = true;
\r
1517 string oldTelephone = (string)((PropertyValueCollection)barakTsabariDE1.Properties["telephoneNumber"]).Value;
\r
1518 string newTelephone = "+972 3 6078596";
\r
1519 string oldFacsimilieTelephoneNumber = (string)((PropertyValueCollection)barakTsabariDE1.Properties["facsimileTelephoneNumber"]).Value;
\r
1520 string newFacsimilieTelephoneNumber1 = "+972-3-9872365";
\r
1521 string newFacsimilieTelephoneNumber2 = "+972-3-9999999";
\r
1523 barakTsabariDE1.Properties["telephoneNumber"].Value = newTelephone;
\r
1524 barakTsabariDE1.Properties["facsimileTelephoneNumber"].Value = newFacsimilieTelephoneNumber1;
\r
1526 barakTsabariDE2.Properties["facsimileTelephoneNumber"].Value = newFacsimilieTelephoneNumber2;
\r
1528 // only the changed properties of each object are set
\r
1530 barakTsabariDE1.CommitChanges();
\r
1531 de = new DirectoryEntry(barakTsabariDN,
\r
1532 configuration.Username,
\r
1533 configuration.Password,
\r
1534 configuration.AuthenticationType);
\r
1535 Assert.AreEqual(de.Properties["telephoneNumber"].Value,newTelephone);
\r
1536 Assert.AreEqual(de.Properties["facsimileTelephoneNumber"].Value,newFacsimilieTelephoneNumber1);
\r
1538 barakTsabariDE2.CommitChanges();
\r
1539 de = new DirectoryEntry(barakTsabariDN,
\r
1540 configuration.Username,
\r
1541 configuration.Password,
\r
1542 configuration.AuthenticationType);
\r
1543 Assert.AreEqual(de.Properties["telephoneNumber"].Value,newTelephone);
\r
1544 Assert.AreEqual(de.Properties["facsimileTelephoneNumber"].Value,newFacsimilieTelephoneNumber2);
\r
1551 [ExpectedException(typeof(NotImplementedException))]
\r
1552 public void DirectoryEntry_CopyTo()
\r
1554 string barakTsabariDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1555 de = new DirectoryEntry(configuration.ConnectionString,
\r
1556 configuration.Username,
\r
1557 configuration.Password,
\r
1558 configuration.AuthenticationType);
\r
1560 using (DirectoryEntry cnBarakTsabari = new DirectoryEntry( barakTsabariDN,
\r
1561 configuration.Username,
\r
1562 configuration.Password,
\r
1563 configuration.AuthenticationType)){
\r
1565 cnBarakTsabari.CopyTo(de);
\r
1571 public void DirectoryEntry_DeleteTree()
\r
1573 string barakTsabariDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1575 Assert.IsTrue(DirectoryEntry.Exists(barakTsabariDN));
\r
1576 de = new DirectoryEntry(barakTsabariDN,
\r
1577 configuration.Username,
\r
1578 configuration.Password,
\r
1579 configuration.AuthenticationType);
\r
1581 // no properties changed
\r
1583 de.CommitChanges();
\r
1585 Assert.IsFalse(DirectoryEntry.Exists(barakTsabariDN));
\r
1587 string johnSmithDN = configuration.ServerRoot + "cn=John Smith,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1589 Assert.IsTrue(DirectoryEntry.Exists(johnSmithDN));
\r
1590 de = new DirectoryEntry(johnSmithDN,
\r
1591 configuration.Username,
\r
1592 configuration.Password,
\r
1593 configuration.AuthenticationType);
\r
1595 de.Properties["telephoneNumber"].Value = "+972 3 9999999";
\r
1597 // some properties changed
\r
1600 de.CommitChanges();
\r
1601 Assert.Fail("Object " + johnSmithDN + " was not deleted from server");
\r
1603 catch(AssertionException ae) {
\r
1606 catch(Exception e) {
\r
1612 public void DirectoryEntry_DeleteTree2()
\r
1614 string johnSmithDN = configuration.ServerRoot + "cn=John Smith,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1616 Assert.IsTrue(DirectoryEntry.Exists(johnSmithDN));
\r
1617 // two objects refer to the same entry
\r
1618 de = new DirectoryEntry(johnSmithDN,
\r
1619 configuration.Username,
\r
1620 configuration.Password,
\r
1621 configuration.AuthenticationType);
\r
1623 using (DirectoryEntry johnSmithDE = new DirectoryEntry(johnSmithDN,
\r
1624 configuration.Username,
\r
1625 configuration.Password,
\r
1626 configuration.AuthenticationType)){
\r
1628 johnSmithDE.Properties["telephoneNumber"].Value = "+972 3 9999999";
\r
1630 // check that the second entry is not accessible after the first is deleted
\r
1632 de.CommitChanges();
\r
1635 johnSmithDE.CommitChanges();
\r
1636 Assert.Fail("Object " + johnSmithDN + " should not be accessible");
\r
1638 catch(AssertionException ae) {
\r
1641 catch(Exception e) {
\r
1649 public void DirectoryEntry_Exists()
\r
1651 string barakTsabariDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1652 string johnSmithDN = configuration.ServerRoot + "cn=John Smith,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1653 string humanResourcesOU = configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1655 Assert.IsTrue(DirectoryEntry.Exists(barakTsabariDN));
\r
1656 Assert.IsTrue(DirectoryEntry.Exists(johnSmithDN));
\r
1657 Assert.IsTrue(DirectoryEntry.Exists(humanResourcesOU));
\r
1659 Assert.IsFalse(DirectoryEntry.Exists(barakTsabariDN + ",dc=mono"));
\r
1664 public void DirectoryEntry_MoveTo_De()
\r
1666 string barakTsabariHumanResourcesDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1667 string barakTsabariDevQaDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=DevQA,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1669 using (DirectoryEntry barakTsabariDE = new DirectoryEntry( barakTsabariHumanResourcesDN,
\r
1670 configuration.Username,
\r
1671 configuration.Password,
\r
1672 configuration.AuthenticationType)){
\r
1674 string devQaOU = configuration.ServerRoot + "ou=DevQA,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1676 using (DirectoryEntry devQaDE = new DirectoryEntry(devQaOU,
\r
1677 configuration.Username,
\r
1678 configuration.Password,
\r
1679 configuration.AuthenticationType)){
\r
1681 barakTsabariDE.MoveTo(devQaDE);
\r
1682 barakTsabariDE.CommitChanges();
\r
1684 Assert.IsTrue(DirectoryEntry.Exists(barakTsabariDevQaDN));
\r
1686 string humanRwsourcesOU = configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1688 using (DirectoryEntry humanResourcesDE = new DirectoryEntry( humanRwsourcesOU,
\r
1689 configuration.Username,
\r
1690 configuration.Password,
\r
1691 configuration.AuthenticationType)){
\r
1693 barakTsabariDE.MoveTo(humanResourcesDE);
\r
1694 barakTsabariDE.CommitChanges();
\r
1696 Assert.IsTrue(DirectoryEntry.Exists(barakTsabariHumanResourcesDN));
\r
1704 public void DirectoryEntry_MoveTo_DeStr()
\r
1706 string barakTsabariHumanResourcesDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1707 string barakTsabariDevQaDN = configuration.ServerRoot + "cn=My Name,ou=DevQA,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1709 using (DirectoryEntry barakTsabariDE = new DirectoryEntry( barakTsabariHumanResourcesDN,
\r
1710 configuration.Username,
\r
1711 configuration.Password,
\r
1712 configuration.AuthenticationType)){
\r
1714 string devQaOU = configuration.ServerRoot + "ou=DevQA,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1716 using (DirectoryEntry devQaDE = new DirectoryEntry(devQaOU,
\r
1717 configuration.Username,
\r
1718 configuration.Password,
\r
1719 configuration.AuthenticationType)){
\r
1721 barakTsabariDE.MoveTo(devQaDE,"cn=My Name");
\r
1722 barakTsabariDE.CommitChanges();
\r
1724 Assert.IsTrue(DirectoryEntry.Exists(barakTsabariDevQaDN));
\r
1726 string humanRwsourcesOU = configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1728 using (DirectoryEntry humanResourcesDE = new DirectoryEntry( humanRwsourcesOU,
\r
1729 configuration.Username,
\r
1730 configuration.Password,
\r
1731 configuration.AuthenticationType)){
\r
1733 barakTsabariDE.MoveTo(humanResourcesDE,"cn=Barak Tsabari");
\r
1734 barakTsabariDE.CommitChanges();
\r
1736 Assert.IsTrue(DirectoryEntry.Exists(barakTsabariHumanResourcesDN));
\r
1743 public void DirectoryEntry_RefreshCache()
\r
1745 de = new DirectoryEntry(configuration.ConnectionString);
\r
1746 de.UsePropertyCache = true;
\r
1748 string newValue = "Just a company";
\r
1749 string oldValue = (string)((PropertyValueCollection)de.Properties["description"]).Value;
\r
1750 ((PropertyValueCollection)de.Properties["description"]).Value = newValue;
\r
1752 Assert.AreEqual(((PropertyValueCollection)de.Properties["description"]).Value,newValue);
\r
1754 de.RefreshCache();
\r
1756 Assert.AreEqual(((PropertyValueCollection)de.Properties["description"]).Value,oldValue);
\r
1758 // call RefeshCache on new entry prior to submitting it to the server shoud fail
\r
1759 string newEmployeeDN = configuration.ServerRoot + "cn=New Employee,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1760 string humanResourcesDN = configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1762 using (DirectoryEntry humanResourcesDE = new DirectoryEntry( humanResourcesDN,
\r
1763 configuration.Username,
\r
1764 configuration.Password,
\r
1765 configuration.AuthenticationType)){
\r
1767 using (DirectoryEntry newEmployeeDE = humanResourcesDE.Children.Add("cn=New Employee","Class")){
\r
1768 Assert.AreEqual(newEmployeeDE.Properties["cn"].Value,null);
\r
1770 ((PropertyValueCollection)newEmployeeDE.Properties["objectClass"]).Add("person");
\r
1771 ((PropertyValueCollection)newEmployeeDE.Properties["objectClass"]).Add("organizationalPerson");
\r
1772 newEmployeeDE.Properties["cn"].Value = "New Employee";
\r
1773 newEmployeeDE.Properties["sn"].Value = "Employee";
\r
1774 newEmployeeDE.Properties["ou"].Value = "Human Resources";
\r
1776 Assert.AreEqual(newEmployeeDE.Properties["cn"].Value,"New Employee");
\r
1779 newEmployeeDE.RefreshCache();
\r
1780 Assert.Fail("Call to RefreshCache did not fail");
\r
1782 catch(AssertionException ae) {
\r
1785 catch (Exception e) {
\r
1786 // supress exception
\r
1789 Assert.AreEqual(newEmployeeDE.Properties["cn"].Value,"New Employee");
\r
1791 newEmployeeDE.CommitChanges();
\r
1793 // now it should work without any problem
\r
1794 newEmployeeDE.RefreshCache();
\r
1796 Assert.AreEqual(newEmployeeDE.Properties["cn"].Value,"New Employee");
\r
1802 public void DirectoryEntry_RefreshCache_StrArr()
\r
1804 de = new DirectoryEntry(configuration.ServerRoot + "cn=Uzi Cohen,cn=Manager" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)));
\r
1805 de.UsePropertyCache = true;
\r
1807 string[] newValues = new string [] { "Just a manager", "Levi" };
\r
1808 string[] oldValues = new string [2];
\r
1809 oldValues [0] = (string)((PropertyValueCollection)de.Properties["description"]).Value;
\r
1810 oldValues [1] = (string)((PropertyValueCollection)de.Properties["sn"]).Value;
\r
1812 ((PropertyValueCollection)de.Properties["description"]).Value = newValues [0];
\r
1813 ((PropertyValueCollection)de.Properties["sn"]).Value = newValues [1];
\r
1815 Assert.AreEqual(((PropertyValueCollection)de.Properties["description"]).Value,newValues [0]);
\r
1816 Assert.AreEqual(((PropertyValueCollection)de.Properties["sn"]).Value,newValues [1]);
\r
1818 de.RefreshCache(new string[] {"cn"});
\r
1820 Assert.AreEqual(((PropertyValueCollection)de.Properties["description"]).Value,newValues [0]);
\r
1821 Assert.AreEqual(((PropertyValueCollection)de.Properties["sn"]).Value,newValues [1]);
\r
1823 de.RefreshCache(new string[] {"description","sn"});
\r
1825 Assert.AreEqual(((PropertyValueCollection)de.Properties["description"]).Value,newValues [0]);
\r
1826 Assert.AreEqual(((PropertyValueCollection)de.Properties["sn"]).Value,oldValues [1]);
\r
1830 public void DirectoryEntry_Rename()
\r
1832 string barakTsabariOldDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1833 string barakTsabariNewDN = configuration.ServerRoot + "cn=My Name,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
\r
1835 using (DirectoryEntry barakTsabariDE = new DirectoryEntry( barakTsabariOldDN,
\r
1836 configuration.Username,
\r
1837 configuration.Password,
\r
1838 configuration.AuthenticationType)){
\r
1840 barakTsabariDE.Rename("cn=My Name");
\r
1841 barakTsabariDE.CommitChanges();
\r
1843 Assert.IsTrue(DirectoryEntry.Exists(barakTsabariNewDN));
\r
1845 barakTsabariDE.Rename("cn=Barak Tsabari");
\r
1846 barakTsabariDE.CommitChanges();
\r
1848 Assert.IsTrue(DirectoryEntry.Exists(barakTsabariOldDN));
\r
1854 private static string GetName (string baseDn)
\r
1856 if (baseDn == null || baseDn.Length == 0 || baseDn.IndexOf (',') == -1)
\r
1859 int index = baseDn.IndexOf (',');
\r
1861 return baseDn.Substring (0, index);
\r
1864 private static string GetParentDN (string baseDn)
\r
1866 if (baseDn == null || baseDn.Length == 0 || baseDn.IndexOf (',') == -1)
\r
1867 return String.Empty;
\r
1869 int index = baseDn.IndexOf (',');
\r
1871 return baseDn.Substring (index + 1,baseDn.Length - index - 1);
\r