Exemple #1
0
        public void TestChangePassword()
        {
            TextBox     testFirstNameBox = new TextBox();
            TextBox     testLastNameBox  = new TextBox();
            PasswordBox testPasswordBox  = new PasswordBox();
            TextBox     testEmailBox     = new TextBox();
            TextBox     testSecretPinBox = new TextBox();

            testFirstNameBox.Text    = "name";
            testLastNameBox.Text     = "surname";
            testPasswordBox.Password = "******";
            testEmailBox.Text        = "*****@*****.**";
            testSecretPinBox.Text    = "1234";

            Books365.BLL.User user = new Books365.BLL.User();
            using (Books365.AppContext db = new Books365.AppContext())
            {
                TextBox testNewPasswordBox = new TextBox();
                testNewPasswordBox.Text = "NewPassword";
                user.AddNewUser(testFirstNameBox, testLastNameBox, testPasswordBox, testEmailBox, testSecretPinBox);
                user.ChangePassword(testEmailBox.Text, testSecretPinBox, testNewPasswordBox);
                Assert.Equal(testNewPasswordBox.Text, db.Users.Where(u => u.Email == testEmailBox.Text).FirstOrDefault().Password);
                db.Users.RemoveRange(db.Users.Where(u => u.Email == testEmailBox.Text));
                db.EmailCurrentUser.RemoveRange(db.EmailCurrentUser.Where(u => u.Email == testEmailBox.Text));
                db.SaveChanges();
            }
        }
        private void Button_Click_Submit(object sender, RoutedEventArgs e)
        {
            Validator validator = new Validator();

            if (validator.IsEmpty(this.SecretPinTextBox) ||
                !validator.SecretPinIsCorrect(this.SecretPinTextBox) ||
                validator.IsEmpty(this.NewPasswordTextBox) ||
                validator.IsEmpty(this.NewPasswordConfirmTextBox) ||
                !validator.PasswordIsCorrect(this.NewPasswordTextBox) ||
                !validator.ConfirmIsSame(this.NewPasswordConfirmTextBox, this.NewPasswordTextBox))
            {
                Logger.Debug("User information is incorrect. Forgot password Failed");
            }
            else
            {
                Books365.BLL.User u = new Books365.BLL.User();
                bool answer         = u.ChangePassword(this.EmailTextBox.Text, this.SecretPinTextBox, this.NewPasswordTextBox);
                if (!answer)
                {
                    MessageBox.Show("Wrong secret pin or email", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    Logger.Debug($"User {u.Email} - enter a wrong secret pin");
                }
                else
                {
                    this.Close();
                    Window1 w1 = new Window1();
                    w1.Show();
                    Logger.Debug($"Secret Pin was successfully changed");
                }
            }
        }
Exemple #3
0
        public void TestLoginValid()
        {
            TextBox     testFirstNameBox = new TextBox();
            TextBox     testLastNameBox  = new TextBox();
            PasswordBox testPasswordBox  = new PasswordBox();
            TextBox     testEmailBox     = new TextBox();
            TextBox     testSecretPinBox = new TextBox();

            testFirstNameBox.Text    = "name";
            testLastNameBox.Text     = "surname";
            testPasswordBox.Password = "******";
            testEmailBox.Text        = "*****@*****.**";
            testSecretPinBox.Text    = "1234";

            Books365.BLL.User user = new Books365.BLL.User();
            using (Books365.AppContext db = new Books365.AppContext())
            {
                user.AddNewUser(testFirstNameBox, testLastNameBox, testPasswordBox, testEmailBox, testSecretPinBox);
                db.EmailCurrentUser.RemoveRange(db.EmailCurrentUser.Where(u => u.Email == testEmailBox.Text));
                db.SaveChanges();
                Assert.True(user.Login(testEmailBox, testPasswordBox));
                db.Users.RemoveRange(db.Users.Where(u => u.Email == testEmailBox.Text));
                db.EmailCurrentUser.RemoveRange(db.EmailCurrentUser.Where(u => u.Email == testEmailBox.Text));
                db.SaveChanges();
            }
        }
Exemple #4
0
        public void TestLoginInvalid()
        {
            TextBox     emailBox = new TextBox();
            PasswordBox pwdBox   = new PasswordBox();

            emailBox.Text   = "*****@*****.**";
            pwdBox.Password = "******";
            Books365.BLL.User user = new Books365.BLL.User();
            using (Books365.AppContext db = new Books365.AppContext())
            {
                Assert.False(user.Login(emailBox, pwdBox));
            }
        }
Exemple #5
0
 private void Button_Click_Login(object sender, RoutedEventArgs e)
 {
     Books365.BLL.User u = new Books365.BLL.User();
     if (u.Login(this.EmailTextBox, this.PasswordTextBox))
     {
         Logger.Info($"User {this.EmailTextBox.Text} - was logged in");
         Window1 w1 = new Window1();
         w1.Show();
         this.Close();
     }
     else
     {
         Logger.Warn($"Login data was incorrect");
     }
 }
Exemple #6
0
        public void TestAddBook()
        {
            TextBox testTitleBox  = new TextBox();
            TextBox testYearBox   = new TextBox();
            TextBox testAuthorBox = new TextBox();

            testTitleBox.Text  = "testBook";
            testYearBox.Text   = "2020";
            testAuthorBox.Text = "testAuthor";
            Books365.BLL.User user = new Books365.BLL.User();
            using (Books365.AppContext db = new Books365.AppContext())
            {
                user.AddBook(testTitleBox, testYearBox, testAuthorBox);
                Assert.Equal(db.Books.Where(b => b.Title == testTitleBox.Text).FirstOrDefault().Title, testTitleBox.Text);
                db.Books.RemoveRange(db.Books.Where(b => b.Title == testTitleBox.Text));
                db.SaveChanges();
            }
        }
        private void ButtonAddBook_Click(object sender, RoutedEventArgs e)
        {
            Validator validator = new Validator();

            if (validator.IsEmpty(this.TitleText) || validator.IsEmpty(this.YearText) ||
                !validator.YearIsValid(this.YearText) || validator.IsEmpty(this.AuthorText))
            {
                Logger.Info($"Adding books - was failed");
            }
            else
            {
                string            title  = this.TitleText.Text;
                int               year   = Convert.ToInt32(this.YearText.Text);
                string            author = this.AuthorText.Text;
                Books365.BLL.User u      = new Books365.BLL.User();
                u.AddBook(title, year, author);
                Window1 p = new Window1();
                p.Show();
                this.Close();
                Logger.Info($"Book{this.TitleText.Text} was added to library");
            }
        }
Exemple #8
0
        private void Button_Click_Reg(object sender, RoutedEventArgs e)
        {
            Validator validator = new Validator();

            if (validator.IsEmpty(this.Email_Register) ||
                !validator.EmailIsCorrect(this.Email_Register) ||
                validator.IsEmpty(this.LastNameTextBox) ||
                validator.IsEmpty(this.FirstNameTextBox) ||
                validator.IsEmpty(this.SecretPinTextBox) ||
                validator.EmailExists(this.Email_Register) ||
                !validator.SecretPinIsCorrect(this.SecretPinTextBox) ||
                !validator.PasswordIsCorrect(this.Password_Register))
            {
            }
            else
            {
                Books365.BLL.User user = new Books365.BLL.User();
                user.AddNewUser(this.FirstNameTextBox, this.LastNameTextBox, this.Password_Register, this.Email_Register, this.SecretPinTextBox);
                Window1 w1 = new Window1();
                w1.Show();
                this.Close();
            }
        }
Exemple #9
0
 private void EditProfileFunc()
 {
     Books365.BLL.User u = new Books365.BLL.User();
     u.EditProfile(this.FirstNameTextBox, this.LastNameTextBox, this.PasswordTextBox, this.ConfirmPasswordTextBox, this.SecretPinTextBox);
 }