Example #1
0
        public void Create_new_author_and_assign_to_book()
        {
            var ticks = DateTime.Now.Ticks;

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

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

            var book = bookService.GetList(0, 1).SingleOrDefault();
            Assert.IsNotNull(book);
            Assert.IsNotNull(book.Category);
            Assert.IsNotNull(book.Authors);

            var author = new Author { Name = "Автор #" + ticks };

            authorService.RegisterAuthor(author);
            authorService.SaveChanges();

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

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

            book.Authors.Add(author);
            bookService.SaveChanges();

            var countOfBooksAfter2 = bookService.Count();
            var countOfAuthorsAfter2 = authorService.Count();

            Assert.AreEqual(countOfBooksAfter, countOfBooksAfter2);
            Assert.AreEqual(countOfAuthorsAfter, countOfAuthorsAfter2);

            var savedBook = bookService.GetById(book.Id);
            Assert.IsNotNull(savedBook);
            Assert.IsNotNull(savedBook.Authors);
            Assert.IsNotNull(savedBook.Category);

            Assert.AreEqual(savedBook.Authors.Count, book.Authors.Count);
            Assert.IsTrue(savedBook.Authors.Select(a => a.Id).ToList().Contains(author.Id));
        }
Example #2
0
        public void Create_new_author()
        {
            var ticks = DateTime.Now.Ticks;

            var authorService = _ninjectKernel.Get<IAuthorService>();

            var countOfAuthorsBefore = authorService.Count();

            var author = new Author {Name = "Автор #" + ticks};

            authorService.RegisterAuthor(author);
            authorService.SaveChanges();

            var countOfAuthorsAfter = authorService.Count();

            Assert.IsTrue(author.Id != null);
            Assert.AreEqual(countOfAuthorsBefore + 1, countOfAuthorsAfter);

            var savedAuthor = authorService.GetById(author.Id);
            Assert.IsNotNull(savedAuthor);
            Assert.AreEqual(author.Name, savedAuthor.Name);
            Assert.IsNull(savedAuthor.Books);
        }