Exemplo n.º 1
0
        public void GivenArchive_WhenArchiveBookIsNull_ShouldReturnException()
        {
            // Arrange
            var books = new List <Book>
            {
                new Book {
                    Id = 1, Name = "The Lord of the Rings", IsArchive = false
                },
                new Book {
                    Id = 2, Name = "Le Petit Prince", IsArchive = false
                },
                new Book {
                    Id = 3, Name = "Harry Potter and the Philosopher's Stone", IsArchive = false
                },
            };
            var bookMemoryStorage = new BookMemoryStorage(books);

            //Act
            TestDelegate testAction = () => bookMemoryStorage.Archive(null);

            //Assert
            var ex = Assert.Throws <InvalidOperationException>(testAction);

            Assert.That(ex.Message, Is.EqualTo("Can not archive null object!"));
        }
Exemplo n.º 2
0
        public void GivenGetAll_WhenBooksExist_ShouldReturnBookList()
        {
            // Arrange
            var books = new List <Book>
            {
                new Book {
                    Id = 1, Name = "The Lord of the Rings", IsArchive = false
                },
                new Book {
                    Id = 2, Name = "Le Petit Prince", IsArchive = false
                },
                new Book {
                    Id = 3, Name = "Harry Potter and the Philosopher's Stone", IsArchive = false
                },
            };
            var store = new BookMemoryStorage(books);

            // Act
            var result = store.GetAll();

            // Assert
            result.Should().BeEquivalentTo(new List <Book>
            {
                new Book {
                    Id = 1, Name = "The Lord of the Rings", IsArchive = false
                },
                new Book {
                    Id = 2, Name = "Le Petit Prince", IsArchive = false
                },
                new Book {
                    Id = 3, Name = "Harry Potter and the Philosopher's Stone", IsArchive = false
                },
            });
        }
Exemplo n.º 3
0
        public void GivenArchive_WhenArchiveNonExistBook_ShouldReturnException()
        {
            // Arrange
            var book = new Book {
                Id = 4, Name = "Herbert Schildt C#", IsArchive = false
            };
            var books = new List <Book>
            {
                new Book {
                    Id = 1, Name = "The Lord of the Rings", IsArchive = false
                },
                new Book {
                    Id = 2, Name = "Le Petit Prince", IsArchive = false
                },
                new Book {
                    Id = 3, Name = "Harry Potter and the Philosopher's Stone", IsArchive = false
                },
            };
            var bookMemoryStorage = new BookMemoryStorage(books);

            //Act
            TestDelegate testAction = () => bookMemoryStorage.Archive(book);

            //Assert
            var ex = Assert.Throws <InvalidOperationException>(testAction);

            Assert.That(ex.Message, Is.EqualTo("There is not this item in the Item Storage!"));
        }
Exemplo n.º 4
0
        public void GivenDelete_WhenDeleteExistBook_ShouldReturnBookListWithoutDeletedBook()
        {
            // Arrange
            var book = new Book {
                Id = 3, Name = "Harry Potter and the Philosopher's Stone", IsArchive = false
            };
            var books = new List <Book>
            {
                new Book {
                    Id = 1, Name = "The Lord of the Rings", IsArchive = false
                },
                new Book {
                    Id = 2, Name = "Le Petit Prince", IsArchive = false
                },
                new Book {
                    Id = 3, Name = "Harry Potter and the Philosopher's Stone", IsArchive = false
                },
            };
            var bookMemoryStorage = new BookMemoryStorage(books);

            // Act
            bookMemoryStorage.Delete(book);
            var result = bookMemoryStorage.GetAll();

            // Assert
            result.Should().BeEquivalentTo(new List <Book>
            {
                new Book {
                    Id = 1, Name = "The Lord of the Rings", IsArchive = false
                },
                new Book {
                    Id = 2, Name = "Le Petit Prince", IsArchive = false
                }
            });
        }
Exemplo n.º 5
0
        public void GivenGetAll_WhenBooksNotProvide_ShouldReturnEmptyList()
        {
            // Arrange
            var store = new BookMemoryStorage(null);

            // Act
            var result = store.GetAll();

            // Assert
            result.Should().BeEmpty();
        }