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); }