public void BookStorageDeleteBookTest() { List <Genre> genres1 = new List <Genre> { new Genre("fantasy") }; BookInfo bookInfo1 = new BookInfo("Harry Potter and the Chamber of Secrets", "J.K.Rowling", genres1); Book book1 = new Book(bookInfo1, 500m, DateTime.Today); List <Genre> genres2 = new List <Genre> { new Genre("other") }; BookInfo bookInfo2 = new BookInfo("One Flew Over the Cuckoo's Nest", " Ken Kesey", genres2); Book book2 = new Book(bookInfo2, 600m, DateTime.Today.AddDays(-110)); BookStorage bookStorage = new BookStorage(); bookStorage.AddBook(book1); bookStorage.AddBook(book2); bookStorage.FindByGuidOrDefault(book1.Guid).Should().Be(book1); bookStorage.FindByGuidOrDefault(book2.Guid).Should().Be(book2); bookStorage.DeleteBook(book1); bookStorage.FindByGuidOrDefault(book1.Guid).Should().Be(null); bookStorage.FindByGuidOrDefault(book2.Guid).Should().Be(book2); }
public void BookStorageAddTwoBooksTest() { List <Genre> genres = new List <Genre> { new Genre("fantasy") }; BookInfo bookInfo = new BookInfo("Harry Potter and the Chamber of Secrets", "J.K.Rowling", genres); Book book1 = new Book(bookInfo, 500m, DateTime.Today); Book book2 = new Book(bookInfo, 600m, DateTime.Today.AddDays(-110)); BookStorage bookStorage = new BookStorage(); bookStorage.AddBook(book1); bookStorage.AddBook(book2); bookStorage.FindByGuidOrDefault(book1.Guid).Should().Be(book1); bookStorage.FindByGuidOrDefault(book2.Guid).Should().Be(book2); }
public virtual bool TransferBook(BookStorage target, BookModel bookModel) { if (!ContainBook(bookModel.book)) { throw new Exception("This storage does not contain the book " + bookModel.book.Title); } if (!target.AddBook(bookModel)) { return(false); } books.Remove(bookModel); return(true); }
private void Init() { foreach (SaverLoader.GameData.BookStorage bookStorage in CurrentSave.BookStorages) { BookStorage bookStorageInstance = null; switch (bookStorage.Type) { case SaverLoader.GameData.BookStorage.BuildingType.Bookshelf: bookStorageInstance = Instantiate(pm.BookshelfPrefab, bookStorage.Position, bookStorage.Rotation); break; case SaverLoader.GameData.BookStorage.BuildingType.Checkout: bookStorageInstance = Instantiate(pm.CheckoutPrefab, bookStorage.Position, bookStorage.Rotation); ((Checkout)bookStorageInstance).dropOffCheckout = bookStorage.DropOffCheckout; break; default: throw new ArgumentOutOfRangeException(); } foreach (int bookId in bookStorage.BookIds) { BookModel bookModel = BookModel.Instantiate(bm.Books[bookId]); bookStorageInstance.AddBook(bookModel, true); } bookStorageInstance.Init(); } foreach (int bookId in CurrentSave.TransportedBooks) { BookModel bookModel = BookModel.Instantiate(bm.Books[bookId]); PlayerTransport.AddBook(bookModel, true); PlayerTransport.booksToStore.Add(bookModel); } }