public void Does_It_Add_in_Database_in_Table_PersonBookType() { var data = new List <PersonBookType>() { new PersonBookType() { Id = 1, BookType = "Business", PersonAccountId = 1 } }.AsQueryable(); var MockSet = new Mock <DbSet <PersonBookType> >(); MockSet.As <IQueryable <PersonBookType> >().Setup(x => x.Provider).Returns(data.Provider); MockSet.As <IQueryable <PersonBookType> >().Setup(x => x.Expression).Returns(data.Expression); MockSet.As <IQueryable <PersonBookType> >().Setup(x => x.ElementType).Returns(data.ElementType); MockSet.As <IQueryable <PersonBookType> >().Setup(x => x.GetEnumerator()).Returns(data.GetEnumerator()); var MockContext = new Mock <ApplicationContexts>(); MockContext.Setup(x => x.PersonBookTypes).Returns(MockSet.Object); var service = new PersonBookTypeController(MockContext.Object); data.ToList().ForEach(x => service.Add(x.BookType, x.PersonAccountId)); }
public void CheckIfExists_Method_Does_It_Return_True() { var data = new List <PersonBookType>() { new PersonBookType() { Id = 1, BookType = "Business", PersonAccountId = 1 } }.AsQueryable(); var MockSet = new Mock <DbSet <PersonBookType> >(); MockSet.As <IQueryable <PersonBookType> >().Setup(x => x.Provider).Returns(data.Provider); MockSet.As <IQueryable <PersonBookType> >().Setup(x => x.Expression).Returns(data.Expression); MockSet.As <IQueryable <PersonBookType> >().Setup(x => x.ElementType).Returns(data.ElementType); MockSet.As <IQueryable <PersonBookType> >().Setup(x => x.GetEnumerator()).Returns(data.GetEnumerator()); var MockContext = new Mock <ApplicationContexts>(); MockContext.Setup(x => x.PersonBookTypes).Returns(MockSet.Object); var service = new PersonBookTypeController(MockContext.Object); data.ToList().ForEach(x => service.Add(x.BookType, x.PersonAccountId)); var Checker = service.CheckIfExsist(); Assert.AreEqual(true, Checker, "Method Does not Return true"); }
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 CreatePersonBookType_Saves_In_Database() { var Personbook = new PersonBookType() { BookType = "Goshko", PersonAccountId = 1 }; var MockSet = new Mock <DbSet <PersonBookType> >(); var MockContext = new Mock <ApplicationContexts>(); MockContext.Setup(x => x.PersonBookTypes).Returns(MockSet.Object); var service = new PersonBookTypeController(MockContext.Object); service.Add(Personbook.BookType, Personbook.PersonAccountId); MockSet.Verify(x => x.Add(It.IsAny <PersonBookType>()), Times.Once()); MockContext.Verify(x => x.SaveChanges(), Times.Once()); }