コード例 #1
0
        public JsonResult GetByOrdinal(int id)
        {
            var book = _bookService.FindByOrdinal(id);

            if (book == null)
            {
                return(ErrorResponse("Not found"));
            }

            return(SingleResult(BookViewModelHelpers.ConvertToViewModel(book)));
        }
コード例 #2
0
        public JsonResult GetByName(string bookName)
        {
            if (string.IsNullOrWhiteSpace(bookName))
            {
                return(ErrorResponse("Book name is required"));
            }
            var book = _bookService.GetByName(bookName);

            if (book == null)
            {
                return(ErrorResponse("No book with that name could be found"));
            }

            return(SingleResult(BookViewModelHelpers.ConvertToViewModel(book)));
        }
コード例 #3
0
        public void BookService_GetBookByOrdinal_ReturnsOneBook()
        {
            // What is this test even testing?

            // Arrange
            var idForTest     = 1;
            var dbBook        = GetTestBookById(idForTest);
            var testViewModel = GetBookViewModels()
                                .FirstOrDefault(b => b.BookOrdinal == idForTest);
            // Act
            var viewModel = BookViewModelHelpers.ConvertToViewModel(dbBook);

            // Assert
            Assert.Equal(testViewModel.BookName, viewModel.BookName);
            Assert.Equal(testViewModel.BookDescription, viewModel.BookDescription);
            Assert.Equal(testViewModel.BookIsbn10, viewModel.BookIsbn10);
            Assert.Equal(testViewModel.BookIsbn13, viewModel.BookIsbn13);
        }