private void AddIsbnButton_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrWhiteSpace(isbnTextBox.Text)) { string errorMessage = String.Format("Nenašla se knížka. Zkuste znovu zadat ISBN.", isbnTextBox.Text); MessageBox.Show(errorMessage, "Knížka nenalezena", MessageBoxButton.OK, MessageBoxImage.Warning); return; } try { BookSearchService bookSearchService = new BookSearchService(new GoogleApiIsbnSearchInvoker()); string jsonBookInfo = bookSearchService.GetBookInfo(isbnTextBox.Text); if (jsonBookInfo == null) { string errorMessage = String.Format("Nenašla se knížka polde ISBN: '{0}'. Zkuste znovu zadat ISBN.", isbnTextBox.Text); MessageBox.Show(errorMessage, "Knížka nenalezena", MessageBoxButton.OK, MessageBoxImage.Warning); } else { JavaScriptSerializer jsSerializer = new JavaScriptSerializer(); IBookInfo bookInfo = jsSerializer.Deserialize <BookInfo>(jsonBookInfo); titleTextBox.Text = bookInfo.Title; authorTextBox.Text = String.Join(", ", bookInfo.Authors); noteTextBox.Text = bookInfo.Description; } } catch { string errorMessage = String.Format("Nelze se připojit k serveru. Zkontrolujte připojení k internetu"); MessageBox.Show(errorMessage, "Knížka nenalezena", MessageBoxButton.OK, MessageBoxImage.Warning); } }
private void searchIsbnButton_Click(object sender, EventArgs e) { BookSearchService bookSearchService = new BookSearchService(new GoogleApiIsbnSearchInvoker()); string jsonBookInfo = bookSearchService.GetBookInfo(textBoxIsbn.Text); if (jsonBookInfo == null) { string errorMessage = String.Format("No book found with ISBN '{0}'. Please try another ISBN.", textBoxIsbn.Text); MessageBox.Show(errorMessage); } else { JavaScriptSerializer jsSerializer = new JavaScriptSerializer(); IBookInfo bookInfo = jsSerializer.Deserialize <BookInfo>(jsonBookInfo); labelTitle.Text = bookInfo.Title; labelSubTitle.Text = bookInfo.SubTitle; labelDescription.Text = bookInfo.Description; labelAuthors.Text = String.Join(", ", bookInfo.Authors); if (!string.IsNullOrWhiteSpace(bookInfo.Cover)) { pictureBoxCover.LoadAsync(bookInfo.Cover); } } }
private void downloadClicked(object sender, RoutedEventArgs e) { IBookInfo be = (IBookInfo)sender; downloadTaskList.StartNewTask(be.book); ShowMessage("已添加到下载列表"); }
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 BookInfoSnapshot(IBookInfo bookInfo) { BookId = bookInfo.BookId; Book = bookInfo.Book; Owner = bookInfo.Owner; Status = bookInfo.Status; Queue = bookInfo.ShowQueue(); }
public void ICanBuildAnEmptyBook() { IBookInfo bookInfo = BookBuilder.GetInstance().Build(); Assert.IsNotNull(bookInfo); Assert.IsNull(bookInfo.Title); Assert.IsNull(bookInfo.SubTitle); Assert.IsNull(bookInfo.Authors); Assert.IsNull(bookInfo.Description); Assert.IsNull(bookInfo.Cover); }
public void DeserializeJsonResponseAndReturnNullWhenNotFound() { string jsonBookFixture = "google-api-not-found.json"; CopyResource(jsonBookFixture); String jsonBookNotFoundContent = File.ReadAllText(jsonBookFixture); JavaScriptSerializer jsSerializer = new JavaScriptSerializer(); GoogleApiBookWrapper googleApiBookWrapper = jsSerializer.Deserialize <GoogleApiBookWrapper>(jsonBookNotFoundContent); IBookInfo bookInfo = googleApiBookWrapper.GetBookInfo; Assert.IsNull(bookInfo); }
public string GetBookInfo(string isbn) { isbn = isbn.Replace("-", String.Empty); IBookInfo bookInfo = _isbnSearchInvoker.GetBookInfo(isbn); if (bookInfo == null) { return(null); } JavaScriptSerializer jsSerializer = new JavaScriptSerializer(); return(jsSerializer.Serialize(bookInfo)); }
public void ICanCallGoogleApiWithIsbnContainingHyphens() { IsbnSearchInvoker googleApiIsbnSearchInvoker = new GoogleApiIsbnSearchInvoker(); BookSearchService bookSearchService = new BookSearchService(googleApiIsbnSearchInvoker); string jsonBookInfo = bookSearchService.GetBookInfo(PragmaticProgrammerIsbnWithHyphens); JavaScriptSerializer jsSerializer = new JavaScriptSerializer(); IBookInfo bookInfo = jsSerializer.Deserialize <BookInfo>(jsonBookInfo); Assert.AreEqual("The Pragmatic Programmer", bookInfo.Title); Assert.AreEqual(2, bookInfo.Authors.Count()); Assert.AreEqual("Andrew Hunt", bookInfo.Authors.ElementAt(0)); Assert.AreEqual("David Thomas", bookInfo.Authors.ElementAt(1)); }
public void ReturnsNullWhenIsbnIsNotFound() { IBookInfo bookInfo = null; MockFactory mockFactory = new MockFactory(); Mock <IsbnSearchInvoker> isbnSearchInvokerMocked = mockFactory.CreateMock <IsbnSearchInvoker>(); isbnSearchInvokerMocked.Expects.One.Method(invoker => invoker.GetBookInfo(null)) .With(WrongIsbn) .WillReturn(bookInfo); BookSearchService bookSearchService = new BookSearchService(isbnSearchInvokerMocked.MockObject); string jsonBookInfo = bookSearchService.GetBookInfo(WrongIsbn); Assert.IsNull(jsonBookInfo); }
public void ICanCallGoogleApiToSearchForABookWithIsbn() { IsbnSearchInvoker googleApiIsbnSearchInvoker = new GoogleApiIsbnSearchInvoker(); BookSearchService bookSearchService = new BookSearchService(googleApiIsbnSearchInvoker); string jsonBookInfo = bookSearchService.GetBookInfo(ImpactMappingIsbn); JavaScriptSerializer jsSerializer = new JavaScriptSerializer(); IBookInfo bookInfo = jsSerializer.Deserialize <BookInfo>(jsonBookInfo); Assert.AreEqual("Impact Mapping", bookInfo.Title); Assert.AreEqual("Making a Big Impact with Software Products and Projects", bookInfo.SubTitle); Assert.AreEqual(1, bookInfo.Authors.Count()); Assert.AreEqual("Gojko Adzic", bookInfo.Authors.ElementAt(0)); StringAssert.Contains(bookInfo.Description, "A practical guide to impact mapping, a simple yet incredibly effective method for"); Assert.AreEqual("http://books.google.com/books/content?id=6tNoMwEACAAJ&printsec=frontcover&img=1&zoom=1&source=gbs_api", bookInfo.Cover); }
public void DeserializeJsonResponseAndBuildBookInfo() { string jsonBookFixture = "google-api-impact-mapping.json"; CopyResource(jsonBookFixture); String jsonBookContent = File.ReadAllText(jsonBookFixture); JavaScriptSerializer jsSerializer = new JavaScriptSerializer(); GoogleApiBookWrapper googleApiBookWrapper = jsSerializer.Deserialize <GoogleApiBookWrapper>(jsonBookContent); IBookInfo bookInfo = googleApiBookWrapper.GetBookInfo; Assert.AreEqual("Impact Mapping", bookInfo.Title); Assert.AreEqual("Making a Big Impact with Software Products and Projects", bookInfo.SubTitle); Assert.AreEqual(1, bookInfo.Authors.Count()); Assert.AreEqual("Gojko Adzic", bookInfo.Authors.ElementAt(0)); StringAssert.Contains(bookInfo.Description, "A practical guide to impact mapping, a simple yet incredibly effective method for"); Assert.AreEqual("http://books.google.com/books/content?id=6tNoMwEACAAJ&printsec=frontcover&img=1&zoom=1&source=gbs_api", bookInfo.Cover); }
public void ReturnsJsonResponseWithBookInfoWhenIsbnIsGood() { string bookTitle = "Impact mapping"; string bookSubTitle = "Making a big impact with software products and projects"; string bookAuthor = "Gojko Adzik"; string bookDescription = "long description for Impact mapping book"; string bookCover = "http://books.google.com/books/content?id=6tNoMwEACAAJ&printsec=frontcover&img=1&zoom=1&source=gbs_api"; IBookInfo impactMappingBookInfo = BookBuilder.GetInstance() .WithTitle(bookTitle) .WithSubTitle(bookSubTitle) .WithAuthors(bookAuthor) .WithDescription(bookDescription) .WithCover(bookCover) .Build(); MockFactory mockFactory = new MockFactory(); Mock <IsbnSearchInvoker> isbnSearchInvokerMocked = mockFactory.CreateMock <IsbnSearchInvoker>(); isbnSearchInvokerMocked.Expects.One.Method(invoker => invoker.GetBookInfo(null)) .With(GoodIsbn) .WillReturn(impactMappingBookInfo); BookSearchService bookSearchService = new BookSearchService(isbnSearchInvokerMocked.MockObject); string jsonBookInfo = bookSearchService.GetBookInfo(GoodIsbn); JavaScriptSerializer jsSerializer = new JavaScriptSerializer(); IBookInfo bookInfo = jsSerializer.Deserialize <BookInfo>(jsonBookInfo); Assert.AreEqual(bookTitle, bookInfo.Title); Assert.AreEqual(bookSubTitle, bookInfo.SubTitle); Assert.AreEqual(1, bookInfo.Authors.Count()); Assert.AreEqual(bookAuthor, bookInfo.Authors.ElementAt(0)); Assert.AreEqual(bookDescription, bookInfo.Description); Assert.AreEqual(bookCover, bookInfo.Cover); }
public BookPostingPageModel(IConfiguration config, IBookInfo bookInfo) { this.config = config; this.bookInfo = bookInfo; }
public static BookBuilder GetInstance() { _bookInfo = new BookInfo(); return(new BookBuilder()); }