示例#1
0
        public BookFormModel(Book book, List<Author> authors, List<Category> categories)
            : this(authors, categories)
        {
            if (book != null)
            {
                BookId = book.Id;
                //CategoryId = book.CategoryId;
                AuthorId = book.Authors.Select(author => author.Id).ToArray();
                Title = book.Title;

                Image = book.Image;
            }
        }
示例#2
0
        public void Create_new_book_with_exists_category_and_authors()
        {
            var bookService = _ninjectKernel.Get<IBookService>();
            var categoryService = _ninjectKernel.Get<ICategoryService>();
            var authorService = _ninjectKernel.Get<IAuthorService>();

            var countOfBooksBefore = bookService.Count();
            var countOfCategoriesBefore = categoryService.Count();
            var countOfAuthorsBefore = authorService.Count();

            var random = new Random();

            var allAuthors = authorService.GetAll();
            Assert.IsTrue(allAuthors.Count > 0);

            var allCategories = categoryService.GetAll();
            Assert.IsTrue(allCategories.Count > 0);

            var authors = new List<Author>
                              {
                                  allAuthors[random.Next(allAuthors.Count)],
                                  allAuthors[random.Next(allAuthors.Count)],
                                  allAuthors[random.Next(allAuthors.Count)]
                              };

            var category = allCategories[random.Next(allCategories.Count)];

            var book = new Book
            {
                Authors = authors,
                Category = category,
                Image = "",

                Title = "Test book #" + DateTime.Now.Ticks
            };

            bookService.RegisterBook(book);
            bookService.SaveChanges();

            var countOfBooksAfter = bookService.Count();
            var countOfCategoriesAfter = categoryService.Count();
            var countOfAuthorsAfter = authorService.Count();

            Assert.AreEqual(countOfBooksBefore + 1, countOfBooksAfter);
            Assert.AreEqual(countOfCategoriesBefore, countOfCategoriesAfter);
            Assert.AreEqual(countOfAuthorsBefore, countOfAuthorsAfter);
        }
示例#3
0
        public void Create_new_book_with_new_category_and_authors()
        {
            var ticks = DateTime.Now.Ticks;

            var bookService = _ninjectKernel.Get<IBookService>();
            var categoryService = _ninjectKernel.Get<ICategoryService>();
            var authorService = _ninjectKernel.Get<IAuthorService>();

            var countOfBooksBefore = bookService.Count();
            var countOfCategoriesBefore = categoryService.Count();
            var countOfAuthorsBefore = authorService.Count();

            var authors = new List<Author>
                              {
                                  new Author {Name = "Автор #" + ticks},
                                  new Author {Name = "Автор #" + ticks},
                              };

            var category = new Category
            {
                Name = "Категория #" + ticks,
                State = CategoryState.Published
            };

            var book = new Book
            {

                Authors = authors,
                Category = category,
                Image = "",

                Title = "Test book #" + DateTime.Now.Ticks
            };

            bookService.RegisterBook(book);
            bookService.SaveChanges();

            var countOfBooksAfter = bookService.Count();
            var countOfCategoriesAfter = categoryService.Count();
            var countOfAuthorsAfter = authorService.Count();

            Assert.AreEqual(countOfBooksBefore + 1, countOfBooksAfter);
            Assert.AreEqual(countOfCategoriesBefore + 1, countOfCategoriesAfter);
            Assert.AreEqual(countOfAuthorsBefore + 2, countOfAuthorsAfter);

            Assert.IsTrue(book.Id != null);

            var savedBook = bookService.GetById(book.Id);
            Assert.IsNotNull(savedBook);
            Assert.AreEqual(book.Title, savedBook.Title);
        }