Exemplo n.º 1
0
        public void Returns_NotFound_if_centreIds_dont_match()
        {
            // Given
            var context = GetDefaultContext();

            A.CallTo(() => groupsService.GetGroupCentreId(A <int> ._)).Returns(UserCentreId + 1);

            // When
            new VerifyAdminUserCanAccessGroup(groupsService).OnActionExecuting(context);

            // Then
            context.Result.Should().BeNotFoundResult();
        }
Exemplo n.º 2
0
        public void DeleteGroup_redirects_to_confirmation_if_group_has_delegates()
        {
            // Given
            A.CallTo(() => groupsService.GetGroupCentreId(A <int> ._))
            .Returns(delegateGroupsController.User.GetCentreId());
            A.CallTo(() => groupsService.GetGroupDelegates(A <int> ._))
            .Returns(new List <GroupDelegate> {
                new GroupDelegate()
            });
            const int groupId = 1;

            // When
            var result = delegateGroupsController.DeleteGroup(groupId);

            // Then
            result.Should().BeRedirectToActionResult()
            .WithActionName("ConfirmDeleteGroup")
            .WithRouteValue("groupId", groupId);
        }
Exemplo n.º 3
0
        public void GetGroupCentreId_returns_expected_centre_id()
        {
            // Given
            const int groupId  = 1;
            const int centreId = 12;

            A.CallTo(() => groupsDataService.GetGroupCentreId(groupId))
            .Returns(centreId);

            // When
            var result = groupsService.GetGroupCentreId(groupId);

            // Then
            result.Should().Be(centreId);
        }
        public void OnActionExecuting(ActionExecutingContext context)
        {
            if (!(context.Controller is Controller controller))
            {
                return;
            }

            var groupId       = int.Parse(context.RouteData.Values["groupId"].ToString() !);
            var groupCentreId = groupsService.GetGroupCentreId(groupId);

            if (controller.User.GetCentreId() != groupCentreId)
            {
                context.Result = new NotFoundResult();
            }
        }