Exemple #1
0
        private void Register_Click(object sender, EventArgs e)
        {
            LoginPart login = new LoginPart();

            //Check's is everything filled
            if (txtUsernameRegisterForm.Text == "" || txtPasswordRegisterForm.Text == "" || txtConfirmPasswordRegisterForm.Text == "" || Bookstypes.Text == "")
            {
                MessageBox.Show("Please fill the rows to register");
            }
            else
            {
                if (Bookstypes.Text == "Business")
                {
                    //Check's is the password textbox and Confirmpassword texbox are equal and not equal to zero
                    if (txtPasswordRegisterForm.Text == txtConfirmPasswordRegisterForm.Text && txtPasswordRegisterForm.Text.Length != 0)
                    {
                        //this variable returns true if the name exists or false if no
                        var CheckIfExists = User.CheckIfUsernameExists(txtUsernameRegisterForm.Text);
                        //this if statement checks if the names are equal or no
                        if (!(CheckIfExists == txtUsernameRegisterForm.Text))
                        {
                            User.Add(txtUsernameRegisterForm.Text, txtPasswordRegisterForm.Text);
                            //this if will happen only once per creation of a new account
                            if (!(UserBookType.CheckIfExsist()))
                            {
                                var business = "Business";
                                UserBookType.Add(business, 1);
                            }
                            var a = User.GetAll();
                            UserAccount.Add(1);
                            BookForUser.Add(smallshop.GetTime(), 0, 0, 0, 0, 0, 0, 1, a.Count());
                            this.Hide();
                            login.Show();
                            MessageBox.Show("Succsessfully registered");
                        }
                        else
                        {
                            MessageBox.Show("This Username is taken");
                        }
                    }
                    else
                    {
                        MessageBox.Show("Passswords doesn't match");
                    }
                }
            }
        }
Exemple #2
0
        public void CheckIfNameExists_Method_Does_it_finds_the_given_name()
        {
            var data = new List <PersonRegister>()
            {
                new PersonRegister()
                {
                    Id = 1, Username = "******", Password = "******"
                },
                new PersonRegister()
                {
                    Id = 2, Username = "******", Password = "******"
                },
                new PersonRegister()
                {
                    Id = 3, Username = "******", Password = "******"
                }
            }.AsQueryable();

            var MockSet = new Mock <DbSet <PersonRegister> >();

            MockSet.As <IQueryable <PersonRegister> >().Setup(x => x.Provider).Returns(data.Provider);
            MockSet.As <IQueryable <PersonRegister> >().Setup(x => x.Expression).Returns(data.Expression);
            MockSet.As <IQueryable <PersonRegister> >().Setup(x => x.ElementType).Returns(data.ElementType);
            MockSet.As <IQueryable <PersonRegister> >().Setup(x => x.GetEnumerator()).Returns(data.GetEnumerator());

            var MockContext = new Mock <ApplicationContexts>();

            MockContext.Setup(x => x.PersonRegisters).Returns(MockSet.Object);

            var service = new PersonRegisterController(MockContext.Object);

            data.ToList().ForEach(x => service.Add(x.Username, x.Password));

            var a = service.CheckIfUsernameExists("Goshko2");

            Assert.AreEqual("Goshko2", a, "Doesn't return the given name while the name exists");
        }