public void RemoveGroupDelegates_should_call_remove_progress_if_checked() { // Given var model = new RemoveGroupDelegatesViewModel { ConfirmRemovalFromGroup = true, RemoveStartedEnrolments = true }; A.CallTo(() => groupsService.GetGroupName(1, 2)).Returns("Group"); A.CallTo(() => groupsService.GetGroupDelegates(1)) .Returns(new List <GroupDelegate> { new GroupDelegate { DelegateId = 2 } }); A.CallTo(() => groupsService.RemoveDelegateFromGroup(1, 2, A <bool> ._)) .DoesNothing(); // When var result = delegateGroupsController.RemoveGroupDelegates(model, 1, 2); // Then A.CallTo(() => groupsService.RemoveDelegateFromGroup(1, 2, A <bool> ._)) .MustHaveHappened(); result.Should().BeRedirectToActionResult().WithActionName("GroupDelegates"); }
public void RemoveGroupDelegates_should_call_remove_progress_but_keep_started_enrolments_if_unchecked() { // Given var model = new RemoveGroupDelegatesViewModel { ConfirmRemovalFromGroup = true, RemoveStartedEnrolments = false }; const int groupId = 44; const int delegateId = 3274; A.CallTo(() => groupsService.GetGroupName(groupId, 2)).Returns("Group"); A.CallTo(() => groupsService.GetGroupDelegates(groupId)) .Returns(new List <GroupDelegate> { new GroupDelegate { DelegateId = delegateId } }); A.CallTo( () => groupsService.RemoveDelegateFromGroup(groupId, delegateId, model.RemoveStartedEnrolments) ).DoesNothing(); // When var result = delegateGroupsController.RemoveGroupDelegates(model, groupId, delegateId); // Then A.CallTo( () => groupsService.RemoveDelegateFromGroup(groupId, delegateId, model.RemoveStartedEnrolments) ).MustHaveHappened(); result.Should().BeRedirectToActionResult().WithActionName("GroupDelegates"); }
public IActionResult RemoveGroupDelegates(RemoveGroupDelegatesViewModel model, int groupId, int delegateId) { var centreId = User.GetCentreId(); var groupName = groupsService.GetGroupName(groupId, centreId); var groupDelegates = groupsService.GetGroupDelegates(groupId).ToList(); var delegateUser = groupDelegates.SingleOrDefault(gd => gd.DelegateId == delegateId); if (groupName == null || delegateUser == null) { return(NotFound()); } if (!model.ConfirmRemovalFromGroup) { ModelState.AddModelError( nameof(RemoveGroupDelegatesViewModel.ConfirmRemovalFromGroup), "You must confirm before removing this user from the group" ); return(View(model)); } groupsService.RemoveDelegateFromGroup(groupId, delegateId, model.RemoveStartedEnrolments); return(RedirectToAction("GroupDelegates", new { groupId })); }
public void RemoveGroupDelegatesPost_should_return_not_found_with_invalid_group_for_centre() { // Given var model = new RemoveGroupDelegatesViewModel { ConfirmRemovalFromGroup = true, RemoveStartedEnrolments = true }; A.CallTo(() => groupsService.GetGroupName(1, 2)).Returns(null); // When var result = delegateGroupsController.RemoveGroupDelegates(model, 1, 2); // Them result.Should().BeNotFoundResult(); }
public IActionResult RemoveGroupDelegates(int groupId, int delegateId) { var centreId = User.GetCentreId(); var groupName = groupsService.GetGroupName(groupId, centreId); var groupDelegates = groupsService.GetGroupDelegates(groupId).ToList(); var delegateUser = groupDelegates.SingleOrDefault(gd => gd.DelegateId == delegateId); if (groupName == null || delegateUser == null) { return(NotFound()); } var progressId = groupsService.GetRelatedProgressIdForGroupDelegate(groupId, delegateId); var model = new RemoveGroupDelegatesViewModel(delegateUser, groupName, groupId, progressId); return(View(model)); }
public void RemoveGroupDelegates_should_return_view_if_unconfirmed() { // Given var model = new RemoveGroupDelegatesViewModel { ConfirmRemovalFromGroup = false }; A.CallTo(() => groupsService.GetGroupName(1, 2)).Returns("Group"); A.CallTo(() => groupsService.GetGroupDelegates(1)) .Returns(new List <GroupDelegate> { new GroupDelegate { DelegateId = 2 } }); // When var result = delegateGroupsController.RemoveGroupDelegates(model, 1, 2); // Then result.Should().BeViewResult(); delegateGroupsController.ModelState.IsValid.Should().BeFalse(); }