public bool Run(StreamWriter sw) { try { GoogleBooksConnectionManager.SearchVolumes("Any Title", "Any Author", "Any Publisher", null); } catch { sw.WriteLine("GoogleBooksTestConnection failed: No response from API."); return(false); } return(true); }
/// <summary> /// Tests the SearchVolumes method using all empty parameters. Returns true if an ArgumentNullException occurs. /// </summary> private bool SearchVolumesEmptyParams(StreamWriter sw) { try { GoogleBooksConnectionManager.SearchVolumes("", "", "", null); } catch (ArgumentNullException e) { return(true); } catch { sw.WriteLine("GoogleBooksTestSearchVolumes - SearchVolumesEmptyParams failed: Unexpected exception."); } sw.WriteLine("GoogleBooksTestSearchVolumes - SearchVolumesEmptyParams failed: Expected an ArgumentNullException."); return(false); }
/// <summary> /// Tests the SearchVolumes method using the Title as the parameter. Returns true if any result is returned. /// </summary> private bool SearchVolumesTitle(StreamWriter sw) { try { List <BookSearchResultsModel> results = GoogleBooksConnectionManager.SearchVolumes("Harry Potter", null, null, null); if (results.Count <= 0) { sw.WriteLine("GoogleBooksTestSearchVolumes - SearchVolumesTitle failed: No results."); return(false); } } catch { sw.WriteLine("GoogleBooksTestSearchVolumes - SearchVolumesTitle failed: Unexpected exception."); return(false); } return(true); }
/// <summary> /// Tests the SearchVolumes method using all of the parameters. /// Returns true if any result is returned. /// </summary> private bool SearchVolumesAll(StreamWriter sw) { try { List <BookSearchResultsModel> results = GoogleBooksConnectionManager.SearchVolumes("Harry Potter", "J.K. Rowling", "Pottermore Publishing", "9781781100226"); if (results.Count <= 0) { sw.WriteLine("GoogleBooksTestSearchVolumes - SearchVolumesAll failed: No results."); return(false); } } catch { sw.WriteLine("GoogleBooksTestSearchVolumes - SearchVolumesAll failed: Unexpected exception."); return(false); } return(true); }
/// <summary> /// Tests the SearchVolumes method using the Isbn as a parameter. Returns true if any result is returned. /// </summary> private bool SearchVolumesIsbn(StreamWriter sw) { try { List <BookSearchResultsModel> results = GoogleBooksConnectionManager.SearchVolumes(null, null, null, "9781781100226"); if (results.Count <= 0) { sw.WriteLine("GoogleBooksTestSearchVolumes - SearchVolumesIsbn failed: No results."); return(false); } } catch (ArgumentException e) { sw.WriteLine("GoogleBooksTestSearchVolumes - SearchVolumesIsbn failed: ISBN invalid."); } catch { sw.WriteLine("GoogleBooksTestSearchVolumes - SearchVolumesIsbn failed: Unexpected exception."); return(false); } return(true); }
protected void SearchForBook(object sender, EventArgs e) { // // Determine what parameters we are using to search: ISBN or Title/Author/Publisher // string searchKey = ((WebControl)sender).ID == "btnISBNPostback" ? "ISBN" : "details"; // // Search Google Books with the provided parameters // List <BookSearchResultsModel> searchResults; try { searchResults = searchKey == "ISBN" ? GoogleBooksConnectionManager.SearchVolumes("", "", "", IsbnBox.Text) : GoogleBooksConnectionManager.SearchVolumes(HttpUtility.UrlDecode(HiddenTitleEntry.Value), HttpUtility.UrlDecode(HiddenAuthorEntry.Value), HttpUtility.UrlDecode(HiddenPublisherEntry.Value), null); } catch (ArgumentNullException ex) { return; } // // Convert the search results to HTML table rows // List <TableRow> resultRows = new List <TableRow>(); int idnum = 0; foreach (BookSearchResultsModel volume in searchResults) { TableRow volumeRow = new TableRow(); volumeRow.CssClass = "search_result"; volumeRow.ID = searchKey == "ISBN" ? "ResultRowISBN" + idnum++ : "ResultRowDetails" + idnum++; volumeRow.Attributes["onclick"] = "rowClicked(this)"; TableCell titleCell = new TableCell(); HtmlGenericControl innerDiv = new HtmlGenericControl("div"); innerDiv.ID = volumeRow.ID + "_Title"; innerDiv.InnerHtml = volume.Title; titleCell.Controls.Add(innerDiv); volumeRow.Controls.Add(titleCell); TableCell authorCell = new TableCell(); innerDiv = new HtmlGenericControl("div"); innerDiv.ID = volumeRow.ID + "_Authors"; innerDiv.InnerHtml = volume.Authors; authorCell.Controls.Add(innerDiv); volumeRow.Controls.Add(authorCell); TableCell publisherCell = new TableCell(); innerDiv = new HtmlGenericControl("div"); innerDiv.ID = volumeRow.ID + "_Publisher"; innerDiv.InnerHtml = volume.Publisher; publisherCell.Controls.Add(innerDiv); volumeRow.Controls.Add(publisherCell); TableCell pubDateCell = new TableCell(); innerDiv = new HtmlGenericControl("div"); innerDiv.ID = volumeRow.ID + "_PublishDate"; innerDiv.InnerHtml = volume.PublishDate; pubDateCell.Controls.Add(innerDiv); volumeRow.Controls.Add(pubDateCell); TableCell isbnCell = new TableCell(); innerDiv = new HtmlGenericControl("div"); innerDiv.ID = volumeRow.ID + "_ISBN"; innerDiv.InnerHtml = volume.ISBN; isbnCell.Controls.Add(innerDiv); volumeRow.Controls.Add(isbnCell); TableCell coverUrlCell = new TableCell(); innerDiv = new HtmlGenericControl("div"); innerDiv.ID = volumeRow.ID + "_CoverUrl"; innerDiv.InnerHtml = volume.CoverURL; coverUrlCell.Controls.Add(innerDiv); coverUrlCell.Style.Add("display", "none"); volumeRow.Controls.Add(coverUrlCell); resultRows.Add(volumeRow); } // // Insert search results into the relevant table // WebControl resultsTable = searchKey == "ISBN" ? SearchGridISBN : SearchGridDetails; foreach (TableRow volume in resultRows) { resultsTable.Controls.Add(volume); } }