Exemplo n.º 1
0
        public void CreateBookTest_Test()
        {
            Book book1 = new Book {
                Author = "Author", Title = "Title1", EditionDate = DateTimeOffset.Parse("05/01/2008")
            };
            Book book2 = new Book {
                Author = "Author", Title = "Title2", EditionDate = DateTimeOffset.Parse("05/01/2008")
            };
            Book book3 = new Book {
                Author = "Author", Title = "Title3", EditionDate = DateTimeOffset.Parse("05/01/2008")
            };

            var bookRepository = new BookRepository(context);

            bookRepository.Create(book1);
            bookRepository.Create(book2);
            bookRepository.Create(book3);

            var targetBook1 = context.Books.Where(b => b.Title.Equals("Title1")).First();
            var targetBook2 = context.Books.Where(b => b.Title.Equals("Title2")).First();
            var targetBook3 = context.Books.Where(b => b.Title.Equals("Title3")).First();

            Assert.AreEqual(book1, targetBook1);
            Assert.AreEqual(book2, targetBook2);
            Assert.AreEqual(book3, targetBook3);
            Assert.AreEqual(3, context.Books.ToList().Count());
        }
        public void Should_add_new_book()
        {
            var newBook = new Book
            {
                Id     = 2,
                Title  = "Aldrig f***a upp",
                Intro  = "Uppföljaren till succén...",
                Author = 1
            };

            _bookRepository.Create(newBook);
            var book = _bookRepository.Find(newBook.Id);

            Assert.That(book, Is.EqualTo(book));
        }
Exemplo n.º 3
0
        public void SearchBookByAuthor_Test()
        {
            Book book1 = new Book {
                Author = "Author", Title = "Title1", EditionDate = DateTimeOffset.Parse("05/01/2008")
            };
            Book book2 = new Book {
                Author = "Author", Title = "Title2", EditionDate = DateTimeOffset.Parse("05/01/2008")
            };
            Book book3 = new Book {
                Author = "Author", Title = "Title3", EditionDate = DateTimeOffset.Parse("05/01/2008")
            };
            Book book4 = new Book {
                Author = "Author", Title = "Title3", EditionDate = DateTimeOffset.Parse("05/01/2008")
            };
            Book book5 = new Book {
                Author = "Author1", Title = "Title3", EditionDate = DateTimeOffset.Parse("05/01/2008")
            };
            Book book6 = new Book {
                Author = "Author1", Title = "Title3", EditionDate = DateTimeOffset.Parse("05/01/2008")
            };
            Book book7 = new Book {
                Author = "Author1", Title = "Title3", EditionDate = DateTimeOffset.Parse("05/01/2008")
            };
            Book book8 = new Book {
                Author = "Author1", Title = "Title3", EditionDate = DateTimeOffset.Parse("05/01/2008")
            };

            List <Book> books1 = new List <Book>();

            books1.Add(book1);
            books1.Add(book2);
            books1.Add(book3);
            books1.Add(book4);

            List <Book> books2 = new List <Book>();

            books2.Add(book5);
            books2.Add(book6);
            books2.Add(book7);
            books2.Add(book8);

            var bookRepository = new BookRepository(context);

            bookRepository.Create(book1);
            bookRepository.Create(book2);
            bookRepository.Create(book3);
            bookRepository.Create(book4);
            bookRepository.Create(book5);
            bookRepository.Create(book6);
            bookRepository.Create(book7);
            bookRepository.Create(book8);

            var targetList1 = bookRepository.SearchByAuthor("Author");
            var targetList2 = bookRepository.SearchByAuthor("Author1");

            CollectionAssert.AreEqual(books1, targetList1);
            CollectionAssert.AreEqual(books2, targetList2);
        }
Exemplo n.º 4
0
        public ActionResult Create(BookModels book)
        {
            try
            {
                using (var repo = new BookRepository())
                {
                    repo.Create(book);
                    book.Id = repo.GetBookByTitle(book.Title);
                }

                foreach (var author in book.SelectedAuthors)
                {
                    using (var repo = new BookRepository())
                    {
                        repo.BindAuthorToBook(book.Id, author);
                    }
                }

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Exemplo n.º 5
0
        public void Create(BookViewModel bookViewModel)
        {
            var book = Mapper.Map <BookViewModel, Book>(bookViewModel);

            book.Type = LibraryType.Books;
            _bookRepository.Create(book);
        }
Exemplo n.º 6
0
        public ActionResult Create(CreateBookViewModel model)
        {
            Book book = new Book
            {
                Name      = model.Name,
                GenreID   = model.Genre,
                AuthorID  = model.Author,
                SeriesID  = model.Series,
                Price     = model.Price,
                Pages     = model.Pages,
                ImageName = model.ImageName
            };

            if (Request.Files.Count > 0)
            {
                HttpPostedFileBase file = Request.Files[0];
                if (file.ContentLength != 0)
                {
                    string imgPath       = Server.MapPath(Constants.ImagesDirectory);
                    string fileName      = file.FileName;
                    string savedFileName = Path.Combine(imgPath, Path.GetFileName(fileName));
                    file.SaveAs(savedFileName);
                    book.ImageName = fileName;
                }
                else
                {
                    book.ImageName = Constants.NoCoverPath;
                }
            }
            bookRepository.Create(book);
            return(RedirectToAction("Index"));
        }
Exemplo n.º 7
0
 public Book AddBook([FromBody] Book book)
 {
     if (ModelState.IsValid)
     {
         return(_repo.Create(book));
     }
     return(null);
 }
Exemplo n.º 8
0
        public void ShouldInsertBook()
        {
            var repo = new BookRepository(Context);
            var book = new Book { Title = "The Silmarillion", ISBN = "0-04-823139-8", AuthorId = 1 };
            repo.Create(book);
            Context.Commit();

            var savedBook = repo.FindAll().SingleOrDefault(x => x.Title == book.Title && x.ISBN == book.ISBN);
            Assert.That(savedBook != null, "Unable to find the book that was inserted.");
        }
Exemplo n.º 9
0
        public void Create_WhenCreateBookWithExistedId_ThenThrowArgumentException()
        {
            // Arrange
            var book = _db.Books.First();

            var repository = new BookRepository(_db);

            // Act - Assert
            Assert.Throws <ArgumentException>(() => repository.Create(book));
        }
Exemplo n.º 10
0
        public async void Create_ReturnsBook()
        {
            Mock <IDbCommand> command = new Mock <IDbCommand>();
            Mock <IDataParameterCollection> parameters = new Mock <IDataParameterCollection>();
            Mock <IDataReader> reader = new Mock <IDataReader>();

            DateTime now = DateTime.UtcNow;

            reader.Setup(r => r.GetInt32(0)).Returns(1);
            reader.Setup(r => r.GetString(1)).Returns("book title");
            reader.Setup(r => r.GetString(2)).Returns("book author");
            reader.Setup(r => r.GetString(3)).Returns("book isbn");
            reader.Setup(r => r.GetString(4)).Returns("book description");
            reader.Setup(r => r.GetBoolean(5)).Returns(true);
            reader.Setup(r => r.GetDateTime(6)).Returns(now);
            reader.Setup(r => r.GetDateTime(7)).Returns(now);
            reader.Setup(r => r.GetString(8)).Returns("book created by");
            reader.Setup(r => r.GetString(9)).Returns("book checked out by");

            command.SetupGet(c => c.Parameters).Returns(parameters.Object);
            command.Setup(c => c.ExecuteReader()).Returns(reader.Object);
            _connection.Setup(c => c.CreateCommand()).Returns(command.Object);

            Book expected = new Book(
                1,
                "book title",
                "book author",
                "book isbn",
                "book description",
                true,
                now,
                now,
                "book created by",
                "book checked out by"
                );

            BookRepository repository = CreateRepository();

            Book actual = await repository.Create(
                new Book(
                    1,
                    "book title",
                    "book author",
                    "book isbn",
                    "book description",
                    true,
                    now,
                    now,
                    "book created by",
                    "book checked out by"
                    )
                );

            Assert.Equal(expected, actual);
        }
        public ActionResult Create([Bind(Include = "Id,Name,ISBN,PageCount,PublishingDate,AuthorId,IsDeleted,IsRented")] Book book)
        {
            if (ModelState.IsValid)
            {
                _bookRepo.Create(Mapper.Map <BookBusiness>(book));
                return(RedirectToAction("Index"));
            }

            ViewBag.AuthorId = new SelectList(_authorRepo.ReadAll(), "Id", "Name", book.AuthorId);
            return(View(book));
        }
Exemplo n.º 12
0
        public BookViewModel Create(ResponseBookViewModel responseBookViewModel)
        {
            responseBookViewModel.Id = Guid.NewGuid();

            var book          = ViewModelToDomain(responseBookViewModel);
            var bookViewModel = DomainToViewModel(responseBookViewModel);

            _bookRepository.Create(book, responseBookViewModel.AuthorsList);

            return(bookViewModel);
        }
Exemplo n.º 13
0
        public IHttpActionResult PostBook([FromBody] Book book)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            repository.Create(book);
            repository.Save();

            return(CreatedAtRoute("DefaultApi", new { id = book.Id }, book));
        }
Exemplo n.º 14
0
        public void Upsert(Book entity)
        {
            validateBook(entity);

            if (entity._id == null)
            {
                bookRepository.Create(entity);
            }
            else
            {
                bookRepository.Update(entity);
            }
        }
Exemplo n.º 15
0
        public async Task <int> Create(CreateBookViewModel item)
        {
            var createdItem   = Mapper.Map <CreateBookViewModel, Book>(item);
            int createdItemId = await _bookRepository.Create(createdItem);

            var authors = Mapper.Map <ICollection <AuthorCreateBookViewModelItem>, List <Author> >(item.Authors);
            await _authorInBookRepository.AddAuthorsByBookId(createdItemId, authors);

            var publicHouses = Mapper.Map <ICollection <PublicHouseCreateBookViewModelItem>, List <PublicHouse> >(item.PublicHouses);
            await _publicHouseInBookRepository.AddPublicHousesByBookId(createdItemId, publicHouses);

            return(createdItemId);
        }
Exemplo n.º 16
0
        public void Create_WhenCreateBook_ThenBecomeOneMoreInDb()
        {
            // Arrange
            var book = new Book();
            var amoutBeforeOperations = _db.Books.Count;
            var repository            = new BookRepository(_db);

            // Act
            repository.Create(book);

            // Assert
            Assert.AreEqual(_db.Books.Count, amoutBeforeOperations + 1);
        }
Exemplo n.º 17
0
        private void saveBookButton_Click(object sender, EventArgs e)
        {
            _entry = new Book();

            _entry.Name        = BookName;
            _entry.Description = Description;
            _entry.Author      = Author;
            _repository.Create(_entry);

            DialogResult = DialogResult.OK;

            Close();
        }
Exemplo n.º 18
0
        public void TestIRepository_GetByProperty_NoParentEntity_RestrictionOnChildEntity_SingleRestriction_ShouldFailToInsertChildEntities()
        {
            // Arrange
            List <Book> books = GetBooks(3, 3);
            Book        book  = books[0];

            //Act
            BookRepository.Create(books);
            Book bookReadResult = BookRepository.GetByProperty("Title", Enums.RestrictionTypes.EqualTo, book.Title)[0];

            // Assert
            Assert.IsTrue(BooksAreEqual(bookReadResult, book));
        }
Exemplo n.º 19
0
        public JsonResult Create(CreateBookModel model)
        {
            var book = model.ToDomain();

            using (var bookRepo = new BookRepository())
            {
                bookRepo.Create(book);
            }

            return(new JsonResult {
                Data = new { IsOk = true }
            });
        }
Exemplo n.º 20
0
        public void SearchByTitle_Test()
        {
            Book book1 = new Book {
                Author = "Author", Title = "Title1", EditionDate = DateTimeOffset.Parse("05/01/2008")
            };
            Book book2 = new Book {
                Author = "Author", Title = "Title2", EditionDate = DateTimeOffset.Parse("05/01/2008")
            };
            Book book3 = new Book {
                Author = "Author", Title = "Title3", EditionDate = DateTimeOffset.Parse("05/01/2008")
            };
            Book book4 = new Book {
                Author = "Author", Title = "Title4", EditionDate = DateTimeOffset.Parse("05/01/2008")
            };
            Book book5 = new Book {
                Author = "Author1", Title = "Title5", EditionDate = DateTimeOffset.Parse("05/01/2008")
            };
            Book book6 = new Book {
                Author = "Author1", Title = "Title6", EditionDate = DateTimeOffset.Parse("05/01/2008")
            };
            Book book7 = new Book {
                Author = "Author1", Title = "Title7", EditionDate = DateTimeOffset.Parse("05/01/2008")
            };
            Book book8 = new Book {
                Author = "Author1", Title = "Title8", EditionDate = DateTimeOffset.Parse("05/01/2008")
            };

            var bookRepository = new BookRepository(context);

            bookRepository.Create(book1);
            bookRepository.Create(book2);
            bookRepository.Create(book3);
            bookRepository.Create(book4);
            bookRepository.Create(book5);
            bookRepository.Create(book6);
            bookRepository.Create(book7);
            bookRepository.Create(book8);

            var targetBook1 = bookRepository.SearchByTitle("Title1");
            var targetBook3 = bookRepository.SearchByTitle("Title3");
            var targetBook5 = bookRepository.SearchByTitle("Title5");
            var targetBook7 = bookRepository.SearchByTitle("Title7");

            Assert.AreEqual(book1, targetBook1);
            Assert.AreEqual(book3, targetBook3);
            Assert.AreEqual(book5, targetBook5);
            Assert.AreEqual(book7, targetBook7);
        }
Exemplo n.º 21
0
        public void Max_BookId_AreEqual_5()
        {
            // Arrange
            var fileHandlerMock = new Mock <IBookFileHandler>();

            fileHandlerMock.Setup(x => x.Load()).Returns(new List <Book> {
            });

            var subject = new BookRepository(fileHandlerMock.Object);

            subject.Create(new Book()
            {
                Id = 1, Title = "Book 1"
            });
            subject.Create(new Book()
            {
                Id = 4, Title = "Book 3"
            });
            subject.Create(new Book()
            {
                Id = 2, Title = "Book 2"
            });
            subject.Create(new Book()
            {
                Id = 5, Title = "Book 5"
            });
            subject.Create(new Book()
            {
                Id = 3, Title = "Book 3"
            });

            // Act
            var result = subject.Max(x => x.Id);

            // Assert
            Assert.AreEqual(5, result);
        }
Exemplo n.º 22
0
        public string post([FromBody] Book book)
        {
            dynamic response = new ExpandoObject();
            bool    inserted = bookRepository.Create(book);

            if (inserted)
            {
                response.sucess = "Livro inserido com sucesso";
            }
            else
            {
                response.sucess = "Erro ao inserir editar o Livro";
            }
            return(JsonSerializer.Serialize(response));
        }
        public void GivenCreate_WhenInvokedWithBook_ThenShouldAddBookToTheDbSet()
        {
            // Arrange
            var book    = BookStub.CreateNew();
            var set     = new Mock <DbSet <Book> >();
            var context = new Mock <DbContext>();

            context.Setup(c => c.Set <Book>()).Returns(set.Object);
            var repository = new BookRepository(context.Object);

            // Act
            repository.Create(book);

            // Assert
            set.Verify(s => s.Add(It.IsAny <Book>()), Times.Exactly(1));
        }
        public static void Main(string[] args)
        {
            var db = new LibrarySystemDbEntities2();

            var author = db.Book.FirstOrDefault(b => b.Id == 3).Owner.Name;

            Console.WriteLine(author);


            var bookRepo   = new BookRepository();
            var authorRepo = new AuthorRepository();
            var ownerRepo  = new OwnerRepository();

            //var bookUpdate3 = bookRepo.Read(3);
            //var bookUpdate4 = bookRepo.Read(4);

            //bookUpdate3.isDeleted = false;
            //bookUpdate4.isDeleted = false;

            //bookRepo.Update(bookUpdate3);
            //bookRepo.Update(bookUpdate4);

            //var owner1 = new OwnerBusiness();
            //owner1.Name = "Alex Todorv";
            //owner1.Gender = 0;
            //owner1.Email = "*****@*****.**";
            //owner1.Address = "Sofia, Druzhba 2";
            //owner1.UniqueIdNumber = "9406257845";
            //owner1.isDeleted = false;

            var book1 = new BookBusiness {
                Name = "Test book", ISBN = 122445667, countPages = 120, AuthorId = 12, OwnerId = 4
            };

            //var author1 = new AuthorBusiness();
            //author1.Name = "Hristo Botev";
            //author1.isDeleted = false;
            //author1.Gender = 0;

            //var book3 = new BookBusiness { Name = "Pod Igoto", ISBN = 122445667, countPages = 230, Author = author1, Owner = new OwnerBusiness { Name = "Gosho Peshov", PhoneNumber = "08859494616", Email = "*****@*****.**" } };


            bookRepo.Create(book1);
            //authorRepo.Create(author1);
            //bookRepo.Create(book3);
            //ownerRepo.Create(owner1);
        }
Exemplo n.º 25
0
 public void TestInitialize()
 {
     SUT = new List <Book>()
     {
         Book.Create(1, "Sherlock Holmes", 1950, 100, GenreEnum.NonFiction),
         Book.Create(2, "Alba ca zapada", 1900, 50, GenreEnum.Fiction),
         Book.Create(3, "Praslea", 1920, 30, GenreEnum.Fiction),
         Book.Create(4, "Marul auriu", 1970, 200, GenreEnum.Fiction),
         Book.Create(5, "Viata lui Stalin", 2015, 500, GenreEnum.NonFiction),
         Book.Create(6, "Mein Kampf", 1935, 400, GenreEnum.NonFiction),
         Book.Create(7, "Winston Churchill", 1967, 200, GenreEnum.NonFiction),
         Book.Create(8, "Prichindeii", 2010, 20, GenreEnum.Fiction),
         Book.Create(9, "Aoleu", 1987, 10, GenreEnum.Fiction),
         Book.Create(10, "Dancila", 2018, 2, GenreEnum.Fiction)
     };
     BookRepository = BookRepository.Create(SUT.ToList());
 }
        public async Task CreateBook_ReturnsCreatedBook()
        {
            // Arrange
            var databaseName = Guid.NewGuid().ToString();
            var context      = BuildContext(databaseName);

            var newBook = CreateFakeBook("Created Title");

            // Act
            var repo = new BookRepository(context);
            var book = await repo.Create(newBook);

            // Assert
            Assert.NotNull(book);
            Assert.IsType <Book>(book);
            Assert.Equal("Created Title", book.Title);
        }
Exemplo n.º 27
0
        public void CreateBookTest_Verify_Add_And_Save()
        {
            var mockSet = new Mock <DbSet <Book> >();

            var mockContext = new Mock <ApplicationContext>();

            mockContext.Setup(m => m.Books).Returns(mockSet.Object);

            var bookRepositry = new BookRepository(mockContext.Object);

            bookRepositry.Create(new Book {
                Author = "Author500", Title = "Title5", EditionDate = DateTimeOffset.Parse("05/01/2008")
            });

            mockSet.Verify(m => m.Add(It.IsAny <Book>()), Times.Once());
            mockContext.Verify(m => m.SaveChanges(), Times.Once());
        }
Exemplo n.º 28
0
        public ActionResult Create([Bind(Include = "Id,Name,ISBN,countPages,datePublished,AuthorId,OwnerId,isDeleted")] Book book)
        {
            if (ModelState.IsValid)
            {
                book.isDeleted = false;
                book.OwnerId   = 17;
                book.Author    = MappingWeb.ConvertToWebEntity(_authorRepo.Read(book.AuthorId));
                book.Owner     = MappingWeb.ConvertToWebEntity(_ownerRepo.Read(book.OwnerId));
                _bookRepo.Create(MappingWeb.ConvertToBusinessEntity(book));
                return(RedirectToAction("Index"));
            }


            ViewBag.AuthorId = new SelectList(_authorRepo.ReadAll(), "Id", "Name", book.AuthorId);
            ViewBag.OwnerId  = new SelectList(_ownerRepo.ReadAll(), "Id", "Name", book.OwnerId);

            return(View(book));
        }
Exemplo n.º 29
0
        public void AddBook(BookViewModel bvm)
        {
            int _id = _bookRepository.Create(new Book
            {
                Name = bvm.Name,
                Date = bvm.Date,
            }).Id;
            List <BookAuthor> _bookAuthors = bvm.Authors.Select(c => new BookAuthor {
                BookId = _id, AuthorId = (int)c.Id
            }).ToList();

            _bookAuthorRepository.AddRange(_bookAuthors);
            List <BookPublishingHouse> _bookPublishingHouses = bvm.PublishingHouses.Select(c => new BookPublishingHouse {
                BookId = _id, PublishingHouseId = (int)c.Id
            }).ToList();

            _bookPublishingHouseRepository.AddRange(_bookPublishingHouses);
        }
Exemplo n.º 30
0
        private void AcceptButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string name  = BookNameTextBox.Text;
                int    count = int.Parse(BookCountTextBox.Text);
                BookNameTextBox.Clear();
                BookCountTextBox.Clear();
                _books.Create(new Book(name, count));
            }
            catch (Exception exp)
            {
                (Owner.Owner as MainWindow).CallExceptionWindow($"Что-то пошло не так :(\n+{exp.Message}");
                return;
            }

            (Owner.Owner as MainWindow).CallAcceptWindow("Книга добавлена успешно");
        }
Exemplo n.º 31
0
        public void Create(BookViewModel bookViewModel, HttpPostedFileBase uploadImage)
        {
            var book = Mapper.Map <BookViewModel, Book>(bookViewModel);

            book.Type = LibraryType.Books;

            IEnumerable <Author> authors = _authorRepository.GetAll();

            book.AuthorName = authors.FirstOrDefault(x => x.AuthorId == book.AuthorId)?.AuthorName;

            IEnumerable <Redaction> redactions = _redactionRepository.GetAll();

            book.RedactionName = redactions.FirstOrDefault(x => x.RedactionId == book.RedactionId)?.RedactionName;

            byte[] imageData = _imageHelper.GetImage(uploadImage);

            book.Image = imageData;

            _bookRepository.Create(book);
        }