public void Create_new_category_and_assign_to_book() { var ticks = DateTime.Now.Ticks; var bookService = _ninjectKernel.Get<IBookService>(); var categoryService = _ninjectKernel.Get<ICategoryService>(); var countOfBooksBefore = bookService.Count(); var countOfCategoriesBefore = categoryService.Count(); var book = bookService.GetList(0, 1).SingleOrDefault(); Assert.IsNotNull(book); Assert.IsNotNull(book.Category); Assert.IsNotNull(book.Authors); var category = new Category { Name = "Категория #" + ticks, State = CategoryState.Published }; categoryService.RegisterCategory(category); categoryService.SaveChanges(); var countOfBooksAfter = bookService.Count(); var countOfCategoriesAfter = categoryService.Count(); Assert.AreEqual(countOfBooksBefore, countOfBooksAfter); Assert.AreEqual(countOfCategoriesBefore + 1, countOfCategoriesAfter); book.Category = category; bookService.SaveChanges(); var countOfBooksAfter2 = bookService.Count(); var countOfCategoriesAfter2 = categoryService.Count(); Assert.AreEqual(countOfBooksAfter, countOfBooksAfter2); Assert.AreEqual(countOfCategoriesAfter, countOfCategoriesAfter2); var savedBook = bookService.GetById(book.Id); Assert.IsNotNull(savedBook); Assert.IsNotNull(savedBook.Authors); Assert.IsNotNull(savedBook.Category); Assert.AreEqual(savedBook.Category.Id, book.Category.Id); }
public void Create_new_category() { var ticks = DateTime.Now.Ticks; var categoryService = _ninjectKernel.Get<ICategoryService>(); var countOfCategoriesBefore = categoryService.Count(); var category = new Category {Name = "Категория #" + ticks, State = CategoryState.Published}; categoryService.RegisterCategory(category); categoryService.SaveChanges(); var countOfCategoriesAfter = categoryService.Count(); Assert.IsTrue(category.Id !=null); Assert.AreEqual(countOfCategoriesBefore + 1, countOfCategoriesAfter); var savedCategory = categoryService.GetById(category.Id); Assert.IsNotNull(savedCategory); Assert.AreEqual(category.Name, savedCategory.Name); Assert.AreEqual(category.State, savedCategory.State); Assert.IsNull(savedCategory.Books); }
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); }