public void DetailsShouldAuthorsBooks() { var author1 = new Author() { Name = "Author1", Biography = "Biography1", PictureUrl = "myPicture1.jpg", CreatedAt = DateTime.UtcNow }; var book1 = new Book { Title = "Oliver Orphan", Author = author1.Name, AgeRange = "0~2", CreatedAt = DateTime.UtcNow }; var book2 = new Book { Title = "Oliver Orphan2", Author = author1.Name, AgeRange = "0~2", CreatedAt = DateTime.UtcNow.AddDays(-1) }; UsingSession((session) => { var repository = new Repository(session); var controller = new AuthorsController(repository); controller.Create(author1); repository.Create(book1); repository.Create(book2); }); using (var session = _documentStore.OpenSession()) { var author = WaitForTheLastWrite<Author>(session); var controller = new AuthorsController(new Repository(session)); var result = (ViewResult) controller.Details(author.Id); var authorViewModel = (AuthorViewModel) result.Model; AuthorsContollerTestHelper.AssertEqual(authorViewModel.Author, author1); var books = authorViewModel.Books; Assert.AreEqual(2, books.Count()); Assert.IsFalse(authorViewModel.HasMoreBooks); Assert.AreEqual(book1.Title, books.First().Title); Assert.AreEqual(book2.Title, books.Last().Title); } }
public void DetailsShouldHaveAuthorInfoAndListAuthorBooks() { var author = new Author() { Id = 3, Name = "Author", Biography = "Biography", PictureUrl = "Pic.jpg" }; var books = new List<Book> {new Book(), new Book(), new Book(), new Book()}; var mockedRepo = new Mock<Repository>(); mockedRepo.Setup(repo => repo.Get<Author>(3)).Returns(author); mockedRepo.Setup(r => r.Search(It.IsAny<Expression<Func<Book, bool>>>())).Returns(books); var controller = new AuthorsController(mockedRepo.Object); var result = controller.Details(3); var model = (AuthorViewModel)result.Model; AuthorsContollerTestHelper.AssertEqual(author, model.Author); Assert.AreEqual(4, model.Books.Count()); }
public void ShouldOnlyListAuthorFirst4BooksInAuthorDetailPage() { var author1 = new Author() { Name = "Author1", Biography = "Biography1", PictureUrl = "myPicture1.jpg", CreatedAt = DateTime.UtcNow }; UsingSession((session) => { var repository = new Repository(session); var controller = new AuthorsController(repository); controller.Create(author1); Enumerable.Range(1, 9) .ToList() .ForEach(i => repository.Create(new Book() { Title = "Book " + i, Author = author1.Name, CreatedAt = DateTime.UtcNow.AddDays(-i)})); }); UsingSession((session) => { var author = WaitForTheLastWrite<Author>(session); var controller = new AuthorsController(new Repository(session)); var viewResult = controller.Details(author.Id); var authorViewModel = (AuthorViewModel) (viewResult.Model); Assert.AreEqual(4, authorViewModel.Books.Count); Assert.IsTrue(authorViewModel.HasMoreBooks); }); }