public void testCompleteInitLibrary()
        {

            LdapUser adminUser = new LdapUser(ConfigurationManager.AppSettings["LDAPAdminUserDN"],
                                                ConfigurationManager.AppSettings["LDAPAdminUserCN"],
                                                ConfigurationManager.AppSettings["LDAPAdminUserSN"],
                                                null);
            adminUser.CreateUserAttribute("userPassword", ConfigurationManager.AppSettings["LDAPAdminUserPassword"]);

            AuthType authType = (AuthType)Enum.Parse(typeof(AuthType),
                                                        ConfigurationManager.AppSettings["LDAPAuthType"]);

            LdapManagerObj = new LdapManager(adminUser,
                                                ConfigurationManager.AppSettings["LDAPServer"],
                                                ConfigurationManager.AppSettings["LDAPSearchBaseDN"],
                                                authType,
                                                Convert.ToBoolean(ConfigurationManager.AppSettings["secureSocketLayerFlag"]),
                                                Convert.ToBoolean(ConfigurationManager.AppSettings["transportSocketLayerFlag"]),
                                                Convert.ToBoolean(ConfigurationManager.AppSettings["ClientCertificationFlag"]),
                                                ConfigurationManager.AppSettings["clientCertificatePath"],
                                                Convert.ToBoolean(ConfigurationManager.AppSettings["enableLDAPLibraryLog"]),
                                                ConfigurationManager.AppSettings["LDAPLibraryLogPath"],
                                                ConfigurationManager.AppSettings["LdapUserObjectClass"],
                                                ConfigurationManager.AppSettings["LDAPMatchFieldUsername"]
                                                );

            Assert.IsFalse(LdapManagerObj.Equals(null));
        }
        public static ILdapManager SetupLdapLibrary()
        {
            var authType = (AuthType) Enum.Parse(typeof (AuthType),
                Config.LdapLibrary["LDAPAuthType"]);

            if (string.IsNullOrEmpty(Config.LdapLibrary["LDAPAdminUserDN"]))
                return new LdapManager(null,
                    (LDAPAdminMode)Enum.Parse(typeof(LDAPAdminMode), Config.LdapLibrary["LDAPAdminMode"]),
                    Config.LdapLibrary["LDAPServer"],
                    Config.LdapLibrary["LDAPSearchBaseDN"],
                    authType,
                    (LoggerType) Enum.Parse(typeof (LoggerType), Config.LdapLibrary["enableLDAPLibraryLog"]),
                    Config.LdapLibrary["LDAPLibraryLogPath"]
                    );

            var adminUser = new LdapUser(Config.LdapLibrary["LDAPAdminUserDN"],
                Config.LdapLibrary["LDAPAdminUserCN"],
                Config.LdapLibrary["LDAPAdminUserSN"],
                null);

            adminUser.CreateUserAttribute("userPassword", Config.LdapLibrary["LDAPAdminUserPassword"]);

            return new LdapManager(adminUser,
                (LDAPAdminMode)Enum.Parse(typeof(LDAPAdminMode), Config.LdapLibrary["LDAPAdminMode"]),
                Config.LdapLibrary["LDAPServer"],
                Config.LdapLibrary["LDAPSearchBaseDN"],
                authType,
                (LoggerType) Enum.Parse(typeof (LoggerType), Config.LdapLibrary["enableLDAPLibraryLog"]),
                Config.LdapLibrary["LDAPLibraryLogPath"]
                );
        }
        public bool TestCompleteInitLibrary()
        {
            try
            {
                var adminUser = new LdapUser(Config.LdapLibrary["LDAPAdminUserDN"],
                    Config.LdapLibrary["LDAPAdminUserCN"],
                    Config.LdapLibrary["LDAPAdminUserSN"],
                    null);
                adminUser.CreateUserAttribute("userPassword", Config.LdapLibrary["LDAPAdminUserPassword"]);

                var authType = (AuthType) Enum.Parse(typeof (AuthType),
                    Config.LdapLibrary["LDAPAuthType"]);

                _ldapManagerObj = new LdapManager(adminUser,
                    (LDAPAdminMode) Enum.Parse(typeof (LDAPAdminMode),Config.LdapLibrary["LDAPAdminMode"]),
                    Config.LdapLibrary["LDAPServer"],
                    Config.LdapLibrary["LDAPSearchBaseDN"],
                    authType,
                    Convert.ToBoolean(Config.LdapLibrary["secureSocketLayerFlag"]),
                    Convert.ToBoolean(Config.LdapLibrary["transportSocketLayerFlag"]),
                    Convert.ToBoolean(Config.LdapLibrary["ClientCertificationFlag"]),
                    Config.LdapLibrary["clientCertificatePath"],
                    (LoggerType) Enum.Parse(typeof (LoggerType), Config.LdapLibrary["enableLDAPLibraryLog"]),
                    Config.LdapLibrary["LDAPLibraryLogPath"],
                    Config.LdapLibrary["LDAPUserObjectClass"],
                    Config.LdapLibrary["LDAPMatchFieldUsername"]
                    );

                if (!_ldapManagerObj.Equals(null))
                    return true;
                return false;
            }
            catch (Exception)
            {
                return false;
            }
        }
        public void testStandardInitLibrary()
        {

            LdapUser adminUser = new LdapUser(ConfigurationManager.AppSettings["LDAPAdminUserDN"],
                                                 ConfigurationManager.AppSettings["LDAPAdminUserCN"],
                                                 ConfigurationManager.AppSettings["LDAPAdminUserSN"],
                                                 null);
            adminUser.CreateUserAttribute("userPassword", ConfigurationManager.AppSettings["LDAPAdminUserPassword"]);


            AuthType authType = (AuthType)Enum.Parse(typeof(AuthType),
                                                        ConfigurationManager.AppSettings["LDAPAuthType"]);

            LdapManagerObj = new LdapManager(adminUser,
                                                ConfigurationManager.AppSettings["LDAPServer"],
                                                ConfigurationManager.AppSettings["LDAPSearchBaseDN"],
                                                authType
                                                );

            Assert.IsFalse(LdapManagerObj.Equals(null));
        }
        private LdapUser setupReadOnlyTestUser()
        {
            string userDN = "cn=Matteo,o=ApexNet,ou=People,dc=maxcrc,dc=com";
            string userCN = "Matteo";
            string userSN = "Paci";

            LdapUser testLdapUser = new LdapUser(userDN, userCN, userSN, null);

            testLdapUser.CreateUserAttribute("userPassword", "1");
            testLdapUser.CreateUserAttribute("description", "test");

            if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["LDAPMatchFieldUsername"]))
            {
                if (ConfigurationManager.AppSettings["LDAPMatchFieldUsername"].Equals("cn"))
                    LDAPMatchSearchField = new string[1] { testLdapUser.GetUserCn() };
                else if (ConfigurationManager.AppSettings["LDAPMatchFieldUsername"].Equals("dn"))
                    LDAPMatchSearchField = new string[1] { testLdapUser.GetUserDn() };
                else if (ConfigurationManager.AppSettings["LDAPMatchFieldUsername"].Equals("sn"))
                    LDAPMatchSearchField = new string[1] { testLdapUser.GetUserSn() };
                else
                    LDAPMatchSearchField = new string[1] {
						testLdapUser.GetUserAttribute( ConfigurationManager.AppSettings["LDAPMatchFieldUsername"] )[0]
					};
            }

            //Set the test user
            return testLdapUser;
        }
        public void CreateUserAttributeSingle()
        {
            var user = new LdapUser(LdapUserDn,
                LdapUserCn,
                LdapUserSn,
                LdapUserAttributes);
            const string newAttribute = "new test value 1";

            user.CreateUserAttribute("newAttribute1", newAttribute);

            CollectionAssert.AreEqual(user.GetUserAttribute("newAttribute1"), new List<string> {newAttribute});
        }
        public void CreateUserAttributeList()
        {
            var user = new LdapUser(LdapUserDn,
                LdapUserCn,
                LdapUserSn,
                LdapUserAttributes);
            var newAttribute = new List<string> {"new test value 1", "new test value 2"};

            user.CreateUserAttribute("newAttribute", newAttribute);

            CollectionAssert.AreEqual(user.GetUserAttribute("newAttribute"), newAttribute);
        }