public void ToBook_AllValuesSet_CreatesBook() { var testee = new BookBuilder { Title = nameof(Book.Title), Author = nameof(Book.Author), Description = nameof(Book.Description), DatePublished = nameof(Book.DatePublished), Publisher = nameof(Book.Publisher), Language = nameof(Book.Language), Files = Array.Empty <File>(), NavigationPoints = Array.Empty <NavigationPoint>(), }; var result = testee.ToBook(); Assert.AreEqual(testee.Title, result.Title); Assert.AreEqual(testee.Author, result.Author); Assert.AreEqual(testee.Description, result.Description); Assert.AreEqual(testee.DatePublished, result.DatePublished); Assert.AreEqual(testee.Publisher, result.Publisher); Assert.AreEqual(testee.Language, result.Language); Assert.AreEqual(testee.Files, result.Files); Assert.AreEqual(testee.NavigationPoints, result.NavigationPoints); }
public async Task Setup() { var book = BookBuilder.WithLibrary(LibraryId).Build(); var chapter = ChapterBuilder.WithLibrary(LibraryId).Build(); _response = await Client.PostString($"/libraries/{-RandomData.Number}/books/{book.Id}/chapters/{chapter.Id}/contents?language={RandomData.Locale}", RandomData.String, RandomData.Locale); }
public async void Update_update_real_return_date_properly() { _context.Manipulate(_ => _.BookCategories.Add(_category)); var book = new BookBuilder() .BuildBookWithCategoryId(_category.Id) .BuildBookWithAgeRange(15) .Build(); _context.Manipulate(_ => _.Books.Add(book)); var member = MemberFactory.GenerateMember("dummy-address", 31, "dummy-name"); _context.Manipulate(_ => _.Members.Add(member)); var determinateShamsiToMiladi = new DateTime(1400, 2, 30, new PersianCalendar()); var entrust = EntrustFactory.GenerateEntrust(book.Id, member.Id, determinateShamsiToMiladi); _context.Manipulate(_ => _.Entrusts.Add(entrust)); var realShamsiToMiladiDate = new DateTime(1400, 2, 25, new PersianCalendar()); var dto = EntrustFactory.GenerateEntrustRealReturnDateDto(realShamsiToMiladiDate); var actual = await _sut.UpdateEntrustRealReturnDate(entrust.Id, dto); var expected = _readContext.Entrusts.Single(_ => _.Id == actual); expected.RealReturnDate.Should().Be(realShamsiToMiladiDate); }
public async Task Setup() { var books = BookBuilder.WithLibrary(LibraryId).Build(4); var expected = books.PickRandom(); _response = await Client.DeleteAsync($"/libraries/{LibraryId}/books/{expected.Id}"); }
public override void Display() { base.Display(); BookBuilder bb = new BookBuilder(); bb.WithTitle(StandardMessages.GetInputForParam("title")) .WithAuthorName(StandardMessages.GetInputForParam("name of the author")) .WithYear(StandardMessages.GetInputForParam("year")) .WithPages(StandardMessages.GetInputForParam("pages")) .WithCountry(StandardMessages.GetInputForParam("country")) .WithLink(StandardMessages.GetInputForParam("link")) .WithImageLink(StandardMessages.GetInputForParam("link of the image")) .WithLanguage(StandardMessages.GetInputForParam("language")); Book bk; if ((bk = bb.Create()) != null) { bk.ShowBookProp(); Catalog.Instance.AddNewBook(bk); } else { StandardMessages.TryAgain(); } StandardMessages.PressAnyKey(); StandardMessages.PressKeyToContinue(); Program.NavigateBack(); }
public void Should_Validatebook_Already_Published() { var bookPublishValidator = Resolve <IBookPublishValidator>(); var bookRepository = Resolve <IBookRepository>(); var publisher = new PublisherBuilder().Build(); var author = new AuthorBuilder() .WithPublisher(publisher) .Build(); var book = new BookBuilder() .WithPublisher(publisher) .Build(); var authorBook = new AuthorBookBuilder() .WithAuthor(author) .WithBook(book) .Build(); AddEntities(publisher, author, book, authorBook); book = bookRepository.Get(book.Id).FirstOrDefault(); Action act = () => bookPublishValidator.ValidatePublish(book, publisher); act.Should() .Throw <BusinessException>() .WithMessage($"Book ({book.Id}) is already published!"); }
[TestMethod, Ignore] // Only VS Premium and Ultimate has Fakes public void TestWithShivCompleteDependantRepository() { var author = new AuthorBuilder().CliveCustler().Build(); var request = new BookBuilder().DeepSix().BuildRequest(); Book response; using (ShimsContext.Create()) { // Create SHIV var stubAuthRepo = new Contracts.Fakes.StubIAuthorRepository { // Method = (parameters) => { method } GetAuthorByIdGuid = id => author }; // SHIM the property that retrieves the repository ShimBookRepository.AllInstances.AuthorRepoGet = _ => stubAuthRepo; var repo = new BookRepository(); response = repo.AddBook(request); } Assert.IsNotNull(response); Assert.AreEqual(author, response.Author); }
public void Setup() { _user = new User(); _returnedKindle = new lib.Kindle(); _bookOne = new BookBuilder().WithAuthor("author1").WithTitle("title"); _bookTwo = new BookBuilder().WithAuthor("author2").WithTitle("title2"); }
public void CalculateExactAvg() { var review1 = new Review() { Rating = 5 }; var review2 = new Review() { Rating = 5 }; var review3 = new Review() { Rating = 5 }; var reviews = new[] { review1, review2, review3 }; var book = new BookBuilder() .WithDefalutValues() .WithReviews(reviews) .Build(); var result = book.GetAvgRating(); Assert.NotNull(result); Assert.Equal(5, result.Value); }
public Book FindById(Guid id) { var bookEntity = _dbContext.Books.Include(b => b.Author).FirstOrDefault(b => b.Id == id); if (bookEntity == null) { return(null); } var authorEntity = bookEntity.Author; var author = AuthorBuilder.CreateNew() .WithId(authorEntity.Id) .WithFirstName(authorEntity.FirstName) .WithLastName(authorEntity.LastName) .Build(); return(BookBuilder.CreateNew() .WithId(bookEntity.Id) .WithTitle(bookEntity.Title) .WithIsbn13(bookEntity.Isbn) .WithReleaseDate(bookEntity.ReleaseDate) .WithPublisher(bookEntity.Publisher) .WithAuthor(author) .Build()); }
public void ICanBuildABookWithAllFields() { IBookInfo bookInfo = BookBuilder.GetInstance() .WithTitle("my book title") .WithSubTitle("my book subtitle") .WithAuthors("author 1", "author 2", "author 3") .WithDescription("my book description") .WithCover("my book cover") .Build(); Assert.IsNotNull(bookInfo); Assert.AreEqual("my book title", bookInfo.Title); Assert.AreEqual("my book subtitle", bookInfo.SubTitle); Assert.AreEqual("my book description", bookInfo.Description); Assert.AreEqual("my book cover", bookInfo.Cover); Assert.AreEqual(3, bookInfo.Authors.Count()); string author1 = bookInfo.Authors.ElementAt(0); string author2 = bookInfo.Authors.ElementAt(1); string author3 = bookInfo.Authors.ElementAt(2); Assert.AreEqual("author 1", author1); Assert.AreEqual("author 2", author2); Assert.AreEqual("author 3", author3); }
public static BookBuilder CreateBook(string title) { var builder = new BookBuilder(); builder.Title = title; return(builder); }
public void BuildBookWithDifferentReleaseDate() { var normalBook = new BookBuilder().FiveDysfunctions().Build(); var updatedBook = new BookBuilder().FiveDysfunctions().UpdateReleaseDate(DateTime.Now).Build(); Assert.AreNotEqual(normalBook.ReleaseDate, updatedBook.ReleaseDate); }
public void BasicBuilderTests() { var builder = new BookBuilder().CrucialCOnversations(); var sampleBook = builder.Build(); Assert.AreEqual(builder.Title, sampleBook.Title); }
public void Should_Validate_publisher_Different_From_Authors() { var bookPublishValidator = Resolve <IBookPublishValidator>(); var bookRepository = Resolve <IBookRepository>(); var publisher = new PublisherBuilder().Build(); var anotherPublisher = new PublisherBuilder().Build(); var author = new AuthorBuilder() .WithPublisher(publisher) .Build(); var book = new BookBuilder() .Build(); var authorBook = new AuthorBookBuilder().WithAuthor(author).WithBook(book).Build(); AddEntities(publisher, anotherPublisher, author, book, authorBook); book = bookRepository.Get(book.Id).FirstOrDefault(); Action act = () => bookPublishValidator.ValidatePublish(book, anotherPublisher); act.Should() .Throw <BusinessException>() .WithMessage($"{Environment.NewLine}The publisher of publication's book must be from one of the authors!"); }
public async Task UpdateBook_ValidBook_UpdatesBook() { // Arrange var book = new BookBuilder().WithId(1).Build(); var data = new List <Book> { book }; var dbset = GenerateEnumerableDbSetMock(data.AsQueryable()); var context = GenerateEnumerableContextMock(dbset); var booksService = new BooksService(context.Object); var updatedBook = new BookBuilder() .WithId(book.Id) .WithTitle("aa") .WithReadingEnd(DateTime.Today) .WithReadingStart(DateTime.Today) .WithYear(2000) .Build(); // Act await booksService.UpdateBook(updatedBook); // Assert book.Should().BeEquivalentTo(updatedBook); }
public void Should_Validate_Publish_With_Excedent_Authors() { var bookPublishValidator = Resolve <IBookPublishValidator>(); var bookRepository = Resolve <IBookRepository>(); var publisher = new PublisherBuilder().Build(); var authorBuilder = new AuthorBuilder().WithPublisher(publisher); var author = authorBuilder.Build(); var author2 = authorBuilder.Build(); var author3 = authorBuilder.Build(); var author4 = authorBuilder.Build(); var book = new BookBuilder().Build(); var authorBookBuilder = new AuthorBookBuilder().WithBook(book); var authorBook = authorBookBuilder.WithAuthor(author).Build(); var authorBook2 = authorBookBuilder.WithAuthor(author2).Build(); var authorBook3 = authorBookBuilder.WithAuthor(author3).Build(); var authorBook4 = authorBookBuilder.WithAuthor(author4).Build(); var authorsBook = new List <AuthorBookEntity> { authorBook, authorBook2, authorBook3, authorBook4 }; AddEntities(publisher, author, author2, author3, author4, book, authorBook, authorBook2, authorBook3, authorBook4); book = bookRepository.Get(book.Id).FirstOrDefault(); Action act = () => bookPublishValidator.ValidatePublish(book, publisher); act.Should() .Throw <BusinessException>() .WithMessage($"Book can't have more than 3 authors!"); }
public void Should_Validatebook_Already_Published() { var bookBll = Resolve <IBookBll>(); var bookRepository = Resolve <IBookRepository>(); var publisher = new PublisherBuilder().Build(); var author = new AuthorBuilder() .WithPublisher(publisher) .Build(); var book = new BookBuilder() .WithPublisher(publisher) .Build(); var authorBook = new AuthorBookBuilder() .WithAuthor(author) .WithBook(book) .Build(); AddEntities(publisher, author, book, authorBook); Action act = () => bookBll.PublishBook(book.Id, new PublishBookRequestDTO { PublishierId = publisher.Id }); act.Should() .Throw <BusinessException>() .WithMessage($"Book ({book.Id}) is already published!"); }
public void Should_Validate_Author_Without_Publisher() { var bookPublishValidator = Resolve <IBookPublishValidator>(); var bookRepository = Resolve <IBookRepository>(); var publisher = new PublisherBuilder().Build(); var author = new AuthorBuilder() .Build(); var book = new BookBuilder() .Build(); var authorBook = new AuthorBookBuilder().WithAuthor(author).WithBook(book).Build(); AddEntities(publisher, author, book, authorBook); book = bookRepository.Get(book.Id).FirstOrDefault(); Action act = () => bookPublishValidator.ValidatePublish(book, publisher); act.Should() .Throw <BusinessException>() .WithMessage($"The following authors do not have publishers on his register:{Environment.NewLine}{author.FirstName}" + $"{Environment.NewLine}The publisher of publication's book must be from one of the authors!"); }
public void Should_Validate_Publisher_Different_From_Authors() { var bookBll = Resolve <IBookBll>(); var bookRepository = Resolve <IBookRepository>(); var publisher = new PublisherBuilder().Build(); var anotherPublisher = new PublisherBuilder().Build(); var author = new AuthorBuilder() .WithPublisher(publisher) .Build(); var book = new BookBuilder() .Build(); var authorBook = new AuthorBookBuilder().WithAuthor(author).WithBook(book).Build(); AddEntities(publisher, anotherPublisher, author, book, authorBook); Action act = () => bookBll.PublishBook(book.Id, new PublishBookRequestDTO { PublishierId = anotherPublisher.Id }); act.Should() .Throw <BusinessException>() .WithMessage($"{Environment.NewLine}The publisher of publication's book must be from one of the authors!"); }
public async Task Setup() { BookBuilder.WithLibrary(LibraryId).IsPublic().AddToFavorites(AccountId).Build(25); _response = await Client.GetAsync($"/libraries/{LibraryId}/books?pageNumber=2&pageSize=10&favorite=true"); _assert = new PagingAssert <BookView>(_response); }
public void Should_Validate_Publish_With_Excedent_Authors() { var bookBll = Resolve <IBookBll>(); var bookRepository = Resolve <IBookRepository>(); var publisher = new PublisherBuilder().Build(); var authorBuilder = new AuthorBuilder().WithPublisher(publisher); var author = authorBuilder.Build(); var author2 = authorBuilder.Build(); var author3 = authorBuilder.Build(); var author4 = authorBuilder.Build(); var book = new BookBuilder().Build(); var authorBookBuilder = new AuthorBookBuilder().WithBook(book); var authorBook = authorBookBuilder.WithAuthor(author).Build(); var authorBook2 = authorBookBuilder.WithAuthor(author2).Build(); var authorBook3 = authorBookBuilder.WithAuthor(author3).Build(); var authorBook4 = authorBookBuilder.WithAuthor(author4).Build(); var authorsBook = new List <AuthorBookEntity> { authorBook, authorBook2, authorBook3, authorBook4 }; AddEntities(publisher, author, author2, author3, author4, book, authorBook, authorBook2, authorBook3, authorBook4); Action act = () => bookBll.PublishBook(book.Id, new PublishBookRequestDTO { PublishierId = publisher.Id }); act.Should() .Throw <BusinessException>() .WithMessage($"Book can't have more than 3 authors!"); }
public async void Get_get_books_by_categoryid() { List <Book> books = new List <Book>(); var bookCategory = BookCategoryFactory.GenerateBookCategory(); _context.Manipulate(_ => _.BookCategories.Add(bookCategory)); var firstBook = new BookBuilder() .BuildBookWithName("first-book") .BuildBookWithCategoryId(bookCategory.Id) .Build(); var secondBook = new BookBuilder() .BuildBookWithName("second-book") .BuildBookWithCategoryId(bookCategory.Id) .Build();; books.Add(firstBook); books.Add(secondBook); _context.Manipulate(_ => _.Books.AddRange(books)); var expected = await _sut.GetBooksByCategoryId(bookCategory.Id); expected.Should().HaveCount(2); expected.Select(_ => _.Name).Should().Contain("first-book"); expected.Select(_ => _.Name).Should().Contain("second-book"); }
public async Task Setup() { var _book = BookBuilder.WithLibrary(LibraryId).WithContents(5).Build(); var _expected = BookBuilder.Contents.PickRandom(); _response = await Client.GetAsync($"/libraries/{LibraryId}/books/{_book.Id}/content", _expected.Language, _expected.MimeType + "2"); }
public void Setup() { _user = new User(); _returnedKindle = new lib.Kindle(); _bookOne = new BookBuilder().WithAuthor("author1").WithTitle("title"); _bookTwo = new BookBuilder().WithAuthor("author2").WithTitle("title2"); }
public void AdjustNavigationPoints_FuncThatAddsPrefixToNavigationPoints_AdjustsNavigationPointsRecursive() { var testee = new BookBuilder(); testee.NavigationPoints = new[] { new NavigationPoint("One", null, null, 0, new [] { new NavigationPoint("One Two", null, null, 0, new NavigationPoint[0]), }), new NavigationPoint("Two", null, null, 0, new NavigationPoint[0]), }; testee.AdjustNavigationPoints(point => new NavigationPoint( "Chapter: " + point.Title, point.File, point.ElementId, point.Order, point.Children)); var resultChapterOne = testee.NavigationPoints.First(); var resultChapterOneTwo = testee.NavigationPoints.First().Children.First(); var resultChapterTwo = testee.NavigationPoints.Skip(1).First(); Assert.AreEqual("Chapter: One", resultChapterOne.Title); Assert.AreEqual("Chapter: One Two", resultChapterOneTwo.Title); Assert.AreEqual("Chapter: Two", resultChapterTwo.Title); }
public async Task Setup() { var book = BookBuilder.WithLibrary(LibraryId).WithContents(5).IsPublic(false).Build(); var expected = BookBuilder.Contents.PickRandom(); _response = await Client.GetAsync($"/libraries/{LibraryId}/books/{expected.BookId}/contents", expected.Language, expected.MimeType); }
public async Task Setup() { var book = BookBuilder.WithLibrary(LibraryId).WithPages(3, true).Build(); _page = BookBuilder.GetPages(book.Id).PickRandom(); _bookId = book.Id; _response = await Client.DeleteAsync($"/libraries/{LibraryId}/books/{_bookId}/pages/{_page.SequenceNumber}/image"); }
public async Task Setup() { BookBuilder.WithLibrary(LibraryId).IsPublic().Build(30); _response = await Client.GetAsync($"/libraries/{LibraryId}/books?pageNumber=2&pageSize=10"); _assert = new PagingAssert <BookView>(_response); }
public async Task Setup() { _book = BookBuilder.WithLibrary(LibraryId).Build(); _response = await Client.GetAsync($"/libraries/{LibraryId}/books/{_book.Id}/chapters"); _view = _response.GetContent <ListView <ChapterView> >().Result; }
public async Task Setup() { var book = BookBuilder.WithLibrary(LibraryId).WithPages(3).Build(); _page = BookBuilder.GetPages(book.Id).PickRandom(); _bookId = book.Id; _response = await Client.PutFile($"/libraries/{LibraryId}/books/{_bookId}/pages/{_page.SequenceNumber}/image", RandomData.Bytes); }