Пример #1
0
        public void Book_AddBook_Should_Return_Invalid_Model_State()
        {
            var book = new NewBookViewModel
            {
                Isbn = "1"
            };

            _bookController.ModelState.AddModelError("test", "error");

            var response = _bookController.AddBook(book);

            Assert.IsInstanceOf <InvalidModelStateResult>(response);
        }
Пример #2
0
        private void buttonConfirm_Click(object sender, EventArgs e)
        {
            if (textBoxISBN.Text != "" && textBoxName.Text != "" && textBoxAuthor.Text != "" && textBoxPublish.Text != "" && textBoxStorage.Text != "")//添加健壮性检查
            {
                Book book = new Book()
                {
                    Id     = textBoxISBN.Text,
                    Name   = textBoxName.Text,
                    Author = textBoxAuthor.Text,
                    Press  = textBoxPublish.Text,
                    Number = Convert.ToInt32(textBoxStorage.Text),
                };
                using BookController bookMapper = new BookController();

                if (bookMapper.AddBook(book) > 0)
                {
                    MessageBox.Show("you are successful to add new books!");
                }
                else
                {
                    MessageBox.Show("you are failed to add new books!");
                }
                textBoxName.Text    = "";
                textBoxISBN.Text    = "";
                textBoxAuthor.Text  = "";
                textBoxPublish.Text = "";
                textBoxStorage.Text = "";
                this.Close();
            }
            else
            {
                MessageBox.Show("the input is illegal!");
            }
        }
Пример #3
0
        public void Given_AddBook_Data_Valid()
        {
            var data = new BookShowModel()
            {
                BooKTitle = "mvc",
                Author    = "microsoft",
                Language  = "English",
                Category  = "Tech",
                ISBN      = 1290,
                Price     = 123,
                Pages     = 123
            };
            var response = bookController.AddBook(data);

            Assert.IsType <OkObjectResult>(response);
        }
        public void AddBook_NewBook_ReturnsOk()
        {
            mockService.Setup(s => s.AddBook(It.IsAny <AddBookDto>()))
            .Returns(BookTestData.AddBookServiceResponse());

            BookController bookController = new BookController(mockService.Object);
            AddBookDto     newBook        = BookTestData.AddBookDto();

            var result = bookController.AddBook(newBook);

            Assert.That(result, Is.InstanceOf <OkObjectResult>());
        }
Пример #5
0
        public void GivenBookDetail_ToController_ShouldReturnBookDetails()
        {
            var service    = new Mock <IManagerBL>();
            var controller = new BookController(service.Object);

            book.BookTitle    = "Never Happen Twice";
            book.AuthorName   = "BDEC";
            book.BookImage    = "images.jpg";
            book.BookPrice    = 85.00;
            book.Availability = 10;
            var data = controller.AddBook(book);

            Assert.NotNull(data);
        }
        public void GetAllBooks_ReturnsOk()
        {
            mockService.Setup(s => s.GetAllBooks())
            .Returns(BookTestData.GetAllBooksServiceResponse());

            BookController bookController = new BookController(mockService.Object);
            AddBookDto     newBook        = BookTestData.AddBookDto();

            bookController.AddBook(newBook);

            var result = bookController.Get();

            Assert.That(result, Is.InstanceOf <OkObjectResult>());
        }
Пример #7
0
        public void AddBook_NewBook_ReturnsOk()
        {
            dbContext.Database.EnsureDeleted();
            dbContext.Database.EnsureCreated();

            AddBookDto newBook = GetAddBookDto();

            BookService    bookService    = new BookService(mapper, dbContext);
            BookController bookController = new BookController(bookService);

            var result = bookController.AddBook(newBook);

            Assert.That(result, Is.InstanceOf <OkObjectResult>());
        }
Пример #8
0
        public void AddBookTest()
        {
            // Arrange
            var repo           = new FakeBookRepository();
            var bookController = new BookController(repo);

            // Act
            bookController.AddBook("A Tale of Two Cities",
                                   "Charles Dickens", "1/1/1859");

            // Assert
            Assert.Equal("A Tale of Two Cities",
                         repo.Books.Last().Title);
        }
Пример #9
0
        public void AddBook_InvalidModeStade_BadRequest()
        {
            //Arrange
            var bookstore  = new Bookstore();
            var controller = new BookController(_bookServiceMock.Object);

            controller.ModelState.AddModelError("ModelError", "ModelError");

            //Act
            var action = controller.AddBook(bookstore);

            //Assert
            Assert.IsTrue(action is InvalidModelStateResult);
        }
Пример #10
0
        public void AddBookTest()
        {
            // Arrange
            var repo           = new FakeBookRepository();
            var bookController = new BookController(repo);

            // Act
            bookController.AddBook(new Book()
            {
                Title   = "A Tale of Two Cities",
                PubDate = DateTime.Parse("1/1/1859")
            });
            // Assert
            Assert.Equal("A Tale of Two Cities",
                         repo.Books[repo.Books.Count - 1].Title);
        }
        public void GetBookById_ExistingBook_ReturnsOk()
        {
            mockService.Setup(s => s.AddBook(It.IsAny <AddBookDto>()))
            .Returns(BookTestData.AddBookServiceResponse());
            mockService.Setup(s => s.GetBookById(It.IsAny <int>()))
            .Returns(BookTestData.GetSingleBookServiceResponse());

            BookController bookController = new BookController(mockService.Object);
            AddBookDto     newBook        = BookTestData.AddBookDto();

            bookController.AddBook(newBook);

            var result = bookController.GetSingleBook(1);

            Assert.That(result, Is.InstanceOf <OkObjectResult>());
        }
Пример #12
0
        public void AddBook_Test()
        {
            BookController c = CreateController <BookController>();
            BookViewModel  vm; int bookCount;

            using (var db = new SDCContext())
            {
                bookCount = db.Books.Count();

                var profile   = db.UserProfiles.Find(1);
                var shelf     = db.Shelves.FirstOrDefault(p => p.Owner.UserId == profile.UserId);
                var twoGenres = db.Genres.Take(2)
                                .ToList();

                var twoAuthors = db.Authors.OrderBy(a => Guid.NewGuid().ToString())
                                 .Take(2)
                                 .ToList();

                var publisher = db.Publishers.Take(1)
                                .First();

                var language = db.Languages
                               .Where(l => l.IsVisible)
                               .OrderBy(l => Guid.NewGuid().ToString())
                               .First();

                vm = new BookViewModel()
                {
                    Title       = Guid.NewGuid().ToString(),
                    Year        = 2015,
                    Genres      = twoGenres,
                    Authors     = twoAuthors,
                    Description = "Lorem ipsum",
                    Publisher   = publisher,
                    Language    = language,
                    ShelfId     = shelf.Id,
                    ShelfName   = shelf.Name,
                    ISBN        = Guid.NewGuid().ToString(),
                    AddedDate   = DateTime.Now
                };
            }


            c.AddBook(vm);
            Assert.AreEqual(bookCount + 1, new SDCContext().Books.Count());
        }
Пример #13
0
        public void AddBookTest()
        {
            // Arrange
            var repo           = new FakeBookRepository();
            var bookController = new BookController(repo);

            // Act
            bookController.AddBook(new Book()
            {
                Title = "A Tale of Two Cities", PubDate = new DateTime(1859, 1, 1)
            },
                                   "Charles Dickens");

            // Assert
            Assert.Equal("A Tale of Two Cities",
                         repo.Books.Last().Title);
        }
Пример #14
0
        public void AddBookTest_Invalid()
        {
            Mock <IDatabase> mock = new Mock <IDatabase>();

            mock.Setup(x => x.Execute(It.IsAny <string>(), It.IsAny <Dictionary <string, object> >())).Returns(1);
            BookController bookcontroller = new BookController(mock.Object);
            Book           book           = new Book();

            book.SetBookID(1);
            book.SetName("Times");
            book.SetAuthor("David Stanley");
            book.SetStatus("Available");
            book.SetPrice(25);
            book.SetRackno(12);
            book.SetCount(0);
            var result = bookcontroller.AddBook(book) as ViewResult;

            Assert.IsNotNull(result);
        }
Пример #15
0
        public void AddBookTest_Valid()
        {
            Mock <IDatabase> mock = new Mock <IDatabase>();

            mock.Setup(x => x.Execute(It.IsAny <string>(), It.IsAny <Dictionary <string, object> >())).Returns(1);
            BookController bookcontroller = new BookController(mock.Object);
            Book           book           = new Book();

            book.SetBookID(1);
            book.SetName("New York Times");
            book.SetAuthor("James Keith");
            book.SetStatus("Available");
            book.SetPrice(25);
            book.SetRackno(12);
            book.SetCount(2);
            var result = bookcontroller.AddBook(book) as ViewResult;

            Assert.AreEqual("AddBook", result.ViewName);
        }
Пример #16
0
        private void btnBookAdded_Click(object sender, EventArgs e)
        {
            var user = new
            {
                Bookname = textBoxBookName.Text,
                Author   = textBoxAuthor.Text,
                Edition  = textBoxEdition.Text
            };
            var result = BookController.AddBook(user);

            if (result)
            {
                MessageBox.Show("Book Added");
            }
            else
            {
                MessageBox.Show("Could not Add Book");
            }
        }
        public void AddBookTest()
        {
            var       bookrepomock       = new Mock <IBookRepo>();
            var       bookmangermock     = new BookManager(bookrepomock.Object);
            var       BookControllermock = new BookController(bookmangermock);
            BookModel bookModel          = new BookModel()
            {
                BookId         = 0,
                Author         = "sumit",
                Title          = "Sumit-Biograpy",
                AvailableBooks = 5,
                Price          = 50000,
                Image          = "imageurl",
                Description    = "asdfghj wertyu sdvb tgb ikm ",
                Ratings        = "5 star",
                Review         = "wqer  dvzs sd rht tyjh nfg "
            };
            var result = BookControllermock.AddBook(bookModel);

            Assert.NotNull(result);
        }
Пример #18
0
        private void btnAddBook_Click(object sender, EventArgs e)
        {
            try
            {
                if ((bookController.CheckBook((int)nudBookISBN.Value)) == null)
                {
                    Editorial editorial = new Editorial(editorialID, editorialName);
                    Author    author    = new Author(authorID, authorName);
                    Book      book      = new Book(bookID, ISBN, title, editorial, edition, year, editionYear, author, deterioration);
                    book.ISBN          = (int)nudBookISBN.Value;
                    book.Title         = txbBookName.Text;
                    book.Year          = (int)nudBookYear.Value;
                    book.EditionYear   = (int)nudBookEditionYear.Value;
                    book.Deterioration = txbBookDeterioration.Text;
                    book.Author        = (Author)cmbBookAuthor.SelectedItem;
                    book.Editorial     = (Editorial)cmbBookEditorial.SelectedItem;
                    book.Edition       = (int)nudBookEdition.Value;

                    if (bookController.AddBook(book) != null)
                    {
                        MessageBox.Show("Se agregó un libro con éxito.");
                    }
                }
                else
                {
                    MessageBox.Show("Ya existe un libro con ese ISBN.");
                }

                updateAll();
            }
            catch (Exception ex)
            {
                error = ex.Message;
                MessageBox.Show(error);
            }
        }
        private void add_Click(object sender, EventArgs e)
        {
            Author author = new Author(authorFirstNameTextBox.Text, authorLastNameTextBox.Text);

            bookController.AddBook(isbnTextBox.Text, titleTextBox.Text, author);
        }
Пример #20
0
 private void addBook_Click(object sender, EventArgs e)
 {
     bookController.AddBook(Title.Text, ISBN.Text, AuthorFirstName.Text, AuthorLastName.Text);
 }
Пример #21
0
 private void btAdd_Click(object sender, EventArgs e)
 {
     bookController.AddBook(txtISBN.Text, txtTitle.Text, txtFirstName.Text, txtLastName.Text);
 }
Пример #22
0
        private void buttonImport_Click(object sender, EventArgs e)
        {
            string         txtpath = null;
            OpenFileDialog opn     = new OpenFileDialog();

            if (opn.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                txtpath = opn.FileName;
            }
            else
            {
                return;
            }
            Match match = Regex.Match(txtpath, @"[^\.]*$");

            if (match.Groups[0].Value == "xlsx" || match.Groups[0].Value == "xls" || match.Groups[0].Value == "csv")  //健壮性检验
            {
                try {
                    DataTable dt = getDataTableFromExcel(txtpath);

                    foreach (DataRow row in dt.Rows)
                    {
                        //MessageBox.Show(row[0].ToString());  //I find the datatable begins at 0 which does not inclues the headers.
                        bool flag    = true;
                        Book newBook = new Book();
                        for (int i = 0; i < row.Table.Columns.Count; i++)
                        {
                            if (row[i] == null)
                            {
                                MessageBox.Show("bookID:" + newBook.Id + "is failed to add, beacause there is some information empty!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                flag = false;
                                break;
                            }
                        }
                        if (flag)
                        {
                            newBook.Id     = row[0].ToString();
                            newBook.Name   = row[1].ToString();
                            newBook.Author = row[2].ToString();
                            newBook.Press  = row[3].ToString();
                            newBook.Number = int.Parse(row[4].ToString());
                            using BookController bookMapper = new BookController();
                            if (bookMapper.AddBook(newBook) == 0)
                            {
                                MessageBox.Show("bookID:" + newBook.Id + "is failed to add", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                            MessageBox.Show($"Succeful to add {newBook.Name} to library system!", "Successful!");
                            this.Close();//关闭添加页面
                        }
                    }
                }
                catch (System.IO.IOException) {
                    MessageBox.Show("you should not occupy the process of Excel and you need to close it before importing data! ");
                    throw;
                }
                catch (Microsoft.EntityFrameworkCore.DbUpdateException) {
                    MessageBox.Show("we are regret to tell you that there are some items that are same as those in database, so you need to check carefully! ");
                    throw;
                }
                catch (Exception ex) {
                    MessageBox.Show("You have met some errors so you need to contact with the developer! The error information is: " + ex.Message);
                }
            }
            else
            {
                MessageBox.Show("opps! you have chosen a wrong document! we only support .xlsx, .xls and csv");
            }
        }