public void ReturnsDinnersInViewModel() { _mockRepository.Setup(r => r.List()).Returns(GetTestDinnerCollection()); var controller = new DinnersController(_mockRepository.Object, null); var result = controller.Index(); var viewResult = Assert.IsType <ViewResult>(result); var viewModel = Assert.IsType <List <Dinner> >(viewResult.ViewData.Model); Assert.Equal("Test Dinner 1", viewModel.First().Title); Assert.Equal(2, viewModel.Count); }
public void IndexAction_With_Dinner_Just_Started_Should_Show_Dinner() { // Arrange var testData = FakeDinnerData.CreateTestDinners(); var dinner = FakeDinnerData.CreateDinner(); dinner.EventDate = DateTime.Now.AddHours(-1); dinner.Title = "Dinner which just started"; testData.Add(dinner); var repository = new FakeDinnerRepository(testData); var controller = new DinnersController(repository, new CommandServiceClient(), new DinnerReadModel()); // Act // Get first page ViewResult result = (ViewResult)controller.Index(null, null); PaginatedList <Dinner> list = result.ViewData.Model as PaginatedList <Dinner>; // Assert Assert.AreEqual("Dinner which just started", list.First().Title); }
public void IndexAction_With_Search_Term_Should_Filter() { // Arrange string searchterm = "Dinner we will be searching for (spaghetti)"; var testData = FakeDinnerData.CreateTestDinners(); var dinner = FakeDinnerData.CreateDinner(); dinner.Title = searchterm; testData.Add(dinner); var repository = new FakeDinnerRepository(testData); var controller = new DinnersController(repository, new CommandServiceClient(), new DinnerReadModel()); // Act // Get first page ViewResult result = (ViewResult)controller.Index("etti", null); PaginatedList <Dinner> list = result.ViewData.Model as PaginatedList <Dinner>; // Assert Assert.AreEqual(searchterm, list.First().Title); }