コード例 #1
0
        public void AddBookTest()
        {
            AddAuthorTest();
            Assert.AreEqual(0, _dataLayer.GetAllBooks().Count());
            Book hobbit = new Book("Hobbit, czyli tam i z powrotem", _dataLayer.FindAuthor(a => a.Name.Equals("Fiodor")), "Powie�� fantasy dla dzieci autorstwa J.R.R. Tolkiena.", Book.BookType.Fantasy);

            _dataLayer.AddBook(hobbit);
            Assert.AreEqual(1, _dataLayer.GetAllBooks().Count());
            Book zik = new Book("Zbrodnia i Kara", _dataLayer.FindAuthor(a => a.Name.Equals("Fiodor")), "Tematem powie�ci s� losy by�ego studenta, Rodiona Raskolnikowa, kt�ry postanawia zamordowa� i obrabowa� star� lichwiark�.", Book.BookType.Classics);

            _dataLayer.AddBook(zik);
            Assert.AreEqual(2, _dataLayer.GetAllBooks().Count());
            Book wp = new Book("Wladca Pierscieni", _dataLayer.FindAuthor(a => a.Surname.Equals("Tolkien")), "Powie�� high fantasy J.R.R. Tolkiena, kt�rej akcja rozgrywa si� w mitologicznym �wiecie �r�dziemia.Jest ona kontynuacj� innej powie�ci tego autora zatytu�owanej Hobbit, czyli tam i z powrotem.", Book.BookType.Fantasy);

            _dataLayer.AddBook(wp);
            Assert.AreEqual(3, _dataLayer.GetAllBooks().Count());
            Assert.ThrowsException <ArgumentException>(() => _dataLayer.AddBook(wp));
        }
コード例 #2
0
        public IActionResult Create([Bind("Name,Id,Count,Description,AuthorId")] Book book)
        {
            if (ModelState.IsValid)
            {
                _repository.AddBook(book);
                return(RedirectToAction(nameof(Index)));
            }

            return(View(book));
        }
コード例 #3
0
        public IHttpActionResult PostBook(Book book)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.AddBook(book);

            return(CreatedAtRoute("DefaultApi", new { id = book.Book_Id }, book));
        }
コード例 #4
0
        public void IsRepositoryAddsBook()
        {
            Book productToInsert = new Book
            {
                Book_Id    = 4,
                Book_Title = "Book Title 004",
                Price      = 9.00M,
                Edition    = "4th Edition",
                Author_Id  = 1
            };

            Repo.AddBook(productToInsert);
            // If Product inserts successfully,
            //number of records will increase to 4
            var result          = Repo.GetBooks();
            var numberOfRecords = result.ToList().Count;

            Assert.AreEqual(4, numberOfRecords);
        }
コード例 #5
0
        public void AddBook_PassBookObject_BookAddedToDatabse()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <DataContext>().UseInMemoryDatabase("Add_book_to_database").Options;
            var book    = new Book {
                Title = "Test", Description = "Test"
            };

            //Act
            using (var context = new DataContext(options))
            {
                var repo = new LibraryRepository(context);
                repo.AddBook(book);
                context.SaveChanges();
            }

            //Assert
            using (var context = new DataContext(options))
            {
                Assert.Equal(1, context.Books.Count());
                Assert.Equal("Test", context.Books.Single().Title);
            }
        }