Ejemplo n.º 1
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();
            }
        }
Ejemplo n.º 2
0
        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");
            }
        }