public void GetSchemaNamingContextEasy() { ActiveDirectorySchema ads = ActiveDirectorySchema.GetCurrentSchema(); using (ads) using (DirectoryEntry entry = ads.GetDirectoryEntry()) { //bound to schema partition } }
public void TestSchemaFilter() { // using (ActiveDirectorySchemaClass schema = ActiveDirectorySchemaClass.FindByName(ActiveDirectoryContext, "user")) using (ActiveDirectorySchema schema = ActiveDirectorySchema.GetSchema(ActiveDirectoryContext)) using (DirectoryEntry de = schema.GetDirectoryEntry()) { // by default there is no filters Assert.Equal(0, de.Children.SchemaFilter.Count); int topClassCount = 0; foreach (DirectoryEntry child in de.Children) { string s = (string)child.Properties["objectClass"][0]; topClassCount += s.Equals("top", StringComparison.OrdinalIgnoreCase) ? 1 : 0; } de.Children.SchemaFilter.Add("top"); Assert.Equal(1, de.Children.SchemaFilter.Count); Assert.True(de.Children.SchemaFilter.Contains("top")); Assert.Equal(0, de.Children.SchemaFilter.IndexOf("top")); Assert.Equal("top", de.Children.SchemaFilter[0]); int newTopClassCount = 0; foreach (DirectoryEntry child in de.Children) { // we expect to get top only entries string s = (string)child.Properties["objectClass"][0]; Assert.True(s.Equals("top", StringComparison.OrdinalIgnoreCase)); newTopClassCount += 1; } Assert.Equal(topClassCount, newTopClassCount); de.Children.SchemaFilter.Remove("top"); Assert.Equal(0, de.Children.SchemaFilter.Count); de.Children.SchemaFilter.Add("top"); Assert.Equal(1, de.Children.SchemaFilter.Count); de.Children.SchemaFilter.RemoveAt(0); Assert.Equal(0, de.Children.SchemaFilter.Count); de.Children.SchemaFilter.AddRange(new string [] { "top", "user" }); Assert.Equal(2, de.Children.SchemaFilter.Count); de.Children.SchemaFilter.Insert(0, "person"); Assert.Equal(3, de.Children.SchemaFilter.Count); Assert.Equal("person", de.Children.SchemaFilter[0]); Assert.Equal("user", de.Children.SchemaFilter[2]); de.Children.SchemaFilter.Clear(); Assert.Equal(0, de.Children.SchemaFilter.Count); } }
public void TestSchema() { using (ActiveDirectorySchema schema = ActiveDirectorySchema.GetSchema(ActiveDirectoryContext)) { Assert.True(schema.FindAllClasses().Contains(ActiveDirectorySchemaClass.FindByName(ActiveDirectoryContext, "user"))); Assert.True(schema.FindAllClasses().Contains(ActiveDirectorySchemaClass.FindByName(ActiveDirectoryContext, "samDomainBase"))); Assert.NotNull(schema.FindAllDefunctClasses()); Assert.NotNull(schema.FindAllDefunctProperties()); Assert.True(schema.FindAllProperties(PropertyTypes.Indexed).Contains(ActiveDirectorySchemaProperty.FindByName(ActiveDirectoryContext, "ou"))); Assert.True(schema.FindAllProperties().Contains(ActiveDirectorySchemaProperty.FindByName(ActiveDirectoryContext, "cn"))); Assert.Equal("person", schema.FindClass("person").Name); Assert.Equal("cn", schema.FindProperty("cn").Name); using (DirectoryEntry de = schema.GetDirectoryEntry()) { Assert.True("CN=Schema".Equals(de.Name, StringComparison.OrdinalIgnoreCase)); } } }