public void Can_Display_List_Of_Guest_Book_Items() { // Arrange IGuestBookService guestBookService = _mockRepository.Stub<IGuestBookService>(); var getCurrentGuestBookEntriesRequest = new GetCurrentGuestBookEntriesRequest { Top = 10 }; var expectedGetCurrentGuestBookEntriesResponse = new GetCurrentGuestBookEntriesResponse { Result = new[] { new GuestBookEntry {GuestName = TEST_GUEST_NAME, Comment = TEST_GUEST_COMMENT, PhotoUrl = null} }, IsSuccess = true }; using (_mockRepository.Record()) { SetupResult .For(guestBookService.GetCurrentGuestBookEntries(getCurrentGuestBookEntriesRequest)) .IgnoreArguments() .Return(expectedGetCurrentGuestBookEntriesResponse); } HomeController homeController = new HomeController(guestBookService); // Act var actionResult = homeController.Index(); // Assert actionResult.AssertViewRendered().ForView("Index"); }
private void testCallingIndexAction(HomeController homeController) { // Act - Show index var result = homeController.Index() as ViewResult; // Assert Assert.IsNotNull(result); Assert.IsNotNull(result.ViewBag.GuestBookEntries); var guestBookEntries = result.ViewBag.GuestBookEntries as IEnumerable<GuestBookItemModel>; Assert.IsNotNull(guestBookEntries); Assert.IsTrue(guestBookEntries.Any(guestBookEntry => guestBookEntry.Name.Equals(TEST_GUEST_NAME) && guestBookEntry.Comment.Equals(TEST_GUEST_COMMENT))); }