public void Mapper_Should_Map_Book_To_Database_Model()
        {
            var googleBook    = GoogleApi.FindBook("9780132350884");
            var book          = Mapper.ConvertModel <GoogleBookModel, Book>(googleBook);
            var databaseModel = Mapper.ConvertModel <Book, BookDB>(book);

            ValidateBook(book, databaseModel);
        }
        public void Mapper_Should_Map_Google_Model_To_Book()
        {
            var source      = GoogleApi.FindBook("9780132350884");
            var destination = Mapper.ConvertModel <GoogleBookModel, Book>(source);

            Assert.Equal(source.title, destination.Title);
            Assert.Equal(source.industryIdentifiers[0].identifier, destination.Isbn);
            Assert.Equal(source.publisher, destination.Publisher);
            Assert.Equal(source.publishedDate, destination.PublishedDate.Year.ToString());
            Assert.Equal(source.description, destination.Description);
            Assert.Equal(source.pageCount, destination.PageCount);
            Assert.Equal(source.averageRating, destination.AverageRating);
            Assert.Equal(source.maturityRating, destination.MaturityRating);
            Assert.Equal(source.language, destination.Language);
            Assert.Equal(source.authors[0], destination.Authors[0].Name);
        }
示例#3
0
        public Book GetBookFromApi(string isbn)
        {
            var googleBook = GoogleApi.FindBook(isbn);
            var book       = Mapper.ConvertModel <GoogleBookModel, Book>(googleBook);

            foreach (var author in googleBook.authors)
            {
                var foundAuthor = _authorCollection.Find("Name", author).FirstOrDefault();
                if (foundAuthor == null)
                {
                    continue;
                }

                book.Authors.Remove(book.Authors.SingleOrDefault(a => a.Name == author));
                book.Authors.Add(foundAuthor);
            }

            return(book);
        }
        public void Google_Api_Should_Return_Null_With_Invalid_ISBN()
        {
            var book = GoogleApi.FindBook("xxxxxxxxxxxxx");

            Assert.Null(book);
        }
        public void Google_Api_Should_Not_Fail_With_Valid_ISBN13()
        {
            var book = GoogleApi.FindBook("9780132350884");

            Assert.NotNull(book);
        }