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); } } }
public HomeController(WordInSentencesService wordInSentencesService, ReCaptchaService recaptchaService, BookSearchService bookSearchService, APIService apiService) { _wordInSentencesService = wordInSentencesService ?? throw new ArgumentNullException(nameof(wordInSentencesService)); _recaptchaService = recaptchaService ?? throw new ArgumentNullException(nameof(recaptchaService)); _bookSearchService = bookSearchService ?? throw new ArgumentNullException(nameof(bookSearchService)); _apiService = apiService ?? throw new ArgumentNullException(nameof(apiService)); }
private async void SucheBuch(object parameter) { IList <Book> books = await BookSearchService.SucheBücherAsync(Suchbegriff); Books = new ObservableCollection <Book>(books); }
private SearchResult CheckForCahedBookSearchResult() { if (Session["searchString"] != null) { var searchString = Session["searchString"].ToString(); var searchResult = new SearchResult(); if (!string.IsNullOrEmpty(searchString)) { searchResult = BookSearchService.SearchForBooks(searchString); return(searchResult); } } return(new SearchResult()); }
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 ActionResult BookSearch(string searchString) { SearchResult searchResult = new SearchResult(); if (!string.IsNullOrEmpty(searchString)) { searchResult = BookSearchService.SearchForBooks(searchString); Session["searchString"] = searchString; } var model = new BookSearchViewModel() { SearchResult = searchResult }; return(View("BookSearch", model)); }
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 async Task SearchBookTest() { var testMetadata = Substitute.For <IMetadata>(); testMetadata.Author.Returns("George R. R. Martin"); testMetadata.Title.Returns("A Feast for Crows"); var bookSearchService = new BookSearchService(); var results = await bookSearchService.SearchSecondarySourceAsync(_goodreads, testMetadata, CancellationToken.None); Assert.GreaterOrEqual(results.Length, 1); var first = results.First(); Assert.AreEqual(first.Author, "George R.R. Martin"); Assert.AreEqual("13497", first.GoodreadsId); Assert.False(string.IsNullOrEmpty(first.ImageUrl)); Assert.AreEqual("A Feast for Crows (A Song of Ice and Fire, #4)", first.Title); Assert.Greater(first.Editions, 0); }
public void TestSetUp() { _currencyConvertClientMock = new Mock <ICurrencyConvertClient>(); _mapper = new Mapper(new MapperConfiguration(e => e.AddProfile <EngineProfile>())); _firstBookDataProviderMock = new Mock <IBookDataProvider>(); _secondBookDataProviderMock = new Mock <IBookDataProvider>(); _firstBookDataProviderMock.SetupGet(x => x.Name).Returns("firstProvider"); _secondBookDataProviderMock.SetupGet(x => x.Name).Returns("secondProvider"); var bookDataProviders = new[] { _firstBookDataProviderMock.Object, _secondBookDataProviderMock.Object }; _target = new BookSearchService(bookDataProviders, null, _mapper, _currencyConvertClientMock.Object); }
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 MainWindowViewModel() { SuchCommand = new DelegateCommand(async p => { Buchergebnisse = (await BookSearchService.Suche(Suchbegriff)).ToArray(); }, p => !string.IsNullOrWhiteSpace(Suchbegriff)); FavoritenCommand = new DelegateCommand(p => { Header = "Favoriten"; Buchergebnisse = FavoritenManager.Favoriten.ToArray(); }, p => FavoritenManager.Favoriten.Count > 0); AddFavoriteCommand = new DelegateCommand(p => { if (p is Book book) { FavoritenManager.Favoriten.Add(book); FavoritenCommand.OnCanExecuteChanged(); } }); }
public SpeakController(ILogger <SpeakController> logger, WordInSentencesService wordInSentencesService, BookSearchService bookSearchService) { _logger = logger; _wordInSentencesService = wordInSentencesService ?? throw new ArgumentNullException(nameof(wordInSentencesService)); _bookSearchService = bookSearchService ?? throw new ArgumentNullException(nameof(bookSearchService)); }