示例#1
0
        private static IDirectoryAttributes AddContainerIfNecessary(Type type)
        {
            var mapping = LdapConfiguration.Configuration.Mapper.GetMapping(type);

            var containerCn     = DnParser.ParseName(mapping.NamingContext);
            var containerPrefix = DnParser.ParseRDN(mapping.NamingContext);

            return(AddContainerIfNecessary(containerPrefix, containerCn));
        }
示例#2
0
        private static void PopulateDirectoryForTests()

        {
            var user2Container = DnParser.ParseName(TestUserDirectoryContainer);

            var user2Prefix = DnParser.ParseRDN(TestUserDirectoryContainer);

            AddContainerIfNecessary(user2Prefix, user2Container);

            using (var context = new DirectoryContext())

            {
                AddEntryIfNecessary("CN=PasswordUser," + TestUserDirectoryContainer, "user", context);

                AddEntryIfNecessary("CN=persontest," + TestUserDirectoryContainer, "user", context);

                AddEntryIfNecessary("CN=TestUser," + TestUserDirectoryContainer, "user", context);

                AddEntryIfNecessary("CN=TestUser2," + TestUserDirectoryContainer, "user", context);
            }

            var roleContainer = DnParser.ParseName(RolesDirectoryContainer);

            var rolePrefix = DnParser.ParseRDN(RolesDirectoryContainer);

            AddContainerIfNecessary(rolePrefix, roleContainer);

            using (var context = new DirectoryContext())

            {
                IDirectoryAttributes rangeTest = AddEntryIfNecessary("CN=RangeTest," + RolesDirectoryContainer, "group", context);

                foreach (var kvp in rangeTest.Where(kvp => kvp.Key.StartsWith("member", StringComparison.OrdinalIgnoreCase)))

                {
                    if (kvp.Value is IEnumerable <string> && ((IEnumerable <string>)kvp.Value).Any())

                    {
                        Console.WriteLine("RangeTest members already populated");

                        return;
                    }
                }

                var newMembers = new List <string>();

                newMembers.AddRange(context.Query <LdsUser>().Take(10000).Select(u => u.DistinguishedName));

                rangeTest.Set("member", newMembers);

                context.Update(rangeTest);
            }
        }
示例#3
0
 public void ParseRDN_NullDn_ThrowsException()
 {
     Executing.This(() => DnParser.ParseRDN(null))
     .Should().Throw <ArgumentException>();
 }
示例#4
0
 public void ParseRDN_MultipleCharacters_ReturnsPrefix()
 {
     DnParser.ParseRDN("XYZ=test,Dd=domain,Dd=com").Should().Be.EqualTo("XYZ");
 }
示例#5
0
 public void ParseRDN_SingleCharacter_ReturnsPrefix()
 {
     DnParser.ParseRDN("n=test,Dd=domain,Dd=com").Should().Be.EqualTo("n");
 }