public void Create_NewBook_ShouldReturnOkObjectResult()
        {
            var book = new Mock <BookToCreate>();

            var result = _controller.Add(book.Object);

            result.Should().NotBeNull();
        }
Beispiel #2
0
        public async void Add_ShouldReturnOk_WhenBookIsAdded()
        {
            var book       = CreateBook();
            var bookAddDto = new BookAddDto()
            {
                Name = book.Name
            };
            var bookResultDto = MapModelToBookResultDto(book);

            _mapperMock.Setup(m => m.Map <Book>(It.IsAny <BookAddDto>())).Returns(book);
            _bookServiceMock.Setup(c => c.Add(book)).ReturnsAsync(book);
            _mapperMock.Setup(m => m.Map <BookResultDto>(It.IsAny <Book>())).Returns(bookResultDto);

            var result = await _booksController.Add(bookAddDto);

            Assert.IsType <OkObjectResult>(result);
        }
        public void Add_Should_Add_A_Book_And_Return_Added_Book()
        {
            // Arrange
            var fakeAddedBook = new Book()
            {
                Id   = 1,
                Name = "Fake Book"
            };
            var fakeAddedBookViewModel = new BookViewModel()
            {
                Id   = 1,
                Name = "Fake Book"
            };

            _mockRepo.Setup(repo => repo.Add(It.IsAny <Book>(), 0)).Returns(fakeAddedBook);

            // Act
            var methodResult = _mockController.Add(fakeAddedBookViewModel);

            // Assert
            var testResult = methodResult.Result as OkObjectResult;

            Assert.Equal(fakeAddedBook, testResult.Value);
        }