Example #1
0
        // GET: api/Search
        public async Task <IEnumerable <Book> > GetBooks(string search) //GeneralSearch not implemented yet. To be added later.
        {
            GoogleBookSearch getBooksSearch = new GoogleBookSearch();
            // return getBooksSearch.GeneralSearch(search).Result;
            //cheking identifier
            var TheResult = await getBooksSearch.GeneralSearch(search);

            return(TheResult);
        }
Example #2
0
        public void testSearchById()
        {
            //arrange
            GoogleBookSearch testSearch = new GoogleBookSearch();

            //act
            IEnumerable <Models.Book> result = testSearch.GeneralSearch("8_DfMSS9r9cC").Result;

            //assert
            Assert.IsNotNull(result);
            var CarrieResult = result.FirstOrDefault(n => n.Title.Equals("Diversity and Evolutionary Biology of Tropical Flowers"));

            Assert.IsNotNull(CarrieResult);
        }
Example #3
0
        public void testValidAuthorName()
        {
            //arrange
            GoogleBookSearch testSearch = new GoogleBookSearch();

            //act
            IEnumerable <Models.Book> result = testSearch.GeneralSearch("Stephen King").Result;

            //assert
            Assert.IsNotNull(result);
            var CarrieResult = result.FirstOrDefault(n => n.Title.Equals("Carrie"));

            Assert.IsNotNull(CarrieResult);
        }
Example #4
0
        public void testInvalidAuthorName()
        {
            //arrange
            GoogleBookSearch testSearch = new GoogleBookSearch();

            //act
            Guid   guid       = Guid.NewGuid();
            String GuidString = guid.ToString();
            IEnumerable <Models.Book> result = testSearch.GeneralSearch(GuidString).Result;

            //assert
            var GuidResult = result.Any(n => n.Title.Equals(GuidString));

            Assert.IsFalse(GuidResult);
        }
Example #5
0
        public async Task <IHttpActionResult> PostBookshelfItem(BookshelfItem bookshelfItem)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (bookshelfItem.ImgURI == null)
            {
                GoogleBookSearch   search = new GoogleBookSearch();
                IEnumerable <Book> result = await search.GeneralSearch(bookshelfItem.ISBN);


                Book firstResult = result.FirstOrDefault();
                if (firstResult != null)
                {
                    bookshelfItem.ImgURI = firstResult.ImgURI;
                }
            }
            //if uri null go get if
            //call uri returner
            //bookshelfItem
            //web api 401 error if not logged in



            var             userID        = User.Identity.GetUserId();
            string          currentUserID = User.Identity.GetUserId();
            ApplicationUser userFound     = db.Users.Find(currentUserID);

            bookshelfItem.User = userFound;
            db.BookShelfItems.Add(bookshelfItem);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = bookshelfItem.Id }, bookshelfItem));
        }