Esempio n. 1
0
        public void CheckLogin_TestTrue_OutputisTrue()
        {
            string  user     = User.UserName;
            string  password = User.Password;
            Boolean expected = true;
            Boolean actual;

            actual = User.CheckLogin(user, password);
            Assert.AreEqual(expected, actual);
        }
Esempio n. 2
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            //Create a dummy login for testing
            userAdd = new User("LewisAllan", "LewisA", "lewisallan");
            //create variables for storing information
            Boolean bool1    = false;
            string  username = txtHasUsername.Text;
            string  password = txtHasPassword.Text;

            //Run function for deserializing
            ReadFromFile();
            //Find user that is logging in
            User test = users.FindItem(username);

            while (bool1 == false)
            {
                try
                {
                    if (txtHasUsername.Text == "" || txtHasPassword.Text == "")
                    {
                        EnterFieldsException fields = new EnterFieldsException();
                        throw (fields);
                    }
                    else
                    {
                        Boolean bool2;
                        //Check this user has entered correct login details
                        bool2 = test.CheckLogin(username, password);
                        if (bool2 == true)
                        {
                            using (StreamWriter sw = new StreamWriter("CurrentUser.txt"))
                            {
                                sw.WriteLine(users.FindItem(username));
                            }

                            BookingForm frm2 = new BookingForm();
                            frm2.FormClosed += new FormClosedEventHandler(frm2_FormClosed);
                            this.Hide();
                            frm2.Show();
                            bool1 = true;
                        }
                        else
                        {
                            MessageBox.Show("Wrong details");
                            bool1 = true;
                        }
                    }
                    bool1 = true;
                }
                catch (FormatException ex)
                {
                    MessageBox.Show(ex.Message, "error");
                }
                catch (IOException ex)
                {
                    MessageBox.Show(ex.Message, "error");
                    outFile.Close();
                    Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "error");
                    bool1 = true;
                }
            }
        }