예제 #1
0
        public void Init()
        {
            // Arrange
            b1 = new Book("1");
            b2 = new Book("2", "Falling in Love with Yourself");
            b3 = new Book("3", "Spirits in the Night", 123.55);

            a1 = new Amulet("11");
            a2 = new Amulet("12", Level.high);
            a3 = new Amulet("13", Level.low, "Capricorn");

            c1 = new Course("Eufori med røg");
            c2 = new Course("Nuru Massage using Chia Oil", 157);

            courses = new CourseRepository();
            books   = new BookRepository();
            amulets = new AmuletRepository();

            // Act
            books.AddBook(b1);
            books.AddBook(b2);
            books.AddBook(b3);

            amulets.AddAmulet(a1);
            amulets.AddAmulet(a2);
            amulets.AddAmulet(a3);

            courses.AddCourse(c1);
            courses.AddCourse(c2);
        }
        public ActionResult AddBook(BookDetails book)
        {
            try
            {
                BookRepository bookRepository = new BookRepository();
                bookRepository.AddBook(book);

                var profileData = Session["UserProfile"] as UserSession;
                var logModel    = new LogModel
                {
                    UserId    = profileData.UserID,
                    TableName = "Book",
                    Activity  = "Added Book",
                    LogDate   = DateTime.Now
                };
                var logRepository = new logRepository();
                logRepository.AddLog(logModel);

                return(RedirectToAction("Dashboard", "Home"));
            }
            catch
            {
                return(RedirectToAction("Dashboard", "Home"));
            }
        }
예제 #3
0
        private void SaveButton_Click(object sender, EventArgs e)
        {
            NameTextBox.Text = NameTextBox.Text.TrimAndRemoveWhiteSpaces();
            if (!CheckForErrors())
            {
                return;
            }

            var toAdd = new Book
            {
                Name      = NameTextBox.Text,
                PageCount = PageCountTextBox.Text,
                Genre     = (Genre)Enum.Parse(typeof(Genre), GenreComboBox.Text),
                Author    = _authorRepository.GetAllAuthors().First(author => author.ToString() == AuthorComboBox.Text),
                Publisher = _publisherRepository.GetAllPublishers().First(publisher => publisher.ToString() == PublisherComboBox.Text)
            };

            _bookRepository.AddBook(toAdd);

            var statusToAdd = IsReadOnlyCheckBox.Checked ? BookStatus.ReadOnly : BookStatus.Available;

            for (var i = 0; i < int.Parse(NumberOfCopiesTextBox.Text); i++)
            {
                var copyToAdd = new BookCopy(statusToAdd, _bookRepository.GetAllBooks().FirstOrDefault(book => book.ToString() == toAdd.ToString()));
                _bookCopyRepository.AddBookCopy(copyToAdd);
            }

            Close();
        }
예제 #4
0
        public void AddBook()
        {
            // Arrange
            var bookID            = 11;
            var entites           = MockDataGenerator.CreateBookEntities(10);
            var entitiesQueryable = entites.AsQueryable();
            var viewModel         = MockDataGenerator.CreateBookViewModel(bookID);
            var BookEntity        = MockDataGenerator.CreateBookEntity(bookID);
            var BookDTO           = MockDataGenerator.CreateBook(bookID);

            var mockDbContext = new Mock <DatabaseContext>();
            var mockBookSet   = new Mock <DbSet <BookEntity> >();
            var mockMapper    = new Mock <IMapper>();

            mockBookSet.As <IQueryable <BookEntity> >().Setup(m => m.Provider).Returns(entitiesQueryable.Provider);
            mockBookSet.As <IQueryable <BookEntity> >().Setup(m => m.Expression).Returns(entitiesQueryable.Expression);
            mockBookSet.As <IQueryable <BookEntity> >().Setup(m => m.ElementType).Returns(entitiesQueryable.ElementType);
            mockBookSet.As <IQueryable <BookEntity> >().Setup(m => m.GetEnumerator()).Returns(entitiesQueryable.GetEnumerator()); mockBookSet.As <IQueryable <BookEntity> >().Setup(m => m.GetEnumerator()).Returns(entitiesQueryable.GetEnumerator());
            mockBookSet.Setup(f => f.Add(It.Is <BookEntity>(data => data.Title == BookEntity.Title))).Callback <BookEntity>(u => u.ID = BookEntity.ID);
            mockDbContext.Setup(f => f.Books).Returns(mockBookSet.Object);
            mockMapper.Setup(f => f.Map <BookViewModel, BookEntity>(It.Is <BookViewModel>(data => data.Title == viewModel.Title))).Returns(BookEntity);
            mockMapper.Setup(f => f.Map <BookEntity, BookDTO>(It.Is <BookEntity>(data => data.ID == BookDTO.ID))).Returns(BookDTO);

            var repository = new BookRepository(mockDbContext.Object, mockMapper.Object);

            // Act
            var result = repository.AddBook(viewModel);

            // Assert
            mockMapper.Verify(f => f.Map <BookViewModel, BookEntity>(It.Is <BookViewModel>(data => data.Title == viewModel.Title)), Times.Once());
            mockMapper.Verify(f => f.Map <BookEntity, BookDTO>(It.Is <BookEntity>(data => data.ID == BookDTO.ID)), Times.Once());
            mockBookSet.Verify(f => f.Add(It.Is <BookEntity>(data => data.Title == BookEntity.Title)), Times.Once());
            Assert.IsNotNull(result);
            Assert.AreEqual(result.ID, bookID);
        }
예제 #5
0
        public void AddBookException()
        {
            // Arrange
            var bookID            = 11;
            var entites           = MockDataGenerator.CreateBookEntities(10);
            var entitiesQueryable = entites.AsQueryable();
            var viewModel         = MockDataGenerator.CreateBookViewModel(bookID);
            var BookEntity        = MockDataGenerator.CreateBookEntity(bookID);

            var mockDbContext = new Mock <DatabaseContext>();
            var mockBookSet   = new Mock <DbSet <BookEntity> >();
            var mockLoanRepo  = new Mock <ILoanRepository>();
            var mockMapper    = new Mock <IMapper>();

            mockBookSet.As <IQueryable <BookEntity> >().Setup(m => m.Provider).Returns(entitiesQueryable.Provider);
            mockBookSet.As <IQueryable <BookEntity> >().Setup(m => m.Expression).Returns(entitiesQueryable.Expression);
            mockBookSet.As <IQueryable <BookEntity> >().Setup(m => m.ElementType).Returns(entitiesQueryable.ElementType);
            mockBookSet.As <IQueryable <BookEntity> >().Setup(m => m.GetEnumerator()).Returns(entitiesQueryable.GetEnumerator()); mockBookSet.As <IQueryable <BookEntity> >().Setup(m => m.GetEnumerator()).Returns(entitiesQueryable.GetEnumerator());
            mockBookSet.Setup(f => f.Add(It.Is <BookEntity>(data => data.Title == BookEntity.Title))).Throws(new Exception());
            mockDbContext.Setup(f => f.Books).Returns(mockBookSet.Object);
            mockMapper.Setup(f => f.Map <BookViewModel, BookEntity>(It.Is <BookViewModel>(data => data.Title == viewModel.Title))).Returns(BookEntity);

            var repository = new BookRepository(mockDbContext.Object, mockMapper.Object);

            // Act
            repository.AddBook(viewModel);
        }
        public ActionResult <Book> Post([FromBody] Book book)
        {
            var repo   = new BookRepository();
            var result = repo.AddBook(book);

            return(result);
        }
예제 #7
0
        public void Post([FromBody] string value)
        {
            BookContext    context        = new BookContext();
            BookRepository bookRepository = new BookRepository(context);

            bookRepository.AddBook("Sridhar", "Sridhar");
        }
        [TestMethod, Ignore] // Only VS Premium and Ultimate has Fakes
        public void TestWithShivCompleteDependantRepository()
        {
            var  author  = new AuthorBuilder().CliveCustler().Build();
            var  request = new BookBuilder().DeepSix().BuildRequest();
            Book response;

            using (ShimsContext.Create())
            {
                // Create SHIV
                var stubAuthRepo = new Contracts.Fakes.StubIAuthorRepository
                {
                    // Method = (parameters) => { method }
                    GetAuthorByIdGuid = id => author
                };

                // SHIM the property that retrieves the repository
                ShimBookRepository.AllInstances.AuthorRepoGet = _ => stubAuthRepo;

                var repo = new BookRepository();
                response = repo.AddBook(request);
            }

            Assert.IsNotNull(response);
            Assert.AreEqual(author, response.Author);
        }
예제 #9
0
 public int AddBook(FullBook fullBook)
 {
     if (User.Identity.IsAuthenticated && User.Identity.Name.Equals(ConfigurationManager.AppSettings["adminUserName"].ToString()))
     {
         return(BookRepository.AddBook(fullBook));
     }
     return(-1);
 }
        public void AddBookingDetailTest()
        {
            var bookrepo = new BookRepository(bookcontextmock.Object);
            var bookobj  = bookrepo.AddBook(new Book {
                Book_id = 3, Book_Name = "social", Cost = 50
            });

            Assert.IsNotNull(bookobj);
        }
예제 #11
0
 public IActionResult create(Book b)
 {
     if (ModelState.IsValid)
     {
         Book mybook = bookRepository.AddBook(b);
         return(RedirectToAction("index"));
     }
     return(View());
 }
예제 #12
0
        public void AddBookShouldSuccess()
        {
            Book book = new Book {
                BookName = "The Secret", AuthorName = "Rhonda Byrne", Genre = "Spiritual", Price = 545
            };
            var actual = repository.AddBook(book);

            Assert.IsAssignableFrom <Book>(actual);
            Assert.Equal(2, actual.BookId);
        }
 public static void ClassInitialize(TestContext context)
 {
     books = new BookRepository(new Book(1, "1", "Description", 10, 2008, Generes.Action));
     books.AddBook(new Book(2, "2", "Description", 20, 2009, Generes.Action));
     books.AddBook(new Book(3, "3", "Description", 30, 2010, Generes.Action));
     books.AddBook(new Book(4, "4", "Description", 40, 2011, Generes.Kids));
     books.AddBook(new Book(5, "5", "Description", 50, 2012, Generes.Kids));
     books.AddBook(new Book(6, "6", "Description", 60, 2013, Generes.Manual));
     books.AddBook(new Book(7, "7", "Description", 70, 2014, Generes.Science));
     books.AddBook(new Book(8, "8", "Description", 80, 2015, Generes.Action));
     books.AddBook(new Book(9, "9", "Description", 90, 2016, Generes.Story), new Book(10, "10", "Description", 100, 2017, Generes.Story));
 }
예제 #14
0
 public ActionResult CreateBook([Bind(Include = "authorName,bookName")] BookDetails book)
 {
     if (ModelState.IsValid)
     {
         BookRepository.AddBook(book);
         TempData["Message"] = "Added Successfully";
         return(RedirectToAction("Index"));
     }
     return(View());
 }
예제 #15
0
        public ActionResult Add(Books b)
        {
            BookRepository _AddRepository = new BookRepository();

            _AddRepository.AddBook(b);
            List <Books> bookList = new List <Books>();

            bookList = _AddRepository.GetAllBooks();
            return(View("ListView", bookList));
        }
예제 #16
0
        public IActionResult AddBook(BookModel bookModel)
        {
            int id = _bookRepository.AddBook(bookModel);

            if (id > 0)
            {
                return(RedirectToAction(nameof(AddBook), new { isSuccess = true, bookId = id }));
            }
            return(View());
        }
예제 #17
0
        public ActionResult AddBook(AddBookViewModel model, string returnUrl)
        {
            var bookRepository = new BookRepository(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString);
            var book           = new Book(model.ISBN, model.Title, model.Author);

            bookRepository.AddBook(book);
            TempData["Barcodes"] = bookRepository.AddCopiesOfBook(book, model.NumberOfCopies);

            return(Redirect("Success"));
        }
예제 #18
0
        public IActionResult AddBook(AddBookCommand newBook)
        {
            var repo      = new BookRepository();
            var bookAdded = repo.AddBook(newBook);

            if (bookAdded != null)
            {
                return(Ok(newBook));
            }
            return(BadRequest($"Unable to add book with title: {newBook.Title}."));
        }
예제 #19
0
        private void AddBook(Book book)
        {
            var repo = new BookRepository();

            if (!repo.AddBook(book))
            {
                return;
            }
            UpdateRows();
            labelLog.Text = @"Log: Добавлено";
        }
예제 #20
0
        public void Init()
        {
            b1 = new Book("1");
            b2 = new Book("2", "Falling in Love with Yourself");
            b3 = new Book("3", "Spirits in the Night", 123.55);
            books.AddBook(b1);
            books.AddBook(b2);
            books.AddBook(b3);

            a11 = new Amulet("11");
            a12 = new Amulet("12", Level.high);
            a13 = new Amulet("13", Level.low, "Capricorn");
            amulets.AddAmulet(a11);
            amulets.AddAmulet(a12);
            amulets.AddAmulet(a13);

            c111 = new Course("Eufori med røg");
            c112 = new Course("Nuru Massage using Chia Oil", 157);
            courses.AddCourse(c111);
            courses.AddCourse(c112);
        }
 public void AddBook()
 {
     book                = new Book();
     book.bookType       = BookType.Academics;
     book.name           = "testBook2";
     book.price          = 100;
     book.quantity       = 25;
     book.publishedBy    = "Test";
     book.publisher      = "pppp";
     book.dateOfPurchase = DateTime.Now;
     Assert.IsTrue(_bookRepository.AddBook(book));
 }
예제 #22
0
 public IActionResult CreateBook(Book book)
 {
     if (ModelState.IsValid)
     {
         bookRepository.AddBook(book);
         return(Ok(book));
     }
     else
     {
         return(BadRequest());
     }
 }
 public ActionResult Create(Book newBook, IFormCollection collection)
 {
     try
     {
         _bookRepo.AddBook(newBook);
         return(RedirectToAction(nameof(Index)));
     }
     catch
     {
         return(View());
     }
 }
예제 #24
0
        public void VerifyThatSpecificMethodsWasExecutedBehindCall()
        {
            var stubAuthorRepo = new AuthorRepoMockBuilder().GetAuthorById(
                null, ObjectMother.Instance.Authors.CliveCustler, true).Build();

            var repo = new BookRepository(stubAuthorRepo);
            var book = repo.AddBook(new BookBuilder().BookOne().BuildRequest());

            repo.AuthorRepo.VerifyAllExpectations();
            Assert.IsNotNull(book);
            Assert.AreEqual(ObjectMother.Instance.Authors.CliveCustler.Id, book.Author.Id);
        }
예제 #25
0
 public IActionResult Create(Book book)
 {
     if (ModelState.IsValid)
     {
         _bookRepository.AddBook(book);
         return(View("GetUpdatedList", _bookRepository.Database));
     }
     else
     {
         throw new NotImplementedException("One of more field(s) are empty");
     }
 }
예제 #26
0
        public void AddBook_ReturnsFalse()
        {
            //Arrange
            var testBook = new BookRepository(_ctx);
            //Act
            var result = testBook.AddBook(new Book {
                isbn = "9781234567025", name = "Demo", author = "Demo", publisher = "Demo", cost = 10, descriptuon = "Demo"
            });                                                                                                                                                      //adding an ISBN which already exists

            //Assert
            Assert.IsFalse(result);
        }
예제 #27
0
        public void AddBook_ReturnsTrue()
        {
            //Arrange
            var testBook = new BookRepository(_ctx);
            //Act
            var result = testBook.AddBook(new Book {
                isbn = "1234", name = "Demo", author = "Demo", publisher = "Demo", cost = 10, descriptuon = "Demo"
            });

            //Assert
            Assert.IsTrue(result);
        }
예제 #28
0
        public ActionResult Create([Bind(Include = "ID,Name,BookAvailability")] Book book)
        {
            if (ModelState.IsValid)
            {
                db1.AddBook(book);

                //db.Books.Add(book);
                //db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(book));
        }
예제 #29
0
        public async Task <IActionResult> AddBook(BookModel book)
        {
            if (ModelState.IsValid)
            {
                long id = await _repo.AddBook(book);

                if (id > 0)
                {
                    return(RedirectToAction("AddBook", new { IsSuccess = true, BookId = id }));
                }
            }

            return(View());
        }
예제 #30
0
        public void AddBook(BookDTO book, string currentUser)
        {
            Book dbBook = new Book()
            {
                Id      = book.Id,
                Title   = book.Title,
                Author  = book.Author,
                BookUrl = book.BookUrl,
                Price   = book.Price,
                UserId  = _uRepo.GetUser(currentUser).First().Id
            };

            _bookRepo.AddBook(dbBook, currentUser);
        }