public void TestSchemaClass()
        {
            using (ActiveDirectorySchemaClass orgClass = ActiveDirectorySchemaClass.FindByName(ActiveDirectoryContext, "organization"))
            {
                Assert.Equal("organization", orgClass.Name);
                Assert.Equal("Organization", orgClass.CommonName);
                Assert.Equal("2.5.6.4", orgClass.Oid);
                Assert.Equal("bf967aa3-0de6-11d0-a285-00aa003049e2", orgClass.SchemaGuid.ToString());
                Assert.Equal("top", orgClass.SubClassOf.Name);
                Assert.NotNull(orgClass.DefaultObjectSecurityDescriptor);
                string s = orgClass.Description; // it can be null
                Assert.False(orgClass.IsDefunct);

                Assert.True(orgClass.AuxiliaryClasses.Contains(ActiveDirectorySchemaClass.FindByName(ActiveDirectoryContext, "samDomainBase")));
                Assert.True(orgClass.PossibleInferiors.Contains(ActiveDirectorySchemaClass.FindByName(ActiveDirectoryContext, "user")));

                ActiveDirectorySchemaClass country = ActiveDirectorySchemaClass.FindByName(ActiveDirectoryContext, "country");
                Assert.True(orgClass.PossibleSuperiors.Contains(country));
                int index = orgClass.PossibleSuperiors.IndexOf(country);
                Assert.Equal(country.Name, orgClass.PossibleSuperiors[index].Name);

                Assert.True(orgClass.MandatoryProperties.Contains(ActiveDirectorySchemaProperty.FindByName(ActiveDirectoryContext, "ntSecurityDescriptor")));
                Assert.True(orgClass.OptionalProperties.Contains(ActiveDirectorySchemaProperty.FindByName(ActiveDirectoryContext, "description")));
                Assert.True(orgClass.MandatoryProperties.Contains(ActiveDirectorySchemaProperty.FindByName(ActiveDirectoryContext, "objectClass")));

                using (DirectoryEntry de = orgClass.GetDirectoryEntry())
                {
                    Assert.True("CN=Organization".Equals(de.Name, StringComparison.OrdinalIgnoreCase));
                }
            }
        }
Exemple #2
0
 private static SchemaClass GetSchemaClass(string className)
 {
     if (!schemaClassCache.TryGetValue(className, out SchemaClass schemaClass))
     {
         using (ActiveDirectorySchema schema = ActiveDirectorySchema.GetCurrentSchema())
         {
             ActiveDirectorySchemaClass result = schema.FindClass(className);
             System.DirectoryServices.DirectoryEntry directoryEntry = result.GetDirectoryEntry();
             schemaClass = new SchemaClass()
             {
                 LdapDisplayName   = result.Name,
                 SchemaGuid        = result.SchemaGuid,
                 DistinguishedName = (string)directoryEntry.Properties["distinguishedName"][0]
             };
             schemaClassCache.Add(result.Name, schemaClass);
         }
     }
     return(schemaClass);
 }