public void AddBook_CorrectData_TrueReturned()
        {
            //Arrange
            string author             = "Джорджи Кроули";
            int    field_knowledge_id = 523;
            string name           = "Корги по имени Генри";
            string isbn           = "978-5-386-12347-5";
            string place          = "Москва";
            int    year           = 1755;
            int    interpreter_id = 2;
            int    chamber_id     = 2;

            int updatedBooksLength = 0;
            int oldBooksLength     = dbHelper.context.books.Count();

            //Act
            if (booksController.AddNewBook(author, field_knowledge_id, name, isbn, place, year, interpreter_id, chamber_id))
            {
                updatedBooksLength = dbHelper.context.books.Count();
                var selectString = dbHelper.context.books.AsNoTracking().OrderByDescending(t => t.book_id).Take(1);

                foreach (var item in selectString)
                {
                    booksController.DeleteBookInfo(item);
                }


                //Assert
                Assert.AreEqual(oldBooksLength + 1, updatedBooksLength);
            }
        }
예제 #2
0
        public void AddBookToListTest()
        {
            BooksController controller = new BooksController();

            Book book1 = new Book("Harry Potter and The Philosopher's stone", "J.K. Rowling", 373, "1232123212321");

            controller.AddNewBook(book1);

            var resultAll = controller.GetAllBooks() as List <Book>;

            var resultOne = controller.GetSpecificBook("1232123212321");

            Assert.AreEqual(3, resultAll.Count);

            Assert.AreEqual("J.K. Rowling", resultOne.Author);
        }
예제 #3
0
        /// <summary>
        /// Событие при клике на кнопку "Продолжить"
        /// </summary>
        private void SaveBtn_Click(object sender, RoutedEventArgs e)
        {
            StringCheck check        = new StringCheck();
            string      resultString = "";

            bool resultAuthor = check.CheckName(AuthorInput.Text);

            if (!resultAuthor || AuthorInput.Text == "")
            {
                resultString += "Неправильно введено имя Автора\n";
            }

            bool resultName = check.CheckBookName(NameInput.Text);

            if (!resultName || NameInput.Text == "")
            {
                resultString += "Неправильно введено название\n";
            }

            string resultBbk       = BBkInputComboBox.Text;
            string resultDirectBbk = DirectInputTextBox.Text;

            if (resultBbk == "" && resultDirectBbk == "")
            {
                resultString += "Неправильно введено BBK\n";
            }

            bool resultIsbn = check.CheckBookIsbn(ISBNInput.Text);

            if (!resultIsbn || ISBNInput.Text == "")
            {
                resultString += "Неправильно введен ISBN\n";
            }

            bool resultYear = check.CheckBookYear(YearInput.Text);

            if (!resultYear || YearInput.Text == "" || Convert.ToInt32(YearInput.Text) < 1500 || Convert.ToInt32(YearInput.Text) > DateTime.Now.Year)
            {
                resultString += "Неправильно введен год\n";
            }

            string resultInterpretor = InterpreterComboBox.Text;

            if (resultInterpretor == "")
            {
                resultString += "Неправильно введено имя Издания\n";
            }

            string resultChamber = ChamberComboBox.Text;

            if (resultChamber == "")
            {
                resultString += "Неправильно введен номер отсека\n";
            }

            if (resultString == "")
            {
                int userBbk = 0;

                if (SelectInputBtn.Visibility == Visibility.Collapsed)
                {
                    BbkWarningBtn.Visibility = Visibility.Collapsed;
                    userBbk = Convert.ToInt32(BBkInputComboBox.SelectedValue);
                }
                else if (SelectInputBtn.Visibility == Visibility.Visible)
                {
                    userBbk = fieldsController.GetBbkId(DirectInputTextBox.Text);
                }

                if (booksController.AddNewBook(AuthorInput.Text, userBbk, NameInput.Text, ISBNInput.Text, PlaceInput.Text, Convert.ToInt32(YearInput.Text), interpretorsController.GetInterpretorId(InterpreterComboBox.Text), Convert.ToInt32(ChamberComboBox.Text)))
                {
                    if (quantityController.AddNewQuantity(Settings.Default.bookId))
                    {
                        if (booksController.UpdateBookQuantity(Settings.Default.quantityId))
                        {
                            MessageBox.Show("Книга добавлена");
                            if (Settings.Default.role == 1)
                            {
                                this.NavigationService.Navigate(new MenuAdminPage());
                            }
                            if (Settings.Default.role == 2)
                            {
                                this.NavigationService.Navigate(new MenuLibrarianPage());
                            }
                        }
                        else
                        {
                            MessageBox.Show("Ошибка базы данных, попробуйте позже.");
                        }
                    }
                    else
                    {
                        MessageBox.Show("Ошибка базы данных, попробуйте позже.");
                    }
                }
            }
            else
            {
                MessageBox.Show(resultString);
            }
        }