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");
        }
        public void Should_Be_Able_To_Submit_Guest_Book_Entry_With_No_Picture_And_List_Current_Entries()
        {
            // Arrange
            var homeController = new HomeController(_guestBookService);

            // act & assert
            testSubmitGuestBookEntry(homeController, null);

            // Act & assert - Show index
            testCallingIndexAction(homeController);
        }
        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)));
        }
        public void Should_Be_Able_To_Submit_Guest_Book_Entry_And_List_Current_Entries()
        {
            // Arrange
            var homeController = new HomeController(_guestBookService);
            var imageUpload = prepareUploadedImage();

            // act & assert
            testSubmitGuestBookEntry(homeController, imageUpload);

            // Act & assert - Show index
            testCallingIndexAction(homeController);
        }
        public void Can_Submit_Guest_Book_Entry()
        {
            // Arrange
            SubmitGuestBookEntryRequest submitGuestBookEntryRequest = new SubmitGuestBookEntryRequest
                {
                    Name = TEST_GUEST_NAME,
                    Comment = TEST_GUEST_COMMENT,
                    ImageFile = null
                };
            SubmitGuestBookEntryResponse expectedSubmitGuestBookEntryResponse = new SubmitGuestBookEntryResponse { IsSuccess = true };

            IGuestBookService guestBookService = _mockRepository.Stub<IGuestBookService>();
            using (_mockRepository.Record())
            {
                SetupResult
                    .For(guestBookService.SubmitGuestBookEntry(submitGuestBookEntryRequest))
                    .IgnoreArguments()
                    .Return(expectedSubmitGuestBookEntryResponse);
            }

            HomeController homeController = new HomeController(guestBookService);
            GuestBookEntryModel guestBookEntryModel = new GuestBookEntryModel { Name = TEST_GUEST_NAME, Comment = TEST_GUEST_COMMENT };

            // Act
            var actionResult = homeController.Submit(guestBookEntryModel, null);
            RedirectToRouteResult redirectToRouteResult = actionResult as RedirectToRouteResult;

            // Assert
            Assert.IsNotNull(redirectToRouteResult);
            Assert.IsNotNull(redirectToRouteResult.RouteValues["action"]);
            Assert.AreEqual("Index", redirectToRouteResult.RouteValues["action"]);
            SubmitResponse submitResponse = homeController.TempData["SubmitResponse"] as SubmitResponse;
            Assert.IsNotNull(submitResponse);
            Assert.AreEqual(true, submitResponse.IsSuccess);
            Assert.AreEqual("Data submission is success.", submitResponse.Message);
        }
        private void testSubmitGuestBookEntry(HomeController homeController, HttpPostedFileBase imageUpload)
        {
            // Arrange            
            _guestBookEntryModel = new GuestBookEntryModel { Name = TEST_GUEST_NAME, Comment = TEST_GUEST_COMMENT };

            // Act            
            var submitActionResult = homeController.Submit(_guestBookEntryModel, imageUpload);
            var redirectToRouteResult = submitActionResult as RedirectToRouteResult;

            // Assert
            Assert.IsNotNull(redirectToRouteResult);
            Assert.IsNotNull(redirectToRouteResult.RouteValues["action"]);
            Assert.AreEqual("Index", redirectToRouteResult.RouteValues["action"]);
            var submitResponse = homeController.TempData["SubmitResponse"] as SubmitResponse;
            Assert.IsNotNull(submitResponse);
            Assert.AreEqual(true, submitResponse.IsSuccess);
            Assert.AreEqual("Data submission is success.", submitResponse.Message);

        }