public async Task AddOwnedBookAsync(IOwnedBook ownedBook, GoogleBooks googleBooks)
        {
            if (googleBooks is null)
            {
                throw new ArgumentNullException(nameof(googleBooks));
            }

            var user = await _context.Users.SingleAsync(u => u.Id == ownedBook.OwnerId);

            var book = await _context.Books.SingleOrDefaultAsync(b => b.Isbn == ownedBook.Isbn.IsbnValue);

            if (book is null)
            {
                IBook bookObj = await googleBooks.GetBookFromIsbn(ownedBook.Isbn.IsbnValue);

                if (bookObj is null)
                {
                    throw new AggregateException("Unable to retrieve book from Google Books.");
                }

                book = await AddBook(bookObj);
            }

            var ownedBookData = new OwnedBook()
            {
                User                 = user,
                Book                 = book,
                ConditionId          = (int)ownedBook.Condition,
                AvailabilityStatusId = (int)ownedBook.Availability
            };

            await _context.OwnedBooks.AddAsync(ownedBookData);
        }
        public void OwnedBook_Construct_Pass()
        {
            // arrange

            PhysicalCondition condition    = PhysicalCondition.LikeNew;
            Availability      availability = Availability.Available;

            // act
            IOwnedBook ownedBook = new OwnedBook(id, isbn, ownerId, condition, availability);

            // assert
            Assert.NotNull(ownedBook);
        }
        private void CreateOwnedBooks()
        {
            OwnedBook book;

            // Neville's books
            book = new OwnedBook()
            {
                Id        = Guid.NewGuid(),
                Available = true,
                Book      = Books[BookType.Who_Am_I],
                Notes     = "Signed special edition."
            };
            Users[UserType.Neville].OwnedBooks.Add(book);
            OwnedBooks.Add(book);
            // Harry's books
            book = new OwnedBook()
            {
                Id        = Guid.NewGuid(),
                Available = true,
                Book      = Books[BookType.Potion_Making],
                Notes     = "Missing pages 31-32."
            };
            Users[UserType.Harry].OwnedBooks.Add(book);
            OwnedBooks.Add(book);
            // Hermione's books
            book = new OwnedBook()
            {
                Id        = Guid.NewGuid(),
                Available = false,
                Book      = Books[BookType.Potion_Making],
                Notes     = "Unabridged version"
            };
            Users[UserType.Hermione].OwnedBooks.Add(book);
            OwnedBooks.Add(book);
            book = new OwnedBook()
            {
                Id        = Guid.NewGuid(),
                Available = true,
                Book      = Books[BookType.Potente_Potions],
                Notes     = "Slightly damp"
            };
            Users[UserType.Hermione].OwnedBooks.Add(book);
            OwnedBooks.Add(book);
            // Ron's books
            book = new OwnedBook()
            {
                Id        = Guid.NewGuid(),
                Available = true,
                Book      = Books[BookType.Potion_Making],
                Notes     = "Unread."
            };
            Users[UserType.Ron].OwnedBooks.Add(book);
            OwnedBooks.Add(book);
            // Ginny's books
            book = new OwnedBook()
            {
                Id        = Guid.NewGuid(),
                Available = false,
                Book      = Books[BookType.Dear_Diary],
                Notes     = "Only copy in the school."
            };
            Users[UserType.Ginny].OwnedBooks.Add(book);
            OwnedBooks.Add(book);
            // Malfoy's books
            book = new OwnedBook()
            {
                Id        = Guid.NewGuid(),
                Available = true,
                Book      = Books[BookType.Basic_Hexes],
                Notes     = ""
            };
            Users[UserType.Malfoy].OwnedBooks.Add(book);
            OwnedBooks.Add(book);
        }