public void Does_It_Add_In_Database_In_Table_PersonRegisters() { var data = new List <PersonRegister>() { 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)); }
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"); } } } }
public void CreatPersonRegister_saves_in_database() { var personregister = new PersonRegister() { Id = 1, Username = "******", Password = "******" }; var MockSet = new Mock <DbSet <PersonRegister> >(); var MockContext = new Mock <ApplicationContexts>(); MockContext.Setup(x => x.PersonRegisters).Returns(MockSet.Object); var service = new PersonRegisterController(MockContext.Object); service.Add(personregister.Username, personregister.Password); MockSet.Verify(x => x.Add(It.IsAny <PersonRegister>()), Times.Once()); MockContext.Verify(x => x.SaveChanges(), Times.Once()); }
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"); }
public void GettAll_Method_Does_it_gets_all_Accounts() { 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 result = service.GetAll(); Assert.AreEqual(3, result.Count(), "Incorrect Count"); }