public void TestRecycleMode()
    {
        MockUser user = new MockUser("TestUser", "TestPassword", "MyNewPassword");

            PasswordChanger pc = new PasswordChanger(user, update, errorHandle, 1, 2);
            pc.ChangePasswordRecycleMode();
            Assert.AreEqual(user.NewPassword, user.Password);
    }
    public void TestRecycleModeNoIterations()
    {
        MockUser user = new MockUser("TestUser", "TestPassword", "MyNewPassword");

            PasswordChanger pc = new PasswordChanger(user, update, errorHandle);
            try
            {
                pc.ChangePasswordRecycleMode();
            }
            catch (Exception ex)
            {
                string expected = "Iterations must be set when recycling a password. \n\n(Choose the corresponding number of previous passwords kept by your domain)";
                Assert.AreEqual(expected, ex.Message);
            }
    }
    public void TestRecycleModeFailDuringRecycle()
    {
        MockUserWithChangeErrorOnThirdAttempt user = new MockUserWithChangeErrorOnThirdAttempt("TestUser", "TestPassword", "MyNewPassword");

            PasswordChanger pc = new PasswordChanger(user, update, errorHandle, 1, 4);
            try
            {
                pc.ChangePasswordRecycleMode();
            }
            catch (Exception ex)
            {
                string expected = "An error occured, your current password is: "
                            + "MyNewPassword*2"
                            + "\n\nYou will most likely be locked out."
                            + "\nPlease contact your system administrator to get your account unlocked. Error Message: \n\n"
                            + "Unit Test";
                //assert that the expected exeption was thrown
                Assert.AreEqual(expected, ex.Message);
            }
    }
        private void btnGo_Click(object sender, EventArgs e)
        {
            if (comboConnections.SelectedIndex == -1)
            {
                MessageBox.Show("You must select a Connection first.");
                return;
            }
            progressBarMain.Increment(-100);
            User user = new User(txtUsername.Text, txtPassword.Text, txtNewPassword.Text, _domain, _dn);

            int start;
            int.TryParse(txtStart.Text, out start);
            int iterations;
            int.TryParse(txtIterations.Text, out iterations);
            Action<string, int> update = delegate(string status, int progress)
            {
                UpdateStatus(status, progress);
            };
            Action<string> errorHandle = delegate(string message)
            {
                MessageBox.Show(message);
            };
            _adPasswordChanger = new PasswordChanger(user, update, errorHandle, start, iterations);
            if (txtNewPassword.Text == txtConfirm.Text)
            {
                if (txtPassword.Text != txtNewPassword.Text)
                {
                    DialogResult result;
                    result = MessageBox.Show("Since you are not recycling back to your current password, it is STRONGLY recommended that you reboot after completion. "
                    + "Do you want to continue?", "Reboot Recommended", MessageBoxButtons.YesNo);
                    if (result == DialogResult.No)
                    {
                        return;
                    }
                }
                _adPasswordChanger.StartJob(cbSingleMode.Checked);
            }
            else
            {
                MessageBox.Show("Your passwords do not match.");
            }
        }
 private void btnTest_Click(object sender, EventArgs e)
 {
     if (comboConnections.SelectedIndex == -1)
     {
         MessageBox.Show("You must select a Connection first.");
         return;
     }
     if (txtUsername.Text.Length < 2 || txtPassword.Text.Length < 2)
     {
         MessageBox.Show("Please fill in your username and current password before testing.");
         return;
     }
     User user = new User(txtUsername.Text, txtPassword.Text, txtNewPassword.Text, _domain, _dn);
     PasswordChanger pc = new PasswordChanger(user);
     try
     {
         pc.Connect();
         MessageBox.Show("Success!");
     }
     catch (Exception ex)
     {
         if (!string.IsNullOrWhiteSpace(ex.Message))
             MessageBox.Show(ex.Message);
         else
             MessageBox.Show("Oops! Something went wrong. Please check your connection settings.");
     }
 }