public void EditPost_WithNotSuccessfullEdit_ShouldReturnView() { // Arranges Mock <IStarService> starService = new Mock <IStarService>(); StarFormServiceModel model = this.GetStarFormModel(); starService .Setup(s => s.Exists(It.IsAny <string>())) .Returns(false); starService .Setup(s => s.GetName(It.IsAny <int>())) .Returns(model.Name); starService .Setup(s => s.Edit(It.IsAny <int>(), It.IsAny <string>(), It.IsAny <int>())) .Returns(false); StarsController starsController = new StarsController(starService.Object, null); // Act IActionResult result = starsController.Edit(1, 1, model); // Assert Assert.IsType <BadRequestResult>(result); }
public void EditGet_WithNotExistingId_ShouldReturnBadRequest() { // Arrange Mock <IStarService> starService = new Mock <IStarService>(); StarFormServiceModel model = null; starService .Setup(s => s.GetForm(It.IsAny <int>())) .Returns(model); StarsController starsController = new StarsController(starService.Object, null); // Act IActionResult result = starsController.Edit(1, 1); // Assert Assert.IsType <BadRequestResult>(result); }
public void EditPost_WithSuccessfullEdit_ShouldReturnRedirectResult() { // Arranges Mock <IStarService> starService = new Mock <IStarService>(); StarFormServiceModel formModel = this.GetStarFormModel(); const int discoveryId = 1; starService .Setup(s => s.Exists(It.IsAny <string>())) .Returns(false); starService .Setup(s => s.GetName(It.IsAny <int>())) .Returns(formModel.Name); starService .Setup(s => s.Edit(It.IsAny <int>(), It.IsAny <string>(), It.IsAny <int>())) .Returns(true); Mock <ITempDataDictionary> tempData = new Mock <ITempDataDictionary>(); string successmessage = null; tempData .SetupSet(t => t[WebConstants.TempDataSuccessMessage] = It.IsAny <string>()) .Callback((string key, object message) => successmessage = message as string); StarsController starsController = new StarsController(starService.Object, null); starsController.TempData = tempData.Object; // Act IActionResult result = starsController.Edit(1, discoveryId, formModel); // Assert Assert.IsType <RedirectToActionResult>(result); RedirectToActionResult redirectResult = result as RedirectToActionResult; this.AssertRedirect(discoveryId, redirectResult); Assert.Equal(string.Format(WebConstants.SuccessfullEntityOperation, Star, WebConstants.Edited), successmessage); }
public void EditPost_WithExistingStarName_ShouldReturnView() { // Arranges Mock <IStarService> starService = new Mock <IStarService>(); starService .Setup(s => s.Exists(It.IsAny <string>())) .Returns(true); starService .Setup(s => s.GetName(It.IsAny <int>())) .Returns("New Name"); Mock <ITempDataDictionary> tempData = new Mock <ITempDataDictionary>(); string errorMessage = null; tempData .SetupSet(t => t[WebConstants.TempDataErrorMessage] = It.IsAny <string>()) .Callback((string key, object message) => errorMessage = message as string); StarFormServiceModel formModel = this.GetStarFormModel(); StarsController starsController = new StarsController(starService.Object, null); starsController.TempData = tempData.Object; // Act IActionResult result = starsController.Edit(1, 1, formModel); // Assert Assert.IsType <ViewResult>(result); object model = (result as ViewResult).Model; Assert.IsType <StarFormServiceModel>(model); StarFormServiceModel returnModel = model as StarFormServiceModel; this.AssertStars(formModel, returnModel); Assert.Equal(string.Format(WebConstants.EntryExists, Star), errorMessage); }
public void EditGet_WithExistingId_ShouldReturnView() { // Arrange Mock <IStarService> starService = new Mock <IStarService>(); StarFormServiceModel formModel = this.GetStarFormModel(); starService .Setup(s => s.GetForm(It.IsAny <int>())) .Returns(formModel); StarsController starsController = new StarsController(starService.Object, null); // Act IActionResult result = starsController.Edit(1, 1); // Assert Assert.IsType <ViewResult>(result); object model = (result as ViewResult).Model; Assert.IsType <StarFormServiceModel>(model); StarFormServiceModel returnModel = model as StarFormServiceModel; this.AssertStars(formModel, returnModel); }