public void List() { var cancellationToken = new CancellationToken(false); var result = _booksController.All().ExecuteAsync(cancellationToken).Result; Assert.IsTrue(result.StatusCode == HttpStatusCode.OK); }
public void All_ReturnsAViewResult_WithAListOfAllBooks() { // Arrange var mockBookServices = new Mock <IBookService>(); var mockUserServices = new Mock <IUserService>(); var automapper = new MapperConfiguration(cfg => { cfg.AddProfile(new MappingProfiles()); }); IMapper mapper = automapper.CreateMapper(); mockBookServices.Setup(repo => repo.GetAll()) .Returns(GetTestSessions()); var controller = new BooksController(mapper, mockUserServices.Object, mockBookServices.Object); // Act var result = controller.All(); // Assert var viewResult = Assert.IsType <ViewResult>(result); var model = Assert.IsAssignableFrom <IEnumerable <BookViewModel> >( viewResult.ViewData.Model); Assert.Equal(2, model.Count()); }