コード例 #1
0
        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);
            }
        }
コード例 #2
0
        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);
                }
            }
        }
コード例 #3
0
        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));
        }
コード例 #4
0
        private async void SucheBuch(object parameter)
        {
            IList <Book> books = await BookSearchService.SucheBücherAsync(Suchbegriff);



            Books = new ObservableCollection <Book>(books);
        }
コード例 #5
0
 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());
 }
コード例 #6
0
        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));
        }
コード例 #7
0
        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));
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        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);
        }
コード例 #11
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);
        }
コード例 #12
0
        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);
        }
コード例 #13
0
        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();
                }
            });
        }
コード例 #14
0
 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));
 }