Ejemplo n.º 1
0
        public async void GetBookTest_GetBookFromTheDatabase()
        {
            var mockBooks = new List <Book>
            {
                new Book
                {
                    ISBN   = "Test ISBN 1",
                    Author = "Test Author 1",
                    Title  = "Test Title 1"
                },
                new Book
                {
                    ISBN   = "Test ISBN 2",
                    Author = "Test Author 2",
                    Title  = "Test Title 2"
                }
            };

            var connectionMock = new Mock <DbConnection>();

            connectionMock
            .SetupDapperAsync(m => m.QueryAsync <Book>(It.IsAny <string>(), It.IsAny <object>(), It.IsAny <IDbTransaction>(), It.IsAny <int?>(), It.IsAny <CommandType?>()))
            .ReturnsAsync(mockBooks);


            var connectionFactoryMock = new Mock <IDbConnectionFactory>();

            connectionFactoryMock
            .Setup(m => m.CreateConnection())
            .Returns(connectionMock.Object);


            var booksRepository = new BooksRepository(connectionFactoryMock.Object);

            var book = await booksRepository.GetAsync(mockBooks.First().ISBN);

            Assert.Equal(mockBooks.First().ISBN, book.ISBN);
        }