Exemple #1
0
        public async Task get_all_books()
        {
            // Arrange
            var repository = LibraryContextMocker.GetInMemoryLibraryRepository(nameof(get_all_books));
            var controller = new LibraryController(repository);
            // Act
            var response = await controller.GetAll() as ObjectResult;

            var books = response.Value as List <Book>;

            // Assert
            Assert.Equal(200, response.StatusCode);
            Assert.Equal(5, books.Count);
        }
Exemple #2
0
        public async Task get_book_with_not_existing_id()
        {
            // Arrange
            var repository      = LibraryContextMocker.GetInMemoryLibraryRepository(nameof(get_book_with_not_existing_id));
            var controller      = new LibraryController(repository);
            var expectedMessage = "Record couldn't ve found";
            // Act
            var response = await controller.Get(10) as ObjectResult;

            var book = response.Value as Book;

            // Assert
            Assert.Equal(404, response.StatusCode);
            Assert.Equal(expectedMessage, response.Value);
        }
Exemple #3
0
        public async Task get_book_with_existing_id()
        {
            // Arrange
            var repository    = LibraryContextMocker.GetInMemoryLibraryRepository(nameof(get_book_with_existing_id));
            var controller    = new LibraryController(repository);
            var expectedValue = "Wiedzmin";
            // Act
            var response = await controller.Get(1) as ObjectResult;

            var book = response.Value as Book;

            // Assert
            Assert.Equal(200, response.StatusCode);
            Assert.Equal(expectedValue, book.Title);
        }