示例#1
0
        public void Count_GetCount_CountShouldBeEqualToAddedBookCount()
        {
            BookRegister register = new BookRegister();

            register.Add(new Book("name", "author", "category", "language", "1999", "123"));
            register.Add(new Book("n", "a", "c", "l", "1999", "789"));
            register.Count().Should().Be(2);
        }
示例#2
0
        public void FilterBooks_FilterByOnlyByName_ActualShoulBeEqualExpected()
        {
            BookRegister register = new BookRegister();
            Book         book1    = new Book("name", "author", "category", "language", "1999", "123");
            Book         expected = new Book("n", "a", "c", "l", "1999", "789");

            register.Add(book1);
            register.Add(expected);
            TakenBookRegister takenBooks = new TakenBookRegister();
            BookRegister      filtered   = register.FilterBooks("", "", "", "", "n", "", takenBooks);
            Book actual = filtered.Get("789");

            Assert.AreEqual(expected, actual);
        }
示例#3
0
        public void Remove_GivenBookIsEqualToOneInRegister_RemovesGivenBookFromRegister()
        {
            BookRegister register = new BookRegister();
            Book         book1    = new Book("name", "author", "category", "language", "1999", "123");
            Book         expected = new Book("n", "a", "c", "l", "1999", "789");

            register.Add(book1);
            register.Add(expected);
            register.Remove(book1);
            Book actual = register.Get(0);

            register.Count().Should().Be(1);
            Assert.AreEqual(expected, actual);
        }
示例#4
0
        public void CopyToList_CopiesRegisterToList_BooksFromListAreEqualToBooksFromRegister()
        {
            BookRegister register  = new BookRegister();
            Book         expected1 = new Book("name", "author", "category", "language", "1999", "123");
            Book         expected2 = new Book("n", "a", "c", "l", "1999", "789");

            register.Add(expected1);
            register.Add(expected2);
            List <Book> copy    = register.CopyToList();
            Book        actual1 = copy[0];
            Book        actual2 = copy[1];

            Assert.AreEqual(expected1, actual1);
            Assert.AreEqual(expected2, actual2);
        }
示例#5
0
        public void Get_IndexLessThanZero_ReturnNull()
        {
            BookRegister register = new BookRegister();

            register.Add(new Book("name", "author", "category", "language", "1999", "123"));
            register.Get(-1).Should().Be(null);
        }
示例#6
0
        public void Get_IndexMoreOrEqualCount_ReturnNull()
        {
            BookRegister register = new BookRegister();

            register.Add(new Book("name", "author", "category", "language", "1999", "123"));
            register.Get(1).Should().Be(null);
        }
示例#7
0
        public void Get_RegisterDoesNotContainBookWithCertainIsbn_ReturnNull()
        {
            BookRegister register = new BookRegister();

            register.Add(new Book("name", "author", "category", "language", "1999", "123"));
            register.Get("1").Should().Be(null);
        }
示例#8
0
        public void Contains_RegisterDoesNotContainBookWithCertainIsbn_False()
        {
            BookRegister register = new BookRegister();

            register.Add(new Book("name", "author", "category", "language", "1999", "123"));
            bool actual = register.Contains("1");

            Assert.IsFalse(actual);
        }
示例#9
0
        public void FilterBooks_FilterByOnlyByAvailabiltyTaken_ActualShoulBeEqualExpected()
        {
            ReaderRegister readerRegister = new ReaderRegister();
            BookRegister   register       = new BookRegister();
            Book           book1          = new Book("name", "author", "category", "language", "1999", "123");
            Book           expected       = new Book("n", "a", "c", "l", "1999", "789");

            register.Add(book1);
            register.Add(expected);
            TakenBookRegister takenBooks = new TakenBookRegister();
            bool successful;

            TaskUtils.TakeBook(register, takenBooks, readerRegister, "789", "reader", Convert.ToDateTime("2021-05-12"), out successful, 3);
            BookRegister filtered = register.FilterBooks("", "", "", "", "", "false", takenBooks);
            Book         actual   = filtered.Get("789");

            Assert.AreEqual(expected, actual);
        }
示例#10
0
        public void Remove_GivenBookIsbnEqualToOneInRegister_RemovesThatBookFromRegister()
        {
            BookRegister register = new BookRegister();
            Book         book1    = new Book("name", "author", "category", "language", "1999", "123");
            Book         remove   = new Book("n", "a", "c", "l", "1999", "123");

            register.Add(book1);
            register.Remove(remove);
            register.Count().Should().Be(0);
        }
示例#11
0
        public void Remove_GivenBookIsbnNotEqualToOneInRegister_DoesNotRemove()
        {
            BookRegister register = new BookRegister();
            Book         book     = new Book("name", "author", "category", "language", "1999", "123");
            Book         remove   = new Book("n", "a", "c", "l", "1999", "1");

            register.Add(book);
            register.Remove(remove);
            register.Count().Should().Be(1);
        }
示例#12
0
        public void Get_RegisterContainsBookWithCertainIsbn_ExpectedIsEqualActual()
        {
            BookRegister register = new BookRegister();
            Book         expected = new Book("name", "author", "category", "language", "1999", "123");

            register.Add(expected);
            Book actual = register.Get("123");

            Assert.AreEqual(expected, actual);
        }
示例#13
0
        public void Add_AddBookToRegister_AddedBookShouldBeEqualToGiven()
        {
            Book         expected = new Book("name", "author", "category", "language", "1999", "123");
            BookRegister register = new BookRegister();

            register.Add(expected);
            Book actual = register.Get(0);

            Assert.AreEqual(expected, actual);
        }
示例#14
0
        public void Get_IndexMoreOrEqualZeroAndLessThanCount_ExpectedIsEqualActual()
        {
            BookRegister register = new BookRegister();
            Book         expected = new Book("name", "author", "category", "language", "1999", "123");

            register.Add(expected);
            Book actual = register.Get(0);

            Assert.AreEqual(expected, actual);
        }
示例#15
0
        public void TakeBook_ReaderHasAlreadyTakenOneBook_SuccessfullTrueAddbookToTakenBookRegisterAndAddPlusOneToReaderBookCount()
        {
            BookRegister libraryRegister = new BookRegister();
            Book         book1           = new Book("name", "author", "category", "language", "1999", "123");
            Book         book2           = new Book("n", "a", "c", "language", "1999", "123456");

            libraryRegister.Add(book1);
            libraryRegister.Add(book2);
            ReaderRegister    readerRegister = new ReaderRegister();
            TakenBookRegister takenRegister  = new TakenBookRegister();
            bool successful;

            TaskUtils.TakeBook(libraryRegister, takenRegister, readerRegister, "123", "Name", Convert.ToDateTime("2021-05-16"), out successful, 3);
            TaskUtils.TakeBook(libraryRegister, takenRegister, readerRegister, "123456", "Name", Convert.ToDateTime("2021-05-16"), out successful, 3);
            bool containsTakenRegister = takenRegister.Contains("123456");

            Assert.IsTrue(successful);
            Assert.IsTrue(containsTakenRegister);
            readerRegister.Get("Name").BookCount.Should().Be(2);
        }
示例#16
0
        public void TakeBook_BookRegisterDoenNotContainBookWithCertainIsbn_SuccessfullFalse()
        {
            BookRegister libraryRegister = new BookRegister();
            Book         book            = new Book("name", "author", "category", "language", "1999", "123");

            libraryRegister.Add(book);
            ReaderRegister    readerRegister = new ReaderRegister();
            TakenBookRegister takenRegister  = new TakenBookRegister();
            bool successful;

            TaskUtils.TakeBook(libraryRegister, takenRegister, readerRegister, "1", "John", Convert.ToDateTime("2021-05-16"), out successful, 3);
            Assert.IsFalse(successful);
        }
示例#17
0
        public void Remove_GivenBookIsbnNotEqualToOneInRegister_DoesNotRemove()
        {
            BookRegister register     = new BookRegister();
            Book         book1        = new Book("name", "author", "category", "language", "1999", "123");
            Book         book2        = new Book("n", "a", "c", "l", "1999", "789");
            Reader       reader1      = new Reader("Name");
            Reader       reader2      = new Reader("N");
            TakenBook    takenBook    = new TakenBook(book1, Convert.ToDateTime("2021-05-12"), reader1);
            TakenBook    bookToRemove = new TakenBook(book2, Convert.ToDateTime("2021-05-12"), reader2);

            register.Add(takenBook);
            register.Remove(bookToRemove);
            register.Count().Should().Be(1);
        }
示例#18
0
        public void DeleteBook_DeletesBookFromBookRegisterAndTakenBookREgister_BookRegisterAndTakenBookRegisterDoesNotContainBook()
        {
            BookRegister libraryRegister = new BookRegister();
            Book         book1           = new Book("name", "author", "category", "language", "1999", "123");

            libraryRegister.Add(book1);
            ReaderRegister    readerRegister = new ReaderRegister();
            TakenBookRegister takenRegister  = new TakenBookRegister();
            bool successful;

            TaskUtils.TakeBook(libraryRegister, takenRegister, readerRegister, "123", "Name", Convert.ToDateTime("2022-05-16"), out successful, 3);
            TaskUtils.DeleteBook(takenRegister, libraryRegister, readerRegister, "123");
            bool containsBookRegister      = takenRegister.Contains("123");
            bool containsTakenBookRegister = readerRegister.Contains("123");

            Assert.IsFalse(containsBookRegister);
            Assert.IsFalse(containsTakenBookRegister);
        }
示例#19
0
        public void TakeBook_ReaderHasAlreadyTakenThreeBooks_SuccessfullFalse()
        {
            BookRegister libraryRegister = new BookRegister();
            Book         book            = new Book("name", "author", "category", "language", "1999", "123");

            libraryRegister.Add(book);
            ReaderRegister readerRegister = new ReaderRegister();
            Reader         reader         = new Reader("Name");

            readerRegister.Add(reader);
            readerRegister.AddBookCount(reader);
            readerRegister.AddBookCount(reader);
            TakenBookRegister takenRegister = new TakenBookRegister();
            bool successful;

            TaskUtils.TakeBook(libraryRegister, takenRegister, readerRegister, "123", "Name", Convert.ToDateTime("2021-05-16"), out successful, 3);
            Assert.IsFalse(successful);
        }
示例#20
0
        public void TakeBook_NewReaderTakesBook_SuccessfullTrueAddbookToTakenBookRegisterAndAddsNewReaderToReaderRegister()
        {
            BookRegister libraryRegister = new BookRegister();
            Book         book1           = new Book("name", "author", "category", "language", "1999", "123");

            libraryRegister.Add(book1);
            ReaderRegister    readerRegister = new ReaderRegister();
            TakenBookRegister takenRegister  = new TakenBookRegister();
            bool successful;

            TaskUtils.TakeBook(libraryRegister, takenRegister, readerRegister, "123", "Name", Convert.ToDateTime("2021-05-16"), out successful, 3);
            bool containsTakenRegister  = takenRegister.Contains("123");
            bool containsReaderRegister = readerRegister.Contains("Name");

            Assert.IsTrue(successful);
            Assert.IsTrue(containsTakenRegister);
            Assert.IsTrue(containsReaderRegister);
        }
示例#21
0
        public void ReturnBook_ReturnDateIsNotLate_LateReturnIsFalseAndReaderMinusBookCountAndRemoveBookFfromTakenBookRegister()
        {
            BookRegister libraryRegister = new BookRegister();
            Book         book1           = new Book("name", "author", "category", "language", "1999", "123");

            libraryRegister.Add(book1);
            ReaderRegister    readerRegister = new ReaderRegister();
            TakenBookRegister takenRegister  = new TakenBookRegister();
            bool successful;

            TaskUtils.TakeBook(libraryRegister, takenRegister, readerRegister, "123", "Name", Convert.ToDateTime("2022-05-16"), out successful, 3);
            bool lateReturn;

            TaskUtils.ReturnBook(takenRegister, readerRegister, "123", out lateReturn);
            readerRegister.Get("Name").BookCount.Should().Be(0);
            Assert.IsFalse(lateReturn);
            takenRegister.Get("123").Should().Be(null);
        }