public void EditGroupName_should_redirect_to_index_action_when_update_is_successful() { // Given const int groupId = 103; const int centreId = 2; var model = new EditGroupNameViewModel { GroupName = "Test Group Name", }; A.CallTo( () => groupsService.UpdateGroupName( groupId, centreId, model.GroupName ) ).DoesNothing(); // When var result = delegateGroupsController.EditGroupName(model, groupId); // Then A.CallTo( () => groupsService.UpdateGroupName( groupId, centreId, model.GroupName ) ) .MustHaveHappened(); result.Should().BeRedirectToActionResult().WithActionName("Index"); }
public void EditGroupName_should_redirect_to_not_found_page_when_linked_to_field_is_not_zero() { // Given var model = new EditGroupNameViewModel { GroupName = "Test Group Name" }; A.CallTo(() => groupsService.GetGroupAtCentreById(1, 2)) .Returns(new Group { LinkedToField = 1 }); // When var result = delegateGroupsController.EditGroupName(1); // Them A.CallTo(() => groupsService.GetGroupAtCentreById(1, 2)).MustHaveHappened(); result.Should().BeNotFoundResult(); }
public IActionResult EditGroupName(EditGroupNameViewModel model, int groupId) { if (!ModelState.IsValid) { return(View(model)); } var centreId = User.GetCentreId(); var group = groupsService.GetGroupAtCentreById(groupId, centreId); if (group?.LinkedToField != 0) { return(NotFound()); } groupsService.UpdateGroupName( groupId, centreId, model.GroupName ); return(RedirectToAction("Index")); }