public void GetCopyOfBookTest() { AddCopyOfBookTest(); CopyOfBook copyOfBookFromCollection = _dataLayer.GetAllCopiesOfBook().First(); Assert.AreEqual(copyOfBookFromCollection, _dataLayer.GetCopyOfBook(copyOfBookFromCollection.Id)); Assert.AreEqual(null, _dataLayer.GetCopyOfBook(Guid.NewGuid())); }
public void DeleteCopyOfBook(CopyOfBook copyOfBook) { if (IsCopyOfBookRented(copyOfBook)) { throw new ArgumentException("This copy of book is already rented!"); } _dataLayer.DeleteCopyOfBook(copyOfBook); }
public void DeleteCopyOfBookTest() { AddCopyOfBookTest(); Assert.AreEqual(5, _dataLayer.GetAllCopiesOfBook().Count()); CopyOfBook copy = _dataLayer.GetAllCopiesOfBook().First(); _dataLayer.DeleteCopyOfBook(copy); Assert.AreEqual(4, _dataLayer.GetAllCopiesOfBook().Count()); Assert.IsNull(_dataLayer.GetCopyOfBook(copy.Id)); }
public bool IsCopyOfBookRented(CopyOfBook copyOfBook) { if (copyOfBook == null) { throw new ArgumentNullException("Reference to copy of book is null!"); } IEnumerable <CopyOfBook> rentedBooks = GetRentedCopiesOfBooks(); return(rentedBooks.Contains(copyOfBook)); }
public void UpdateCopyOfBookTest() { ConstObjectsFiller cof = new ConstObjectsFiller(); _dataLayer = new LibraryRepository(); _dataLayer.DataFiller = cof; _dataLayer.FillData(); CopyOfBook newBook = new CopyOfBook(Guid.NewGuid(), _dataLayer.GetAllBooks().ElementAt(0), DateTime.Now, 21); Guid id = _dataLayer.GetAllCopiesOfBook().ElementAt(0).Id; Assert.ThrowsException <ArgumentException>(() => _dataLayer.UpdateCopyOfBook(id, newBook)); Assert.ThrowsException <ArgumentException>(() => _dataLayer.UpdateCopyOfBook(Guid.NewGuid(), newBook)); newBook = new CopyOfBook(id, _dataLayer.GetAllBooks().ElementAt(0), DateTime.Now, 21); _dataLayer.UpdateCopyOfBook(id, newBook); Assert.AreEqual(_dataLayer.GetCopyOfBook(id).PricePerDay, newBook.PricePerDay); }
public void Fill(LibraryContext context) { Reader person1 = new Reader(Guid.NewGuid(), "Adam", "Nowak", new DateTime(1998, 05, 23), "111222333", "*****@*****.**", Person.Gender.Male, new DateTime(2019, 9, 11)); Employee person2 = new Employee(Guid.NewGuid(), "Katarzyna", "Kowalska", new DateTime(1967, 03, 13), "123456789", "*****@*****.**", Person.Gender.Female, new DateTime(2019, 9, 11)); Author tolkien = new Author(Guid.NewGuid(), "John Ronald Reuel", "Tolkien"); Author fDostojewski = new Author(Guid.NewGuid(), "Fiodor", "Dostojewski"); Book hobbit = new Book("Hobbit, czyli tam i z powrotem", tolkien, "Powieść fantasy dla dzieci autorstwa J.R.R. Tolkiena.", Book.BookType.Fantasy); Book zik = new Book("Zbrodnia i Kara", fDostojewski, "Tematem powieści są losy byłego studenta, Rodiona Raskolnikowa, który postanawia zamordować i obrabować starą lichwiarkę." , Book.BookType.Classics); Book wp = new Book("Wladca Pierscieni", tolkien, "Powieść high fantasy J.R.R. Tolkiena, której akcja rozgrywa się w mitologicznym świecie Śródziemia.Jest ona kontynuacją innej powieści tego autora zatytułowanej Hobbit, czyli tam i z powrotem.", Book.BookType.Fantasy); CopyOfBook hobbit1 = new CopyOfBook(Guid.NewGuid(), hobbit, new DateTime(2004, 11, 21, 0, 0, 0), 0.4); CopyOfBook hobbit2 = new CopyOfBook(Guid.NewGuid(), hobbit, new DateTime(2004, 12, 3, 0, 0, 0), 0.4); CopyOfBook zik1 = new CopyOfBook(Guid.NewGuid(), zik, new DateTime(2001, 10, 11, 0, 0, 0), 0.5); CopyOfBook zik2 = new CopyOfBook(Guid.NewGuid(), zik, new DateTime(2001, 10, 11, 0, 0, 0), 0.5); CopyOfBook wp1 = new CopyOfBook(Guid.NewGuid(), wp, new DateTime(2005, 12, 23, 0, 0, 0), 0.7); List <CopyOfBook> booksForRent1 = new List <CopyOfBook>(); booksForRent1.Add(hobbit1); Rent rent1 = new Rent(Guid.NewGuid(), person1, person2, booksForRent1, new DateTime(2010, 1, 6, 0, 0, 0)); context.Authors.Add(tolkien); context.Authors.Add(fDostojewski); context.Employees.Add(person2); context.Readers.Add(person1); context.Books.Add(1, hobbit); context.Books.Add(2, wp); context.Books.Add(3, zik); context.CopiesOfBooks.Add(hobbit1); context.CopiesOfBooks.Add(hobbit2); context.CopiesOfBooks.Add(zik1); context.CopiesOfBooks.Add(zik2); context.CopiesOfBooks.Add(wp1); context.Events.Add(rent1); }
public void AddCopyOfBookTest() { AddBookTest(); CopyOfBook cob1 = new CopyOfBook(Guid.NewGuid(), _dataLayer.FindBook(b => b.Name.Equals("Zbrodnia i Kara")), new DateTime(2004, 12, 3, 0, 0, 0), 0.6); CopyOfBook cob2 = new CopyOfBook(Guid.NewGuid(), _dataLayer.FindBook(b => b.Name.Equals("Zbrodnia i Kara")), new DateTime(2014, 12, 3, 0, 0, 0), 0.6); Assert.AreNotEqual(cob1, cob2); Assert.AreEqual(0, _dataLayer.GetAllCopiesOfBook().Count()); _dataLayer.AddCopyOfBook(cob1); Assert.AreEqual(1, _dataLayer.GetAllCopiesOfBook().Count()); _dataLayer.AddCopyOfBook(cob2); Assert.AreEqual(2, _dataLayer.GetAllCopiesOfBook().Count()); Assert.ThrowsException <ArgumentException>(() => _dataLayer.AddCopyOfBook(cob1)); CopyOfBook zik1 = new CopyOfBook(Guid.NewGuid(), _dataLayer.GetAllBooks().ElementAt(0), new DateTime(2001, 10, 11, 0, 0, 0), 0.5); CopyOfBook zik2 = new CopyOfBook(Guid.NewGuid(), _dataLayer.GetAllBooks().ElementAt(0), new DateTime(2002, 10, 11, 0, 0, 0), 0.5); CopyOfBook wp1 = new CopyOfBook(Guid.NewGuid(), _dataLayer.GetAllBooks().ElementAt(0), new DateTime(2005, 12, 23, 0, 0, 0), 0.7); _dataLayer.AddCopyOfBook(zik1); _dataLayer.AddCopyOfBook(zik2); _dataLayer.AddCopyOfBook(wp1); Assert.AreEqual(5, _dataLayer.GetAllCopiesOfBook().Count()); }
public void Init() { _author1 = new Author(Guid.NewGuid(), "Adam", "Malysz"); _author2 = new Author(Guid.NewGuid(), "Robert", "Maklowicz"); _author3 = new Author(Guid.NewGuid(), "Edyta", "Gorniak"); _book1 = new Book("DSJ 2.1 Jurii Kosela Tutorial", _author1, "How to beat super bots", Book.BookType.Detective); _book2 = new Book("Goplana the best chocolate", _author1, "Explanation why i love Goplana", Book.BookType.Biographie); _book3 = new Book("How to cook water", _author2, "Best chef in the word shows how to properly cook water", Book.BookType.Romance); _book4 = new Book("abc", _author2, "abc", Book.BookType.Novel); _book5 = new Book("next time I'll beat you", _author3, "le", Book.BookType.Romance); _book1copy1 = new CopyOfBook(Guid.NewGuid(), _book1, DateTime.Now, 100); _book1copy2 = new CopyOfBook(Guid.NewGuid(), _book1, DateTime.Now, 100); _book2copy1 = new CopyOfBook(Guid.NewGuid(), _book2, DateTime.Now, 50); _book2copy2 = new CopyOfBook(Guid.NewGuid(), _book2, DateTime.Now, 50); _book3copy1 = new CopyOfBook(Guid.NewGuid(), _book3, DateTime.Now, 200); _book3copy2 = new CopyOfBook(Guid.NewGuid(), _book3, DateTime.Now, 200); _book4copy1 = new CopyOfBook(Guid.NewGuid(), _book4, DateTime.Now, 30); _book4copy2 = new CopyOfBook(Guid.NewGuid(), _book4, DateTime.Now, 30); _book5copy1 = new CopyOfBook(Guid.NewGuid(), _book5, DateTime.Now, 10); _book5copy2 = new CopyOfBook(Guid.NewGuid(), _book5, DateTime.Now, 10); _reader1 = new Reader(Guid.NewGuid(), "Agnieszka", "Kolano", new DateTime(1970, 3, 1), "111111111", "*****@*****.**", Person.Gender.Female, DateTime.Now); _reader2 = new Reader(Guid.NewGuid(), "Adam", "Nowak", new DateTime(1998, 05, 23), "111222333", "*****@*****.**", Person.Gender.Female, new DateTime(2019, 9, 11)); _employee1 = new Employee(Guid.NewGuid(), "Katarzyna", "Kowalska", new DateTime(1967, 03, 13), "123456789", "*****@*****.**", Person.Gender.Female, new DateTime(2019, 9, 11)); _booksForRent1 = new List <CopyOfBook>() { _book1copy1, _book2copy1, _book3copy1 }; _booksForRent2 = new List <CopyOfBook>() { _book4copy1, _book5copy1, _book1copy2, _book2copy2 }; _booksForRent3 = new List <CopyOfBook>() { _book3copy2, _book4copy2, _book5copy2 }; _rent1 = new Rent(Guid.NewGuid(), _reader1, _employee1, _booksForRent1, DateTime.Now); _rent2 = new Rent(Guid.NewGuid(), _reader2, _employee1, _booksForRent2, DateTime.Now); _rent3 = new Rent(Guid.NewGuid(), _reader1, _employee1, _booksForRent3, DateTime.Now); _return1 = new Return(Guid.NewGuid(), DateTime.Now, _booksForRent1, _rent1); _return2 = new Return(Guid.NewGuid(), DateTime.Now, _booksForRent2, _rent2); _return3 = new Return(Guid.NewGuid(), DateTime.Now, _booksForRent3, _rent1); _payment1 = new Payment(Guid.NewGuid(), DateTime.Now, _reader1, 100); _payment2 = new Payment(Guid.NewGuid(), DateTime.Now, _reader2, 200); _payment3 = new Payment(Guid.NewGuid(), DateTime.Now, _reader1, 300); _authors = new List <Author>() { _author1, _author2, _author3 }; _books = new Dictionary <int, Book>() { { 1, _book1 }, { 2, _book2 }, { 3, _book3 }, { 4, _book4 }, { 5, _book5 } }; _copiesOfBooks = new List <CopyOfBook>() { _book1copy1, _book1copy2, _book2copy1, _book2copy2, _book3copy1, _book3copy2, _book4copy1, _book4copy2, _book5copy1, _book5copy2 }; _employees = new List <Employee>() { _employee1 }; _readers = new List <Reader>() { _reader1, _reader2 }; _events = new ObservableCollection <Event>() { _rent1, _rent2, _rent3, _return1, _return2, _return3, _payment1, _payment2, _payment3 }; _context = new LibraryContext(); }