Exemple #1
0
        public void UpdateTest_PassInvalidBook_ShouldNotRemoveFromCollection()
        {
            // Arrange
            JsonBookRepository jsonBookRepository = new JsonBookRepository();
            Book book = new Book();

            book.Title       = "Hello";
            book.Author      = "Sasha";
            book.DateOfissue = 1984;
            jsonBookRepository.Add(book);
            Book book2 = new Book();

            book2.Title       = "World";
            book2.Author      = "Vasya";
            book2.DateOfissue = 1991;
            book2.Id          = 0;

            // Act
            jsonBookRepository.Update(book2);

            //Assert
            Assert.AreEqual("Hello", book.Title);
            Assert.AreEqual("Sasha", book.Author);
            Assert.AreEqual(1984, book.DateOfissue);
        }
Exemple #2
0
        public void UpdateTest_PassValidBook_ShouldRemoveFromCollection()
        {
            // Arrange
            JsonBookRepository jsonBookRepository = new JsonBookRepository();
            Book book = new Book();

            book.Name        = "Hello";
            book.Author      = "Sasha";
            book.YearOfIssue = 1984;
            jsonBookRepository.Add(book);
            int  id    = book.Id;
            Book book2 = new Book();

            book2.Name        = "World";
            book2.Author      = "Vasya";
            book2.YearOfIssue = 1991;
            book2.Id          = id;

            // Act
            jsonBookRepository.Update(book2);

            //Assert
            Assert.AreEqual("World", book.Name);
            Assert.AreEqual("Vasya", book.Author);
            Assert.AreEqual(1991, book.YearOfIssue);
        }
Exemple #3
0
        public void AddBookTest_PassInvalidBook_ShouldNotAddToCollection()
        {
            // Arrange
            JsonBookRepository jsonBookRepository = new JsonBookRepository();
            Book book = null;

            // Act
            jsonBookRepository.Add(book);

            //Assert
            Assert.AreEqual(0, jsonBookRepository.Books.Count);
        }
Exemple #4
0
        public void AddBookTest_PassValidBook_ShouldAddToCollection()
        {
            // Arrange
            JsonBookRepository jsonBookRepository = new JsonBookRepository();
            Book book = new Book();

            // Act
            jsonBookRepository.Add(book);

            //Assert
            Assert.AreEqual(1, book.Id);
            Assert.AreEqual(1, jsonBookRepository.Books.Count);
        }
Exemple #5
0
        public void RemoveTest_PassInvalidBook_ShouldNotRemoveFromCollection()
        {
            // Arrange
            JsonBookRepository jsonBookRepository = new JsonBookRepository();
            Book book = new Book();

            jsonBookRepository.Add(book);

            // Act
            jsonBookRepository.Remove(0);

            //Assert
            Assert.AreEqual(1, jsonBookRepository.Books.Count);
        }
Exemple #6
0
        public void GetBooksTest_ShouldReturnBooks()
        {
            //Arrange
            JsonBookRepository jsonBookRepository = new JsonBookRepository();
            Book book = new Book();

            jsonBookRepository.Add(book);

            //Act
            var books = jsonBookRepository.GetAll();

            //Assert
            Assert.IsNotNull(books);
            Assert.AreEqual(1, books.Count);
        }
Exemple #7
0
        public void GetBookTest_PassValidId_ShouldReturnBook()
        {
            // Arrange
            JsonBookRepository jsonBookRepository = new JsonBookRepository();
            Book book = new Book();

            jsonBookRepository.Add(book);

            // Act
            var actual = jsonBookRepository.Get(book.Id);


            //Assert
            Assert.AreEqual(actual, book);
        }